Author: thomas.heute(a)jboss.com
Date: 2008-01-20 11:01:57 -0500 (Sun, 20 Jan 2008)
New Revision: 9539
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/BufferedBridgeResponse.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/ScrapperContentPortlet.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/BridgeStartPageNotSpecifiedException.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/PHPPortlet.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockPortletURL.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockRenderResponse.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/ScrapperTestCase.java
Modified:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/JBossServletContextProvider.java
Log:
PHP Portlet *prototype*
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/BufferedBridgeResponse.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/BufferedBridgeResponse.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/BufferedBridgeResponse.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * 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.bridge;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.portlet.RenderResponse;
+import javax.servlet.ServletOutputStream;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6862 $
+ */
+public class BufferedBridgeResponse extends BridgeResponse
+{
+
+ private OutputStream out = new ByteArrayOutputStream();
+
+ public BufferedBridgeResponse(JBossServletContextProvider.BridgeInfo info)
+ {
+ super(info);
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ if (sos == null)
+ {
+ if (presp instanceof RenderResponse)
+ {
+ sos = new ServletOutputStream()
+ {
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ out.write(b, off, len);
+ }
+
+ public void write(byte b[]) throws IOException
+ {
+ out.write(b);
+ }
+
+ public void write(int b) throws IOException
+ {
+ out.write(b);
+ }
+ };
+ }
+ else
+ {
+ throw new IllegalStateException("getOutputStream called on non render
response");
+ }
+ }
+ return sos;
+ }
+
+ public InputStream getInputStream()
+ {
+ byte[] bytes = ((ByteArrayOutputStream)out).toByteArray();
+ return new ByteArrayInputStream(bytes);
+ }
+
+}
Modified:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/JBossServletContextProvider.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/JBossServletContextProvider.java 2008-01-19
00:38:11 UTC (rev 9538)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/JBossServletContextProvider.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -46,7 +46,7 @@
{
/** . */
- private static final ThreadLocal local = new ThreadLocal();
+ private static final ThreadLocal<BridgeInfo> local = new
ThreadLocal<BridgeInfo>();
static void set(BridgeInfo info)
{
@@ -83,20 +83,36 @@
}
return info.breq;
}
+
+ public HttpServletResponse getHttpServletResponse(GenericPortlet genericPortlet,
PortletResponse portletResponse) throws IllegalStateException
+ {
+ return getHttpServletResponse(genericPortlet, portletResponse, false);
+ }
/** @throws IllegalStateException if no bridge info is found */
- public HttpServletResponse getHttpServletResponse(GenericPortlet genericPortlet,
PortletResponse portletResponse) throws IllegalStateException
+ public HttpServletResponse getHttpServletResponse(GenericPortlet genericPortlet,
PortletResponse portletResponse, boolean buffered) throws IllegalStateException
{
BridgeInfo info = (BridgeInfo)JBossServletContextProvider.local.get();
if (info == null)
{
throw new IllegalStateException("No bridge set");
}
- if (info.breq == null)
+ if (buffered)
{
- init(info);
+ if (info.bbresp == null)
+ {
+ init(info);
+ }
+ return info.bbresp;
}
- return info.bresp;
+ else
+ {
+ if (info.bresp == null)
+ {
+ init(info);
+ }
+ return info.bresp;
+ }
}
/** Lazy initialisation of the bridge info. */
@@ -104,6 +120,7 @@
{
bridgeInfo.breq = bridgeInfo.getInvocation().getDispatchedRequest();
bridgeInfo.bresp = new BridgeResponse(bridgeInfo);
+ bridgeInfo.bbresp = new BufferedBridgeResponse(bridgeInfo);
}
public static class BridgeInfo
@@ -120,6 +137,9 @@
/** The bridge response. */
private HttpServletResponse bresp;
+ /** The buffered bridge response. */
+ private HttpServletResponse bbresp;
+
public BridgeInfo(PortletInvocation invocation)
{
PortletContainer container =
(PortletContainer)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
PortletContainerInvoker.PORTLET_CONTAINER);
@@ -129,6 +149,7 @@
this.ctx = container.getApplication().getContext().getServletContext();
this.breq = null;
this.bresp = null;
+ this.bbresp = null;
}
public PortletInvocation getInvocation()
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/ScrapperContentPortlet.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/ScrapperContentPortlet.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/ScrapperContentPortlet.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -0,0 +1,190 @@
+/******************************************************************************
+ * 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.bridge;
+
+import javax.portlet.PortletURL;
+import javax.portlet.RenderResponse;
+
+import org.jboss.portal.portlet.bridge.php.PHPPortlet;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ScrapperContentPortlet implements ContentHandler
+{
+
+ private StringBuffer out;
+
+ private RenderResponse renderResponse;
+
+ private String contextPath;
+
+ public String getContent()
+ {
+ return out.toString();
+ }
+
+ public ScrapperContentPortlet(RenderResponse renderResponse, String contextPath)
+ {
+ out = new StringBuffer();
+ this.renderResponse = renderResponse;
+ this.contextPath = contextPath;
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException
+ {
+ out.append(ch, start, length);
+ }
+
+ public void endDocument() throws SAXException
+ {
+ // FIXME endDocument
+
+ }
+
+ public void endElement(String namespaceURI, String localName, String name) throws
SAXException
+ {
+ if (!"html".equals(localName.toLowerCase()))
+ {
+ out.append("</" + localName + ">");
+ }
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException
+ {
+ // FIXME endPrefixMapping
+
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
+ {
+ // FIXME ignorableWhitespace
+
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException
+ {
+ // FIXME processingInstruction
+
+ }
+
+ public void setDocumentLocator(Locator locator)
+ {
+ // FIXME setDocumentLocator
+
+ }
+
+ public void skippedEntity(String name) throws SAXException
+ {
+ // FIXME skippedEntity
+
+ }
+
+ public void startDocument() throws SAXException
+ {
+ // FIXME startDocument
+
+ }
+
+ public void startElement(String namespaceURI, String localName, String name,
Attributes atts) throws SAXException
+ {
+ if ("img".equals(localName.toLowerCase()))
+ {
+ out.append("<" + localName);
+ for (int i=0; i<atts.getLength(); i++)
+ {
+ String key = atts.getValue(i);
+ if ("src".equals(atts.getLocalName(i).toLowerCase()))
+ {
+ if (!key.startsWith("/"))
+ {
+ key = contextPath + "/" + key;
+ }
+ }
+ out.append(" " + atts.getLocalName(i) + "=\"" + key
+ "\"");
+ }
+ out.append(">");
+ }
+ else if ("form".equals(localName.toLowerCase()))
+ {
+ out.append("<" + localName);
+ for (int i=0; i<atts.getLength(); i++)
+ {
+ String key = atts.getValue(i);
+ if ("action".equals(atts.getLocalName(i).toLowerCase()))
+ {
+ PortletURL url = renderResponse.createActionURL();
+ url.setParameter(PHPPortlet.REQUESTED_PAGE, atts.getValue(i));
+ out.append(" " + atts.getLocalName(i) + "=\"" +
url + "\"");
+ }
+ else
+ {
+ out.append(" " + atts.getLocalName(i) + "=\"" +
key + "\"");
+ }
+ }
+ out.append(">");
+ }
+ else if ("a".equals(localName.toLowerCase()))
+ {
+ out.append("<" + localName);
+ for (int i=0; i<atts.getLength(); i++)
+ {
+ String key = atts.getValue(i);
+ if ("href".equals(atts.getLocalName(i).toLowerCase()))
+ {
+ PortletURL url = renderResponse.createActionURL();
+ url.setParameter(PHPPortlet.REQUESTED_PAGE, atts.getValue(i));
+ out.append(" " + atts.getLocalName(i) + "=\"" +
url + "\"");
+ }
+ else
+ {
+ out.append(" " + atts.getLocalName(i) + "=\"" +
key + "\"");
+ }
+ }
+ out.append(">");
+ }
+ else if (!"html".equals(localName.toLowerCase()))
+ {
+ out.append("<" + localName);
+ for (int i=0; i<atts.getLength(); i++)
+ {
+ String key = atts.getValue(i);
+ out.append(" " + atts.getLocalName(i) + "=\"" + key
+ "\"");
+ }
+ out.append(">");
+ }
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException
+ {
+ // FIXME startPrefixMapping
+
+ }
+
+}
+
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/BridgeStartPageNotSpecifiedException.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/BridgeStartPageNotSpecifiedException.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/BridgeStartPageNotSpecifiedException.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -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.bridge.php;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class BridgeStartPageNotSpecifiedException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7815203218188190804L;
+
+}
+
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/PHPPortlet.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/PHPPortlet.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/portlet/bridge/php/PHPPortlet.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -0,0 +1,193 @@
+/******************************************************************************
+ * 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.bridge.php;
+
+import java.io.InputStream;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ccil.cowan.tagsoup.Parser;
+import org.jboss.portal.portlet.bridge.BufferedBridgeResponse;
+import org.jboss.portal.portlet.bridge.JBossServletContextProvider;
+import org.jboss.portal.portlet.bridge.ScrapperContentPortlet;
+import org.xml.sax.InputSource;
+
+/**
+ *
+ * <portlet-app>
+ * <portlet>
+ * <portlet-name>PHP Poll Portlet</portlet-name>
+ *
<portlet-class>org.jboss.portal.portlet.bridge.php.PHPPortlet</portlet-class>
+ * <init-param>
+ * <name>defaultPage</name>
+ * <value>/index.php</value>
+ * </init-param>
+ * <supports>
+ * <mime-type>text/html</mime-type>
+ * <portlet-mode>VIEW</portlet-mode>
+ * </supports>
+ * <portlet-info>
+ * <title>PHP Poll Portlet</title>
+ * <short-title>PHP Poll Portlet</short-title>
+ * </portlet-info>
+ * </portlet>
+ * </portlet-app>
+ *
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class PHPPortlet extends GenericPortlet
+{
+ public static String DEFAULT_PAGE = "defaultPage";
+
+ private String defaultPage;
+
+ private JBossServletContextProvider servletContextProvider;
+
+ public static final String REQUESTED_PAGE =
"org.jboss.portal.bridge.php.requested_page";
+
+ public static final String ACTION_REQUEST =
"org.jboss.portal.bridge.php.action_request";
+
+ public static final String RENDER_RESULT =
"org.jboss.portal.bridge.php.render_result";
+
+ public void init(PortletConfig portletConfig) throws PortletException
+ {
+ super.init(portletConfig);
+
+ defaultPage = portletConfig.getInitParameter(DEFAULT_PAGE);
+
+ if (defaultPage == null)
+ {
+ throw new PortletException(new BridgeStartPageNotSpecifiedException());
+ }
+
+ servletContextProvider = new JBossServletContextProvider();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException
+ {
+ String requestedPage = actionRequest.getParameter(REQUESTED_PAGE);
+ int i = requestedPage.lastIndexOf("?");
+ if (i != -1)
+ {
+ requestedPage.substring(0, i);
+ }
+ actionResponse.setRenderParameter(REQUESTED_PAGE, requestedPage);
+ Map map = actionRequest.getParameterMap();
+ Set<String> set = map.keySet();
+ Iterator<String> it = set.iterator();
+ while (it.hasNext())
+ {
+ String key = (String)it.next();
+ String value = ((String[])map.get(key))[0];
+ actionResponse.setRenderParameter(key, value);
+ }
+ actionRequest.getPortletSession().setAttribute(ACTION_REQUEST, "true");
+ }
+
+ public void doView(RenderRequest request, RenderResponse response) throws
PortletException
+ {
+ HttpServletRequest httpRequest = servletContextProvider.getHttpServletRequest(this,
request);
+ HttpServletResponse httpResponse =
servletContextProvider.getHttpServletResponse(this, response, true);
+
+ response.setContentType("text/html");
+
+ String render = null;
+
+ if
("true".equals(request.getPortletSession().getAttribute(ACTION_REQUEST))||
request.getParameter(REQUESTED_PAGE)==null)
+ {
+
+ String phpPage = request.getParameter(REQUESTED_PAGE);
+ if (phpPage == null)
+ {
+ phpPage = defaultPage;
+ }
+ else
+ {
+ phpPage = "/" + phpPage;
+ }
+
+ ServletContext sc = servletContextProvider.getServletContext(this);
+ ServletContext sc2 = sc.getContext(request.getContextPath());
+ RequestDispatcher rd = sc2.getRequestDispatcher(phpPage);
+ try
+ {
+ rd.include(httpRequest, httpResponse);
+ InputStream is = ((BufferedBridgeResponse)httpResponse).getInputStream();
+ render = parse(is, response, request.getContextPath());
+ }
+ catch (Exception e)
+ {
+ throw new PortletException(e);
+ }
+
+ request.getPortletSession().removeAttribute(ACTION_REQUEST);
+ }
+
+ if (render != null)
+ {
+ request.getPortletSession().setAttribute(RENDER_RESULT, render);
+ }
+ else
+ {
+ render = (String)request.getPortletSession().getAttribute(RENDER_RESULT);
+ }
+
+ try
+ {
+ Writer writer = response.getWriter();
+ writer.write(render);
+ }
+ catch (Exception e)
+ {
+ throw new PortletException(e);
+ }
+ }
+
+ private String parse(InputStream is, RenderResponse response, String contextPath)
throws Exception
+ {
+ Parser parser = new Parser();
+
+ ScrapperContentPortlet myContentHandler = new ScrapperContentPortlet(response,
contextPath);
+ parser.setContentHandler(myContentHandler);
+
+ parser.parse(new InputSource(is));
+ return myContentHandler.getContent();
+ }
+
+}
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockPortletURL.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockPortletURL.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockPortletURL.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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.test.portlet.bridge;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.PortletURL;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+
+import org.jboss.portal.portlet.PortletParameters;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class MockPortletURL implements PortletURL
+{
+
+ PortletParameters params = new org.jboss.portal.portlet.PortletParameters();
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("actionURL[");
+ Set<String> set = params.keySet();
+ for (String key: set)
+ {
+ buffer.append(key + "=" + params.getValue(key));
+ }
+
+ buffer.append("]");
+
+ return buffer.toString();
+ }
+
+
+
+ public void setParameter(String name, String value) throws IllegalArgumentException
+ {
+ params.put(name, new String[]{value});
+ }
+
+ public void setParameter(String name, String[] values) throws
IllegalArgumentException
+ {
+ params.put(name, values);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setParameters(Map parameters) throws IllegalArgumentException
+ {
+ params = new PortletParameters(parameters);
+ }
+
+ public void setPortletMode(PortletMode portletMode) throws PortletModeException
+ {
+ // FIXME setPortletMode
+
+ }
+
+ public void setSecure(boolean secure) throws PortletSecurityException
+ {
+ // FIXME setSecure
+
+ }
+
+ public void setWindowState(WindowState windowState) throws WindowStateException
+ {
+ // FIXME setWindowState
+
+ }
+
+}
+
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockRenderResponse.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockRenderResponse.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/MockRenderResponse.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * 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.test.portlet.bridge;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Locale;
+
+import javax.portlet.PortletURL;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class MockRenderResponse implements javax.portlet.RenderResponse
+{
+
+ public MockRenderResponse()
+ {
+ }
+
+ public PortletURL createActionURL()
+ {
+ return new MockPortletURL();
+ }
+
+ public PortletURL createRenderURL()
+ {
+ // FIXME createRenderURL
+ return null;
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ // FIXME flushBuffer
+
+ }
+
+ public int getBufferSize()
+ {
+ // FIXME getBufferSize
+ return 0;
+ }
+
+ public String getCharacterEncoding()
+ {
+ // FIXME getCharacterEncoding
+ return null;
+ }
+
+ public String getContentType()
+ {
+ // FIXME getContentType
+ return null;
+ }
+
+ public Locale getLocale()
+ {
+ // FIXME getLocale
+ return null;
+ }
+
+ public String getNamespace()
+ {
+ // FIXME getNamespace
+ return null;
+ }
+
+ public OutputStream getPortletOutputStream() throws IllegalStateException,
IOException
+ {
+ // FIXME getPortletOutputStream
+ return null;
+ }
+
+ public PrintWriter getWriter() throws IOException, IllegalStateException
+ {
+ // FIXME getWriter
+ return null;
+ }
+
+ public boolean isCommitted()
+ {
+ // FIXME isCommitted
+ return false;
+ }
+
+ public void reset() throws IllegalStateException
+ {
+ // FIXME reset
+
+ }
+
+ public void resetBuffer() throws IllegalStateException
+ {
+ // FIXME resetBuffer
+
+ }
+
+ public void setBufferSize(int size) throws IllegalStateException
+ {
+ // FIXME setBufferSize
+
+ }
+
+ public void setContentType(String type) throws IllegalArgumentException
+ {
+ // FIXME setContentType
+
+ }
+
+ public void setTitle(String title)
+ {
+ // FIXME setTitle
+
+ }
+
+ public void addProperty(String key, String value) throws IllegalArgumentException
+ {
+ // FIXME addProperty
+
+ }
+
+ public String encodeURL(String path) throws IllegalArgumentException
+ {
+ // FIXME encodeURL
+ return null;
+ }
+
+ public void setProperty(String key, String value) throws IllegalArgumentException
+ {
+ // FIXME setProperty
+
+ }
+
+}
+
Added:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/ScrapperTestCase.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/ScrapperTestCase.java
(rev 0)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/bridge/src/main/org/jboss/portal/test/portlet/bridge/ScrapperTestCase.java 2008-01-20
16:01:57 UTC (rev 9539)
@@ -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.test.portlet.bridge;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.ccil.cowan.tagsoup.Parser;
+import org.jboss.portal.portlet.bridge.ScrapperContentPortlet;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ScrapperTestCase extends TestCase
+{
+
+ public void testRemovedHTML() throws IOException, SAXException
+ {
+
+ String test = "<html><foo></foo></html>";
+ InputStream is = new ByteArrayInputStream(test.getBytes());
+
+ Parser parser = new Parser();
+
+ ScrapperContentPortlet myContentHandler = new ScrapperContentPortlet(null,
"/context");
+ parser.setContentHandler(myContentHandler);
+
+ parser.parse(new InputSource(is));
+ String result = myContentHandler.getContent();
+ assertEquals("<foo></foo>", result);
+ }
+
+ public void testLink() throws IOException, SAXException
+ {
+
+ String test = "<a href=\"foo\">";
+ InputStream is = new ByteArrayInputStream(test.getBytes());
+
+ Parser parser = new Parser();
+
+ ScrapperContentPortlet myContentHandler = new ScrapperContentPortlet(new
MockRenderResponse(), "/context");
+ parser.setContentHandler(myContentHandler);
+
+ parser.parse(new InputSource(is));
+ String result = myContentHandler.getContent();
+ assertEquals("<body><a shape=\"rect\"
href=\"actionURL[org.jboss.portal.bridge.php.requested_page=foo]\"></a></body>",
result);
+ }
+
+}
+