You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by zh...@apache.org on 2006/02/22 12:16:11 UTC
svn commit: r379753 - in
/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto:
core/InternalPortletRequest.java core/InternalPortletResponse.java
core/impl/PortletResponseImpl.java core/impl/RenderResponseImpl.java
util/StringUtils.java
Author: zheng
Date: Wed Feb 22 03:16:05 2006
New Revision: 379753
URL: http://svn.apache.org/viewcvs?rev=379753&view=rev
Log:
Removed lateInit in InternalPortletResponse. Removed inherited methods from PortletResponseImpl.
Modified:
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletRequest.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletResponse.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletResponseImpl.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/RenderResponseImpl.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/util/StringUtils.java
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletRequest.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletRequest.java?rev=379753&r1=379752&r2=379753&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletRequest.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletRequest.java Wed Feb 22 03:16:05 2006
@@ -43,7 +43,7 @@
* @param context the target portlet context.
* @param request the servlet request.
*/
- public void init(PortletContext context, HttpServletRequest req);
+ public void init(PortletContext context, HttpServletRequest request);
/**
* Recycle the request by rolling the underlying request
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletResponse.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletResponse.java?rev=379753&r1=379752&r2=379753&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletResponse.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/InternalPortletResponse.java Wed Feb 22 03:16:05 2006
@@ -17,8 +17,6 @@
package org.apache.pluto.core;
import javax.portlet.PortletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
* The internal portlet response interface extends PortletResponse and adds
@@ -28,9 +26,6 @@
* @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
*/
public interface InternalPortletResponse extends PortletResponse {
-
- public void lateInit(HttpServletRequest webModuleServletRequest,
- HttpServletResponse webModuleServletResponse);
public InternalPortletWindow getInternalPortletWindow();
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletResponseImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletResponseImpl.java?rev=379753&r1=379752&r2=379753&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletResponseImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletResponseImpl.java Wed Feb 22 03:16:05 2006
@@ -21,8 +21,6 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.Locale;
import javax.portlet.PortletResponse;
import javax.servlet.ServletOutputStream;
@@ -55,14 +53,9 @@
/** The internal portlet window. */
private InternalPortletWindow internalPortletWindow = null;
- /**
- * this variable holds the servlet request of the target/portlet's web
- * module
- */
- private HttpServletRequest httpServletRequest;
+ /** The servlet request of the target/portlet's web module. */
+ private HttpServletRequest httpServletRequest = null;
- private HttpServletResponse httpServletResponse;
-
private boolean usingWriter;
private boolean usingStream;
@@ -78,7 +71,6 @@
super(servletResponse);
this.container = container;
this.httpServletRequest = servletRequest;
- this.httpServletResponse = servletResponse;
this.internalPortletWindow = internalPortletWindow;
}
@@ -128,12 +120,6 @@
// InternalPortletResponse impl --------------------------------------------
- public void lateInit(HttpServletRequest httpServletRequest,
- HttpServletResponse httpServletResponse) {
- this.httpServletRequest = httpServletRequest;
- this.setResponse(httpServletResponse);
- }
-
public InternalPortletWindow getInternalPortletWindow() {
return internalPortletWindow;
}
@@ -162,115 +148,43 @@
* @return the nested HttpServletResponse instance.
*/
public HttpServletResponse getHttpServletResponse() {
- return httpServletResponse;
+ return (HttpServletResponse) super.getResponse();
}
// HttpServletResponse Methods ---------------------------------------------
- // TODO: should we just use super impl?
- public void addCookie(javax.servlet.http.Cookie cookie) {
- getHttpServletResponse().addCookie(cookie);
- }
-
- public boolean containsHeader(String name) {
- return getHttpServletResponse().containsHeader(name);
- }
-
- public String encodeRedirectUrl(String url) {
- return getHttpServletResponse().encodeRedirectURL(url);
- }
-
- public String encodeRedirectURL(String url) {
- return getHttpServletResponse().encodeRedirectURL(url);
- }
-
- public void sendRedirect(String location) throws java.io.IOException {
- getHttpServletResponse().sendRedirect(location);
- }
-
- public void setDateHeader(String name, long date) {
- getHttpServletResponse().setDateHeader(name, date);
- }
-
- public void sendError(int sc, String msg) throws java.io.IOException {
- getHttpServletResponse().sendError(sc, msg);
- }
-
- public void sendError(int sc) throws java.io.IOException {
- getHttpServletResponse().sendError(sc);
- }
-
- public void addHeader(String name, String value) {
- getHttpServletResponse().addHeader(name, value);
- }
-
- public void setIntHeader(String name, int value) {
- getHttpServletResponse().setIntHeader(name, value);
- }
-
- public void addDateHeader(String name, long date) {
- getHttpServletResponse().addDateHeader(name, date);
- }
-
- public void setHeader(String name, String value) {
- getHttpServletResponse().setHeader(name, value);
- }
-
- public void setStatus(int statusCode) {
- getHttpServletResponse().setStatus(statusCode);
- }
-
- public void setStatus(int statusCode, String message) {
- getHttpServletResponse().setStatus(statusCode, message);
- }
-
- public void addIntHeader(String name, int value) {
- getHttpServletResponse().addIntHeader(name, value);
- }
-
- public void setContentLength(int len) {
- getHttpServletResponse().setContentLength(len);
- }
-
public String encodeUrl(String url) {
return this.encodeURL(url);
}
-
- public void setLocale(Locale locale) {
- getHttpServletResponse().setLocale(locale);
- }
-
-
- // -------------------------------------------------------------------------
+ /**
+ * TODO: javadoc about why we are using a wrapped writer here.
+ * @see org.apache.pluto.util.PrintWriterServletOutputStream
+ */
public ServletOutputStream getOutputStream()
throws IllegalStateException, IOException {
if (usingWriter) {
throw new IllegalStateException(
- "getPortletOutputStream can't be used after getWriter was invoked");
+ "getPortletOutputStream can't be used "
+ + "after getWriter was invoked.");
}
-
if (wrappedWriter == null) {
- wrappedWriter =
- new PrintWriterServletOutputStream(
- getHttpServletResponse().getWriter());
+ wrappedWriter = new PrintWriterServletOutputStream(
+ getHttpServletResponse().getWriter());
}
-
usingStream = true;
-
return wrappedWriter;
}
-
+
public PrintWriter getWriter()
- throws UnsupportedEncodingException, IllegalStateException, IOException {
+ throws IllegalStateException, IOException {
if (usingStream) {
throw new IllegalStateException(
- "getWriter can't be used after getOutputStream was invoked");
+ "getWriter can't be used "
+ + "after getOutputStream was invoked.");
}
-
usingWriter = true;
-
return getHttpServletResponse().getWriter();
}
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/RenderResponseImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/RenderResponseImpl.java?rev=379753&r1=379752&r2=379753&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/RenderResponseImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/RenderResponseImpl.java Wed Feb 22 03:16:05 2006
@@ -24,10 +24,10 @@
import org.apache.pluto.PortletContainer;
import org.apache.pluto.core.InternalPortletWindow;
import org.apache.pluto.core.InternalRenderResponse;
-import org.apache.pluto.core.PortletEntity;
import org.apache.pluto.descriptors.portlet.PortletDD;
import org.apache.pluto.descriptors.portlet.SupportsDD;
import org.apache.pluto.services.PortalCallbackService;
+import org.apache.pluto.util.ArgumentUtility;
import org.apache.pluto.util.NamespaceMapper;
import org.apache.pluto.util.StringManager;
import org.apache.pluto.util.StringUtils;
@@ -35,21 +35,29 @@
import javax.portlet.PortletURL;
import javax.portlet.RenderResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
+/**
+ * Implementation of the <code>javax.portlet.RenderResponse</code> interface.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
public class RenderResponseImpl extends PortletResponseImpl
implements RenderResponse, InternalRenderResponse {
/** Logger. */
private static final Log LOG = LogFactory.getLog(RenderResponseImpl.class);
- private static final StringManager EXCEPTIONS =
- StringManager.getManager(RenderResponseImpl.class.getPackage().getName());
+ private static final StringManager EXCEPTIONS = StringManager.getManager(
+ RenderResponseImpl.class.getPackage().getName());
// Private Member Variables ------------------------------------------------
@@ -57,10 +65,7 @@
/** True if we are in an include call. */
private boolean included = false;
- /**
- * The current content type.
- * TODO: This should be made dynamic
- */
+ /** The current content type. */
private String currentContentType = null;
private NamespaceMapper mapper = new NamespaceMapperImpl();
@@ -70,10 +75,9 @@
public RenderResponseImpl(PortletContainer container,
InternalPortletWindow internalPortletWindow,
- javax.servlet.http.HttpServletRequest servletRequest,
- javax.servlet.http.HttpServletResponse servletResponse) {
- super(container, internalPortletWindow, servletRequest,
- servletResponse);
+ HttpServletRequest servletRequest,
+ HttpServletResponse servletResponse) {
+ super(container, internalPortletWindow, servletRequest, servletResponse);
}
@@ -81,7 +85,7 @@
public String getContentType() {
// NOTE: in servlet 2.4 we could simply use this:
- // return this.getHttpServletResponse().getContentType();
+ // return super.getHttpServletResponse().getContentType();
return currentContentType;
}
@@ -116,19 +120,26 @@
title);
}
- public void setContentType(String type) {
- String mimeType = StringUtils.stringCharacterEncoding(type);
+ public void setContentType(String contentType)
+ throws IllegalArgumentException {
+ ArgumentUtility.validateNotNull("contentType", contentType);
+ String mimeType = StringUtils.getMimeTypeWithoutEncoding(contentType);
if (!isValidContentType(mimeType)) {
- throw new IllegalArgumentException(mimeType);
+ throw new IllegalArgumentException("Specified content type '"
+ + mimeType + "' is not supported.");
}
- this.getHttpServletResponse().setContentType(mimeType);
+ getHttpServletResponse().setContentType(mimeType);
this.currentContentType = mimeType;
}
public String getCharacterEncoding() {
- return this.getHttpServletResponse().getCharacterEncoding();
+ return getHttpServletResponse().getCharacterEncoding();
}
-
+
+ /**
+ * @see PortletResponseImpl#getOutputStream()
+ * @see #getWriter()
+ */
public OutputStream getPortletOutputStream()
throws IOException, IllegalStateException {
if (currentContentType == null) {
@@ -138,9 +149,13 @@
}
throw new IllegalStateException(message);
}
- return getOutputStream();
+ return super.getOutputStream();
}
+ /**
+ * @see PortletResponseImpl#getWriter()
+ * @see #getPortletOutputStream()
+ */
public PrintWriter getWriter() throws IOException, IllegalStateException {
if (currentContentType == null) {
String message = EXCEPTIONS.getString("error.contenttype.null");
@@ -153,7 +168,7 @@
}
public Locale getLocale() {
- return this.getHttpServletRequest().getLocale();
+ return getHttpServletRequest().getLocale();
}
// TODO: port 1.0.1 setBufferSize fix to 1.1
@@ -168,19 +183,19 @@
}
public void flushBuffer() throws IOException {
- this.getHttpServletResponse().flushBuffer();
+ getHttpServletResponse().flushBuffer();
}
public void resetBuffer() {
- this.getHttpServletResponse().resetBuffer();
+ getHttpServletResponse().resetBuffer();
}
public boolean isCommitted() {
- return this.getHttpServletResponse().isCommitted();
+ return getHttpServletResponse().isCommitted();
}
public void reset() {
- this.getHttpServletResponse().reset();
+ getHttpServletResponse().reset();
}
@@ -195,7 +210,7 @@
}
- // -------------------------------------------------------------------------
+ // Included HttpServletResponse (Limited) Impl -----------------------------
/**
* TODO
@@ -218,11 +233,15 @@
return super.encodeRedirectURL(url);
}
}
-
+
+
+ // Private Methods ---------------------------------------------------------
+
/**
- * @param isAction
- * @return
- * @todo make dynamic? as service?
+ * Creates a portlet URL.
+ * TODO: make dynamic? as service?
+ * @param isAction true for an action URL, false for a render URL.
+ * @return the created portlet (action/render) URL.
*/
private PortletURL createURL(boolean isAction) {
return new PortletURLImpl(getContainer(),
@@ -230,41 +249,51 @@
getHttpServletRequest(),
getHttpServletResponse(),
isAction);
-
}
-
- private boolean isValidContentType(String type)
- {
- type = StringUtils.stringCharacterEncoding(type);
- PortletEntity entity = getInternalPortletWindow().getPortletEntity();
- PortletDD def = entity.getPortletDefinition();
- List contentTypes = def.getSupports();
- Iterator it = contentTypes.iterator();
- while(it.hasNext()) {
- SupportsDD ct = (SupportsDD)it.next();
- String supportedType = ct.getMimeType();
- if (supportedType.equals(type)) {
- return true;
- } else if (supportedType.indexOf("*") >= 0) {
- // the supported type contains a wildcard
+
+ /**
+ * Checks if the specified content type is valid (supported by the portlet).
+ * The specified content type should be a tripped mime type without any
+ * character encoding suffix.
+ * @param contentType the content type to check.
+ * @return true if the content type is valid, false otherwise.
+ */
+ private boolean isValidContentType(String contentType) {
+ boolean valid = false;
+
+ PortletDD portletDD = getInternalPortletWindow().getPortletEntity()
+ .getPortletDefinition();
+ for (Iterator it = portletDD.getSupports().iterator();
+ !valid && it.hasNext(); ) {
+
+ SupportsDD supportsDD = (SupportsDD) it.next();
+ String supportedType = supportsDD.getMimeType();
+
+ // Content type is supported by an exact match.
+ if (supportedType.equals(contentType)) {
+ valid = true;
+ }
+ // The supported type contains a wildcard.
+ else if (supportedType.indexOf("*") >= 0) {
+
int index = supportedType.indexOf("/");
String supportedPrefix = supportedType.substring(0, index);
- String supportedSuffix = supportedType.substring(index + 1, supportedType.length());
-
- index = type.indexOf("/");
- String typePrefix = type.substring(0, index);
- String typeSuffix = type.substring(index + 1, type.length());
-
+ String supportedSuffix = supportedType.substring(index + 1);
+
+ index = contentType.indexOf("/");
+ String typePrefix = contentType.substring(0, index);
+ String typeSuffix = contentType.substring(index + 1);
+
+ // Check if the prefixes match AND the suffixes match.
if (supportedPrefix.equals("*") || supportedPrefix.equals(typePrefix)) {
- // the prefixes match
if (supportedSuffix.equals("*") || supportedSuffix.equals(typeSuffix)) {
- // the suffixes match
- return true;
+ valid = true;
}
}
}
}
- return false;
+ // Return the check result.
+ return valid;
}
}
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/util/StringUtils.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/util/StringUtils.java?rev=379753&r1=379752&r2=379753&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/util/StringUtils.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/util/StringUtils.java Wed Feb 22 03:16:05 2006
@@ -24,23 +24,35 @@
import java.util.Map;
/**
- * <CODE>StringUtils</CODE> hosts a couple of utility methods around
- * strings.
+ * Static class hosting a couple of utility methods around strings.
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
*/
public class StringUtils {
-
-
+
+ // Private Constructor -----------------------------------------------------
+
+ /**
+ * Private constructor that prevents external instantiation.
+ */
+ private StringUtils() {
+ // Do nothing.
+ }
+
+
+ // Static Utility Methods --------------------------------------------------
+
/**
- * Replace all occurrences of a pattern within a string by a replacement
- * @param source The string that should be searched
- * @param pattern The pattern that should be replaced
- * @param replace The replacement that should be inserted instead of the
- * pattern
- * @return The updated source string
+ * Replaces all occurrences of a pattern within a string by a replacement.
+ * @param source the string that should be searched.
+ * @param pattern the pattern that should be replaced.
+ * @param replace the replacement that should be inserted instead of the
+ * pattern.
+ * @return The updated source string.
*/
public static String replace(String source, String pattern, String replace) {
- if (source == null || source.length() == 0 ||
- pattern == null || pattern.length() == 0) {
+ if (source == null || source.length() == 0
+ || pattern == null || pattern.length() == 0) {
return source;
}
@@ -66,7 +78,12 @@
out.append(source.substring(i));
return out.toString();
}
-
+
+ /**
+ * TODO: can't we just use String[].clone()?
+ * @param source
+ * @return
+ */
public static String[] copy(String[] source) {
if (source == null) {
return null;
@@ -76,7 +93,13 @@
System.arraycopy(source, 0, result, 0, length);
return result;
}
-
+
+ /**
+ * Deep-clones a parameter map. The key is the parameter name as a String
+ * instance, while the value is a String array (String[]) instance.
+ * @param parameters the parameter map to deep-clone.
+ * @return the deep-cloned parameter map.
+ */
public static Map copyParameters(Map parameters) {
Map result = new HashMap(parameters);
for (Iterator it = result.entrySet().iterator(); it.hasNext();) {
@@ -94,14 +117,22 @@
}
return result;
}
-
- public static String stringCharacterEncoding(String mimeType) {
- int xs = mimeType.indexOf(';');
- String strippedType;
- if (xs == -1) {
+
+ /**
+ * Strips the specified mime type by removing the character encoding
+ * specified at the end of the mime type (all characters after the ';').
+ * The stripped mime type is trimmed string which contains no white
+ * spaces at the beginning and the end.
+ * @param mimeType the mime type to strip.
+ * @return the stripped mime type.
+ */
+ public static String getMimeTypeWithoutEncoding(String mimeType) {
+ int index = mimeType.indexOf(';');
+ String strippedType = null;
+ if (index == -1) {
strippedType = mimeType;
} else {
- strippedType = mimeType.substring(0,xs);
+ strippedType = mimeType.substring(0, index);
}
return strippedType.trim();
}