FileDocCategorySizeDatePackage
TCONTextInformationID3V2Frame.javaAPI Docjid3 0.466580Sun Feb 06 18:11:18 GMT 2005org.blinkenlights.jid3.v2

TCONTextInformationID3V2Frame

public class TCONTextInformationID3V2Frame extends TextInformationID3V2Frame
author
paul Text frame which contains the content type of the track (ie. genre details).

Fields Summary
private ContentType
m_oContentType
Constructors Summary
public TCONTextInformationID3V2Frame(ContentType oContentType)
Constructor.

param
oContentType the content type (genre) of this track

    
                   
      
    
        super("");
        
        m_oContentType = oContentType;
        
        m_sInformation = oContentType.toString();
    
public TCONTextInformationID3V2Frame(InputStream oIS)

        super(oIS);
        
        try
        {
            m_oContentType = convertStringToContentType(m_sInformation);
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception("Encountered a corrupt TCON year frame.", e);
        }

    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitTCONTextInformationID3V2Frame(this);
    
private ContentTypeconvertStringToContentType(java.lang.String sContentType)
Internal method to convert a string in the format stored in a frame, to a content type object.

param
sContentType a string to be parsed
return
a ContentType object representing the string value
throws
ID3Exception if there is any error parsing the string value

        ContentType oContentType = new ContentType();
        
        try
        {
            String sPiece = null;
            while ((sPiece = getNextPiece(sContentType)).length() > 0)
            {
                // is piece a refinement?
                if ((sPiece.charAt(0) != '(") || (sPiece.startsWith("((")))
                {
                    oContentType.setRefinement(sPiece);
                }
                // cover?
                else if (sPiece.toUpperCase().equals("(CR)"))
                {
                    oContentType.setIsCover(true);
                }
                // remix?
                else if (sPiece.toUpperCase().equals("(RX)"))
                {
                    oContentType.setIsRemix(true);
                }
                // valid genre?
                else
                {
                    String sGenreValue = sPiece.substring(1, sPiece.length()-1);
                    int iGenreValue = Integer.parseInt(sGenreValue);
                    try
                    {
                        ContentType.Genre oGenre = ContentType.Genre.lookupGenre(iGenreValue);
                        oContentType.setGenre(oGenre);
                    }
                    catch (Exception e)
                    {
                        if (ID3Tag.usingStrict())
                        {
                            throw e;
                        }
                        // else, skip what we can't parse
                    }
                }

                sContentType = sContentType.substring(sPiece.length());
            }
        }
        catch (ID3Exception e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new ID3Exception("Encountered corrupt content type value in tag.", e);
        }
        
        return oContentType;
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof TCONTextInformationID3V2Frame)))
        {
            return false;
        }
        
        TCONTextInformationID3V2Frame oOtherTCON = (TCONTextInformationID3V2Frame)oOther;
        
        return (m_oContentType.equals(oOtherTCON.m_oContentType) &&
                m_oTextEncoding.equals(oOtherTCON.m_oTextEncoding) &&
                m_sInformation.equals(oOtherTCON.m_sInformation));
    
public ContentTypegetContentType()
Get the content type from this frame.

return
the current ContentType

        return m_oContentType;
    
protected byte[]getFrameId()

        return "TCON".getBytes();
    
private java.lang.StringgetNextPiece(java.lang.String sContentType)
Internal method to help in parsing a string value to a ContentType.

        // there's nothing in an empty string
        if (sContentType.length() == 0)
        {
            return "";
        }
        
        // it's all refinement
        if ((sContentType.charAt(0) != '(") || (sContentType.startsWith("((")))
        {
            return sContentType;
        }
        
        // there's a piece to return here
        return sContentType.substring(0, sContentType.indexOf(')")+1);
    
public ContentTypesetContentType(ContentType oContentType)
Set the content type (genre) of this frame.

param
oContentType the content type of this track
return
the previous content type

        ContentType oOldContentType = m_oContentType;
        
        m_oContentType = oContentType;
        
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = oContentType.toString();

        return oOldContentType;
    
public java.lang.StringtoString()

        return "Content type: [" + m_sInformation + "]";