|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jackrabbit.xml.SystemViewExportVisitor
Generic system view exporter for JCR content repositories. This class can be used to implement the XML system view export operations using nothing but the standard JCR interfaces. The export operation is implemented as an ItemVisitor that generates the system 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 SystemViewExportVisitor(handler, true, false) { protected boolean includeProperty(Property property) throws RepositoryException { if (property.getName().equals("title")) { return super.includeProperty(property); } else { return false; } } protected boolean includeNode(Node node) throws RepositoryException { return (node.getDepth() <= root.getDepth() + 2); } });
The following is an example of the Session.exportSysView(String, ContentHandler, boolean, boolean) method implemented in terms of this exporter class:
public void exportSysView(String absPath, ContentHandler handler, boolean skipBinary, boolean noRecurse) throws InvalidSerializedDataException, 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.exportSysView(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 exportSysView(String absPath, OutputStream output, boolean skipBinary, boolean noRecurse) throws InvalidSerializedDataException, PathNotFoundException, IOException, RepositoryException { try { XMLSerializer serializer = new XMLSerializer(output, new OutputFormat()); exportSysView(absPath, serializer.asContentHandler(), binaryAsLink, noRecurse); } catch (SAXException ex) { throw new IOException(ex.getMessage()); } }
ItemVisitor
,
Session.exportSystemView(String, ContentHandler, boolean, boolean)
,
Session.exportSystemView(String, java.io.OutputStream, boolean, boolean)
Field Summary | |
protected Node |
root
The root node of the serialization tree. |
Constructor Summary | |
SystemViewExportVisitor(ContentHandler handler,
boolean skipBinary,
boolean noRecurse)
Creates an visitor for exporting content using the system 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 system view serialization format. |
void |
visit(Property property)
Exports the visited property using the system view serialization format. |
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 SystemViewExportVisitor(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 void visit(Property property) throws RepositoryException
visit
in interface ItemVisitor
property
- the visited property
RepositoryException
- on repository errorspublic void visit(Node node) throws RepositoryException
visit
in interface ItemVisitor
node
- the node to visit
RepositoryException
- on repository errorsprotected boolean includeProperty(Property property) throws RepositoryException
To avoid losing the default behaviour described above, subclasses should always call super.includeProperty(property) instead of simply returning true for a property.
property
- the property to check
RepositoryException
- on repository errorsprotected boolean includeNode(Node node) throws RepositoryException
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 |