portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r815368 - in /portals/applications/webcontent/trunk: webcontent-jar/ webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/ webcontent-war/src/main/webapp/javascript/
Date Tue, 15 Sep 2009 15:34:21 GMT
Author: woonsan
Date: Tue Sep 15 15:34:19 2009
New Revision: 815368

URL: http://svn.apache.org/viewvc?rev=815368&view=rev
Log:
APA-15: Adding reverse proxied url replacement option and auto-resizing option.
If the IFrame portlet has preferences to map the local base path to the remote base url, then
the external url src will be replaced by the local path.

For example, if the following pairs are set by the preferences,

"PROXYREMOTEURL" = "http://portals.apache.org/"
"PROXYLOCALPATH" = "/jetspeed/webcontent/portals/"

then, the IFrame portlet will replace "http://portals.apache.org/"" of the src attribute by
"/jetspeed/webcontent/portals/".

If a portal web site administrator configures a reverse web proxy provider, this feature can
help that case.

Also, the portlet can have "AUTORESIZE" preference. If this preference is set to true, then
the portlet will try to resize the height of the iframe based on the content height.
This "AUTORESIZE" preference option will not work if the iframe src url is in a different
domain url and it can make script errors.
So, if you want to use "AUTORESIZE" option with external domain urls, then you might consider
reverse proxied url option mentioned above.

Added:
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
  (with props)
Modified:
    portals/applications/webcontent/trunk/webcontent-jar/pom.xml
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java

Modified: portals/applications/webcontent/trunk/webcontent-jar/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/pom.xml?rev=815368&r1=815367&r2=815368&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/pom.xml (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/pom.xml Tue Sep 15 15:34:19 2009
@@ -37,6 +37,7 @@
     <junit.version>3.8.1</junit.version>
     <nekohtml.version>0.9.5</nekohtml.version>
     <castor.version>1.1.1-xml</castor.version>
+    <commons-lang.version>2.4</commons-lang.version>
     <commons-httpclient.version>3.0.1</commons-httpclient.version>
   </properties>
 
@@ -97,6 +98,11 @@
       <version>${nekohtml.version}</version>
     </dependency>
     <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>${commons-lang.version}</version>
+    </dependency>
+    <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>${commons-httpclient.version}</version>

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=815368&r1=815367&r2=815368&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
Tue Sep 15 15:34:19 2009
@@ -29,6 +29,8 @@
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
 
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 
 /**
@@ -48,6 +50,8 @@
     {
         super.init(config);
         attributes.put("SRC", "http://www.apache.org");
+        attributes.put("PROXYREMOTEURL", "");
+        attributes.put("PROXYLOCALPATH", "");
         attributes.put("ALIGN", "BOTTOM");
         attributes.put("CLASS", "");
         attributes.put("FRAMEBORDER", "0");
@@ -55,6 +59,8 @@
         attributes.put("MARGINHEIGHT", "0");
         attributes.put("MARGINWIDTH", "0");
         attributes.put("NAME", "");
+        attributes.put("AUTORESIZE", "false");
+        attributes.put("AUTORESIZESCRIPT", "");
 
         attributes.put("HEIGHT", "");
         attributes.put("WIDTH", "100%");
@@ -133,7 +139,7 @@
         String source = getURLSource(request, response, prefs);
         // generate HTML IFRAME content
         StringBuffer content = new StringBuffer(4096);
-
+        
         // fix JS2-349
         content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY
CLASS='iframePortletTbodyContainer'><TR><TD>");
 
@@ -149,6 +155,8 @@
         appendAttribute(prefs, content, "MARGINHEIGHT");
         appendAttribute(prefs, content, "MARGINWIDTH");
         appendAttribute(prefs, content, "NAME");
+        appendAttribute(prefs, content, "AUTORESIZE");
+        
         if (request.getWindowState().equals(WindowState.MAXIMIZED))
         {
             appendMaxAttribute(prefs, content, "HEIGHT");
@@ -171,6 +179,19 @@
         // end fix JS2-349
         content.append("</TD></TR></TBODY></TABLE>");
 
+        String autoResize = getAttributePreference(prefs, "AUTORESIZE");
+        String autoResizeScript = getAttributePreference(prefs, "AUTORESIZESCRIPT");
+        
+        if (StringUtils.isBlank(autoResizeScript))
+        {
+            autoResizeScript = request.getContextPath() + "/javascript/iframe_autoresize.js";
+        }
+        
+        if (BooleanUtils.toBoolean(autoResize))
+        {
+            content.append("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"").append(autoResizeScript).append("\"></SCRIPT>\n");
+        }
+        
         // set required content type and write HTML IFRAME content
         response.setContentType("text/html");
         response.getWriter().print(content.toString());
@@ -179,7 +200,23 @@
     public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences
prefs)
     {
         String source = getAttributePreference(prefs, "SRC");
-        if (source == null) source = "";
+        
+        // Sometimes, iframe's SRC attribute can be set to a local url to allow cross-domain
scripting.
+        // If proxy remote URL and its corresponding local path are set, then the proxy remote
URL prefix
+        // should be replaced by the local path.
+        
+        String proxyRemoteURL = getAttributePreference(prefs, "PROXYREMOTEURL");
+        String proxyLocalPath = getAttributePreference(prefs, "PROXYLOCALPATH");
+
+        if (source == null) 
+        {
+            source = "";
+        }
+        else if (StringUtils.isNotEmpty(proxyRemoteURL) && StringUtils.isNotEmpty(proxyLocalPath)
&& source.startsWith(proxyRemoteURL))
+        {
+            source = proxyLocalPath + source.substring(proxyRemoteURL.length());
+        }
+        
         return source;
     }
 

Added: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js?rev=815368&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
(added)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
Tue Sep 15 15:34:19 2009
@@ -0,0 +1,55 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+*/
+function iframePortlet_resetHeight(iframe, bindEvent) {
+    if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) {
+        iframe.height = iframe.contentDocument.body.offsetHeight + 16;
+    } else if (iframe.Document && iframe.Document.body.scrollHeight) {
+        iframe.height = iframe.Document.body.scrollHeight;
+    }
+    if (bindEvent) {
+        if (window.addEventListener) {
+            iframe.addEventListener("load", iframePortlet_iframeOnLoad, false);
+        } else if (window.attachEvent) {
+            iframe.detachEvent("onload", iframePortlet_iframeOnLoad);;
+            iframe.attachEvent("onload", iframePortlet_iframeOnLoad);
+        }
+    }
+}
+function iframePortlet_iframeOnLoad(evt) {
+    var iframe = (window.event ? window.event.srcElement : evt.currentTarget);
+    if (iframe) {
+        iframePortlet_resetHeight(iframe, false);
+    }
+}
+var iframePortlet_iframesContainerOnLoad_working = false;
+function iframePortlet_iframesContainerOnLoad() {
+    if (iframePortlet_iframesContainerOnLoad_working) return;
+    iframePortlet_iframesContainerOnLoad_working = true;
+    var iframes = document.getElementsByTagName("IFRAME");
+    for (var i = 0; i < iframes.length; i++) {
+        var autoResize = "" + iframes[i].getAttribute("autoresize");
+        if (autoResize.match(/^(true)|(yes)|(on)$/i)) {
+            iframePortlet_resetHeight(iframes[i], true);
+        }
+    }
+    iframePortlet_iframesContainerOnLoad_working = false;
+}
+if (window.addEventListener) {
+    window.addEventListener("load", iframePortlet_iframesContainerOnLoad, false);
+} else if (window.attachEvent) {
+    window.attachEvent("onload", iframePortlet_iframesContainerOnLoad)
+}

Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message