org.apache.cocoon.serialization
Class ZipArchiveSerializer

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.xml.AbstractXMLPipe
              extended byorg.apache.cocoon.serialization.AbstractSerializer
                  extended byorg.apache.cocoon.serialization.ZipArchiveSerializer
All Implemented Interfaces:
ContentHandler, Disposable, LexicalHandler, Poolable, Recyclable, org.apache.cocoon.serialization.Serializer, Serviceable, org.apache.cocoon.sitemap.SitemapOutputComponent, XMLConsumer, org.apache.cocoon.xml.XMLConsumer, org.apache.cocoon.xml.XMLPipe, org.apache.cocoon.xml.XMLProducer

public class ZipArchiveSerializer
extends org.apache.cocoon.serialization.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 1304280 2012-03-23 11:18:01Z ilgrosso $

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  org.apache.cocoon.serialization.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)
           
 void dispose()
           
 void endDocument()
           
 void endElement(String namespaceURI, String localName, String qName)
           
 void endPrefixMapping(String prefix)
           
 String getMimeType()
          Returns default mime type for zip archives, application/zip.
 void recycle()
           
 void service(ServiceManager manager)
           
 void startDocument()
           
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
           
 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.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
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 org.apache.cocoon.serialization.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 org.apache.cocoon.sitemap.SitemapOutputComponent
Returns:
application/zip

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
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
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
Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Throws:
SAXException
See Also:
ContentHandler.startElement(String, String, String, Attributes)

characters

public void characters(char[] buffer,
                       int offset,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
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
Specified by:
endElement in interface ContentHandler
Throws:
SAXException
See Also:
ContentHandler.endElement(String, String, String)

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Throws:
SAXException
See Also:
ContentHandler.endDocument()

recycle

public void recycle()
Specified by:
recycle in interface Recyclable
See Also:
Recyclable.recycle()

dispose

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


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.