Class Exporter
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description protected NamespaceHelper
helper
Namespace helper.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Exporter(Session session, ContentHandler handler, boolean recurse, boolean binary)
Creates an exporter instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 abstractexportNode(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 byexportNode(String, String, Node)
to recursively callexportNode(String, String, Node)
for each child node.protected void
exportProperties(Node node)
Processes all properties of the given node by calling the abstractexportProperty(String, String, Value)
andexportProperty(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 byexportProperties(Node)
to process a multivalued property.protected abstract void
exportProperty(String uri, String local, Value value)
Called byexportProperties(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.
-
-
-
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 sessionhandler
- SAX event handlerrecurse
- whether the export should be recursivebinary
- 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 abstractexportNode(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 occursRepositoryException
- 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 (orjcr: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)
andexportProperties(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 namespacelocal
- node namenode
- node- Throws:
RepositoryException
- if a repository error occursSAXException
- if a SAX error occurs
-
exportProperty
protected abstract void exportProperty(String uri, String local, Value value) throws RepositoryException, SAXException
Called byexportProperties(Node)
to process a single-valued property.- Parameters:
uri
- property namespacelocal
- property namevalue
- property value- Throws:
RepositoryException
- if a repository error occursSAXException
- if a SAX error occurs
-
exportProperty
protected abstract void exportProperty(String uri, String local, int type, Value[] values) throws RepositoryException, SAXException
Called byexportProperties(Node)
to process a multivalued property.- Parameters:
uri
- property namespacelocal
- property nametype
- property typevalues
- property values- Throws:
RepositoryException
- if a repository error occursSAXException
- if a SAX error occurs
-
exportNodes
protected void exportNodes(Node node) throws RepositoryException, SAXException
Called byexportNode(String, String, Node)
to recursively callexportNode(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 occursSAXException
- if a SAX error occurs
-
exportProperties
protected void exportProperties(Node node) throws RepositoryException, SAXException
Processes all properties of the given node by calling the abstractexportProperty(String, String, Value)
andexportProperty(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
, andjcr: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 thejcr:uuid
property of the shareable node are exported.- Parameters:
node
- node- Throws:
RepositoryException
- if a repository error occursSAXException
- if a SAX error occurs- See Also:
- 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 arraystart
- start offset within the arraylength
- 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 attributelocal
- local name of the attributevalue
- 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 usingaddAttribute(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 elementlocal
- local name of the element- Throws:
RepositoryException
- if a repository error occursSAXException
- 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 elementlocal
- local name of the element- Throws:
RepositoryException
- if a repository error occursSAXException
- 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 URIlocal
- 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 hinturi
- namespace URI- Returns:
- registered prefix
-
-