You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2009/04/13 21:26:00 UTC
svn commit: r764572 - in /myfaces/core/branches/2_0_0:
api/src/main/java/javax/faces/context/
impl/src/main/java/org/apache/myfaces/context/servlet/
Author: jankeesvanandel
Date: Mon Apr 13 19:25:59 2009
New Revision: 764572
URL: http://svn.apache.org/viewvc?rev=764572&view=rev
Log:
MYFACES-2187: Fixed issue and validated the rest of the classes with the spec (one note: ExternalContextWrapper is not in the spec JavaDocs, so it might be removed later)
Modified:
myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContext.java
myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContextWrapper.java
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
Modified: myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContext.java?rev=764572&r1=764571&r2=764572&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContext.java (original)
+++ myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContext.java Mon Apr 13 19:25:59 2009
@@ -22,13 +22,14 @@
import java.io.OutputStream;
import java.io.Writer;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
- *
+ *
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
*/
@@ -40,11 +41,11 @@
public static final String FORM_AUTH = "FORM";
/**
- *
+ *
* @param name
* @param value
* @param properties
- *
+ *
* @since 2.0
*/
public void addResponseCookie(String name, String value, Map<String, Object> properties)
@@ -53,10 +54,10 @@
}
/**
- *
+ *
* @param name
* @param value
- *
+ *
* @since 2.0
*/
public void addResponseHeader(String name, String value)
@@ -68,8 +69,38 @@
public abstract String encodeActionURL(String url);
+ /**
+ *
+ * @param baseUrl
+ * @param parameters
+ *
+ * @since 2.0
+ */
+ public String encodeBookmarkableURL(String baseUrl, Map<String,List<String>> parameters)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public abstract String encodeNamespace(String name);
+
+ /**
+ * @since 2.0
+ */
+ public abstract String encodePartialActionURL(String url); // TODO: IMPLEMENT IMPL
+
+ /**
+ *
+ * @param baseUrl
+ * @param parameters
+ *
+ * @since 2.0
+ */
+ public String encodeRedirectURL(String baseUrl, Map<String,List<String>> parameters)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public abstract String encodeResourceURL(String url);
public abstract Map<String, Object> getApplicationMap();
@@ -80,14 +111,21 @@
/**
* Returns the name of the underlying context
- *
+ *
* @return the name or null
- *
+ *
* @since 2.0
*/
public String getContextName()
{
- // TODO: IMPLEMENT IMPL JSF 2.0 MYFACES-1950
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Flash getFlash()
+ {
throw new UnsupportedOperationException();
}
@@ -122,9 +160,9 @@
}
/**
- *
+ *
* @return
- *
+ *
* @since 2.0
*/
public int getRequestContentLength()
@@ -194,9 +232,9 @@
public abstract Object getResponse();
/**
- *
+ *
* @return
- *
+ *
* @since 2.0
*/
public int getResponseBufferSize()
@@ -211,7 +249,7 @@
/**
* throws <code>UnsupportedOperationException</code> by default.
- *
+ *
* @since JSF 1.2
*/
public String getResponseContentType()
@@ -242,8 +280,6 @@
public abstract java.security.Principal getUserPrincipal();
/**
- *
- *
* @since 2.0
*/
public void invalidateSession()
@@ -252,9 +288,6 @@
}
/**
- *
- * @return
- *
* @since 2.0
*/
public boolean isResponseCommitted()
@@ -264,16 +297,22 @@
public abstract boolean isUserInRole(String role);
+ /**
+ * @since 2.0
+ */
public abstract void log(String message);
+ /**
+ * @since 2.0
+ */
public abstract void log(String message, Throwable exception);
public abstract void redirect(String url) throws java.io.IOException;
/**
- *
+ *
* @throws IOException
- *
+ *
* @since 2.0
*/
public void responseFlushBuffer() throws IOException
@@ -282,7 +321,7 @@
}
/**
- *
+ *
* @since 2.0
*/
public void responseReset()
@@ -291,11 +330,11 @@
}
/**
- *
+ *
* @param statusCode
* @param message
* @throws IOException
- *
+ *
* @since 2.0
*/
public void responseSendError(int statusCode, String message) throws IOException
@@ -305,7 +344,7 @@
/**
* throws <code>UnsupportedOperationException</code> by default.
- *
+ *
* @since JSF 1.2
* @param request
*/
@@ -316,7 +355,7 @@
/**
* throws <code>UnsupportedOperationException</code> by default.
- *
+ *
* @since JSF 1.2
* @param encoding
* @throws java.io.UnsupportedEncodingException
@@ -328,7 +367,7 @@
/**
* throws <code>UnsupportedOperationException</code> by default.
- *
+ *
* @since JSF 1.2
* @param response
*/
@@ -338,9 +377,9 @@
}
/**
- *
+ *
* @param size
- *
+ *
* @since 2.0
*/
public void setResponseBufferSize(int size)
@@ -350,7 +389,7 @@
/**
* throws <code>UnsupportedOperationException</code> by default.
- *
+ *
* @since JSF 1.2
* @param encoding
*/
@@ -360,9 +399,9 @@
}
/**
- *
+ *
* @param length
- *
+ *
* @since 2.0
*/
public void setResponseContentLength(int length)
@@ -371,9 +410,9 @@
}
/**
- *
+ *
* @param contentType
- *
+ *
* @since 2.0
*/
public void setResponseContentType(String contentType)
@@ -382,21 +421,21 @@
}
/**
- *
+ *
* @param name
* @param value
- *
+ *
* @since 2.0
*/
public void setResponseHeader(String name, String value)
{
throw new UnsupportedOperationException();
}
-
+
/**
- *
+ *
* @param statusCode
- *
+ *
* @since 2.0
*/
public void setResponseStatus(int statusCode)
Modified: myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContextWrapper.java?rev=764572&r1=764571&r2=764572&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContextWrapper.java (original)
+++ myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/ExternalContextWrapper.java Mon Apr 13 19:25:59 2009
@@ -27,6 +27,7 @@
import java.net.URL;
import java.security.Principal;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -43,7 +44,7 @@
{
/**
- *
+ *
*/
public ExternalContextWrapper()
{
@@ -74,12 +75,30 @@
}
@Override
+ public String encodeBookmarkableURL(String baseUrl, Map<String,List<String>> parameters)
+ {
+ return getWrapped().encodeBookmarkableURL(baseUrl,parameters);
+ }
+
+ @Override
public String encodeNamespace(String name)
{
return getWrapped().encodeNamespace(name);
}
@Override
+ public String encodePartialActionURL(String url)
+ {
+ return getWrapped().encodePartialActionURL(url);
+ }
+
+ @Override
+ public String encodeRedirectURL(String baseUrl,Map<String,List<String>> parameters)
+ {
+ return getWrapped().encodeRedirectURL(baseUrl,parameters);
+ }
+
+ @Override
public String encodeResourceURL(String url)
{
return getWrapped().encodeResourceURL(url);
@@ -110,6 +129,12 @@
}
@Override
+ public Flash getFlash()
+ {
+ return getWrapped().getFlash();
+ }
+
+ @Override
public String getInitParameter(String name)
{
return getWrapped().getInitParameter(name);
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java?rev=764572&r1=764571&r2=764572&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java Mon Apr 13 19:25:59 2009
@@ -22,10 +22,15 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLEncoder;
import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -45,17 +50,25 @@
import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.util.EnumerationIterator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Implements the external context for servlet request. JSF 1.2, 6.1.3
- *
+ *
* @author Manfred Geiler (latest modification by $Author$)
* @author Anton Koinov
* @version $Revision$ $Date$
*/
public final class ServletExternalContextImpl extends ExternalContext implements ReleaseableExternalContext
{
+ private static final Log log = LogFactory.getLog(ServletExternalContextImpl.class);
+
private static final String INIT_PARAMETER_MAP_ATTRIBUTE = InitParameterMap.class.getName();
+ private static final String URL_PARAM_SEPERATOR="&";
+ private static final String URL_QUERY_SEPERATOR="?";
+ private static final String URL_FRAGMENT_SEPERATOR="#";
+ private static final String URL_NAME_VALUE_PAIR_SEPERATOR="=";
private ServletContext _servletContext;
private ServletRequest _servletRequest;
@@ -138,14 +151,14 @@
{
return _servletRequest;
}
-
+
/**
* @since 2.0
*/
@Override
public int getRequestContentLength()
- {
- return _servletRequest.getContentLength();
+ {
+ return _servletRequest.getContentLength();
}
@Override
@@ -153,14 +166,14 @@
{
return _servletResponse;
}
-
+
/**
* @since 2.0
*/
@Override
public int getResponseBufferSize()
{
- return _servletResponse.getBufferSize();
+ return _servletResponse.getBufferSize();
}
@Override
@@ -174,7 +187,7 @@
{
return _servletResponse.getOutputStream();
}
-
+
/**
* @since JSF 2.0
*/
@@ -280,7 +293,7 @@
checkHttpServletRequest();
_requestCookieMap = new CookieMap(_httpServletRequest);
}
-
+
return _requestCookieMap;
}
@@ -371,6 +384,12 @@
}
@Override
+ public String encodeBookmarkableURL(String baseUrl, Map<String,List<String>> parameters)
+ {
+ return _httpServletResponse.encodeURL(encodeURL(baseUrl, parameters));
+ }
+
+ @Override
public String encodeResourceURL(final String url)
{
checkNull(url, "url");
@@ -385,6 +404,19 @@
}
@Override
+ public String encodePartialActionURL(String url)
+ {
+ // TODO: IMPLEMENT HERE
+ return null;
+ }
+
+ @Override
+ public String encodeRedirectURL(String baseUrl, Map<String,List<String>> parameters)
+ {
+ return _httpServletResponse.encodeRedirectURL(encodeURL(baseUrl, parameters));
+ }
+
+ @Override
public void dispatch(final String requestURI) throws IOException, FacesException
{
RequestDispatcher requestDispatcher = _servletRequest.getRequestDispatcher(requestURI);
@@ -468,13 +500,13 @@
public void invalidateSession()
{
HttpSession session = (HttpSession) getSession(false);
-
+
if (session != null)
{
session.invalidate();
}
}
-
+
/**
* @since 2.0
*/
@@ -512,15 +544,15 @@
throw new IllegalArgumentException("Only HttpServletResponse supported");
}
}
-
+
/**
* @since 2.0
*/
@Override
public void responseFlushBuffer() throws IOException
{
- checkHttpServletResponse();
- _httpServletResponse.flushBuffer();
+ checkHttpServletResponse();
+ _httpServletResponse.flushBuffer();
}
/**
@@ -529,8 +561,8 @@
@Override
public void responseReset()
{
- checkHttpServletResponse();
- _httpServletResponse.reset();
+ checkHttpServletResponse();
+ _httpServletResponse.reset();
}
/**
@@ -539,8 +571,15 @@
@Override
public void responseSendError(int statusCode, String message) throws IOException
{
- checkHttpServletResponse();
- _httpServletResponse.sendError(statusCode, message);
+ checkHttpServletResponse();
+ if (message == null)
+ {
+ _httpServletResponse.sendError(statusCode);
+ }
+ else
+ {
+ _httpServletResponse.sendError(statusCode, message);
+ }
}
@Override
@@ -610,7 +649,7 @@
{
this._servletResponse = (ServletResponse) response;
}
-
+
/**
* @since 2.0
*/
@@ -630,7 +669,7 @@
{
this._servletResponse.setCharacterEncoding(encoding);
}
-
+
/**
* @since 2.0
*/
@@ -641,7 +680,6 @@
_httpServletResponse.setContentLength(length);
}
-
@Override
public void setResponseContentType(String contentType)
{
@@ -651,8 +689,13 @@
// Sets the content type of the response being sent to the client
_servletResponse.setContentType(contentType);
}
- }
-
+ else
+ {
+ // I did not throw an exception just to be sure nothing breaks.
+ log.error("Cannot set content type. Response already committed");
+ }
+ }
+
/**
* @since 2.0
*/
@@ -663,6 +706,13 @@
_httpServletResponse.setHeader(name, value);
}
+ @Override
+ public void setResponseStatus(int statusCode)
+ {
+ checkHttpServletResponse();
+ _httpServletResponse.setStatus(statusCode);
+ }
+
private void checkNull(final Object o, final String param)
{
if (o == null)
@@ -683,14 +733,14 @@
{
return servletRequest instanceof HttpServletRequest;
}
-
+
private void checkHttpServletResponse()
{
if (_httpServletRequest == null)
{
throw new UnsupportedOperationException("Only HttpServletResponse supported");
}
- }
+ }
private boolean isHttpServletResponse(final ServletResponse servletResponse)
{
return servletResponse instanceof HttpServletResponse;
@@ -704,7 +754,7 @@
final String value, final Map<String, Object> properties)
{
checkHttpServletResponse();
- Cookie cookie = new Cookie(name,value);
+ Cookie cookie = new Cookie(name, value);
if (properties != null)
{
for (Map.Entry<String, Object> entry : properties.entrySet())
@@ -743,17 +793,106 @@
}
@Override
+ public void addResponseHeader(String name, String value)
+ {
+ _httpServletResponse.addHeader(name, value);
+ }
+
+ @Override
public String getContextName() {
return _servletContext.getServletContextName();
}
- /**
- * @since 2.0
- */
- @Override
- public void setResponseStatus(int statusCode)
+
+ private String encodeURL(String baseUrl, Map<String, List<String>> parameters)
{
- checkHttpServletResponse();
- _httpServletResponse.setStatus(statusCode);
+ checkNull(baseUrl, "url");
+ checkHttpServletRequest();
+
+ String fragment = null;
+ String queryString = null;
+ Map<String, List<String>> paramMap = new HashMap<String, List<String>>();
+
+ //extract any URL fragment
+ int index = baseUrl.indexOf(URL_FRAGMENT_SEPERATOR);
+ if (index != -1)
+ {
+ fragment = baseUrl.substring(index+1);
+ baseUrl = baseUrl.substring(0,index);
+ }
+
+ //extract the current query string and add the params to the paramMap
+ index = baseUrl.indexOf(URL_QUERY_SEPERATOR);
+ if (index != -1)
+ {
+ queryString = baseUrl.substring(index + 1);
+ baseUrl = baseUrl.substring(0, index);
+ String[] nameValuePairs = queryString.split(URL_PARAM_SEPERATOR);
+ for (int i = 0; i < nameValuePairs.length; i++)
+ {
+ String[] currentPair = nameValuePairs[i].split(URL_NAME_VALUE_PAIR_SEPERATOR);
+ if (currentPair[1] != null)
+ {
+ ArrayList<String> value = new ArrayList<String>(1);
+ value.add(currentPair[1]);
+ paramMap.put(currentPair[0], value);
+ }
+ }
+ }
+
+ //add/update with new params on the paramMap
+ if (parameters != null && parameters.size() > 0)
+ {
+ for (Map.Entry<String, List<String>> pair : parameters.entrySet())
+ {
+ if (pair.getKey() != null && pair.getKey().trim().length() != 0)
+ {
+ paramMap.put(pair.getKey(), pair.getValue());
+ }
+ }
+ }
+
+ // start building the new URL
+ StringBuilder newUrl = new StringBuilder();
+
+ //now add the updated param list onto the url
+ if (paramMap.size()>0)
+ {
+ boolean isFirstPair = true;
+ for (Map.Entry<String, List<String>> pair : paramMap.entrySet())
+ {
+ for (String value : pair.getValue())
+ {
+ if (!isFirstPair)
+ {
+ newUrl.append(URL_PARAM_SEPERATOR);
+ }
+ else
+ {
+ newUrl.append(URL_QUERY_SEPERATOR);
+ isFirstPair = false;
+ }
+
+ newUrl.append(pair.getKey());
+ newUrl.append(URL_NAME_VALUE_PAIR_SEPERATOR);
+ try
+ {
+ newUrl.append(URLEncoder.encode(value,getResponseCharacterEncoding()));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ //shouldn't ever get here
+ throw new UnsupportedOperationException("Encoding type=" + getResponseCharacterEncoding() + " not supported", e);
+ }
+ }
+ }
+ }
+
+ //add the fragment back on (if any)
+ if (fragment != null)
+ {
+ newUrl.append(URL_FRAGMENT_SEPERATOR + fragment);
+ }
+
+ return newUrl.toString();
}
-
}