jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r111990 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Date Wed, 15 Dec 2004 16:26:31 GMT
Author: tripod
Date: Wed Dec 15 08:26:30 2004
New Revision: 111990

URL: http://svn.apache.org/viewcvs?view=rev&rev=111990
Log:
- fixed resolving of references (JCR-33)
Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java?view=diff&rev=111990&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java&r1=111989&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java&r2=111990
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Wed Dec 15 08:26:30 2004
@@ -18,6 +18,7 @@
 import org.apache.jackrabbit.core.*;
 import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.util.Base64;
 import org.apache.jackrabbit.core.util.ValueHelper;
 import org.apache.log4j.Logger;
@@ -32,8 +33,7 @@
 import javax.jcr.nodetype.ConstraintViolationException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Stack;
+import java.util.*;
 
 /**
  * <code>SysViewImportHandler</code>  ...
@@ -51,6 +51,12 @@
      */
     private Stack stateStack = new Stack();
 
+    /** list of all reference properties that need to be adjusted */
+    private LinkedList references = new LinkedList();
+
+    /** list of all mix:referenceable */
+    private HashMap referees = new HashMap();
+
     /**
      * fields used temporarily while processing sv:property and sv:value elements
      */
@@ -292,6 +298,9 @@
 			try {
 			    // try setting single-value
 			    current.node.setProperty(currentPropName, vals[0]);
+			} catch (ValueFormatException vfe) {
+                            // try setting value array
+                            current.node.setProperty(currentPropName, vals);
 			} catch (ConstraintViolationException vfe) {
 			    // try setting value array
 			    current.node.setProperty(currentPropName, vals);
@@ -300,6 +309,10 @@
 			// can only be multi-valued (n == 0 || n > 1)
 			current.node.setProperty(currentPropName, vals);
 		    }
+                    // check if reference for later resolution
+                    if (currentPropType==PropertyType.REFERENCE) {
+                        references.add(current.node.getProperty(currentPropName));
+                    }
 		}
 
 		// reset temp fields
@@ -331,21 +344,71 @@
 	    NodeDef def = state.node.getDefinition();
 	    if (def.isProtected()) {
                 // @todo how to handle protected/auto-created child node?
-                return;
+
             } else if (def.isAutoCreate()) {
 		// @todo how to handle protected/auto-created child node?
-                return;
-	    }
-	}
 
-	state.node = (NodeImpl) state.parent.addNode(state.nodeName, state.primaryType);
-	if (state.mixinTypes != null) {
-	    for (int i = 0; i < state.mixinTypes.size(); i++) {
-		NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType((QName) state.mixinTypes.get(i));
-		state.node.addMixin(mixin.getName());
 	    }
-	}
+	} else {
+            state.node = (NodeImpl) state.parent.addNode(state.nodeName, state.primaryType);
+            if (state.mixinTypes != null) {
+                for (int i = 0; i < state.mixinTypes.size(); i++) {
+                    NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType((QName)
state.mixinTypes.get(i));
+                    state.node.addMixin(mixin.getName());
+                }
+            }
+        }
+
+        // check for mix:referenceable
+        if (state.node.isNodeType(NodeTypeRegistry.MIX_REFERENCEABLE)) {
+            log.info("adding refereee: ori=" + state.uuid + " new=" + state.node.getUUID());
+            referees.put(state.uuid, state.node.getUUID());
+        }
+    }
+
+    public void endDocument() throws SAXException {
+        try {
+            // adjust all reference properties
+            Iterator iter = references.iterator();
+            while (iter.hasNext()) {
+                Property prop = (Property) iter.next();
+                if (prop.getDefinition().isMultiple()) {
+                    Value[] values = prop.getValues();
+                    Value[] newVals = new Value[values.length];
+                    for (int i=0; i<values.length; i++) {
+                        Value val = values[i];
+                        if (val.getType()==PropertyType.REFERENCE) {
+                            String original = val.getString();
+                            String adjusted = (String) referees.get(original);
+                            if (adjusted==null) {
+                                log.error("Reference " + original + " of property can not
be adjusted! " + prop.getPath());
+                                newVals[i] = val;
+                            } else {
+                                newVals[i] = new ReferenceValue(session.getNodeByUUID(adjusted));
+                            }
+                        } else {
+                            newVals[i] = val;
+                        }
+                    }
+                    prop.setValue(newVals);
+                } else {
+                    Value val = prop.getValue();
+                    if (val.getType()==PropertyType.REFERENCE) {
+                        String original = val.getString();
+                        String adjusted = (String) referees.get(original);
+                        if (adjusted==null) {
+                            log.error("Reference " + original + " of property can not be
adjusted! " + prop.getPath());
+                        } else {
+                            prop.setValue(session.getNodeByUUID(adjusted));
+                        }
+                    }
+                }
+            }
+        } catch (RepositoryException e) {
+            log.error("Error while adjusting reference proerties: " + e.toString());
+        }
     }
+
 
     //--------------------------------------------------------< inner classes >
     class ImportState {

Mime
View raw message