portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r819646 - /portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
Date Mon, 28 Sep 2009 17:09:37 GMT
Author: woonsan
Date: Mon Sep 28 17:09:37 2009
New Revision: 819646

URL: http://svn.apache.org/viewvc?rev=819646&view=rev
Log:
APA-17: Makes it work under both Portlet 1.0 and Portlet 2.0 environments.

Modified:
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java?rev=819646&r1=819645&r2=819646&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
Mon Sep 28 17:09:37 2009
@@ -27,6 +27,7 @@
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
 import javax.portlet.PortletPreferences;
+import javax.portlet.PortletURL;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.ResourceRequest;
@@ -35,6 +36,7 @@
 import javax.portlet.WindowState;
 
 import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 import org.apache.portals.messaging.PortletMessaging;
@@ -56,11 +58,14 @@
     private Map<String, String> attributes = new HashMap<String, String>();
 
     private Map<String, String> maxAttributes = new HashMap<String, String>();
+    
+    private boolean isPortlet10Container;
 
     @Override
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
+        
         attributes.put("SRC", "http://www.apache.org");
         attributes.put("PROXYREMOTEURL", "");
         attributes.put("PROXYLOCALPATH", "");
@@ -84,6 +89,15 @@
         maxAttributes.put("WIDTH", "100%");
         maxAttributes.put("SCROLLING", "AUTO");
         maxAttributes.put("STYLE", "");
+        
+        try
+        {
+            ClassUtils.getPublicMethod(PortletConfig.class, "getDefaultNamespace", new Class[0]);
+        }
+        catch (Throwable ignorable)
+        {
+            isPortlet10Container = true;
+        }
     }
 
     private String getAttributePreference(PortletPreferences prefs, String attribute)
@@ -221,12 +235,23 @@
         {
             appendAttribute(prefs, content, "VISITLASTPAGE");
             
-            // append a resource url string as an attribute to enable the handler javascript
to invoke.
-            ResourceURL visitPageResourceURL = response.createResourceURL();
-            visitPageResourceURL.setResourceID("visit");
-            content.append(" ").append("visitresourceurl").append("=\"");
-            visitPageResourceURL.write(content, true);
-            content.append("\"");
+            if (!isPortlet10Container)
+            {
+                // append a resource url string as an attribute to enable the handler javascript
to invoke.
+                ResourceURL visitPageResourceURL = response.createResourceURL();
+                visitPageResourceURL.setResourceID("visit");
+                content.append(" ").append("visitresourceurl").append("=\"");
+                visitPageResourceURL.write(content, true);
+                content.append("\"");
+            }
+            else
+            {
+                PortletURL visitPageActionURL = response.createActionURL();
+                visitPageActionURL.setParameter("action", "visit");
+                content.append(" ").append("visitresourceurl").append("=\"");
+                content.append(visitPageActionURL.toString());
+                content.append("\"");
+            }
         }
         
         if (request.getWindowState().equals(WindowState.MAXIMIZED))
@@ -251,7 +276,28 @@
 
         // end fix JS2-349
         content.append("</TD></TR></TBODY></TABLE>");
-
+        
+        if (isPortlet10Container)
+        {
+            boolean autoResize = BooleanUtils.toBoolean(getAttributePreference(prefs, "AUTORESIZE"));
+            boolean visitLastPage = BooleanUtils.toBoolean(getAttributePreference(prefs,
"VISITLASTPAGE"));
+            
+            if (autoResize || visitLastPage)
+            {
+                String handlerScript = getAttributePreference(prefs, "HANDLERSCRIPT");
+                
+                if (StringUtils.isBlank(handlerScript))
+                {
+                    handlerScript = request.getContextPath() + "/javascript/iframe_handler.js";
+                }
+                
+                content.append("\n<script id=\"").append(IFRAME_AUTORESIZE_SCRIPT_ID).append("\"
");
+                content.append("language=\"JavaScript\" type=\"text/javascript\" ");
+                content.append("src=\"").append(handlerScript).append("\">");
+                content.append("</script>\n");
+            }
+        }
+        
         // set required content type and write HTML IFRAME content
         response.setContentType("text/html");
         response.getWriter().print(content.toString());
@@ -299,7 +345,19 @@
     public void processAction(ActionRequest request, ActionResponse actionResponse) throws
PortletException,
             IOException
     {
-        processPreferencesAction(request, actionResponse);
+        if ("visit".equals(request.getParameter("action")))
+        {
+            String url = request.getParameter("URL");
+            
+            if (!StringUtils.isBlank(url))
+            {
+                PortletMessaging.publish(request, IFRAME_SRC_URL, url.trim());
+            }
+        }
+        else
+        {
+            processPreferencesAction(request, actionResponse);
+        }
     }
 
 }



Mime
View raw message