contentList) throws RepositoryException {
+ NodeIterator ni = startNode.getNodes();
+ while (ni.hasNext()) {
+ Node tmpNode = ni.nextNode();
+ if (tmpNode.getPrimaryNodeType().isNodeType(NodeType.NT_UNSTRUCTURED) && (!tmpNode.hasProperty("localized") || !tmpNode.getProperty("localized").getBoolean())) {
+ contentList.add(tmpNode.getPath());
+ if (tmpNode.hasNodes()) {
+ getContentList(tmpNode, contentList);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/framework/example/webapp/example/WEB-INF/actions/includes/PrepareLocalesForDropDown.groovy b/framework/example/webapp/example/WEB-INF/actions/includes/PrepareLocalesForDropDown.groovy
new file mode 100644
index 0000000000..b7d9d80399
--- /dev/null
+++ b/framework/example/webapp/example/WEB-INF/actions/includes/PrepareLocalesForDropDown.groovy
@@ -0,0 +1,22 @@
+/*
+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.
+*/
+
+def localeMap = []
+org.ofbiz.base.util.UtilMisc.availableLocales().each { localeMap.add(localeId:it.toString()) };
+parameters.localeList = localeMap;
\ No newline at end of file
diff --git a/framework/example/webapp/example/WEB-INF/controller.xml b/framework/example/webapp/example/WEB-INF/controller.xml
index 5a487295be..4a481fee09 100644
--- a/framework/example/webapp/example/WEB-INF/controller.xml
+++ b/framework/example/webapp/example/WEB-INF/controller.xml
@@ -28,7 +28,7 @@ under the License.
Example Component Site Configuration File
-
+
-
+
@@ -236,6 +236,95 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -280,6 +369,18 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+${uiLabelMap.ExampleJackrabbitQuickContentSelect}
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl b/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl
new file mode 100644
index 0000000000..8d2aa7c963
--- /dev/null
+++ b/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl
@@ -0,0 +1,94 @@
+<#--
+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.
+-->
+
+
+${parameters.dataTree!""}
+
+
\ No newline at end of file
diff --git a/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl b/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl
new file mode 100644
index 0000000000..a0914f74f5
--- /dev/null
+++ b/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl
@@ -0,0 +1,110 @@
+<#--
+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.
+-->
+
+
+${parameters.fileTree!""}
+
+
\ No newline at end of file
diff --git a/framework/example/widget/example/CommonScreens.xml b/framework/example/widget/example/CommonScreens.xml
index 39ba47d167..1e1b24d4f5 100644
--- a/framework/example/widget/example/CommonScreens.xml
+++ b/framework/example/widget/example/CommonScreens.xml
@@ -294,6 +294,32 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/example/widget/example/ExampleJackrabbitScreens.xml b/framework/example/widget/example/ExampleJackrabbitScreens.xml
new file mode 100644
index 0000000000..b4506a8ce0
--- /dev/null
+++ b/framework/example/widget/example/ExampleJackrabbitScreens.xml
@@ -0,0 +1,213 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/example/widget/example/ExampleMenus.xml b/framework/example/widget/example/ExampleMenus.xml
index 490a504ff8..42575e78e2 100644
--- a/framework/example/widget/example/ExampleMenus.xml
+++ b/framework/example/widget/example/ExampleMenus.xml
@@ -48,6 +48,7 @@ under the License.
+
+
+
diff --git a/framework/jcr/build.xml b/framework/jcr/build.xml
new file mode 100644
index 0000000000..1d08c7eecc
--- /dev/null
+++ b/framework/jcr/build.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/jcr/config/custom-jackrabbit-nodetypes.xml b/framework/jcr/config/custom-jackrabbit-nodetypes.xml
new file mode 100644
index 0000000000..bba7fa043d
--- /dev/null
+++ b/framework/jcr/config/custom-jackrabbit-nodetypes.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+ nt:base
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/jcr/config/jackrabbit.xml b/framework/jcr/config/jackrabbit.xml
new file mode 100644
index 0000000000..e54d692158
--- /dev/null
+++ b/framework/jcr/config/jackrabbit.xml
@@ -0,0 +1,138 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/jcr/config/jcr-config.xml b/framework/jcr/config/jcr-config.xml
new file mode 100644
index 0000000000..98f3b015a6
--- /dev/null
+++ b/framework/jcr/config/jcr-config.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/jcr/config/jcr-test-config.xml b/framework/jcr/config/jcr-test-config.xml
new file mode 100644
index 0000000000..0e6c027e1a
--- /dev/null
+++ b/framework/jcr/config/jcr-test-config.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/jcr/lib/cglib-2.2.jar b/framework/jcr/lib/cglib-2.2.jar
new file mode 100644
index 0000000000..084ef6e54b
Binary files /dev/null and b/framework/jcr/lib/cglib-2.2.jar differ
diff --git a/framework/jcr/lib/concurrent-1.3.4.jar b/framework/jcr/lib/concurrent-1.3.4.jar
new file mode 100644
index 0000000000..551f347142
Binary files /dev/null and b/framework/jcr/lib/concurrent-1.3.4.jar differ
diff --git a/framework/jcr/lib/jackrabbit-api-2.3.3.jar b/framework/jcr/lib/jackrabbit-api-2.3.3.jar
new file mode 100644
index 0000000000..43ca34c7a8
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-api-2.3.3.jar differ
diff --git a/framework/jcr/lib/jackrabbit-core-2.3.3.jar b/framework/jcr/lib/jackrabbit-core-2.3.3.jar
new file mode 100644
index 0000000000..3d52cfc65e
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-core-2.3.3.jar differ
diff --git a/framework/jcr/lib/jackrabbit-jca-2.3.3.jar b/framework/jcr/lib/jackrabbit-jca-2.3.3.jar
new file mode 100644
index 0000000000..4c01421974
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-jca-2.3.3.jar differ
diff --git a/framework/jcr/lib/jackrabbit-jcr-commons-2.3.3.jar b/framework/jcr/lib/jackrabbit-jcr-commons-2.3.3.jar
new file mode 100644
index 0000000000..344132b6b9
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-jcr-commons-2.3.3.jar differ
diff --git a/framework/jcr/lib/jackrabbit-ocm-2.0.jar b/framework/jcr/lib/jackrabbit-ocm-2.0.jar
new file mode 100644
index 0000000000..dc368c694d
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-ocm-2.0.jar differ
diff --git a/framework/jcr/lib/jackrabbit-spi-2.3.3.jar b/framework/jcr/lib/jackrabbit-spi-2.3.3.jar
new file mode 100644
index 0000000000..bb9ce8475d
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-spi-2.3.3.jar differ
diff --git a/framework/jcr/lib/jackrabbit-spi-commons-2.3.3.jar b/framework/jcr/lib/jackrabbit-spi-commons-2.3.3.jar
new file mode 100644
index 0000000000..dec4de8695
Binary files /dev/null and b/framework/jcr/lib/jackrabbit-spi-commons-2.3.3.jar differ
diff --git a/framework/jcr/lib/jcr-2.0.jar b/framework/jcr/lib/jcr-2.0.jar
new file mode 100644
index 0000000000..6afce9b584
Binary files /dev/null and b/framework/jcr/lib/jcr-2.0.jar differ
diff --git a/framework/jcr/lib/tagsoup-1.2.1.jar b/framework/jcr/lib/tagsoup-1.2.1.jar
new file mode 100644
index 0000000000..2751601917
Binary files /dev/null and b/framework/jcr/lib/tagsoup-1.2.1.jar differ
diff --git a/framework/jcr/lib/tika-core-0.10.jar b/framework/jcr/lib/tika-core-0.10.jar
new file mode 100644
index 0000000000..78087e1381
Binary files /dev/null and b/framework/jcr/lib/tika-core-0.10.jar differ
diff --git a/framework/jcr/lib/tika-parsers-0.10.jar b/framework/jcr/lib/tika-parsers-0.10.jar
new file mode 100644
index 0000000000..b1eca29d96
Binary files /dev/null and b/framework/jcr/lib/tika-parsers-0.10.jar differ
diff --git a/framework/jcr/ofbiz-component.xml b/framework/jcr/ofbiz-component.xml
new file mode 100644
index 0000000000..56ba5fc938
--- /dev/null
+++ b/framework/jcr/ofbiz-component.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/jcr/servicedef/services.xml b/framework/jcr/servicedef/services.xml
new file mode 100644
index 0000000000..eb9efda131
--- /dev/null
+++ b/framework/jcr/servicedef/services.xml
@@ -0,0 +1,36 @@
+
+
+
+
+ Jackrabbit Services
+ OFBiz
+ 1.0
+
+
+
+ Determine the JCR Repository Overhead
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java b/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java
new file mode 100644
index 0000000000..f1e5ce9421
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java
@@ -0,0 +1,63 @@
+package org.ofbiz.jcr.access;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.QueryResult;
+
+import net.sf.json.JSONArray;
+
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+
+public interface ContentReader {
+
+ /**
+ * Return an OfbizRepositoryMapping Object from the JCR Repository. The node
+ * path have to be an absolute path.
+ *
+ * @param nodePath
+ * @return
+ * @throws PathNotFoundException
+ */
+ OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException;
+
+ /**
+ * Return an OfbizRepositoryMapping Object in the specified language and
+ * version from the JCR Repository. The Method checks if the requested
+ * version for this node exist. If not the latest version of the node will
+ * be returned. The node path have to be an absolute path.
+ *
+ * @param nodePath
+ * @param language
+ * @param version
+ * @return
+ * @throws PathNotFoundException
+ */
+ OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException;
+
+ /**
+ * Returns a tree of all content nodes (except folders and files) in the
+ * repository.
+ *
+ * @return
+ * @throws RepositoryException
+ */
+ JSONArray getJsonDataTree() throws RepositoryException;
+
+ /**
+ * Returns a tree of all folder/file nodes in the repository.
+ *
+ * @return
+ * @throws RepositoryException
+ */
+ JSONArray getJsonFileTree() throws RepositoryException;
+
+ /**
+ * Query for Data in the JCR Repository using the SQL2 or JQOM Query
+ * language. Returns the Query Result.
+ *
+ * @param query
+ * either a SQL2 or JQOM statement.
+ * @return
+ */
+ QueryResult queryRepositoryData(String query) throws RepositoryException;
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java b/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java
new file mode 100644
index 0000000000..3beea5e010
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java
@@ -0,0 +1,36 @@
+package org.ofbiz.jcr.access;
+
+import javax.jcr.ItemExistsException;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+
+public interface ContentWriter {
+
+ /**
+ * Stores the OfbizRepositoryMapping Class in the content repository.
+ *
+ * @param orm
+ * @throws ObjectContentManagerException
+ * @throws ItemExistsException
+ */
+ public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException, ItemExistsException;
+
+ /**
+ * Update the OfbizRepositoryMapping Class in the content repository.
+ *
+ * @param orm
+ * @throws ObjectContentManagerException
+ */
+ public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException;
+
+ /**
+ * Remove the passed node from the content repository. The node path should be absolute.
+ *
+ * @param nodePath
+ * @throws ObjectContentManagerException
+ */
+ public void removeContentObject(String nodePath) throws ObjectContentManagerException;
+
+
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java b/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java
new file mode 100644
index 0000000000..eee919b6f4
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java
@@ -0,0 +1,144 @@
+package org.ofbiz.jcr.access;
+
+import java.util.List;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+
+import net.sf.json.JSONArray;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+
+public interface JcrRepositoryAccessor {
+
+ /**
+ * Close the current repository session should be used when the operation
+ * with this object are finished.
+ */
+ public void closeAccess();
+
+ /**
+ * Return an OfbizRepositoryMapping Object from the content repository.
+ *
+ * @param nodePath
+ * @return
+ * @throws PathNotFoundException
+ */
+ OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException;
+
+ /**
+ * Return an OfbizRepositoryMapping Object in the specified version from the
+ * JCR Repository.
+ *
+ * @param nodePath
+ * @param language
+ * @param version
+ * @return
+ * @throws PathNotFoundException
+ */
+ OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException;
+
+ /**
+ * Stores the OfbizRepositoryMapping Class in the content repository.
+ *
+ * @param orm
+ * @throws ObjectContentManagerException
+ * @throws ItemExistsException
+ */
+ void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException, ItemExistsException;
+
+ /**
+ * Update the passed content object.
+ *
+ * @param orm
+ * @throws ObjectContentManagerException
+ */
+ public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException;
+
+ /**
+ * Remove the passed node from the content repository
+ *
+ * @param nodePath
+ * @throws ObjectContentManagerException
+ */
+ public void removeContentObject(String nodePath) throws ObjectContentManagerException;
+
+ /**
+ * Remove the passed node from the content repository
+ *
+ * @param orm
+ * @throws ObjectContentManagerException
+ */
+ public void removeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException;
+
+ /**
+ * Returns a tree of all content nodes (except folders and files) in the
+ * repository.
+ *
+ * @return
+ * @throws RepositoryException
+ */
+ JSONArray getJsonDataTree() throws RepositoryException;
+
+ /**
+ * Returns a tree of all file/folder nodes in the repository.
+ *
+ * @return
+ * @throws RepositoryException
+ */
+ JSONArray getJsonFileTree() throws RepositoryException;
+
+ /**
+ * Returns a list of the available versions.
+ *
+ * @param nodePath
+ * @return
+ */
+ public List getVersionList(String nodePath);
+
+ /**
+ * Returns the last checked in version.
+ *
+ * @param nodePath
+ * @return
+ */
+ public String getBaseVersion(String nodePath);
+
+ /**
+ * Returns the first checked in version.
+ *
+ * @param nodePath
+ * @return
+ */
+ public String getRootVersion(String nodePath);
+
+ /**
+ * Query for Data in the JCR Repository using the SQL2 or JQOM Query
+ * language. Returns the Query result.
+ *
+ * @param query
+ * either a SQL2 or JQOM statement.
+ * @return
+ */
+ public QueryResult queryForRepositoryData(String query) throws RepositoryException;
+
+ /**
+ * Returns a JCR Session object
+ *
+ * @return
+ */
+ public Session getSession();
+
+ /**
+ * Returns true if the node with the passed node path exist, if not or if an
+ * exception occurs false will be returned.
+ *
+ * @param nodePathToCheck
+ * @return
+ */
+ public boolean checkIfNodeExist(String nodePathToCheck);
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java b/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java
new file mode 100644
index 0000000000..0217064697
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java
@@ -0,0 +1,70 @@
+package org.ofbiz.jcr.access;
+
+import java.util.List;
+
+public interface VersioningManager {
+
+ /**
+ * Returns a List of all available versions for the passed node.
+ *
+ * @param nodePath
+ * @return
+ */
+ public List getVersionList(String nodePath);
+
+ /**
+ * Returns true if the passed node exist in the requested version.
+ *
+ * @param nodePath
+ * @param version
+ * @return
+ */
+ public boolean checkIfVersionExist(String nodePath, String version);
+
+ /**
+ * Returns the last checked in version.
+ *
+ * @param nodePath
+ * @return
+ */
+ public String getBaseVersion(String nodePath);
+
+ /**
+ * Returns the first checked in version.
+ *
+ * @param nodePath
+ * @return
+ */
+ public String getRootVersion(String nodePath);
+
+ /**
+ * Check Out a node from a repository
+ *
+ * @param nodePath
+ */
+ public void checkOutContentObject(String nodePath);
+
+ /**
+ * Check Out a node from a repository. If recursive is set to TRUE all
+ * related sub nodes and the parent node will also be checked out.
+ *
+ * @param nodePath
+ * @param recursiv
+ */
+ public void checkOutContentObject(String nodePath, boolean recursiv);
+
+ /**
+ * Saves the state of the session and checks in all checkout content nodes.
+ */
+ public void checkInContentAndSaveState();
+
+ /**
+ * Add a node path to a list of node path which will be checked in when the
+ * state is saved. This is to add new created nodes which could not checked
+ * out before.
+ *
+ * @param nodePath
+ */
+ public void addContentToCheckInList(String nodePath);
+
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java
new file mode 100644
index 0000000000..7827903e97
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java
@@ -0,0 +1,22 @@
+package org.ofbiz.jcr.access.jackrabbit;
+
+import javax.jcr.nodetype.NodeType;
+
+public class ConstantsJackrabbit {
+ // JCR Variables
+ public static String MESSAGE = "jcr:message";
+ public static String FILE = NodeType.NT_FILE;
+ public static String FOLDER = NodeType.NT_FOLDER;
+ public static String RESOURCE = NodeType.NT_RESOURCE;
+ public static String DATA = "jcr:data";
+ public static String UNSTRUCTURED = NodeType.NT_UNSTRUCTURED;
+ public static String MIMETYPE = "jcr:mimeType";
+ public static String MIXIN_LANGUAGE = "mix:language";
+ public static String MIXIN_VERSIONING = "mix:versionable";
+ public static String ROOTVERSION = "jcr:rootVersion";
+
+ //
+ public static String ROOTPATH = "/";
+ public static String FILEROOT = ROOTPATH + "fileHome";
+ public static String NODEPATHDELIMITER = "/";
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java
new file mode 100644
index 0000000000..d338b92175
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java
@@ -0,0 +1,212 @@
+package org.ofbiz.jcr.access.jackrabbit;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionException;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.jcr.access.ContentReader;
+import org.ofbiz.jcr.access.VersioningManager;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit;
+
+public class ContentReaderJackrabbit implements ContentReader {
+
+ private final static String module = ContentReaderJackrabbit.class.getName();
+
+ private final ObjectContentManager ocm;
+
+ public ContentReaderJackrabbit(ObjectContentManager ocm) {
+ this.ocm = ocm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String)
+ */
+ @Override
+ public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException{
+ nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath);
+ OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath);
+ try {
+ if (orm != null) {
+ orm.setVersion(ocm.getBaseVersion(nodePath).getName());
+ }
+ } catch (VersionException e) {
+ // -0.0 means we have no version information
+ orm.setVersion("-0.0");
+ Debug.logError(e, module);
+ }
+ return orm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException {
+ nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath);
+ VersioningManager vm = new VersioningManagerJackrabbit(ocm);
+ if (!vm.checkIfVersionExist(nodePath, version)) {
+ Debug.logWarning("The version: " + version + " for content object: " + nodePath + " does not exist, the latest version for this object will be returned.", module);
+ return getContentObject(nodePath);
+ }
+
+ OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath, version);
+ orm.setVersion(version);
+ return orm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.orm.ContentReader#getJsonDataTree()
+ */
+ @Override
+ public JSONArray getJsonDataTree() throws RepositoryException {
+ return getJsonDataChildNodes(ocm.getSession().getRootNode());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.access.ContentReader#getJsonFileTree()
+ */
+ @Override
+ public JSONArray getJsonFileTree() throws RepositoryException {
+ return getJsonFileChildNodes(ocm.getSession().getRootNode());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentReader#queryRepositoryData(java.lang.String)
+ */
+ @Override
+ public QueryResult queryRepositoryData(String query) throws RepositoryException {
+ return executeQuery(query);
+ }
+
+ /**
+ * 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 getJsonFileChildNodes(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(ConstantsJackrabbit.FOLDER)) {
+ 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", getJsonFileChildNodes(node).toString());
+
+ folderStrucutre.element(folder);
+ } else if (node.getPrimaryNodeType().isNodeType(ConstantsJackrabbit.FILE)) {
+ 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;
+ }
+
+ /**
+ * Returns a JSON Array with the repository text data structure. The JSON
+ * array is directly build for the jsTree jQuery plugin.
+ *
+ * @param startNode
+ * @return
+ * @throws RepositoryException
+ */
+ private JSONArray getJsonDataChildNodes(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(ConstantsJackrabbit.UNSTRUCTURED) && !node.hasProperty(ConstantsJackrabbit.MIXIN_LANGUAGE)) {
+ 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", getJsonDataChildNodes(node).toString());
+
+ folderStrucutre.element(folder);
+ }
+ }
+
+ return folderStrucutre;
+ }
+
+ /**
+ * Executes the query specified by statement and returns the
+ * query result.
+ *
+ * @param statement
+ * either a SQL2 or JQOM statement.
+ * @return the query result.
+ * @throws RepositoryException
+ * if an error occurs.
+ */
+ protected QueryResult executeQuery(String statement) throws RepositoryException {
+ // TODO create a query manager which uses the OCM Layer.
+ QueryManager qm = ocm.getSession().getWorkspace().getQueryManager();
+
+ if (statement.trim().toLowerCase().startsWith("select")) {
+ return qm.createQuery(statement, Query.JCR_SQL2).execute();
+ } else {
+ return qm.createQuery(statement, Query.JCR_JQOM).execute();
+ }
+ }
+
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java
new file mode 100644
index 0000000000..a1987e8d7e
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java
@@ -0,0 +1,203 @@
+package org.ofbiz.jcr.access.jackrabbit;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.jcr.access.ContentWriter;
+import org.ofbiz.jcr.access.VersioningManager;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit;
+
+public class ContentWriterJackrabbit implements ContentWriter {
+
+ private final static String module = ContentWriterJackrabbit.class.getName();
+
+ private final ObjectContentManager ocm;
+ private final VersioningManager versioningManager;
+
+ /**
+ *
+ * @param ocm
+ */
+ public ContentWriterJackrabbit(ObjectContentManager ocm) {
+ this.ocm = ocm;
+ versioningManager = new VersioningManagerJackrabbit(ocm);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentWriter#storeContentObject(org.ofbiz.jcr.orm
+ * .OfbizRepositoryMapping)
+ */
+ @Override
+ public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException, ItemExistsException {
+ if (orm == null) {
+ return;
+ }
+
+ // we want to avoid same name sibling (SnS) for each node Type
+ try {
+ if (this.ocm.getSession().itemExists(orm.getPath())) {
+ // we could either throw an exception or call the update method
+ throw new ItemExistsException("There already exists an object stored at " + orm.getPath() + ". Please use update if you want to change it.");
+ }
+ } catch (ItemExistsException e) {
+ throw (e);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ return;
+ }
+
+ // create all nodes in the node structure which do not exist yet
+ try {
+ createNodeStructure(orm.getPath(), orm.getClass().getAnnotation(org.apache.jackrabbit.ocm.mapper.impl.annotation.Node.class).jcrType());
+ } catch (PathNotFoundException e) {
+ Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
+ return;
+ } catch (RepositoryException e) {
+ Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
+ return;
+ }
+
+ ocm.insert(orm);
+ versioningManager.addContentToCheckInList(orm.getPath());
+
+ this.saveState();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentWriter#updateContentObject(org.ofbiz.jcr.
+ * orm.OfbizRepositoryMapping)
+ */
+ @Override
+ public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException {
+ versioningManager.checkOutContentObject(orm.getPath());
+ ocm.update(orm);
+ this.saveState();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.ContentWriter#removeContentObject(java.lang.String)
+ */
+ @Override
+ public void removeContentObject(String nodePath) throws ObjectContentManagerException {
+ nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath);
+ versioningManager.checkOutContentObject(nodePath, true);
+
+ ocm.remove(nodePath);
+ this.saveState();
+ }
+
+ private void saveState() {
+ versioningManager.checkInContentAndSaveState();
+ }
+
+ /**
+ * Create the new Node structure.
+ *
+ * @param completeNodePath
+ * @param primaryNodeType
+ * a primary node type from the mapping annotation class, that
+ * will be used as primary type for the created nodes
+ * @throws PathNotFoundException
+ * @throws RepositoryException
+ */
+ private void createNodeStructure(String completeNodePath, String primaryNodeType) throws PathNotFoundException, RepositoryException {
+ // We have to check if the node structure (the sub nodes of the passed
+ // ORM Object) exist, otherwise they will be created.
+ String[] nodeStructure = completeNodePath.split(ConstantsJackrabbit.NODEPATHDELIMITER);
+ Node parentNode = null;
+ try {
+ parentNode = this.ocm.getSession().getRootNode();
+ } catch (RepositoryException e) {
+ Debug.logError(e, "The new node could not be created: " + completeNodePath, module);
+ return;
+ }
+
+ // We loop only over the sub nodes.
+ for (int i = 0; i < (nodeStructure.length - 1); i++) {
+ String node = nodeStructure[i];
+ if (UtilValidate.isEmpty(node)) {
+ continue;
+ }
+
+ parentNode = createNewSubNodeIfNotExist(primaryNodeType, parentNode, node);
+ }
+ }
+
+ /**
+ * Checks if the new node already exist, otherwise it will be created.
+ *
+ * @param primaryNodeType
+ * @param parentNode
+ * @param node
+ * @return
+ * @throws RepositoryException
+ * @throws PathNotFoundException
+ * @throws ItemExistsException
+ * @throws NoSuchNodeTypeException
+ * @throws LockException
+ * @throws VersionException
+ * @throws ConstraintViolationException
+ */
+ private Node createNewSubNodeIfNotExist(String primaryNodeType, Node parentNode, String node) throws RepositoryException, PathNotFoundException, ItemExistsException, NoSuchNodeTypeException, LockException, VersionException,
+ ConstraintViolationException {
+
+ if (parentNode.hasNode(node)) {
+ parentNode = parentNode.getNode(node);
+ versioningManager.checkOutContentObject(parentNode.getPath());
+ } else {
+ versioningManager.checkOutContentObject(parentNode.getPath());
+
+ Node newNode = addNewNode(primaryNodeType, parentNode, node);
+
+ versioningManager.addContentToCheckInList(newNode.getPath());
+ parentNode = newNode;
+ }
+
+ return parentNode;
+ }
+
+ /**
+ * The method adds a new node to its parent, write the versioning mixin and
+ * set the primary node type.
+ *
+ * @param primaryNodeType
+ * @param parentNode
+ * @param node
+ * @return
+ * @throws ItemExistsException
+ * @throws PathNotFoundException
+ * @throws NoSuchNodeTypeException
+ * @throws LockException
+ * @throws VersionException
+ * @throws ConstraintViolationException
+ * @throws RepositoryException
+ */
+ private Node addNewNode(String primaryNodeType, Node parentNode, String node) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
+ Node newNode = parentNode.addNode(node, primaryNodeType);
+ newNode.addMixin(ConstantsJackrabbit.MIXIN_VERSIONING);
+ if (!ConstantsJackrabbit.ROOTPATH.equals(parentNode.getPath())) {
+ newNode.setPrimaryType(parentNode.getPrimaryNodeType().getName());
+ }
+ return newNode;
+ }
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java
new file mode 100644
index 0000000000..1ee6ea06bc
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java
@@ -0,0 +1,241 @@
+package org.ofbiz.jcr.access.jackrabbit;
+
+import java.util.List;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+
+import net.sf.json.JSONArray;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.jcr.access.ContentReader;
+import org.ofbiz.jcr.access.ContentWriter;
+import org.ofbiz.jcr.access.JcrRepositoryAccessor;
+import org.ofbiz.jcr.access.VersioningManager;
+import org.ofbiz.jcr.loader.JCRFactoryUtil;
+import org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+
+public class JackrabbitRepositoryAccessor implements JcrRepositoryAccessor {
+
+ private final static String module = JackrabbitRepositoryAccessor.class.getName();
+
+ private final Session session;
+ private final ObjectContentManagerImpl ocm;
+
+ /**
+ * Create a repository Access object based on the userLogin.
+ *
+ * @param userLogin
+ */
+ public JackrabbitRepositoryAccessor(GenericValue userLogin) {
+ // TODO pass the userLogin to the getSession() method and perform some
+ this(JCRFactoryUtil.getSession());
+ }
+
+ /**
+ * Create a repository Access object based on a JCR Session.
+ *
+ * @param userLogin
+ */
+ public JackrabbitRepositoryAccessor(Session session) {
+ this.session = session;
+ this.ocm = new ObjectContentManagerImpl(session, JCRFactoryImpl.getMapper());
+
+ return;
+ }
+
+ /**
+ * Returns the Jackrabbit session object.
+ *
+ * @return
+ */
+ public Session getSession() {
+ return this.session;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.orm.RepositoryAccess#closeAccess()
+ */
+ @Override
+ public void closeAccess() {
+ if (this.ocm != null && this.ocm.getSession().isLive()) {
+ this.ocm.logout();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.orm.RepositoryAccess#getContentObject(java.lang.String)
+ */
+ @Override
+ public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException {
+ ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+ return contentReader.getContentObject(nodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.RepositoryAccess#getContentObject(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException {
+ ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+ return contentReader.getContentObject(nodePath, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.orm.RepositoryAccess#storeContentObject(org.ofbiz.jcr.orm
+ * .OfbizRepositoryMapping)
+ */
+ @Override
+ public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException, ItemExistsException {
+ ContentWriter contentWriter = new ContentWriterJackrabbit(this.ocm);
+ contentWriter.storeContentObject(orm);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.orm.RepositoryAccess#updateContentObject(org.ofbiz.jcr.
+ * orm.OfbizRepositoryMapping)
+ */
+ @Override
+ public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException {
+ ContentWriter contentWriter = new ContentWriterJackrabbit(this.ocm);
+ contentWriter.updateContentObject(orm);
+
+ return;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.orm.RepositoryAccess#removeContentObject(java.lang.String)
+ */
+ @Override
+ public void removeContentObject(String nodePath) throws ObjectContentManagerException {
+ ContentWriter contentWriter = new ContentWriterJackrabbit(this.ocm);
+ contentWriter.removeContentObject(nodePath);
+
+ return;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.orm.RepositoryAccess#removeContentObject(org.ofbiz.jcr.
+ * orm.OfbizRepositoryMapping)
+ */
+ @Override
+ public void removeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException {
+ removeContentObject(orm.getPath());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.RepositoryAccess#getVersionList(java.lang.String)
+ */
+ @Override
+ public List getVersionList(String nodePath) {
+ VersioningManager versioningnManager = new VersioningManagerJackrabbit(this.ocm);
+ return versioningnManager.getVersionList(nodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.RepositoryAccess#getBaseVersion(java.lang.String)
+ */
+ @Override
+ public String getBaseVersion(String nodePath) {
+ VersioningManager versioningnManager = new VersioningManagerJackrabbit(this.ocm);
+ return versioningnManager.getBaseVersion(nodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.RepositoryAccess#getRootVersion(java.lang.String)
+ */
+ @Override
+ public String getRootVersion(String nodePath) {
+ VersioningManager versioningnManager = new VersioningManagerJackrabbit(this.ocm);
+ return versioningnManager.getRootVersion(nodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.orm.RepositoryAccess#getJsonFileTree()
+ */
+ @Override
+ public JSONArray getJsonDataTree() throws RepositoryException {
+ ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+ return contentReader.getJsonDataTree();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.access.RepositoryAccess#getJsonFileTree()
+ */
+ @Override
+ public JSONArray getJsonFileTree() throws RepositoryException {
+ ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+ return contentReader.getJsonFileTree();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.RepositoryAccess#queryForRepositoryData(java.lang
+ * .String)
+ */
+ @Override
+ public QueryResult queryForRepositoryData(String query) throws RepositoryException {
+ ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+ return contentReader.queryRepositoryData(query);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.JcrRepositoryAccessor#checkIfNodeExist(java.lang
+ * .String)
+ */
+ @Override
+ public boolean checkIfNodeExist(String nodePathToCheck) {
+ try {
+ return getSession().itemExists(nodePathToCheck);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ return false;
+ }
+ }
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java
new file mode 100644
index 0000000000..7ab3d92fa2
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java
@@ -0,0 +1,233 @@
+package org.ofbiz.jcr.access.jackrabbit;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.version.Version;
+import org.apache.jackrabbit.ocm.version.VersionIterator;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.jcr.access.VersioningManager;
+
+public class VersioningManagerJackrabbit implements VersioningManager {
+
+ private final static String module = VersioningManagerJackrabbit.class.getName();
+
+ private final ObjectContentManager ocm;
+
+ private final Set checkedOutNodeStore = Collections.synchronizedSet(new HashSet());
+ private final static String NOVERSION = "-0.0";
+
+ VersioningManagerJackrabbit(ObjectContentManager ocm) {
+ this.ocm = ocm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#getVersionList(java.lang.String)
+ */
+ @Override
+ public List getVersionList(String nodePath) {
+ List result = new ArrayList();
+ VersionIterator versionIterator = null;
+ try {
+ versionIterator = this.ocm.getAllVersions(nodePath);
+ } catch (VersionException e) {
+ Debug.logError(e, module);
+ // return an empty List
+ return result;
+ }
+
+ // write the versions to the array list.
+ while (versionIterator.hasNext()) {
+ Version version = (Version) versionIterator.next();
+ // filter the root version string, because it's not needed each node
+ // starts with the version number 1.0
+ if (!ConstantsJackrabbit.ROOTVERSION.equals(version.getName())) {
+ result.add(version.getName());
+ }
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#checkIfVersionExist(java.lang.
+ * String, java.lang.String)
+ */
+ @Override
+ public boolean checkIfVersionExist(String nodePath, String version) {
+ return getVersionList(nodePath).contains(version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#checkOutContentObject(java.lang
+ * .String)
+ */
+ @Override
+ public void checkOutContentObject(String nodePath) {
+ // check if the parent node is the root node, because the
+ // root node can not be checked out.
+ if (ConstantsJackrabbit.ROOTPATH.equals(nodePath)) {
+ return;
+ }
+
+ try {
+ if (this.ocm.getSession().nodeExists(nodePath) && !this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath) && !checkedOutNodeStore.contains(nodePath)) {
+ this.ocm.checkout(nodePath);
+ this.addContentToCheckInList(nodePath);
+ }
+ } catch (VersionException e) {
+ Debug.logError(e, module);
+ } catch (UnsupportedRepositoryOperationException e) {
+ Debug.logError(e, module);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ }
+ }
+
+ public void checkOutContentObject(String nodePath, boolean recursiv) {
+ if (recursiv) {
+ try {
+ checkOutRelatedNodes(nodePath);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ }
+ } else {
+ checkOutContentObject(nodePath);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#addContentToCheckInList(java.lang
+ * .String)
+ */
+ @Override
+ public void addContentToCheckInList(String nodePath) {
+ checkedOutNodeStore.add(nodePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ofbiz.jcr.access.VersioningManager#checkInContentAndSaveState()
+ */
+ @Override
+ public void checkInContentAndSaveState() {
+ if (ocm != null) {
+ ocm.save();
+ }
+
+ try {
+ for (String nodePath : checkedOutNodeStore) {
+ // add the new resource content to the version history
+ if (this.ocm.getSession().nodeExists(nodePath) && this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath)) {
+ this.ocm.checkin(nodePath);
+ }
+ }
+
+ // reset the node store after everything is checked in
+ checkedOutNodeStore.clear();
+ } catch (VersionException e) {
+ Debug.logError(e, module);
+ } catch (UnsupportedRepositoryOperationException e) {
+ Debug.logError(e, module);
+ } catch (RepositoryException e) {
+ Debug.logError(e, module);
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#getBaseVersion(java.lang.String)
+ */
+ public String getBaseVersion(String nodePath) {
+ try {
+ return ocm.getBaseVersion(nodePath).getName();
+ } catch (VersionException e) {
+ Debug.logError(e, module);
+ return NOVERSION;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ofbiz.jcr.access.VersioningManager#getRootVersion(java.lang.String)
+ */
+ public String getRootVersion(String nodePath) {
+ try {
+ return ocm.getRootVersion(nodePath).getName();
+ } catch (VersionException e) {
+ Debug.logError(e, module);
+ return NOVERSION;
+ }
+ }
+
+ /**
+ * Checks out recursively all related nodes (parent, all child's (if exists)
+ * and the node itself)
+ *
+ * @param startNode
+ * @throws RepositoryException
+ */
+ protected void checkOutRelatedNodes(String startNodePath) throws RepositoryException {
+ List nodesToCheckOut = new ArrayList();
+ nodesToCheckOut.add(startNodePath);
+ nodesToCheckOut.add(ocm.getSession().getNode(startNodePath).getParent().getPath());
+ if (ocm.getSession().getNode(startNodePath).hasNodes()) {
+ nodesToCheckOut.addAll(getAllChildNodes(startNodePath));
+ }
+
+ for (String node : nodesToCheckOut) {
+ this.checkOutContentObject(node);
+ }
+
+ }
+
+ /**
+ * Return recursively all child nodes
+ *
+ * @param startNode
+ * @return
+ * @throws RepositoryException
+ */
+ private List getAllChildNodes(String startNode) throws RepositoryException {
+ List nodes = new ArrayList();
+ NodeIterator ni = ocm.getSession().getNode(startNode).getNodes();
+ while (ni.hasNext()) {
+ Node nextNode = ni.nextNode();
+ if (nextNode.hasNodes()) {
+ nodes.addAll(getAllChildNodes(nextNode.getPath()));
+ }
+
+ nodes.add(nextNode.getPath());
+ }
+
+ return nodes;
+ }
+}
diff --git a/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java
new file mode 100644
index 0000000000..addeb0212e
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java
@@ -0,0 +1,88 @@
+package org.ofbiz.jcr.api;
+
+import java.util.Calendar;
+import java.util.List;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.ofbiz.jcr.orm.jackrabbit.JackrabbitArticle;
+
+public interface JcrDataHelper extends JcrHelper{
+
+ /**
+ * Read the article content object from the repository. Throws an Exception
+ * when the read content type is not an article content type.
+ *
+ * @param contentPath
+ * @return content article object
+ * @throws PathNotFoundException
+ * @throws ClassCastException
+ */
+ public abstract JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException, PathNotFoundException;
+
+ /**
+ * @throws PathNotFoundException
+ * Read the article content object, in the passed language, from the
+ * repository. if the language is not available, the default language will
+ * be choose. Throws an Exception when the read content type is not an
+ * article content type.
+ *
+ * @param contentPath
+ * @return content article object
+ * @throws PathNotFoundException
+ * @throws ClassCastException
+ */
+ public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException, PathNotFoundException;
+
+ /**
+ * @throws PathNotFoundException
+ * Read the article content object, in the passed language and version, from
+ * the repository. if the language is not available, the default language
+ * will be choose. Throws an Exception when the read content type is not an
+ * article content type.
+ *
+ * @param contentPath
+ * @param language
+ * @param version
+ * @return
+ * @throws PathNotFoundException
+ * @throws ClassCastException
+ */
+ public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException, PathNotFoundException;
+
+ /**
+ * Stores a new article content object in the repository.
+ *
+ * @param contentPath
+ * @param language
+ * @param title
+ * @param content
+ * @param publicationDate
+ * @throws ObjectContentManagerException
+ * @throws ItemExistsException
+ */
+ public abstract void storeContentInRepository(String contentPath, String language, String title, String content, Calendar publicationDate) throws ObjectContentManagerException, ItemExistsException;
+
+ /**
+ * Update an existing content article object in the repository.
+ *
+ * @param updatedArticle
+ * @throws RepositoryException
+ * @throws ObjectContentManagerException
+ */
+ public abstract void updateContentInRepository(JackrabbitArticle updatedArticle) throws RepositoryException, ObjectContentManagerException;
+
+ /**
+ * Returns a list of versions which are available for the current article.
+ * If no article is loaded before, the list will be empty.
+ *
+ * @return
+ */
+ public abstract List getVersionListForCurrentArticle();
+
+ public abstract List getAvailableLanguageList();
+
+}
\ No newline at end of file
diff --git a/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java
new file mode 100644
index 0000000000..59bcf52edd
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java
@@ -0,0 +1,76 @@
+package org.ofbiz.jcr.api;
+
+import java.io.InputStream;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.ofbiz.jcr.orm.jackrabbit.JackrabbitHierarchyNode;
+
+public interface JcrFileHelper extends JcrHelper{
+
+ /**
+ * Returns a content file object from the repository. Throws an Exception
+ * when the read content type is not an article content type.
+ *
+ * @param contentPath
+ * @return
+ * @throws ClassCastException
+ * @throws PathNotFoundException
+ */
+ public abstract JackrabbitHierarchyNode getRepositoryContent(String contentPath) throws ClassCastException, PathNotFoundException;
+
+ /**
+ * Returns a content file object in the passed version from the repository.
+ * Throws an Exception when the read content type is not an article content
+ * type.
+ *
+ * @param contentPath
+ * @return
+ * @throws ClassCastException
+ * @throws PathNotFoundException
+ */
+ public abstract JackrabbitHierarchyNode getRepositoryContent(String contentPath, String version) throws ClassCastException, PathNotFoundException;
+
+ /**
+ * Stores a new file content object in the repository.
+ *
+ * @param fileData
+ * @param fileName
+ * @param folderPath
+ * @param mimeType
+ * @throws ObjectContentManagerException
+ * @throws RepositoryException
+ */
+ public abstract void storeContentInRepository(byte[] fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException;
+
+ /**
+ * Stores a new file content object in the repository.
+ *
+ * @param fileData
+ * @param fileName
+ * @param folderPath
+ * @param mimeType
+ * @throws ObjectContentManagerException
+ * @throws RepositoryException
+ */
+ public abstract void storeContentInRepository(InputStream fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException;
+
+ /**
+ * Returns TRUE if the current content is a file content (Type:
+ * OfbizRepositoryMappingJackrabbitFile)
+ *
+ * @return
+ */
+ public abstract boolean isFileContent();
+
+ /**
+ * Returns TRUE if the current content is a folder content (Type:
+ * OfbizRepositoryMappingJackrabbitFolder)
+ *
+ * @return
+ */
+ public abstract boolean isFolderContent();
+
+}
\ No newline at end of file
diff --git a/framework/jcr/src/org/ofbiz/jcr/api/JcrHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/JcrHelper.java
new file mode 100644
index 0000000000..e21fc5d042
--- /dev/null
+++ b/framework/jcr/src/org/ofbiz/jcr/api/JcrHelper.java
@@ -0,0 +1,25 @@
+package org.ofbiz.jcr.api;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+public interface JcrHelper {
+
+ /**
+ * This will close the connection to the content repository and make sure
+ * that all changes a stored successfully.
+ */
+ public abstract void closeContentSession();
+
+ /**
+ * Remove the passed node from the content repository.
+ *
+ * @param contentPath
+ */
+ public abstract void removeContentObject(String contentPath);
+
+ public abstract List