Author: sascharodekamp
Date: Thu Oct 13 11:16:40 2011 New Revision: 1182785 URL: http://svn.apache.org/viewvc?rev=1182785&view=rev Log: Improve the version and language handling Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Thu Oct 13 11:16:40 2011 @@ -86,7 +86,7 @@ under the License. <drop-down allow-empty="false" current="first-in-list" current-description="${parameters.selectedLanguage}"><list-options key-name="languageList" description="${languageList}" list-name="parameters.languageList" list-entry-name="languageList"/></drop-down> </field> <field name="versions" > - <drop-down allow-empty="false" current="selected" no-current-selected-key="${parameters.version}"><list-options key-name="versionList" description="${versionList}" list-name="parameters.versionList" list-entry-name="versionList"/></drop-down> + <drop-down allow-empty="true" current="selected" no-current-selected-key="${parameters.version}"><list-options key-name="versionList" description="${versionList}" list-name="parameters.versionList" list-entry-name="versionList"/></drop-down> </field> <field name="submit" ><submit/></field> </form> Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java Thu Oct 13 11:16:40 2011 @@ -3,6 +3,7 @@ package org.ofbiz.jcr.access.jackrabbit; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; +import javax.jcr.version.VersionException; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -31,7 +32,15 @@ public class ContentReaderJackrabbit imp */ @Override public OfbizRepositoryMapping getContentObject(String nodePath) { - return (OfbizRepositoryMapping) ocm.getObject(nodePath); + OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath); + try { + 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; } /* @@ -49,7 +58,9 @@ public class ContentReaderJackrabbit imp return getContentObject(nodePath); } - return (OfbizRepositoryMapping) ocm.getObject(nodePath, version); + OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath, version); + orm.setVersion(version); + return orm; } /* Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java Thu Oct 13 11:16:40 2011 @@ -112,7 +112,6 @@ public class JcrArticleHelper extends Ab if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) { article = (OfbizRepositoryMappingJackrabbitArticle) orm; - article.setVersion(version); article.setPath(contentPath); // the content path must be // manipulated because, the jackrabbit // orm returns a full blown path with @@ -171,7 +170,8 @@ public class JcrArticleHelper extends Ab * @return */ public List<String> getVersionListForCurrentArticle() { - List<String> versions = null; + List<String> versions = new ArrayList<String>(); + ; if (article != null) { versions = access.getVersionList(article.getPath()); @@ -184,31 +184,31 @@ public class JcrArticleHelper extends Ab } public List<String> getAvailableLanguageList() { - List<String> languages = null; + List<String> languages = new ArrayList<String>(); if (article != null && article.getLocalized()) { Session session = access.getSession(); try { - languages = new ArrayList<String>(); Node node = session.getNode(article.getPath()).getParent(); NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { - String l = nodes.nextNode().getPath(); - languages.add(l.substring(l.lastIndexOf("/") + 1)); + Node tmpNode = nodes.nextNode(); + // only use nodes which have the language mix in + if (tmpNode.hasProperty("localized") && tmpNode.getProperty("localized").getBoolean()) { + String l = tmpNode.getPath(); + languages.add(l.substring(l.lastIndexOf("/") + 1)); + } } } catch (PathNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Debug.logError(e, module); } catch (RepositoryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Debug.logError(e, module); } } else { Debug.logWarning("No Article is loaded from the repository, please load an article first before requesting the version list.", module); - languages = new ArrayList<String>(1); } return languages; @@ -242,6 +242,9 @@ public class JcrArticleHelper extends Ab // chunk if the last chunk contains a language flag StringBuffer canonicalizedContentPath = new StringBuffer("/"); if (possibleLocales.contains(path[path.length - 1])) { + if (UtilValidate.isEmpty(language)) { + language = path[path.length - 1]; + } for (int i = 0; i < path.length - 1; i++) { if (UtilValidate.isNotEmpty(path[i])) { canonicalizedContentPath.append(path[i]).append("/"); Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java Thu Oct 13 11:16:40 2011 @@ -13,4 +13,16 @@ public interface OfbizRepositoryMapping * @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 Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java Thu Oct 13 11:16:40 2011 @@ -11,6 +11,7 @@ import org.ofbiz.jcr.orm.OfbizRepository public class OfbizRepositoryMappingJackrabbitHierarchyNode implements OfbizRepositoryMapping { @Field(path = true, id = true, jcrProtected = true) protected String path; + private String version; @Field(jcrName = "jcr:created") private Calendar creationDate; @@ -34,4 +35,15 @@ public class OfbizRepositoryMappingJackr public void setCreationDate(Calendar creationDate) { this.creationDate = creationDate; } + + @Override + public String getVersion() { + return version; + } + + @Override + public void setVersion(String version) { + this.version = version; + } + } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java?rev=1182785&r1=1182784&r2=1182785&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java Thu Oct 13 11:16:40 2011 @@ -32,18 +32,22 @@ public abstract class OfbizRepositoryMap this.localized = false; } + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.orm.OfbizRepositoryMapping#getPath() + */ + @Override public String getPath() { return path; } - public Calendar getCreationDate() { - return creationDate; - } - - public void setCreationDate(Calendar creationDate) { - this.creationDate = creationDate; - } - + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.orm.OfbizRepositoryMapping#setPath(java.lang.String) + */ + @Override public void setPath(String nodePath) { // check if the node path is an absolute path if (!nodePath.startsWith(ConstantsJackrabbit.ROOTPATH)) { @@ -53,14 +57,35 @@ public abstract class OfbizRepositoryMap 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; } |
Free forum by Nabble | Edit this page |