jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1345268 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: SessionImpl.java xml/ xml/XmlImportHandler.java
Date Fri, 01 Jun 2012 16:21:09 GMT
Author: jukka
Date: Fri Jun  1 16:21:08 2012
New Revision: 1345268

URL: http://svn.apache.org/viewvc?rev=1345268&view=rev
Log:
OAK-127: Support for XML imports

Initial XML import content handler. WIP...

Added:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1345268&r1=1345267&r2=1345268&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Fri Jun  1 16:21:08 2012
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.api.Jackrab
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.AbstractSession;
+import org.apache.jackrabbit.oak.jcr.xml.XmlImportHandler;
 import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -165,13 +166,10 @@ public class SessionImpl extends Abstrac
 
     @Override
     @Nonnull
-    public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior)
throws RepositoryException {
-        ensureIsAlive();
-
-        @SuppressWarnings("unused")
-        String oakPath = dlg.getOakPathOrThrowNotFound(parentAbsPath);
-
-        throw new UnsupportedRepositoryOperationException("TODO: Session.getImportContentHandler");
+    public ContentHandler getImportContentHandler(
+            String parentAbsPath, int uuidBehavior) throws RepositoryException {
+        final Node parent = getNode(parentAbsPath);
+        return new XmlImportHandler(parent, uuidBehavior);
     }
 
     /**

Added: 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=1345268&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
Fri Jun  1 16:21:08 2012
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class XmlImportHandler extends DefaultHandler {
+
+    private Node node;
+
+    private String name;
+
+    private final List<String> values = new ArrayList<String>();
+
+    private final StringBuilder builder = new StringBuilder();
+
+    public XmlImportHandler(Node parent, int uuidBehavior) {
+        this.node = parent;
+    }
+
+    @Override
+    public void startElement(
+            String uri, String localName, String qName,
+            Attributes atts) throws SAXException {
+        if ("http://www.jcp.org/jcr/sv/1.0".equals(uri)) {
+            String value = atts.getValue("sv:name");
+            if ("node".equals(localName)) {
+                try {
+                    node = node.addNode(value);
+                } catch (RepositoryException e) {
+                    throw new SAXException(e);
+                }
+            } else if (value != null) {
+                name = value;
+            }
+            builder.setLength(0);
+        } else {
+            for (int i = 0; i < atts.getLength(); i++) {
+                try {
+                    node.setProperty(atts.getQName(i), atts.getValue(i));
+                } catch (RepositoryException e) {
+                    throw new SAXException(e);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void endElement(
+            String uri, String localName, String qName)
+            throws SAXException {
+        if (!"http://www.jcp.org/jcr/sv/1.0".equals(uri)) {
+            return;
+        } else if ("value".equals(localName)) {
+            values.add(builder.toString());
+        } else if ("property".equals(localName)) {
+            try {
+                if (values.size() == 1) {
+                    if (name.equals("jcr:primaryType")) {
+                        node.setPrimaryType(values.get(0));
+                    } else {
+                        node.setProperty(name, values.get(0));
+                    }
+                } else {
+                    node.setProperty(name, values.toArray(new String[values.size()]));
+                }
+            } catch (RepositoryException e) {
+                throw new SAXException(e);
+            }
+            values.clear();
+        }
+    }
+
+    @Override
+    public void characters(char[] ch, int offset, int length) {
+        builder.append(ch, offset, length);
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/XmlImportHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message