svn commit: r1135587 - in /ofbiz/branches/jackrabbit20100709: applications/content/src/org/ofbiz/content/jcr/ applications/content/src/org/ofbiz/content/jcr/helper/ applications/content/src/org/ofbiz/content/jcr/orm/ applications/content/src/org/ofbiz/...

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

svn commit: r1135587 - in /ofbiz/branches/jackrabbit20100709: applications/content/src/org/ofbiz/content/jcr/ applications/content/src/org/ofbiz/content/jcr/helper/ applications/content/src/org/ofbiz/content/jcr/orm/ applications/content/src/org/ofbiz/...

sascharodekamp
Author: sascharodekamp
Date: Tue Jun 14 14:15:06 2011
New Revision: 1135587

URL: http://svn.apache.org/viewvc?rev=1135587&view=rev
Log:
Refactor - Refactored the JCR container startup process. Make the loading of the used JCR implementation more abstract, that the specific implementation can be configured via xml file.

Added:
    ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java   (with props)
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java   (with props)
Removed:
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java
Modified:
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java
    ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml
    ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml
    ofbiz/branches/jackrabbit20100709/runtime/data/   (props changed)

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java Tue Jun 14 14:15:06 2011
@@ -1,5 +1,6 @@
 package org.ofbiz.content.jcr;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -20,6 +21,7 @@ import org.apache.commons.fileupload.Fil
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.io.IOUtils;
+import org.apache.tika.Tika;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.FileUtil;
 import org.ofbiz.base.util.StringUtil;
