You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2005/01/26 18:03:12 UTC
cvs commit: incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp JspViewHandlerImpl.java
matzew 2005/01/26 09:03:12
Modified: src/myfaces/org/apache/myfaces/application
NavigationHandlerImpl.java
build build.xml build.default.properties
src/myfaces/org/apache/myfaces/context
FacesContextFactoryImpl.java
src/myfaces/org/apache/myfaces/context/servlet
ServletFacesContextImpl.java
ServletExternalContextImpl.java
src/myfaces/org/apache/myfaces/lifecycle LifecycleImpl.java
src/myfaces/org/apache/myfaces/config FacesConfigurator.java
src/myfaces/org/apache/myfaces/application/jsp
JspViewHandlerImpl.java
Added: src/myfaces/org/apache/myfaces/context/portlet
InitParameterMap.java ApplicationMap.java
RequestParameterValuesMap.java
PortletExternalContextImpl.java
RequestParameterMap.java RequestMap.java
RequestHeaderValuesMap.java SessionMap.java
RequestHeaderMap.java
lib portlet-api-1.0.jar
src/myfaces/org/apache/myfaces/portlet
MyFacesGenericPortlet.java DefaultViewSelector.java
src/myfaces/org/apache/myfaces/context
ReleaseableExternalContext.java
Log:
MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
Revision Changes Path
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/InitParameterMap.java
Index: InitParameterMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletContext;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* ServletContext init parameters as Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: InitParameterMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class InitParameterMap extends AbstractAttributeMap
{
final PortletContext _portletContext;
InitParameterMap(PortletContext portletContext)
{
_portletContext = portletContext;
}
protected Object getAttribute(String key)
{
return _portletContext.getInitParameter(key);
}
protected void setAttribute(String key, Object value)
{
throw new UnsupportedOperationException(
"Cannot set PortletContext InitParameter");
}
protected void removeAttribute(String key)
{
throw new UnsupportedOperationException(
"Cannot remove PortletContext InitParameter");
}
protected Enumeration getAttributeNames()
{
return _portletContext.getInitParameterNames();
}
public boolean equals(Object o) {
boolean retValue;
retValue = super.equals(o);
return retValue;
}
public int hashCode() {
int retValue;
retValue = super.hashCode();
return retValue;
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/ApplicationMap.java
Index: ApplicationMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletContext;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletContext attributes as a Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: ApplicationMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class ApplicationMap extends AbstractAttributeMap
{
final PortletContext _portletContext;
ApplicationMap(PortletContext portletContext)
{
_portletContext = portletContext;
}
protected Object getAttribute(String key)
{
return _portletContext.getAttribute(key);
}
protected void setAttribute(String key, Object value)
{
_portletContext.setAttribute(key, value);
}
protected void removeAttribute(String key)
{
_portletContext.removeAttribute(key);
}
protected Enumeration getAttributeNames()
{
return _portletContext.getAttributeNames();
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/RequestParameterValuesMap.java
Index: RequestParameterValuesMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletRequest;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletRequest multi-value parameters as Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: RequestParameterValuesMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class RequestParameterValuesMap extends AbstractAttributeMap
{
private final PortletRequest _portletRequest;
RequestParameterValuesMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
return _portletRequest.getParameterValues(key);
}
protected void setAttribute(String key, Object value)
{
throw new UnsupportedOperationException(
"Cannot set PortletRequest ParameterValues");
}
protected void removeAttribute(String key)
{
throw new UnsupportedOperationException(
"Cannot remove PortletRequest ParameterValues");
}
protected Enumeration getAttributeNames()
{
return _portletRequest.getParameterNames();
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/PortletExternalContextImpl.java
Index: PortletExternalContextImpl.java
===================================================================
/*
* 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.context.portlet;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.Principal;
import java.util.Collections;
import java.util.HashMap;
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.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.util.EnumerationIterator;
/**
* An ExternalContext implementation for JSF applications that run inside a
* a Portlet.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: PortletExternalContextImpl.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class PortletExternalContextImpl extends ExternalContext implements ReleaseableExternalContext {
private static final Log log = LogFactory.getLog(PortletExternalContextImpl.class);
private static final String INIT_PARAMETER_MAP_ATTRIBUTE = InitParameterMap.class.getName();
private static final Map EMPTY_UNMODIFIABLE_MAP = Collections.unmodifiableMap(new HashMap(0));
PortletContext _portletContext;
PortletRequest _portletRequest;
PortletResponse _portletResponse;
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 _isActionRequest;
/** Creates a new instance of PortletFacesContextImpl */
public PortletExternalContextImpl(PortletContext portletContext,
PortletRequest portletRequest,
PortletResponse portletResponse)
{
_portletContext = portletContext;
_portletRequest = portletRequest;
_portletResponse = portletResponse;
_isActionRequest = (portletRequest != null &&
portletRequest instanceof ActionRequest);
if (_isActionRequest)
{
ActionRequest actionRequest = (ActionRequest)portletRequest;
// try to set character encoding as described in section 2.5.2.2 of JSF 1.1 spec
try
{
String contentType = portletRequest.getProperty("Content-Type");
String characterEncoding = lookupCharacterEncoding(contentType);
if (characterEncoding == null) {
PortletSession session = portletRequest.getPortletSession(false);
if (session != null) {
characterEncoding = (String) session.getAttribute(ViewHandler.CHARACTER_ENCODING_KEY,
PortletSession.PORTLET_SCOPE);
}
if (characterEncoding != null) {
actionRequest.setCharacterEncoding(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 dispatch(String path) throws IOException
{
if (_isActionRequest)
{ // dispatch only allowed for RenderRequest
String msg = "Can not call dispatch() during a portlet ActionRequest";
throw new IllegalStateException(msg);
}
PortletRequestDispatcher requestDispatcher
= _portletContext.getRequestDispatcher(path); //TODO: figure out why I need named dispatcher
try
{
requestDispatcher.include((RenderRequest)_portletRequest,
(RenderResponse)_portletResponse);
}
catch (PortletException e)
{
if (e.getMessage() != null)
{
throw new FacesException(e.getMessage(), e);
}
else
{
throw new FacesException(e);
}
}
}
public String encodeActionURL(String url) {
checkNull(url, "url");
return _portletResponse.encodeURL(url);
}
public String encodeNamespace(String name) {
if (_isActionRequest)
{ // encodeNamespace only allowed for RenderRequest
String msg = "Can not call encodeNamespace() during a portlet ActionRequest";
throw new IllegalStateException(msg);
}
return ((RenderResponse)_portletResponse).getNamespace() + name;
}
public String encodeResourceURL(String url) {
checkNull(url, "url");
return _portletResponse.encodeURL(url);
}
public Map getApplicationMap() {
if (_applicationMap == null)
{
_applicationMap = new ApplicationMap(_portletContext);
}
return _applicationMap;
}
public String getAuthType() {
return _portletRequest.getAuthType();
}
public Object getContext() {
return _portletContext;
}
public String getInitParameter(String name) {
return _portletContext.getInitParameter(name);
}
public Map getInitParameterMap() {
if (_initParameterMap == null)
{
// We cache it as an attribute in PortletContext itself (is this circular reference a problem?)
if ((_initParameterMap = (Map) _portletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE)) == null)
{
_initParameterMap = new InitParameterMap(_portletContext);
_portletContext.setAttribute(INIT_PARAMETER_MAP_ATTRIBUTE, _initParameterMap);
}
}
return _initParameterMap;
}
public String getRemoteUser() {
return _portletRequest.getRemoteUser();
}
public Object getRequest() {
return _portletRequest;
}
public String getRequestContextPath() {
return _portletRequest.getContextPath();
}
public Map getRequestCookieMap() {
return EMPTY_UNMODIFIABLE_MAP;
}
public Map getRequestHeaderMap() {
if (_requestHeaderMap == null)
{
_requestHeaderMap = new RequestHeaderMap(_portletRequest);
}
return _requestHeaderMap;
}
public Map getRequestHeaderValuesMap() {
if (_requestHeaderValuesMap == null)
{
_requestHeaderValuesMap = new RequestHeaderValuesMap(_portletRequest);
}
return _requestHeaderValuesMap;
}
public Locale getRequestLocale() {
return _portletRequest.getLocale();
}
public Iterator getRequestLocales() {
return new EnumerationIterator(_portletRequest.getLocales());
}
public Map getRequestMap() {
if (_requestMap == null)
{
_requestMap = new RequestMap(_portletRequest);
}
return _requestMap;
}
public Map getRequestParameterMap() {
if (_requestParameterMap == null)
{
_requestParameterMap = new RequestParameterMap(_portletRequest);
}
return _requestParameterMap;
}
public Iterator getRequestParameterNames() {
// TODO: find out why it is not done this way in ServletExternalContextImpl
return new EnumerationIterator(_portletRequest.getParameterNames());
}
public Map getRequestParameterValuesMap() {
if (_requestParameterValuesMap == null)
{
_requestParameterValuesMap = new RequestParameterValuesMap(_portletRequest);
}
return _requestParameterValuesMap;
}
public String getRequestPathInfo() {
return null; // must return null
}
public String getRequestServletPath() {
return null; // must return null
}
public URL getResource(String path) throws MalformedURLException {
checkNull(path, "path");
return _portletContext.getResource(path);
}
public InputStream getResourceAsStream(String path) {
checkNull(path, "path");
return _portletContext.getResourceAsStream(path);
}
public Set getResourcePaths(String path) {
checkNull(path, "path");
return _portletContext.getResourcePaths(path);
}
public Object getResponse() {
return _portletResponse;
}
public Object getSession(boolean create) {
return _portletRequest.getPortletSession(create);
}
public Map getSessionMap() {
if (_sessionMap == null)
{
_sessionMap = new SessionMap(_portletRequest);
}
return _sessionMap;
}
public Principal getUserPrincipal() {
return _portletRequest.getUserPrincipal();
}
public boolean isUserInRole(String role) {
checkNull(role, "role");
return _portletRequest.isUserInRole(role);
}
public void log(String message) {
checkNull(message, "message");
_portletContext.log(message);
}
public void log(String message, Throwable exception) {
checkNull(message, "message");
checkNull(exception, "exception");
_portletContext.log(message, exception);
}
public void redirect(String url) throws IOException {
if (_portletResponse instanceof ActionResponse)
{
((ActionResponse)_portletResponse).sendRedirect(url);
}
else
{
throw new IllegalArgumentException("Only ActionResponse supported");
}
}
public void release() {
_portletContext = null;
_portletRequest = null;
_portletResponse = null;
_applicationMap = null;
_sessionMap = null;
_requestMap = null;
_requestParameterMap = null;
_requestParameterValuesMap = null;
_requestHeaderMap = null;
_requestHeaderValuesMap = null;
_requestCookieMap = null;
_initParameterMap = null;
}
private void checkNull(Object o, String param)
{
if (o == null)
{
throw new NullPointerException(param + " can not be null.");
}
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/RequestParameterMap.java
Index: RequestParameterMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletRequest;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletRequest parameters as Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: RequestParameterMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class RequestParameterMap extends AbstractAttributeMap
{
private final PortletRequest _portletRequest;
RequestParameterMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
return _portletRequest.getParameter(key);
}
protected void setAttribute(String key, Object value)
{
throw new UnsupportedOperationException(
"Cannot set PortletRequest Parameter");
}
protected void removeAttribute(String key)
{
throw new UnsupportedOperationException(
"Cannot remove PortletRequest Parameter");
}
protected Enumeration getAttributeNames()
{
return _portletRequest.getParameterNames();
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/RequestMap.java
Index: RequestMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletRequest;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletRequest attributes Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: RequestMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class RequestMap extends AbstractAttributeMap
{
final PortletRequest _portletRequest;
RequestMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
return _portletRequest.getAttribute(key);
}
protected void setAttribute(String key, Object value)
{
_portletRequest.setAttribute(key, value);
}
protected void removeAttribute(String key)
{
_portletRequest.removeAttribute(key);
}
protected Enumeration getAttributeNames()
{
return _portletRequest.getAttributeNames();
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/RequestHeaderValuesMap.java
Index: RequestHeaderValuesMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletRequest;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletRequest header values (multi-value headers) as Map of String[].
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: RequestHeaderValuesMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class RequestHeaderValuesMap extends AbstractAttributeMap
{
private final PortletRequest _portletRequest;
private final Map _valueCache = new HashMap();
RequestHeaderValuesMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
Object ret = _valueCache.get(key);
if (ret == null)
{
_valueCache.put(key, ret = toArray(_portletRequest
.getProperties(key)));
}
return ret;
}
protected void setAttribute(String key, Object value)
{
throw new UnsupportedOperationException(
"Cannot set PortletRequest Properties");
}
protected void removeAttribute(String key)
{
throw new UnsupportedOperationException(
"Cannot remove PortletRequest Properties");
}
protected Enumeration getAttributeNames()
{
return _portletRequest.getPropertyNames();
}
private String[] toArray(Enumeration e)
{
List ret = new ArrayList();
while (e.hasMoreElements())
{
ret.add(e.nextElement());
}
return (String[]) ret.toArray(new String[ret.size()]);
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/SessionMap.java
Index: SessionMap.java
===================================================================
/*
* 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.context.portlet;
import org.apache.myfaces.util.NullEnumeration;
import java.util.Enumeration;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* Portlet scope PortletSession attibutes as Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: SessionMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*
*/
public class SessionMap extends AbstractAttributeMap
{
private final PortletRequest _portletRequest;
SessionMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
PortletSession portletSession = getSession();
return (portletSession == null)
? null : portletSession.getAttribute(key.toString(), PortletSession.PORTLET_SCOPE);
}
protected void setAttribute(String key, Object value)
{
_portletRequest.getPortletSession(true).setAttribute(key, value, PortletSession.PORTLET_SCOPE);
}
protected void removeAttribute(String key)
{
PortletSession portletSession = getSession();
if (portletSession != null)
{
portletSession.removeAttribute(key, PortletSession.PORTLET_SCOPE);
}
}
protected Enumeration getAttributeNames()
{
PortletSession portletSession = getSession();
return (portletSession == null)
? NullEnumeration.instance()
: portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE);
}
private PortletSession getSession()
{
return _portletRequest.getPortletSession(false);
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/portlet/RequestHeaderMap.java
Index: RequestHeaderMap.java
===================================================================
/*
* 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.context.portlet;
import java.util.Enumeration;
import javax.portlet.PortletRequest;
import org.apache.myfaces.context.servlet.AbstractAttributeMap;
/**
* PortletRequest headers as Map.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
* $Log: RequestHeaderMap.java,v $
* Revision 1.1 2005/01/26 17:03:09 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class RequestHeaderMap extends AbstractAttributeMap
{
private final PortletRequest _portletRequest;
RequestHeaderMap(PortletRequest portletRequest)
{
_portletRequest = portletRequest;
}
protected Object getAttribute(String key)
{
return _portletRequest.getProperty(key);
}
protected void setAttribute(String key, Object value)
{
throw new UnsupportedOperationException(
"Cannot set PortletRequest property");
}
protected void removeAttribute(String key)
{
throw new UnsupportedOperationException(
"Cannot remove PortletRequest property");
}
protected Enumeration getAttributeNames()
{
return _portletRequest.getPropertyNames();
}
}
1.34 +10 -8 incubator-myfaces/src/myfaces/org/apache/myfaces/application/NavigationHandlerImpl.java
Index: NavigationHandlerImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/application/NavigationHandlerImpl.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- NavigationHandlerImpl.java 13 Oct 2004 11:50:59 -0000 1.33
+++ NavigationHandlerImpl.java 26 Jan 2005 17:03:09 -0000 1.34
@@ -32,12 +32,16 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;
+import javax.portlet.PortletRequest;
/**
* @author Thomas Spiegl (latest modification by $Author$)
* @author Anton Koinov
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.34 2005/01/26 17:03:09 matzew
+ * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
+ *
* Revision 1.33 2004/10/13 11:50:59 matze
* renamed packages to org.apache
*
@@ -147,8 +151,9 @@
" toViewId =" + navigationCase.getToViewId() +
" redirect=" + navigationCase.isRedirect());
}
- if (navigationCase.isRedirect())
- {
+ if (navigationCase.isRedirect() &&
+ (!(facesContext.getExternalContext().getRequest() instanceof PortletRequest)))
+ { // Spec section 7.4.2 says "redirects not possible" in this case for portlets
ExternalContext externalContext = facesContext.getExternalContext();
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
String redirectPath = viewHandler.getActionURL(facesContext, navigationCase.getToViewId());
@@ -168,10 +173,7 @@
}
}
}
- else
- {
- //TODO: What about Portlet requests?
- }
+
try
{
externalContext.redirect(externalContext.encodeActionURL(redirectPath));
1.1 incubator-myfaces/lib/portlet-api-1.0.jar
<<Binary file>>
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/portlet/MyFacesGenericPortlet.java
Index: MyFacesGenericPortlet.java
===================================================================
/*
* 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.portlet;
import java.io.IOException;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.faces.webapp.FacesServlet;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.config.FacesConfigurator;
import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.context.portlet.PortletExternalContextImpl;
import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
import org.apache.myfaces.webapp.webxml.WebXml;
/**
* This portlet initializes MyFaces and converts portlet requests into
* JSF requests.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:10 $
* $Log: MyFacesGenericPortlet.java,v $
* Revision 1.1 2005/01/26 17:03:10 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public class MyFacesGenericPortlet extends GenericPortlet
{
private static final Log log = LogFactory.getLog(MyFacesGenericPortlet.class);
// PortletRequest parameter
public static final String VIEW_ID =
MyFacesGenericPortlet.class.getName() + ".VIEW_ID";
// PortletSession attribute
private static final String CURRENT_FACES_CONTEXT =
MyFacesGenericPortlet.class.getName() + ".CURRENT_FACES_CONTEXT";
// portlet config parameter from portlet.xml
private static final String DEFAULT_VIEW = "default-view";
// portlet config parameter from portlet.xml
private static final String DEFAULT_VIEW_SELECTOR = "default-view-selector";
private static final String FACES_INIT_DONE =
MyFacesGenericPortlet.class.getName() + ".FACES_INIT_DONE";
private PortletContext portletContext;
private FacesContextFactory facesContextFactory;
private Lifecycle lifecycle;
private String defaultView;
private DefaultViewSelector defaultViewSelector;
/**
* Creates a new instance of MyFacesPortlet
*/
public MyFacesGenericPortlet()
{
}
/**
* Portlet lifecycle.
*/
public void destroy()
{
super.destroy();
FactoryFinder.releaseFactories();
}
/**
* Portlet lifecycle.
*/
public void init() throws PortletException, UnavailableException
{
this.portletContext = getPortletContext();
setDefaultView();
setDefaultViewSelector();
initMyFaces();
facesContextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
// Javadoc says: Lifecycle instance is shared across multiple simultaneous requests, it must be
// implemented in a thread-safe manner. So we can acquire it here once:
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
}
private void setDefaultView() throws UnavailableException
{
this.defaultView = getPortletConfig().getInitParameter(DEFAULT_VIEW);
if (defaultView == null)
{
String msg = "Fatal: must specify a JSF view id as the default view in portlet.xml";
throw new UnavailableException(msg);
}
}
private void setDefaultViewSelector() throws UnavailableException
{
String selectorClass = getPortletConfig().getInitParameter(DEFAULT_VIEW_SELECTOR);
if (selectorClass == null) return;
try
{
this.defaultViewSelector = (DefaultViewSelector)Class.forName(selectorClass).newInstance();
this.defaultViewSelector.setPortletContext(getPortletContext());
}
catch (Exception e)
{
log.error("Failed to load " + DEFAULT_VIEW_SELECTOR, e);
throw new UnavailableException(e.getMessage());
}
}
private String getLifecycleId()
{
String lifecycleId = getPortletConfig().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
return lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE;
}
private void initMyFaces()
{
try
{
Boolean b = (Boolean)portletContext.getAttribute(FACES_INIT_DONE);
if (b == null || b.booleanValue() == false)
{
log.trace("Initializing MyFaces");
//Load the configuration
ExternalContext externalContext = new PortletExternalContextImpl(portletContext, null, null);
//And configure everything
new FacesConfigurator(externalContext).configure();
// parse web.xml - not sure if this is needed for portlet
WebXml.init(externalContext);
portletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
}
else
{
log.info("MyFaces already initialized");
}
}
catch (Exception ex)
{
log.error("Error initializing MyFacesGenericPortlet", ex);
}
log.info("PortletContext '" + portletContext.getRealPath("/") + "' initialized.");
}
/**
* Called by the portlet container to allow the portlet to process an action request.
*/
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
if (log.isTraceEnabled()) log.trace("called processAction");
if (sessionTimedOut(request)) return;
FacesContext facesContext = facesContext(request, response);
try
{
lifecycle.execute(facesContext);
if (!facesContext.getResponseComplete())
{
response.setRenderParameter(VIEW_ID, facesContext.getViewRoot().getViewId());
}
request.getPortletSession().setAttribute(CURRENT_FACES_CONTEXT, facesContext);
}
catch (Throwable e)
{
facesContext.release();
handleExceptionFromLifecycle(e);
}
}
private void handleExceptionFromLifecycle(Throwable e)
throws PortletException, IOException
{
logException(e, null);
if (e instanceof IOException)
{
throw (IOException)e;
}
if (e instanceof PortletException)
{
throw (PortletException)e;
}
if (e.getMessage() != null)
{
throw new PortletException(e.getMessage(), e);
}
throw new PortletException(e);
}
/**
* Helper method to serve up the view mode.
*/
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
facesRender(request, response);
}
/**
* Helper method to serve up the edit mode. Can be overridden to add
* the edit mode concept to a JSF application.
*/
protected void doEdit(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
facesRender(request, response);
}
/**
* Helper method to serve up the edit mode. Can be overridden to add
* the help mode concept to a JSF application.
*/
protected void doHelp(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
facesRender(request, response);
}
// JSF Spec section 2.1.1
protected void nonFacesRequest(RenderRequest request, RenderResponse response) throws PortletException
{
if (log.isTraceEnabled()) log.trace("Non-faces request: contextPath = " + request.getContextPath());
ApplicationFactory appFactory =
(ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = appFactory.getApplication();
ViewHandler viewHandler = application.getViewHandler();
FacesContext facesContext = facesContext(request, response);
UIViewRoot view = viewHandler.createView(facesContext, selectDefaultView(request, response));
facesContext.setViewRoot(view);
lifecycle.render(facesContext);
}
private String selectDefaultView(RenderRequest request, RenderResponse response) throws PortletException
{
String view = this.defaultView;
if (this.defaultViewSelector != null)
{
String selectedView = this.defaultViewSelector.selectViewId(request, response);
if (selectedView != null)
{
view = selectedView;
}
}
return view;
}
private FacesContext facesContext(PortletRequest request,
PortletResponse response)
{
return facesContextFactory.getFacesContext(portletContext,
request,
response,
lifecycle);
}
private ReleaseableExternalContext makeExternalContext(PortletRequest request,
PortletResponse response)
{
return (ReleaseableExternalContext)new PortletExternalContextImpl(portletContext, request, response);
}
private boolean sessionTimedOut(PortletRequest request)
{
return request.getPortletSession(false) == null;
}
/**
* Render a JSF view.
*/
protected void facesRender(RenderRequest request, RenderResponse response)
throws PortletException, java.io.IOException
{
if (log.isTraceEnabled()) log.trace("called facesRender");
response.setContentType("text/html");
String viewId = request.getParameter(VIEW_ID);
if ((viewId == null) || sessionTimedOut(request))
{
nonFacesRequest(request, response);
return;
}
try
{
ServletFacesContextImpl facesContext = (ServletFacesContextImpl)request.
getPortletSession().
getAttribute(CURRENT_FACES_CONTEXT);
// TODO: not sure if this can happen. Also double check this against spec section 2.1.3
if (facesContext.getResponseComplete()) return;
facesContext.setExternalContext(makeExternalContext(request, response));
lifecycle.render(facesContext);
}
catch (Throwable e)
{
handleExceptionFromLifecycle(e);
}
}
private void logException(Throwable e, String msgPrefix) {
String msg;
if (msgPrefix == null)
{
if (e.getMessage() == null)
{
msg = "Exception in FacesServlet";
}
else
{
msg = e.getMessage();
}
}
else
{
if (e.getMessage() == null)
{
msg = msgPrefix;
}
else
{
msg = msgPrefix + ": " + e.getMessage();
}
}
portletContext.log(msg, e);
Throwable cause = e.getCause();
if (cause != null && cause != e)
{
logException(cause, "Root cause");
}
if(e instanceof PortletException)
{
cause = ((PortletException) e).getCause();
if(cause != null && cause != e)
{
logException(cause, "Root cause of PortletException");
}
}
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/portlet/DefaultViewSelector.java
Index: DefaultViewSelector.java
===================================================================
/*
* 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.portlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* Imlementations of this interface allow a JSF application to specify which
* JSF view will be selected when the incoming request does not provide a View
* Id. The implementation can optionally return <code>null</code> to revert to
* the default View Id specified in portlet.xml.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:10 $
* $Log: DefaultViewSelector.java,v $
* Revision 1.1 2005/01/26 17:03:10 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public interface DefaultViewSelector {
/**
* This method will be called by the MyFacesGenericPortlet in order to
* give the selector an opportunity to store a reference to the
* PortletContext.
*/
public void setPortletContext(PortletContext portletContext);
/**
* This method allows a JSF application to specify which JSF view will be
* when the incoming request does not provide a view id.
*
* @param request The RenderRequest
* @param response The RenderResponse
* @return a JSF View Id, or <code>null</code> if the selector wishes to
* revert to the default View Id specified in portlet.xml.
* @throws PortletException if a View Id can not be determined because of
* some underlying error.
*/
public String selectViewId(RenderRequest request, RenderResponse response) throws PortletException;
}
1.75 +1 -0 incubator-myfaces/build/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/incubator-myfaces/build/build.xml,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- build.xml 24 Jan 2005 20:55:15 -0000 1.74
+++ build.xml 26 Jan 2005 17:03:10 -0000 1.75
@@ -66,6 +66,7 @@
<pathelement location="${commons-beanutils.jar}"/>
<pathelement location="${commons-collections.jar}"/>
<pathelement location="${commons-digester.jar}"/>
+ <pathelement location="${portlet.jar}"/>
<pathelement location="${api.classes}"/>
<pathelement location="${share.classes}"/>
</path>
1.24 +3 -0 incubator-myfaces/build/build.default.properties
Index: build.default.properties
===================================================================
RCS file: /home/cvs/incubator-myfaces/build/build.default.properties,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- build.default.properties 30 Dec 2004 16:57:04 -0000 1.23
+++ build.default.properties 26 Jan 2005 17:03:10 -0000 1.24
@@ -29,6 +29,9 @@
# File path to commons digester package
commons-digester.jar = ${project.dir}/lib/commons-digester-1.5.jar
+# File path to portlet file for portlet support
+portlet.jar = ${project.dir}/lib/portlet-api-1.0.jar
+
# File path to commons el package
commons-el.jar = ${project.dir}/lib/commons-el.jar
1.12 +12 -4 incubator-myfaces/src/myfaces/org/apache/myfaces/context/FacesContextFactoryImpl.java
Index: FacesContextFactoryImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/context/FacesContextFactoryImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FacesContextFactoryImpl.java 13 Oct 2004 11:51:00 -0000 1.11
+++ FacesContextFactoryImpl.java 26 Jan 2005 17:03:10 -0000 1.12
@@ -21,6 +21,9 @@
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -45,9 +48,14 @@
(ServletRequest)request,
(ServletResponse)response);
}
- else
+
+ if (context instanceof PortletContext)
{
- throw new FacesException("Unsupported context type " + context.getClass().getName());
+ return new ServletFacesContextImpl((PortletContext)context,
+ (PortletRequest)request,
+ (PortletResponse)response);
}
+
+ throw new FacesException("Unsupported context type " + context.getClass().getName());
}
}
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/context/ReleaseableExternalContext.java
Index: ReleaseableExternalContext.java
===================================================================
/*
* 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.context;
/**
* Allows the ServletFacesContextImpl to refer to the external context
* polymorphically.
*
* @author Stan Silvert (latest modification by $Author: matzew $)
* @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:10 $
* $Log: ReleaseableExternalContext.java,v $
* Revision 1.1 2005/01/26 17:03:10 matzew
* MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
*
*/
public interface ReleaseableExternalContext
{
/**
* Release resources that the ExternalContext is holding onto.
*/
public void release();
}
1.18 +38 -7 incubator-myfaces/src/myfaces/org/apache/myfaces/context/servlet/ServletFacesContextImpl.java
Index: ServletFacesContextImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/context/servlet/ServletFacesContextImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ServletFacesContextImpl.java 13 Oct 2004 11:51:00 -0000 1.17
+++ ServletFacesContextImpl.java 26 Jan 2005 17:03:11 -0000 1.18
@@ -32,6 +32,11 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.*;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import org.apache.myfaces.context.ReleaseableExternalContext;
+import org.apache.myfaces.context.portlet.PortletExternalContextImpl;
/**
@@ -39,6 +44,9 @@
* @author Anton Koinov
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.18 2005/01/26 17:03:11 matzew
+ * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
+ *
* Revision 1.17 2004/10/13 11:51:00 matze
* renamed packages to org.apache
*
@@ -67,7 +75,7 @@
List _messageClientIds = null;
private List _messages = null;
private Application _application;
- private ServletExternalContextImpl _externalContext;
+ private ReleaseableExternalContext _externalContext;
private ResponseStream _responseStream = null;
private ResponseWriter _responseWriter = null;
private FacesMessage.Severity _maximumSeverity = FacesMessage.SEVERITY_INFO;
@@ -78,16 +86,31 @@
//~ Constructors -------------------------------------------------------------------------------
+ // TODO: FIXME: the name of this class should be changed.
+ public ServletFacesContextImpl(PortletContext portletContext,
+ PortletRequest portletRequest,
+ PortletResponse portletResponse)
+ {
+ this(new PortletExternalContextImpl(portletContext,
+ portletRequest,
+ portletResponse));
+ }
+
public ServletFacesContextImpl(ServletContext servletContext,
ServletRequest servletRequest,
ServletResponse servletResponse)
{
+ this(new ServletExternalContextImpl(servletContext,
+ servletRequest,
+ servletResponse));
+ }
+
+ private ServletFacesContextImpl(ReleaseableExternalContext externalContext)
+ {
_application = ((ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY))
.getApplication();
_renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- _externalContext = new ServletExternalContextImpl(servletContext,
- servletRequest,
- servletResponse);
+ _externalContext = externalContext;
FacesContext.setCurrentInstance(this); //protected method, therefore must be called from here
}
@@ -95,7 +118,7 @@
public ExternalContext getExternalContext()
{
- return _externalContext;
+ return (ExternalContext)_externalContext;
}
public FacesMessage.Severity getMaximumSeverity()
@@ -299,4 +322,12 @@
{
_responseComplete = true;
}
+
+ // Portlet need to do this to change from ActionRequest/Response to
+ // RenderRequest/Response
+ public void setExternalContext(ReleaseableExternalContext extContext)
+ {
+ _externalContext = extContext;
+ FacesContext.setCurrentInstance(this); //TODO: figure out if I really need to do this
+ }
}
1.19 +4 -3 incubator-myfaces/src/myfaces/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
Index: ServletExternalContextImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ServletExternalContextImpl.java 13 Oct 2004 11:51:00 -0000 1.18
+++ ServletExternalContextImpl.java 26 Jan 2005 17:03:11 -0000 1.19
@@ -34,6 +34,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
+import org.apache.myfaces.context.ReleaseableExternalContext;
/**
* JSF 1.0 PRD2, 6.1.1
@@ -45,7 +46,7 @@
* Forward the message when an exception is thrown in dispatch
*/
public class ServletExternalContextImpl
- extends ExternalContext
+ extends ExternalContext implements ReleaseableExternalContext
{
private static final Log log = LogFactory.getLog(ServletExternalContextImpl.class);
1.42 +15 -8 incubator-myfaces/src/myfaces/org/apache/myfaces/lifecycle/LifecycleImpl.java
Index: LifecycleImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/lifecycle/LifecycleImpl.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- LifecycleImpl.java 13 Oct 2004 11:51:00 -0000 1.41
+++ LifecycleImpl.java 26 Jan 2005 17:03:11 -0000 1.42
@@ -38,12 +38,17 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import javax.portlet.PortletRequest;
+import org.apache.myfaces.portlet.MyFacesGenericPortlet;
/**
* Implements the lifecycle as described in Spec. 1.0 PFD Chapter 2
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.42 2005/01/26 17:03:11 matzew
+ * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
+ *
* Revision 1.41 2004/10/13 11:51:00 matze
* renamed packages to org.apache
*
@@ -280,9 +285,7 @@
if (log.isDebugEnabled()) log.debug("exiting renderResponse in " + LifecycleImpl.class.getName() + " (response complete)");
return;
}
-
informPhaseListenersBefore(facesContext, PhaseId.RENDER_RESPONSE);
-
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
try
@@ -295,7 +298,6 @@
}
informPhaseListenersAfter(facesContext, PhaseId.RENDER_RESPONSE);
-
if (log.isTraceEnabled())
{
//Note: DebugUtils Logger must also be in trace level
@@ -310,14 +312,19 @@
{
ExternalContext externalContext = facesContext.getExternalContext();
- String viewId = externalContext.getRequestPathInfo();
+ if (externalContext.getRequest() instanceof PortletRequest)
+ {
+ PortletRequest request = (PortletRequest)externalContext.getRequest();
+ return request.getParameter(MyFacesGenericPortlet.VIEW_ID);
+ }
+
+ String viewId = externalContext.getRequestPathInfo(); //getPathInfo
if (viewId == null)
{
//No extra path info found, so it is propably extension mapping
- viewId = externalContext.getRequestServletPath();
+ viewId = externalContext.getRequestServletPath(); //getServletPath
DebugUtils.assertError(viewId != null,
log, "RequestServletPath is null, cannot determine viewId of current page.");
-
//TODO: JSF Spec 2.2.1 - what do they mean by "if the default ViewHandler implementation is used..." ?
String defaultSuffix = externalContext.getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
String suffix = defaultSuffix != null ? defaultSuffix : ViewHandler.DEFAULT_SUFFIX;
1.10 +54 -50 incubator-myfaces/src/myfaces/org/apache/myfaces/config/FacesConfigurator.java
Index: FacesConfigurator.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/config/FacesConfigurator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FacesConfigurator.java 13 Dec 2004 22:20:34 -0000 1.9
+++ FacesConfigurator.java 26 Jan 2005 17:03:11 -0000 1.10
@@ -15,26 +15,33 @@
*/
package org.apache.myfaces.config;
-import org.apache.myfaces.application.ApplicationFactoryImpl;
-import org.apache.myfaces.config.element.ManagedBean;
-import org.apache.myfaces.config.element.NavigationRule;
-import org.apache.myfaces.config.element.Renderer;
-import org.apache.myfaces.config.impl.digester.DigesterFacesConfigDispenserImpl;
-import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
-import org.apache.myfaces.context.FacesContextFactoryImpl;
-import org.apache.myfaces.lifecycle.LifecycleFactoryImpl;
-import org.apache.myfaces.renderkit.RenderKitFactoryImpl;
-import org.apache.myfaces.renderkit.html.HtmlRenderKitImpl;
-import org.apache.myfaces.util.ClassUtils;
-import org.apache.myfaces.util.LocaleUtils;
-import org.xml.sax.SAXException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
-import javax.faces.application.*;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.NavigationHandler;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
import javax.faces.context.ExternalContext;
import javax.faces.el.PropertyResolver;
import javax.faces.el.VariableResolver;
@@ -45,14 +52,22 @@
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
import javax.faces.webapp.FacesServlet;
-import javax.servlet.ServletContext;
-import java.io.*;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.application.ApplicationFactoryImpl;
+import org.apache.myfaces.config.element.ManagedBean;
+import org.apache.myfaces.config.element.NavigationRule;
+import org.apache.myfaces.config.element.Renderer;
+import org.apache.myfaces.config.impl.digester.DigesterFacesConfigDispenserImpl;
+import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
+import org.apache.myfaces.context.FacesContextFactoryImpl;
+import org.apache.myfaces.lifecycle.LifecycleFactoryImpl;
+import org.apache.myfaces.renderkit.RenderKitFactoryImpl;
+import org.apache.myfaces.renderkit.html.HtmlRenderKitImpl;
+import org.apache.myfaces.util.ClassUtils;
+import org.apache.myfaces.util.LocaleUtils;
+import org.xml.sax.SAXException;
/**
@@ -63,6 +78,9 @@
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.10 2005/01/26 17:03:11 matzew
+ * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
+ *
* Revision 1.9 2004/12/13 22:20:34 oros
* fix #1046763: close temporary jar file before trying to delete it
*
@@ -292,30 +310,22 @@
}
}
-
private void feedJarConfig(String jarPath)
throws FacesException
{
try
{
- if (!(_externalContext.getContext() instanceof ServletContext))
- {
- log.error("ServletContext expected");
- return;
- }
- ServletContext servletContext = (ServletContext) _externalContext.getContext();
-
// not all containers expand archives, so we have to do it the generic way:
- // 1. get the stream from servlet context
- InputStream in = servletContext.getResourceAsStream(jarPath);
+ // 1. get the stream from external context
+ InputStream in = _externalContext.getResourceAsStream(jarPath);
if (in == null)
{
if (jarPath.startsWith("/"))
{
- in = servletContext.getResourceAsStream(jarPath.substring(1));
+ in = _externalContext.getResourceAsStream(jarPath.substring(1));
} else
{
- in = servletContext.getResourceAsStream("/" + jarPath);
+ in = _externalContext.getResourceAsStream("/" + jarPath);
}
}
if (in == null)
@@ -348,7 +358,7 @@
if (found)
{
tmp = File.createTempFile("myfaces", ".jar");
- in = servletContext.getResourceAsStream(jarPath);
+ in = _externalContext.getResourceAsStream(jarPath);
FileOutputStream out = new FileOutputStream(tmp);
byte[] buffer = new byte[4096];
int r;
@@ -654,19 +664,13 @@
private String getLifecycleId()
{
- if (_externalContext.getContext() instanceof ServletContext)
- {
- ServletContext context = (ServletContext) _externalContext.getContext();
- String id = context.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
+ String id = _externalContext.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
- if (id != null)
- {
- return id;
- }
- } else
+ if (id != null)
{
- log.warn("No servlet context available, don't know how to obtain LIFECYCLE_ID. Using default!");
+ return id;
}
+
return LifecycleFactory.DEFAULT_LIFECYCLE;
}
}
1.31 +30 -2 incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
Index: JspViewHandlerImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- JspViewHandlerImpl.java 13 Oct 2004 11:50:59 -0000 1.30
+++ JspViewHandlerImpl.java 26 Jan 2005 17:03:12 -0000 1.31
@@ -36,11 +36,18 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderResponse;
+import org.apache.myfaces.portlet.MyFacesGenericPortlet;
/**
* @author Thomas Spiegl (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.31 2005/01/26 17:03:12 matzew
+ * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
+ *
* Revision 1.30 2004/10/13 11:50:59 matze
* renamed packages to org.apache
*
@@ -174,6 +181,14 @@
public String getActionURL(FacesContext facesContext, String viewId)
{
+ if (facesContext.getExternalContext().getResponse() instanceof RenderResponse)
+ {
+ RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
+ PortletURL url = response.createActionURL();
+ url.setParameter(MyFacesGenericPortlet.VIEW_ID, viewId);
+ return url.toString();
+ }
+
String path = getViewIdPath(facesContext, viewId);
if (path.length() > 0 && path.charAt(0) == '/')
{
@@ -209,6 +224,12 @@
ExternalContext externalContext = facesContext.getExternalContext();
String viewId = facesContext.getViewRoot().getViewId();
+
+ if (externalContext.getRequest() instanceof PortletRequest) {
+ externalContext.dispatch(viewId);
+ return;
+ }
+
ServletMapping servletMapping = getServletMapping(externalContext);
if (servletMapping.isExtensionMapping())
{
@@ -240,6 +261,8 @@
ServletResponse response = (ServletResponse) externalContext.getResponse();
response.setLocale(viewToRender.getLocale());
}
+
+ // TODO: 2.5.2.2 for Portlet? What do I do?
externalContext.dispatch(viewId);
@@ -297,6 +320,11 @@
}
ExternalContext externalContext = facescontext.getExternalContext();
+
+ if (externalContext.getRequest() instanceof PortletRequest) {
+ return viewId;
+ }
+
ServletMapping servletMapping = getServletMapping(externalContext);
if (servletMapping.isExtensionMapping())