entagged.audioformats.asf.util
Class AsfCopyrightField

java.lang.Object
  extended by entagged.audioformats.asf.util.AsfCopyrightField
All Implemented Interfaces:
TagField, TagTextField

public final class AsfCopyrightField
extends Object
implements TagTextField

This class represents the copyright field of asf files.
The copyright cannot be accessed like an ordinary "name"-"value"-property, since it has a defined position within the asf structure.
Use:
If you want to modify the copyright field of asf files using the entagged audio library, you should access it using this class.
You can get a it using Tag.get(String). The argument must be the value of FIELD_ID, since the reading facility of asf files will place the copyright there. (consider that the copyright field of asf fils is only supported once, you may place several copyright fields into Tag, however only the first one will be written.)
It is recommended to use the setString(String)method if possible because only then you will get feedback of validity checks. If your environment doesn't support "UTF-16LE" encoding or the "UTF-16LE"-representation would exceed 65533 Bytes you will be notified. Otherwise if you use the standard method setContent(String), the value "Conversion Exception occured." will be placed on errors.
Alternative:
You can use your own implementation of TagField, then you must remember using FIELD_IDas the "ID", since the asf writing methods will look at that for writing the file. Additional isCommon() must return true
Example :
Reading copyright

 
 AudioFile file = AudioFileIO.read(new File("/somewhere/test.wma"));
 // Get the copyright field
 TagTextField copyright = AsfCopyrightField.getCopyright(file.getTag());
 // Will be null, if no copyright is specified.
 if (copyright != null)
        System.out.println(copyright.getContent());
  
 


Modifying copyright
 
 AudioFile file = AudioFileIO.read(new File("/somewhere/test.wma"));
 // Get the copyright field
 TagTextField copyright = AsfCopyrightField.getCopyright(file.getTag());
 // Will be null, if no copyright is specified.
 if (copyright != null) {
        System.out.println(copyright.getContent());
        // setThe value
        copyright.setContent("It belongs to me now.");
 }
 AudioFileIO.write(file);
  
 


Creating new copyright
 
 AudioFile file = AudioFileIO.read(new File("/somewhere/test.wma"));
 // Create field
 TagTextField copyright = new AsfCopyrightField();
 // setThe value
 copyright.setContent("My intellectual property");
 // Add the new field
 file.getTag().set(copyright);
 AudioFileIO.write(file);
  
 


Delete copyright
 
 AudioFile file = AudioFileIO.read(new File("/somewhere/test.wma"));
 // Create field
 TagTextField copyright = new AsfCopyrightField();
 // Without a value, the field will be deleted.
 file.getTag().set(copyright);
 AudioFileIO.write(file);
  
 




Programming internals
This class's method isCommon()will always return true, so that the represented value will not be handled as a "name"-"value"-property. The TagConverterwill identify this field at TagConverter.createContentDescription(Tag) and place the value into the corresponding java object ( ContentDescription).

Author:
Christian Laireiter

Field Summary
static String FIELD_ID
          This constant represents the field id of the currently represented copyright field.
 
Constructor Summary
AsfCopyrightField()
           
 
Method Summary
 void copyContent(TagField field)
          (overridden)
 String getContent()
          (overridden)
static TagTextField getCopyright(Tag tag)
          This method should help programmers to extract the copyright field out of asf files.
 String getEncoding()
          (overridden)
 String getId()
          (overridden) Will return FIELD_ID.
 byte[] getRawContent()
          (overridden)
 boolean isBinary()
          (overridden)
 void isBinary(boolean b)
          (overridden)
 boolean isCommon()
          (overridden) This Method will return true, so it won't be used for the extended content description chunk, where the "name"-"value" properties are stored.
 boolean isEmpty()
          (overridden)
 void setContent(String s)
          (overridden)
 void setEncoding(String s)
          (overridden)
 void setString(String s)
          This method sets the content of the current copyright field.
 String toString()
          (overridden)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIELD_ID

public static final String FIELD_ID
This constant represents the field id of the currently represented copyright field.
This value will be filtered at TagConverter.

See Also:
Constant Field Values
Constructor Detail

AsfCopyrightField

public AsfCopyrightField()
Method Detail

getCopyright

public static TagTextField getCopyright(Tag tag)
This method should help programmers to extract the copyright field out of asf files.

Parameters:
tag - The tag which contains the copyright field.
Returns:
null if the tag represents a file which is not a asf file, or no copyright has been entered.

copyContent

public void copyContent(TagField field)
(overridden)

Specified by:
copyContent in interface TagField
Parameters:
field - The field containing the data to be taken.
See Also:
TagField.copyContent(entagged.audioformats.generic.TagField)

getContent

public String getContent()
(overridden)

Specified by:
getContent in interface TagTextField
Returns:
Content
See Also:
TagTextField.getContent()

getEncoding

public String getEncoding()
(overridden)

Specified by:
getEncoding in interface TagTextField
Returns:
Charset encoding.
See Also:
TagTextField.getEncoding()

getId

public String getId()
(overridden) Will return FIELD_ID.

Specified by:
getId in interface TagField
Returns:
Unique identifier for the fields type. (title, artist...)
See Also:
TagField.getId()

getRawContent

public byte[] getRawContent()
                     throws UnsupportedEncodingException
(overridden)

Specified by:
getRawContent in interface TagField
Returns:
Binary data representing the current tag field.
Throws:
UnsupportedEncodingException - Most tag data represents text. In some cases the underlying implementation will need to convert the text data in java to a specific charset encoding. In these cases an UnsupportedEncodingException may occur.
See Also:
TagField.getRawContent()

isBinary

public boolean isBinary()
(overridden)

Specified by:
isBinary in interface TagField
Returns:
true if field represents binary data (not human readable).
See Also:
TagField.isBinary()

isBinary

public void isBinary(boolean b)
(overridden)

Specified by:
isBinary in interface TagField
Parameters:
b - true, if the field contains binary data.
See Also:
TagField.isBinary(boolean)

isCommon

public boolean isCommon()
(overridden) This Method will return true, so it won't be used for the extended content description chunk, where the "name"-"value" properties are stored.

Specified by:
isCommon in interface TagField
Returns:
true if the field is of common use.
See Also:
TagConverter.assignOptionalTagValues(Tag, ExtendedContentDescription), TagField.isCommon()

isEmpty

public boolean isEmpty()
(overridden)

Specified by:
isEmpty in interface TagField
Returns:
true if no data is stored (or empty String).
See Also:
TagField.isEmpty()

setContent

public void setContent(String s)
(overridden)

Specified by:
setContent in interface TagTextField
Parameters:
s - fields content.
See Also:
TagTextField.setContent(java.lang.String)

setEncoding

public void setEncoding(String s)
(overridden)

Specified by:
setEncoding in interface TagTextField
Parameters:
s - charset.
See Also:
TagTextField.setEncoding(java.lang.String)

setString

public void setString(String s)
This method sets the content of the current copyright field.
The reason for existence of this method is that you will get Exceptions if the given value cannot be used for asf files.
The restriction for asf field contents is that they must not exceed 65535 bytes including the zero termination character and they must be stored in "UTF-16LE" encoding.

Parameters:
s - The new copyright.
Throws:
IllegalArgumentException - If the size of the value would exceed 65535 bytes in UTF-16LE encoding including two bytes for zero termination.

toString

public String toString()
(overridden)

Specified by:
toString in interface TagField
Overrides:
toString in class Object
Returns:
Description of the fields content.
See Also:
TagField.toString()


Copyright © 2007-2008. All Rights Reserved.