Author: sascharodekamp
Date: Wed Apr 18 12:22:20 2012 New Revision: 1327470 URL: http://svn.apache.org/viewvc?rev=1327470&view=rev Log: Small code cleanups and refactoring for the Jackrabbit implementation, no functional changes Added: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java (contents, props changed) - copied, changed from r1327107, ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java Removed: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java Modified: ofbiz/trunk/framework/base/config/test-containers.xml ofbiz/trunk/framework/example/src/org/ofbiz/example/JackrabbitEvents.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/JackrabbitHierarchyNode.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java Modified: ofbiz/trunk/framework/base/config/test-containers.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/config/test-containers.xml?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/base/config/test-containers.xml (original) +++ ofbiz/trunk/framework/base/config/test-containers.xml Wed Apr 18 12:22:20 2012 @@ -66,7 +66,7 @@ under the License. upon JNDI, it must be started after the naming-container container.--> <container name="jcr-container" class="org.ofbiz.jcr.loader.JCRContainer"> <property name="configFilePath" value="framework/jcr/config/jcr-test-config.xml"/> - <property name="removeOnShutdown" value="true"/> + <property name="removeRepositoryOnShutdown" value="true"/> </container> <!-- load catalina (tomcat) and all web applications --> Modified: ofbiz/trunk/framework/example/src/org/ofbiz/example/JackrabbitEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/src/org/ofbiz/example/JackrabbitEvents.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (original) +++ ofbiz/trunk/framework/example/src/org/ofbiz/example/JackrabbitEvents.java Wed Apr 18 12:22:20 2012 @@ -47,7 +47,7 @@ import org.ofbiz.jcr.orm.jackrabbit.Jack import org.ofbiz.jcr.orm.jackrabbit.JackrabbitFile; import org.ofbiz.jcr.orm.jackrabbit.JackrabbitFolder; import org.ofbiz.jcr.orm.jackrabbit.JackrabbitHierarchyNode; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; public class JackrabbitEvents { @@ -95,7 +95,7 @@ public class JackrabbitEvents { public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); try { - List<Map<String, String>> listIt = JcrUtilJackrabbit.getRepositoryNodes(userLogin, ""); + List<Map<String, String>> listIt = JackrabbitUtils.getRepositoryNodes(userLogin, ""); request.setAttribute("listIt", listIt); } catch (RepositoryException e) { Debug.logError(e, module); Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java Wed Apr 18 12:22:20 2012 @@ -17,7 +17,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.jcr.access.ContentReader; import org.ofbiz.jcr.access.VersioningManager; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; public class ContentReaderJackrabbit implements ContentReader { @@ -36,8 +36,9 @@ public class ContentReaderJackrabbit imp * org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String) */ @Override - public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException{ - nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); + public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException { + nodePath = JackrabbitUtils.createAbsoluteNodePath(nodePath); + OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath); try { if (orm != null) { @@ -60,7 +61,8 @@ public class ContentReaderJackrabbit imp */ @Override public OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException { - nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); + 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); @@ -198,15 +200,21 @@ public class ContentReaderJackrabbit imp * @throws RepositoryException * if an error occurs. */ - protected QueryResult executeQuery(String statement) throws RepositoryException { + private QueryResult executeQuery(String statement) throws RepositoryException { // TODO create a query manager which uses the OCM Layer. - QueryManager qm = ocm.getSession().getWorkspace().getQueryManager(); - if (statement.trim().toLowerCase().startsWith("select")) { - return qm.createQuery(statement, Query.JCR_SQL2).execute(); + return executeQuery(statement, Query.JCR_SQL2); } else { - return qm.createQuery(statement, Query.JCR_JQOM).execute(); + 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(); + } } Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java Wed Apr 18 12:22:20 2012 @@ -16,7 +16,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.jcr.access.ContentWriter; import org.ofbiz.jcr.access.VersioningManager; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; public class ContentWriterJackrabbit implements ContentWriter { @@ -43,10 +43,6 @@ public class ContentWriterJackrabbit imp */ @Override public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException, ItemExistsException { - if (orm == null) { - return; - } - // we want to avoid same name sibling (SnS) for each node Type try { if (this.ocm.getSession().itemExists(orm.getPath())) { @@ -62,7 +58,7 @@ public class ContentWriterJackrabbit imp // create all nodes in the node structure which do not exist yet try { - createNodeStructure(orm.getPath(), orm.getClass().getAnnotation(org.apache.jackrabbit.ocm.mapper.impl.annotation.Node.class).jcrType()); + createNodeStructure(orm.getPath(), getJcrTypeFromOrmAnnotation(orm)); } catch (PathNotFoundException e) { Debug.logError(e, "The new node could not be created: " + orm.getPath(), module); return; @@ -77,6 +73,12 @@ public class ContentWriterJackrabbit imp 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) * @@ -99,7 +101,7 @@ public class ContentWriterJackrabbit imp */ @Override public void removeContentObject(String nodePath) throws ObjectContentManagerException { - nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); + nodePath = JackrabbitUtils.createAbsoluteNodePath(nodePath); versioningManager.checkOutContentObject(nodePath, true); ocm.remove(nodePath); @@ -121,9 +123,7 @@ public class ContentWriterJackrabbit imp * @throws RepositoryException */ private void createNodeStructure(String completeNodePath, String primaryNodeType) throws PathNotFoundException, RepositoryException { - // We have to check if the node structure (the sub nodes of the passed - // ORM Object) exist, otherwise they will be created. - String[] nodeStructure = completeNodePath.split(ConstantsJackrabbit.NODEPATHDELIMITER); + String[] nodeStructure = splitNodePathByDelimiter(completeNodePath); Node parentNode = null; try { parentNode = this.ocm.getSession().getRootNode(); @@ -132,17 +132,18 @@ public class ContentWriterJackrabbit imp return; } - // We loop only over the sub nodes. for (int i = 0; i < (nodeStructure.length - 1); i++) { String node = nodeStructure[i]; - if (UtilValidate.isEmpty(node)) { - continue; + if (UtilValidate.isNotEmpty(node)) { + parentNode = createNewSubNodeIfNotExist(primaryNodeType, parentNode, 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. * @@ -161,14 +162,13 @@ public class ContentWriterJackrabbit imp 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); - versioningManager.checkOutContentObject(parentNode.getPath()); } else { - versioningManager.checkOutContentObject(parentNode.getPath()); Node newNode = addNewNode(primaryNodeType, parentNode, node); - versioningManager.addContentToCheckInList(newNode.getPath()); parentNode = newNode; } @@ -195,7 +195,8 @@ public class ContentWriterJackrabbit imp private Node addNewNode(String primaryNodeType, Node parentNode, String node) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException { Node newNode = parentNode.addNode(node, primaryNodeType); newNode.addMixin(ConstantsJackrabbit.MIXIN_VERSIONING); - if (!ConstantsJackrabbit.ROOTPATH.equals(parentNode.getPath())) { + + if (JackrabbitUtils.isNotARootNode(parentNode)) { newNode.setPrimaryType(parentNode.getPrimaryNodeType().getName()); } return newNode; Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java Wed Apr 18 12:22:20 2012 @@ -8,6 +8,7 @@ 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; @@ -17,6 +18,7 @@ import org.apache.jackrabbit.ocm.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 { @@ -45,7 +47,6 @@ public class VersioningManagerJackrabbit versionIterator = this.ocm.getAllVersions(nodePath); } catch (VersionException e) { Debug.logError(e, module); - // return an empty List return result; } @@ -54,7 +55,7 @@ public class VersioningManagerJackrabbit Version version = (Version) versionIterator.next(); // filter the root version string, because it's not needed each node // starts with the version number 1.0 - if (!ConstantsJackrabbit.ROOTVERSION.equals(version.getName())) { + if (isNotRootVersion(version)) { result.add(version.getName()); } } @@ -85,12 +86,12 @@ public class VersioningManagerJackrabbit public void checkOutContentObject(String nodePath) { // check if the parent node is the root node, because the // root node can not be checked out. - if (ConstantsJackrabbit.ROOTPATH.equals(nodePath)) { + if (JackrabbitUtils.isARootNode(nodePath)) { return; } try { - if (this.ocm.getSession().nodeExists(nodePath) && !this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath) && !checkedOutNodeStore.contains(nodePath)) { + if (doNodeExist(nodePath) && isNodeNotCheckedOut(nodePath)) { this.ocm.checkout(nodePath); this.addContentToCheckInList(nodePath); } @@ -103,8 +104,8 @@ public class VersioningManagerJackrabbit } } - public void checkOutContentObject(String nodePath, boolean recursiv) { - if (recursiv) { + public void checkOutContentObject(String nodePath, boolean checkOutAllSubnodes) { + if (checkOutAllSubnodes) { try { checkOutRelatedNodes(nodePath); } catch (RepositoryException e) { @@ -134,16 +135,11 @@ public class VersioningManagerJackrabbit */ @Override public void checkInContentAndSaveState() { - if (ocm != null) { - ocm.save(); - } + ocm.save(); try { for (String nodePath : checkedOutNodeStore) { - // add the new resource content to the version history - if (this.ocm.getSession().nodeExists(nodePath) && this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath)) { - this.ocm.checkin(nodePath); - } + checkinNode(nodePath); } // reset the node store after everything is checked in @@ -164,6 +160,7 @@ public class VersioningManagerJackrabbit * @see * org.ofbiz.jcr.access.VersioningManager#getBaseVersion(java.lang.String) */ + @Override public String getBaseVersion(String nodePath) { try { return ocm.getBaseVersion(nodePath).getName(); @@ -179,6 +176,7 @@ public class VersioningManagerJackrabbit * @see * org.ofbiz.jcr.access.VersioningManager#getRootVersion(java.lang.String) */ + @Override public String getRootVersion(String nodePath) { try { return ocm.getRootVersion(nodePath).getName(); @@ -195,12 +193,16 @@ public class VersioningManagerJackrabbit * @param startNode * @throws RepositoryException */ - protected void checkOutRelatedNodes(String startNodePath) throws RepositoryException { + private void checkOutRelatedNodes(String startNodePath) throws RepositoryException { + Node startNode = getNode(startNodePath); List<String> nodesToCheckOut = new ArrayList<String>(); + nodesToCheckOut.add(startNodePath); - nodesToCheckOut.add(ocm.getSession().getNode(startNodePath).getParent().getPath()); - if (ocm.getSession().getNode(startNodePath).hasNodes()) { - nodesToCheckOut.addAll(getAllChildNodes(startNodePath)); + nodesToCheckOut.add(startNode.getParent().getPath()); + + if (startNode.hasNodes()) { + List<String> allChildNodes = getAllChildNodes(startNode); + nodesToCheckOut.addAll(allChildNodes); } for (String node : nodesToCheckOut) { @@ -216,18 +218,49 @@ public class VersioningManagerJackrabbit * @return * @throws RepositoryException */ - private List<String> getAllChildNodes(String startNode) throws RepositoryException { + private List<String> getAllChildNodes(Node startNode) throws RepositoryException { List<String> nodes = new ArrayList<String>(); - NodeIterator ni = ocm.getSession().getNode(startNode).getNodes(); - while (ni.hasNext()) { - Node nextNode = ni.nextNode(); - if (nextNode.hasNodes()) { - nodes.addAll(getAllChildNodes(nextNode.getPath())); + + NodeIterator subNodeIterator = startNode.getNodes(); + while (subNodeIterator.hasNext()) { + Node subNode = subNodeIterator.nextNode(); + + if (subNode.hasNodes()) { + nodes.addAll(getAllChildNodes(subNode)); } - nodes.add(nextNode.getPath()); + 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); + } } Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java Wed Apr 18 12:22:20 2012 @@ -22,7 +22,7 @@ import org.ofbiz.jcr.access.jackrabbit.J import org.ofbiz.jcr.api.JcrDataHelper; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; import org.ofbiz.jcr.orm.jackrabbit.JackrabbitArticle; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; /** * This Helper class encapsulate the jcr article content bean. it provide all @@ -126,7 +126,7 @@ public class JackrabbitArticleHelper ext @Override public void storeContentInRepository(String contentPath, String language, String title, String content, Calendar publicationDate) throws ObjectContentManagerException, ItemExistsException { if (UtilValidate.isEmpty(language)) { - language = JcrUtilJackrabbit.determindeTheDefaultLanguage(); + language = JackrabbitUtils.determindeTheDefaultLanguage(); } // construct the content article object @@ -248,8 +248,8 @@ public class JackrabbitArticleHelper ext if (super.access.checkIfNodeExist(canonicalizedContentPath + contentLanguage) && checkIfNodeHaveValidLanguageMixIn(canonicalizedContentPath + contentLanguage)) { contentPath = canonicalizedContentPath + contentLanguage; - } else if (super.access.checkIfNodeExist(canonicalizedContentPath + JcrUtilJackrabbit.determindeTheDefaultLanguage())) { - contentPath = canonicalizedContentPath + JcrUtilJackrabbit.determindeTheDefaultLanguage(); + } else if (super.access.checkIfNodeExist(canonicalizedContentPath + JackrabbitUtils.determindeTheDefaultLanguage())) { + contentPath = canonicalizedContentPath + JackrabbitUtils.determindeTheDefaultLanguage(); } else { contentPath = determineFirstAvailableLanguageNode(canonicalizedContentPath); } Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java Wed Apr 18 12:22:20 2012 @@ -22,7 +22,7 @@ import org.ofbiz.jcr.orm.jackrabbit.Jack import org.ofbiz.jcr.orm.jackrabbit.JackrabbitFolder; import org.ofbiz.jcr.orm.jackrabbit.JackrabbitHierarchyNode; import org.ofbiz.jcr.orm.jackrabbit.JackrabbitResource; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; /** * This Helper class encapsulate the jcr file content bean. it provide all @@ -120,7 +120,7 @@ public class JackrabbitFileHelper extend // Create the folder if necessary, otherwise we just update the folder // content - folderPath = JcrUtilJackrabbit.createAbsoluteNodePath(folderPath); + folderPath = JackrabbitUtils.createAbsoluteNodePath(folderPath); if (super.access.checkIfNodeExist(folderPath)) { OfbizRepositoryMapping orm = super.access.getContentObject(folderPath); if (orm instanceof JackrabbitFolder) { Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java Wed Apr 18 12:22:20 2012 @@ -34,6 +34,7 @@ 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; @@ -128,7 +129,11 @@ public class JCRFactoryImpl implements J if (removeRepositoryOnShutdown) { if (UtilValidate.isNotEmpty(homeDir)) { File homeDirFile = new File(homeDir); - homeDirFile.deleteOnExit(); + try { + FileUtils.deleteDirectory(homeDirFile); + } catch (IOException e) { + Debug.logError(e, module); + } } } } Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/JackrabbitHierarchyNode.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/JackrabbitHierarchyNode.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/JackrabbitHierarchyNode.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/JackrabbitHierarchyNode.java Wed Apr 18 12:22:20 2012 @@ -5,7 +5,7 @@ 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.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; @Node(jcrType = "nt:hierarchyNode", jcrMixinTypes="mix:versionable") public class JackrabbitHierarchyNode implements OfbizRepositoryMapping { @@ -21,7 +21,7 @@ public class JackrabbitHierarchyNode imp public void setPath(String nodePath) { // check if the node path is an absolute path - this.path = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); + this.path = JackrabbitUtils.createAbsoluteNodePath(nodePath); } public Calendar getCreationDate() { Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java?rev=1327470&r1=1327469&r2=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java Wed Apr 18 12:22:20 2012 @@ -53,7 +53,7 @@ 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.JackrabbitArticle; -import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.jcr.util.jackrabbit.JackrabbitUtils; import org.ofbiz.service.ServiceUtil; import org.ofbiz.service.testtools.OFBizTestCase; @@ -105,24 +105,24 @@ public class JackrabbitTests extends OFB // public void testCreateAbsoluteAndNormalizedNodePath() { - String result = JcrUtilJackrabbit.createAbsoluteNodePath("foo/baa"); + String result = JackrabbitUtils.createAbsoluteNodePath("foo/baa"); assertEquals("/foo/baa", result); } public void testCheckIfNodePathIsAbsoluteAndNormalized() { - assertFalse(JcrUtilJackrabbit.checkIfNodePathIsAbsolute("foo/baa")); - assertFalse(JcrUtilJackrabbit.checkIfNodePathIsAbsolute("foo/baa/")); - assertTrue(JcrUtilJackrabbit.checkIfNodePathIsAbsolute("/foo/baa/")); - assertTrue(JcrUtilJackrabbit.checkIfNodePathIsAbsolute("/foo/baa")); + 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(JcrUtilJackrabbit.getRepositoryNodes(userLogin, null)); + assertNotNull(JackrabbitUtils.getRepositoryNodes(userLogin, null)); } public void testDefaultLanguage() { - assertEquals(UtilProperties.getPropertyValue("general", "locale.properties.fallback"), JcrUtilJackrabbit.determindeTheDefaultLanguage()); + assertEquals(UtilProperties.getPropertyValue("general", "locale.properties.fallback"), JackrabbitUtils.determindeTheDefaultLanguage()); } // Copied: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java (from r1327107, ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java) URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java?p2=ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java&p1=ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java&r1=1327107&r2=1327470&rev=1327470&view=diff ============================================================================== --- ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java (original) +++ ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java Wed Apr 18 12:22:20 2012 @@ -17,9 +17,9 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; import org.ofbiz.jcr.loader.JCRFactoryUtil; -public class JcrUtilJackrabbit { +public class JackrabbitUtils { - public static final String module = JcrUtilJackrabbit.class.getName(); + public static final String module = JackrabbitUtils.class.getName(); /** * A method to list all nodes in the repository. The result List contains @@ -125,4 +125,16 @@ public class JcrUtilJackrabbit { 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); + } } Propchange: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JackrabbitUtils.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |