svn commit: r1094371 [1/2] - in /ofbiz/branches/jackrabbit20100709: ./ applications/content/ applications/content/data/ applications/content/entitydef/ applications/content/src/org/ofbiz/content/jcr/ applications/content/src/org/ofbiz/content/jcr/helpe...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1094371 [1/2] - in /ofbiz/branches/jackrabbit20100709: ./ applications/content/ applications/content/data/ applications/content/entitydef/ applications/content/src/org/ofbiz/content/jcr/ applications/content/src/org/ofbiz/content/jcr/helpe...

sascharodekamp
Author: sascharodekamp
Date: Mon Apr 18 09:08:14 2011
New Revision: 1094371

URL: http://svn.apache.org/viewvc?rev=1094371&view=rev
Log:
Update - Basic CRUD operations for the Jackrabbit Repository. If you want some more information about the architecture check: https://cwiki.apache.org/OFBIZ/jackrabbit-branch-development.html

With this first pre version of the jackrabbit integration you can add, update remove text nodes and store or delete files in the repository, have a look under: Exampels --> Jackrabbit Sandbox

Added:
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java   (with props)
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java   (with props)
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java   (with props)
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java   (with props)
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java   (with props)
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/
    ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml   (with props)
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/lib/apache-mime4j-0.6.1.jar   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrFileHelper.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrFileHelperAbstract.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrHelperAbstract.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrTextHelper.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrTextHelperAbstract.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/
    ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/
    ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml   (with props)
Modified:
    ofbiz/branches/jackrabbit20100709/.classpath
    ofbiz/branches/jackrabbit20100709/applications/content/build.xml
    ofbiz/branches/jackrabbit20100709/applications/content/data/ContentTypeData.xml
    ofbiz/branches/jackrabbit20100709/applications/content/entitydef/entitymodel.xml
    ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml
    ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml
    ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml
    ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/CommonScreens.xml
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java

Modified: ofbiz/branches/jackrabbit20100709/.classpath
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.classpath?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/.classpath (original)
+++ ofbiz/branches/jackrabbit20100709/.classpath Mon Apr 18 09:08:14 2011
@@ -139,15 +139,16 @@
     <classpathentry kind="lib" path="framework/guiapp/lib/XuiCoreSwing-v3.2rc2b.jar"/>
     <classpathentry kind="lib" path="framework/guiapp/lib/XuiOptional-v3.2rc2b.jar"/>
     <classpathentry kind="lib" path="framework/jcr/lib/concurrent-1.3.4.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-api-2.2.4.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-core-2.2.4.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.2.4.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.2.4.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.2.4.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-api-2.2.5.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-core-2.2.5.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jca-2.2.5.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.2.5.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.2.5.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.2.5.jar"/>
     <classpathentry kind="lib" path="framework/jcr/lib/jcr-2.0.jar"/>
     <classpathentry kind="lib" path="framework/jcr/lib/pdfbox-1.3.1.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.5.8.jar"/>
-    <classpathentry kind="lib" path="framework/jcr/lib/slf4j-log4j12-1.5.8.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.5.11.jar"/>
+    <classpathentry kind="lib" path="framework/jcr/lib/slf4j-log4j12-1.5.11.jar"/>
     <classpathentry kind="lib" path="framework/jcr/lib/tika-core-0.8.jar"/>
     <classpathentry kind="lib" path="framework/jcr/lib/tika-parsers-0.8.jar"/>
     <classpathentry kind="lib" path="framework/jetty/lib/jasper-compiler-5.5.15.jar"/>

