You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2009/09/21 14:18:05 UTC
svn commit: r817219 - in /portals/applications/webcontent/trunk:
webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/
webcontent-war/src/main/webapp/WEB-INF/
webcontent-war/src/main/webapp/javascript/
Author: woonsan
Date: Mon Sep 21 12:18:04 2009
New Revision: 817219
URL: http://svn.apache.org/viewvc?rev=817219&view=rev
Log:
APA-17: Adding the last visited page feature.
I chose to use client-side script to invoke resource url to set a portlet session attribute for storing the last visited page.
If I choose a server-side solution with reverse proxy component, then it will not work with other proxy server solutions.
Added:
portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js (contents, props changed)
- copied, changed from r816527, portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
Removed:
portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js
Modified:
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml
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=817219&r1=817218&r2=817219&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 21 12:18:04 2009
@@ -17,6 +17,7 @@
package org.apache.portals.applications.webcontent.portlet;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
@@ -28,11 +29,15 @@
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
import javax.portlet.WindowState;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.messaging.PortletMessaging;
import org.w3c.dom.Element;
/**
@@ -45,7 +50,9 @@
{
public static final String IFRAME_AUTORESIZE_SCRIPT_ID = "org.apache.portals.applications.webcontent.portlet.iframe.autoresize";
-
+
+ public static final String IFRAME_SRC_URL = "org.apache.portals.applications.webcontent.portlet.iframe.src";
+
private Map<String, String> attributes = new HashMap<String, String>();
private Map<String, String> maxAttributes = new HashMap<String, String>();
@@ -65,7 +72,8 @@
attributes.put("MARGINWIDTH", "0");
attributes.put("NAME", "");
attributes.put("AUTORESIZE", "false");
- attributes.put("AUTORESIZESCRIPT", "");
+ attributes.put("VISITLASTPAGE", "false");
+ attributes.put("HANDLERSCRIPT", "");
attributes.put("HEIGHT", "");
attributes.put("WIDTH", "100%");
@@ -93,7 +101,7 @@
return prefs.getValue(attribute, map.get(attribute));
}
- private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute, Map<String, String> map)
+ private void appendAttribute(PortletPreferences prefs, StringWriter content, String attribute, Map<String, String> map)
{
String value;
@@ -106,12 +114,12 @@
content.append(" ").append(attribute).append("=\"").append(value).append("\"");
}
- private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
+ private void appendAttribute(PortletPreferences prefs, StringWriter content, String attribute)
{
appendAttribute(prefs, content, attribute, attributes);
}
- private void appendMaxAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
+ private void appendMaxAttribute(PortletPreferences prefs, StringWriter content, String attribute)
{
appendAttribute(prefs, content, attribute, maxAttributes);
}
@@ -120,21 +128,23 @@
protected void doHeaders(RenderRequest request, RenderResponse response)
{
PortletPreferences prefs = request.getPreferences();
- String autoResize = getAttributePreference(prefs, "AUTORESIZE");
- String autoResizeScript = getAttributePreference(prefs, "AUTORESIZESCRIPT");
+ boolean autoResize = BooleanUtils.toBoolean(getAttributePreference(prefs, "AUTORESIZE"));
+ boolean visitLastPage = BooleanUtils.toBoolean(getAttributePreference(prefs, "VISITLASTPAGE"));
- if (BooleanUtils.toBoolean(autoResize))
+ if (autoResize || visitLastPage)
{
- if (StringUtils.isBlank(autoResizeScript))
+ String handlerScript = getAttributePreference(prefs, "HANDLERSCRIPT");
+
+ if (StringUtils.isBlank(handlerScript))
{
- autoResizeScript = request.getContextPath() + "/javascript/iframe_autoresize.js";
+ handlerScript = request.getContextPath() + "/javascript/iframe_handler.js";
}
Element headElem = response.createElement("script");
headElem.setAttribute("id", IFRAME_AUTORESIZE_SCRIPT_ID);
headElem.setAttribute("language", "JavaScript");
headElem.setAttribute("type", "text/javascript");
- headElem.setAttribute("src", autoResizeScript);
+ headElem.setAttribute("src", handlerScript);
response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
}
}
@@ -152,14 +162,30 @@
doIFrame(request, response);
}
}
-
+
@Override
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
{
response.setContentType("text/html");
doPreferencesEdit(request, response);
}
-
+
+ @Override
+ public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException
+ {
+ String resourceId = request.getResourceID();
+
+ if ("visit".equals(resourceId))
+ {
+ String url = request.getParameter("URL");
+
+ if (!StringUtils.isBlank(url))
+ {
+ PortletMessaging.publish(request, IFRAME_SRC_URL, url.trim());
+ }
+ }
+ }
+
/**
* Render IFRAME content
*/
@@ -168,7 +194,7 @@
PortletPreferences prefs = request.getPreferences();
String source = getURLSource(request, response, prefs);
// generate HTML IFRAME content
- StringBuffer content = new StringBuffer(4096);
+ StringWriter content = new StringWriter(4096);
// fix JS2-349
content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY CLASS='iframePortletTbodyContainer'><TR><TD>");
@@ -185,7 +211,23 @@
appendAttribute(prefs, content, "MARGINHEIGHT");
appendAttribute(prefs, content, "MARGINWIDTH");
appendAttribute(prefs, content, "NAME");
- appendAttribute(prefs, content, "AUTORESIZE");
+
+ if (BooleanUtils.toBoolean(getAttributePreference(prefs, "AUTORESIZE")))
+ {
+ appendAttribute(prefs, content, "AUTORESIZE");
+ }
+
+ if (BooleanUtils.toBoolean(getAttributePreference(prefs, "VISITLASTPAGE")))
+ {
+ 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 (request.getWindowState().equals(WindowState.MAXIMIZED))
{
@@ -201,6 +243,7 @@
appendAttribute(prefs, content, "SCROLLING");
appendAttribute(prefs, content, "STYLE");
}
+
content.append(">");
content.append("<P STYLE=\"textAlign:center\"><A HREF=\"").append(source).append("\">").append(source).append(
"</A></P>");
@@ -216,7 +259,12 @@
public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences prefs)
{
- String source = getAttributePreference(prefs, "SRC");
+ String source = (String) PortletMessaging.receive(request, IFRAME_SRC_URL);
+
+ if (source == null)
+ {
+ source = getAttributePreference(prefs, "SRC");
+ }
// 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
@@ -224,7 +272,7 @@
String proxyRemoteURL = getAttributePreference(prefs, "PROXYREMOTEURL");
String proxyLocalPath = getAttributePreference(prefs, "PROXYLOCALPATH");
-
+
if (source == null)
{
source = "";
Modified: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml?rev=817219&r1=817218&r2=817219&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml Mon Sep 21 12:18:04 2009
@@ -57,11 +57,16 @@
<name>SRC</name>
<value>http://portals.apache.org/</value>
</preference>
- <!-- You can set AUTORESIZE to true when the SRC is in the same domain of the portal web pages. -->
+ <!-- You can set AUTORESIZE to true when the SRC can be in the same domain of the portal web pages. -->
<preference>
<name>AUTORESIZE</name>
<value>false</value>
</preference>
+ <!-- You can set VISITLASTPAGE to true when the SRC can be in the same domain of the portal web pages. -->
+ <preference>
+ <name>VISITLASTPAGE</name>
+ <value>false</value>
+ </preference>
<!--
Don't specify a HEIGHT if you want a normal filled out layout
because percentage values result in the content not to be
@@ -140,6 +145,10 @@
<name>AUTORESIZE</name>
<value>true</value>
</preference>
+ <preference>
+ <name>VISITLASTPAGE</name>
+ <value>true</value>
+ </preference>
<!--
Don't specify a HEIGHT if you want a normal filled out layout
because percentage values result in the content not to be
Copied: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js (from r816527, 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_handler.js?p2=portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js&p1=portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js&r1=816527&r2=817219&rev=817219&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_autoresize.js (original)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js Mon Sep 21 12:18:04 2009
@@ -14,20 +14,37 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
-function iframePortlet_resetHeight(iframe, bindEvent) {
+function iframePortlet_resetHeight(iframe) {
try {
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);
- }
+ } catch (e) {
+ }
+}
+function iframePortlet_onreadystatechange() {
+}
+function iframePortlet_recordVisitPage(iframe) {
+ try {
+ var xmlHttp = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
+ var visitResourceURL = "" + iframe.getAttribute("visitresourceurl");
+ visitResourceURL += (visitResourceURL.indexOf("?") > 0 ? "&" : "?");
+ visitResourceURL += ("URL=" + iframe.contentWindow.location.href);
+ xmlHttp.open("GET", visitResourceURL, true);
+ xmlHttp.onreadystatechange = iframePortlet_onreadystatechange;
+ xmlHttp.send(null);
+ } catch (e) {
+ }
+}
+function iframePortlet_attachEvents(iframe) {
+ try {
+ if (window.addEventListener) {
+ iframe.addEventListener("load", iframePortlet_iframeOnLoad, false);
+ } else if (window.attachEvent) {
+ iframe.detachEvent("onload", iframePortlet_iframeOnLoad);;
+ iframe.attachEvent("onload", iframePortlet_iframeOnLoad);
}
} catch (e) {
}
@@ -35,7 +52,14 @@
function iframePortlet_iframeOnLoad(evt) {
var iframe = (window.event ? window.event.srcElement : evt.currentTarget);
if (iframe) {
- iframePortlet_resetHeight(iframe, false);
+ var autoResize = "" + iframe.getAttribute("autoresize");
+ if (autoResize.match(/^(true)|(yes)|(on)$/i)) {
+ iframePortlet_resetHeight(iframe);
+ }
+ var visitLastPage = "" + iframe.getAttribute("visitlastpage");
+ if (visitLastPage.match(/^(true)|(yes)|(on)$/i)) {
+ iframePortlet_recordVisitPage(iframe);
+ }
}
}
var iframePortlet_iframesContainerOnLoad_working = false;
@@ -46,8 +70,13 @@
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_resetHeight(iframes[i]);
+ }
+ var visitLastPage = "" + iframes[i].getAttribute("visitlastpage");
+ if (visitLastPage.match(/^(true)|(yes)|(on)$/i)) {
+ iframePortlet_recordVisitPage(iframes[i]);
}
+ iframePortlet_attachEvents(iframes[i]);
}
iframePortlet_iframesContainerOnLoad_working = false;
}
Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/javascript/iframe_handler.js
------------------------------------------------------------------------------
svn:mime-type = text/plain