Author: bdaw
Date: 2008-01-10 12:01:20 -0500 (Thu, 10 Jan 2008)
New Revision: 9472
Added:
modules/portlet/trunk/test/src/main/java/
modules/portlet/trunk/test/src/main/java/org/
modules/portlet/trunk/test/src/main/java/org/jboss/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalNavigationalState.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodec.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodecTestCase.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestActionContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestInstanceContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestPortletInvoker.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestRenderContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/WindowNavigationalState.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/metadata/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/metadata/factory/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/metadata/impl/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/CodecBuilder.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java
Removed:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalNavigationalState.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalServlet.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletController.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContext.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodec.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodecTestCase.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestActionContext.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestInstanceContext.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestPortletInvoker.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestRenderContext.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/WindowNavigationalState.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/metadata/factory/
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/metadata/impl/
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/CodecBuilder.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java
Modified:
modules/portlet/trunk/test/pom.xml
modules/portlet/trunk/test/src/test/build.xml
Log:
moving some classes....
Modified: modules/portlet/trunk/test/pom.xml
===================================================================
--- modules/portlet/trunk/test/pom.xml 2008-01-10 00:25:47 UTC (rev 9471)
+++ modules/portlet/trunk/test/pom.xml 2008-01-10 17:01:20 UTC (rev 9472)
@@ -13,100 +13,74 @@
<dependencies>
+ <dependency>
+ <groupId>org.jboss.portal.portlet</groupId>
+ <artifactId>portlet</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+
<!--TEST SCOPE-->
<dependency>
<groupId>org.jboss.portal.portlet</groupId>
<artifactId>portlet</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>concurrent</groupId>
<artifactId>concurrent</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.portal.common</groupId>
<artifactId>jboss-portal-modules-common-mc</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>javassist</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit-remote</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit-mc</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit-tooling-ant</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>portal-test</artifactId>
- <scope>test</scope>
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>dom4j</groupId>-->
- <!--<artifactId>dom4j</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
</dependency>
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>portal-test-generic</artifactId>
- <scope>test</scope>
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>dom4j</groupId>-->
- <!--<artifactId>dom4j</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
</dependency>
<dependency>
<groupId>trove</groupId>
<artifactId>trove</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>apache-xerces</groupId>
<artifactId>resolver</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jbossxb</artifactId>
- <scope>test</scope>
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>sun-jaxb</groupId>-->
- <!--<artifactId>jaxb-api</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-logging-jdk</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-logging-log4j</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
@@ -115,87 +89,70 @@
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-aop-mc-int</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-classloader</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-container</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-dependency</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-client-spi</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-client</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-core-spi</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-core</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-impl</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-spi</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-structure-spi</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-vfs-spi</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-vfs</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-managed</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-metatype</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.aop</groupId>
@@ -205,12 +162,10 @@
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>cargo</groupId>
@@ -222,27 +177,13 @@
<groupId>org.jboss.portal.web</groupId>
<artifactId>portal-web</artifactId>
<type>jar</type>
- <scope>test</scope>
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>apache-xerces</groupId>-->
- <!--<artifactId>xml-apis</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
</dependency>
<dependency>
<groupId>org.jboss.portal.portlet</groupId>
<artifactId>jsr168api</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss.portal.portlet</groupId>
- <artifactId>portlet</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
+
</dependencies>
<build>
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.common.invocation.InterceptorStack;
+import org.jboss.portal.common.invocation.Interceptor;
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class InterceptorStackFactoryImpl implements InterceptorStackFactory
+{
+
+ /** . */
+ private volatile Interceptor[] interceptors;
+
+ /** . */
+ private final InterceptorStackImpl stack = new InterceptorStackImpl();
+
+ public Interceptor[] getInterceptors()
+ {
+ return interceptors;
+ }
+
+ public void setInterceptors(Interceptor[] interceptors)
+ {
+ this.interceptors = interceptors;
+ }
+
+ public InterceptorStack getInterceptorStack()
+ {
+ return stack;
+ }
+
+ private class InterceptorStackImpl implements InterceptorStack
+ {
+
+ public int getLength()
+ {
+ // Avoid dirty reads
+ Interceptor[] interceptors = InterceptorStackFactoryImpl.this.interceptors;
+
+ //
+ return interceptors != null ? interceptors.length : 0;
+ }
+
+ public Interceptor getInterceptor(int i) throws ArrayIndexOutOfBoundsException
+ {
+ // Avoid dirty reads
+ Interceptor[] interceptors = InterceptorStackFactoryImpl.this.interceptors;
+
+ //
+ if (interceptors == null)
+ {
+ throw new ArrayIndexOutOfBoundsException("No interceptors");
+ }
+
+ //
+ return interceptors[i];
+ }
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalNavigationalState.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalNavigationalState.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalNavigationalState.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalNavigationalState.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.GZIPInputStream;
+import java.io.Serializable;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalNavigationalState implements Serializable
+{
+
+ /** . */
+ private final Map windows = new HashMap();
+
+ public WindowNavigationalState getWindow(String windowId)
+ {
+ return (WindowNavigationalState)windows.get(windowId);
+ }
+
+ public void setWindow(String windowId, WindowNavigationalState window)
+ {
+ windows.put(windowId, window);
+ }
+
+ public byte[] getBytes() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream zos = new GZIPOutputStream(baos);
+ ObjectOutputStream oos = new ObjectOutputStream(zos);
+ oos.writeObject(this);
+ oos.close();
+ return baos.toByteArray();
+ }
+
+ public static PortalNavigationalState create(byte[] bytes) throws IOException,
ClassNotFoundException
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ GZIPInputStream zis = new GZIPInputStream(bais);
+ ObjectInputStream ois = new ObjectInputStream(zis);
+ return (PortalNavigationalState)ois.readObject();
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalServlet.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalServlet extends HttpServlet
+{
+
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ try
+ {
+ _service(req, resp);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof ServletException)
+ {
+ throw (ServletException)e;
+ }
+ if (e instanceof IOException)
+ {
+ throw (IOException)e;
+ }
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException)e;
+ }
+ throw new ServletException(e);
+ }
+ }
+
+ protected void _service(HttpServletRequest req, HttpServletResponse resp) throws
Exception
+ {
+ PortletControllerContext context = new PortletControllerContextImpl(req,
PortletControllerContextImpl.SESSION_SCOPE);
+
+ //
+ PortletController controller = new PortletController(context, getServletContext(),
req);
+
+ //
+ controller.process(resp);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,327 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.web.WebAppListener;
+import org.jboss.portal.web.WebAppEvent;
+import org.jboss.portal.web.WebAppLifeCycleEvent;
+import org.jboss.portal.web.WebApp;
+import org.jboss.portal.web.ServletContainer;
+import static
org.jboss.portal.portlet.impl.metadata.PortletMetaDataConstants.PORTLET_JSR_168_NS;
+import static
org.jboss.portal.portlet.impl.metadata.PortletMetaDataConstants.PORTLET_JSR_286_NS;
+import org.jboss.portal.portlet.impl.metadata.PortletApplication10MetaData;
+import
org.jboss.portal.portlet.test.metadata.impl.AnnotationPortletApplication20MetaData;
+import
org.jboss.portal.portlet.test.metadata.impl.AnnotationPortletApplication10MetaData;
+import org.jboss.portal.portlet.test.metadata.impl.ValueTrimmingFilter;
+import org.jboss.portal.portlet.test.metadata.factory.PortletApplicationModelFactory;
+import org.jboss.portal.portlet.container.PortletApplication;
+import org.jboss.portal.portlet.container.PortletContainer;
+import org.jboss.portal.portlet.container.PortletApplicationRegistry;
+import org.jboss.portal.portlet.container.PortletApplicationRegistrationContext;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.apache.log4j.Logger;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.net.URL;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletApplicationDeployer implements WebAppListener,
KernelControllerContextAware
+{
+
+ /** The schema resolver factory. */
+ private static SingletonSchemaResolverFactory factory;
+
+ /** The schema resolver. */
+ private static DefaultSchemaResolver resolver;
+
+ static
+ {
+ try
+ {
+ factory = SingletonSchemaResolverFactory.getInstance();
+ resolver = (DefaultSchemaResolver) factory.getSchemaBindingResolver();
+
+ /** SchemaResolver */
+ resolver.addSchemaLocation(PORTLET_JSR_168_NS,
"portlet-app_1_0.xsd");
+ resolver.addSchemaLocation(PORTLET_JSR_286_NS,
"portlet-app_2_0.xsd");
+ resolver.addClassBinding(PORTLET_JSR_286_NS,
AnnotationPortletApplication20MetaData.class);
+ resolver.addClassBinding(PORTLET_JSR_168_NS,
AnnotationPortletApplication10MetaData.class);
+ }
+ catch (Exception e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ /** . */
+ private Logger log = Logger.getLogger(PortletApplicationDeployer.class);
+
+ /** . */
+ private PortletApplicationRegistry registry;
+
+ /** . */
+ private ServletContainer servletContainer;
+
+ /** . */
+ private KernelControllerContext controllerContext;
+
+ /** . */
+ private Map deploymentMap = new HashMap();
+
+ /** . */
+ private ClassLoader classLoader;
+
+ /** . */
+ private final Map registrationContextMap = new HashMap();
+
+ /** . */
+ private Object driver;
+
+ public Object getDriver()
+ {
+ return driver;
+ }
+
+ public void setDriver(Object driver)
+ {
+ this.driver = driver;
+ }
+
+ public PortletApplicationRegistry getRegistry()
+ {
+ return registry;
+ }
+
+ public void setRegistry(PortletApplicationRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ public ServletContainer getServletContainer()
+ {
+ return servletContainer;
+ }
+
+ public void setServletContainer(ServletContainer servletContainer)
+ {
+ this.servletContainer = servletContainer;
+ }
+
+ public void onEvent(WebAppEvent event)
+ {
+ if (event instanceof WebAppLifeCycleEvent)
+ {
+ WebAppLifeCycleEvent lifeCycleEvent = (WebAppLifeCycleEvent)event;
+ String cp = event.getWebApp().getContextPath();
+ switch(lifeCycleEvent.getType())
+ {
+ case WebAppLifeCycleEvent.ADDED:
+ log.debug("Going to install war file" + cp);
+ add(event.getWebApp());
+ log.debug("Installed war file" + cp);
+ break;
+ case WebAppLifeCycleEvent.REMOVED:
+ try
+ {
+ log.debug("Going to uninstall war file" + cp);
+ remove(event.getWebApp());
+ log.debug("Uninstalled war file" + cp);
+ }
+ catch (Throwable e)
+ {
+ log.error("Uninstalled war file " + cp + " with an
error", e);
+ }
+ break;
+ }
+ }
+ }
+
+ private void add(WebApp webApp)
+ {
+ // Set the driver for the web app
+ webApp.getServletContext().setAttribute("TestDriverServer", driver);
+
+ //
+ PortletApplication10MetaData metaData = buildPortletApplicationMetaData(webApp);
+ if (metaData != null)
+ {
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ Kernel kernel = controllerContext.getKernel();
+ PortletApplicationDeployment deployment = new
PortletApplicationDeployment(kernel, webApp, metaData);
+ deploymentMap.put(webApp.getContextPath(), deployment);
+ deployment.start();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ }
+ }
+
+ private void remove(WebApp webApp)
+ {
+ PortletApplicationDeployment deployment =
(PortletApplicationDeployment)deploymentMap.remove(webApp.getContextPath());
+ if (deployment != null)
+ {
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ deployment.stop();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ }
+ }
+
+ public void setKernelControllerContext(KernelControllerContext controllerContext)
throws Exception
+ {
+ log.debug("Set controller context " + controllerContext);
+
+ //
+ this.controllerContext = controllerContext;
+ }
+
+ public void unsetKernelControllerContext(KernelControllerContext controllerContext)
throws Exception
+ {
+ log.debug("Unset controller context " + controllerContext);
+
+ //
+ this.controllerContext = null;
+ }
+
+ public void start()
+ {
+ classLoader = Thread.currentThread().getContextClassLoader();
+
+ //
+ servletContainer.addWebAppListener(this);
+ }
+
+ public void stop()
+ {
+ servletContainer.removeWebAppListener(this);
+
+ //
+ classLoader = null;
+ }
+
+ private PortletApplication10MetaData buildPortletApplicationMetaData(WebApp webApp)
+ {
+ try
+ {
+ URL url =
webApp.getServletContext().getResource("/WEB-INF/portlet.xml");
+ if (url != null)
+ {
+ InputStream in = null;
+ try
+ {
+ in = IOTools.safeBufferedWrapper(url.openStream());
+
+ // Validate
+ Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
+ unmarshaller.setNamespaceAware(true);
+ unmarshaller.setSchemaValidation(false);
+ unmarshaller.setValidation(false);
+
+ //
+ PortletApplicationModelFactory factory = new
PortletApplicationModelFactory();
+
+ // Unmarshal
+ PortletApplication10MetaData portletApplicationMD =
(PortletApplication10MetaData)unmarshaller.unmarshal(in, new ValueTrimmingFilter(factory),
null);
+ portletApplicationMD.setId(webApp.getContextPath());
+
+ //
+ return portletApplicationMD;
+ }
+ finally
+ {
+ IOTools.safeClose(in);
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ log.error("Cannot read portlet.xml", e);
+ }
+ catch (JBossXBException e)
+ {
+ log.error("Cannot parse portlet.xml", e);
+ }
+ return null;
+ }
+
+ /**
+ * Called by MC to install application.
+ */
+ public void installPortletApplication(PortletApplication application)
+ {
+ PortletApplicationRegistrationContext context =
registry.registerPortletApplication(application);
+ registrationContextMap.put(application, context);
+ }
+
+ /**
+ * Called by MC to install container.
+ */
+ public void installPortletContainer(PortletContainer container)
+ {
+ PortletApplicationRegistrationContext context =
(PortletApplicationRegistrationContext)registrationContextMap.get(container.getApplication());
+ context.registerPortlet(container);
+ }
+
+ /**
+ * Called by MC to uninstall application.
+ */
+ public void uninstallPortletApplication(PortletApplication application)
+ {
+ registry.unregisterPortletApplication(application);
+ }
+
+ /**
+ * Called by MC to uninstall container.
+ */
+ public void uninstallPortletContainer(PortletContainer container)
+ {
+ PortletApplicationRegistrationContext context =
(PortletApplicationRegistrationContext)registrationContextMap.get(container.getApplication());
+ context.unregisterPortlet(container);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,288 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.container.PortletApplicationContext;
+import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
+import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
+import org.jboss.portal.portlet.impl.jsr168.SimpleResourceBundleFactory;
+import org.jboss.portal.portlet.impl.jsr168.spi.PortletAPIFactory;
+import org.jboss.portal.portlet.impl.metadata.PortletApplication10MetaData;
+import org.jboss.portal.portlet.impl.metadata.portlet.PortletMetaData;
+import org.jboss.portal.portlet.impl.info.ContainerPortletInfo;
+import org.jboss.portal.portlet.impl.info.ContainerPortletInfoBuilder;
+import org.jboss.portal.portlet.metadata.JBossApplicationMetaData;
+import org.jboss.portal.web.WebApp;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.i18n.ResourceBundleFactory;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractLifecycleMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractInstallMetaData;
+import org.jboss.beans.metadata.plugins.ThisValueMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.InstallMetaData;
+import org.apache.log4j.Logger;
+
+import javax.servlet.ServletContext;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletApplicationDeployment implements PortletApplicationContext
+{
+
+ /** . */
+ private final Logger log;
+
+ /** . */
+ private final Kernel kernel;
+
+ /** . */
+ private final WebApp webApp;
+
+ /** . */
+ private final PortletApplication10MetaData metaData;
+
+ /** . */
+ private final LinkedList<String> installed;
+
+ /** . */
+ private KernelControllerContext portletApplicationControllerContext;
+
+ /** . */
+ private List<KernelControllerContext> portletContainerControllerContexts = new
ArrayList<KernelControllerContext>();
+
+ public PortletApplicationDeployment(Kernel kernel, WebApp webApp,
PortletApplication10MetaData metaData)
+ {
+ this.kernel = kernel;
+ this.webApp = webApp;
+ this.metaData = metaData;
+ this.log = Logger.getLogger(PortletApplicationDeployment.class + "." +
webApp.getContextPath().replace('.', '_'));
+ this.installed = new LinkedList<String>();
+ }
+
+ void start()
+ {
+
+ log.debug("Starting installation");
+
+ //
+ KernelController controller = kernel.getController();
+
+ //
+ String portletApplicationId = "PortletApplication[" +
webApp.getContextPath() + "]";
+
+ //
+ for (PortletMetaData portletMetaData : metaData.getPortlets().values())
+ {
+ // Create resource bundle manager
+ String baseName = portletMetaData.getResourceBundle();
+ ResourceBundleFactory rbf = new
SimpleResourceBundleFactory(webApp.getClassLoader(), baseName);
+ ResourceBundleManager bundleMgr = new ResourceBundleManager(null, rbf);
+
+ // Build container info
+ ContainerPortletInfo containerInfo = new
ContainerPortletInfoBuilder(portletMetaData, bundleMgr).build();
+
+ //
+ String portletContainerId = "PortletContainer[" +
webApp.getContextPath() + "," + portletMetaData.getPortletName() +
"]";
+
+ //
+ AbstractBeanMetaData bmd = new AbstractBeanMetaData(portletContainerId,
PortletContainerImpl.class.getName());
+ AbstractConstructorMetaData ctormd = new AbstractConstructorMetaData();
+ ctormd.setParameters(Tools.toList((ParameterMetaData)new
AbstractParameterMetaData(ContainerPortletInfo.class.getName(), containerInfo), new
AbstractParameterMetaData(ResourceBundleManager.class.getName(), bundleMgr)));
+ bmd.setConstructor(ctormd);
+ bmd.setStart(new AbstractLifecycleMetaData("start"));
+ bmd.setStop(new AbstractLifecycleMetaData("stop"));
+ bmd.setProperties(Collections.singleton((PropertyMetaData)new
AbstractPropertyMetaData("application", new
AbstractDependencyValueMetaData(portletApplicationId))));
+ AbstractInstallMetaData deployerinstallmd = new AbstractInstallMetaData();
+ deployerinstallmd.setBean("PortletApplicationDeployer");
+ deployerinstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ deployerinstallmd.setMethodName("installPortletContainer");
+ AbstractInstallMetaData applicationinstallmd = new AbstractInstallMetaData();
+ applicationinstallmd.setBean(portletApplicationId);
+
applicationinstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ applicationinstallmd.setMethodName("addContainer");
+ bmd.setInstalls(Tools.toList((InstallMetaData)deployerinstallmd,
applicationinstallmd));
+ AbstractInstallMetaData deployeruninstallmd = new AbstractInstallMetaData();
+ deployeruninstallmd.setBean("PortletApplicationDeployer");
+
deployeruninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ deployeruninstallmd.setMethodName("uninstallPortletContainer");
+ AbstractInstallMetaData applicationuninstallmd = new AbstractInstallMetaData();
+ applicationuninstallmd.setBean(portletApplicationId);
+
applicationuninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ applicationuninstallmd.setMethodName("removeContainer");
+ bmd.setUninstalls(Tools.toList((InstallMetaData)deployeruninstallmd,
applicationuninstallmd));
+ try
+ {
+ installed.addFirst(portletContainerId);
+ KernelControllerContext portletContainerControllerContext =
kernel.getController().install(bmd);
+ portletContainerControllerContexts.add(portletContainerControllerContext);
+ }
+ catch (Throwable t)
+ {
+ log.debug("Cannot install portlet container " +
portletMetaData.getPortletName() + " produced an error", t);
+ }
+ }
+
+ //
+ AbstractBeanMetaData bmd = new AbstractBeanMetaData(portletApplicationId,
PortletApplicationImpl.class.getName());
+ AbstractConstructorMetaData ctormd = new AbstractConstructorMetaData();
+ ctormd.setParameters(Tools.toList(
+ (ParameterMetaData)new
AbstractParameterMetaData(PortletApplication10MetaData.class.getName(), metaData),
+ new AbstractParameterMetaData(JBossApplicationMetaData.class.getName(),
(Object)null),
+ new AbstractParameterMetaData(PortletApplicationContext.class.getName(), this),
+ new AbstractParameterMetaData(PortletAPIFactory.class.getName(), new
AbstractDependencyValueMetaData("PortletAPIFactory"))));
+ bmd.setConstructor(ctormd);
+ bmd.setStart(new AbstractLifecycleMetaData("start"));
+ bmd.setStop(new AbstractLifecycleMetaData("stop"));
+ AbstractInstallMetaData installmd = new AbstractInstallMetaData();
+ installmd.setBean("PortletApplicationDeployer");
+ installmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ installmd.setMethodName("installPortletApplication");
+ bmd.setInstalls(Collections.singletonList((InstallMetaData)installmd));
+ AbstractInstallMetaData uninstallmd = new AbstractInstallMetaData();
+ uninstallmd.setBean("PortletApplicationDeployer");
+ uninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
+ uninstallmd.setMethodName("uninstallPortletApplication");
+ bmd.setUninstalls(Collections.singletonList((InstallMetaData)uninstallmd));
+
+ //
+ try
+ {
+ installed.addFirst(portletApplicationId);
+ portletApplicationControllerContext = controller.install(bmd);
+ }
+ catch (Throwable throwable)
+ {
+ log.debug("Installation of portlet application produced an error",
throwable);
+ }
+
+ logBeanFailure(portletApplicationControllerContext);
+ for (KernelControllerContext portletContainerControllerContext :
portletContainerControllerContexts)
+ {
+ logBeanFailure(portletContainerControllerContext);
+ }
+ }
+
+ private void logBeanFailure(KernelControllerContext context)
+ {
+ Throwable t = context.getError();
+ if (t != null)
+ {
+ log.debug("Installation of bean " + context.getName() + "
produced an error", t);
+ }
+ }
+
+ void stop()
+ {
+ log.debug("Stopping installation");
+
+ KernelController controller = kernel.getController();
+
+ for (Iterator<String> i = installed.iterator();i.hasNext();)
+ {
+ String beanName = i.next();
+ i.remove();
+ try
+ {
+ controller.uninstall(beanName);
+ }
+ catch (Throwable t)
+ {
+ // MC throws Error .... need to catch them here
+
+ log.error("Bean " + beanName + " undeployment threw
something", t);
+ }
+ }
+
+ //
+ portletApplicationControllerContext = null;
+ portletContainerControllerContexts = null;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return webApp.getServletContext();
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return webApp.getClassLoader();
+ }
+
+ public void startPortletApplication() throws Exception
+ {
+ throw new NotYetImplemented();
+// try
+// {
+// kernel.getController().change(portletApplicationControllerContext,
ControllerState.INSTALLED);
+// }
+// catch (Throwable throwable)
+// {
+// }
+ }
+
+ public void stopPortletApplication()
+ {
+ throw new NotYetImplemented();
+// try
+// {
+// kernel.getController().change(portletApplicationControllerContext,
ControllerState.CREATE);
+// }
+// catch (Throwable throwable)
+// {
+// throwable.printStackTrace();
+// }
+ }
+
+ public void startPortletContainer(String portletName) throws Exception
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void stopPortletContainer(String portletName)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public String getContextPath()
+ {
+ throw new NotYetImplemented();
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletController.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,369 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.PortletParametersStateString;
+import org.jboss.portal.portlet.PortletParameters;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.RenderURL;
+import org.jboss.portal.portlet.impl.spi.AbstractRequestContext;
+import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
+import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
+import org.jboss.portal.portlet.impl.spi.AbstractPortalContext;
+import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.RenderResponse;
+import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.web.IllegalRequestException;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.MarkupInfo;
+import org.jboss.portal.common.util.MediaType;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
+import java.io.UnsupportedEncodingException;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletController
+{
+
+ /** . */
+ private MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML, "UTF8");
+
+ /** . */
+ private final ServletContext servletContext;
+
+ /** . */
+ private final HttpServletRequest req;
+
+ /** . */
+ private final PortletInvoker invoker;
+
+ /** . */
+ private final PortletControllerContext context;
+
+ /** . */
+ private final boolean redirectAfterAction = true;
+
+ public PortletController(PortletControllerContext context, ServletContext
servletContext, HttpServletRequest req) throws IllegalRequestException,
UnsupportedEncodingException
+ {
+ this.context = context;
+ this.servletContext = servletContext;
+
+ //
+ this.req = req;
+ this.invoker =
(PortletInvoker)servletContext.getAttribute("ConsumerPortletInvoker");
+ }
+
+ public void process(HttpServletResponse resp) throws PortletInvokerException,
IOException
+ {
+
+ //
+ Request request = context.getRequest();
+
+ //
+ PortalNavigationalState navState = context.getNavigationalState();
+
+ //
+ if (request != null)
+ {
+ PortletContext target = PortletContext.createPortletContext(request.portletId);
+
+ //
+ Portlet portlet = invoker.getPortlet(target);
+
+ //
+ PortletURLRenderer renderer = new PortletURLRenderer(navState, portlet, req,
resp);
+
+ //
+ WindowNavigationalState windowNS = navState.getWindow(request.portletId);
+
+ //
+ PortletInvocationResponse response = null;
+
+ if (request instanceof Render)
+ {
+ RenderResponse render = new RenderResponse();
+ render.setMode(request.mode);
+ render.setWindowState(request.windowState);
+
render.setNavigationalState(PortletParametersStateString.create(request.queryParameters));
+ response = render;
+ }
+ else
+ {
+ //
+ StateString portletNS = null;
+ if (windowNS != null)
+ {
+ portletNS = windowNS.getPortletNavigationalState();
+ }
+
+ //
+ Mode mode = request.mode;
+ if (mode == null && windowNS != null && windowNS.getMode() !=
null)
+ {
+ mode = windowNS.getMode();
+ }
+ if (mode == null)
+ {
+ mode = Mode.VIEW;
+ }
+
+ //
+ WindowState windowState = request.windowState;
+ if (windowState == null && windowNS != null &&
windowNS.getWindowState() != null)
+ {
+ windowState = windowNS.getWindowState();
+ }
+ if (windowState == null)
+ {
+ windowState = WindowState.NORMAL;
+ }
+
+ //
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
+ TestActionContext actionContext = new TestActionContext(
+ renderer,
+ mode,
+ windowState,
+ portletNS,
+ MARKUP_INFO,
+ PortletParametersStateString.create(request.queryParameters),
+ request.bodyParameters != null ? new
PortletParameters(request.bodyParameters) : null);
+ ActionInvocation action = new ActionInvocation(actionContext);
+
+ //
+ action.setRequestContext(new AbstractRequestContext(req, resp));
+ action.setInstanceContext(instanceContext);
+ action.setUserContext(new AbstractUserContext(req));
+ action.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ action.setPortalContext(new AbstractPortalContext());
+ action.setSecurityContext(new AbstractSecurityContext(req));
+ action.setTarget(instanceContext.getTarget());
+
+ //
+ try
+ {
+ response = invoker.invoke(action);
+ }
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+ }
+
+ //
+ if (response instanceof RenderResponse && redirectAfterAction)
+ {
+ final RenderResponse render = (RenderResponse)response;
+ String location = renderer.renderURL(new RenderURL()
+ {
+ public StateString getNavigationalState()
+ {
+ return render.getNavigationalState();
+ }
+ public Mode getMode()
+ {
+ return render.getMode();
+ }
+ public WindowState getWindowState()
+ {
+ return render.getWindowState();
+ }
+ }, null, null, true);
+ response = new HTTPRedirectionResponse(location);
+ }
+ }
+
+ //
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse render = (RenderResponse)response;
+
+ //
+ if (windowNS == null)
+ {
+ windowNS = new WindowNavigationalState();
+ navState.setWindow(portlet.getContext().getId(), windowNS);
+ }
+
+ //
+ if (render.getMode() != null)
+ {
+ windowNS.setMode(render.getMode());
+ }
+ if (render.getWindowState() != null)
+ {
+ windowNS.setWindowState(render.getWindowState());
+ }
+ if (render.getNavigationalState() != null)
+ {
+ windowNS.setPortletNavigationalState(render.getNavigationalState());
+ }
+ }
+ else if (response instanceof HTTPRedirectionResponse)
+ {
+ HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
+ resp.sendRedirect(redirection.getLocation());
+ return;
+ }
+ else if (response instanceof ErrorResponse)
+ {
+ ErrorResponse error = (ErrorResponse)response;
+ System.out.println("Error " + error.getMessage());
+ if (error.getCause() != null)
+ {
+ error.getCause().printStackTrace();
+ }
+ resp.sendError(404, error.getMessage());
+ return;
+ }
+ else
+ {
+ System.out.println("Not yet handled " + response);
+ }
+ }
+
+ //
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.print("<html><body>");
+
+ //
+ try
+ {
+ for (Iterator i = invoker.getPortlets().iterator(); i.hasNext();)
+ {
+ Portlet portlet = (Portlet)i.next();
+ writer.print("<div><div>" + portlet.getContext() +
"</div>");
+ PortletURLRenderer renderer = new PortletURLRenderer(navState, portlet, req,
resp);
+
+ //
+ Mode mode = Mode.VIEW;
+ WindowState windowState = WindowState.NORMAL;
+ StateString portletNS = null;
+
+ //
+ WindowNavigationalState windowNS =
navState.getWindow(portlet.getContext().getId());
+ if (windowNS != null)
+ {
+ if (windowNS.getMode() != null)
+ {
+ mode= windowNS.getMode();
+ }
+ if (windowNS.getWindowState() != null)
+ {
+ windowState= windowNS.getWindowState();
+ }
+ if (windowNS.getPortletNavigationalState() != null)
+ {
+ portletNS= windowNS.getPortletNavigationalState();
+ }
+ }
+
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), false);
+ TestRenderContext renderContext = new TestRenderContext(renderer, mode,
windowState, portletNS, MARKUP_INFO);
+
+ //
+ RenderInvocation render = new RenderInvocation(renderContext);
+
+ //
+ render.setRequestContext(new AbstractRequestContext(req, resp));
+ render.setInstanceContext(instanceContext);
+ render.setUserContext(new AbstractUserContext(req));
+ render.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ render.setPortalContext(new AbstractPortalContext());
+ render.setSecurityContext(new AbstractSecurityContext(req));
+ render.setTarget(instanceContext.getTarget());
+
+ //
+ try
+ {
+ invoker.invoke(render);
+ }
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+ }
+
+ writer.print("</div>");
+ }
+ }
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+ }
+
+ writer.print("</body></html>");
+ }
+
+ static class Request
+ {
+
+ final String portletId;
+ final ParameterMap queryParameters;
+ final ParameterMap bodyParameters;
+ final Mode mode;
+ final WindowState windowState;
+
+ public Request(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
+ {
+ this.portletId = portletId;
+ this.queryParameters = queryParameters;
+ this.bodyParameters = bodyParameters;
+ this.mode = mode;
+ this.windowState = windowState;
+ }
+ }
+
+ static class Action extends Request
+ {
+ public Action(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
+ {
+ super(portletId, queryParameters, bodyParameters, mode, windowState);
+ }
+ }
+
+ static class Render extends Request
+ {
+ public Render(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
+ {
+ super(portletId, queryParameters, bodyParameters, mode, windowState);
+ }
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContext.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContext.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface PortletControllerContext
+{
+
+ PortalNavigationalState getNavigationalState();
+
+ PortletController.Request getRequest();
+
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,155 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.web.IllegalRequestException;
+import org.jboss.portal.web.WebRequest;
+import org.jboss.portal.web.Body;
+import org.jboss.portal.portlet.test.url.ParameterDecoder;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletControllerContextImpl implements PortletControllerContext
+{
+
+ /** . */
+ public static final int NAV_SCOPE = 0;
+
+ /** . */
+ public static final int SESSION_SCOPE = 1;
+
+ /** . */
+ private final PortalNavigationalState navState;
+
+ /** . */
+ private final PortletController.Request request;
+
+ public PortletControllerContextImpl(HttpServletRequest req, int navStateScope)
+ throws IllegalRequestException, IOException, ClassNotFoundException
+ {
+
+ if (navStateScope < NAV_SCOPE || navStateScope > SESSION_SCOPE)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String pathInfo = req.getPathInfo();
+ String targetId;
+
+ if (pathInfo != null && pathInfo.startsWith("/") &&
pathInfo.length() > 1)
+ {
+ targetId = StringCodec.decode(pathInfo.substring(1));
+
+ WebRequest ri = new WebRequest(req);
+ ParameterDecoder decoder = PortletURLRenderer.builder.createDecoder();
+ decoder.decode(ri.getQueryParameterMap());
+
+ //
+ ParameterMap metaParameters = decoder.getMetaParameters();
+
+ PortalNavigationalState navState;
+ if (navStateScope == NAV_SCOPE)
+ {
+ String ns = metaParameters.getValue("ns");
+ byte[] bytes = Tools.fromHexString(ns);
+ navState = PortalNavigationalState.create(bytes);
+ }
+ else
+ {
+ navState =
(PortalNavigationalState)req.getSession().getAttribute("nav_state");
+ }
+
+ //
+ ParameterMap actualParameters = decoder.getActualParameters();
+
+ //
+ Mode mode = null;
+ if (metaParameters.getValue("mode") != null)
+ {
+ mode = Mode.create(metaParameters.getValue("mode"));
+ }
+
+ //
+ WindowState windowState = null;
+ if (metaParameters.getValue("windowstate") != null)
+ {
+ windowState =
WindowState.create(metaParameters.getValue("windowstate"));
+ }
+
+ //
+ PortletController.Request request;
+ String type = metaParameters.getValue("type");
+
+ //
+ ParameterMap formParameters = null;
+ if (ri.getBody() instanceof Body.Form)
+ {
+ formParameters = ((Body.Form)ri.getBody()).getParameters();
+ }
+
+ if ("action".equals(type))
+ {
+ request = new PortletController.Action(targetId, actualParameters,
formParameters, mode, windowState);
+ }
+ else
+ {
+ request = new PortletController.Render(targetId, actualParameters,
formParameters, mode, windowState);
+ }
+
+ //
+ this.navState = navState;
+ this.request = request;
+ }
+ else
+ {
+ this.navState = new PortalNavigationalState();
+ this.request = null;
+
+ //
+ if (navStateScope == SESSION_SCOPE)
+ {
+ req.getSession().setAttribute("nav_state", navState);
+ }
+ }
+ }
+
+ public PortletController.Request getRequest()
+ {
+ return request;
+ }
+
+ public PortalNavigationalState getNavigationalState()
+ {
+ return navState;
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletURLRenderer.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,151 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletURL;
+import org.jboss.portal.portlet.RenderURL;
+import org.jboss.portal.portlet.PortletParametersStateString;
+import org.jboss.portal.portlet.ActionURL;
+import org.jboss.portal.portlet.test.url.CodecBuilder;
+import org.jboss.portal.portlet.test.url.ParameterEncoder;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.Tools;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Iterator;
+import java.util.Map;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletURLRenderer
+{
+
+ /** . */
+ final Portlet portlet;
+
+ /** . */
+ final HttpServletRequest clientReq;
+
+ /** . */
+ final HttpServletResponse clientResp;
+
+ /** . */
+ final PortalNavigationalState navState;
+
+ public PortletURLRenderer(PortalNavigationalState navState, Portlet portlet,
HttpServletRequest clientReq, HttpServletResponse clientResp)
+ {
+ this.navState = navState;
+ this.portlet = portlet;
+ this.clientReq = clientReq;
+ this.clientResp = clientResp;
+ }
+
+ static final CodecBuilder builder = new CodecBuilder("action").
+ addMetaParameter("windowstate").
+ addMetaParameter("mode").
+ addMetaParameter("type").
+ addMetaParameter("ns");
+
+ String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean wantAuthenticated,
boolean relative)
+ {
+ CharBuffer buffer = new CharBuffer();
+ buffer.append(clientReq.getScheme());
+ buffer.append("://");
+ buffer.append(clientReq.getServerName());
+ buffer.append(':');
+ buffer.append(Integer.toString(clientReq.getServerPort()));
+ buffer.append(clientReq.getContextPath());
+ buffer.append('/');
+ buffer.append(StringCodec.encode(portlet.getContext().getId()));
+
+ //
+ ParameterMap metaParameters = new ParameterMap();
+
+ //
+ metaParameters.setValue("type", portletURL instanceof RenderURL ?
"render" : "action");
+
+ //
+ try
+ {
+ byte[] bytes = navState.getBytes();
+ String ns = Tools.toHexString(bytes);
+ metaParameters.setValue("ns", ns);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ //
+ if (portletURL.getMode() != null)
+ {
+ metaParameters.setValue("mode", portletURL.getMode().toString());
+ }
+ if (portletURL.getWindowState() != null)
+ {
+ metaParameters.setValue("windowstate",
portletURL.getWindowState().toString());
+ }
+
+ //
+ ParameterMap actualParameters;
+ if (portletURL instanceof RenderURL)
+ {
+ actualParameters =
((PortletParametersStateString)((RenderURL)portletURL).getNavigationalState()).getParameters();
+ }
+ else
+ {
+ actualParameters =
((PortletParametersStateString)((ActionURL)portletURL).getInteractionState()).getParameters();
+ }
+
+ //
+ ParameterEncoder encoder = builder.createEncoder();
+ encoder.encode(actualParameters, metaParameters);
+ boolean first = true;
+ for (Iterator i = encoder.getParameters().entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry parameter = (Map.Entry)i.next();
+ String name = (String)parameter.getKey();
+ String[] values = (String[])parameter.getValue();
+ for (int j = 0; j < values.length; j++)
+ {
+ String value = values[j];
+ buffer.append(first ? '?' : '&');
+ buffer.append(name, FastURLEncoder.getUTF8Instance());
+ buffer.append('=');
+ buffer.append(value, FastURLEncoder.getUTF8Instance());
+ first = false;
+ }
+ }
+
+ //
+ String url = buffer.asString();
+ return clientResp.encodeURL(url);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodec.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodec.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodec.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodec.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,114 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import java.io.OutputStreamWriter;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringCodec
+{
+
+ private static char[] blah = "0123456789ABCDEF".toCharArray();
+
+
+ public static String encode(String decodedValue)
+ {
+ try
+ {
+ StringBuffer buffer = new StringBuffer();
+ char[] tmp = new char[1];
+ for (int i = 0;i < decodedValue.length();i++)
+ {
+ char c = decodedValue.charAt(i);
+ if (Character.isLetterOrDigit(c))
+ {
+ buffer.append(c);
+ }
+ else
+ {
+ tmp[0] = c;
+ byte[] bytes = new String(tmp).getBytes("UTF8");
+ for (int j = 0; j < bytes.length; j++)
+ {
+ byte b = bytes[j];
+ buffer.append('_').append(blah[(b & 0XF0) >>
4]).append(blah[b & 0x0F]);
+ }
+ }
+ }
+ return buffer.toString();
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static String decode(String encodedValue)
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(encodedValue.length());
+ for (int i = 0;i < encodedValue.length();i++)
+ {
+ char c = encodedValue.charAt(i);
+ if (Character.isLetterOrDigit(c))
+ {
+ baos.write(c);
+ }
+ else if ('_' == c)
+ {
+ if (i + 3 > encodedValue.length())
+ {
+ throw new IllegalArgumentException("There should be at least 2
chars after an _ char");
+ }
+ String hex = encodedValue.substring(i + 1, i + 3);
+ int x = Integer.parseInt(hex, 16);
+ baos.write(x);
+ i += 2;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid char " + c);
+ }
+ }
+ return baos.toString("UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+
+
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodecTestCase.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodecTestCase.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodecTestCase.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/StringCodecTestCase.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.unit.api.pojo.annotations.Test;
+
+import static org.jboss.unit.api.Assert.*;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringCodecTestCase
+{
+
+ private static final char EURO_CHAR = '\u20AC';
+
+ @Test
+ public void testA()
+ {
+
+ assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
StringCodec.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+ assertEquals("abcdefghijklmnopqrstuvwxyz",
StringCodec.encode("abcdefghijklmnopqrstuvwxyz"));
+ assertEquals("0123456789", StringCodec.encode("0123456789"));
+ assertEquals("_2F", StringCodec.encode("/"));
+ assertEquals("_40", StringCodec.encode("@"));
+ assertEquals("_E2_82_AC",
StringCodec.encode(Character.toString(EURO_CHAR)));
+ assertEquals("A_E2_82_ACB_40C", StringCodec.encode("A" +
EURO_CHAR + "B@C"));
+
+ }
+
+ @Test
+ public void testB()
+ {
+ assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
StringCodec.decode(StringCodec.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
+ assertEquals("abcdefghijklmnopqrstuvwxyz",
StringCodec.decode(StringCodec.encode("abcdefghijklmnopqrstuvwxyz")));
+ assertEquals("0123456789",
StringCodec.decode(StringCodec.encode("0123456789")));
+ assertEquals("/",
StringCodec.decode(StringCodec.encode("/")));
+ assertEquals("@",
StringCodec.decode(StringCodec.encode("@")));
+ assertEquals(Character.toString(EURO_CHAR),
StringCodec.decode(StringCodec.encode(Character.toString(EURO_CHAR))));
+ assertEquals("A" + EURO_CHAR +"B@C",
StringCodec.decode(StringCodec.encode("A" + EURO_CHAR + "B@C")));
+ }
+
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestActionContext.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestActionContext.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestActionContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestActionContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,78 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.PortletParameters;
+import org.jboss.portal.portlet.PortletURL;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.impl.spi.AbstractActionContext;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.MarkupInfo;
+import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
+import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestActionContext extends AbstractActionContext
+{
+
+ /** . */
+ private final PortletURLRenderer urlRenderer;
+
+ public TestActionContext(PortletURLRenderer urlRenderer, Mode mode, WindowState
windowState, StateString navigationalState, MarkupInfo markupInfo, StateString
interactionState, PortletParameters form)
+ {
+ super(mode, windowState, navigationalState, markupInfo, interactionState, form);
+
+ //
+ this.urlRenderer = urlRenderer;
+
+ //
+ addResolver(PortletInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(urlRenderer.clientReq));
+ addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
+ addResolver(PortletInvocation.REQUEST_PROPERTIES_SCOPE, new
MapAttributeResolver());
+ addResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, new
MapAttributeResolver());
+ addResolver(PortletInvocation.REQUEST_SCOPE, new MapAttributeResolver());
+ }
+
+ public HttpServletRequest getClientRequest() throws IllegalStateException
+ {
+ return urlRenderer.clientReq;
+ }
+
+ public HttpServletResponse getClientResponse() throws IllegalStateException
+ {
+ return urlRenderer.clientResp;
+ }
+
+ public String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
+ {
+ return urlRenderer.renderURL(portletURL, wantSecure, wantAuthenticated, relative);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestInstanceContext.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestInstanceContext.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestInstanceContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestInstanceContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.state.AccessMode;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.StateEvent;
+import org.jboss.portal.portlet.spi.InstanceContext;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestInstanceContext implements InstanceContext
+{
+
+ private HttpServletRequest req;
+
+ private boolean modifiable;
+
+ private PortletContext target;
+
+ private boolean useClone;
+
+ private String id;
+
+ public TestInstanceContext(
+ HttpServletRequest req,
+ PortletContext portletContext,
+ boolean modifiable)
+ {
+ String id = portletContext.getId();
+ PortletContext target = portletContext;
+ boolean useClone = false;
+ HttpSession session = req.getSession(false);
+ if (session != null)
+ {
+ PortletContext clone = (PortletContext)session.getAttribute("clone." +
id);
+ if (clone != null)
+ {
+ target = clone;
+ useClone = true;
+ }
+ }
+
+ //
+ this.req = req;
+ this.useClone = useClone;
+ this.target = target;
+ this.id = id;
+ this.modifiable = modifiable;
+ }
+
+ public PortletContext getTarget()
+ {
+ return target;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public AccessMode getAccessMode()
+ {
+ return modifiable ? (useClone ? AccessMode.READ_WRITE :
AccessMode.CLONE_BEFORE_WRITE) : AccessMode.READ_ONLY;
+ }
+
+ public void onStateEvent(StateEvent event)
+ {
+ target = event.getPortletContext();
+ req.getSession().setAttribute("clone." + id, target);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestPortletInvoker.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestPortletInvoker.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestPortletInvoker.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestPortletInvoker.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.portlet.state.PropertyChange;
+import org.jboss.portal.portlet.state.DestroyCloneFailure;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+import org.jboss.portal.common.invocation.InvocationHandler;
+import org.jboss.portal.common.invocation.Invocation;
+import org.jboss.portal.common.invocation.InvocationException;
+
+import java.util.Set;
+import java.util.List;
+
+/**
+ * A simple consumer.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6712 $
+ */
+public class TestPortletInvoker implements PortletInvoker
+{
+
+ /** . */
+ private InterceptorStackFactory stackFactory;
+
+ /** . */
+ private PortletInvoker producer;
+
+ /** . */
+ private InvocationHandler handler = new InvocationHandler()
+ {
+ public Object invoke(Invocation invocation) throws Exception, InvocationException
+ {
+ PortletInvocation portletInvocation = (PortletInvocation)invocation;
+ try
+ {
+ portletInvocation.setHandler(null);
+ return producer.invoke(portletInvocation);
+ }
+ finally
+ {
+ portletInvocation.setHandler(this);
+ }
+ }
+ };
+
+ public InterceptorStackFactory getStackFactory()
+ {
+ return stackFactory;
+ }
+
+ public void setStackFactory(InterceptorStackFactory stackFactory)
+ {
+ this.stackFactory = stackFactory;
+ }
+
+ public PortletInvoker getProducer()
+ {
+ return producer;
+ }
+
+ public void setProducer(PortletInvoker producer)
+ {
+ this.producer = producer;
+ }
+
+ public Set<Portlet> getPortlets() throws PortletInvokerException
+ {
+ return producer.getPortlets();
+ }
+
+ public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
+ {
+ return producer.getPortlet(portletContext);
+ }
+
+ public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ InvocationHandler prevHandler = invocation.getHandler();
+ try
+ {
+ invocation.setHandler(handler);
+ return
(PortletInvocationResponse)invocation.invoke(stackFactory.getInterceptorStack());
+ }
+ catch (Exception e)
+ {
+ if (e instanceof PortletInvokerException)
+ {
+ throw(PortletInvokerException)e;
+ }
+ else if (e instanceof RuntimeException)
+ {
+ throw(RuntimeException)e;
+ }
+ else
+ {
+ throw new PortletInvokerException(e);
+ }
+ }
+ finally
+ {
+ invocation.setHandler(prevHandler);
+ }
+ }
+
+ public PortletContext createClone(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public PropertyMap getProperties(PortletContext portletContext, Set keys) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestRenderContext.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestRenderContext.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestRenderContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/TestRenderContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.PortletURL;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.impl.spi.AbstractRenderContext;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.MarkupInfo;
+import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
+import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestRenderContext extends AbstractRenderContext
+{
+
+ /** . */
+ private final PortletURLRenderer urlRenderer;
+
+ public TestRenderContext(PortletURLRenderer urlRenderer, Mode mode, WindowState
windowState, StateString navigationalState, MarkupInfo markupInfo)
+ {
+ super(mode, windowState, navigationalState, markupInfo);
+
+ //
+ this.urlRenderer = urlRenderer;
+
+ //
+ addResolver(PortletInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(urlRenderer.clientReq));
+ addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
+ addResolver(PortletInvocation.REQUEST_PROPERTIES_SCOPE, new
MapAttributeResolver());
+ addResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, new
MapAttributeResolver());
+ addResolver(PortletInvocation.REQUEST_SCOPE, new MapAttributeResolver());
+ }
+
+ public HttpServletRequest getClientRequest() throws IllegalStateException
+ {
+ return urlRenderer.clientReq;
+ }
+
+ public HttpServletResponse getClientResponse() throws IllegalStateException
+ {
+ return urlRenderer.clientResp;
+ }
+
+ public String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
+ {
+ return urlRenderer.renderURL(portletURL, wantSecure, wantAuthenticated, relative);
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/WindowNavigationalState.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/WindowNavigationalState.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/WindowNavigationalState.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/WindowNavigationalState.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test;
+
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowNavigationalState implements Serializable
+{
+
+ /** . */
+ private StateString portletNavigationalState;
+
+ /** . */
+ private Mode mode;
+
+ /** . */
+ private WindowState windowState;
+
+ public StateString getPortletNavigationalState()
+ {
+ return portletNavigationalState;
+ }
+
+ public void setPortletNavigationalState(StateString portletNavigationalState)
+ {
+ this.portletNavigationalState = portletNavigationalState;
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public void setMode(Mode mode)
+ {
+ this.mode = mode;
+ }
+
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+
+ public void setWindowState(WindowState windowState)
+ {
+ this.windowState = windowState;
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/metadata/factory
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/metadata/factory)
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/metadata/impl (from
rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/metadata/impl)
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/CodecBuilder.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/CodecBuilder.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/CodecBuilder.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/CodecBuilder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test.url;
+
+import java.util.LinkedHashSet;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CodecBuilder
+{
+
+ /** . */
+ final ArrayList metaParameterNames;
+
+ /** . */
+ final String reservedParameterName;
+
+ public CodecBuilder(CodecBuilder that)
+ {
+ this.metaParameterNames = new ArrayList(that.metaParameterNames);
+ this.reservedParameterName = that.reservedParameterName;
+ }
+
+ public CodecBuilder(String reservedParameter)
+ {
+ this.metaParameterNames = new ArrayList();
+ this.reservedParameterName = reservedParameter;
+ }
+
+ public CodecBuilder addMetaParameter(String name)
+ {
+ if (metaParameterNames.contains(name))
+ {
+ throw new IllegalStateException();
+ }
+ if (reservedParameterName.equals(name))
+ {
+ throw new IllegalStateException();
+ }
+ metaParameterNames.add(name);
+ return this;
+ }
+
+ public ParameterEncoder createEncoder()
+ {
+ return new ParameterEncoder(this);
+ }
+
+ public ParameterDecoder createDecoder()
+ {
+ return new ParameterDecoder(this);
+ }
+
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,161 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test.url;
+
+import org.jboss.portal.common.util.ParameterMap;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParameterDecoder
+{
+
+ /** . */
+ private final CodecBuilder builder;
+
+ /** . */
+ private final ParameterMap metaParameters;
+
+ /** . */
+ private final ParameterMap actualParameters;
+
+ public ParameterDecoder(CodecBuilder builder)
+ {
+ this.builder = builder;
+ this.actualParameters = new ParameterMap();
+ this.metaParameters = new ParameterMap();
+ }
+
+ public ParameterMap getMetaParameters()
+ {
+ return metaParameters;
+ }
+
+ public ParameterMap getActualParameters()
+ {
+ return actualParameters;
+ }
+
+ public void decode(ParameterMap parameters)
+ {
+ actualParameters.clear();
+ metaParameters.clear();
+
+ // Get the meta parameter
+ long reservedParameter = 0;
+ String[] reservedParameters = parameters.getValues(builder.reservedParameterName);
+ if (reservedParameters != null)
+ {
+ if (reservedParameters.length < 1)
+ {
+ throw new IllegalArgumentException();
+ }
+ try
+ {
+ reservedParameter = Long.parseLong(reservedParameters[0], 2);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ for (int i = builder.metaParameterNames.size() - 1;reservedParameter > 0;)
+ {
+ if (i < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String parameterName = (String)builder.metaParameterNames.get(i--);
+
+ //
+ if ((reservedParameter & 1) == 1)
+ {
+ String[] parameterValues = parameters.getValues(parameterName);
+
+ //
+ if (parameterValues == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (parameterValues.length == 0)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String metaParameterValue = parameterValues[0];
+ metaParameters.setValue(parameterName, metaParameterValue);
+
+ //
+ if (parameterValues.length > 1)
+ {
+ String[] actualParameterValues = new String[parameterValues.length - 1];
+ System.arraycopy(parameterValues, 1, actualParameterValues, 0,
actualParameterValues.length);
+ actualParameters.setValues(parameterName, actualParameterValues);
+ }
+ }
+
+ //
+ reservedParameter = reservedParameter >> 1;
+ }
+
+ //
+ for (Iterator i = parameters.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String parameterName = (String)entry.getKey();
+ if (!metaParameters.containsKey(parameterName))
+ {
+ if (builder.reservedParameterName.equals(parameterName))
+ {
+ String[] reservedParameterValues = (String[])entry.getValue();
+ if (reservedParameterValues.length > 1)
+ {
+ String[] parameterValues = new String[reservedParameterValues.length -
1];
+ System.arraycopy(reservedParameterValues, 1, parameterValues, 0,
parameterValues.length);
+ actualParameters.setValues(parameterName, parameterValues);
+ }
+ }
+ else
+ {
+ String[] parameterValues = (String[])entry.getValue();
+ actualParameters.setValues(parameterName, parameterValues);
+ }
+ }
+ }
+ }
+}
Copied:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java
(from rev 9471,
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java)
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test.url;
+
+import org.jboss.portal.common.util.ParameterMap;
+
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParameterEncoder
+{
+
+ /** . */
+ private final CodecBuilder builder;
+
+ /** . */
+ private final ParameterMap parameters;
+
+ public ParameterEncoder(CodecBuilder builder)
+ {
+ this.builder = new CodecBuilder(builder);
+ this.parameters = new ParameterMap();
+ }
+
+ public ParameterMap getParameters()
+ {
+ return parameters;
+ }
+
+ public void encode(ParameterMap actualParameters, ParameterMap metaParameters)
+ {
+ parameters.clear();
+
+ //
+ long meta = 0;
+
+ //
+ for (Iterator i = builder.metaParameterNames.iterator();i.hasNext();)
+ {
+ String mv = (String)i.next();
+ String pv = metaParameters.getValue(mv);
+
+ //
+ meta *= 2;
+
+ //
+ if (pv != null)
+ {
+ String[] pvs = actualParameters.getValues(mv);
+ if (pvs != null)
+ {
+ String[] blah = new String[1 + pvs.length];
+ blah[0] = pv;
+ System.arraycopy(pvs, 0, blah, 1, pvs.length);
+ parameters.setValues(mv, blah);
+ }
+ else
+ {
+ parameters.setValue(mv, pv);
+ }
+ meta |= 1;
+ }
+ }
+
+ //
+ String def = Long.toBinaryString(meta);
+ String[] pvs = actualParameters.getValues(builder.reservedParameterName);
+ if (pvs != null)
+ {
+ String[] blah = new String[1 + pvs.length];
+ blah[0] = def;
+ System.arraycopy(pvs, 0, blah, 1, pvs.length);
+ parameters.setValues(builder.reservedParameterName, blah);
+ }
+ else
+ {
+ parameters.setValue(builder.reservedParameterName, def);
+ }
+
+ //
+ for (Iterator i = actualParameters.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String name = (String)entry.getKey();
+ if (!parameters.containsKey(name))
+ {
+ String[] values = (String[])entry.getValue();
+ parameters.setValues(name, values);
+ }
+ }
+ }
+}
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-01-10 00:25:47 UTC (rev 9471)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-01-10 17:01:20 UTC (rev 9472)
@@ -236,6 +236,7 @@
<jar jarfile="${test.temp.lib}/portlet-test-lib.jar">
<fileset dir="${target}/test-classes"/>
+ <fileset dir="${target}/classes"/>
</jar>
<path id="mc.concurrent">
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/InterceptorStackFactoryImpl.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,84 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.common.invocation.InterceptorStack;
-import org.jboss.portal.common.invocation.Interceptor;
-import org.jboss.portal.common.invocation.InterceptorStackFactory;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class InterceptorStackFactoryImpl implements InterceptorStackFactory
-{
-
- /** . */
- private volatile Interceptor[] interceptors;
-
- /** . */
- private final InterceptorStackImpl stack = new InterceptorStackImpl();
-
- public Interceptor[] getInterceptors()
- {
- return interceptors;
- }
-
- public void setInterceptors(Interceptor[] interceptors)
- {
- this.interceptors = interceptors;
- }
-
- public InterceptorStack getInterceptorStack()
- {
- return stack;
- }
-
- private class InterceptorStackImpl implements InterceptorStack
- {
-
- public int getLength()
- {
- // Avoid dirty reads
- Interceptor[] interceptors = InterceptorStackFactoryImpl.this.interceptors;
-
- //
- return interceptors != null ? interceptors.length : 0;
- }
-
- public Interceptor getInterceptor(int i) throws ArrayIndexOutOfBoundsException
- {
- // Avoid dirty reads
- Interceptor[] interceptors = InterceptorStackFactoryImpl.this.interceptors;
-
- //
- if (interceptors == null)
- {
- throw new ArrayIndexOutOfBoundsException("No interceptors");
- }
-
- //
- return interceptors[i];
- }
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalNavigationalState.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalNavigationalState.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalNavigationalState.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,73 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.GZIPInputStream;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortalNavigationalState implements Serializable
-{
-
- /** . */
- private final Map windows = new HashMap();
-
- public WindowNavigationalState getWindow(String windowId)
- {
- return (WindowNavigationalState)windows.get(windowId);
- }
-
- public void setWindow(String windowId, WindowNavigationalState window)
- {
- windows.put(windowId, window);
- }
-
- public byte[] getBytes() throws IOException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- GZIPOutputStream zos = new GZIPOutputStream(baos);
- ObjectOutputStream oos = new ObjectOutputStream(zos);
- oos.writeObject(this);
- oos.close();
- return baos.toByteArray();
- }
-
- public static PortalNavigationalState create(byte[] bytes) throws IOException,
ClassNotFoundException
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- GZIPInputStream zis = new GZIPInputStream(bais);
- ObjectInputStream ois = new ObjectInputStream(zis);
- return (PortalNavigationalState)ois.readObject();
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalServlet.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,72 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
-import java.io.IOException;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortalServlet extends HttpServlet
-{
-
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
- {
- try
- {
- _service(req, resp);
- }
- catch (Exception e)
- {
- if (e instanceof ServletException)
- {
- throw (ServletException)e;
- }
- if (e instanceof IOException)
- {
- throw (IOException)e;
- }
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException)e;
- }
- throw new ServletException(e);
- }
- }
-
- protected void _service(HttpServletRequest req, HttpServletResponse resp) throws
Exception
- {
- PortletControllerContext context = new PortletControllerContextImpl(req,
PortletControllerContextImpl.SESSION_SCOPE);
-
- //
- PortletController controller = new PortletController(context, getServletContext(),
req);
-
- //
- controller.process(resp);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployer.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,327 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.web.WebAppListener;
-import org.jboss.portal.web.WebAppEvent;
-import org.jboss.portal.web.WebAppLifeCycleEvent;
-import org.jboss.portal.web.WebApp;
-import org.jboss.portal.web.ServletContainer;
-import static
org.jboss.portal.portlet.impl.metadata.PortletMetaDataConstants.PORTLET_JSR_168_NS;
-import static
org.jboss.portal.portlet.impl.metadata.PortletMetaDataConstants.PORTLET_JSR_286_NS;
-import org.jboss.portal.portlet.impl.metadata.PortletApplication10MetaData;
-import
org.jboss.portal.portlet.test.metadata.impl.AnnotationPortletApplication20MetaData;
-import
org.jboss.portal.portlet.test.metadata.impl.AnnotationPortletApplication10MetaData;
-import org.jboss.portal.portlet.test.metadata.impl.ValueTrimmingFilter;
-import org.jboss.portal.portlet.test.metadata.factory.PortletApplicationModelFactory;
-import org.jboss.portal.portlet.container.PortletApplication;
-import org.jboss.portal.portlet.container.PortletContainer;
-import org.jboss.portal.portlet.container.PortletApplicationRegistry;
-import org.jboss.portal.portlet.container.PortletApplicationRegistrationContext;
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.Kernel;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
-import org.apache.log4j.Logger;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.net.URL;
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletApplicationDeployer implements WebAppListener,
KernelControllerContextAware
-{
-
- /** The schema resolver factory. */
- private static SingletonSchemaResolverFactory factory;
-
- /** The schema resolver. */
- private static DefaultSchemaResolver resolver;
-
- static
- {
- try
- {
- factory = SingletonSchemaResolverFactory.getInstance();
- resolver = (DefaultSchemaResolver) factory.getSchemaBindingResolver();
-
- /** SchemaResolver */
- resolver.addSchemaLocation(PORTLET_JSR_168_NS,
"portlet-app_1_0.xsd");
- resolver.addSchemaLocation(PORTLET_JSR_286_NS,
"portlet-app_2_0.xsd");
- resolver.addClassBinding(PORTLET_JSR_286_NS,
AnnotationPortletApplication20MetaData.class);
- resolver.addClassBinding(PORTLET_JSR_168_NS,
AnnotationPortletApplication10MetaData.class);
- }
- catch (Exception e)
- {
- throw new Error(e);
- }
- }
-
- /** . */
- private Logger log = Logger.getLogger(PortletApplicationDeployer.class);
-
- /** . */
- private PortletApplicationRegistry registry;
-
- /** . */
- private ServletContainer servletContainer;
-
- /** . */
- private KernelControllerContext controllerContext;
-
- /** . */
- private Map deploymentMap = new HashMap();
-
- /** . */
- private ClassLoader classLoader;
-
- /** . */
- private final Map registrationContextMap = new HashMap();
-
- /** . */
- private Object driver;
-
- public Object getDriver()
- {
- return driver;
- }
-
- public void setDriver(Object driver)
- {
- this.driver = driver;
- }
-
- public PortletApplicationRegistry getRegistry()
- {
- return registry;
- }
-
- public void setRegistry(PortletApplicationRegistry registry)
- {
- this.registry = registry;
- }
-
- public ServletContainer getServletContainer()
- {
- return servletContainer;
- }
-
- public void setServletContainer(ServletContainer servletContainer)
- {
- this.servletContainer = servletContainer;
- }
-
- public void onEvent(WebAppEvent event)
- {
- if (event instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent lifeCycleEvent = (WebAppLifeCycleEvent)event;
- String cp = event.getWebApp().getContextPath();
- switch(lifeCycleEvent.getType())
- {
- case WebAppLifeCycleEvent.ADDED:
- log.debug("Going to install war file" + cp);
- add(event.getWebApp());
- log.debug("Installed war file" + cp);
- break;
- case WebAppLifeCycleEvent.REMOVED:
- try
- {
- log.debug("Going to uninstall war file" + cp);
- remove(event.getWebApp());
- log.debug("Uninstalled war file" + cp);
- }
- catch (Throwable e)
- {
- log.error("Uninstalled war file " + cp + " with an
error", e);
- }
- break;
- }
- }
- }
-
- private void add(WebApp webApp)
- {
- // Set the driver for the web app
- webApp.getServletContext().setAttribute("TestDriverServer", driver);
-
- //
- PortletApplication10MetaData metaData = buildPortletApplicationMetaData(webApp);
- if (metaData != null)
- {
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(classLoader);
- Kernel kernel = controllerContext.getKernel();
- PortletApplicationDeployment deployment = new
PortletApplicationDeployment(kernel, webApp, metaData);
- deploymentMap.put(webApp.getContextPath(), deployment);
- deployment.start();
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
- }
-
- private void remove(WebApp webApp)
- {
- PortletApplicationDeployment deployment =
(PortletApplicationDeployment)deploymentMap.remove(webApp.getContextPath());
- if (deployment != null)
- {
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(classLoader);
- deployment.stop();
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
- }
-
- public void setKernelControllerContext(KernelControllerContext controllerContext)
throws Exception
- {
- log.debug("Set controller context " + controllerContext);
-
- //
- this.controllerContext = controllerContext;
- }
-
- public void unsetKernelControllerContext(KernelControllerContext controllerContext)
throws Exception
- {
- log.debug("Unset controller context " + controllerContext);
-
- //
- this.controllerContext = null;
- }
-
- public void start()
- {
- classLoader = Thread.currentThread().getContextClassLoader();
-
- //
- servletContainer.addWebAppListener(this);
- }
-
- public void stop()
- {
- servletContainer.removeWebAppListener(this);
-
- //
- classLoader = null;
- }
-
- private PortletApplication10MetaData buildPortletApplicationMetaData(WebApp webApp)
- {
- try
- {
- URL url =
webApp.getServletContext().getResource("/WEB-INF/portlet.xml");
- if (url != null)
- {
- InputStream in = null;
- try
- {
- in = IOTools.safeBufferedWrapper(url.openStream());
-
- // Validate
- Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
- unmarshaller.setNamespaceAware(true);
- unmarshaller.setSchemaValidation(false);
- unmarshaller.setValidation(false);
-
- //
- PortletApplicationModelFactory factory = new
PortletApplicationModelFactory();
-
- // Unmarshal
- PortletApplication10MetaData portletApplicationMD =
(PortletApplication10MetaData)unmarshaller.unmarshal(in, new ValueTrimmingFilter(factory),
null);
- portletApplicationMD.setId(webApp.getContextPath());
-
- //
- return portletApplicationMD;
- }
- finally
- {
- IOTools.safeClose(in);
- }
- }
- }
- catch (IOException e)
- {
- log.error("Cannot read portlet.xml", e);
- }
- catch (JBossXBException e)
- {
- log.error("Cannot parse portlet.xml", e);
- }
- return null;
- }
-
- /**
- * Called by MC to install application.
- */
- public void installPortletApplication(PortletApplication application)
- {
- PortletApplicationRegistrationContext context =
registry.registerPortletApplication(application);
- registrationContextMap.put(application, context);
- }
-
- /**
- * Called by MC to install container.
- */
- public void installPortletContainer(PortletContainer container)
- {
- PortletApplicationRegistrationContext context =
(PortletApplicationRegistrationContext)registrationContextMap.get(container.getApplication());
- context.registerPortlet(container);
- }
-
- /**
- * Called by MC to uninstall application.
- */
- public void uninstallPortletApplication(PortletApplication application)
- {
- registry.unregisterPortletApplication(application);
- }
-
- /**
- * Called by MC to uninstall container.
- */
- public void uninstallPortletContainer(PortletContainer container)
- {
- PortletApplicationRegistrationContext context =
(PortletApplicationRegistrationContext)registrationContextMap.get(container.getApplication());
- context.unregisterPortlet(container);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletApplicationDeployment.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,288 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.container.PortletApplicationContext;
-import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
-import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
-import org.jboss.portal.portlet.impl.jsr168.SimpleResourceBundleFactory;
-import org.jboss.portal.portlet.impl.jsr168.spi.PortletAPIFactory;
-import org.jboss.portal.portlet.impl.metadata.PortletApplication10MetaData;
-import org.jboss.portal.portlet.impl.metadata.portlet.PortletMetaData;
-import org.jboss.portal.portlet.impl.info.ContainerPortletInfo;
-import org.jboss.portal.portlet.impl.info.ContainerPortletInfoBuilder;
-import org.jboss.portal.portlet.metadata.JBossApplicationMetaData;
-import org.jboss.portal.web.WebApp;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.common.i18n.ResourceBundleFactory;
-import org.jboss.portal.common.i18n.ResourceBundleManager;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
-import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
-import org.jboss.beans.metadata.plugins.AbstractLifecycleMetaData;
-import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
-import org.jboss.beans.metadata.plugins.AbstractInstallMetaData;
-import org.jboss.beans.metadata.plugins.ThisValueMetaData;
-import org.jboss.beans.metadata.spi.PropertyMetaData;
-import org.jboss.beans.metadata.spi.ParameterMetaData;
-import org.jboss.beans.metadata.spi.InstallMetaData;
-import org.apache.log4j.Logger;
-
-import javax.servlet.ServletContext;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletApplicationDeployment implements PortletApplicationContext
-{
-
- /** . */
- private final Logger log;
-
- /** . */
- private final Kernel kernel;
-
- /** . */
- private final WebApp webApp;
-
- /** . */
- private final PortletApplication10MetaData metaData;
-
- /** . */
- private final LinkedList<String> installed;
-
- /** . */
- private KernelControllerContext portletApplicationControllerContext;
-
- /** . */
- private List<KernelControllerContext> portletContainerControllerContexts = new
ArrayList<KernelControllerContext>();
-
- public PortletApplicationDeployment(Kernel kernel, WebApp webApp,
PortletApplication10MetaData metaData)
- {
- this.kernel = kernel;
- this.webApp = webApp;
- this.metaData = metaData;
- this.log = Logger.getLogger(PortletApplicationDeployment.class + "." +
webApp.getContextPath().replace('.', '_'));
- this.installed = new LinkedList<String>();
- }
-
- void start()
- {
-
- log.debug("Starting installation");
-
- //
- KernelController controller = kernel.getController();
-
- //
- String portletApplicationId = "PortletApplication[" +
webApp.getContextPath() + "]";
-
- //
- for (PortletMetaData portletMetaData : metaData.getPortlets().values())
- {
- // Create resource bundle manager
- String baseName = portletMetaData.getResourceBundle();
- ResourceBundleFactory rbf = new
SimpleResourceBundleFactory(webApp.getClassLoader(), baseName);
- ResourceBundleManager bundleMgr = new ResourceBundleManager(null, rbf);
-
- // Build container info
- ContainerPortletInfo containerInfo = new
ContainerPortletInfoBuilder(portletMetaData, bundleMgr).build();
-
- //
- String portletContainerId = "PortletContainer[" +
webApp.getContextPath() + "," + portletMetaData.getPortletName() +
"]";
-
- //
- AbstractBeanMetaData bmd = new AbstractBeanMetaData(portletContainerId,
PortletContainerImpl.class.getName());
- AbstractConstructorMetaData ctormd = new AbstractConstructorMetaData();
- ctormd.setParameters(Tools.toList((ParameterMetaData)new
AbstractParameterMetaData(ContainerPortletInfo.class.getName(), containerInfo), new
AbstractParameterMetaData(ResourceBundleManager.class.getName(), bundleMgr)));
- bmd.setConstructor(ctormd);
- bmd.setStart(new AbstractLifecycleMetaData("start"));
- bmd.setStop(new AbstractLifecycleMetaData("stop"));
- bmd.setProperties(Collections.singleton((PropertyMetaData)new
AbstractPropertyMetaData("application", new
AbstractDependencyValueMetaData(portletApplicationId))));
- AbstractInstallMetaData deployerinstallmd = new AbstractInstallMetaData();
- deployerinstallmd.setBean("PortletApplicationDeployer");
- deployerinstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- deployerinstallmd.setMethodName("installPortletContainer");
- AbstractInstallMetaData applicationinstallmd = new AbstractInstallMetaData();
- applicationinstallmd.setBean(portletApplicationId);
-
applicationinstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- applicationinstallmd.setMethodName("addContainer");
- bmd.setInstalls(Tools.toList((InstallMetaData)deployerinstallmd,
applicationinstallmd));
- AbstractInstallMetaData deployeruninstallmd = new AbstractInstallMetaData();
- deployeruninstallmd.setBean("PortletApplicationDeployer");
-
deployeruninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- deployeruninstallmd.setMethodName("uninstallPortletContainer");
- AbstractInstallMetaData applicationuninstallmd = new AbstractInstallMetaData();
- applicationuninstallmd.setBean(portletApplicationId);
-
applicationuninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- applicationuninstallmd.setMethodName("removeContainer");
- bmd.setUninstalls(Tools.toList((InstallMetaData)deployeruninstallmd,
applicationuninstallmd));
- try
- {
- installed.addFirst(portletContainerId);
- KernelControllerContext portletContainerControllerContext =
kernel.getController().install(bmd);
- portletContainerControllerContexts.add(portletContainerControllerContext);
- }
- catch (Throwable t)
- {
- log.debug("Cannot install portlet container " +
portletMetaData.getPortletName() + " produced an error", t);
- }
- }
-
- //
- AbstractBeanMetaData bmd = new AbstractBeanMetaData(portletApplicationId,
PortletApplicationImpl.class.getName());
- AbstractConstructorMetaData ctormd = new AbstractConstructorMetaData();
- ctormd.setParameters(Tools.toList(
- (ParameterMetaData)new
AbstractParameterMetaData(PortletApplication10MetaData.class.getName(), metaData),
- new AbstractParameterMetaData(JBossApplicationMetaData.class.getName(),
(Object)null),
- new AbstractParameterMetaData(PortletApplicationContext.class.getName(), this),
- new AbstractParameterMetaData(PortletAPIFactory.class.getName(), new
AbstractDependencyValueMetaData("PortletAPIFactory"))));
- bmd.setConstructor(ctormd);
- bmd.setStart(new AbstractLifecycleMetaData("start"));
- bmd.setStop(new AbstractLifecycleMetaData("stop"));
- AbstractInstallMetaData installmd = new AbstractInstallMetaData();
- installmd.setBean("PortletApplicationDeployer");
- installmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- installmd.setMethodName("installPortletApplication");
- bmd.setInstalls(Collections.singletonList((InstallMetaData)installmd));
- AbstractInstallMetaData uninstallmd = new AbstractInstallMetaData();
- uninstallmd.setBean("PortletApplicationDeployer");
- uninstallmd.setParameters(Collections.singletonList((ParameterMetaData)new
AbstractParameterMetaData(new ThisValueMetaData())));
- uninstallmd.setMethodName("uninstallPortletApplication");
- bmd.setUninstalls(Collections.singletonList((InstallMetaData)uninstallmd));
-
- //
- try
- {
- installed.addFirst(portletApplicationId);
- portletApplicationControllerContext = controller.install(bmd);
- }
- catch (Throwable throwable)
- {
- log.debug("Installation of portlet application produced an error",
throwable);
- }
-
- logBeanFailure(portletApplicationControllerContext);
- for (KernelControllerContext portletContainerControllerContext :
portletContainerControllerContexts)
- {
- logBeanFailure(portletContainerControllerContext);
- }
- }
-
- private void logBeanFailure(KernelControllerContext context)
- {
- Throwable t = context.getError();
- if (t != null)
- {
- log.debug("Installation of bean " + context.getName() + "
produced an error", t);
- }
- }
-
- void stop()
- {
- log.debug("Stopping installation");
-
- KernelController controller = kernel.getController();
-
- for (Iterator<String> i = installed.iterator();i.hasNext();)
- {
- String beanName = i.next();
- i.remove();
- try
- {
- controller.uninstall(beanName);
- }
- catch (Throwable t)
- {
- // MC throws Error .... need to catch them here
-
- log.error("Bean " + beanName + " undeployment threw
something", t);
- }
- }
-
- //
- portletApplicationControllerContext = null;
- portletContainerControllerContexts = null;
- }
-
- public ServletContext getServletContext()
- {
- return webApp.getServletContext();
- }
-
- public ClassLoader getClassLoader()
- {
- return webApp.getClassLoader();
- }
-
- public void startPortletApplication() throws Exception
- {
- throw new NotYetImplemented();
-// try
-// {
-// kernel.getController().change(portletApplicationControllerContext,
ControllerState.INSTALLED);
-// }
-// catch (Throwable throwable)
-// {
-// }
- }
-
- public void stopPortletApplication()
- {
- throw new NotYetImplemented();
-// try
-// {
-// kernel.getController().change(portletApplicationControllerContext,
ControllerState.CREATE);
-// }
-// catch (Throwable throwable)
-// {
-// throwable.printStackTrace();
-// }
- }
-
- public void startPortletContainer(String portletName) throws Exception
- {
- throw new NotYetImplemented();
- }
-
- public void stopPortletContainer(String portletName)
- {
- throw new NotYetImplemented();
- }
-
- public String getContextPath()
- {
- throw new NotYetImplemented();
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletController.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletController.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletController.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,369 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.portlet.PortletParameters;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.PortletInvoker;
-import org.jboss.portal.portlet.RenderURL;
-import org.jboss.portal.portlet.impl.spi.AbstractRequestContext;
-import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
-import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
-import org.jboss.portal.portlet.impl.spi.AbstractPortalContext;
-import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.RenderResponse;
-import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
-import org.jboss.portal.portlet.invocation.response.ErrorResponse;
-import org.jboss.portal.portlet.invocation.ActionInvocation;
-import org.jboss.portal.portlet.invocation.RenderInvocation;
-import org.jboss.portal.web.IllegalRequestException;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.common.util.MarkupInfo;
-import org.jboss.portal.common.util.MediaType;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletContext;
-import java.io.UnsupportedEncodingException;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletController
-{
-
- /** . */
- private MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML, "UTF8");
-
- /** . */
- private final ServletContext servletContext;
-
- /** . */
- private final HttpServletRequest req;
-
- /** . */
- private final PortletInvoker invoker;
-
- /** . */
- private final PortletControllerContext context;
-
- /** . */
- private final boolean redirectAfterAction = true;
-
- public PortletController(PortletControllerContext context, ServletContext
servletContext, HttpServletRequest req) throws IllegalRequestException,
UnsupportedEncodingException
- {
- this.context = context;
- this.servletContext = servletContext;
-
- //
- this.req = req;
- this.invoker =
(PortletInvoker)servletContext.getAttribute("ConsumerPortletInvoker");
- }
-
- public void process(HttpServletResponse resp) throws PortletInvokerException,
IOException
- {
-
- //
- Request request = context.getRequest();
-
- //
- PortalNavigationalState navState = context.getNavigationalState();
-
- //
- if (request != null)
- {
- PortletContext target = PortletContext.createPortletContext(request.portletId);
-
- //
- Portlet portlet = invoker.getPortlet(target);
-
- //
- PortletURLRenderer renderer = new PortletURLRenderer(navState, portlet, req,
resp);
-
- //
- WindowNavigationalState windowNS = navState.getWindow(request.portletId);
-
- //
- PortletInvocationResponse response = null;
-
- if (request instanceof Render)
- {
- RenderResponse render = new RenderResponse();
- render.setMode(request.mode);
- render.setWindowState(request.windowState);
-
render.setNavigationalState(PortletParametersStateString.create(request.queryParameters));
- response = render;
- }
- else
- {
- //
- StateString portletNS = null;
- if (windowNS != null)
- {
- portletNS = windowNS.getPortletNavigationalState();
- }
-
- //
- Mode mode = request.mode;
- if (mode == null && windowNS != null && windowNS.getMode() !=
null)
- {
- mode = windowNS.getMode();
- }
- if (mode == null)
- {
- mode = Mode.VIEW;
- }
-
- //
- WindowState windowState = request.windowState;
- if (windowState == null && windowNS != null &&
windowNS.getWindowState() != null)
- {
- windowState = windowNS.getWindowState();
- }
- if (windowState == null)
- {
- windowState = WindowState.NORMAL;
- }
-
- //
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
- TestActionContext actionContext = new TestActionContext(
- renderer,
- mode,
- windowState,
- portletNS,
- MARKUP_INFO,
- PortletParametersStateString.create(request.queryParameters),
- request.bodyParameters != null ? new
PortletParameters(request.bodyParameters) : null);
- ActionInvocation action = new ActionInvocation(actionContext);
-
- //
- action.setRequestContext(new AbstractRequestContext(req, resp));
- action.setInstanceContext(instanceContext);
- action.setUserContext(new AbstractUserContext(req));
- action.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- action.setPortalContext(new AbstractPortalContext());
- action.setSecurityContext(new AbstractSecurityContext(req));
- action.setTarget(instanceContext.getTarget());
-
- //
- try
- {
- response = invoker.invoke(action);
- }
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
-
- //
- if (response instanceof RenderResponse && redirectAfterAction)
- {
- final RenderResponse render = (RenderResponse)response;
- String location = renderer.renderURL(new RenderURL()
- {
- public StateString getNavigationalState()
- {
- return render.getNavigationalState();
- }
- public Mode getMode()
- {
- return render.getMode();
- }
- public WindowState getWindowState()
- {
- return render.getWindowState();
- }
- }, null, null, true);
- response = new HTTPRedirectionResponse(location);
- }
- }
-
- //
- if (response instanceof RenderResponse)
- {
- RenderResponse render = (RenderResponse)response;
-
- //
- if (windowNS == null)
- {
- windowNS = new WindowNavigationalState();
- navState.setWindow(portlet.getContext().getId(), windowNS);
- }
-
- //
- if (render.getMode() != null)
- {
- windowNS.setMode(render.getMode());
- }
- if (render.getWindowState() != null)
- {
- windowNS.setWindowState(render.getWindowState());
- }
- if (render.getNavigationalState() != null)
- {
- windowNS.setPortletNavigationalState(render.getNavigationalState());
- }
- }
- else if (response instanceof HTTPRedirectionResponse)
- {
- HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
- resp.sendRedirect(redirection.getLocation());
- return;
- }
- else if (response instanceof ErrorResponse)
- {
- ErrorResponse error = (ErrorResponse)response;
- System.out.println("Error " + error.getMessage());
- if (error.getCause() != null)
- {
- error.getCause().printStackTrace();
- }
- resp.sendError(404, error.getMessage());
- return;
- }
- else
- {
- System.out.println("Not yet handled " + response);
- }
- }
-
- //
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.print("<html><body>");
-
- //
- try
- {
- for (Iterator i = invoker.getPortlets().iterator(); i.hasNext();)
- {
- Portlet portlet = (Portlet)i.next();
- writer.print("<div><div>" + portlet.getContext() +
"</div>");
- PortletURLRenderer renderer = new PortletURLRenderer(navState, portlet, req,
resp);
-
- //
- Mode mode = Mode.VIEW;
- WindowState windowState = WindowState.NORMAL;
- StateString portletNS = null;
-
- //
- WindowNavigationalState windowNS =
navState.getWindow(portlet.getContext().getId());
- if (windowNS != null)
- {
- if (windowNS.getMode() != null)
- {
- mode= windowNS.getMode();
- }
- if (windowNS.getWindowState() != null)
- {
- windowState= windowNS.getWindowState();
- }
- if (windowNS.getPortletNavigationalState() != null)
- {
- portletNS= windowNS.getPortletNavigationalState();
- }
- }
-
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), false);
- TestRenderContext renderContext = new TestRenderContext(renderer, mode,
windowState, portletNS, MARKUP_INFO);
-
- //
- RenderInvocation render = new RenderInvocation(renderContext);
-
- //
- render.setRequestContext(new AbstractRequestContext(req, resp));
- render.setInstanceContext(instanceContext);
- render.setUserContext(new AbstractUserContext(req));
- render.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- render.setPortalContext(new AbstractPortalContext());
- render.setSecurityContext(new AbstractSecurityContext(req));
- render.setTarget(instanceContext.getTarget());
-
- //
- try
- {
- invoker.invoke(render);
- }
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
-
- writer.print("</div>");
- }
- }
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
-
- writer.print("</body></html>");
- }
-
- static class Request
- {
-
- final String portletId;
- final ParameterMap queryParameters;
- final ParameterMap bodyParameters;
- final Mode mode;
- final WindowState windowState;
-
- public Request(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
- {
- this.portletId = portletId;
- this.queryParameters = queryParameters;
- this.bodyParameters = bodyParameters;
- this.mode = mode;
- this.windowState = windowState;
- }
- }
-
- static class Action extends Request
- {
- public Action(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
- {
- super(portletId, queryParameters, bodyParameters, mode, windowState);
- }
- }
-
- static class Render extends Request
- {
- public Render(String portletId, ParameterMap queryParameters, ParameterMap
bodyParameters, Mode mode, WindowState windowState)
- {
- super(portletId, queryParameters, bodyParameters, mode, windowState);
- }
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContext.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,36 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public interface PortletControllerContext
-{
-
- PortalNavigationalState getNavigationalState();
-
- PortletController.Request getRequest();
-
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,155 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.web.IllegalRequestException;
-import org.jboss.portal.web.WebRequest;
-import org.jboss.portal.web.Body;
-import org.jboss.portal.portlet.test.url.ParameterDecoder;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletControllerContextImpl implements PortletControllerContext
-{
-
- /** . */
- public static final int NAV_SCOPE = 0;
-
- /** . */
- public static final int SESSION_SCOPE = 1;
-
- /** . */
- private final PortalNavigationalState navState;
-
- /** . */
- private final PortletController.Request request;
-
- public PortletControllerContextImpl(HttpServletRequest req, int navStateScope)
- throws IllegalRequestException, IOException, ClassNotFoundException
- {
-
- if (navStateScope < NAV_SCOPE || navStateScope > SESSION_SCOPE)
- {
- throw new IllegalArgumentException();
- }
-
- //
- String pathInfo = req.getPathInfo();
- String targetId;
-
- if (pathInfo != null && pathInfo.startsWith("/") &&
pathInfo.length() > 1)
- {
- targetId = StringCodec.decode(pathInfo.substring(1));
-
- WebRequest ri = new WebRequest(req);
- ParameterDecoder decoder = PortletURLRenderer.builder.createDecoder();
- decoder.decode(ri.getQueryParameterMap());
-
- //
- ParameterMap metaParameters = decoder.getMetaParameters();
-
- PortalNavigationalState navState;
- if (navStateScope == NAV_SCOPE)
- {
- String ns = metaParameters.getValue("ns");
- byte[] bytes = Tools.fromHexString(ns);
- navState = PortalNavigationalState.create(bytes);
- }
- else
- {
- navState =
(PortalNavigationalState)req.getSession().getAttribute("nav_state");
- }
-
- //
- ParameterMap actualParameters = decoder.getActualParameters();
-
- //
- Mode mode = null;
- if (metaParameters.getValue("mode") != null)
- {
- mode = Mode.create(metaParameters.getValue("mode"));
- }
-
- //
- WindowState windowState = null;
- if (metaParameters.getValue("windowstate") != null)
- {
- windowState =
WindowState.create(metaParameters.getValue("windowstate"));
- }
-
- //
- PortletController.Request request;
- String type = metaParameters.getValue("type");
-
- //
- ParameterMap formParameters = null;
- if (ri.getBody() instanceof Body.Form)
- {
- formParameters = ((Body.Form)ri.getBody()).getParameters();
- }
-
- if ("action".equals(type))
- {
- request = new PortletController.Action(targetId, actualParameters,
formParameters, mode, windowState);
- }
- else
- {
- request = new PortletController.Render(targetId, actualParameters,
formParameters, mode, windowState);
- }
-
- //
- this.navState = navState;
- this.request = request;
- }
- else
- {
- this.navState = new PortalNavigationalState();
- this.request = null;
-
- //
- if (navStateScope == SESSION_SCOPE)
- {
- req.getSession().setAttribute("nav_state", navState);
- }
- }
- }
-
- public PortletController.Request getRequest()
- {
- return request;
- }
-
- public PortalNavigationalState getNavigationalState()
- {
- return navState;
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletURLRenderer.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/PortletURLRenderer.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,151 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletURL;
-import org.jboss.portal.portlet.RenderURL;
-import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.portlet.ActionURL;
-import org.jboss.portal.portlet.test.url.CodecBuilder;
-import org.jboss.portal.portlet.test.url.ParameterEncoder;
-import org.jboss.portal.common.text.CharBuffer;
-import org.jboss.portal.common.text.FastURLEncoder;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.common.util.Tools;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Iterator;
-import java.util.Map;
-import java.io.IOException;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletURLRenderer
-{
-
- /** . */
- final Portlet portlet;
-
- /** . */
- final HttpServletRequest clientReq;
-
- /** . */
- final HttpServletResponse clientResp;
-
- /** . */
- final PortalNavigationalState navState;
-
- public PortletURLRenderer(PortalNavigationalState navState, Portlet portlet,
HttpServletRequest clientReq, HttpServletResponse clientResp)
- {
- this.navState = navState;
- this.portlet = portlet;
- this.clientReq = clientReq;
- this.clientResp = clientResp;
- }
-
- static final CodecBuilder builder = new CodecBuilder("action").
- addMetaParameter("windowstate").
- addMetaParameter("mode").
- addMetaParameter("type").
- addMetaParameter("ns");
-
- String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean wantAuthenticated,
boolean relative)
- {
- CharBuffer buffer = new CharBuffer();
- buffer.append(clientReq.getScheme());
- buffer.append("://");
- buffer.append(clientReq.getServerName());
- buffer.append(':');
- buffer.append(Integer.toString(clientReq.getServerPort()));
- buffer.append(clientReq.getContextPath());
- buffer.append('/');
- buffer.append(StringCodec.encode(portlet.getContext().getId()));
-
- //
- ParameterMap metaParameters = new ParameterMap();
-
- //
- metaParameters.setValue("type", portletURL instanceof RenderURL ?
"render" : "action");
-
- //
- try
- {
- byte[] bytes = navState.getBytes();
- String ns = Tools.toHexString(bytes);
- metaParameters.setValue("ns", ns);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
-
- //
- if (portletURL.getMode() != null)
- {
- metaParameters.setValue("mode", portletURL.getMode().toString());
- }
- if (portletURL.getWindowState() != null)
- {
- metaParameters.setValue("windowstate",
portletURL.getWindowState().toString());
- }
-
- //
- ParameterMap actualParameters;
- if (portletURL instanceof RenderURL)
- {
- actualParameters =
((PortletParametersStateString)((RenderURL)portletURL).getNavigationalState()).getParameters();
- }
- else
- {
- actualParameters =
((PortletParametersStateString)((ActionURL)portletURL).getInteractionState()).getParameters();
- }
-
- //
- ParameterEncoder encoder = builder.createEncoder();
- encoder.encode(actualParameters, metaParameters);
- boolean first = true;
- for (Iterator i = encoder.getParameters().entrySet().iterator(); i.hasNext();)
- {
- Map.Entry parameter = (Map.Entry)i.next();
- String name = (String)parameter.getKey();
- String[] values = (String[])parameter.getValue();
- for (int j = 0; j < values.length; j++)
- {
- String value = values[j];
- buffer.append(first ? '?' : '&');
- buffer.append(name, FastURLEncoder.getUTF8Instance());
- buffer.append('=');
- buffer.append(value, FastURLEncoder.getUTF8Instance());
- first = false;
- }
- }
-
- //
- String url = buffer.asString();
- return clientResp.encodeURL(url);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodec.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodec.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodec.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,114 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import java.io.OutputStreamWriter;
-import java.io.OutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.ByteArrayOutputStream;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class StringCodec
-{
-
- private static char[] blah = "0123456789ABCDEF".toCharArray();
-
-
- public static String encode(String decodedValue)
- {
- try
- {
- StringBuffer buffer = new StringBuffer();
- char[] tmp = new char[1];
- for (int i = 0;i < decodedValue.length();i++)
- {
- char c = decodedValue.charAt(i);
- if (Character.isLetterOrDigit(c))
- {
- buffer.append(c);
- }
- else
- {
- tmp[0] = c;
- byte[] bytes = new String(tmp).getBytes("UTF8");
- for (int j = 0; j < bytes.length; j++)
- {
- byte b = bytes[j];
- buffer.append('_').append(blah[(b & 0XF0) >>
4]).append(blah[b & 0x0F]);
- }
- }
- }
- return buffer.toString();
- }
- catch (UnsupportedEncodingException e)
- {
- throw new RuntimeException();
- }
- }
-
- public static String decode(String encodedValue)
- {
- try
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(encodedValue.length());
- for (int i = 0;i < encodedValue.length();i++)
- {
- char c = encodedValue.charAt(i);
- if (Character.isLetterOrDigit(c))
- {
- baos.write(c);
- }
- else if ('_' == c)
- {
- if (i + 3 > encodedValue.length())
- {
- throw new IllegalArgumentException("There should be at least 2
chars after an _ char");
- }
- String hex = encodedValue.substring(i + 1, i + 3);
- int x = Integer.parseInt(hex, 16);
- baos.write(x);
- i += 2;
- }
- else
- {
- throw new IllegalArgumentException("Invalid char " + c);
- }
- }
- return baos.toString("UTF-8");
- }
- catch (UnsupportedEncodingException e)
- {
- throw new RuntimeException();
- }
- }
-
-
-
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodecTestCase.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodecTestCase.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/StringCodecTestCase.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,64 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import static org.jboss.unit.api.Assert.*;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class StringCodecTestCase
-{
-
- private static final char EURO_CHAR = '\u20AC';
-
- @Test
- public void testA()
- {
-
- assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
StringCodec.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
- assertEquals("abcdefghijklmnopqrstuvwxyz",
StringCodec.encode("abcdefghijklmnopqrstuvwxyz"));
- assertEquals("0123456789", StringCodec.encode("0123456789"));
- assertEquals("_2F", StringCodec.encode("/"));
- assertEquals("_40", StringCodec.encode("@"));
- assertEquals("_E2_82_AC",
StringCodec.encode(Character.toString(EURO_CHAR)));
- assertEquals("A_E2_82_ACB_40C", StringCodec.encode("A" +
EURO_CHAR + "B@C"));
-
- }
-
- @Test
- public void testB()
- {
- assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
StringCodec.decode(StringCodec.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
- assertEquals("abcdefghijklmnopqrstuvwxyz",
StringCodec.decode(StringCodec.encode("abcdefghijklmnopqrstuvwxyz")));
- assertEquals("0123456789",
StringCodec.decode(StringCodec.encode("0123456789")));
- assertEquals("/",
StringCodec.decode(StringCodec.encode("/")));
- assertEquals("@",
StringCodec.decode(StringCodec.encode("@")));
- assertEquals(Character.toString(EURO_CHAR),
StringCodec.decode(StringCodec.encode(Character.toString(EURO_CHAR))));
- assertEquals("A" + EURO_CHAR +"B@C",
StringCodec.decode(StringCodec.encode("A" + EURO_CHAR + "B@C")));
- }
-
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestActionContext.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestActionContext.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestActionContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,78 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.PortletParameters;
-import org.jboss.portal.portlet.PortletURL;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.impl.spi.AbstractActionContext;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.MarkupInfo;
-import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
-import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class TestActionContext extends AbstractActionContext
-{
-
- /** . */
- private final PortletURLRenderer urlRenderer;
-
- public TestActionContext(PortletURLRenderer urlRenderer, Mode mode, WindowState
windowState, StateString navigationalState, MarkupInfo markupInfo, StateString
interactionState, PortletParameters form)
- {
- super(mode, windowState, navigationalState, markupInfo, interactionState, form);
-
- //
- this.urlRenderer = urlRenderer;
-
- //
- addResolver(PortletInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(urlRenderer.clientReq));
- addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
- addResolver(PortletInvocation.REQUEST_PROPERTIES_SCOPE, new
MapAttributeResolver());
- addResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, new
MapAttributeResolver());
- addResolver(PortletInvocation.REQUEST_SCOPE, new MapAttributeResolver());
- }
-
- public HttpServletRequest getClientRequest() throws IllegalStateException
- {
- return urlRenderer.clientReq;
- }
-
- public HttpServletResponse getClientResponse() throws IllegalStateException
- {
- return urlRenderer.clientResp;
- }
-
- public String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
- {
- return urlRenderer.renderURL(portletURL, wantSecure, wantAuthenticated, relative);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestInstanceContext.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestInstanceContext.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestInstanceContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,97 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.state.AccessMode;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.StateEvent;
-import org.jboss.portal.portlet.spi.InstanceContext;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class TestInstanceContext implements InstanceContext
-{
-
- private HttpServletRequest req;
-
- private boolean modifiable;
-
- private PortletContext target;
-
- private boolean useClone;
-
- private String id;
-
- public TestInstanceContext(
- HttpServletRequest req,
- PortletContext portletContext,
- boolean modifiable)
- {
- String id = portletContext.getId();
- PortletContext target = portletContext;
- boolean useClone = false;
- HttpSession session = req.getSession(false);
- if (session != null)
- {
- PortletContext clone = (PortletContext)session.getAttribute("clone." +
id);
- if (clone != null)
- {
- target = clone;
- useClone = true;
- }
- }
-
- //
- this.req = req;
- this.useClone = useClone;
- this.target = target;
- this.id = id;
- this.modifiable = modifiable;
- }
-
- public PortletContext getTarget()
- {
- return target;
- }
-
- public String getId()
- {
- return id;
- }
-
- public AccessMode getAccessMode()
- {
- return modifiable ? (useClone ? AccessMode.READ_WRITE :
AccessMode.CLONE_BEFORE_WRITE) : AccessMode.READ_ONLY;
- }
-
- public void onStateEvent(StateEvent event)
- {
- target = event.getPortletContext();
- req.getSession().setAttribute("clone." + id, target);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestPortletInvoker.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestPortletInvoker.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestPortletInvoker.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,158 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.PortletInvoker;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.state.PropertyMap;
-import org.jboss.portal.portlet.state.PropertyChange;
-import org.jboss.portal.portlet.state.DestroyCloneFailure;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.common.invocation.InterceptorStackFactory;
-import org.jboss.portal.common.invocation.InvocationHandler;
-import org.jboss.portal.common.invocation.Invocation;
-import org.jboss.portal.common.invocation.InvocationException;
-
-import java.util.Set;
-import java.util.List;
-
-/**
- * A simple consumer.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6712 $
- */
-public class TestPortletInvoker implements PortletInvoker
-{
-
- /** . */
- private InterceptorStackFactory stackFactory;
-
- /** . */
- private PortletInvoker producer;
-
- /** . */
- private InvocationHandler handler = new InvocationHandler()
- {
- public Object invoke(Invocation invocation) throws Exception, InvocationException
- {
- PortletInvocation portletInvocation = (PortletInvocation)invocation;
- try
- {
- portletInvocation.setHandler(null);
- return producer.invoke(portletInvocation);
- }
- finally
- {
- portletInvocation.setHandler(this);
- }
- }
- };
-
- public InterceptorStackFactory getStackFactory()
- {
- return stackFactory;
- }
-
- public void setStackFactory(InterceptorStackFactory stackFactory)
- {
- this.stackFactory = stackFactory;
- }
-
- public PortletInvoker getProducer()
- {
- return producer;
- }
-
- public void setProducer(PortletInvoker producer)
- {
- this.producer = producer;
- }
-
- public Set<Portlet> getPortlets() throws PortletInvokerException
- {
- return producer.getPortlets();
- }
-
- public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
- {
- return producer.getPortlet(portletContext);
- }
-
- public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
- {
- InvocationHandler prevHandler = invocation.getHandler();
- try
- {
- invocation.setHandler(handler);
- return
(PortletInvocationResponse)invocation.invoke(stackFactory.getInterceptorStack());
- }
- catch (Exception e)
- {
- if (e instanceof PortletInvokerException)
- {
- throw(PortletInvokerException)e;
- }
- else if (e instanceof RuntimeException)
- {
- throw(RuntimeException)e;
- }
- else
- {
- throw new PortletInvokerException(e);
- }
- }
- finally
- {
- invocation.setHandler(prevHandler);
- }
- }
-
- public PortletContext createClone(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PropertyMap getProperties(PortletContext portletContext, Set keys) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestRenderContext.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestRenderContext.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/TestRenderContext.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,77 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.PortletURL;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.impl.spi.AbstractRenderContext;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.MarkupInfo;
-import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
-import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class TestRenderContext extends AbstractRenderContext
-{
-
- /** . */
- private final PortletURLRenderer urlRenderer;
-
- public TestRenderContext(PortletURLRenderer urlRenderer, Mode mode, WindowState
windowState, StateString navigationalState, MarkupInfo markupInfo)
- {
- super(mode, windowState, navigationalState, markupInfo);
-
- //
- this.urlRenderer = urlRenderer;
-
- //
- addResolver(PortletInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(urlRenderer.clientReq));
- addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
- addResolver(PortletInvocation.REQUEST_PROPERTIES_SCOPE, new
MapAttributeResolver());
- addResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, new
MapAttributeResolver());
- addResolver(PortletInvocation.REQUEST_SCOPE, new MapAttributeResolver());
- }
-
- public HttpServletRequest getClientRequest() throws IllegalStateException
- {
- return urlRenderer.clientReq;
- }
-
- public HttpServletResponse getClientResponse() throws IllegalStateException
- {
- return urlRenderer.clientResp;
- }
-
- public String renderURL(PortletURL portletURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
- {
- return urlRenderer.renderURL(portletURL, wantSecure, wantAuthenticated, relative);
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/WindowNavigationalState.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/WindowNavigationalState.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/WindowNavigationalState.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,76 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test;
-
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class WindowNavigationalState implements Serializable
-{
-
- /** . */
- private StateString portletNavigationalState;
-
- /** . */
- private Mode mode;
-
- /** . */
- private WindowState windowState;
-
- public StateString getPortletNavigationalState()
- {
- return portletNavigationalState;
- }
-
- public void setPortletNavigationalState(StateString portletNavigationalState)
- {
- this.portletNavigationalState = portletNavigationalState;
- }
-
- public Mode getMode()
- {
- return mode;
- }
-
- public void setMode(Mode mode)
- {
- this.mode = mode;
- }
-
- public WindowState getWindowState()
- {
- return windowState;
- }
-
- public void setWindowState(WindowState windowState)
- {
- this.windowState = windowState;
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/CodecBuilder.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/CodecBuilder.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/CodecBuilder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,77 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test.url;
-
-import java.util.LinkedHashSet;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class CodecBuilder
-{
-
- /** . */
- final ArrayList metaParameterNames;
-
- /** . */
- final String reservedParameterName;
-
- public CodecBuilder(CodecBuilder that)
- {
- this.metaParameterNames = new ArrayList(that.metaParameterNames);
- this.reservedParameterName = that.reservedParameterName;
- }
-
- public CodecBuilder(String reservedParameter)
- {
- this.metaParameterNames = new ArrayList();
- this.reservedParameterName = reservedParameter;
- }
-
- public CodecBuilder addMetaParameter(String name)
- {
- if (metaParameterNames.contains(name))
- {
- throw new IllegalStateException();
- }
- if (reservedParameterName.equals(name))
- {
- throw new IllegalStateException();
- }
- metaParameterNames.add(name);
- return this;
- }
-
- public ParameterEncoder createEncoder()
- {
- return new ParameterEncoder(this);
- }
-
- public ParameterDecoder createDecoder()
- {
- return new ParameterDecoder(this);
- }
-
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterDecoder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,161 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test.url;
-
-import org.jboss.portal.common.util.ParameterMap;
-
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ParameterDecoder
-{
-
- /** . */
- private final CodecBuilder builder;
-
- /** . */
- private final ParameterMap metaParameters;
-
- /** . */
- private final ParameterMap actualParameters;
-
- public ParameterDecoder(CodecBuilder builder)
- {
- this.builder = builder;
- this.actualParameters = new ParameterMap();
- this.metaParameters = new ParameterMap();
- }
-
- public ParameterMap getMetaParameters()
- {
- return metaParameters;
- }
-
- public ParameterMap getActualParameters()
- {
- return actualParameters;
- }
-
- public void decode(ParameterMap parameters)
- {
- actualParameters.clear();
- metaParameters.clear();
-
- // Get the meta parameter
- long reservedParameter = 0;
- String[] reservedParameters = parameters.getValues(builder.reservedParameterName);
- if (reservedParameters != null)
- {
- if (reservedParameters.length < 1)
- {
- throw new IllegalArgumentException();
- }
- try
- {
- reservedParameter = Long.parseLong(reservedParameters[0], 2);
- }
- catch (NumberFormatException e)
- {
- throw new IllegalArgumentException();
- }
- }
- else
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (int i = builder.metaParameterNames.size() - 1;reservedParameter > 0;)
- {
- if (i < 0)
- {
- throw new IllegalArgumentException();
- }
-
- //
- String parameterName = (String)builder.metaParameterNames.get(i--);
-
- //
- if ((reservedParameter & 1) == 1)
- {
- String[] parameterValues = parameters.getValues(parameterName);
-
- //
- if (parameterValues == null)
- {
- throw new IllegalArgumentException();
- }
- if (parameterValues.length == 0)
- {
- throw new IllegalArgumentException();
- }
-
- //
- String metaParameterValue = parameterValues[0];
- metaParameters.setValue(parameterName, metaParameterValue);
-
- //
- if (parameterValues.length > 1)
- {
- String[] actualParameterValues = new String[parameterValues.length - 1];
- System.arraycopy(parameterValues, 1, actualParameterValues, 0,
actualParameterValues.length);
- actualParameters.setValues(parameterName, actualParameterValues);
- }
- }
-
- //
- reservedParameter = reservedParameter >> 1;
- }
-
- //
- for (Iterator i = parameters.entrySet().iterator();i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String parameterName = (String)entry.getKey();
- if (!metaParameters.containsKey(parameterName))
- {
- if (builder.reservedParameterName.equals(parameterName))
- {
- String[] reservedParameterValues = (String[])entry.getValue();
- if (reservedParameterValues.length > 1)
- {
- String[] parameterValues = new String[reservedParameterValues.length -
1];
- System.arraycopy(reservedParameterValues, 1, parameterValues, 0,
parameterValues.length);
- actualParameters.setValues(parameterName, parameterValues);
- }
- }
- else
- {
- String[] parameterValues = (String[])entry.getValue();
- actualParameters.setValues(parameterName, parameterValues);
- }
- }
- }
- }
-}
Deleted:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java 2008-01-10
00:25:47 UTC (rev 9471)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/test/url/ParameterEncoder.java 2008-01-10
17:01:20 UTC (rev 9472)
@@ -1,116 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test.url;
-
-import org.jboss.portal.common.util.ParameterMap;
-
-import java.util.Map;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ParameterEncoder
-{
-
- /** . */
- private final CodecBuilder builder;
-
- /** . */
- private final ParameterMap parameters;
-
- public ParameterEncoder(CodecBuilder builder)
- {
- this.builder = new CodecBuilder(builder);
- this.parameters = new ParameterMap();
- }
-
- public ParameterMap getParameters()
- {
- return parameters;
- }
-
- public void encode(ParameterMap actualParameters, ParameterMap metaParameters)
- {
- parameters.clear();
-
- //
- long meta = 0;
-
- //
- for (Iterator i = builder.metaParameterNames.iterator();i.hasNext();)
- {
- String mv = (String)i.next();
- String pv = metaParameters.getValue(mv);
-
- //
- meta *= 2;
-
- //
- if (pv != null)
- {
- String[] pvs = actualParameters.getValues(mv);
- if (pvs != null)
- {
- String[] blah = new String[1 + pvs.length];
- blah[0] = pv;
- System.arraycopy(pvs, 0, blah, 1, pvs.length);
- parameters.setValues(mv, blah);
- }
- else
- {
- parameters.setValue(mv, pv);
- }
- meta |= 1;
- }
- }
-
- //
- String def = Long.toBinaryString(meta);
- String[] pvs = actualParameters.getValues(builder.reservedParameterName);
- if (pvs != null)
- {
- String[] blah = new String[1 + pvs.length];
- blah[0] = def;
- System.arraycopy(pvs, 0, blah, 1, pvs.length);
- parameters.setValues(builder.reservedParameterName, blah);
- }
- else
- {
- parameters.setValue(builder.reservedParameterName, def);
- }
-
- //
- for (Iterator i = actualParameters.entrySet().iterator();i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String name = (String)entry.getKey();
- if (!parameters.containsKey(name))
- {
- String[] values = (String[])entry.getValue();
- parameters.setValues(name, values);
- }
- }
- }
-}