Author: taylor
Date: Fri Jun 15 15:02:33 2007
New Revision: 547809
URL: http://svn.apache.org/viewvc?view=rev&rev=547809
Log:
https://issues.apache.org/jira/browse/PB-67
https://issues.apache.org/jira/browse/PB-68
patch from Thomas Spiegl
thanks MyFaces team!
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletCookieMap.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletExternalContextImpl.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletFacesContextImpl.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderMap.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderValuesMap.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestMap.java
Modified:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesContextFactoryImpl.java
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/PortletUIViewRoot.java
Modified:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesContextFactoryImpl.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesContextFactoryImpl.java?view=diff&rev=547809&r1=547808&r2=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesContextFactoryImpl.java
(original)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesContextFactoryImpl.java
Fri Jun 15 15:02:33 2007
@@ -23,12 +23,15 @@
import javax.portlet.PortletContext;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
/**
* <p>
* Loads the [EMAIL PROTECTED] PortletFacesContextImpl}
* </p>
- *
+ *
* @author <a href="[EMAIL PROTECTED]">David Le Strat </a>
*/
public class FacesContextFactoryImpl extends FacesContextFactory
@@ -37,16 +40,22 @@
* @see
javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
* java.lang.Object, java.lang.Object,
javax.faces.lifecycle.Lifecycle)
*/
- public FacesContext getFacesContext(Object context, Object request, Object
response, Lifecycle lifecycle)
+ public FacesContext getFacesContext(Object context, Object request, Object
response, Lifecycle lifecycle)
throws FacesException
- {
+ {
if (context instanceof PortletContext)
{
- PortletFacesContextImpl facesContext = new
PortletFacesContextImpl(
- (PortletContext) context,
+ return new PortletFacesContextImpl(
+ (PortletContext) context,
(PortletRequest) request,
(PortletResponse) response);
- return facesContext;
+ }
+ else if (context instanceof ServletContext)
+ {
+ return new ServletFacesContextImpl(
+ (ServletContext) context,
+ (ServletRequest) request,
+ (ServletResponse) response);
}
else
{
Modified:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/PortletUIViewRoot.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/PortletUIViewRoot.java?view=diff&rev=547809&r1=547808&r2=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/PortletUIViewRoot.java
(original)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/PortletUIViewRoot.java
Fri Jun 15 15:02:33 2007
@@ -19,6 +19,7 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import javax.portlet.RenderResponse;
/**
* A portlet view root that implements a naming container to creates unique
@@ -27,37 +28,58 @@
*/
public class PortletUIViewRoot extends UIViewRoot implements NamingContainer
{
- /** A portlet view id constant to prepend to the namespace. */
- public static final String VIEW_PREFIX = "view";
-
- /** The default constructor calls the UIViewRoot default constructor. */
- public PortletUIViewRoot()
- {
- super();
- }
-
- /**
- * The convenience constructor creates a PortletUIViewRoot from a UIViewRoot.
- * @param viewRoot The UIViewRoot to use when creating this object.
- */
- public PortletUIViewRoot( UIViewRoot viewRoot )
- {
- setLocale( viewRoot.getLocale() );
- setRenderKitId( viewRoot.getRenderKitId() );
- setViewId( viewRoot.getViewId() );
- }
-
- /**
- * Return a string which can be used as output to the response which
uniquely
- * identifies a component within the current view.
- * @param context The FacesContext object for the current request.
- */
- public String getClientId( FacesContext context )
- {
- if ( context == null )
- throw new NullPointerException( "context can not be null." );
-
- String nameSpace = context.getExternalContext().encodeNamespace( "" );
- return VIEW_PREFIX + nameSpace;
- }
+ /** A portlet view id constant to prepend to the namespace. */
+ public static final String VIEW_PREFIX = "view";
+
+ private String _namespace;
+
+ /** The default constructor calls the UIViewRoot default constructor. */
+ public PortletUIViewRoot()
+ {
+ super();
+ }
+
+ /**
+ * The convenience constructor creates a PortletUIViewRoot from a
UIViewRoot.
+ * @param viewRoot The UIViewRoot to use when creating this object.
+ */
+ public PortletUIViewRoot( UIViewRoot viewRoot )
+ {
+ setLocale( viewRoot.getLocale() );
+ setRenderKitId( viewRoot.getRenderKitId() );
+ setViewId( viewRoot.getViewId() );
+ }
+
+ /**
+ * Return a string which can be used as output to the response which
uniquely
+ * identifies a component within the current view.
+ * @param context The FacesContext object for the current request.
+ */
+ public String getClientId( FacesContext context )
+ {
+ if ( context == null )
+ throw new NullPointerException( "context can not be null." );
+
+ if (_namespace == null && context.getExternalContext().getResponse()
instanceof RenderResponse) {
+ String nameSpace = context.getExternalContext().encodeNamespace(
"" );
+ _namespace = VIEW_PREFIX + nameSpace;
+ }
+ return _namespace;
+ }
+
+
+ public Object saveState(FacesContext context) {
+ Object values[] = new Object[2];
+ values[0] = super.saveState(context);
+ values[1] = _namespace;
+ return values;
+ }
+
+
+ public void restoreState(FacesContext context, Object state) {
+ Object values[] = (Object[])state;
+ super.restoreState(context, values[0]);
+ _namespace = (String) values[1];
+ }
}
+
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletCookieMap.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletCookieMap.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletCookieMap.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletCookieMap.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.jsf;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+import java.util.Map;
+
+/**
+ * @author Apache MyFaces team
+ */
+public class ServletCookieMap extends AbstractAttributeMap
+{
+ private static final Cookie[] EMPTY_ARRAY = new Cookie[0];
+
+ final HttpServletRequest _httpServletRequest;
+
+ ServletCookieMap(HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException(
+ "Cannot clear HttpRequest Cookies");
+ }
+
+ public boolean containsKey(Object key)
+ {
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null) return false;
+ for (int i = 0, len = cookies.length; i < len; i++)
+ {
+ if (cookies[i].getName().equals(key))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean containsValue(Object findValue)
+ {
+ if (findValue == null)
+ {
+ return false;
+ }
+
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null) return false;
+ for (int i = 0, len = cookies.length; i < len; i++)
+ {
+ if (findValue.equals(cookies[i]))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean isEmpty()
+ {
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ return cookies == null || cookies.length == 0;
+ }
+
+ public int size()
+ {
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ return cookies == null ? 0 : cookies.length;
+ }
+
+ public void putAll(Map t)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ protected Object getAttribute(String key)
+ {
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null) return null;
+ for (int i = 0, len = cookies.length; i < len; i++)
+ {
+ if (cookies[i].getName().equals(key))
+ {
+ return cookies[i];
+ }
+ }
+
+ return null;
+ }
+
+ protected void setAttribute(String key, Object value)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot set HttpRequest Cookies");
+ }
+
+ protected void removeAttribute(String key)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot remove HttpRequest Cookies");
+ }
+
+ protected Enumeration getAttributeNames()
+ {
+ Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null)
+ {
+ return new CookieNameEnumeration(EMPTY_ARRAY);
+ }
+ else
+ {
+ return new CookieNameEnumeration(cookies);
+ }
+ }
+
+ private static class CookieNameEnumeration implements Enumeration {
+ private final Cookie[] _cookies;
+ private final int _length;
+ private int _index;
+
+ public CookieNameEnumeration(Cookie[] cookies)
+ {
+ _cookies = cookies;
+ _length = cookies.length;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return _index < _length;
+ }
+
+ public Object nextElement()
+ {
+ return _cookies[_index++].getName();
+ }
+ }
+}
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletExternalContextImpl.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletExternalContextImpl.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletExternalContextImpl.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletExternalContextImpl.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,510 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.jsf;
+
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.*;
+import java.lang.reflect.Method;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * @author Apache MyFaces team
+ */
+public class ServletExternalContextImpl
+ extends ExternalContext
+{
+
+ private static final Log log =
LogFactory.getLog(ServletExternalContextImpl.class);
+
+ private static final String INIT_PARAMETER_MAP_ATTRIBUTE =
InitParameterMap.class.getName();
+
+ private ServletContext _servletContext;
+ private ServletRequest _servletRequest;
+ private ServletResponse _servletResponse;
+ private Map _applicationMap;
+ private Map _sessionMap;
+ private Map _requestMap;
+ private Map _requestParameterMap;
+ private Map _requestParameterValuesMap;
+ private Map _requestHeaderMap;
+ private Map _requestHeaderValuesMap;
+ private Map _requestCookieMap;
+ private Map _initParameterMap;
+ private boolean _isHttpServletRequest;
+ private String _requestServletPath;
+ private String _requestPathInfo;
+ private static Method setCharacterEncodingMethod = null;
+
+ static {
+ try {
+ setCharacterEncodingMethod =
ServletRequest.class.getMethod("setCharacterEncoding", new
Class[]{String.class});
+ } catch (Exception e) {
+ log.warn("Detecting request character encoding is
disable.");
+ log.warn("Failed to obtain
ServletRequest#setCharacterEncoding() method: " + e);
+ }
+ }
+
+ public ServletExternalContextImpl(ServletContext servletContext,
+ ServletRequest servletRequest,
+ ServletResponse servletResponse)
+ {
+ _servletContext = servletContext;
+ _servletRequest = servletRequest;
+ _servletResponse = servletResponse;
+ _applicationMap = null;
+ _sessionMap = null;
+ _requestMap = null;
+ _requestParameterMap = null;
+ _requestParameterValuesMap = null;
+ _requestHeaderMap = null;
+ _requestHeaderValuesMap = null;
+ _requestCookieMap = null;
+ _initParameterMap = null;
+ _isHttpServletRequest = (servletRequest != null &&
+ servletRequest instanceof HttpServletRequest);
+ if (_isHttpServletRequest)
+ {
+ //HACK: MultipartWrapper scrambles the servletPath for some reason
in Tomcat 4.1.29 embedded in JBoss 3.2.3!?
+ // (this was reported by frederic.auge [EMAIL PROTECTED])
+ HttpServletRequest httpServletRequest =
(HttpServletRequest)servletRequest;
+
+ _requestServletPath = httpServletRequest.getServletPath();
+ _requestPathInfo = httpServletRequest.getPathInfo();
+
+ // try to set character encoding as described in section 2.5.2.2
of JSF 1.1 spec
+ // we have to use reflection as method setCharacterEncoding is not
supported Servlet API <= 2.3
+ try
+ {
+ if (setCharacterEncodingMethod != null) {
+ String contentType =
httpServletRequest.getHeader("Content-Type");
+
+ String characterEncoding =
lookupCharacterEncoding(contentType);
+
+ if (characterEncoding == null) {
+ HttpSession session =
httpServletRequest.getSession(false);
+
+ if (session != null) {
+ characterEncoding = (String)
session.getAttribute(ViewHandler.CHARACTER_ENCODING_KEY);
+ }
+
+ if (characterEncoding != null) {
+ setCharacterEncodingMethod.invoke(servletRequest,
new Object[]{characterEncoding});
+ }
+ }
+ }
+ } catch (Exception e)
+ {
+ if (log.isWarnEnabled())
+ log.warn("Failed to set character encoding " + e);
+ }
+ }
+ }
+
+
+ private String lookupCharacterEncoding(String contentType)
+ {
+ String characterEncoding = null;
+
+ if (contentType != null)
+ {
+ int charsetFind = contentType.indexOf("charset=");
+ if (charsetFind != -1)
+ {
+ if (charsetFind == 0)
+ {
+ //charset at beginning of Content-Type, curious
+ characterEncoding = contentType.substring(8);
+ }
+ else
+ {
+ char charBefore = contentType.charAt(charsetFind - 1);
+ if (charBefore == ';' ||
Character.isWhitespace(charBefore))
+ {
+ //Correct charset after mime type
+ characterEncoding = contentType.substring(charsetFind
+ 8);
+ }
+ }
+ if (log.isDebugEnabled()) log.debug("Incoming request has
Content-Type header with character encoding " + characterEncoding);
+ }
+ else
+ {
+ if (log.isDebugEnabled()) log.debug("Incoming request has
Content-Type header without character encoding: " + contentType);
+ }
+ }
+ return characterEncoding;
+ }
+
+
+ public void release()
+ {
+ _servletContext = null;
+ _servletRequest = null;
+ _servletResponse = null;
+ _applicationMap = null;
+ _sessionMap = null;
+ _requestMap = null;
+ _requestParameterMap = null;
+ _requestParameterValuesMap = null;
+ _requestHeaderMap = null;
+ _requestHeaderValuesMap = null;
+ _requestCookieMap = null;
+ _initParameterMap = null;
+ }
+
+
+ public Object getSession(boolean create)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).getSession(create);
+ }
+
+ public Object getContext()
+ {
+ return _servletContext;
+ }
+
+ public Object getRequest()
+ {
+ return _servletRequest;
+ }
+
+ public Object getResponse()
+ {
+ return _servletResponse;
+ }
+
+ public void setResponse(Object response) {
+ if (response instanceof ServletResponse) {
+ this._servletResponse = (ServletResponse) response;
+ }
+ }
+
+ public Map getApplicationMap()
+ {
+ if (_applicationMap == null)
+ {
+ _applicationMap = new ApplicationMap(_servletContext);
+ }
+ return _applicationMap;
+ }
+
+ public Map getSessionMap()
+ {
+ if (_sessionMap == null)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ _sessionMap = new SessionMap((HttpServletRequest) _servletRequest);
+ }
+ return _sessionMap;
+ }
+
+ public Map getRequestMap()
+ {
+ if (_requestMap == null)
+ {
+ _requestMap = new ServletRequestMap(_servletRequest);
+ }
+ return _requestMap;
+ }
+
+ public Map getRequestParameterMap()
+ {
+ if (_requestParameterMap == null)
+ {
+ _requestParameterMap = new RequestParameterMap(_servletRequest);
+ }
+ return _requestParameterMap;
+ }
+
+ public Map getRequestParameterValuesMap()
+ {
+ if (_requestParameterValuesMap == null)
+ {
+ _requestParameterValuesMap = new
RequestParameterValuesMap(_servletRequest);
+ }
+ return _requestParameterValuesMap;
+ }
+
+ public Iterator getRequestParameterNames()
+ {
+ final Enumeration enumer = _servletRequest.getParameterNames();
+ Iterator it = new Iterator()
+ {
+ public boolean hasNext() {
+ return enumer.hasMoreElements();
+ }
+
+ public Object next() {
+ return enumer.nextElement();
+ }
+
+ public void remove() {
+ throw new
UnsupportedOperationException(this.getClass().getName() + "
UnsupportedOperationException");
+ }
+ };
+ return it;
+ }
+
+ public Map getRequestHeaderMap()
+ {
+ if (_requestHeaderMap == null)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ _requestHeaderMap = new
ServletRequestHeaderMap((HttpServletRequest)_servletRequest);
+ }
+ return _requestHeaderMap;
+ }
+
+ public Map getRequestHeaderValuesMap()
+ {
+ if (_requestHeaderValuesMap == null)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ _requestHeaderValuesMap = new
ServletRequestHeaderValuesMap((HttpServletRequest)_servletRequest);
+ }
+ return _requestHeaderValuesMap;
+ }
+
+ public Map getRequestCookieMap()
+ {
+ if (_requestCookieMap == null)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ _requestCookieMap = new
ServletCookieMap((HttpServletRequest)_servletRequest);
+ }
+ return _requestCookieMap;
+ }
+
+ public Locale getRequestLocale()
+ {
+ return _servletRequest.getLocale();
+ }
+
+ public String getRequestPathInfo()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ //return ((HttpServletRequest)_servletRequest).getPathInfo();
+ //HACK: see constructor
+ return _requestPathInfo;
+ }
+
+ public String getRequestContextPath()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).getContextPath();
+ }
+
+ public String getInitParameter(String s)
+ {
+ return _servletContext.getInitParameter(s);
+ }
+
+ public Map getInitParameterMap()
+ {
+ if (_initParameterMap == null)
+ {
+ // We cache it as an attribute in ServletContext itself (is this
circular reference a problem?)
+ if ((_initParameterMap = (Map)
_servletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE)) == null)
+ {
+ _initParameterMap = new InitParameterMap(_servletContext);
+ _servletContext.setAttribute(INIT_PARAMETER_MAP_ATTRIBUTE,
_initParameterMap);
+ }
+ }
+ return _initParameterMap;
+ }
+
+ public Set getResourcePaths(String s)
+ {
+ return _servletContext.getResourcePaths(s);
+ }
+
+ public InputStream getResourceAsStream(String s)
+ {
+ return _servletContext.getResourceAsStream(s);
+ }
+
+ public String encodeActionURL(String s)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletResponse)_servletResponse).encodeURL(s);
+ }
+
+ public String encodeResourceURL(String s)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletResponse)_servletResponse).encodeURL(s);
+ }
+
+ public String encodeNamespace(String s)
+ {
+ return s;
+ }
+
+ public void dispatch(String requestURI) throws IOException, FacesException
+ {
+ RequestDispatcher requestDispatcher
+ = _servletRequest.getRequestDispatcher(requestURI);
+
+ // If there is no dispatcher, send NOT_FOUND
+ if (requestDispatcher == null)
+ {
+ ((HttpServletResponse)_servletResponse).sendError(
+ HttpServletResponse.SC_NOT_FOUND);
+
+ return;
+ }
+
+ try
+ {
+ requestDispatcher.forward(_servletRequest, _servletResponse);
+ }
+ catch (ServletException e)
+ {
+ if (e.getMessage() != null)
+ {
+ throw new FacesException(e.getMessage(), e);
+ }
+ else
+ {
+ throw new FacesException(e);
+ }
+ }
+ }
+
+ public String getRequestServletPath()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ //return ((HttpServletRequest)_servletRequest).getServletPath();
+ //HACK: see constructor
+ return _requestServletPath;
+ }
+
+ public String getAuthType()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).getAuthType();
+ }
+
+ public String getRemoteUser()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).getRemoteUser();
+ }
+
+ public boolean isUserInRole(String role)
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).isUserInRole(role);
+ }
+
+ public Principal getUserPrincipal()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return ((HttpServletRequest)_servletRequest).getUserPrincipal();
+ }
+
+ public void log(String message) {
+ _servletContext.log(message);
+ }
+
+ public void log(String message, Throwable t) {
+ _servletContext.log(message, t);
+ }
+
+ public void redirect(String url) throws IOException
+ {
+ if (_servletResponse instanceof HttpServletResponse)
+ {
+ ((HttpServletResponse)_servletResponse).sendRedirect(url);
+ FacesContext.getCurrentInstance().responseComplete();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only HttpServletResponse
supported");
+ }
+ }
+
+ public Iterator getRequestLocales()
+ {
+ if (!_isHttpServletRequest)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest
supported");
+ }
+ return new
EnumerationIterator(((HttpServletRequest)_servletRequest).getLocales());
+ }
+
+ public URL getResource(String s) throws MalformedURLException
+ {
+ return _servletContext.getResource(s);
+ }
+}
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletFacesContextImpl.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletFacesContextImpl.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletFacesContextImpl.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletFacesContextImpl.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,324 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.jsf;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.util.*;
+
+/**
+ * @author Apache MyFaces team
+ */
+public class ServletFacesContextImpl
+ extends FacesContext {
+ //~ Instance fields
----------------------------------------------------------------------------
+
+ private List _messageClientIds = null;
+ private List _messages = null;
+ private Application _application;
+ private ServletExternalContextImpl _externalContext;
+ private ResponseStream _responseStream = null;
+ private ResponseWriter _responseWriter = null;
+ private FacesMessage.Severity _maximumSeverity = null;
+ private UIViewRoot _viewRoot;
+ private boolean _renderResponse = false;
+ private boolean _responseComplete = false;
+ private RenderKitFactory _renderKitFactory;
+ private boolean _released = false;
+
+ //~ Constructors
-------------------------------------------------------------------------------
+
+ public ServletFacesContextImpl(ServletContext servletContext,
+ ServletRequest servletRequest,
+ ServletResponse servletResponse)
+ {
+ this(new ServletExternalContextImpl(servletContext,
+ servletRequest,
+ servletResponse));
+ }
+
+ private ServletFacesContextImpl(ServletExternalContextImpl externalContext)
+ {
+ _application =
((ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY))
+ .getApplication();
+ _renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ _externalContext = externalContext;
+ FacesContext.setCurrentInstance(this); //protected method, therefore
must be called from here
+ }
+
+ //~ Methods
------------------------------------------------------------------------------------
+
+ public ExternalContext getExternalContext()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return (ExternalContext)_externalContext;
+ }
+
+ public FacesMessage.Severity getMaximumSeverity()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _maximumSeverity;
+ }
+
+ public Iterator getMessages()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return (_messages != null) ? _messages.iterator() :
Collections.EMPTY_LIST.iterator();
+ }
+
+ public Application getApplication()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _application;
+ }
+
+ public Iterator getClientIdsWithMessages()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (_messages == null || _messages.isEmpty())
+ {
+ return NullIterator.instance();
+ }
+
+ final Set uniqueClientIds = new LinkedHashSet(_messageClientIds);
+ return uniqueClientIds.iterator();
+ }
+
+ public Iterator getMessages(String clientId)
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (_messages == null)
+ {
+ return NullIterator.instance();
+ }
+
+ List lst = new ArrayList();
+ for (int i = 0; i < _messages.size(); i++)
+ {
+ Object savedClientId = _messageClientIds.get(i);
+ if (clientId == null)
+ {
+ if (savedClientId == null) lst.add(_messages.get(i));
+ }
+ else
+ {
+ if (clientId.equals(savedClientId)) lst.add(_messages.get(i));
+ }
+ }
+ return lst.iterator();
+ }
+
+ public RenderKit getRenderKit()
+ {
+ if (getViewRoot() == null)
+ {
+ return null;
+ }
+
+ String renderKitId = getViewRoot().getRenderKitId();
+
+ if (renderKitId == null)
+ {
+ return null;
+ }
+
+ return _renderKitFactory.getRenderKit(this, renderKitId);
+ }
+
+ public boolean getRenderResponse()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _renderResponse;
+ }
+
+ public boolean getResponseComplete()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseComplete;
+ }
+
+ public void setResponseStream(ResponseStream responseStream)
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (responseStream == null)
+ {
+ throw new NullPointerException("responseStream");
+ }
+ _responseStream = responseStream;
+ }
+
+ public ResponseStream getResponseStream()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseStream;
+ }
+
+ public void setResponseWriter(ResponseWriter responseWriter)
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (responseWriter == null)
+ {
+ throw new NullPointerException("responseWriter");
+ }
+ _responseWriter = responseWriter;
+ }
+
+ public ResponseWriter getResponseWriter()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseWriter;
+ }
+
+ public void setViewRoot(UIViewRoot viewRoot)
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (viewRoot == null)
+ {
+ throw new NullPointerException("viewRoot");
+ }
+ _viewRoot = viewRoot;
+ }
+
+ public UIViewRoot getViewRoot()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _viewRoot;
+ }
+
+ public void addMessage(String clientId, FacesMessage message)
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (message == null)
+ {
+ throw new NullPointerException("message");
+ }
+
+ if (_messages == null)
+ {
+ _messages = new ArrayList();
+ _messageClientIds = new ArrayList();
+ }
+ _messages.add(message);
+ _messageClientIds.add((clientId != null) ? clientId : null);
+ FacesMessage.Severity serSeverity = message.getSeverity();
+ if (serSeverity != null) {
+ if (_maximumSeverity == null)
+ {
+ _maximumSeverity = serSeverity;
+ }
+ else if (serSeverity.compareTo(_maximumSeverity) > 0)
+ {
+ _maximumSeverity = serSeverity;
+ }
+ }
+ }
+
+ public boolean isReleased()
+ {
+ return _released;
+ }
+
+ public void release()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ if (_externalContext != null)
+ {
+ _externalContext.release();
+ _externalContext = null;
+ }
+
+ _messageClientIds = null;
+ _messages = null;
+ _application = null;
+ _responseStream = null;
+ _responseWriter = null;
+ _viewRoot = null;
+ _maximumSeverity = null;
+
+ _released = true;
+ FacesContext.setCurrentInstance(null);
+ }
+
+ public void renderResponse()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ _renderResponse = true;
+ }
+
+ public void responseComplete()
+ {
+ if (_released) {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ _responseComplete = true;
+ }
+
+ // Portlet need to do this to change from ActionRequest/Response to
+ // RenderRequest/Response
+ public void setExternalContext(ServletExternalContextImpl extContext)
+ {
+ _externalContext = extContext;
+ FacesContext.setCurrentInstance(this); //TODO: figure out if I really
need to do this
+ }
+}
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderMap.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderMap.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderMap.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderMap.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.jsf;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * <p>
+ * This must be the set of properties available via the
javax.portlet.PortletRequest methods getProperty()
+ * and getPropertyNames(). As such, HTTP headers will only be included if they
were provided by the portlet container,
+ * and additional properties provided by the portlet container may also be
included.
+ * @author Apache MyFaces team
+ */
+public class ServletRequestHeaderMap extends AbstractAttributeMap
+{
+ /** The portlet request. */
+ private final HttpServletRequest servletRequest;
+
+ /**
+ * @param portletRequest The [EMAIL PROTECTED]
javax.portlet.PortletRequest}.
+ */
+ ServletRequestHeaderMap(HttpServletRequest portletRequest)
+ {
+ this.servletRequest = portletRequest;
+ }
+
+ /**
+ * @see AbstractAttributeMap#getAttribute(String)
+ */
+ protected Object getAttribute(String key)
+ {
+ return servletRequest.getHeader(key);
+ }
+
+ /**
+ * @see AbstractAttributeMap#setAttribute(String, Object)
+ */
+ protected void setAttribute(String key, Object value)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot set PortletRequest Property");
+ }
+
+ /**
+ * @see AbstractAttributeMap#removeAttribute(String)
+ */
+ protected void removeAttribute(String key)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot remove PortletRequest Property");
+ }
+
+ /**
+ * @see AbstractAttributeMap#getAttributeNames()
+ */
+ protected Enumeration getAttributeNames()
+ {
+ return servletRequest.getHeaderNames();
+ }
+}
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderValuesMap.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderValuesMap.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderValuesMap.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestHeaderValuesMap.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.jsf;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * HttpServletRequest header values (multi-value headers) as Map of String[].
+ * @author Apache MyFaces team
+ */
+public class ServletRequestHeaderValuesMap extends AbstractAttributeMap
+{
+ private final HttpServletRequest _httpServletRequest;
+ private final Map _valueCache = new HashMap();
+
+ ServletRequestHeaderValuesMap(HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ protected Object getAttribute(String key)
+ {
+ Object ret = _valueCache.get(key);
+ if (ret == null)
+ {
+ _valueCache.put(key, ret = toArray(_httpServletRequest
+ .getHeaders(key)));
+ }
+
+ return ret;
+ }
+
+ protected void setAttribute(String key, Object value)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot set HttpServletRequest HeaderValues");
+ }
+
+ protected void removeAttribute(String key)
+ {
+ throw new UnsupportedOperationException(
+ "Cannot remove HttpServletRequest HeaderValues");
+ }
+
+ protected Enumeration getAttributeNames()
+ {
+ return _httpServletRequest.getHeaderNames();
+ }
+
+ private String[] toArray(Enumeration e)
+ {
+ List ret = new ArrayList();
+
+ while (e.hasMoreElements())
+ {
+ ret.add(e.nextElement());
+ }
+
+ return (String[]) ret.toArray(new String[ret.size()]);
+ }
+}
\ No newline at end of file
Added:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestMap.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestMap.java?view=auto&rev=547809
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestMap.java
(added)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/ServletRequestMap.java
Fri Jun 15 15:02:33 2007
@@ -0,0 +1,87 @@
+package org.apache.portals.bridges.jsf;
+
+import javax.servlet.ServletRequest;
+import java.util.Enumeration;
+
+/**
+ * <p>[EMAIL PROTECTED] javax.portlet.PortletRequest} attributes Map.</p>
+ * <p>
+ * See MyFaces project for servlet implementation.
+ * </p>
+ *
+ * @author <a href="[EMAIL PROTECTED]">Thomas Spiegl</a>
+ */
+public class ServletRequestMap extends AbstractAttributeMap
+{
+ /** Illegal argument exception message. */
+ final private static String ILLEGAL_ARGUMENT = "Only ServletREquest
supported";
+ /** The [EMAIL PROTECTED] javax.portlet.PortletContext}. */
+ private final ServletRequest servletRequest;
+
+ /**
+ * @param request The request.
+ */
+ public ServletRequestMap(Object request)
+ {
+ if (request instanceof ServletRequest)
+ {
+ this.servletRequest = (ServletRequest) request;
+ }
+ else
+ {
+ throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
+ }
+ }
+
+ /**
+ * @see AbstractAttributeMap#getAttribute(String)
+ */
+ public Object getAttribute(String key)
+ {
+ if (null != this.servletRequest)
+ {
+ return this.servletRequest.getAttribute(key);
+ }
+ else
+ {
+ throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
+ }
+ }
+
+ /**
+ * @see AbstractAttributeMap#setAttribute(String, Object)
+ */
+ public void setAttribute(String key, Object value)
+ {
+ if (null != this.servletRequest)
+ {
+ this.servletRequest.setAttribute(key, value);
+ }
+ }
+
+ /**
+ * @see AbstractAttributeMap#removeAttribute(String)
+ */
+ public void removeAttribute(String key)
+ {
+ if (null != this.servletRequest)
+ {
+ this.servletRequest.removeAttribute(key);
+ }
+ }
+
+ /**
+ * @see AbstractAttributeMap#getAttributeNames()
+ */
+ public Enumeration getAttributeNames()
+ {
+ if (null != this.servletRequest)
+ {
+ return this.servletRequest.getAttributeNames();
+ }
+ else
+ {
+ throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]