Author: sascharodekamp
Date: Wed May 18 14:31:33 2011 New Revision: 1124282 URL: http://svn.apache.org/viewvc?rev=1124282&view=rev Log: Update - Versioning and some bugfixes for Text content in JCR Repository Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/example/config/ExampleUiLabels.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/helper/JcrFileHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrHelperAbstract.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrTextHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/helper/JcrTextHelperAbstract.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/OfbizRepositoryMapping.java ofbiz/branches/jackrabbit20100709/runtime/data/ (props changed) 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=1124282&r1=1124281&r2=1124282&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 May 18 14:31:33 2011 @@ -36,374 +36,392 @@ import org.ofbiz.jcr.helper.JcrTextHelpe public class JackrabbitEvents { - public static final String module = JackrabbitEvents.class.getName(); + public static final String module = JackrabbitEvents.class.getName(); - /** - * - * @param request - * @param response - * @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); - - 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()); - return "error"; - } finally { - jackrabbit.closeSession(); - } - - 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 = JackrabbitWorker.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) { - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); - String language = UtilValidate.isNotEmpty(request.getParameter("language")) ? request.getParameter("language") : (String) request.getAttribute("language"); - - try { - String textContent = null; - if (UtilValidate.isEmpty(language)) { - textContent = jackrabbit.getTextData(); - } else { - textContent = jackrabbit.getTextData(language); - } - 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); - } - - request.setAttribute("languageList", langMap); - request.setAttribute("selectedLanguage", jackrabbit.getSelctedLanguage()); - - } 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"; - } finally { - jackrabbit.closeSession(); - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { - String message = request.getParameter("message"); - String language = request.getParameter("selectedLanguage"); - - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); - - 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(); - } - - return "success"; - } - - /** - * - * @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(); - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String removeRepositoryFileNode(HttpServletRequest request, HttpServletResponse response) { - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(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(); - } - - return "success"; - } - - /** - * - * @param request - * @param response - * @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"; - } - - /** - * - * @param request - * @param response - * @return - */ - public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { - - 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 jackrabbit = new JcrFileHelperJackrabbit((GenericValue) request.getSession().getAttribute("userLogin"), (Delegator) request.getAttribute("delegator"), null, passedParams.get("repositoryNode")); - - if (file != null && file.length >= 1) { - try { - jackrabbit.uploadFileData(file, passedParams.get("completeFileName")); - } 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(); - } - - 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"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - - JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(userLogin, delegator, null, "/fileHome"); - - try { - JSONArray fileTree = jackrabbit.getJsonFileTree(); - request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } finally { - jackrabbit.closeSession(); - } - - 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"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - - JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(userLogin, delegator, null, "/"); - - try { - JSONArray fileTree = jackrabbit.getJsonDataTree(); - request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); - } catch (RepositoryException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } finally { - jackrabbit.closeSession(); - } - - return "success"; - } - - public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { - - 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()); - return "error"; - } catch (IOException e) { - Debug.logError(e, module); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - 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"; - } - } - } + /** + * + * @param request + * @param response + * @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); + + 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()); + return "error"; + } finally { + jackrabbit.closeSession(); + } + + 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 = JackrabbitWorker.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) { + 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"); + + 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); + } + + 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()); + return "error"; + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + return "error"; + } finally { + jackrabbit.closeSession(); + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String updateRepositoryData(HttpServletRequest request, HttpServletResponse response) { + String message = request.getParameter("message"); + String language = request.getParameter("selectedLanguage"); + + JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(request); + + 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(); + } + + return "success"; + } + + /** + * + * @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(); + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String removeRepositoryFileNode(HttpServletRequest request, HttpServletResponse response) { + JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(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(); + } + + return "success"; + } + + /** + * + * @param request + * @param response + * @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"; + } + + /** + * + * @param request + * @param response + * @return + */ + public static String uploadFileData(HttpServletRequest request, HttpServletResponse response) { + + 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 jackrabbit = new JcrFileHelperJackrabbit((GenericValue) request.getSession().getAttribute("userLogin"), (Delegator) request.getAttribute("delegator"), null, passedParams.get("repositoryNode")); + + if (file != null && file.length >= 1) { + try { + jackrabbit.uploadFileData(file, passedParams.get("completeFileName")); + } 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(); + } + + 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"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + + JcrFileHelper jackrabbit = new JcrFileHelperJackrabbit(userLogin, delegator, null, "/fileHome"); + + try { + JSONArray fileTree = jackrabbit.getJsonFileTree(); + request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + return "error"; + } finally { + jackrabbit.closeSession(); + } + + 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"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + + JcrTextHelper jackrabbit = new JcrTextHelperJackrabbit(userLogin, delegator, null, "/"); + + try { + JSONArray fileTree = jackrabbit.getJsonDataTree(); + request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); + } catch (RepositoryException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + return "error"; + } finally { + jackrabbit.closeSession(); + } + + return "success"; + } + + public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { + + 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()); + return "error"; + } catch (IOException e) { + Debug.logError(e, module); + request.setAttribute("_ERROR_MESSAGE_", e.toString()); + 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"; - } + return "success"; + } } \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java?rev=1124282&r1=1124281&r2=1124282&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrTextHelperJackrabbit.java Wed May 18 14:31:33 2011 @@ -20,163 +20,175 @@ import org.ofbiz.jcr.helper.JcrTextHelpe public class JcrTextHelperJackrabbit extends JcrTextHelperAbstract implements JcrTextHelper { - public JcrTextHelperJackrabbit(GenericValue userLogin, Delegator delegator, String contentId, String repositoryNode) { - super.userLogin = userLogin; - if (userLogin == null || delegator == null) { - Debug.logError("You pass null for the UserLogin or Delegator, Object can't be created.", module); - return; - } - - Session session = null; - try { - session = JackrabbitContainer.getUserSession(userLogin); - } catch (RepositoryException re) { - Debug.logError(re, module); - return; - } - - try { - super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode, OfbizRepositoryMappingJackrabbit.NODE_TYPE.DATA); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return; - } catch (RepositoryException e) { - Debug.logError(e, module); - return; - } - } - - public JcrTextHelperJackrabbit(HttpServletRequest request) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - super.userLogin = userLogin; - - Session session = null; - try { - session = JackrabbitContainer.getUserSession(userLogin); - } catch (RepositoryException re) { - Debug.logError(re, module); - return; - } - - String contentId = request.getParameter("contentId"); - String repositoryNode = request.getParameter("repositoryNode"); - - Delegator delegator = (Delegator) request.getAttribute("delegator"); - try { - super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode, OfbizRepositoryMappingJackrabbit.NODE_TYPE.DATA); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return; - } catch (RepositoryException e) { - Debug.logError(e, module); - return; - } - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.helper.JcrTextHelper#storeNewTextData(java.lang.String) - */ - @Override - public String storeNewTextData(String message) throws RepositoryException, GenericEntityException { - return storeNewTextData(message, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.helper.JcrTextHelper#storeNewTextData(java.lang.String, - * java.lang.String) - */ - @Override - public String storeNewTextData(String message, String language) throws RepositoryException, GenericEntityException { - orm.updateOrStoreTextData(message, language); - - return orm.getContentId(); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrTextHelper#getStringContent() - */ - @Override - public String getTextData() throws PathNotFoundException, RepositoryException { - return orm.getStringContent(); - } - - /* - * (non-Javadoc) - * - * @see - * org.ofbiz.jcr.helper.JcrTextHelper#getStringContent(java.lang.String) - */ - @Override - public String getTextData(String language) throws PathNotFoundException, RepositoryException { - return orm.getStringContent(language); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrTextHelper#updateTextData(java.lang.String) - */ - @Override - public String updateTextData(String message) throws RepositoryException, GenericEntityException { - orm.updateOrStoreTextData(message); - - return message; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrTextHelper#updateTextData(java.lang.String, - * java.lang.String) - */ - @Override - public String updateTextData(String message, String language) throws RepositoryException, GenericEntityException { - orm.updateOrStoreTextData(message, language); - return message; - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrDataHelper#getJsonDataTree() - */ - @Override - public JSONArray getJsonDataTree() throws RepositoryException { - return orm.getJsonDataTree(); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrTextHelper#addNewNode(java.lang.String) - */ - @Override - public JcrTextHelper addNewNode(String newNode) throws RepositoryException, GenericEntityException { - if (!newNode.startsWith("/")) { - newNode = "/" + newNode; - } - - String newAbsoluteNodePath = orm.getNodePath() + newNode; - - return new JcrTextHelperJackrabbit(userLogin, orm.getDelegator(), null, newAbsoluteNodePath); - } - - /* - * (non-Javadoc) - * - * @see org.ofbiz.jcr.helper.JcrTextHelper#getAvailableLanguages(); - */ - @Override - public List<String> getAvailableLanguages() throws PathNotFoundException, RepositoryException { - return orm.getAvailableLanguages(); - } + public JcrTextHelperJackrabbit(GenericValue userLogin, Delegator delegator, String contentId, String repositoryNode) { + super.userLogin = userLogin; + if (userLogin == null || delegator == null) { + Debug.logError("You pass null for the UserLogin or Delegator, Object can't be created.", module); + return; + } + + Session session = null; + try { + session = JackrabbitContainer.getUserSession(userLogin); + } catch (RepositoryException re) { + Debug.logError(re, module); + return; + } + + try { + super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode, OfbizRepositoryMappingJackrabbit.NODE_TYPE.DATA); + } catch (GenericEntityException e) { + Debug.logError(e, module); + return; + } catch (RepositoryException e) { + Debug.logError(e, module); + return; + } + } + + public JcrTextHelperJackrabbit(HttpServletRequest request) { + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + super.userLogin = userLogin; + + Session session = null; + try { + session = JackrabbitContainer.getUserSession(userLogin); + } catch (RepositoryException re) { + Debug.logError(re, module); + return; + } + + String contentId = request.getParameter("contentId"); + String repositoryNode = request.getParameter("repositoryNode"); + + Delegator delegator = (Delegator) request.getAttribute("delegator"); + try { + super.orm = new OfbizRepositoryMappingJackrabbit(delegator, session, contentId, repositoryNode, OfbizRepositoryMappingJackrabbit.NODE_TYPE.DATA); + } catch (GenericEntityException e) { + Debug.logError(e, module); + return; + } catch (RepositoryException e) { + Debug.logError(e, module); + return; + } + } + + /* + * (non-Javadoc) + * + * @see + * org.ofbiz.jcr.helper.JcrTextHelper#storeNewTextData(java.lang.String) + */ + @Override + public String storeNewTextData(String message) throws RepositoryException, GenericEntityException { + return storeNewTextData(message, null); + } + + /* + * (non-Javadoc) + * + * @see + * org.ofbiz.jcr.helper.JcrTextHelper#storeNewTextData(java.lang.String, + * java.lang.String) + */ + @Override + public String storeNewTextData(String message, String language) throws RepositoryException, GenericEntityException { + orm.updateOrStoreTextData(message, language); + + return orm.getContentId(); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrTextHelper#getStringContent() + */ + @Override + public String getTextData() throws PathNotFoundException, RepositoryException { + return orm.getStringContent(); + } + + /* + * (non-Javadoc) + * + * @see + * org.ofbiz.jcr.helper.JcrTextHelper#getStringContent(java.lang.String) + */ + @Override + public String getTextData(String language) throws PathNotFoundException, RepositoryException { + return orm.getStringContent(language); + } + + /* + * (non-Javadoc) + * + * @see + * org.ofbiz.jcr.helper.JcrTextHelper#getStringContent(java.lang.String, + * java.lang.String) + */ + @Override + public String getTextData(String language, String version) throws PathNotFoundException, RepositoryException { + return orm.getStringContent(language, version); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrTextHelper#updateTextData(java.lang.String) + */ + @Override + public String updateTextData(String message) throws RepositoryException, GenericEntityException { + orm.updateOrStoreTextData(message); + + return message; + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrTextHelper#updateTextData(java.lang.String, + * java.lang.String) + */ + @Override + public String updateTextData(String message, String language) throws RepositoryException, GenericEntityException { + orm.updateOrStoreTextData(message, language); + return message; + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrDataHelper#getJsonDataTree() + */ + @Override + public JSONArray getJsonDataTree() throws RepositoryException { + return orm.getJsonDataTree(); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrTextHelper#addNewNode(java.lang.String) + */ + @Override + public JcrTextHelper addNewNode(String newNode) throws RepositoryException, GenericEntityException { + if (!newNode.startsWith("/")) { + newNode = "/" + newNode; + } + + String newAbsoluteNodePath = orm.getNodePath() + newNode; + + return new JcrTextHelperJackrabbit(userLogin, orm.getDelegator(), null, newAbsoluteNodePath); + } + + /* + * (non-Javadoc) + * + * @see org.ofbiz.jcr.helper.JcrTextHelper#getAvailableLanguages(); + */ + @Override + public List<String> getAvailableLanguages() throws PathNotFoundException, RepositoryException { + return orm.getAvailableLanguages(); + } } |
Free forum by Nabble | Edit this page |