jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r599366 - in /jackrabbit/trunk/jackrabbit-jcr2spi/src: main/java/org/apache/jackrabbit/jcr2spi/ main/java/org/apache/jackrabbit/jcr2spi/xml/ test/java/org/apache/jackrabbit/jcr2spi/xml/
Date Thu, 29 Nov 2007 10:26:51 GMT
Author: angela
Date: Thu Nov 29 02:26:50 2007
New Revision: 599366

URL: http://svn.apache.org/viewvc?rev=599366&view=rev
Log:
JCR-1245: JCR2SPI: Use namespace decl. present in imported xml to resolve Name/Path values

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/DocViewImportHandler.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImportHandler.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/TargetImportHandler.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Thu Nov 29 02:26:50 2007
@@ -380,7 +380,7 @@
         // NOTE: check if path corresponds to Node and is writable is performed
         // within the SessionImporter.
         Importer importer = new SessionImporter(parentPath, this, itemStateManager, uuidBehavior);
-        return new ImportHandler(importer, getNamespaceResolver(), workspace.getNamespaceRegistry(),
getNameFactory());
+        return new ImportHandler(importer, getNamespaceResolver(), workspace.getNamespaceRegistry(),
getNameFactory(), getPathFactory());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/DocViewImportHandler.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/DocViewImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/DocViewImportHandler.java
Thu Nov 29 02:26:50 2007
@@ -16,9 +16,9 @@
  */
 package org.apache.jackrabbit.jcr2spi.xml;
 
-import org.apache.jackrabbit.conversion.NameResolver;
+import org.apache.jackrabbit.conversion.NameException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 import org.apache.jackrabbit.name.NameConstants;
-import org.apache.jackrabbit.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.util.ISO9075;
@@ -59,9 +59,9 @@
      * @param importer
      * @param nsContext
      */
