svn commit: r1183255 - in /ofbiz/branches/jackrabbit20100709/framework: example/config/ example/src/org/ofbiz/example/ example/webapp/example/WEB-INF/ example/webapp/example/jackrabbit/ example/widget/example/ jcr/src/org/ofbiz/jcr/access/ jcr/src/org/...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1183255 - in /ofbiz/branches/jackrabbit20100709/framework: example/config/ example/src/org/ofbiz/example/ example/webapp/example/WEB-INF/ example/webapp/example/jackrabbit/ example/widget/example/ jcr/src/org/ofbiz/jcr/access/ jcr/src/org/...

sascharodekamp
Author: sascharodekamp
Date: Fri Oct 14 09:21:32 2011
New Revision: 1183255

URL: http://svn.apache.org/viewvc?rev=1183255&view=rev
Log:
Add a new "Quick content" Chooser. Add new Unit Tests for checking the language determination.

Added:
    ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/ContentChooser.ftl
Modified:
    ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml
    ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java
    ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml
    ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java
    ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java

Modified: ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.xml Fri Oct 14 09:21:32 2011
@@ -861,5 +861,9 @@
         <value xml:lang="de">Informationen öffnen</value>
         <value xml:lang="en">Open information</value>
     </property>
+    <property key="ExampleJackrabbitQuickContentSelect">
+        <value xml:lang="de">Content Schnellauswahl - Content Node auswählen und Sprache bestimmen.</value>
+        <value xml:lang="en">Content quick select - Choose your content node and select a language.</value>
+    </property>
 
 </resource>

Modified: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java Fri Oct 14 09:21:32 2011
@@ -2,18 +2,26 @@ package org.ofbiz.example;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.NodeType;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import javolution.util.FastMap;
 import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
 
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
@@ -261,6 +269,8 @@ public class JackrabbitEvents {
             request.setAttribute("dataTree", new JSONArray());
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
+        } finally {
+            repositoryAccess.closeAccess();
         }
 
         return "success";
@@ -276,7 +286,7 @@ public class JackrabbitEvents {
     public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) {
         GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
-        RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
+        RepositoryAccessJackrabbit repositoryAccess = new RepositoryAccessJackrabbit(userLogin);
         try {
             JSONArray fileTree = repositoryAccess.getJsonDataTree();
             request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString()));
@@ -284,9 +294,54 @@ public class JackrabbitEvents {
             Debug.logError(e, module);
             request.setAttribute("dataTree", new JSONArray());
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
+            repositoryAccess.closeAccess();
+            return "error";
+        }
+
+        List<String> contentList = new ArrayList<String>();
+        Map<String, List<String>> languageList = FastMap.newInstance();
+        Session session = repositoryAccess.getSession();
+        Node root;
+        try {
+            root = session.getRootNode();
+            getContentList(root, contentList);
+        } catch (RepositoryException e) {
+            Debug.logError(e, module);
+            request.setAttribute("_ERROR_MESSAGE_", e.toString());
+            repositoryAccess.closeAccess();
             return "error";
+        } finally {
+        }
+
+        try {
+        for (String path : contentList) {
+            Node parent = session.getNode(path);
+            NodeIterator ni = parent.getNodes();
+            List<String> language = new ArrayList<String>();
+            while (ni.hasNext()) {
+                Node t = ni.nextNode();
+                    if (t.hasProperty("localized") && t.getProperty("localized").getBoolean()) {
+                        String l = t.getPath();
+                        language.add(l.substring(l.lastIndexOf("/") + 1));
+                    }
+            }
+            languageList.put(path, language);
+        }
+        } catch (ValueFormatException e) {
+            Debug.logError(e, module);
+        } catch (PathNotFoundException e) {
+            Debug.logError(e, module);
+        } catch (RepositoryException e) {
+            Debug.logError(e, module);
+        } finally {
+            repositoryAccess.closeAccess();
         }
 
+        request.setAttribute("contentList", contentList);
+        JSONObject jo = new JSONObject();
+        jo.putAll(languageList);
+        request.setAttribute("languageList", jo);
+
         return "success";
     }
 
@@ -350,4 +405,16 @@ public class JackrabbitEvents {
         return "success";
     }
 
