You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2005/05/09 02:16:39 UTC
svn commit: r169200 - in
/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml:
DocumentViewExportVisitor.java SystemViewExportVisitor.java
SystemViewImportContentHandler.java
Author: jukka
Date: Sun May 8 17:16:38 2005
New Revision: 169200
URL: http://svn.apache.org/viewcvs?rev=169200&view=rev
Log:
JCR-EXT: Minor documentation and code style updates.
Modified:
incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/DocumentViewExportVisitor.java
incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewExportVisitor.java
incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewImportContentHandler.java
Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/DocumentViewExportVisitor.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/DocumentViewExportVisitor.java?rev=169200&r1=169199&r2=169200&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/DocumentViewExportVisitor.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/DocumentViewExportVisitor.java Sun May 8 17:16:38 2005
@@ -84,13 +84,13 @@
* <h2>Implementing the standard export methods</h2>
* <p>
* The following is an example of the
- * Session.exportDocView(String, ContentHandler, boolean, boolean)
+ * Session.exportDocumentView(String, ContentHandler, boolean, boolean)
* method implemented in terms of this exporter class:
* <pre>
- * public void exportDocView(String absPath, ContentHandler handler,
- * boolean skipBinary, boolean noRecurse) throws
- * InvalidSerializedDataException, PathNotFoundException,
- * SAXException, RepositoryException {
+ * 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(
@@ -102,32 +102,32 @@
* </pre>
* <p>
* The companion method
- * Session.exportDocView(String, OutputStream, boolean, boolean)
+ * Session.exportDocumentView(String, OutputStream, boolean, boolean)
* can be implemented in terms of the above method and the XMLSerializer
* class from the Xerces library:
* <pre>
* import org.apache.xml.serialize.XMLSerializer;
* import org.apache.xml.serialize.OutputFormat;
*
- * public void exportDocView(String absPath, OutputStream output,
- * boolean skipBinary, boolean noRecurse) throws
- * InvalidSerializedDataException, PathNotFoundException,
- * IOException, RepositoryException {
+ * 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(),
+ * exportDocView(
+ * absPath, serializer.asContentHandler(),
* binaryAsLink, noRecurse);
- * } catch (SAXException ex) {
- * throw new IOException(ex.getMessage());
+ * } catch (SAXException e) {
+ * throw new IOException(e.getMessage());
* }
* }
* </pre>
*
- * @author Jukka Zitting
* @see ItemVisitor
- * @see Session#exportDocView(String, ContentHandler, boolean, boolean)
- * @see Session#exportDocView(String, java.io.OutputStream, boolean, boolean)
+ * @see Session#exportDocumentView(String, ContentHandler, boolean, boolean)
+ * @see Session#exportDocumentView(String, java.io.OutputStream, boolean, boolean)
*/
public class DocumentViewExportVisitor implements ItemVisitor {
@@ -140,17 +140,17 @@
/**
* The SAX content handler for the serialized XML stream.
*/
- private ContentHandler handler;
+ private final ContentHandler handler;
/**
* Flag to skip all binary properties.
*/
- private boolean skipBinary;
+ private final boolean skipBinary;
/**
* Flag to only serialize the selected node.
*/
- private boolean noRecurse;
+ private final boolean noRecurse;
/**
* The root node of the serialization tree. This is the node that
@@ -178,9 +178,11 @@
/**
* Ignored. Properties are included as attributes of node elements.
- * {@inheritDoc}
+ *
+ * @param property ignored property
+ * @see ItemVisitor#visit(Property)
*/
- public void visit(Property property) throws RepositoryException {
+ public void visit(Property property) {
}
/**
@@ -194,6 +196,9 @@
*
* @param node the node to visit
* @throws RepositoryException on repository errors
+ * @see ItemVisitor#visit(Node)
+ * @see #includeProperty(Property)
+ * @see #includeNode(Node)
*/
public void visit(Node node) throws RepositoryException {
try {
@@ -223,8 +228,8 @@
if (root == node) {
handler.endDocument();
}
- } catch (SAXException ex) {
- throw new RepositoryException(ex);
+ } catch (SAXException e) {
+ throw new RepositoryException(e);
}
}
@@ -378,7 +383,7 @@
if (name.length() == 0) {
name = "jcr:root";
}
- return Name.parseJCRName(item.getSession(), name);
+ return Name.fromJCRName(item.getSession(), name);
}
/**
Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewExportVisitor.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewExportVisitor.java?rev=169200&r1=169199&r2=169200&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewExportVisitor.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewExportVisitor.java Sun May 8 17:16:38 2005
@@ -1,12 +1,12 @@
/*
- * Copyright 2005 The Apache Software Foundation or its licensors,
- * as applicable.
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -42,7 +42,7 @@
* export operation is implemented as an ItemVisitor that generates
* the system view SAX event stream as it traverses the selected
* JCR content tree.
- *
+ *
* <h2>Implementing a customized XML serializer</h2>
* <p>
* A client can extend this class to provide customized XML serialization
@@ -57,7 +57,7 @@
* Node parent = ...;
* parent.accept(
* new SystemViewExportVisitor(handler, true, false) {
- *
+ *
* protected boolean includeProperty(Property property)
* throws RepositoryException {
* if (property.getName().equals("title")) {
@@ -66,15 +66,15 @@
* return false;
* }
* }
- *
+ *
* protected boolean includeNode(Node node)
* throws RepositoryException {
* return (node.getDepth() <= root.getDepth() + 2);
* }
- *
+ *
* });
* </pre>
- *
+ *
* <h2>Implementing the standard export methods</h2>
* <p>
* The following is an example of the
@@ -91,7 +91,7 @@
* handler, skipBinary, noRecurse));
* } else {
* throw new PathNotFoundException("Invalid node path: " + path);
- * }
+ * }
* }
* </pre>
* <p>
@@ -102,7 +102,7 @@
* <pre>
* 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,
@@ -117,20 +117,19 @@
* }
* }
* </pre>
- *
- * @author Jukka Zitting
+ *
* @see ItemVisitor
- * @see Session#exportSysView(String, ContentHandler, boolean, boolean)
- * @see Session#exportSysView(String, java.io.OutputStream, boolean, boolean)
+ * @see Session#exportSystemView(String, ContentHandler, boolean, boolean)
+ * @see Session#exportSystemView(String, java.io.OutputStream, boolean, boolean)
*/
public class SystemViewExportVisitor implements ItemVisitor {
/** The system view namespace URI. */
private static final String SV = "http://www.jcp.org/jcr/sv/1.0";
-
+
/** The special jcr:root node name. */
private static final String JCR_ROOT = "jcr:root";
-
+
/** The special jcr:uuid property name. */
private static final String JCR_UUID = "jcr:uuid";
@@ -142,31 +141,31 @@
/** The special sv:node element name. */
private static final String SV_NODE = "sv:node";
-
+
/** Local part of the special sv:node element name. */
private static final String NODE = "node";
-
+
/** The special sv:value element name. */
private static final String SV_VALUE = "sv:value";
-
+
/** Local part of the special sv:value element name. */
private static final String VALUE = "value";
-
+
/** The special sv:property element name. */
private static final String SV_PROPERTY = "sv:property";
-
+
/** Local part of the special sv:property element name. */
private static final String PROPERTY = "property";
/** The special sv:type element name. */
private static final String SV_TYPE = "sv:type";
-
+
/** Local part of the special sv:type element name. */
private static final String TYPE = "type";
-
+
/** The special sv:name element name. */
private static final String SV_NAME = "sv:name";
-
+
/** Local part of the special sv:name element name. */
private static final String NAME = "name";
@@ -174,7 +173,7 @@
* The SAX content handler for the serialized XML stream.
*/
private ContentHandler handler;
-
+
/**
* Flag to skip all binary properties.
*/
@@ -184,7 +183,7 @@
* Flag to only serialize the selected node.
*/
private boolean noRecurse;
-
+
/**
* The root node of the serialization tree. This is the node that
* is mapped to the root element of the serialized XML stream.
@@ -196,9 +195,9 @@
* format. To actually perform the export operation, you need to pass
* the visitor instance to the selected content node using the
* Node.accept(ItemVisitor) method.
- *
+ *
* @param handler the SAX event handler
- * @param skipBinary flag for ignoring binary properties
+ * @param skipBinary flag for ignoring binary properties
* @param noRecurse flag for not exporting an entire content subtree
*/
public SystemViewExportVisitor(
@@ -213,8 +212,8 @@
* Exports the visited property using the system view serialization
* format. This method generates an sv:property element with appropriate
* sv:name and sv:type attributes. The value or values of the node
- * are included as sv:value sub-elements.
- *
+ * are included as sv:value sub-elements.
+ *
* @param property the visited property
* @throws RepositoryException on repository errors
*/
@@ -226,7 +225,7 @@
attributes.addAttribute(SV, TYPE, SV_TYPE,
"CDATA", PropertyType.nameFromValue(property.getType()));
handler.startElement(SV, PROPERTY, SV_PROPERTY, attributes);
-
+
if (property.getDefinition().isMultiple()) {
Value[] values = property.getValues();
for (int i = 0; i < values.length; i++) {
@@ -235,13 +234,13 @@
} else {
exportValue(property.getValue());
}
-
+
handler.endElement(SV, PROPERTY, SV_PROPERTY);
} catch (SAXException ex) {
throw new RepositoryException(ex);
}
}
-
+
/**
* Exports the visited node using the system view serialization format.
* This method is the main entry point to the serialization mechanism.
@@ -249,8 +248,8 @@
* registration of the namespace mappings. The process of actually
* generating the document view SAX events is spread into various
* private methods, and can be controlled by overriding the protected
- * includeProperty() and includeNode() methods.
- *
+ * includeProperty() and includeNode() methods.
+ *
* @param node the node to visit
* @throws RepositoryException on repository errors
*/
@@ -260,7 +259,7 @@
if (root == null) {
root = node;
handler.startDocument();
-
+
Session session = root.getSession();
String[] prefixes = session.getNamespacePrefixes();
for (int i = 0; i < prefixes.length; i++) {
@@ -280,20 +279,20 @@
throw new RepositoryException(ex);
}
}
-
+
/**
* Checks whether the given property should be included in the XML
* serialization. By default this method returns false for the special
* jcr:primaryType, jcr:mixinTypes, and jcr:uuid properties that are
* required by the system view format. This method also returns false
- * for all binary properties if the skipBinary flag is set.
+ * for all binary properties if the skipBinary flag is set.
* Subclasses can extend this default behaviour to implement more
* selective XML serialization.
* <p>
* To avoid losing the default behaviour described above, subclasses
* should always call super.includeProperty(property) instead of
* simply returning true for a property.
- *
+ *
* @param property the property to check
* @return true if the property should be included, false otherwise
* @throws RepositoryException on repository errors
@@ -316,7 +315,7 @@
* 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.
- *
+ *
* @param node the node to check
* @return true if the node should be included, false otherwise
* @throws RepositoryException on repository errors
@@ -324,29 +323,29 @@
protected boolean includeNode(Node node) throws RepositoryException {
return true;
}
-
+
/**
* Serializes the given node to the XML stream. This method generates
* an sv:node element that contains the node name as the sv:name
* attribute. Node properties are included as sv:property elements
* and child nodes as other sv:node sub-elements.
- *
+ *
* @param node the given node
* @throws SAXException on SAX errors
* @throws RepositoryException on repository errors
*/
- private void exportNode(Node node)
+ private void exportNode(Node node)
throws SAXException, RepositoryException {
String name = node.getName();
if (name.length() == 0) {
name = JCR_ROOT;
}
-
+
// Start element
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(SV, NAME, SV_NAME, "CDATA", name);
handler.startElement(SV, NODE, SV_NODE, attributes);
-
+
// Visit the meta-properties
node.getProperty(JCR_PRIMARYTYPE).accept(this);
if (node.hasProperty(JCR_MIXINTYPES)) {
@@ -355,7 +354,7 @@
if (node.hasProperty(JCR_UUID)) {
node.getProperty(JCR_UUID).accept(this);
}
-
+
// Visit other properties
PropertyIterator properties = node.getProperties();
while (properties.hasNext()) {
@@ -364,7 +363,7 @@
property.accept(this);
}
}
-
+
// Visit child nodes (unless denied by the noRecurse flag)
if (!noRecurse) {
NodeIterator children = node.getNodes();
@@ -375,7 +374,7 @@
}
}
}
-
+
// End element
handler.endElement(SV, NODE, SV_NODE);
}
@@ -385,8 +384,8 @@
* an sv:value element and writes the string representation of the
* given value as the character content of the element. Binary values
* are encoded using the Base64 encoding.
- *
- * @param node the given node
+ *
+ * @param value the given value
* @throws SAXException on SAX errors
* @throws RepositoryException on repository errors
*/
@@ -394,7 +393,7 @@
throws SAXException, RepositoryException {
try {
handler.startElement(SV, VALUE, SV_VALUE, new AttributesImpl());
-
+
if (value.getType() != PropertyType.BINARY) {
char[] characters = value.getString().toCharArray();
handler.characters(characters, 0, characters.length);
@@ -403,16 +402,16 @@
encodeValue(value.getStream()).toCharArray();
handler.characters(characters, 0, characters.length);
}
-
+
handler.endElement(SV, VALUE, SV_VALUE);
- } catch (IOException ex) {
- throw new RepositoryException(ex);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
}
}
-
+
/**
* Encodes the given binary stream using Base64 encoding.
- *
+ *
* @param input original binary value
* @return Base64-encoded value
* @throws IOException on IO errors
Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewImportContentHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewImportContentHandler.java?rev=169200&r1=169199&r2=169200&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewImportContentHandler.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/xml/SystemViewImportContentHandler.java Sun May 8 17:16:38 2005
@@ -37,36 +37,36 @@
public class SystemViewImportContentHandler implements ContentHandler {
private Session session;
-
+
private Stack stack;
-
+
private Node node;
-
+
private StringBuffer text;
-
+
private int type;
-
+
private List values;
-
+
public SystemViewImportContentHandler(Node parent) throws RepositoryException {
this.session = parent.getSession();
this.stack = new Stack();
this.node = parent;
this.text = new StringBuffer();
}
-
+
private String getName(String uri, String local, String qname)
throws RepositoryException {
if (uri == null || uri.length() == 0) {
return local;
}
-
+
try {
return session.getNamespacePrefix(uri) + ":" + local;
} catch (NamespaceException ex) {
// fall through
}
-
+
int i = qname.indexOf(':');
String prefix = (i != -1) ? qname.substring(0, i) : "ext";
try {
@@ -82,12 +82,12 @@
.registerNamespace(prefix, uri);
return getName(uri, local, qname);
}
-
+
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
try {
importText();
-
+
stack.push(node);
node = node.addNode(getName(uri, localName, qName));
@@ -154,14 +154,14 @@
/**
* Appends the received characters to the current text buffer.
* The accumulated contents of the text buffer is written to an
- * jcr:xmltext node when an element boundary is reached.
+ * jcr:xmltext node when an element boundary is reached.
* {@inheritDoc}
*/
public void characters(char[] ch, int start, int length)
throws SAXException {
text.append(ch, start, length);
}
-
+
/**
* Imports the accumulated XML character data as an jcr:xmltext node.
* The character data is stored as a jcr:xmlcharacters string property
@@ -169,8 +169,8 @@
* <p>
* This method does nothing if the character data buffer is empty, and
* can therefore be invoked whenever an element boundary is reached to
- * handle the importing of any accumulated character data.
- *
+ * handle the importing of any accumulated character data.
+ *
* @throws RepositoryException
*/
private void importText() throws RepositoryException {
@@ -190,30 +190,27 @@
}
/** Ignored. */
- public void endDocument() throws SAXException {
+ public void endDocument() {
}
/** Ignored. */
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
+ public void startPrefixMapping(String prefix, String uri) {
}
/** Ignored. */
- public void endPrefixMapping(String prefix) throws SAXException {
+ public void endPrefixMapping(String prefix) {
}
-
+
/** Ignored. */
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {
+ public void ignorableWhitespace(char[] ch, int start, int length) {
}
/** Ignored. */
- public void processingInstruction(String target, String data)
- throws SAXException {
+ public void processingInstruction(String target, String data) {
}
/** Ignored. */
- public void skippedEntity(String name) throws SAXException {
+ public void skippedEntity(String name) {
}
}