jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1408235 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
Date Mon, 12 Nov 2012 09:52:35 GMT
Author: mreutegg
Date: Mon Nov 12 09:52:35 2012
New Revision: 1408235

URL: http://svn.apache.org/viewvc?rev=1408235&view=rev
Log:
OAK-127: Support for XML imports
- jcr:mixinTypes are not set correctly when system view import contains sv:node for jcr:mixinTypes
before sv:node for jcr:primaryType

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java?rev=1408235&r1=1408234&r2=1408235&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
Mon Nov 12 09:52:35 2012
@@ -22,17 +22,23 @@ import java.util.List;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
 public class XmlImportHandler extends DefaultHandler {
 
+    private static final Logger log = LoggerFactory.getLogger(XmlImportHandler.class);
+
     private Node node;
 
     private String nodeName;
 
-    private String name;
+    private String propertyName;
+
+    private final List<String> mixinNames = new ArrayList<String>();
 
     private final List<String> values = new ArrayList<String>();
 
@@ -52,7 +58,7 @@ public class XmlImportHandler extends De
                 // create node on jcr:primaryType sv:property
                 nodeName = value;
             } else if (value != null) {
-                name = value;
+                propertyName = value;
             }
             builder.setLength(0);
         } else {
@@ -77,23 +83,40 @@ public class XmlImportHandler extends De
         } else if ("property".equals(localName)) {
             try {
                 if (values.size() == 1) {
-                    if (name.equals("jcr:primaryType")) {
+                    if (propertyName.equals("jcr:primaryType")) {
                         try {
+                            log.debug(node.getPath() + " adding child " + nodeName + " with
jcr:primaryType " + values.get(0));
                             node = node.addNode(nodeName, values.get(0));
+                            for (String mixin : mixinNames) {
+                                node.addMixin(mixin);
+                            }
+                            mixinNames.clear();
                         } catch (RepositoryException e) {
                             throw new SAXException(e);
                         }
-                    } else if (name.equals("jcr:mixinTypes")) {
-                        node.addMixin(values.get(0));
+                    } else if (propertyName.equals("jcr:mixinTypes")) {
+                        if (node.getName().equals(nodeName)) {
+                            log.debug(node.getPath() + " adding mixinType " + values.get(0));
+                            node.addMixin(values.get(0));
+                        } else {
+                            // remember mixin and add when jcr:primaryType is known
+                            mixinNames.addAll(values);
+                        }
                     } else {
-                        node.setProperty(name, values.get(0));
+                        node.setProperty(propertyName, values.get(0));
                     }
-                } else if (name.equals("jcr:mixinTypes")) {
-                    for (String value : values) {
-                        node.addMixin(value);
+                } else if (propertyName.equals("jcr:mixinTypes")) {
+                    if (node.getName().equals(nodeName)) {
+                        for (String value : values) {
+                            log.debug(node.getPath() + " adding mixinType " + value);
+                            node.addMixin(value);
+                        }
+                    } else {
+                        // remember mixin and add when jcr:primaryType is known
+                        mixinNames.addAll(values);
                     }
                 } else {
-                    node.setProperty(name, values.toArray(new String[values.size()]));
+                    node.setProperty(propertyName, values.toArray(new String[values.size()]));
                 }
             } catch (RepositoryException e) {
                 throw new SAXException(e);
@@ -101,6 +124,11 @@ public class XmlImportHandler extends De
             values.clear();
         } else if ("node".equals(localName)) {
             try {
+                // any mixins we missed?
+                for (String mixin : mixinNames) {
+                    node.addMixin(mixin);
+                }
+                mixinNames.clear();
                 node = node.getParent();
             } catch (RepositoryException e) {
                 throw new SAXException(e);



Mime
View raw message