Author: julien(a)jboss.com
Date: 2008-01-10 18:15:34 -0500 (Thu, 10 Jan 2008)
New Revision: 9482
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ClientDataRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
Log:
added ClientDataRequestImpl, MimeResponseImpl and StateAwareResponseImpl which are now
intermediary interfaces between PortletRequest/PortletResponse and their subinterfaces in
JSR 168
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionRequestImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionRequestImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -26,31 +26,19 @@
import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.invocation.ActionInvocation;
-import org.jboss.portal.portlet.spi.ActionContext;
-import org.jboss.portal.common.NotYetImplemented;
import javax.portlet.ActionRequest;
-import javax.servlet.http.Cookie;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6697 $
*/
-public class ActionRequestImpl extends PortletRequestImpl implements ActionRequest
+public class ActionRequestImpl extends ClientDataRequestImpl implements ActionRequest
{
- /** . */
- protected final ActionContext actionContext;
-
public ActionRequestImpl(ActionInvocation invocation)
{
super(invocation);
- this.actionContext = (ActionContext)invocation.getPortletContext();
// Get the possibly null interaction state
StateString interactionState = actionContext.getInteractionState();
@@ -88,71 +76,4 @@
}
}
}
-
- //
-
- public InputStream getPortletInputStream() throws IOException
- {
- if
("application/x-www-form-urlencoded".equals(actionContext.getContentType()))
- {
- throw new IllegalStateException();
- }
- return actionContext.getInputStream();
- }
-
- public void setCharacterEncoding(String s) throws UnsupportedEncodingException
- {
- // This method is frankly stupid
- throw new IllegalStateException("called after the body has been read");
- // req.setCharacterEncoding(s);
- }
-
- public BufferedReader getReader() throws UnsupportedEncodingException, IOException
- {
- if
("application/x-www-form-urlencoded".equals(actionContext.getContentType()))
- {
- throw new IllegalStateException();
- }
- return actionContext.getReader();
- }
-
- public String getCharacterEncoding()
- {
- return actionContext.getCharacterEncoding();
- }
-
- public String getContentType()
- {
- return actionContext.getContentType();
- }
-
- public int getContentLength()
- {
- return actionContext.getContentLength();
- }
-
- public String getWindowID()
- {
- throw new NotYetImplemented();
- }
-
- public Cookie[] getCookies()
- {
- throw new NotYetImplemented();
- }
-
- public Map<String, String[]> getPrivateParameterMap()
- {
- throw new NotYetImplemented();
- }
-
- public Map<String, String[]> getPublicParameterMap()
- {
- throw new NotYetImplemented();
- }
-
- public String getMethod()
- {
- throw new NotYetImplemented();
- }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -23,34 +23,21 @@
package org.jboss.portal.portlet.impl.jsr168.api;
import org.apache.log4j.Logger;
-import org.jboss.portal.Mode;
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
import org.jboss.portal.portlet.invocation.ActionInvocation;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.RedirectionResponse;
import org.jboss.portal.portlet.invocation.response.RenderResponse;
-import org.w3c.dom.Element;
-import org.w3c.dom.DOMException;
import javax.portlet.ActionResponse;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletModeException;
-import javax.portlet.WindowState;
-import javax.portlet.WindowStateException;
-import javax.servlet.http.Cookie;
-import javax.xml.namespace.QName;
import java.io.IOException;
-import java.io.Serializable;
-import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7379 $
*/
-public class ActionResponseImpl extends PortletResponseImpl implements ActionResponse
+public class ActionResponseImpl extends StateAwareResponseImpl implements ActionResponse
{
private static final Logger log = Logger.getLogger(ActionResponseImpl.class);
@@ -75,55 +62,11 @@
this.decision = WANT_NOTHING;
}
- public PortletInvocationResponse getResult()
+ public void sendRedirect(String s, String s1) throws IOException
{
- return response;
+ throw new NotYetImplemented();
}
- public void setWindowState(WindowState windowState) throws WindowStateException
- {
- if (decision == WANT_NOTHING || decision == WANT_RENDER)
- {
- if (!preq.isWindowStateAllowed(windowState))
- {
- throw new WindowStateException("Not supported", windowState);
- }
-
((RenderResponse)response).setWindowState(org.jboss.portal.WindowState.create(windowState.toString()));
- decision = WANT_RENDER;
- }
- else
- {
- throw new IllegalStateException("Window state cannot be set after
redirect");
- }
- }
-
- public void setPortletMode(PortletMode portletMode) throws PortletModeException
- {
- if (decision == WANT_NOTHING || decision == WANT_RENDER)
- {
- if (portletMode == null)
- {
- // The spec does not define that case
- // we just issue a warn
- log.warn("Set null portlet mode");
- }
- else
- {
- if (!preq.isPortletModeAllowed(portletMode))
- {
- throw new PortletModeException("Not supported", portletMode);
- }
- Mode mode = Mode.create(portletMode.toString());
- ((RenderResponse)response).setMode(mode);
- }
- decision = WANT_RENDER;
- }
- else
- {
- throw new IllegalStateException("Portlet mode cannot be set after
redirect");
- }
- }
-
public void sendRedirect(String location) throws IOException
{
if (location == null)
@@ -140,128 +83,4 @@
throw new IllegalArgumentException("URL must be absolute. Was: " +
location);
}
}
-
- /**
- * Generic send redirect.
- *
- * @param redirect
- * @throws IllegalStateException implement jsr168 behavior if the portlet as already
commited stuff
- */
- protected final void sendRedirect(RedirectionResponse redirect) throws
IllegalStateException
- {
- if (decision == WANT_NOTHING || decision == WANT_REDIRECT)
- {
- response = redirect;
- decision = WANT_REDIRECT;
- }
- else
- {
- throw new IllegalStateException("sendRedirect cannot be called after "
+
- "setPortletMode/setWindowState/setRenderParameter/setRenderParameters
" +
- "has been called previously");
- }
- }
-
- public void setRenderParameters(Map<String, String[]> map)
- {
- PortletUtils.checkPortletParameterMapValidity(map);
-
- //
- if (decision == WANT_NOTHING || decision == WANT_RENDER)
- {
-
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).replace(map);
- decision = WANT_RENDER;
- }
- else
- {
- throw new IllegalStateException("setRenderParameters cannot be called after
redirect");
- }
- }
-
- public void setRenderParameter(String name, String value)
- {
- PortletUtils.checkPortletParameterValidity(name, value);
-
- //
- if (decision == WANT_NOTHING || decision == WANT_RENDER)
- {
-
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).setValue(name,
value);
- decision = WANT_RENDER;
- }
- else
- {
- throw new IllegalStateException("setRenderParameter cannot be called after
redirect");
- }
- }
-
- public void setRenderParameter(String name, String[] values)
- {
- PortletUtils.checkPortletParameterValidity(name, values);
-
- //
- if (decision == WANT_NOTHING || decision == WANT_RENDER)
- {
-
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).setValues(name,
values);
- decision = WANT_RENDER;
- }
- else
- {
- throw new IllegalStateException("setRenderParameter cannot be called after
redirect");
- }
- }
-
- public String getNamespace()
- {
- throw new NotYetImplemented();
- }
-
- public void addProperty(Cookie cookie)
- {
- throw new NotYetImplemented();
- }
-
- public void addProperty(String s, Element element)
- {
- throw new NotYetImplemented();
- }
-
- public Element createElement(String s) throws DOMException
- {
- throw new NotYetImplemented();
- }
-
- public void sendRedirect(String s, String s1) throws IOException
- {
- throw new NotYetImplemented();
- }
-
- public void setEvent(QName qName, Serializable serializable)
- {
- throw new NotYetImplemented();
- }
-
- public void setEvent(String s, Serializable serializable)
- {
- throw new NotYetImplemented();
- }
-
- public Map<String, String[]> getRenderParameterMap()
- {
- throw new NotYetImplemented();
- }
-
- public PortletMode getPortletMode()
- {
- throw new NotYetImplemented();
- }
-
- public WindowState getWindowState()
- {
- throw new NotYetImplemented();
- }
-
- public void removePublicRenderParameter(String s)
- {
- throw new NotYetImplemented();
- }
}
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ClientDataRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ClientDataRequestImpl.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ClientDataRequestImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -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.impl.jsr168.api;
+
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.spi.ActionContext;
+import org.jboss.portal.common.NotYetImplemented;
+
+import javax.portlet.ClientDataRequest;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class ClientDataRequestImpl extends PortletRequestImpl implements
ClientDataRequest
+{
+
+ /** . */
+ protected final ActionContext actionContext;
+
+ public ClientDataRequestImpl(PortletInvocation invocation)
+ {
+ super(invocation);
+
+ //
+ this.actionContext = (ActionContext)invocation.getPortletContext();
+ }
+
+ public InputStream getPortletInputStream() throws IOException
+ {
+ if
("application/x-www-form-urlencoded".equals(actionContext.getContentType()))
+ {
+ throw new IllegalStateException();
+ }
+ return actionContext.getInputStream();
+ }
+
+ public BufferedReader getReader() throws UnsupportedEncodingException, IOException
+ {
+ if
("application/x-www-form-urlencoded".equals(actionContext.getContentType()))
+ {
+ throw new IllegalStateException();
+ }
+ return actionContext.getReader();
+ }
+
+ public String getCharacterEncoding()
+ {
+ return actionContext.getCharacterEncoding();
+ }
+
+ public String getContentType()
+ {
+ return actionContext.getContentType();
+ }
+
+ public int getContentLength()
+ {
+ return actionContext.getContentLength();
+ }
+
+ public void setCharacterEncoding(String s) throws UnsupportedEncodingException
+ {
+ // This method is frankly stupid
+ throw new IllegalStateException("called after the body has been read");
+ // req.setCharacterEncoding(s);
+ }
+
+ public String getMethod()
+ {
+ throw new NotYetImplemented();
+ }
+}
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -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.impl.jsr168.api;
+
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
+import org.jboss.portal.common.util.MediaType;
+import org.jboss.portal.common.util.ContentInfo;
+import org.jboss.portal.common.NotYetImplemented;
+import org.w3c.dom.Element;
+import org.w3c.dom.DOMException;
+
+import javax.portlet.MimeResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.ResourceURL;
+import javax.portlet.CacheControl;
+import javax.activation.MimeTypeParseException;
+import javax.servlet.http.Cookie;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class MimeResponseImpl extends PortletResponseImpl implements
MimeResponse
+{
+
+ /** The fragment result. */
+ protected FragmentResponse result;
+
+ /** Not really used but we need it to memorize what the client set optionally. */
+ protected int bufferSize;
+
+ public MimeResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
+ {
+ super(invocation, preq);
+
+ // 0 means no buffering - we say no buffering
+ this.bufferSize = 0;
+ this.result = new FragmentResponse();
+ }
+
+ public PortletInvocationResponse getResult()
+ {
+ return result;
+ }
+
+ public String getContentType()
+ {
+ return result.getContentType();
+ }
+
+ public void setContentType(String contentType)
+ {
+ try
+ {
+ // Remove the unused appended charset first
+ int index = contentType.indexOf(';');
+ if (index != -1)
+ {
+ contentType = contentType.substring(0, index);
+ }
+
+ // Find the content type among the media type we know
+ MediaType requestedMediaType = MediaType.parseMimeType(contentType);
+
+ // Get the response media type
+ ContentInfo info = invocation.getPortletContext().getMarkupInfo();
+ MediaType responseMediaType = info.getContentType();
+
+ // Check if the requested media type is allowed as a subtype of the main
response
+ if (!responseMediaType.isAllowedSubType(requestedMediaType))
+ {
+ throw new IllegalArgumentException("Content type not accepted");
+ }
+
+ // Set the content type
+ result.setContentType(contentType);
+ }
+ catch (MimeTypeParseException e)
+ {
+ IllegalArgumentException ex = new IllegalArgumentException("Content type
not accepted");
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+
+ public PrintWriter getWriter() throws IOException
+ {
+ return result.getWriter();
+ }
+
+ public OutputStream getPortletOutputStream() throws IOException
+ {
+ return result.getOutputStream();
+ }
+
+ public PortletURL createRenderURL()
+ {
+ return PortletUtils.createRenderURL(invocation, preq);
+ }
+
+ public PortletURL createActionURL()
+ {
+ return PortletUtils.createActionURL(invocation, preq);
+ }
+
+ public String getCharacterEncoding()
+ {
+ return invocation.getPortletContext().getMarkupInfo().getCharset();
+ }
+
+ public Locale getLocale()
+ {
+ return invocation.getUserContext().getLocale();
+ }
+
+ public void setBufferSize(int bufferSize)
+ {
+ if (bufferSize > -0)
+ {
+ this.bufferSize = bufferSize;
+ }
+ }
+
+ public int getBufferSize()
+ {
+ return bufferSize;
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ }
+
+ public void resetBuffer()
+ {
+ // Clear the buffer
+ result.resetBuffer();
+ }
+
+ public void reset()
+ {
+ // Clear the buffer
+ resetBuffer();
+
+ // And properties
+
invocation.getContext().getAttributeResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE).getKeys().clear();
+ }
+
+ public boolean isCommitted()
+ {
+ // Never afterCommit
+ return false;
+ }
+
+ public ResourceURL createResourceURL()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public CacheControl getCacheControl()
+ {
+ throw new NotYetImplemented();
+ }
+}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -24,6 +24,7 @@
import org.apache.log4j.Logger;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.portlet.PortletParameters;
import org.jboss.portal.portlet.container.PortletContainerInvoker;
import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
@@ -49,6 +50,7 @@
import javax.portlet.WindowState;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.servlet.http.Cookie;
import java.security.Principal;
import java.util.Collections;
import java.util.Enumeration;
@@ -468,4 +470,24 @@
{
return attributes;
}
+
+ public String getWindowID()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Cookie[] getCookies()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Map<String, String[]> getPrivateParameterMap()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Map<String, String[]> getPublicParameterMap()
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -23,9 +23,14 @@
package org.jboss.portal.portlet.impl.jsr168.api;
import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.common.NotYetImplemented;
+import org.w3c.dom.Element;
+import org.w3c.dom.DOMException;
import javax.portlet.PortletResponse;
+import javax.servlet.http.Cookie;
import java.util.Collection;
import java.util.ArrayList;
@@ -42,6 +47,9 @@
/** . */
protected final PortletRequestImpl preq;
+ /** The namespace. */
+ protected String namespace;
+
protected PortletResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
{
this.invocation = invocation;
@@ -102,4 +110,29 @@
//
invocation.setAttribute(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, key, value);
}
+
+ public String getNamespace()
+ {
+ if (namespace == null)
+ {
+ String windowId = invocation.getWindowContext().getId();
+ namespace = PortletUtils.generateNamespaceFrom(windowId);
+ }
+ return namespace;
+ }
+
+ public void addProperty(Cookie cookie)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void addProperty(String s, Element element)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Element createElement(String s) throws DOMException
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderRequestImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderRequestImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -69,26 +69,6 @@
}
}
- public String getWindowID()
- {
- throw new NotYetImplemented();
- }
-
- public Cookie[] getCookies()
- {
- throw new NotYetImplemented();
- }
-
- public Map<String, String[]> getPrivateParameterMap()
- {
- throw new NotYetImplemented();
- }
-
- public Map<String, String[]> getPublicParameterMap()
- {
- throw new NotYetImplemented();
- }
-
public String getETag()
{
throw new NotYetImplemented();
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-01-10
22:12:28 UTC (rev 9481)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -22,210 +22,32 @@
******************************************************************************/
package org.jboss.portal.portlet.impl.jsr168.api;
-import org.jboss.portal.common.util.MediaType;
-import org.jboss.portal.common.util.ContentInfo;
import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
-import org.jboss.portal.portlet.invocation.response.FragmentResponse;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
-import org.w3c.dom.Element;
-import org.w3c.dom.DOMException;
-import javax.activation.MimeTypeParseException;
-import javax.portlet.PortletURL;
import javax.portlet.RenderResponse;
import javax.portlet.PortletMode;
-import javax.portlet.ResourceURL;
-import javax.portlet.CacheControl;
-import javax.servlet.http.Cookie;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.Locale;
import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6704 $
*/
-public class RenderResponseImpl extends PortletResponseImpl implements RenderResponse
+public class RenderResponseImpl extends MimeResponseImpl implements RenderResponse
{
- /** The fragment result. */
- protected FragmentResponse result;
-
- /** The namespace. */
- protected String namespace;
-
- /** Not really used but we need it to memorize what the client set optionally. */
- protected int bufferSize;
-
public RenderResponseImpl(RenderInvocation invocation, PortletRequestImpl preq)
{
super(invocation, preq);
-
- // 0 means no buffering - we say no buffering
- this.bufferSize = 0;
- this.result = new FragmentResponse();
}
- public PortletInvocationResponse getResult()
- {
- return result;
- }
-
public void setTitle(String s)
{
result.setTitle(s);
}
- public String getContentType()
- {
- return result.getContentType();
- }
-
- public void setContentType(String contentType)
- {
- try
- {
- // Remove the unused appended charset first
- int index = contentType.indexOf(';');
- if (index != -1)
- {
- contentType = contentType.substring(0, index);
- }
-
- // Find the content type among the media type we know
- MediaType requestedMediaType = MediaType.parseMimeType(contentType);
-
- // Get the response media type
- ContentInfo info = invocation.getPortletContext().getMarkupInfo();
- MediaType responseMediaType = info.getContentType();
-
- // Check if the requested media type is allowed as a subtype of the main
response
- if (!responseMediaType.isAllowedSubType(requestedMediaType))
- {
- throw new IllegalArgumentException("Content type not accepted");
- }
-
- // Set the content type
- result.setContentType(contentType);
- }
- catch (MimeTypeParseException e)
- {
- IllegalArgumentException ex = new IllegalArgumentException("Content type
not accepted");
- ex.initCause(e);
- throw ex;
- }
- }
-
- public PrintWriter getWriter() throws IOException
- {
- return result.getWriter();
- }
-
- public OutputStream getPortletOutputStream() throws IOException
- {
- return result.getOutputStream();
- }
-
- public PortletURL createRenderURL()
- {
- return PortletUtils.createRenderURL(invocation, preq);
- }
-
- public PortletURL createActionURL()
- {
- return PortletUtils.createActionURL(invocation, preq);
- }
-
- public String getNamespace()
- {
- if (namespace == null)
- {
- String windowId = invocation.getWindowContext().getId();
- namespace = PortletUtils.generateNamespaceFrom(windowId);
- }
- return namespace;
- }
-
- public String getCharacterEncoding()
- {
- return invocation.getPortletContext().getMarkupInfo().getCharset();
- }
-
- public Locale getLocale()
- {
- return invocation.getUserContext().getLocale();
- }
-
- public void setBufferSize(int bufferSize)
- {
- if (bufferSize > -0)
- {
- this.bufferSize = bufferSize;
- }
- }
-
- public int getBufferSize()
- {
- return bufferSize;
- }
-
- public void flushBuffer() throws IOException
- {
- }
-
- public void resetBuffer()
- {
- // Clear the buffer
- result.resetBuffer();
- }
-
- public void reset()
- {
- // Clear the buffer
- resetBuffer();
-
- // And properties
-
invocation.getContext().getAttributeResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE).getKeys().clear();
- }
-
- public boolean isCommitted()
- {
- // Never afterCommit
- return false;
- }
-
- public void addProperty(Cookie cookie)
- {
- throw new NotYetImplemented();
- }
-
- public void addProperty(String s, Element element)
- {
- throw new NotYetImplemented();
- }
-
- public Element createElement(String s) throws DOMException
- {
- throw new NotYetImplemented();
- }
-
public void setNextPossiblePortletModes(Collection<PortletMode> portletModes)
{
throw new NotYetImplemented();
}
-
- public ResourceURL createResourceURL()
- {
- throw new NotYetImplemented();
- }
-
- public CacheControl getCacheControl()
- {
- throw new NotYetImplemented();
- }
}
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-10
23:15:34 UTC (rev 9482)
@@ -0,0 +1,220 @@
+/******************************************************************************
+ * 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.impl.jsr168.api;
+
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.RenderResponse;
+import org.jboss.portal.portlet.invocation.response.RedirectionResponse;
+import org.jboss.portal.portlet.PortletParametersStateString;
+import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
+import org.jboss.portal.Mode;
+import org.jboss.portal.common.NotYetImplemented;
+import org.apache.log4j.Logger;
+
+import javax.portlet.StateAwareResponse;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class StateAwareResponseImpl extends PortletResponseImpl implements
StateAwareResponse
+{
+
+ private static final Logger log = Logger.getLogger(ActionResponseImpl.class);
+
+ protected static final int WANT_NOTHING = 0;
+ protected static final int WANT_RENDER = 1;
+ protected static final int WANT_REDIRECT = 2;
+
+ protected PortletInvocationResponse response;
+ protected int decision;
+
+ public StateAwareResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
+ {
+ super(invocation, preq);
+
+ //
+ RenderResponse rr = new RenderResponse();
+ rr.setNavigationalState(new PortletParametersStateString());
+
+ //
+ this.response = rr;
+ this.decision = WANT_NOTHING;
+ }
+
+ public PortletInvocationResponse getResult()
+ {
+ return response;
+ }
+
+ public void setWindowState(WindowState windowState) throws WindowStateException
+ {
+ if (decision == WANT_NOTHING || decision == WANT_RENDER)
+ {
+ if (!preq.isWindowStateAllowed(windowState))
+ {
+ throw new WindowStateException("Not supported", windowState);
+ }
+
((RenderResponse)response).setWindowState(org.jboss.portal.WindowState.create(windowState.toString()));
+ decision = WANT_RENDER;
+ }
+ else
+ {
+ throw new IllegalStateException("Window state cannot be set after
redirect");
+ }
+ }
+
+ public void setPortletMode(PortletMode portletMode) throws PortletModeException
+ {
+ if (decision == WANT_NOTHING || decision == WANT_RENDER)
+ {
+ if (portletMode == null)
+ {
+ // The spec does not define that case
+ // we just issue a warn
+ log.warn("Set null portlet mode");
+ }
+ else
+ {
+ if (!preq.isPortletModeAllowed(portletMode))
+ {
+ throw new PortletModeException("Not supported", portletMode);
+ }
+ Mode mode = Mode.create(portletMode.toString());
+ ((RenderResponse)response).setMode(mode);
+ }
+ decision = WANT_RENDER;
+ }
+ else
+ {
+ throw new IllegalStateException("Portlet mode cannot be set after
redirect");
+ }
+ }
+
+ /**
+ * Generic send redirect.
+ *
+ * @param redirect
+ * @throws IllegalStateException implement jsr168 behavior if the portlet as already
commited stuff
+ */
+ protected final void sendRedirect(RedirectionResponse redirect) throws
IllegalStateException
+ {
+ if (decision == WANT_NOTHING || decision == WANT_REDIRECT)
+ {
+ response = redirect;
+ decision = WANT_REDIRECT;
+ }
+ else
+ {
+ throw new IllegalStateException("sendRedirect cannot be called after "
+
+ "setPortletMode/setWindowState/setRenderParameter/setRenderParameters
" +
+ "has been called previously");
+ }
+ }
+
+ public void setRenderParameters(Map<String, String[]> map)
+ {
+ PortletUtils.checkPortletParameterMapValidity(map);
+
+ //
+ if (decision == WANT_NOTHING || decision == WANT_RENDER)
+ {
+
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).replace(map);
+ decision = WANT_RENDER;
+ }
+ else
+ {
+ throw new IllegalStateException("setRenderParameters cannot be called after
redirect");
+ }
+ }
+
+ public void setRenderParameter(String name, String value)
+ {
+ PortletUtils.checkPortletParameterValidity(name, value);
+
+ //
+ if (decision == WANT_NOTHING || decision == WANT_RENDER)
+ {
+
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).setValue(name,
value);
+ decision = WANT_RENDER;
+ }
+ else
+ {
+ throw new IllegalStateException("setRenderParameter cannot be called after
redirect");
+ }
+ }
+
+ public void setRenderParameter(String name, String[] values)
+ {
+ PortletUtils.checkPortletParameterValidity(name, values);
+
+ //
+ if (decision == WANT_NOTHING || decision == WANT_RENDER)
+ {
+
((PortletParametersStateString)((RenderResponse)response).getNavigationalState()).setValues(name,
values);
+ decision = WANT_RENDER;
+ }
+ else
+ {
+ throw new IllegalStateException("setRenderParameter cannot be called after
redirect");
+ }
+ }
+
+ public void setEvent(QName qName, Serializable serializable)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void setEvent(String s, Serializable serializable)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Map<String, String[]> getRenderParameterMap()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletMode getPortletMode()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public WindowState getWindowState()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void removePublicRenderParameter(String s)
+ {
+ throw new NotYetImplemented();
+ }
+}