|
From: <jbo...@li...> - 2006-06-11 02:35:28
|
Author: conkan Date: 2006-06-10 22:35:09 -0400 (Sat, 10 Jun 2006) New Revision: 4722 Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/file.gif labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_image.jpg labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_thumbnail.jpg labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/upload.gif labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/CMSHelper.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/DataHelper.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/ErrorHelper.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/HarvestHelper.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/fileUpload.jsp Removed: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/DataHelper.java Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/.classpath labs/portletswap/imagegalleryportlet/trunk/ig_2.2/portal-imagegallery.ear labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/Thumbs.db labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/Const.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryModule.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryPortlet.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/impl/ImageGalleryModuleImpl.java labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/classes/Resource.properties labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/classes/Resource_en.properties labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/collectionAdd.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/collectionEdit.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/detailAdd.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/detailEdit.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/detailView.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/details.jsp labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/resources/portal-imagegallery-war/WEB-INF/jsp/imagedetail.jsp Log: Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/.classpath =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/.classpath 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/.classpath 2006-06-11 02:35:09 UTC (rev 4722) @@ -20,5 +20,6 @@ <classpathentry exported="true" kind="lib" path="/portal-thirdparty/jakarta-lucene/lib/lucene.jar"/> <classpathentry exported="true" kind="lib" path="/portal-thirdparty/oswego-concurrent/lib/concurrent.jar"/> <classpathentry exported="true" kind="lib" path="/portal-thirdparty/jboss-hibernate/lib/jboss-hibernate.jar"/> + <classpathentry kind="con" path="org.jboss.ide.eclipse.jdt.core.classpath.j2ee-1.4"/> <classpathentry kind="output" path="output"/> </classpath> Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/portal-imagegallery.ear =================================================================== (Binary files differ) Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/Thumbs.db =================================================================== (Binary files differ) Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/file.gif =================================================================== (Binary files differ) Property changes on: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/file.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_image.jpg =================================================================== (Binary files differ) Property changes on: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_image.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_thumbnail.jpg =================================================================== (Binary files differ) Property changes on: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/no_picture_thumbnail.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/upload.gif =================================================================== (Binary files differ) Property changes on: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/bin/portal-imagegallery-war/images/upload.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/Const.java =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/Const.java 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/Const.java 2006-06-11 02:35:09 UTC (rev 4722) @@ -1,3 +1,11 @@ +/***************************************** + * * + * The Image Gallery Portlet * + * * + * Distributable under LGPL license. * + * See terms of license at gnu.org. * + * * + *****************************************/ package org.jboss.portlet.imagegallery; @@ -2,4 +10,3 @@ /** - * This is a file of constants that are used for the image gallery - * portlet. These are parameters that will be passed within the portlet. + * These are constants that are used for the image gallery portlet. * @@ -14,6 +21,7 @@ public static final String OP = "op"; public static final String OP_ADD = "add"; public static final String OP_EDIT = "edit"; + public static final String OP_UPLOAD = "upload"; public static final String OP_DELETE = "delete"; public static final String OP_CANCEL = "cancel"; public static final String OP_VIEW = "view"; @@ -21,6 +29,8 @@ public static final String OP_REDIRECT = "redirect"; public static final String OP_CMS_ACTION = "cmsAction"; public static final String OP_BROWSE_CMS = "browseCMSSystem"; + public static final String OP_LOCAL_UPLOAD = "localFileSystem"; + public static final String OP_HARVEST = "harvest"; // Operations for image collection public static final String OP_COLLECTIONVIEW = "collectionView"; @@ -49,12 +59,14 @@ public static final String ACTION_DELETEDETAIL = "deleteDetail"; public static final String ACTION_ADDDETAIL = "addDetail"; - // Action for returning to a file + // Actions for returning a CMS file public static final String ACTION_CAPTURE_CMS = "captureCMS"; + public static final String ACTION_GET_LOCAL = "getLocalFile"; // Special operations public static final String OP_CMS_VIEW = "viewCMS"; - + public static final String OP_LOCAL_TO_CMS = "uploadFromLocalToCMS"; + // Image width constants public static final Integer THUMBNAIL_WIDTH = new Integer(100); public static final Integer IMAGE_WIDTH = new Integer(500); @@ -74,7 +86,7 @@ public static final String SHOW_THUMBNAIL = "showThumbnail"; public static final String SHOW_IMAGE = "showImage"; public static final String PHOTOGRAPHER = "photographer"; - public static final String REDIRECT = "redirectToLocation"; + public static final String RETURN_LOCATION = "returnLocation"; // Constants for browsing individual images public static final String ID_INDEX = "IDindex"; @@ -84,7 +96,8 @@ // Constants for browsing the CMS File System public static final String CMS_THUMBNAIL = "thumbnails"; - public static final String CMS_IMAGE = "images"; + public static final String CMS_IMAGE = "images"; + public static final String CMS_FILE = "cmsFile"; public static final String CMS_FOLDER = "cmsFolder"; public static final String CMS_ACTION = "cmsAction"; public static final String CMS_FILE_NAME = "cmsFileName"; @@ -92,6 +105,9 @@ public static final String CMS_FILE_LAST_MODIFIED = "cmsFileLastModified"; public static final String CMS_FILE_CREATION_DATE = "cmsFileCreationDate"; + // Local file + public static final String LOCAL_FILE = "localFile"; + // Change this when the CMS Root Path changes in the JBoss Portal. public static final String CMS_ROOT = "/portal/content"; Deleted: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/DataHelper.java =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/DataHelper.java 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/DataHelper.java 2006-06-11 02:35:09 UTC (rev 4722) @@ -1,337 +0,0 @@ - -package org.jboss.portlet.imagegallery; - -import org.jboss.portal.common.context.DelegateContext; -import org.jboss.portlet.imagegallery.model.*; -import org.jboss.portlet.imagegallery.ImageGalleryPortlet; -import org.jboss.portlet.JBossActionRequest; -import org.jboss.portlet.JBossPortlet; -import org.jboss.portlet.JBossRenderRequest; - -import org.jboss.portal.cms.model.Folder; -import org.jboss.portal.cms.impl.FolderImpl; -import org.jboss.portal.cms.model.File; -import org.jboss.portal.cms.impl.FileImpl; -import org.jboss.portal.cms.util.FileUtil; - -/** - * @author <a href="im...@ho...">Ron & Conrad Kanengieter</a> - * $Revision: 1.5.6.1 $ - */ -public class DataHelper -{ - public DataHelper() - { - } - - /** - * Load the ctx with key-values from the imagecollection. - * @param imageCollection is the imagecollection object. - * @param ctx is the ctx object to be loaded. - */ - public void getCtxCollection(ImageCollection imageCollection, DelegateContext ctx) - { - ctx.put(Const.COLLECTION_ID, imageCollection.getID()); - ctx.put(Const.NAME, imageCollection.getName()); - ctx.put(Const.DESCRIPTION, imageCollection.getDescription()); - ctx.put(Const.BASE_PATH, imageCollection.getBasePath()); - ctx.put(Const.THUMBNAIL_PATH, imageCollection.getThumbnailPath()); - String sThumbnail = FileUtil.cleanDoubleSlashes(imageCollection.getBasePath() - + "/" + imageCollection.getThumbnailPath()); - ctx.put(Const.SHOW_THUMBNAIL, sThumbnail); - - if (imageCollection.getFeaturedFlag().booleanValue() == true) - { - ctx.put(Const.FEATURED_FLAG, "True"); - ctx.put(Const.FEATURED_CHECKED, "checked"); - } - else - { - ctx.put(Const.FEATURED_FLAG, "False"); - ctx.put(Const.FEATURED_CHECKED, ""); - } - } - - - /** - * Load the ctx with key-values from the imagecollection and imagedetail. - * @param imageCollection is the imagecollection object. - * @param imageDetail is the imagedetail object. - * @param ctx is the ctx object to be loaded. - */ - public void getCtxDetail(ImageCollection imageCollection, - ImageDetail imageDetail, - DelegateContext ctx) - { - ctx.put(Const.COLLECTION_ID, imageCollection.getID()); - ctx.put(Const.DETAIL_ID, imageDetail.getID()); - ctx.put(Const.NAME, imageDetail.getName()); - ctx.put(Const.DESCRIPTION, imageDetail.getDescription()); - ctx.put(Const.THUMBNAIL_PATH, imageDetail.getThumbnailPath()); - String sThumbnail = FileUtil.cleanDoubleSlashes(imageCollection.getBasePath() - + "/" + imageDetail.getThumbnailPath()); - ctx.put(Const.SHOW_THUMBNAIL, sThumbnail); - String sImage = FileUtil.cleanDoubleSlashes(imageCollection.getBasePath() - + "/" + imageDetail.getImagePath()); - ctx.put(Const.SHOW_IMAGE, sImage); - ctx.put(Const.IMAGE_PATH, imageDetail.getImagePath()); - ctx.put(Const.PHOTOGRAPHER, imageDetail.getPhotographer()); - } - - - /** - * Load the ctx with blank key-values for forms. - * @param ctx is the ctx object to be loaded. - */ - public void getFormCtxInit(DelegateContext ctx) - { - String imageGalleryRoot = FileUtil.cleanDoubleSlashes(Const.CMS_ROOT + "/gallery"); - ctx.put(Const.MSG, ""); - ctx.put(Const.DETAIL_ID, ""); - ctx.put(Const.COLLECTION_ID, ""); - ctx.put(Const.NAME, ""); - ctx.put(Const.DESCRIPTION, ""); - ctx.put(Const.FEATURED_FLAG, ""); - ctx.put(Const.BASE_PATH, imageGalleryRoot); - ctx.put(Const.THUMBNAIL_PATH, ""); - ctx.put(Const.IMAGE_PATH, ""); - ctx.put(Const.SHOW_THUMBNAIL, ""); - ctx.put(Const.SHOW_IMAGE, ""); - ctx.put(Const.PHOTOGRAPHER, ""); - ctx.put(Const.REDIRECT, ""); - ctx.put(Const.OP_SUB, ""); - - } - - - /** - * Load the ctx with key-values from the collection form. - * @param req is the object containing the collection form parameters. - * @param ctx is the ctx object to be loaded. - */ - public void getFormCtxCollection(JBossActionRequest req, DelegateContext ctx) - { - Integer id = req.getParameters().getIntObject(Const.COLLECTION_ID); - String name = req.getParameter(Const.NAME); - String description = req.getParameter(Const.DESCRIPTION); - String basePath = req.getParameter(Const.BASE_PATH); - String thumbnailPath = req.getParameter(Const.THUMBNAIL_PATH); - String featuredFlag = req.getParameter(Const.FEATURED_FLAG); - String opSub = req.getParameter(Const.OP_SUB); - String opRedirect = req.getParameter(Const.OP_REDIRECT); - String opCmsAction = req.getParameter(Const.OP_CMS_ACTION); - String checkPath = null; - - if (name != null) - ctx.put(Const.NAME, name); - else - ctx.put(Const.NAME, ""); - - if (description != null) - ctx.put(Const.DESCRIPTION, description); - else - ctx.put(Const.DESCRIPTION, ""); - - if (basePath != null) - { - // Trim off the CMS root path if present for CMS path. - if (basePath.startsWith(Const.CMS_ROOT)) - { - checkPath = basePath.substring(Const.CMS_ROOT.length()); - } - else - { - checkPath = FileUtil.cleanDoubleSlashes("/" + basePath); - basePath = FileUtil.cleanDoubleSlashes(Const.CMS_ROOT + "/" + basePath); - } - checkPath = FileUtil.cleanDoubleSlashes(checkPath + "/"); - - // Remove ending slash from base path if present. - if (basePath.endsWith("/")) - { - basePath = basePath.substring(0, basePath.length() - 1); - } - ctx.put(Const.BASE_PATH, basePath); - ctx.put(Const.CMS_FOLDER, checkPath); - } - else - { - ctx.put(Const.BASE_PATH, ""); - ctx.put(Const.CMS_FOLDER, ""); - } - - if (thumbnailPath != null) - ctx.put(Const.THUMBNAIL_PATH, thumbnailPath); - else - ctx.put(Const.THUMBNAIL_PATH, ""); - - ctx.put(Const.FEATURED_CHECKED, ""); - if (featuredFlag != null) - { - ctx.put(Const.FEATURED_FLAG, featuredFlag); - if (featuredFlag.equals("true")) - ctx.put(Const.FEATURED_CHECKED, "checked"); - } - else - ctx.put(Const.FEATURED_FLAG, ""); - - if (opSub != null) - ctx.put(Const.OP_SUB, opSub); - else - ctx.put(Const.OP_SUB, ""); - - if (opRedirect != null) - ctx.put(Const.OP_REDIRECT, opRedirect); - else - ctx.put(Const.OP_REDIRECT, ""); - - if (opCmsAction != null) - ctx.put(Const.OP_CMS_ACTION, opCmsAction); - else - ctx.put(Const.OP_CMS_ACTION, ""); - - if (id != null) - ctx.put(Const.COLLECTION_ID, id.toString()); - } - - - /** - * Load the ctx with key-values from the detail form. - * @param imageCollection is the imagecollection object containing the image base path. - * @param req is the object containing the detail form parameters. - * @param ctx is the ctx object to be loaded. - */ - public void getFormCtxDetail(ImageCollection imageCollection, JBossActionRequest req, DelegateContext ctx) - { - Integer collectionID = req.getParameters().getIntObject(Const.COLLECTION_ID); - Integer detailID = req.getParameters().getIntObject(Const.DETAIL_ID); - String name = req.getParameter(Const.NAME); - String description = req.getParameter(Const.DESCRIPTION); - String thumbnailPath = req.getParameter(Const.THUMBNAIL_PATH); - String imagePath = req.getParameter(Const.IMAGE_PATH); - String photographer = req.getParameter(Const.PHOTOGRAPHER); - String opSub = req.getParameter(Const.OP_SUB); - String redirect = req.getParameter(Const.REDIRECT); - String opCmsAction = req.getParameter(Const.OP_CMS_ACTION); - String opRedirect = req.getParameter(Const.OP_REDIRECT); - String basePath = imageCollection.getBasePath(); - String checkPath = basePath.substring(Const.CMS_ROOT.length()); - ctx.put(Const.CMS_FOLDER, checkPath); - - if (name != null) - ctx.put(Const.NAME, name); - else - ctx.put(Const.NAME, ""); - - if (description != null) - ctx.put(Const.DESCRIPTION, description); - else - ctx.put(Const.DESCRIPTION, ""); - - if (thumbnailPath != null) - ctx.put(Const.THUMBNAIL_PATH, thumbnailPath); - else - ctx.put(Const.THUMBNAIL_PATH, ""); - - if (imagePath != null) - ctx.put(Const.IMAGE_PATH, imagePath); - else - ctx.put(Const.IMAGE_PATH, ""); - - if (photographer != null) - ctx.put(Const.PHOTOGRAPHER, photographer); - else - ctx.put(Const.PHOTOGRAPHER, ""); - - if (opSub != null) - ctx.put(Const.OP_SUB, opSub); - else - ctx.put(Const.OP_SUB, ""); - - if (redirect != null) - ctx.put(Const.REDIRECT, redirect); - else - ctx.put(Const.REDIRECT, ""); - - ctx.put(Const.COLLECTION_ID, collectionID.toString()); - - if (detailID != null) - ctx.put(Const.DETAIL_ID, detailID.toString()); - - if (opCmsAction != null) - ctx.put(Const.OP_CMS_ACTION, opCmsAction); - else - ctx.put(Const.OP_CMS_ACTION, ""); - - if (opRedirect != null) - ctx.put(Const.OP_REDIRECT, opRedirect); - else - ctx.put(Const.OP_REDIRECT, ""); - - } - - - /** - * Load the ctx with key-values from the CMS view form. - * @param imageCollection is the imagecollection object containing the image base path. - * @param req is the object containing the CMS view form parameters. - * @param ctx is the ctx object to be loaded. - */ - public void getFormCtxCaptureCMS (ImageCollection imageCollection, JBossActionRequest req, DelegateContext ctx) - { - String submit = req.getParameter(Const.OP_SUB); - String sPath = null; - - // Image Collection Add does not have a imagecollection object so use the base path. - if (imageCollection != null) - { - sPath = FileUtil.cleanDoubleSlashes(imageCollection.getBasePath() - + "/" + ctx.get(Const.THUMBNAIL_PATH)); - } - - ctx.put(Const.SHOW_THUMBNAIL, sPath); - - if (submit.equals(Const.OP_CANCEL)) - { - req.getPortletSession().setAttribute(Const.CTX, ctx); - return; - } - - String cleanedPath = submit.substring(ctx.get(Const.CMS_FOLDER).length()); - - if (ctx.get(Const.OP_CMS_ACTION).equals(Const.CMS_THUMBNAIL)) - { - String sThumbnail = null; - ctx.put(Const.THUMBNAIL_PATH, cleanedPath); - - // Image Collection Add does not have a imagecollection object so use the base path. - if (imageCollection != null) - { - sThumbnail = FileUtil.cleanDoubleSlashes(imageCollection.getBasePath() - + "/" + cleanedPath); - } - - ctx.put(Const.SHOW_THUMBNAIL, sThumbnail); - } - else - if (ctx.get(Const.OP_CMS_ACTION).equals(Const.CMS_IMAGE)) - ctx.put(Const.IMAGE_PATH, cleanedPath); - - } - - - /** - * Load the ctx with key-values from the CMS file object. - * @param file is the object containing the CMS file information. - * @param ctx is the ctx object to be loaded. - */ - public void getCtxFile(File file, DelegateContext ctx) - { - String fileName = file.getBasePath().substring(file.getBasePath(). - lastIndexOf("/") + 1, file.getBasePath().length()); - ctx.put(Const.CMS_FILE_NAME, fileName); - ctx.put(Const.CMS_FILE_PATH, file.getBasePath()); - ctx.put(Const.CMS_FILE_LAST_MODIFIED, file.getLastModified().toString()); - ctx.put(Const.CMS_FILE_CREATION_DATE, file.getCreationDate().toString()); - } -} Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryModule.java =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryModule.java 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryModule.java 2006-06-11 02:35:09 UTC (rev 4722) @@ -103,4 +103,17 @@ ImageDetail createImageDetail(ImageCollection imagecollection, DelegateContext ctx) throws ModuleException; + /** + * Create the image detail from harvest information. + * @param imagecollection is the image collection parent. + * @param name is the image detail record name. + * @param thumbnailPath is the image detail record thumbnail path. + * @param imagePath is the image detail record image path. + * @return the image detail that is created from this method. + */ + ImageDetail harvestCreateImageDetail(ImageCollection imagecollection, + String name, + String thumbnailPath, + String imagePath) + throws ModuleException; } \ No newline at end of file Modified: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryPortlet.java =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryPortlet.java 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/ImageGalleryPortlet.java 2006-06-11 02:35:09 UTC (rev 4722) @@ -11,6 +11,7 @@ import org.jboss.logging.Logger; import org.jboss.portal.common.context.DelegateContext; import org.jboss.portlet.imagegallery.model.*; +import org.jboss.portlet.imagegallery.helper.*; import org.jboss.portlet.imagegallery.impl.ImageGalleryModuleImpl; import org.jboss.portal.core.modules.ModuleException; import org.jboss.portal.core.servlet.jsp.PortalJsp; @@ -21,6 +22,10 @@ import org.jboss.portlet.JBossRenderRequest; import org.jboss.portlet.JBossRenderResponse; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.portlet.PortletFileUpload; + import org.jboss.portal.cms.model.Content; import org.jboss.portal.cms.impl.ContentImpl; import org.jboss.portal.cms.CMS; @@ -44,6 +49,7 @@ import javax.portlet.WindowState; import javax.portlet.WindowStateException; import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; import java.util.Date; import java.util.Iterator; @@ -55,7 +61,9 @@ /** * This portlet provides an imagegallery on the web using the JBoss portal CMS. - * + * This contains methods to capture local files and CMS files as well as methods + * for modifying and viewing content. + * * @author <a href="mailto:im...@ho...">Ron & Conrad Kanengieter</a> * @version $Revision: 2.0 $ */ @@ -72,8 +80,11 @@ // private helper and service classes private ImageGalleryModule imagegalleryModule; + private CMSHelper fileHelper; private CMS CMSService; private DataHelper dataHelper = new DataHelper(); + private ErrorHelper errorHelper = new ErrorHelper(); + private HarvestHelper harvestHelper = new HarvestHelper(); public void init() throws PortletException @@ -95,6 +106,10 @@ { throw new PortletException("Cannot start CMS service due to unavailability"); } + else + { + fileHelper = new CMSHelper(CMSService); + } } @@ -149,6 +164,7 @@ // Collections if(Const.OP_COLLECTIONS.equals(op)) { + try { List imagecollections = imagegalleryModule.findImageCollections(); @@ -159,7 +175,7 @@ ImageCollection imagecollection = (ImageCollection) i.next(); rowCtx = ctx.next("imagecollections"); - dataHelper.getCtxCollection(imagecollection, rowCtx); + dataHelper.getCtxCollection(req, imagecollection, rowCtx); } req.setAttribute(PortalJsp.CTX_REQUEST, ctx); } @@ -177,11 +193,11 @@ { try { - Integer id = req.getParameters().getIntObject(Const.COLLECTION_ID); // Get the collection ID so one could see the + Integer id = req.getParameters().getIntObject(Const.COLLECTION_ID); - ImageCollection imageCollection = imagegalleryModule.findImageCollectionByID(id); // collection ID. - List imagedetails = imagegalleryModule.findDetailsByCollectionID(id); // Get a list of images in the directory - LinkedList idList = new LinkedList(); // New list for collection IDs to get. + ImageCollection imageCollection = imagegalleryModule.findImageCollectionByID(id); + List imagedetails = imagegalleryModule.findDetailsByCollectionID(id); + LinkedList idList = new LinkedList(); DelegateContext rowCtx = null; ctx.put(Const.COLLECTION_ID, (id.toString())); @@ -191,7 +207,7 @@ { ImageDetail imageDetail = (ImageDetail) i.next(); rowCtx = ctx.next("imagedetails"); - dataHelper.getCtxDetail(imageCollection, imageDetail, rowCtx); + dataHelper.getCtxDetail(req, imageCollection, imageDetail, rowCtx); idList.addLast(imageDetail.getID()); } req.getPortletSession().setAttribute("idList", idList); @@ -213,10 +229,9 @@ { Integer collectionID = req.getParameters().getIntObject(Const.COLLECTION_ID); Integer detailID = req.getParameters().getIntObject(Const.DETAIL_ID); - LinkedList idList = (LinkedList)req.getPortletSession().getAttribute("idList"); // List of IDs in a - // collection. - ListIterator iterateIdList = null; // Used to iterate the list of IDs in the - // details of a collection. + LinkedList idList = (LinkedList)req.getPortletSession().getAttribute("idList"); + ListIterator iterateIdList = null; + if (idList != null) { iterateIdList = idList.listIterator(); @@ -226,8 +241,8 @@ throw new PortletException("The ID list cannot be null"); } - int imageCount = 0; // The total count of images for the iterator. - int saveCount = 0; // The current count of images. + int imageCount = 0; + int saveCount = 0; Integer currentID = new Integer(0); Integer nextID = new Integer(0); @@ -259,7 +274,7 @@ ImageDetail imageDetail = imagegalleryModule.findImageDetailByID(detailID); ImageCollection imageCollection = imagegalleryModule.findImageCollectionByID(collectionID); - dataHelper.getCtxDetail(imageCollection, imageDetail, ctx); + dataHelper.getCtxDetail(req, imageCollection, imageDetail, ctx); if (previousID.intValue() > 0) { @@ -323,7 +338,7 @@ try { imagecollection = imagegalleryModule.findImageCollectionByID(id); - dataHelper.getCtxCollection(imagecollection, ctx); + dataHelper.getCtxCollection(req, imagecollection, ctx); } catch(ModuleException e) { @@ -384,7 +399,7 @@ Integer collectionID = req.getParameters().getIntObject(Const.COLLECTION_ID); Integer detailID = req.getParameters().getIntObject(Const.DETAIL_ID); - String redirect = req.getParameter(Const.REDIRECT); + String redirect = req.getParameter(Const.RETURN_LOCATION); ImageCollection imageCollection = null; ImageDetail imageDetail = null; @@ -401,8 +416,8 @@ imageCollection = imagegalleryModule.findImageCollectionByID(collectionID); imageDetail = imagegalleryModule.findImageDetailByID(detailID); - ctx.put(Const.REDIRECT, redirect); - dataHelper.getCtxDetail(imageCollection, imageDetail, ctx); + ctx.put(Const.RETURN_LOCATION, redirect); + dataHelper.getCtxDetail(req, imageCollection, imageDetail, ctx); } catch(ModuleException e) { @@ -437,8 +452,8 @@ DelegateContext rowCtx = null; - Folder mainFolder; // main folder of the content management system. - List files; // list of files in the content management system. + Folder mainFolder; + List files; String fullPath = FileUtil.cleanDoubleSlashes(jspCtx.get(Const.CMS_FOLDER) + "/" + jspCtx.get(Const.OP_CMS_ACTION)); @@ -467,7 +482,16 @@ PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/browseCMS.jsp"); rd.include(req, resp); } - + + // UPLOAD from local to CMS system + else if (Const.OP_LOCAL_TO_CMS.equals(op)) + { + req.setAttribute(PortalJsp.CTX_REQUEST, ctx); + + PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/fileUpload.jsp"); + rd.include(req, resp); + } + // Error else log.error("This operation does not exist: " + op); @@ -475,12 +499,75 @@ writer.close(); } + /* + * Action to get a local file with an image on a multipart form + * and upload it to the CMS + * + * @param req contains the parameters from the form + * @param resp contains the parameters needed to move to a new form + */ + public void getLocalFile(JBossActionRequest req, JBossActionResponse resp) + { + String submit = ""; + // Path from local file system + String localPath = ""; + DelegateContext ctx = (DelegateContext) req.getPortletSession().getAttribute(Const.CTX); + Locale locale = req.getLocale(); + List fileItems = new LinkedList(); + Iterator itr = fileItems.iterator(); + try + { + if (req.isUserInRole("Admin")) + { + + DiskFileItemFactory factory = new DiskFileItemFactory(); + PortletFileUpload upload = new PortletFileUpload(factory); + if (upload.isMultipartContent(req)) + { + fileItems = upload.parseRequest(req); + itr = fileItems.iterator(); + } + + while(itr.hasNext()) + { + FileItem item = (FileItem) itr.next(); + // check if the current item is a form field or an uploaded file + + + if(!item.isFormField()) + { + InputStream is = item.getInputStream(); + localPath = item.getName(); + + if(submit.equals(Const.OP_UPLOAD) && localPath != null && !localPath.equals("")) + { + fileHelper.cleanPath(localPath, ctx); + fileHelper.uploadToCMS(ctx, locale, item.get()); + } + } + else + { + String fieldName = item.getFieldName(); + if(Const.OP_SUB.equals(fieldName)) + { + submit = item.getString(); + } + } + } + } + resp.setRenderParameter(Const.OP, ctx.get(Const.OP_REDIRECT)); + } + catch(Exception e) + { + e.printStackTrace(); + } + } /** * Action to capture the image file selected from the CMS view * * @param req is the request of the action form that holds parameters - * @param resp is the response for the next action form + * @param resp contains the parameters needed to move to a new form */ public void captureCMS(JBossActionRequest req, JBossActionResponse resp) { @@ -505,7 +592,7 @@ dataHelper.getFormCtxCaptureCMS(imageCollection, req, ctx); resp.setRenderParameter(Const.OP, ctx.get(Const.OP_REDIRECT)); - } + } /** @@ -518,58 +605,44 @@ { DelegateContext formCtx = new DelegateContext(); dataHelper.getFormCtxCollection(req, formCtx); - // The path should have thumbnails or images. - String folderPath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.OP_CMS_ACTION)); - // Check also to see the user's file - String filePath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.THUMBNAIL_PATH)); - Command folderExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(folderPath); - Command fileExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(filePath); - Boolean folderExists = (Boolean) CMSService.execute(folderExistsCMD); - Boolean fileExists = (Boolean) CMSService.execute(fileExistsCMD); - - if(!formCtx.get(Const.OP_SUB).equals(Const.OP_CANCEL)) + + if(formCtx.get(Const.OP_SUB).equals(Const.OP_CANCEL)) { - if(!folderExists.booleanValue()) - { - formCtx.put(Const.MSG, "'" + formCtx.get(Const.OP_CMS_ACTION) + "' does not exist under '" + formCtx.get(Const.BASE_PATH) + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONADD); - return; - } + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); + req.getPortletSession().removeAttribute(Const.CTX); } - - if(formCtx.get(Const.OP_SUB).equals(Const.OP_ADD)) + else + if (errorHelper.collectionErrors(req, formCtx, fileHelper)) { - if(!fileExists.booleanValue()) - { - formCtx.put(Const.MSG, "'" + formCtx.get(Const.THUMBNAIL_PATH) + "' does not exist under '" + formCtx.get(Const.BASE_PATH) + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONADD); - return; - } + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONADD); } - - if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS) && req.isUserInRole("Admin")) + else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS)) { req.getPortletSession().setAttribute(Const.CTX, formCtx); resp.setRenderParameter(Const.OP, Const.OP_CMS_VIEW); } else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_LOCAL_UPLOAD)) { - if(formCtx.get(Const.OP_SUB).equals(Const.OP_ADD) && req.isUserInRole("Admin")) - { - try - { - imagegalleryModule.createImageCollection(formCtx); - } - catch(ModuleException e) - { - e.printStackTrace(); - } - } - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); - req.getPortletSession().removeAttribute(Const.CTX); + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_LOCAL_TO_CMS); } + else + if(formCtx.get(Const.OP_SUB).equals(Const.OP_ADD)) + { + try + { + imagegalleryModule.createImageCollection(formCtx); + } + catch(ModuleException e) + { + e.printStackTrace(); + } + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); + req.getPortletSession().removeAttribute(Const.CTX); + } } @@ -586,75 +659,65 @@ DelegateContext formCtx = new DelegateContext(); dataHelper.getFormCtxCollection(req, formCtx); - - // The path should have thumbnails or images. - String folderPath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.OP_CMS_ACTION)); - // Check also to see the user's file - String filePath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.THUMBNAIL_PATH)); - Command folderExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(folderPath); - Command fileExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(filePath); - Boolean folderExists = (Boolean) CMSService.execute(folderExistsCMD); - Boolean fileExists = (Boolean) CMSService.execute(fileExistsCMD); - - boolean checked = false; // The featured flag needs to be set to - // "checked" if true. - if (formCtx.get(Const.FEATURED_FLAG).equals("true")) - checked = true; - Boolean featuredFlag = new Boolean(checked); - if(!formCtx.get(Const.OP_SUB).equals(Const.OP_CANCEL)) + if(formCtx.get(Const.OP_SUB).equals(Const.OP_CANCEL)) { - if(!folderExists.booleanValue()) - { - formCtx.put(Const.MSG, "'" + formCtx.get(Const.OP_CMS_ACTION) + "' does not exist under '" + formCtx.get(Const.BASE_PATH) + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONEDIT); - return; - } + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); + req.getPortletSession().removeAttribute(Const.CTX); } - - if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT)) + else + if (errorHelper.collectionErrors(req, formCtx, fileHelper)) { - - if(!fileExists.booleanValue()) - { - formCtx.put(Const.MSG, "'" + formCtx.get(Const.THUMBNAIL_PATH) + "' does not exist under '" + formCtx.get(Const.BASE_PATH) + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONEDIT); - return; - } + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONADD); } - - if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS) && req.isUserInRole("Admin")) + else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS)) { req.getPortletSession().setAttribute(Const.CTX, formCtx); resp.setRenderParameter(Const.OP, Const.OP_CMS_VIEW); } else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_HARVEST)) { - if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT) && req.isUserInRole("Admin")) - { - try - { - // If the collection ID is null, try getting from the context. - if (id == null) - id = Integer.decode(formCtx.get(Const.COLLECTION_ID)); - ImageCollection imagecollection = imagegalleryModule.findImageCollectionByID(id); + req.getPortletSession().setAttribute(Const.CTX, formCtx); + harvestHelper.harvest(fileHelper, req, imagegalleryModule, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONEDIT); + } + else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_LOCAL_UPLOAD)) + { + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_LOCAL_TO_CMS); + } + else + if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT)) + { + try + { + boolean checked = false; + if (formCtx.get(Const.FEATURED_FLAG).equals("true")) + checked = true; + Boolean featuredFlag = new Boolean(checked); - imagecollection.setName(formCtx.get(Const.NAME)); - imagecollection.setDescription(formCtx.get(Const.DESCRIPTION)); - imagecollection.setBasePath(formCtx.get(Const.BASE_PATH)); - imagecollection.setThumbnailPath(formCtx.get(Const.THUMBNAIL_PATH)); - imagecollection.setFeaturedFlag(featuredFlag); - } - catch(ModuleException e) - { - e.printStackTrace(); - } - } + // If the collection ID is null, browse CMS puts it in the context. + if (id == null) + id = Integer.decode(formCtx.get(Const.COLLECTION_ID)); + ImageCollection imagecollection = imagegalleryModule.findImageCollectionByID(id); - resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); - req.getPortletSession().removeAttribute(Const.CTX); + imagecollection.setName(formCtx.get(Const.NAME)); + imagecollection.setDescription(formCtx.get(Const.DESCRIPTION)); + imagecollection.setBasePath(formCtx.get(Const.BASE_PATH)); + imagecollection.setThumbnailPath(formCtx.get(Const.THUMBNAIL_PATH)); + imagecollection.setFeaturedFlag(featuredFlag); + } + catch(ModuleException e) + { + e.printStackTrace(); + } + + resp.setRenderParameter(Const.OP, Const.OP_COLLECTIONS); + req.getPortletSession().removeAttribute(Const.CTX); } } @@ -712,50 +775,40 @@ dataHelper.getFormCtxDetail(imageCollection, req, formCtx); - if(formCtx.get(Const.OP_SUB).equals(Const.OP_ADD)) + if(errorHelper.detailErrors(req, formCtx, fileHelper)) { - // Check also to see the user's files exist. - String thumbnailPath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.THUMBNAIL_PATH)); - String imagePath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.IMAGE_PATH)); - System.out.println(thumbnailPath); - System.out.println(imagePath); - Command thumbnailExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(thumbnailPath); - Command imageExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(imagePath); - Boolean thumbnailExists = (Boolean) CMSService.execute(thumbnailExistsCMD); - Boolean imageExists = (Boolean) CMSService.execute(imageExistsCMD); - if(!thumbnailExists.booleanValue() || !imageExists.booleanValue()) - { - formCtx.put(Const.MSG, "The thumbnail or image does not exist under '" + imageCollection.getBasePath() + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_DETAILADD); - return; - } + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_DETAILADD); } - + else if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS)) { req.getPortletSession().setAttribute(Const.CTX, formCtx); resp.setRenderParameter(Const.OP, Const.OP_CMS_VIEW); } else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_LOCAL_UPLOAD) && req.isUserInRole("Admin")) { + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_LOCAL_TO_CMS); + } + else + { if (formCtx.get(Const.OP_SUB).equals(Const.OP_ADD) && req.isUserInRole("Admin")) { try { - imagegalleryModule.createImageDetail(imageCollection, formCtx); - } + imagegalleryModule.createImageDetail(imageCollection, formCtx); + } catch (ModuleException e) { - e.printStackTrace(); + e.printStackTrace(); } } - resp.setRenderParameter(Const.OP, Const.OP_DETAILS); resp.setRenderParameter(Const.COLLECTION_ID, (id.toString())); req.getPortletSession().removeAttribute(Const.CTX); } - } @@ -784,59 +837,49 @@ dataHelper.getFormCtxDetail(imageCollection, req, formCtx); - if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT)) + if(errorHelper.detailErrors(req, formCtx, fileHelper)) { - // Check also to see the user's files exist. - String thumbnailPath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.THUMBNAIL_PATH)); - String imagePath = FileUtil.cleanDoubleSlashes(formCtx.get(Const.CMS_FOLDER) + formCtx.get(Const.IMAGE_PATH)); - System.out.println(thumbnailPath); - System.out.println(imagePath); - Command thumbnailExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(thumbnailPath); - Command imageExistsCMD = CMSService.getCommandFactory().createItemExistsCommand(imagePath); - Boolean thumbnailExists = (Boolean) CMSService.execute(thumbnailExistsCMD); - Boolean imageExists = (Boolean) CMSService.execute(imageExistsCMD); - System.out.println(thumbnailPath + " " + thumbnailExists.booleanValue()); - System.out.println(imagePath + " " + imageExists.booleanValue()); - if(!thumbnailExists.booleanValue() || !imageExists.booleanValue()) - { - formCtx.put(Const.MSG, " The thumbnail or the image does not exist under '" + imageCollection.getBasePath() + "'."); - req.getPortletSession().setAttribute(Const.CTX, formCtx); - resp.setRenderParameter(Const.OP, Const.OP_DETAILEDIT); - return; - } + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_DETAILEDIT); } - + else if (formCtx.get(Const.OP_SUB).equals(Const.OP_BROWSE_CMS) && req.isUserInRole("Admin")) { req.getPortletSession().setAttribute(Const.CTX, formCtx); resp.setRenderParameter(Const.OP, Const.OP_CMS_VIEW); } else + if (formCtx.get(Const.OP_SUB).equals(Const.OP_LOCAL_UPLOAD) && req.isUserInRole("Admin")) { - if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT) && req.isUserInRole("Admin")) - { - try - { - ImageDetail imagedetail = imagegalleryModule.findImageDetailByID(detailID); - - imagedetail.setName(formCtx.get(Const.NAME)); - imagedetail.setDescription(formCtx.get(Const.DESCRIPTION)); - imagedetail.setThumbnailPath(formCtx.get(Const.THUMBNAIL_PATH)); - imagedetail.setImagePath(formCtx.get(Const.IMAGE_PATH)); - imagedetail.setPhotographer(formCtx.get(Const.PHOTOGRAPHER)); - } - catch(ModuleException e) - { - e.printStackTrace(); - } - } - - resp.setRenderParameter(Const.OP, formCtx.get(Const.REDIRECT)); - resp.setRenderParameter(Const.COLLECTION_ID, (collectionID.toString())); - resp.setRenderParameter(Const.DETAIL_ID, (detailID.toString())); - req.getPortletSession().removeAttribute(Const.CTX); + req.getPortletSession().setAttribute(Const.CTX, formCtx); + resp.setRenderParameter(Const.OP, Const.OP_LOCAL_TO_CMS); } + else + { + if(formCtx.get(Const.OP_SUB).equals(Const.OP_EDIT) && req.isUserInRole("Admin")) + { + try + { + ImageDetail imagedetail = imagegalleryModule.findImageDetailByID(detailID); + + imagedetail.setName(formCtx.get(Const.NAME)); + imagedetail.setDescription(formCtx.get(Const.DESCRIPTION)); + imagedetail.setThumbnailPath(formCtx.get(Const.THUMBNAIL_PATH)); + imagedetail.setImagePath(formCtx.get(Const.IMAGE_PATH)); + imagedetail.setPhotographer(formCtx.get(Const.PHOTOGRAPHER)); + } + catch(ModuleException e) + { + e.printStackTrace(); + } + } + resp.setRenderParameter(Const.OP, formCtx.get(Const.RETURN_LOCATION)); + resp.setRenderParameter(Const.COLLECTION_ID, (collectionID.toString())); + resp.setRenderParameter(Const.DETAIL_ID, (detailID.toString())); + req.getPortletSession().removeAttribute(Const.CTX); + } } + /** Added: labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/CMSHelper.java =================================================================== --- labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/CMSHelper.java 2006-06-10 22:28:06 UTC (rev 4721) +++ labs/portletswap/imagegalleryportlet/trunk/ig_2.2/src/main/org/jboss/portlet/imagegallery/helper/CMSHelper.java 2006-06-11 02:35:09 UTC (rev 4722) @@ -0,0 +1,244 @@ +/***************************************** + * * + * The Image Gallery Portlet * + * * + * Distributable under LGPL license. * + * See terms of license at gnu.org. * + * * + *****************************************/ + +package org.jboss.portlet.imagegallery.helper; + +import org.jboss.portlet.imagegallery.Const; +import org.jboss.portal.common.context.DelegateContext; + +import org.jboss.portal.cms.model.Content; +import org.jboss.portal.cms.impl.ContentImpl; +import org.jboss.portal.cms.CMS; +import org.jboss.portal.cms.Command; +import org.jboss.portal.cms.model.Folder; +import org.jboss.portal.cms.impl.FolderImpl; +import org.jboss.portal.cms.model.File; +import org.jboss.portal.cms.impl.FileImpl; +import org.jboss.portal.cms.CMSMimeMappings; +import org.jboss.portal.cms.util.FileUtil; +import org.jboss.portal.cms.util.NodeUtil; + +import java.util.Date; +import java.util.List; +import java.util.LinkedList; +import java.util.Locale; +/** + * CMSHelper is a class to manage CMS transactions in the image gallery portlet. + * This is able to check the paths. It is also able to create files and folders. + * + * @author <a href="mailto:im...@ho...">Ron & Conrad Kanengieter</a> + * @version $Revision: 2.2 $ + */ + +public class CMSHelper +{ + private CMS service; + + public CMSHelper() + { + } + + public CMSHelper(CMS newService) + { + service = newService; + } + + /** + * A routine to check if a folder exists in the CMS + * + * @param path is the place in the CMS to be checked + * @return a value stating whether a folder exists + */ + public boolean folderExists(String path) + { + Command folderExistsCMD = service.getCommandFactory().createItemExistsCommand(path); + Boolean folderExists = null; + if (folderExistsCMD != null) + { + folderExists = (Boolean) service.execute(folderExistsCMD); + } + + if (folderExists == null) + { + folderExists = new Boolean(false); + } + return folderExists.booleanValue(); + } + + /** + * A routine to check if a file exists in the CMS + * + * @param path is the place in the CMS to be checked + * @return a value stating whether a file exists + */ + public boolean fileExists(String path) + { + Command fileExistsCMD = service.getCommandFactory().createItemExistsCommand(path); + Boolean fileExists = null; + + if (fileExistsCMD != null) + { + fileExists = (Boolean) service.execute(fileExistsCMD); + } + + if (fileExists == null) + { + fileExists = new Boolean(false); + } + return fileExists.booleanValue(); + } + + /** + * Trims the local path in order to get the base file name and + * makes a CMS path. + * + * @param localPath is the path from which to create the CMS Path + * @param ctx is the thumbnail path + */ + public void cleanPath(String localPath, DelegateContext ctx) + { + // The path to the base file name if the browser has the + // full path. + int backslashIndex = localPath.lastIndexOf("\\"); + if(backslashIndex > -1) // getWindows + { + localPath = localPath.substring(backslashIndex + 1); + } + else // unix + { + backslashIndex = localPath.lastIndexOf("/"); + localPath = localPath.substring(backslashIndex + 1); + } + String CMSPath = FileUtil.cleanDoubleSlashes(ctx.get(Const.CMS_FOLDER) + ctx.get(Const.OP_CMS_ACTION) + "/" + localPath); + String relativePath = FileUtil.cleanDoubleSlashes(ctx.get(Const.OP_CMS_ACTION) + "/" + localPath); + String pathToShow = FileUtil.cleanDoubleSlashes(ctx.get(Const.BASE_PATH) + "/" + ctx.get(Const.CMS_ACTION) + "/" + localPath); + + + if (ctx.get(Const.OP_CMS_ACTION).equals(Const.CMS_THUMBNAIL)) + ctx.put (Const.THUMBNAIL_PATH, relativePath); + else + if (ctx.get(Const.OP_CMS_ACTION).equals(Const.CMS_IMAGE)) + ctx.put (Const.IMAGE_PATH, relativePath); + + ctx.put(Const.SHOW_THUMBNAIL, pathToShow); + ctx.put (Const.LOCAL_FILE, localPath); + ctx.put (Const.CMS_FILE, CMSPath); + } + + /** + * See if any images exist in the CMS Folder path of the context + * + * @param ctx is the context that contains the CMS image folder + * @return list of the files that are found in the CMS folder + */ + public List checkCMSPath(DelegateContext ctx) + { + Command checkCMD = service.getCommandFactory().createFolderGetListCommand(ctx.get(Const.CMS_FOLDER)); + Folder folderToCheck = null; + List folderContents = null; + + if (checkCMD != null) + { + folderToCheck = (Folder) service.execute(checkCMD); + } + + if (folderToCheck != null) + { + folderContents = folderToCheck.getFiles(); + } + else + { + folderContents = new LinkedList(); + } + + return folderContents; + } + + /* + * Create the file using the path to the CMS file, bytes, and locale. + * + * @param ctx contains the file name and path to CMS file + * @param locale is the locale in which the file is created + * @param fileBytes is the file bytes. + */ + public void uploadToCMS (DelegateContext ctx, Locale locale, byte[] fileBytes) + { + // This is the file object that will be on the CMS. + File imageGalleryUpload = new FileImpl(); + + // This is the content that will be on on the file in the CMS. + Content content = new ContentImpl(); + + String fileExt = ctx.get(Const.LOCAL_FILE).substring(ctx.get(Const.LOCAL_FILE).lastIndexOf(".") + 1, ctx.get(Const.LOCAL_FILE).length()); + // This is the name to go into the CMS system + String fileName = ctx.get(Const.LOCAL_FILE).substring(0, ctx.get(Const.LOCAL_FILE).lastIndexOf(".")); + CMSMimeMappings mapper = new CMSMimeMappings(); + if(mapper.getMimeType(fileExt) != null) + { + content.setMimeType(mapper.getMimeType(fileExt)); + } + else + { + content.setMimeType(""); + } + + imageGalleryUpload.setBasePath(ctx.get(Const.CMS_FILE)); + + content.setTitle(fileName + " file"); + content.setDescription("Created by IG upload"); + content.setBasePath(ctx.get(Const.CMS_FILE) + "/" + locale.getLanguage()); + content.setBytes(fileBytes); + + imageGalleryUpload.setContent(locale, content); + if (fileBytes.length > 0) + { + Command existsCMD = service.getCommandFactory().createItemExistsCommand(content.getBasePath()); + Boolean bExists = (Boolean) service.execute(existsCMD); + if(bExists.booleanValue()) // if file exists, update contentNode + { + // force "make live" + Command cmdUpdate = service.getCommandFactory().createFileUpdateCommand(imageGalleryUpload); + service.execute(cmdUpdate); + + Command cmdVersion = service.getCommandFactory().createContentCreateNewVersionCommand(content, true); + service.execute(cmdVersion); + } + else // if file doesnt exist, create the file and the contentNode. + { + Command saveFileCMD = service.getCommandFactory().createFileSaveCo... [truncated message content] |