org.apache.jackrabbit.commons.xml
Class Exporter

java.lang.Object
  extended by org.apache.jackrabbit.commons.xml.Exporter
Direct Known Subclasses:
DocumentViewExporter, SystemViewExporter

public abstract class Exporter
extends Object

Abstract base class for document and system view exporters. This class takes care of all the details related to namespace mappings, shareable nodes, recursive exports, binary values, and so on while leaving the decisions about what kind of SAX events to generate to subclasses.

A subclass should only need to implement the abstract methods of this class to produce a fully functional exporter.

Since:
Jackrabbit JCR Commons 1.5

Field Summary
protected  NamespaceHelper helper
          Namespace helper.
 
Constructor Summary
protected Exporter(Session session, ContentHandler handler, boolean recurse, boolean binary)
          Creates an exporter instance.
 
Method Summary
protected  void addAttribute(String uri, String local, String value)
          Adds the given attribute to be included in the next element.
protected  String addNamespace(String hint, String uri)
          Adds the given namespace to the export.
protected  void characters(char[] ch, int start, int length)
          Emits a characters event with the given character content.
protected  void endElement(String uri, String local)
          Emits the end element event for an element with the given name.
 void export(Node node)
          Exports the given node by preparing the export and calling the abstract exportNode(String, String, Node) method to give control of the export format to a subclass.
protected abstract  void exportNode(String uri, String local, Node node)
          Called to export the given node.
protected  void exportNodes(Node node)
          Called by exportNode(String, String, Node) to recursively call exportNode(String, String, Node) for each child node.
protected  void exportProperties(Node node)
          Processes all properties of the given node by calling the abstract exportProperty(String, String, Value) and exportProperty(String, String, int, Value[]) methods for each property depending on whether the property is single- or multivalued.
protected abstract  void exportProperty(String uri, String local, int type, Value[] values)
          Called by exportProperties(Node) to process a multivalued property.
protected abstract  void exportProperty(String uri, String local, Value value)
          Called by exportProperties(Node) to process a single-valued property.
protected  String getXMLName(String uri, String local)
          Returns a prefixed XML name for the given namespace URI and local name.
protected  void startElement(String uri, String local)
          Emits the start element event for an element with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

helper

protected final NamespaceHelper helper
Namespace helper.

Constructor Detail

Exporter

protected Exporter(Session session,
                   ContentHandler handler,
                   boolean recurse,
                   boolean binary)
Creates an exporter instance.

Parameters:
session - current session
handler - SAX event handler
recurse - whether the export should be recursive
binary - whether the export should include binary values
Method Detail

export

public void export(Node node)
            throws RepositoryException,
                   SAXException
Exports the given node by preparing the export and calling the abstract exportNode(String, String, Node) method to give control of the export format to a subclass.

This method should be called only once for an exporter instance.

Parameters:
node - node to be exported
Throws:
SAXException - if a SAX error occurs
RepositoryException - if a repository error occurs

exportNode

protected abstract void exportNode(String uri,
                                   String local,
                                   Node node)
                            throws RepositoryException,
                                   SAXException
Called to export the given node. The node name (or jcr:root if the node is the root node) is given as an explicit pair of the resolved namespace URI and local part of the name.

The implementation of this method should call the methods exportProperties(Node) and exportProperties(Node) to respectively export the properties and child nodes of the given node. Those methods will call back to the implementations of this method and the abstract property export methods so the subclass can decide what SAX events to emit for each exported item.

Parameters:
uri - node namespace
local - node name
node - node
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

exportProperty

protected abstract void exportProperty(String uri,
                                       String local,
                                       Value value)
                                throws RepositoryException,
                                       SAXException
Called by exportProperties(Node) to process a single-valued property.

Parameters:
uri - property namespace
local - property name
value - property value
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

exportProperty

protected abstract void exportProperty(String uri,
                                       String local,
                                       int type,
                                       Value[] values)
                                throws RepositoryException,
                                       SAXException
Called by exportProperties(Node) to process a multivalued property.

Parameters:
uri - property namespace
local - property name
type - property type
values - property values
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

exportNodes

protected void exportNodes(Node node)
                    throws RepositoryException,
                           SAXException
Called by exportNode(String, String, Node) to recursively call exportNode(String, String, Node) for each child node. Does nothing if this exporter is not recursive.

Parameters:
node - parent node
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

exportProperties

protected void exportProperties(Node node)
                         throws RepositoryException,
                                SAXException
Processes all properties of the given node by calling the abstract exportProperty(String, String, Value) and exportProperty(String, String, int, Value[]) methods for each property depending on whether the property is single- or multivalued.

The first properties to be processed are jcr:primaryType, jcr:mixinTypes, and jcr:uuid, and then the remaining properties ordered by their names.

If the node is a shareable node that has already been encountered by this event generator, then only a jcr:primaryType property with the fixed value "nt:share" and the jcr:uuid property of the shareable node are exported.

Parameters:
node - node
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs
See Also:
https://issues.apache.org/jira/browse/JCR-1084

characters

protected void characters(char[] ch,
                          int start,
                          int length)
                   throws SAXException
Emits a characters event with the given character content.

Parameters:
ch - character array
start - start offset within the array
length - number of characters to emit
Throws:
SAXException - if a SAX error occurs

addAttribute

protected void addAttribute(String uri,
                            String local,
                            String value)
                     throws RepositoryException
Adds the given attribute to be included in the next element.

Parameters:
uri - namespace URI of the attribute
local - local name of the attribute
value - attribute value
Throws:
RepositoryException - if a repository error occurs

startElement

protected void startElement(String uri,
                            String local)
                     throws SAXException,
                            RepositoryException
Emits the start element event for an element with the given name. All the attributes added using addAttribute(String, String, String) are included in the element along with any new namespace mappings. The namespace stack is extended for potential child elements.

Parameters:
uri - namespace URI or the element
local - local name of the element
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

endElement

protected void endElement(String uri,
                          String local)
                   throws SAXException,
                          RepositoryException
Emits the end element event for an element with the given name. The namespace stack and mappings are automatically updated.

Parameters:
uri - namespace URI or the element
local - local name of the element
Throws:
RepositoryException - if a repository error occurs
SAXException - if a SAX error occurs

getXMLName

protected String getXMLName(String uri,
                            String local)
                     throws RepositoryException
Returns a prefixed XML name for the given namespace URI and local name. If a prefix mapping for the namespace URI is not yet available, it is created based on the namespace mappings of the current JCR session.

Parameters:
uri - namespace URI
local - local name
Returns:
prefixed XML name
Throws:
RepositoryException - if a JCR namespace mapping is not available

addNamespace

protected String addNamespace(String hint,
                              String uri)
Adds the given namespace to the export. A unique prefix based on the given prefix hint is mapped to the given namespace URI. If the namespace is already mapped, then the existing prefix is returned.

Parameters:
hint - prefix hint
uri - namespace URI
Returns:
registered prefix


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