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 ta...@apache.org on 2009/04/13 23:18:01 UTC

svn commit: r764612 [1/5] - in /portals/applications/webcontent: ./ trunk/ trunk/webcontent-jar/ trunk/webcontent-jar/src/ trunk/webcontent-jar/src/main/ trunk/webcontent-jar/src/main/java/ trunk/webcontent-jar/src/main/java/org/ trunk/webcontent-jar/s...

Author: taylor
Date: Mon Apr 13 21:17:59 2009
New Revision: 764612

URL: http://svn.apache.org/viewvc?rev=764612&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-966

Added:
    portals/applications/webcontent/
    portals/applications/webcontent/trunk/
    portals/applications/webcontent/trunk/pom.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/
    portals/applications/webcontent/trunk/webcontent-jar/pom.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/xml/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/xml/SaxParserAdaptor.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/util/
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/util/Streams.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/log4j.properties   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/rewriter/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/rewriter/RewriterTestCase.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/rewriter/TestNekoRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/rewriter/TestRewriterController.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/rewriter/UnitTestRewriter.java   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/rewriter/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/rewriter/default-rewriter-rules.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/rewriter/test-001.html   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/rewriter/test-remove-rules.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/rewriter/test-rewriter-rules.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-jar/src/test/webapp/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/webapp/WEB-INF/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/webapp/WEB-INF/conf/
    portals/applications/webcontent/trunk/webcontent-jar/src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-war/
    portals/applications/webcontent/trunk/webcontent-war/pom.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/
    portals/applications/webcontent/trunk/webcontent-war/src/main/
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/log4j.properties   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/velocity/
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/velocity/toolbox.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/velocity/velocity-macros.vm   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/velocity/velocity.properties   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml   (with props)
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/logs/

Added: portals/applications/webcontent/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/pom.xml?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/pom.xml (added)
+++ portals/applications/webcontent/trunk/pom.xml Mon Apr 13 21:17:59 2009
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+
+  $Id$
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <prerequisites>
+        <maven>2.0.4</maven>
+    </prerequisites>
+
+    <!-- POM Identification -->
+    <parent>
+        <groupId>org.apache.portals</groupId>
+        <artifactId>applications-pom</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>org.apache.portals.applications</groupId>
+    <artifactId>apa-webcontent</artifactId>
+    <packaging>pom</packaging>
+    <name>Portals Web Content Application</name>
+    <description>
+        Web Content Application
+    </description>
+
+	<properties>
+		<portlet-api.version>2.0</portlet-api.version>
+		<javax.servlet.version>2.4</javax.servlet.version>
+		<org.apache.portals.bridges.velocity.version>1.0.4</org.apache.portals.bridges.velocity.version>
+		<xalan.version>2.4.1</xalan.version>
+		<xerces.version>2.3.0</xerces.version>
+		<xml-apis.version>2.0.2</xml-apis.version>
+		<commons-logging.version>1.1</commons-logging.version>
+		<portlet-api.version>1.0</portlet-api.version>
+		<javax.servlet.version>2.4</javax.servlet.version>
+	    <junit.version>3.8.1</junit.version>
+	    <xml-apis.version>2.0.2</xml-apis.version>
+	
+	    <nekohtml.version>0.9.5</nekohtml.version>
+	    <castor.version>1.1.1-xml</castor.version>
+	    <commons-httpclient.version>3.0.1</commons-httpclient.version>
+	
+	</properties>
+    <!-- Application Modules -->
+
+    <modules>
+        <module>webcontent-jar</module>
+        <module>webcontent-war</module>
+    </modules>
+
+    <!-- Project Information -->
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/portals/applications/webcontent</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/applications/webcontent</developerConnection>
+        <url>http://svn.apache.org/viewcvs.cgi/portals/applications/webcontent/</url>
+    </scm>
+
+</project>

