|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jackrabbit.xml.DocumentViewExportVisitor
Generic document view exporter for JCR content repositories. This class can be used to implement the XML document view export operations using nothing but the standard JCR interfaces. The export operation is implemented as an ItemVisitor that generates the document view SAX event stream as it traverses the selected JCR content tree.
A client can extend this class to provide customized XML serialization formats. By overriding the protected includeProperty() and includeNode() methods, a subclass can select which properties and nodes will be included in the serialized XML stream.
For example, the following code implements an XML serialization that only contains the titles of the first two levels of the node tree.
ContentHandler handler = ...; Node parent = ...; parent.accept( new DocumentViewExportVisitor(handler, true, false) { protected boolean includeProperty(Property property) throws RepositoryException { return property.getName().equals("title"); } protected boolean includeNode(Node node) throws RepositoryException { return (node.getDepth() <= root.getDepth() + 2); } });
The following is an example of the Session.exportDocumentView(String, ContentHandler, boolean, boolean) method implemented in terms of this exporter class:
public void exportDocumentView( String absPath, ContentHandler handler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException { Item item = getItem(absPath); if (item.isNode()) { item.accept(new DocumentViewExportVisitor( handler, skipBinary, noRecurse)); } else { throw new PathNotFoundException("Invalid node path: " + path); } }
The companion method Session.exportDocumentView(String, OutputStream, boolean, boolean) can be implemented in terms of the above method and the XMLSerializer class from the Xerces library:
import org.apache.xml.serialize.XMLSerializer; import org.apache.xml.serialize.OutputFormat; public void exportDocumentView( String absPath, OutputStream output, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, IOException, RepositoryException { try { XMLSerializer serializer = new XMLSerializer(output, new OutputFormat()); exportDocView( absPath, serializer.asContentHandler(), binaryAsLink, noRecurse); } catch (SAXException e) { throw new IOException(e.getMessage()); } }
ItemVisitor
,
Session.exportDocumentView(String, ContentHandler, boolean, boolean)
,
Session.exportDocumentView(String, java.io.OutputStream, boolean, boolean)
Field Summary | |
protected Node |
root
The root node of the serialization tree. |
Constructor Summary | |
DocumentViewExportVisitor(ContentHandler handler,
boolean skipBinary,
boolean noRecurse)
Creates an visitor for exporting content using the document view format. |
Method Summary | |
protected boolean |
includeNode(Node node)
Checks whether the given node should be included in the XML serialization. |
protected boolean |
includeProperty(Property property)
Checks whether the given property should be included in the XML serialization. |
void |
visit(Node node)
Exports the visited node using the document view serialization format. |
void |
visit(Property property)
Ignored. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Node root
Constructor Detail |
public DocumentViewExportVisitor(ContentHandler handler, boolean skipBinary, boolean noRecurse)
handler
- the SAX event handlerskipBinary
- flag for ignoring binary propertiesnoRecurse
- flag for not exporting an entire content subtreeMethod Detail |
public final void visit(Property property)
visit
in interface ItemVisitor
property
- ignored propertyItemVisitor.visit(Property)
public final void visit(Node node) throws RepositoryException
visit
in interface ItemVisitor
node
- the node to visit
RepositoryException
- on repository errorsItemVisitor.visit(Node)
,
includeProperty(Property)
,
includeNode(Node)
protected boolean includeProperty(Property property) throws RepositoryException
true
by default,
but subclasses can override this method to implement more selective
XML serialization.
property
- the property to check
RepositoryException
- on repository errorsprotected boolean includeNode(Node node) throws RepositoryException
true
by default,
but subclasses override this method to implement selective
XML serialization.
Note that this method is only called for the descendants of the root node of the serialized tree. Also, this method is never called if the noRecurse flag is set because no descendant nodes will be serialized anyway.
node
- the node to check
RepositoryException
- on repository errors
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |