incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r156344 [1/2] - in incubator/graffito/trunk/applications/browser/src: java/org/apache/portals/graffito/portlets/ java/org/apache/portals/graffito/portlets/actions/ java/org/apache/portals/graffito/portlets/dto/ java/org/apache/portals/graffito/portlets/services/ java/org/apache/portals/graffito/portlets/upload/ java/org/apache/portals/graffito/portlets/util/ java/org/apache/portals/graffito/servlets/ webapp/META-INF/ webapp/WEB-INF/ webapp/WEB-INF/actions/ webapp/WEB-INF/view/ webapp/WEB-INF/view/document/ webapp/WEB-INF/view/folder/ webapp/kupu/
Date Sun, 06 Mar 2005 22:27:58 GMT
Author: clombart
Date: Sun Mar  6 14:27:53 2005
New Revision: 156344

URL: http://svn.apache.org/viewcvs?view=rev&rev=156344
Log:
Continue to work on The Graffito Browser. It is now more stable for the navigation. 
Next step : add some tabs to set the permissions & update metadata.

Added:
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/CmsObjectAction.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/DocumentAction.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/FolderAction.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GeneralAction.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GraffitoAction.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionHandler.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionInfo.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/BrowserDTO.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/ServiceUtil.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletDiskFileUpload.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUpload.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUploadBase.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/util/BrowserDTOUtil.java
    incubator/graffito/trunk/applications/browser/src/webapp/META-INF/
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/actions/
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/actions/actions.xml
Modified:
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/BrowserPortlet.java
    incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/servlets/GraffitoViewerServlet.java
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/jetspeed-portlet.xml
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/document/document-text-edit.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/document/document-text-html-view.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/document/document-type.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/document/document-upload-edit.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/document/document.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/edit-tab-sample.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/folder/folder-browser.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/folder/folder-detail.vm
    incubator/graffito/trunk/applications/browser/src/webapp/WEB-INF/view/folder/folder-edit.vm
    incubator/graffito/trunk/applications/browser/src/webapp/kupu/kupu.vm

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.graffito.portlets.actions.PortletActionHandler;
+import org.apache.portals.graffito.portlets.tabs.TabReader;
+import org.apache.portals.graffito.portlets.tabs.VelocityTab;
+import org.apache.portals.graffito.portlets.util.GraffitoTools;
+import org.apache.velocity.context.Context;
+
+/**
+ * Velocity portlet used for all Graffito Portlets
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * @version $Id:  Exp $
+ */
+public abstract class AbstractGraffitoPortlet extends GenericVelocityPortlet
+{
+
+    private static final String TAB_CONFIG = "TabConfig";
+    private static final String ACTION_CONFIG = "ActionConfig"; 
+    private static final String VIEWER_SERVLET = "ViewerServlet";    
+    
+    protected HashMap tabs = new HashMap();
+    protected PortletActionHandler actionHandler;
+    protected String viewerServlet;
+    
+    
+    protected Log log = LogFactory.getLog(AbstractGraffitoPortlet.class);
+
+    /**
+     * @see javax.portlet.Portlet#init(javax.portlet.PortletConfig)
+     */
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+                        
+        PortletContext context = getPortletContext();
+                
+        String tabConfig = config.getInitParameter(TAB_CONFIG);
+        if (null == tabConfig)
+        {
+            throw new PortletException("Portlet init parameter TabConfig not found");
+        }
+        
+        String xmlFile = context.getRealPath(tabConfig);
+        try
+        {
+            tabs = TabReader.getTabs(xmlFile);            
+        }
+        catch (Exception e)
+        {
+            throw new PortletException("Impossible to read the tab xml file : " + xmlFile );            
+        }
+        
+        
+        String actionConfig = config.getInitParameter(ACTION_CONFIG);
+        if (null == actionConfig)
+        {
+            throw new PortletException("Portlet init parameter ActionConfig not found");
+        }
+        
+        xmlFile = context.getRealPath(actionConfig);
+        try
+        {
+            actionHandler = new PortletActionHandler(xmlFile);            
+        }
+        catch (Exception e)
+        {
+            throw new PortletException("Impossible to read the action xml file : " + xmlFile, e );            
+        }        
+        
+        
+        viewerServlet = config.getInitParameter(VIEWER_SERVLET);
+        if (null == viewerServlet)
+        {
+            throw new PortletException("Portlet init parameter ViewerServlet not found");
+        }
+                                 
+    }
+
+    /**
+     * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+     */
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        
+        Context velocityContext = this.getContext(request);
+        velocityContext.put("tabs", tabs);   
+        velocityContext.put("graffitoTools", new GraffitoTools(request.getContextPath() + "/" + viewerServlet));
+        
+        super.doView(request, response);
+    }
+
+    /**
+     * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+     */
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        Context velocityContext = this.getContext(request);
+        velocityContext.put("tabs", tabs); 
+        velocityContext.put("graffitoTools", new GraffitoTools(request.getContextPath() + "/" + viewerServlet));
+        super.doEdit(request, response);
+    }
+
+    /**
+     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+     */
+    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+    {
+                      
+            String tabId = request.getParameter("selectTab");
+            if (tabId != null)
+            {                
+                
+                VelocityTab tab = (VelocityTab) tabs.get(tabId);
+                String pageId = request.getParameter("selectPage");
+                    
+                if (pageId == null)
+                {
+                    throw new PortletException("Impossible to find the selected page");
+                }
+                
+                tab.setSelectedPage(pageId);
+            }            
+            
+    }
+}
\ No newline at end of file

