jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r523372 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
Date Wed, 28 Mar 2007 15:34:46 GMT
Author: stefan
Date: Wed Mar 28 08:34:45 2007
New Revision: 523372

URL: http://svn.apache.org/viewvc?view=rev&rev=523372
Log:
JCR-821: Document View Import: ISO 9075-encoded element/attribute names may lead to illegal
node/property names

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java?view=diff&rev=523372&r1=523371&r2=523372
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
Wed Mar 28 08:34:45 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.name.NameException;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.IllegalNameException;
 import org.apache.jackrabbit.util.ISO9075;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,6 +61,29 @@
     }
 
     /**
+     * Parses the given string as a list of JCR names. Any whitespace sequence
+     * is supported as a names separator instead of just a single space to
+     * be more liberal in what we accept. The current namespace context is
+     * used to convert the prefixed name strings to QNames.
+     *
+     * @param value string value
+     * @return the parsed names
+     * @throws SAXException if an invalid name was encountered
+     */
+    private QName[] parseNames(String value) throws SAXException {
+        String[] names = value.split("\\p{Space}+");
+        QName[] qnames = new QName[names.length];
+        for (int i = 0; i < names.length; i++) {
+            try {
+                qnames[i] = NameFormat.parse(names[i], nsContext);
+            } catch (NameException ne) {
+                throw new SAXException("Invalid name: " + names[i], ne);
+            }
+        }
+        return qnames;
+    }
+
+    /**
      * Appends the given character data to the internal buffer.
      *
      * @param ch     the characters to be appended
@@ -147,6 +171,34 @@
         }
     }
 
+    /**
+     * Processes the given <code>name</code>, i.e. decodes it and checks
+     * the format of the decoded name.
+     *
+     * @param name name to process
+     * @return the decoded and valid jcr name or the original name if it is
+     *         not encoded or if the resulting decoded name would be illegal.
+     */
+    private QName processName(QName name) {
+        QName decoded = ISO9075.decode(name);
+        if (decoded != name) {
+            // only need to check format of decoded name since
+            // an xml name is always a legal jcr name
+            // (http://issues.apache.org/jira/browse/JCR-821)
+            try {
+                NameFormat.checkFormat(decoded.getLocalName());
+                return decoded;
+            } catch (IllegalNameException ine) {
+                // decoded name would be illegal according to jsr 170,
+                // use encoded name as a fallback
+                log.warn("encountered illegal encoded name '"
+                        + name.getLocalName() + "': "
+                        + ine.getMessage());
+            }
+        }
+        return name;
+    }
+
     //-------------------------------------------------------< ContentHandler >
 
     /**
@@ -163,8 +215,8 @@
 
         try {
             QName nodeName = new QName(namespaceURI, localName);
-            // decode node name
-            nodeName = ISO9075.decode(nodeName);
+            // process node name
+            nodeName = processName(nodeName);
 
             // properties
             NodeId id = null;
@@ -179,8 +231,8 @@
                     continue;
                 }
                 QName propName = new QName(atts.getURI(i), atts.getLocalName(i));
-                // decode property name
-                propName = ISO9075.decode(propName);
+                // process property name
+                propName = processName(propName);
 
                 // value(s)
                 String attrValue = atts.getValue(i);
@@ -227,29 +279,6 @@
         } catch (RepositoryException re) {
             throw new SAXException(re);
         }
-    }
-
-    /**
-     * Parses the given string as a list of JCR names. Any whitespace sequence
-     * is supported as a names separator instead of just a single space to
-     * be more liberal in what we accept. The current namespace context is
-     * used to convert the prefixed name strings to QNames.
-     *
-     * @param value string value
-     * @return the parsed names
-     * @throws SAXException if an invalid name was encountered
-     */
-    private QName[] parseNames(String value) throws SAXException {
-        String[] names = value.split("\\p{Space}+");
-        QName[] qnames = new QName[names.length];
-        for (int i = 0; i < names.length; i++) {
-            try {
-                qnames[i] = NameFormat.parse(names[i], nsContext);
-            } catch (NameException ne) {
-                throw new SAXException("Invalid name: " + names[i], ne);
-            }
-        }
-        return qnames;
     }
 
     /**



Mime
View raw message