Author: sascharodekamp
Date: Wed Aug 10 14:29:40 2011 New Revision: 1156196 URL: http://svn.apache.org/viewvc?rev=1156196&view=rev Log: Refactoring: Now useing the jackrabbit ObjectContentMapping Library to map POJOs to the Jackrabbit repository. That makes the code more generic and we can define Content Objects for different approches (ie. File Content, News Content, Blog content, Forum Content, Product Content ...). Furthermore i removed the connection between the repository and the database. The default JCR implementation went back to the framework layer and can be used from each application. If an application need additional content information in the database, it is possible to build a database access layer on top of the default JCR implementation (application specific). TODO: Versioning, Language Support, Better Tests, documentation Added: ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/cglib-2.2.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-ocm.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/VersioningManagerJackrabbit.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/handler/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/handler/JcrEventHandler.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/JCRContainer.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactory.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/JCRFactoryUtil.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/OFBizLoginModule.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryFactory.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/RepositoryLoader.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryLoader.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/loader/jackrabbit/JCRFactoryImpl.java (contents, props changed) - copied, changed from r1140127, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/JCRFactoryImpl.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitFile.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitFolder.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitHierarchyNode.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitResource.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitUnstructured.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/security/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/ - copied from r1151379, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java (with props) Removed: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitWorker.java ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRContainer.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JCRFactoryUtil.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryLoader.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrFileHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrFileHelperAbstract.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrHelperAbstract.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrTextHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrTextHelperAbstract.java Modified: ofbiz/branches/jackrabbit20100709/.classpath ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/WEB-INF/controller.xml ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java Modified: ofbiz/branches/jackrabbit20100709/.classpath URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.classpath?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/.classpath (original) +++ ofbiz/branches/jackrabbit20100709/.classpath Wed Aug 10 14:29:40 2011 @@ -147,6 +147,7 @@ <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.2.7.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.2.7.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.2.7.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-ocm.jar" sourcepath="/ocm"/> <classpathentry kind="lib" path="framework/jcr/lib/jcr-2.0.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/pdfbox-1.3.1.jar"/> <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.5.11.jar"/> 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=1156196&r1=1156195&r2=1156196&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 Wed Aug 10 14:29:40 2011 @@ -3,12 +3,11 @@ package org.ofbiz.content.jcr; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.List; import java.util.Map; -import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -21,20 +20,23 @@ import org.apache.commons.fileupload.Fil 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.apache.tika.Tika; +import org.apache.tika.io.TikaInputStream; 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.content.jcr.helper.JcrFileHelperJackrabbit; -import org.ofbiz.content.jcr.helper.JcrTextHelperJackrabbit; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.helper.JcrFileHelper; -import org.ofbiz.jcr.helper.JcrTextHelper; +import org.ofbiz.jcr.access.RepositoryAccess; +import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +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; public class JackrabbitEvents { @@ -47,37 +49,26 @@ public class JackrabbitEvents { * @return */ public static String addNewTextMessageToJcrRepository(HttpServletRequest request, HttpServletResponse response) { - String message = request.getParameter("message"); - String language = request.getParameter("msgLocale"); - - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); - - String newContentId = null; - try { - newContentId = jackrabbit.storeNewTextData(message, language); + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); - if (newContentId == null) { - request.setAttribute("_ERROR_MESSAGE_", "Couldn't be created, maybe the node already exists. Use another node name to store you're content."); - return "error"; - } - - request.setAttribute("newContentId", newContentId); - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); // UtilProperties.getMessage(resourceErr, - // "idealEvents.problemsGettingMerchantConfiguration", - // locale) - return "error"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (GenericEntityException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + String nodePath = request.getParameter("path"); + String language = request.getParameter("msgLocale"); + String title = request.getParameter("title"); + Calendar pubDate = new GregorianCalendar(); // TODO + String content = request.getParameter("message"); + + OfbizRepositoryMappingJackrabbitNews orm = new OfbizRepositoryMappingJackrabbitNews(nodePath, language, title, pubDate, content); + + RepositoryAccess repositoryAccess = null; + try { + repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + repositoryAccess.storeContentObject(orm); + } catch (ObjectContentManagerException ocme) { + Debug.logError(ocme, module); + request.setAttribute("_ERROR_MESSAGE_", ocme.toString()); return "error"; } finally { - jackrabbit.closeSession(); + repositoryAccess.closeAccess(); } return "success"; @@ -92,7 +83,7 @@ public class JackrabbitEvents { public static String scanRepositoryStructure(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); try { - List<Map<String, String>> listIt = JackrabbitWorker.getRepositoryNodes(userLogin, ""); + List<Map<String, String>> listIt = JcrUtilJackrabbit.getRepositoryNodes(userLogin, ""); request.setAttribute("listIt", listIt); } catch (RepositoryException e) { Debug.logError(e, module); @@ -110,56 +101,29 @@ public class JackrabbitEvents { * @return */ public static String getNodeContent(HttpServletRequest request, HttpServletResponse response) { - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); - String language = UtilValidate.isNotEmpty(request.getParameter("language")) ? request.getParameter("language") : (String) request.getAttribute("language"); - String version = UtilValidate.isNotEmpty(request.getParameter("version")) ? request.getParameter("version") : (String) request.getAttribute("version"); + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); - try { - String textContent = null; - if (UtilValidate.isEmpty(language)) { - textContent = jackrabbit.getTextData(); - } else { - if (UtilValidate.isEmpty(version)) { - textContent = jackrabbit.getTextData(language); - } else { - textContent = jackrabbit.getTextData(language, version); - } - } - request.setAttribute("message", textContent); - List<String> availableLanguages = jackrabbit.getAvailableLanguages(); - List<Map<String, String>> langMap = new ArrayList<Map<String, String>>(); - for (String lang : availableLanguages) { - Map<String, String> tmp = new HashMap<String, String>(); - tmp.put("localeId", lang); - langMap.add(tmp); - } - - List<String> availableVersions = jackrabbit.getAllLanguageVersions(); - List<Map<String, String>> versMap = new ArrayList<Map<String, String>>(); - for (String v : availableVersions) { - Map<String, String> tmp = new HashMap<String, String>(); - tmp.put("version", v); - versMap.add(tmp); - } + String node = request.getParameter("path"); - request.setAttribute("languageList", langMap); - request.setAttribute("versionList", versMap); - request.setAttribute("selectedLanguage", jackrabbit.getSelctedLanguage()); - request.setAttribute("currentLanguageVersion", jackrabbit.getCurrentLanguageVersion()); - request.setAttribute("currentBaseNodeVersion", jackrabbit.getCurrentBaseVersion()); - - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + if (UtilValidate.isEmpty(node)) { + 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"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } finally { - jackrabbit.closeSession(); } + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + OfbizRepositoryMappingJackrabbitNews news = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject(node); + + request.setAttribute("contentObject", news); + request.setAttribute("path", news.getPath()); + request.setAttribute("language", news.getLanguage()); + request.setAttribute("pubDate", news.getPubDate()); + request.setAttribute("title", news.getTitle()); + request.setAttribute("version", news.getVersion()); + request.setAttribute("createDate", news.getCreationDate()); + request.setAttribute("content", news.getContent()); + return "success"; } @@ -170,65 +134,21 @@ public class JackrabbitEvents { * @return */ public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { - String message = request.getParameter("message"); - String language = request.getParameter("selectedLanguage"); + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); + String path = request.getParameter("path"); - try { - String textContent = null; - if (UtilValidate.isEmpty(language)) { - textContent = jackrabbit.updateTextData(message); - } else { - textContent = jackrabbit.updateTextData(message, language); - request.setAttribute("language", language); - } - request.setAttribute("message", textContent); - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (GenericEntityException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } finally { - jackrabbit.closeSession(); - } + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + OfbizRepositoryMappingJackrabbitNews news = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject(path); - return "success"; - } + news.setLanguage(request.getParameter("language")); + news.setTitle(request.getParameter("title")); + news.setContent(request.getParameter("content")); + // request.getParameter("pubDate") + // request.getParameter("createDate") - /** - * - * @param request - * @param response - * @return - */ - public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) { - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); - - try { - jackrabbit.removeRepositoryNode(); - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (GenericEntityException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } finally { - jackrabbit.closeSession(); - } + repositoryAccess.updateContentObject(news); + repositoryAccess.closeAccess(); return "success"; } @@ -239,27 +159,14 @@ public class JackrabbitEvents { * @param response * @return */ - public static String removeRepositoryFileNode(HttpServletRequest request, HttpServletResponse response) { - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(request); + public static String removeRepositoryNode(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); - try { - jackrabbit.removeRepositoryNode(); - } catch (PathNotFoundException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (GenericEntityException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } finally { - jackrabbit.closeSession(); - } + String path = request.getParameter("path"); + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + repositoryAccess.removeContentObject(path); + repositoryAccess.closeAccess(); return "success"; } @@ -270,18 +177,6 @@ public class JackrabbitEvents { * @return */ public static String cleanJcrRepository(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - - try { - JackrabbitWorker.cleanJcrRepository(delegator, userLogin); - } catch (GenericEntityException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (RepositoryException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } return "success"; } @@ -293,6 +188,7 @@ public class JackrabbitEvents { * @return */ public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); List<FileItem> list = null; Map<String, String> passedParams = FastMap.newInstance(); @@ -318,35 +214,26 @@ public class JackrabbitEvents { } } - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit((GenericValue) request.getSession().getAttribute("userLogin"), (Delegator) request.getAttribute("delegator"), null, passedParams.get("repositoryNode")); + OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); + ormResource.setData(new ByteArrayInputStream(file)); + ormResource.setMimeType(getMimeTypeFromInputStream(new ByteArrayInputStream(file))); + ormResource.setLastModified(new GregorianCalendar()); + + OfbizRepositoryMappingJackrabbitFile ormFile = new OfbizRepositoryMappingJackrabbitFile(); + ormFile.setCreationDate(new GregorianCalendar()); + ormFile.setResource(ormResource); + + // ormFile.setPath(passedParams.get("path") + "/" + + // passedParams.get("completeFileName")); + ormFile.setPath(passedParams.get("completeFileName")); + // ormFile.setFileName(passedParams.get("completeFileName")); + + OfbizRepositoryMappingJackrabbitFolder ormFolder = new OfbizRepositoryMappingJackrabbitFolder(); + ormFolder.addChild(ormFile); + ormFolder.setPath(passedParams.get("path")); -InputStream i = new ByteArrayInputStream(file); -Tika tika = new Tika(); -try { - String mt = tika.detect(i); -} catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); -} - - - if (file != null && file.length >= 1) { - try { - jackrabbit.uploadFileData(file, passedParams.get("completeFileName"), passedParams.get("fileLocale"), passedParams.get("description")); - } catch (GenericEntityException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } finally { - jackrabbit.closeSession(); - } - } else { - jackrabbit.closeSession(); - } + RepositoryAccess repositoryAcces = new RepositoryAccessJackrabbit(userLogin); + repositoryAcces.storeContentObject(ormFolder); return "success"; } @@ -359,20 +246,17 @@ try { * @return */ public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(userLogin, delegator, null, "/fileHome"); + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); try { - JSONArray fileTree = jackrabbit.getJsonFileTree(); + 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"; - } finally { - jackrabbit.closeSession(); } return "success"; @@ -386,51 +270,50 @@ try { * @return */ public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(userLogin, delegator, null, "/"); + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); + RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); try { - JSONArray fileTree = jackrabbit.getJsonDataTree(); + 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"; - } finally { - jackrabbit.closeSession(); } return "success"; } public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { + GenericValue userLogin = (GenericValue) request.getAttribute("userLogin"); - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(request); - InputStream file = null; - try { - file = jackrabbit.getFileContent(); - UtilHttp.streamContentToBrowser(response, IOUtils.toByteArray(file), jackrabbit.getFileMimeType(), jackrabbit.getNodeName()); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); + String node = request.getParameter("path"); + + if (UtilValidate.isEmpty(node)) { + 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); + OfbizRepositoryMappingJackrabbitFile file = (OfbizRepositoryMappingJackrabbitFile) repositoryAccess.getContentObject(node); + + 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.toString()); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; - } finally { - jackrabbit.closeSession(); - if (file != null) { - try { - file.close(); - } catch (IOException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } - } } return "success"; @@ -438,14 +321,19 @@ try { public static String getFileInformation(HttpServletRequest request, HttpServletResponse resposne) { - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(request); - - request.setAttribute("fileName", jackrabbit.getNodeName()); - request.setAttribute("fileLanguage", jackrabbit.getSelctedLanguage()); - request.setAttribute("fileDescription", jackrabbit.getFileDescription()); - request.setAttribute("fileMimeType", jackrabbit.getFileMimeType()); - jackrabbit.closeSession(); - return "success"; } + + private static String getMimeTypeFromInputStream(InputStream is) { + if (!TikaInputStream.isTikaInputStream(is)) { + is = TikaInputStream.get(is); + } + Tika tika = new Tika(); + try { + return tika.detect(is); + } catch (IOException e) { + Debug.logError(e, module); + return "application/octet-stream"; + } + } } \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java Wed Aug 10 14:29:40 2011 @@ -18,27 +18,17 @@ under the License. */ package org.ofbiz.content.test; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.List; - -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; - -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.content.jcr.JackrabbitWorker; -import org.ofbiz.content.jcr.helper.JcrFileHelperJackrabbit; -import org.ofbiz.content.jcr.helper.JcrTextHelperJackrabbit; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.helper.JcrFileHelper; -import org.ofbiz.jcr.helper.JcrTextHelper; import org.ofbiz.service.testtools.OFBizTestCase; public class JcrTests extends OFBizTestCase { + public JcrTests(String name) { + super(name); + // TODO Auto-generated constructor stub + } + +// TODO create new tests :-) +/* protected GenericValue userLogin = null; protected JcrTextHelper jh = null; @@ -144,4 +134,5 @@ public class JcrTests extends OFBizTestC public void testCleanRepositoryStructure() throws Exception { JackrabbitWorker.cleanJcrRepository(delegator, userLogin); } + */ } \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Wed Aug 10 14:29:40 2011 @@ -97,7 +97,7 @@ under the License. <!-- Load embedded Jackrabbit content repository. Since this container depends upon JNDI, it must be started after the naming-container container.--> - <container name="jcr-container" class="org.ofbiz.jcr.JCRContainer"> + <container name="jcr-container" class="org.ofbiz.jcr.loader.JCRContainer"> <property name="configFilePath" value="framework/jcr/config/jcr-config.xml"/> <property name="removeOnShutdown" value="false"/> </container> Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/base/config/test-containers.xml Wed Aug 10 14:29:40 2011 @@ -64,7 +64,7 @@ under the License. <!-- Load embedded Jackrabbit content repository. Since this container depends upon JNDI, it must be started after the naming-container container.--> - <container name="jcr-container" class="org.ofbiz.jcr.JCRContainer"> + <container name="jcr-container" class="org.ofbiz.jcr.loader.JCRContainer"> <property name="configFilePath" value="framework/jcr/config/jcr-test-config.xml"/> <property name="removeOnShutdown" value="true"/> </container> 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=1156196&r1=1156195&r2=1156196&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 Aug 10 14:29:40 2011 @@ -249,7 +249,7 @@ 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.content.jcr.JackrabbitEvents" invoke="addNewTextMessageToJcrRepository" /> <response name="success" type="request" value="ExampleJackrabbitShowContentData" /> <response name="error" type="view" value="ExampleJackrabbitAddData" /> </request-map> @@ -279,16 +279,10 @@ under the License. </request-map> <request-map uri="RemoveRepositoryFile"> <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryFileNode"/> + <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="removeRepositoryNode"/> <response name="success" type="request" value="ExampleJackrabbitShowUploadedFiles" /> <response name="error" type="request" value="ExampleJackrabbitShowUploadedFiles" /> </request-map> - <request-map uri="CleanJcrRepository"> - <security auth="true" https="true" /> - <event type="java" path="org.ofbiz.content.jcr.JackrabbitEvents" invoke="cleanJcrRepository"/> - <response name="success" type="request-redirect-noparam" value="ExampleJackrabbitScanRepositoryStructure" /> - <response name="error" type="request-redirect-noparam" value="ExampleJackrabbitScanRepositoryStructure" /> - </request-map> <request-map uri="ExampleJackrabbitUploadFileData"> <security auth="true" https="true" /> <response name="success" type="view" value="ExampleJackrabbitUploadFileData" /> Modified: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitDataTree.ftl Wed Aug 10 14:29:40 2011 @@ -52,7 +52,7 @@ under the License. }); function removeDataFromRepository(nodepath, nodetype) { - var parameters = {"repositoryNode" : nodepath}; + var parameters = {"path" : nodepath}; var url = "RemoveRepositoryNode"; runPostRequest(url, parameters) @@ -60,7 +60,7 @@ under the License. function openDataFromRepository(nodepath, nodetype) { - var parameters = {"repositoryNode" : nodepath}; + var parameters = {"path" : nodepath}; var url = "EditRepositoryContent"; runPostRequest(url, parameters) Modified: ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/webapp/example/jackrabbit/JackrabbitFileTree.ftl Wed Aug 10 14:29:40 2011 @@ -58,14 +58,14 @@ under the License. }); function openFileFromRepository(nodepath, nodetype) { - var parameters = {"repositoryNode" : nodepath}; + var parameters = {"path" : nodepath}; var url = "OpenFileInformation"; runPostRequest(url, parameters) } function removeFileFromRepository(nodepath, nodetype) { - var parameters = {"repositoryNode" : nodepath}; + var parameters = {"path" : nodepath}; var url = "RemoveRepositoryFile"; runPostRequest(url, parameters) @@ -76,7 +76,7 @@ under the License. return; } - var parameters = {"repositoryNode" : nodepath}; + var parameters = {"path" : nodepath}; var url = "GetFileFromRepository"; runPostRequest(url, parameters) 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=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitForms.xml Wed Aug 10 14:29:40 2011 @@ -21,16 +21,16 @@ 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"> - <field name="repositoryNode"> - <hyperlink target="EditRepositoryContent" description="${repositoryNode}"> + <field name="path"> + <hyperlink target="EditRepositoryContent" description="${path}"> <parameter param-name="contentId" from-field="contentId" /> - <parameter param-name="repositoryNode" from-field="repositoryNode" /> + <parameter param-name="path" from-field="path" /> </hyperlink> </field> <field name="contentId"> <hyperlink target="EditRepositoryContent" description="${contentId}"> <parameter param-name="contentId" from-field="contentId" /> - <parameter param-name="repositoryNode" from-field="repositoryNode" /> + <parameter param-name="path" from-field="path" /> </hyperlink> </field> <field name="contentTypeId"> @@ -45,12 +45,15 @@ under the License. </form> <form name="AddRepositoryData" type="single" target="StoreNewRepositoryData"> - <field name="repositoryNode" title="${uiLabelMap.ExampleRepositoryNode}" tooltip="${uiLabelMap.ExampleAddNewNodePath}"> - <text></text> + <field name="path" title="${uiLabelMap.ExampleRepositoryNode}" tooltip="${uiLabelMap.ExampleAddNewNodePath}"> + <text /> </field> <field name="msgLocale" title="${uiLabelMap.CommonChooseLanguage}" > <drop-down allow-empty="true" ><list-options key-name="localeId" list-name="parameters.localeList" description="${localeId}"/></drop-down> </field> + <field name="title"> + <text /> + </field> <field name="message" title="${uiLabelMap.ExampleRepositoryMessage}"> <textarea visual-editor-enable="true" /> </field> @@ -60,7 +63,7 @@ under the License. </form> <form name="UploadRepositoryFileData" type="upload" target="StoreNewRepositoryFileData"> - <field name="repositoryNode" title="${uiLabelMap.ExampleRepositoryFolder}" tooltip="${uiLabelMap.ExampleAddNewNodePath}"> + <field name="path" title="${uiLabelMap.ExampleRepositoryFolder}" tooltip="${uiLabelMap.ExampleAddNewNodePath}"> <text></text> </field> <field name="fileData" title="${uiLabelMap.ExampleRepositoryFile}"> @@ -76,7 +79,7 @@ under the License. </form> <form name="EditRepositoryDataChangeLanguage" type="single" target="EditRepositoryContent" default-entity-name="Content"> - <field name="repositoryNode" title="${uiLabelMap.ExampleRepositoryNode}" map-name="content"> + <field name="path" title="${uiLabelMap.ExampleRepositoryNode}" map-name="content"> <hidden /> </field> <field name="language" title="${uiLabelMap.CommonChooseLanguage}" > @@ -88,20 +91,26 @@ under the License. <field name="submit" ><submit/></field> </form> - <form name="EditRepositoryData" type="single" target="UpdateRepositoryData" default-entity-name="Content"> - <field name="repositoryNode" title="${uiLabelMap.ExampleRepositoryNode}" map-name="content"> + <form name="EditRepositoryData" type="single" target="UpdateRepositoryData" > + <field name="title"> <display /> </field> - <field name="selectedLanguage" title="${uiLabelMap.CommonLanguageTitle}"> + <field name="path" title="${uiLabelMap.ExampleRepositoryNode}" > <display /> </field> - <field name="currentLanguageVersion" title="${uiLabelMap.ExampleLanguageTextVersion}"> + <field name="language" title="${uiLabelMap.CommonLanguageTitle}"> <display /> </field> - <field name="currentBaseNodeVersion" title="${uiLabelMap.ExampleBaseNodeVersion}"> + <field name="pubDate" > <display /> </field> - <field name="message" title="${uiLabelMap.ExampleRepositoryMessage}" map-name="content"> + <field name="createDate" > + <display /> + </field> + <field name="version" > + <display /> + </field> + <field name="content" title="${uiLabelMap.ExampleRepositoryMessage}" > <textarea visual-editor-enable="true" default-value="${parameters.message}"/> </field> <field name="submit"> @@ -110,10 +119,7 @@ under the License. </form> <form name="ScanRepositoryStructure" type="list" list-name="listIt" 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"> - <field name="repositoryNode"> - <display /> - </field> - <field name="nodeContent"> + <field name="path"> <display /> </field> <field name="primaryNodeType"> 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=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleJackrabbitScreens.xml Wed Aug 10 14:29:40 2011 @@ -112,9 +112,6 @@ under the License. <decorator-screen name="CommonExampleJackrabbitDecorator" location="${parameters.mainDecoratorLocation}"> <decorator-section name="body"> <container> - <link target="CleanJcrRepository" style="buttontext" text="${uiLabelMap.ExampleJackrabbitCleanRepository}"></link> <label>${uiLabelMap.ExampleJackrabbitCleanRepositoryTooltip}</label> - </container> - <container> <include-form location="component://example/widget/example/ExampleJackrabbitForms.xml" name="ScanRepositoryStructure" /> </container> </decorator-section> @@ -128,9 +125,6 @@ under the License. <actions> <set field="titleProperty" value="PageTitleExampleJackrabbit" /> <set field="tabButtonItem" value="ExampleJackrabbitMainPage" /> - <entity-one value-field="content" entity-name="Content"> - <field-map field-name="contentId" from-field="parameters.contentId"/> - </entity-one> </actions> <widgets> <decorator-screen name="CommonExampleJackrabbitDecorator" location="${parameters.mainDecoratorLocation}"> Modified: ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/widget/example/ExampleMenus.xml Wed Aug 10 14:29:40 2011 @@ -108,7 +108,6 @@ under the License. <menu-item name="ExampleJackrabbitAddData" title="${uiLabelMap.ExampleAddNewContentEntry}"><link target="ExampleJackrabbitAddData"/></menu-item> <menu-item name="ExampleJackrabbitUploadFileData" title="${uiLabelMap.ExampleJackrabbitUploadFileData}"><link target="ExampleJackrabbitUploadFileData"/></menu-item> <menu-item name="ExampleJackrabbitShowUploadedFiles" title="${uiLabelMap.ExampleJackrabbitShowUploadedFiles}"><link target="ExampleJackrabbitShowUploadedFiles"/></menu-item> - <menu-item name="ExampleJackrabbitListNodes" title="${uiLabelMap.ExampleJackrabbitListNodes}"><link target="ExampleJackrabbit"/></menu-item> <menu-item name="ExampleJackrabbitScanRepositoryStrukture" title="${uiLabelMap.ExampleScanRepositoryStrukture}"><link target="ExampleJackrabbitScanRepositoryStructure"/></menu-item> </menu> </menus> Added: ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml Wed Aug 10 14:29:40 2011 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<nodeTypes xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" + xmlns:ocm="http://jackrabbit.apache.org/ocm" xmlns:rep="internal" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <nodeType hasOrderableChildNodes="false" isAbstract="false" isMixin="true" isQueryable="true" name="ocm:discriminator" primaryItemName=""> + <supertypes> + <supertype>nt:base</supertype> + </supertypes> + <propertyDefinition autoCreated="false" isFullTextSearchable="false" isQueryOrderable="false" mandatory="true" multiple="false" name="ocm_classname" onParentVersion="COPY" protected="false" requiredType="String" /> + </nodeType> + +</nodeTypes> \ No newline at end of file Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/config/custom-jackrabbit-nodetypes.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jackrabbit.xml Wed Aug 10 14:29:40 2011 @@ -66,7 +66,7 @@ <!-- <param name="config" value="${rep.home}/access.xml"/> --> </AccessManager> - <LoginModule class="org.ofbiz.jcr.OFBizLoginModule"/> + <LoginModule class="org.ofbiz.jcr.loader.OFBizLoginModule"/> </Security> <!-- Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-config.xml Wed Aug 10 14:29:40 2011 @@ -9,7 +9,7 @@ <jcr-context name="default" /> <!-- This is the default implementation and uses the JackRabbit implementation as its default --> - <jcr name="default" class="org.ofbiz.jcr.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local" /> + <jcr name="default" class="org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local" /> <!-- This is an example custom implementation and uses the class name specified as jcr implementation --> <!-- <jcr name="myCustom" class="com.mycompany.jcr.MyCustomJCR"/> --> Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml?rev=1156196&r1=1156195&r2=1156196&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/config/jcr-test-config.xml Wed Aug 10 14:29:40 2011 @@ -24,7 +24,7 @@ under the License. <jcr-context name="default" /> <!-- This is the default implementation and uses the JackRabbit implementation as its default --> - <jcr name="default" class="org.ofbiz.jcr.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local"/> + <jcr name="default" class="org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl" jndi-name="jcr/local"/> <!-- This is an example custom implementation and uses the class name specified as jcr implementation --> <!-- Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/cglib-2.2.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/cglib-2.2.jar?rev=1156196&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/cglib-2.2.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-ocm.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-ocm.jar?rev=1156196&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-ocm.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,4 @@ +package org.ofbiz.jcr.access; + +public interface Constants { +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/Constants.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,35 @@ +package org.ofbiz.jcr.access; + +import javax.jcr.RepositoryException; + +import net.sf.json.JSONArray; + +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; + + +public interface ContentReader { + + /** + * Return an OfbizRepositoryMapping Object from the JCR Repository. + * + * @param nodePath + * @return + */ + OfbizRepositoryMapping getContentObject(String nodePath); + + /** + * Returns a tree of all content nodes (except folders and files) in the repository. + * + * @return + * @throws RepositoryException + */ + JSONArray getJsonDataTree() throws RepositoryException; + + /** + * Returns a tree of all folder/file nodes in the repository. + * + * @return + * @throws RepositoryException + */ + JSONArray getJsonFileTree() throws RepositoryException; +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,33 @@ +package org.ofbiz.jcr.access; + +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; + +public interface ContentWriter { + + /** + * Stores the OfbizRepositoryMapping Class in the content repository. + * + * @param orm + * @throws ObjectContentManagerException + */ + public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException; + + /** + * Update the OfbizRepositoryMapping Class in the content repository. + * + * @param orm + * @throws ObjectContentManagerException + */ + public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException; + + /** + * Remove the passed node from the content repository + * + * @param nodePath + * @throws ObjectContentManagerException + */ + public void removeContentObject(String nodePath) throws ObjectContentManagerException; + + +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentWriter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,5 @@ +package org.ofbiz.jcr.access; + +public interface DBAccess { + +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/DBAccess.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,5 @@ +package org.ofbiz.jcr.access; + +public interface HealthCheck { + +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/HealthCheck.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,73 @@ +package org.ofbiz.jcr.access; + +import javax.jcr.RepositoryException; + +import net.sf.json.JSONArray; + +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; + +public interface RepositoryAccess { + + /** + * Close the current repository session should be used when the operation + * with this object are finished. + */ + public void closeAccess(); + + /** + * Return an OfbizRepositoryMapping Object from the content repository. + * + * @param nodePath + * @return + */ + OfbizRepositoryMapping getContentObject(String nodePath); + + /** + * Stores the OfbizRepositoryMapping Class in the content repository. + * + * @param orm + * @throws ObjectContentManagerException + */ + void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException; + + /** + * Update the passed content object. + * + * @param orm + * @throws ObjectContentManagerException + */ + public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException; + + /** + * Remove the passed node from the content repository + * + * @param nodePath + * @throws ObjectContentManagerException + */ + public void removeContentObject(String nodePath) throws ObjectContentManagerException; + + /** + * Remove the passed node from the content repository + * + * @param orm + * @throws ObjectContentManagerException + */ + public void removeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException; + + /** + * Returns a tree of all content nodes (except folders and files) in the repository. + * + * @return + * @throws RepositoryException + */ + JSONArray getJsonDataTree() throws RepositoryException; + + /** + * Returns a tree of all file/folder nodes in the repository. + * + * @return + * @throws RepositoryException + */ + JSONArray getJsonFileTree() throws RepositoryException; +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/RepositoryAccess.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,5 @@ +package org.ofbiz.jcr.access; + +public interface VersioningManager { + +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/VersioningManager.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,26 @@ +package org.ofbiz.jcr.access.jackrabbit; + +import javax.jcr.nodetype.NodeType; + +import org.ofbiz.jcr.access.Constants; + +public class ConstantsJackrabbit implements Constants { + protected enum PROPERTY_FIELDS { + MESSAGE("jcr:message"), FILE(NodeType.NT_FILE), FOLDER(NodeType.NT_FOLDER), RESOURCE(NodeType.NT_RESOURCE), DATA("jcr:data"), UNSTRUCTURED(NodeType.NT_UNSTRUCTURED), MIMETYPE("jcr:mimeType"), REPROOT("rep:root"), mixInLANGUAGE("mix:language"), mixInVERSIONING( + "mix:versionable"), mixInTITLE("mix:title"), LANGUAGE("jcr:language"), TITLE("jcr:title"), DESCRIPTION("jcr:description"); + + String type = null; + + PROPERTY_FIELDS(String type) { + this.type = type; + } + + String getType() { + return this.type; + } + + }; + + public static String ROOTPATH = "/"; + public static String FILEROOT = ROOTPATH + "fileHome"; +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ConstantsJackrabbit.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,135 @@ +package org.ofbiz.jcr.access.jackrabbit; + +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.RepositoryException; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.ofbiz.jcr.access.ContentReader; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; + +public class ContentReaderJackrabbit implements ContentReader { + + private static String module = ContentReaderJackrabbit.class.getName(); + + private ObjectContentManager ocm = null; + + public ContentReaderJackrabbit(ObjectContentManager ocm) { + this.ocm = ocm; + } + + @Override + public OfbizRepositoryMapping getContentObject(String nodePath) { + // OfbizRepositoryMappingJackrabbit ofbizRepositoryMapping = + // (OfbizRepositoryMappingJackrabbit) ocm.getObject(nodePath); + return (OfbizRepositoryMapping) ocm.getObject(nodePath); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.orm.ContentReader#getJsonDataTree() + */ + @Override + public JSONArray getJsonDataTree() throws RepositoryException { + return getJsonDataChildNodes(ocm.getSession().getRootNode()); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.access.ContentReader#getJsonFileTree() + */ + @Override + public JSONArray getJsonFileTree() throws RepositoryException { + return getJsonFileChildNodes(ocm.getSession().getRootNode()); + } + + /** + * Returns a JSON Array with the repository folder structure. The JSON array + * is directly build for the jsTree jQuery plugin. + * + * @param startNode + * @return + * @throws RepositoryException + */ + private JSONArray getJsonFileChildNodes(Node startNode) throws RepositoryException { + NodeIterator nodeIterator = startNode.getNodes(); + + JSONArray folderStrucutre = new JSONArray(); + JSONObject attr = new JSONObject(); + + while (nodeIterator.hasNext()) { + JSONObject folder = new JSONObject(); + Node node = nodeIterator.nextNode(); + + if (node.getPrimaryNodeType().isNodeType(ConstantsJackrabbit.PROPERTY_FIELDS.FOLDER.getType())) { + attr.element("title", node.getName()); + folder.element("data", attr); + + attr = new JSONObject(); + attr.element("NodePath", node.getPath()); + attr.element("NodeType", node.getPrimaryNodeType().getName()); + folder.element("attr", attr); + + folder.element("children", getJsonFileChildNodes(node).toString()); + + folderStrucutre.element(folder); + } else if (node.getPrimaryNodeType().isNodeType(ConstantsJackrabbit.PROPERTY_FIELDS.FILE.getType())) { + attr = new JSONObject(); + attr.element("title", node.getName()); + folder.element("data", attr); + + attr = new JSONObject(); + attr.element("NodePath", node.getPath()); + attr.element("NodeType", node.getPrimaryNodeType().getName()); + folder.element("attr", attr); + + folderStrucutre.element(folder); + } + + } + + return folderStrucutre; + } + + /** + * Returns a JSON Array with the repository text data structure. The JSON + * array is directly build for the jsTree jQuery plugin. + * + * @param startNode + * @return + * @throws RepositoryException + */ + private JSONArray getJsonDataChildNodes(Node startNode) throws RepositoryException { + NodeIterator nodeIterator = startNode.getNodes(); + + JSONArray folderStrucutre = new JSONArray(); + JSONObject attr = new JSONObject(); + + while (nodeIterator.hasNext()) { + JSONObject folder = new JSONObject(); + Node node = nodeIterator.nextNode(); + + // + if (node.getPrimaryNodeType().isNodeType(ConstantsJackrabbit.PROPERTY_FIELDS.UNSTRUCTURED.getType()) && !node.hasProperty(ConstantsJackrabbit.PROPERTY_FIELDS.mixInLANGUAGE.getType())) { + attr.element("title", node.getName()); + folder.element("data", attr); + + attr = new JSONObject(); + attr.element("NodePath", node.getPath()); + attr.element("NodeType", node.getPrimaryNodeType().getName()); + folder.element("attr", attr); + + folder.element("children", getJsonDataChildNodes(node).toString()); + + folderStrucutre.element(folder); + } + } + + return folderStrucutre; + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,103 @@ +package org.ofbiz.jcr.access.jackrabbit; + +import javax.jcr.Node; +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.jcr.access.ContentWriter; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; + +public class ContentWriterJackrabbit implements ContentWriter { + + private static String module = ContentWriterJackrabbit.class.getName(); + + private ObjectContentManager ocm = null; + + public ContentWriterJackrabbit(ObjectContentManager ocm) { + this.ocm = ocm; + } + + @Override + public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { + if (orm == null) { + return; + } + + // We have to check if the node structure (the sub nodes of the passed + // ORM Object) exist, otherwise they will be created. + String path = orm.getPath(); + String[] nodeStructure = path.split("/"); + Node parentNode = null; + try { + parentNode = this.ocm.getSession().getRootNode(); + } catch (RepositoryException e) { + Debug.logError(e, "The new node could not be created: " + orm.getPath(), module); + return; + } + + // We loop only over the sub nodes. + for (int i = 0; i < (nodeStructure.length - 1); i++) { + String node = nodeStructure[i]; + if (UtilValidate.isEmail(node)) { + continue; + } + + try { + if (parentNode.hasNode(node)) { + parentNode = parentNode.getNode(node); + } 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); + + ocm.insert(newNode); + parentNode = parentNode.getNode(node); + } + } catch (PathNotFoundException e) { + Debug.logError(e, "The new node could not be created: " + orm.getPath(), module); + return; + } 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; + } + + } + + ocm.insert(orm); + this.saveState(); + } + + @Override + public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { + ocm.update(orm); + this.saveState(); + } + + @Override + public void removeContentObject(String nodePath) throws ObjectContentManagerException { + ocm.remove(nodePath); + this.saveState(); + } + + private void saveState() { + if (ocm != null) { + ocm.save(); + } + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,7 @@ +package org.ofbiz.jcr.access.jackrabbit; + +import org.ofbiz.jcr.access.HealthCheck; + +public class HealthCheckJackrabbit implements HealthCheck{ + +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/HealthCheckJackrabbit.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java?rev=1156196&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java Wed Aug 10 14:29:40 2011 @@ -0,0 +1,18 @@ +package org.ofbiz.jcr.access.jackrabbit; + +import javax.jcr.nodetype.NodeType; + +public enum NodePropertiesJackrabbit { + MESSAGE("jcr:message"), FILE(NodeType.NT_FILE), FOLDER(NodeType.NT_FOLDER), RESOURCE(NodeType.NT_RESOURCE), DATA("jcr:data"), UNSTRUCTURED(NodeType.NT_UNSTRUCTURED), MIMETYPE("jcr:mimeType"), REPROOT("rep:root"), mixInLANGUAGE("mix:language"), mixInVERSIONING( + "mix:versionable"), mixInTITLE("mix:title"), LANGUAGE("jcr:language"), TITLE("jcr:title"), DESCRIPTION("jcr:description"); + + String type = null; + + NodePropertiesJackrabbit(String type) { + this.type = type; + } + + public String getType() { + return this.type; + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |