FileDocCategorySizeDatePackage
AbstractFrameBodyUrlLink.javaAPI DocJaudiotagger 2.0.45467Wed Mar 30 16:12:02 BST 2011org.jaudiotagger.tag.id3.framebody

AbstractFrameBodyUrlLink

public abstract class AbstractFrameBodyUrlLink extends AbstractID3v2FrameBody
Abstract super class of all URL Frames

Fields Summary
Constructors Summary
protected AbstractFrameBodyUrlLink()
Creates a new FrameBodyUrlLink datatype.

        super();
    
protected AbstractFrameBodyUrlLink(AbstractFrameBodyUrlLink body)
Copy Constructor

param
body

        super(body);
    
public AbstractFrameBodyUrlLink(String urlLink)
Creates a new FrameBodyUrlLink datatype., set up with data.

param
urlLink

        setObjectValue(DataTypes.OBJ_URLLINK, urlLink);
    
protected AbstractFrameBodyUrlLink(ByteBuffer byteBuffer, int frameSize)
Creates a new FrameBodyUrlLink datatype.

param
byteBuffer
param
frameSize
throws
InvalidTagException if unable to create framebody from buffer

        super(byteBuffer, frameSize);
    
Methods Summary
private java.lang.StringencodeURL(java.lang.String url)
Encode url because may receive url already encoded or not, but we can only store as ISO8859-1

param
url
return

        try
        {
            final String[] splitURL = url.split("(?<!/)/(?!/)", -1);
            final StringBuffer sb = new StringBuffer(splitURL[0]);
            for (int i = 1; i < splitURL.length; i++)
            {
                sb.append("/").append(URLEncoder.encode(splitURL[i], "utf-8"));
            }
            return sb.toString();
        }
        catch (UnsupportedEncodingException uee)
        {
            //Should never happen as utf-8 is always availablebut in case it does we just return the utl
            //unmodified
            logger.warning("Uable to url encode because utf-8 charset not available:" + uee.getMessage());
            return url;
        }
    
public java.lang.StringgetUrlLink()
Get URL Link

return
the urllink

        return (String) getObjectValue(DataTypes.OBJ_URLLINK);
    
public java.lang.StringgetUserFriendlyValue()

        return getUrlLink();
    
public voidsetUrlLink(java.lang.String urlLink)
Set URL Link

param
urlLink

        if (urlLink == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        setObjectValue(DataTypes.OBJ_URLLINK, urlLink);
    
protected voidsetupObjectList()

        objectList.add(new StringSizeTerminated(DataTypes.OBJ_URLLINK, this));
    
public voidwrite(java.io.ByteArrayOutputStream tagBuffer)
If the description cannot be encoded using the current encoding change the encoder

        CharsetEncoder encoder = Charset.forName(TextEncoding.CHARSET_ISO_8859_1).newEncoder();
        String origUrl = getUrlLink();
        if (!encoder.canEncode(origUrl))
        {
            //ALL W Frames only support ISO-8859-1 for the url itself, if unable to encode let us assume
            //the link just needs url encoding
            setUrlLink(encodeURL(origUrl));

            //We still cant convert so just set log error and set to blank to allow save to continue
            if (!encoder.canEncode(getUrlLink()))
            {
                logger.warning(ErrorMessage.MP3_UNABLE_TO_ENCODE_URL.getMsg(origUrl));
                setUrlLink("");
            }
            //it was ok, just note the modification made
            else
            {
                logger.warning(ErrorMessage.MP3_URL_SAVED_ENCODED.getMsg(origUrl, getUrlLink()));
            }
        }
        super.write(tagBuffer);