Save This Page
Home » cocoon-2.1.11-src » org.apache » cocoon » transformation » [javadoc | source]
org.apache.cocoon.transformation
public class: XMLDBTransformer [javadoc | source]
java.lang.Object
   org.apache.avalon.framework.logger.AbstractLogEnabled
      org.apache.cocoon.xml.AbstractXMLProducer
         org.apache.cocoon.xml.AbstractXMLPipe
            org.apache.cocoon.transformation.AbstractTransformer
               org.apache.cocoon.transformation.XMLDBTransformer

All Implemented Interfaces:
    CacheableProcessingComponent, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, Transformer, XMLPipe, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer

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:

Fields inherited from org.apache.cocoon.xml.AbstractXMLProducer:
EMPTY_CONTENT_HANDLER,  xmlConsumer,  contentHandler,  lexicalHandler
Constructor:
 public XMLDBTransformer() 
Method from org.apache.cocoon.transformation.XMLDBTransformer Summary:
characters,   comment,   configure,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   getKey,   getTransformerFactory,   getValidity,   ignorableWhitespace,   initialize,   processingInstruction,   recycle,   setup,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startPrefixMapping
Methods from org.apache.cocoon.xml.AbstractXMLPipe:
characters,   comment,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   ignorableWhitespace,   processingInstruction,   setDocumentLocator,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startPrefixMapping
Methods from org.apache.cocoon.xml.AbstractXMLProducer:
recycle,   setConsumer,   setContentHandler,   setLexicalHandler
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.cocoon.transformation.XMLDBTransformer Detail:
 public  void characters(char[] c,
    int start,
    int len) throws SAXException 
    Receive notification of character data.
 public  void comment(char[] ch,
    int start,
    int len) throws SAXException 
    Report an XML comment anywhere in the document.
 public  void configure(Configuration configuration) throws ConfigurationException 
 public  void endCDATA() throws SAXException 
    Report the end of a CDATA section.
 public  void endDTD() throws SAXException 
    Report the end of DTD declarations.
 public  void endDocument() throws SAXException 
    Receive notification of the end of a document.
 public  void endElement(String uri,
    String loc,
    String raw) throws SAXException 
    Receive notification of the end of an element.
 public  void endEntity(String name) throws SAXException 
    Report the end of an entity.
 public  void endPrefixMapping(String prefix) throws SAXException 
    End the scope of a prefix-URI mapping.
 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.
 protected SAXTransformerFactory getTransformerFactory() 
    Helper for TransformerFactory.
 public SourceValidity getValidity() 
    Generate the validity object. Before this method can be invoked the generateKey() method must be invoked.
 public  void ignorableWhitespace(char[] c,
    int start,
    int len) throws SAXException 
    Receive notification of ignorable whitespace in element content.
 public  void initialize() throws Exception 
    Initializes XML:DB database instance if driver class was configured.
 public  void processingInstruction(String target,
    String data) throws SAXException 
    Receive notification of a processing instruction.
 public  void recycle() 
 public  void setup(SourceResolver resolver,
    Map objectModel,
    String src,
    Parameters par) throws IOException, SAXException, ProcessingException 
    Setup the transformer.
 public  void skippedEntity(String name) throws SAXException 
    Receive notification of a skipped entity.
 public  void startCDATA() throws SAXException 
    Report the start of a CDATA section.
 public  void startDTD(String name,
    String publicId,
    String systemId) throws SAXException 
    Report the start of DTD declarations, if any.
 public  void startDocument() throws SAXException 
    Receive notification of the beginning of a document.
 public  void startElement(String uri,
    String loc,
    String raw,
    Attributes a) throws SAXException 
    Receive notification of the beginning of an element.
 public  void startEntity(String name) throws SAXException 
    Report the beginning of an entity.
 public  void startPrefixMapping(String prefix,
    String uri) throws SAXException 
    Begin the scope of a prefix-URI Namespace mapping.