Modified: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/BrowserPortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/BrowserPortlet.java?view=diff&r1=156343&r2=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/BrowserPortlet.java (original)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/BrowserPortlet.java Sun Mar  6 14:27:53 2005
@@ -18,22 +18,19 @@
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletConfig;
-import javax.portlet.PortletContext;
+
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequest;
 
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
-import org.apache.portals.graffito.ContentModelService;
-import org.apache.portals.graffito.ContentServerService;
-import org.apache.portals.graffito.exception.ContentManagementException;
 import org.apache.portals.graffito.model.CmsObject;
 import org.apache.portals.graffito.model.Document;
 import org.apache.portals.graffito.model.Folder;
-import org.apache.portals.graffito.portlets.dto.BrowserInfo;
-import org.apache.portals.graffito.portlets.util.BrowserInfoUtil;
-import org.apache.portals.graffito.util.CmsUtil;
+import org.apache.portals.graffito.portlets.dto.BrowserDTO;
+import org.apache.portals.graffito.portlets.util.BrowserDTOUtil;
+
 import org.apache.velocity.context.Context;
 
 /**
@@ -49,7 +46,7 @@
 {
 
     /** Velocity variable to set the browser info object in the Velocity context */
-    private static final String VELOCITY_BROWSER_INFO = "browserInfo";
+    private static final String VELOCITY_BROWSER_DTO = "browserDTO";
 
     /** Default uri used to display the content browser */
     private static final String DEFAULT_CONTENT_SCOPE = "/graffito";
@@ -63,9 +60,6 @@
     /** Portlet init param containing all available document languages */
     private ArrayList documentLanguages = new ArrayList();
 
-    private ContentModelService modelService;
-
-    private ContentServerService serverService;
 
     /**
      * @see javax.portlet.Portlet#init(javax.portlet.PortletConfig)
@@ -74,20 +68,6 @@
     {
         super.init(config);
 
-        PortletContext context = getPortletContext();
-
-        modelService = (ContentModelService) context.getAttribute("cps:ContentModel");
-        if (null == modelService)
-        {
-            throw new PortletException("Failed to find the content model service on portlet initialization");
-        }
-
-        serverService = (ContentServerService) context.getAttribute("cps:ContentServer");
-        if (null == serverService)
-        {
-            throw new PortletException("Failed to find the content server service on portlet initialization");
-        }
-
         String param = config.getInitParameter("DocumentTypes");
         if (null == param)
         {
@@ -113,24 +93,27 @@
 
         response.setContentType("text/html");
         Context velocityContext = this.getContext(request);
-
-        BrowserInfo browserInfo = null;
-        String uri = request.getParameter("uri");
+       
+        BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+        String uri = request.getParameter("uri");                
         if (uri == null)
         {
-            uri = this.getDefaultContentScope(request);
-            browserInfo = BrowserInfoUtil.getSessionBrowserInfo(request);
-        }
-
-        if (null == browserInfo)
-        {
-            browserInfo = this.initBrowserInfo(uri, request, response);
-            BrowserInfoUtil.setSessionContentBrowser(request, browserInfo);
-        }
-
-        this.selectViewTemplate(browserInfo, request, response);
+            if (browserDTO == null )
+            {
+               uri = this.getDefaultContentScope(request);
+            }
+            else
+            {
+               uri = browserDTO.getUri();
+            }            
+        }    
+        
+        browserDTO = BrowserDTOUtil.createBrowserDTO(uri, request, response, this.documentTypes, this.documentLanguages);
+        BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+        
+        this.selectViewTemplate(browserDTO, request, response);
 
-        velocityContext.put(VELOCITY_BROWSER_INFO, browserInfo);
+        velocityContext.put(VELOCITY_BROWSER_DTO, browserDTO);
         super.doView(request, response);
 
     }
@@ -141,13 +124,39 @@
     public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
     {
 
+        boolean isNewUri = false; 
         response.setContentType("text/html");
         Context velocityContext = this.getContext(request);
-
-        BrowserInfo browserInfo = BrowserInfoUtil.getSessionBrowserInfo(request);
+        BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
         
-        this.selectEditTemplate(browserInfo, request, response);
-        velocityContext.put(VELOCITY_BROWSER_INFO, browserInfo);
+        String uri = request.getParameter("uri");
+        if (uri == null)
+        {
+            if (browserDTO == null)
+            {
+                uri = this.getDefaultContentScope(request);
+            }
+            else
+            {
+                uri = browserDTO.getUri();
+            }
+        }
+        else
+        {
+            //a new uri is asked, reset the DTO
+            isNewUri = true;            
+        }
+        
+        
+        // Refresh the DTO object (retrieve data from the repository )
+        if ((( ! browserDTO.isInsert() ) && ( ! browserDTO.isUpdate())) || (isNewUri))
+        {
+            browserDTO = BrowserDTOUtil.createBrowserDTO(uri, request, response, this.documentTypes, this.documentLanguages);        
+            BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+        }
+
+        this.selectEditTemplate(browserDTO, request, response);
+        velocityContext.put(VELOCITY_BROWSER_DTO, browserDTO);
 
         super.doEdit(request, response);
     }
@@ -156,10 +165,9 @@
      * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
      */
     public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
-    {
+    {        
         actionHandler.processAction(request, response);
         super.processAction(request, response);
-
     }
 
 
@@ -199,54 +207,10 @@
         }
     }
 