Modified: ofbiz/branches/jackrabbit20100709/applications/content/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/build.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/build.xml (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/build.xml Mon Apr 18 09:08:14 2011
@@ -47,6 +47,8 @@ under the License.
         <fileset dir="../../framework/webapp/build/lib" includes="*.jar"/>
         <fileset dir="../../framework/widget/build/lib" includes="*.jar"/>
         <fileset dir="../../framework/common/build/lib" includes="*.jar"/>
+        <fileset dir="../../framework/jcr/lib" includes="*.jar"/>
+        <fileset dir="../../framework/jcr/build/lib" includes="*.jar"/>
     </path>
 
     <patternset id="src.exc.set">

Modified: ofbiz/branches/jackrabbit20100709/applications/content/data/ContentTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/data/ContentTypeData.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/data/ContentTypeData.xml (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/data/ContentTypeData.xml Mon Apr 18 09:08:14 2011
@@ -39,6 +39,7 @@ under the License.
     <ContentAssocType contentAssocTypeId="SUB_CONTENT" description="Sub-Content"/>
     <ContentAssocType contentAssocTypeId="TOPIC" description="Topic"/>
     <ContentAssocType contentAssocTypeId="DESCRIPTION" description="Description"/>
+    <ContentAssocType contentAssocTypeId="REPOSITORY" description="Repository Assoc"/>
 
     <ContentAssocType contentAssocTypeId="SUBSITE" description="SubSite"/>
     <ContentAssocType contentAssocTypeId="DEPARTMENT" description="Department"/>
@@ -67,6 +68,7 @@ under the License.
     <MetaDataPredicate metaDataPredicateId="event-person-name" description="The name of a person involved in the subject event."/>
 
     <ContentType contentTypeId="DOCUMENT" description="Document" hasTable="N" parentTypeId=""/>
+    <ContentType contentTypeId="REPOSITORY" description="Content Repository Data" hasTable="N" parentTypeId=""/>
     <ContentType contentTypeId="TEMPLATE" description="Template or Form" hasTable="N" parentTypeId=""/>
     <ContentType contentTypeId="DECORATOR" description="Decorator" hasTable="N" parentTypeId="TEMPLATE"/>
     <ContentType contentTypeId="ANNOTATION" description="Annotation" hasTable="N" parentTypeId=""/>

Modified: ofbiz/branches/jackrabbit20100709/applications/content/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/entitydef/entitymodel.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/entitydef/entitymodel.xml (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/entitydef/entitymodel.xml Mon Apr 18 09:08:14 2011
@@ -157,6 +157,7 @@ under the License.
       <field name="dataResourceId" type="id"></field>
       <field name="templateDataResourceId" type="id"></field>
       <field name="dataSourceId" type="id"></field>
+      <field name="repositoryNode" type="long-varchar"></field>
       <field name="statusId" type="id"></field>
       <field name="privilegeEnumId" type="id"></field>
       <field name="serviceName" type="long-varchar"></field>

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,341 @@
+package org.ofbiz.content.jcr;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import javolution.util.FastMap;
+import net.sf.json.JSONArray;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.io.IOUtils;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.FileUtil;
+import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.content.jcr.helper.JcrFileHelperJackrabbit;
+import org.ofbiz.content.jcr.helper.JcrTextHelperJackrabbit;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.helper.JcrFileHelper;
+import org.ofbiz.jcr.helper.JcrTextHelper;
+
+public class JackrabbitEvents {
+
+ public static final String module = JackrabbitEvents.class.getName();
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) {
+ String message = request.getParameter("message");
+
+ JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request);
+
+ String newContentId = null;
+ try {
+ newContentId = jackrabbit.storeNewTextData(message);
+
+ if (newContentId == null) {
+ request.setAttribute("_ERROR_MESSAGE_", "Couldn't be created, maybe the node already exists. Use another node name to store you're content.");
+ return "error";
+ }
+
+ request.setAttribute("newContentId", newContentId);
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); // UtilProperties.getMessage(resourceErr,
+                                                         // "idealEvents.problemsGettingMerchantConfiguration",
+                                                         // locale)
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) {
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+ try {
+ List<Map<String, String>> listIt = JackrabbitWorker.getRepositoryNodes(userLogin, "");
+ request.setAttribute("listIt", listIt);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) {
+ JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request);
+
+ try {
+ String textContent = jackrabbit.getTextData();
+ request.setAttribute("message", textContent);
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) {
+ String message = request.getParameter("message");
+
+ JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request);
+
+ try {
+ String textContent = jackrabbit.updateTextData(message);
+ request.setAttribute("message", textContent);
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) {
+ JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request);
+
+ try {
+ jackrabbit.removeRepositoryNode();
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String removeRepositoryFileNode(HttpServletRequest request, HttpServletResponse response) {
+ JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(request);
+
+ try {
+ jackrabbit.removeRepositoryNode();
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String cleanJcrRepository(HttpServletRequest request, HttpServletResponse response) {
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+ Delegator delegator = (Delegator) request.getAttribute("delegator");
+
+ try {
+ JackrabbitWorker.cleanJcrRepository(delegator, userLogin);
+ } catch (GenericEntityException e) {
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } catch (RepositoryException e) {
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ }
+
+ return "success";
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @return
+ */
+ public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) {
+
+ ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp")));
+ List<FileItem> list = null;
+ Map<String, String> passedParams = FastMap.newInstance();
+
+ try {
+ list = UtilGenerics.checkList(fu.parseRequest(request));
+ } catch (FileUploadException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ }
+
+ byte[] file = null;
+ for (FileItem fi : list) {
+ String fieldName = fi.getFieldName();
+
+ if (fi.isFormField()) {
+ String fieldStr = fi.getString();
+ passedParams.put(fieldName, fieldStr);
+ } else if (fieldName.startsWith("fileData")) {
+ passedParams.put("completeFileName", fi.getName());
+ file = fi.get();
+ }
+ }
+
+ JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit((GenericValue) request.getSession().getAttribute("userLogin"), (Delegator) request.getAttribute("delegator"), null, passedParams.get("repositoryNode"));
+
+ if (file != null && file.length >= 1) {
+ try {
+ jackrabbit.uploadFileData(file, passedParams.get("completeFileName"));
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+ } else {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) {
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+ Delegator delegator = (Delegator) request.getAttribute("delegator");
+
+ JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(userLogin, delegator, null, "/fileHome");
+
+ try {
+ JSONArray fileTree = jackrabbit.getJsonFileTree();
+ request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString()));
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ }
+
+ return "success";
+ }
+
+ public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) {
+
+ JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(request);
+ InputStream file = null;
+ try {
+ file = jackrabbit.getFileContent();
+ UtilHttp.streamContentToBrowser(response, IOUtils.toByteArray(file), jackrabbit.getFileMimeType(), jackrabbit.getNodeName());
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } catch (IOException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ } finally {
+ jackrabbit.closeSession();
+ if (file != null) {
+ try {
+ file.close();
+ } catch (IOException e) {
+ Debug.logError(e, module);
+ request.setAttribute("_ERROR_MESSAGE_", e.toString());
+ return "error";
+ }
+ }
+ }
+
+ return "success";
+ }
+}
\ No newline at end of file

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,156 @@
+package org.ofbiz.content.jcr;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.JackrabbitContainer;
+
+public class JackrabbitWorker {
+
+    public static final String module = JackrabbitWorker.class.getName();
+
+    /**
+     * Just a dummy method to list all nodes in the repository.
+     *
+     * @param startNodePath
+     * @return
+     * @throws RepositoryException
+     */
+    public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException {
+        List<Map<String, String>> returnList = null;
+        Session session = null;
+        try {
+            session = JackrabbitContainer.getUserSession(userLogin);
+            returnList = getRepositoryNodes(session, startNodePath);
+        }
+        catch (RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+        finally {
+            session.logout();
+        }
+
+        return returnList;
+    }
+
+    /**
+     * A helper method to check if all repository nodes have a database
+     * relation. If a node is found which is not in the database, the node will
+     * be deleted.
+     *
+     * @param userLogin
+     * @return
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    public static void cleanJcrRepository(Delegator delegator, GenericValue userLogin) throws RepositoryException, GenericEntityException {
+        Session session = null;
+        List<Map<String, String>> nodesList = null;
+        try {
+            session = JackrabbitContainer.getUserSession(userLogin);
+            nodesList = getRepositoryNodes(session, null);
+            for (Map<String, String> node : nodesList) {
+                String nodePath = node.get("repositoryNode");
+                if (UtilValidate.isEmpty(nodePath)) {
+                    continue;
+                }
+
+                // if the node path is a jcr:system node than ignore this
+                // entry
+                if (nodePath.startsWith("/jcr:system")) {
+                    continue;
+                }
+
+                List<GenericValue> contentList = delegator.findByAnd("Content", UtilMisc.toMap("repositoryNode", nodePath));
+
+                // if the List is Empty there is node connection between the
+                // node and the database, so this node is a dead node an
+                // will be deleted.
+                if (UtilValidate.isEmpty(contentList)) {
+                    Node n = session.getNode(nodePath);
+                    n.remove();
+                }
+
+            }
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            throw new RepositoryException(e);
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            throw new GenericEntityException(e);
+        }
+        finally {
+            try {
+                session.save();
+            }
+            catch (RepositoryException e) {
+                Debug.logError(e, module);
+                throw new RepositoryException(e);
+            }
+            session.logout();
+        }
+    }
+
+    /**
+     * Just a dummy method to list all nodes in the repository.
+     *
+     * @param startNodePath
+     * @return
+     * @throws RepositoryException
+     */
+    private static List<Map<String, String>> getRepositoryNodes(Session session, String startNodePath) throws RepositoryException {
+        Node node = null;
+
+        List<Map<String, String>> nodeList = FastList.newInstance();
+        if (UtilValidate.isEmpty(startNodePath)) {
+            node = session.getRootNode();
+        } else {
+            node = session.getNode(startNodePath);
+        }
+
+        NodeIterator nodeIterator = node.getNodes();
+        Map<String, String> nodeEntry = null;
+        while (nodeIterator.hasNext()) {
+            Node n = nodeIterator.nextNode();
+
+            // recursion - get all subnodes and add the results to our nodeList
+            if (n.getNodes().hasNext()) {
+                nodeList.addAll(getRepositoryNodes(session, n.getPath()));
+            }
+
+            nodeEntry = FastMap.newInstance();
+
+            nodeEntry.put("repositoryNode", n.getPath());
+
+            String message = null;
+            if (n.hasProperty("jcr:message")) {
+                message = n.getProperty("jcr:message").getString();
+            } else {
+                message = new String();
+            }
+            nodeEntry.put("nodeContent", message);
+            nodeEntry.put("primaryNodeType", n.getPrimaryNodeType().getName());
+
+            nodeList.add(nodeEntry);
+        }
+
+        return nodeList;
+    }
+
+}

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,234 @@
+package org.ofbiz.content.jcr.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.http.HttpServletRequest;
+
+import net.sf.json.JSONArray;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.content.jcr.orm.OfbizRepositoryMappingJackrabbit;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.JackrabbitContainer;
+import org.ofbiz.jcr.helper.JcrFileHelper;
+import org.ofbiz.jcr.helper.JcrFileHelperAbstract;
+
+public class JcrFileHelperJackrabbit extends JcrFileHelperAbstract implements JcrFileHelper {
+
+ private static String fileRootNode = "/fileHome";
+
+ /**
+ * The JcrHelper constructor loads the node and linked content data from the
+ * DB. You can pass a contentId *OR* a node path. Primary the constructor
+ * will take a contentId, get the content information from the database and
+ * read the linked repository node from the database. If you pass a
+ * repository node path, the method will look in the database for a linked
+ * content entry. If none is found the constructor creates a *new* content
+ * node in the repository. All nodes creates by the JcrFileHelper
+ * constructor will be stored under a file home node. This file home node
+ * represents the root folder for each file.
+ *
+ * @param userLogin
+ * @param delegator
+ * @param contentId
+ * @param repositoryNode
+ */
+ public JcrFileHelperJackrabbit(GenericValue userLogin, Delegator delegator, String contentId, String repositoryNode) {
+ super.userLogin = userLogin;
+ if (userLogin == null || delegator == null) {
+ Debug.logError("You pass null for the UserLogin or Delegator, Object can't be created.", module);
+ return;
+ }
+
+ Session session = null;
+ try {
+ session = JackrabbitContainer.getUserSession(userLogin);
+ } catch (RepositoryException re) {
+ Debug.logError(re, module);
+ return;
+ }
+
+ // if neither a contentId nor a repositoryNode is set or the repository node is set to the root node
+ // we have to point the repository node to our file root node
+ if (UtilValidate.isEmpty(contentId) && (UtilValidate.isEmpty(repositoryNode) || "/".equals(repositoryNode))) {
+ repositoryNode = fileRootNode;
+ }
+
+ // add the file home node to the repository node if necessary
+ repositoryNode = addRepositoryFileHomeNode(repositoryNode);
+
+ try {
+ super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ return;
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ return;
+ }
+ }
+
+ /**
+ * The JcrHelper constructor loads the node and linked content data from the
+ * DB. You can pass a contentId *OR* a node path. Primary the constructor
+ * will take a contentId, get the content information from the database and
+ * read the related repository node from the database. If you pass a
+ * repository node path, the method will look in the database for a linked
+ * content entry. If none is found the constructor creates a *new* content
+ * node in the repository. The request object should contain the parameters:
+ * userLogin (GenericValue), contentId (String) *or* repositoryNode
+ * (String). All nodes creates by the JcrFileHelper constructor will be
+ * stored under a file home node. This file home node represents the root
+ * folder for each file.
+ *
+ * @param request
+ */
+ public JcrFileHelperJackrabbit(HttpServletRequest request) {
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+ super.userLogin = userLogin;
+
+ Session session = null;
+ try {
+ session = JackrabbitContainer.getUserSession(userLogin);
+ } catch (RepositoryException re) {
+ Debug.logError(re, module);
+ return;
+ }
+
+ String contentId = request.getParameter("contentId");
+ String repositoryNode = request.getParameter("repositoryNode");
+
+ // if neither a contentId nor a repositoryNode is set or the repository node is set to the root node
+ // we have to point the repository node to our file root node
+ if (UtilValidate.isEmpty(contentId) && (UtilValidate.isEmpty(repositoryNode) || "/".equals(repositoryNode))) {
+ repositoryNode = fileRootNode;
+ }
+
+ // add the file home node to the repository node if necessary
+ repositoryNode = addRepositoryFileHomeNode(repositoryNode);
+
+ Delegator delegator = (Delegator) request.getAttribute("delegator");
+ try {
+ super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ return;
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ return;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#uploadFileData(byte[],
+ * java.lang.String)
+ */
+ @Override
+ public GenericValue uploadFileData(byte[] file, String fileName) throws RepositoryException, GenericEntityException {
+ InputStream is = new ByteArrayInputStream(file);
+
+ orm.uploadFileData(is, fileName);
+ return orm.getContentObject();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.helper.JcrFileHelper#uploadFileData(java.io.InputStream,
+ * java.lang.String)
+ */
+ @Override
+ public GenericValue uploadFileData(InputStream file, String fileName) throws RepositoryException, GenericEntityException {
+ orm.uploadFileData(file, fileName);
+ return orm.getContentObject();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#getFileContent(java.lang.String)
+ */
+ @Override
+ public InputStream getFileContent(String fileName) throws RepositoryException {
+ return orm.getFileContent(fileName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#getFileContent()
+ */
+ @Override
+ public InputStream getFileContent() throws RepositoryException {
+ return orm.getFileContent();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#addNewNode(java.lang.String)
+ */
+ @Override
+ public JcrFileHelper addNewNode(String newNode) throws RepositoryException, GenericEntityException {
+ if (!newNode.startsWith("/")) {
+ newNode = "/" + newNode;
+ }
+
+ String newAbsoluteNodePath = orm.getNodePath() + newNode;
+
+ return new JcrFileHelperJackrabbit(userLogin, orm.getDelegator(), null, newAbsoluteNodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#getJsonFileTree(java.lang.String)
+ */
+ @Override
+ public JSONArray getJsonFileTree() throws RepositoryException {
+ return orm.getJsonFileTree();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.helper.JcrFileHelper#getFileMimeType()
+ */
+ @Override
+ public String getFileMimeType() throws RepositoryException{
+ return orm.getFileMimeType();
+ }
+
+ /**
+ * Adds the file home node to the repository node, if not already exists.
+ *
+ * @param repositoryNode
+ * @return
+ */
+ private String addRepositoryFileHomeNode(String repositoryNode) {
+ if (UtilValidate.isEmpty(repositoryNode)) {
+ return repositoryNode;
+ }
+
+ // check if the node already starts with the home node
+ if (repositoryNode.startsWith(fileRootNode)) {
+ return repositoryNode;
+ }
+
+ if (repositoryNode.startsWith("/")) {
+ return repositoryNode = fileRootNode + repositoryNode;
+ }
+
+ return fileRootNode + "/" + repositoryNode;
+ }
+
+}

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,120 @@
+package org.ofbiz.content.jcr.helper;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.http.HttpServletRequest;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.content.jcr.orm.OfbizRepositoryMappingJackrabbit;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.JackrabbitContainer;
+import org.ofbiz.jcr.helper.JcrTextHelper;
+import org.ofbiz.jcr.helper.JcrTextHelperAbstract;
+
+public class JcrTextHelperJackrabbit extends JcrTextHelperAbstract implements JcrTextHelper {
+
+    public JcrTextHelperJackrabbit(GenericValue userLogin, Delegator delegator, String contentId, String repositoryNode) {
+        super.userLogin = userLogin;
+        if (userLogin == null || delegator == null) {
+            Debug.logError("You pass null for the UserLogin or Delegator, Object can't be created.", module);
+            return;
+        }
+
+        Session session = null;
+        try {
+            session = JackrabbitContainer.getUserSession(userLogin);
+        }
+        catch (RepositoryException re) {
+            Debug.logError(re, module);
+            return;
+        }
+
+        try {
+            super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode);
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return;
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            return;
+        }
+    }
+
+    public JcrTextHelperJackrabbit(HttpServletRequest request) {
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+        super.userLogin = userLogin;
+
+        Session session = null;
+        try {
+            session = JackrabbitContainer.getUserSession(userLogin);
+        }
+        catch (RepositoryException re) {
+            Debug.logError(re, module);
+            return;
+        }
+
+        String contentId = request.getParameter("contentId");
+        String repositoryNode = request.getParameter("repositoryNode");
+
+        Delegator delegator = (Delegator) request.getAttribute("delegator");
+        try {
+            super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode);
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return;
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            return;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.ofbiz.jcr.helper.JcrTextHelper#storeNewTextData(java.lang.String)
+     */
+    @Override
+    public String storeNewTextData(String message) throws RepositoryException {
+        orm.updateOrStoreTextData(message);
+
+        return orm.getContentId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.ofbiz.jcr.helper.JcrTextHelper#getStringContent()
+     */
+    @Override
+    public String getTextData() throws PathNotFoundException, RepositoryException {
+        return orm.getStringContent();
+    }
+
+    /* (non-Javadoc)
+     * @see org.ofbiz.jcr.helper.JcrTextHelper#updateTextData(java.lang.String)
+     */
+    @Override
+    public String updateTextData(String message) throws PathNotFoundException, RepositoryException {
+        orm.updateOrStoreTextData(message);
+
+        return message;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.ofbiz.jcr.helper.JcrTextHelper#addNewNode(java.lang.String)
+     */
+    @Override
+    public JcrTextHelper addNewNode(String newNode) throws RepositoryException, GenericEntityException {
+        if (!newNode.startsWith("/")) {
+            newNode = "/" + newNode;
+        }
+
+        String newAbsoluteNodePath = orm.getNodePath() + newNode;
+
+        return new JcrTextHelperJackrabbit(userLogin, orm.getDelegator(), null, newAbsoluteNodePath);
+    }
+}

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,704 @@
+package org.ofbiz.content.jcr.orm;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import javolution.util.FastMap;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import org.apache.tika.Tika;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+
+public class OfbizRepositoryMappingJackrabbit implements OfbizRepositoryMapping {
+
+    private static String module = OfbizRepositoryMappingJackrabbit.class.getName();
+
+    private enum PROPERTY_FIELDS {
+        MESSAGE("jcr:message"), FILE(NodeType.NT_FILE), FOLDER(NodeType.NT_FOLDER), RESOURCE(NodeType.NT_RESOURCE), DATA("jcr:data"), UNSTRUCTURED(
+                NodeType.NT_UNSTRUCTURED), MIMETYPE("jcr:mimetype"), REPROOT("rep:root");
+
+        String type = null;
+
+        PROPERTY_FIELDS(String type) {
+            this.type = type;
+        }
+
+        String getType() {
+            return this.type;
+        }
+
+    };
+
+    private Delegator delegator = null;
+    private GenericValue content = null;
+    // private GenericValue contentAssoc = null;
+    private Session session = null;
+    private Node node = null;
+
+    /**
+     * The OfbizContentMapping constructor loads the node and related content
+     * data from the DB. You can pass a contentId *OR* a node path. Primary the
+     * constructor will take a contentId, get the content information from the
+     * database and read the related repository node from the database. If you
+     * pass a repository node path, the method will look in the database for a
+     * related content entry.
+     *
+     * @param delegator
+     * @param session
+     * @param contentId
+     * @param repositoryNode
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    public OfbizRepositoryMappingJackrabbit(Delegator delegator, Session session, String contentId, String repositoryNode) throws RepositoryException,
+            GenericEntityException {
+        if (session == null) {
+            Debug.logWarning("A repository session is needed to create an OfbizContentMapping Object.", module);
+            return;
+        } else if (UtilValidate.isEmpty(contentId) && UtilValidate.isEmpty(repositoryNode)) {
+            Debug.logWarning("There should be either a contentId or a repositoryNode", module);
+            return;
+        }
+
+        this.delegator = delegator;
+        this.session = session;
+
+        // check if the node path is an abolute path
+        if (!repositoryNode.startsWith("/")) {
+            repositoryNode = "/" + repositoryNode;
+        }
+
+        if (UtilValidate.isNotEmpty(contentId)) {
+            this.content = delegator.findOne("Content", true, UtilMisc.toMap("contentId", contentId));
+            this.node = getRepositoryNode(content.getString("repositoryNode"));
+
+        } else if (UtilValidate.isNotEmpty(repositoryNode)) {
+
+            List<GenericValue> contentList = delegator.findByAndCache("Content", UtilMisc.toMap("repositoryNode", repositoryNode));
+
+            // if the List is Empty there might be no repository node with
+            // this path information, so we have to create a new one
+            if (UtilValidate.isNotEmpty(contentList)) {
+                this.content = EntityUtil.getFirst(contentList);
+                this.node = getRepositoryNode(repositoryNode);
+            } else {
+                Map<String, Object> newRepositoryEntry = createNewRepositoryNode(repositoryNode);
+                this.node = (Node) newRepositoryEntry.get("node");
+                this.content = (GenericValue) newRepositoryEntry.get("content");
+                this.session.save();
+            }
+
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getDelegator()
+     */
+    @Override
+    public Delegator getDelegator() {
+        return delegator;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#closeSession()
+     */
+    @Override
+    public void closeSession() {
+        if (session != null && session.isLive()) {
+            session.logout();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.ofbiz.jcr.orm.OfbizContentMapping#updateTextData(java.lang.String)
+     */
+    @Override
+    public void updateOrStoreTextData(String message) throws RepositoryException {
+
+        this.node.setProperty(PROPERTY_FIELDS.MESSAGE.getType(), message);
+        this.session.save();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getContent()
+     */
+    @Override
+    public GenericValue getContentObject() {
+        return content;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getNode()
+     */
+    @Override
+    public Node getNode() {
+        return node;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getContentId()
+     */
+    @Override
+    public String getContentId() {
+        if (content != null) {
+            return content.getString("contentId");
+        } else {
+            return new String();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getNodePath()
+     */
+    @Override
+    public String getNodePath() {
+        try {
+            return node.getPath();
+        }
+        catch (RepositoryException e) {
+            return new String();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#removeRepositoryNode()
+     */
+    @Override
+    public void removeRepositoryNode() throws RepositoryException, GenericEntityException {
+        node.remove();
+        try {
+            GenericValue content = delegator.findOne("Content", false, UtilMisc.toMap("contentId", this.content.getString("contentId")));
+            List<GenericValue> relatedContents = getAllRelatedContents(content);
+            // TODO We should decide if we set a thru date or delete the
+            // resource
+            if (UtilValidate.isNotEmpty(relatedContents)) {
+                delegator.removeAll(relatedContents);
+            }
+            session.save();
+        }
+        catch (GenericEntityException e) {
+            throw new GenericEntityException(e);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getStringContent()
+     */
+    @Override
+    public String getStringContent() throws PathNotFoundException, RepositoryException {
+        Property property = getNodeContentProperty(PROPERTY_FIELDS.MESSAGE.getType());
+
+        if (property == null || property.getType() != 1) {
+            Debug.logWarning("The content from the node:" + node.getPath() + " is not a String content.", module);
+            return new String();
+        }
+
+        return property.getString();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#uploadFileData()
+     */
+    @Override
+    public void uploadFileData(InputStream file, String fileName) throws PathNotFoundException, RepositoryException, GenericEntityException {
+        try {
+            this.node.setPrimaryType(PROPERTY_FIELDS.FOLDER.getType());
+        }
+        catch (RepositoryException e) {
+            Debug.logError("Appanding a file to a text content is not allowed. Please create a folder which haven't a text node as parent.", module);
+            throw new RepositoryException("Appanding a file to a text content is not allowed. Please create a folder which haven't a text node as parent.", e);
+        }
+
+        Node folder = (Node) createNewRepositoryNode(this.node.getPath() + "/" + fileName, PROPERTY_FIELDS.FILE.getType()).get("node");
+
+        Node resource = (Node) createNewRepositoryNode(folder.getPath() + "/jcr:content", PROPERTY_FIELDS.RESOURCE.getType()).get("node");
+        Binary binary = this.session.getValueFactory().createBinary(file);
+
+        String mimeType = getMimeTypeFromInputStream(file);
+
+        resource.setProperty("jcr:mimeType", mimeType);
+        // resource.setProperty("jcr:encoding", "");
+
+        resource.setProperty(PROPERTY_FIELDS.DATA.getType(), binary);
+        this.session.save();
+
+        return;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getFileContent()
+     */
+    @Override
+    public InputStream getFileContent(String fileName) throws RepositoryException {
+        if (!this.node.getPrimaryNodeType().isNodeType(PROPERTY_FIELDS.FOLDER.getType())) {
+            Debug.logWarning("The Node: " + this.node.getPath() + " is not a node from type: " + PROPERTY_FIELDS.FOLDER.getType()
+                             + ". No OutputStream can retunred.", module);
+            return null;
+        }
+
+        if (!this.node.hasNode(fileName)) {
+            throw new RepositoryException("This file does not exists in the folder");
+        }
+
+        Node fileNode = this.node.getNode(fileName);
+
+        Node jcrContent = fileNode.getNode("jcr:content");
+        if (!jcrContent.hasProperty(PROPERTY_FIELDS.DATA.getType())) {
+            Debug.logWarning("No File Content found in repository node.", module);
+            return null;
+        }
+
+        return jcrContent.getProperty(PROPERTY_FIELDS.DATA.getType()).getBinary().getStream();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getFileContent()
+     */
+    @Override
+    public InputStream getFileContent() throws RepositoryException {
+        if (!this.node.getPrimaryNodeType().isNodeType(PROPERTY_FIELDS.FILE.getType())) {
+            Debug.logWarning("The Node: " + this.node.getPath() + " is not a node from type: " + PROPERTY_FIELDS.FILE.getType()
+                             + ". No OutputStream can retunred.", module);
+            return null;
+        }
+
+        Node jcrContent = this.node.getNode("jcr:content");
+        if (!jcrContent.hasProperty(PROPERTY_FIELDS.DATA.getType())) {
+            Debug.logWarning("No File Content found in repository node.", module);
+            return null;
+        }
+
+        return jcrContent.getProperty(PROPERTY_FIELDS.DATA.getType()).getBinary().getStream();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getJsonFileTree()
+     */
+    @Override
+    public JSONArray getJsonFileTree() throws RepositoryException {
+        return getJsonChildNodes(this.node);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getNodeName()
+     */
+    @Override
+    public String getNodeName() {
+        try {
+            return this.node.getName();
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            return new String();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.orm.OfbizContentMapping#getFileMimeType()
+     */
+    @Override
+    public String getFileMimeType() throws RepositoryException {
+        String mimeType = new String();
+
+        if (!this.node.getPrimaryNodeType().isNodeType(PROPERTY_FIELDS.FILE.getType())) {
+            Debug.logWarning("The Node: " + this.node.getPath() + " is not a node from type: " + PROPERTY_FIELDS.FILE.getType()
+                             + ". No OutputStream can retunred.", module);
+            return mimeType;
+        }
+
+        Node jcrContent = this.node.getNode("jcr:content");
+        if (!jcrContent.hasProperty(PROPERTY_FIELDS.DATA.getType())) {
+            Debug.logWarning("No File Content found in repository node.", module);
+            return mimeType;
+        }
+
+        if (jcrContent.hasProperty(PROPERTY_FIELDS.MIMETYPE.getType())) {
+            mimeType = jcrContent.getProperty(PROPERTY_FIELDS.MIMETYPE.getType()).getString();
+        }
+
+        return mimeType;
+    }
+
+    /**
+     * Returns a JSON Array with the repository folder structure. The JSON array
+     * is directly build for the jsTree jQuery plugin.
+     *
+     * @param startNode
+     * @return
+     * @throws RepositoryException
+     */
+    private JSONArray getJsonChildNodes(Node startNode) throws RepositoryException {
+        NodeIterator nodeIterator = startNode.getNodes();
+
+        JSONArray folderStrucutre = new JSONArray();
+        JSONObject attr = new JSONObject();
+
+        while (nodeIterator.hasNext()) {
+            JSONObject folder = new JSONObject();
+            Node node = nodeIterator.nextNode();
+
+            if (node.getPrimaryNodeType().isNodeType(PROPERTY_FIELDS.FOLDER.getType())) {
+                attr.element("title", node.getName());
+                folder.element("data", attr);
+
+                attr = new JSONObject();
+                attr.element("NodePath", node.getPath());
+                attr.element("NodeType", node.getPrimaryNodeType().getName());
+                folder.element("attr", attr);
+
+                folder.element("children", getJsonChildNodes(node).toString());
+
+                folderStrucutre.element(folder);
+            } else if (node.getPrimaryNodeType().isNodeType(PROPERTY_FIELDS.FILE.getType())) {
+                attr = new JSONObject();
+                attr.element("title", node.getName());
+                folder.element("data", attr);
+
+                attr = new JSONObject();
+                attr.element("NodePath", node.getPath());
+                attr.element("NodeType", node.getPrimaryNodeType().getName());
+                folder.element("attr", attr);
+
+                folderStrucutre.element(folder);
+            }
+
+        }
+
+        return folderStrucutre;
+    }
+
+    /**
+     * Get a property to a node, if this property not exist null will be
+     * returned.
+     *
+     * @return
+     * @throws PathNotFoundException
+     * @throws RepositoryException
+     */
+    private Property getNodeContentProperty(String type) throws PathNotFoundException, RepositoryException {
+        if (!node.hasProperty(type)) {
+            return null;
+        }
+
+        return node.getProperty(type);
+    }
+
+    /**
+     * Create a new node in the repository. The new node will be linked with an
+     * content object. The method can create recursive node structures.
+     * Recursive node associations will be stored in the ContentAssoc table
+     *
+     * @param newNodePath
+     *            - have to be an absolute path
+     * @return returned a map with the last created content and node object. The
+     *         objects are stored with the key "content" and "node"
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    private Map<String, Object> createNewRepositoryNode(String newNodePath) throws RepositoryException, GenericEntityException {
+        return createNewRepositoryNode(newNodePath, null);
+    }
+
+    /**
+     * Create a new node in the repository. The new node will be linked with an
+     * content object. The method can create recursive node structures.
+     * Recursive node associations will be stored in the ContentAssoc table
+     *
+     * @param newNodePath
+     *            - have to be an absolute path
+     * @param type
+     *            - defines a primary type for the new node
+     * @return returned a map with the last created content and node object. The
+     *         objects are stored with the key "content" and "node"
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    private Map<String, Object> createNewRepositoryNode(String newNodePath, String type) throws RepositoryException, GenericEntityException {
+        Map<String, Object> returnMap = createNodeStructure(newNodePath, type);
+        return returnMap;
+    }
+
+    /**
+     * Returns a list of all (recursive) related content to the base content.
+     * The return list contains the ContentAssoc Objects as well as the Content
+     * Objects.
+     *
+     * @param content
+     * @return
+     */
+    private List<GenericValue> getAllRelatedContents(GenericValue content) {
+        List<GenericValue> returnList = null;
+
+        try {
+            returnList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", content.getString("contentId")));
+
+            if (UtilValidate.isNotEmpty(returnList)) {
+                List<GenericValue> tmpReturnList = returnList;
+                for (GenericValue c : tmpReturnList) {
+                    returnList.addAll(getAllRelatedContents(delegator.findOne("Content", false, UtilMisc.toMap("contentId", c.getString("contentIdTo")))));
+                }
+            }
+            // find all content assoc links where the current content object is
+            // the child object
+            returnList.addAll(delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentIdTo", content.getString("contentId"))));
+            returnList.add(content);
+
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return null;
+        }
+
+        return returnList;
+    }
+
+    /**
+     * Here we create a new node Structure, if you pass a node path like
+     * "/foo/baa/node" It will create first "/foo" and "/baa" as parent node and
+     * than node.
+     *
+     * @param newNode
+     *            Path
+     * @return returned a map with the last created content and node object. The
+     *         objects are stored with the key "content" and "node"
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    private Map<String, Object> createNodeStructure(String newNodes, String type) throws RepositoryException, GenericEntityException {
+        Map<String, Object> returnMap = FastMap.newInstance();
+        Node newNodeParent = this.session.getRootNode();
+        String assocContentId = null;
+        String parentContentId = null;
+        String[] nodes = newNodes.split("/");
+        for (String node : nodes) {
+            if (UtilValidate.isEmpty(node)) {
+                continue;
+            } else if (newNodeParent.hasNode(node)) {
+                newNodeParent = newNodeParent.getNode(node);
+                continue;
+            }
+
+            // If the current node is not the root node and has a parent node
+            // search for the parent content id.
+            if (!newNodeParent.getPath().equals("/") && UtilValidate.isEmpty(parentContentId) && UtilValidate.isEmpty(assocContentId)
+                && (newNodeParent.getParent() != null)) {
+                parentContentId = getParentNodeContentId(newNodeParent);
+            }
+
+            if (UtilValidate.isEmpty(type)) {
+                // If the nodeType is empty, add a node with the same node type
+                // as the parent node.
+                // Only when the parent node is the overall repository root
+                // node, we have to create a node without parent type.
+                String parentNodeType = newNodeParent.getPrimaryNodeType().getName();
+                if (!PROPERTY_FIELDS.REPROOT.getType().equals(parentNodeType)) {
+                    newNodeParent = newNodeParent.addNode(node, newNodeParent.getPrimaryNodeType().getName());
+                } else {
+                    newNodeParent = newNodeParent.addNode(node);
+                }
+            } else {
+                newNodeParent = newNodeParent.addNode(node, type);
+            }
+            GenericValue newContent = nodeContentDatabaseConnection(newNodeParent);
+            returnMap.put("content", newContent);
+            assocContentId = newContent.getString("contentId");
+
+            // create the content assoc entry for the new node parent - child
+            // relation
+            if (UtilValidate.isNotEmpty(assocContentId) && UtilValidate.isNotEmpty(parentContentId)) {
+                nodeContentAssoc(assocContentId, parentContentId);
+                parentContentId = assocContentId;
+            }
+
+        }
+
+        // only the last node which is created will be returned
+        returnMap.put("node", newNodeParent);
+        return returnMap;
+    }
+
+    /**
+     * Creates the database relationship between two nodes.
+     *
+     * @param assocContentId
+     * @param parentContentId
+     */
+    private void nodeContentAssoc(String assocContentId, String parentContentId) {
+        GenericValue contentAssoc = delegator.makeValue("ContentAssoc");
+
+        contentAssoc.set("contentId", parentContentId);
+        contentAssoc.set("contentIdTo", assocContentId);
+        contentAssoc.set("contentAssocTypeId", "REPOSITORY");
+        contentAssoc.set("fromDate", UtilDateTime.nowTimestamp());
+
+        try {
+            this.delegator.createOrStore(contentAssoc);
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+        }
+
+    }
+
+    /**
+     * Returns the contentId to a node.
+     *
+     * @param newNodeParent
+     * @return
+     */
+    private String getParentNodeContentId(Node newNodeParent) {
+        List<GenericValue> list = null;
+        String parentNodeContentId = null;
+        try {
+            list = delegator.findByAndCache("Content", UtilMisc.toMap("repositoryNode", newNodeParent.getPath()));
+            if (UtilValidate.isNotEmpty(list)) {
+                parentNodeContentId = EntityUtil.getFirst(list).getString("contentId");
+            }
+        }
+        catch (GenericEntityException e) {
+            Debug.logError(e, module);
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+        }
+
+        return parentNodeContentId;
+    }
+
+    /**
+     * Creates a database relation to a repository node. Returns the new
+     * contentId.
+     *
+     * @param newNode
+     * @return
+     * @throws RepositoryException
+     * @throws GenericEntityException
+     */
+    private GenericValue nodeContentDatabaseConnection(Node newNode) throws RepositoryException, GenericEntityException {
+        // create the content database connection
+        GenericValue content = null;
+        content = this.delegator.makeValue("Content");
+        String primaryKey = this.delegator.getNextSeqId("Content");
+        content.set("contentId", primaryKey);
+        content.set("contentTypeId", "REPOSITORY");
+
+        content.set("repositoryNode", newNode.getPath());
+
+        GenericValue newContent = null;
+        try {
+            newContent = this.delegator.createOrStore(content);
+            // only save the session when a new content value is created
+        }
+        catch (GenericEntityException e) {
+            throw new GenericEntityException(e);
+        }
+
+        return newContent;
+    }
+
+    /**
+     * Checks if the node is in the repository. An absolute path should be
+     * passed.
+     *
+     * @param absoluteNodePath
+     * @return
+     */
+    private Boolean isNodeInRepository(String absoluteNodePath) {
+        try {
+            if (this.session.nodeExists(absoluteNodePath)) {
+                return Boolean.TRUE;
+            }
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            return Boolean.FALSE;
+        }
+
+        return Boolean.FALSE;
+    }
+
+    /**
+     * Get the node object from the repository. If an exceptions rasises null
+     * will be returned.
+     *
+     * @param nodePath
+     * @return
+     */
+    private Node getRepositoryNode(String nodePath) {
+        try {
+            return session.getNode(nodePath);
+        }
+        catch (PathNotFoundException e) {
+            Debug.logError(e, module);
+            return null;
+        }
+        catch (RepositoryException e) {
+            Debug.logError(e, module);
+            return null;
+        }
+    }
+
+    private String getMimeTypeFromInputStream(InputStream is) {
+        Tika tika = new Tika();
+        try {
+            return tika.detect(is);
+        }
+        catch (IOException e) {
+            Debug.logError(e, module);
+            return new String();
+        }
+    }
+
+}

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java?rev=1094371&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java Mon Apr 18 09:08:14 2011
@@ -0,0 +1,135 @@
+/*
+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.ofbiz.content.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.content.jcr.JackrabbitWorker;
+import org.ofbiz.content.jcr.helper.JcrFileHelperJackrabbit;
+import org.ofbiz.content.jcr.helper.JcrTextHelperJackrabbit;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.helper.JcrFileHelper;
+import org.ofbiz.jcr.helper.JcrTextHelper;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
+public class JcrTests extends OFBizTestCase {
+
+    protected GenericValue userLogin = null;
+    protected JcrTextHelper jh = null;
+
+    public JcrTests(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
+        jh = new JcrTextHelperJackrabbit(userLogin, delegator, null, "/unitTestNode");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        jh.closeSession();
+    }
+
+    public void testRepositoryConstructor() throws Exception {
+        assertNotNull(jh);
+        assertNotNull(jh.getContentObject());
+    }
+
+    public void testCreateRepositoryNode() throws Exception {
+        GenericValue content = jh.getContentObject();
+        assertNotNull(content);
+        // check if the content object is correctly stored in the database
+        GenericValue contentCheck = delegator.findOne("Content", true, UtilMisc.toMap("contentId", content.getString("contentId")));
+
+        assertNotNull(contentCheck);
+    }
+
+    public void testAddTextContent() throws Exception {
+        jh.storeNewTextData("Hello World!");
+
+        assertEquals("Hello World!", jh.getTextData());
+    }
+
+    public void testCreateNewChildNodes() throws Exception {
+        JcrTextHelper subnode = jh.addNewNode("subNode");
+        assertNotNull(subnode);
+
+        String parentContentId = jh.getContentObject().getString("contentId");
+        String childContentId = subnode.getContentObject().getString("contentId");
+
+        List<GenericValue> list = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", parentContentId, "contentIdTo", childContentId));
+        assertNotNull(list);
+        if (UtilValidate.isEmpty(list) || list.size() != 1) {
+            assertTrue(false);
+        }
+        subnode.closeSession();
+
+        JcrTextHelper subsubnode = jh.addNewNode("/subNodeTwo/subSubNodeOne");
+        assertNotNull(subsubnode);
+        parentContentId = jh.getContentObject().getString("contentId");
+        childContentId = subnode.getContentObject().getString("contentId");
+
+        list = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", parentContentId, "contentIdTo", childContentId));
+        assertNotNull(list);
+        if (UtilValidate.isEmpty(list) || list.size() != 1) {
+            assertTrue(false);
+        }
+        subsubnode.closeSession();
+
+    }
+
+    public void testUploadFileToRepository() throws Exception {
+        File f = new File("build.xml");
+        assertTrue(f.exists());
+
+        InputStream file = new FileInputStream(f);
+
+        JcrFileHelper uf = new JcrFileHelperJackrabbit(userLogin, delegator, null, "/unitTestFolder");
+
+        GenericValue newFile = uf.uploadFileData(file, f.getName());
+        assertNotNull(newFile);
+
+        InputStream rs = uf.getFileContent(f.getName());
+        assertNotNull(rs);
+
+        uf.removeRepositoryNode();
+        uf.closeSession();
+    }
+
+    public void testRemoveRepositoryNode() throws Exception {
+        jh.removeRepositoryNode();
+
+        assertNotNull(jh);
+    }
+
+    public void testListRepositoryNodes() throws Exception {
+        assertNotNull(JackrabbitWorker.getRepositoryNodes(userLogin, null));
+    }
+
+    public void testCleanRepositoryStructure() throws Exception {
+        JackrabbitWorker.cleanJcrRepository(delegator, userLogin);
+    }
+}
\ No newline at end of file

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Mon Apr 18 09:08:14 2011
@@ -101,6 +101,7 @@ under the License.
         <property name="repHomeDir" value="runtime/data/jackrabbit/"/>
         <property name="configFilePath" value="framework/jcr/config/jackrabbit.xml"/>
         <property name="jndiName" value="jcr/local"/>
+        <property name="removeOnShutdown" value="false"></property>
     </container>
 
     <container name="catalina-container" class="org.ofbiz.catalina.container.CatalinaContainer">

Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml Mon Apr 18 09:08:14 2011
@@ -62,6 +62,15 @@ under the License.
     </container>
      -->
 
+    <!-- Load embedded Jackrabbit content repository. Since this container depends
+    upon JNDI, it must be started after the naming-container container.-->
+    <container name="jcr-container" class="org.ofbiz.jcr.JackrabbitContainer">
+        <property name="repHomeDir" value="runtime/data/jackrabbitTest/"/>
+        <property name="configFilePath" value="framework/jcr/config/jackrabbit.xml"/>
+        <property name="jndiName" value="jcr/local"/>
+        <property name="removeOnShutdown" value="true"></property>
+    </container>
+
     <!-- load catalina (tomcat) and all web applications -->
     <container name="catalina-container" class="org.ofbiz.catalina.container.CatalinaContainer">
         <!-- static configuration for tomcat -->

Modified: ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml Mon Apr 18 09:08:14 2011
@@ -722,6 +722,10 @@
         <value xml:lang="th">แก้ไขสินค้าตัวอย่าง</value>
         <value xml:lang="zh">编辑样例明细</value>
     </property>
+    <property key="PageTitleExampleJackrabbit">
+        <value xml:lang="de">Jackrabbit Sandbox</value>
+        <value xml:lang="en">Jackrabbit Sandbox</value>
+    </property>
     <!-- Page Titles -->
     <property key="PageTitleFindExample">
         <value xml:lang="en">Find Example</value>
@@ -761,4 +765,64 @@
         <value xml:lang="de">Sie haben den Wert in der Select Box geändert.</value>
         <value xml:lang="en">You have changed the value in the select box</value>
     </property>
+    <property key="ExampleAddNewContentEntry">
+        <value xml:lang="de">Einen neuen Content Eintrag hinzufügen</value>
+        <value xml:lang="en">Add a new content entry</value>
+    </property>
+    <property key="ExampleRepositoryNode">
+        <value xml:lang="de">Knoten</value>
+        <value xml:lang="en">Node</value>
+    </property>
+    <property key="ExampleRepositoryFolder">
+        <value xml:lang="de">Ordner</value>
+        <value xml:lang="en">Folder</value>
+    </property>
+    <property key="ExampleRepositoryFile">
+        <value xml:lang="de">Datei</value>
+        <value xml:lang="en">File</value>
+    </property>
+    <property key="ExampleRepositoryMessage">
+        <value xml:lang="de">Text Nachricht</value>
+        <value xml:lang="en">Text message</value>
+    </property>
+    <property key="ExampleScanRepositoryStrukture">
+        <value xml:lang="de">Repository Struktur überprüfen</value>
+        <value xml:lang="en">Scan repository structure</value>
+    </property>
+    <property key="ExampleJackrabbitUploadFileData">
+        <value xml:lang="de">Eine neue Datei speichern</value>
+        <value xml:lang="en">Upload a new file</value>
+    </property>
+    <property key="ExampleJackrabbitCleanRepository">
+        <value xml:lang="de">Repository aufräumen</value>
+        <value xml:lang="en">Clean repository</value>
+    </property>
+    <property key="ExampleJackrabbitShowUploadedFiles">
+        <value xml:lang="de">Dateien anzeigen</value>
+        <value xml:lang="en">Show uploaded Files</value>
+    </property>
+    <property key="ExampelsJackrabbitOpenFile">
+        <value xml:lang="de">Datei öffnen</value>
+        <value xml:lang="en">Open file</value>
+    </property>
+    <property key="ExampelsJackrabbitDownloadFile">
+        <value xml:lang="de">Datei herunterladen</value>
+        <value xml:lang="en">Download file</value>
+    </property>
+    <property key="ExampelsJackrabbitRemoveFile">
+        <value xml:lang="de">Datei löschen</value>
+        <value xml:lang="en">Remove file</value>
+    </property>
+    <property key="ExampleAddNewNodePath">
+        <value xml:lang="de">Füge einen neuen Node Pfad hinzu, z.B. /Foo/Baa speichert die Datei im Ordner "Baa"</value>
+        <value xml:lang="en">Add a (new) node path like /Foo/Baa will store the file under the folder "Baa"</value>
+    </property>
+    <property key="ExampleJackrabbitTryRightClick">
+        <value xml:lang="de">Wähle eine Datei und versuche einen Rechtklick</value>
+        <value xml:lang="en">Choose a file and try a 'right click'</value>
+    </property>
+    <property key="ExampleJackrabbitCleanRepositoryTooltip">
+        <value xml:lang="de">Löscht alle Nodes aus dem Repository, die keine Verkünpfung in der Content Tabelle haben.</value>
+        <value xml:lang="en">Removes all nodes which are not linked in the content table.</value>
+    </property>
 </resource>

Modified: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml?rev=1094371&r1=1094370&r2=1094371&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml Mon Apr 18 09:08:14 2011
@@ -236,6 +236,83 @@ under the License.
     </request-map>
     <!-- end of request mappings -->
 
+    <!-- Jackrabbit Example Requests -->
+    <request-map uri="ExampleJackrabbit">
+        <security auth="true" https="true" />
+        <response name="success" type="view" value="ExampleJackrabbit" />
+        <response name="error" type="view" value="ExampleJackrabbit" />
+    </request-map>
+    <request-map uri="ExampleJackrabbitAddData">
+        <security auth="true" https="true" />
+        <response name="success" type="view" value="ExampleJackrabbitAddData" />
+        <response name="error" type="view" value="ExampleJackrabbitAddData" />
+    </request-map>
+    <request-map uri="StoreNewRepositoryData">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="addNewTextMessageToJcrRepository"/>
+        <response name="success" type="request" value="ExampleJackrabbit" />
+        <response name="error" type="view" value="ExampleJackrabbitAddData" />
+    </request-map>
+    <request-map uri="ExampleJackrabbitScanRepositoryStructure">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="scanRepositoryStructure"/>
+        <response name="success" type="view" value="ExampleJackrabbitScanRepositoryStructure" />
+        <response name="error" type="view" value="ExampleJackrabbitScanRepositoryStructure" />
+    </request-map>
+    <request-map uri="EditRepositoryContent">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getNodeContent"/>
+        <response name="success" type="view" value="ExampleJackrabbitEditRepositoryContent" />
+        <response name="error" type="view" value="ExampleJackrabbitEditeRepositoryContent" />
+    </request-map>
+    <request-map uri="UpdateRepositoryData">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="updateRepositoryData"/>
+        <response name="success" type="request" value="EditRepositoryContent" />
+        <response name="error" type="request" value="EditRepositoryContent" />
+    </request-map>
+    <request-map uri="RemoveRepositoryNode">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryNode"/>
+        <response name="success" type="request" value="ExampleJackrabbit" />
+        <response name="error" type="request" value="ExampleJackrabbit" />
+    </request-map>
+    <request-map uri="RemoveRepositoryFile">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryFileNode"/>
+        <response name="success" type="request" value="ExampleJackrabbitShowUploadedFiles" />
+        <response name="error" type="request" value="ExampleJackrabbitShowUploadedFiles" />
+    </request-map>
+    <request-map uri="CleanJcrRepository">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="cleanJcrRepository"/>
+        <response name="success" type="request-redirect-noparam" value="ExampleJackrabbitScanRepositoryStructure" />
+        <response name="error" type="request-redirect-noparam" value="ExampleJackrabbitScanRepositoryStructure" />
+    </request-map>
+    <request-map uri="ExampleJackrabbitUploadFileData">
+        <security auth="true" https="true" />
+        <response name="success" type="view" value="ExampleJackrabbitUploadFileData" />
+        <response name="error" type="view" value="ExampleJackrabbitUploadFileData" />
+    </request-map>
+    <request-map uri="StoreNewRepositoryFileData">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="uploadFileData"/>
+        <response name="success" type="request" value="ExampleJackrabbitShowUploadedFiles" />
+        <response name="error" type="view" value="ExampleJackrabbitUploadFileData" />
+    </request-map>
+    <request-map uri="ExampleJackrabbitShowUploadedFiles">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getRepositoryFileTree"/>
+        <response name="success" type="view" value="ExampleJackrabbitShowUploadedFiles" />
+        <response name="error" type="view" value="ExampleJackrabbitShowUploadedFiles" />
+    </request-map>
+    <request-map uri="GetFileFromRepository">
+        <security auth="true" https="true" />
+        <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getFileFromRepository"/>
+        <response name="success" type="none" />
+        <response name="error" type="none" />
+    </request-map>
+
     <!-- View Mappings -->
     <view-map name="main" type="screen" page="component://example/widget/example/CommonScreens.xml#main"/>
 
@@ -280,6 +357,15 @@ under the License.
     <view-map name="ExampleBarChart" page="component://example/widget/example/ExampleScreens.xml#ExampleBarChart" type="screen"/>
     <view-map name="ExamplePieChart" page="component://example/widget/example/ExampleScreens.xml#ExamplePieChart" type="screen"/>
 
+    <!-- Jackrabbit View Mapping -->
+    <view-map name="ExampleJackrabbit" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ListRepositoryData" type="screen" />
+    <view-map name="ExampleJackrabbitAddData" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitAddData" type="screen" />
+    <view-map name="ExampleJackrabbitScanRepositoryStructure" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitScanRepositoryStructure" type="screen" />
+    <view-map name="ExampleJackrabbitEditRepositoryContent" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitEditRepositoryContent" type="screen" />
+    <view-map name="ExampleJackrabbitUploadFileData" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitUploadFileData" type="screen" />
+    <view-map name="ExampleJackrabbitShowUploadedFiles" page="component://example/widget/example/ExampleJackrabbitScreens.xml#ExampleJackrabbitShowUploadedFiles" type="screen" />
+
+
     <!-- Supported Content Types -->
     <!--
         text/html