You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2011/09/23 14:02:02 UTC

svn commit: r1174682 - in /ofbiz/branches/jackrabbit20100709: applications/content/src/org/ofbiz/content/jcr/ applications/content/src/org/ofbiz/content/jcr/helper/ framework/example/widget/example/ framework/jcr/src/org/ofbiz/jcr/access/ framework/jcr...

Author: sascharodekamp
Date: Fri Sep 23 12:02:01 2011
New Revision: 1174682

URL: http://svn.apache.org/viewvc?rev=1174682&view=rev
Log:
* I add a new layer for content object organization. The new layer provides a simpler API to work with the OfbizContentMapping. The new Layer lives in the application area, because it contains application related code instead of the JCR default implementation in the framework which only contains generic code.

* Added and improve the node versioning

Added:
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java   (with props)
Modified:
    ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitArticle.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitLocalizedContent.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java

Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java (original)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java Fri Sep 23 12:02:01 2011
@@ -30,14 +30,13 @@ 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.content.jcr.helper.JcrArticleHelper;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.jcr.access.RepositoryAccess;
 import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle;
-import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitLocalizedContent;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder;
-import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitResource;
 import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit;
 
@@ -52,30 +51,27 @@ public class JackrabbitEvents {
      * @return
      */
     public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+        JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin);
 
-        String nodePath = request.getParameter("path");
+        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");
 
-        OfbizRepositoryMappingJackrabbitArticle ormArticle = new OfbizRepositoryMappingJackrabbitArticle(nodePath, language, title, content);
-
-        RepositoryAccess repositoryAccess = null;
         try {
-            repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
-            repositoryAccess.storeContentObject(ormArticle);
-        } catch (ObjectContentManagerException ocme) {
-            Debug.logError(ocme, module);
-            request.setAttribute("_ERROR_MESSAGE_", ocme.toString());
+            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.toString());
+            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
             return "error";
         } finally {
-            repositoryAccess.closeAccess();
+            articleHelper.closeContentSession();
         }
 
         return "success";
@@ -108,28 +104,30 @@ public class JackrabbitEvents {
      * @return
      */
     public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
-        String node = request.getParameter("path");
+        String contentPath = request.getParameter("path");
 
-        if (UtilValidate.isEmpty(node)) {
+        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";
         }
 
-        RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
-
-        List<String> list = repositoryAccess.getVersionList(node);
+        JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin);
+        OfbizRepositoryMappingJackrabbitArticle ormArticle = articleHelper.readContentFromRepository(contentPath, language);
 
-        OfbizRepositoryMappingJackrabbitArticle ormArticle = (OfbizRepositoryMappingJackrabbitArticle) repositoryAccess.getContentObject(node);
 
         request.setAttribute("contentObject", ormArticle);
         request.setAttribute("path", ormArticle.getPath());
         request.setAttribute("language", ormArticle.getLanguage());
         request.setAttribute("title", ormArticle.getTitle());
-        request.setAttribute("version", list.get(list.size() - 1));
+        request.setAttribute("version", ormArticle.getVersion());
+        request.setAttribute("versionList", articleHelper.getVersionListForCurrentArticle());
         request.setAttribute("createDate", ormArticle.getCreationDate());
         request.setAttribute("content", ormArticle.getContent());
 