-    /**
-     * Initialise the DTO browserInfo. This DTO is used by the velocity templates to display the content browser infos.
-     * 
-     * @param uri
-     *            The uri associated to the cms object to display
-     * @param request
-     *            RenderRequest
-     * @param response
-     *            RenderResponse
-     * @return a new initialised {@link BrowserInfo}
-     * @throws PortletException
-     *             when it is not possible to initialise the
-     */
-    private BrowserInfo initBrowserInfo(String uri, RenderRequest request, RenderResponse response) throws PortletException
-    {
-        try
-        {
-            BrowserInfo browserInfo = new BrowserInfo(this.documentTypes, this.documentLanguages);
-            CmsObject cmsObject = modelService.getCmsObject(uri);
-            browserInfo.setCurrentCmsObject(cmsObject);
-            if ((cmsObject instanceof Folder) || (cmsObject == null)) // cms object is null if the uri match to a server root
-            {
-                browserInfo.setDocuments(modelService.getDocuments(uri));
-                browserInfo.setFolders(modelService.getFolders(uri));
-                browserInfo.setCurrentFolder(modelService.getFolder(uri));
-
-            }
-            else
-            {
-                browserInfo.setCurrentFolder(cmsObject.getParentFolder());
-            }
-            String scopeServer = CmsUtil.getServerScope(uri);
-            browserInfo.setCurrentServer(serverService.getServer(scopeServer));
-
-            return browserInfo;
-
-        }
-        catch (ContentManagementException e)
-        {
-            throw new PortletException("Failed to view the portlet - impossible to access to Graffito content store : "
-                    + e.getMessage());
-        }
-
-    }
 
-    private void selectViewTemplate(BrowserInfo browserInfo, RenderRequest request, RenderResponse response)
+    private void selectViewTemplate(BrowserDTO browserDTO, RenderRequest request, RenderResponse response)
     {
-        CmsObject cmsObject = browserInfo.getCurrentCmsObject();
+        CmsObject cmsObject = browserDTO.getCurrentCmsObject();
         if ((cmsObject instanceof Folder) || (cmsObject == null))
         {
             request.setAttribute(PARAM_VIEW_PAGE, "/WEB-INF/view/folder/folder-browser.vm");
@@ -269,20 +233,19 @@
         }
     }
 
