|
|||||||||
| Home >> All >> org >> esau >> ptarmigan >> [ impl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.esau.ptarmigan.impl
Class GeneratorImpl

java.lang.Objectorg.xml.sax.helpers.XMLFilterImpl
org.esau.ptarmigan.impl.GeneratorImpl
- All Implemented Interfaces:
- org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.esau.ptarmigan.Generator, org.xml.sax.XMLFilter, org.xml.sax.XMLReader
- public final class GeneratorImpl
- extends org.xml.sax.helpers.XMLFilterImpl
- implements org.esau.ptarmigan.Generator
- extends org.xml.sax.helpers.XMLFilterImpl
GeneratorImpl
From which the source is identified and which the parsers are launched
Instances of this class parse media files of different formats (mp3, ogg, pls, etc.) and generate SAX events describing the metadata of those files which can then be consumed, such as for data storage.
Those SAX events are typically used to build a Document which in turn is transformed to an object useable by the caller.
IMPLEMENTATION DETAILS
The algorithm used is designed for one-pass usage. It requires the use of a buffered stream where a marker can be set to sniff ahead for tags.
One at a time, give each parser a chance to sniff that buffer. The first one who returns sniff==true will own that position and immediately can parse data from it up to a limit.
NOTES
TODO: remove all references to specific parsers from the GeneratorImpl. Instead refer to them dynamically through StreamParser (ID3v2, Vorbis, etc.) and FileParser (ID3v1) interfaces. Place each parser in a jar and use a resource reference to identify it as a client parser.
- Version:
- $Revision: 1.7 $ $Date: 2002/09/24 02:51:17 $
| Field Summary | |
(package private) static int |
DEFAULT_MAX_TAG_SIZE
the number of bytes to read from the start of a stream/file to identify which parser it requires |
(package private) static org.xml.sax.Attributes |
EMPTY_ATTRS
|
(package private) static boolean |
EXCLUDE_DIGEST
|
(package private) static boolean |
INCLUDE_DIGEST
|
(package private) static org.apache.commons.logging.Log |
log
logging object |
(package private) java.util.List |
m_binary_filters
the filters that work with binary streams |
(package private) boolean |
m_configured
have the parsers been loaded? |
(package private) java.util.List |
m_file_filters
the parsers that only work with files |
(package private) boolean |
m_include_digest
should a digest be calculated for media? |
(package private) boolean |
m_include_entries
should entries (perhaps many) be included in scanned playlists? |
(package private) MediaProperties |
m_media_properties
details on the media, like data range and mime-type |
(package private) java.lang.String |
m_parse_error
a holder for a stack trace in case a problem occurs; written out to xml |
(package private) int |
m_read_limit
|
(package private) java.lang.String |
m_system_id
the unmodified system_id passed in as input |
(package private) java.io.File |
m_system_id_file
if the source is a local file, here's its name |
(package private) java.net.URL |
m_system_id_url
the system_id in URL form |
(package private) java.util.List |
m_text_filters
the parsers that work with text streams |
(package private) static java.lang.String |
NS_PREFIX
|
(package private) static java.lang.String |
NS_URI
|
| Fields inherited from class org.xml.sax.helpers.XMLFilterImpl |
|
| Fields inherited from interface org.esau.ptarmigan.Generator |
DEFAULT_INCLUDE_DIGEST, DEFAULT_INCLUDE_PLAYLIST_ENTRIES, DEFAULT_PROPERTY_READ_LIMIT, FEATURE_INCLUDE_DIGEST, FEATURE_INCLUDE_PLAYLIST_ENTRIES, PROPERTY_READ_LIMIT |
| Constructor Summary | |
GeneratorImpl()
|
|
| Method Summary | |
(package private) void |
configure()
generator configuration TODO: configure this object from classnames specfied in an XML file, or via Jakarta Commons Discovery. |
boolean |
getFeature(java.lang.String name)
OVERRIDE Look up the value of a feature. |
java.lang.Object |
getProperty(java.lang.String name)
OVERRIDE Look up the value of a property. |
(package private) java.io.InputStream |
getStream()
obtain an input stream from the system-id in the specified input source. |
(package private) java.lang.String |
getTextMarker(byte[] sniff_bytes,
int length)
read in the (text-based) marker, skipping any BOM for UTF-16 or UTF-8 |
(package private) void |
initSystemId(java.lang.String sid)
init the original system_id and the derived fields |
void |
parse(org.xml.sax.InputSource input)
OVERRIDE SAX-invoked parse If it's a file, attempt to parse the ID3v1 tag at the end of the file. |
(package private) void |
parseBinaryStream(java.io.InputStream is)
Binary stream reading is constrained by the READ_LIMIT property. |
(package private) void |
parseStream(java.io.InputStream is)
This is where the magic happens. |
(package private) void |
parseTextStream(java.io.InputStream is)
Try to find a TEXT parser that can handle the stream, and if found let it consume it in its entireity. |
(package private) void |
processFileSource()
|
void |
resetData()
Reset data members for reuse |
void |
setContentHandler(org.xml.sax.ContentHandler handler)
OVERRIDE Set the content event handler. |
void |
setFeature(java.lang.String name,
boolean value)
OVERRIDE Set the value of a feature. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
OVERRIDE Set the value of a property. |
(package private) void |
write(java.lang.String key,
java.util.Date date,
boolean date_only)
|
(package private) void |
write(java.lang.String key,
long value)
|
(package private) void |
write(java.lang.String key,
java.lang.String value)
|
(package private) void |
write(java.lang.String key,
java.lang.String value,
org.xml.sax.Attributes attrs)
|
(package private) void |
writeFileProps()
write file-properties element and children |
(package private) void |
writeLog()
|
(package private) void |
writeMediaDigest()
|
(package private) void |
writeMediaProps()
produce SAX events for the audio data-oriented metadata |
| Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
characters, endDocument, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getParent, ignorableWhitespace, notationDecl, parse, processingInstruction, resolveEntity, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setParent, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.xml.sax.XMLFilter |
getParent, setParent |
| Methods inherited from interface org.xml.sax.XMLReader |
getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, parse, setDTDHandler, setEntityResolver, setErrorHandler |
| Methods inherited from interface org.xml.sax.ContentHandler |
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping |
| Field Detail |
m_parse_error
java.lang.String m_parse_error
- a holder for a stack trace in case a problem occurs; written out to xml
m_read_limit
int m_read_limit
m_system_id
java.lang.String m_system_id
- the unmodified system_id passed in as input
m_configured
boolean m_configured
- have the parsers been loaded?
m_file_filters
java.util.List m_file_filters
- the parsers that only work with files
m_binary_filters
java.util.List m_binary_filters
- the filters that work with binary streams
m_text_filters
java.util.List m_text_filters
- the parsers that work with text streams
m_media_properties
MediaProperties m_media_properties
- details on the media, like data range and mime-type
m_system_id_url
java.net.URL m_system_id_url
- the system_id in URL form
m_system_id_file
java.io.File m_system_id_file
- if the source is a local file, here's its name
m_include_digest
boolean m_include_digest
- should a digest be calculated for media?
m_include_entries
boolean m_include_entries
- should entries (perhaps many) be included in scanned playlists?
INCLUDE_DIGEST
static final boolean INCLUDE_DIGEST
- See Also:
- Constant Field Values
EXCLUDE_DIGEST
static final boolean EXCLUDE_DIGEST
- See Also:
- Constant Field Values
NS_URI
static final java.lang.String NS_URI
- See Also:
- Constant Field Values
NS_PREFIX
static final java.lang.String NS_PREFIX
- See Also:
- Constant Field Values
EMPTY_ATTRS
static final org.xml.sax.Attributes EMPTY_ATTRS
DEFAULT_MAX_TAG_SIZE
static final int DEFAULT_MAX_TAG_SIZE
- the number of bytes to read from the start of a stream/file
to identify which parser it requires
- See Also:
- Constant Field Values
log
static org.apache.commons.logging.Log log
- logging object
| Constructor Detail |
GeneratorImpl
public GeneratorImpl()
| Method Detail |
configure
void configure()
throws java.io.IOException,
org.xml.sax.SAXException
- generator configuration
TODO: configure this object from classnames specfied in an XML file, or
via Jakarta Commons Discovery.
TODO: use lazy loading
TODO: where available, use file extension hints to determine which parser
to invoke.
parse
public void parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
- OVERRIDE
SAX-invoked parse
If it's a file, attempt to parse the ID3v1 tag at the end of the file.
- Specified by:
parsein interfaceorg.xml.sax.XMLReader
resetData
public void resetData()
- Reset data members for reuse
Note that features and properties are NOT reset to defaults as they are usually set when the generator is created.
- Specified by:
resetDatain interfaceorg.esau.ptarmigan.Generator
setContentHandler
public void setContentHandler(org.xml.sax.ContentHandler handler)
- OVERRIDE
Set the content event handler.
- Specified by:
setContentHandlerin interfaceorg.xml.sax.XMLReader
getFeature
public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- OVERRIDE
Look up the value of a feature.
- Specified by:
getFeaturein interfaceorg.xml.sax.XMLReader
setFeature
public void setFeature(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- OVERRIDE
Set the value of a feature.
- Specified by:
setFeaturein interfaceorg.xml.sax.XMLReader
getProperty
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- OVERRIDE
Look up the value of a property.
- Specified by:
getPropertyin interfaceorg.xml.sax.XMLReader
setProperty
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- OVERRIDE
Set the value of a property.
- Specified by:
setPropertyin interfaceorg.xml.sax.XMLReader
getStream
java.io.InputStream getStream() throws java.io.IOException
- obtain an input stream from the system-id in the specified input source.
Note that we explicitly don't buffer the stream here, as that is dealt
with elsewhere.
initSystemId
void initSystemId(java.lang.String sid) throws java.io.IOException
- init the original system_id and the derived fields
processFileSource
void processFileSource()
throws java.io.IOException,
org.xml.sax.SAXException
parseStream
void parseStream(java.io.InputStream is) throws java.io.IOException, org.xml.sax.SAXException
- This is where the magic happens.
Extract metadata from a stream (text or binary) using the available parsers.
Parsing continues until a mime-type is assigned. TODO: some other flag perhaps?
parseBinaryStream
void parseBinaryStream(java.io.InputStream is) throws java.io.IOException, java.text.ParseException, org.xml.sax.SAXException
- Binary stream reading is constrained by the READ_LIMIT property.
parseTextStream
void parseTextStream(java.io.InputStream is) throws java.io.IOException, java.text.ParseException, org.xml.sax.SAXException
- Try to find a TEXT parser that can handle the stream, and if found
let it consume it in its entireity.
The stream should be positioned at the start.
getTextMarker
java.lang.String getTextMarker(byte[] sniff_bytes, int length) throws java.io.IOException, java.text.ParseException
- read in the (text-based) marker, skipping any BOM for UTF-16 or UTF-8
writeFileProps
void writeFileProps()
throws java.io.IOException,
org.xml.sax.SAXException
- write file-properties element and children
writeMediaProps
void writeMediaProps()
throws java.io.IOException,
org.xml.sax.SAXException
- produce SAX events for the audio data-oriented metadata
writeMediaDigest
void writeMediaDigest()
throws java.io.IOException,
org.xml.sax.SAXException
writeLog
void writeLog()
throws java.io.IOException,
org.xml.sax.SAXException
write
void write(java.lang.String key, java.lang.String value, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
write
void write(java.lang.String key, java.lang.String value) throws org.xml.sax.SAXException
write
void write(java.lang.String key, long value) throws org.xml.sax.SAXException
write
void write(java.lang.String key, java.util.Date date, boolean date_only) throws org.xml.sax.SAXException
|
|||||||||
| Home >> All >> org >> esau >> ptarmigan >> [ impl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC