[Jsf4portlets-devel] SF.net SVN: jsf4portlets: [23] trunk/src
Status: Alpha
Brought to you by:
alonsoft
From: <alo...@us...> - 2007-08-21 15:07:14
|
Revision: 23 http://jsf4portlets.svn.sourceforge.net/jsf4portlets/?rev=23&view=rev Author: alonsoft Date: 2007-08-21 08:07:12 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Early Draft 2 Update Modified Paths: -------------- trunk/src/main/java/javax/portlet/faces/Bridge.java trunk/src/main/java/javax/portlet/faces/GenericFacesPortlet.java trunk/src/main/java/net/sf/jsf4portlets/BridgeConstants.java trunk/src/main/java/net/sf/jsf4portlets/BridgeImpl.java trunk/src/main/java/net/sf/jsf4portlets/RequestScope.java trunk/src/main/java/net/sf/jsf4portlets/application/BridgeLifecycleListener.java trunk/src/main/java/net/sf/jsf4portlets/application/ViewHandlerImpl.java trunk/src/main/java/net/sf/jsf4portlets/config/PortletConfiguration.java trunk/src/main/java/net/sf/jsf4portlets/context/ApplicationMap.java trunk/src/main/java/net/sf/jsf4portlets/context/ExternalContextImpl.java trunk/src/main/java/net/sf/jsf4portlets/context/RenderRequestParameterMap.java trunk/src/main/java/net/sf/jsf4portlets/context/RenderRequestParameterValuesMap.java trunk/src/main/java/net/sf/jsf4portlets/context/SessionMap.java trunk/src/main/java/net/sf/jsf4portlets/ext/PortletPageTag.java trunk/src/main/java/net/sf/jsf4portlets/ext/UIPortletPage.java trunk/src/main/java/net/sf/jsf4portlets/util/PathString.java trunk/src/main/java/net/sf/jsf4portlets/util/Util.java trunk/src/main/resources/META-INF/faces-config.xml trunk/src/main/resources/META-INF/jsf4portlets.tld trunk/src/main/resources/net/sf/jsf4portlets/LogMessages.properties trunk/src/site/apt/user_docs.apt Added Paths: ----------- trunk/src/main/java/javax/portlet/faces/BridgeDefaultViewNotSpecifiedException.java trunk/src/main/java/javax/portlet/faces/BridgeException.java trunk/src/main/java/javax/portlet/faces/BridgeRenderFilter.java trunk/src/main/java/javax/portlet/faces/component/ trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainer.java trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java trunk/src/main/java/javax/portlet/faces/el/ trunk/src/main/java/javax/portlet/faces/el/PortletELResolver.java trunk/src/main/java/net/sf/jsf4portlets/RequestScopeManager.java trunk/src/main/java/net/sf/jsf4portlets/config/ApplicationConfiguration.java trunk/src/main/java/net/sf/jsf4portlets/renderkit/RenderKitFactoryWrapper.java trunk/src/main/java/net/sf/jsf4portlets/renderkit/RenderKitWrapper.java trunk/src/main/java/net/sf/jsf4portlets/renderkit/ResponseStateManagerWrapper.java trunk/src/main/resources/META-INF/services/javax.portlet.faces.Bridge Removed Paths: ------------- trunk/src/main/java/net/sf/jsf4portlets/BridgePhase.java trunk/src/main/java/net/sf/jsf4portlets/application/EncodedByteArrayOutputStream.java trunk/src/main/java/net/sf/jsf4portlets/application/ViewHandlerResponseWrapper.java trunk/src/main/java/net/sf/jsf4portlets/el/ELConstants.java trunk/src/main/java/net/sf/jsf4portlets/el/ImplicitObjectELResolver.java trunk/src/main/java/net/sf/jsf4portlets/renderkit/ResponseStateManagerImpl.java trunk/src/main/resources/javax/ Modified: trunk/src/main/java/javax/portlet/faces/Bridge.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/Bridge.java 2007-07-06 09:25:03 UTC (rev 22) +++ trunk/src/main/java/javax/portlet/faces/Bridge.java 2007-08-21 15:07:12 UTC (rev 23) @@ -3,21 +3,223 @@ import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; -import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; +/** + * The <CODE>Bridge</CODE> interface is used by a portlet to + * execute a JSF artifact. Its lifecycle follows the pattern used by other web + * components such as portlets or servlets, namely: + * <ul> + * <li><code>init</code>: one time (per portlet) initialization. Usually + * invoked during portlet <code>init</code> but may also occur + * lazily. Context is passed to the Bridge at initialization via + * <code>PortletContext</code> attributes. See method description for + * details. + * </li> + * <li><code>doFacesRequest</code>: called for each portlet request that is to + * be handled by Faces. Must only be called after the bridge has been + * initialized. + * </li> + * <li><code>destroy</code>: called to destroy this bridge instance. Usually + * invoked during portlet <code>destroy</code> but may also occur earlier + * if the portlet decides to reclaim resources. + * </li> + * </ul> + * <P> + * Portlet developers are encouraged to allow deployers an ability to configure + * the particular Bridge implementation it uses within a given deployment. This + * ensures a best fit solution for a given application server, portlet container, + * and/or Faces environment. The specifics for this configuation are undefined. + * Each portlet can define a preferred mechanism. Subclasses of + * {@link GenericFacesPortlet} automatically inherit this behavior as it + * recognizes a defined portlet initialization parameter. + * <p> + * Implementations of this <code>Bridge</code> interface are required to have + * a <code>code</code> constructor. + */ + public interface Bridge { + + // Base Bridge attribute/context parameter prefix + public static final String BRIDGE_PACKAGE_PREFIX = "javax.portlet.faces."; + + // Following are the names of context init parameters that control + // Bridge behavior. These are specified in the web.xml + + public static final String MAX_MANAGED_REQUEST_SCOPES = + BRIDGE_PACKAGE_PREFIX + "MAX_MANAGED_REQUEST_SCOPES"; + + public static final String LIFECYCLE_ID = + "javax.faces.LIFECYCLE_ID"; + + // Attribute signifying whether this render is a postback or not. + public static final String IS_POSTBACK_ATTRIBUTE = + BRIDGE_PACKAGE_PREFIX + "isPostback"; + + // Special session attribute name to hold the application_scope in the + // portlet_scope of the session so these are accessible as well. + public static final String APPLICATION_SCOPE_MAP = "javax.portlet.faces.ApplicationScopeMap"; + + + // Following are the names of context attributes that a portlet can set prior + // to calling the bridge's init() method to control Bridge behavior. + + // These attributes are scoped to a specific portlet in the context + // hence to acquire one must include the portlet name within attribute name: + // BRIDGE_PACKAGE_PREFIX + context.getPortletName() + attributeName + + // if "true" indicates the bridge will preserve all the action params in its + // request scope and restore them as parameters in the subsequent renders + public static final String PRESERVE_ACTION_PARAMS = "preserveActionParams"; + + // allows a portlet to control render delgation. A value of "ALWAYS_DELEGATE" indicates + // the bridge doesn't render itself, it merely delegates. A value of "NEVER_DELEGATE" + // indicates the bridge never delegates, rather it always overrides and renders. + // A value of "DEFAULT" indicates the bridge will delegate first and only render + // if the delegatee throws an exception/throwable. + public static final String RENDER_POLICY = "renderPolicy"; - public void init(PortletConfig portletConfig) - throws PortletException; - - public void doFacesRequest(ActionRequest request, ActionResponse response) - throws PortletException; - - public void doFacesRequest(RenderRequest request, RenderResponse response) - throws PortletException; - - public void destroy(); - + + // Parameter that can be added to an ActionURL to signify it is a direct link + // and hence shouldn't be encoded by encodeActionURL as an actionURL + public static final String DIRECT_LINK = BRIDGE_PACKAGE_PREFIX + "DirectLink"; + + // Session attribute pushed by bridge into session scope to give one access + // to Application scope + public static final String SESSION_APPLICATION_SCOPE_MAP = BRIDGE_PACKAGE_PREFIX + + "ApplicationScopeMap"; + + // Request attribute pushed by bridge in renderView to indicate it can + // handle a filter putting the AFTER_VIEW_CONTENT in a buffer on the request. + // Allows rendering order to be preserved in jsps + public static final String RENDER_CONTENT_AFTER_VIEW = BRIDGE_PACKAGE_PREFIX + + "RenderContentAfterView"; + + // Request attribute set by servlet filter in request/responseWrapper to + // place the AFTER_VIEW_CONTENT in a buffer on the request. + // Allows filter to transfer such content back to the bridge/renderView so + // if can output in correct order. Should only be done if + // RENDER_CONTENT_AFTER_VIEW request attribute is true. + public static final String AFTER_VIEW_CONTENT = BRIDGE_PACKAGE_PREFIX + + "AfterViewContent"; + + + // Following are names of request attributes a portlet must set before + // calling the Bridge to process a request + public static final String DEFAULT_VIEWID = BRIDGE_PACKAGE_PREFIX + "defaultViewId"; + + // Following are the names of request attributes the Bridge must set before + // acquiring its first FacesContext/FacesContextFactory in each request + public static final String PORTLET_LIFECYCLE_PHASE = BRIDGE_PACKAGE_PREFIX + "phase"; + + public static final String PORTLET_ISNAMESPACED_PROPERTY = "X-JAVAX-PORTLET-IS-NAMESPACED"; + + // The possible JSR168 portlet lifecycle phazses + public static enum PortletPhase{ + ActionPhase, + RenderPhase + } + + public static enum BridgeRenderPolicy { + DEFAULT, + ALWAYS_DELEGATE, + NEVER_DELEGATE + } + + /** + * Called by the portlet. It indicates that the + * bridge is being placed into service. + * + * <p>The portlet calls the <code>init</code> + * method exactly once before invoking other lifecycle methods. Usually, + * done immediately after instantiating the bridge. + * The <code>init</code> method must complete successfully + * before the bridge can receive any requests. + * + * <p>The portlet cannot place the bridge into service + * if the <code>init</code> method Throws a <code>BridgeException</code>. + * + * <p>Initialization context is passed to bridge via <code>PortletContext</code> + * attributes. The following attributes are defined: + * <ul> + * <li><code>javax.portlet.faces.encodeRedirectURL</code>: + * instructs the bridge to call <code>ExternalContext.encodeActionURL()</code> + * before processing the redirect request. This exists because some (newer) versions + * of JSF 1.2 call <code>encodeActionURL</code> before calling <code>redirect</code> + * while others do not. This flag adjusts the behavior of the bridge in accordance + * with the JSF 1.2 implementation it runs with. + * <li><code>javax.portlet.faces.numManagedActionScopes</code>: defines the maximum + * number of actionScopes this bridge preserves at any given time. Value is + * an integer. ActionScopes are managed on a per Bridge class portlet + * context wide basis. As a typical portlet application uses the same + * bridge implementation for all its Faces based portlets, this means that + * all actionScopes are managed in a single bucket.<br> + * For convenience this interface defines the <code>NUM_MANAGED_ACTIONSCOPES</code> + * constant. + * <li><code>javax.faces.lifecycleID</code>: defines the Faces <code>Lifecycle</code> id + * that bridge uses when acquiring the <code>Faces.Lifecycle</code> via + * which it executes the request. As a context wide attribute, all bridge + * instances in this portlet application will use this lifecyle. + * <li><code>javax.portlet.faces.[portlet name].preserveActionParams</code>: + * instructs the bridge to preserve action parameters in the action scope + * and represent them in subsequent renders. Should be used only when binding + * to a Faces implementation that relies on accessing such parameters during + * its render phase. As this is a portlet/bridge instance specific attribute, + * the <code>PortletContext</code>attribute name is qualified by the portlet + * instance name. This allows different portlets within the same portlet + * application to have different settings.<br> + * For convenience this interfaces defines a number of constants that + * simplifies constructing and/or recognizing this name. + * </ul> + * + * + * @param config a <code>PortletConfig</code> object + * containing the portlet's + * configuration and initialization parameters + * + * @exception PortletException if an exception has occurred that + * interferes with the portlet's normal + * operation. + * @exception UnavailableException if the portlet cannot perform the initialization at this time. + * + * + */ + public void init(PortletConfig config) throws BridgeException; + + /** + * Called by the portlet when it wants the bridge to process an action request. + * + * @param request the request object. + * @param response the response object. + * @throws BridgeDefaultViewNotSpecifiedException thrown if the request indicates + * to the Bridge that is should use the default ViewId and the portlet + * hasn't supplied one. + * @throws BridgeException all other internal exceptions are converted to a + * BridgeException. + */ + public void doFacesRequest(ActionRequest request, ActionResponse response) + throws BridgeDefaultViewNotSpecifiedException, BridgeException; + + /** + * Called by the portlet when it wants the bridge to process a render request. + * + * @param request the request object. + * @param response the response object. + * @throws BridgeDefaultViewNotSpecifiedException thrown if the request indicates + * to the Bridge that is should use the default ViewId and the portlet + * hasn't supplied one. + * @throws BridgeException all other internal exceptions are converted to a + * BridgeException. + */ + public void doFacesRequest(RenderRequest request, RenderResponse response) + throws BridgeDefaultViewNotSpecifiedException, BridgeException; + + /** + * Called by the portlet to take the bridge out of service. Once out of + * service, the bridge must be reinitialized before processing any further + * requests. + */ + public void destroy(); + } Added: trunk/src/main/java/javax/portlet/faces/BridgeDefaultViewNotSpecifiedException.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/BridgeDefaultViewNotSpecifiedException.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/BridgeDefaultViewNotSpecifiedException.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,19 @@ +package javax.portlet.faces; + +public class BridgeDefaultViewNotSpecifiedException extends BridgeException { + public BridgeDefaultViewNotSpecifiedException() { + super(); + } + + public BridgeDefaultViewNotSpecifiedException(String message) { + super(message); + } + + public BridgeDefaultViewNotSpecifiedException(String message, Throwable cause) { + super(message, cause); + } + + public BridgeDefaultViewNotSpecifiedException(Throwable cause) { + super(cause); + } +} Added: trunk/src/main/java/javax/portlet/faces/BridgeException.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/BridgeException.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/BridgeException.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,21 @@ +package javax.portlet.faces; + +import javax.faces.FacesException; + +public class BridgeException extends FacesException { + public BridgeException() { + super(); + } + + public BridgeException(String message) { + super(message); + } + + public BridgeException(String message, Throwable cause) { + super(message, cause); + } + + public BridgeException(Throwable cause) { + super(cause); + } +} Added: trunk/src/main/java/javax/portlet/faces/BridgeRenderFilter.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/BridgeRenderFilter.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/BridgeRenderFilter.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,206 @@ +package javax.portlet.faces; + +import java.io.ByteArrayOutputStream; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.ByteBuffer; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +public class BridgeRenderFilter implements Filter { + + private FilterConfig filterConfig; + + public void destroy() { + filterConfig = null; + } + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + if(!(request instanceof HttpServletRequest) + && !(response instanceof HttpServletResponse)) { + chain.doFilter(request, response); + return ; + } + + if(Boolean.TRUE.equals(request.getAttribute(Bridge.RENDER_CONTENT_AFTER_VIEW))) { + BridgeRenderResponseWrapper bridgeResponse = new BridgeRenderResponseWrapper( + (HttpServletResponse) response); + chain.doFilter(request, bridgeResponse); + if(bridgeResponse.isBytes()) { + request.setAttribute(Bridge.AFTER_VIEW_CONTENT, + bridgeResponse.getBytes()); + } else { + request.setAttribute(Bridge.AFTER_VIEW_CONTENT, + bridgeResponse.getChars()); + } + } else { + chain.doFilter(request, response); + } + } + + public void init(FilterConfig filterConfig) + throws ServletException { + this.filterConfig = filterConfig; + } + + public FilterConfig getFilterConfig() { + return filterConfig; + } + + public ServletContext getServletContext() { + return filterConfig.getServletContext(); + } + + private class BridgeRenderResponseWrapper extends HttpServletResponseWrapper { + + private ByteArrayWebOutputStream basos; + private PrintWriter pw ; + private CharArrayWriter caw; + private int status = HttpServletResponse.SC_OK; + + public BridgeRenderResponseWrapper(HttpServletResponse response) { + super(response); + } + + @Override + public void sendError(int sc, String msg) throws IOException { + super.sendError(sc, msg); + status = sc; + } + + @Override + public void sendError(int sc) throws IOException { + super.sendError(sc); + status = sc; + } + + @Override + public void setStatus(int sc) { + super.setStatus(sc); + status = sc; + } + + @Override + public void setStatus(int sc, String sm) { + super.setStatus(sc, sm); + status = sc; + } + + + public int getStatus() { + return status; + } + + public boolean isBytes() { + return (null != basos); + } + + public boolean isChars() { + return (null != caw); + } + + public byte[] getBytes() { + byte[] result = null; + if (null != basos) { + result = basos.toByteArray(); + } + return result; + } + + public char[] getChars() { + char[] result = null; + if (null != caw) { + result = caw.toCharArray(); + } + return result; + } + + public String toString() { + String result = null; + if (null != caw) { + result = caw.toString(); + } else if (null != basos) { + result = basos.toString(); + } + return result; + } + + public void resetBuffers() throws IOException { + if (null != caw) { + caw.reset(); + } else if (null != basos) { + basos.resetByteArray(); + } + } + + public ServletOutputStream getOutputStream() throws IOException { + if (pw != null) { + throw new IllegalStateException(); + } + if (null == basos) { + basos = new ByteArrayWebOutputStream(); + } + return basos; + } + + public PrintWriter getWriter() throws IOException { + if (basos != null) { + throw new IllegalStateException(); + } + if (null == pw) { + caw = new CharArrayWriter(1024); + pw = new PrintWriter(caw); + } + + return pw; + } + + } + + private static class ByteArrayWebOutputStream extends ServletOutputStream { + + private ByteBufferOutputStream bbos; + + public ByteArrayWebOutputStream() { + bbos = new ByteBufferOutputStream(1024); + } + + public void resetByteArray() { + bbos.reset(); + } + + public byte[] toByteArray() { + return bbos.toByteArray(); + } + + public void write(int n) { + bbos.write(n); + } + + } + + private static class ByteBufferOutputStream extends ByteArrayOutputStream { + + public ByteBufferOutputStream(int initialCapacity) { + super(initialCapacity); + } + + public ByteBuffer getByteBuffer() { + return ByteBuffer.wrap(buf, 0, count); + } + + } + +} Modified: trunk/src/main/java/javax/portlet/faces/GenericFacesPortlet.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2007-07-06 09:25:03 UTC (rev 22) +++ trunk/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2007-08-21 15:07:12 UTC (rev 23) @@ -1,15 +1,23 @@ +/* Copyright (c) 2007, Oracle. All rights reserved. + * Use is subject to license terms. + */ + + + package javax.portlet.faces; +import java.io.BufferedReader; import java.io.IOException; -import java.util.Enumeration; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.logging.Logger; -import javax.faces.FacesException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +import java.util.Properties; + import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; -import javax.portlet.Portlet; +import javax.portlet.GenericPortlet; import javax.portlet.PortletConfig; import javax.portlet.PortletContext; import javax.portlet.PortletException; @@ -17,174 +25,319 @@ import javax.portlet.PortletRequest; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import javax.portlet.UnavailableException; +import javax.portlet.WindowState; -public class GenericFacesPortlet implements Portlet, PortletConfig { - private static Logger logger = Logger - .getLogger(GenericFacesPortlet.class.getPackage().getName()); - - public static final String LIFECYCLE_ID_ATTR = - "javax.portlet.faces.extension.LIFECYCLE_ID"; - - public static final String BRIDGE_CLASS_ATTR = - "javax.portlet.faces.extension.bridgeClass"; - - public static final String INIT_VIEW = - "javax.portlet.faces.extension.INIT_VIEW"; - - public static final String INIT_EDIT = - "javax.portlet.faces.extension.INIT_EDIT"; - - public static final String INIT_HELP = - "javax.portlet.faces.extension.INIT_HELP"; - - private Bridge bridge; - - private PortletConfig portletConfig; - - public void init(PortletConfig portletConfig) - throws PortletException { - this.portletConfig = portletConfig; - - logger.finest("Initializing portlet: " + getPortletName()); - - String bridgeClassName = portletConfig - .getInitParameter(BRIDGE_CLASS_ATTR); - if(bridgeClassName == null) { - bridgeClassName = getPortletContext() - .getInitParameter(BRIDGE_CLASS_ATTR); - } - if(bridgeClassName == null) { - throw new UnavailableException("Missed parameter: " - + BRIDGE_CLASS_ATTR); - } - - try { - Class bridgeClass = Class.forName(bridgeClassName); - bridge = (Bridge) bridgeClass.newInstance(); - } catch(Exception e) { - throw new UnavailableException(e.getLocalizedMessage()); - } - - bridge.init(portletConfig); - init(); - logger.finest("Portlet '" + getPortletName() + "' initialized."); - } - - public void init() throws PortletException { } - public void processAction(ActionRequest request, ActionResponse response) - throws PortletException, IOException { - logger.entering(GenericFacesPortlet.class.getName(), - "processAction", new Object[]{ request, response }); - - storeViewIdParameter(request); - try { - bridge.doFacesRequest(request, response); - } catch(FacesException e) { - Throwable t = e.getCause(); - if(t == null) { - throw new PortletException(e); - } else { - if(t instanceof IOException) { - throw ((IOException) t); - } - throw new PortletException(t); - } - } - - logger.exiting(GenericFacesPortlet.class.getName(), "processAction"); - } - - public void render(RenderRequest request, RenderResponse response) - throws PortletException, IOException { - logger.entering(GenericFacesPortlet.class.getName(), - "render", new Object[]{ request, response }); - - storeViewIdParameter(request); - try { - bridge.doFacesRequest(request, response); - } catch(FacesException e) { - Throwable t = e.getCause(); - if(t == null) { - throw new PortletException(e); - } else { - if(t instanceof IOException) { - throw ((IOException) t); - } - throw new PortletException(t); - } - } - - logger.exiting(GenericFacesPortlet.class.getName(), "render"); - } - - public void destroy() { - bridge.destroy(); - logger.finest("Portlet '" + getPortletName() + "' destroyed."); - - bridge = null; - portletConfig = null; - } +/** + * The <code>GenericFacesPortlet</code> is provided to simplify development of a + * portlet that in whole or part relies on the Faces bridge to process requests. + * If all requests are to be handled by the bridge, <code>GenericFacesPortlet</code> + * is a turnkey implementation. Developers do not need to subclass it. + * However, if there are some situations where the portlet doesn't require + * bridge services then <code>GenericFacesPortlet</code> can be subclassed and overriden.<p> + * Since <code>GenericFacesPortlet</code> subclasses <code>GenericPortlet</code> + * care is taken to all subclasses to override naturally. For example, though + * <code>doDispatch()</code> is overriden, requests are only dispatched to the + * bridge from here if the <code>PortletMode</code> isn't <code>VIEW</code>, + * <code>EDIT</code>, or <code>HELP</code>.<p> + * The <code>GenericFacesPortlet</code> recognizes the following portlet init + * parameters: + * <ul> + * <li><code>javax.portlet.faces.defaultViewId.[<i>mode</i>]</code>: + * specifies on a per mode basis the default viewId the Bridge executes + * when not already encoded in the incoming request. A value must be + * defined for each <code>PortletMode</code> the <code>Bridge</code> is + * expected to process. + * </li> + * </ul> + * The <code>GenericFacesPortlet</code> recognizes the following <code> + * PortletContext</code> init parameters: + * <ul> + * <li><code>javax.portlet.faces.BridgeImplClass</code>: specifies the + * <code>Bridge</code>implementation class used by this portlet. This + * init parameter must be specified or else an exception is thrown. + * </li> + * </ul> + */ +public class GenericFacesPortlet extends GenericPortlet +{ + public final static String BRIDGE_CLASS = Bridge.BRIDGE_PACKAGE_PREFIX + "BridgeClassName"; + public final static String BRIDGE_SERVICE_CLASSPATH = "META-INF/services/javax.portlet.faces.Bridge"; + + private Class mFacesBridgeClass = null; + private Bridge mFacesBridge = null; + + /** + * Initialize generic faces portlet from portlet.xml + */ + public void init(PortletConfig portletConfig) + throws PortletException + { + super.init(portletConfig); + + // Make sure the bridge impl class is defined -- if not then search for it + // using same search rules as Faces + String bridgeClassName = getBridgeClassName(); + + if (bridgeClassName != null) { + try { + mFacesBridgeClass = Class.forName(bridgeClassName); + } catch (ClassNotFoundException cnfe) { + // Do nothing and fall through to null check + } + } + + if (mFacesBridgeClass == null) + { + throw new PortletException("Configuration Error: Initial Parameter '" + + BRIDGE_CLASS + + "' is not defined for portlet: " + + getPortletName()); + } - public String getInitParameter(String name) { - return portletConfig.getInitParameter(name); - } - - public Enumeration getInitParameterNames() { - return portletConfig.getInitParameterNames(); - } - - public PortletConfig getPortletConfig() { - return portletConfig; - } - - public PortletContext getPortletContext() { - return portletConfig.getPortletContext(); - } - - public String getPortletName() { - return portletConfig.getPortletName(); - } - - public ResourceBundle getResourceBundle(Locale locale) { - return portletConfig.getResourceBundle(locale); - } - - protected Bridge getBridge() { - return bridge; - } - - private void storeViewIdParameter(PortletRequest request) - throws PortletException { - PortletMode portletMode = request.getPortletMode(); - - // Check whether the requested mode is allowed - if(!request.isPortletModeAllowed(portletMode)) { - throw new PortletException(portletMode + " is not allowed"); + // Context level attribute for whether to encode redirect URL + String renderPolicy = + this.getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX + Bridge.RENDER_POLICY); + if (renderPolicy != null) + this.getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + + this.getPortletName() + "." + Bridge.RENDER_POLICY, + Bridge.BridgeRenderPolicy.valueOf(renderPolicy)); + String preserveActionParams = + this.getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX + Bridge.PRESERVE_ACTION_PARAMS); + if (preserveActionParams != null) + this.getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + + this.getPortletName() + "." + Bridge.PRESERVE_ACTION_PARAMS, + Boolean.valueOf(preserveActionParams)); + + // Don't instanciate/initialize the bridge yet. Do it on first use + } + + /** + * Release resources + */ + public void destroy() + { + if (mFacesBridge != null) + { + mFacesBridge.destroy(); + mFacesBridge = null; + mFacesBridgeClass = null; } - - String viewId = null; - // Get the view identifier based on the mode. - if(PortletMode.VIEW.equals(portletMode)) { - viewId = getPortletConfig().getInitParameter(INIT_VIEW); - } else if(PortletMode.EDIT.equals(portletMode)) { - viewId = getPortletConfig().getInitParameter(INIT_EDIT); - } else if(PortletMode.HELP.equals(portletMode)) { - viewId = getPortletConfig().getInitParameter(INIT_HELP); - } + } + + /** + * If mode is VIEW, EDIT, or HELP -- defer to the doView, doEdit, doHelp + * so subclasses can override. Otherwise handle mode here if there is a + * defaultViewId mapping for it. + */ + public void doDispatch(RenderRequest request, RenderResponse response) + throws PortletException, IOException + { + // Defer to helper methods for standard modes so subclasses can override + PortletMode mode = request.getPortletMode(); + if (mode == PortletMode.EDIT || + mode == PortletMode.HELP || + mode == PortletMode.VIEW) + { + super.doDispatch(request, response); + } else + { + doDispatchInternal(request, response, request.getPortletMode()); + } + } + + protected void doEdit(RenderRequest request, + RenderResponse response) + throws PortletException, + java.io.IOException + { + doDispatchInternal(request, response, request.getPortletMode()); - if(viewId == null) { - if(PortletMode.VIEW.equals(portletMode)) { - throw new PortletException("Portlet '" + getPortletName() - + "' misses a default view page. "); - } - throw new PortletException("Portlet '" + getPortletName() - + "' misses a default viewId for portlet mode: " + portletMode); + } + + protected void doHelp(RenderRequest request, + RenderResponse response) + throws PortletException, + java.io.IOException + { + doDispatchInternal(request, response, request.getPortletMode()); + + } + + protected void doView(RenderRequest request, + RenderResponse response) + throws PortletException, + java.io.IOException + { + doDispatchInternal(request, response, request.getPortletMode()); + + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException + { + doBridgeDispatch(request, response, getDefaultViewId(request, request.getPortletMode())); + } + + /** + * Returns the className of the bridge implementation this portlet uses. + * Subclasses override to alter the default behavior. + * Default implementation first checks for a portlet context init parameter: + * javax.portlet.faces.BridgeImplClass. If it doesn't exist then it looks for + * the resource file "/META-INF/services/javax.portlet.faces.Bridge" using the + * current threads classloader and extracts the classname from the first + * line in that file. + * + * @return the class name of the Bridge class the GenericFacesPortlet uses. + * null if it can't be determined. + */ + public String getBridgeClassName() { + String bridgeClassName = + this.getPortletConfig().getPortletContext().getInitParameter(BRIDGE_CLASS); + + if (bridgeClassName == null) { + bridgeClassName = getFromServicesPath(this.getPortletConfig().getPortletContext(), BRIDGE_SERVICE_CLASSPATH); } + return bridgeClassName; + } + + /** + * Returns the defaultViewId to be used for this request. The defaultViewId + * is depends on the PortletMode. + * + * @param request the request object. + * @param mode the mode which to return the defaultViewId for. + * @return the defaultViewId for this mode + */ + public String getDefaultViewId(PortletRequest request, PortletMode mode) + { + return this.getPortletConfig().getInitParameter(Bridge.DEFAULT_VIEWID + "." + + mode.toString()); + } + + private void doDispatchInternal(RenderRequest request, RenderResponse response, PortletMode mode) + throws PortletException, IOException + { + // Only process if there is a default page defined for this mode + String modeDefaultViewId = getDefaultViewId(request, mode); - request.setAttribute("javax.portlet.faces.defaultViewId", viewId); - logger.fine("Default viewId for mode '" + portletMode + "': " + viewId); - } - + if (!(modeDefaultViewId == null)) + { + WindowState state = request.getWindowState(); + if (!state.equals(WindowState.MINIMIZED)) + { + doBridgeDispatch(request, response, modeDefaultViewId); + } + } + else + { + super.doDispatch(request, response); + } + } + + private void doBridgeDispatch(RenderRequest request, RenderResponse response, String defaultViewId) + throws PortletException + { + // initial Bridge if not already active + initBridge(); + // Push information for Bridge into request attributes + setBridgeRequestContext(request, defaultViewId); + try { + mFacesBridge.doFacesRequest(request, response); + } catch (BridgeException e) { + throw new PortletException( + "doBridgeDispatch failed: error from Bridge in executing the request", e); + } + + } + + private void doBridgeDispatch(ActionRequest request, ActionResponse response, String defaultViewId) + throws PortletException + { + // initial Bridge if not already active + initBridge(); + // Push information for Bridge into request attributes + setBridgeRequestContext(request, defaultViewId); + try { + mFacesBridge.doFacesRequest(request, response); + } catch (BridgeException e) { + throw new PortletException( + "doBridgeDispatch failed: error from Bridge in executing the request", e); + } + + } + + private void initBridge() throws PortletException + { + if (mFacesBridge == null) + { + try + { + mFacesBridge = (Bridge) mFacesBridgeClass.newInstance(); + mFacesBridge.init(this.getPortletConfig()); + } catch (Exception e) + { + throw new PortletException( + "doBridgeDisptach: error instantiating the bridge class", e); + } + } + } + + private void setBridgeRequestContext(PortletRequest request, String defaultViewId) { + // Make the defaultViewId available to the Bridge + request.setAttribute(Bridge.DEFAULT_VIEWID, defaultViewId); + } + + private String getFromServicesPath(PortletContext context, String resourceName) { + // Check for a services definition + String result = null; + BufferedReader reader = null; + InputStream stream = null; + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) return null; + + stream = cl.getResourceAsStream(resourceName); + if (stream != null) { + // Deal with systems whose native encoding is possibly + // different from the way that the services entry was created + try { + reader = + new BufferedReader(new InputStreamReader(stream, + "UTF-8")); + } catch (UnsupportedEncodingException e) { + reader = new BufferedReader(new InputStreamReader(stream)); + } + result = reader.readLine(); + if (result != null) + result = result.trim(); + reader.close(); + reader = null; + stream = null; + } + } catch (IOException e) { + } catch (SecurityException e) { + } finally { + if (reader != null) { + try { + reader.close(); + stream = null; + } catch (Throwable t) { + ; + } + reader = null; + } + if (stream != null) { + try { + stream.close(); + } catch (Throwable t) { + ; + } + stream = null; + } + } + return result; + } + + } Added: trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainer.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainer.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainer.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,23 @@ +/* Copyright (c) 2007, Oracle. All rights reserved. + * Use is subject to license terms. + */ + +package javax.portlet.faces.component; + +import javax.faces.component.NamingContainer; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; + + +/** + * <p><strong>PortletNamingContainer</strong> is an interface that must be + * implemented by any UIViewRoot that wants to be used in a Portlet Bridge + * environment. It indicates that this the component (usually a UIViewRoot) + * that implements this <code>NamingContainer</code> incorporates + * the consumer provided portlet namespaceId into the id returned from + * <code>getContainerClientId</code>. This is merely a marker interface + */ + +public interface PortletNamingContainer extends NamingContainer { + +} Added: trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,79 @@ +/* Copyright (c) 2007, Oracle. All rights reserved. + * Use is subject to license terms. + */ + +package javax.portlet.faces.component; + +import java.io.IOException; +import java.io.Serializable; + +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.el.MethodExpression; +import javax.el.ValueExpression; + +import javax.faces.FacesException; +import javax.faces.component.ContextCallback; +import javax.faces.context.FacesContext; +import javax.faces.event.FacesEvent; +import javax.faces.event.PhaseListener; +import javax.faces.component.NamingContainer; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.context.ExternalContext; +import javax.faces.el.ValueBinding; + +import javax.portlet.PortletRequest; +import javax.portlet.faces.component.PortletNamingContainer; + + +/** + * Bridge ViewRoot that implements NamingContainer which uses the + * ExternalContext.encodeNamespace to introduce the consumer namespace + * into tree components. + */ + +public class PortletNamingContainerUIViewRoot extends UIViewRoot implements PortletNamingContainer, Serializable { + + private static final String SEPARATOR = (new Character(NamingContainer.SEPARATOR_CHAR)).toString(); + + public PortletNamingContainerUIViewRoot() { + super(); + } + + public PortletNamingContainerUIViewRoot(UIViewRoot viewRootToReplace) { + super(); + setViewId(viewRootToReplace.getViewId()); + setLocale(viewRootToReplace.getLocale()); + setRenderKitId(viewRootToReplace.getRenderKitId()); + } + + // Implement the method that satisfies NamingContainer + public static String getContainerClientId(FacesContext context, String additionalId) { + ExternalContext ec = context.getExternalContext(); + String namespace = ec.encodeNamespace(SEPARATOR); + + /* In servlet world encodeNamespace does nothing -- so if we get back + * what we sent in then do not perturn the NamingContainer Id + */ + if (namespace.length() > 1) { + if (additionalId != null) + return namespace + additionalId; + else + return namespace; + } else { + return null; + } + } + + // Implement the method that satisfies NamingContainer + public String getContainerClientId(FacesContext context) { + return PortletNamingContainerUIViewRoot.getContainerClientId( + context, super.getContainerClientId(context)); + } + + +} Added: trunk/src/main/java/javax/portlet/faces/el/PortletELResolver.java =================================================================== --- trunk/src/main/java/javax/portlet/faces/el/PortletELResolver.java (rev 0) +++ trunk/src/main/java/javax/portlet/faces/el/PortletELResolver.java 2007-08-21 15:07:12 UTC (rev 23) @@ -0,0 +1,198 @@ +/* Copyright (c) 2007, Oracle. All rights reserved. + * Use is subject to license terms. + */ + + +package javax.portlet.faces.el; + +import java.beans.FeatureDescriptor; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.el.ELContext; +import javax.el.ELException; +import javax.el.ELResolver; +import javax.el.PropertyNotFoundException; +import javax.el.PropertyNotWritableException; + +import javax.faces.context.FacesContext; +import javax.faces.context.ExternalContext; + +import javax.portlet.PortletConfig; +import javax.portlet.PortletRequest; + +import javax.portlet.faces.Bridge; + + +public class PortletELResolver extends ELResolver { + + // Important preserve index (order) between array and constants + public static final String[] IMPLICIT_OBJECTS = new String[] { + "portletConfig", "sessionApplicationScope", "sessionPortletScope", "portletPreferenceValue", "portletPreferenceValues" }; + + public static final int PORTLET_CONFIG = 0; + public static final int SESSION_APPLICATION_SCOPE = 1; + public static final int SESSION_PORTLET_SCOPE = 2; + public static final int PORTLET_PREFERENCE_VALUE = 3; + public static final int PORTLET_PREFERENCE_VALUES = 4; + + public PortletELResolver() { + } + + public Object getValue(ELContext context, Object base, Object property) + throws ELException { + // variable resolution is a special case of property resolution + // where the base is null. + if (base != null) { + return null; + } + if (property == null) { + throw new PropertyNotFoundException("Null property"); + } + + FacesContext facesContext = + (FacesContext) context.getContext(FacesContext.class); + ExternalContext extCtx = facesContext.getExternalContext(); + + // only process if running in a portlet request + if (!(extCtx.getRequest() instanceof PortletRequest)) { + return null; + } + + int index = Arrays.binarySearch(IMPLICIT_OBJECTS, property); + if (index < 0) { + return null; + } else { + switch (index) { + case PORTLET_CONFIG: + context.setPropertyResolved(true); + return context.getContext(PortletConfig.class); + case SESSION_APPLICATION_SCOPE: + context.setPropertyResolved(true); + return extCtx.getSessionMap().get(Bridge.APPLICATION_SCOPE_MAP); + case SESSION_PORTLET_SCOPE: + context.setPropertyResolved(true); + return extCtx.getSessionMap(); + case PORTLET_PREFERENCE_VALUE: + context.setPropertyResolved(true); + return getPreferencesValueMap(extCtx); + case PORTLET_PREFERENCE_VALUES: + context.setPropertyResolved(true); + return ((PortletRequest)extCtx.getRequest()).getPreferences().getMap(); + default: + return null; + } + } + } + + public void setValue(ELContext context, Object base, Object property, + Object val) throws ELException { + if (base != null) { + return; + } + if (property == null) { + throw new PropertyNotFoundException("Null property"); + } + + int index = Arrays.binarySearch(IMPLICIT_OBJECTS, property); + if (index >= 0) { + throw new PropertyNotWritableException((String)property); + } + } + + public boolean isReadOnly(ELContext context, Object base, Object property) + throws ELException{ + if (base != null) { + return false; + } + if (property == null) { + throw new PropertyNotFoundException("Null property"); + } + + int index = Arrays.binarySearch(IMPLICIT_OBJECTS, property); + if (index >= 0) { + context.setPropertyResolved(true); + return true; + } + return false; + } + + public Class<?> getType(ELContext context, Object base, Object property) + throws ELException { + if (base != null) { + return null; + } + if (property == null) { + throw new PropertyNotFoundException("Null property"); + } + + int index = Arrays.binarySearch(IMPLICIT_OBJECTS, property); + if (index >= 0) { + context.setPropertyResolved(true); + } + return null; + } + + public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { + if (base != null) { + return null; + } + ArrayList<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(14); + list.add(getFeatureDescriptor("portletConfig", "portletConfig", + "portletConfig",false, false, true, Object.class, Boolean.TRUE)); + list.add(getFeatureDescriptor("sessionApplicationScope", "sessionApplicationScope", + "sessionApplicationScope",false, false, true, Map.class, Boolean.TRUE)); + list.add(getFeatureDescriptor("sessionPortletScope", "sessionPortletScope", + "sessionPortletScope",false, false, true, Map.class, Boolean.TRUE)); + list.add(getFeatureDescriptor("portletPreferenceValue", "portletPreferenceValue", + "portletPreferenceValue",false, false, true, Map.class, Boolean.TRUE)); + list.add(getFeatureDescriptor("portletPreferenceValues", "portletPreferenceValues", + "portletPreferenceValues",false, false, true, Map.class, Boolean.TRUE)); + return list.iterator(); + + } + + public Class<?> getCommonPropertyType(ELContext context, Object base) { + if (base != null) { + return null; + } + return String.class; + } + + private FeatureDescriptor getFeatureDescriptor(String name, String + displayName, String desc, boolean expert, boolean hidden, + boolean preferred, Object type, Boolean designTime) { + + FeatureDescriptor fd = new FeatureDescriptor(); + fd.setName(name); + fd.setDisplayName(displayName); + fd.setShortDescription(desc); + fd.setExpert(expert); + fd.setHidden(hidden); + fd.setPreferred(preferred); + fd.setValue(ELResolver.TYPE, type); + fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, designTime); + return fd; + } + + private Map getPreferencesValueMap(ExternalContext extCtx) { + PortletRequest portletRequest = (PortletRequest) extCtx.getRequest(); + Enumeration e = portletRequest.getPreferences().getNames(); + Map m = null; + + while (e.hasMoreElements()) { + if (m == null) + m = new HashMap(); + String name = (String) e.nextElement(); + String value = portletRequest.getPreferences().getValue(name, null); + if (value != null) + m.put(name, value); + } + return m; + } + +} Modified: trunk/src/main/java/net/sf/jsf4portlets/BridgeConstants.java =================================================================== --- trunk/src/main/java/net/sf/jsf4portlets/BridgeConstants.java 2007-07-06 09:25:03 UTC (rev 22) +++ trunk/src/main/java/net/sf/jsf4portlets/BridgeConstants.java 2007-08-21 15:07:12 UTC (rev 23) @@ -27,40 +27,10 @@ * */ public final class BridgeConstants { - - // JSR-252 Constants - public static final String AFTER_VIEW_CONTENT = - "javax.faces.AfterViewContent"; - // JSR-301 Constants - /** - * Identifies the PORTLET_SCOPE in the <tt>PortletSession</tt> - */ - public static final String APPLICATION_SCOPE_MAP = - "javax.portlet.faces.ApplicationScopeMap"; - - /** - * Identifies the current bridge phase for request which belongs to - */ - public static final String BRIDGE_PHASE = - "javax.portlet.faces.phase"; - - /** - * Default <tt>viewId</tt> that will be used when the request - * doesn't specifies one. - */ - public static final String DEFAULT_VIEW_ID = - "javax.portlet.faces.defaultViewId"; - /** - * Boolean flag used to mark a URL as an external link - */ - public static final String DIRECT_LINK = - "_javax.portlet.faces.DirectLink"; - - /** * Boolean flag used to know if URL should be * encoded before performing a redirect call. */ @@ -74,11 +44,11 @@ public static final String PRESERVE_ACTION_PARAMS = "javax.portlet.faces.PRESERVE_ACTION_PARAMS"; - public static final String RENDER_AFTER_VIEW_CONTEXT = - "javax.portlet.faces.RenderAfterViewContext"; - // Implementation constants + public static final String FACES_PREFIX = + "net.sf.jsf4portlets."; + /** * Context initialization parameter used to check for * an alternative InjectionProvider instace @@ -100,6 +70,9 @@ public static final String REQUEST_SCOPE = "net.sf.jsf4portlets.REQUEST_SCOPE"; + public static final String REQUEST_SCOPE_MANAGER = + "net.sf.jsf4portlets.REQUEST_SCOPE_MANAGER"; + /** * URL parameter used to pass to the bridge * the viewId that should be processed. Modified: trunk/src/main/java/net/sf/jsf4portlets/BridgeImpl.java =================================================================== --- trunk/src/main/java/net/sf/jsf4portlets/BridgeImpl.java 2007-07-06 09:25:03 UTC (rev 22) +++ trunk/src/main/java/net/sf/jsf4portlets/BridgeImpl.java 2007-08-21 15:07:12 UTC (rev 23) @@ -20,20 +20,12 @@ */ package net.sf.jsf4portlets; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; import java.util.ResourceBundle; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.faces.FacesException; import javax.faces.FactoryFinder; -import javax.faces.application.FacesMessage; -import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.context.FacesContextFactory; import javax.faces.lifecycle.Lifecycle; @@ -42,19 +34,12 @@ import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletContext; -import javax.portlet.PortletException; -import javax.portlet.PortletMode; import javax.portlet.PortletRequest; -import javax.portlet.PortletSession; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.faces.Bridge; -import javax.portlet.faces.GenericFacesPortlet; +import javax.portlet.faces.BridgeException; -import net.sf.jsf4portlets.config.ManagedBeanBean; -import net.sf.jsf4portlets.config.PortletConfiguration; -import net.sf.jsf4portlets.util.Util; - /** * Default JSF Bridge Implementation. * @@ -63,85 +48,30 @@ * */ public class BridgeImpl implements Bridge { + private final Logger logger = Logger.getLogger( BridgeImpl.class.getPackage().getName(), "net.sf.jsf4portlets.LogMessages"); - - private static final String VIEW_ATTR = - "net.sf.jsf4portlets.VIEW"; - private static final String EDIT_ATTR = - "net.sf.jsf4portlets.EDIT"; - - private static final String HELP_ATTR = - "net.sf.jsf4portlets.HELP"; - - private static final String CUSTOM_ATTR = - "net.sf.jsf4portlets.CUSTOM"; - - private static final String PREVIOUS_REQUEST_SCOPE = - "net.sf.jsf4portlets.PREVIOUS_REQUEST_SCOPE"; - - private static final Set<String> TRANSIENT_REQUEST_ATTRS; - - static { - Set<String> attrs = new HashSet<String>(); - attrs.add(BridgeConstants.AFTER_VIEW_CONTENT); - attrs.add(BridgeConstants.BRIDGE_PHASE); - attrs.add(BridgeConstants.DEFAULT_VIEW_ID); - attrs.add(BridgeConstants.ENCODE_REDIRECT_URL); - attrs.add(BridgeConstants.PORTLET_CONFIG); - attrs.add(BridgeConstants.PRESERVE_ACTION_PARAMS); - attrs.add(BridgeConstants.RENDER_AFTER_VIEW_CONTEXT); - attrs.add(BridgeConstants.REQUEST_SCOPE); - attrs.add("javax.portlet.request"); - attrs.add("javax.portlet.response"); - attrs.add("javax.portlet.http_session_id"); - attrs.add("javax.servlet.include.context_path"); - attrs.add("javax.portlet.session_invalid"); - attrs.add("javax.portlet.portletc.httpServletRequest"); - attrs.add("javax.portlet.portletc.httpServletResponse"); - attrs.add("javax.portlet.portletc.portletname"); - TRANSIENT_REQUEST_ATTRS = Collections.unmodifiableSet(attrs); - } - private PortletConfig portletConfig = null; - private boolean encodeRedirectURL = false; - - private boolean preserveActionParams = false; - private FacesContextFactory facesContextFactory = null; private Lifecycle lifecycle = null; + private RequestScopeManager requestScopeManager = null; + public void init(PortletConfig portletConfig) - throws PortletException { + throws BridgeException { this.portletConfig = portletConfig; logger.log(Level.FINEST, "J4P_000001", getPortletName()); - if("true".equals(initParam( - BridgeConstants.ENCODE_REDIRECT_URL))) { - encodeRedirectURL = true; - } - if("true".equals(initParam( - BridgeConstants.PRESERVE_ACTION_PARAMS))) { - preserveActionParams = true; - } - - getPortletContext().setAttribute("javax.portlet.faces." - + getPortletName() + ".ENCODE_REDIRECT_URL", - Boolean.valueOf(encodeRedirectURL)); - getPortletContext().setAttribute("javax.portlet.faces." - + getPortletName() + ".PRESERVE_ACTION_PARAMS", - Boolean.valueOf(preserveActionParams)); - init(); logger.log(Level.FINEST, "J4P_000002", getPortletName()); } - public void init() throws PortletException { } + public void init() throws BridgeException { } public void destroy() { logger.log(Level.FINEST, "J4P_000003", getPortletName()); @@ -152,11 +82,11 @@ } public void doFacesRequest(ActionRequest request, ActionResponse response) - throws PortletException { + throws BridgeException { logger.entering(BridgeImpl.class.getName(), "doFacesRequest", new Object[]{ request, response }); - initRequest(request, BridgePhase.ACTION_PHASE); + initRequest(request, Bridge.PortletPhase.ActionPhase); // Acquire the FacesContext instance for this request ... [truncated message content] |