org.apache.cocoon.transformation
Class XMLDBTransformer

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.transformation.AbstractTransformer
                  extended by org.apache.cocoon.transformation.XMLDBTransformer
All Implemented Interfaces:
Poolable, Recyclable, Initializable, Component, Configurable, LogEnabled, CacheableProcessingComponent, SitemapModelComponent, Transformer, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class XMLDBTransformer
extends AbstractTransformer
implements CacheableProcessingComponent, Configurable, Initializable

This transformer allows to perform resource creation, deletion, and XUpdate command execution in XML:DB. All operations are performed either in base collection, or context collection, which is specified as collection attribute on the query element. Context collection must be specified relative to the base collection.

Definition:

 <map:transformer name="xmldb" src="org.apache.cocoon.transformation.XMLDBTransformer">
   <!-- Optional driver parameter. Uncomment if you want transformer to register a database.
   <driver>org.apache.xindice.client.xmldb.DatabaseImpl</driver>
   -->
   <base>xmldb:xindice:///db/collection</base>
   <user>myDatabaseLogin</user>
   <password>myDatabasePassword</password>
 </map:transformer>
 

The component configuration defined in <map:transformer> can be overriden with sitemap parameters on the <map:transform>:

 <map:transform type="xmldb">
   <map:parameter name="base" value="xmldb:xindice:///db/collection"/>
   <map:parameter name="user" value="myDatabaseLogin"/>
   <map:parameter name="password" value="myDatabasePassword"/>
 </map:transform>
 

Input XML document example:

 <page xmlns:db="http://apache.org/cocoon/xmldb/1.0">
   ...
   <p>Create XML resource in base collection with specified object ID</p>
   <db:query type="create" oid="xmldb-object-id">
     <page>
       XML Object body
     </page>
   </db:query>

   <p>Delete XML resource from the base collection with specified object ID</p>
   <db:query type="delete" oid="xmldb-object-id"/>

   <p>Update XML resource with specified object ID</p>
   <db:query type="update" oid="xmldb-object-id">
     <xu:modifications version="1.0" xmlns:xu="http://www.xmldb.org/xupdate">
       <xu:remove select="/person/phone[@type = 'home']"/>
       <xu:update select="/person/phone[@type = 'work']">
         480-300-3003
       </xu:update>
       </xu:modifications>
   </db:query>

   <p>Create collection nested into the base collection</p>
   <db:query type="create" oid="inner/"/>

   <p>Create XML resource in context collection with specified object ID</p>
   <db:query type="create" collection="inner" oid="xmldb-object-id">
     <page>
       XML Object body
     </page>
   </db:query>
   ...
 </page>
 

Output XML document example:

 <page xmlns:db="http://apache.org/cocoon/xmldb/1.0">
   ...
   <db:query type="create" oid="xmldb-object-id" result="success"/>

   <db:query type="delete" oid="xmldb-object-id" result="success"/>

   <db:query type="update" oid="xmldb-object-id" result="failure">
     Resource xmldb-object-id is not found
   </db:query>
   ...
 </page>
 

Known bugs and limitations:

Version:
$Id: XMLDBTransformer.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
XMLDBTransformer()
           
 
Method Summary
 void characters(char[] c, int start, int len)
          Receive notification of character data.
 void comment(char[] ch, int start, int len)
          Report an XML comment anywhere in the document.
 void configure(Configuration configuration)
           
 void endCDATA()
          Report the end of a CDATA section.
 void endDocument()
          Receive notification of the end of a document.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(String uri, String loc, String raw)
          Receive notification of the end of an element.
 void endEntity(String name)
          Report the end of an entity.
 void endPrefixMapping(String prefix)
          End the scope of a prefix-URI mapping.
 Serializable getKey()
          Generate the unique key.
