Author: sascharodekamp
Date: Wed Oct 12 14:39:08 2011 New Revision: 1182405 URL: http://svn.apache.org/viewvc?rev=1182405&view=rev Log: Update the Node Language and Version selection, move the Event class from content to example module to absolute decouple the JCR from the application area. Added: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (with props) Removed: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java Modified: ofbiz/branches/jackrabbit20100709/applications/content/build.xml ofbiz/branches/jackrabbit20100709/framework/example/build.xml ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml 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/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/VersioningManagerJackrabbit.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/applications/content/build.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/build.xml?rev=1182405&r1=1182404&r2=1182405&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/build.xml (original) +++ ofbiz/branches/jackrabbit20100709/applications/content/build.xml Wed Oct 12 14:39:08 2011 @@ -47,8 +47,6 @@ under the License. <fileset dir="../../framework/webapp/build/lib" includes="*.jar"/> <fileset dir="../../framework/widget/build/lib" includes="*.jar"/> <fileset dir="../../framework/common/build/lib" includes="*.jar"/> - <fileset dir="../../framework/jcr/lib" includes="*.jar"/> - <fileset dir="../../framework/jcr/build/lib" includes="*.jar"/> </path> <patternset id="src.exc.set"> Modified: ofbiz/branches/jackrabbit20100709/framework/example/build.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/build.xml?rev=1182405&r1=1182404&r2=1182405&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/build.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/build.xml Wed Oct 12 14:39:08 2011 @@ -37,6 +37,9 @@ under the License. <path id="local.class.path"> <fileset dir="${lib.dir}" includes="*.jar"/> <fileset dir="../../framework/base/lib" includes="*.jar"/> + <fileset dir="../../framework/base/lib/commons" includes="*.jar"/> + <fileset dir="../../framework/base/lib/j2eespecs" includes="*.jar"/> + <fileset dir="../../framework/base/lib/scripting" includes="*.jar"/> <fileset dir="../../framework/base/build/lib" includes="*.jar"/> <fileset dir="../../framework/entity/lib" includes="*.jar"/> <fileset dir="../../framework/entity/build/lib" includes="*.jar"/> @@ -47,5 +50,8 @@ under the License. <fileset dir="../../framework/widget/build/lib" includes="*.jar"/> <fileset dir="../../framework/webapp/lib" includes="*.jar"/> <fileset dir="../../framework/webapp/build/lib" includes="*.jar"/> + <fileset dir="../../framework/common/build/lib" includes="*.jar"/> + <fileset dir="../../framework/jcr/lib" includes="*.jar"/> + <fileset dir="../../framework/jcr/build/lib" includes="*.jar"/> </path> </project> Added: 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=1182405&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java Wed Oct 12 14:39:08 2011 @@ -0,0 +1,353 @@ +package org.ofbiz.example; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Map; + +import javax.jcr.ItemExistsException; +import javax.jcr.RepositoryException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import javolution.util.FastMap; +import net.sf.json.JSONArray; + +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.io.IOUtils; +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.FileUtil; +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.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.api.JcrContentHelper; +import org.ofbiz.jcr.api.JcrFileHelper; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitHierarchyNode; +import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; + +public class JackrabbitEvents { + + public static final String module = JackrabbitEvents.class.getName(); + + /** + * + * @param request + * @param response + * @return + */ + public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin); + + 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"); + + try { + 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.getMessage()); + return "error"; + } finally { + articleHelper.closeContentSession(); + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + try { + List<Map<String, String>> listIt = JcrUtilJackrabbit.getRepositoryNodes(userLogin, ""); + request.setAttribute("listIt", listIt); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + return "error"; + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + String contentPath = request.getParameter("path"); + + 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"; + } + + JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin); + OfbizRepositoryMappingJackrabbitArticle ormArticle = null; + if (UtilValidate.isEmpty(version)) { + ormArticle = articleHelper.readContentFromRepository(contentPath, language); + } else { + ormArticle = articleHelper.readContentFromRepository(contentPath, language, version); + } + + request.setAttribute("path", ormArticle.getPath()); + request.setAttribute("language", ormArticle.getLanguage()); + request.setAttribute("title", ormArticle.getTitle()); + request.setAttribute("version", ormArticle.getVersion()); + request.setAttribute("versionList", articleHelper.getVersionListForCurrentArticle()); + request.setAttribute("languageList", articleHelper.getAvailableLanguageList()); + request.setAttribute("createDate", ormArticle.getCreationDate()); + request.setAttribute("content", ormArticle.getContent()); + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + String contentPath = request.getParameter("path"); + JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin); + + OfbizRepositoryMappingJackrabbitArticle ormArticle = articleHelper.readContentFromRepository(contentPath); + + // news.setLanguage(request.getParameter("language")); + ormArticle.setTitle(request.getParameter("title")); + ormArticle.setContent(request.getParameter("content")); + // request.getParameter("pubDate") + // request.getParameter("createDate") + + try { + articleHelper.updateContentInRepository(ormArticle); + } catch (ObjectContentManagerException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + } finally { + articleHelper.closeContentSession(); + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + String contentPath = request.getParameter("path"); + + JcrContentHelper helper = new JcrContentHelper(userLogin); + helper.removeContentObject(contentPath); + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { + 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(); + + try { + list = UtilGenerics.checkList(fu.parseRequest(request)); + } catch (FileUploadException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + return "error"; + } + + byte[] file = null; + for (FileItem fi : list) { + String fieldName = fi.getFieldName(); + + if (fi.isFormField()) { + String fieldStr = fi.getString(); + passedParams.put(fieldName, fieldStr); + } else if (fieldName.startsWith("fileData")) { + passedParams.put("completeFileName", fi.getName()); + file = fi.get(); + } + } + + JcrFileHelper fileHelper = new JcrFileHelper(userLogin); + + try { + + fileHelper.storeContentInRepository(file, passedParams.get("completeFileName"), passedParams.get("path")); + + } catch (ObjectContentManagerException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + } catch (ItemExistsException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + } finally { + fileHelper.closeContentSession(); + } + + return "success"; + } + + /** + * Creates the FILE Tree as JSON Object + * + * @param request + * @param response + * @return + */ + public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + try { + JSONArray fileTree = repositoryAccess.getJsonFileTree(); + request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("dataTree", new JSONArray()); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + return "error"; + } + + return "success"; + } + + /** + * Creates the DATA (TEXT) Tree as JSON Object + * + * @param request + * @param response + * @return + */ + public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + try { + JSONArray fileTree = repositoryAccess.getJsonDataTree(); + request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("dataTree", new JSONArray()); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + return "error"; + } + + return "success"; + } + + public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + + String contentPath = request.getParameter("path"); + + 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"; + } + + JcrFileHelper fileHelper = new JcrFileHelper(userLogin); + OfbizRepositoryMappingJackrabbitHierarchyNode orm = fileHelper.getRepositoryContent(contentPath); + + if (fileHelper.isFileContent()) { + OfbizRepositoryMappingJackrabbitFile file = (OfbizRepositoryMappingJackrabbitFile) orm; + InputStream fileStream = file.getResource().getData(); + + String fileName = file.getPath(); + if (fileName.indexOf("/") != -1) { + fileName = fileName.substring(fileName.indexOf("/") + 1); + } + + try { + UtilHttp.streamContentToBrowser(response, IOUtils.toByteArray(fileStream), file.getResource().getMimeType(), fileName); + } catch (IOException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + return "error"; + } + } else { + Debug.logWarning("This content is no file content, the content is from the type: " + orm.getClass().getName(), module); + } + return "success"; + } + + public static String getFileInformation(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + String contentPath = request.getParameter("path"); + + JcrFileHelper fileHelper = new JcrFileHelper(userLogin); + OfbizRepositoryMapping orm = fileHelper.getRepositoryContent(contentPath); + + // Here we can differentiate between a file or folder content + if (fileHelper.isFileContent()) { + OfbizRepositoryMappingJackrabbitFile file = (OfbizRepositoryMappingJackrabbitFile) orm; + request.setAttribute("fileName", file.getPath()); + request.setAttribute("fileLastModified", file.getResource().getLastModified().getTime()); + request.setAttribute("fileMimeType", file.getResource().getMimeType()); + request.setAttribute("fileCreationDate", file.getCreationDate().getTime()); + } else if (fileHelper.isFolderContent()) { + OfbizRepositoryMappingJackrabbitFolder folder = (OfbizRepositoryMappingJackrabbitFolder) orm; + request.setAttribute("fileName", folder.getPath()); + request.setAttribute("fileCreationDate", folder.getCreationDate().getTime()); + } + + return "success"; + } + +} \ No newline at end of file Propchange: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java ------------------------------------------------------------------------------ svn:mime-type = text/plain 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -249,37 +249,37 @@ under the License. </request-map> <request-map uri="StoreNewRepositoryData"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="addNewTextMessageToJcrRepository" /> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="addNewTextMessageToJcrRepository" /> <response name="success" type="request" value="ExampleJackrabbitShowContentData" /> <response name="error" type="view" value="ExampleJackrabbitAddData" /> </request-map> <request-map uri="ExampleJackrabbitScanRepositoryStructure"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="scanRepositoryStructure"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="scanRepositoryStructure"/> <response name="success" type="view" value="ExampleJackrabbitScanRepositoryStructure" /> <response name="error" type="view" value="ExampleJackrabbitScanRepositoryStructure" /> </request-map> <request-map uri="EditRepositoryContent"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getNodeContent"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getNodeContent"/> <response name="success" type="view" value="ExampleJackrabbitEditRepositoryContent" /> <response name="error" type="view" value="ExampleJackrabbitShowContentData" /> </request-map> <request-map uri="UpdateRepositoryData"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="updateRepositoryData"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="updateRepositoryData"/> <response name="success" type="request" value="EditRepositoryContent" /> <response name="error" type="request" value="EditRepositoryContent" /> </request-map> <request-map uri="RemoveRepositoryNode"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryNode"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="removeRepositoryNode"/> <response name="success" type="request" value="ExampleJackrabbitShowContentData" /> <response name="error" type="request" value="ExampleJackrabbitShowContentData" /> </request-map> <request-map uri="RemoveRepositoryFile"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryNode"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="removeRepositoryNode"/> <response name="success" type="request" value="ExampleJackrabbitShowUploadedFiles" /> <response name="error" type="request" value="ExampleJackrabbitShowUploadedFiles" /> </request-map> @@ -290,31 +290,31 @@ under the License. </request-map> <request-map uri="StoreNewRepositoryFileData"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="uploadFileData"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="uploadFileData"/> <response name="success" type="request" value="ExampleJackrabbitShowUploadedFiles" /> <response name="error" type="view" value="ExampleJackrabbitUploadFileData" /> </request-map> <request-map uri="ExampleJackrabbitShowUploadedFiles"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getRepositoryFileTree"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getRepositoryFileTree"/> <response name="success" type="view" value="ExampleJackrabbitShowUploadedFiles" /> <response name="error" type="view" value="ExampleJackrabbitShowUploadedFiles" /> </request-map> <request-map uri="GetFileFromRepository"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getFileFromRepository"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getFileFromRepository"/> <response name="success" type="none" /> <response name="error" type="none" /> </request-map> <request-map uri="ExampleJackrabbitShowContentData"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getRepositoryDataTree"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getRepositoryDataTree"/> <response name="success" type="view" value="ExampleJackrabbitShowContentData"/> <response name="error" type="view" value="ExampleJackrabbitShowContentData"/> </request-map> <request-map uri="OpenFileInformation"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="getFileInformation"/> + <event type="java" path="org.ofbiz.example.JackrabbitEvents" invoke="getFileInformation"/> <response name="success" type="view" value="ExampleJackrabbitOpenFileInformation"/> <response name="error" type="view" value="ExampleJackrabbitShowUploadedFiles"/> </request-map> 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=1182405&r1=1182404&r2=1182405&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Wed Oct 12 14:39:08 2011 @@ -83,7 +83,7 @@ under the License. <hidden /> </field> <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> + <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> 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -6,7 +6,6 @@ import net.sf.json.JSONArray; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; - public interface ContentReader { /** @@ -18,7 +17,10 @@ public interface ContentReader { OfbizRepositoryMapping getContentObject(String nodePath); /** - * Return an OfbizRepositoryMapping Object in the specified language and version from the JCR Repository. + * Return an OfbizRepositoryMapping Object in the specified language and + * version from the JCR Repository. The Method checks if the requested + * version for this node exist. If not the latest version of the node will + * be returned. * * @param nodePath * @param language @@ -28,7 +30,8 @@ public interface ContentReader { OfbizRepositoryMapping getContentObject(String nodePath, String version); /** - * 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 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -14,6 +14,15 @@ public interface VersioningManager { public List<String> getVersionList(String nodePath); /** + * Returns true if the passed node exist in the requested version. + * + * @param nodePath + * @param version + * @return + */ + public boolean checkIfVersionExist(String nodePath, String version); + + /** * Returns the last checked in version. * * @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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -2,14 +2,15 @@ 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; import net.sf.json.JSONObject; import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.ofbiz.base.util.Debug; import org.ofbiz.jcr.access.ContentReader; +import org.ofbiz.jcr.access.VersioningManager; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; public class ContentReaderJackrabbit implements ContentReader { @@ -24,30 +25,30 @@ public class ContentReaderJackrabbit imp /* * (non-Javadoc) - * @see org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String) + * + * @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) + * + * @see + * org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String, + * java.lang.String, java.lang.String) */ @Override public OfbizRepositoryMapping getContentObject(String nodePath, String version) { + 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); + return getContentObject(nodePath); + } + return (OfbizRepositoryMapping) ocm.getObject(nodePath, version); } 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -63,6 +63,15 @@ public class VersioningManagerJackrabbit /* * (non-Javadoc) + * @see org.ofbiz.jcr.access.VersioningManager#checkIfVersionExist(java.lang.String, java.lang.String) + */ + @Override + public boolean checkIfVersionExist(String nodePath, String version) { + return getVersionList(nodePath).contains(version); + } + + /* + * (non-Javadoc) * * @see * org.ofbiz.jcr.access.VersioningManager#checkOutContentObject(java.lang 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -8,6 +8,7 @@ import java.util.Locale; import javax.jcr.ItemExistsException; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -112,7 +113,10 @@ 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 version information. + article.setPath(contentPath); // the content path must be + // manipulated because, the jackrabbit + // orm returns a full blown path with + // version information. 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()); @@ -173,12 +177,43 @@ public class JcrArticleHelper extends Ab 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>(); + versions = new ArrayList<String>(1); } return versions; } + public List<String> getAvailableLanguageList() { + List<String> languages = null; + + 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)); + } + + } catch (PathNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RepositoryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } 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; + } + /** * This method should determine the correct language for the content. It * covers the case when the passed language is not available. 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=1182405&r1=1182404&r2=1182405&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 Wed Oct 12 14:39:08 2011 @@ -65,7 +65,7 @@ public class JcrTests extends OFBizTestC public void testCreateRepositoryNewsNode() throws Exception { // Create New Object // path, language, title, publication date, content string - OfbizRepositoryMappingJackrabbitNews orm = new OfbizRepositoryMappingJackrabbitNews("/news/today", "en", "News of Today", new GregorianCalendar(), "Hello World"); + OfbizRepositoryMappingJackrabbitNews orm = new OfbizRepositoryMappingJackrabbitNews("/news/today", "en", "News of Today", new GregorianCalendar(), "Hello World"); assertNotNull(orm); repositoryAccess.storeContentObject(orm); |
Free forum by Nabble | Edit this page |