-    DocViewImportHandler(Importer importer, NamespaceResolver nsContext,
-                         NameResolver nameResolver, NameFactory nameFactory) {
-        super(importer, nsContext, nameResolver);
+    DocViewImportHandler(Importer importer, NamePathResolver resolver,
+                         NameFactory nameFactory) {
+        super(importer, resolver);
         this.nameFactory = nameFactory;
     }
 
@@ -137,7 +137,7 @@
                         new Importer.PropInfo(NameConstants.JCR_XMLCHARACTERS, PropertyType.STRING,
values);
                 props.add(prop);
                 // call Importer
-                importer.startNode(node, props, nsContext);
+                importer.startNode(node, props, resolver);
                 importer.endNode(node);
 
                 // reset handler
@@ -193,8 +193,8 @@
                     // jcr:primaryType
                     if (attrValue.length() > 0) {
                         try {
-                            nodeTypeName = nameResolver.getQName(attrValue);
-                        } catch (org.apache.jackrabbit.conversion.NameException ne) {
+                            nodeTypeName = resolver.getQName(attrValue);
+                        } catch (NameException ne) {
                             throw new SAXException("illegal jcr:primaryType value: "
                                     + attrValue, ne);
                         }
@@ -221,7 +221,7 @@
 
             Importer.NodeInfo node = new Importer.NodeInfo(nodeName, nodeTypeName, mixinTypes,
uuid);
             // all information has been collected, now delegate to importer
-            importer.startNode(node, props, nsContext);
+            importer.startNode(node, props, resolver);
             // push current node data onto stack
             stack.push(node);
         } catch (RepositoryException re) {
@@ -244,8 +244,8 @@
         Name[] qnames = new Name[names.length];
         for (int i = 0; i < names.length; i++) {
             try {
-                qnames[i] = nameResolver.getQName(names[i]);
-            } catch (org.apache.jackrabbit.conversion.NameException ne) {
+                qnames[i] = resolver.getQName(names[i]);
+            } catch (NameException ne) {
                 throw new SAXException("Invalid name: " + names[i], ne);
             } catch (NamespaceException e) {
                 throw new SAXException("Invalid name: " + names[i], e);

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImportHandler.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImportHandler.java
Thu Nov 29 02:26:50 2007
@@ -18,10 +18,14 @@
 
 import org.apache.jackrabbit.conversion.NameResolver;
 import org.apache.jackrabbit.conversion.ParsingNameResolver;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.conversion.ParsingPathResolver;
 import org.apache.jackrabbit.namespace.AbstractNamespaceResolver;
 import org.apache.jackrabbit.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.PathFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.Attributes;
@@ -65,7 +69,7 @@
     private boolean initialized;
 
     private final NamespaceContext nsContext;
-    private final NameResolver nameResolver;
+    private final NamePathResolver resolver;
 
     /**
      * this flag is used to determine whether a namespace context needs to be
@@ -77,14 +81,16 @@
     protected boolean nsContextStarted;
 
     public ImportHandler(Importer importer, NamespaceResolver nsResolver,
-                         NamespaceRegistry nsReg, NameFactory nameFactory) {
+                         NamespaceRegistry nsReg, NameFactory nameFactory,
+                         PathFactory pathFactory) {
         this.importer = importer;
         this.nsResolver = nsResolver;
         this.nsReg = nsReg;
         this.nameFactory = nameFactory;
 
         nsContext = new NamespaceContext();
-        nameResolver = new ParsingNameResolver(nameFactory, nsContext);
+        NameResolver nr = new ParsingNameResolver(nameFactory, nsContext);
+        resolver = new DefaultNamePathResolver(nr, new ParsingPathResolver(pathFactory, nr));
     }
 
     //---------------------------------------------------------< ErrorHandler >
@@ -228,9 +234,9 @@
             systemViewXML = Name.NS_SV_URI.equals(namespaceURI);
 
             if (systemViewXML) {
-                targetHandler = new SysViewImportHandler(importer, nsContext, nameResolver);
+                targetHandler = new SysViewImportHandler(importer, resolver);
             } else {
-                targetHandler = new DocViewImportHandler(importer, nsContext, nameResolver,
nameFactory);
+                targetHandler = new DocViewImportHandler(importer, resolver, nameFactory);
             }
             targetHandler.startDocument();
             initialized = true;

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java
Thu Nov 29 02:26:50 2007
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.jcr2spi.xml;
 
-import org.apache.jackrabbit.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 
 import javax.jcr.RepositoryException;
 import java.io.IOException;
@@ -37,10 +37,11 @@
     /**
      * @param nodeInfo
      * @param propInfos list of <code>PropInfo</code> instances
-     * @param nsContext prefix mappings of current context
+     * @param resolver NamePathResolver dealing with prefix mappings of current
+     * context.
      * @throws RepositoryException
      */
-    void startNode(NodeInfo nodeInfo, List propInfos, NamespaceResolver nsContext)
+    void startNode(NodeInfo nodeInfo, List propInfos, NamePathResolver resolver)
             throws RepositoryException;
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
Thu Nov 29 02:26:50 2007
@@ -38,7 +38,6 @@
 import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.name.NameConstants;
-import org.apache.jackrabbit.namespace.NamespaceResolver;
 import org.apache.jackrabbit.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
@@ -51,6 +50,7 @@
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.value.ValueFormat;
 import org.apache.jackrabbit.value.ValueHelper;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -157,7 +157,7 @@
    /**
      * {@inheritDoc}
      */
-    public void startNode(NodeInfo nodeInfo, List propInfos, NamespaceResolver nsContext)
+    public void startNode(NodeInfo nodeInfo, List propInfos, NamePathResolver resolver)
             throws RepositoryException {
        if (isClosed()) {
            // workspace-importer only: ignore if import has been aborted before.
@@ -235,7 +235,7 @@
            Iterator iter = propInfos.iterator();
            while (iter.hasNext()) {
                PropInfo pi = (PropInfo) iter.next();
-               importProperty(pi, nodeState, nsContext);
+               importProperty(pi, nodeState, resolver);
            }
        }
 
@@ -477,7 +477,7 @@
      * @throws RepositoryException
      * @throws ConstraintViolationException
      */
-    private void importProperty(PropInfo pi, NodeState parentState, org.apache.jackrabbit.namespace.NamespaceResolver
nsResolver) throws RepositoryException, ConstraintViolationException {
+    private void importProperty(PropInfo pi, NodeState parentState, NamePathResolver resolver)
throws RepositoryException, ConstraintViolationException {
         Name propName = pi.getName();
         TextValue[] tva = pi.getValues();
         int infoType = pi.getType();
@@ -539,7 +539,7 @@
             }
         }
 
-        QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), nsResolver);
+        QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), resolver);
         if (propState == null) {
             // create new property
             Operation ap = AddProperty.create(parentState, propName, targetType, def, values);
@@ -566,7 +566,7 @@
      * @return
      * @throws RepositoryException
      */
-    private QValue[] getPropertyValues(PropInfo propertyInfo, int targetType, boolean isMultiple,
org.apache.jackrabbit.namespace.NamespaceResolver nsResolver) throws RepositoryException {
+    private QValue[] getPropertyValues(PropInfo propertyInfo, int targetType, boolean isMultiple,
NamePathResolver resolver) throws RepositoryException {
         TextValue[] tva = propertyInfo.getValues();
         // check multi-valued characteristic
         if ((tva.length == 0 || tva.length > 1) && !isMultiple) {
@@ -575,7 +575,7 @@
         // convert serialized values to QValue objects
         QValue[] iva = new QValue[tva.length];
         for (int i = 0; i < tva.length; i++) {
-            iva[i] = buildQValue(tva[i], targetType, nsResolver);
+            iva[i] = buildQValue(tva[i], targetType, resolver);
         }
         return iva;
     }
@@ -588,7 +588,7 @@
      * @return
      * @throws RepositoryException
      */
-    private QValue buildQValue(TextValue tv, int targetType, org.apache.jackrabbit.namespace.NamespaceResolver
nsResolver) throws RepositoryException {
+    private QValue buildQValue(TextValue tv, int targetType, NamePathResolver resolver) throws
RepositoryException {
         QValue iv;
         try {
             switch (targetType) {
@@ -620,7 +620,7 @@
                 default:
                     // build iv using namespace context of xml document
                     Value v = ValueHelper.convert(tv.retrieve(), targetType, session.getValueFactory());
-                    iv = ValueFormat.getQValue(v, session.getNamePathResolver(), session.getQValueFactory());
+                    iv = ValueFormat.getQValue(v, resolver, session.getQValueFactory());
                     break;
             }
             return iv;

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
Thu Nov 29 02:26:50 2007
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.jcr2spi.xml;
 
 import org.apache.jackrabbit.conversion.NameException;
-import org.apache.jackrabbit.conversion.NameResolver;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 import org.apache.jackrabbit.name.NameConstants;
 import org.apache.jackrabbit.spi.Name;
 import org.xml.sax.Attributes;
@@ -60,8 +60,8 @@
      * @param importer
      * @param nsContext
      */
-    SysViewImportHandler(Importer importer, org.apache.jackrabbit.namespace.NamespaceResolver
nsContext, NameResolver nameResolver) {
-        super(importer, nsContext, nameResolver);
+    SysViewImportHandler(Importer importer, NamePathResolver resolver) {
+        super(importer, resolver);
     }
 
     private void processNode(ImportState state, boolean start, boolean end)
@@ -81,7 +81,7 @@
         // call Importer
         try {
             if (start) {
-                importer.startNode(nodeInfo, state.props, nsContext);
+                importer.startNode(nodeInfo, state.props, resolver);
                 // dispose temporary property values
                 for (Iterator iter = state.props.iterator(); iter.hasNext();) {
                     Importer.PropInfo pi = (Importer.PropInfo) iter.next();
@@ -132,7 +132,7 @@
             // push new ImportState instance onto the stack
             ImportState state = new ImportState();
             try {
-                state.nodeName = nameResolver.getQName(name);
+                state.nodeName = resolver.getQName(name);
             } catch (NameException e) {
                 throw new SAXException(new InvalidSerializedDataException("illegal node name:
" + name, e));
             } catch (NamespaceException e) {
@@ -152,8 +152,8 @@
                         "missing mandatory sv:name attribute of element sv:property"));
             }
             try {
-                currentPropName = nameResolver.getQName(name);
-            } catch (org.apache.jackrabbit.conversion.NameException e) {
+                currentPropName = resolver.getQName(name);
+            } catch (NameException e) {
                 throw new SAXException(new InvalidSerializedDataException("illegal property
name: " + name, e));
             } catch (NamespaceException e) {
                 throw new SAXException(new InvalidSerializedDataException("illegal property
name: " + name, e));
@@ -240,10 +240,10 @@
                 String s = null;
                 try {
                     s = val.retrieve();
-                    state.nodeTypeName = nameResolver.getQName(s);
+                    state.nodeTypeName = resolver.getQName(s);
                 } catch (IOException ioe) {
                     throw new SAXException("error while retrieving value", ioe);
-                } catch (org.apache.jackrabbit.conversion.NameException e) {
+                } catch (NameException e) {
                     throw new SAXException(new InvalidSerializedDataException("illegal node
type name: " + s, e));
                 } catch (NamespaceException e) {
                     throw new SAXException(new InvalidSerializedDataException("illegal node
type name: " + s, e));
@@ -258,11 +258,11 @@
                     String s = null;
                     try {
                         s = val.retrieve();
-                        Name mixin = nameResolver.getQName(s);
+                        Name mixin = resolver.getQName(s);
                         state.mixinNames.add(mixin);
                     } catch (IOException ioe) {
                         throw new SAXException("error while retrieving value", ioe);
-                    } catch (org.apache.jackrabbit.conversion.NameException e) {
+                    } catch (NameException e) {
                         throw new SAXException(new InvalidSerializedDataException("illegal
mixin type name: " + s, e));
                     } catch (NamespaceException e) {
                         throw new SAXException(new InvalidSerializedDataException("illegal
mixin type name: " + s, e));

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/TargetImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/TargetImportHandler.java?rev=599366&r1=599365&r2=599366&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/TargetImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/TargetImportHandler.java
Thu Nov 29 02:26:50 2007
@@ -16,8 +16,7 @@
  */
 package org.apache.jackrabbit.jcr2spi.xml;
 
-import org.apache.jackrabbit.conversion.NameResolver;
-import org.apache.jackrabbit.namespace.NamespaceResolver;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,13 +43,11 @@
     private static Logger log = LoggerFactory.getLogger(TargetImportHandler.class);
 
     protected final Importer importer;
-    protected final NamespaceResolver nsContext;
-    protected final NameResolver nameResolver;
+    protected final NamePathResolver resolver;
 
-    protected TargetImportHandler(Importer importer, NamespaceResolver nsContext, org.apache.jackrabbit.conversion.NameResolver
nameResolver) {
+    protected TargetImportHandler(Importer importer, NamePathResolver resolver) {
         this.importer = importer;
-        this.nsContext = nsContext;
-        this.nameResolver = nameResolver;
+        this.resolver = resolver;
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java?rev=599366&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
Thu Nov 29 02:26:50 2007
@@ -0,0 +1,131 @@
+/*
+ * 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.jcr2spi.xml;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.JcrConstants;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.PropertyType;
+import javax.jcr.Session;
+import javax.jcr.Item;
+import javax.jcr.Property;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * <code>SessionImportTest</code>...
+ */
+public class SessionImportTest extends AbstractJCRTest {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testImportNameValueWithUnregisteredNamespace() throws RepositoryException,
SAXException {
+        String prefix = getUniquePrefix(superuser);
+        String uri = getUnknownURI(superuser, "anyURI");
+        String testValue = prefix + ":someLocalName";
+
+        String svuri = Name.NS_SV_URI;
+        String svprefix = Name.NS_SV_PREFIX + ":";
+
+        ContentHandler ch = superuser.getImportContentHandler(testRootNode.getPath(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+        ch.startDocument();
+        ch.startPrefixMapping(prefix, uri);
+
+        String nN = "node";
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute(svuri, "name", svprefix + "name", "CDATA", nodeName1);
+        ch.startElement(svuri, nN, svprefix + nN, attrs);
+
+        // primary node type
+        String pN = "property";
+        attrs = new AttributesImpl();
+        attrs.addAttribute(svuri, "name", svprefix + "name", "CDATA", JcrConstants.JCR_PRIMARYTYPE);
+        attrs.addAttribute(svuri, "type", svprefix + "type", "CDATA", PropertyType.nameFromValue(PropertyType.NAME));
+        ch.startElement(svuri, pN, svprefix + pN, attrs);
+            ch.startElement(svuri, "value", svprefix + "value", new AttributesImpl());
+            char[] val = testNodeType.toCharArray();
+            ch.characters(val, 0, val.length);
+            ch.endElement(svuri, "value", svprefix + "value");
+        ch.endElement(svuri, pN, prefix + pN);
+
+        // another name value
+        attrs = new AttributesImpl();
+        attrs.addAttribute(svuri, "name", svprefix + "name", "CDATA", propertyName1);
+        attrs.addAttribute(svuri, "type", svprefix + "type", "CDATA", PropertyType.nameFromValue(PropertyType.NAME));
+        ch.startElement(svuri, pN, svprefix + pN, attrs);
+            ch.startElement(svuri, "value", svprefix + "value", new AttributesImpl());
+            val = testValue.toCharArray();
+            ch.characters(val, 0, val.length);
+            ch.endElement(svuri, "value", svprefix + "value");
+        ch.endElement(svuri, pN, svprefix + pN);
+
+        ch.endElement(svuri, nN, svprefix + nN);
+        ch.endDocument();
+
+        // test if property has been imported with correct namespace
+        String assignedPrefix = superuser.getNamespacePrefix(uri);
+        assertTrue(superuser.getNamespaceURI(assignedPrefix).equals(uri));
+        String path = testRootNode.getPath() + "/" + nodeName1 + "/" + propertyName1;
+
+        assertTrue(superuser.itemExists(path));
+        Item item = superuser.getItem(path);
+        if (item.isNode()) {
+            fail("Item with path " + path + " must be a property.");
+        } else {
+            Property prop = (Property) item;
+            assertTrue(prop.getValue().getType() == PropertyType.NAME);
+            String expectedValue = assignedPrefix + ":someLocalName";
+            assertTrue(prop.getValue().getString().equals(expectedValue));
+        }
+
+        // try to save
+        superuser.save();
+    }
+
+    private static String getUnknownURI(Session session, String uriHint) throws RepositoryException
{
+        String uri = uriHint;
+        int index = 0;
+        List uris = Arrays.asList(session.getWorkspace().getNamespaceRegistry().getURIs());
+        while (uris.contains(uri)) {
+            uri = uriHint + index;
+            index++;
+        }
+        return uri;
+    }
+
+    /**
+     * Returns a prefix that is unique among the already registered prefixes.
+     *
+     * @param uriHint namespace uri that serves as hint for the prefix generation
+     * @return a unique prefix
+     */
+    public static String getUniquePrefix(Session session) throws RepositoryException {
+        return "_pre" + (session.getNamespacePrefixes().length + 1);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/SessionImportTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java?rev=599366&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
Thu Nov 29 02:26:50 2007
@@ -0,0 +1,32 @@
+/*
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.jcr2spi.xml;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * <code>TestAll</code>...
+ */
+public class TestAll extends TestCase {
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite("jcr2spi xml tests");
+
+        suite.addTestSuite(SessionImportTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/xml/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message