jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r943567 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nam...
Date Wed, 12 May 2010 16:16:20 GMT
Author: stefan
Date: Wed May 12 16:16:19 2010
New Revision: 943567

URL: http://svn.apache.org/viewvc?rev=943567&view=rev
Log:
JCR-2627: System-view export/import of multi-value property does not respect JCR 2.0

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SystemViewExporter.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java?rev=943567&r1=943566&r2=943567&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java
Wed May 12 16:16:19 2010
@@ -56,7 +56,13 @@ public class PropInfo {
     private final TextValue[] values;
 
     /**
-     * Creates a proprety information instance.
+     * Hint indicating whether the property is multi- or single-value
+     */
+    public enum MultipleStatus { UNKNOWN, SINGLE, MULTIPLE };
+    private MultipleStatus multipleStatus;
+
+    /**
+     * Creates a property information instance.
      *
      * @param name name of the property being imported
      * @param type type of the property being imported
@@ -66,6 +72,26 @@ public class PropInfo {
         this.name = name;
         this.type = type;
         this.values = values;
+        multipleStatus =
+                values.length == 1
+                        ? MultipleStatus.UNKNOWN : MultipleStatus.MULTIPLE;
+    }
+
+    /**
+     * Creates a property information instance.
+     *
+     * @param name name of the property being imported
+     * @param type type of the property being imported
+     * @param values value(s) of the property being imported
+     * @param multipleStatus Hint indicating whether the property is
+     *                       multi- or single-value
+     */
+    public PropInfo(Name name, int type, TextValue[] values,
+                    MultipleStatus multipleStatus) {
+        this.name = name;
+        this.type = type;
+        this.values = values;
+        this.multipleStatus = multipleStatus;
     }
 
     /**
@@ -90,12 +116,13 @@ public class PropInfo {
 
     public QPropertyDefinition getApplicablePropertyDef(EffectiveNodeType ent)
             throws ConstraintViolationException {
-        if (values.length == 1) {
-            // could be single- or multi-valued (n == 1)
-            return ent.getApplicablePropertyDef(name, type);
-        } else {
-            // can only be multi-valued (n == 0 || n > 1)
+        if (multipleStatus == MultipleStatus.MULTIPLE) {
             return ent.getApplicablePropertyDef(name, type, true);
+        } else if (multipleStatus == MultipleStatus.SINGLE) {
+            return ent.getApplicablePropertyDef(name, type, false);
+        } else {
+            // could be single- or multi-valued
+            return ent.getApplicablePropertyDef(name, type);
         }
     }
 
@@ -107,6 +134,10 @@ public class PropInfo {
         return type;
     }
 
+    public MultipleStatus getMultipleStatus() {
+        return multipleStatus;
+    }
+
     public TextValue[] getTextValues() {
         return values;        
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java?rev=943567&r1=943566&r2=943567&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Wed May 12 16:16:19 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.xml;
 
+import org.apache.jackrabbit.core.xml.PropInfo.MultipleStatus;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -54,7 +56,8 @@ class SysViewImportHandler extends Targe
      */
     private Name currentPropName;
     private int currentPropType = PropertyType.UNDEFINED;
-    // list of AppendableValue objects
+    private MultipleStatus currentPropMultipleStatus = MultipleStatus.UNKNOWN;
+    // list of appendable value objects
     private ArrayList<BufferedStringValue> currentPropValues =
         new ArrayList<BufferedStringValue>();
     private BufferedStringValue currentPropValue;
@@ -174,6 +177,13 @@ class SysViewImportHandler extends Targe
                 throw new SAXException(new InvalidSerializedDataException(
                         "Unknown property type: " + type, e));
             }
+            // 'multi-value' hint (sv:multiple attribute)
+            String multiple = getAttribute(atts, NameConstants.SV_MULTIPLE);
+            if (multiple != null) {
+                currentPropMultipleStatus = MultipleStatus.MULTIPLE;
+            } else {
+                currentPropMultipleStatus = MultipleStatus.UNKNOWN;
+            }
         } else if (name.equals(NameConstants.SV_VALUE)) {
             // sv:value element
             currentPropValue = new BufferedStringValue(resolver, valueFactory);
@@ -287,7 +297,8 @@ class SysViewImportHandler extends Targe
                 PropInfo prop = new PropInfo(
                         currentPropName,
                         currentPropType,
-                        currentPropValues.toArray(new TextValue[currentPropValues.size()]));
+                        currentPropValues.toArray(new TextValue[currentPropValues.size()]),
+                        currentPropMultipleStatus);
                 state.props.add(prop);
             }
             // reset temp fields

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java?rev=943567&r1=943566&r2=943567&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
Wed May 12 16:16:19 2010
@@ -167,7 +167,7 @@ public abstract class Exporter {
             throws RepositoryException, SAXException;
 
     /**
-     * Called by {@link #processProperties(Node)} to process a single-valued
+     * Called by {@link #exportProperties(Node)} to process a single-valued
      * property.
      *
      * @param uri property namespace
@@ -181,13 +181,13 @@ public abstract class Exporter {
             throws RepositoryException, SAXException;
 
     /**
-     * Called by {@link #processProperties(Node)} to process a multivalued
+     * Called by {@link #exportProperties(Node)} to process a multivalued
      * property.
      *
      * @param uri property namespace
      * @param local property name
      * @param type property type
-     * @param value property values
+     * @param values property values
      * @throws RepositoryException if a repository error occurs
      * @throws SAXException if a SAX error occurs
      */

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SystemViewExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SystemViewExporter.java?rev=943567&r1=943566&r2=943567&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SystemViewExporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SystemViewExporter.java
Wed May 12 16:16:19 2010
@@ -84,7 +84,13 @@ public class SystemViewExporter extends 
      */
     protected void exportProperty(String uri, String local, Value value)
             throws RepositoryException, SAXException {
-        exportProperty(uri, local, value.getType(), new Value[] { value });
+        // start property element
+        addAttribute(SV, "name", getXMLName(uri, local));
+        addAttribute(SV, "type", PropertyType.nameFromValue(value.getType()));
+        startElement(SV, "property");
+        // value
+        exportValue(value);
+        endElement(SV, "property");
     }
 
     /**
@@ -96,6 +102,7 @@ public class SystemViewExporter extends 
         // start property element
         addAttribute(SV, "name", getXMLName(uri, local));
         addAttribute(SV, "type", PropertyType.nameFromValue(type));
+        addAttribute(SV, "multiple", Boolean.TRUE.toString());
         startElement(SV, "property");
         // values
         for (int i = 0; i < values.length; i++) {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java?rev=943567&r1=943566&r2=943567&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
Wed May 12 16:16:19 2010
@@ -633,6 +633,9 @@ public class NameConstants {
      * sv:name
      */
     public static final Name SV_NAME = FACTORY.create(Name.NS_SV_URI, "name");
-
+    /**
+     * sv:multiple
+     */
+    public static final Name SV_MULTIPLE = FACTORY.create(Name.NS_SV_URI, "multiple");
 
 }
\ No newline at end of file



Mime
View raw message