FileDocCategorySizeDatePackage
WXXXUrlLinkID3V2Frame.javaAPI Docjid3 0.468723Sun Feb 06 18:11:20 GMT 2005org.blinkenlights.jid3.v2

WXXXUrlLinkID3V2Frame

public class WXXXUrlLinkID3V2Frame extends UrlLinkID3V2Frame
author
paul Url frame containing user-defined information.

Fields Summary
private TextEncoding
m_oTextEncoding
private String
m_sDescription
Constructors Summary
public WXXXUrlLinkID3V2Frame(String sDescription, String sUrl)
Constructor.

param
sDescription a description of the URL being stored
param
sUrl the URL being stored
throws
ID3Exception if the URL passed is null, or if the description is null

    
                                       
        
         
    
        super(sUrl);
        
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if (sDescription == null)
        {
            throw new ID3Exception("Description cannot be null in WXXX frame.");
        }
        m_sDescription = sDescription;
        m_sURL = sUrl;
    
public WXXXUrlLinkID3V2Frame(String sDescription, URL oURL)
Constructor.

param
sDescription a description of the URL being stored
param
oURL the URL being stored
throws
ID3Exception if the URL passed is null, or if the description is null

        super(oURL);
        
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if (sDescription == null)
        {
            throw new ID3Exception("Description cannot be null in WXXX frame.");
        }
        m_sDescription = sDescription;
        m_sURL = oURL.toExternalForm();
    
public WXXXUrlLinkID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);

            // text encoding
            m_oTextEncoding = TextEncoding.getTextEncoding(oFrameDataID3DIS.readUnsignedByte());

            // description (read to null)
            m_sDescription = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
            
            // url
            byte[] abyUrl = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(abyUrl);
            m_sURL = new String(abyUrl);
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitWXXXUrlLinkID3V2Frame(this);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof WXXXUrlLinkID3V2Frame)))
        {
            return false;
        }
        
        WXXXUrlLinkID3V2Frame oOtherWXXX = (WXXXUrlLinkID3V2Frame)oOther;
        
        return (m_sDescription.equals(oOtherWXXX.m_sDescription) &&
                m_oTextEncoding.equals(oOtherWXXX.m_oTextEncoding) &&
                m_sURL.equals(oOtherWXXX.m_sURL));
    
public java.lang.StringgetDescription()
Get the description of the URL stored in this frame.

return
the description of the URL stored in this frame

        return m_sDescription;
    
protected byte[]getFrameId()

        return "WXXX".getBytes();
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the description in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public java.lang.StringgetUrl()
Get the URL stored in this frame.

return
the URL stored in this frame (note returned value may not be a valid url)

        return m_sURL;
    
public voidsetDescriptionAndUrl(java.lang.String sDescription, java.lang.String sUrl)
Set the description of the URL to be stored in this frame, along with the actual URL.

param
sDescription a description of the URL being stored
param
sUrl the URL being stored
throws
ID3Exception if the URL passed is null, or if the description is null

        TextEncoding oOrigTextEncoding = m_oTextEncoding;
        String sOrigDescription = m_sDescription;
        String sOrigURL = m_sURL;
        
        if (sDescription == null)
        {
            throw new ID3Exception("Description cannot be null in WXXX frame.");
        }
        if (sUrl == null)
        {
            throw new ID3Exception("Url cannot be null in WXXX frame.");
        }

        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sDescription = sDescription;
        m_sURL = sUrl;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_oTextEncoding = oOrigTextEncoding;
            m_sDescription = sOrigDescription;
            m_sURL = sOrigURL;
            
            throw e;
        }
    
public voidsetDescriptionAndUrl(java.lang.String sDescription, java.net.URL oURL)
Set the description of the URL to be stored in this frame, along with the actual URL.

param
sDescription a description of the URL being stored
param
oURL the URL being stored
throws
ID3Exception if the URL passed is null, or if the description is null

        TextEncoding oOrigTextEncoding = m_oTextEncoding;
        String sOrigDescription = m_sDescription;
        String sOrigURL = m_sURL;
        
        if (sDescription == null)
        {
            throw new ID3Exception("Description cannot be null in WXXX frame.");
        }
        if (oURL == null)
        {
            throw new ID3Exception("URL cannot be null in WXXX frame.");
        }

        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sDescription = sDescription;
        m_sURL = oURL.toExternalForm();
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_oTextEncoding = oOrigTextEncoding;
            m_sDescription = sOrigDescription;
            m_sURL = sOrigURL;
            
            throw e;
        }
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the description in this frame.

param
oTextEncoding the text encoding to be used for this frame

        if (oTextEncoding == null)
        {
            throw new NullPointerException("Text encoding cannot be null.");
        }
        m_oTextEncoding = oTextEncoding;
    
public java.lang.StringtoString()

        return "User-defined URL: Description=[" + m_sDescription + "], URL=[" + m_sURL + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        oIDOS.write(m_sDescription.getBytes(m_oTextEncoding.getEncodingString()));
        // null separating content descriptor from lyrics
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        // url
        oIDOS.write(m_sURL.getBytes());