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 2007/02/26 17:30:09 UTC
svn commit: r511877 - in /jackrabbit/branches/1.2:
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/
Author: jukka
Date: Mon Feb 26 08:30:08 2007
New Revision: 511877
URL: http://svn.apache.org/viewvc?view=rev&rev=511877
Log:
1.2: Merged revisions 510905 and 510908 (JCR-762)
Modified:
jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
jackrabbit/branches/1.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/QName.java
Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java?view=diff&rev=511877&r1=511876&r2=511877
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java (original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java Mon Feb 26 08:30:08 2007
@@ -107,17 +107,13 @@
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts)
throws SAXException {
- // check namespace
- if (!QName.NS_SV_URI.equals(namespaceURI)) {
- throw new SAXException(new InvalidSerializedDataException("invalid namespace for element in system view xml document: "
- + namespaceURI));
- }
+ QName name = new QName(namespaceURI, localName);
// check element name
- if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) {
+ if (name.equals(QName.SV_NODE)) {
// sv:node element
// node name (value of sv:name attribute)
- String name = atts.getValue(SysViewSAXEventGenerator.PREFIXED_NAME_ATTRIBUTE);
+ String svName = getAttribute(atts, QName.SV_NAME);
if (name == null) {
throw new SAXException(new InvalidSerializedDataException(
"missing mandatory sv:name attribute of element sv:node"));
@@ -136,47 +132,52 @@
// push new ImportState instance onto the stack
ImportState state = new ImportState();
try {
- state.nodeName = NameFormat.parse(name, nsContext);
+ state.nodeName = NameFormat.parse(svName, nsContext);
} catch (IllegalNameException ine) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, ine));
} catch (UnknownPrefixException upe) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, upe));
}
stack.push(state);
- } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localName)) {
+ } else if (name.equals(QName.SV_PROPERTY)) {
// sv:property element
// reset temp fields
currentPropValues.clear();
// property name (value of sv:name attribute)
- String name = atts.getValue(SysViewSAXEventGenerator.PREFIXED_NAME_ATTRIBUTE);
+ String svName = getAttribute(atts, QName.SV_NAME);
if (name == null) {
throw new SAXException(new InvalidSerializedDataException(
"missing mandatory sv:name attribute of element sv:property"));
}
try {
- currentPropName = NameFormat.parse(name, nsContext);
+ currentPropName = NameFormat.parse(svName, nsContext);
} catch (IllegalNameException ine) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, ine));
} catch (UnknownPrefixException upe) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, upe));
}
// property type (sv:type attribute)
- String type = atts.getValue(SysViewSAXEventGenerator.PREFIXED_TYPE_ATTRIBUTE);
+ String type = getAttribute(atts, QName.SV_TYPE);
if (type == null) {
throw new SAXException(new InvalidSerializedDataException(
"missing mandatory sv:type attribute of element sv:property"));
}
- currentPropType = PropertyType.valueFromName(type);
- } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName)) {
+ try {
+ currentPropType = PropertyType.valueFromName(type);
+ } catch (IllegalArgumentException e) {
+ throw new SAXException(new InvalidSerializedDataException(
+ "Unknown property type: " + type, e));
+ }
+ } else if (name.equals(QName.SV_VALUE)) {
// sv:value element
// reset temp fields
currentPropValue = new BufferedStringValue(nsContext);
} else {
- throw new SAXException(new InvalidSerializedDataException("unexpected element found in system view xml document: "
- + localName));
+ throw new SAXException(new InvalidSerializedDataException(
+ "Unexpected element in system view xml document: " + name));
}
}
@@ -220,9 +221,10 @@
*/
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
+ QName name = new QName(namespaceURI, localName);
// check element name
ImportState state = (ImportState) stack.peek();
- if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) {
+ if (name.equals(QName.SV_NODE)) {
// sv:node element
if (!state.started) {
// need to start & end current node
@@ -234,7 +236,7 @@
}
// pop current state from stack
stack.pop();
- } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localName)) {
+ } else if (name.equals(QName.SV_PROPERTY)) {
// sv:property element
// check if all system properties (jcr:primaryType, jcr:uuid etc.)
@@ -288,7 +290,7 @@
}
// reset temp fields
currentPropValues.clear();
- } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName)) {
+ } else if (name.equals(QName.SV_VALUE)) {
// sv:value element
currentPropValues.add(currentPropValue);
// reset temp fields
@@ -327,4 +329,19 @@
*/
boolean started = false;
}
+
+ //-------------------------------------------------------------< private >
+
+ /**
+ * Returns the value of the named XML attribute.
+ *
+ * @param attributes set of XML attributes
+ * @param name attribute name
+ * @return attribute value,
+ * or <code>null</code> if the named attribute is not found
+ */
+ private static String getAttribute(Attributes attributes, QName name) {
+ return attributes.getValue(name.getNamespaceURI(), name.getLocalName());
+ }
+
}
Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java?view=diff&rev=511877&r1=511876&r2=511877
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java (original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java Mon Feb 26 08:30:08 2007
@@ -16,12 +16,16 @@
*/
package org.apache.jackrabbit.core.xml;
+import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.name.NameFormat;
import org.apache.jackrabbit.name.QName;
import org.apache.jackrabbit.value.ValueHelper;
+import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
@@ -36,29 +40,6 @@
*/
public class SysViewSAXEventGenerator extends AbstractSAXEventGenerator {
- /**
- * The XML elements and attributes used in serialization
- */
- public static final String NODE_ELEMENT = "node";
- public static final String PREFIXED_NODE_ELEMENT =
- QName.NS_SV_PREFIX + ":" + NODE_ELEMENT;
-
- public static final String PROPERTY_ELEMENT = "property";
- public static final String PREFIXED_PROPERTY_ELEMENT =
- QName.NS_SV_PREFIX + ":" + PROPERTY_ELEMENT;;
-
- public static final String VALUE_ELEMENT = "value";
- public static final String PREFIXED_VALUE_ELEMENT =
- QName.NS_SV_PREFIX + ":" + VALUE_ELEMENT;;
-
- public static final String NAME_ATTRIBUTE = "name";
- public static final String PREFIXED_NAME_ATTRIBUTE =
- QName.NS_SV_PREFIX + ":" + NAME_ATTRIBUTE;
-
- public static final String TYPE_ATTRIBUTE = "type";
- public static final String PREFIXED_TYPE_ATTRIBUTE =
- QName.NS_SV_PREFIX + ":" + TYPE_ATTRIBUTE;
-
public static final String CDATA_TYPE = "CDATA";
public static final String ENUMERATION_TYPE = "ENUMERATION";
@@ -97,11 +78,9 @@
nodeName = node.getName();
}
- attrs.addAttribute(QName.NS_SV_URI, NAME_ATTRIBUTE, PREFIXED_NAME_ATTRIBUTE,
- CDATA_TYPE, nodeName);
+ addAttribute(attrs, QName.SV_NAME, CDATA_TYPE, nodeName);
// start node element
- contentHandler.startElement(QName.NS_SV_URI, NODE_ELEMENT,
- PREFIXED_NODE_ELEMENT, attrs);
+ startElement(QName.SV_NODE, attrs);
}
/**
@@ -126,7 +105,7 @@
protected void leaving(Node node, int level)
throws RepositoryException, SAXException {
// end node element
- contentHandler.endElement(QName.NS_SV_URI, NODE_ELEMENT, PREFIXED_NODE_ELEMENT);
+ endElement(QName.SV_NODE);
}
/**
@@ -134,35 +113,27 @@
*/
protected void entering(Property prop, int level)
throws RepositoryException, SAXException {
- String propName = prop.getName();
AttributesImpl attrs = new AttributesImpl();
// name attribute
- attrs.addAttribute(QName.NS_SV_URI, NAME_ATTRIBUTE, PREFIXED_NAME_ATTRIBUTE,
- CDATA_TYPE, propName);
+ addAttribute(attrs, QName.SV_NAME, CDATA_TYPE, prop.getName());
// type attribute
- int type = prop.getType();
- String typeName;
try {
- typeName = PropertyType.nameFromValue(type);
- } catch (IllegalArgumentException iae) {
+ String typeName = PropertyType.nameFromValue(prop.getType());
+ addAttribute(attrs, QName.SV_TYPE, ENUMERATION_TYPE, typeName);
+ } catch (IllegalArgumentException e) {
// should never be getting here
- throw new RepositoryException("unexpected property-type ordinal: "
- + type, iae);
+ throw new RepositoryException(
+ "unexpected property-type ordinal: " + prop.getType(), e);
}
- attrs.addAttribute(QName.NS_SV_URI, TYPE_ATTRIBUTE, PREFIXED_TYPE_ATTRIBUTE,
- ENUMERATION_TYPE, typeName);
// start property element
- contentHandler.startElement(QName.NS_SV_URI, PROPERTY_ELEMENT,
- PREFIXED_PROPERTY_ELEMENT, attrs);
+ startElement(QName.SV_PROPERTY, attrs);
// values
if (prop.getType() == PropertyType.BINARY && skipBinary) {
// empty value element
- contentHandler.startElement(QName.NS_SV_URI, VALUE_ELEMENT,
- PREFIXED_VALUE_ELEMENT, new AttributesImpl());
- contentHandler.endElement(QName.NS_SV_URI, VALUE_ELEMENT,
- PREFIXED_VALUE_ELEMENT);
+ startElement(QName.SV_VALUE, new AttributesImpl());
+ endElement(QName.SV_VALUE);
} else {
boolean multiValued = prop.getDefinition().isMultiple();
Value[] vals;
@@ -175,8 +146,7 @@
Value val = vals[i];
// start value element
- contentHandler.startElement(QName.NS_SV_URI, VALUE_ELEMENT,
- PREFIXED_VALUE_ELEMENT, new AttributesImpl());
+ startElement(QName.SV_VALUE, new AttributesImpl());
// characters
Writer writer = new Writer() {
@@ -210,8 +180,7 @@
}
// end value element
- contentHandler.endElement(QName.NS_SV_URI, VALUE_ELEMENT,
- PREFIXED_VALUE_ELEMENT);
+ endElement(QName.SV_VALUE);
}
}
}
@@ -221,7 +190,69 @@
*/
protected void leaving(Property prop, int level)
throws RepositoryException, SAXException {
- contentHandler.endElement(QName.NS_SV_URI, PROPERTY_ELEMENT,
- PREFIXED_PROPERTY_ELEMENT);
+ endElement(QName.SV_PROPERTY);
}
+
+ //-------------------------------------------------------------< private >
+
+ /**
+ * Adds an attribute to the given XML attribute set. The local part of
+ * the given {@link QName} is assumed to be a valid XML NCName, i.e. it
+ * won't be encoded.
+ *
+ * @param attributes the XML attribute set
+ * @param name name of the attribute
+ * @param type XML type of the attribute
+ * @param value value of the attribute
+ * @throws NamespaceException if the namespace of the attribute is not found
+ */
+ private void addAttribute(
+ AttributesImpl attributes, QName name, String type, String value)
+ throws NamespaceException {
+ try {
+ attributes.addAttribute(
+ name.getNamespaceURI(), name.getLocalName(),
+ NameFormat.format(name, nsResolver), type, value);
+ } catch (NameException e) {
+ throw new NamespaceException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Starts an XML element. The local part of the given {@link QName} is
+ * assumed to be a valid XML NCName, i.e. it won't be encoded.
+ *
+ * @param name name of the element
+ * @param attributes XML attributes
+ * @throws NamespaceException if the namespace of the element is not found
+ */
+ private void startElement(QName name, Attributes attributes)
+ throws NamespaceException, SAXException {
+ try {
+ contentHandler.startElement(
+ name.getNamespaceURI(), name.getLocalName(),
+ NameFormat.format(name, nsResolver), attributes);
+ } catch (NameException e) {
+ throw new NamespaceException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Ends an XML element. The local part of the given {@link QName} is
+ * assumed to be a valid XML NCName, i.e. it won't be encoded.
+ *
+ * @param name name of the element
+ * @throws NamespaceException if the namespace of the element is not found
+ */
+ private void endElement(QName name)
+ throws NamespaceException, SAXException {
+ try {
+ contentHandler.endElement(
+ name.getNamespaceURI(), name.getLocalName(),
+ NameFormat.format(name, nsResolver));
+ } catch (NameException e) {
+ throw new NamespaceException(e.getMessage(), e);
+ }
+ }
+
}
Modified: jackrabbit/branches/1.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/QName.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/QName.java?view=diff&rev=511877&r1=511876&r2=511877
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/QName.java (original)
+++ jackrabbit/branches/1.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/QName.java Mon Feb 26 08:30:08 2007
@@ -498,6 +498,33 @@
*/
public static final QName NT_CHILDNODEDEFINITION = new QName(NS_NT_URI, "childNodeDefinition");
+ //------------------------------------------< system view name constants >
+
+ /**
+ * sv:node
+ */
+ public static final QName SV_NODE = new QName(NS_SV_URI, "node");
+
+ /**
+ * sv:property
+ */
+ public static final QName SV_PROPERTY = new QName(NS_SV_URI, "property");
+
+ /**
+ * sv:value
+ */
+ public static final QName SV_VALUE = new QName(NS_SV_URI, "value");
+
+ /**
+ * sv:type
+ */
+ public static final QName SV_TYPE = new QName(NS_SV_URI, "type");
+
+ /**
+ * sv:name
+ */
+ public static final QName SV_NAME = new QName(NS_SV_URI, "name");
+
/** Serialization UID of this class. */
static final long serialVersionUID = -2712313010017755368L;