portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r883815 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/custom/ webapp/WEB-INF/view/custom/ webapp/images/preview/
Date Tue, 24 Nov 2009 19:00:31 GMT
Author: woonsan
Date: Tue Nov 24 19:00:30 2009
New Revision: 883815

URL: http://svn.apache.org/viewvc?rev=883815&view=rev
Log:
JS2-1086: Adding a default preview image and refining delegatee preview page.

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/images/preview/
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/images/preview/preview-na.png
  (with props)
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomPreviewModePortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/preview-mode.jsp

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomPreviewModePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomPreviewModePortlet.java?rev=883815&r1=883814&r2=883815&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomPreviewModePortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomPreviewModePortlet.java
Tue Nov 24 19:00:30 2009
@@ -17,32 +17,52 @@
 package org.apache.jetspeed.portlets.custom;
 
 import java.io.IOException;
+import java.util.Collection;
 
 import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
 import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequestDispatcher;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
 
-import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.om.portlet.LocalizedField;
+import org.apache.jetspeed.om.portlet.PortletDefinition;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.portals.bridges.common.GenericServletPortlet;
 
 /**
  * Common Custom Preview Mode Portlet
  * 
  * @version $Id$
  */
-public class CustomPreviewModePortlet extends GenericVelocityPortlet
+public class CustomPreviewModePortlet extends GenericServletPortlet
 {
+    
+    public static final String PARAM_PREVIEW_PAGE = "PreviewPage";
+    
     private static final PortletMode PREVIEW_MODE = new PortletMode("preview");
     
-    private String previewPage;
+    private String defaultPreviewPage;
+    
+    private boolean allowPreferences;
     
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
         
-        this.previewPage = config.getInitParameter("PreviewPage");
+        this.defaultPreviewPage = config.getInitParameter(PARAM_PREVIEW_PAGE);
+        
+        String allowPreferencesString = config.getInitParameter(PARAM_ALLOW_PREFERENCES);
+        
+        if (allowPreferencesString != null)
+        {
+            allowPreferences = new Boolean(allowPreferencesString).booleanValue();
+        }
     }
     
     protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException,
IOException
@@ -53,8 +73,7 @@
             
             if (PREVIEW_MODE.equals(curMode))
             {
-                request.setAttribute(PARAM_VIEW_PAGE, previewPage);
-                doView(request, response);
+                doPreview(request, response);
             }
             else
             {
@@ -63,4 +82,54 @@
         }
     }
     
+    protected void doPreview(RenderRequest request, RenderResponse response) throws PortletException,
IOException 
+    {
+        String previewImage = "";
+        
+        RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
+        PortletDefinition def = rc.getCurrentPortletWindow().getPortletDefinition();
+        Collection<LocalizedField> colMetaData = null;
+        
+        if (def != null)
+        {
+            colMetaData = def.getMetadata().getFields(PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_PREVIEW_IMAGE);
+        }
+        
+        if (colMetaData != null && !colMetaData.isEmpty())
+        {
+            previewImage = colMetaData.iterator().next().getValue();
+        }
+        
+        request.setAttribute("previewImage", previewImage);
+        
+        String previewPage = this.defaultPreviewPage;
+        
+        // allow PreviewPage override by the request
+        String reqPreviewPage = (String) request.getAttribute(PARAM_PREVIEW_PAGE);
+        
+        if (reqPreviewPage != null)
+        {
+            previewPage = reqPreviewPage;
+        }
+        
+        if (allowPreferences == true)
+        {
+            PortletPreferences prefs = request.getPreferences();
+            
+            if (prefs != null && reqPreviewPage == null)
+            {
+                previewPage = prefs.getValue(PARAM_PREVIEW_PAGE, defaultPreviewPage);
+            }
+        }
+        
+        if (previewPage != null)
+        {
+            PortletContext context = getPortletContext();
+            PortletRequestDispatcher rd = context.getRequestDispatcher(previewPage);
+            rd.include(request, response);
+        }
+        
+        return;
+    }
+    
 }
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/preview-mode.jsp
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/preview-mode.jsp?rev=883815&r1=883814&r2=883815&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/preview-mode.jsp
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/preview-mode.jsp
Tue Nov 24 19:00:30 2009
@@ -12,5 +12,13 @@
 See the License for the specific language governing permissions and
 limitations under the License.
 --%>
-<%@ page language="java" %>
-<img src="/demo/images/preview/pickanumber.png"/>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<c:choose>
+  <c:when test="${not empty previewImage}">
+    <img src="${previewImage}"/>
+  </c:when>
+  <c:otherwise>
+    <c:url var="previewNAImage" value="/images/preview/preview-na.png"/>
+    <img src="${previewNAImage}"/>
+  </c:otherwise>
+</c:choose>
\ No newline at end of file

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/images/preview/preview-na.png
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/images/preview/preview-na.png?rev=883815&view=auto
==============================================================================
Binary file - no diff available.

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/images/preview/preview-na.png
------------------------------------------------------------------------------
    svn:mime-type = image/png



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message