diff --git a/.classpath b/.classpath index 65246ae7eb..a6cd7196b4 100644 --- a/.classpath +++ b/.classpath @@ -11,6 +11,8 @@ + + @@ -117,15 +119,6 @@ - - - - - - - - - @@ -194,7 +187,6 @@ - @@ -221,7 +213,5 @@ - - diff --git a/.gitignore b/.gitignore index 8def1fcd4e..ebb3923c81 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,6 @@ runtime/logs/*.log* runtime/logs/*.html* runtime/logs/test-results/* runtime/data/derby/* -runtime/data/jcr/* -runtime/data/jcr-test/* runtime/data/utilcache.* runtime/catalina/work/* runtime/jetty diff --git a/applications/content/build.xml b/applications/content/build.xml index 4e8286d801..b295c3356d 100644 --- a/applications/content/build.xml +++ b/applications/content/build.xml @@ -47,7 +47,6 @@ under the License. - diff --git a/framework/jcr/lib/tika-core-1.0.jar b/applications/content/lib/tika-core-1.0.jar similarity index 100% rename from framework/jcr/lib/tika-core-1.0.jar rename to applications/content/lib/tika-core-1.0.jar diff --git a/framework/jcr/lib/tika-parsers-1.0.jar b/applications/content/lib/tika-parsers-1.0.jar similarity index 100% rename from framework/jcr/lib/tika-parsers-1.0.jar rename to applications/content/lib/tika-parsers-1.0.jar diff --git a/build.xml b/build.xml index 8c2142bb5b..b15c8b3494 100644 --- a/build.xml +++ b/build.xml @@ -1058,7 +1058,7 @@ under the License. diff --git a/framework/base/config/ofbiz-containers.xml b/framework/base/config/ofbiz-containers.xml index 1eac4afb8f..d61220d916 100644 --- a/framework/base/config/ofbiz-containers.xml +++ b/framework/base/config/ofbiz-containers.xml @@ -74,13 +74,6 @@ under the License. --> - - - - - - diff --git a/framework/base/config/test-containers.xml b/framework/base/config/test-containers.xml index 62653461c2..34d00d1a7f 100644 --- a/framework/base/config/test-containers.xml +++ b/framework/base/config/test-containers.xml @@ -50,13 +50,6 @@ under the License. - - - - - - diff --git a/framework/base/lib/jcl-over-slf4j-1.6.4.jar b/framework/base/lib/jcl-over-slf4j-1.6.4.jar deleted file mode 100644 index 3ddc1d1b1e..0000000000 Binary files a/framework/base/lib/jcl-over-slf4j-1.6.4.jar and /dev/null differ diff --git a/framework/base/lib/slf4j-log4j12-1.6.4.jar b/framework/base/lib/slf4j-log4j12-1.6.4.jar new file mode 100644 index 0000000000..daa3aa1631 Binary files /dev/null and b/framework/base/lib/slf4j-log4j12-1.6.4.jar differ diff --git a/framework/base/lib/slf4j-simple-1.6.4.jar b/framework/base/lib/slf4j-simple-1.6.4.jar deleted file mode 100644 index 3d1b8d912c..0000000000 Binary files a/framework/base/lib/slf4j-simple-1.6.4.jar and /dev/null differ diff --git a/framework/build.xml b/framework/build.xml index faef4663ce..7957a245a2 100644 --- a/framework/build.xml +++ b/framework/build.xml @@ -25,7 +25,7 @@ under the License. files="start/build.xml,base/build.xml,sql/build.xml, entity/build.xml,geronimo/build.xml, catalina/build.xml,jetty/build.xml, - security/build.xml,service/build.xml,jcr/build.xml,entityext/build.xml, + security/build.xml,service/build.xml,entityext/build.xml, bi/build.xml,minilang/build.xml, webapp/build.xml,widget/build.xml, common/build.xml,datafile/build.xml,birt/build.xml, diff --git a/framework/component-load.xml b/framework/component-load.xml index 01c0629b25..addb95afb3 100644 --- a/framework/component-load.xml +++ b/framework/component-load.xml @@ -32,7 +32,6 @@ under the License. - diff --git a/framework/jcr/build.xml b/framework/jcr/build.xml deleted file mode 100644 index 1d08c7eecc..0000000000 --- a/framework/jcr/build.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/jcr/config/custom-jackrabbit-nodetypes.xml b/framework/jcr/config/custom-jackrabbit-nodetypes.xml deleted file mode 100644 index bba7fa043d..0000000000 --- a/framework/jcr/config/custom-jackrabbit-nodetypes.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - nt:base - - - - - \ No newline at end of file diff --git a/framework/jcr/config/jackrabbit.xml b/framework/jcr/config/jackrabbit.xml deleted file mode 100644 index 0739fa9779..0000000000 --- a/framework/jcr/config/jackrabbit.xml +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/framework/jcr/config/jcr-config.xml b/framework/jcr/config/jcr-config.xml deleted file mode 100644 index 98f3b015a6..0000000000 --- a/framework/jcr/config/jcr-config.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/jcr/config/jcr-test-config.xml b/framework/jcr/config/jcr-test-config.xml deleted file mode 100644 index 0e6c027e1a..0000000000 --- a/framework/jcr/config/jcr-test-config.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/jcr/lib/cglib-2.2.jar b/framework/jcr/lib/cglib-2.2.jar deleted file mode 100644 index 084ef6e54b..0000000000 Binary files a/framework/jcr/lib/cglib-2.2.jar and /dev/null differ diff --git a/framework/jcr/lib/concurrent-1.3.4.jar b/framework/jcr/lib/concurrent-1.3.4.jar deleted file mode 100644 index 551f347142..0000000000 Binary files a/framework/jcr/lib/concurrent-1.3.4.jar and /dev/null differ diff --git a/framework/jcr/lib/jackrabbit-api-2.3.3.jar b/framework/jcr/lib/jackrabbit-api-2.3.3.jar deleted file mode 100644 index 43ca34c7a8..0000000000 Binary files a/framework/jcr/lib/jackrabbit-api-2.3.3.jar and /dev/null differ diff --git a/framework/jcr/lib/jackrabbit-core-2.3.3.jar b/framework/jcr/lib/jackrabbit-core-2.3.3.jar deleted file mode 100644 index 3d52cfc65e..0000000000 Binary files a/framework/jcr/lib/jackrabbit-core-2.3.3.jar and /dev/null differ diff --git a/framework/jcr/lib/jackrabbit-jca-2.3.3.jar b/framework/jcr/lib/jackrabbit-jca-2.3.3.jar deleted file mode 100644 index 4c01421974..0000000000 Binary files a/framework/jcr/lib/jackrabbit-jca-2.3.3.jar and /dev/null 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 deleted file mode 100644 index 344132b6b9..0000000000 Binary files a/framework/jcr/lib/jackrabbit-jcr-commons-2.3.3.jar and /dev/null differ diff --git a/framework/jcr/lib/jackrabbit-ocm-2.0.jar b/framework/jcr/lib/jackrabbit-ocm-2.0.jar deleted file mode 100644 index dc368c694d..0000000000 Binary files a/framework/jcr/lib/jackrabbit-ocm-2.0.jar and /dev/null differ diff --git a/framework/jcr/lib/jackrabbit-spi-2.3.3.jar b/framework/jcr/lib/jackrabbit-spi-2.3.3.jar deleted file mode 100644 index bb9ce8475d..0000000000 Binary files a/framework/jcr/lib/jackrabbit-spi-2.3.3.jar and /dev/null 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 deleted file mode 100644 index dec4de8695..0000000000 Binary files a/framework/jcr/lib/jackrabbit-spi-commons-2.3.3.jar and /dev/null differ diff --git a/framework/jcr/lib/jcr-2.0.jar b/framework/jcr/lib/jcr-2.0.jar deleted file mode 100644 index 6afce9b584..0000000000 Binary files a/framework/jcr/lib/jcr-2.0.jar and /dev/null differ diff --git a/framework/jcr/lib/tagsoup-1.2.1.jar b/framework/jcr/lib/tagsoup-1.2.1.jar deleted file mode 100644 index 2751601917..0000000000 Binary files a/framework/jcr/lib/tagsoup-1.2.1.jar and /dev/null differ diff --git a/framework/jcr/ofbiz-component.xml b/framework/jcr/ofbiz-component.xml deleted file mode 100644 index 56ba5fc938..0000000000 --- a/framework/jcr/ofbiz-component.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - diff --git a/framework/jcr/servicedef/services.xml b/framework/jcr/servicedef/services.xml deleted file mode 100644 index eb9efda131..0000000000 --- a/framework/jcr/servicedef/services.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - 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 deleted file mode 100644 index f1e5ce9421..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index 3beea5e010..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java +++ /dev/null @@ -1,36 +0,0 @@ -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 deleted file mode 100644 index eee919b6f4..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java +++ /dev/null @@ -1,144 +0,0 @@ -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 deleted file mode 100644 index 0217064697..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java +++ /dev/null @@ -1,70 +0,0 @@ -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 deleted file mode 100644 index 7827903e97..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 74cbad1c67..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java +++ /dev/null @@ -1,220 +0,0 @@ -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.JackrabbitUtils; - -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 = JackrabbitUtils.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 = JackrabbitUtils.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. - */ - private QueryResult executeQuery(String statement) throws RepositoryException { - // TODO create a query manager which uses the OCM Layer. - if (statement.trim().toLowerCase().startsWith("select")) { - return executeQuery(statement, Query.JCR_SQL2); - } else { - return executeQuery(statement, Query.JCR_JQOM); - } - } - - private QueryResult executeQuery(String statement, String queryType) throws RepositoryException { - QueryManager qm = getQueryManager(); - return qm.createQuery(statement, queryType).execute(); - } - - private QueryManager getQueryManager() throws RepositoryException { - return ocm.getSession().getWorkspace().getQueryManager(); - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java deleted file mode 100644 index 84808a4754..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java +++ /dev/null @@ -1,204 +0,0 @@ -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.JackrabbitUtils; - -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 { - // 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(), getJcrTypeFromOrmAnnotation(orm)); - } 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(); - } - - private String getJcrTypeFromOrmAnnotation(OfbizRepositoryMapping orm) { - org.apache.jackrabbit.ocm.mapper.impl.annotation.Node annotationForNodeClass = orm.getClass().getAnnotation(org.apache.jackrabbit.ocm.mapper.impl.annotation.Node.class); - - return annotationForNodeClass.jcrType(); - } - - /* - * (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 = JackrabbitUtils.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 { - String[] nodeStructure = splitNodePathByDelimiter(completeNodePath); - 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; - } - - for (int i = 0; i < (nodeStructure.length - 1); i++) { - String node = nodeStructure[i]; - if (UtilValidate.isNotEmpty(node)) { - parentNode = createNewSubNodeIfNotExist(primaryNodeType, parentNode, node); - } - } - } - - private String[] splitNodePathByDelimiter(String completeNodePath) { - return completeNodePath.split(ConstantsJackrabbit.NODEPATHDELIMITER); - } - - /** - * 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 { - - versioningManager.checkOutContentObject(parentNode.getPath()); - - if (parentNode.hasNode(node)) { - parentNode = parentNode.getNode(node); - } else { - - 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 (JackrabbitUtils.isNotARootNode(parentNode)) { - 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 deleted file mode 100644 index d91eee9d4b..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java +++ /dev/null @@ -1,243 +0,0 @@ -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; - private final GenericValue userLogin; - - /** - * Create a repository Access object based on the userLogin. - * - * @param userLogin - */ - public JackrabbitRepositoryAccessor(GenericValue userLogin) { - this.userLogin = userLogin; - // TODO pass the userLogin to the getSession() method and perform some - this.session = JCRFactoryUtil.getSession(); - this.ocm = new ObjectContentManagerImpl(session, JCRFactoryImpl.getMapper()); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.access.JcrRepositoryAccessor#getSession() - */ - @Override - public Session getSession() { - return this.session; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.access.JcrRepositoryAccessor#closeAccess() - */ - @Override - public void closeAccess() { - if (this.ocm != null && this.ocm.getSession().isLive()) { - this.ocm.logout(); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.access.JcrRepositoryAccessor#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.JcrRepositoryAccessor#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.access.JcrRepositoryAccessor#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.access.JcrRepositoryAccessor#updateContentObject(org.ofbiz - * .jcr.orm.OfbizRepositoryMapping) - */ - @Override - public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { - ContentWriter contentWriter = new ContentWriterJackrabbit(this.ocm); - contentWriter.updateContentObject(orm); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.access.JcrRepositoryAccessor#removeContentObject(java.lang - * .String) - */ - @Override - public void removeContentObject(String nodePath) throws ObjectContentManagerException { - ContentWriter contentWriter = new ContentWriterJackrabbit(this.ocm); - contentWriter.removeContentObject(nodePath); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.access.JcrRepositoryAccessor#removeContentObject(org.ofbiz - * .jcr.orm.OfbizRepositoryMapping) - */ - @Override - public void removeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { - removeContentObject(orm.getPath()); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.access.JcrRepositoryAccessor#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.JcrRepositoryAccessor#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.JcrRepositoryAccessor#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.access.JcrRepositoryAccessor#getJsonDataTree() - */ - @Override - public JSONArray getJsonDataTree() throws RepositoryException { - ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); - return contentReader.getJsonDataTree(); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.access.JcrRepositoryAccessor#getJsonFileTree() - */ - @Override - public JSONArray getJsonFileTree() throws RepositoryException { - ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); - return contentReader.getJsonFileTree(); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.access.JcrRepositoryAccessor#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; - } - } - - /** - * Returns the party ID which created the accessor. - * - * @return - */ - private String getPartyId() { - return this.userLogin.getString("partyId"); - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java b/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java deleted file mode 100644 index a56aa63349..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java +++ /dev/null @@ -1,266 +0,0 @@ -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.PathNotFoundException; -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; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -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 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 (isNotRootVersion(version)) { - 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 (JackrabbitUtils.isARootNode(nodePath)) { - return; - } - - try { - if (doNodeExist(nodePath) && isNodeNotCheckedOut(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 checkOutAllSubnodes) { - if (checkOutAllSubnodes) { - 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() { - ocm.save(); - - try { - for (String nodePath : checkedOutNodeStore) { - checkinNode(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) - */ - @Override - 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) - */ - @Override - 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 - */ - private void checkOutRelatedNodes(String startNodePath) throws RepositoryException { - Node startNode = getNode(startNodePath); - List nodesToCheckOut = new ArrayList(); - - nodesToCheckOut.add(startNodePath); - nodesToCheckOut.add(startNode.getParent().getPath()); - - if (startNode.hasNodes()) { - List allChildNodes = getAllChildNodes(startNode); - nodesToCheckOut.addAll(allChildNodes); - } - - for (String node : nodesToCheckOut) { - this.checkOutContentObject(node); - } - - } - - /** - * Return recursively all child nodes - * - * @param startNode - * @return - * @throws RepositoryException - */ - private List getAllChildNodes(Node startNode) throws RepositoryException { - List nodes = new ArrayList(); - - NodeIterator subNodeIterator = startNode.getNodes(); - while (subNodeIterator.hasNext()) { - Node subNode = subNodeIterator.nextNode(); - - if (subNode.hasNodes()) { - nodes.addAll(getAllChildNodes(subNode)); - } - - nodes.add(subNode.getPath()); - } - - return nodes; - } - - private void checkinNode(String nodePath) throws RepositoryException, UnsupportedRepositoryOperationException, VersionException { - if (doNodeExist(nodePath) && this.isNodeCheckedOut(nodePath)) { - this.ocm.checkin(nodePath); - } - } - - private Node getNode(String startNodePath) throws PathNotFoundException, RepositoryException { - return ocm.getSession().getNode(startNodePath); - } - - private boolean isNotRootVersion(Version version) { - return !ConstantsJackrabbit.ROOTVERSION.equals(version.getName()); - } - - private boolean doNodeExist(String nodePath) throws RepositoryException { - return this.ocm.getSession().nodeExists(nodePath); - } - - private boolean isNodeNotCheckedOut(String nodePath) throws RepositoryException, UnsupportedRepositoryOperationException { - return !isNodeCheckedOut(nodePath); - } - - private boolean isNodeCheckedOut(String nodePath) throws UnsupportedRepositoryOperationException, RepositoryException { - boolean isNodeMarkedAsCheckedOut = this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath); - boolean isNodeInCheckedOutNodeStore = checkedOutNodeStore.contains(nodePath); - - return (isNodeMarkedAsCheckedOut && isNodeInCheckedOutNodeStore); - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java deleted file mode 100644 index 0e9962cd34..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -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.data.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 - * @param partyThatChangedThisContent - * @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 deleted file mode 100644 index 1830d6ea53..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java +++ /dev/null @@ -1,76 +0,0 @@ -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.file.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 deleted file mode 100644 index e21fc5d042..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/JcrHelper.java +++ /dev/null @@ -1,25 +0,0 @@ -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> queryData(String query) throws RepositoryException; - -} \ No newline at end of file diff --git a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitAbstractHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitAbstractHelper.java deleted file mode 100644 index f4e324a53f..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitAbstractHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.ofbiz.jcr.api.jackrabbit; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.jcr.RepositoryException; -import javax.jcr.query.QueryResult; -import javax.jcr.query.Row; -import javax.jcr.query.RowIterator; - -import javolution.util.FastMap; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.jcr.access.JcrRepositoryAccessor; -import org.ofbiz.jcr.api.JcrHelper; - -public abstract class JackrabbitAbstractHelper implements JcrHelper { - - private static String module = JackrabbitAbstractHelper.class.getName(); - - protected final JcrRepositoryAccessor access; - - public JackrabbitAbstractHelper(JcrRepositoryAccessor accessor) { - this.access = accessor; - } - - /* (non-Javadoc) - * @see org.ofbiz.jcr.api.jackrabbit.JcrHelper#closeContentSession() - */ - @Override - public void closeContentSession() { - access.closeAccess(); - } - - /* (non-Javadoc) - * @see org.ofbiz.jcr.api.jackrabbit.JcrHelper#removeContentObject(java.lang.String) - */ - @Override - public void removeContentObject(String contentPath) { - access.removeContentObject(contentPath); - } - - /* (non-Javadoc) - * @see org.ofbiz.jcr.api.jackrabbit.JcrHelper#queryData(java.lang.String) - */ - @Override - public List> queryData(String query) throws RepositoryException { - QueryResult qr = this.access.queryForRepositoryData(query); - - List> resultNodePaths = new ArrayList>(); - RowIterator rows = qr.getRows(); - while (rows.hasNext()) { - Row row = rows.nextRow(); - Map content = FastMap.newInstance(); - content.put("path", row.getPath()); - content.put("score", String.valueOf(row.getScore())); - - resultNodePaths.add(content); - if (Debug.isOn(Debug.INFO)) { - Debug.logInfo("For query: " + query + " found node with path: " + row.getPath(), module); - } - - } - - return resultNodePaths; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java deleted file mode 100644 index da5d8d63cf..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java +++ /dev/null @@ -1,397 +0,0 @@ -package org.ofbiz.jcr.api.jackrabbit; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Locale; - -import javax.jcr.ItemExistsException; -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.ValueFormatException; - -import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; -import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; -import org.ofbiz.jcr.api.JcrDataHelper; -import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -/** - * This Helper class encapsulate the jcr article content bean. it provide all - * attributes and operations which are necessary to work with the content - * repository. - * - * The concrete implementations covers the different content use case related - * workflows. I.E. Different behavior for File/Folder or Text content. - * - * The Helper classes should be build on top of the generic JCR implementation - * in the Framework. - * - */ -public class JackrabbitArticleHelper extends JackrabbitAbstractHelper implements JcrDataHelper { - - private final static String module = JackrabbitArticleHelper.class.getName(); - - private JackrabbitArticle article = null; - private static List possibleLocales = null; - - static { - if (UtilValidate.isEmpty(possibleLocales)) { - possibleLocales = new ArrayList(); - List locales = org.ofbiz.base.util.UtilMisc.availableLocales(); - for (Locale locale : locales) { - possibleLocales.add(locale.toString()); - } - } - } - - /** - * Setup my content Object - */ - public JackrabbitArticleHelper(GenericValue userLogin) { - super(new JackrabbitRepositoryAccessor(userLogin)); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#readContentFromRepository(java - * .lang.String) - */ - @Override - public JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException, PathNotFoundException { - return readContentFromRepository(contentPath, ""); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#readContentFromRepository(java - * .lang.String, java.lang.String) - */ - @Override - public JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException, PathNotFoundException { - contentPath = determineContentLanguagePath(contentPath, language); - - OfbizRepositoryMapping orm = super.access.getContentObject(contentPath); - setArticleContentObject(orm); - - article.setVersion(super.access.getBaseVersion(contentPath)); - return article; - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#readContentFromRepository(java - * .lang.String, java.lang.String, java.lang.String) - */ - @Override - public JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException, PathNotFoundException { - contentPath = determineContentLanguagePath(contentPath, language); - - OfbizRepositoryMapping orm = super.access.getContentObject(contentPath, version); - setArticleContentObject(orm); - - // manipulating the content path, because the jackrabbit orm - // returns a content path with version information. - article.setPath(contentPath); - return article; - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#storeContentInRepository(java - * .lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.util.Calendar) - */ - @Override - public void storeContentInRepository(String contentPath, String language, String title, String content, Calendar publicationDate) throws ObjectContentManagerException, ItemExistsException { - if (UtilValidate.isEmpty(language)) { - language = JackrabbitUtils.determindeTheDefaultLanguage(); - } - - article = new JackrabbitArticle(contentPath, language, title, content, publicationDate); - super.access.storeContentObject(article); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#updateContentInRepository(org - * .ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle) - */ - @Override - public void updateContentInRepository(JackrabbitArticle updatedArticle) throws RepositoryException, ObjectContentManagerException { - // if the item not already exist create it. - if (!super.access.checkIfNodeExist(updatedArticle.getPath())) { - Debug.logWarning("This content object with the path: " + updatedArticle.getPath() + " doesn't exist in the repository. It will now created.", module); - this.storeContentInRepository(updatedArticle.getPath(), updatedArticle.getLanguage(), updatedArticle.getTitle(), updatedArticle.getContent(), updatedArticle.getPubDate()); - return; - } - - super.access.updateContentObject(updatedArticle); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.DataHelper#getVersionListForCurrentArticle() - */ - @Override - public List getVersionListForCurrentArticle() { - List versions = new ArrayList(); - - if (article != null) { - versions = super.access.getVersionList(article.getPath()); - } else { - Debug.logWarning("No Article is loaded from the repository, please load an article first before requesting the version list.", module); - } - - return versions; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.api.jackrabbit.DataHelper#getAvailableLanguageList() - */ - @Override - public List getAvailableLanguageList() { - List availableLanguages = new ArrayList(); - - if (article == null || !article.getLocalized()) { - Debug.logWarning("No Article is loaded from the repository, please load an article first before requesting the version list.", module); - return availableLanguages; - } - - Session session = super.access.getSession(); - - try { - Node node = session.getNode(article.getPath()).getParent(); - NodeIterator nodeList = node.getNodes(); - - while (nodeList.hasNext()) { - Node currentNodeToExtractLanguage = nodeList.nextNode(); - // only use nodes which have the language mix in - if (checkIfNodeHaveValidLanguageMixIn(currentNodeToExtractLanguage)) { - String languageFlag = extractLanguageFlagFromNodePath(currentNodeToExtractLanguage.getPath()); - availableLanguages.add(languageFlag); - } - } - - } catch (PathNotFoundException e) { - Debug.logError(e, module); - } catch (RepositoryException e) { - Debug.logError(e, module); - } - - return availableLanguages; - } - - /** - * This method should determine the correct language for the content. It - * covers the case when the passed language is not available. - * - * A default (system) language will be taken, if the passed language, does - * not exist, if no default language node is specified the first language - * node which will be found will be choose. - * - * @param contentPath - * @param contentLanguage - * @return - * @throws PathNotFoundException - */ - private String determineContentLanguagePath(String contentPath, String contentLanguage) throws PathNotFoundException { - // return if only the root node path is requested - if (JackrabbitUtils.isARootNode(contentPath)) { - return contentPath; - } - - // contentLanaguage should never be null, because the concatenation - // goes wrong if the String have a null value. - if (contentLanguage == null) { - contentLanguage = ""; - } - - String canonicalizedContentPath = canonicalizeContentPath(contentPath, contentLanguage); - - // Step 1.) Check if the requested node language combination exist and - // if it have a valid localize flag - // Step 2.) If the first condition is not true, check the combination - // from node path and default language have a valid node result - // Step 3.) If condition one and two are false, determine the first node - // which have a valid language flag - - if (super.access.checkIfNodeExist(canonicalizedContentPath + contentLanguage) && checkIfNodeHaveValidLanguageMixIn(canonicalizedContentPath + contentLanguage)) { - contentPath = canonicalizedContentPath + contentLanguage; - - } else if (super.access.checkIfNodeExist(canonicalizedContentPath + JackrabbitUtils.determindeTheDefaultLanguage())) { - contentPath = canonicalizedContentPath + JackrabbitUtils.determindeTheDefaultLanguage(); - - } else { - contentPath = determineFirstAvailableLanguageNode(canonicalizedContentPath); - } - - return contentPath; - } - - /** - * Iterate over all child nodes and returns the first with a valid language - * flag. - * - * @param canonicalizedContentPath - * @return - * @throws PathNotFoundException - */ - private String determineFirstAvailableLanguageNode(String canonicalizedContentPath) throws PathNotFoundException { - String contentPath = ""; - - try { - // return the first available language - NodeIterator childNodes = super.access.getSession().getNode(canonicalizedContentPath).getNodes(); - while (childNodes.hasNext()) { - Node child = childNodes.nextNode(); - if (possibleLocales.contains(child.getName()) && checkIfNodeHaveValidLanguageMixIn(child)) { - contentPath = child.getPath(); - break; - } - } - childNodes = null; - } catch (PathNotFoundException pnf) { - throw new PathNotFoundException(pnf); - } catch (RepositoryException e) { - Debug.logError(e, module); - } - return contentPath; - } - - /** - * We check if the content path already contains a language. If a language - * is found it will be removed from the path string. - * - * @param contentPath - * @return - */ - private String canonicalizeContentPath(String contentPath, String contentLanguage) { - // we split the path string in chunks - String[] splitContentPath = contentPath.split(ConstantsJackrabbit.NODEPATHDELIMITER); - - String canonicalizedCotnentPath = ""; - // check if the last chunk contains a language flags, which is part of - // our locale list. - // It's possible to request a node directly with the language in the - // URL. If the node path contains a language and the language should not - // be changed (contentLanaguage is empty), the language flag stay in the - // content path. Otherwise it will be removed. - if (UtilValidate.isNotEmpty(contentLanguage) && possibleLocales.contains(splitContentPath[splitContentPath.length - 1])) { - canonicalizedCotnentPath = buildCanonicalizeContentPath(splitContentPath, splitContentPath.length - 1); - } else { - canonicalizedCotnentPath = buildCanonicalizeContentPath(splitContentPath, splitContentPath.length); - } - - return canonicalizedCotnentPath; - } - - /** - * Build a new path string from the split content path. A loop iterates - * throw the array until lastFieldWhichShouldBeAddedToTheNewPathString is - * reached. That means if you want to avoid that the last field of the array - * is added to the string lastFieldWhichShouldBeAddedToTheNewPathString - * should be array.length -1. - * - * @param splitContentPath - * @param lastFieldWhichShouldBeAddedToTheNewPathString - * @return - */ - private String buildCanonicalizeContentPath(String[] splitContentPath, int lastFieldWhichShouldBeAddedToTheNewPathString) { - StringBuffer canonicalizedContentPath = new StringBuffer(ConstantsJackrabbit.ROOTPATH); - - for (int i = 0; i < lastFieldWhichShouldBeAddedToTheNewPathString; i++) { - if (UtilValidate.isNotEmpty(splitContentPath[i])) { - canonicalizedContentPath.append(splitContentPath[i]).append(ConstantsJackrabbit.NODEPATHDELIMITER); - } - } - return canonicalizedContentPath.toString(); - } - - /** - * This extract the language flag from the node path, normally the language - * should be the substring after the last / (slash). - * - * @param nodePathWithLanguageFlag - * @return - */ - private String extractLanguageFlagFromNodePath(String nodePathWithLanguageFlag) { - int startPointAfterLastSlash = nodePathWithLanguageFlag.lastIndexOf(ConstantsJackrabbit.NODEPATHDELIMITER) + 1; - - return nodePathWithLanguageFlag.substring(startPointAfterLastSlash); - } - - /** - * Checks if a node have the property localized and if this - * property is be true. If an exception occurs false will be - * returned. - * - * @param nodePathWhichShouldHaveAValidLanguageFlag - * @return - */ - private boolean checkIfNodeHaveValidLanguageMixIn(String nodePathWhichShouldHaveAValidLanguageFlag) { - try { - Node node = super.access.getSession().getNode(nodePathWhichShouldHaveAValidLanguageFlag); - return checkIfNodeHaveValidLanguageMixIn(node); - } catch (RepositoryException e) { - Debug.logError(e, module); - return false; - } - } - - /** - * Checks if a node have the property localized and if this - * property is true - * - * @param nodeWhichShouldHaveAValidLanguageFlag - * @return - * @throws RepositoryException - * @throws ValueFormatException - * @throws PathNotFoundException - */ - private boolean checkIfNodeHaveValidLanguageMixIn(Node nodeWhichShouldHaveAValidLanguageFlag) throws RepositoryException, ValueFormatException, PathNotFoundException { - boolean hasProperty = nodeWhichShouldHaveAValidLanguageFlag.hasProperty("localized"); - - return hasProperty && nodeWhichShouldHaveAValidLanguageFlag.getProperty("localized").getBoolean(); - } - - /** - * Set the article class variable if the orm Object is an - * instance of JackrabbitArticle. Throws a ClassCastException - * if the orm Object is from another type. - * - * @param orm - * @throws ClassCastException - * @return - */ - private void setArticleContentObject(OfbizRepositoryMapping orm) throws ClassCastException { - if (orm != null && orm instanceof JackrabbitArticle) { - article = (JackrabbitArticle) orm; - return; - } - - throw new ClassCastException("The content object for the path: " + orm.getPath() + " is not an article content object. This Helper can only handle content objects with the type: " + JackrabbitArticle.class.getName()); - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java b/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java deleted file mode 100644 index 6cb2dd7946..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java +++ /dev/null @@ -1,218 +0,0 @@ -package org.ofbiz.jcr.api.jackrabbit; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.GregorianCalendar; - -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; - -import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; -import org.apache.tika.Tika; -import org.apache.tika.io.TikaInputStream; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; -import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; -import org.ofbiz.jcr.api.JcrFileHelper; -import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFile; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFolder; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitHierarchyNode; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitResource; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -/** - * This Helper class encapsulate the jcr file content bean. it provide all - * attributes and operations which are necessary to work with the content - * repository. - * - * The concrete implementations covers the different content use case related - * workflows. I.E. Different behavior for File/Folder or Text content. - * - * The Helper classes should be build on top of the generic JCR implementation - * in the Framework. - * - */ -public class JackrabbitFileHelper extends JackrabbitAbstractHelper implements JcrFileHelper { - - private final static String module = JackrabbitFileHelper.class.getName(); - - private JackrabbitHierarchyNode hierarchy = null; - - public JackrabbitFileHelper(GenericValue userLogin) { - super(new JackrabbitRepositoryAccessor(userLogin)); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.FileHelper#getRepositoryContent(java.lang - * .String) - */ - @Override - public JackrabbitHierarchyNode getRepositoryContent(String contentPath) throws ClassCastException, PathNotFoundException { - return getRepositoryContent(contentPath, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.FileHelper#getRepositoryContent(java.lang - * .String, java.lang.String) - */ - @Override - public JackrabbitHierarchyNode getRepositoryContent(String contentPath, String version) throws ClassCastException, PathNotFoundException { - OfbizRepositoryMapping orm = null; - if (version != null) { - orm = super.access.getContentObject(contentPath, version); - } else { - orm = super.access.getContentObject(contentPath); - } - - if (orm instanceof JackrabbitFile) { - hierarchy = (JackrabbitFile) orm; - } else if (orm instanceof JackrabbitFolder) { - hierarchy = (JackrabbitFolder) orm; - } else { - throw new ClassCastException("The content object for the path: " + contentPath + " is not a file content object. This Helper can only handle content objects with the type: " + JackrabbitFile.class.getName()); - } - - return hierarchy; - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.FileHelper#storeContentInRepository(byte[], - * java.lang.String, java.lang.String) - */ - @Override - public void storeContentInRepository(byte[] fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException { - storeContentInRepository(new ByteArrayInputStream(fileData), fileName, folderPath); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.api.jackrabbit.FileHelper#storeContentInRepository(java - * .io.InputStream, java.lang.String, java.lang.String) - */ - @Override - public void storeContentInRepository(InputStream fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException { - if (UtilValidate.isEmpty(folderPath)) { - throw new ObjectContentManagerException("Please specify a folder path, the folder path should not be empty!"); - } else if (ConstantsJackrabbit.ROOTPATH.equals(folderPath)) { - throw new ObjectContentManagerException("Please specify a folder, a file content can't be stored directly under root."); - } - - JackrabbitResource ormResource = createResource(fileData); - - JackrabbitFile ormFile = createFile(fileName, ormResource); - - // Create the folder if necessary, otherwise we just update the folder - // content - folderPath = JackrabbitUtils.createAbsoluteNodePath(folderPath); - if (super.access.checkIfNodeExist(folderPath)) { - OfbizRepositoryMapping orm = super.access.getContentObject(folderPath); - if (orm instanceof JackrabbitFolder) { - JackrabbitFolder ormFolder = (JackrabbitFolder) orm; - ormFolder.addChild(ormFile); - super.access.updateContentObject(ormFolder); - } - } else { - JackrabbitFolder ormFolder = createFolder(folderPath, ormFile); - super.access.storeContentObject(ormFolder); - } - - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.api.jackrabbit.FileHelper#isFileContent() - */ - @Override - public boolean isFileContent() { - return (hierarchy instanceof JackrabbitFile); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.api.jackrabbit.FileHelper#isFolderContent() - */ - @Override - public boolean isFolderContent() { - return (hierarchy instanceof JackrabbitFolder); - } - - private static String getMimeTypeFromInputStream(InputStream is) { - if (!TikaInputStream.isTikaInputStream(is)) { - is = TikaInputStream.get(is); - } - Tika tika = new Tika(); - try { - return tika.detect(is); - } catch (IOException e) { - Debug.logError(e, module); - return "application/octet-stream"; - } - } - - /** - * Creates a Jackrabbit Folder Object which should be stored in the - * repository. - * - * @param folderPath - * @param ormFile - * @return - */ - private JackrabbitFolder createFolder(String folderPath, JackrabbitFile ormFile) { - // create the ORM folder Object - JackrabbitFolder ormFolder = new JackrabbitFolder(); - ormFolder.addChild(ormFile); - ormFolder.setPath(folderPath); - return ormFolder; - } - - /** - * Creates a Jackrabbit File Object which is needed for a Jackrabbit Folder - * Object. - * - * @param fileName - * @param ormResource - * @return - */ - private JackrabbitFile createFile(String fileName, JackrabbitResource ormResource) { - // create an ORM File Object - JackrabbitFile ormFile = new JackrabbitFile(); - ormFile.setCreationDate(new GregorianCalendar()); - ormFile.setResource(ormResource); - ormFile.setPath(fileName); - return ormFile; - } - - /** - * Creates a Jackrabbit Resource Object which is needed for a Jackrabbit - * File Object. - * - * @param fileData - * @return - */ - private JackrabbitResource createResource(InputStream fileData) { - // create an ORM Resource Object - JackrabbitResource ormResource = new JackrabbitResource(); - ormResource.setData(fileData); - ormResource.setMimeType(getMimeTypeFromInputStream(fileData)); - ormResource.setLastModified(new GregorianCalendar()); - return ormResource; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/handler/JcrEventHandler.java b/framework/jcr/src/org/ofbiz/jcr/handler/JcrEventHandler.java deleted file mode 100644 index 8053b1e025..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/handler/JcrEventHandler.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.ofbiz.jcr.handler; - -public interface JcrEventHandler { - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java b/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java deleted file mode 100644 index 28495570d0..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * 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.loader; - -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 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 { - readContainerConfig(configFile); - - Element configRootElement = getConfigFileRootElement(); - - Element factoryImplDefinition = getJcrFactoryImplementationClassName(configRootElement); - initializeJcrFactory(configRootElement, factoryImplDefinition); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.base.container.Container#start() - */ - @Override - public boolean start() throws ContainerException { - JCRFactory jcrFactory = getJCRFactory(); - - 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 = getJCRFactory(); - - try { - jcrFactory.stop(removeRepositoryOnShutdown); - } catch (RepositoryException e) { - throw new ContainerException("Cannot stop JCRFactory context", e); - } - } - - - public static String getConfigFilePath() { - return configFilePath; - } - - private void readContainerConfig(String configFile) throws ContainerException { - // get the container configuration - ContainerConfig.Container cc = ContainerConfig.getContainer("jcr-container", configFile); - if (cc == null) { - throw new ContainerException("No jcr-container configuration found in container config!"); - } - - // embedded properties - removeRepositoryOnShutdown = ContainerConfig.getPropertyValue(cc, "removeRepositoryOnShutdown", false); - configFilePath = ContainerConfig.getPropertyValue(cc, "configFilePath", DEFAULT_JCR_CONFIG_PATH); - } - - private Element getConfigFileRootElement() throws ContainerException { - 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); - } - return configRootElement; - } - - private Element getJcrFactoryImplementationClassName(Element configRootElement) { - Element childElement = UtilXml.firstChildElement(configRootElement, "jcr-context"); - String jcrContextName = UtilXml.elementAttribute(childElement, "name", "default"); - - // find the default JCR implementation - for (Element curElement : UtilXml.childElementList(configRootElement, "jcr")) { - if (jcrContextName.equals(curElement.getAttribute("name"))) { - return curElement; - } - } - - return null; - } - - private void initializeJcrFactory(Element configRootElement, Element factoryImplDefinition) throws ContainerException { - JCRFactoryUtil.setJcrFactoryClassName(factoryImplDefinition.getAttribute("class")); - JCRFactory jcrFactory = getJCRFactory(); - - try { - jcrFactory.initialize(configRootElement, factoryImplDefinition); - } catch (RepositoryException e) { - throw new ContainerException("Cannot initialize JCRFactory context", e); - } - } - - private JCRFactory getJCRFactory() throws ContainerException { - JCRFactory jcrFactory = JCRFactoryUtil.getJCRFactory(); - if (jcrFactory == null) { - throw new ContainerException("Cannot load JCRFactory implementation class"); - } - return jcrFactory; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java b/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java deleted file mode 100644 index 9fb0d9edb3..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * 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.loader; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.w3c.dom.Element; - -public interface JCRFactory { - - /** - * - * @param configRootElement - * @param factoryImplDefinition - * @throws RepositoryException - */ - public void initialize(Element configRootElement, Element factoryImplDefinition) 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; - - /** - * Should return an instance of the repository implementation. - * - * @return - */ - public Repository getInstance(); - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java b/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java deleted file mode 100644 index 478155e61b..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * 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.loader; - -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; - private static String jcrFactoryName; - - /** - * - * @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(jcrFactoryName); - 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; - } - - public static void setJcrFactoryClassName(String jcrFactoryClassName) { - jcrFactoryName = jcrFactoryClassName; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java b/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java deleted file mode 100644 index 5d3096848c..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/JCRJndi.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.ofbiz.jcr.loader; - -import javax.jcr.Repository; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.StringRefAddr; - -import org.ofbiz.base.config.GenericConfigException; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.JNDIContextFactory; - -public class JCRJndi { - - public static final String module = JCRJndi.class.getName(); - - public final static String ADDR_TYPE_FOR_REPOSITORY_HOME_DIR = "REPHOME"; - public final String ADDR_TYPE_FOR_CONFIG_FILE_PATH = "CONFPATH"; - - private final String jndiName; - private final String configFilePath; - private final String repositoryHomeDir; - - public JCRJndi(String configFilePath, String jndiName, String repositoryHomeDir) { - this.configFilePath = configFilePath; - this.jndiName = jndiName; - this.repositoryHomeDir = repositoryHomeDir; - } - - public void registerJcrToJndi() { - InitialContext jndiContext = null; - - try { - jndiContext = getInitialContext(); - } catch (GenericConfigException e) { - Debug.logError(e, module); - } - - bindRepository(jndiContext); - // Test JNDI bind - RepositoryLoader.getRepository(); - } - - public void unbindRepository() { - try { - InitialContext jndiContext = getInitialContext(); - jndiContext.unbind(jndiName); - } catch (NamingException e) { - Debug.logError(e, module); - } catch (GenericConfigException e) { - Debug.logError(e, module); - } - } - - private InitialContext getInitialContext() throws GenericConfigException { - return JNDIContextFactory.getInitialContext("default"); - } - - private void bindRepository(InitialContext jndiContext) { - try { - Reference ref = new Reference(Repository.class.getName(), org.ofbiz.jcr.loader.RepositoryFactory.class.getName(), null); - ref.add(new StringRefAddr(ADDR_TYPE_FOR_REPOSITORY_HOME_DIR, repositoryHomeDir)); - ref.add(new StringRefAddr(ADDR_TYPE_FOR_CONFIG_FILE_PATH, configFilePath)); - jndiContext.bind(jndiName, ref); - Debug.logInfo("Repository bound to JNDI as " + jndiName, module); - } catch (NamingException ne) { - Debug.logError(ne, module); - } - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/OFBizLoginModule.java b/framework/jcr/src/org/ofbiz/jcr/loader/OFBizLoginModule.java deleted file mode 100644 index 563869609d..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/OFBizLoginModule.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * 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.loader; - -import java.io.IOException; -import java.util.Map; - -import javax.security.auth.Subject; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.auth.login.LoginException; -import javax.security.auth.spi.LoginModule; - -import javolution.util.FastMap; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.DelegatorFactory; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.service.GenericDispatcher; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.service.ServiceUtil; - -public class OFBizLoginModule implements LoginModule { - - public static final String module = OFBizLoginModule.class.getName(); - - protected Subject subject; - protected CallbackHandler callbackHandler; - protected Map sharedState; - protected Map options; - - private Delegator delegator; - private LocalDispatcher dispatcher; - - private GenericValue userLogin; - - @Override - public boolean abort() throws LoginException { - return logout(); - } - - @Override - public boolean commit() throws LoginException { - if (userLogin != null) { - return true; - } - return false; - } - - @Override - public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { - // get the delegator - delegator = DelegatorFactory.getDelegator("default"); - - // get the dispatcher - dispatcher = GenericDispatcher.getLocalDispatcher("auth-dispatcher", delegator); - - this.subject = subject; - this.callbackHandler = callbackHandler; - this.sharedState = sharedState; - this.options = options; - - if (options != null) { - for (Map.Entry option : options.entrySet()) { - Debug.logWarning("OFBizLoginModule does not support provided option [" + option.getKey() + "] with value [" + option.getValue() + "], ignoring", module); - } - } - } - - @Override - public boolean login() throws LoginException { - NameCallback nameCallback = new NameCallback("userLoginId"); - PasswordCallback passwordCallback = new PasswordCallback("currentPassword", false); - Callback[] callbacks = new Callback[]{nameCallback, passwordCallback}; - try { - callbackHandler.handle(callbacks); - } catch (IOException e) { - Debug.logError(e, module); - throw new LoginException(e.getMessage()); - } catch (UnsupportedCallbackException e) { - Debug.logError(e, module); - throw new LoginException(e.getMessage()); - } - - String userLoginId = nameCallback.getName(); - String password = String.valueOf(passwordCallback.getPassword()); - passwordCallback.clearPassword(); - // try matching against the encrypted password - try { - GenericValue newUserLogin = delegator.findOne("UserLogin", false, "userLoginId", userLoginId); - if (newUserLogin.getString("currentPassword") == null || newUserLogin.getString("currentPassword").equals(password)) { - userLogin = newUserLogin; - return true; - } - } catch (GenericEntityException e) { - Debug.logError(e, module); - } - // plain text password - if (UtilValidate.isNotEmpty(password)) { - Map loginCtx = FastMap.newInstance(); - loginCtx.put("login.username", userLoginId); - loginCtx.put("login.password", password); - try { - Map result = dispatcher.runSync("userLogin", loginCtx); - if (ServiceUtil.isSuccess(result)) { - userLogin = (GenericValue) result.get("userLogin"); - return true; - } - } catch (GenericServiceException e) { - Debug.logError(e, module); - throw new LoginException(e.getMessage()); - } - } - return false; - } - - @Override - public boolean logout() throws LoginException { - userLogin = null; - return true; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryFactory.java b/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryFactory.java deleted file mode 100644 index c803c8447e..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.ofbiz.jcr.loader; - -import java.io.File; -import java.util.Hashtable; -import java.util.Map; - -import javax.jcr.RepositoryException; -import javax.naming.Context; -import javax.naming.Name; -import javax.naming.Reference; -import javax.naming.spi.ObjectFactory; - -import org.apache.commons.collections.map.ReferenceMap; -import org.apache.jackrabbit.commons.JcrUtils; -import org.apache.jackrabbit.core.TransientRepository; - -public class RepositoryFactory implements ObjectFactory { - - private static final Map cache = new ReferenceMap(); - - public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws RepositoryException { - synchronized (cache) { - Object instance = cache.get(obj); - if (instance == null && obj instanceof Reference) { - Reference reference = (Reference) obj; - String repHomeDir = reference.get(JCRJndi.ADDR_TYPE_FOR_REPOSITORY_HOME_DIR).getContent().toString(); - // check if the repository is already started, than use it - // otherwise create it - File lock = new File(repHomeDir); - if (lock.exists()) { - instance = JcrUtils.getRepository(lock.toURI().toString()); - } else { - instance = new TransientRepository(reference.get(JCRContainer.DEFAULT_JCR_CONFIG_PATH).getContent().toString(), repHomeDir); - } - - cache.put(obj, instance); - } - - return instance; - } - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java b/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java deleted file mode 100644 index fabd78069f..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.ofbiz.jcr.loader; - -import java.util.Map; - -import javax.jcr.Repository; -import javax.naming.NamingException; - -import javolution.util.FastMap; - -import org.ofbiz.base.config.GenericConfigException; -import org.ofbiz.base.config.ResourceLoader; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.JNDIContextFactory; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.w3c.dom.Element; - -public class RepositoryLoader { - public static final String module = RepositoryLoader.class.getName(); - private static Map repositories = loadRepositories(); - - public static Repository getRepository(String name) { - return repositories.get(name); - } - - public static Repository getRepository() { - return repositories.get("default"); - } - - private static Repository createFromFactory(String repositoryName, ClassLoader loader, String className) { - try { - JCRFactory factory = (JCRFactory) loader.loadClass(className).newInstance(); - return factory.getInstance(); - } catch (InstantiationException e) { - Debug.logError(e, module); - } catch (IllegalAccessException e) { - Debug.logError(e, module); - } catch (ClassNotFoundException e) { - Debug.logError(e, module); - } - - return null; - } - - private static Map loadRepositories() { - Map repos = FastMap.newInstance(); - - String configFilePath = JCRContainer.getConfigFilePath(); - Element configRootElement = null; - try { - configRootElement = ResourceLoader.getXmlRootElement(configFilePath); - } catch (GenericConfigException e) { - Debug.logError(e, "Could not load the jcr configuration in file " + configFilePath, module); - } - - if (configRootElement == null) { - Debug.logError("No jcr configuration found in file " + configFilePath, module); - } - - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - // find the default JCR implementations - for (Element curElement : UtilXml.childElementList(configRootElement, "jcr")) { - String name = curElement.getAttribute("name"); - - // first check if the found repository is already in the repository - // map - if (repos.get(name) != null && (repos.get(name) instanceof Repository)) { - continue; - } - - String jndiName = curElement.getAttribute("jndi-name"); - if (UtilValidate.isNotEmpty(jndiName)) { - try { - repos.put(name, (Repository) JNDIContextFactory.getInitialContext("default").lookup(jndiName)); - } catch (NamingException e) { - Debug.logError(e, module); - } catch (GenericConfigException e) { - Debug.logError(e, module); - } - continue; - } - - String factoryClass = curElement.getAttribute("class"); - if (UtilValidate.isNotEmpty(factoryClass)) { - try { - repos.put(name, createFromFactory(name, loader, factoryClass)); - } catch (Exception e) { - Debug.logError(e, module); - } - } - - } - - return repos; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java b/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java deleted file mode 100644 index 50bcdf3a85..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * 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.loader.jackrabbit; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import javax.jcr.Credentials; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; -import javax.jcr.Workspace; -import javax.jcr.nodetype.NoSuchNodeTypeException; -import javax.jcr.nodetype.NodeTypeManager; - -import org.apache.commons.io.FileUtils; -import org.apache.jackrabbit.core.TransientRepository; -import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException; -import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl; -import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry; -import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader; -import org.apache.jackrabbit.ocm.mapper.Mapper; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl; -import org.apache.jackrabbit.ocm.nodemanagement.impl.RepositoryUtil; -import org.apache.jackrabbit.spi.QNodeTypeDefinition; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.entity.Delegator; -import org.ofbiz.jcr.loader.JCRFactory; -import org.ofbiz.jcr.loader.JCRJndi; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFile; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFolder; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitHierarchyNode; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitLocalizedContent; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitNews; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitResource; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitUnstructured; -import org.w3c.dom.Element; - -public class JCRFactoryImpl implements JCRFactory { - - public static final String module = JCRFactoryImpl.class.getName(); - - private static String CUSTOM_NODE_TYPES = "framework/jcr/config/custom-jackrabbit-nodetypes.xml"; - - 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; - - protected static Mapper mapper = null; - - private JCRJndi jndi; - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.JCRFactory#initialize(org.w3c.dom.Element) - */ - @Override - public void initialize(Element configRootElement, Element factoryImplDefinition) throws RepositoryException { - homeDir = UtilXml.childElementAttribute(configRootElement, "home-dir", "path", "runtime/data/jcr/"); - String factoryJndiName = factoryImplDefinition.getAttribute("jndi-name"); - - jndi = new JCRJndi(jackrabbitConfigFile, factoryJndiName, homeDir); - - 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"); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.JCRFactory#start() - */ - @Override - public void start() throws RepositoryException { - // Transient repositories closes automatically when the last session is - // closed - repository = new TransientRepository(jackrabbitConfigFile, homeDir); - createSession(); - - List classes = new ArrayList(); - // put this in an xml configuration file - // should the ocm classes be loaded in during the container startup? - classes.add(JackrabbitUnstructured.class); - classes.add(JackrabbitHierarchyNode.class); - classes.add(JackrabbitNews.class); - classes.add(JackrabbitFile.class); - classes.add(JackrabbitFolder.class); - classes.add(JackrabbitResource.class); - classes.add(JackrabbitLocalizedContent.class); - classes.add(JackrabbitArticle.class); - - mapper = new AnnotationMapperImpl(classes); - - jndi.registerJcrToJndi(); - } - - /* - * (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); - try { - FileUtils.deleteDirectory(homeDirFile); - } catch (IOException e) { - Debug.logError(e, module); - } - } - } - - jndi.unbindRepository(); - } - - /* - * (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); - // register NameSpaces - RepositoryUtil.setupSession(session); - try { - // register the cool new noteTypes - registerNodeTypes(session); - } catch (InvalidNodeTypeDefException e) { - Debug.logError(e, module); - } catch (IOException e) { - Debug.logError(e, module); - } - - } catch (RepositoryException e) { - Debug.logError(e, "Could not login to the workspace"); - throw e; - } - - } - return session; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.JCRFactory#getInstance() - */ - @Override - public Repository getInstance() { - return repository; - } - - public static Mapper getMapper() { - return mapper; - } - - /* - * Register some new node types - */ - private void registerNodeTypes(Session session) throws InvalidNodeTypeDefException, javax.jcr.RepositoryException, IOException { - InputStream xml = new FileInputStream(CUSTOM_NODE_TYPES); - - // HINT: throws InvalidNodeTypeDefException, IOException - QNodeTypeDefinition[] types = NodeTypeReader.read(xml); - - Workspace workspace = session.getWorkspace(); - NodeTypeManager ntMgr = workspace.getNodeTypeManager(); - NodeTypeRegistry ntReg = ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry(); - - for (int j = 0; j < types.length; j++) { - QNodeTypeDefinition def = types[j]; - - try { - ntReg.getNodeTypeDef(def.getName()); - } catch (NoSuchNodeTypeException nsne) { - // HINT: if not already registered than register custom node - // type - ntReg.registerNodeType(def); - } - - } - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java b/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java deleted file mode 100644 index 8742ca3106..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.ofbiz.jcr.orm; - -public interface OfbizRepositoryMapping { - /** - * Return the Node Path. - * - * @return - */ - String getPath(); - - /** - * Set the Node Path. - * - * @param path - */ - void setPath(String path); - - /** - * Return the current Version of the content object. - * - * @return - */ - public String getVersion(); - - /** - * Set the node version. - * - * @param version - */ - public void setVersion(String version); -} \ No newline at end of file diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java deleted file mode 100644 index 1024c27d08..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitArticle.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.data; - -import java.util.Calendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; - -@Node(extend = JackrabbitLocalizedContent.class) -public class JackrabbitArticle extends JackrabbitLocalizedContent { - - @Field(id = true) - String title = null; - @Field - String content = null; - @Field - Calendar pubDate = null; - - /** - * - * @param nodePath - * @param language - * @param title - * @param content - * @param pubDate - */ - public JackrabbitArticle(String nodePath, String language, String title, String content, Calendar pubDate) { - super(nodePath, language); - - this.title = title; - this.content = content; - this.pubDate = pubDate; - } - - /** - * - */ - public JackrabbitArticle() { - super(); - // create empty instance - } - - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Calendar getPubDate() { - return pubDate; - } - - public void setPubDate(Calendar pubDate) { - this.pubDate = pubDate; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitLocalizedContent.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitLocalizedContent.java deleted file mode 100644 index c1f0debaaf..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitLocalizedContent.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.data; - -import java.util.GregorianCalendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; -import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; - -@Node(isAbstract = true, extend = JackrabbitUnstructured.class) -public abstract class JackrabbitLocalizedContent extends JackrabbitUnstructured { - - @Field - private String language; - - public JackrabbitLocalizedContent() { - super(); - this.language = ""; - super.setLocalized(true); - super.setCreationDate(new GregorianCalendar()); - // create an empty localized object - } - - /** - * - * @param nodePath - * @param language - */ - public JackrabbitLocalizedContent(String nodePath, String language) { - super(nodePath); - this.language = language; - - super.setPath(createLanguagePath(nodePath)); - // define this node as a localized node - super.setLocalized(true); - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - private String createLanguagePath(String contentPath) { - // the content path should contain the language information - // TODO this have to be a little bit more intelligent in the future - if (contentPath.endsWith(ConstantsJackrabbit.NODEPATHDELIMITER)) { - contentPath = contentPath + language; - } else { - contentPath = contentPath + ConstantsJackrabbit.NODEPATHDELIMITER + language; - } - - return contentPath; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java deleted file mode 100644 index 92c5fb241a..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitNews.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.data; - -import java.util.Calendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; - -@Node(extend = JackrabbitLocalizedContent.class) -public class JackrabbitNews extends JackrabbitLocalizedContent { - - @Field(id = true) - String title = null; - @Field(jcrType = "Date") - Calendar pubDate = null; - @Field - String content = null; - - public JackrabbitNews() { - super(); - // create an empty object - } - - public JackrabbitNews(String nodePath, String language, String title, Calendar pubDate, String content) { - super(nodePath, language); - this.title = title; - this.pubDate = pubDate; - this.content = content; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Calendar getPubDate() { - return pubDate; - } - - public void setPubDate(Calendar pubDate) { - this.pubDate = pubDate; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java deleted file mode 100644 index 1de94fc3d7..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/data/JackrabbitUnstructured.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.data; - -import java.util.Calendar; -import java.util.GregorianCalendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; -import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -@Node(isAbstract = true, jcrMixinTypes = "mix:versionable") -public abstract class JackrabbitUnstructured implements OfbizRepositoryMapping { - - protected static String module = JackrabbitUnstructured.class.getName(); - - @Field(path = true) - private String path; - @Field - private String version; - @Field(jcrName = "jcr:created") - private Calendar creationDate; - @Field - private boolean localized; - @Field - private String partyThatCreatedTheContent; - @Field - private String lastUpdatedParty; - - protected JackrabbitUnstructured() { - // create an empty object - } - - protected JackrabbitUnstructured(String nodePath) { - this.setPath(nodePath); - this.creationDate = new GregorianCalendar(); - this.localized = false; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.orm.OfbizRepositoryMapping#getPath() - */ - @Override - public String getPath() { - return path; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.orm.OfbizRepositoryMapping#setPath(java.lang.String) - */ - @Override - public void setPath(String nodePath) { - nodePath = JackrabbitUtils.createAbsoluteNodePath(nodePath); - this.path = nodePath; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.orm.OfbizRepositoryMapping#getVersion() - */ - @Override - public String getVersion() { - return version; - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.orm.OfbizRepositoryMapping#setVersion(java.lang.String) - */ - @Override - public void setVersion(String version) { - this.version = version; - } - - public Calendar getCreationDate() { - return creationDate; - } - - public void setCreationDate(Calendar creationDate) { - this.creationDate = creationDate; - } - - public boolean getLocalized() { - return localized; - } - - public void setLocalized(boolean isLocalized) { - this.localized = isLocalized; - } - - public void setPartyThatCreatedTheContent(String partyId) { - this.partyThatCreatedTheContent = partyId; - } - - public String getPartyThatCreatedTheContent() { - return this.partyThatCreatedTheContent; - } - - public void setLastUpdatedParty(String partyId) { - this.lastUpdatedParty = partyId; - } - - public String getLastUpdatedParty() { - return this.lastUpdatedParty; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFile.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFile.java deleted file mode 100644 index 41fd5631f4..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFile.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.file; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Bean; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; -import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; - -@Node(jcrType = "nt:file", extend = JackrabbitHierarchyNode.class) -public class JackrabbitFile extends JackrabbitHierarchyNode { - - @Bean(jcrName = "jcr:content") - private JackrabbitResource resource; - - public JackrabbitResource getResource() { - return resource; - } - - public void setResource(JackrabbitResource resource) { - this.resource = resource; - } - - public void setPath(String nodePath) { - // check that the path don't end with a / - if (nodePath.endsWith(ConstantsJackrabbit.ROOTPATH)) { - nodePath = nodePath.substring(0, nodePath.indexOf(ConstantsJackrabbit.NODEPATHDELIMITER)); - } - - // check that it is a relative path - if (nodePath.indexOf(ConstantsJackrabbit.NODEPATHDELIMITER) != -1) { - nodePath = nodePath.substring(nodePath.lastIndexOf(ConstantsJackrabbit.NODEPATHDELIMITER) + 1); - } - - super.path = nodePath; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFolder.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFolder.java deleted file mode 100644 index a371665315..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitFolder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.file; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.NTCollectionConverterImpl; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; - -@Node(jcrType = "nt:folder", extend = JackrabbitHierarchyNode.class) -public class JackrabbitFolder extends JackrabbitHierarchyNode { - @Collection(autoUpdate = true, jcrSameNameSiblings = false, elementClassName = JackrabbitHierarchyNode.class, collectionConverter = NTCollectionConverterImpl.class) - private List children; - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } - - public void addChild(JackrabbitHierarchyNode node) { - if (children == null) { - children = new ArrayList(); - } - children.add(node); - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitHierarchyNode.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitHierarchyNode.java deleted file mode 100644 index 1f39705744..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitHierarchyNode.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.file; - -import java.util.Calendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; -import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -@Node(jcrType = "nt:hierarchyNode", jcrMixinTypes = "mix:versionable") -public class JackrabbitHierarchyNode implements OfbizRepositoryMapping { - @Field(path = true, id = true, jcrProtected = true) - protected String path; - private String version; - @Field(jcrName = "jcr:created") - private Calendar creationDate; - - public String getPath() { - return path; - } - - public void setPath(String nodePath) { - // check if the node path is an absolute path - this.path = JackrabbitUtils.createAbsoluteNodePath(nodePath); - } - - public Calendar getCreationDate() { - return creationDate; - } - - public void setCreationDate(Calendar creationDate) { - this.creationDate = creationDate; - } - - @Override - public String getVersion() { - return version; - } - - @Override - public void setVersion(String version) { - this.version = version; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitResource.java b/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitResource.java deleted file mode 100644 index bb9fc423c8..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/file/JackrabbitResource.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.ofbiz.jcr.orm.jackrabbit.file; - -import java.io.InputStream; -import java.util.Calendar; - -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; -import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; - -@Node(jcrType = "nt:resource") -public class JackrabbitResource { - - @Field(jcrName = "jcr:mimeType") - private String mimeType; - @Field(jcrName = "jcr:data") - private InputStream data; - @Field(jcrName = "jcr:lastModified") - private Calendar lastModified; - - public InputStream getData() { - return data; - } - - public void setData(InputStream data) { - this.data = data; - } - - public Calendar getLastModified() { - return lastModified; - } - - public void setLastModified(Calendar lastModified) { - this.lastModified = lastModified; - } - - public String getMimeType() { - return mimeType; - } - - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java b/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java deleted file mode 100644 index cd30e1fd33..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.ofbiz.jcr.services; - -import java.util.Date; -import java.util.Map; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.UnsupportedRepositoryOperationException; -import javax.jcr.version.VersionManager; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; -import org.ofbiz.jcr.loader.JCRFactoryUtil; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitNews; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.service.ServiceUtil; - -public class JackrabbitServices { - - private static String module = JackrabbitServices.class.getName(); - - public static Map determineJackrabbitRepositorySpeed(DispatchContext ctx, Map context) throws UnsupportedRepositoryOperationException, RepositoryException { - Map result = ServiceUtil.returnSuccess(); - GenericValue userLogin = (GenericValue) context.get("userLogin"); - Integer maxNodes = (Integer) context.get("maxNodes"); - - Long start = 0l; - Long diff = 0l; - - Session session = JCRFactoryUtil.getSession(); - VersionManager vm = session.getWorkspace().getVersionManager(); - start = new Date().getTime(); - for (int i = 0; i <= maxNodes; i++) { - try { - // add a node - Node n = session.getRootNode().addNode("__Speedtest_Node-" + i); - n.addMixin("mix:versionable"); - n.setProperty("anyProperty", "Blah"); - session.save(); - vm.checkin(n.getPath()); - - vm.checkout("/__Speedtest_Node-" + i); - // remove the node - session.removeItem("/__Speedtest_Node-" + i); - session.save(); - } catch (Exception e) { - Debug.logError(e, module); - } - } - - session.logout(); - diff = (new Date().getTime() - start); - result.put("repositoryDirectAccessTime", diff.toString()); - - JackrabbitRepositoryAccessor access = new JackrabbitRepositoryAccessor(userLogin); - start = new Date().getTime(); - for (int i = 0; i <= maxNodes; i++) { - try { - JackrabbitNews news = new JackrabbitNews("/__Speedtest_Node-" + i, "de", "", null, ""); - access.storeContentObject(news); - access.removeContentObject("/__Speedtest_Node-" + i); - } catch (Exception e) { - Debug.logError(e, module); - } - - } - - access.closeAccess(); - diff = (new Date().getTime() - start); - result.put("repositoryOcmAccessTime", diff.toString()); - - return result; - } -} diff --git a/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java b/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java deleted file mode 100644 index 16c833d603..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java +++ /dev/null @@ -1,329 +0,0 @@ -/* -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.test; - -import java.util.GregorianCalendar; -import java.util.Map; - -import javax.jcr.ItemExistsException; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import javolution.util.FastMap; -import net.sf.json.JSONArray; - -import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; -import org.apache.jackrabbit.ocm.manager.ObjectContentManager; -import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl; -import org.apache.jackrabbit.ocm.mapper.Mapper; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.ContentWriter; -import org.ofbiz.jcr.access.JcrRepositoryAccessor; -import org.ofbiz.jcr.access.jackrabbit.ContentWriterJackrabbit; -import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; -import org.ofbiz.jcr.api.JcrDataHelper; -import org.ofbiz.jcr.api.jackrabbit.JackrabbitArticleHelper; -import org.ofbiz.jcr.loader.JCRFactory; -import org.ofbiz.jcr.loader.JCRFactoryUtil; -import org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; -import org.ofbiz.service.ServiceUtil; -import org.ofbiz.service.testtools.OFBizTestCase; - -public class JackrabbitTests extends OFBizTestCase { - - protected GenericValue userLogin = null; - - public JackrabbitTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", "system"), false); - - } - - @Override - protected void tearDown() throws Exception { - } - - public void testRepositoryConstructor() throws Exception { - JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); - assertNotNull(repositoryAccess); - } - - /* - * Base Method Tests - */ - public void testFactoryGetMapper() { - assertNotNull(JCRFactoryImpl.getMapper()); - assertTrue(JCRFactoryImpl.getMapper() instanceof Mapper); - } - - public void testFactoryUtilGetJcrFactory() { - JCRFactory factory = JCRFactoryUtil.getJCRFactory(); - assertNotNull(factory); - assertTrue((factory instanceof JCRFactoryImpl)); - } - - public void testUtilGetSession() { - Session session = JCRFactoryUtil.getSession(); - assertNotNull(session); - assertTrue((session instanceof Session)); - } - - // - // Test JcrJackrabbitUtil - // - - public void testCreateAbsoluteAndNormalizedNodePath() { - String result = JackrabbitUtils.createAbsoluteNodePath("foo/baa"); - - assertEquals("/foo/baa", result); - } - - public void testCheckIfNodePathIsAbsoluteAndNormalized() { - assertFalse(JackrabbitUtils.checkIfNodePathIsAbsolute("foo/baa")); - assertFalse(JackrabbitUtils.checkIfNodePathIsAbsolute("foo/baa/")); - assertTrue(JackrabbitUtils.checkIfNodePathIsAbsolute("/foo/baa/")); - assertTrue(JackrabbitUtils.checkIfNodePathIsAbsolute("/foo/baa")); - } - - public void testListRepositoryNodes() throws Exception { - assertNotNull(JackrabbitUtils.getRepositoryNodes(userLogin, null)); - } - - public void testDefaultLanguage() { - assertEquals(UtilProperties.getPropertyValue("general", "locale.properties.fallback"), JackrabbitUtils.determindeTheDefaultLanguage()); - } - - // - // Jackrabbit Accessor tests - // - - public void testAccessorConstructor() throws RepositoryException { - JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); - - assertNotNull(accessor); - assertEquals("/", accessor.getSession().getRootNode().getPath()); - - accessor.closeAccess(); - } - - public void testAccessorDataTree() throws RepositoryException { - JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); - - JSONArray array = accessor.getJsonDataTree(); - assertEquals(0, array.size()); // should be 0 because there are no - // entries in the repository yet - - accessor.closeAccess(); - } - /* - public void testAccessorFileTree() throws RepositoryException { - JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); - - JSONArray array = accessor.getJsonFileTree(); - assertEquals(0, array.size()); // should be 0 because there are no - // entries in the repository yet - accessor.closeAccess(); - }*/ - - /* - public void testAccessorQuery() throws RepositoryException { - JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); - QueryResult results = accessor.queryForRepositoryData("SELECT * FROM [rep:root]"); - - assertNotNull(results); - assertEquals(1, results.getNodes().getSize()); - - accessor.closeAccess(); - }*/ - - public void testAccessorNodeExist() throws RepositoryException { - JcrRepositoryAccessor accessor = new JackrabbitRepositoryAccessor(userLogin); - assertTrue(accessor.checkIfNodeExist("/")); - assertFalse(accessor.checkIfNodeExist("/test")); - - accessor.closeAccess(); - } - - // - // Content Writer - // - - public void testWriterConsturctor() { - - Session session = JCRFactoryUtil.getSession(); - ObjectContentManager ocm = new ObjectContentManagerImpl(session, JCRFactoryImpl.getMapper()); - ContentWriter writer = new ContentWriterJackrabbit(ocm); - - assertNotNull(writer); - - ocm.logout(); - } - - /* - * Functional Integration Tests - */ - - public void testCrudArticleNode() throws Exception { - // Create New Object - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - helper.storeContentInRepository("news/article", "en", "News Of Today", "Hello World", new GregorianCalendar()); - - JackrabbitArticle content = helper.readContentFromRepository("news/article"); - assertEquals("Hello World", content.getContent()); - - content.setContent("New World!"); - - helper.updateContentInRepository(content); - - JackrabbitArticle updatedContent = helper.readContentFromRepository("news/article"); - assertEquals("New World!", updatedContent.getContent()); - - helper.removeContentObject("news"); - - helper.closeContentSession(); - } - - public void testVersionning() throws Exception { - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - helper.storeContentInRepository("news/versionArticle", "en", "News Of Today", "Hello World", new GregorianCalendar()); - - JackrabbitArticle content = helper.readContentFromRepository("news/versionArticle"); - assertEquals("1.0", content.getVersion()); - - content.setTitle("New Title"); - helper.updateContentInRepository(content); - - content = helper.readContentFromRepository("news/versionArticle"); - assertEquals("1.1", content.getVersion()); - - helper.removeContentObject("news"); - - helper.closeContentSession(); - } - - public void testLanguageDetermination() throws Exception { - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - - helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); - helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar()); - - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage()); - assertEquals("en", helper.readContentFromRepository("/news/tomorrow/en", "").getLanguage()); - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage()); - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage()); - - assertEquals("de", helper.readContentFromRepository("/superhero", "de").getLanguage()); - assertEquals("de", helper.readContentFromRepository("/superhero", "").getLanguage()); - assertEquals("de", helper.readContentFromRepository("/superhero", "fr").getLanguage()); - - helper.removeContentObject("/superhero"); - helper.removeContentObject("/news"); - helper.closeContentSession(); - } - - public void testLanguageDeterminationExpectedPathNotFoundException() throws ObjectContentManagerException, ItemExistsException { - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); - - try { - helper.readContentFromRepository("/news/tomorrow/fr", "").getLanguage(); - // if no exception is thrown, the test should fail - assertTrue("A PathNotFoundException is thrown as expected", false); - } catch (PathNotFoundException pnf) { - // check if the right excpetion is thrown (in jUnit 4 this could be replaced by annotations) - assertTrue("A PathNotFoundException is catched as expected.", true); - } - - helper.removeContentObject("/news"); - helper.closeContentSession(); - } - - /* - * Test the File upload - */ /* - public void testCreateRepositoryFileNode() throws Exception { - File f = new File("stopofbiz.sh"); - File f2 = new File("README"); - assertTrue(f.exists() && f2.exists()); - - InputStream file = new FileInputStream(f); - - JcrFileHelper helper = new JackrabbitFileHelper(userLogin); - helper.storeContentInRepository(file, f.getName(), "/fileHome"); - - assertNotNull(helper.getRepositoryContent("/fileHome/" + f.getName())); - - // add a second file to the same folder - file = new FileInputStream(f2); - - helper.storeContentInRepository(file, f2.getName(), "/fileHome"); - assertNotNull(helper.getRepositoryContent("/fileHome/" + f2.getName())); - - // remove all files in folder - helper.removeContentObject("/fileHome"); - - helper.closeContentSession(); - }*/ - - /* - public void testQuery() throws Exception { - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - - helper.storeContentInRepository("/query", "en", "query", "query test", new GregorianCalendar()); - - List> queryResult = helper.queryData("SELECT * FROM [nt:unstructured]"); - - assertEquals(3, queryResult.size()); // the list should contain 3 result - // sets - - assertEquals("/", queryResult.get(0).get("path")); - assertEquals("/query", queryResult.get(1).get("path")); - assertEquals("/query/en", queryResult.get(2).get("path")); - - helper.removeContentObject("query"); - - helper.closeContentSession(); - - }*/ - - public void testSpeedTestService() throws Exception { - Map context = FastMap.newInstance(); - context.put("maxNodes", new Integer(10)); - context.put("userLogin", dispatcher.getDelegator().findOne("UserLogin", UtilMisc.toMap("userLoginId", "system"), false)); - - Map serviceResult = this.dispatcher.runSync("determineJackrabbitRepositorySpeed", context); - - if (ServiceUtil.isError(serviceResult)) { - assertFalse(true); - } else { - assertTrue(true); - } - - } - -} diff --git a/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java b/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java deleted file mode 100644 index 1363df34e1..0000000000 --- a/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.ofbiz.jcr.util.jackrabbit; - -import java.util.List; -import java.util.Map; - -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import javolution.util.FastList; -import javolution.util.FastMap; - -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; -import org.ofbiz.jcr.loader.JCRFactoryUtil; - -public class JackrabbitUtils { - - public static final String module = JackrabbitUtils.class.getName(); - - /** - * A method to list all nodes in the repository. The result List contains - * the node path and the node type. - * - * @param startNodePath - * @return - * @throws RepositoryException - */ - public static List> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException { - List> returnList = null; - Session session = JCRFactoryUtil.getSession(); - - try { - returnList = getRepositoryNodes(session, startNodePath); - } catch (RepositoryException e) { - throw new RepositoryException(e); - } finally { - session.logout(); - } - - return returnList; - } - - /** - * Just a dummy method to list all nodes in the repository. - * - * @param startNodePath - * @return - * @throws RepositoryException - */ - private static List> getRepositoryNodes(Session session, String startNodePath) throws RepositoryException { - Node node = null; - - List> nodeList = FastList.newInstance(); - if (UtilValidate.isEmpty(startNodePath)) { - node = session.getRootNode(); - } else { - node = session.getNode(startNodePath); - } - - NodeIterator nodeIterator = node.getNodes(); - Map nodeEntry = null; - while (nodeIterator.hasNext()) { - Node n = nodeIterator.nextNode(); - - // recursion - get all subnodes and add the results to our nodeList - if (n.getNodes().hasNext()) { - nodeList.addAll(getRepositoryNodes(session, n.getPath())); - } - - nodeEntry = FastMap.newInstance(); - - // if the node path is a jcr:system node than ignore this - // entry - if (n.getPath().startsWith("/jcr:system")) { - continue; - } - - nodeEntry.put("path", n.getPath()); - - nodeEntry.put("primaryNodeType", n.getPrimaryNodeType().getName()); - - nodeList.add(nodeEntry); - } - - return nodeList; - } - - /** - * If the node path is not absolute (means starts with /), an - * absolute path will be created. - * - * @param nodePath - * @return - */ - public static String createAbsoluteNodePath(String nodePath) { - if (UtilValidate.isEmpty(nodePath)) { - nodePath = ConstantsJackrabbit.ROOTPATH; - } else if (!checkIfNodePathIsAbsolute(nodePath)) { - nodePath = ConstantsJackrabbit.ROOTPATH + nodePath; - } - - return nodePath; - } - - /** - * Returns true if the passed node path is an absolute path (starts with a - * /). - * - * @param nodePath - * @return - */ - public static boolean checkIfNodePathIsAbsolute(String nodePath) { - return nodePath.startsWith(ConstantsJackrabbit.ROOTPATH); - } - - /** - * Return default language from property file. - * - * @return - */ - public static String determindeTheDefaultLanguage() { - return UtilProperties.getPropertyValue("general", "locale.properties.fallback"); - } - - public static boolean isNotARootNode(Node node) throws RepositoryException { - return !isARootNode(node); - } - - public static boolean isARootNode(Node node) throws RepositoryException { - return isARootNode(node.getPath()); - } - - public static boolean isARootNode(String nodePath) { - return ConstantsJackrabbit.ROOTPATH.equals(nodePath); - } -} diff --git a/framework/jcr/testdef/jcrtests.xml b/framework/jcr/testdef/jcrtests.xml deleted file mode 100644 index 2da848c0f7..0000000000 --- a/framework/jcr/testdef/jcrtests.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/specialpurpose/example/build.xml b/specialpurpose/example/build.xml index 70ec24c15a..8add5d5f51 100644 --- a/specialpurpose/example/build.xml +++ b/specialpurpose/example/build.xml @@ -51,7 +51,5 @@ under the License. - - diff --git a/specialpurpose/example/config/ExampleUiLabels.xml b/specialpurpose/example/config/ExampleUiLabels.xml index 321de99bd9..262a10211e 100644 --- a/specialpurpose/example/config/ExampleUiLabels.xml +++ b/specialpurpose/example/config/ExampleUiLabels.xml @@ -19,34 +19,6 @@ under the License. --> - - Datei herunterladen - Download file - - - Content öffnen. - Open content. - - - Datei öffnen - Open file - - - Content löschen. - Remove content. - - - Datei löschen - Remove file - - - Einen neuen Content Eintrag hinzufügen - Add a new content entry - - - Füge einen neuen Node Pfad hinzu, z.B. /Foo/Baa speichert die Datei im Ordner "Baa" - Add a (new) node path like /Foo/Baa will store the file under the folder "Baa" - Ajax Examples Exemples Ajax @@ -505,42 +477,6 @@ Gruppi campi 数据项组 - - Repository aufräumen - Clean repository - - - Löscht alle Nodes aus dem Repository, die keine Verkünpfung in der Content Tabelle haben. - Removes all nodes which are not linked in the content table. - - - Liste alles Knoten - List Nodes - - - Das Repository kann mit Hilfe der SQL2 oder JQOM Query Language durchsucht werden: z.B. SELECT * FROM [nt:unstructured] gibt alle nodes vom Typ nt:unstructured zurück. - You can search the repository by using SQL2 or JQOM query syntax: i.e. SELECT * FROM [nt:unstructured] gives all nodes with the typ nt:unstructured. - - - Content Schnellauswahl - Content Node auswählen und Sprache bestimmen. - Content quick select - Choose your content node and select a language. - - - (Text) Content anzeigen - Show (text) content - - - Dateien anzeigen - Show uploaded Files - - - Wähle eine Datei und versuche einen Rechtklick - Choose a file and try a 'right click' - - - Eine neue Datei speichern - Upload a new file - Verion der gewählten sprache Version of the choosen language @@ -826,10 +762,6 @@ แก้ไขสินค้าตัวอย่าง 编辑样例明细 - - Jackrabbit - Jackrabbit - Find Example diff --git a/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java b/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java deleted file mode 100644 index 6203e3f93b..0000000000 --- a/specialpurpose/example/src/org/ofbiz/example/JackrabbitEvents.java +++ /dev/null @@ -1,482 +0,0 @@ -package org.ofbiz.example; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Map; - -import javax.jcr.ItemExistsException; -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.ValueFormatException; -import javax.jcr.nodetype.NodeType; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import javolution.util.FastMap; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.io.IOUtils; -import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.FileUtil; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.JcrRepositoryAccessor; -import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; -import org.ofbiz.jcr.api.JcrDataHelper; -import org.ofbiz.jcr.api.JcrFileHelper; -import org.ofbiz.jcr.api.jackrabbit.JackrabbitArticleHelper; -import org.ofbiz.jcr.api.jackrabbit.JackrabbitFileHelper; -import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.orm.jackrabbit.data.JackrabbitArticle; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFile; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitFolder; -import org.ofbiz.jcr.orm.jackrabbit.file.JackrabbitHierarchyNode; -import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; - -public class JackrabbitEvents { - - public static final String module = JackrabbitEvents.class.getName(); - - /** - * - * @param request - * @param response - * @return - */ - public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); - - String contentPath = request.getParameter("path"); - String language = request.getParameter("msgLocale"); - String title = request.getParameter("title"); - Calendar pubDate = new GregorianCalendar(); // TODO - String content = request.getParameter("message"); - - try { - articleHelper.storeContentInRepository(contentPath, language, title, content, pubDate); - } catch (ObjectContentManagerException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (ItemExistsException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } finally { - articleHelper.closeContentSession(); - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - try { - List> listIt = JackrabbitUtils.getRepositoryNodes(userLogin, ""); - request.setAttribute("listIt", listIt); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - String contentPath = request.getParameter("path"); - - String version = request.getParameter("versions"); - String language = request.getParameter("language"); - - if (UtilValidate.isEmpty(contentPath)) { - String msg = "A node path is missing, please pass the path to the node which should be read from the repository."; // TODO - Debug.logError(msg, module); - request.setAttribute("_ERROR_MESSAGE_", msg); - return "error"; - } - - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); - JackrabbitArticle ormArticle = null; - try { - if (UtilValidate.isEmpty(version)) { - ormArticle = articleHelper.readContentFromRepository(contentPath, language); - } else { - ormArticle = articleHelper.readContentFromRepository(contentPath, language, version); - } - } catch (ClassCastException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } - - request.setAttribute("path", ormArticle.getPath()); - request.setAttribute("language", ormArticle.getLanguage()); - request.setAttribute("title", ormArticle.getTitle()); - request.setAttribute("version", ormArticle.getVersion()); - request.setAttribute("versionList", articleHelper.getVersionListForCurrentArticle()); - request.setAttribute("languageList", articleHelper.getAvailableLanguageList()); - request.setAttribute("createDate", ormArticle.getCreationDate()); - request.setAttribute("content", ormArticle.getContent()); - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - String contentPath = request.getParameter("path"); - JcrDataHelper articleHelper = new JackrabbitArticleHelper(userLogin); - - JackrabbitArticle ormArticle = null; - try { - ormArticle = articleHelper.readContentFromRepository(contentPath); - } catch (ClassCastException e1) { - Debug.logError(e1, module); - request.setAttribute("_ERROR_MESSAGE_", e1.getMessage()); - return "error"; - } catch (PathNotFoundException e1) { - Debug.logError(e1, module); - request.setAttribute("_ERROR_MESSAGE_", e1.getMessage()); - return "error"; - } - - ormArticle.setTitle(request.getParameter("title")); - ormArticle.setContent(request.getParameter("content")); - - try { - articleHelper.updateContentInRepository(ormArticle); - } catch (ObjectContentManagerException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - } finally { - articleHelper.closeContentSession(); - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - String contentPath = request.getParameter("path"); - - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - helper.removeContentObject(contentPath); - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); - List list = null; - Map passedParams = FastMap.newInstance(); - - try { - list = UtilGenerics.checkList(fu.parseRequest(request)); - } catch (FileUploadException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } - - byte[] file = null; - for (FileItem fi : list) { - String fieldName = fi.getFieldName(); - - if (fi.isFormField()) { - String fieldStr = fi.getString(); - passedParams.put(fieldName, fieldStr); - } else if (fieldName.startsWith("fileData")) { - passedParams.put("completeFileName", fi.getName()); - file = fi.get(); - } - } - - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); - - try { - - fileHelper.storeContentInRepository(file, passedParams.get("completeFileName"), passedParams.get("path")); - - } catch (ObjectContentManagerException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - } catch (ItemExistsException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - } finally { - fileHelper.closeContentSession(); - } - - return "success"; - } - - /** - * Creates the FILE Tree as JSON Object - * - * @param request - * @param response - * @return - */ - public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); - try { - JSONArray fileTree = repositoryAccess.getJsonFileTree(); - request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("dataTree", new JSONArray()); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } finally { - repositoryAccess.closeAccess(); - } - - return "success"; - } - - /** - * Creates the DATA (TEXT) Tree as JSON Object - * - * @param request - * @param response - * @return - */ - public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - JackrabbitRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); - try { - JSONArray fileTree = repositoryAccess.getJsonDataTree(); - request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("dataTree", new JSONArray()); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - repositoryAccess.closeAccess(); - return "error"; - } - - List contentList = new ArrayList(); - Map> languageList = FastMap.newInstance(); - Session session = repositoryAccess.getSession(); - Node root; - try { - root = session.getRootNode(); - getContentList(root, contentList); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - repositoryAccess.closeAccess(); - return "error"; - } finally { - } - - try { - for (String path : contentList) { - Node parent = session.getNode(path); - NodeIterator ni = parent.getNodes(); - List language = new ArrayList(); - while (ni.hasNext()) { - Node t = ni.nextNode(); - if (t.hasProperty("localized") && t.getProperty("localized").getBoolean()) { - String l = t.getPath(); - language.add(l.substring(l.lastIndexOf("/") + 1)); - } - } - languageList.put(path, language); - } - } catch (ValueFormatException e) { - Debug.logError(e, module); - } catch (PathNotFoundException e) { - Debug.logError(e, module); - } catch (RepositoryException e) { - Debug.logError(e, module); - } finally { - repositoryAccess.closeAccess(); - } - - request.setAttribute("contentList", contentList); - JSONObject jo = new JSONObject(); - jo.putAll(languageList); - request.setAttribute("languageList", jo); - - return "success"; - } - - public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - String contentPath = request.getParameter("path"); - - if (UtilValidate.isEmpty(contentPath)) { - String msg = "A node path is missing, please pass the path to the node which should be read from the repository."; // TODO - Debug.logError(msg, module); - request.setAttribute("_ERROR_MESSAGE_", msg); - return "error"; - } - - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); - JackrabbitHierarchyNode orm = null; - try { - orm = fileHelper.getRepositoryContent(contentPath); - } catch (ClassCastException e1) { - Debug.logError(e1, module); - request.setAttribute("_ERROR_MESSAGE_", e1.getMessage()); - return "error"; - } catch (PathNotFoundException e1) { - Debug.logError(e1, module); - request.setAttribute("_ERROR_MESSAGE_", e1.getMessage()); - return "error"; - } - - if (fileHelper.isFileContent()) { - JackrabbitFile file = (JackrabbitFile) orm; - InputStream fileStream = file.getResource().getData(); - - String fileName = file.getPath(); - if (fileName.indexOf("/") != -1) { - fileName = fileName.substring(fileName.indexOf("/") + 1); - } - - try { - UtilHttp.streamContentToBrowser(response, IOUtils.toByteArray(fileStream), file.getResource().getMimeType(), fileName); - } catch (IOException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } - } else { - Debug.logWarning("This content is no file content, the content is from the type: " + orm.getClass().getName(), module); - } - return "success"; - } - - public static String getFileInformation(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - String contentPath = request.getParameter("path"); - - JcrFileHelper fileHelper = new JackrabbitFileHelper(userLogin); - OfbizRepositoryMapping orm; - try { - orm = fileHelper.getRepositoryContent(contentPath); - } catch (ClassCastException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } - - // Here we can differentiate between a file or folder content - if (fileHelper.isFileContent()) { - JackrabbitFile file = (JackrabbitFile) orm; - request.setAttribute("fileName", file.getPath()); - request.setAttribute("fileLastModified", file.getResource().getLastModified().getTime()); - request.setAttribute("fileMimeType", file.getResource().getMimeType()); - request.setAttribute("fileCreationDate", file.getCreationDate().getTime()); - } else if (fileHelper.isFolderContent()) { - JackrabbitFolder folder = (JackrabbitFolder) orm; - request.setAttribute("fileName", folder.getPath()); - request.setAttribute("fileCreationDate", folder.getCreationDate().getTime()); - } - - return "success"; - } - - public static String queryRepositoryData(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - - String searchQuery = request.getParameter("queryData"); - - JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); - - try { - request.setAttribute("queryResult", helper.queryData(searchQuery)); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } - - return "success"; - } - - private static void getContentList(Node startNode, List 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/specialpurpose/example/webapp/example/WEB-INF/controller.xml b/specialpurpose/example/webapp/example/WEB-INF/controller.xml index 4573c7e5ce..04cedf4211 100644 --- a/specialpurpose/example/webapp/example/WEB-INF/controller.xml +++ b/specialpurpose/example/webapp/example/WEB-INF/controller.xml @@ -236,95 +236,6 @@ under the License. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -369,18 +280,6 @@ under the License. - - - - - - - - - - - - -${uiLabelMap.ExampleJackrabbitQuickContentSelect} -
- - - -
- - - -
\ No newline at end of file diff --git a/specialpurpose/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl b/specialpurpose/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl deleted file mode 100644 index 8d2aa7c963..0000000000 --- a/specialpurpose/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl +++ /dev/null @@ -1,94 +0,0 @@ -<#-- -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/specialpurpose/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl b/specialpurpose/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl deleted file mode 100644 index a0914f74f5..0000000000 --- a/specialpurpose/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl +++ /dev/null @@ -1,110 +0,0 @@ -<#-- -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/specialpurpose/example/widget/example/CommonScreens.xml b/specialpurpose/example/widget/example/CommonScreens.xml index 1e1b24d4f5..39ba47d167 100644 --- a/specialpurpose/example/widget/example/CommonScreens.xml +++ b/specialpurpose/example/widget/example/CommonScreens.xml @@ -294,32 +294,6 @@ under the License. - -
- - - - - - - - - - - - -
- - - -
-
-
-
-
-
- - - - -
- - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - - - - - -