[exo-jcr-commits] exo-jcr SVN: r1573 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/xml/importing and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 26 03:27:19 EST 2010


Author: nzamosenchuk
Date: 2010-01-26 03:27:18 -0500 (Tue, 26 Jan 2010)
New Revision: 1573

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/DecodedValue.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java
Log:
EXOJCR-438: Added special test and applied proposed patch for SysView import.

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/DecodedValue.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/DecodedValue.java	2010-01-25 14:46:56 UTC (rev 1572)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/DecodedValue.java	2010-01-26 08:27:18 UTC (rev 1573)
@@ -49,6 +49,11 @@
    private StringBuffer stringBuffer;
 
    /**
+    * true if DecodedValue is completed
+    */
+   private boolean complete;
+
+   /**
     * Dafault constructor.
     */
    public DecodedValue()
@@ -112,6 +117,26 @@
    }
 
    /**
+    * Used to determine the end of value tag in system view import.
+    * 
+    * @param complete
+    */
+   public void setComplete(boolean complete)
+   {
+      this.complete = complete;
+   }
+
+   /**
+    * Used to determine the end of value tag in system view import.
+    * 
+    * @return
+    */
+   public boolean isComplete()
+   {
+      return complete;
+   }
+
+   /**
     * @return string representation for value.
     */
    public String toString()

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java	2010-01-25 14:46:56 UTC (rev 1572)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java	2010-01-26 08:27:18 UTC (rev 1573)
@@ -104,6 +104,11 @@
       if (propertyInfo.getValues().size() > 0)
       {
          DecodedValue curPropValue = propertyInfo.getValues().get(propertyInfo.getValues().size() - 1);
+         if (curPropValue.isComplete())
+         {
+            return;
+         }
+
          if (propertyInfo.getType() == PropertyType.BINARY)
          {
             try
@@ -122,7 +127,7 @@
       }
       else
       {
-         log.warn("Wrong XML content. Element 'sv:value' expected,"
+         log.debug("Wrong XML content. Element 'sv:value' expected,"
             + " but SAX event 'characters' occured. characters:[" + new String(ch, start, length) + "]");
       }
    }
@@ -150,6 +155,9 @@
       else if (Constants.SV_VALUE_NAME.equals(elementName))
       {
          // sv:value element
+         //mark current value as completed
+         DecodedValue curPropValue = propertyInfo.getValues().get(propertyInfo.getValues().size() - 1);
+         curPropValue.setComplete(true);
       }
       else
       {

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java	2010-01-25 14:46:56 UTC (rev 1572)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java	2010-01-26 08:27:18 UTC (rev 1573)
@@ -141,6 +141,64 @@
 
          "</sv:node>";
 
+   public static final String SYSTEM_VIEW_CONTENT_FORMATTED =
+      "<sv:node xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"\n "
+         + "xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:exo=\"http://www.exoplatform.com/jcr/exo/1.0\"\n  "
+         + "xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" sv:name=\"exo:test\">\n "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n      <sv:value>nt:unstructured</sv:value>\n    </sv:property>\n\n   "
+         + "<sv:node sv:name=\"childNode\">\n      "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n         <sv:value>nt:folder</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name=\"jcr:created\" sv:type=\"Date\">\n       <sv:value>2004-08-18T15:17:00.856+01:00</sv:value>\n     </sv:property>\n     "
+         + "<sv:node sv:name=\"childNode3\">\n        "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n            <sv:value>nt:file</sv:value>\n         </sv:property>\n        "
+         + "<sv:property sv:name=\"jcr:created\" sv:type=\"Date\">\n          <sv:value>2004-08-18T15:17:00.856+01:00</sv:value>\n        </sv:property>\n        "
+         + "<sv:node sv:name=\"jcr:content\">\n          "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n               <sv:value>nt:resource</sv:value>\n           </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">\n              <sv:value>1092835020617_</sv:value>\n           </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:data\" sv:type=\"Binary\">\n              <sv:value>dGhpcyBpcyB0aGUgYmluYXJ5IGNvbnRlbnQ=</sv:value>\n          </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:mimeType\" sv:type=\"String\">\n             <sv:value>application/unknown</sv:value>\n            </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:lastModified\" sv:type=\"Date\">\n              <sv:value>2004-08-18T15:17:00.856+01:00</sv:value>\n           </sv:property>\n        "
+         + "</sv:node>\n      "
+         + "</sv:node>\n      "
+         + "<sv:node sv:name=\"childNode2\">\n        "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n            <sv:value>nt:file</sv:value>\n         </sv:property>\n        "
+         + "<sv:property sv:name=\"jcr:created\" sv:type=\"Date\">\n          <sv:value>2004-08-18T15:17:00.856+01:00</sv:value>\n        </sv:property>\n        "
+         + "<sv:node sv:name=\"jcr:content\">\n          "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n               <sv:value>nt:resource</sv:value>\n           </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">\n              <sv:value>1092835020616_</sv:value>\n           </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:data\" sv:type=\"Binary\">\n              <sv:value>dGhpcyBpcyB0aGUgYmluYXJ5IGNvbnRlbnQ=</sv:value>\n          </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:mimeType\" sv:type=\"String\">\n             <sv:value>text/text</sv:value>\n          </sv:property>\n           "
+         + "<sv:property sv:name=\"jcr:lastModified\" sv:type=\"Date\">\n              <sv:value>2004-08-18T15:17:00.856+01:00</sv:value>\n           </sv:property>\n        "
+         + "</sv:node>\n      "
+         + "</sv:node>\n   "
+         + "</sv:node>\n\n "
+         + "<sv:node sv:name='uuidNode1'>\n     "
+         + "<sv:property sv:name='jcr:primaryType' sv:type='Name'>\n       <sv:value>nt:unstructured</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='jcr:mixinTypes' sv:type='Name'>\n        <sv:value>mix:referenceable</sv:value>\n        "
+         + "<!-- sv:value>exo:accessControllable</sv:value -->\n     "
+         + "</sv:property>\n     "
+         + "<sv:property sv:name='jcr:test' sv:type='String'>\n         <sv:value>val1</sv:value>\n         <sv:value>val1</sv:value>\n      </sv:property>\n     "
+         + "<sv:property sv:name='source' sv:type='String'>\n        <sv:value>sysView</sv:value>\n      </sv:property>\n     "
+         + "<sv:property sv:name='jcr:uuid' sv:type='String'>\n         <sv:value>id_uuidNode1</sv:value>\n    </sv:property>\n  </sv:node>\n\n "
+         + "<sv:node sv:name='uuidNode2'>\n     "
+         + "<sv:property sv:name='jcr:primaryType' sv:type='Name'>\n       <sv:value>nt:unstructured</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='jcr:mixinTypes' sv:type='Name'>\n        <sv:value>mix:referenceable</sv:value>\n     </sv:property>\n     "
+         + "<sv:property sv:name='jcr:test' sv:type='String'>\n         <sv:value>val2</sv:value>\n         <sv:value>val1</sv:value>\n      </sv:property>\n     "
+         + "<sv:property sv:name='jcr:uuid' sv:type='String'>\n         <sv:value>uuidNode2</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='ref_to_1' sv:type='Reference'>\n         <sv:value>id_uuidNode1</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='ref_to_1_and_3' sv:type='Reference'>\n         <sv:value>id_uuidNode1</sv:value>\n       <sv:value>id_uuidNode3</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='ref_to_3' sv:type='Reference'>\n         <sv:value>id_uuidNode3</sv:value>\n    </sv:property>\n  </sv:node>\n\n <sv:node sv:name='uuidNode3'>\n     "
+         + "<sv:property sv:name='jcr:primaryType' sv:type='Name'>\n       <sv:value>nt:unstructured</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='jcr:mixinTypes' sv:type='Name'>\n        <sv:value>mix:referenceable</sv:value>\n     </sv:property>\n     "
+         + "<sv:property sv:name='ref_to_1' sv:type='Reference'>\n         <sv:value>id_uuidNode1</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name='jcr:test' sv:type='String'>\n         <sv:value>val1</sv:value>\n         <sv:value>va31</sv:value>\n      </sv:property>\n     <sv:property sv:name='jcr:uuid' sv:type='String'>\n         <sv:value>id_uuidNode3</sv:value>\n    </sv:property>\n  "
+         + "</sv:node>\n\n "
+         + "<sv:node sv:name=\"childNode4\">\n     "
+         + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n         "
+         + "<sv:value>nt:unstructured</sv:value>\n    </sv:property>\n     "
+         + "<sv:property sv:name=\"jcr:test\" sv:type=\"String\">\n        <sv:value>val1</sv:value>\n         <sv:value>val1</sv:value>\n      </sv:property>\n  "
+         + "</sv:node>\n\n" + "</sv:node>";
+
    public static final String SYSTEM_VIEW_CONTENT2 =
       "<sv:node xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" "
          + "xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" "
@@ -441,6 +499,34 @@
       assertEquals("val1", property.getValues()[0].getString());
    }
 
+   public void testImportSysViewFormatted() throws RepositoryException, InvalidSerializedDataException,
+      ConstraintViolationException, IOException, ItemExistsException
+   {
+
+      root.addNode("testFormatted");
+      session.importXML("/testFormatted", new ByteArrayInputStream(SYSTEM_VIEW_CONTENT_FORMATTED.getBytes()), 0);
+      session.save();
+
+      Node testRoot = session.getRootNode().getNode("testFormatted");
+      NodeIterator iterator = testRoot.getNodes();
+      assertEquals(1, iterator.getSize());
+
+      // log.debug(">>"+session.getWorkspaceDataContainer());
+
+      iterator = testRoot.getNode("exo:test/childNode").getNodes();
+      assertEquals(2, iterator.getSize());
+
+      Property property = testRoot.getProperty("exo:test/childNode/childNode3/jcr:content/jcr:data");
+      assertEquals("this is the binary content", property.getString());
+
+      property = testRoot.getProperty("exo:test/childNode/childNode2/jcr:content/jcr:data");
+      assertEquals("this is the binary content", property.getString());
+
+      property = testRoot.getProperty("exo:test/childNode4/jcr:test");
+      assertEquals(2, property.getValues().length);
+      assertEquals("val1", property.getValues()[0].getString());
+   }
+
    public void testImportSysViewContentHandler() throws Exception
    {
 



More information about the exo-jcr-commits mailing list