magoffin.matt.ma2.web.service
Class AddMediaContentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by magoffin.matt.ma2.web.service.AddMediaContentHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public final class AddMediaContentHandler
extends org.xml.sax.helpers.DefaultHandler

ContentHandler implementation that splits the XML document into one XML document and one Base64-decoded zip archive from the element.

Low-level SAX is used for parsing here to efficiently parse potentially huge Base64 character streams from large zip archives. StAX is used to copy the SAX events to an XMLStreamWriter.


Constructor Summary
AddMediaContentHandler(java.io.File xmlFile, java.io.File mediaFile, javax.xml.stream.XMLOutputFactory outputFactory)
          Constructor.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
           
 void endPrefixMapping(java.lang.String prefix)
           
 java.lang.Long getCollectionId()
           
 java.lang.String getLocalTz()
           
 java.io.File getMediaFile()
           
 java.lang.String getMediaTz()
           
 java.io.File getXmlFile()
           
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddMediaContentHandler

public AddMediaContentHandler(java.io.File xmlFile,
                              java.io.File mediaFile,
                              javax.xml.stream.XMLOutputFactory outputFactory)
                       throws javax.xml.stream.XMLStreamException,
                              java.io.FileNotFoundException
Constructor.

Parameters:
xmlFile - the file to store the XML metadata document in
mediaFile - the file to store the media binary data in
outputFactory - the OutputFactory to use
Throws:
javax.xml.stream.XMLStreamException - if any XML stream exception occurs
java.io.FileNotFoundException - if either of the files are not found
Method Detail

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String name,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String name)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
endPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws java.io.IOException,
                                             org.xml.sax.SAXException
Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
Throws:
java.io.IOException
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws org.xml.sax.SAXException
Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Overrides:
unparsedEntityDecl in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

getCollectionId

public java.lang.Long getCollectionId()
Returns:
the collectionId

getXmlFile

public java.io.File getXmlFile()
Returns:
the xmlFile

getLocalTz

public java.lang.String getLocalTz()
Returns:
the localTz

getMediaTz

public java.lang.String getMediaTz()
Returns:
the mediaTz

getMediaFile

public java.io.File getMediaFile()
Returns:
the mediaFile