Author: sascharodekamp
Date: Wed Apr 18 13:37:25 2012 New Revision: 1327506 URL: http://svn.apache.org/viewvc?rev=1327506&view=rev Log: Small jackrabbit API code cleanups and refactoring, no functional changes Modified: ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java ofbiz/trunk/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitFileHelper.java 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=1327506&r1=1327505&r2=1327506&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 13:37:25 2012 @@ -84,13 +84,10 @@ public class JackrabbitArticleHelper ext contentPath = determineContentLanguagePath(contentPath, language); OfbizRepositoryMapping orm = super.access.getContentObject(contentPath); + setArticleContentObject(orm); - if (checkAndSetArticleContentObject(orm)) { - article.setVersion(super.access.getBaseVersion(contentPath)); - return article; - } else { - throw new ClassCastException("The content object for the path: " + contentPath + " is not an article content object. This Helper can only handle content objects with the type: " + JackrabbitArticle.class.getName()); - } + article.setVersion(super.access.getBaseVersion(contentPath)); + return article; } /* @@ -103,16 +100,14 @@ public class JackrabbitArticleHelper ext @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); - if (checkAndSetArticleContentObject(orm)) { - // the content path must be manipulated because, the jackrabbit orm - // returns a full blown path with version information. - article.setPath(contentPath); - return article; - } else { - throw new ClassCastException("The content object for the path: " + contentPath + " is not an article content object. This Helper can only handle content objects with the type: " + JackrabbitArticle.class.getName()); - } + // manipulating the content path, because the jackrabbit orm + // returns a content path with version information. + article.setPath(contentPath); + return article; } /* @@ -129,9 +124,7 @@ public class JackrabbitArticleHelper ext language = JackrabbitUtils.determindeTheDefaultLanguage(); } - // construct the content article object article = new JackrabbitArticle(contentPath, language, title, content, publicationDate); - super.access.storeContentObject(article); } @@ -168,7 +161,6 @@ public class JackrabbitArticleHelper ext 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); - versions = new ArrayList<String>(1); } return versions; @@ -227,12 +219,12 @@ public class JackrabbitArticleHelper ext */ private String determineContentLanguagePath(String contentPath, String contentLanguage) throws PathNotFoundException { // return if only the root node path is requested - if (ConstantsJackrabbit.ROOTPATH.equals(contentPath)) { + if (JackrabbitUtils.isARootNode(contentPath)) { return contentPath; } // contentLanaguage should never be null, because the concatenation - // looks really bad if the String have a null value. + // goes wrong if the String have a null value. if (contentLanguage == null) { contentLanguage = ""; } @@ -248,8 +240,10 @@ public class JackrabbitArticleHelper ext 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); } @@ -279,7 +273,7 @@ public class JackrabbitArticleHelper ext } } childNodes = null; - } catch(PathNotFoundException pnf) { + } catch (PathNotFoundException pnf) { throw new PathNotFoundException(pnf); } catch (RepositoryException e) { Debug.logError(e, module); @@ -299,18 +293,15 @@ public class JackrabbitArticleHelper ext String[] splitContentPath = contentPath.split(ConstantsJackrabbit.NODEPATHDELIMITER); String canonicalizedCotnentPath = ""; - // check if the last chunk contains a language which is part of our - // locale list, but this should only be called if the language should be - // changed. Because it is possible to request a node directly with the - // language flag. That means if the node path contains a language and - // the language should not be changed (contentLanaguage is empty), the - // language flag should be stay in the content path. + // 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])) { - // this local field should not be part of our path string canonicalizedCotnentPath = buildCanonicalizeContentPath(splitContentPath, splitContentPath.length - 1); } else { - // make sure the passed content path is absolute and ends with a - // slash "/" canonicalizedCotnentPath = buildCanonicalizeContentPath(splitContentPath, splitContentPath.length); } @@ -372,7 +363,7 @@ public class JackrabbitArticleHelper ext /** * Checks if a node have the property <code>localized</code> and if this - * property is be <code>true</code> + * property is <code>true</code> * * @param nodeWhichShouldHaveAValidLanguageFlag * @return @@ -381,25 +372,25 @@ public class JackrabbitArticleHelper ext * @throws PathNotFoundException */ private boolean checkIfNodeHaveValidLanguageMixIn(Node nodeWhichShouldHaveAValidLanguageFlag) throws RepositoryException, ValueFormatException, PathNotFoundException { - return nodeWhichShouldHaveAValidLanguageFlag.hasProperty("localized") && nodeWhichShouldHaveAValidLanguageFlag.getProperty("localized").getBoolean(); + boolean hasProperty = nodeWhichShouldHaveAValidLanguageFlag.hasProperty("localized"); + + return hasProperty && nodeWhichShouldHaveAValidLanguageFlag.getProperty("localized").getBoolean(); } /** - * Checks if the <code>orm</code> Object is an instance of - * <code>JackrabbitArticle</code>, set the class variable and return true, - * otherwise false will be returned and the class variable is det to null. + * Set the article class variable if the <code>orm</code> Object is an + * instance of <code>JackrabbitArticle</code>. Throws a ClassCastException + * if the <code>orm</code> Object is from another type. * * @param orm + * @throws ClassCastException * @return */ - private boolean checkAndSetArticleContentObject(OfbizRepositoryMapping orm) { + private void setArticleContentObject(OfbizRepositoryMapping orm) throws ClassCastException { if (orm != null && orm instanceof JackrabbitArticle) { article = (JackrabbitArticle) orm; - return true; - } else { - article = null; } - return false; + 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()); } } 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=1327506&r1=1327505&r2=1327506&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 13:37:25 2012 @@ -75,16 +75,14 @@ public class JackrabbitFileHelper extend } if (orm instanceof JackrabbitFile) { - JackrabbitFile fileObj = (JackrabbitFile) orm; - hierarchy = fileObj; - return fileObj; + hierarchy = (JackrabbitFile) orm; } else if (orm instanceof JackrabbitFolder) { - JackrabbitFolder fileObj = (JackrabbitFolder) orm; - hierarchy = fileObj; - return fileObj; + 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()); } - 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; } /* |
Free forum by Nabble | Edit this page |