@@ -143,7 +141,7 @@ public class JackrabbitEvents {
      * @return
      */
     public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
         String path = request.getParameter("path");
 
@@ -169,7 +167,7 @@ public class JackrabbitEvents {
      * @return
      */
     public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
         String path = request.getParameter("path");
 
@@ -197,7 +195,7 @@ public class JackrabbitEvents {
      * @return
      */
     public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
         ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp")));
         List<FileItem> list = null;
         Map<String, String> passedParams = FastMap.newInstance();
@@ -263,7 +261,7 @@ public class JackrabbitEvents {
      * @return
      */
     public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
         RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
         try {
@@ -287,7 +285,7 @@ public class JackrabbitEvents {
      * @return
      */
     public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
         RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
         try {
@@ -304,7 +302,7 @@ public class JackrabbitEvents {
     }
 
     public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) {
-        GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
         String node = request.getParameter("path");
 

Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java?rev=1174682&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java (added)
+++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java Fri Sep 23 12:02:01 2011
@@ -0,0 +1,253 @@
+package org.ofbiz.content.jcr.helper;
+
+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.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+import org.ofbiz.base.util.Debug;
+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.access.jackrabbit.RepositoryAccessJackrabbit;
+import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
+import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle;
+
+/**
+ * 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 JcrArticleHelper {
+
+    private final static String module = JcrArticleHelper.class.getName();
+
+    private static RepositoryAccessJackrabbit access = null;
+    private static OfbizRepositoryMappingJackrabbitArticle article = null;
+
+    private static List<String> possibleLocales = null;
+
+    static {
+        if (UtilValidate.isEmpty(possibleLocales)) {
+            possibleLocales = new ArrayList<String>();
+            List<Locale> locales = org.ofbiz.base.util.UtilMisc.availableLocales();
+            for (Locale locale : locales) {
+                possibleLocales.add(locale.toString());
+            }
+        }
+    }
+
+    /**
+     * Setup my content Object
+     */
+    public JcrArticleHelper(GenericValue userLogin) {
+        access = new RepositoryAccessJackrabbit(userLogin);
+    }
+
+    /**
+     * This will close the connection to the content repository and make sure
+     * that all changes a stored successfully.
+     */
+    public void closeContentSession() {
+        access.closeAccess();
+        access = null;
+    }
+
+    /**
+     * 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
+     */
+    public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath) {
+        OfbizRepositoryMapping orm = access.getContentObject(contentPath);
+
+        if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) {
+            article = (OfbizRepositoryMappingJackrabbitArticle) orm;
+            article.setVersion(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: " + OfbizRepositoryMappingJackrabbitArticle.class.getName());
+        }
+    }
+
+    /**
+     * 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
+     */
+    public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language) {
+        contentPath = determineContentLanguagePath(contentPath, language);
+        return readContentFromRepository(contentPath);
+    }
+
+    /**
+     * 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
+     */
+    public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language, String version) {
+        contentPath = determineContentLanguagePath(contentPath, language);
+        OfbizRepositoryMapping orm = access.getContentObject(contentPath, version);
+
+        if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) {
+            article = (OfbizRepositoryMappingJackrabbitArticle) orm;
+            article.setVersion(version);
+            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: " + OfbizRepositoryMappingJackrabbitArticle.class.getName());
+        }
+    }
+
+    /**
+     * Stores a new article content object in the repository.
+     *
+     * @param contentPath
+     * @param language
+     * @param title
+     * @param content
+     * @param pubDate
+     * @throws ObjectContentManagerException
+     * @throws ItemExistsException
+     */
+    public void storeContentInRepository(String contentPath, String language, String title, String content, Calendar pubDate) throws ObjectContentManagerException, ItemExistsException {
+        if (UtilValidate.isEmpty(language)) {
+            language = determindeTheDefaultLanguage();
+        }
+
+        // the content path should contain the language information
+        // TODO this have to be a little bit more intelligent in the future
+        if (!contentPath.endsWith(language)) {
+            if (contentPath.endsWith("/")) {
+                contentPath = contentPath + language;
+            } else {
+                contentPath = contentPath + "/" + language;
+            }
+        }
+
+        // construct the content article object
+        article = new OfbizRepositoryMappingJackrabbitArticle(contentPath, language, title, content, pubDate);
+
+        access.storeContentObject(article);
+
+    }
+
+    /**
+     * 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 List<String> getVersionListForCurrentArticle() {
+        List<String> versions = null;
+
+        if (article != null) {
+            versions = 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>();
+        }
+
+        return versions;
+    }
+
+    /**
+     * 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 language
+     * @return
+     */
+    private String determineContentLanguagePath(String contentPath, String language) {
+        // return if only the root node path is requested
+        if (ConstantsJackrabbit.ROOTPATH.equals(contentPath)) {
+            return contentPath;
+        }
+
+        // we have to check if the content path already contains a language and
+        // if the language is already in the path we have to check if it is
+        // equal to the passed language
+
+        // we split the path string in chunks
+        String[] path = contentPath.split("/");
+
+        // chunk if the last chunk contains a language flag
+        StringBuffer canonicalizedContentPath = new StringBuffer("/");
+        if (possibleLocales.contains(path[path.length - 1])) {
+            for (int i = 0; i < path.length - 1; i++) {
+                if (UtilValidate.isNotEmpty(path[i])) {
+                    canonicalizedContentPath.append(path[i]).append("/");
+                }
+            }
+        } else {
+            for (String p : path) {
+                if (UtilValidate.isNotEmpty(p)) {
+                    canonicalizedContentPath.append(p).append("/");
+                }
+            }
+        }
+
+        // check if this language exist in the repository
+        Session session = access.getSession();
+        try {
+            if (!session.itemExists(canonicalizedContentPath.toString() + language)) {
+                // check for default language
+                if (!session.itemExists(canonicalizedContentPath.toString() + determindeTheDefaultLanguage())) {
+                    // return the first available language
+                    NodeIterator ni = session.getNode(canonicalizedContentPath.toString()).getNodes();
+                    while (ni.hasNext()) {
+                        Node n = ni.nextNode();
+                        if (possibleLocales.contains(n.getName())) {
+                            contentPath = n.getPath();
+                            break;
+                        }
+                    }
+                    ni = null;
+                } else {
+                    contentPath = canonicalizedContentPath.toString() + determindeTheDefaultLanguage();
+                }
+            } else {
+                contentPath = canonicalizedContentPath.toString() + language;
+            }
+        } catch (RepositoryException e) {
+            Debug.logError(e, module);
+        }
+
+        return contentPath;
+    }
+
+    private String determindeTheDefaultLanguage() {
+        return UtilProperties.getPropertyValue("general", "locale.properties.fallback");
+    }
+}

Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Fri Sep 23 12:02:01 2011
@@ -85,8 +85,8 @@ under the License.
         <field name="language" title="${uiLabelMap.CommonChooseLanguage}" >
             <drop-down allow-empty="false" current="first-in-list" current-description="${parameters.selectedLanguage}"><list-options key-name="localeId" list-name="parameters.languageList" description="${localeId}"/></drop-down>
         </field>
-        <field name="version" >
-            <drop-down allow-empty="true" current="first-in-list" current-description="${parameters.currentLanguageVersion}"><list-options key-name="version" list-name="parameters.versionList" description="${version}"/></drop-down>
+        <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>
         </field>
         <field name="submit" ><submit/></field>
     </form>

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java Fri Sep 23 12:02:01 2011
@@ -18,6 +18,16 @@ public interface ContentReader {
     OfbizRepositoryMapping getContentObject(String nodePath);
 
     /**
+     * Return an OfbizRepositoryMapping Object in the specified language and version from the JCR Repository.
+     *
+     * @param nodePath
+     * @param language
+     * @param version
+     * @return
+     */
+    OfbizRepositoryMapping getContentObject(String nodePath, String version);
+
+    /**
      * Returns a tree of all content nodes (except folders and files) in the repository.
      *
      * @return

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java Fri Sep 23 12:02:01 2011
@@ -27,6 +27,17 @@ public interface RepositoryAccess {
     OfbizRepositoryMapping getContentObject(String nodePath);
 
     /**
+     * Return an OfbizRepositoryMapping Object in the specified version from the
+     * JCR Repository.
+     *
+     * @param nodePath
+     * @param language
+     * @param version
+     * @return
+     */
+    OfbizRepositoryMapping getContentObject(String nodePath, String version);
+
+    /**
      * Stores the OfbizRepositoryMapping Class in the content repository.
      *
      * @param orm
@@ -60,7 +71,8 @@ public interface RepositoryAccess {
     public void removeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException;
 
     /**
-     * Returns a tree of all content nodes (except folders and files) in the repository.
+     * Returns a tree of all content nodes (except folders and files) in the
+     * repository.
      *
      * @return
      * @throws RepositoryException
@@ -82,4 +94,20 @@ public interface RepositoryAccess {
      * @return
      */
     public List<String> 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);
 }

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java Fri Sep 23 12:02:01 2011
@@ -14,6 +14,22 @@ public interface VersioningManager {
     public List<String> 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);
+
+    /**
      * Check Out a node from a repository
      *
      * @param nodePath

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=1174682&r1=1174681&r2=1174682&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 Fri Sep 23 12:02:01 2011
@@ -2,6 +2,7 @@ package org.ofbiz.jcr.access.jackrabbit;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 
 import net.sf.json.JSONArray;
@@ -21,13 +22,37 @@ public class ContentReaderJackrabbit imp
         this.ocm = ocm;
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String)
+     */
     @Override
     public OfbizRepositoryMapping getContentObject(String nodePath) {
+        Node n = null;
+        try {
+            n = ocm.getSession().getNode(nodePath);
+        } catch (PathNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (RepositoryException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
         return (OfbizRepositoryMapping) ocm.getObject(nodePath);
     }
 
     /*
      * (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) {
+        return (OfbizRepositoryMapping) ocm.getObject(nodePath, version);
+    }
+
+    /*
+     * (non-Javadoc)
      *
      * @see org.ofbiz.jcr.orm.ContentReader#getJsonDataTree()
      */

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java Fri Sep 23 12:02:01 2011
@@ -11,6 +11,7 @@ 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.access.jackrabbit.ConstantsJackrabbit.PROPERTY_FIELDS;
 import org.ofbiz.jcr.orm.OfbizRepositoryMapping;
 
 public class ContentWriterJackrabbit implements ContentWriter {
@@ -70,29 +71,24 @@ public class ContentWriterJackrabbit imp
         // We loop only over the sub nodes.
         for (int i = 0; i < (nodeStructure.length - 1); i++) {
             String node = nodeStructure[i];
-            if (UtilValidate.isEmail(node)) {
+            if (UtilValidate.isEmpty(node)) {
                 continue;
             }
 
             try {
                 if (parentNode.hasNode(node)) {
                     parentNode = parentNode.getNode(node);
+                    versioningManager.checkOutContentObject(parentNode.getPath());
                 } else {
-                    // create new sub node based on the passed
-                    // OrfbizRepositoryMapping object.
-                    OfbizRepositoryMapping newNode = orm.getClass().newInstance();
-                    String parentNodePath = parentNode.getPath();
-
-                    if (!parentNodePath.endsWith("/")) {
-                        parentNodePath = parentNodePath + "/";
-                    }
-                    newNode.setPath(parentNodePath + node);
-
                     versioningManager.checkOutContentObject(parentNode.getPath());
+                    Node newNode = parentNode.addNode(node);
+                    newNode.addMixin(PROPERTY_FIELDS.mixInVERSIONING.getType());
+                    if (!ConstantsJackrabbit.ROOTPATH.equals(parentNode.getPath())) {
+                        newNode.setPrimaryType(parentNode.getPrimaryNodeType().getName());
+                    }
 
-                    ocm.insert(newNode);
                     versioningManager.addContentToCheckInList(newNode.getPath());
-                    parentNode = parentNode.getNode(node);
+                    parentNode = newNode;
                 }
             } catch (PathNotFoundException e) {
                 Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
@@ -100,12 +96,6 @@ public class ContentWriterJackrabbit imp
             } catch (RepositoryException e) {
                 Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
                 return;
-            } catch (InstantiationException e) {
-                Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
-                return;
-            } catch (IllegalAccessException e) {
-                Debug.logError(e, "The new node could not be created: " + orm.getPath(), module);
-                return;
             }
 
         }

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java Fri Sep 23 12:02:01 2011
@@ -78,6 +78,15 @@ public class RepositoryAccessJackrabbit 
         return;
     }
 
+    /**
+     * Returns the Jackrabbit session object.
+     *
+     * @return
+     */
+    public Session getSession() {
+        return this.session;
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -107,6 +116,19 @@ public class RepositoryAccessJackrabbit 
      * (non-Javadoc)
      *
      * @see
+     * org.ofbiz.jcr.access.RepositoryAccess#getContentObject(java.lang.String,
+     * java.lang.String)
+     */
+    @Override
+    public OfbizRepositoryMapping getContentObject(String nodePath, String version) {
+        ContentReader contentReader = new ContentReaderJackrabbit(this.ocm);
+        return contentReader.getContentObject(nodePath, version);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
      * org.ofbiz.jcr.orm.RepositoryAccess#storeContentObject(org.ofbiz.jcr.orm
      * .OfbizRepositoryMapping)
      */
@@ -161,7 +183,9 @@ public class RepositoryAccessJackrabbit 
 
     /*
      * (non-Javadoc)
-     * @see org.ofbiz.jcr.access.RepositoryAccess#getVersionList(java.lang.String)
+     *
+     * @see
+     * org.ofbiz.jcr.access.RepositoryAccess#getVersionList(java.lang.String)
      */
     @Override
     public List<String> getVersionList(String nodePath) {
@@ -172,6 +196,30 @@ public class RepositoryAccessJackrabbit 
     /*
      * (non-Javadoc)
      *
+     * @see
+     * org.ofbiz.jcr.access.RepositoryAccess#getBaseVersion(java.lang.String)
+     */
+    @Override
+    public String getBaseVersion(String nodePath) {
+        VersioningManager versioningnManager = new VersioningManagerJackrabbit(this.ocm);
+        return versioningnManager.getBaseVersion(nodePath);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.ofbiz.jcr.access.RepositoryAccess#getRootVersion(java.lang.String)
+     */
+    @Override
+    public String getRootVersion(String nodePath) {
+        VersioningManager versioningnManager = new VersioningManagerJackrabbit(this.ocm);
+        return versioningnManager.getRootVersion(nodePath);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
      * @see org.ofbiz.jcr.orm.RepositoryAccess#getJsonFileTree()
      */
     @Override
@@ -182,6 +230,7 @@ public class RepositoryAccessJackrabbit 
 
     /*
      * (non-Javadoc)
+     *
      * @see org.ofbiz.jcr.access.RepositoryAccess#getJsonFileTree()
      */
     @Override

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java Fri Sep 23 12:02:01 2011
@@ -51,7 +51,11 @@ public class VersioningManagerJackrabbit
         // write the versions to the array list.
         while (versionIterator.hasNext()) {
             Version version = (Version) versionIterator.next();
-            result.add(version.getName());
+            // filter the root version string, because it's not needed each node
+            // starts with the version number 1.0
+            if (!"jcr:rootVersion".equals(version.getName())) {
+                result.add(version.getName());
+            }
         }
 
         return result;
@@ -73,7 +77,7 @@ public class VersioningManagerJackrabbit
         }
 
         try {
-            if (this.ocm.getSession().nodeExists(nodePath) && !this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath)) {
+            if (this.ocm.getSession().nodeExists(nodePath) && !this.ocm.getSession().getWorkspace().getVersionManager().isCheckedOut(nodePath) && !checkedOutNodeStore.contains(nodePath)) {
                 this.ocm.checkout(nodePath);
                 this.addContentToCheckInList(nodePath);
             }
@@ -141,6 +145,36 @@ public class VersioningManagerJackrabbit
 
     }
 
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.ofbiz.jcr.access.VersioningManager#getBaseVersion(java.lang.String)
+     */
+    public String getBaseVersion(String nodePath) {
+        try {
+            return ocm.getBaseVersion(nodePath).getName();
+        } catch (VersionException e) {
+            Debug.logError(e, module);
+            return "0.0";
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.ofbiz.jcr.access.VersioningManager#getRootVersion(java.lang.String)
+     */
+    public String getRootVersion(String nodePath) {
+        try {
+            return ocm.getRootVersion(nodePath).getName();
+        } catch (VersionException e) {
+            Debug.logError(e, module);
+            return "0.0";
+        }
+    }
+
     /**
      * Checks out recursively all related nodes (parent, all child's (if exists)
      * and the node itself)

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitArticle.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitArticle.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitArticle.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitArticle.java Fri Sep 23 12:02:01 2011
@@ -1,5 +1,7 @@
 package org.ofbiz.jcr.orm.jackrabbit;
 
+import java.util.Calendar;
+
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
 
@@ -10,6 +12,8 @@ public class OfbizRepositoryMappingJackr
     String title = null;
     @Field
     String content = null;
+    @Field
+    Calendar pubDate = null;
 
     /**
      *
@@ -17,19 +21,25 @@ public class OfbizRepositoryMappingJackr
      * @param language
      * @param title
      * @param content
+     * @param pubDate
      */
-    public OfbizRepositoryMappingJackrabbitArticle(String nodePath, String language, String title, String content) {
+    public OfbizRepositoryMappingJackrabbitArticle(String nodePath, String language, String title, String content, Calendar pubDate) {
         super(nodePath, language);
 
         this.title = title;
         this.content = content;
+        this.pubDate = pubDate;
     }
 
+    /**
+     *
+     */
     public OfbizRepositoryMappingJackrabbitArticle() {
         super();
-        // create an empty object
+        // create empty instance
     }
 
+
     public String getTitle() {
         return title;
     }
@@ -45,4 +55,12 @@ public class OfbizRepositoryMappingJackr
     public void setContent(String content) {
         this.content = content;
     }
+
+    public Calendar getPubDate() {
+        return pubDate;
+    }
+
+    public void setPubDate(Calendar pubDate) {
+        this.pubDate = pubDate;
+    }
 }

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitLocalizedContent.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitLocalizedContent.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitLocalizedContent.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitLocalizedContent.java Fri Sep 23 12:02:01 2011
@@ -1,9 +1,9 @@
 package org.ofbiz.jcr.orm.jackrabbit;
 
+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.base.util.UtilProperties;
-import org.ofbiz.base.util.UtilValidate;
 
 @Node(isAbstract = true, extend = OfbizRepositoryMappingJackrabbitUnstructured.class)
 public abstract class OfbizRepositoryMappingJackrabbitLocalizedContent extends OfbizRepositoryMappingJackrabbitUnstructured {
@@ -13,7 +13,9 @@ public abstract class OfbizRepositoryMap
 
     public OfbizRepositoryMappingJackrabbitLocalizedContent() {
         super();
+        this.language = "";
         super.setLocalized(true);
+        super.setCreationDate(new GregorianCalendar());
         // create an empty localized object
     }
 
@@ -23,51 +25,19 @@ public abstract class OfbizRepositoryMap
      * @param language
      */
     public OfbizRepositoryMappingJackrabbitLocalizedContent(String nodePath, String language) {
+        super(nodePath);
         this.language = language;
-        setLocalizedPath(nodePath);
 
         // define this node as a localized node
         super.setLocalized(true);
     }
 
-    /**
-     * The path of a localized node is always a combination of path and language
-    */
-    private void setLocalizedPath(String path) {
-        // determine a default language
-        if (UtilValidate.isEmpty(language)) {
-            language = determindeTheDefaultLanguage();
-        }
-
-        path = path + "/" + language;
-        super.setPath(path);
-    }
-
     public String getLanguage() {
         return language;
     }
 
     public void setLanguage(String language) {
         this.language = language;
-
-        // if the language is set after the path make sure the new language fits to the path
-        if (!super.getPath().endsWith(language) || !super.getPath().endsWith(language + "/")) {
-            String newPath = super.getPath();
-            if (newPath.endsWith("/")) {
-                // cut a trailing slash /
-                newPath = newPath.substring(0, newPath.lastIndexOf("/"));
-            }
-
-            // cut the old trailing language
-            newPath = newPath.substring(0, newPath.lastIndexOf("/"));
-            // write the new path
-            setLocalizedPath(newPath);
-        }
-
-    }
-
-    private String determindeTheDefaultLanguage() {
-        return language = UtilProperties.getPropertyValue("general", "locale.properties.fallback");
     }
 
 }

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java?rev=1174682&r1=1174681&r2=1174682&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java Fri Sep 23 12:02:01 2011
@@ -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;
 
-@Node(extend = OfbizRepositoryMappingJackrabbitUnstructured.class)
+@Node(extend = OfbizRepositoryMappingJackrabbitLocalizedContent.class)
 public class OfbizRepositoryMappingJackrabbitNews extends OfbizRepositoryMappingJackrabbitLocalizedContent {
 
     @Field(id = true) String title = null;