You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bridges-commits@portals.apache.org by sh...@apache.org on 2005/10/31 22:31:37 UTC
svn commit: r329917 - in /portals/bridges/trunk: ./ portletfilter/
portletfilter/src/ portletfilter/src/java/ portletfilter/src/java/org/
portletfilter/src/java/org/apache/ portletfilter/src/java/org/apache/portals/
portletfilter/src/java/org/apache/po...
Author: shinsuke
Date: Mon Oct 31 13:31:29 2005
New Revision: 329917
URL: http://svn.apache.org/viewcvs?rev=329917&view=rev
Log:
Portlet Filter: http://issues.apache.org/jira/browse/PB-15
Added:
portals/bridges/trunk/portletfilter/
portals/bridges/trunk/portletfilter/.cvsignore
portals/bridges/trunk/portletfilter/project.properties (with props)
portals/bridges/trunk/portletfilter/project.xml (with props)
portals/bridges/trunk/portletfilter/src/
portals/bridges/trunk/portletfilter/src/java/
portals/bridges/trunk/portletfilter/src/java/org/
portals/bridges/trunk/portletfilter/src/java/org/apache/
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java (with props)
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java (with props)
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java (with props)
portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java (with props)
portals/bridges/trunk/portletfilter/xdocs/
portals/bridges/trunk/portletfilter/xdocs/index.xml (with props)
portals/bridges/trunk/portletfilter/xdocs/navigation.xml (with props)
Modified:
portals/bridges/trunk/.classpath
portals/bridges/trunk/project.properties
portals/bridges/trunk/xdocs/navigation.xml
Modified: portals/bridges/trunk/.classpath
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/.classpath?rev=329917&r1=329916&r2=329917&view=diff
==============================================================================
--- portals/bridges/trunk/.classpath (original)
+++ portals/bridges/trunk/.classpath Mon Oct 31 13:31:29 2005
@@ -8,6 +8,7 @@
<classpathentry excluding="**/.svn/*" kind="src" path="perl/src/java"/>
<classpathentry excluding="**/.svn/*" kind="src" path="struts/src/java"/>
<classpathentry excluding="**/.svn/*" kind="src" path="velocity/src/java"/>
+ <classpathentry excluding="**/.svn/*" kind="src" path="portletfilter/src/java"/>
<classpathentry kind="var" path="MAVEN_REPO/servletapi/jars/servletapi-2.3.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/itgroundwork/jars/phpportlet-1.0.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/struts/jars/struts-1.2.7.jar"/>
Added: portals/bridges/trunk/portletfilter/.cvsignore
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/.cvsignore?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/.cvsignore (added)
+++ portals/bridges/trunk/portletfilter/.cvsignore Mon Oct 31 13:31:29 2005
@@ -0,0 +1,2 @@
+target
+jcoverage.ser
Added: portals/bridges/trunk/portletfilter/project.properties
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/project.properties?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/project.properties (added)
+++ portals/bridges/trunk/portletfilter/project.properties Mon Oct 31 13:31:29 2005
@@ -0,0 +1,18 @@
+# Copyright 2004 The Apache Software Foundation
+#
+# Licensed 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.properties 191820 2005-06-22 12:35:38Z ate $
+maven.multiproject.type=jar
+maven.license.licenseFile=${basedir}/../LICENSE.TXT
+
Propchange: portals/bridges/trunk/portletfilter/project.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/project.xml
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/project.xml?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/project.xml (added)
+++ portals/bridges/trunk/portletfilter/project.xml Mon Oct 31 13:31:29 2005
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.xml 295122 2005-10-05 21:41:48Z sgala $
+-->
+<project>
+ <extend>${basedir}/../project.xml</extend>
+ <pomVersion>3</pomVersion>
+ <id>portals-bridges-portletfilter</id>
+ <name>Portlet Filter</name>
+ <currentVersion>${portals.bridges.portletfilter.version}</currentVersion>
+ <package>org.apache.portals.bridges.portletfilter</package>
+ <description>Apache Portals Portlet Filter</description>
+ <shortDescription>Apache Portals Portlet Filter</shortDescription>
+ <repository>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/portals/bridges/trunk/portletfilter</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/bridges/trunk/portletfilter</developerConnection>
+ <url>http://svn.apache.org/viewcvs.cgi/portals/bridges/trunk/portletfilter/</url>
+ </repository>
+ <developers>
+ <developer>
+ <name>Shinsuke Sugaya</name>
+ <id>shinsuke</id>
+ <email>shinsuke@apache.org</email>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <dependencies>
+ <dependency>
+ <groupId>portlet-api</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>1.0</version>
+ <properties>
+ <war.bundle>false</war.bundle>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.3</version>
+ <url>http://jakarta.apache.org/commons/logging.html</url>
+ <properties>
+ <war.bundle>false</war.bundle>
+ </properties>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>src/java</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>${basedir}/src/java</directory>
+ <includes>
+ <include>META-INF/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+</project>
Propchange: portals/bridges/trunk/portletfilter/project.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java (added)
+++ portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java Mon Oct 31 13:31:29 2005
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.bridges.portletfilter;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * FilterPortlet provides a portlet implementation to filter the
+ * specified portlet. The filtered portlet and filters are defined in
+ * a portlet descriptor(portlet.xml). The filetered portlet is specified
+ * by portlet-class, and the filters are specified by portlet-filters.
+ *
+ * Example:
+ * <pre>
+ * <portlet-app id="example-portlets" version="1.0">
+ * <portlet id="ExamplePortlet">
+ * ...
+ * <init-param>
+ * <name>portlet-class</name>
+ * <value>org.apache.myfaces.portlet.MyFacesGenericPortlet</value>
+ * </init-param>
+ * <init-param>
+ * <name>portlet-filters</name>
+ * <value>org.apache.myfaces.portlet.TomahawkPortletFilter</value>
+ * </init-param>
+ * <init-param>
+ * <name>org.apache.myfaces.portlet.TomahawkPortletFilter:upload-threshold-size</name>
+ * <value>1m</value>
+ * </init-param>
+ * <init-param>
+ * <name>org.apache.myfaces.portlet.TomahawkPortletFilter:upload-max-file-size</name>
+ * <value>10m</value>
+ * </init-param>
+ * ...
+ * </pre>
+ *
+ * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
+ */
+public class FilterPortlet implements Portlet, PortletConfig
+{
+ private static final Log log = LogFactory.getLog(FilterPortlet.class);
+
+ public static final String PORTLET_CLASS = "portlet-class";
+
+ private PortletFilterChain portletFilterChain;
+
+ private PortletConfig portletConfig;
+
+ private Portlet portlet;
+
+ public void init(PortletConfig config) throws PortletException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Initializing FilterPortlet.");
+ }
+
+ // create Portlet
+ String portletClassName = config.getInitParameter(PORTLET_CLASS);
+ if (portletClassName == null)
+ {
+ throw new PortletException("Portlet Class Name is null.");
+ }
+ portlet = null;
+
+ try
+ {
+ Class portletClass = Class.forName(portletClassName);
+ Object portletObj = portletClass.newInstance();
+ if (portletObj instanceof Portlet)
+ {
+ portlet = (Portlet) portletObj;
+ portlet.init(config);
+ }
+ else
+ {
+ throw new PortletException(portletClassName + " is not Portlet instance.");
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new PortletException("Class " + portletClassName + " is not found.", e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new PortletException("Could not instantiate " + portletClassName + ".", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new PortletException("Illegal Access: " + portletClassName, e);
+ }
+
+ // create PortletFilterChain
+ portletFilterChain = new PortletFilterChain(config);
+ portletFilterChain.setPortlet(portlet);
+ }
+
+ public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("called processAction method.");
+ }
+ portletFilterChain.processActionFilter(request, response);
+ }
+
+ public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("called render method.");
+ }
+ portletFilterChain.renderFilter(request, response);
+ }
+
+ public void destroy()
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("called destory method.");
+ }
+ portletFilterChain.release();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String arg0)
+ {
+ if (portlet instanceof PortletConfig)
+ {
+ return ((PortletConfig) portlet).getInitParameter(arg0);
+ }
+ return portletConfig.getInitParameter(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getInitParameterNames()
+ */
+ public Enumeration getInitParameterNames()
+ {
+ if (portlet instanceof PortletConfig)
+ {
+ return ((PortletConfig) portlet).getInitParameterNames();
+ }
+ return portletConfig.getInitParameterNames();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getPortletContext()
+ */
+ public PortletContext getPortletContext()
+ {
+ if (portlet instanceof PortletConfig)
+ {
+ return ((PortletConfig) portlet).getPortletContext();
+ }
+ return portletConfig.getPortletContext();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getPortletName()
+ */
+ public String getPortletName()
+ {
+ if (portlet instanceof PortletConfig)
+ {
+ return ((PortletConfig) portlet).getPortletName();
+ }
+ return portletConfig.getPortletName();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getResourceBundle(java.util.Locale)
+ */
+ public ResourceBundle getResourceBundle(Locale arg0)
+ {
+ if (portlet instanceof PortletConfig)
+ {
+ return ((PortletConfig) portlet).getResourceBundle(arg0);
+ }
+ return portletConfig.getResourceBundle(arg0);
+ }
+
+}
Propchange: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/FilterPortlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java (added)
+++ portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java Mon Oct 31 13:31:29 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.bridges.portletfilter;
+
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * A filter is an object that performs filtering tasks on either the request
+ * to a resource (a portlet), or on the response from a resource, or both.
+ *
+ * Filters perform filtering in the renderFilter and processActionFilter
+ * method. Every Filter has access to a PortletFilterConfig object from
+ * which it can obtain its initialization parameters, a reference to the
+ * PortletConfig which it can use, for example, to load resources needed
+ * for filtering tasks. Filters are configured in the deployment descriptor
+ * of a portlet(portlet.xml).
+ *
+ * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
+ */
+public interface PortletFilter
+{
+
+ /**
+ * Called by init method of FilterPortlet to initialize this
+ * portlet filter.
+ *
+ * @param filterConfig
+ * @throws PortletException
+ */
+ public abstract void init(PortletFilterConfig filterConfig) throws PortletException;
+
+ /**
+ * Called by render method of FilterPortlet to put tags, such as
+ * <style>, into <head>.
+ *
+ * @param request
+ * @param response
+ * @param chain PortletFilterChain instance
+ * @throws PortletException
+ */
+ public abstract void renderFilter(RenderRequest request, RenderResponse response, PortletFilterChain chain)
+ throws PortletException, IOException;
+
+ /**
+ * Called by render method of FilterPortlet to wrap the request
+ * when it has a multipart content.
+ *
+ * @param request
+ * @param response
+ * @param chain PortletFilterChain instance
+ * @throws PortletException
+ */
+ public abstract void processActionFilter(ActionRequest request, ActionResponse response, PortletFilterChain chain)
+ throws PortletException, IOException;
+
+ /**
+ * Called by destroy method of FilterPortlet to destroy this
+ * portlet filter.
+ *
+ * @throws PortletException
+ */
+ public abstract void destroy();
+
+}
\ No newline at end of file
Propchange: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java (added)
+++ portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java Mon Oct 31 13:31:29 2005
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.bridges.portletfilter;
+
+
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A PortletFilterChain is an object provided to the developer giving a view
+ * into the invocation chain of a filtered request for a resource.
+ * PortletFilters use the PortletFilterChain to invoke the next filter in the
+ * chain, or if the calling filter is the last filter in the chain, to invoke
+ * the resource at the end of the chain.
+ *
+ * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
+ *
+ */
+public class PortletFilterChain
+{
+ private static final Log log = LogFactory.getLog(PortletFilterChain.class);
+
+ // -------------------------------------------------------------- Constants
+
+ public static final int INCREMENT = 10;
+
+ public static final String PORTLET_FILTERS = "portlet-filters";
+
+ /**
+ * PortletFilters.
+ */
+ private PortletFilterConfig[] filters = new PortletFilterConfig[0];
+
+ /**
+ * The int which is used to maintain the current position in the filter chain.
+ */
+ private int renderPosition = 0;
+
+ /**
+ * The int which is used to maintain the current position in the filter chain.
+ */
+ private int processActionPosition = 0;
+
+ /**
+ * The int which gives the current number of filters in the chain.
+ */
+ private int n = 0;
+
+ /**
+ * The portlet instance to be executed by this chain.
+ */
+ private Portlet portlet = null;
+
+ public PortletFilterChain(PortletConfig config)
+ {
+ String portletFilters = config.getInitParameter(PORTLET_FILTERS);
+ StringTokenizer st = new StringTokenizer(portletFilters, ", ");
+ while (st.hasMoreTokens())
+ {
+ String className = st.nextToken();
+ try
+ {
+ addPortletFilter(new PortletFilterConfig(className, config));
+ }
+ catch (PortletException e)
+ {
+ log.warn("Invalid portlet filter: " + className, e);
+ }
+ }
+ }
+
+ /**
+ * Causes the next filter for renderFilter in the chain to be invoked, or
+ * if the calling filter is the last filter in the chain, causes the
+ * resource at the end of the chain to be invoked.
+ *
+ * @param request
+ * @param response
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void renderFilter(RenderRequest request, RenderResponse response) throws PortletException, IOException
+ {
+ // Call the next filter if there is one
+ if (renderPosition < n)
+ {
+ PortletFilterConfig filterConfig = filters[renderPosition++];
+ PortletFilter filter = filterConfig.getPortletFilter();
+
+ filter.renderFilter(request, response, this);
+ return;
+ }
+
+ renderPosition = 0;
+
+ // We fell off the end of the chain -- call the servlet instance
+ portlet.render(request, response);
+ }
+
+ /**
+ * Causes the next filter for processActionFilter in the chain to be invoked, or
+ * if the calling filter is the last filter in the chain, causes the
+ * resource at the end of the chain to be invoked.
+ *
+ * @param request
+ * @param response
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void processActionFilter(ActionRequest request, ActionResponse response) throws PortletException,
+ IOException
+ {
+ // Call the next filter if there is one
+ if (processActionPosition < n)
+ {
+ PortletFilterConfig filterConfig = filters[processActionPosition++];
+ PortletFilter filter = filterConfig.getPortletFilter();
+
+ filter.processActionFilter(request, response, this);
+ return;
+ }
+
+ processActionPosition = 0;
+
+ // We fell off the end of the chain -- call the servlet instance
+ portlet.processAction(request, response);
+
+ }
+
+ /**
+ * Add a filter to the set of filters that will be executed in this chain.
+ *
+ * @param filterConfig The PortletFilterConfig for the portlet to be executed
+ */
+ public void addPortletFilter(PortletFilterConfig filterConfig)
+ {
+ if (filterConfig != null && filterConfig.getPortletFilter() != null)
+ {
+ if (n == filters.length)
+ {
+ PortletFilterConfig[] newFilters = new PortletFilterConfig[n + INCREMENT];
+ System.arraycopy(filters, 0, newFilters, 0, n);
+ filters = newFilters;
+ }
+ filters[n++] = filterConfig;
+ }
+ }
+
+ /**
+ * Release references to the filters and wrapper executed by this chain.
+ */
+ public void release()
+ {
+ n = 0;
+ renderPosition = 0;
+ processActionPosition = 0;
+ for (int i = 0; i < n; i++)
+ {
+ filters[i].release();
+ }
+ portlet = null;
+ }
+
+ /**
+ * Set Portlet instance.
+ *
+ * @param portlet The portlet to set.
+ */
+ public void setPortlet(Portlet portlet)
+ {
+ this.portlet = portlet;
+ }
+
+}
Propchange: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterChain.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java (added)
+++ portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java Mon Oct 31 13:31:29 2005
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.bridges.portletfilter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+
+/**
+ * A filter configuration object used by FilterPortlet to pass
+ * information to a filter during initialization.
+ *
+ * The initialization parameter provided by getInitParameter(String) is
+ * specified in the portlet descriptor(portlet.xml) with the target
+ * PortletFilter name and a separator(:).
+ *
+ * Example:
+ * <pre>
+ * <portlet-app id="example-portlets" version="1.0">
+ * <portlet id="ExamplePortlet">
+ * ...
+ * <init-param>
+ * <name>portlet-class</name>
+ * <value>org.apache.myfaces.portlet.MyFacesGenericPortlet</value>
+ * </init-param>
+ * <init-param>
+ * <name>portlet-filters</name>
+ * <value>org.apache.myfaces.portlet.TomahawkPortletFilter</value>
+ * </init-param>
+ * <init-param>
+ * <name>org.apache.myfaces.portlet.TomahawkPortletFilter:upload-threshold-size</name>
+ * <value>1m</value>
+ * </init-param>
+ * <init-param>
+ * <name>org.apache.myfaces.portlet.TomahawkPortletFilter:upload-max-file-size</name>
+ * <value>10m</value>
+ * </init-param>
+ * ...
+ * </pre>
+ *
+ * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
+ *
+ */
+public class PortletFilterConfig
+{
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory.getLog(PortletFilterConfig.class);
+
+ private String PARAMETER_SEPRATOR = ":";
+
+ private PortletFilter portletFilter = null;
+
+ private PortletConfig portletConfig;
+
+ private String filterName;
+
+ private Map parameters;
+
+ public PortletFilterConfig(String filterName, PortletConfig config) throws PortletException
+ {
+ setPortletConfig(config);
+ setFilterName(filterName);
+ parseParameters();
+
+ try
+ {
+ Class portletFilterClass = Class.forName(filterName);
+ if (portletFilterClass != null)
+ {
+ Object portletFilter = portletFilterClass.newInstance();
+ if (portletFilter instanceof PortletFilter)
+ {
+ this.portletFilter = (PortletFilter) portletFilter;
+ }
+ else
+ {
+ throw new PortletException(filterName + " is not PortletFilter class.");
+ }
+ }
+ else
+ {
+ throw new PortletException(filterName + " is not found.");
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new PortletException("ClassNotFoundException occurred.", e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new PortletException("InstantiationException occurred.", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new PortletException("IllegalAccessException occurred.", e);
+ }
+
+ // init
+ this.portletFilter.init(this);
+ }
+
+ /**
+ * Parses initialization parameters in a portlet descriptor(portlet.xml).
+ */
+ private void parseParameters()
+ {
+ parameters = new HashMap();
+ for (Enumeration e = getPortletConfig().getInitParameterNames(); e.hasMoreElements();)
+ {
+ String key = (String) e.nextElement();
+ if (key.startsWith(getFilterName() + PARAMETER_SEPRATOR))
+ {
+ String newKey = key.substring(getFilterName().length() + PARAMETER_SEPRATOR.length());
+ parameters.put(newKey, getPortletConfig().getInitParameter(key));
+ }
+ }
+ }
+
+ /**
+ * Return a <code>String</code> containing the value of the named initialization parameter, or <code>null</code>
+ * if the parameter does not exist.
+ *
+ * @param name Name of the requested initialization parameter
+ */
+ public String getInitParameter(String name)
+ {
+ if (parameters == null)
+ {
+ return (null);
+ }
+ else
+ {
+ return ((String) parameters.get(name));
+ }
+ }
+
+ /**
+ * Return an <code>Enumeration</code> of the names of the initialization parameters for this Filter.
+ */
+ public Enumeration getInitParameterNames()
+ {
+ if (parameters == null)
+ return (new Enumerator(new ArrayList().iterator()));
+ else
+ return (new Enumerator(parameters.keySet().iterator()));
+
+ }
+
+ /**
+ * Returns the PortletFilter instance.
+ *
+ * @return
+ */
+ public PortletFilter getPortletFilter()
+ {
+ return portletFilter;
+ }
+
+ /**
+ * @return Returns the portletConfig.
+ */
+ public PortletConfig getPortletConfig()
+ {
+ return portletConfig;
+ }
+
+ /**
+ * @param portletConfig The portletConfig to set.
+ */
+ public void setPortletConfig(PortletConfig portletConfig)
+ {
+ this.portletConfig = portletConfig;
+ }
+
+ public void release()
+ {
+ portletFilter.destroy();
+ portletConfig = null;
+ }
+
+ /**
+ * @return Returns the filterName.
+ */
+ public String getFilterName()
+ {
+ return filterName;
+ }
+
+ /**
+ * @param filterName The filterName to set.
+ */
+ public void setFilterName(String filterName)
+ {
+ this.filterName = filterName;
+ }
+
+ /**
+ * Uitlity class to wraps an <code>Iterator</code>
+ *
+ * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
+ *
+ */
+ public final class Enumerator implements Enumeration
+ {
+ /**
+ * Return an Enumeration over the values returned by the specified
+ * Iterator.
+ *
+ * @param iterator Iterator to be wrapped
+ */
+ public Enumerator(Iterator iterator)
+ {
+
+ super();
+ this.iterator = iterator;
+
+ }
+
+ /**
+ * The <code>Iterator</code> over which the <code>Enumeration</code>
+ * represented by this class actually operates.
+ */
+ private Iterator iterator = null;
+
+ /**
+ * Tests if this enumeration contains more elements.
+ *
+ * @return <code>true</code> if and only if this enumeration object
+ * contains at least one more element to
+ * provide, <code>false</code> otherwise
+ */
+ public boolean hasMoreElements()
+ {
+
+ return (iterator.hasNext());
+
+ }
+
+ /**
+ * Returns the next element of this enumeration if this enumeration
+ * has at least one more element to provide.
+ *
+ * @return the next element of this enumeration
+ * @exception NoSuchElementException if no more elements exist
+ */
+ public Object nextElement() throws NoSuchElementException
+ {
+
+ return (iterator.next());
+
+ }
+
+ }
+}
Propchange: portals/bridges/trunk/portletfilter/src/java/org/apache/portals/bridges/portletfilter/PortletFilterConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/xdocs/index.xml
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/xdocs/index.xml?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/xdocs/index.xml (added)
+++ portals/bridges/trunk/portletfilter/xdocs/index.xml Mon Oct 31 13:31:29 2005
@@ -0,0 +1,106 @@
+<?xml version="1.0"?>
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<document>
+ <properties>
+ <title>About Apache Portals Portlet Filter</title>
+ <authors>
+ <person name="Shinsuke Sugaya" email="shinsuke@apache.org"/>
+ </authors>
+ </properties>
+ <body>
+ <section name="About Apache Portals Portlet Filter">
+ <subsection name="Overview">
+ <p>
+ FilterPortlet enables you to add processes you want before and after accessing the target portlet.
+ The feature provided by FilterPortlet is like Servlet Filter. (Portlet Filter may be included in
+ the future Portlet Spec, but currently it's not included yet.)
+ </p>
+ </subsection>
+ <subsection name="Class and Interface">
+ <p>
+ <table>
+ <tr>
+ <th>Class/Interface</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>FilterPortlet class</td>
+ <td>FilterPortlet wraps the target portlet.</td>
+ </tr>
+ <tr>
+ <td>PortletFilter interface</td>
+ <td>The process you want to add is implemented this interface.</td>
+ </tr>
+ <tr>
+ <td>PortletFilterChain class</td>
+ <td>
+ This class is an object provided to the developer giving a view
+ into the invocation chain of a filtered request for a resource.
+ </td>
+ </tr>
+ <tr>
+ <td>PortletFilterConfig class</td>
+ <td>
+ A filter configuration object used by FilterPortlet to pass
+ information to a filter during initialization.
+ </td>
+ </tr>
+ </table>
+ If you know how to use Servlet Filter, it's easy to use FilterPortlet.
+ </p>
+ </subsection>
+ <subsection name="Example">
+ <p>
+ For example, if you create "HelloWorldPortletFilter" as the portlet filter, portlet.xml is:
+ </p>
+ <p>
+<source><![CDATA[
+<portlet-app id="helloworld" version="1.0">
+ <portlet id="FilteredHelloWorld">
+ <portlet-name>FilteredHelloWorld</portlet-name>
+ <display-name>Filtered Hello World</display-name>
+ <description>HelloWorld is a filtered portlet for testing</description>
+ <portlet-class>org.apache.portals.bridges.portletfilter.FilterPortlet</portlet-class>
+ <init-param>
+ <name>portlet-class</name>
+ <value>org.apache.portals.bridges.helloworld.HelloWorldPortlet</value>
+ </init-param>
+ <init-param>
+ <name>portlet-filters</name>
+ <value>org.apache.portals.bridges.helloworld.filter.HelloWorldPortletFilter</value>
+ </init-param>
+ <expiration-cache>-1</expiration-cache>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+ <supported-locale>en</supported-locale>
+ <supported-locale>ja</supported-locale>
+ <resource-bundle>org.apache.portals.bridges.helloworld.resources.HelloWorldResources</resource-bundle>
+ <portlet-info>
+ <title>Filtered Hello World</title>
+ <short-title>This is a filtered portlet for testing</short-title>
+ <keywords>Hello,Test,PortletFilter</keywords>
+ </portlet-info>
+ </portlet>
+</portlet-app>
+]]></source>
+ </p>
+ </subsection>
+ </section>
+ </body>
+</document>
Propchange: portals/bridges/trunk/portletfilter/xdocs/index.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/bridges/trunk/portletfilter/xdocs/navigation.xml
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/portletfilter/xdocs/navigation.xml?rev=329917&view=auto
==============================================================================
--- portals/bridges/trunk/portletfilter/xdocs/navigation.xml (added)
+++ portals/bridges/trunk/portletfilter/xdocs/navigation.xml Mon Oct 31 13:31:29 2005
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<project>
+
+ <title>Portals Bridges - Portlet Filter</title>
+
+ <body>
+ <links>
+ <item name="Jetspeed 2" href="http://portals.apache.org/jetspeed-2" target="_nw"/>
+ <item name="Bridges Home" href="../../index.html"/>
+ </links>
+
+ </body>
+</project>
Propchange: portals/bridges/trunk/portletfilter/xdocs/navigation.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: portals/bridges/trunk/project.properties
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/project.properties?rev=329917&r1=329916&r2=329917&view=diff
==============================================================================
--- portals/bridges/trunk/project.properties (original)
+++ portals/bridges/trunk/project.properties Mon Oct 31 13:31:29 2005
@@ -80,6 +80,7 @@
portals.bridges.python.version=0.4-SNAPSHOT
portals.bridges.struts.version=0.4-SNAPSHOT
portals.bridges.velocity.version=0.4-SNAPSHOT
+portals.bridges.portletfilter.version=1.0-SNAPSHOT
# dependency versions
commons.logging.version=1.0.4
Modified: portals/bridges/trunk/xdocs/navigation.xml
URL: http://svn.apache.org/viewcvs/portals/bridges/trunk/xdocs/navigation.xml?rev=329917&r1=329916&r2=329917&view=diff
==============================================================================
--- portals/bridges/trunk/xdocs/navigation.xml (original)
+++ portals/bridges/trunk/xdocs/navigation.xml Mon Oct 31 13:31:29 2005
@@ -28,6 +28,7 @@
<item name="PHP Bridge" href="multiproject/portals-bridges-php/index.html"/>
<item name="Velocity Bridge" href="multiproject/portals-bridges-velocity/index.html"/>
<item name="Perl Bridge" href="multiproject/portals-bridges-perl/index.html"/>
+ <item name="Portlet Filter" href="multiproject/portals-bridges-portletfilter/index.html"/>
<item name="Frameworks" href="multiproject/portals-bridges-frameworks/index.html"/>
</menu>
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: bridges-commits-unsubscribe@portals.apache.org
For additional commands, e-mail: bridges-commits-help@portals.apache.org