Author: sascharodekamp
Date: Wed Sep 28 09:26:28 2011 New Revision: 1176796 URL: http://svn.apache.org/viewvc?rev=1176796&view=rev Log: (empty) Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java (with props) ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java (with props) Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/JackrabbitEvents.java?rev=1176796&r1=1176795&r2=1176796&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 Sep 28 09:26:28 2011 @@ -1,6 +1,5 @@ package org.ofbiz.content.jcr; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Calendar; @@ -22,8 +21,6 @@ import org.apache.commons.fileupload.dis 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; @@ -31,13 +28,12 @@ import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.content.jcr.helper.JcrArticleHelper; +import org.ofbiz.content.jcr.helper.JcrFileHelper; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.RepositoryAccess; import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitResource; import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; public class JackrabbitEvents { @@ -121,7 +117,6 @@ public class JackrabbitEvents { JcrArticleHelper articleHelper = new JcrArticleHelper(userLogin); OfbizRepositoryMappingJackrabbitArticle ormArticle = articleHelper.readContentFromRepository(contentPath, language); - request.setAttribute("contentObject", ormArticle); request.setAttribute("path", ormArticle.getPath()); request.setAttribute("language", ormArticle.getLanguage()); @@ -221,33 +216,20 @@ public class JackrabbitEvents { } } - 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")); + JcrFileHelper fileHelper = new JcrFileHelper(userLogin); - RepositoryAccess repositoryAcces = new RepositoryAccessJackrabbit(userLogin); try { - repositoryAcces.storeContentObject(ormFolder); + + fileHelper.storeContentInRepository(file, passedParams.get("completeFileName"), passedParams.get("path")); + } catch (ObjectContentManagerException e) { Debug.logError(e, module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); } catch (ItemExistsException e) { Debug.logError(e, module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); + } finally { + fileHelper.closeContentSession(); } return "success"; @@ -304,17 +286,17 @@ public class JackrabbitEvents { public static String getFileFromRepository(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - String node = request.getParameter("path"); + String contentPath = request.getParameter("path"); - if (UtilValidate.isEmpty(node)) { + if (UtilValidate.isEmpty(contentPath)) { String msg = "A node path is missing, please pass the path to the node which should be read from the repository."; // TODO Debug.logError(msg, module); request.setAttribute("_ERROR_MESSAGE_", msg); return "error"; } - RepositoryAccess repositoryAccess = new RepositoryAccessJackrabbit(userLogin); - OfbizRepositoryMappingJackrabbitFile file = (OfbizRepositoryMappingJackrabbitFile) repositoryAccess.getContentObject(node); + JcrFileHelper fileHelper = new JcrFileHelper(userLogin); + OfbizRepositoryMappingJackrabbitFile file = fileHelper.getRepositoryContent(contentPath); InputStream fileStream = file.getResource().getData(); @@ -334,21 +316,4 @@ public class JackrabbitEvents { return "success"; } - public static String getFileInformation(HttpServletRequest request, HttpServletResponse resposne) { - - 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 Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java?rev=1176796&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java (added) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java Wed Sep 28 09:26:28 2011 @@ -0,0 +1,17 @@ +package org.ofbiz.content.jcr.helper; + +import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; + +public abstract class AbstractJcrHelper { + + protected static RepositoryAccessJackrabbit access = null; + + /** + * This will close the connection to the content repository and make sure + * that all changes a stored successfully. + */ + public void closeContentSession() { + access.closeAccess(); + access = null; + } +} Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/AbstractJcrHelper.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java?rev=1176796&r1=1176795&r2=1176796&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrArticleHelper.java Wed Sep 28 09:26:28 2011 @@ -33,11 +33,10 @@ import org.ofbiz.jcr.orm.jackrabbit.Ofbi * in the Framework. * */ -public class JcrArticleHelper { +public class JcrArticleHelper extends AbstractJcrHelper { private final static String module = JcrArticleHelper.class.getName(); - private static RepositoryAccessJackrabbit access = null; private static OfbizRepositoryMappingJackrabbitArticle article = null; private static List<String> possibleLocales = null; @@ -60,22 +59,14 @@ public class JcrArticleHelper { } /** - * This will close the connection to the content repository and make sure - * that all changes a stored successfully. - */ - public void closeContentSession() { - access.closeAccess(); - access = null; - } - - /** * Read the article content object from the repository. Throws an Exception * when the read content type is not an article content type. * * @param contentPath * @return content article object + * @throws */ - public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath) { + public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException{ OfbizRepositoryMapping orm = access.getContentObject(contentPath); if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) { @@ -95,8 +86,9 @@ public class JcrArticleHelper { * * @param contentPath * @return content article object + * @throws */ - public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language) { + public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException{ contentPath = determineContentLanguagePath(contentPath, language); return readContentFromRepository(contentPath); } @@ -111,8 +103,9 @@ public class JcrArticleHelper { * @param language * @param version * @return + * @throws */ - public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language, String version) { + public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException{ contentPath = determineContentLanguagePath(contentPath, language); OfbizRepositoryMapping orm = access.getContentObject(contentPath, version); Added: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java?rev=1176796&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java (added) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java Wed Sep 28 09:26:28 2011 @@ -0,0 +1,125 @@ +package org.ofbiz.content.jcr.helper; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.GregorianCalendar; + +import javax.jcr.ItemExistsException; + +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.entity.GenericValue; +import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.orm.OfbizRepositoryMapping; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitResource; + +/** + * This Helper class encapsulate the jcr file content bean. it provide all + * attributes and operations which are necessary to work with the content + * repository. + * + * The concrete implementations covers the different content use case related + * workflows. I.E. Different behavior for File/Folder or Text content. + * + * The Helper classes should be build on top of the generic JCR implementation + * in the Framework. + * + */ +public class JcrFileHelper extends AbstractJcrHelper { + + private final static String module = JcrFileHelper.class.getName(); + + public JcrFileHelper(GenericValue userLogin) { + access = new RepositoryAccessJackrabbit(userLogin); + } + + /** + * Returns a content file object from the repository. Throws an Exception + * when the read content type is not an article content type. + * + * @param contentPath + * @return + * @throws + */ + public OfbizRepositoryMappingJackrabbitFile getRepositoryContent(String contentPath) throws ClassCastException { + OfbizRepositoryMapping orm = access.getContentObject(contentPath); + + if (orm instanceof OfbizRepositoryMappingJackrabbitFile) { + OfbizRepositoryMappingJackrabbitFile fileObj = (OfbizRepositoryMappingJackrabbitFile) orm; + return fileObj; + } + + throw new ClassCastException("The content object for the path: " + contentPath + " is not a file content object. This Helper can only handle content objects with the type: " + OfbizRepositoryMappingJackrabbitFile.class.getName()); + } + + /** + * Returns a content file object in the passed version from the repository. + * Throws an Exception when the read content type is not an article content + * type. + * + * @param contentPath + * @return + * @throws + */ + public OfbizRepositoryMappingJackrabbitFile getRepositoryContent(String contentPath, String version) throws ClassCastException { + OfbizRepositoryMapping orm = access.getContentObject(contentPath, version); + + if (orm instanceof OfbizRepositoryMappingJackrabbitFile) { + OfbizRepositoryMappingJackrabbitFile fileObj = (OfbizRepositoryMappingJackrabbitFile) orm; + return fileObj; + } + + throw new ClassCastException("The content object for the path: " + contentPath + " is not a file content object. This Helper can only handle content objects with the type: " + OfbizRepositoryMappingJackrabbitFile.class.getName()); + } + + /** + * Stores a new file content object in the repository. + * + * @param fileData + * @param fileName + * @param folderPath + * @param mimeType + * @throws ObjectContentManagerException + * @throws ItemExistsException + */ + public void storeContentInRepository(byte[] fileData, String fileName, String folderPath) throws ObjectContentManagerException, ItemExistsException { + + // create an ORM Resource Object + OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); + ormResource.setData(new ByteArrayInputStream(fileData)); + ormResource.setMimeType(getMimeTypeFromInputStream(new ByteArrayInputStream(fileData))); + ormResource.setLastModified(new GregorianCalendar()); + + // create an ORM File Object + OfbizRepositoryMappingJackrabbitFile ormFile = new OfbizRepositoryMappingJackrabbitFile(); + ormFile.setCreationDate(new GregorianCalendar()); + ormFile.setResource(ormResource); + ormFile.setPath(fileName); + + // create the ORM folder Object + OfbizRepositoryMappingJackrabbitFolder ormFolder = new OfbizRepositoryMappingJackrabbitFolder(); + ormFolder.addChild(ormFile); + ormFolder.setPath(folderPath); + + access.storeContentObject(ormFolder); + } + + 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"; + } + } + +} Propchange: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/helper/JcrFileHelper.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java?rev=1176796&r1=1176795&r2=1176796&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/orm/jackrabbit/OfbizRepositoryMappingJackrabbitNews.java Wed Sep 28 09:26:28 2011 @@ -8,9 +8,12 @@ import org.apache.jackrabbit.ocm.mapper. @Node(extend = OfbizRepositoryMappingJackrabbitLocalizedContent.class) public class OfbizRepositoryMappingJackrabbitNews extends OfbizRepositoryMappingJackrabbitLocalizedContent { - @Field(id = true) String title = null; - @Field(jcrType = "Date") Calendar pubDate = null; - @Field String content = null; + @Field(id = true) + String title = null; + @Field(jcrType = "Date") + Calendar pubDate = null; + @Field + String content = null; public OfbizRepositoryMappingJackrabbitNews() { super(); |
Free forum by Nabble | Edit this page |