+    private static void getContentList(Node startNode, List<String> contentList) throws RepositoryException {
+        NodeIterator ni = startNode.getNodes();
+        while (ni.hasNext()) {
+            Node tmpNode = ni.nextNode();
+            if (tmpNode.getPrimaryNodeType().isNodeType(NodeType.NT_UNSTRUCTURED) && (!tmpNode.hasProperty("localized") || !tmpNode.getProperty("localized").getBoolean())) {
+                contentList.add(tmpNode.getPath());
+                if (tmpNode.hasNodes()) {
+                    getContentList(tmpNode, contentList);
+                }
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml Fri Oct 14 09:21:32 2011
@@ -263,7 +263,7 @@ under the License.
         <security auth="true" https="true" />
         <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getNodeContent"/>
         <response name="success" type="view" value="ExampleJackrabbitEditRepositoryContent" />
-        <response name="error" type="view" value="ExampleJackrabbitShowContentData" />
+        <response name="error" type="request" value="ExampleJackrabbitShowContentData" />
     </request-map>
     <request-map uri="UpdateRepositoryData">
         <security auth="true" https="true" />

Added: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/ContentChooser.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/ContentChooser.ftl?rev=1183255&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/ContentChooser.ftl (added)
+++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/ContentChooser.ftl Fri Oct 14 09:21:32 2011
@@ -0,0 +1,52 @@
+<#--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+${uiLabelMap.ExampleJackrabbitQuickContentSelect}
+<form id="selectNode" action="EditRepositoryContent" type="post">
+    <select name="path" id="nodePath">
+        <option value="" selected></option>
+        <#list parameters.contentList as content>
+            <option value="${content}">${content}</option>
+        </#list>
+    </select>
+    <select name="language" id="nodeLanguage">
+        <option value="" selected></option>
+    </select>
+    <input type="submit" />
+</form>
+
+<script type="text/javascript">
+    var languageList = ${parameters.languageList}
+
+    jQuery("#nodePath").change(function() {
+        var newOptions = languageList[jQuery(this).val()];
+
+        var options = "";
+        for (option in newOptions) {
+            options = options + "<option value='" + newOptions[option] + "'>" + newOptions[option] + "</option>";
+
+        }
+        options = options + "<option value='' ></option>"
+
+        jQuery("#nodeLanguage").children().remove();
+        jQuery("#nodeLanguage").append(options);
+
+    });
+</script>
+
+<br />
\ No newline at end of file

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=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Fri Oct 14 09:21:32 2011
@@ -20,7 +20,7 @@ under the License.
 
 <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-form.xsd">
 
-    <form name="ListRepositoryData" type="list" list-name="repositoryContent" default-entity-name="Content" separate-columns="true" odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">
+    <form name="ListRepositoryData" type="list" list-name="repositoryContent" separate-columns="true" odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">
         <field name="path">
             <hyperlink target="EditRepositoryContent" description="${path}">
                 <parameter param-name="contentId" from-field="contentId" />
@@ -44,6 +44,19 @@ under the License.
         </field>
     </form>
 
+    <form name="SelectContentObject" type="single" target="">
+        <field name="contentDropDown" position="1">
+            <drop-down ><list-options key-name="contentList" description="${contentList}" list-name="parameters.contentList" list-entry-name="contentList"/></drop-down>
+        </field>
+        
+        <!--
+        <field name="languageDropDown" position="2" title="">
+            <drop-down><list-options key-name="languageList" list-name="parameters.languageList"/></drop-down>
+        </field>
+        -->
+        <field name="submit" position="2"><submit/></field>
+    </form>
+
     <form name="AddRepositoryData" type="single" target="StoreNewRepositoryData">
         <field name="path" title="${uiLabelMap.ExampleRepositoryNode}" tooltip="${uiLabelMap.ExampleAddNewNodePath}">
             <text />

Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml Fri Oct 14 09:21:32 2011
@@ -52,6 +52,11 @@ under the License.
                 <decorator-screen name="CommonExampleJackrabbitDecorator" location="${parameters.mainDecoratorLocation}">
                     <decorator-section name="body">
                         <container>
+                            <platform-specific>
+                                <html><html-template location="component://example/webapp/example/jackrabbit/ContentChooser.ftl"/></html>
+                            </platform-specific>
+                        </container>
+                        <container>
                             <label>${uiLabelMap.ExampleJackrabbitTryRightClick}</label>
                             <platform-specific>
                                 <html><html-template location="component://example/webapp/example/jackrabbit/JackrabbitDataTree.ftl"/></html>

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java Fri Oct 14 09:21:32 2011
@@ -25,7 +25,7 @@ public interface ContentWriter {
     public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException;
 
     /**
-     * Remove the passed node from the content repository
+     * Remove the passed node from the content repository. The node path should be absolute.
      *
      * @param nodePath
      * @throws ObjectContentManagerException

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=1183255&r1=1183254&r2=1183255&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 Fri Oct 14 09:21:32 2011
@@ -261,7 +261,10 @@ public class JcrArticleHelper extends Ab
         // check if this language exist in the repository
         Session session = access.getSession();
         try {
-            if (!session.itemExists(canonicalizedContentPath.toString() + language)) {
+            // check if the node exist OR if the node has NO localized flag OR
+            // the localized flag is set to false
+            if (!session.itemExists(canonicalizedContentPath.toString() + language)
+                    || (!session.getNode(canonicalizedContentPath.toString() + language).hasProperty("localized") || !session.getNode(canonicalizedContentPath.toString() + language).getProperty("localized").getBoolean())) {
                 // check for default language
                 if (!session.itemExists(canonicalizedContentPath.toString() + determindeTheDefaultLanguage())) {
                     // return the first available language

Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java?rev=1183255&r1=1183254&r2=1183255&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java Fri Oct 14 09:21:32 2011
@@ -30,6 +30,7 @@ import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.jcr.access.RepositoryAccess;
 import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit;
+import org.ofbiz.jcr.api.JcrArticleHelper;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder;
 import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews;
@@ -97,6 +98,24 @@ public class JcrTests extends OFBizTestC
         assertEquals("1.2", repositoryAccess.getBaseVersion("/news/today/en"));
     }
 
+    public void testLanguageDetermination() throws Exception{
+        JcrArticleHelper helper = new JcrArticleHelper(userLogin);
+
+        helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar());
+        helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar());
+
+        assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage());
+        assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage());
+        assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage());
+
+        assertEquals("de", helper.readContentFromRepository("/superhero", "de").getLanguage());
+        assertEquals("de", helper.readContentFromRepository("/superhero", "").getLanguage());
+        assertEquals("de", helper.readContentFromRepository("/superhero", "fr").getLanguage());
+
+        helper.removeContentObject("/superhero");
+        helper.closeContentSession();
+    }
+
     public void testRemoveRepositoryNewsNode() throws Exception {
         repositoryAccess.removeContentObject("/news/today");
     }