-    private void selectEditTemplate(BrowserInfo browserInfo, RenderRequest request, RenderResponse response)
+    private void selectEditTemplate(BrowserDTO browserDTO, RenderRequest request, RenderResponse response)
             throws PortletException
     {
 
         // Check if the edit template has been already defined (from the processAction method)
-        String editPageParam = request.getParameter(PARAM_EDIT_PAGE);
-        if (editPageParam != null && (! editPageParam.equals(this.getDefaultEditPage())))
+        String editPageParam = browserDTO.getTemplate();
+        if (editPageParam != null)
         {
             request.setAttribute(PARAM_EDIT_PAGE, editPageParam);
         }
         else
         {
-            CmsObject cmsObject = browserInfo.getCurrentCmsObject();
-
+            CmsObject cmsObject = browserDTO.getCurrentCmsObject();
             if ((cmsObject == null) || (cmsObject instanceof Folder))
             {
                 request.setAttribute(PARAM_EDIT_PAGE, "/WEB-INF/view/folder/folder-edit.vm");
@@ -303,10 +266,7 @@
             }
         }
         
-        if (browserInfo.getOperation() == null)
-        {
-            browserInfo.setOperation(BrowserInfo.UPDATE);
-        }
+        
     }
 
 }

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/CmsObjectAction.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/CmsObjectAction.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/CmsObjectAction.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/CmsObjectAction.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.exception.ContentManagementException;
+
+import org.apache.portals.graffito.portlets.dto.BrowserDTO;
+import org.apache.portals.graffito.portlets.services.ServiceUtil;
+import org.apache.portals.graffito.portlets.util.BrowserDTOUtil;
+
+/**
+ * Portlet Action used to manage all common action on Cms object like delete, ...
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class CmsObjectAction extends GraffitoAction
+{
+
+    public void delete(PortletActionInfo portletActionInfo) throws PortletException
+    {
+        ActionResponse actionResponse = portletActionInfo.getActionResponse();
+        ActionRequest actionRequest = portletActionInfo.getActionRequest();
+        
+        try
+        {
+            String[] uriToDelete = portletActionInfo.getActionRequest().getParameterValues("uri");
+            if (uriToDelete == null)
+            {
+                // No cms object has been selected
+                return;
+            }
+            
+            ContentModelService modelService = ServiceUtil.getModelService();
+            modelService.removeAll(uriToDelete);                        
+            BrowserDTO browserDTO = BrowserDTOUtil.cleanBrowserDTO(actionRequest);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-edit.vm");
+
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to delete all cms objects ", e);
+        }
+
+    }   
+        
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/DocumentAction.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/DocumentAction.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/DocumentAction.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/DocumentAction.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.Document;
+import org.apache.portals.graffito.model.Folder;
+import org.apache.portals.graffito.portlets.dto.BrowserDTO;
+import org.apache.portals.graffito.portlets.services.ServiceUtil;
+import org.apache.portals.graffito.portlets.upload.PortletDiskFileUpload;
+import org.apache.portals.graffito.portlets.util.BrowserDTOUtil;
+
+/**
+ *  Portlet Action used to manage the Graffito Folders
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class DocumentAction extends GraffitoAction
+{
+
+    public void createStep1(PortletActionInfo actionInfo) throws PortletException
+    {
+        ActionRequest request = actionInfo.getActionRequest();
+        ActionResponse response = actionInfo.getActionResponse();
+        try
+        {
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            ContentModelService modelService = ServiceUtil.getModelService();
+            Document document = modelService.createDocument();
+            browserDTO.setCurrentCmsObject(document);
+            browserDTO.setOperation(BrowserDTO.INSERT);
+            browserDTO.setTemplate("/WEB-INF/view/document/document-type.vm");
+            BrowserDTOUtil.setBrowserDTO(request, browserDTO); 
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to create a document ", e);
+        }
+    }   
+    
+    public void createStep2(PortletActionInfo actionInfo) throws PortletException
+    {
+        ActionRequest request = actionInfo.getActionRequest();
+        ActionResponse response = actionInfo.getActionResponse();
+        
+        BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+        Document document = (Document) browserDTO.getCurrentCmsObject();
+        String name = request.getParameter("name");
+        String title = request.getParameter("title");
+        String description = request.getParameter("description");
+        String owner = request.getParameter("owner");
+        String language = request.getParameter("language");
+
+        document.setCreationDate(new Date());
+        document.setDescription(description);
+        document.setLastModified(new Date());
+        document.setName(name);
+        document.setTitle(title);
+        document.setOwner(owner);
+        document.setLanguage(language);
+
+        String parentFolderUri = null;
+        if (browserDTO.getCurrentFolder() == null)
+        {
+            parentFolderUri = browserDTO.getCurrentServer().getScope();
+        }
+        else
+        {
+            parentFolderUri = browserDTO.getCurrentFolder().getUri();
+        }
+
+        document.setUri(parentFolderUri + "/" + name);
+        document.setVersionNumber("1.0");
+
+        String type = request.getParameter("documentType");
+        if (type.equals("document.type.text"))
+        {
+            document.setContentType("text/plain");
+            browserDTO.setTemplate("/WEB-INF/view/document/document-text-edit.vm");
+        }
+
+        if (type.equals("document.type.html"))
+        {
+            document.getContent().setContent("[Add your text here]".getBytes());
+            document.setContentType("text/html");            
+            browserDTO.setTemplate( "/kupu/kupu.vm");
+
+        }
+
+        if (type.equals("document.type.upload"))
+        {
+            browserDTO.setTemplate("/WEB-INF/view/document/document-upload-edit.vm");
+        }
+
+        browserDTO.setCurrentCmsObject(document);
+        BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+        
+    }
+
+    public void edit(PortletActionInfo actionInfo) throws PortletException
+    {    
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            String uri = request.getParameter("uri");
+            ContentModelService modelService = ServiceUtil.getModelService();          
+            Document document= modelService.getDocument(uri);
+            browserDTO.setCurrentCmsObject(document);
+            browserDTO.setOperation(BrowserDTO.UPDATE);
+            BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+
+
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to create a folder ", e);
+        }        
+        
+    }
+    
+    public void save(PortletActionInfo actionInfo) throws PortletException
+    {
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            Document document = (Document) browserDTO.getCurrentCmsObject();
+
+            //Other attributes has been initialised in the method createDocumentStep2
+            String content = request.getParameter("content");
+            try
+            {
+                document.getContent().setContent(content.getBytes(request.getCharacterEncoding()));
+                document.getContent().setEncoding(request.getCharacterEncoding());
+            }
+            catch (UnsupportedEncodingException e)
+            {
+                document.getContent().setContent(content.getBytes());
+            }
+            document.setSize(content.length());
+            
+            ContentModelService modelService = ServiceUtil.getModelService();           
+            if (browserDTO.isInsert())
+            {
+                modelService.addDocument(document);
+            }
+            else
+            {
+                modelService.updateDocument(document);
+            }
+                        
+            browserDTO = BrowserDTOUtil.cleanBrowserDTO(request);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-edit.vm");
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to create a document ", e);
+        }
+        
+    }
+    
+    public void upload(PortletActionInfo actionInfo) throws PortletException
+    {
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            Document document = (Document) browserDTO.getCurrentCmsObject();
+            PortletDiskFileUpload diskFileUpload = actionInfo.getDiskFileUpload();
+            diskFileUpload.setRepositoryPath("c:/tmp/upload");
+            FileItem fileItem = diskFileUpload.getFileItem(request, "file");
+            document.setContentType(fileItem.getContentType());
+            document.getContent().setContent(fileItem.get());
+            document.getContent().setEncoding(request.getCharacterEncoding());
+
+            document.setSize(fileItem.getSize());
+            ContentModelService modelService = ServiceUtil.getModelService();            
+            if (browserDTO.isInsert())
+            {
+                modelService.addDocument(document);
+            }
+            else
+            {
+                modelService.updateDocument(document);
+            }
+                        
+            browserDTO = BrowserDTOUtil.cleanBrowserDTO(request);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-edit.vm");
+        }
+        catch (Exception e)
+        {
+            throw new PortletException("Impossible to upload a document ", e);
+        }
+    }
+    
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/FolderAction.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/FolderAction.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/FolderAction.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/FolderAction.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+import java.util.Date;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.Folder;
+import org.apache.portals.graffito.portlets.dto.BrowserDTO;
+import org.apache.portals.graffito.portlets.services.ServiceUtil;
+import org.apache.portals.graffito.portlets.util.BrowserDTOUtil;
+
+/**
+ *  Portlet Action used to manage the Graffito Folders
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class FolderAction extends GraffitoAction
+{
+
+    public void create(PortletActionInfo actionInfo) throws PortletException
+    {
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            ContentModelService modelService = ServiceUtil.getModelService();
+            Folder folder = modelService.createFolder();
+            browserDTO.setCurrentCmsObject(folder);
+            browserDTO.setOperation(BrowserDTO.INSERT);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-detail.vm");
+            BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to create a folder ", e);
+        }
+    }   
+    
+    public void edit(PortletActionInfo actionInfo) throws PortletException
+    {
+
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            String uri = request.getParameter("uri");
+            ContentModelService modelService = ServiceUtil.getModelService();          
+            Folder folder = modelService.getFolder(uri);
+            browserDTO.setCurrentCmsObject(folder);
+            browserDTO.setOperation(BrowserDTO.UPDATE);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-detail.vm");
+            BrowserDTOUtil.setBrowserDTO(request, browserDTO);
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to create a folder ", e);
+        }
+    }
+    
+    public void save(PortletActionInfo actionInfo) throws PortletException
+    {
+        try
+        {
+            ActionRequest request = actionInfo.getActionRequest();
+            ActionResponse response = actionInfo.getActionResponse();
+            
+            BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+            Folder folder = (Folder) browserDTO.getCurrentCmsObject();
+            if (browserDTO.isInsert())
+            {
+                String name = request.getParameter("name");
+                folder.setCreationDate(new Date());
+                folder.setLastModified(new Date());
+                folder.setName(name);
+                String parentFolderUri = null;
+                if (browserDTO.getCurrentFolder() == null)
+                {
+                    parentFolderUri = browserDTO.getCurrentServer().getScope();
+                }
+                else
+                {
+                    parentFolderUri = browserDTO.getCurrentFolder().getUri();
+                }
+
+                folder.setUri(parentFolderUri + "/" + name);
+
+            }
+            else
+            {
+                folder.setLastModified(new Date());
+            }
+
+            String title = request.getParameter("title");
+            String description = request.getParameter("description");
+            folder.setDescription(description);
+            folder.setTitle(title);
+            ContentModelService modelService = ServiceUtil.getModelService();
+            
+            if (browserDTO.isInsert())
+            {
+                modelService.addFolder(folder);
+            }
+            else
+            {
+                modelService.updateFolder(folder);
+            }
+            
+            browserDTO = BrowserDTOUtil.cleanBrowserDTO(request);
+            browserDTO.setTemplate("/WEB-INF/view/folder/folder-edit.vm");
+            
+        }
+        catch (ContentManagementException e)
+        {
+            throw new PortletException("Impossible to save a folder ", e);
+        }
+    }
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GeneralAction.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GeneralAction.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GeneralAction.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GeneralAction.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.graffito.model.Document;
+import org.apache.portals.graffito.portlets.dto.BrowserDTO;
+import org.apache.portals.graffito.portlets.util.BrowserDTOUtil;
+
+/**
+ *  Portlet Action used for generic process 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class GeneralAction extends GraffitoAction
+{    
+ 
+    public void cancel(PortletActionInfo actionInfo) throws PortletException
+    {
+        ActionRequest request = actionInfo.getActionRequest();
+        ActionResponse response = actionInfo.getActionResponse();
+        
+        BrowserDTO browserDTO = BrowserDTOUtil.getBrowserDTO(request);
+        
+        if (browserDTO.isInsert() || browserDTO.isUpdate())
+        {        
+           browserDTO.setTemplate("/WEB-INF/view/folder/folder-edit.vm");
+        }
+        else
+        {
+            response.setPortletMode(PortletMode.VIEW);
+        }
+        
+        BrowserDTOUtil.cleanBrowserDTO(request);               
+    }
+
+
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GraffitoAction.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GraffitoAction.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GraffitoAction.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/GraffitoAction.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+
+/**
+ * Ancestor class for all Graffito Portlet Action
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class GraffitoAction
+{
+    
+
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionHandler.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionHandler.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionHandler.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionHandler.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.portlets.upload.PortletDiskFileUpload;
+import org.apache.portals.graffito.portlets.upload.PortletFileUploadBase;
+//import org.apache.portals.graffito.portlets.util.PortletFileUploadBase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * Portlet Action Handler. This handler can be used in the portlet method 'processAction' in order
+ * to manage all actions to process. 
+ * 
+ * This handler provides a more cleaner code when the number of possible actions increase. 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class PortletActionHandler
+{
+    private HashMap actions = new HashMap();
+    
+    private Log log = LogFactory.getLog(PortletActionHandler.class); 
+    
+    private String ACTION_PREFIX = "portletAction_";
+    
+    
+    /**
+     * Constructor. 
+     * 
+     * Build a PortletActionHandler from an xml file. This xml file should contains all possible actions.
+     * 
+     * @param xmlFile
+     * @throws PortletException
+     * 
+     */
+    public PortletActionHandler(String xmlFile)  throws PortletException
+    {
+        try
+        {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            Document document = builder.parse(xmlFile);
+            Node root = document.getFirstChild();
+            
+            NodeList actionList = root.getChildNodes();
+            for (int actionIndex = 0; actionIndex < actionList.getLength(); actionIndex++)
+            {
+                Node actionNode = actionList.item(actionIndex);
+                if (actionNode.getNodeType() == Node.ELEMENT_NODE)
+                {                
+                    String actionId = actionNode.getAttributes().getNamedItem("id").getNodeValue();
+                    String actionClassName = actionNode.getAttributes().getNamedItem("class").getNodeValue();
+                    log.info("Add Action Handler : " + actionClassName);
+                    actions.put(actionId, Class.forName(actionClassName));
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            throw new PortletException("Failed to initialise the PortletActionHandler", e);
+        }
+        
+    }
+    
+    /**
+     * Process an action from a portlet
+     * 
+     * @param request
+     * @param response
+     * 
+     * @return 
+     * @throws PortletException   
+     */
+    public int processAction(ActionRequest request, ActionResponse response) throws PortletException
+    {
+        PortletActionInfo portletActionInfo = getSelectedAction(request, response);
+        return executePortletAction(portletActionInfo);
+    }
+    
+    private PortletActionInfo getSelectedAction(ActionRequest request, ActionResponse response) throws PortletException
+    {
+        //-------------------------------------------------------------------------------------------
+        // ! MULTIPART REQUEST
+        //-------------------------------------------------------------------------------------------
+        if (!PortletFileUploadBase.isMultipartContent(request))
+        {
+            Enumeration parameterNames = request.getParameterNames();
+            while (parameterNames.hasMoreElements())
+            {
+                String parameterName = (String) parameterNames.nextElement();
+                if (parameterName.startsWith(ACTION_PREFIX))
+                {
+                    String actionName = parameterName.substring(ACTION_PREFIX.length());
+                    return new PortletActionInfo(actionName, request, response);
+                }
+            }
+            return null;
+        }
+        
+        //-------------------------------------------------------------------------------------------
+        // MULTIPART REQUEST
+        // ------------------------------------------------------------------------------------------                
+        else
+        {
+            try
+            {
+                PortletDiskFileUpload diskFileUpload =  new PortletDiskFileUpload();
+                Iterator fileItemIterator = diskFileUpload.getFileItems(request).iterator();
+                while(fileItemIterator.hasNext())
+                {
+                    FileItem fileItem = (FileItem) fileItemIterator.next();
+                    if( (fileItem.isFormField()) && (fileItem.getFieldName().startsWith(ACTION_PREFIX)))
+                    {
+                        String actionName = fileItem.getFieldName().substring(ACTION_PREFIX.length());
+                        return new PortletActionInfo(actionName, request, response, diskFileUpload);
+                    }
+                }
+                return null;
+            }
+            catch (FileUploadException e)
+            {
+                throw new PortletException("Impossible to selection the action portlet", e);                
+            }
+            
+        }
+    }
+    
+    private int executePortletAction(PortletActionInfo portletActionInfo) throws PortletException
+    {
+        try
+        {
+           if (portletActionInfo == null)
+           {
+               return -1;    
+           }
+           
+           Class actionClass = (Class) actions.get(portletActionInfo.getActionName());
+
+           // No action found  
+           if (actionClass == null)
+           {
+               return -1;
+           }
+           
+           Object action = actionClass.newInstance();
+           Class[] argClasses = {PortletActionInfo.class};
+           Object[] args = {portletActionInfo};
+           Method method = actionClass.getMethod(portletActionInfo.getActionMethod(), argClasses);           
+           method.invoke(action, args);
+           return 1;
+        }
+        catch(Exception e)
+        {
+            throw new PortletException("Failed to execute method :" + portletActionInfo.getActionName() + '.' + portletActionInfo.getActionMethod(), e); 
+        }
+    }
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionInfo.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionInfo.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionInfo.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/actions/PortletActionInfo.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.actions;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+
+import org.apache.portals.graffito.portlets.upload.PortletDiskFileUpload;
+
+class PortletActionInfo
+{
+    private String ACTION_SEPARATOR = "\\.";
+
+    private String actionName;
+
+    private String actionMethod;
+
+    private PortletDiskFileUpload diskFileUpload;
+    
+    private ActionRequest request;
+    
+    private ActionResponse response;
+    
+
+    public PortletActionInfo(String actionExpression, ActionRequest request, ActionResponse response)
+    {
+        String[] split = actionExpression.split(ACTION_SEPARATOR);
+        actionName = split[0];
+        actionMethod = split[1];
+        
+        this.request = request;
+        this.response = response;
+
+    }
+
+    public PortletActionInfo(String actionExpression, ActionRequest request, ActionResponse response, PortletDiskFileUpload diskFileUpload)
+    {
+        this(actionExpression, request, response);
+        this.diskFileUpload = diskFileUpload;
+    }
+
+    public String getActionName()
+    {
+        return actionName;
+    }
+
+    public String getActionMethod()
+    {
+        return actionMethod;
+    }
+
+    public PortletDiskFileUpload getDiskFileUpload()
+    {
+        return diskFileUpload;
+    }
+    
+    
+    public ActionRequest getActionRequest()
+    {
+        return request;
+    }
+    public ActionResponse getActionResponse()
+    {
+        return response;
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/BrowserDTO.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/BrowserDTO.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/BrowserDTO.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/dto/BrowserDTO.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.dto;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.portals.graffito.model.CmsObject;
+import org.apache.portals.graffito.model.Document;
+import org.apache.portals.graffito.model.Folder;
+import org.apache.portals.graffito.model.Server;
+
+/**
+ * Information on the current content folder displayed in the Graffito Browser Portlet.
+ * This is the DTO used between the velocity template and the portlet methods
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class BrowserDTO
+{   
+    /** The uri assigned to the cms object display in the Browser */
+    private String uri;
+    
+    /** Current folder display in the Browser portlet, can be null if it is a server root folder */    
+    private Folder currentFolder;
+    
+    /** Server object associated to the current folder */
+    private Server currentServer;
+
+    /** Current cms object display in the Browser porlet, can be null if there is no "edited" cms object  */
+    private CmsObject currentCmsObject;
+    
+    /** Document children found in the current folder */ 
+    private Collection documents;
+
+    /** Folder children found in the current folder */
+    private Collection folders;
+    
+    /** Template to redirect to */
+    private String template;
+    
+    /** All document types that can be created */ 
+    private ArrayList documentTypes = new ArrayList();
+    
+    /** All document languages can be used */
+    private Collection languages = new ArrayList();
+    
+    public static final String INSERT = "insert";
+    
+    public static final String UPDATE = "update";
+    
+    public static final String DELETE = "delete";
+    
+    private String operation; 
+    
+    /**
+     * Contructor 
+     * 
+     * @param uri The uri assigned to the cms object displayed in the Browser 
+     * @param documentTypes list of all available document types   
+     * @param languages list of all available languages
+     */
+    public BrowserDTO (String uri, Collection documentTypes, Collection languages)
+    {
+         this.uri = uri;
+         this.documentTypes.addAll(documentTypes);
+         this.languages.addAll(languages);
+    }
+    
+    
+    /**
+     * Get the uri associated to the cms object display in the Browser
+     * @return The uri
+     */
+    public String getUri()
+    {
+        return uri;
+    }
+    /**
+     * Get all document type that can be created in this Graffito application
+     * @return all document types (collection of String)
+     */
+    public Collection getDocumentTypes()
+    {
+         return documentTypes;    
+    }
+
+    /**
+     * Get all document type that can be created in this Graffito application
+     * @return all document types (collection of String)
+     */
+    public Collection getDocumentLanguages()
+    {
+         return languages;    
+    }
+    
+    /**
+     * @return Returns the document children.
+     */
+    public Collection getDocuments()
+    {
+        return documents;
+    }
+
+    /**
+     * @param documents The document children to set.
+     */
+    public void setDocuments(Collection documents)
+    {
+        this.documents = documents;
+    }
+
+    /**
+     * @return Returns the folders children.
+     */
+    public Collection getFolders()
+    {
+        return folders;
+    }
+
+    /**
+     * @param folders The folders to set.
+     */
+    public void setFolders(Collection folders)
+    {
+        this.folders = folders;
+    }
+
+    /** 
+     * @param currentCmsObject Current Cms object to set
+     */
+    public void setCurrentCmsObject(CmsObject currentCmsObject)
+    {
+        this.currentCmsObject = currentCmsObject;
+    }
+    
+    /**
+     * @return the current folder
+     */
+    public Folder getCurrentFolder()
+    {
+        return currentFolder;
+    }
+    
+    /**
+     * @param currentFolder The current folder to set
+     */
+    public void setCurrentFolder(Folder currentFolder)
+    {
+        this.currentFolder = currentFolder;
+    }
+    
+    /**
+     * @return the current cms object
+     */
+    public CmsObject getCurrentCmsObject()
+    {
+        return currentCmsObject;
+    }
+    
+    /**
+     * @return the current server
+     */
+    public Server getCurrentServer()
+    {
+        return currentServer;
+    }
+    
+    /**
+     * 
+     * @param currentServer The current server to set
+     */
+    public void setCurrentServer(Server currentServer)
+    {
+        this.currentServer = currentServer;
+    }
+    
+    public ArrayList getFolderPath()
+    {
+        ArrayList cmsPath = new ArrayList();
+        if (currentFolder != null)
+        {
+            cmsPath.add(currentFolder);
+            Folder parentFolder = currentFolder.getParentFolder();
+            while (parentFolder != null)
+            {
+                cmsPath.add(0, parentFolder);
+                parentFolder = parentFolder.getParentFolder();
+            }
+        }
+        
+        if (currentCmsObject instanceof Document)
+        {
+            cmsPath.add(currentCmsObject);
+        }
+        
+        return cmsPath;
+        
+    }
+    
+        
+    public String getOperation()
+    {
+        return operation;
+    }
+    
+    public void setOperation(String operation)
+    {
+        this.operation = operation;
+    }
+    
+    public String getTemplate()
+    {
+        return template;
+    }
+    
+    public void setTemplate(String template)
+    {
+        this.template = template;
+    }
+    
+    /**
+     * @return true if the Browser is empty, else false
+     */
+    public boolean isEmpty()
+    {
+        if ((((documents == null) || (documents.size() == 0))) &&
+            (((folders == null) || (folders.size() == 0)))) 
+        {
+            return true;
+        }
+        else 
+        {
+            return false;
+        }
+    }
+    
+    public boolean isUpdate()
+    {
+        if (this.operation == null)
+        {
+            return false ;
+        }        
+        return this.operation.equals(UPDATE);
+    }
+    
+    public boolean isInsert()
+    {
+        
+        if (this.operation == null)
+        {
+            return false ;
+        }
+        return this.operation.equals(INSERT);
+    }
+            
+}
\ No newline at end of file

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/ServiceUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/ServiceUtil.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/ServiceUtil.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/services/ServiceUtil.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.portlets.services;
+
+import org.apache.jetspeed.services.JetspeedPortletServices;
+import org.apache.jetspeed.services.PortletServices;
+import org.apache.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.ContentServerService;
+
+/**
+ * Utility class used to access to Graffito services
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class ServiceUtil
+{
+      public static ContentModelService getModelService()
+      {
+          PortletServices services = JetspeedPortletServices.getSingleton();
+          return (ContentModelService) services.getService("ContentModel");
+      }
+
+      public static ContentServerService getServerService()
+      {
+          PortletServices services = JetspeedPortletServices.getSingleton();
+          return (ContentServerService) services.getService("ContentServer");
+      }
+      
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletDiskFileUpload.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletDiskFileUpload.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletDiskFileUpload.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletDiskFileUpload.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+
+package org.apache.portals.graffito.portlets.upload;
+
+
+import java.io.File;
+import java.util.List;
+import javax.portlet.ActionRequest;
+
+import org.apache.commons.fileupload.DefaultFileItemFactory;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.FileUploadException;
+
+
+
+/**
+ * <p>High level API for processing file uploads.</p>
+ *
+ * <p>This class handles multiple files per single HTML widget, sent using
+ * <code>multipart/mixed</code> encoding type, as specified by
+ * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Use {@link
+ * #parseRequest(HttpServletRequest)} to acquire a list of {@link
+ * org.apache.commons.fileupload.FileItem}s associated with a given HTML
+ * widget.</p>
+ *
+ * <p>Individual parts will be stored in temporary disk storage or in memory,
+ * depending on their size, and will be available as {@link
+ * org.apache.commons.fileupload.FileItem}s.</p>
+ *
+ * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
+ * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
+ * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
+ * @author Sean C. Sullivan
+ *
+ * @version $Id: Exp $
+ */
+public class PortletDiskFileUpload
+    extends PortletFileUploadBase
+ {
+
+    // ----------------------------------------------------------- Data members
+
+
+    /**
+     * The factory to use to create new form items.
+     */
+    private DefaultFileItemFactory fileItemFactory;
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Constructs an instance of this class which uses the default factory to
+     * create <code>FileItem</code> instances.
+     *
+     * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
+     */
+    public PortletDiskFileUpload()
+    {
+        super();
+        this.fileItemFactory = new DefaultFileItemFactory();
+    }
+
+
+    /**
+     * Constructs an instance of this class which uses the supplied factory to
+     * create <code>FileItem</code> instances.
+     *
+     * @see #DiskFileUpload()
+     */
+    public PortletDiskFileUpload(DefaultFileItemFactory fileItemFactory)
+    {
+        super();
+        this.fileItemFactory = fileItemFactory;
+    }
+
+
+    // ----------------------------------------------------- Property accessors
+
+
+    /**
+     * Returns the factory class used when creating file items.
+     *
+     * @return The factory class for new file items.
+     */
+    public FileItemFactory getFileItemFactory()
+    {
+        return fileItemFactory;
+    }
+
+
+    /**
+     * Sets the factory class to use when creating file items. The factory must
+     * be an instance of <code>DefaultFileItemFactory</code> or a subclass
+     * thereof, or else a <code>ClassCastException</code> will be thrown.
+     *
+     * @param factory The factory class for new file items.
+     */
+    public void setFileItemFactory(FileItemFactory factory)
+    {
+        this.fileItemFactory = (DefaultFileItemFactory) factory;
+    }
+
+
+    /**
+     * Returns the size threshold beyond which files are written directly to
+     * disk.
+     *
+     * @return The size threshold, in bytes.
+     *
+     * @see #setSizeThreshold(int)
+     */
+    public int getSizeThreshold()
+    {
+        return fileItemFactory.getSizeThreshold();
+    }
+
+
+    /**
+     * Sets the size threshold beyond which files are written directly to disk.
+     *
+     * @param sizeThreshold The size threshold, in bytes.
+     *
+     * @see #getSizeThreshold()
+     */
+    public void setSizeThreshold(int sizeThreshold)
+    {
+        fileItemFactory.setSizeThreshold(sizeThreshold);
+    }
+
+
+    /**
+     * Returns the location used to temporarily store files that are larger
+     * than the configured size threshold.
+     *
+     * @return The path to the temporary file location.
+     *
+     * @see #setRepositoryPath(String)
+     */
+    public String getRepositoryPath()
+    {
+        return fileItemFactory.getRepository().getPath();
+    }
+
+
+    /**
+     * Sets the location used to temporarily store files that are larger
+     * than the configured size threshold.
+     *
+     * @param repositoryPath The path to the temporary file location.
+     *
+     * @see #getRepositoryPath()
+     */
+    public void setRepositoryPath(String repositoryPath)
+    {
+        fileItemFactory.setRepository(new File(repositoryPath));
+    }
+
+
+    // --------------------------------------------------------- Public methods
+
+
+    /**
+     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+     * compliant <code>multipart/form-data</code> stream. If files are stored
+     * on disk, the path is given by <code>getRepository()</code>.
+     *
+     * @param req           The servlet request to be parsed. Must be non-null.
+     * @param sizeThreshold The max size in bytes to be stored in memory.
+     * @param sizeMax       The maximum allowed upload size, in bytes.
+     * @param path          The location where the files should be stored.
+     *
+     * @return A list of <code>FileItem</code> instances parsed from the
+     *         request, in the order that they were transmitted.
+     *
+     * @exception FileUploadException if there are problems reading/parsing
+     *                                the request or storing files.
+     */
+    public List parseRequest(ActionRequest req, int sizeThreshold, long sizeMax, String path)
+        throws FileUploadException
+    {
+        setSizeThreshold(sizeThreshold);
+        setSizeMax(sizeMax);
+        setRepositoryPath(path);
+        return parseRequest(req);
+    }
+
+}

Added: incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUpload.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUpload.java?view=auto&rev=156344
==============================================================================
--- incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUpload.java (added)
+++ incubator/graffito/trunk/applications/browser/src/java/org/apache/portals/graffito/portlets/upload/PortletFileUpload.java Sun Mar  6 14:27:53 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+
+package org.apache.portals.graffito.portlets.upload;
+
+import org.apache.commons.fileupload.FileItemFactory;
+
+
+/**
+ * <p>High level API for processing file uploads.</p>
+ *
+ * <p>This class handles multiple files per single HTML widget, sent using
+ * <code>multipart/mixed</code> encoding type, as specified by
+ * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Use {@link
+ * #parseRequest(HttpServletRequest)} to acquire a list of {@link
+ * org.apache.commons.fileupload.FileItem}s associated with a given HTML
+ * widget.</p>
+ *
+ * <p>How the data for individual parts is stored is determined by the factory
+ * used to create them; a given part may be in memory, on disk, or somewhere
+ * else.</p>
+ *
+ * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
+ * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
+ * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
+ * @author Sean C. Sullivan
+ *
+ * @version $Id: PortletFileUpload.java,v 1.1 2003/10/01 22:21:43 jsackett Exp $
+ */
+public class PortletFileUpload
+    extends PortletFileUploadBase
+ {
+
+    // ----------------------------------------------------------- Data members
+
+
+    /**
+     * The factory to use to create new form items.
+     */
+    private FileItemFactory fileItemFactory;
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Constructs an instance of this class which uses the default factory to
+     * create <code>FileItem</code> instances.
+     *
+     * @see #FileUpload(FileItemFactory)
+     */
+    public PortletFileUpload()
+    {
+        super();
+    }
+
+
+    /**
+     * Constructs an instance of this class which uses the supplied factory to
+     * create <code>FileItem</code> instances.
+     *
+     * @see #FileUpload()
+     */
+    public PortletFileUpload(FileItemFactory fileItemFactory)
+    {
+        super();
+        this.fileItemFactory = fileItemFactory;
+    }
+
+
+    // ----------------------------------------------------- Property accessors
+
+
+    /**
+     * Returns the factory class used when creating file items.
+     *
+     * @return The factory class for new file items.
+     */
+    public FileItemFactory getFileItemFactory()
+    {
+        return fileItemFactory;
+    }
+
+
+    /**
+     * Sets the factory class to use when creating file items.
+     *
+     * @param factory The factory class for new file items.
+     */
+    public void setFileItemFactory(FileItemFactory factory)
+    {
+        this.fileItemFactory = factory;
+    }
+
+
+}



Mime
View raw message