protected  SAXTransformerFactory getTransformerFactory()
          Helper for TransformerFactory.
 SourceValidity getValidity()
          Generate the validity object.
 void ignorableWhitespace(char[] c, int start, int len)
          Receive notification of ignorable whitespace in element content.
 void initialize()
          Initializes XML:DB database instance if driver class was configured.
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
 void recycle()
          Recycle the producer by removing references, and resetting handlers to null (empty) implementations.
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          Setup the transformer.
 void skippedEntity(String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDocument()
          Receive notification of the beginning of a document.
 void startDTD(String name, String publicId, String systemId)
          Report the start of DTD declarations, if any.
 void startElement(String uri, String loc, String raw, Attributes a)
          Receive notification of the beginning of an element.
 void startEntity(String name)
          Report the beginning of an entity.
 void startPrefixMapping(String prefix, String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
setDocumentLocator
 
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
setDocumentLocator
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Constructor Detail

XMLDBTransformer

public XMLDBTransformer()
Method Detail

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

initialize

public void initialize()
                throws Exception
Initializes XML:DB database instance if driver class was configured.

Specified by:
initialize in interface Initializable
Throws:
Exception

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
Setup the transformer.

Specified by:
setup in interface SitemapModelComponent
Throws:
ProcessingException
SAXException
IOException

getTransformerFactory

protected SAXTransformerFactory getTransformerFactory()
Helper for TransformerFactory.


getKey

public Serializable getKey()
Generate the unique key. This key must be unique inside the space of this component. This method must be invoked before the generateValidity() method.

Specified by:
getKey in interface CacheableProcessingComponent
Returns:
The generated key or null if the component is currently not cacheable.

getValidity

public SourceValidity getValidity()
Generate the validity object. Before this method can be invoked the generateKey() method must be invoked.

Specified by:
getValidity in interface CacheableProcessingComponent
Returns:
The generated validity object or null if the component is currently not cacheable.

startDocument

public void startDocument()
                   throws SAXException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class AbstractXMLPipe
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Receive notification of the end of a document.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class AbstractXMLPipe
Throws:
SAXException

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
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 uri,
                         String loc,
                         String raw,
                         Attributes a)
                  throws SAXException
Receive notification of the beginning of an element.

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

endElement

public void endElement(String uri,
                       String loc,
                       String raw)
                throws SAXException
Receive notification of the end of an element.

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

characters

public void characters(char[] c,
                       int start,
                       int len)
                throws SAXException
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] c,
                                int start,
                                int len)
                         throws SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class AbstractXMLPipe
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Receive notification of a skipped entity.

Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class AbstractXMLPipe
Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Report the start of DTD declarations, if any.

Specified by:
startDTD in interface LexicalHandler
Overrides:
startDTD in class AbstractXMLPipe
Parameters:
name - The document type name.
publicId - The declared public identifier for the external DTD subset, or null if none was declared.
systemId - The declared system identifier for the external DTD subset, or null if none was declared.
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Report the end of DTD declarations.

Specified by:
endDTD in interface LexicalHandler
Overrides:
endDTD in class AbstractXMLPipe
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Report the beginning of an entity.

Specified by:
startEntity in interface LexicalHandler
Overrides:
startEntity in class AbstractXMLPipe
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Report the end of an entity.

Specified by:
endEntity in interface LexicalHandler
Overrides:
endEntity in class AbstractXMLPipe
Parameters:
name - The name of the entity that is ending.
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Report the start of a CDATA section.

Specified by:
startCDATA in interface LexicalHandler
Overrides:
startCDATA in class AbstractXMLPipe
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Report the end of a CDATA section.

Specified by:
endCDATA in interface LexicalHandler
Overrides:
endCDATA in class AbstractXMLPipe
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int len)
             throws SAXException
Report an XML comment anywhere in the document.

Specified by:
comment in interface LexicalHandler
Overrides:
comment in class AbstractXMLPipe
Parameters:
ch - An array holding the characters in the comment.
start - The starting position in the array.
len - The number of characters to use from the array.
Throws:
SAXException

recycle

public void recycle()
Description copied from class: AbstractXMLProducer
Recycle the producer by removing references, and resetting handlers to null (empty) implementations.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractXMLProducer


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