jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r160189 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: SessionImpl.java WorkspaceImpl.java xml/DocViewImportHandler.java xml/ImportHandler.java xml/SysViewImportHandler.java
Date Tue, 05 Apr 2005 15:58:07 GMT
Author: stefan
Date: Tue Apr  5 08:58:06 2005
New Revision: 160189

URL: http://svn.apache.org/viewcvs?view=rev&rev=160189
Log:
- ImportHandler & specialized friends now rely on default SAX2 Namespace support
- Doc/SysViewImportHandler are now processing ignorableWhitespace events

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&r1=160188&r2=160189
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Tue Apr
 5 08:58:06 2005
@@ -1008,9 +1008,15 @@
 
         ImportHandler handler = (ImportHandler) getImportContentHandler(parentAbsPath);
         try {
-            XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+            XMLReader parser =
+                    XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
             parser.setContentHandler(handler);
             parser.setErrorHandler(handler);
+            // being paranoid...
+            parser.setFeature("http://xml.org/sax/features/namespaces", true);
+            parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
+                    false);
+
             parser.parse(new InputSource(in));
         } catch (SAXException se) {
             // check for wrapped repository exception

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java?view=diff&r1=160188&r2=160189
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java Tue
Apr  5 08:58:06 2005
@@ -1645,6 +1645,11 @@
                     XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
             parser.setContentHandler(handler);
             parser.setErrorHandler(handler);
+            // being paranoid...
+            parser.setFeature("http://xml.org/sax/features/namespaces", true);
+            parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
+                    false);
+
             parser.parse(new InputSource(in));
         } catch (SAXException se) {
             // check for wrapped repository exception

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java?view=diff&r1=160188&r2=160189
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
Tue Apr  5 08:58:06 2005
@@ -17,10 +17,8 @@
 package org.apache.jackrabbit.core.xml;
 
 import org.apache.jackrabbit.core.BaseException;
-import org.apache.jackrabbit.core.IllegalNameException;
 import org.apache.jackrabbit.core.NamespaceResolver;
 import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.UnknownPrefixException;
 import org.apache.jackrabbit.core.util.ISO9075;
 import org.apache.log4j.Logger;
 import org.xml.sax.Attributes;
@@ -30,6 +28,7 @@
 import javax.jcr.RepositoryException;
 import java.util.ArrayList;
 import java.util.Stack;
+import java.io.IOException;
 
 /**
  * <code>DocViewImportHandler</code> processes Document View XML SAX events
@@ -119,18 +118,7 @@
         }
 
         try {
-            QName nodeName;
-            if (namespaceURI != null && !"".equals(namespaceURI)) {
-                nodeName = new QName(namespaceURI, localName);
-            } else {
-                try {
-                    nodeName = QName.fromJCRName(qName, nsContext);
-                } catch (IllegalNameException ine) {
-                    throw new SAXException("illegal node name: " + qName, ine);
-                } catch (UnknownPrefixException upe) {
-                    throw new SAXException("illegal node name: " + qName, upe);
-                }
-            }
+            QName nodeName = new QName(namespaceURI, localName);
             // decode node name
             nodeName = ISO9075.decode(nodeName);
 
@@ -141,20 +129,7 @@
 
             ArrayList props = new ArrayList(atts.getLength());
             for (int i = 0; i < atts.getLength(); i++) {
-                QName propName;
-                if (atts.getURI(i) != null && !"".equals(atts.getURI(i))) {
-                    propName = new QName(atts.getURI(i), atts.getLocalName(i));
-                } else {
-                    try {
-                        propName = QName.fromJCRName(atts.getQName(i), nsContext);
-                    } catch (IllegalNameException ine) {
-                        throw new SAXException("illegal property name: "
-                                + atts.getQName(i), ine);
-                    } catch (UnknownPrefixException upe) {
-                        throw new SAXException("illegal property name: "
-                                + atts.getQName(i), upe);
-                    }
-                }
+                QName propName = new QName(atts.getURI(i), atts.getLocalName(i));
                 // decode property name
                 propName = ISO9075.decode(propName);
 
@@ -224,6 +199,21 @@
         /**
          * buffer character data; will be processed
          * in endElement and startElement method
+         */
+        if (textHandler == null) {
+            textHandler = new StringBufferValue();
+        }
+        textHandler.append(ch, start, length);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void ignorableWhitespace(char ch[], int start, int length)
+            throws SAXException {
+        /**
+         * buffer data reported by the ignorableWhitespace event;
+         * will be processed in endElement and startElement method
          */
         if (textHandler == null) {
             textHandler = new StringBufferValue();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java?view=diff&r1=160188&r2=160189
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
Tue Apr  5 08:58:06 2005
@@ -16,11 +16,9 @@
  */
 package org.apache.jackrabbit.core.xml;
 
-import org.apache.jackrabbit.core.BaseException;
 import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
 import org.apache.jackrabbit.core.NamespaceResolver;
-import org.apache.jackrabbit.core.QName;
 import org.apache.log4j.Logger;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
@@ -35,12 +33,19 @@
 
 /**
  * An <code>ImportHandler</code> instance can be used to import serialized
- * data in System View XML or Document View XML. Processing of the XML is handled
- * by specialized <code>ContentHandler</code>s (i.e. <code>SysViewImportHandler</code>
- * and <code>DocViewImportHandler</code>).
+ * data in System View XML or Document View XML. Processing of the XML is
+ * handled by specialized <code>ContentHandler</code>s
+ * (i.e. <code>SysViewImportHandler</code> and <code>DocViewImportHandler</code>).
  * <p/>
  * The actual task of importing though is delegated to the implementation of
  * the <code>{@link Importer}</code> interface.
+ * <p/>
+ * <b>Important Note:</b>
+ * <p/>
+ * These SAX Event Handlers expect that Namespace URI's and local names are
+ * reported in the <code>start/endElement</code> events and that
+ * <code>start/endPrefixMapping</code> events are reported
+ * (i.e. default SAX2 Namespace processing).
  */
 public class ImportHandler extends DefaultHandler {
 
@@ -213,21 +218,7 @@
         if (!initialized) {
             // the namespace of the first element determines the type of XML
             // (system view/document view)
-            String nsURI;
-            if (namespaceURI != null && !"".equals(namespaceURI)) {
-                nsURI = namespaceURI;
-            } else {
-                try {
-                    nsURI = QName.fromJCRName(qName, nsResolver).getNamespaceURI();
-                } catch (BaseException e) {
-                    // should never happen...
-                    String msg = "internal error: failed to parse/resolve element name "
-                            + qName;
-                    log.debug(msg);
-                    throw new SAXException(msg, e);
-                }
-            }
-            systemViewXML = Constants.NS_SV_URI.equals(nsURI);
+            systemViewXML = Constants.NS_SV_URI.equals(namespaceURI);
 
             if (systemViewXML) {
                 targetHandler = new SysViewImportHandler(importer, nsContext);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java?view=diff&r1=160188&r2=160189
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Tue Apr  5 08:58:06 2005
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.xml;
 
-import org.apache.jackrabbit.core.BaseException;
 import org.apache.jackrabbit.core.IllegalNameException;
 import org.apache.jackrabbit.core.NamespaceResolver;
 import org.apache.jackrabbit.core.QName;
@@ -117,34 +116,19 @@
     public void startElement(String namespaceURI, String localName,
                              String qName, Attributes atts)
             throws SAXException {
-        String elemName;
-        String nsURI;
-        if (namespaceURI != null && !"".equals(namespaceURI)) {
-            nsURI = namespaceURI;
-            elemName = localName;
-        } else {
-            try {
-                nsURI = QName.fromJCRName(qName, nsContext).getNamespaceURI();
-                elemName = QName.fromJCRName(qName, nsContext).getLocalName();
-            } catch (BaseException e) {
-                // should never happen...
-                String msg = "internal error: failed to parse/resolve element name " + qName;
-                log.debug(msg);
-                throw new SAXException(msg, e);
-            }
-        }
         // check namespace
-        if (!NS_SV_URI.equals(nsURI)) {
-            throw new SAXException(new InvalidSerializedDataException("invalid namespace
for element in system view xml document: " + nsURI));
+        if (!NS_SV_URI.equals(namespaceURI)) {
+            throw new SAXException(new InvalidSerializedDataException("invalid namespace
for element in system view xml document: "
+                    + namespaceURI));
         }
         // check element name
-        if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(elemName)) {
+        if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) {
             // sv:node element
 
             // node name (value of sv:name attribute)
             String name = atts.getValue(SysViewSAXEventGenerator.PREFIXED_NAME_ATTRIBUTE);
             if (name == null) {
-                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:name attributeof element sv:node"));
+                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:name attribute of element sv:node"));
             }
 
             if (!stack.isEmpty()) {
@@ -167,7 +151,7 @@
                 throw new SAXException(new InvalidSerializedDataException("illegal node name:
" + name, upe));
             }
             stack.push(state);
-        } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(elemName)) {
+        } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localName)) {
             // sv:property element
 
             // reset temp fields
@@ -176,7 +160,7 @@
             // property name (value of sv:name attribute)
             String name = atts.getValue(SysViewSAXEventGenerator.PREFIXED_NAME_ATTRIBUTE);
             if (name == null) {
-                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:name attributeof element sv:property"));
+                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:name attribute of element sv:property"));
             }
             try {
                 currentPropName = QName.fromJCRName(name, nsContext);
@@ -188,10 +172,10 @@
             // property type (sv:type attribute)
             String type = atts.getValue(SysViewSAXEventGenerator.PREFIXED_TYPE_ATTRIBUTE);
             if (type == null) {
-                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:type attributeof element sv:property"));
+                throw new SAXException(new InvalidSerializedDataException("missing mandatory
sv:type attribute of element sv:property"));
             }
             currentPropType = PropertyType.valueFromName(type);
-        } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(elemName)) {
+        } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName)) {
             // sv:value element
 
             // reset temp fields
@@ -200,15 +184,18 @@
                 try {
                     currentPropValue = new CLOBValue();
                 } catch (IOException ioe) {
-                    throw new SAXException("error while processing property value",
-                            ioe);
+                    String msg = "error while processing property value "
+                            + currentPropName;
+                    log.debug(msg, ioe);
+                    throw new SAXException(msg, ioe);
                 }
             } else {
                 // 'normal' value; use StringBuffer-backed value appender
                 currentPropValue = new StringBufferValue();
             }
         } else {
-            throw new SAXException(new InvalidSerializedDataException("unexpected element
found in system view xml document: " + elemName));
+            throw new SAXException(new InvalidSerializedDataException("unexpected element
found in system view xml document: "
+                    + localName));
         }
     }
 
@@ -231,24 +218,30 @@
     /**
      * {@inheritDoc}
      */
-    public void endElement(String namespaceURI, String localName, String qName)
+    public void ignorableWhitespace(char ch[], int start, int length)
             throws SAXException {
-        String elemName;
-        if (localName != null && !"".equals(localName)) {
-            elemName = localName;
-        } else {
+        if (currentPropValue != null) {
+            // property value
+
+            // data reported by the ignorableWhitespace event within
+            // sv:value tags is considered part of the value
             try {
-                elemName = QName.fromJCRName(qName, nsContext).getLocalName();
-            } catch (BaseException e) {
-                // should never happen...
-                String msg = "internal error: failed to parse/resolve element name " + qName;
-                log.debug(msg);
-                throw new SAXException(msg, e);
+                currentPropValue.append(ch, start, length);
+            } catch (IOException ioe) {
+                throw new SAXException("error while processing property value",
+                        ioe);
             }
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void endElement(String namespaceURI, String localName, String qName)
+            throws SAXException {
         // check element name
         ImportState state = (ImportState) stack.peek();
-        if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(elemName)) {
+        if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) {
             // sv:node element
             if (!state.started) {
                 // need to start & end current node
@@ -260,7 +253,7 @@
             }
             // pop current state from stack
             stack.pop();
-        } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(elemName)) {
+        } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localName)) {
             // sv:property element
 
             // check if all system properties (jcr:primaryType, jcr:uuid etc.)
@@ -283,7 +276,8 @@
                     state.mixinNames = new ArrayList(currentPropValues.size());
                 }
                 for (int i = 0; i < currentPropValues.size(); i++) {
-                    AppendableValue val = (AppendableValue) currentPropValues.get(0);
+                    AppendableValue val =
+                            (AppendableValue) currentPropValues.get(0);
                     String s = null;
                     try {
                         s = val.retrieve();
@@ -314,13 +308,13 @@
             }
             // reset temp fields
             currentPropValues.clear();
-        } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(elemName)) {
+        } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName)) {
             // sv:value element
             currentPropValues.add(currentPropValue);
             // reset temp fields
             currentPropValue = null;
         } else {
-            throw new SAXException(new InvalidSerializedDataException("invalid element in
system view xml document: " + elemName));
+            throw new SAXException(new InvalidSerializedDataException("invalid element in
system view xml document: " + localName));
         }
     }
 



Mime
View raw message