@@ -318,6 +320,16 @@ public class JackrabbitEvents {
 
         JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit((GenericValue) request.getSession().getAttribute("userLogin"), (Delegator) request.getAttribute("delegator"), null, passedParams.get("repositoryNode"));
 
+InputStream i = new ByteArrayInputStream(file);
+Tika tika = new Tika();
+try {
+    String mt = tika.detect(i);
+} catch (IOException e1) {
+    // TODO Auto-generated catch block
+    e1.printStackTrace();
+}
+
+
         if (file != null && file.length >= 1) {
             try {
                 jackrabbit.uploadFileData(file, passedParams.get("completeFileName"), passedParams.get("fileLocale"), passedParams.get("description"));

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java Tue Jun 14 14:15:06 2011
@@ -1,5 +1,6 @@
 package org.ofbiz.content.jcr;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -7,6 +8,7 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.version.VersionManager;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
@@ -17,7 +19,7 @@ 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;
+import org.ofbiz.jcr.JCRFactoryUtil;
 
 public class JackrabbitWorker {
 
@@ -32,9 +34,8 @@ public class JackrabbitWorker {
      */
     public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException {
         List<Map<String, String>> returnList = null;
-        Session session = null;
+        Session session = JCRFactoryUtil.getSession();
         try {
-            session = JackrabbitContainer.getUserSession(userLogin);
             returnList = getRepositoryNodes(session, startNodePath);
         } catch (RepositoryException e) {
             throw new RepositoryException(e);
@@ -56,10 +57,9 @@ public class JackrabbitWorker {
      * @throws GenericEntityException
      */
     public static void cleanJcrRepository(Delegator delegator, GenericValue userLogin) throws RepositoryException, GenericEntityException {
-        Session session = null;
+        Session session = JCRFactoryUtil.getSession();
         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");
@@ -80,6 +80,7 @@ public class JackrabbitWorker {
                 // will be deleted.
                 if (UtilValidate.isEmpty(contentList)) {
                     Node n = session.getNode(nodePath);
+                    checkOutRelatedNodes(n, session);
                     n.remove();
                 }
 
@@ -147,4 +148,34 @@ public class JackrabbitWorker {
         return nodeList;
     }
 
+    private static void checkOutRelatedNodes(Node startNode, Session session) throws RepositoryException {
+        List<Node> nodesToCheckOut = new ArrayList<Node>();
+        nodesToCheckOut.add(startNode);
+        nodesToCheckOut.add(startNode.getParent());
+        if (startNode.hasNodes()) {
+            nodesToCheckOut.addAll(getAllChildNodes(startNode));
+        }
+
+        VersionManager vm = session.getWorkspace().getVersionManager();
+        for (Node node : nodesToCheckOut) {
+            vm.checkout(node.getPath());
+        }
+
+    }
+
+    private static List<Node> getAllChildNodes(Node startNode) throws RepositoryException {
+        List<Node> nodes = new ArrayList<Node>();
+        NodeIterator ni = startNode.getNodes();
+        while (ni.hasNext()) {
+            Node nextNode = ni.nextNode();
+            if (nextNode.hasNodes()) {
+                nodes.addAll(getAllChildNodes(nextNode));
+            }
+
+            nodes.add(nextNode);
+        }
+
+        return nodes;
+    }
+
 }

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelperJackrabbit.java Tue Jun 14 14:15:06 2011
@@ -16,7 +16,7 @@ import org.ofbiz.content.jcr.orm.OfbizRe
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.jcr.JackrabbitContainer;
+import org.ofbiz.jcr.JCRFactoryUtil;
 import org.ofbiz.jcr.helper.JcrFileHelper;
 import org.ofbiz.jcr.helper.JcrFileHelperAbstract;
 
@@ -48,13 +48,7 @@ public class JcrFileHelperJackrabbit ext
             return;
         }
 
-        Session session = null;
-        try {
-            session = JackrabbitContainer.getUserSession(userLogin);
-        } catch (RepositoryException re) {
-            Debug.logError(re, module);
-            return;
-        }
+        Session session = JCRFactoryUtil.getSession();
 
         // if neither a contentId nor a repositoryNode is set or the repository
         // node is set to the root node
@@ -96,13 +90,7 @@ public class JcrFileHelperJackrabbit ext
         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;
-        }
+        Session session = JCRFactoryUtil.getSession();
 
         String contentId = request.getParameter("contentId");
         String repositoryNode = request.getParameter("repositoryNode");

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java Tue Jun 14 14:15:06 2011
@@ -14,7 +14,7 @@ import org.ofbiz.content.jcr.orm.OfbizRe
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.jcr.JackrabbitContainer;
+import org.ofbiz.jcr.JCRFactoryUtil;
 import org.ofbiz.jcr.helper.JcrTextHelper;
 import org.ofbiz.jcr.helper.JcrTextHelperAbstract;
 
@@ -27,13 +27,7 @@ public class JcrTextHelperJackrabbit ext
             return;
         }
 
-        Session session = null;
-        try {
-            session = JackrabbitContainer.getUserSession(userLogin);
-        } catch (RepositoryException re) {
-            Debug.logError(re, module);
-            return;
-        }
+        Session session = JCRFactoryUtil.getSession();
 
         try {
             super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode, OfbizRepositoryMappingJackrabbit.NODE_TYPE.DATA);
@@ -50,13 +44,7 @@ public class JcrTextHelperJackrabbit ext
         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;
-        }
+        Session session = JCRFactoryUtil.getSession();
 
         String contentId = request.getParameter("contentId");
         String repositoryNode = request.getParameter("repositoryNode");

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java Tue Jun 14 14:15:06 2011
@@ -697,7 +697,7 @@ public class OfbizRepositoryMappingJackr
                 }
             }
 
-            // reset the node store after everythink is chcked in
+            // reset the node store after everything is checked in
             checkedOutNodeStore = new ArrayList<Node>();
         } catch (RepositoryException e) {
             Debug.logError(e, module);

Modified: 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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java Tue Jun 14 14:15:06 2011
@@ -132,6 +132,8 @@ public class JcrTests extends OFBizTestC
         InputStream rs = uf.getFileContent(f.getName());
         assertNotNull(rs);
 
+        uf.removeRepositoryNode();
+
         uf.closeSession();
     }
 

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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Tue Jun 14 14:15:06 2011
@@ -97,11 +97,9 @@ under the License.
 
     <!-- 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/jackrabbit/"/>
-        <property name="configFilePath" value="framework/jcr/config/jackrabbit.xml"/>
-        <property name="jndiName" value="jcr/local"/>
-        <property name="removeOnShutdown" value="false"></property>
+    <container name="jcr-container" class="org.ofbiz.jcr.JCRContainer">
+        <property name="configFilePath" value="framework/jcr/config/jcr-config.xml"/>
+        <property name="removeOnShutdown" value="false"/>
     </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=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml Tue Jun 14 14:15:06 2011
@@ -64,11 +64,9 @@ under the License.
 
     <!-- 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 name="jcr-container" class="org.ofbiz.jcr.JCRContainer">
+        <property name="configFilePath" value="framework/jcr/config/jcr-test-config.xml"/>
+        <property name="removeOnShutdown" value="true"/>
     </container>
 
     <!-- load catalina (tomcat) and all web applications -->

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml?rev=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml Tue Jun 14 14:15:06 2011
@@ -38,6 +38,7 @@ under the License.
         <fileset dir="../../framework/webapp/lib" includes="*.jar"/>
         <fileset dir="../../framework/entity/build/lib" includes="*.jar"/>
         <fileset dir="../../framework/service/build/lib" includes="*.jar"/>
+        <fileset dir="../../framework/security/build/lib" includes="*.jar"/>
     </path>
 
     <target name="jar" depends="classes">

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml?rev=1135587&r1=1135586&r2=1135587&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml Tue Jun 14 14:15:06 2011
@@ -37,8 +37,10 @@
     <!--
         data store configuration
     -->
-    <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
-
+    <DataStore class="org.apache.jackrabbit.core.data.FileDataStore" >
+        <param name="path" value="${rep.home}/repository/datastore"/>
+        <param name="minRecordLength" value="0"/>
+    </DataStore>
     <!--
         security configuration
     -->

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml Tue Jun 14 14:15:06 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+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.
+-->
+
+<jcr-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+    <!-- define the default jcr implementation, to be used -->
+    <jcr-context name="default" />
+
+    <!-- This is the default implementation and uses the JackRabbit implementation as its default -->
+    <jcr name="default" class="org.ofbiz.jcr.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local"/>
+
+    <!-- This is an example custom implementation and uses the class name specified as jcr implementation -->
+    <!--
+    <jcr name="myCustom" class="com.mycompany.jcr.MyCustomJCR"/>
+    -->
+
+    <!-- jcr home directory -->
+    <home-dir path="runtime/data/jcr/" />
+
+    <!-- config file for thr jcr implementation -->
+    <config-file-path path="framework/jcr/config/jackrabbit.xml" />
+
+    <!-- jcr workspace credentials -->
+    <jcr-credentials username="system" password="ofbiz" />
+
+</jcr-config>

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml Tue Jun 14 14:15:06 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+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.
+-->
+
+<jcr-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+    <!-- define the default jcr implementation, to be used -->
+    <jcr-context name="default" />
+
+    <!-- This is the default implementation and uses the JackRabbit implementation as its default -->
+    <jcr name="default" class="org.ofbiz.jcr.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local"/>
+
+    <!-- This is an example custom implementation and uses the class name specified as jcr implementation -->
+    <!--
+    <jcr name="myCustom" class="com.mycompany.jcr.MyCustomJCR"/>
+    -->
+
+    <!-- jcr home directory -->
+    <home-dir path="runtime/data/jcr-test/" />
+
+    <!-- config file for thr jcr implementation -->
+    <config-file-path path="framework/jcr/config/jackrabbit.xml" />
+
+    <!-- jcr workspace credentials -->
+    <jcr-credentials username="system" password="ofbiz" />
+
+</jcr-config>

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java Tue Jun 14 14:15:06 2011
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * 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.jcr;
+
+import javax.jcr.RepositoryException;
+
+import org.ofbiz.base.config.GenericConfigException;
+import org.ofbiz.base.config.ResourceLoader;
+import org.ofbiz.base.container.Container;
+import org.ofbiz.base.container.ContainerConfig;
+import org.ofbiz.base.container.ContainerException;
+import org.ofbiz.base.util.UtilXml;
+import org.w3c.dom.Element;
+
+/**
+ * A container for a local JCR-compliant content repository. The default
+ * implementation uses Apache Jackrabbit.
+ */
+public class JCRContainer implements Container {
+
+    public static final String module = JCRContainer.class.getName();
+
+    public static final String DEFAULT_JCR_CONFIG_PATH = "framework/jcr/config/jcr-config.xml";
+
+    private static String jndiName = null;
+    private static String factoryClassName = null;
+    private static String jcrContextName = null;
+
+    private String configFilePath = null;
+    private boolean removeRepositoryOnShutdown = false;
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.base.container.Container#init(java.lang.String[],
+     * java.lang.String)
+     */
+    @Override
+    public void init(String[] args, String configFile) throws ContainerException {
+        // get the container config
+        ContainerConfig.Container cc = ContainerConfig.getContainer("jcr-container", configFile);
+        if (cc == null) {
+            throw new ContainerException("No jcr-container configuration found in container config!");
+        }
+
+        // embedded properties
+        jndiName = ContainerConfig.getPropertyValue(cc, "jndiName", "jcr/local");
+        removeRepositoryOnShutdown = ContainerConfig.getPropertyValue(cc, "removeRepositoryOnShutdown", false);
+        configFilePath = ContainerConfig.getPropertyValue(cc, "configFilePath", DEFAULT_JCR_CONFIG_PATH);
+
+        Element configRootElement = null;
+        try {
+            configRootElement = ResourceLoader.getXmlRootElement(configFilePath);
+        } catch (GenericConfigException e) {
+            throw new ContainerException("Could not load the jcr configuration in file " + configFilePath, e);
+        }
+
+        if (configRootElement == null) {
+            throw new ContainerException("No jcr configuration found in file " + configFilePath);
+        }
+
+        Element childElement = UtilXml.firstChildElement(configRootElement, "jcr-context");
+        jcrContextName = UtilXml.elementAttribute(childElement, "name", "default");
+
+        // find the default JCR implementation
+        for (Element curElement : UtilXml.childElementList(configRootElement, "jcr")) {
+            if (jcrContextName.equals(curElement.getAttribute("name"))) {
+                factoryClassName = curElement.getAttribute("class");
+                break;
+            }
+        }
+
+        // get the default JCR factory
+        JCRFactory jcrFactory = JCRFactoryUtil.getJCRFactory();
+
+        if (jcrFactory == null) {
+            throw new ContainerException("Cannot load JCRFactory implementation class");
+        }
+
+        try {
+            jcrFactory.initialize(configRootElement);
+        } catch (RepositoryException e) {
+            throw new ContainerException("Cannot initialize JCRFactory context", e);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.base.container.Container#start()
+     */
+    @Override
+    public boolean start() throws ContainerException {
+        JCRFactory jcrFactory = JCRFactoryUtil.getJCRFactory();
+        if (jcrFactory == null) {
+            throw new ContainerException("Cannot load JCRFactory implementation class");
+        }
+
+        try {
+            jcrFactory.start();
+        } catch (RepositoryException e) {
+            throw new ContainerException("Cannot start JCRFactory context", e);
+        }
+
+        return true;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.base.container.Container#stop()
+     */
+    @Override
+    public void stop() throws ContainerException {
+        JCRFactory jcrFactory = JCRFactoryUtil.getJCRFactory();
+        if (jcrFactory == null) {
+            throw new ContainerException("Cannot load JCRFactory implementation class");
+        }
+
+        try {
+            jcrFactory.stop(removeRepositoryOnShutdown);
+        } catch (RepositoryException e) {
+            throw new ContainerException("Cannot stop JCRFactory context", e);
+        }
+    }
+
+    /**
+     * returns the class name of the JCRFactory implementation
+     *
+     * @return
+     */
+    public static String getFactoryClassName() {
+        return factoryClassName;
+    }
+}

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java Tue Jun 14 14:15:06 2011
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.jcr;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.w3c.dom.Element;
+
+public interface JCRFactory {
+
+    /**
+     *
+     * @param configRootElement
+     * @throws RepositoryException
+     */
+    public void initialize(Element configRootElement) throws RepositoryException;
+
+    /**
+     *
+     * @throws RepositoryException
+     */
+    public void start() throws RepositoryException;
+
+    /**
+     *
+     * @param removeRepositoryOnShutdown
+     * @throws RepositoryException
+     */
+    public void stop(boolean removeRepositoryOnShutdown) throws RepositoryException;
+
+    /**
+     *
+     * @param workspaceName
+     * @return
+     * @throws RepositoryException
+     */
+    public Session createSession() throws RepositoryException;
+
+    // public static final String WORKSPACE_NAME =
+    // PropsUtil.get(PropsKeys.JCR_WORKSPACE_NAME);
+    //
+    // public static final String NODE_DOCUMENTLIBRARY =
+    // PropsUtil.get(PropsKeys.JCR_NODE_DOCUMENTLIBRARY);
+
+}

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java Tue Jun 14 14:15:06 2011
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.jcr;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.security.SecurityFactory;
+
+public class JCRFactoryUtil {
+
+    public static final String module = JCRFactoryUtil.class.getName();
+
+    private static JCRFactory jcrFactory = null;
+
+    /**
+     *
+     * @return
+     */
+    public static JCRFactory getJCRFactory() {
+        if (jcrFactory == null) {
+
+            synchronized (SecurityFactory.class) {
+                if (jcrFactory == null) {
+
+                    ClassLoader loader = Thread.currentThread().getContextClassLoader();
+                    Class<?> c;
+                    try {
+                        c = loader.loadClass(JCRContainer.getFactoryClassName());
+                        jcrFactory = (JCRFactory) c.newInstance();
+                    } catch (ClassNotFoundException e) {
+                        Debug.logError(e, "Cannot get instance of the jcr implementation", module);
+                    } catch (InstantiationException e) {
+                        Debug.logError(e, "Cannot get instance of the jcr implementation", module);
+                    } catch (IllegalAccessException e) {
+                        Debug.logError(e, "Cannot get instance of the jcr implementation", module);
+                    }
+
+                }
+            }
+        }
+
+        return jcrFactory;
+    }
+
+    public static Session getSession() {
+        Session session = null;
+        try {
+            session = getJCRFactory().createSession();
+        } catch (RepositoryException e) {
+            Debug.logError(e, module);
+        }
+
+        return session;
+    }
+}

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java?rev=1135587&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java Tue Jun 14 14:15:06 2011
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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.jcr.jackrabbit;
+
+import java.io.File;
+
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.core.TransientRepository;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.jcr.JCRFactory;
+import org.w3c.dom.Element;
+
+public class JCRFactoryImpl implements JCRFactory {
+
+    public static final String module = JCRFactoryImpl.class.getName();
+
+    private static String homeDir = null;
+    private static String jackrabbitConfigFile = null;
+    private static String CREDENTIALS_USERNAME = null;
+    private static char[] CREDENTIALS_PASSWORD = null;
+
+    protected static Repository repository = null;
+    protected Session session = null;
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.JCRFactory#initialize(org.w3c.dom.Element)
+     */
+    @Override
+    public void initialize(Element configRootElement) throws RepositoryException {
+        Element childElement = UtilXml.firstChildElement(configRootElement, "jcr-credentials");
+        CREDENTIALS_USERNAME = UtilXml.elementAttribute(childElement, "username", null);
+        CREDENTIALS_PASSWORD = UtilXml.elementAttribute(childElement, "password", null).toCharArray();
+
+        jackrabbitConfigFile = UtilXml.childElementAttribute(configRootElement, "config-file-path", "path", "framework/jcr/config/jackrabbit.xml");
+        homeDir = UtilXml.childElementAttribute(configRootElement, "home-dir", "path", "runtime/data/jcr/");
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.JCRFactory#start()
+     */
+    @Override
+    public void start() throws RepositoryException {
+        repository = new TransientRepository(jackrabbitConfigFile, homeDir);
+        createSession();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.JCRFactory#stop(boolean)
+     */
+    @Override
+    public void stop(boolean removeRepositoryOnShutdown) throws RepositoryException {
+        if (session != null && session.isLive()) {
+            session.logout();
+        }
+
+        if (removeRepositoryOnShutdown) {
+            if (UtilValidate.isNotEmpty(homeDir)) {
+                File homeDirFile = new File(homeDir);
+                homeDirFile.deleteOnExit();
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.ofbiz.jcr.JCRFactory#createSession()
+     */
+    @Override
+    public Session createSession() throws RepositoryException {
+        if (session == null || !session.isLive()) {
+            Credentials credentials = new SimpleCredentials(CREDENTIALS_USERNAME, CREDENTIALS_PASSWORD);
+            try {
+                session = repository.login(credentials);
+            } catch (RepositoryException e) {
+                Debug.logError(e, "Could not login to the workspace");
+                throw e;
+            }
+
+        }
+        return session;
+    }
+}

Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: ofbiz/branches/jackrabbit20100709/runtime/data/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 14 14:15:06 2011
@@ -8,3 +8,7 @@ utilcache*
 jackrabbit
 
 jackrabbitTest
+
+jcr
+
+jcr-test