FileDocCategorySizeDatePackage
IPLSID3V2Frame.javaAPI Docjid3 0.4610512Sun Feb 06 18:11:23 GMT 2005org.blinkenlights.jid3.v2

IPLSID3V2Frame

public class IPLSID3V2Frame extends ID3V2Frame
author
paul Frame containing an involved people list.

Fields Summary
private TextEncoding
m_oTextEncoding
private SortedMap
m_oPeopleMap
Constructors Summary
public IPLSID3V2Frame()
Constructor.

    
      
     
    
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_oPeopleMap = new TreeMap();
    
public IPLSID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // text encoding
            m_oTextEncoding = TextEncoding.getTextEncoding(oFrameDataID3DIS.readUnsignedByte());
            
            // involved persons
            m_oPeopleMap = new TreeMap();
            while (oFrameDataID3DIS.available() > 0)
            {
                String sInvolvement = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
                String sPerson = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
                if ((sInvolvement == null) || (sPerson == null))
                {
                    throw new ID3Exception("IPLS frame missing involvement or person.");
                }
                addInvolvedPerson(new InvolvedPerson(sInvolvement, sPerson));
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitIPLSID3V2Frame(this);
    
public voidaddInvolvedPerson(org.blinkenlights.jid3.v2.IPLSID3V2Frame$InvolvedPerson oInvolvedPerson)
Add an involved person to the list.

param
oInvolvedPerson the involved person to be added

        // create set mapping if not there
        if ( ! m_oPeopleMap.containsKey(oInvolvedPerson.getInvolvement()))
        {
            m_oPeopleMap.put(oInvolvedPerson.getInvolvement(), new TreeSet());
        }
        
        // add involved person to mapped set
        Set oIPSet = (Set)m_oPeopleMap.get(oInvolvedPerson.getInvolvement());
        oIPSet.add(oInvolvedPerson);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof IPLSID3V2Frame)))
        {
            return false;
        }
        
        IPLSID3V2Frame oOtherIPLS = (IPLSID3V2Frame)oOther;
        
        return ( m_oTextEncoding.equals(oOtherIPLS.m_oTextEncoding) &&
                 m_oPeopleMap.equals(oOtherIPLS.m_oPeopleMap));
    
protected byte[]getFrameId()

        return "IPLS".getBytes();
    
public org.blinkenlights.jid3.v2.IPLSID3V2Frame$InvolvedPerson[]getInvolvedPersons(java.lang.String sInvolvement)
Get all involved persons with a given involvement.

param
sInvolvement the involvement for which a list of involved persons is to be returned
return
an array of matching involved persons

        Set oIPSet = (Set)m_oPeopleMap.get(sInvolvement);
        
        if (oIPSet != null)
        {
            return (InvolvedPerson[])oIPSet.toArray(new InvolvedPerson[0]);
        }
        else
        {
            return new InvolvedPerson[0];
        }
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the involved people in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public org.blinkenlights.jid3.v2.IPLSID3V2Frame$InvolvedPerson[]removedInvolvedPersons(java.lang.String sInvolvement)
Removed all persons with a given involvement.

param
sInvolvement the involvement for which all involved persons are to be removed
return
an array of involved persons which previously matched the specified involvement

        Set oIPSet = (Set)m_oPeopleMap.remove(sInvolvement);
        
        if (oIPSet != null)
        {
            return (InvolvedPerson[])oIPSet.toArray(new InvolvedPerson[0]);
        }
        else
        {
            return new InvolvedPerson[0];
        }
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the involved people 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()

        StringBuffer sbOutput = new StringBuffer();
        sbOutput.append("InvolvedPersons: Involvments =");
        if (m_oPeopleMap.values().size() > 0)
        {
            Iterator oSetIter = m_oPeopleMap.values().iterator();
            while (oSetIter.hasNext())
            {
                Set oInvolvedPersonSet = (Set)oSetIter.next();
                Iterator oIPIter = oInvolvedPersonSet.iterator();
                while (oIPIter.hasNext())
                {
                    InvolvedPerson oIP = (InvolvedPerson)oIPIter.next();
                    sbOutput.append("\nInvolvement=" + oIP.getInvolvement() + ", Person=" + oIP.getPerson());
                }
            }
        }
        else
        {
            sbOutput.append(" none");
        }
        
        return sbOutput.toString();
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // text encoding
        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        // involvements
        Iterator oSetIter = m_oPeopleMap.values().iterator();
        while (oSetIter.hasNext())
        {
            Set oInvolvedPersonSet = (Set)oSetIter.next();
            Iterator oIPIter = oInvolvedPersonSet.iterator();
            while (oIPIter.hasNext())
            {
                InvolvedPerson oIP = (InvolvedPerson)oIPIter.next();
                
                oIDOS.write(oIP.getInvolvement().getBytes(m_oTextEncoding.getEncodingString()));
                // null after involvement
                if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
                {
                    oIDOS.writeUnsignedByte(0);
                }
                else
                {
                    oIDOS.writeUnsignedByte(0);
                    oIDOS.writeUnsignedByte(0);
                }
                oIDOS.write(oIP.getPerson().getBytes(m_oTextEncoding.getEncodingString()));
                // null after person
                if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
                {
                    oIDOS.writeUnsignedByte(0);
                }
                else
                {
                    oIDOS.writeUnsignedByte(0);
                    oIDOS.writeUnsignedByte(0);
                }
            }
        }