You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2006/12/05 02:02:55 UTC
svn commit: r482451 [2/5] - in
/incubator/adffaces/branches/jwaldman-portal/trinidad: trinidad-api/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/
trinidad-api/src/main/jav...
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletCookieMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletCookieMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletCookieMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletCookieMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * HttpServletRequest Cookies as Map.
+ *
+ * @author Dimitry D'hondt
+ * @author Anton Koinov
+ * @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
+ */
+public class ServletCookieMap extends AbstractAttributeMap<String, Object>
+{
+ public ServletCookieMap(final HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ @Override
+ public boolean containsKey(final Object key)
+ {
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null)
+ {
+ return false;
+ }
+ for (Cookie element : cookies)
+ {
+ if (element.getName().equals(key))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean containsValue(final Object findValue)
+ {
+ if (findValue == null)
+ {
+ return false;
+ }
+
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null)
+ {
+ return false;
+ }
+ for (Cookie element : cookies)
+ {
+ if (findValue.equals(element))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ return cookies == null || cookies.length == 0;
+ }
+
+ @Override
+ public int size()
+ {
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ return cookies == null ? 0 : cookies.length;
+ }
+
+ @Override
+ protected Object getAttribute(final Object key)
+ {
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null)
+ {
+ return null;
+ }
+ for (Cookie element : cookies)
+ {
+ if (element.getName().equals(key))
+ {
+ return element;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ final Cookie[] cookies = _httpServletRequest.getCookies();
+ if (cookies == null)
+ {
+ return new CookieNameEnumeration(EMPTY_ARRAY);
+ }
+ else
+ {
+ return new CookieNameEnumeration(cookies);
+ }
+ }
+
+ final HttpServletRequest _httpServletRequest;
+ private static final Cookie[] EMPTY_ARRAY = new Cookie[0];
+
+ private static class CookieNameEnumeration implements Enumeration<String>
+ {
+ public CookieNameEnumeration(final Cookie[] cookies)
+ {
+ _cookies = cookies;
+ _length = cookies.length;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return _index < _length;
+ }
+
+ public String nextElement()
+ {
+ return _cookies[_index++].getName();
+ }
+
+ private final Cookie[] _cookies;
+ private int _index;
+ private final int _length;
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletExternalContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletExternalContext.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletExternalContext.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletExternalContext.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,603 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+/**
+ * This class will implement the ExternalContext for use with Trinidad Configurations using the
+ * Trinidad {@link org.apache.myfaces.Trinidad.config.Configurator} object. <br>
+ * This code was origionally taken from MyFaces.
+ *
+ * @author Manfred Geiler (Origional MyFaces Code)
+ * @author Anton Koinov
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ServletExternalContext extends ExternalContext
+{
+ public ServletExternalContext(final ServletContext servletContext,
+ final ServletRequest servletRequest, final ServletResponse servletResponse)
+ {
+ assert servletContext != null;
+
+ _servletContext = servletContext;
+ _servletRequest = servletRequest;
+ _servletResponse = servletResponse;
+
+ if (servletRequest != null && servletRequest instanceof HttpServletRequest)
+ {
+ _httpServletRequest = (HttpServletRequest) servletRequest;
+ _httpServletResponse = (HttpServletResponse) servletResponse;
+ }
+
+ if (_httpServletRequest != null)
+ {
+ // 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 [frederic.auge@laposte.net])
+ _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)
+ {
+ final String contentType = _httpServletRequest.getHeader("Content-Type");
+
+ String characterEncoding = _lookupCharacterEncoding(contentType);
+
+ if (characterEncoding == null)
+ {
+ final 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 (final Exception e)
+ {
+ if (_LOG.isWarning())
+ {
+ _LOG.warning("Failed to set character encoding " + e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void dispatch(final String path) throws IOException, FacesException
+ {
+ _checkRequest();
+ final RequestDispatcher requestDispatcher = _servletRequest.getRequestDispatcher(path);
+
+ // If there is no dispatcher, send NOT_FOUND
+ if (requestDispatcher == null)
+ {
+ if (_httpServletResponse != null)
+ {
+ _httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+
+ return;
+ }
+
+ try
+ {
+ requestDispatcher.forward(_servletRequest, _servletResponse);
+ }
+ catch (final ServletException e)
+ {
+ if (e.getMessage() != null)
+ {
+ throw new FacesException(e.getMessage(), e);
+ }
+ else
+ {
+ throw new FacesException(e);
+ }
+ }
+ }
+
+ @Override
+ public String encodeActionURL(final String url)
+ {
+ _checkRequest();
+ _checkNull(url, "url");
+
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+
+ return _httpServletResponse.encodeURL(url);
+ }
+
+ @Override
+ public String encodeNamespace(final String s)
+ {
+ _checkRequest();
+ return s;
+ }
+
+ @Override
+ public String encodeResourceURL(final String s)
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletResponse.encodeURL(s);
+ }
+
+ @Override
+ public Map<String, Object> getApplicationMap()
+ {
+ if (_applicationMap == null)
+ {
+ _applicationMap = new ServletApplicationMap(_servletContext);
+ }
+ return _applicationMap;
+ }
+
+ @Override
+ public String getAuthType()
+ {
+ _checkRequest();
+
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.getAuthType();
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return _servletContext;
+ }
+
+ @Override
+ public String getInitParameter(final String s)
+ {
+ return _servletContext.getInitParameter(s);
+ }
+
+ @Override
+ 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 ServletInitParameterMap(_servletContext);
+ _servletContext.setAttribute(_INIT_PARAMETER_MAP_ATTRIBUTE, _initParameterMap);
+ }
+ }
+ return _initParameterMap;
+ }
+
+ @Override
+ public String getRemoteUser()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.getRemoteUser();
+ }
+
+ @Override
+ public Object getRequest()
+ {
+ return _servletRequest;
+ }
+
+ @Override
+ public String getRequestContextPath()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.getContextPath();
+ }
+
+ @Override
+ public Map<String, Object> getRequestCookieMap()
+ {
+ _checkRequest();
+ if (_requestCookieMap == null)
+ {
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ _requestCookieMap = new ServletCookieMap(_httpServletRequest);
+ }
+ return _requestCookieMap;
+ }
+
+ @Override
+ public Map<String, String> getRequestHeaderMap()
+ {
+ _checkRequest();
+ if (_requestHeaderMap == null)
+ {
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ _requestHeaderMap = new ServletRequestHeaderMap(_httpServletRequest);
+ }
+ return _requestHeaderMap;
+ }
+
+ @Override
+ public Map<String, String[]> getRequestHeaderValuesMap()
+ {
+ _checkRequest();
+ if (_requestHeaderValuesMap == null)
+ {
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ _requestHeaderValuesMap = new ServletRequestHeaderValuesMap(_httpServletRequest);
+ }
+ return _requestHeaderValuesMap;
+ }
+
+ @Override
+ public Locale getRequestLocale()
+ {
+ _checkRequest();
+ return _servletRequest.getLocale();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Iterator<Locale> getRequestLocales()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return new EnumerationIterator<Locale>(_httpServletRequest.getLocales());
+ }
+
+ @Override
+ public Map<String, Object> getRequestMap()
+ {
+ _checkRequest();
+ if (_requestMap == null)
+ {
+ _requestMap = new ServletRequestMap(_servletRequest);
+ }
+ return _requestMap;
+ }
+
+ @Override
+ public Map<String, String> getRequestParameterMap()
+ {
+ _checkRequest();
+ if (_requestParameterMap == null)
+ {
+ _requestParameterMap = new ServletRequestParameterMap(_servletRequest);
+ }
+ return _requestParameterMap;
+ }
+
+ @Override
+ public Iterator<String> getRequestParameterNames()
+ {
+ _checkRequest();
+ @SuppressWarnings("unchecked")
+ final Iterator<String> it = new EnumerationIterator<String>(_servletRequest.getParameterNames());
+ return it;
+ }
+
+ @Override
+ public Map<String, String[]> getRequestParameterValuesMap()
+ {
+ _checkRequest();
+ if (_requestParameterValuesMap == null)
+ {
+ _requestParameterValuesMap = new ServletRequestParameterValuesMap(_servletRequest);
+ }
+ return _requestParameterValuesMap;
+ }
+
+ @Override
+ public String getRequestPathInfo()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _requestPathInfo;
+ }
+
+ @Override
+ public String getRequestServletPath()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ // return ((HttpServletRequest)_servletRequest).getServletPath();
+ // HACK: see constructor
+ return _requestServletPath;
+ }
+
+ @Override
+ public URL getResource(final String s) throws MalformedURLException
+ {
+ return _servletContext.getResource(s);
+ }
+
+ @Override
+ public InputStream getResourceAsStream(final String s)
+ {
+ return _servletContext.getResourceAsStream(s);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Set<String> getResourcePaths(final String s)
+ {
+ return _servletContext.getResourcePaths(s);
+ }
+
+ @Override
+ public Object getResponse()
+ {
+ return _servletResponse;
+ }
+
+ @Override
+ public Object getSession(final boolean create)
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.getSession(create);
+ }
+
+ @Override
+ public Map<String, Object> getSessionMap()
+ {
+ _checkRequest();
+ if (_sessionMap == null)
+ {
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ _sessionMap = new ServletSessionMap(_httpServletRequest);
+ }
+ return _sessionMap;
+ }
+
+ @Override
+ public Principal getUserPrincipal()
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.getUserPrincipal();
+ }
+
+ @Override
+ public boolean isUserInRole(final String role)
+ {
+ _checkRequest();
+ if (_httpServletRequest == null)
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+ return _httpServletRequest.isUserInRole(role);
+ }
+
+ @Override
+ public void log(final String message)
+ {
+ _servletContext.log(message);
+ }
+
+ @Override
+ public void log(final String message, final Throwable t)
+ {
+ _servletContext.log(message, t);
+ }
+
+ @Override
+ public void redirect(final String url) throws IOException
+ {
+ _checkRequest();
+ if (_servletRequest == null)
+ {
+ throw new UnsupportedOperationException("No request object present on this context");
+ }
+
+ if (_servletResponse instanceof HttpServletResponse)
+ {
+ _httpServletResponse.sendRedirect(url);
+ FacesContext.getCurrentInstance().responseComplete();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only HttpServletResponse supported");
+ }
+ }
+
+ 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;
+ }
+
+ private void _checkNull(final Object o, final String param)
+ {
+ if (o == null)
+ {
+ throw new NullPointerException(param + " can not be null.");
+ }
+ }
+
+ private void _checkRequest()
+ {
+ if(_servletRequest == null)
+ {
+ throw new UnsupportedOperationException("Request and Response is null on this context.");
+ }
+ }
+
+ private String _lookupCharacterEncoding(final String contentType)
+ {
+ String characterEncoding = null;
+
+ if (contentType != null)
+ {
+ final int charsetFind = contentType.indexOf("charset=");
+ if (charsetFind != -1)
+ {
+ if (charsetFind == 0)
+ {
+ // charset at beginning of Content-Type, curious
+ characterEncoding = contentType.substring(8);
+ }
+ else
+ {
+ final char charBefore = contentType.charAt(charsetFind - 1);
+ if (charBefore == ';' || Character.isWhitespace(charBefore))
+ {
+ // Correct charset after mime type
+ characterEncoding = contentType.substring(charsetFind + 8);
+ }
+ }
+ if (_LOG.isFine())
+ {
+ _LOG.fine("Incoming request has Content-Type header with character encoding "
+ + characterEncoding);
+ }
+ }
+ else
+ {
+ if (_LOG.isFine())
+ {
+ _LOG.fine("Incoming request has Content-Type header without character encoding: "
+ + contentType);
+ }
+ }
+ }
+ return characterEncoding;
+ }
+
+ private Map<String, Object> _applicationMap;
+ private HttpServletRequest _httpServletRequest;
+ private HttpServletResponse _httpServletResponse;
+ private Map _initParameterMap;
+ private Map<String, Object> _requestCookieMap;
+ private Map<String, String> _requestHeaderMap;
+ private Map<String, String[]> _requestHeaderValuesMap;
+ private Map<String, Object> _requestMap;
+ private Map<String, String> _requestParameterMap;
+ private Map<String, String[]> _requestParameterValuesMap;
+ private String _requestPathInfo;
+ private String _requestServletPath;
+ private ServletContext _servletContext;
+ private ServletRequest _servletRequest;
+ private ServletResponse _servletResponse;
+ private Map<String, Object> _sessionMap;
+ private static final String _INIT_PARAMETER_MAP_ATTRIBUTE = ServletInitParameterMap.class
+ .getName();
+ private static final TrinidadLogger _LOG = TrinidadLogger
+ .createTrinidadLogger(ServletExternalContext.class);
+ private static Method _setCharacterEncodingMethod = null;
+ static
+ {
+ try
+ {
+ _setCharacterEncodingMethod = ServletRequest.class.getMethod("setCharacterEncoding",
+ new Class[] { String.class });
+ }
+ catch (final Exception e)
+ {
+ _LOG.warning("Detecting request character encoding is disable.");
+ _LOG.warning("Failed to obtain ServletRequest#setCharacterEncoding() method: " + e);
+ }
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletInitParameterMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletInitParameterMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletInitParameterMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletInitParameterMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletContext;
+
+
+/**
+ * ServletContext init parameters as Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: oros $)
+ * @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
+ */
+public class ServletInitParameterMap extends AbstractAttributeMap
+{
+ public ServletInitParameterMap(final ServletContext servletContext)
+ {
+ _servletContext = servletContext;
+ }
+
+ @Override
+ protected Object getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ return _servletContext.getInitParameter(key.toString());
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration getAttributeNames()
+ {
+ return _servletContext.getInitParameterNames();
+ }
+
+ final ServletContext _servletContext;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * HttpServletRequest headers as Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: oros $)
+ * @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
+ */
+public class ServletRequestHeaderMap extends AbstractAttributeMap<String, String>
+{
+ public ServletRequestHeaderMap(final HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ @Override
+ protected String getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ return _httpServletRequest.getHeader(key.toString());
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ final Enumeration<String> headerNames = _httpServletRequest.getHeaderNames();
+ return headerNames;
+ }
+
+ private final HttpServletRequest _httpServletRequest;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderValuesMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderValuesMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderValuesMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestHeaderValuesMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+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 Anton Koinov (latest modification by $Author: matze $)
+ * @version $Revision: 167257 $ $Date: 2004-10-13 05:51:02 -0600 (Wed, 13 Oct 2004) $
+ */
+public class ServletRequestHeaderValuesMap extends AbstractAttributeMap<String, String[]>
+{
+ public ServletRequestHeaderValuesMap(final HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ @Override
+ protected String[] getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ final String k = key.toString();
+ String[] ret = _valueCache.get(k);
+ if (ret == null)
+ {
+ @SuppressWarnings("unchecked")
+ final Enumeration<String> headers = _httpServletRequest.getHeaders(k);
+ ret = _toArray(headers);
+ _valueCache.put(k, ret);
+ }
+
+ return ret;
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> headerNames = _httpServletRequest.getHeaderNames();
+ return headerNames;
+ }
+
+ private String[] _toArray(final Enumeration<String> e)
+ {
+ final List<String> ret = new ArrayList<String>();
+
+ while (e.hasMoreElements())
+ {
+ ret.add(e.nextElement());
+ }
+
+ return ret.toArray(new String[ret.size()]);
+ }
+
+ private final HttpServletRequest _httpServletRequest;
+ private final Map<String, String[]> _valueCache = new HashMap<String, String[]>();
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+import javax.servlet.ServletRequest;
+
+
+/**
+ * ServletRequest attributes Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: oros $)
+ * @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
+ */
+public class ServletRequestMap extends ModifiableAbstractAttributeMap<String, Object>
+{
+ public ServletRequestMap(final ServletRequest servletRequest)
+ {
+ _servletRequest = servletRequest;
+ }
+
+ @Override
+ protected Object getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ return _servletRequest.getAttribute(key.toString());
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> attributeNames = _servletRequest.getAttributeNames();
+ return attributeNames;
+ }
+
+ @Override
+ protected void removeAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ _servletRequest.removeAttribute(key.toString());
+ }
+ }
+
+ @Override
+ protected void setAttribute(final String key, final Object value)
+ {
+ _servletRequest.setAttribute(key, value);
+ }
+
+ final ServletRequest _servletRequest;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletRequest;
+
+
+/**
+ * ServletRequest parameters as Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: matze $)
+ * @version $Revision: 167257 $ $Date: 2004-10-13 05:51:02 -0600 (Wed, 13 Oct 2004) $
+ */
+public class ServletRequestParameterMap extends AbstractAttributeMap<String, String>
+{
+ public ServletRequestParameterMap(final ServletRequest servletRequest)
+ {
+ _servletRequest = servletRequest;
+ }
+
+ @Override
+ protected String getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ return _servletRequest.getParameter(key.toString());
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> parameterNames = _servletRequest.getParameterNames();
+ return parameterNames;
+ }
+
+ private final ServletRequest _servletRequest;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterValuesMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterValuesMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterValuesMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletRequestParameterValuesMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletRequest;
+
+
+/**
+ * ServletRequest multi-value parameters as Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: matze $)
+ * @version $Revision: 167257 $ $Date: 2004-10-13 05:51:02 -0600 (Wed, 13 Oct 2004) $
+ */
+public class ServletRequestParameterValuesMap extends AbstractAttributeMap<String, String[]>
+{
+ public ServletRequestParameterValuesMap(final ServletRequest servletRequest)
+ {
+ _servletRequest = servletRequest;
+ }
+
+ @Override
+ protected String[] getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ return _servletRequest.getParameterValues(key.toString());
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> parameterNames = _servletRequest.getParameterNames();
+ return parameterNames;
+ }
+
+ private final ServletRequest _servletRequest;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletSessionMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletSessionMap.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletSessionMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/ServletSessionMap.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+
+import java.util.Enumeration;
+
+/**
+ * HttpSession attibutes as Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: schof $)
+ * @version $Revision: 382015 $ $Date: 2006-03-01 06:47:11 -0700 (Wed, 01 Mar 2006) $
+ */
+public class ServletSessionMap extends ModifiableAbstractAttributeMap<String, Object>
+{
+ public ServletSessionMap(final HttpServletRequest httpRequest)
+ {
+ _httpRequest = httpRequest;
+ }
+
+ @Override
+ protected Object getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ final HttpSession httpSession = _getSession();
+ return httpSession == null ? null : httpSession.getAttribute(key.toString());
+ }
+
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Enumeration getAttributeNames()
+ {
+ final HttpSession httpSession = _getSession();
+ return httpSession == null ? NullEnumeration.instance() : httpSession.getAttributeNames();
+ }
+
+ @Override
+ protected void removeAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ final HttpSession httpSession = _getSession();
+ if (httpSession != null)
+ {
+ httpSession.removeAttribute(key.toString());
+ }
+ }
+ }
+
+ @Override
+ protected void setAttribute(final String key, final Object value)
+ {
+ _httpRequest.getSession(true).setAttribute(key, value);
+ }
+
+ private HttpSession _getSession()
+ {
+ return _httpRequest.getSession(false);
+ }
+
+ private final HttpServletRequest _httpRequest;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/TrinidadFacesContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/TrinidadFacesContext.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/TrinidadFacesContext.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/TrinidadFacesContext.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,377 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.context.external;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+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;
+
+/**
+ * Provides an implementation for FacesContext for use in Trinidad.
+ * This will typically be used for items which exist outside of
+ * Faces such as resource servlets.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TrinidadFacesContext extends FacesContext
+{
+ /**
+ * Constructs a new TrinidadFacesContext with a provided ExternalContext implementation.
+ * This constructor is dependant upon the ApplicationFactory and RenderKitFactory being
+ * set up properly in the factoryFinder.
+ *
+ * @param ec the ExternalContext for this FacesContext
+ * @throws NullPointerException if ec is <code>null</code>
+ */
+ public TrinidadFacesContext(final ExternalContext ec)
+ {
+ if(ec == null)
+ {
+ throw new NullPointerException("ExternalContext is null");
+ }
+
+ _externalContext = ec;
+ _application = ((ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ _renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+
+ FacesContext.setCurrentInstance(this);
+ }
+
+ @Override
+ public void addMessage(final String component, final FacesMessage message)
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ if (message == null)
+ {
+ throw new NullPointerException("Message cannot be null.");
+ }
+
+ if (_messages == null)
+ {
+ _messages = new ArrayList<FacesMessage>();
+ _messageClientIds = new ArrayList<String>();
+ }
+
+ _messages.add(message);
+ _messageClientIds.add(component);
+
+ // handle maximum severity
+ final FacesMessage.Severity sev = message.getSeverity();
+ if (_maximumSeverity == null || sev.compareTo(_maximumSeverity) > 0)
+ {
+ _maximumSeverity = message.getSeverity();
+ }
+ }
+
+ @Override
+ public Application getApplication()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _application;
+ }
+
+ @Override
+ public Iterator<String> getClientIdsWithMessages()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _messageClientIds == null ? _NULL_STRING_ITERATOR : (new LinkedHashSet<String>(
+ _messageClientIds)).iterator();
+ }
+
+ @Override
+ public ExternalContext getExternalContext()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _externalContext;
+ }
+
+ @Override
+ public Severity getMaximumSeverity()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _maximumSeverity;
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return (_messages == null)?_NULL_FACES_MESSAGE_ITERATOR:_messages.iterator();
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages(final String clientId)
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ if (_messages == null)
+ {
+ return _NULL_FACES_MESSAGE_ITERATOR;
+ }
+
+ final List<FacesMessage> lst = new ArrayList<FacesMessage>();
+ final Iterator<FacesMessage> messageItr = _messages.iterator();
+ for (final String id : _messageClientIds)
+ {
+ final FacesMessage message = messageItr.next();
+ if (clientId == null)
+ {
+ if (id == null)
+ {
+ lst.add(message);
+ }
+ }
+ else
+ {
+ if (clientId.equals(id))
+ {
+ lst.add(message);
+ }
+ }
+ }
+
+ return lst.iterator();
+ }
+
+ @Override
+ public RenderKit getRenderKit()
+ {
+ if (getViewRoot() == null)
+ {
+ return null;
+ }
+
+ final String renderKitId = getViewRoot().getRenderKitId();
+
+ if (renderKitId == null)
+ {
+ return null;
+ }
+
+ return _renderKitFactory.getRenderKit(this, renderKitId);
+ }
+
+ @Override
+ public boolean getRenderResponse()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _renderResponse;
+ }
+
+ @Override
+ public boolean getResponseComplete()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseComplete;
+ }
+
+ @Override
+ public ResponseStream getResponseStream()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseStream;
+ }
+
+ @Override
+ public ResponseWriter getResponseWriter()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+ return _responseWriter;
+ }
+
+ @Override
+ public UIViewRoot getViewRoot()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ return _viewRoot;
+ }
+
+ @Override
+ public void release()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ _externalContext = null;
+ _application = null;
+ _renderKitFactory = null;
+ _messageClientIds = null;
+ _messages = null;
+ _maximumSeverity = null;
+ _responseStream = null;
+ _responseWriter = null;
+ _viewRoot = null;
+ _released = true;
+
+ FacesContext.setCurrentInstance(null);
+ }
+
+ @Override
+ public void renderResponse()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ _renderResponse = true;
+ }
+
+ @Override
+ public void responseComplete()
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ _responseComplete = true;
+
+ }
+
+ @Override
+ public void setResponseStream(final ResponseStream responseStream)
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ if (responseStream == null)
+ {
+ throw new NullPointerException("responseStream");
+ }
+
+ _responseStream = responseStream;
+ }
+
+ @Override
+ public void setResponseWriter(final ResponseWriter responseWriter)
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ if (responseWriter == null)
+ {
+ throw new NullPointerException("responseWriter");
+ }
+
+ _responseWriter = responseWriter;
+ }
+
+ @Override
+ public void setViewRoot(final UIViewRoot viewRoot)
+ {
+ if (_released)
+ {
+ throw new IllegalStateException("FacesContext already released");
+ }
+
+ _viewRoot = viewRoot;
+ }
+
+ private Application _application;
+ private ExternalContext _externalContext;
+ private FacesMessage.Severity _maximumSeverity;
+ private List<String> _messageClientIds;
+ private List<FacesMessage> _messages;
+ private RenderKitFactory _renderKitFactory;
+ private ResponseStream _responseStream;
+ private ResponseWriter _responseWriter;
+ private UIViewRoot _viewRoot;
+
+ private boolean _released = false;
+ private boolean _renderResponse = false;
+ private boolean _responseComplete = false;
+
+ static private final Iterator<FacesMessage> _NULL_FACES_MESSAGE_ITERATOR;
+ static private final Iterator<String> _NULL_STRING_ITERATOR;
+
+ static
+ {
+ final Set<String> strSet = Collections.emptySet();
+ final Set<FacesMessage> fmSet = Collections.emptySet();
+
+ _NULL_STRING_ITERATOR = strSet.iterator();
+ _NULL_FACES_MESSAGE_ITERATOR = fmSet.iterator();
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,173 @@
+package org.apache.myfaces.trinidad.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.faces.context.ExternalContext;
+import javax.portlet.ActionRequest;
+import javax.servlet.ServletRequest;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+/**
+ * This provides some functionality for determining some things
+ * about the native request object that is not provided by the
+ * base utils.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ExternalContextUtils
+{
+ private ExternalContextUtils(){}
+
+ /**
+ * Returns <code>true</code> if this externalContext represents an
+ * "action". An externalContext from a servlet is always considered
+ * an "action" whereas in a Portlet container, it will only return
+ * true if there is an action request.
+ *
+ * @return a boolean of <code>true</code> if this is a ServletRequest
+ * or a PortletActionRequest.
+ */
+ public static boolean isAction(ExternalContext externalContext)
+ {
+ Object request = externalContext.getRequest();
+ if(request instanceof ServletRequest)
+ {
+ return true;
+ }
+
+ try
+ {
+ Class c = Class.forName("javax.portlet.ActionRequest");
+ return c.isInstance(request);
+ }
+ catch (ClassNotFoundException e)
+ {
+ _LOG.warning("A non-servlet request was submitted and the portlet JARs are not on the classpath. Returning false.");
+ }
+ return false;
+ }
+
+ public static boolean isPortlet(ExternalContext externalContext)
+ {
+ Object request = externalContext.getRequest();
+
+ if(request instanceof ServletRequest)
+ {
+ return false;
+ }
+
+ try
+ {
+ Class c = Class.forName("javax.portlet.PortletRequest");
+ return c.isInstance(request);
+ }
+ catch (ClassNotFoundException e)
+ {
+ _LOG.warning("A non-servlet request was aubmitted and the portlet JARs are not on the classpath. Returning false.");
+ }
+ return false;
+ }
+
+ public static String getContentType(ExternalContext externalContext)
+ {
+ String s = null;
+ if(isAction(externalContext))
+ {
+ try
+ {
+ Object request = externalContext.getRequest();
+ Method m = request.getClass().getMethod("getContentType", (Class[])null);
+
+ if(m != null)
+ {
+ s = (String) m.invoke(request, (Object[])null);
+ }
+ }
+ catch (Exception e)
+ {
+ _LOG.severe(e);
+ }
+ }
+
+ return s;
+ }
+
+ public static int getContentLength(ExternalContext externalContext)
+ {
+ if(isAction(externalContext))
+ {
+ try
+ {
+ Object request = externalContext.getRequest();
+ Method m = request.getClass().getMethod("getContentLength", (Class[])null);
+
+ if(m != null)
+ {
+ return ((Integer)m.invoke(request, (Object[])null)).intValue();
+ }
+ }
+ catch (Exception e)
+ {
+ _LOG.severe(e);
+ }
+ }
+ return -1;
+ }
+
+ public static InputStream getRequestInputStream(ExternalContext externalContext) throws IOException
+ {
+ InputStream is = null;
+ if(isAction(externalContext))
+ {
+ if(isPortlet(externalContext))
+ {
+ return getPortletInputStream(externalContext.getRequest());
+ }
+ else
+ {
+ return getServletInputStream(externalContext.getRequest());
+ }
+ }
+ return null;
+ }
+
+ public static String getCharacterEncoding(ExternalContext externalContext)
+ {
+ if(isAction(externalContext))
+ {
+ try
+ {
+ Object request = externalContext.getRequest();
+ Method m = request.getClass().getMethod("getCharacterEncoding", (Class[])null);
+
+ if(m != null)
+ {
+ return (String) m.invoke(request, (Object[])null);
+ }
+ }
+ catch (Exception e)
+ {
+ _LOG.severe(e);
+ }
+ }
+
+ return null;
+ }
+
+ private static final InputStream getPortletInputStream(Object request) throws IOException
+ {
+ return ((ActionRequest)request).getPortletInputStream();
+ }
+
+ private static final InputStream getServletInputStream(Object request) throws IOException
+ {
+ return ((ServletRequest)request).getInputStream();
+ }
+
+ private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ExternalContextUtils.class);
+}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java Mon Dec 4 18:02:50 2006
@@ -47,6 +47,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.myfaces.trinidad.context.external.ServletExternalContext;
+import org.apache.myfaces.trinidad.context.external.TrinidadFacesContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.resource.CachingResourceLoader;
import org.apache.myfaces.trinidad.resource.DirectoryResourceLoader;
@@ -103,26 +105,6 @@
{
super.init(config);
- // Acquire our FacesContextFactory instance
- try
- {
- _facesContextFactory = (FacesContextFactory)
- FactoryFinder.getFactory
- (FactoryFinder.FACES_CONTEXT_FACTORY);
- }
- catch (FacesException e)
- {
- Throwable rootCause = e.getCause();
- if (rootCause == null)
- {
- throw e;
- }
- else
- {
- throw new ServletException(e.getMessage(), rootCause);
- }
- }
-
// Acquire our Lifecycle instance
_lifecycle = new _ResourceLifecycle();
_initDebug(config);
@@ -135,8 +117,10 @@
ServletResponse response
) throws ServletException, IOException
{
- FacesContext context = _facesContextFactory.getFacesContext
- ( getServletContext(), request, response, _lifecycle);
+ //Use trinidad's faces context object rather then FactoryFinder.
+ //This will avoid doing unnecessary wrapping.
+ FacesContext context = new TrinidadFacesContext(new ServletExternalContext(getServletContext(), request, response));
+
try
{
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2003-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.webapp;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+/**
+ * Trinidad context listener.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TrinidadListener implements ServletContextListener
+{
+
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ _impl.contextDestroyed(event);
+ _impl = null;
+ }
+
+ public void contextInitialized(ServletContextEvent event)
+ {
+ //get the impl
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null)
+ _LOG.severe("Could not find context class loader.");
+ else
+ {
+ try
+ {
+ Class<?> proxiedClass = loader.loadClass(
+ "org.apache.myfaces.trinidadinternal.webapp.TrinidadListenerImpl");
+ _impl = (ServletContextListener) proxiedClass.newInstance();
+ _impl.contextInitialized(event);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ _LOG.severe(cnfe);
+ }
+ catch (IllegalAccessException iae)
+ {
+ _LOG.severe(iae);
+ }
+ catch (InstantiationException ie)
+ {
+ _LOG.severe(ie);
+ }
+ catch (RuntimeException e)
+ {
+ // OC4J was not reporting these errors properly:
+ _LOG.severe(e);
+ throw e;
+ }
+ }
+ }
+
+ private ServletContextListener _impl;
+ static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(TrinidadListener.class);
+}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java Mon Dec 4 18:02:50 2006
@@ -17,6 +17,8 @@
import java.io.IOException;
+import javax.faces.context.ExternalContext;
+
import org.apache.myfaces.trinidad.model.UploadedFile;
/**
@@ -80,7 +82,7 @@
* web application context.
* @param context the current ServletContext, if in a servlet environment
*/
- public void init(Object context);
+ public void init(ExternalContext context);
/**
* Process a single uploaded file, moving it from temporary
@@ -104,11 +106,11 @@
* guarantees that {@link UploadedFile#dispose}</code> will be called before
* the request completes.
* </p>
- * @param request the current servlet request, if in a servlet environment
+ * @param ec the current external context
* @param file a temporary file object
* @return a new instance of UploadedFile. It is legal to return null,
* in which case the file will not be available later in the request.
*/
public UploadedFile processFile(
- Object request, UploadedFile file) throws IOException;
+ ExternalContext ec, UploadedFile file) throws IOException;
}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionRequestWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionRequestWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionRequestWrapper.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.webapp.wrappers;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import javax.portlet.ActionRequest;
+
+/**
+ * Wrapper for the native ActionRequest object. Unlike the servlet wrappers,
+ * Portlet Request/Response wrapping is not supported by JSR-160. Therefore
+ * it is important to use the PortletContextWrapper when retrieving the
+ * PortletRequestDispatcher. This will give you a special dispatcher that is
+ * aware of the wrapping and will deploy the underlying PortletRequest/Response
+ * implementations.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ActionRequestWrapper extends PortletRequestWrapper implements ActionRequest
+{
+ public ActionRequestWrapper(ActionRequest request)
+ {
+ super(request);
+ _req = request;
+ }
+
+ private ActionRequest _req;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getCharacterEncoding()
+ */
+ public String getCharacterEncoding()
+ {
+ return _req.getCharacterEncoding();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getContentLength()
+ */
+ public int getContentLength()
+ {
+ return _req.getContentLength();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getContentType()
+ */
+ public String getContentType()
+ {
+ return _req.getContentType();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getPortletInputStream()
+ */
+ public InputStream getPortletInputStream() throws IOException
+ {
+ return _req.getPortletInputStream();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getReader()
+ */
+ public BufferedReader getReader() throws UnsupportedEncodingException, IOException
+ {
+ return _req.getReader();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#setCharacterEncoding(java.lang.String)
+ */
+ public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
+ {
+ _req.setCharacterEncoding(arg0);
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionResponseWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionResponseWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/ActionResponseWrapper.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.webapp.wrappers;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+
+/**
+ * TODO: Document this
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ActionResponseWrapper extends PortletResponseWrapper implements ActionResponse
+{
+ public ActionResponseWrapper(ActionResponse response)
+ {
+ super(response);
+ _resp = response;
+ }
+
+ private ActionResponse _resp;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#sendRedirect(java.lang.String)
+ */
+ public void sendRedirect(String arg0) throws IOException
+ {
+ _resp.sendRedirect(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setPortletMode(javax.portlet.PortletMode)
+ */
+ public void setPortletMode(PortletMode arg0) throws PortletModeException
+ {
+ _resp.setPortletMode(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameter(java.lang.String, java.lang.String)
+ */
+ public void setRenderParameter(String arg0, String arg1)
+ {
+ _resp.setRenderParameter(arg0, arg1);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameter(java.lang.String, java.lang.String[])
+ */
+ public void setRenderParameter(String arg0, String[] arg1)
+ {
+ _resp.setRenderParameter(arg0, arg1);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameters(java.util.Map)
+ */
+ public void setRenderParameters(Map arg0)
+ {
+ _resp.setRenderParameters(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setWindowState(javax.portlet.WindowState)
+ */
+ public void setWindowState(WindowState arg0) throws WindowStateException
+ {
+ _resp.setWindowState(arg0);
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletContextWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletContextWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletContextWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletContextWrapper.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.webapp.wrappers;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequestDispatcher;
+
+/**
+ * TODO: Document this
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class PortletContextWrapper implements PortletContext
+{
+ public PortletContextWrapper(PortletContext context)
+ {
+ _context = context;
+ }
+
+ private PortletContext _context;
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String arg0)
+ {
+ return _context.getAttribute(arg0);
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getAttributeNames()
+ */
+ public Enumeration getAttributeNames()
+ {
+ return _context.getAttributeNames();
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String arg0)
+ {
+ return _context.getInitParameter(arg0);
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getInitParameterNames()
+ */
+ public Enumeration getInitParameterNames()
+ {
+ return _context.getInitParameterNames();
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getMajorVersion()
+ */
+ public int getMajorVersion()
+ {
+ return _context.getMajorVersion();
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getMimeType(java.lang.String)
+ */
+ public String getMimeType(String arg0)
+ {
+ return _context.getMimeType(arg0);
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getMinorVersion()
+ */
+ public int getMinorVersion()
+ {
+ return _context.getMinorVersion();
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getNamedDispatcher(java.lang.String)
+ */
+ public PortletRequestDispatcher getNamedDispatcher(String arg0)
+ {
+ return new PortletRequestDispatcherWrapper(_context.getNamedDispatcher(arg0));
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getPortletContextName()
+ */
+ public String getPortletContextName()
+ {
+ return _context.getPortletContextName();
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getRealPath(java.lang.String)
+ */
+ public String getRealPath(String arg0)
+ {
+ return _context.getRealPath(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getRequestDispatcher(java.lang.String)
+ */
+ public PortletRequestDispatcher getRequestDispatcher(String arg0)
+ {
+ return new PortletRequestDispatcherWrapper(_context.getRequestDispatcher(arg0));
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @throws MalformedURLException
+ * @see javax.portlet.PortletContext#getResource(java.lang.String)
+ */
+ public URL getResource(String arg0) throws MalformedURLException
+ {
+ return _context.getResource(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String arg0)
+ {
+ return _context.getResourceAsStream(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @see javax.portlet.PortletContext#getResourcePaths(java.lang.String)
+ */
+ public Set getResourcePaths(String arg0)
+ {
+ return _context.getResourcePaths(arg0);
+ }
+
+ /**
+ * @return
+ * @see javax.portlet.PortletContext#getServerInfo()
+ */
+ public String getServerInfo()
+ {
+ return _context.getServerInfo();
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @see javax.portlet.PortletContext#log(java.lang.String, java.lang.Throwable)
+ */
+ public void log(String arg0, Throwable arg1)
+ {
+ _context.log(arg0, arg1);
+ }
+
+ /**
+ * @param arg0
+ * @see javax.portlet.PortletContext#log(java.lang.String)
+ */
+ public void log(String arg0)
+ {
+ _context.log(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @see javax.portlet.PortletContext#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String arg0)
+ {
+ _context.removeAttribute(arg0);
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @see javax.portlet.PortletContext#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String arg0, Object arg1)
+ {
+ _context.setAttribute(arg0, arg1);
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestDispatcherWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestDispatcherWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestDispatcherWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestDispatcherWrapper.java Mon Dec 4 18:02:50 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.myfaces.trinidad.webapp.wrappers;
+
+import java.io.IOException;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * TODO: Document this
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class PortletRequestDispatcherWrapper implements PortletRequestDispatcher
+{
+ public PortletRequestDispatcherWrapper(PortletRequestDispatcher dispatcher)
+ {
+ _dispatch = dispatcher;
+ }
+
+ private PortletRequestDispatcher _dispatch;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequestDispatcher#include(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ public void include(RenderRequest arg0, RenderResponse arg1) throws PortletException, IOException
+ {
+ //We need to dispatch the origional request/response objects.
+ //So cut through all the wrappers and dispatch the origionals.
+ //TODO: Try out some usecases.
+ RenderRequest req = arg0;
+ while(req instanceof RenderRequestWrapper)
+ {
+ req = ((RenderRequestWrapper)req).getRequest();
+ }
+
+ RenderResponse resp = arg1;
+ while(resp instanceof RenderResponseWrapper)
+ {
+ resp = ((RenderResponseWrapper)resp).getResponse();
+ }
+ _dispatch.include(req, resp);
+
+ }
+
+}