org.apache.cocoon.serialization
Class ZipArchiveSerializer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.xml.AbstractXMLPipe
              extended by org.apache.cocoon.serialization.AbstractSerializer
                  extended by org.apache.cocoon.serialization.ZipArchiveSerializer
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, LogEnabled, Serviceable, Serializer, SitemapOutputComponent, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class ZipArchiveSerializer
extends AbstractSerializer
implements Disposable, Serviceable

A serializer that builds Zip archives by aggregating several sources.

The input document should describe entries of the archive by means of their name (which can be a path) and their content either as URLs or inline data :

Example :

   <zip:archive xmlns:zip="http://apache.org/cocoon/zip-archive/1.0">
     <zip:entry name="foo.html" src="cocoon://dynFoo.html"/>
     <zip:entry name="images/bar.jpeg" src="bar.jpeg"/>
     <zip:entry name="index.html" serializer="html">
       <html>
         <head>
           <title>Index page</title>
         </head>
         <body>
           Please go <a href="foo.html">there</a>
         </body<
       </html>
     </zip:entry>
   </zip:archive:zip>
 

Version:
$Id: ZipArchiveSerializer.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Sylvain Wallez

Field Summary
protected  byte[] buffer
          Temporary byte buffer to read source data
protected  int contentDepth
          Current depth of the serialized content
protected  ServiceManager manager
          The component manager
protected  SourceResolver resolver
          The resolver to get sources
protected  ServiceSelector selector
          The serializer component selector
protected  Serializer serializer
          Serializer used when in IN_CONTENT state
protected  int state
          The current state
static String ZIP_NAMESPACE
          The namespace for elements handled by this serializer, "http://apache.org/cocoon/zip-archive/1.0".
protected  ZipOutputStream zipOutput
          The Zip stream where entries will be written
 
Fields inherited from class org.apache.cocoon.serialization.AbstractSerializer
output
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.serialization.Serializer
ROLE
 
Constructor Summary
ZipArchiveSerializer()
           
 
Method Summary
protected  void addEntry(Attributes atts)
          Add an entry in the archive.
 void characters(char[] buffer, int offset, int length)
          Receive notification of character data.
 void dispose()
           
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String namespaceURI, String localName, String qName)
          Receive notification of the end of an element.
 void endPrefixMapping(String prefix)
          End the scope of a prefix-URI mapping.
 String getMimeType()
          Returns default mime type for zip archives, application/zip.
 void recycle()
          Recycle serializer by removing references
 void service(ServiceManager manager)
           
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
          Receive notification of the beginning of an element.
 void startPrefixMapping(String prefix, String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 
Methods inherited from class org.apache.cocoon.serialization.AbstractSerializer
setOutputStream, shouldSetContentLength
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
comment, endCDATA, endDTD, endEntity, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startEntity
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
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.ContentHandler
ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

ZIP_NAMESPACE

public static final String ZIP_NAMESPACE
The namespace for elements handled by this serializer, "http://apache.org/cocoon/zip-archive/1.0".

See Also:
Constant Field Values

manager

protected ServiceManager manager
The component manager


selector

protected ServiceSelector selector
The serializer component selector


zipOutput

protected ZipOutputStream zipOutput
The Zip stream where entries will be written


state

protected int state
The current state


resolver

protected SourceResolver resolver
The resolver to get sources


buffer

protected byte[] buffer
Temporary byte buffer to read source data


serializer

protected Serializer serializer
Serializer used when in IN_CONTENT state


contentDepth

protected int contentDepth
Current depth of the serialized content

Constructor Detail

ZipArchiveSerializer

public ZipArchiveSerializer()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(ServiceManager)

getMimeType

public String getMimeType()
Returns default mime type for zip archives, application/zip. Can be overridden in the sitemap.

Specified by:
getMimeType in interface SitemapOutputComponent
Overrides:
getMimeType in class AbstractSerializer
Returns:
application/zip
See Also:
AbstractProcessingPipeline.setMimeTypeForSerializer(org.apache.cocoon.environment.Environment), AbstractProcessingPipeline.setMimeTypeForReader(org.apache.cocoon.environment.Environment)

startDocument

public void startDocument()
                   throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class AbstractXMLPipe
Throws:
SAXException
See Also:
ContentHandler.startDocument()

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Begin the scope of a prefix-URI Namespace mapping.

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class AbstractXMLPipe
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Description copied from class: AbstractXMLPipe
End the scope of a prefix-URI mapping.

Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class AbstractXMLPipe
Parameters:
prefix - The prefix that was being mapping.
Throws:
SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException
See Also:
ContentHandler.startElement(String, String, String, Attributes)

characters

public void characters(char[] buffer,
                       int offset,
                       int length)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
buffer - The characters from the XML document.
offset - The start position in the array.
length - The number of characters to read from the array.
Throws:
SAXException
See Also:
ContentHandler.characters(char[], int, int)

addEntry

protected void addEntry(Attributes atts)
                 throws SAXException
Add an entry in the archive.

Parameters:
atts - the attributes that describe the entry
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException
See Also:
ContentHandler.endElement(String, String, String)

endDocument

public void endDocument()
                 throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of a document.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class AbstractXMLPipe
Throws:
SAXException
See Also:
ContentHandler.endDocument()

recycle

public void recycle()
Description copied from class: AbstractSerializer
Recycle serializer by removing references

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractSerializer
See Also:
Recyclable.recycle()

dispose

public void dispose()
Specified by:
dispose in interface Disposable


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.