Propchange: portals/applications/webcontent/trunk/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/pom.xml?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/pom.xml (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/pom.xml Mon Apr 13 21:17:59 2009
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+		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. $Id$
+	-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+	<prerequisites>
+		<maven>2.0.4</maven>
+	</prerequisites>
+
+	<!-- POM Identification -->
+	<parent>
+		<groupId>org.apache.portals.applications</groupId>
+		<artifactId>apa-webcontent</artifactId>
+		<version>1.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>apa-webcontent-jar</artifactId>
+	<packaging>jar</packaging>
+	<name>Portals Web Content Application JAR</name>
+
+	<!-- Dependencies -->
+
+	<dependencies>
+		
+
+		<!-- Build Dependencies -->
+		<dependency>
+			<groupId>javax.portlet</groupId>
+			<artifactId>portlet-api</artifactId>
+			<version>${portlet-api.version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>${javax.servlet.version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.portals.bridges</groupId>
+			<artifactId>portals-bridges-velocity</artifactId>
+			<version>${org.apache.portals.bridges.velocity.version}</version>
+		</dependency>
+        <!-- Build Dependencies -->
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+			<version>${commons-logging.version}</version>            
+        </dependency>
+        <dependency>
+            <groupId>castor</groupId>
+            <artifactId>castor</artifactId>
+        	<version>${castor.version}</version>            
+        </dependency>
+        <dependency>
+            <groupId>nekohtml</groupId>
+            <artifactId>nekohtml</artifactId>
+	        <version>${nekohtml.version}</version>            
+        </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>${commons-httpclient.version}</version>
+        </dependency>
+
+      <dependency> 
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${junit.version}</version>
+        <scope>test</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>junit-addons</groupId>
+            <artifactId>junit-addons-runner</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+
+	</dependencies>
+
+</project>

Propchange: portals/applications/webcontent/trunk/webcontent-jar/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+package org.apache.portals.applications.webcontent.portlet;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+
+/**
+ * IFrameGenericPortlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id$
+ */
+public class IFrameGenericPortlet extends GenericVelocityPortlet
+{
+
+    private Map attributes = new HashMap();
+
+    private Map maxAttributes = new HashMap();
+
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        attributes.put("SRC", "http://www.apache.org");
+        attributes.put("ALIGN", "BOTTOM");
+        attributes.put("CLASS", "");
+        attributes.put("FRAMEBORDER", "0");
+        attributes.put("ID", "");
+        attributes.put("MARGINHEIGHT", "0");
+        attributes.put("MARGINWIDTH", "0");
+        attributes.put("NAME", "");
+
+        attributes.put("HEIGHT", "");
+        attributes.put("WIDTH", "100%");
+        attributes.put("SCROLLING", "NO");
+        attributes.put("STYLE", "");
+
+        maxAttributes.put("HEIGHT", "800");
+        maxAttributes.put("WIDTH", "100%");
+        maxAttributes.put("SCROLLING", "AUTO");
+        maxAttributes.put("STYLE", "");
+    }
+
+    private String getAttributePreference(PortletPreferences prefs, String attribute)
+    {
+        return this.getMappedAttributePreference(prefs, attribute, attributes);
+    }
+
+    private String getMaxAttributePreference(PortletPreferences prefs, String attribute)
+    {
+        return this.getMappedAttributePreference(prefs, "MAX-" + attribute, maxAttributes);
+    }
+
+    private String getMappedAttributePreference(PortletPreferences prefs, String attribute, Map map)
+    {
+        return prefs.getValue(attribute, (String) map.get(attribute));
+    }
+
+    private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute, Map map)
+    {
+        String value;
+
+        if (map == maxAttributes)
+            value = getMaxAttributePreference(prefs, attribute);
+        else
+            value = getAttributePreference(prefs, attribute);
+
+        if (value == null || value.length() == 0) { return; }
+        content.append(" ").append(attribute).append("=\"").append(value).append("\"");
+    }
+
+    private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
+    {
+        appendAttribute(prefs, content, attribute, attributes);
+    }
+
+    private void appendMaxAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
+    {
+        appendAttribute(prefs, content, attribute, maxAttributes);
+    }
+
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        String viewPage = (String)request.getAttribute(PARAM_VIEW_PAGE);
+        if (viewPage != null)
+        {
+            super.doView(request, response);
+        }
+        else
+        {
+            doIFrame(request, response);
+        }
+    }
+
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        response.setContentType("text/html");
+        doPreferencesEdit(request, response);
+    }
+
+    /**
+     * Render IFRAME content
+     */
+    protected void doIFrame(RenderRequest request, RenderResponse response) throws IOException
+    {
+        PortletPreferences prefs = request.getPreferences();
+        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>");
+
+        content.append("<IFRAME");
+
+        // special case source
+        content.append(" ").append("SRC").append("=\"").append(source).append("\"");
+
+        appendAttribute(prefs, content, "ALIGN");
+        appendAttribute(prefs, content, "CLASS");
+        appendAttribute(prefs, content, "FRAMEBORDER");
+        appendAttribute(prefs, content, "ID");
+        appendAttribute(prefs, content, "MARGINHEIGHT");
+        appendAttribute(prefs, content, "MARGINWIDTH");
+        appendAttribute(prefs, content, "NAME");
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            appendMaxAttribute(prefs, content, "HEIGHT");
+            appendMaxAttribute(prefs, content, "WIDTH");
+            appendMaxAttribute(prefs, content, "SCROLLING");
+            appendMaxAttribute(prefs, content, "STYLE");
+        }
+        else
+        {
+            appendAttribute(prefs, content, "HEIGHT");
+            appendAttribute(prefs, content, "WIDTH");
+            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>");
+        content.append("</IFRAME>");
+
+        // end fix JS2-349
+        content.append("</TD></TR></TBODY></TABLE>");
+
+        // set required content type and write HTML IFRAME content
+        response.setContentType("text/html");
+        response.getWriter().print(content.toString());
+    }
+
+    public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences prefs)
+    {
+        String source = getAttributePreference(prefs, "SRC");
+        if (source == null) source = "";
+        return source;
+    }
+
+    /**
+     * Save the prefs
+     */
+    public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException,
+            IOException
+    {
+        processPreferencesAction(request, actionResponse);
+    }
+
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,442 @@
+/*
+ * 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.
+ */
+package org.apache.portals.applications.webcontent.portlet;
+
+import java.io.IOException;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+/**
+ * IFramePortlet
+ *
+ * TODO:
+ * - add capabilities test for IFRAME
+ * - add locale specific "no iframes" message
+ *
+ * @author <a href="mailto:rwatler@finali.com">Randy Watler</a>
+ * @version $Id$
+ */
+public class IFramePortlet extends GenericPortlet
+{
+    /**
+     * Configuration constants.
+     */
+    public static final String ENABLE_SOURCE_PREFERENCES_PARAM = "enableSourcePreferences";
+    public static final String ENABLE_PREFERENCES_PARAM = "enablePreferences";
+    public static final String CUSTOM_SOURCE_PARAM = "customSource";
+    public static final String MAXIMIZED_CUSTOM_SOURCE_PARAM = "maximizedCustomSource";
+    public static final String EDIT_SOURCE_PARAM = "editSource";
+    public static final String MAXIMIZED_EDIT_SOURCE_PARAM = "maximizedEditSource";
+    public static final String HELP_SOURCE_PARAM = "helpSource";
+    public static final String MAXIMIZED_HELP_SOURCE_PARAM = "maximizedHelpSource";
+    public static final String VIEW_SOURCE_PARAM = "viewSource";
+    public static final String MAXIMIZED_VIEW_SOURCE_PARAM = "maximizedViewSource";
+    public static final String ALIGN_ATTR_PARAM = "align";
+    public static final String CLASS_ATTR_PARAM = "class";
+    public static final String FRAME_BORDER_ATTR_PARAM = "frameBorder";
+    public static final String HEIGHT_ATTR_PARAM = "height";
+    public static final String ID_ATTR_PARAM = "id";
+    public static final String MARGIN_HEIGHT_ATTR_PARAM = "marginHeight";
+    public static final String MARGIN_WIDTH_ATTR_PARAM = "marginWidth";
+    public static final String MAXIMIZED_HEIGHT_ATTR_PARAM = "maximizedHeight";
+    public static final String MAXIMIZED_SCROLLING_ATTR_PARAM = "maximizedScrolling";
+    public static final String MAXIMIZED_STYLE_ATTR_PARAM = "maximizedStyle";
+    public static final String MAXIMIZED_WIDTH_ATTR_PARAM = "maximizedWidth";
+    public static final String NAME_ATTR_PARAM = "name";
+    public static final String SCROLLING_ATTR_PARAM = "scrolling";
+    public static final String STYLE_ATTR_PARAM = "style";
+    public static final String WIDTH_ATTR_PARAM = "width";
+
+    /**
+     * Configuration default constants.
+     */
+    public static final String ALIGN_ATTR_DEFAULT = "BOTTOM";
+    public static final String FRAME_BORDER_ATTR_DEFAULT = "0";
+    public static final String HEIGHT_ATTR_DEFAULT = "";
+    public static final String MARGIN_HEIGHT_ATTR_DEFAULT = "0";
+    public static final String MARGIN_WIDTH_ATTR_DEFAULT = "0";
+    public static final String MAXIMIZED_HEIGHT_ATTR_DEFAULT = "100%";
+    public static final String MAXIMIZED_SCROLLING_ATTR_DEFAULT = "AUTO";
+    public static final String MAXIMIZED_WIDTH_ATTR_DEFAULT = "100%";
+    public static final String SCROLLING_ATTR_DEFAULT = "NO";
+    public static final String WIDTH_ATTR_DEFAULT = "100%";
+
+    /**
+     * Enable parameter preferences overrides member.
+     */
+    private boolean enablePreferences;
+
+    /**
+     * Default IFRAME source attribute members.
+     */
+    private String defaultCustomSource;
+    private String defaultMaximizedCustomSource;
+    private String defaultEditSource;
+    private String defaultMaximizedEditSource;
+    private String defaultHelpSource;
+    private String defaultMaximizedHelpSource;
+    private String defaultViewSource;
+    private String defaultMaximizedViewSource;
+
+    /**
+     * Default IFRAME attribute members.
+     */
+    private String defaultAlignAttr;
+    private String defaultClassAttr;
+    private String defaultFrameBorderAttr;
+    private String defaultHeightAttr;
+    private String defaultIdAttr;
+    private String defaultMarginHeightAttr;
+    private String defaultMarginWidthAttr;
+    private String defaultMaximizedHeightAttr;
+    private String defaultMaximizedScrollingAttr;
+    private String defaultMaximizedStyleAttr;
+    private String defaultMaximizedWidthAttr;
+    private String defaultNameAttr;
+    private String defaultScrollingAttr;
+    private String defaultStyleAttr;
+    private String defaultWidthAttr;
+
+    /**
+     * Portlet constructor.
+     */
+    public IFramePortlet()
+    {
+    }
+
+    /**
+     * Initialize portlet configuration.
+     */
+    public void init(PortletConfig config)
+        throws PortletException
+    {
+        super.init(config);
+
+        String initParam = config.getInitParameter(ENABLE_PREFERENCES_PARAM);
+        if (initParam == null)
+        {
+            initParam = config.getInitParameter(ENABLE_SOURCE_PREFERENCES_PARAM);
+        }
+        if (initParam != null)
+        {
+            enablePreferences = (new Boolean(initParam)).booleanValue();
+        }
+
+        defaultCustomSource = config.getInitParameter(CUSTOM_SOURCE_PARAM);
+        defaultMaximizedCustomSource = config.getInitParameter(MAXIMIZED_CUSTOM_SOURCE_PARAM);
+        defaultEditSource = config.getInitParameter(EDIT_SOURCE_PARAM);
+        defaultMaximizedEditSource = config.getInitParameter(MAXIMIZED_EDIT_SOURCE_PARAM);
+        defaultHelpSource = config.getInitParameter(HELP_SOURCE_PARAM);
+        defaultMaximizedHelpSource = config.getInitParameter(MAXIMIZED_HELP_SOURCE_PARAM);
+        defaultViewSource = config.getInitParameter(VIEW_SOURCE_PARAM);
+        defaultMaximizedViewSource = config.getInitParameter(MAXIMIZED_VIEW_SOURCE_PARAM);
+
+        defaultAlignAttr = getAttributeParam(config, ALIGN_ATTR_PARAM, ALIGN_ATTR_DEFAULT);
+        defaultClassAttr = getAttributeParam(config, CLASS_ATTR_PARAM, null);
+        defaultFrameBorderAttr = getAttributeParam(config, FRAME_BORDER_ATTR_PARAM, FRAME_BORDER_ATTR_DEFAULT);
+        defaultHeightAttr = getAttributeParam(config, HEIGHT_ATTR_PARAM, HEIGHT_ATTR_DEFAULT);
+        defaultIdAttr = getAttributeParam(config, ID_ATTR_PARAM, null);
+        defaultMarginHeightAttr = getAttributeParam(config, MARGIN_HEIGHT_ATTR_PARAM, MARGIN_HEIGHT_ATTR_DEFAULT);
+        defaultMarginWidthAttr = getAttributeParam(config, MARGIN_WIDTH_ATTR_PARAM, MARGIN_WIDTH_ATTR_DEFAULT);
+        defaultMaximizedHeightAttr = getAttributeParam(config, MAXIMIZED_HEIGHT_ATTR_PARAM, MAXIMIZED_HEIGHT_ATTR_DEFAULT);
+        defaultMaximizedScrollingAttr = getAttributeParam(config, MAXIMIZED_SCROLLING_ATTR_PARAM, MAXIMIZED_SCROLLING_ATTR_DEFAULT);
+        defaultMaximizedStyleAttr = getAttributeParam(config, MAXIMIZED_STYLE_ATTR_PARAM, null);
+        defaultMaximizedWidthAttr = getAttributeParam(config, MAXIMIZED_WIDTH_ATTR_PARAM, MAXIMIZED_WIDTH_ATTR_DEFAULT);
+        defaultNameAttr = getAttributeParam(config, NAME_ATTR_PARAM, null);
+        defaultScrollingAttr = getAttributeParam(config, SCROLLING_ATTR_PARAM, SCROLLING_ATTR_DEFAULT);
+        defaultStyleAttr = getAttributeParam(config, STYLE_ATTR_PARAM, null);
+        defaultWidthAttr = getAttributeParam(config, WIDTH_ATTR_PARAM, WIDTH_ATTR_DEFAULT);
+    }
+    
+    /**
+     * Generate IFRAME with custom source.
+     */
+    public void doCustom(RenderRequest request, RenderResponse response)
+        throws PortletException, IOException
+    {
+        // get IFRAME source
+        String source = null;
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_CUSTOM_SOURCE_PARAM, defaultMaximizedCustomSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, CUSTOM_SOURCE_PARAM, defaultCustomSource);
+        }
+        if ((source == null) && request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_VIEW_SOURCE_PARAM, defaultMaximizedViewSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, VIEW_SOURCE_PARAM, defaultViewSource);
+        }
+        if (source == null)
+        {
+            throw new PortletException("IFRAME source not specified for custom portlet mode.");
+        }
+
+        // render IFRAME content
+        doIFrame(request, source, response);
+    }
+
+    /**
+     * Generate IFRAME with edit source.
+     */
+    public void doEdit(RenderRequest request, RenderResponse response)
+        throws PortletException, IOException
+    {
+        // get IFRAME source
+        String source = null;
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_EDIT_SOURCE_PARAM, defaultMaximizedEditSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, EDIT_SOURCE_PARAM, defaultEditSource);
+        }
+        if ((source == null) && request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_VIEW_SOURCE_PARAM, defaultMaximizedViewSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, VIEW_SOURCE_PARAM, defaultViewSource);
+        }
+        if (source == null)
+        {
+            throw new PortletException("IFRAME source not specified for edit portlet mode.");
+        }
+
+        // render IFRAME content
+        doIFrame(request, source, response);
+    }
+
+    /**
+     * Generate IFRAME with help source.
+     */
+    public void doHelp(RenderRequest request, RenderResponse response)
+        throws PortletException, IOException
+    {
+        // get IFRAME source
+        String source = null;
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_HELP_SOURCE_PARAM, defaultMaximizedHelpSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, HELP_SOURCE_PARAM, defaultHelpSource);
+        }
+        if ((source == null) && request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_VIEW_SOURCE_PARAM, defaultMaximizedViewSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, VIEW_SOURCE_PARAM, defaultViewSource);
+        }
+        if (source == null)
+        {
+            throw new PortletException("IFRAME source not specified for help portlet mode.");
+        }
+
+        // render IFRAME content
+        doIFrame(request, source, response);
+    }
+
+    /**
+     * Generate IFRAME with view source.
+     */
+    public void doView(RenderRequest request, RenderResponse response)
+        throws PortletException, IOException
+    {
+        // get IFRAME source
+        String source = null;
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            source = getPreferenceOrDefault(request, MAXIMIZED_VIEW_SOURCE_PARAM, defaultMaximizedViewSource);
+        }
+        if (source == null)
+        {
+            source = getPreferenceOrDefault(request, VIEW_SOURCE_PARAM, defaultViewSource);
+        }
+        if (source == null)
+        {
+            throw new PortletException("IFRAME source not specified for view portlet mode.");
+        }
+
+        // render IFRAME content
+        doIFrame(request, source, response);
+    }
+
+    /**
+     * Render IFRAME content
+     */
+    protected void doIFrame(RenderRequest request, String sourceAttr, RenderResponse response)
+        throws IOException
+    {
+        // generate HTML IFRAME content
+        StringBuffer content = new StringBuffer(4096);
+
+        // fix JS2-349
+        content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY CLASS='iframePortletTbodyContainer'><TR><TD>");
+        
+        content.append("<IFRAME");
+        content.append(" SRC=\"").append(sourceAttr).append("\"");
+        String alignAttr = getPreferenceOrDefault(request, ALIGN_ATTR_PARAM, defaultAlignAttr);
+        if (alignAttr != null)
+        {
+            content.append(" ALIGN=\"").append(alignAttr).append("\"");
+        }
+        String classAttr = getPreferenceOrDefault(request, CLASS_ATTR_PARAM, defaultClassAttr);
+        if (classAttr != null)
+        {
+            content.append(" CLASS=\"").append(classAttr).append("\"");
+        }
+        String frameBorderAttr = getPreferenceOrDefault(request, FRAME_BORDER_ATTR_PARAM, defaultFrameBorderAttr);
+        if (frameBorderAttr != null)
+        {
+            content.append(" FRAMEBORDER=\"").append(frameBorderAttr).append("\"");
+        }
+        String idAttr = getPreferenceOrDefault(request, ID_ATTR_PARAM, defaultIdAttr);
+        if (idAttr != null)
+        {
+            content.append(" ID=\"").append(idAttr).append("\"");
+        }
+        String marginHeightAttr = getPreferenceOrDefault(request, MARGIN_HEIGHT_ATTR_PARAM, defaultMarginHeightAttr);
+        if (marginHeightAttr != null)
+        {
+            content.append(" MARGINHEIGHT=\"").append(marginHeightAttr).append("\"");
+        }
+        String marginWidthAttr = getPreferenceOrDefault(request, MARGIN_WIDTH_ATTR_PARAM, defaultMarginWidthAttr);
+        if (marginWidthAttr != null)
+        {
+            content.append(" MARGINWIDTH=\"").append(marginWidthAttr).append("\"");
+        }
+        String nameAttr = getPreferenceOrDefault(request, NAME_ATTR_PARAM, defaultNameAttr);
+        if (nameAttr != null)
+        {
+            content.append(" NAME=\"").append(nameAttr).append("\"");
+        }
+        if (request.getWindowState().equals(WindowState.MAXIMIZED))
+        {
+            String maximizedHeightAttr = getPreferenceOrDefault(request, MAXIMIZED_HEIGHT_ATTR_PARAM, defaultMaximizedHeightAttr);
+            if (maximizedHeightAttr == null)
+            {
+                maximizedHeightAttr = getPreferenceOrDefault(request, HEIGHT_ATTR_PARAM, defaultHeightAttr);
+            }
+            if (maximizedHeightAttr != null)
+            {
+                content.append(" HEIGHT=\"").append(maximizedHeightAttr).append("\"");
+            }
+            String maximizedScrollingAttr = getPreferenceOrDefault(request, MAXIMIZED_SCROLLING_ATTR_PARAM, defaultMaximizedScrollingAttr);
+            if (maximizedScrollingAttr == null)
+            {
+                maximizedScrollingAttr = getPreferenceOrDefault(request, SCROLLING_ATTR_PARAM, defaultScrollingAttr);
+            }
+            if (maximizedScrollingAttr != null)
+            {
+                content.append(" SCROLLING=\"").append(maximizedScrollingAttr).append("\"");
+            }
+            String maximizedStyleAttr = getPreferenceOrDefault(request, MAXIMIZED_STYLE_ATTR_PARAM,  defaultMaximizedStyleAttr);
+            if (maximizedStyleAttr == null)
+            {
+                maximizedStyleAttr = getPreferenceOrDefault(request, STYLE_ATTR_PARAM, defaultStyleAttr);
+            }
+            if (maximizedStyleAttr != null)
+            {
+                content.append(" STYLE=\"").append(maximizedStyleAttr).append("\"");
+            }
+            String maximizedWidthAttr = getPreferenceOrDefault(request, MAXIMIZED_WIDTH_ATTR_PARAM, defaultMaximizedWidthAttr);
+            if (maximizedWidthAttr == null)
+            {
+                maximizedWidthAttr = getPreferenceOrDefault(request, WIDTH_ATTR_PARAM, defaultWidthAttr);
+            }
+            if (maximizedWidthAttr != null)
+            {
+                content.append(" WIDTH=\"").append(maximizedWidthAttr).append("\"");
+            }
+        }
+        else
+        {
+            String heightAttr = getPreferenceOrDefault(request, HEIGHT_ATTR_PARAM, defaultHeightAttr);
+            if (heightAttr != null)
+            {
+                content.append(" HEIGHT=\"").append(heightAttr).append("\"");
+            }
+            String scrollingAttr = getPreferenceOrDefault(request, SCROLLING_ATTR_PARAM, defaultScrollingAttr);
+            if (scrollingAttr != null)
+            {
+                content.append(" SCROLLING=\"").append(scrollingAttr).append("\"");
+            }
+            String styleAttr = getPreferenceOrDefault(request, STYLE_ATTR_PARAM, defaultStyleAttr);
+            if (styleAttr != null)
+            {
+                content.append(" STYLE=\"").append(styleAttr).append("\"");
+            }
+            String widthAttr = getPreferenceOrDefault(request, WIDTH_ATTR_PARAM, defaultWidthAttr);
+            if (widthAttr != null)
+            {
+                content.append(" WIDTH=\"").append(widthAttr).append("\"");
+            }
+        }
+        content.append(">");
+        content.append("<P STYLE=\"textAlign:center\"><A HREF=\"").append(sourceAttr).append("\">").append(sourceAttr).append("</A></P>");
+        content.append("</IFRAME>");
+
+        // end fix JS2-349
+        content.append("</TD></TR></TBODY></TABLE>");
+
+        // set required content type and write HTML IFRAME content
+        response.setContentType("text/html");
+        response.getWriter().print(content.toString());
+    }
+
+    /**
+     * Get IFRAME attribute parameter.
+     */
+    private String getAttributeParam(PortletConfig config, String name, String defaultValue)
+    {
+        String value = config.getInitParameter(name);
+        if (value == null)
+        {
+            value = defaultValue;
+        }
+        return (((value != null) && (value.length() > 0) && ! value.equalsIgnoreCase("none")) ? value : null);
+    }
+
+    /**
+     * Get IFRAME preference value if enabled.
+     */
+    private String getPreferenceOrDefault(RenderRequest request, String name, String defaultValue)
+    {
+        if (! enablePreferences)
+        {
+            return defaultValue;
+        }
+        PortletPreferences prefs = request.getPreferences();
+        return ((prefs != null) ? prefs.getValue(name, defaultValue) : defaultValue);
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFramePortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.
+ */
+package org.apache.portals.applications.webcontent.portlet;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A history of content navigations in the WebContentPortlet
+ *
+ * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
+ * @version $Id$ 
+ */
+
+public class WebContentHistoryList extends Object
+    implements Serializable
+{
+    int maxLength;
+    List history;
+    int currentIndex;
+    
+    // Constructors
+
+    public WebContentHistoryList()
+    {
+        this( -1 );
+    }
+    public WebContentHistoryList( int maxLength )
+    {
+        super();
+        
+        this.maxLength = maxLength;
+        this.history = new ArrayList();
+        this.currentIndex = -1;
+    }
+    
+    // Methods
+    
+    public boolean isEmpty()
+    {
+        return this.history.isEmpty();
+    }
+    public boolean hasCurrentPage()
+    {
+        return this.currentIndex >= 0;
+    }
+    public boolean hasPreviousPage()
+    {
+        return !isEmpty() && this.currentIndex-1 >= 0;
+    }
+    public boolean hasNextPage()
+    {
+        return !isEmpty() && this.currentIndex+1 < this.history.size();
+    }
+    
+    public WebContentHistoryPage getCurrentPage()
+    {
+        if (!hasCurrentPage())
+            return null ;
+        return (WebContentHistoryPage)this.history.get(this.currentIndex);
+    }
+    public WebContentHistoryPage getPreviousPage()
+    {
+        if (!hasPreviousPage())
+            return null;
+        this.currentIndex = this.currentIndex-1;
+        return getCurrentPage();
+    }
+    public WebContentHistoryPage getNextPage()
+    {
+        if (!hasNextPage())
+            return null;
+        this.currentIndex = this.currentIndex+1;
+        return getCurrentPage();
+    }
+    
+    public void visitPage(WebContentHistoryPage page)
+    {
+        if (page==null)
+            throw new IllegalArgumentException("WebContentHistoryList.addPage() - non-null page required.");
+        
+        int i = this.history.indexOf(page);
+        if (i >= 0 && i == this.currentIndex) 
+        {
+            // just visiting the current page
+            return;
+        }
+        
+        // otherwise - new page...
+        while (hasNextPage())
+        {
+            // ...visiting a page discards any pages we have visited by going "back"
+            this.history.remove(this.currentIndex+1);
+        }
+        if (i >= 0 && i < history.size())
+        {
+            // ...actually, new visit to an old page, only keep one reference to it
+            this.history.remove(i);
+        }
+        
+        // add in the new page, at the end
+        this.history.add(page);
+        this.currentIndex = this.history.size()-1;
+        
+        // System.out.println("WebContentHistoryList.visitPage() - current index is: "+this.currentIndex+"\nhistory list..."+ArrayUtils.toString(this.history));
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryList.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+package org.apache.portals.applications.webcontent.portlet;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.lang.ArrayUtils;
+
+
+/**
+ * Information required to re-visit a page in the WebContentPortlet
+ *
+ * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
+ * @version $Id$ 
+ */
+
+public class WebContentHistoryPage extends Object
+    implements Serializable
+{
+    private String url;
+    private Map params;
+    private boolean is_post;
+
+    // Constructors
+    
+    public WebContentHistoryPage(String url)
+    {
+        this(url, null, null);
+    }
+    public WebContentHistoryPage(String url, Map params, String method)
+    {
+        super();
+
+        // guarantee non-null, so that equals() is well-behaved
+        if (url==null)
+            throw new IllegalArgumentException("WebContentHistoryPage() - url required");
+        
+        this.url = url;
+        this.params = params != null ? params : new HashMap();
+        this.is_post = method != null && method.equalsIgnoreCase("post");
+    }
+    
+    // Base Class Protocol
+    
+    public boolean equals(Object o)
+    {
+        if (o == null || !(o instanceof WebContentHistoryPage))
+            return false ;
+
+        WebContentHistoryPage page = (WebContentHistoryPage)o;
+        
+        return page.url.equals(this.url) && page.params.equals(this.params) && page.isPost() == this.isPost() ;
+    }
+    public String toString()
+    {
+        StringBuffer buff = new StringBuffer();
+        buff.append( "[" ).append(isPost() ? "POST: " : "GET: ").append( getUrl() ).append( ", " ).append( getParams().size() ).append(" params: {");
+        Iterator iter = getParams().entrySet().iterator();
+        while ( iter.hasNext() )
+        {
+            Map.Entry entry = (Map.Entry)iter.next();
+            buff.append("(").append(entry.getKey()).append(" . ").append(ArrayUtils.toString(entry.getKey())).append(")");
+        }
+        buff.append("}]");
+        return buff.toString();
+    }
+    
+    // Data Access
+    
+    public String getUrl()
+    {
+        return this.url;
+    }
+    public Map getParams()
+    {
+        return this.params;
+    }
+    public boolean isPost()
+    {
+        return this.is_post;
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentHistoryPage.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,725 @@
+/* 
+ * 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.
+ */
+package org.apache.portals.applications.webcontent.portlet;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.MultipartPostMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.applications.webcontent.rewriter.MappingRewriterController;
+import org.apache.portals.applications.webcontent.rewriter.RewriterController;
+import org.apache.portals.applications.webcontent.rewriter.RewriterException;
+import org.apache.portals.applications.webcontent.rewriter.RulesetRewriter;
+import org.apache.portals.applications.webcontent.rewriter.WebContentRewriter;
+import org.apache.portals.applications.webcontent.rewriter.html.neko.NekoParserAdaptor;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent.rewriter.xml.SaxParserAdaptor;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.messaging.PortletMessaging;
+
+
+/**
+ * WebContentPortlet
+ * 
+ * TODO: Preferences, cache stream instead of URL *
+ * 
+ * @author <a href="mailto:rogerrutr@apache.org">Roger Ruttimann </a>
+ * @version $Id$
+ */
+
+public class WebContentPortlet extends GenericVelocityPortlet
+{
+
+    /**
+     * WebContentPortlet Allows navigation inside the portlet and caches the
+     * latest URL
+     */
+
+    /**
+     * Configuration constants.
+     */
+    public static final String VIEW_SOURCE_PARAM = "viewSource";
+    public static final String EDIT_SOURCE_PARAM = "editSource";
+    
+    // ...browser action buttons
+    public static final String BROWSER_ACTION_PARAM = "wcBrowserAction"; 
+    public static final String BROWSER_ACTION_PREVIOUS_PAGE = "previousPage"; 
+    public static final String BROWSER_ACTION_REFRESH_PAGE = "refreshPage"; 
+    public static final String BROWSER_ACTION_NEXT_PAGE = "nextPage"; 
+
+    /**
+     * Action Parameter
+     */
+
+    // WebContent session data 
+
+    public static final String HISTORY = "webcontent.history";
+    public static final String HTTP_STATE = "webcontent.http.state";
+    
+    // Class Data
+    
+    protected final static Log log = LogFactory.getLog(WebContentPortlet.class);
+    public final static String defaultEncoding = "UTF-8";
+
+    // Data Members
+    
+    private RulesetRewriter rewriter = null;
+    private RewriterController rewriteController = null;
+
+    public static final String FORM_POST_METHOD = "post";
+    public static final String FORM_GET_METHOD = "get";
+    public static final String FORM_MULTIPART_METHOD = "multipart";
+    
+    public WebContentPortlet()
+    {
+        super();
+    }
+
+    /**
+     * Initialize portlet configuration.
+     */
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+    }
+
+    /**
+     * processAction() Checks action initiated by the WebContent portlet which
+     * means that a user has clicked on an URL
+     * 
+     * @param actionRequest
+     * @param actionResponse
+     * @throws PortletException
+     * @throws IOException
+     */
+    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException,
+            IOException
+    {
+        // check to see if it is a meta-navigation command
+        String browserAction = actionRequest.getParameter(BROWSER_ACTION_PARAM);
+        if (browserAction != null)
+        {
+            if (!browserAction.equalsIgnoreCase(BROWSER_ACTION_REFRESH_PAGE))
+            {
+                // for Refresh, there is nothing special to do - current history page will be re-displayed
+                WebContentHistoryList history = (WebContentHistoryList)PortletMessaging.receive(actionRequest, HISTORY);
+                
+                if (browserAction.equalsIgnoreCase(BROWSER_ACTION_PREVIOUS_PAGE))
+                {
+                    if (history.hasPreviousPage())
+                        history.getPreviousPage();
+                }
+                else if (browserAction.equalsIgnoreCase(BROWSER_ACTION_NEXT_PAGE))
+                {
+                    if (history.hasNextPage())
+                        history.getNextPage();
+                }
+            }
+            
+            return ;   // proceed to doView() with adjusted history
+        }
+        
+        // Check if an action parameter was defined        
+        String webContentURL = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_URL);
+        String webContentMethod = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_METHOD);
+        Map webContentParams = new HashMap(actionRequest.getParameterMap()) ;
+        
+        // defaults
+        if (webContentMethod == null) webContentMethod = "" ;   // default to GET
+        
+        // parameter map includes the URL (as ACTION_PARAMETER_URL), but all actual params as well
+        webContentParams.remove(WebContentRewriter.ACTION_PARAMETER_URL);
+        webContentParams.remove(WebContentRewriter.ACTION_PARAMETER_METHOD);
+        
+        if (webContentURL == null || actionRequest.getPortletMode() == PortletMode.EDIT)
+        {
+            processPreferencesAction(actionRequest, actionResponse);            
+            webContentURL = actionRequest.getPreferences().getValue("SRC", "http://portals.apache.org");
+
+            // parameters are for the EDIT mode form, and should not be propagated to the subsequent GET in doView
+            webContentParams.clear();
+        }
+
+        /*
+         * If the webContentParameter is not empty attach the URL to the session
+         */
+        if (webContentURL != null && webContentURL.length() > 0)
+        {
+            // new page visit - make it the current page in the history
+            WebContentHistoryList history = (WebContentHistoryList)PortletMessaging.receive(actionRequest, HISTORY);
+            if (history == null)
+                history = new WebContentHistoryList();
+            history.visitPage(new WebContentHistoryPage(webContentURL,webContentParams,webContentMethod));
+            PortletMessaging.publish(actionRequest, HISTORY, history);
+        }
+    }
+
+    /**
+     * doView Renders the URL in the following order 1) SESSION_PARAMETER
+     * 2)cached version 3) defined for preference SRC
+     */
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        String viewPage = (String)request.getAttribute(PARAM_VIEW_PAGE);
+        if (viewPage != null)
+        {
+            super.doView(request, response);
+            return;
+        }
+        
+        // view the current page in the history
+        WebContentHistoryList history = (WebContentHistoryList)PortletMessaging.receive(request, HISTORY);
+        if (history == null)
+            history = new WebContentHistoryList();
+        WebContentHistoryPage currentPage = history.getCurrentPage();
+        if (currentPage == null)
+        {
+            String sourceURL = request.getPreferences().getValue("SRC", "");
+            if (sourceURL == null)
+            {
+                // BOZO - switch to edit mode automatically here, instead of throwing exception!
+                throw new PortletException("WebContent source not specified. Go to edit mode and specify an URL.");
+            }
+            currentPage = new WebContentHistoryPage(sourceURL);
+        }
+
+        // Initialize the controller if it's not already done
+        if (rewriteController == null)
+        {
+            PortletContext portletApplication = getPortletContext(); 
+            String path = portletApplication.getRealPath("/WEB-INF");
+            String contextPath = path + "/";
+            try
+            {
+                // Create rewriter adaptor
+                rewriteController = getController(contextPath);
+            }
+            catch (Exception e)
+            {
+                // Failed to create rewriter controller
+                String msg = "WebContentPortlet failed to create rewriter controller.";
+                log.error(msg,e);
+                throw new PortletException(e.getMessage());
+            }
+        }
+
+        // get content from current page
+        response.setContentType("text/html");
+        byte[] content = doWebContent(currentPage.getUrl(), currentPage.getParams(), currentPage.isPost(), request, response);
+        // System.out.println("Rewritten content is\n..."+new String(content));
+        
+        // write the meta-control navigation header
+        PrintWriter writer = response.getWriter();
+        writer.print("<block>");
+        if (history.hasPreviousPage())
+        {
+            PortletURL prevAction = response.createActionURL() ;
+            prevAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_PREVIOUS_PAGE);
+            writer.print(" [<a href=\"" + prevAction.toString() +"\">Previous Page</a>] ");
+        }
+        PortletURL refreshAction = response.createActionURL() ;
+        refreshAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_REFRESH_PAGE);
+        writer.print(" [<a href=\"" + refreshAction.toString() +"\">Refresh Page</a>] ");
+        if (history.hasNextPage())
+        {
+            PortletURL nextAction = response.createActionURL() ;
+            nextAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_NEXT_PAGE);
+            writer.print(" [<a href=\"" + nextAction.toString() +"\">Next Page</a>] ");
+        }
+        writer.print("</block><hr/>");
+
+        // drain the stream to the portlet window
+        ByteArrayInputStream bais = new ByteArrayInputStream(content);
+        drain(new InputStreamReader(bais, WebContentPortlet.defaultEncoding), writer);
+        bais.close();
+        
+        // done, cache results in the history and save the history
+        history.visitPage(currentPage);
+        PortletMessaging.publish(request, HISTORY, history);
+    }
+
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        response.setContentType("text/html");
+        doPreferencesEdit(request, response);
+    }
+        
+    /*
+     * Privaye helpers for generating WebContent
+     */
+    protected byte[] doWebContent(String sourceAttr, Map sourceParams, boolean isPost, RenderRequest request, RenderResponse response)
+        throws PortletException
+    {
+        HttpMethod httpMethod = null ;
+        
+        try
+        {
+            // Set the action and base URLs in the rewriter
+            PortletURL action = response.createActionURL();
+            ((WebContentRewriter) rewriter).setActionURL(action);
+            URL baseURL = new URL(sourceAttr);
+            rewriter.setBaseUrl(baseURL.toString());
+            
+            // ...file URLs may be used for testing
+            if (baseURL.getProtocol().equals("file"))
+            {
+                Reader reader = new InputStreamReader((InputStream)baseURL.getContent());
+                StringWriter writer = new StringWriter();
+                rewriter.rewrite(rewriteController.createParserAdaptor("text/html"), reader, writer);
+                writer.flush();
+                return writer.toString().getBytes();
+            }
+            // else fall through to normal case (http/https)...
+            
+            // ...set up URL and HttpClient stuff
+            HttpClient httpClient = getHttpClient(request) ;
+            String method = (isPost) ? FORM_POST_METHOD : FORM_GET_METHOD;
+            httpMethod = getHttpMethod(httpClient, getURLSource(sourceAttr, sourceParams, request, response), sourceParams, method, request);
+            byte[] result = doPreemptiveAuthentication(httpClient, httpMethod, request, response);
+            
+            // ...get, cache, and return the content
+            if (result == null) {
+            	return doHttpWebContent(httpClient, httpMethod, 0, request, response);
+            } else {
+            	return result;
+            }
+        }
+        catch (PortletException pex)
+        {
+            // already reported
+            throw pex;
+        }
+        catch (Exception ex)
+        {
+            String msg = "Exception while rewritting HTML content" ;
+            log.error(msg,ex);
+            throw new PortletException(msg+", Error: "+ex.getMessage());
+        }
+        finally
+        {
+            // release the http connection
+            if (httpMethod != null)
+                httpMethod.releaseConnection();
+        }
+    }
+
+    protected byte[] doHttpWebContent(HttpClient httpClient, HttpMethod httpMethod, int retryCount, RenderRequest request, RenderResponse response)
+            throws PortletException
+    {
+        try
+        {
+            // Get the input stream from the provided httpClient/httpMethod
+            // System.out.println("WebContentPortlet.doHttpWebContent() - from path: "+httpMethod.getPath());
+            
+            // ...set up URL and HttpClient stuff
+            httpClient.executeMethod(httpMethod);
+            
+            // ...reset base URL with fully resolved path (e.g. if a directory, path will end with a /, which it may not have in the call to this method)
+            rewriter.setBaseUrl( rewriter.getBaseRelativeUrl( httpMethod.getPath() )) ;
+            // System.out.println("...reset base URL from final path: "+httpMethod.getPath());
+            
+            // ...save updated state
+            Cookie[] cookies = httpClient.getState().getCookies();
+            PortletMessaging.publish(request, HTTP_STATE, cookies);
+            // System.out.println("...saving: "+(cookies != null ? cookies.length : 0)+", cookies...");
+            //    for(int i=0,limit = cookies != null ? cookies.length : 0; i<limit; i++) System.out.println("...cookie["+i+"] is: "+cookies[i]);
+
+            // ...check for manual redirects
+            int responseCode = httpMethod.getStatusCode();
+            if (responseCode >= 300 && responseCode <= 399)
+            {
+                // redirection that could not be handled automatically!!! (probably from a POST)
+                Header locationHeader = httpMethod.getResponseHeader("location");
+                String redirectLocation = locationHeader != null ? locationHeader.getValue() : null ;
+                if (redirectLocation != null)
+                {
+                    // System.out.println("WebContentPortlet.doHttpWebContent() >>>handling redirect to: "+redirectLocation+"<<<");
+                    
+                    // one more time (assume most params are already encoded & new URL is using GET protocol!)
+                    return doWebContent( redirectLocation, new HashMap(), false, request, response ) ;
+                }
+                else
+                {
+                    // The response is a redirect, but did not provide the new location for the resource.
+                    throw new PortletException("Redirection code: "+responseCode+", but with no redirectionLocation set.");
+                }
+            }
+            else if ( responseCode >= 400 )
+            {
+                if ( responseCode == 401 )
+                {
+                    if (httpMethod.getHostAuthState().isAuthRequested() && retryCount++ < 1 && doRequestedAuthentication( httpClient, httpMethod, request, response))
+                    {
+                        // try again, now that we are authorizied
+                        return doHttpWebContent(httpClient, httpMethod, retryCount, request, response);
+                    }
+                    else
+                    {
+                        // could not authorize
+                        throw new PortletException("Site requested authorization, but we are unable to provide credentials");
+                    }
+                }
+                else if (retryCount++ < 3)
+                {
+                    log.info("WebContentPortlet.doHttpWebContent() - retrying: "+httpMethod.getPath()+", response code: "+responseCode);
+                    
+                    // retry
+                    return doHttpWebContent(httpClient, httpMethod, retryCount, request, response);
+                }
+                else
+                {
+                    // bad
+                    throw new PortletException("Failure reading: "+httpMethod.getPath()+", response code: "+responseCode);
+                }
+            }
+            
+            // System.out.println("...response code: "+responseCode+", fetching content as stream and rewriting.");
+            
+            // ...ok - *now* create the input stream and reader
+            BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
+            String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
+            if (encoding == null)
+                encoding = getContentCharSet(bis);
+            Reader htmlReader = new InputStreamReader(bis, encoding);
+            
+            // get the output buffer
+            if (encoding == null)
+                encoding = WebContentPortlet.defaultEncoding ;
+            ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
+            Writer htmlWriter = new OutputStreamWriter(byteOutputStream, encoding);
+
+            // rewrite and flush output
+            rewriter.rewrite(rewriteController.createParserAdaptor("text/html"), htmlReader, htmlWriter);
+            htmlWriter.flush();
+
+            // Page has been rewritten
+            // TODO: Write it to cache
+            //System.out.println(new String(byteOutputStream.toByteArray()));
+            return byteOutputStream.toByteArray();
+        }
+        catch (UnsupportedEncodingException ueex)
+        {
+            throw new PortletException("Encoding " + defaultEncoding + " not supported. Error: " + ueex.getMessage());
+        }
+        catch (RewriterException rwe)
+        {
+            throw new PortletException("Failed to rewrite HTML page. Error: " + rwe.getMessage());
+        }
+        catch (Exception e)
+        {
+            throw new PortletException("Exception while rewritting HTML page. Error: " + e.getMessage());
+        }
+    }
+    
+    protected String getURLSource(String source, Map params, RenderRequest request, RenderResponse response)
+    {
+        return source;    
+    }
+    
+    protected byte[] doPreemptiveAuthentication(HttpClient clent,HttpMethod method, RenderRequest request, RenderResponse response)
+    {
+        // derived class responsibilty - return true, if credentials have been set
+        return null ;
+    }
+    
+    protected boolean doRequestedAuthentication(HttpClient clent,HttpMethod method, RenderRequest request, RenderResponse response)
+    {
+        // derived class responsibilty - return true, if credentials have been set
+        return false ;
+    }
+
+    /*
+     * Generate a rewrite controller using the basic rules file
+     */
+    private RewriterController getController(String contextPath) throws Exception
+    {
+        Class[] rewriterClasses = new Class[]
+        { WebContentRewriter.class, WebContentRewriter.class};
+        
+        Class[] adaptorClasses = new Class[]
+        { NekoParserAdaptor.class, SaxParserAdaptor.class};
+        RewriterController rwc = new MappingRewriterController(contextPath + "conf/rewriter-rules-mapping.xml", Arrays
+                .asList(rewriterClasses), Arrays.asList(adaptorClasses));
+
+        FileReader reader = new FileReader(contextPath + "conf/default-rewriter-rules.xml");
+
+        Ruleset ruleset = rwc.loadRuleset(reader);
+        reader.close();
+        rewriter = rwc.createRewriter(ruleset);
+        return rwc;
+    }
+
+    protected HttpClient getHttpClient(RenderRequest request) throws IOException
+    {
+        // derived class hook (e.g. to set up Basic Authentication)
+        HttpClient client = new HttpClient();
+        
+        // reuse existing state, if we have been here before
+        Cookie[] cookies = (Cookie[])PortletMessaging.receive(request, HTTP_STATE);
+        if (cookies != null)
+        {
+            // ...so far, just saving cookies - may need a more complex Serializable object here
+            client.getState().addCookies(cookies);
+
+            // System.out.println("WebContentPortlet.getHttpClient() - reusing: "+cookies.length+", cookies...");
+            //    for(int i=0,limit = cookies.length; i<limit; i++) System.out.println("...cookie["+i+"] is: "+cookies[i]);
+        }
+ 
+        return client ;
+    }
+    
+    protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
+    {
+        // formMethod = FORM_MULTIPART_METHOD;
+        HttpMethodBase httpMethod = null;
+        String useragentProperty = request.getProperty("User-Agent");
+        if(formMethod.equalsIgnoreCase(FORM_MULTIPART_METHOD)){ 
+            // http mutipart
+            MultipartPostMethod mutlitPart = (MultipartPostMethod)( httpMethod = new MultipartPostMethod(uri)) ; 
+            if (params != null && !params.isEmpty())
+            {
+                Iterator iter = params.entrySet().iterator();
+                while (iter.hasNext())
+                {
+                    Map.Entry entry = (Map.Entry)iter.next();
+                    String name = (String)entry.getKey(); 
+                    String[] values = (String[])entry.getValue();
+                    if (values != null)
+                        for (int i=0,limit=values.length; i<limit; i++)
+                        {
+                            // System.out.println("...adding >>>POST parameter: "+name+", with value: "+values[i]+"<<<");
+                            
+                            mutlitPart.addParameter(name, values[i]);
+                        }
+                }   
+            }
+            
+        }else if (formMethod.equalsIgnoreCase(FORM_GET_METHOD)){
+        
+            // System.out.println("WebContentPortlet.getHttpMethod() - HTTP GET from URL: "+uri);
+            // http GET
+            httpMethod = new GetMethod(uri);
+            if (params != null && !params.isEmpty())
+            {
+                ArrayList pairs = new ArrayList();
+                Iterator iter = params.entrySet().iterator();
+                while (iter.hasNext())
+                {
+                    Map.Entry entry = (Map.Entry)iter.next() ;
+                    String name = (String)entry.getKey() ;
+                    String[] values = (String [])entry.getValue() ;
+                    if (values != null)
+                        for (int i = 0,limit = values.length; i < limit; i++)
+                        {
+                            // System.out.println("...adding >>>GET parameter: "+name+", with value: "+values[i]+"<<<");
+                            pairs.add(new NameValuePair(name, values[i]));
+                        }
+                }
+                httpMethod.setQueryString((NameValuePair[])pairs.toArray(new NameValuePair[pairs.size()]));
+            }
+            
+            // automatically follow redirects (NOTE: not supported in POST - will throw exeception if you ask for it, then sees a redirect!!)
+            httpMethod.setFollowRedirects(true);
+        }else if (formMethod.equalsIgnoreCase(FORM_POST_METHOD)) {
+            // System.out.println("WebContentPortlet.getHttpMethod() - HTTP POST to URL: "+uri);
+            
+            // http POST
+            PostMethod postMethod = (PostMethod)( httpMethod = new PostMethod(uri)) ; 
+            if (params != null && !params.isEmpty())
+            {
+                Iterator iter = params.entrySet().iterator();
+                while (iter.hasNext())
+                {
+                    Map.Entry entry = (Map.Entry)iter.next();
+                    String name = (String)entry.getKey(); 
+                    String[] values = (String[])entry.getValue();
+                    if (values != null)
+                        for (int i=0,limit=values.length; i<limit; i++)
+                        {
+                            // System.out.println("...adding >>>POST parameter: "+name+", with value: "+values[i]+"<<<");
+                            
+                            postMethod.addParameter(name, values[i]);
+                        }
+                }   
+            }
+        }
+        
+        // propagate User-Agent, so target site does not think we are a D.O.S. attack
+        httpMethod.addRequestHeader( "User-Agent", useragentProperty );
+        
+        // BOZO - DON'T do this.   default policy seems to be more flexible!!!
+        //httpMethod.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
+        
+        // ...ready to use!
+        return httpMethod ;
+    }
+
+    
+    
+
+    static final int BLOCK_SIZE = 4096;
+
+    /*
+    private void drain(InputStream reader, OutputStream writer) throws IOException
+    {
+        byte[] bytes = new byte[BLOCK_SIZE];
+        try
+        {
+            int length = reader.read(bytes);
+            while (length != -1)
+            {
+                if (length != 0)
+                {
+                    writer.write(bytes, 0, length);
+                }
+                length = reader.read(bytes);
+            }
+        }
+        finally
+        {
+            bytes = null;
+        }
+    }
+    */
+
+    private void drain(Reader r, Writer w) throws IOException
+    {
+        char[] bytes = new char[BLOCK_SIZE];
+        try
+        {
+            int length = r.read(bytes);
+            while (length != -1)
+            {
+                if (length != 0)
+                {
+                    w.write(bytes, 0, length);
+                }
+                length = r.read(bytes);
+            }
+        }
+        finally
+        {
+            bytes = null;
+        }
+
+    }
+
+    /*
+    private void drain(Reader r, OutputStream os) throws IOException
+    {
+        Writer w = new OutputStreamWriter(os);
+        drain(r, w);
+        w.flush();
+    }
+    */
+
+    private String getContentCharSet(InputStream is) throws IOException
+    {
+        if (!is.markSupported())
+        {
+            return null;
+        }
+
+        byte[] buf = new byte[BLOCK_SIZE];
+        try
+        {
+            is.mark(BLOCK_SIZE);
+            is.read(buf, 0, BLOCK_SIZE);
+            String content = new String(buf, "ISO-8859-1");
+            String lowerCaseContent = content.toLowerCase();
+            int startIndex = lowerCaseContent.indexOf("<head");
+            if (startIndex == -1)
+            {
+                startIndex = 0;
+            }
+            int endIndex = lowerCaseContent.indexOf("</head");
+            if (endIndex == -1)
+            {
+                endIndex = content.length();
+            }
+            content = content.substring(startIndex, endIndex);
+
+            StringTokenizer st = new StringTokenizer(content, "<>");
+            while (st.hasMoreTokens())
+            {
+                String element = st.nextToken();
+                String lowerCaseElement = element.toLowerCase();
+                if (lowerCaseElement.startsWith("meta") && lowerCaseElement.indexOf("content-type") > 0)
+                {
+                    StringTokenizer est = new StringTokenizer(element, " =\"\';");
+                    while (est.hasMoreTokens())
+                    {
+                        if (est.nextToken().equalsIgnoreCase("charset"))
+                        {
+                            if (est.hasMoreTokens())
+                            {
+                                return est.nextToken();
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        catch (IOException e)
+        {
+        }
+        finally
+        {
+            is.reset();
+        }
+
+        return null;
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id