JBoss Ajax4JSF SVN: r57 - trunk/test/src/main/java/org/ajax4jsf/tests.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-08 17:37:27 -0400 (Sun, 08 Apr 2007)
New Revision: 57
Added:
trunk/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java
Modified:
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
Log:
Test environment modifications to handle requestContextPath properly
MockViewRoot class added
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-08 15:01:42 UTC (rev 56)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-08 21:37:27 UTC (rev 57)
@@ -44,7 +44,6 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxViewRoot;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl;
import org.ajax4jsf.framework.resource.InternetResource;
@@ -107,7 +106,7 @@
vcpRenderKitFactory.addRenderKit("HTML_CHAMELEON", vcpRenderKit);
renderKit.addRenderer(UIViewRoot.COMPONENT_FAMILY, UIViewRoot.COMPONENT_TYPE, new AjaxViewRootRenderer());
// setup nessesary components.
- application.addComponent("javax.faces.ViewRoot", AjaxViewRoot.class.getName());
+ application.addComponent("javax.faces.ViewRoot", MockViewRoot.class.getName());
// setup AjaxContext.
ajaxContext = new AjaxContext();
request.setAttribute(AjaxContext.AJAX_CONTEXT_KEY, ajaxContext);
@@ -189,9 +188,11 @@
webConnection = new MockWebConnection(webClient) {
public WebResponse getResponse(WebRequestSettings settings)
throws IOException {
- if (settings.getURL().getFile().startsWith(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX)) {
+ String testResourceContextPath = facesContext.getExternalContext().getRequestContextPath() +
+ AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX;
+ if (settings.getURL().getFile().startsWith(testResourceContextPath)) {
InternetResource resource = InternetResourceBuilder.getInstance().getResource(
- settings.getURL().getFile().substring(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX.length()));
+ settings.getURL().getFile().substring(testResourceContextPath.length()));
final MockFacesResourceContext resourceContext = new MockFacesResourceContext(facesContext);
resource.sendHeaders(resourceContext);
@@ -407,7 +408,7 @@
*/
protected Page processResponse() throws Exception {
setupWebClient();
- URL page = new URL( "http:"+facesContext.getViewRoot().getViewId());
+ URL page = new URL( "http:"+ facesContext.getExternalContext().getRequestContextPath() + facesContext.getViewRoot().getViewId());
try {
char[] content = ((MockPrintWriter) response.getWriter()).content();
webConnection.setResponse(page,String.valueOf(content),response.getStatus(), "OK", response.getContentType(), Collections.EMPTY_LIST);
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-04-08 15:01:42 UTC (rev 56)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-04-08 21:37:27 UTC (rev 57)
@@ -38,11 +38,4 @@
//System.out.println(".writeState()");
}
- public String getResourceURL(FacesContext context, String url) {
- return url;
- }
-
- public String getActionURL(FacesContext context, String url) {
- return url;
- }
}
\ No newline at end of file
Added: trunk/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java (rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java 2007-04-08 21:37:27 UTC (rev 57)
@@ -0,0 +1,49 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.tests;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.framework.ajax.AjaxViewRoot;
+import org.apache.commons.collections.Buffer;
+
+/**
+ * @author Nick - mailto:nbelaevski@exadel.com
+ * created 08.04.2007
+ *
+ */
+public class MockViewRoot extends AjaxViewRoot {
+
+ public Buffer getAjaxEventsQueue(FacesContext context) {
+ return super.getAjaxEventsQueue(context);
+ }
+
+ public Buffer[] getEvents(FacesContext context) {
+ return super.getEvents(context);
+ }
+
+ public Buffer getEventsQueue(FacesContext context, PhaseId phase) {
+ return super.getEventsQueue(context, phase);
+ }
+
+}
17 years, 8 months
JBoss Ajax4JSF SVN: r56 - trunk/test.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-08 11:01:42 -0400 (Sun, 08 Apr 2007)
New Revision: 56
Modified:
trunk/test/pom.xml
Log:
missing javax.servlet group dependencies added
Modified: trunk/test/pom.xml
===================================================================
--- trunk/test/pom.xml 2007-04-06 16:17:05 UTC (rev 55)
+++ trunk/test/pom.xml 2007-04-08 15:01:42 UTC (rev 56)
@@ -60,7 +60,17 @@
<version>2.2.1</version>
<optional>true</optional>
</dependency>
-
-
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
17 years, 8 months
JBoss Ajax4JSF SVN: r55 - in trunk: a4j-portlet and 9 other directories.
by ajax4jsf-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-04-06 12:17:05 -0400 (Fri, 06 Apr 2007)
New Revision: 55
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/FacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ELContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleFactoryImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleImpl.java
trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/pages/index.xhtml
Removed:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextCocoonImpl.java
Modified:
trunk/a4j-portlet/pom.xml
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/PortletTest.java
trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/META-INF/maven/archetype.xml
trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/pom.xml
trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/index.jsp
trunk/pom.xml
Log:
change variable cloverLicense to clover.license.path.
Modified: trunk/a4j-portlet/pom.xml
===================================================================
--- trunk/a4j-portlet/pom.xml 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/pom.xml 2007-04-06 16:17:05 UTC (rev 55)
@@ -25,9 +25,15 @@
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
- <version>1.2_02</version>
+ <version>1.2_04-b10-p01</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <version>1.2_04-b10-p01</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,150 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.IOException;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+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.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxFacesPortlet extends GenericPortlet {
+
+ private static final Log log = LogFactory.getLog(AjaxFacesPortlet.class);
+ /**
+ * Stored portlet config.
+ */
+ private PortletConfig config;
+
+ private Lifecycle lifecycle;
+
+ private FacesContextFactory facesContextFactory;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#init(javax.portlet.PortletConfig)
+ */
+ public void init(PortletConfig config) throws PortletException {
+ this.config = config;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Start portlet initialisation for "+config.getPortletName());
+ }
+ // get faces lifecycle instance
+ LifecycleFactory factory = (LifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ String lifecycleId = config.getPortletContext().getInitParameter(
+ FacesServlet.LIFECYCLE_ID_ATTR);
+ if (null == lifecycleId) {
+ lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
+ }
+ if(log.isDebugEnabled()){
+ log.debug("Create instance of a JSF lifecycle "+lifecycleId);
+ }
+ lifecycle = factory.getLifecycle(lifecycleId);
+ // get faces context factory instance
+ facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ } catch (FacesException e) {
+ throw new PortletException("Initialization error", e);
+ }
+ super.init(config);
+ if (log.isDebugEnabled()) {
+ log.debug("Done portlet initialisation for "+config.getPortletName());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#destroy()
+ */
+ public void destroy() {
+ if (log.isDebugEnabled()) {
+ log.debug("Destroy portlet "+this.config.getPortletName());
+ }
+ lifecycle = null;
+ facesContextFactory = null;
+ super.destroy();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+ */
+ public void processAction(ActionRequest arg0, ActionResponse arg1)
+ throws PortletException, IOException {
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doView(RenderRequest arg0, RenderResponse arg1)
+ throws PortletException, IOException {
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doEdit(RenderRequest arg0, RenderResponse arg1)
+ throws PortletException, IOException {
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doHelp(RenderRequest arg0, RenderResponse arg1)
+ throws PortletException, IOException {
+ }
+
+ /**
+ * @return portlet config, stored at init() method.
+ */
+ protected PortletConfig getConfig() {
+ return config;
+ }
+
+ /**
+ * Get currenf JSF lifecycle instance.
+ * @return
+ */
+ protected Lifecycle getLifecycle() {
+ return lifecycle;
+ }
+
+ /**
+ * Create new faces context instance.
+ * @param request
+ * @param response
+ * @return new instance of faces context.
+ */
+ protected FacesContext getFacesContext(PortletRequest request, PortletResponse response){
+ return facesContextFactory.getFacesContext(getConfig().getPortletContext(), request, response, getLifecycle());
+ }
+
+
+ protected void execute(FacesContext context) throws FacesException {
+ getLifecycle().execute(context);
+ }
+
+ protected void render(FacesContext context) throws FacesException {
+ getLifecycle().render(context);
+ }
+}
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/FacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/FacesPortlet.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/FacesPortlet.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,430 @@
+/*
+ * CDDL HEADER START
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the License). You may not use this file except in
+ * compliance with the License.
+ *
+ * You can obtain a copy of the License at
+ * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
+ * See the License for the specific language governing
+ * permission and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * Header Notice in each file and include the License file
+ * at legal/CDDLv1.0.txt.
+ * If applicable, add the following below the CDDL Header,
+ * with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
+ * CDDL HEADER END
+ */
+
+package org.ajax4jsf.portlet;
+
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+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.PortletMode;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletSession;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletRequest;
+
+
+/**
+ * <p><strong>FacesPortlet</strong> is a portlet that manages the request
+ * processing lifecycle for web applications that are utilizing JavaServer
+ * Faces to construct the user interface in a portlet-based environment.</p>
+ */
+
+public class FacesPortlet extends GenericPortlet {
+
+ // The Logger instance for this class
+ private static Logger logger = Logger.getLogger(FacesPortlet.class.getPackage().getName(), "JSFPLogMessages");
+
+ /**
+ * <p>The key used to store/retrive the PortletConfig object.</p>
+ */
+ public static final String PORTLET_CONFIG = "javax.portlet.PortletConfig";
+
+ // ------------------------------------------------------ Manifest Constants
+
+
+ /**
+ * <p>Context initialization parameter name for the lifecycle identifier
+ * of the {@link Lifecycle} instance to be utilized.</p>
+ */
+ private static final String LIFECYCLE_ID_ATTR =
+ FacesServlet.LIFECYCLE_ID_ATTR;
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ /**
+ * <p>The {@link Application} instance for this web application.</p>
+ */
+ private Application application = null;
+
+
+ /**
+ * <p>Factory for {@link FacesContext} instances.</p>
+ */
+ private FacesContextFactory facesContextFactory = null;
+
+
+ /**
+ * <p>The {@link Lifecycle} instance to use for request processing.</p>
+ */
+ private Lifecycle lifecycle = null;
+
+
+ /**
+ * <p>The <code>PortletConfig</code> instance for this portlet.</p>
+ */
+ private PortletConfig portletConfig = null;
+
+
+ // ---------------------------------------------------------- Public Methods
+
+
+ /**
+ * <p>Release all resources acquired at startup time.</p>
+ */
+ public void destroy() {
+ logger.finest("PS_CSFP0006");
+ application = null;
+ facesContextFactory = null;
+ lifecycle = null;
+ portletConfig = null;
+ logger.finest("PS_CSFP0007");
+ }
+
+
+ /**
+ * <p>Acquire the factory instance we will require.</p>
+ *
+ * @exception PortletException if, for any reason, the startp of
+ * this Faces application failed. This includes errors in the
+ * config file that is parsed before or during the processing of
+ * this <code>init()</code> method.
+ */
+ public void init(PortletConfig portletConfig) throws PortletException {
+
+ logger.finest("PS_CSFP0008");
+
+ // Save our PortletConfig instance
+ this.portletConfig = portletConfig;
+ // Invoke Generic Portlet's init method
+ super.init(portletConfig);
+
+ logger.finest("PS_CSFP0009");
+ }
+
+ public FacesContextFactory getFacesContextFactory() throws PortletException{
+ if (facesContextFactory != null) {
+ return facesContextFactory;
+ }
+ // Acquire our FacesContextFactory instance
+ try {
+ facesContextFactory = (FacesContextFactory)
+ FactoryFinder.getFactory
+ (FactoryFinder.FACES_CONTEXT_FACTORY);
+ logger.log(Level.FINEST, "PS_CSFP0010", facesContextFactory);
+ } catch (FacesException e) {
+ Throwable rootCause = e.getCause();
+ if (rootCause == null) {
+ throw e;
+ } else {
+ throw new PortletException(e.getMessage(), rootCause);
+ }
+ }
+ return facesContextFactory;
+ }
+
+ public Lifecycle getLifecycle() throws PortletException {
+ if ( lifecycle != null ) {
+ return lifecycle;
+ }
+ try {
+ LifecycleFactory lifecycleFactory = (LifecycleFactory)
+ FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ logger.log(Level.FINEST, "PS_CSFP0011" , lifecycleFactory);
+ String lifecycleId =
+ portletConfig.getPortletContext().getInitParameter
+ (LIFECYCLE_ID_ATTR);
+ logger.log(Level.FINE, "PS_CSFP0012", lifecycleId);
+ if (lifecycleId == null) {
+ lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
+ }
+ lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
+ logger.log(Level.FINEST, "PS_CSFP0013", lifecycle);
+ } catch (FacesException e) {
+ Throwable rootCause = e.getCause();
+ if (rootCause == null) {
+ throw e;
+ } else {
+ throw new PortletException(e.getMessage(), rootCause);
+ }
+ }
+ return lifecycle;
+ }
+
+ /**
+ * <p>Perform the request processing lifecycle for the specified request,
+ * up to (but not including) the <em>Render Response</em> phase.</p>
+ *
+ * @param request The portlet request we are processing
+ * @param response The portlet response we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception PortletException if a portlet processing error occurs
+ */
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws IOException, PortletException {
+ logger.finest("PS_CSFP0014");
+
+ storeInitParameter(request);
+
+ // Acquire the FacesContext instance for this request
+ FacesContext context =
+ getFacesContextFactory().getFacesContext
+ (portletConfig.getPortletContext(),
+ request, response, lifecycle);
+
+ // Store the PortletConfig in the Application Map
+ storePortletConfig(context);
+
+ logger.finest("PS_CSFP0015");
+
+ // Execute the pre-render request processing lifecycle for this request
+ try {
+ getLifecycle().execute(context);
+ logger.finest("PS_CSFP0016");
+ } catch (FacesException e) {
+ Throwable t = ((FacesException) e).getCause();
+ if (t == null) {
+ throw new PortletException(e.getMessage(), e);
+ } else {
+ if (t instanceof PortletException) {
+ throw ((PortletException) t);
+ } else if (t instanceof IOException) {
+ throw ((IOException) t);
+ } else {
+ throw new PortletException(t.getMessage(), t);
+ }
+ }
+
+ } finally {
+ PortletSession session = (PortletSession)context.getExternalContext().getSession(true);
+ PortletMode mode = request.getPortletMode();
+ Boolean errorFlag = (Boolean)session.getAttribute(LifecycleImpl.ERROR_FLAG);
+ // If any error occured use the same mode
+ if(errorFlag != null && errorFlag.equals(Boolean.TRUE)) {
+ response.setPortletMode(mode);
+ } else {
+ // Check if the page is same as the INIT_VIEW page, if yes set the mode to VIEW
+ // If the page is not the INIT_VIEW page, it means EDIT/HELP has navigation
+ // continue by setting the same mode as the current mode.
+ String currentViewId = context.getViewRoot().getViewId();
+ String viewId = (String) portletConfig.
+ getInitParameter(LifecycleImpl.INIT_VIEW_PARAMETER);
+ try {
+ if(viewId.equals(currentViewId))
+ response.setPortletMode(PortletMode.VIEW);
+ else
+ response.setPortletMode(mode);
+ } catch (IllegalStateException ise) {
+ // sendRedirect might have been called
+ logger.log(Level.INFO, "PS_CSFP0017", ise.getMessage());
+ }
+ }
+ // Release the FacesContext instance for this request
+ context.release();
+ }
+ logger.finest("PS_CSFP0018");
+ }
+
+ /**
+ * <p>Perform the <em>Render Response</em> phase of the request processing
+ * lifecycle for the specified request.</p>
+ *
+ * <p>This method is invoked to serve up the <code>view</code> portlet mode.</p>
+ *
+ * @param request The portlet request we are processing
+ * @param response The portlet response we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception PortletException if a portlet processing error occurs
+ */
+ public void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, java.io.IOException {
+ renderFaces(request, response);
+ }
+
+ /**
+ * <p>Perform the <em>Render Response</em> phase of the request processing
+ * lifecycle for the specified request.</p>
+ *
+ * <p>This method is invoked to serve up the <code>edit</code> portlet mode.</p>
+ *
+ * @param request The portlet request we are processing
+ * @param response The portlet response we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception PortletException if a portlet processing error occurs
+ */
+ public void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, java.io.IOException {
+ renderFaces(request, response);
+ }
+
+ /**
+ * <p>Perform the <em>Render Response</em> phase of the request processing
+ * lifecycle for the specified request.</p>
+ *
+ * <p>This method is invoked to serve up the <code>help</code> portlet mode.</p>
+ *
+ * @param request The portlet request we are processing
+ * @param response The portlet response we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception PortletException if a portlet processing error occurs
+ */
+ public void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, java.io.IOException {
+ renderFaces(request, response);
+ }
+
+ /**
+ * <p>Perform the <em>Render Response</em> phase of the request processing
+ * lifecycle for the specified request.</p>
+ *
+ * @param request The portlet request we are processing
+ * @param response The portlet response we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception PortletException if a portlet processing error occurs
+ */
+ private void renderFaces(RenderRequest request, RenderResponse response)
+ throws IOException, PortletException {
+ logger.finest("PS_CSFP0019");
+
+ // GenericPortlet sets the title before calling this method
+
+ // in a portlet environment, the context type of reponse must
+ // be set explicitly.
+ response.setContentType(request.getResponseContentType());
+
+ storeInitParameter(request);
+
+ // Acquire the FacesContext instance for this request
+ FacesContext context =
+ getFacesContextFactory().getFacesContext
+ (portletConfig.getPortletContext(),
+ request, response, getLifecycle());
+
+ // Store the PortletConfig in the Application Map
+ storePortletConfig(context);
+
+ logger.finest("PS_CSFP0020");
+
+ // Execute the render response phase for this request
+ try {
+ getLifecycle().render(context);
+ logger.finest("PS_CSFP0021");
+ } catch (FacesException e) {
+ Throwable t = ((FacesException) e).getCause();
+ if (t == null) {
+ throw new PortletException(e.getMessage(), e);
+ } else {
+ if (t instanceof PortletException) {
+ throw ((PortletException) t);
+ } else if (t instanceof IOException) {
+ throw ((IOException) t);
+ } else {
+ throw new PortletException(t.getMessage(), t);
+ }
+ }
+ } finally {
+
+ // Release the FacesContext instance for this request
+ context.release();
+
+ }
+ logger.finest("PS_CSFP0022");
+ }
+
+
+ // --------------------------------------------------------- Private Methods
+
+ /**
+ * Stores the init parameter identifier and the value for that in the request map.
+ * The init parameter identifier can be either com.sun.faces.portlet.INIT_VIEW or
+ * com.sun.faces.portlet.INIT_EDIT or com.sun.faces.portlet.INIT_HELP. The appropriate
+ * identifier based on the Portlet mode is stored. This value is used in LifeCycleImpl
+ * to keep the state information for each mode separate.
+ * The value for the identifier is used during the RenderResponse Phase to
+ * display the initial view.
+ *
+ * @param request the portlet request, can be ActionRequest or RenderRequest
+ * @throws PortletException
+ */
+ private void storeInitParameter(PortletRequest request) throws PortletException {
+ PortletMode mode = request.getPortletMode();
+
+ // Get the init parameter identifier based on the mode.
+ String initParameterIdentifier = null;
+ if (mode.equals(PortletMode.VIEW)) {
+ initParameterIdentifier = LifecycleImpl.INIT_VIEW_PARAMETER;
+ } else if (mode.equals(PortletMode.EDIT)) {
+ initParameterIdentifier = LifecycleImpl.INIT_EDIT_PARAMETER;
+ } else if (mode.equals(PortletMode.HELP)) {
+ initParameterIdentifier = LifecycleImpl.INIT_HELP_PARAMETER;
+ }
+ // Check whether the requested mode is allowed
+ if(!request.isPortletModeAllowed(mode) || initParameterIdentifier == null) {
+ throw new PortletException(mode + " is not allowed");
+ }
+
+ String initId = (String) portletConfig.getInitParameter(initParameterIdentifier);
+ if (initId != null) {
+ // store the identifier in the request map. This identifier can be either a
+ // INIT_VIEW or INIT_EDIT or INIT_HELP based on the portlet mode. This information
+ // is used in LifeCycleImpl to keep the state information for each mode separate.
+ request.setAttribute(LifecycleImpl.INIT_PARAMETER, initParameterIdentifier);
+ // store the value for the identifier in the requestMap so that it could be used
+ // during the RenderResponse Phase to display the initial view.
+ request.setAttribute(initParameterIdentifier, initId);
+ } else {
+ throw new PortletException(initParameterIdentifier + " must be specified");
+ }
+ }
+
+ /**
+ * Store the PortletConfig in the Application Map
+ */
+ private void storePortletConfig(FacesContext context) {
+ Map applicationMap = context.getExternalContext().getApplicationMap();
+ if(!applicationMap.containsKey(PORTLET_CONFIG) )
+ applicationMap.put(PORTLET_CONFIG, portletConfig);
+ }
+}
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,1242 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+
+ * Created on 25.09.2004
+
+ *
+
+ * Copyright 1999-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.ajax4jsf.portlet.context;
+
+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.Enumeration;
+
+import java.util.Iterator;
+
+import java.util.Locale;
+
+import java.util.Map;
+
+import java.util.Set;
+
+import javax.faces.FacesException;
+
+import javax.faces.context.ExternalContext;
+
+import javax.servlet.RequestDispatcher;
+
+import javax.servlet.Servlet;
+
+import javax.servlet.ServletContext;
+
+import javax.servlet.ServletException;
+
+import javax.servlet.ServletResponse;
+
+/**
+ *
+ * @author shura
+ *
+ *
+ *
+ * Cocoon specific implementation of <code>ExternalContext</code> Use cocoon
+ *
+ * <code>Context</code> for Implement JSF Servlet specific functions Do not
+ *
+ * perform redirect - but tell <code>Action</code> for internal pipeline
+ *
+ * redirect ? or do normal Cocoon redirect Via Http Environment do not dispanch -
+ *
+ * use Cocoon generator source parametr, but perform generation Full
+ *
+ * Cocoon-specific realization ;
+ *
+ *
+ *
+ */
+
+public abstract class AbstractExternalContext extends ExternalContext {
+
+ // TODO - more configurable with sitemap parameters.
+
+ // TODO - optimization.
+
+ private Map applicationMap;
+
+ private Map initParameterMap;
+
+ private Map requestHeaderMap = null;
+
+ private Map requestHeaderValues;
+
+ private Map requestMap;
+
+ private Map requestParameterMap;
+
+ private Map requestParameterValuesMap;
+
+ private Map sessionMap;
+
+ private Object request;
+
+ private Object response;
+
+ private boolean http;
+
+ private Map actionSettings;
+
+ private Object context;
+
+ /**
+ *
+ * @param response
+ *
+ * @param request
+ *
+ * @param context
+ *
+ * @param defaultContext -
+ *
+ * default implementation of <code>ExternalFacesContext</code>.
+ *
+ */
+
+ public AbstractExternalContext(
+
+ Object context, Object request,
+
+ Object response) {
+
+ super();
+
+ this.context = context;
+
+ this.request = request;
+
+ this.response = response;
+
+ }
+
+
+
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
+ *
+ */
+
+ public void dispatch(String path) throws IOException {
+
+ // perform Generation in generator, do nothing in Action.
+
+ // generator place special Dispatcher to objectModel ...
+
+ // May be must set Dispatcher in special method in Context Component ???
+
+ String jspPageURL = (String) getCocoonRequest().getAttribute(
+
+ JSFGenerator.PAGE_URL_PARAM_NAME);
+
+ RequestDispatcher dispatcher = getCocoonHttpContext()
+
+ .getNamedDispatcher(getJspServletName());
+
+ this.log("Dispatch for page: " + jspPageURL);
+
+ // Dispatcher dispatch = getDispatcher();
+
+ if (dispatcher == null) {
+
+ throw new IOException("NamedDispatcher is null for servlet "
+
+ + getJspServletName());
+
+ }
+
+ try {// Reset jsp Request/Response wrappers - for create on demand
+
+ // with new Writer for current XML Consumer.
+
+ this.jspRequest = null;
+
+ this.jspResponse = null;
+
+ dispatcher.include(new JSPServletRequest(getCocoonHttpRequest(),
+
+ jspPageURL, null), (ServletResponse) this.getResponse());
+
+ } catch (ServletException e) {
+
+ //
+
+ if (e.getMessage() != null) {
+
+ throw new FacesException(e.getMessage(), e);
+
+ } else {
+
+ throw new FacesException(e);
+
+ }
+
+ }
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
+ *
+ */
+
+ public String encodeActionURL(String url) {
+
+ //
+
+ return getCocoonResponse().encodeURL(url);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
+ *
+ */
+
+ public String encodeNamespace(String name) {
+
+ // HACK - set namespace prefix in Action sitemap parameter.
+
+ // return this.getCocoonRequest().getContextPath()+"/"+name;
+
+ String namespace = (String) this.getCocoonRequest().getAttribute(
+
+ FacesAction.ACT_NAMESPACE);
+
+ if (null != namespace) {
+
+ return namespace + name;
+
+ }
+
+ return name;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
+ *
+ */
+
+ public String encodeResourceURL(String url) {
+
+ //
+
+ return this.getCocoonResponse().encodeURL(url);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getApplicationMap()
+ *
+ */
+
+ public Map getApplicationMap() {
+
+ //
+
+ if (applicationMap == null) {
+
+ applicationMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ return getCocoonContext().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonContext().getAttribute(keyString);
+
+ getCocoonContext().setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonContext().getAttribute(keyString);
+
+ getCocoonContext().removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonContext().getAttributeNames();
+
+ }
+
+ };
+
+ }
+
+ return applicationMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getAuthType()
+ *
+ */
+
+ public String getAuthType() {
+
+ //
+
+ return this.getCocoonRequest().getAuthType();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getContext()
+ *
+ */
+
+ public Object getContext() {
+ return this.context;
+ }
+
+
+ public void setContext(Object context) {
+ this.context = context;
+ }
+ /*
+
+ return servletContext; // .getContext(getRequestContextPath());
+
+ // return getCocoonHttpContext();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ *
+ */
+
+ public String getInitParameter(String name) {
+
+ // HACK - get init parameter from Action configuration instead of
+
+ // servlet ...
+
+ String ret = (String) getActionSettings().get(name);
+
+ if (ret == null) {
+
+ ret = this.getCocoonContext().getInitParameter(name);
+
+ }
+
+ return ret;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameterMap()
+ *
+ */
+
+ public Map getInitParameterMap() {
+
+ // Combine Servlet InitParameters with Cocoon Action configuration
+
+ // parameters ?
+
+ if (initParameterMap == null) {
+
+ initParameterMap = new ContextConcatentedMap(this
+
+ .getActionSettings()) {
+
+ public Object getBase(Object key) {
+
+ // HACK - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonContext().getInitParameter(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ if (http) {
+
+ return getCocoonHttpContext().getInitParameterNames();
+
+ } else {
+
+ return Collections.enumeration(Collections.EMPTY_SET);
+
+ }
+
+ }
+
+ };
+
+ }
+
+ return initParameterMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRemoteUser()
+ *
+ */
+
+ public String getRemoteUser() {
+
+ //
+
+ return getCocoonRequest().getRemoteUser();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequest()
+ *
+ */
+
+ public Object getRequest() {
+
+ return request;
+
+ }
+
+ public void setRequest(Object request) {
+ this.request = request;
+ }
+
+ public String getRequestContextPath() {
+
+ // TODO return Cocoon sitemap-specific path ? or configure from sitemap
+
+ // parameters of Action.
+
+ return getCocoonRequest().getContextPath();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestCookieMap()
+ *
+ */
+
+ public Map getRequestCookieMap() {
+
+ //
+
+ return getCocoonRequest().getCookieMap();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
+ *
+ */
+
+ public Map getRequestHeaderMap() {
+
+ // TODO Return values of Http headers, or, may be, addition values from
+
+ // Action parameters .
+
+ if (requestHeaderMap == null) {
+
+ requestHeaderMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest().getHeader(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getHeaderNames();
+
+ }
+
+ };
+
+ }
+
+ return requestHeaderMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestHeaderValuesMap()
+ *
+ */
+
+ public Map getRequestHeaderValuesMap() {
+
+ //
+
+ if (requestHeaderValues == null) {
+
+ requestHeaderValues = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest().getHeaders(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getHeaderNames();
+
+ }
+
+ };
+
+ }
+
+ return requestHeaderValues;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestLocale()
+ *
+ */
+
+ public Locale getRequestLocale() {
+
+ //
+
+ return getCocoonRequest().getLocale();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestLocales()
+ *
+ */
+
+ public Iterator getRequestLocales() {
+
+ //
+
+ return new EnumerationIterator(getCocoonRequest().getLocales());
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestMap()
+ *
+ */
+
+ public Map getRequestMap() {
+
+ // TODO make Cocoon-specific realization ( interact with sitemap
+
+ // parameters )
+
+ if (requestMap == null) {
+
+ requestMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ if ("javax.servlet.include.path_info".equals(key)) {
+
+ return getRequestPathInfo();
+
+ // return getCocoonRequest().getAttribute(
+
+ // FacesAction.ACT_SRC);
+
+ }
+
+ if ("javax.servlet.include.servlet_path".equals(key)) {
+
+ return getRequestServletPath();
+
+ // return getCocoonRequest().getAttribute(
+
+ // FacesAction.ACT_MAPPING);
+
+ }
+
+ return getCocoonRequest().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonRequest().getAttribute(keyString);
+
+ getCocoonRequest().setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonRequest().getAttribute(keyString);
+
+ getCocoonRequest().removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getAttributeNames();
+
+ }
+
+ };
+
+ }
+
+ return requestMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterMap()
+ *
+ */
+
+ public Map getRequestParameterMap() {
+
+ //
+
+ if (requestParameterMap == null) {
+
+ requestParameterMap = new ContextConcatentedMap(
+
+ (Map) (getCocoonRequest()
+
+ .getAttribute(FacesAction.ACT_PARAMETERS))) {
+
+ public Object getBase(Object key) {
+
+ //
+
+ return getCocoonRequest().getParameter(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getParameterNames();
+
+ }
+
+ };
+
+ }
+
+ return requestParameterMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterNames()
+ *
+ */
+
+ public Iterator getRequestParameterNames() {
+
+ // TODO Append Cocoon-specific parameters from FacesAction
+
+ return this.getRequestParameterMap().entrySet().iterator();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
+ *
+ */
+
+ public Map getRequestParameterValuesMap() {
+
+ //
+
+ // TODO make Cocoon-specific realization ( interact with sitemap
+
+ // parameters )
+
+ if (requestParameterValuesMap == null) {
+
+ requestParameterValuesMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest()
+
+ .getParameterValues(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getParameterNames();
+
+ }
+
+ };
+
+ }
+
+ return requestParameterValuesMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestPathInfo()
+ *
+ */
+
+ public String getRequestPathInfo() {
+
+ //
+
+ return (String) getCocoonRequest().getAttribute(FacesAction.ACT_SRC);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestServletPath()
+ *
+ */
+
+ public String getRequestServletPath() {
+
+ // TODO return current sitemap path ??? For cocoon, always "/" !
+
+ return ""; // path;// ??? "";
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ *
+ */
+
+ public URL getResource(String path) throws MalformedURLException {
+
+ //
+
+ return getCocoonContext().getResource(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ *
+ */
+
+ public InputStream getResourceAsStream(String path) {
+
+ return getCocoonContext().getResourceAsStream(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ *
+ */
+
+ public Set getResourcePaths(String path) {
+
+ // Cocoon Context do not Have such method ...
+
+ return null; // getCocoonHttpContext().getResourcePaths(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResponse()
+ *
+ */
+
+ public void setResponse(Object response) {
+ this.response = response;
+ }
+
+
+
+
+ public Object getResponse() {
+ return response;
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getSession(boolean)
+ *
+ */
+
+ public Object getSession(boolean create) {
+
+ // TODO Convert to HttpSession !!!
+
+ return getCocoonRequest().getSession(create);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getSessionMap()
+ *
+ */
+
+ public Map getSessionMap() {
+
+ if (sessionMap == null) {
+
+ sessionMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ return getCocoonSession().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Session session = getCocoonSession();
+
+ Object result = session.getAttribute(keyString);
+
+ session.setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Session session = getCocoonSession();
+
+ Object result = session.getAttribute(keyString);
+
+ session.removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonSession().getAttributeNames();
+
+ }
+
+ private Session getCocoonSession() {
+
+ return (Session) getSession(true);
+
+ }
+
+ };
+
+ }
+
+ return sessionMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getUserPrincipal()
+ *
+ */
+
+ public Principal getUserPrincipal() {
+
+ return getCocoonRequest().getUserPrincipal();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#isUserInRole(java.lang.String)
+ *
+ */
+
+ public boolean isUserInRole(String role) {
+
+ return getCocoonRequest().isUserInRole(role);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#redirect(java.lang.String)
+ *
+ */
+
+ public void redirect(String url) throws IOException {
+
+ // use Redirector Stored In objectModel Map
+
+ ActionRedirector redirector = (ActionRedirector) getCocoonRequest()
+
+ .getAttribute(FacesAction.ACT_REDIRECTOR);
+
+ if (redirector != null) {
+
+ try {
+
+ redirector.redirect(false, url);
+
+ } catch (ProcessingException e) {
+
+ throw new IOException(e.getMessage());
+
+ }
+
+ }
+
+ }
+
+ // Private methods - for Cocoon Context Interaction.
+
+ // TODO - rewrite as lazy creation, but need reset with change Context ?
+
+ // private Map getObjectModel() {
+
+ // return ContextHelper.getObjectModel(getCocoonContext());
+
+ // }
+
+ private class EnumerationIterator implements Iterator {
+
+ public EnumerationIterator(Enumeration locales) {
+
+ this.locales = locales;
+
+ }
+
+ private Enumeration locales;
+
+ public boolean hasNext() {
+
+ return locales.hasMoreElements();
+
+ }
+
+ public Object next() {
+
+ return locales.nextElement();
+
+ }
+
+ public void remove() {
+
+ throw new UnsupportedOperationException();
+
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -31,7 +31,7 @@
*/
-package org.apache.cocoon.components.faces.context;
+package org.ajax4jsf.portlet.context;
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -19,256 +19,183 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*
- * Created on 03.10.2004
+package org.ajax4jsf.portlet.context;
- *
+import java.util.AbstractMap;
- * Copyright 1999-2004 The Apache Software Foundation.
+import java.util.Enumeration;
- *
+import java.util.HashSet;
- * Licensed under the Apache License, Version 2.0 (the "License");
+import java.util.Map;
- * you may not use this file except in compliance with the License.
+import java.util.Set;
- * You may obtain a copy of the License at
+/**
+ *
+ * @author shura
+ *
+ *
+ *
+ * Base class for All maps in <code>ExternalContextCocoonImpl</code> get from
+ *
+ * Sun Jsf-ri
+ *
+ *
+ *
+ */
- *
+abstract class ContextMap extends AbstractMap {
- * http://www.apache.org/licenses/LICENSE-2.0
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see java.util.Map#entrySet()
+ *
+ */
- *
+ public Set entrySet() {
- * Unless required by applicable law or agreed to in writing, software
+ Set entries = new HashSet();
- * distributed under the License is distributed on an "AS IS" BASIS,
+ for (Enumeration e = getEnumeration(); e.hasMoreElements();) {
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ String paramName = (String) e.nextElement();
- * See the License for the specific language governing permissions and
+ entries.add(new Entry(paramName, get(paramName)));
- * limitations under the License.
+ }
- */
+ return entries;
-package org.apache.cocoon.components.faces.context;
+ }
-
+ /**
+ *
+ *
+ *
+ * Template metod - all maps in ExternalFacesContext creates Set from
+ *
+ * parameters <code>Enumeration</code>
+ *
+ *
+ *
+ * @return enumeration for current map.
+ *
+ */
-import java.util.AbstractMap;
+ protected abstract Enumeration getEnumeration();
-import java.util.Enumeration;
+ // Unsupported by all Maps.
-import java.util.HashSet;
+ public void clear() {
-import java.util.Map;
+ throw new UnsupportedOperationException();
-import java.util.Set;
+ }
-
+ // Unsupported by all Maps.
-/**
+ public void putAll(Map t) {
- * @author shura
+ throw new UnsupportedOperationException();
- *
+ }
- * Base class for All maps in <code>ExternalContextCocoonImpl</code> get from
+ // Supported by maps if overridden
- * Sun Jsf-ri
+ public Object remove(Object key) {
- *
+ throw new UnsupportedOperationException();
- */
+ }
-abstract class ContextMap extends AbstractMap {
+ static class Entry implements Map.Entry {
-
+ // immutable Entry
- /*
+ private final Object key;
- * (non-Javadoc)
+ private final Object value;
- *
+ Entry(Object key, Object value) {
- * @see java.util.Map#entrySet()
+ this.key = key;
- */
+ this.value = value;
- public Set entrySet() {
+ }
- Set entries = new HashSet();
+ public Object getKey() {
- for (Enumeration e = getEnumeration(); e.hasMoreElements();) {
+ return key;
- String paramName = (String) e.nextElement();
+ }
- entries.add(new Entry(paramName, get(paramName)));
+ public Object getValue() {
- }
+ return value;
- return entries;
+ }
- }
+ // No support of setting the value
-
+ public Object setValue(Object value) {
- /**
+ throw new UnsupportedOperationException();
- *
+ }
- * Template metod - all maps in ExternalFacesContext creates Set from
+ public int hashCode() {
- * parameters <code>Enumeration</code>
+ return ((key == null ? 0 : key.hashCode()) ^ (value == null ? 0
- *
+ : value.hashCode()));
- * @return enumeration for current map.
+ }
- */
+ public boolean equals(Object obj) {
- protected abstract Enumeration getEnumeration();
+ if (obj == null || !(obj instanceof Map.Entry))
-
+ return false;
- // Unsupported by all Maps.
+ Map.Entry input = (Map.Entry) obj;
- public void clear() {
+ Object inputKey = input.getKey();
- throw new UnsupportedOperationException();
+ Object inputValue = input.getValue();
- }
+ if (inputKey == key || (inputKey != null && inputKey.equals(key))) {
-
+ if (inputValue == value
- // Unsupported by all Maps.
+ || (inputValue != null && inputValue.equals(value))) {
- public void putAll(Map t) {
+ return true;
- throw new UnsupportedOperationException();
+ }
- }
+ }
-
+ return false;
- // Supported by maps if overridden
+ }
- public Object remove(Object key) {
+ }
- throw new UnsupportedOperationException();
+ public boolean equals(Object obj) {
- }
+ if (obj == null || !(obj instanceof ContextMap))
-
+ return false;
- static class Entry implements Map.Entry {
+ return super.equals(obj);
-
+ }
- // immutable Entry
-
- private final Object key;
-
-
-
- private final Object value;
-
-
-
- Entry(Object key, Object value) {
-
- this.key = key;
-
- this.value = value;
-
- }
-
-
-
- public Object getKey() {
-
- return key;
-
- }
-
-
-
- public Object getValue() {
-
- return value;
-
- }
-
-
-
- // No support of setting the value
-
- public Object setValue(Object value) {
-
- throw new UnsupportedOperationException();
-
- }
-
-
-
- public int hashCode() {
-
- return ((key == null ? 0 : key.hashCode()) ^ (value == null ? 0
-
- : value.hashCode()));
-
- }
-
-
-
- public boolean equals(Object obj) {
-
- if (obj == null || !(obj instanceof Map.Entry))
-
- return false;
-
-
-
- Map.Entry input = (Map.Entry) obj;
-
- Object inputKey = input.getKey();
-
- Object inputValue = input.getValue();
-
-
-
- if (inputKey == key || (inputKey != null && inputKey.equals(key))) {
-
- if (inputValue == value
-
- || (inputValue != null && inputValue.equals(value))) {
-
- return true;
-
- }
-
- }
-
- return false;
-
- }
-
- }
-
-
-
- public boolean equals(Object obj) {
-
- if (obj == null || !(obj instanceof ContextMap))
-
- return false;
-
- return super.equals(obj);
-
- }
-
-
-
}
\ No newline at end of file
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ELContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ELContextImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ELContextImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,104 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ELContextImpl extends ELContext {
+
+ /**
+ * @author asmirnov
+ *
+ */
+ public static final class FunctionMapperImpl extends FunctionMapper {
+
+ /* (non-Javadoc)
+ * @see javax.el.FunctionMapper#resolveFunction(java.lang.String, java.lang.String)
+ */
+ public Method resolveFunction(String arg0, String arg1) {
+ return null;
+ }
+
+ }
+
+ /**
+ * @author asmirnov
+ *
+ */
+ public static final class VariableMapperImpl extends VariableMapper {
+
+ private Map variables = new HashMap();
+
+ /* (non-Javadoc)
+ * @see javax.el.VariableMapper#resolveVariable(java.lang.String)
+ */
+ public ValueExpression resolveVariable(String name) {
+ return (ValueExpression) variables.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.VariableMapper#setVariable(java.lang.String, javax.el.ValueExpression)
+ */
+ public ValueExpression setVariable(String name, ValueExpression variable) {
+ return (ValueExpression) variables.put(name, variable);
+ }
+
+ }
+
+ private ELResolver resolver;
+
+ private VariableMapper variableMapper = new VariableMapperImpl();
+
+ private FunctionMapper functionMapper = new FunctionMapperImpl();
+
+
+ public ELContextImpl(ELResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ /**
+ * @return the functionMapper
+ */
+ public FunctionMapper getFunctionMapper() {
+ return functionMapper;
+ }
+
+ /**
+ * @param functionMapper the functionMapper to set
+ */
+ public void setFunctionMapper(FunctionMapper functionMapper) {
+ this.functionMapper = functionMapper;
+ }
+
+ /**
+ * @return the variableMapper
+ */
+ public VariableMapper getVariableMapper() {
+ return variableMapper;
+ }
+
+ /**
+ * @param variableMapper the variableMapper to set
+ */
+ public void setVariableMapper(VariableMapper variableMapper) {
+ this.variableMapper = variableMapper;
+ }
+
+ public ELResolver getELResolver() {
+ return resolver;
+ }
+
+}
Deleted: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextCocoonImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextCocoonImpl.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextCocoonImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -1,2150 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
-
- * Created on 25.09.2004
-
- *
-
- * Copyright 1999-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.cocoon.components.faces.context;
-
-
-
-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.Enumeration;
-
-import java.util.Iterator;
-
-import java.util.Locale;
-
-import java.util.Map;
-
-import java.util.Set;
-
-
-
-import javax.faces.FacesException;
-
-import javax.faces.context.ExternalContext;
-
-import javax.servlet.RequestDispatcher;
-
-import javax.servlet.Servlet;
-
-import javax.servlet.ServletContext;
-
-import javax.servlet.ServletException;
-
-import javax.servlet.ServletResponse;
-
-
-
-import org.apache.cocoon.ProcessingException;
-
-import org.apache.cocoon.acting.FacesAction;
-
-import org.apache.cocoon.components.faces.ActionRedirector;
-
-import org.apache.cocoon.components.faces.renderkit.CocoonResponceWriter;
-
-import org.apache.cocoon.environment.Request;
-
-import org.apache.cocoon.environment.Response;
-
-import org.apache.cocoon.environment.Session;
-
-import org.apache.cocoon.environment.http.HttpContext;
-
-import org.apache.cocoon.environment.http.HttpRequest;
-
-import org.apache.cocoon.environment.http.HttpResponse;
-
-import org.apache.cocoon.generation.JSFGenerator;
-
-
-
-/**
-
- * @author shura
-
- *
-
- * Cocoon specific implementation of <code>ExternalContext</code> Use cocoon
-
- * <code>Context</code> for Implement JSF Servlet specific functions Do not
-
- * perform redirect - but tell <code>Action</code> for internal pipeline
-
- * redirect ? or do normal Cocoon redirect Via Http Environment do not dispanch -
-
- * use Cocoon generator source parametr, but perform generation Full
-
- * Cocoon-specific realization ;
-
- *
-
- */
-
-public abstract class ExternalContextCocoonImpl extends ExternalContext {
-
-
-
- // TODO - more configurable with sitemap parameters.
-
- // TODO - optimization.
-
- private Map applicationMap;
-
-
-
- private Map initParameterMap;
-
-
-
- private Map requestHeaderMap = null;
-
-
-
- private Map requestHeaderValues;
-
-
-
- private Map requestMap;
-
-
-
- private Map requestParameterMap;
-
-
-
- private Map requestParameterValuesMap;
-
-
-
- private Map sessionMap;
-
-
-
- private JSPServletRequest jspRequest;
-
-
-
- private JSPServletResponse jspResponse;
-
-
-
- private org.apache.cocoon.environment.Context context;
-
-
-
- private Request request;
-
-
-
- private Response response;
-
-
-
- private boolean http;
-
-
-
- private Map actionSettings;
-
-
-
- /**
-
- * @param response
-
- * @param request
-
- * @param context
-
- * @param defaultContext -
-
- * default implementation of <code>ExternalFacesContext</code>.
-
- */
-
- public ExternalContextCocoonImpl(
-
- org.apache.cocoon.environment.Context context, Request request,
-
- Response response) {
-
- super();
-
- this.context = context;
-
- this.request = request;
-
- this.response = response;
-
- if (context instanceof HttpContext) {
-
- this.http = true;
-
- }
-
- }
-
-
-
- /**
-
- * Abstract wrapper for FacesContextImpl.
-
- *
-
- * @return Cocoon <code>Context</code> for current
-
- * <code>CocoonFacesContext</code> component.
-
- */
-
- // abstract Context getCocoonContext();
-
- /**
-
- * @return Faces Response writer for current request.
-
- */
-
- abstract CocoonResponceWriter getWriter();
-
-
-
- /**
-
- * @return name of JSP Servlet for current web container.
-
- */
-
- abstract String getJspServletName();
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
-
- */
-
- public void dispatch(String path) throws IOException {
-
- // perform Generation in generator, do nothing in Action.
-
- // generator place special Dispatcher to objectModel ...
-
- // May be must set Dispatcher in special method in Context Component ???
-
- String jspPageURL = (String) getCocoonRequest().getAttribute(
-
- JSFGenerator.PAGE_URL_PARAM_NAME);
-
- RequestDispatcher dispatcher = getCocoonHttpContext()
-
- .getNamedDispatcher(getJspServletName());
-
- this.log("Dispatch for page: " + jspPageURL);
-
- // Dispatcher dispatch = getDispatcher();
-
- if (dispatcher == null) {
-
- throw new IOException("NamedDispatcher is null for servlet "
-
- + getJspServletName());
-
- }
-
-
-
- try {// Reset jsp Request/Response wrappers - for create on demand
-
- // with new Writer for current XML Consumer.
-
- this.jspRequest = null;
-
- this.jspResponse = null;
-
- dispatcher.include(new JSPServletRequest(getCocoonHttpRequest(),
-
- jspPageURL, null), (ServletResponse) this.getResponse());
-
- } catch (ServletException e) {
-
- //
-
- if (e.getMessage() != null) {
-
- throw new FacesException(e.getMessage(), e);
-
- } else {
-
- throw new FacesException(e);
-
- }
-
- }
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
-
- */
-
- public String encodeActionURL(String url) {
-
- //
-
- return getCocoonResponse().encodeURL(url);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
-
- */
-
- public String encodeNamespace(String name) {
-
- // HACK - set namespace prefix in Action sitemap parameter.
-
- // return this.getCocoonRequest().getContextPath()+"/"+name;
-
- String namespace = (String) this.getCocoonRequest().getAttribute(
-
- FacesAction.ACT_NAMESPACE);
-
- if (null != namespace) {
-
- return namespace + name;
-
- }
-
- return name;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
-
- */
-
- public String encodeResourceURL(String url) {
-
- //
-
- return this.getCocoonResponse().encodeURL(url);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getApplicationMap()
-
- */
-
- public Map getApplicationMap() {
-
- //
-
- if (applicationMap == null) {
-
- applicationMap = new ContextMap() {
-
- public Object get(Object key) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- return getCocoonContext().getAttribute(key.toString());
-
- }
-
-
-
- public Object put(Object key, Object value) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonContext().getAttribute(keyString);
-
- getCocoonContext().setAttribute(keyString, value);
-
- return (result);
-
- }
-
-
-
- public Object remove(Object key) {
-
- if (key == null) {
-
- return null;
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonContext().getAttribute(keyString);
-
- getCocoonContext().removeAttribute(keyString);
-
- return (result);
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonContext().getAttributeNames();
-
- }
-
-
-
- };
-
- }
-
-
-
- return applicationMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getAuthType()
-
- */
-
- public String getAuthType() {
-
- //
-
- return this.getCocoonRequest().getAuthType();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getContext()
-
- */
-
- public Object getContext() {
-
- // Return special ServletContext decorator for default
-
- // implementation ?
-
- // As I see in JSF RI sources, used only for get Application Parameter ,
-
- // but I
-
- // want to store application parameters in objectModel.
-
- // Correction - in Sun RI used for store application data between
-
- // servelet context listenier
-
- // ( configure JSF ) and to request processing data in Context#Attribute
-
- // !
-
- ServletContext servletContext = new ServletContext() {
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getContext(java.lang.String)
-
- */
-
- public ServletContext getContext(String uripath) {
-
- return getCocoonHttpContext().getContext(uripath);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getMajorVersion()
-
- */
-
- public int getMajorVersion() {
-
- return getCocoonHttpContext().getMajorVersion();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getMinorVersion()
-
- */
-
- public int getMinorVersion() {
-
- return getCocoonHttpContext().getMinorVersion();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
-
- */
-
- public String getMimeType(String file) {
-
- return getCocoonHttpContext().getMimeType(file);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
-
- */
-
- public Set getResourcePaths(String path) {
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getResource(java.lang.String)
-
- */
-
- public URL getResource(String path) throws MalformedURLException {
-
- return ExternalContextCocoonImpl.this.getResource(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
-
- */
-
- public InputStream getResourceAsStream(String path) {
-
- return ExternalContextCocoonImpl.this.getResourceAsStream(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
-
- */
-
- public RequestDispatcher getRequestDispatcher(String path) {
-
- return getCocoonHttpContext().getRequestDispatcher(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
-
- */
-
- public RequestDispatcher getNamedDispatcher(String name) {
-
- return getCocoonHttpContext().getNamedDispatcher(name);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getServlet(java.lang.String)
-
- */
-
- public Servlet getServlet(String name) throws ServletException {
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getServlets()
-
- */
-
- public Enumeration getServlets() {
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getServletNames()
-
- */
-
- public Enumeration getServletNames() {
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#log(java.lang.String)
-
- */
-
- public void log(String msg) {
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#log(java.lang.Exception,
-
- * java.lang.String)
-
- */
-
- public void log(Exception exception, String msg) {
-
- // TODO Auto-generated method stub
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#log(java.lang.String,
-
- * java.lang.Throwable)
-
- */
-
- public void log(String message, Throwable throwable) {
-
- // TODO Auto-generated method stub
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
-
- */
-
- public String getRealPath(String path) {
-
- // TODO Auto-generated method stub
-
- return getCocoonHttpContext().getRealPath(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getServerInfo()
-
- */
-
- public String getServerInfo() {
-
- // TODO Auto-generated method stub
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
-
- */
-
- public String getInitParameter(String name) {
-
- // TODO Auto-generated method stub
-
- return ExternalContextCocoonImpl.this.getInitParameter(name);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getInitParameterNames()
-
- */
-
- public Enumeration getInitParameterNames() {
-
- // TODO Auto-generated method stub
-
- return null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
-
- */
-
- public Object getAttribute(String name) {
-
- // TODO Auto-generated method stub
-
- return getCocoonHttpContext().getAttribute(name);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getAttributeNames()
-
- */
-
- public Enumeration getAttributeNames() {
-
- // TODO Auto-generated method stub
-
- return getCocoonHttpContext().getAttributeNames();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#setAttribute(java.lang.String,
-
- * java.lang.Object)
-
- */
-
- public void setAttribute(String name, Object object) {
-
- // TODO Auto-generated method stub
-
- getCocoonHttpContext().setAttribute(name, object);
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
-
- */
-
- public void removeAttribute(String name) {
-
- // TODO Auto-generated method stub
-
- getCocoonHttpContext().removeAttribute(name);
-
-
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.servlet.ServletContext#getServletContextName()
-
- */
-
- public String getServletContextName() {
-
- // TODO Auto-generated method stub
-
- return null;
-
- }
-
-
-
- };
-
-
-
- return servletContext; //.getContext(getRequestContextPath());
-
-
-
- // return getCocoonHttpContext();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
-
- */
-
- public String getInitParameter(String name) {
-
- // HACK - get init parameter from Action configuration instead of
-
- // servlet ...
-
- String ret = (String) getActionSettings().get(name);
-
- if (ret == null) {
-
- ret = this.getCocoonContext().getInitParameter(name);
-
- }
-
- return ret;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getInitParameterMap()
-
- */
-
- public Map getInitParameterMap() {
-
- // Combine Servlet InitParameters with Cocoon Action configuration
-
- // parameters ?
-
- if (initParameterMap == null) {
-
- initParameterMap = new ContextConcatentedMap(this
-
- .getActionSettings()) {
-
-
-
- public Object getBase(Object key) {
-
- // HACK - return configuration parameter from Cocoon
-
- // FacesAction
-
- return getCocoonContext().getInitParameter(key.toString());
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- if (http) {
-
- return getCocoonHttpContext().getInitParameterNames();
-
- } else {
-
- return Collections.enumeration(Collections.EMPTY_SET);
-
- }
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return initParameterMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRemoteUser()
-
- */
-
- public String getRemoteUser() {
-
- //
-
- return getCocoonRequest().getRemoteUser();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequest()
-
- */
-
- public Object getRequest() {
-
- //
-
- // return this.getCocoonRequest();
-
- // this.getObjectModel().get(HttpEnvironment.HTTP_REQUEST_OBJECT);
-
-
-
- if (jspRequest == null) {
-
- jspRequest = new JSPServletRequest(getCocoonHttpRequest(),
-
- getRequestServletPath(), getRequestPathInfo());
-
-
-
- }
-
-
-
- return jspRequest;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestContextPath()
-
- */
-
- public String getRequestContextPath() {
-
- // TODO return Cocoon sitemap-specific path ? or configure from sitemap
-
- // parameters of Action.
-
- return getCocoonRequest().getContextPath();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestCookieMap()
-
- */
-
- public Map getRequestCookieMap() {
-
- //
-
- return getCocoonRequest().getCookieMap();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
-
- */
-
- public Map getRequestHeaderMap() {
-
- // TODO Return values of Http headers, or, may be, addition values from
-
- // Action parameters .
-
- if (requestHeaderMap == null) {
-
- requestHeaderMap = new ContextMap() {
-
-
-
- public Object get(Object key) {
-
- // TODO - return configuration parameter from Cocoon
-
- // FacesAction
-
- return getCocoonRequest().getHeader(key.toString());
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonRequest().getHeaderNames();
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return requestHeaderMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestHeaderValuesMap()
-
- */
-
- public Map getRequestHeaderValuesMap() {
-
- //
-
- if (requestHeaderValues == null) {
-
- requestHeaderValues = new ContextMap() {
-
-
-
- public Object get(Object key) {
-
- // TODO - return configuration parameter from Cocoon
-
- // FacesAction
-
- return getCocoonRequest().getHeaders(key.toString());
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonRequest().getHeaderNames();
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return requestHeaderValues;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestLocale()
-
- */
-
- public Locale getRequestLocale() {
-
- //
-
- return getCocoonRequest().getLocale();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestLocales()
-
- */
-
- public Iterator getRequestLocales() {
-
- //
-
- return new EnumerationIterator(getCocoonRequest().getLocales());
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestMap()
-
- */
-
- public Map getRequestMap() {
-
- // TODO make Cocoon-specific realization ( interact with sitemap
-
- // parameters )
-
- if (requestMap == null) {
-
- requestMap = new ContextMap() {
-
- public Object get(Object key) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- if ("javax.servlet.include.path_info".equals(key)) {
-
- return getRequestPathInfo();
-
- // return getCocoonRequest().getAttribute(
-
- // FacesAction.ACT_SRC);
-
- }
-
- if ("javax.servlet.include.servlet_path".equals(key)) {
-
- return getRequestServletPath();
-
- // return getCocoonRequest().getAttribute(
-
- // FacesAction.ACT_MAPPING);
-
- }
-
- return getCocoonRequest().getAttribute(key.toString());
-
- }
-
-
-
- public Object put(Object key, Object value) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonRequest().getAttribute(keyString);
-
- getCocoonRequest().setAttribute(keyString, value);
-
- return (result);
-
- }
-
-
-
- public Object remove(Object key) {
-
- if (key == null) {
-
- return null;
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonRequest().getAttribute(keyString);
-
- getCocoonRequest().removeAttribute(keyString);
-
- return (result);
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonRequest().getAttributeNames();
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return requestMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestParameterMap()
-
- */
-
- public Map getRequestParameterMap() {
-
- //
-
- if (requestParameterMap == null) {
-
- requestParameterMap = new ContextConcatentedMap(
-
- (Map) (getCocoonRequest()
-
- .getAttribute(FacesAction.ACT_PARAMETERS))) {
-
-
-
- public Object getBase(Object key) {
-
- //
-
- return getCocoonRequest().getParameter(key.toString());
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonRequest().getParameterNames();
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return requestParameterMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestParameterNames()
-
- */
-
- public Iterator getRequestParameterNames() {
-
- // TODO Append Cocoon-specific parameters from FacesAction
-
- return this.getRequestParameterMap().entrySet().iterator();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
-
- */
-
- public Map getRequestParameterValuesMap() {
-
- //
-
- // TODO make Cocoon-specific realization ( interact with sitemap
-
- // parameters )
-
- if (requestParameterValuesMap == null) {
-
- requestParameterValuesMap = new ContextMap() {
-
-
-
- public Object get(Object key) {
-
- // TODO - return configuration parameter from Cocoon
-
- // FacesAction
-
- return getCocoonRequest()
-
- .getParameterValues(key.toString());
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonRequest().getParameterNames();
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return requestParameterValuesMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestPathInfo()
-
- */
-
- public String getRequestPathInfo() {
-
- //
-
- return (String) getCocoonRequest().getAttribute(FacesAction.ACT_SRC);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getRequestServletPath()
-
- */
-
- public String getRequestServletPath() {
-
- // TODO return current sitemap path ??? For cocoon, always "/" !
-
- return ""; // path;// ??? "";
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
-
- */
-
- public URL getResource(String path) throws MalformedURLException {
-
- //
-
- return getCocoonContext().getResource(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
-
- */
-
- public InputStream getResourceAsStream(String path) {
-
- return getCocoonContext().getResourceAsStream(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
-
- */
-
- public Set getResourcePaths(String path) {
-
- // Cocoon Context do not Have such method ...
-
- return null; //getCocoonHttpContext().getResourcePaths(path);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getResponse()
-
- */
-
- public Object getResponse() {
-
- //
-
- // return
-
- // this.getObjectModel().get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
-
- if (jspResponse == null) {
-
- // Create request based on Faces ResponseWriter. If no XML Consumer
-
- // ( in Action ) - use null writer .
-
- CocoonResponceWriter contextWriter = getWriter();
-
-
-
- jspResponse = new JSPServletResponse(getCocoonHttpResponse(),
-
- contextWriter);
-
- }
-
- return jspResponse;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getSession(boolean)
-
- */
-
- public Object getSession(boolean create) {
-
- // TODO Convert to HttpSession !!!
-
- return getCocoonRequest().getSession(create);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getSessionMap()
-
- */
-
- public Map getSessionMap() {
-
-
-
- if (sessionMap == null) {
-
- sessionMap = new ContextMap() {
-
-
-
- public Object get(Object key) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- return getCocoonSession().getAttribute(key.toString());
-
- }
-
-
-
- public Object put(Object key, Object value) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- String keyString = key.toString();
-
- Session session = getCocoonSession();
-
- Object result = session.getAttribute(keyString);
-
- session.setAttribute(keyString, value);
-
- return (result);
-
- }
-
-
-
- public Object remove(Object key) {
-
- if (key == null) {
-
- return null;
-
- }
-
- String keyString = key.toString();
-
- Session session = getCocoonSession();
-
- Object result = session.getAttribute(keyString);
-
- session.removeAttribute(keyString);
-
- return (result);
-
- }
-
-
-
- protected Enumeration getEnumeration() {
-
- return getCocoonSession().getAttributeNames();
-
- }
-
-
-
- private Session getCocoonSession() {
-
- return (Session) getSession(true);
-
- }
-
-
-
- };
-
-
-
- }
-
-
-
- return sessionMap;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#getUserPrincipal()
-
- */
-
- public Principal getUserPrincipal() {
-
- return getCocoonRequest().getUserPrincipal();
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#isUserInRole(java.lang.String)
-
- */
-
- public boolean isUserInRole(String role) {
-
- return getCocoonRequest().isUserInRole(role);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.ExternalContext#redirect(java.lang.String)
-
- */
-
- public void redirect(String url) throws IOException {
-
- // use Redirector Stored In objectModel Map
-
- ActionRedirector redirector = (ActionRedirector) getCocoonRequest()
-
- .getAttribute(FacesAction.ACT_REDIRECTOR);
-
- if (redirector != null) {
-
- try {
-
- redirector.redirect(false, url);
-
- } catch (ProcessingException e) {
-
- throw new IOException(e.getMessage());
-
- }
-
- }
-
- }
-
-
-
- // Private methods - for Cocoon Context Interaction.
-
- // TODO - rewrite as lazy creation, but need reset with change Context ?
-
-
-
- // private Map getObjectModel() {
-
- // return ContextHelper.getObjectModel(getCocoonContext());
-
- // }
-
-
-
- private Request getCocoonRequest() {
-
- return request;
-
- }
-
-
-
- private Response getCocoonResponse() {
-
- return response;
-
- }
-
-
-
- private org.apache.cocoon.environment.Context getCocoonContext() {
-
- return context;
-
- }
-
-
-
- /**
-
- * @return
-
- */
-
- private HttpContext getCocoonHttpContext() {
-
- //
-
-
-
- return http ? (HttpContext) context : null;
-
- }
-
-
-
- /**
-
- * @return
-
- */
-
- private HttpRequest getCocoonHttpRequest() {
-
- // TODO Auto-generated method stub
-
- return http ? (HttpRequest) this.request : null;
-
- }
-
-
-
- /**
-
- * @return
-
- */
-
- private HttpResponse getCocoonHttpResponse() {
-
- // TODO Auto-generated method stub
-
- return http ? (HttpResponse) this.response : null;
-
- }
-
-
-
- // Private classes for Maps
-
- private class EnumerationIterator implements Iterator {
-
-
-
- public EnumerationIterator(Enumeration locales) {
-
- this.locales = locales;
-
- }
-
-
-
- private Enumeration locales;
-
-
-
- public boolean hasNext() {
-
- return locales.hasMoreElements();
-
- }
-
-
-
- public Object next() {
-
- return locales.nextElement();
-
- }
-
-
-
- public void remove() {
-
- throw new UnsupportedOperationException();
-
- }
-
-
-
- }
-
-
-
- /**
-
- * @return Returns the actionSettings.
-
- */
-
- private Map getActionSettings() {
-
- if (actionSettings == null) {
-
- actionSettings = (Map) this.getCocoonRequest().getAttribute(
-
- FacesAction.ACT_CONFIGURATION);
-
- if (null == actionSettings) {
-
- actionSettings = Collections.EMPTY_MAP;
-
- }
-
- }
-
- return actionSettings;
-
- }
-
-}
\ No newline at end of file
Copied: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextImpl.java (from rev 48, trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextCocoonImpl.java)
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ExternalContextImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,1749 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+
+ * Created on 25.09.2004
+
+ *
+
+ * Copyright 1999-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.ajax4jsf.portlet.context;
+
+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.Enumeration;
+
+import java.util.Iterator;
+
+import java.util.Locale;
+
+import java.util.Map;
+
+import java.util.Set;
+
+import javax.faces.FacesException;
+
+import javax.faces.context.ExternalContext;
+
+import javax.servlet.RequestDispatcher;
+
+import javax.servlet.Servlet;
+
+import javax.servlet.ServletContext;
+
+import javax.servlet.ServletException;
+
+import javax.servlet.ServletResponse;
+
+/**
+ *
+ * @author shura
+ *
+ *
+ *
+ * Cocoon specific implementation of <code>ExternalContext</code> Use cocoon
+ *
+ * <code>Context</code> for Implement JSF Servlet specific functions Do not
+ *
+ * perform redirect - but tell <code>Action</code> for internal pipeline
+ *
+ * redirect ? or do normal Cocoon redirect Via Http Environment do not dispanch -
+ *
+ * use Cocoon generator source parametr, but perform generation Full
+ *
+ * Cocoon-specific realization ;
+ *
+ *
+ *
+ */
+
+public abstract class ExternalContextImpl extends ExternalContext {
+
+ // TODO - more configurable with sitemap parameters.
+
+ // TODO - optimization.
+
+ private Map applicationMap;
+
+ private Map initParameterMap;
+
+ private Map requestHeaderMap = null;
+
+ private Map requestHeaderValues;
+
+ private Map requestMap;
+
+ private Map requestParameterMap;
+
+ private Map requestParameterValuesMap;
+
+ private Map sessionMap;
+
+ private Object request;
+
+ private Object response;
+
+ private boolean http;
+
+ private Map actionSettings;
+
+ private Object context;
+
+ /**
+ *
+ * @param response
+ *
+ * @param request
+ *
+ * @param context
+ *
+ * @param defaultContext -
+ *
+ * default implementation of <code>ExternalFacesContext</code>.
+ *
+ */
+
+ public ExternalContextImpl(
+
+ Object context, Object request,
+
+ Object response) {
+
+ super();
+
+ this.context = context;
+
+ this.request = request;
+
+ this.response = response;
+
+ }
+
+
+
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
+ *
+ */
+
+ public void dispatch(String path) throws IOException {
+
+ // perform Generation in generator, do nothing in Action.
+
+ // generator place special Dispatcher to objectModel ...
+
+ // May be must set Dispatcher in special method in Context Component ???
+
+ String jspPageURL = (String) getCocoonRequest().getAttribute(
+
+ JSFGenerator.PAGE_URL_PARAM_NAME);
+
+ RequestDispatcher dispatcher = getCocoonHttpContext()
+
+ .getNamedDispatcher(getJspServletName());
+
+ this.log("Dispatch for page: " + jspPageURL);
+
+ // Dispatcher dispatch = getDispatcher();
+
+ if (dispatcher == null) {
+
+ throw new IOException("NamedDispatcher is null for servlet "
+
+ + getJspServletName());
+
+ }
+
+ try {// Reset jsp Request/Response wrappers - for create on demand
+
+ // with new Writer for current XML Consumer.
+
+ this.jspRequest = null;
+
+ this.jspResponse = null;
+
+ dispatcher.include(new JSPServletRequest(getCocoonHttpRequest(),
+
+ jspPageURL, null), (ServletResponse) this.getResponse());
+
+ } catch (ServletException e) {
+
+ //
+
+ if (e.getMessage() != null) {
+
+ throw new FacesException(e.getMessage(), e);
+
+ } else {
+
+ throw new FacesException(e);
+
+ }
+
+ }
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
+ *
+ */
+
+ public String encodeActionURL(String url) {
+
+ //
+
+ return getCocoonResponse().encodeURL(url);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
+ *
+ */
+
+ public String encodeNamespace(String name) {
+
+ // HACK - set namespace prefix in Action sitemap parameter.
+
+ // return this.getCocoonRequest().getContextPath()+"/"+name;
+
+ String namespace = (String) this.getCocoonRequest().getAttribute(
+
+ FacesAction.ACT_NAMESPACE);
+
+ if (null != namespace) {
+
+ return namespace + name;
+
+ }
+
+ return name;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
+ *
+ */
+
+ public String encodeResourceURL(String url) {
+
+ //
+
+ return this.getCocoonResponse().encodeURL(url);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getApplicationMap()
+ *
+ */
+
+ public Map getApplicationMap() {
+
+ //
+
+ if (applicationMap == null) {
+
+ applicationMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ return getCocoonContext().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonContext().getAttribute(keyString);
+
+ getCocoonContext().setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonContext().getAttribute(keyString);
+
+ getCocoonContext().removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonContext().getAttributeNames();
+
+ }
+
+ };
+
+ }
+
+ return applicationMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getAuthType()
+ *
+ */
+
+ public String getAuthType() {
+
+ //
+
+ return this.getCocoonRequest().getAuthType();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getContext()
+ *
+ */
+
+ public Object getContext() {
+
+ // Return special ServletContext decorator for default
+
+ // implementation ?
+
+ // As I see in JSF RI sources, used only for get Application Parameter ,
+
+ // but I
+
+ // want to store application parameters in objectModel.
+
+ // Correction - in Sun RI used for store application data between
+
+ // servelet context listenier
+
+ // ( configure JSF ) and to request processing data in Context#Attribute
+
+ // !
+
+ ServletContext servletContext = new ServletContext() {
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getContext(java.lang.String)
+ *
+ */
+
+ public ServletContext getContext(String uripath) {
+
+ return getCocoonHttpContext().getContext(uripath);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getMajorVersion()
+ *
+ */
+
+ public int getMajorVersion() {
+
+ return getCocoonHttpContext().getMajorVersion();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getMinorVersion()
+ *
+ */
+
+ public int getMinorVersion() {
+
+ return getCocoonHttpContext().getMinorVersion();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
+ *
+ */
+
+ public String getMimeType(String file) {
+
+ return getCocoonHttpContext().getMimeType(file);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
+ *
+ */
+
+ public Set getResourcePaths(String path) {
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getResource(java.lang.String)
+ *
+ */
+
+ public URL getResource(String path) throws MalformedURLException {
+
+ return ExternalContextImpl.this.getResource(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
+ *
+ */
+
+ public InputStream getResourceAsStream(String path) {
+
+ return ExternalContextImpl.this.getResourceAsStream(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
+ *
+ */
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+
+ return getCocoonHttpContext().getRequestDispatcher(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
+ *
+ */
+
+ public RequestDispatcher getNamedDispatcher(String name) {
+
+ return getCocoonHttpContext().getNamedDispatcher(name);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getServlet(java.lang.String)
+ *
+ */
+
+ public Servlet getServlet(String name) throws ServletException {
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getServlets()
+ *
+ */
+
+ public Enumeration getServlets() {
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getServletNames()
+ *
+ */
+
+ public Enumeration getServletNames() {
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#log(java.lang.String)
+ *
+ */
+
+ public void log(String msg) {
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#log(java.lang.Exception,
+ *
+ * java.lang.String)
+ *
+ */
+
+ public void log(Exception exception, String msg) {
+
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#log(java.lang.String,
+ *
+ * java.lang.Throwable)
+ *
+ */
+
+ public void log(String message, Throwable throwable) {
+
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
+ *
+ */
+
+ public String getRealPath(String path) {
+
+ // TODO Auto-generated method stub
+
+ return getCocoonHttpContext().getRealPath(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getServerInfo()
+ *
+ */
+
+ public String getServerInfo() {
+
+ // TODO Auto-generated method stub
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
+ *
+ */
+
+ public String getInitParameter(String name) {
+
+ // TODO Auto-generated method stub
+
+ return ExternalContextImpl.this.getInitParameter(name);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getInitParameterNames()
+ *
+ */
+
+ public Enumeration getInitParameterNames() {
+
+ // TODO Auto-generated method stub
+
+ return null;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
+ *
+ */
+
+ public Object getAttribute(String name) {
+
+ // TODO Auto-generated method stub
+
+ return getCocoonHttpContext().getAttribute(name);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getAttributeNames()
+ *
+ */
+
+ public Enumeration getAttributeNames() {
+
+ // TODO Auto-generated method stub
+
+ return getCocoonHttpContext().getAttributeNames();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#setAttribute(java.lang.String,
+ *
+ * java.lang.Object)
+ *
+ */
+
+ public void setAttribute(String name, Object object) {
+
+ // TODO Auto-generated method stub
+
+ getCocoonHttpContext().setAttribute(name, object);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
+ *
+ */
+
+ public void removeAttribute(String name) {
+
+ // TODO Auto-generated method stub
+
+ getCocoonHttpContext().removeAttribute(name);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.servlet.ServletContext#getServletContextName()
+ *
+ */
+
+ public String getServletContextName() {
+
+ // TODO Auto-generated method stub
+
+ return null;
+
+ }
+
+ };
+
+ return servletContext; // .getContext(getRequestContextPath());
+
+ // return getCocoonHttpContext();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ *
+ */
+
+ public String getInitParameter(String name) {
+
+ // HACK - get init parameter from Action configuration instead of
+
+ // servlet ...
+
+ String ret = (String) getActionSettings().get(name);
+
+ if (ret == null) {
+
+ ret = this.getCocoonContext().getInitParameter(name);
+
+ }
+
+ return ret;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameterMap()
+ *
+ */
+
+ public Map getInitParameterMap() {
+
+ // Combine Servlet InitParameters with Cocoon Action configuration
+
+ // parameters ?
+
+ if (initParameterMap == null) {
+
+ initParameterMap = new ContextConcatentedMap(this
+
+ .getActionSettings()) {
+
+ public Object getBase(Object key) {
+
+ // HACK - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonContext().getInitParameter(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ if (http) {
+
+ return getCocoonHttpContext().getInitParameterNames();
+
+ } else {
+
+ return Collections.enumeration(Collections.EMPTY_SET);
+
+ }
+
+ }
+
+ };
+
+ }
+
+ return initParameterMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRemoteUser()
+ *
+ */
+
+ public String getRemoteUser() {
+
+ //
+
+ return getCocoonRequest().getRemoteUser();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequest()
+ *
+ */
+
+ public Object getRequest() {
+
+ return request;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestContextPath()
+ *
+ */
+
+ public String getRequestContextPath() {
+
+ // TODO return Cocoon sitemap-specific path ? or configure from sitemap
+
+ // parameters of Action.
+
+ return getCocoonRequest().getContextPath();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestCookieMap()
+ *
+ */
+
+ public Map getRequestCookieMap() {
+
+ //
+
+ return getCocoonRequest().getCookieMap();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
+ *
+ */
+
+ public Map getRequestHeaderMap() {
+
+ // TODO Return values of Http headers, or, may be, addition values from
+
+ // Action parameters .
+
+ if (requestHeaderMap == null) {
+
+ requestHeaderMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest().getHeader(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getHeaderNames();
+
+ }
+
+ };
+
+ }
+
+ return requestHeaderMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestHeaderValuesMap()
+ *
+ */
+
+ public Map getRequestHeaderValuesMap() {
+
+ //
+
+ if (requestHeaderValues == null) {
+
+ requestHeaderValues = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest().getHeaders(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getHeaderNames();
+
+ }
+
+ };
+
+ }
+
+ return requestHeaderValues;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestLocale()
+ *
+ */
+
+ public Locale getRequestLocale() {
+
+ //
+
+ return getCocoonRequest().getLocale();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestLocales()
+ *
+ */
+
+ public Iterator getRequestLocales() {
+
+ //
+
+ return new EnumerationIterator(getCocoonRequest().getLocales());
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestMap()
+ *
+ */
+
+ public Map getRequestMap() {
+
+ // TODO make Cocoon-specific realization ( interact with sitemap
+
+ // parameters )
+
+ if (requestMap == null) {
+
+ requestMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ if ("javax.servlet.include.path_info".equals(key)) {
+
+ return getRequestPathInfo();
+
+ // return getCocoonRequest().getAttribute(
+
+ // FacesAction.ACT_SRC);
+
+ }
+
+ if ("javax.servlet.include.servlet_path".equals(key)) {
+
+ return getRequestServletPath();
+
+ // return getCocoonRequest().getAttribute(
+
+ // FacesAction.ACT_MAPPING);
+
+ }
+
+ return getCocoonRequest().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonRequest().getAttribute(keyString);
+
+ getCocoonRequest().setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Object result = getCocoonRequest().getAttribute(keyString);
+
+ getCocoonRequest().removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getAttributeNames();
+
+ }
+
+ };
+
+ }
+
+ return requestMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterMap()
+ *
+ */
+
+ public Map getRequestParameterMap() {
+
+ //
+
+ if (requestParameterMap == null) {
+
+ requestParameterMap = new ContextConcatentedMap(
+
+ (Map) (getCocoonRequest()
+
+ .getAttribute(FacesAction.ACT_PARAMETERS))) {
+
+ public Object getBase(Object key) {
+
+ //
+
+ return getCocoonRequest().getParameter(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getParameterNames();
+
+ }
+
+ };
+
+ }
+
+ return requestParameterMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterNames()
+ *
+ */
+
+ public Iterator getRequestParameterNames() {
+
+ // TODO Append Cocoon-specific parameters from FacesAction
+
+ return this.getRequestParameterMap().entrySet().iterator();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
+ *
+ */
+
+ public Map getRequestParameterValuesMap() {
+
+ //
+
+ // TODO make Cocoon-specific realization ( interact with sitemap
+
+ // parameters )
+
+ if (requestParameterValuesMap == null) {
+
+ requestParameterValuesMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ // TODO - return configuration parameter from Cocoon
+
+ // FacesAction
+
+ return getCocoonRequest()
+
+ .getParameterValues(key.toString());
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonRequest().getParameterNames();
+
+ }
+
+ };
+
+ }
+
+ return requestParameterValuesMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestPathInfo()
+ *
+ */
+
+ public String getRequestPathInfo() {
+
+ //
+
+ return (String) getCocoonRequest().getAttribute(FacesAction.ACT_SRC);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestServletPath()
+ *
+ */
+
+ public String getRequestServletPath() {
+
+ // TODO return current sitemap path ??? For cocoon, always "/" !
+
+ return ""; // path;// ??? "";
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ *
+ */
+
+ public URL getResource(String path) throws MalformedURLException {
+
+ //
+
+ return getCocoonContext().getResource(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ *
+ */
+
+ public InputStream getResourceAsStream(String path) {
+
+ return getCocoonContext().getResourceAsStream(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ *
+ */
+
+ public Set getResourcePaths(String path) {
+
+ // Cocoon Context do not Have such method ...
+
+ return null; // getCocoonHttpContext().getResourcePaths(path);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResponse()
+ *
+ */
+
+ public Object getResponse() {
+ return response;
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getSession(boolean)
+ *
+ */
+
+ public Object getSession(boolean create) {
+
+ // TODO Convert to HttpSession !!!
+
+ return getCocoonRequest().getSession(create);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getSessionMap()
+ *
+ */
+
+ public Map getSessionMap() {
+
+ if (sessionMap == null) {
+
+ sessionMap = new ContextMap() {
+
+ public Object get(Object key) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ return getCocoonSession().getAttribute(key.toString());
+
+ }
+
+ public Object put(Object key, Object value) {
+
+ if (key == null) {
+
+ throw new NullPointerException();
+
+ }
+
+ String keyString = key.toString();
+
+ Session session = getCocoonSession();
+
+ Object result = session.getAttribute(keyString);
+
+ session.setAttribute(keyString, value);
+
+ return (result);
+
+ }
+
+ public Object remove(Object key) {
+
+ if (key == null) {
+
+ return null;
+
+ }
+
+ String keyString = key.toString();
+
+ Session session = getCocoonSession();
+
+ Object result = session.getAttribute(keyString);
+
+ session.removeAttribute(keyString);
+
+ return (result);
+
+ }
+
+ protected Enumeration getEnumeration() {
+
+ return getCocoonSession().getAttributeNames();
+
+ }
+
+ private Session getCocoonSession() {
+
+ return (Session) getSession(true);
+
+ }
+
+ };
+
+ }
+
+ return sessionMap;
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getUserPrincipal()
+ *
+ */
+
+ public Principal getUserPrincipal() {
+
+ return getCocoonRequest().getUserPrincipal();
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#isUserInRole(java.lang.String)
+ *
+ */
+
+ public boolean isUserInRole(String role) {
+
+ return getCocoonRequest().isUserInRole(role);
+
+ }
+
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#redirect(java.lang.String)
+ *
+ */
+
+ public void redirect(String url) throws IOException {
+
+ // use Redirector Stored In objectModel Map
+
+ ActionRedirector redirector = (ActionRedirector) getCocoonRequest()
+
+ .getAttribute(FacesAction.ACT_REDIRECTOR);
+
+ if (redirector != null) {
+
+ try {
+
+ redirector.redirect(false, url);
+
+ } catch (ProcessingException e) {
+
+ throw new IOException(e.getMessage());
+
+ }
+
+ }
+
+ }
+
+ // Private methods - for Cocoon Context Interaction.
+
+ // TODO - rewrite as lazy creation, but need reset with change Context ?
+
+ // private Map getObjectModel() {
+
+ // return ContextHelper.getObjectModel(getCocoonContext());
+
+ // }
+
+ private Request getCocoonRequest() {
+
+ return request;
+
+ }
+
+ private Response getCocoonResponse() {
+
+ return response;
+
+ }
+
+ private org.apache.cocoon.environment.Context getCocoonContext() {
+
+ return context;
+
+ }
+
+ /**
+ *
+ * @return
+ *
+ */
+
+ private HttpContext getCocoonHttpContext() {
+
+ //
+
+ return http ? (HttpContext) context : null;
+
+ }
+
+ /**
+ *
+ * @return
+ *
+ */
+
+ private HttpRequest getCocoonHttpRequest() {
+
+ // TODO Auto-generated method stub
+
+ return http ? (HttpRequest) this.request : null;
+
+ }
+
+ /**
+ *
+ * @return
+ *
+ */
+
+ private HttpResponse getCocoonHttpResponse() {
+
+ // TODO Auto-generated method stub
+
+ return http ? (HttpResponse) this.response : null;
+
+ }
+
+ // Private classes for Maps
+
+ private class EnumerationIterator implements Iterator {
+
+ public EnumerationIterator(Enumeration locales) {
+
+ this.locales = locales;
+
+ }
+
+ private Enumeration locales;
+
+ public boolean hasNext() {
+
+ return locales.hasMoreElements();
+
+ }
+
+ public Object next() {
+
+ return locales.nextElement();
+
+ }
+
+ public void remove() {
+
+ throw new UnsupportedOperationException();
+
+ }
+
+ }
+
+ /**
+ *
+ * @return Returns the actionSettings.
+ *
+ */
+
+ private Map getActionSettings() {
+
+ if (actionSettings == null) {
+
+ actionSettings = (Map) this.getCocoonRequest().getAttribute(
+
+ FacesAction.ACT_CONFIGURATION);
+
+ if (null == actionSettings) {
+
+ actionSettings = Collections.EMPTY_MAP;
+
+ }
+
+ }
+
+ return actionSettings;
+
+ }
+
+}
\ No newline at end of file
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -51,246 +51,100 @@
* limitations under the License.
- */
+ */
-package org.apache.cocoon.components.faces.context;
+package org.ajax4jsf.portlet.context;
-
+import java.util.Map;
-import java.util.Map;
+import javax.faces.FacesException;
-
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
-import javax.faces.FacesException;
+import javax.faces.context.FacesContextFactory;
-import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
-import javax.faces.context.FacesContextFactory;
+/**
+ *
+ * @author shura Implementation of <code>FacesContextFactory</code> for
+ * Portlet
+ *
+ * Environment Use default factory for create default Faces
+ *
+ * implementation context and setup wrappers for it.
+ *
+ *
+ *
+ *
+ *
+ */
-import javax.faces.lifecycle.Lifecycle;
+public class FacesContextFactoryImpl extends FacesContextFactory {
-
+ /**
+ *
+ * Hold <code>FacesContextFactory</code> from default implementation.
+ *
+ */
-import org.apache.avalon.framework.context.Context;
+ private FacesContextFactory defaultFacesContextFactory;
-import org.apache.avalon.framework.context.ContextException;
+ public static final String FACES_CONTEXT_KEY = "COCOON_FACES_CONTEXT";
-import org.apache.avalon.framework.service.ServiceException;
+ /**
+ *
+ * Create instance of Faces context factory, based on implementation.
+ *
+ * @param defaultFactory -
+ *
+ * Factory from JSF implementation.
+ *
+ */
-import org.apache.avalon.framework.service.ServiceManager;
+ public FacesContextFactoryImpl(FacesContextFactory defaultFactory) {
+ super();
+ if (this.defaultFacesContextFactory == null) {
+ this.defaultFacesContextFactory = defaultFactory;
+ }
+ }
-import org.apache.cocoon.components.ContextHelper;
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
+ *
+ * java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
+ *
+ */
-import org.apache.cocoon.components.persistence.RequestDataStore;
+ public FacesContext getFacesContext(Object context, Object request,
+ Object response, Lifecycle lifecycle) throws FacesException {
+ if(null == context || null == request || null == response || null == lifecycle){
+ throw new NullPointerException("One or more parameters for a faces context instantiation is null");
+ }
+ ExternalContext externalContext;
+ if(context instanceof PortletContext && request instanceof PortletRequest && response instanceof PortletResponse){
+ externalContext = new PortletContextImpl( context,
+ request,
+ response);
+ } else if(context instanceof ServletContext && request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
+ externalContext = new ServletContextImpl( context,
+ request,
+ response);
+ }
+ return new FacesContextImpl(externalContext,lifecycle);
-import org.apache.cocoon.environment.ObjectModelHelper;
+ }
-import org.apache.cocoon.environment.Request;
-
-import org.apache.cocoon.environment.Response;
-
-
-
-/**
-
- * @author shura Implementation of <code>FacesContextFactory</code> for Cocoon
-
- * Environment Use default factory for create default Faces
-
- * implementation context and setup wrappers for it.
-
- *
-
- *
-
- */
-
-public class FacesContextFactoryImpl extends FacesContextFactory {
-
-
-
- /**
-
- * Hold <code>FacesContextFactory</code> from default implementation.
-
- */
-
- private FacesContextFactory defaultFacesContextFactory;
-
-
-
- public static final String FACES_CONTEXT_KEY = "COCOON_FACES_CONTEXT";
-
-
-
- /**
-
- * Create instance of Faces context factory, based on implementation.
-
- *
-
- * @param defaultFactory -
-
- * Factory from JSF implementation.
-
- */
-
- public FacesContextFactoryImpl(FacesContextFactory defaultFactory) {
-
- super();
-
- if (this.defaultFacesContextFactory == null) {
-
- this.defaultFacesContextFactory = defaultFactory;
-
- }
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
-
- * java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
-
- */
-
- public FacesContext getFacesContext(Object context, Object request,
-
- Object response, Lifecycle lifecycle) throws FacesException {
-
-
-
- if (!(context instanceof Context)) {
-
- throw new FacesException("Context must be instance of "
-
- + Context.class.getName());
-
- }
-
-
-
- if (!(request instanceof Request)) {
-
- throw new FacesException("Request must be instance of "
-
- + Request.class.getName());
-
- }
-
-
-
- if (!(response instanceof Response)) {
-
- throw new FacesException("Response must be instance of "
-
- + Response.class.getName());
-
- }
-
-
-
- Context cocoonContext = (Context) context;
-
- CocoonFacesContext facesContext = null;
-
- ServiceManager manager;
-
- Map objectModel = ContextHelper.getObjectModel(cocoonContext);
-
-
-
- // Get servlet context, request & responce from cocoon context.
-
- // Create wrappers for use default implementation ...
-
-
-
- /*
-
- * ServletRequest servletRequest = (ServletRequest) objectModel
-
- * .get(HttpEnvironment.HTTP_REQUEST_OBJECT); ServletResponse
-
- * servletResponce = (ServletResponse) objectModel
-
- * .get(HttpEnvironment.HTTP_RESPONSE_OBJECT); ServletContext
-
- * servletContext = (ServletContext) objectModel
-
- * .get(HttpEnvironment.HTTP_SERVLET_CONTEXT); // Create FacesContext
-
- * via implementation-specific Factory. FacesContext defaultContext =
-
- * defaultFacesContextFactory .getFacesContext(servletContext,
-
- * servletRequest, servletResponce, lifecycle);
-
- */
-
- try {
-
- manager = (ServiceManager) cocoonContext
-
- .get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
-
- } catch (ContextException e) {
-
- // Missing servicemanager ???
-
- throw new FacesException("Error get ServiceManager from Context", e);
-
- }
-
- try {
-
- // Create FacesContext implementation from Cocoon component model
-
- facesContext = (CocoonFacesContext) manager
-
- .lookup(CocoonFacesContext.ROLE);
-
- // Setup as wrapper for default context ...
-
- facesContext.setupContext(
-
- ObjectModelHelper.getContext(objectModel),
-
- (Request) request, (Response) response, lifecycle);
-
- // Store context until Request processed - for generator/transformer
-
- // ( render View phase )
-
- RequestDataStore dataStore = (RequestDataStore) manager
-
- .lookup(RequestDataStore.ROLE);
-
- dataStore.setRequestData(CocoonFacesContext.ROLE, facesContext);
-
- } catch (ServiceException e) {
-
- //
-
- throw new FacesException("Error lookup component ", e);
-
- }
-
- // TODO - check parameters, RenderKit initialization ...
-
-
-
- return facesContext.getFacesContext();
-
- }
-
-
-
}
\ No newline at end of file
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -51,848 +51,471 @@
* limitations under the License.
- */
+ */
-package org.apache.cocoon.components.faces.context;
+package org.ajax4jsf.portlet.context;
-
+import java.util.ArrayList;
+import java.util.HashMap;
-import java.util.ArrayList;
+import java.util.Collections;
-import java.util.Collections;
+import java.util.Iterator;
-import java.util.Iterator;
+import java.util.List;
-import java.util.List;
+import java.util.Map;
-import java.util.Map;
+import javax.el.ELContext;
+import javax.faces.FactoryFinder;
-
+import javax.faces.application.Application;
-import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
-import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
-import javax.faces.application.ApplicationFactory;
+import javax.faces.application.FacesMessage.Severity;
-import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
-import javax.faces.application.FacesMessage.Severity;
+import javax.faces.context.ExternalContext;
-import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
-import javax.faces.context.ExternalContext;
+import javax.faces.context.ResponseStream;
-import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
-import javax.faces.context.ResponseStream;
+import javax.faces.lifecycle.Lifecycle;
-import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
-import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKitFactory;
-import javax.faces.render.RenderKit;
+/**
+ *
+ * @author shura
+ *
+ *
+ *
+ * Implementation for <code>FacesContext</code> in Cocoon Environment. Best -
+ *
+ * Act as decorator for default FacesContext implementation, but Sun
+ *
+ * implementstion use too many servlet functions ... Configure in cocoon.xconf
+ *
+ * with next global parameters : name of JSP servlet to NamedDispatcher. In
+ *
+ * Tomcat - "jsp" <parameter name="servlet-name" value="jsp"/>
+ *
+ *
+ *
+ * TODO - Implement as <code>Serviciable</code>,<code>Pullable</code>
+ *
+ * Avalon component ?
+ *
+ *
+ *
+ */
-import javax.faces.render.RenderKitFactory;
+public class FacesContextImpl extends FacesContext {
-
+ private boolean released = true;
-import org.apache.avalon.framework.logger.Logger;
+ private boolean renderResponse;
-import org.apache.avalon.framework.parameters.Parameters;
+ private boolean responseComplete;
-import org.apache.cocoon.components.faces.renderkit.CocoonResponceWriter;
+ private Application application;
-import org.apache.cocoon.environment.Context;
+ private UIViewRoot viewRoot;
-import org.apache.cocoon.environment.Request;
+ private Map messages;
-import org.apache.cocoon.environment.Response;
+ private ExternalContext externalContext;
-import org.apache.cocoon.util.HashMap;
+ private Lifecycle lifecycle;
-import org.apache.cocoon.xml.XMLConsumer;
+ private ResponseWriter responseWriter;
-
+ private ResponseStream responseStream;
-/**
+ private ELContext elContext;
- * @author shura
+ public FacesContextImpl(ExternalContext externalContext,
+ Lifecycle lifecycle) {
+ super();
+ setCurrentInstance(this);
+ this.externalContext = externalContext;
+ this.lifecycle = lifecycle;
+ }
- *
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see org.apache.cocoon.components.faces.context.CocoonFacesContext#getLifecycle()
+ *
+ */
- * Implementation for <code>FacesContext</code> in Cocoon Environment. Best -
+ public Lifecycle getLifecycle() {
- * Act as decorator for default FacesContext implementation, but Sun
+ return lifecycle;
- * implementstion use too many servlet functions ... Configure in cocoon.xconf
+ }
- * with next global parameters : name of JSP servlet to NamedDispatcher. In
- * Tomcat - "jsp" <parameter name="servlet-name" value="jsp"/>
+ public ELContext getELContext() {
+ checkReleased();
+ if (elContext == null) {
+ elContext = new ELContextImpl(getApplication().getELResolver());
+ elContext.putContext(FacesContext.class, this);
+ UIViewRoot root = getViewRoot();
+ if (null!=root) {
+ elContext.setLocale(root.getLocale());
+ }
+ }
- *
+ return elContext;
+ }
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#getExternalContext()
+ *
+ */
- * TODO - Implement as <code>Serviciable</code>,<code>Pullable</code>
+ public ExternalContext getExternalContext() {
+ checkReleased();
+ return externalContext;
+ }
- * Avalon component ?
+ /**
+ *
+ * @param externalContext
+ *
+ * The externalContext to set.
+ *
+ */
- *
+ // public void setExternalContext(ExternalContext externalContext) {
+ // this.externalContext = externalContext;
+ // }
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#getResponseStream()
+ *
+ */
- */
+ public ResponseStream getResponseStream() {
+ return this.responseStream;
+ }
-public class FacesContextImpl extends FacesContext implements
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#setResponseStream(javax.faces.context.ResponseStream)
+ *
+ */
- CocoonFacesContext {
+ public void setResponseStream(ResponseStream responseStream) {
+ this.responseStream = responseStream;
+ }
-
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#getResponseWriter()
+ *
+ */
- private boolean released = true;
+ public ResponseWriter getResponseWriter() {
+ checkReleased();
+ return responseWriter;
+ }
-
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#setResponseWriter(javax.faces.context.ResponseWriter)
+ *
+ */
- private boolean renderResponse;
+ public void setResponseWriter(ResponseWriter responseWriter) {
+ checkReleased();
+ this.responseWriter = responseWriter;
+ }
-
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.FacesContext#release()
+ *
+ */
- private boolean responseComplete;
+ public void release() {
-
+ // Release this and default instances...
- private Application application;
+ this.released = true;
-
+ FacesContext.setCurrentInstance(null);
- private UIViewRoot viewRoot;
+ // defaultContext = null;
-
+ this.lifecycle = null;
- private Map messages;
+ this.externalContext = null;
-
+ this.responseWriter = null;
- private ExternalContext externalContext;
+ this.application = null;
-
+ this.viewRoot = null;
- // private FacesContext defaultContext;
+ this.messages = null;
-
+ this.responseWriter = null;
- private HashMap settings;
+ }
-
- private Context context;
+ public Application getApplication() {
-
+ checkReleased();
- private Logger logger;
+ if (application == null) {
-
+ ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder
- private Lifecycle lifecycle;
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
-
+ this.application = aFactory.getApplication();
- private XMLConsumer consumer;
+ }
-
+ return this.application;
- private ResponseWriter responseWriter;
+ }
-
+ public Iterator getClientIdsWithMessages() {
- public static final String ROLE = FacesContextImpl.class.getName();
+ checkReleased();
-
+ if (this.messages == null) {
- private String jspServletName;
+ return Collections.EMPTY_LIST.iterator();
-
+ } else {
- private static final String DEFAULT_SERVLET_NAME = "jsp";
+ return this.messages.keySet().iterator();
-
+ }
- private Request request;
+ }
-
+ public Severity getMaximumSeverity() {
+ checkReleased();
+ Severity max = null;
+ Iterator messages = getMessages();
+ while (messages.hasNext()) {
+ FacesMessage msg = (FacesMessage) messages.next();
+ Severity severity = msg.getSeverity();
+ if(null == max || max.getOrdinal() < severity.getOrdinal()){
+ max=severity;
+ }
+ }
+ return max;
+ }
- private Response response;
+ public Iterator getMessages() {
-
+ checkReleased();
- /**
+ if (this.messages == null) {
- * This component recognize next configuration paremeters : - servlet-name
+ return Collections.EMPTY_LIST.iterator();
- * The name of JSP Servlet in current container.
+ }
- *
+ List messages = new ArrayList();
- * @param params
+ for (Iterator i = this.messages.values().iterator(); i.hasNext();) {
- * The configuration parameters
+ final List list = (List) i.next();
- */
+ messages.addAll(list);
- public void parameterize(Parameters params) {
+ }
- this.jspServletName = params.getParameter("servlet-name",
+ if (messages.size() > 0) {
- DEFAULT_SERVLET_NAME);
+ return messages.iterator();
- }
+ }
-
+ return Collections.EMPTY_LIST.iterator();
- /*
+ }
- * (non-Javadoc)
+ public Iterator getMessages(String clientID) {
- *
+ checkReleased();
- * @see org.apache.cocoon.components.faces.context.CocoonFacesContext#setXmlConsumer(org.apache.cocoon.xml.XMLConsumer)
+ if (this.messages != null) {
- */
+ final List list = (List) this.messages.get(clientID);
- public void setXmlConsumer(XMLConsumer consumer) {
+ if (list != null) {
- //
+ return list.iterator();
- checkReleased();
+ }
- this.consumer = consumer;
+ }
- this.responseWriter = null;
+ return Collections.EMPTY_LIST.iterator();
- }
+ }
-
+ public RenderKit getRenderKit() {
- /*
+ checkReleased();
- * (non-Javadoc)
+ UIViewRoot viewRoot = getViewRoot();
- *
+ if (viewRoot == null) {
- * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+ return null;
- */
+ }
- public void enableLogging(Logger logger) {
+ String renderKitId = viewRoot.getRenderKitId();
- // store for future use ...
+ if (renderKitId == null) {
- this.logger = logger;
+ return null;
- }
+ } else {
-
+ RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
- /**
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- *
+ return rkFactory.getRenderKit(this, renderKitId);
- */
+ }
- public FacesContextImpl() {
+ }
- super();
+ public boolean getRenderResponse() {
- setCurrentInstance(this);
+ checkReleased();
- }
+ return this.renderResponse;
-
+ }
- /*
+ public boolean getResponseComplete() {
- * (non-Javadoc)
+ checkReleased();
- *
+ return this.responseComplete;
- * @see org.apache.cocoon.components.faces.context.CocoonFacesContext#setupContext(javax.faces.context.FacesContext)
+ }
- */
+ public UIViewRoot getViewRoot() {
- public void setupContext(Context context, Request request,
+ checkReleased();
- Response response, Lifecycle lifecycle) {
+ return this.viewRoot;
- // Set current instance as default for current thread
+ }
- if (null != lifecycle) {
+ public void setViewRoot(UIViewRoot viewRoot) {
- this.lifecycle = lifecycle;
+ checkReleased();
- }
+ this.viewRoot = viewRoot;
- this.context = context;
+ }
- this.request = request;
+ public void addMessage(String clientID, FacesMessage message) {
- this.response = response;
+ checkReleased();
- this.released = false;
+ if (message == null) {
- this.externalContext = null;
+ throw new NullPointerException("Message can't be null");
- setCurrentInstance(this);
+ }
-
+ if (messages == null) {
- }
+ messages = new HashMap();
-
+ }
- /*
+ List list = (List) messages.get(clientID);
- * (non-Javadoc)
+ if (list == null) {
- *
+ list = new ArrayList();
- * @see org.apache.cocoon.components.faces.context.CocoonFacesContext#getLifecycle()
+ messages.put(clientID, list);
- */
+ }
- public Lifecycle getLifecycle() {
+ list.add(message);
-
+ }
- return lifecycle;
+ public void renderResponse() {
- }
+ checkReleased();
-
+ this.renderResponse = true;
- /*
+ }
- * (non-Javadoc)
+ public void responseComplete() {
- *
+ checkReleased();
- * @see org.apache.cocoon.components.faces.context.CocoonFacesContext#getFacesContext()
+ this.responseComplete = true;
- */
+ }
- public FacesContext getFacesContext() {
+ private void checkReleased() {
- // return current component instance as faces context. To divide
+ if (released) {
- // Component and Context functions...
+ throw new IllegalStateException("Context is released.");
- return this;
+ }
- }
+ }
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#getExternalContext()
-
- */
-
- public ExternalContext getExternalContext() {
-
- checkReleased();
-
- if (externalContext == null) {
-
- externalContext = new ExternalContextCocoonImpl(context, request,
-
- response) {
-
-
-
- CocoonResponceWriter getWriter() {
-
- return (CocoonResponceWriter) getResponseWriter();
-
- }
-
-
-
- public void log(String message) {
-
- logger.debug(message);
-
- }
-
-
-
- public void log(String message, Throwable t) {
-
- logger.debug(message, t);
-
- }
-
-
-
- String getJspServletName() {
-
- return jspServletName;
-
- }
-
- };
-
- }
-
- return externalContext;
-
- }
-
-
-
- /**
-
- * @param externalContext
-
- * The externalContext to set.
-
- */
-
- // public void setExternalContext(ExternalContext externalContext) {
-
- // this.externalContext = externalContext;
-
- // }
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#getResponseStream()
-
- */
-
- public ResponseStream getResponseStream() {
-
- //
-
- // return defaultContext.getResponseStream();
-
- throw new UnsupportedOperationException("ResponseStream disabled...");
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#setResponseStream(javax.faces.context.ResponseStream)
-
- */
-
- public void setResponseStream(ResponseStream responseStream) {
-
- //
-
- // defaultContext.setResponseStream(responseStream);
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#getResponseWriter()
-
- */
-
- public ResponseWriter getResponseWriter() {
-
- // HACK - create SAX Consumer-based writer, instead of RenderKit
-
- // return defaultContext.getResponseWriter();
-
- checkReleased();
-
- if (responseWriter == null && consumer != null) {
-
- responseWriter = new CocoonResponceWriter(consumer);
-
-
-
- }
-
-
-
- return responseWriter;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#setResponseWriter(javax.faces.context.ResponseWriter)
-
- */
-
- public void setResponseWriter(ResponseWriter responseWriter) {
-
- // HACK - only current implementation Writer allowed
-
- checkReleased();
-
- if (responseWriter instanceof CocoonResponceWriter) {
-
- this.responseWriter = responseWriter;
-
- // defaultContext.setResponseWriter(responseWriter);
-
- }
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see javax.faces.context.FacesContext#release()
-
- */
-
- public void release() {
-
- // Release this and default instances...
-
- this.released = true;
-
- FacesContext.setCurrentInstance(null);
-
-
-
- // defaultContext = null;
-
-
-
- lifecycle = null;
-
- externalContext = null;
-
- responseWriter = null;
-
- consumer = null;
-
-
-
- this.application = null;
-
- this.viewRoot = null;
-
- this.messages = null;
-
-
-
- this.responseWriter = null;
-
- }
-
-
-
- /*
-
- * (non-Javadoc)
-
- *
-
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
-
- */
-
- public void dispose() {
-
- //
-
- release();
-
- }
-
-
-
- public Application getApplication() {
-
- checkReleased();
-
-
-
- if (application == null) {
-
- ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder
-
- .getFactory(FactoryFinder.APPLICATION_FACTORY);
-
- this.application = aFactory.getApplication();
-
- }
-
-
-
- return this.application;
-
- }
-
-
-
- public Iterator getClientIdsWithMessages() {
-
- checkReleased();
-
-
-
- if (this.messages == null) {
-
- return Collections.EMPTY_LIST.iterator();
-
- } else {
-
- return this.messages.keySet().iterator();
-
- }
-
- }
-
-
-
- public Severity getMaximumSeverity() {
-
- throw new UnsupportedOperationException();
-
- }
-
-
-
- public Iterator getMessages() {
-
- checkReleased();
-
- if (this.messages == null) {
-
- return Collections.EMPTY_LIST.iterator();
-
- }
-
-
-
- List messages = new ArrayList();
-
- for (Iterator i = this.messages.values().iterator(); i.hasNext();) {
-
- final List list = (List) i.next();
-
- messages.addAll(list);
-
- }
-
-
-
- if (messages.size() > 0) {
-
- return messages.iterator();
-
- }
-
-
-
- return Collections.EMPTY_LIST.iterator();
-
- }
-
-
-
- public Iterator getMessages(String clientID) {
-
- checkReleased();
-
- if (this.messages != null) {
-
- final List list = (List) this.messages.get(clientID);
-
- if (list != null) {
-
- return list.iterator();
-
- }
-
- }
-
-
-
- return Collections.EMPTY_LIST.iterator();
-
- }
-
-
-
- public RenderKit getRenderKit() {
-
- checkReleased();
-
-
-
- UIViewRoot viewRoot = getViewRoot();
-
- if (viewRoot == null) {
-
- return null;
-
- }
-
-
-
- String renderKitId = viewRoot.getRenderKitId();
-
- if (renderKitId == null) {
-
- return null;
-
- } else {
-
- RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
-
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-
- return rkFactory.getRenderKit(this, renderKitId);
-
- }
-
- }
-
-
-
- public boolean getRenderResponse() {
-
- checkReleased();
-
- return this.renderResponse;
-
- }
-
-
-
- public boolean getResponseComplete() {
-
- checkReleased();
-
- return this.responseComplete;
-
- }
-
-
-
- public UIViewRoot getViewRoot() {
-
- checkReleased();
-
- return this.viewRoot;
-
- }
-
-
-
- public void setViewRoot(UIViewRoot viewRoot) {
-
- checkReleased();
-
- this.viewRoot = viewRoot;
-
- }
-
-
-
- public void addMessage(String clientID, FacesMessage message) {
-
- checkReleased();
-
- if (message == null) {
-
- throw new NullPointerException("Message can't be null");
-
- }
-
-
-
- if (messages == null) {
-
- messages = new HashMap();
-
- }
-
-
-
- List list = (List) messages.get(clientID);
-
- if (list == null) {
-
- list = new ArrayList();
-
- messages.put(clientID, list);
-
- }
-
-
-
- list.add(message);
-
- }
-
-
-
- public void renderResponse() {
-
- checkReleased();
-
- this.renderResponse = true;
-
- }
-
-
-
- public void responseComplete() {
-
- checkReleased();
-
- this.responseComplete = true;
-
- }
-
-
-
- private void checkReleased() {
-
- if (released) {
-
- throw new IllegalStateException("Context is released.");
-
- }
-
- }
-
}
\ No newline at end of file
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,41 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletContextImpl extends AbstractExternalContext {
+
+ public PortletContextImpl(Object context, Object request, Object response) {
+ super(context, request, response);
+ }
+
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public URL getResource(String path) throws MalformedURLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set getResourcePaths(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ServletContextImpl extends AbstractExternalContext {
+
+ /**
+ * @param context
+ * @param request
+ * @param response
+ */
+ public ServletContextImpl(Object context, Object request, Object response) {
+ super(context, request, response);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ */
+ public URL getResource(String path) throws MalformedURLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ */
+ public Set getResourcePaths(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleFactoryImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleFactoryImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleFactoryImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,111 @@
+/*
+ * CDDL HEADER START
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the License). You may not use this file except in
+ * compliance with the License.
+ *
+ * You can obtain a copy of the License at
+ * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
+ * See the License for the specific language governing
+ * permission and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * Header Notice in each file and include the License file
+ * at legal/CDDLv1.0.txt.
+ * If applicable, add the following below the CDDL Header,
+ * with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
+ * CDDL HEADER END
+ */
+
+package org.ajax4jsf.portlet.lifecycle;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+
+/**
+ * <p>Custom implementation of <code>LifecycleFactory</code> that
+ * provides the portlet-specific <code>Lifecycle</code> by default.</p>
+ */
+
+public final class LifecycleFactoryImpl extends LifecycleFactory {
+
+ // The Logger instance for this class
+ private static Logger logger = Logger.getLogger(LifecycleFactoryImpl.class.getPackage().getName(), "JSFPLogMessages");
+
+ // ------------------------------------------------------------ Constructors
+
+
+ public LifecycleFactoryImpl() {
+ logger.log(Level.FINE, "PS_CSFP0023", this);
+ addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE, new LifecycleImpl());
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ // Registered Lifecycle instances, keyed by lifecycle identifier
+ private Map lifecycles = new HashMap();
+
+
+ // ---------------------------------------------------------- Public Methods
+
+
+ public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
+
+ if ((lifecycleId == null) || (lifecycle == null)) {
+ throw new NullPointerException();
+ }
+ synchronized (lifecycles) {
+ if (lifecycles.containsKey(lifecycleId)) {
+ throw new IllegalArgumentException(lifecycleId);
+ }
+ lifecycles.put(lifecycleId, lifecycle);
+ }
+ logger.log(Level.FINER, "PS_CSFP0024", lifecycleId);
+ }
+
+
+ public Lifecycle getLifecycle(String lifecycleId) {
+
+ if (lifecycleId == null) {
+ throw new NullPointerException();
+ }
+ synchronized (lifecycles) {
+ Lifecycle lifecycle = (Lifecycle) lifecycles.get(lifecycleId);
+ if (lifecycle != null) {
+ if(logger.isLoggable(Level.FINER)){
+ logger.log(Level.FINER, "PS_CSFP0025", new Object[] { lifecycle, lifecycleId});
+ }
+ return (lifecycle);
+ } else {
+ throw new IllegalArgumentException(lifecycleId);
+ }
+ }
+
+ }
+
+
+ public Iterator getLifecycleIds() {
+
+ synchronized (lifecycles) {
+ return (lifecycles.keySet().iterator());
+ }
+
+ }
+
+
+}
Added: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleImpl.java (rev 0)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecycleImpl.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,752 @@
+/*
+ * CDDL HEADER START
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the License). You may not use this file except in
+ * compliance with the License.
+ *
+ * You can obtain a copy of the License at
+ * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
+ * See the License for the specific language governing
+ * permission and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * Header Notice in each file and include the License file
+ * at legal/CDDLv1.0.txt.
+ * If applicable, add the following below the CDDL Header,
+ * with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
+ * CDDL HEADER END
+ */
+
+package org.ajax4jsf.portlet.lifecycle;
+
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKitFactory;
+
+import javax.portlet.PortletSession;
+
+
+
+/**
+ * <p>Custom implementation of <code>Lifecycle</code> that implements a
+ * portlet-specific <code>Lifecycle</code>.</p>
+ */
+
+public final class LifecycleImpl extends Lifecycle {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ // The Logger instance for this class
+ private static Logger logger = Logger.getLogger(LifecycleImpl.class.getPackage().getName(), "JSFPLogMessages");
+
+ /**
+ * <p>Portlet initialization parameter which holds the value of one of
+ * initial mode identifier. i.e either INIT_VIEW_PARAMETER or
+ * INIT_EDIT_PARAMETER or INIT_HELP_PARAMETER</p>
+ */
+ public static final String INIT_PARAMETER =
+ "com.sun.faces.portlet.INIT";
+
+ /**
+ * <p>Portlet initialization parameter under which the application
+ * may specify an initial view mode identifier to be displayed.</p>
+ */
+ public static final String INIT_VIEW_PARAMETER =
+ "com.sun.faces.portlet.INIT_VIEW";
+
+ /**
+ * <p>Portlet initialization parameter under which the application
+ * may specify an initial edit mode identifier to be displayed.</p>
+ */
+ public static final String INIT_EDIT_PARAMETER =
+ "com.sun.faces.portlet.INIT_EDIT";
+
+ /**
+ * <p>Portlet initialization parameter under which the application
+ * may specify an initial help mode identifier to be displayed.</p>
+ */
+ public static final String INIT_HELP_PARAMETER =
+ "com.sun.faces.portlet.INIT_HELP";
+
+ /**
+ * <p>Portlet session attribute (in portlet scope) under which we will
+ * save the window state identifer. i.e one of the WINDOW_STATE_ATTR_* values.</p>
+ */
+ private static final String PREVIOUS_WINDOW_STATE =
+ "com.sun.faces.portlet.PREVIOUS_WINDOW_STATE";
+
+ /**
+ * <p>Portlet session attribute (in portlet scope) under which we will
+ * save state information for VIEW for the current window.</p>
+ */
+ private static final String WINDOW_STATE_ATTR_VIEW =
+ "com.sun.faces.portlet.WINDOW_STATE_VIEW";
+
+ /**
+ * <p>Portlet session attribute (in portlet scope) under which we will
+ * save state information for EDIT for the current window.</p>
+ */
+ private static final String WINDOW_STATE_ATTR_EDIT =
+ "com.sun.faces.portlet.WINDOW_STATE_EDIT";
+
+ /**
+ * <p>Portlet session attribute (in portlet scope) under which we will
+ * save state information for HELP for the current window.</p>
+ */
+ private static final String WINDOW_STATE_ATTR_HELP =
+ "com.sun.faces.portlet.WINDOW_STATE_HELP";
+
+
+ /**
+ * <p>Portlet session attribute (in portlet scope) under which we will
+ * save a Boolean TRUE or FALSE for the current window.</p>
+ */
+ public static final String ERROR_FLAG =
+ "com.sun.faces.portlet.ERROR_FLAG";
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ /**
+ * <p>The set of <code>PhaseListener</code>s registered with this
+ * <code>Lifecycle</code> instance, in order of registration.</p>
+ */
+ private List listeners = new ArrayList();
+
+
+ /**
+ * <p>The set of {@link Phase} instances that are to be
+ * executed by the <code>execute()</code> method, in order by the
+ * ordinal property of each phase.</p>
+ */
+ private Phase phases[] = {
+ null, // ANY_PHASE holder
+ new RestoreViewPhase(),
+ new ApplyRequestValuesPhase(),
+ new ProcessValidationsPhase(),
+ new UpdateModelValuesPhase(),
+ new InvokeApplicationPhase()
+ };
+
+
+ /**
+ * <p>The {@link Phase} instance to process Render Response phase.</p>
+ */
+ private Phase response = new RenderResponsePhase();
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /**
+ * <p>Construct a new <code>LifecycleImpl</code> instance.</p>
+ */
+ public LifecycleImpl() {
+ super();
+ logger.log(Level.FINEST, "PS_CSFP0026", this);
+ }
+
+
+ // ------------------------------------------------------- Lifecycle Methods
+
+
+ // Add a new PhaseListener to the set of registered listeners
+ public void addPhaseListener(PhaseListener listener) {
+
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ if (logger.isLoggable(Level.FINER)) {
+ logger.log(Level.FINER, "PS_CSFP0027", new Object[]{ listener.getPhaseId(), listener});
+ }
+ synchronized (listeners) {
+ listeners.add(listener);
+ }
+
+ }
+
+
+ // Execute the phases up to but not including Render Response
+ public void execute(FacesContext context) throws FacesException {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ logger.log(Level.FINEST, "PS_CSFP0028", context);
+
+ restore(context, true);
+
+ setErrorFlag(context, Boolean.FALSE);
+
+ for (int i = 1; i < phases.length; i++) {
+ PhaseId phaseId = (PhaseId) PhaseId.VALUES.get(i);
+ if (context.getRenderResponse() ||
+ context.getResponseComplete()) {
+ /*
+ (a) If there are any validation/conversion errors, then its an error.
+ (b) If there are no validation/conversion errors, it means either
+ immediate=true is specified or FacesContext.renderResponse() has been
+ called.
+ */
+ Iterator itr = context.getMessages();
+ if(itr.hasNext()) {
+ setErrorFlag(context, Boolean.TRUE);
+ }
+ break;
+ }
+ phase(phaseId, phases[i], context);
+ }
+
+ save(context, true);
+
+ }
+
+
+ // Return the set of PhaseListeners that have been registered
+ public PhaseListener[] getPhaseListeners() {
+
+ synchronized (listeners) {
+ PhaseListener results[] = new PhaseListener[listeners.size()];
+ return ((PhaseListener[]) listeners.toArray(results));
+ }
+
+ }
+
+
+ // Execute the Render Response phase
+ public void render(FacesContext context) throws FacesException {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ logger.log(Level.FINEST, "PS_CSFP0029" , context);
+
+ restore(context, false);
+
+ setErrorFlag(context, Boolean.FALSE);
+
+ if (!context.getResponseComplete()) {
+ phase(PhaseId.RENDER_RESPONSE, response, context);
+ }
+
+ save(context, false);
+ }
+
+
+ // Remove a registered PhaseListener from the set of registered listeners
+ public void removePhaseListener(PhaseListener listener) {
+
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ if (logger.isLoggable(Level.FINER)) {
+ logger.log(Level.FINER, "PS_CSFP0030", new Object[] { listener.getPhaseId(),listener});
+ }
+ synchronized (listeners) {
+ listeners.remove(listener);
+ }
+
+ }
+
+
+ // --------------------------------------------------------- Private Methods
+
+
+ /**
+ * <p>Execute the specified phase instance for the current request.</p>
+ *
+ * @param phaseId Phase identifier of the current phase
+ * @param phase {@link Phase} instance to execute
+ * @param context <code>FacesContext</code> for the current request
+ *
+ * @exception FacesException if thrown by the phase execution
+ */
+ private void phase(PhaseId phaseId, Phase phase, FacesContext context)
+ throws FacesException {
+
+ boolean exceptionThrownInRender = false;
+ Exception tempException = null;
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, "PS_CSFP0031", new Object[] {phaseId, context});
+ }
+
+ // Acquire (once) the list of interested phase listeners
+ // Clone it so that we are independent of changes during the
+ // execution of this phase
+ PhaseListener listeners[] = getPhaseListeners();
+
+ try {
+
+ // Notify the "beforePhase" method of interested listeners
+ if (listeners.length > 0) {
+ PhaseEvent event = new PhaseEvent(context, phaseId, this);
+ for (int i = 0; i < listeners.length; i++) {
+ if (phaseId.equals(listeners[i].getPhaseId()) ||
+ PhaseId.ANY_PHASE.equals(listeners[i].getPhaseId())) {
+ listeners[i].beforePhase(event);
+ }
+ }
+ }
+
+ } catch (Exception e) {
+
+ // Log the problem, but continue
+ if (logger.isLoggable(Level.INFO)) {
+ LogRecord logRecord = new LogRecord(Level.INFO, "PS_CSFP0032");
+ logRecord.setParameters(new Object[] { phaseId, context});
+ logRecord.setThrown(e);
+ logger.log(logRecord);
+ }
+
+ }
+
+ try {
+
+ try {
+
+ // Execute this phase itself
+ phase.execute(context);
+
+ } catch (Exception e) {
+
+ // Log the problem, but continue
+ if (logger.isLoggable(Level.INFO)) {
+ LogRecord logRecord = new LogRecord(Level.INFO, "PS_CSFP0033");
+ logRecord.setParameters(new Object[] { phaseId, context});
+ logRecord.setThrown(e);
+ }
+
+ // Don't rethrow as it will break the jsf lifecycle execution
+ // If exception is thrown in the render phase, hold a reference to the exception
+ if(phaseId.compareTo(PhaseId.RENDER_RESPONSE) == 0) {
+ exceptionThrownInRender = true;
+ tempException = e;
+ }
+ }
+
+ // Notify the "afterPhase" method of interested listeners
+ if (listeners.length > 0) {
+ PhaseEvent event = new PhaseEvent(context, phaseId, this);
+ for (int i = listeners.length - 1; i >= 0; i--) {
+ if (phaseId.equals(listeners[i].getPhaseId()) ||
+ PhaseId.ANY_PHASE.equals(listeners[i].getPhaseId())) {
+ listeners[i].afterPhase(event);
+ }
+ }
+ }
+
+ } catch (Exception e) {
+
+ // Log the problem, but continue
+ if (logger.isLoggable(Level.INFO)) {
+ LogRecord logRecord = new LogRecord(Level.INFO, "PS_CSFP0034");
+ logRecord.setParameters(new Object[] { phaseId, context});
+ logRecord.setThrown(e);
+ }
+ }
+
+ if(exceptionThrownInRender)
+ throw new FacesException(tempException);
+ }
+
+
+ /**
+ * <p>Restore state information for the current window into the
+ * specified <code>FacesContext</code> instance.</p>
+ *
+ * @param context <code>FacesContext</code> for this request
+ * @param action Flag indicating this is action mode (true)
+ * or render mode (false)
+ */
+ private void restore(FacesContext context, boolean action) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, "PS_CSFP0035", new Object[] { context,action});
+ }
+
+ // Retrieve the cached state information (if any)
+ String windowStateIdentifier = getWindowStateIdentifier((String) context.getExternalContext().
+ getRequestMap().get(INIT_PARAMETER));
+
+ PortletSession session = (PortletSession)context.getExternalContext().getSession(true);
+
+ String previousWindowStateIndentifier = (String)session.getAttribute(PREVIOUS_WINDOW_STATE);
+
+ FacesPortletState state = null;
+ // This will ensure that the state information saved for INIT_VIEW will be restored
+ // only for INIT_VIEW and so on..
+ if(previousWindowStateIndentifier != null
+ && previousWindowStateIndentifier.equals(windowStateIdentifier)) {
+ state = (FacesPortletState)session.getAttribute(windowStateIdentifier);
+
+ }
+
+ if (state == null) {
+ setViewId(context);
+ return;
+ }
+
+ // Restore the cached state information
+ if (!action) {
+ Iterator messages;
+ Iterator clientIds = state.getClientIds();
+ while (clientIds.hasNext()) {
+ String clientId = (String) clientIds.next();
+ messages = state.getMessages(clientId);
+ while (messages.hasNext()) {
+ context.addMessage(clientId, (FacesMessage) messages.next());
+ }
+ }
+ }
+ context.setViewRoot(state.getViewRoot());
+
+ // Remove the cached state information
+ session.removeAttribute(windowStateIdentifier);
+
+ logger.finest("PS_CSFP0036");
+ }
+
+
+ /**
+ * <p>Save state information for the current window from the
+ * specified <code>FacesContext</code> instance.</p>
+ *
+ * @param context <code>FacesContext</code> for this request
+ * @param action Flag indicating this is action mode (true)
+ * or render mode (false)
+ */
+ private void save(FacesContext context, boolean action) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, "PS_CSFP0037", new Object[] { context, action });
+ }
+ // Save state information from this FacesContext
+ FacesPortletState state = new FacesPortletState();
+ Iterator messages;
+ Iterator clientIds = context.getClientIdsWithMessages();
+ while (clientIds.hasNext()) {
+ String clientId = (String) clientIds.next();
+ messages = context.getMessages(clientId);
+ while (messages.hasNext()) {
+ state.addMessage(clientId, (FacesMessage) messages.next());
+ }
+ // Log the message
+ if (logger.isLoggable(Level.INFO)) {
+ logger.log(Level.INFO, "PS_CSFP0038", clientId + state.getMessagesBuffer(clientId));
+ }
+ }
+ state.setViewRoot(context.getViewRoot());
+
+ // Cache the state information in a session in portlet scope
+ String windowStateIdentifier = getWindowStateIdentifier((String) context.getExternalContext().
+ getRequestMap().get(INIT_PARAMETER));
+
+ PortletSession session = (PortletSession)context.getExternalContext().getSession(true);
+ // Save the window state identifier in a session in portlet scope
+ // This information is used during restore to restore the cached information for the
+ // appropriate window state. This will ensure that the state information saved for
+ // INIT_VIEW will be restored only for INIT_VIEW and so on..
+ session.setAttribute(PREVIOUS_WINDOW_STATE, windowStateIdentifier);
+
+ session.setAttribute(windowStateIdentifier, state);
+ }
+
+
+ /**
+ * <p>Get the view identifier to a default page specified in a
+ * portlet init parameter.</p>
+ *
+ * @param context <code>FacesContext</code> for the current request
+ */
+ private String getInitViewId(FacesContext context) {
+ Map requestMap = context.getExternalContext().getRequestMap();
+ String initParameterIdentifier = (String) requestMap.get(INIT_PARAMETER);
+ String viewId = (String) requestMap.get(initParameterIdentifier);
+ return viewId;
+ }
+
+ /**
+ * <p>Set the view identifier to a default page specified in a
+ * portlet init parameter.</p>
+ *
+ * @param context <code>FacesContext</code> for the current request
+ */
+ private void setViewId(FacesContext context) {
+ String viewId = getInitViewId(context);
+
+ if (context.getViewRoot() == null) {
+ context.setViewRoot(context.getApplication().getViewHandler().createView(context, viewId));
+ if (logger.isLoggable(Level.FINER)) {
+ logger.log(Level.FINER, "PS_CSFP0039", context.getViewRoot().getViewId());
+ }
+ } else {
+ context.getViewRoot().setViewId(viewId);
+ if (logger.isLoggable(Level.FINER)) {
+ logger.log(Level.FINER, "PS_CSFP0040", viewId);
+ }
+ }
+
+ context.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ }
+
+ /**
+ * Returns the window state attribute identifier based on the
+ * init parameter identifier.
+ *
+ * @param initParameterIdentifier the initialization parameter identifier
+ * @return window state attribute identifier
+ */
+ private String getWindowStateIdentifier(String initParameterIdentifier) {
+ if(initParameterIdentifier.equals(INIT_VIEW_PARAMETER))
+ return WINDOW_STATE_ATTR_VIEW;
+ else if(initParameterIdentifier.equals(INIT_EDIT_PARAMETER))
+ return WINDOW_STATE_ATTR_EDIT;
+ else if(initParameterIdentifier.equals(INIT_HELP_PARAMETER))
+ return WINDOW_STATE_ATTR_HELP;
+ else
+ return null;
+
+ }
+
+ private void setErrorFlag(FacesContext context, Boolean value) {
+ PortletSession session = (PortletSession)context.getExternalContext().getSession(true);
+ session.setAttribute(ERROR_FLAG, value);
+ }
+
+// ------------------------------------------------------- Phase Implementations
+
+
+ interface Phase {
+
+ public void execute(FacesContext context)
+ throws FacesException;
+
+ }
+
+
+ final class RestoreViewPhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0041");
+ // get the viewId from the context
+ String viewId = context.getViewRoot().getViewId();
+ if (viewId == null) {
+ logger.info("PS_CSFP0042");
+ throw new FacesException // PENDING - i18n
+ ("No view identifier in this request");
+ }
+
+ // Try to restore the view
+ ViewHandler vh = context.getApplication().getViewHandler();
+ UIViewRoot viewRoot = vh.restoreView(context, viewId);
+ if (viewRoot == null) {
+ logger.log(Level.FINEST, "PS_CSFP0043", viewId);
+ viewRoot = vh.createView(context, viewId);
+ context.renderResponse();
+ } else {
+ logger.log(Level.FINEST, "PS_CSFP0044", viewId);
+ }
+ context.setViewRoot(viewRoot);
+ doPerComponentActions(context, viewRoot);
+ logger.finest("PS_CSFP0045");
+ }
+
+
+ // Do the per-component actions needed during restore
+ private void doPerComponentActions
+ (FacesContext context, UIComponent component) {
+
+ Iterator kids = component.getFacetsAndChildren();
+ while (kids.hasNext()) {
+ doPerComponentActions(context, (UIComponent) kids.next());
+ }
+ ValueBinding vb = component.getValueBinding("binding");
+ if (vb != null) {
+ vb.setValue(context, component);
+ }
+ }
+
+
+ }
+
+
+ final class ApplyRequestValuesPhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0046");
+ UIViewRoot viewRoot = context.getViewRoot();
+ try {
+ viewRoot.processDecodes(context);
+ } catch (FacesException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw new FacesException(e);
+ }
+ logger.finest("PS_CSFP0047");
+ }
+ }
+
+
+ final class ProcessValidationsPhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0048");
+ UIViewRoot viewRoot = context.getViewRoot();
+ try {
+ viewRoot.processValidators(context);
+ } catch (FacesException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw new FacesException(e);
+ }
+ logger.finest("PS_CSFP0049");
+ }
+
+ }
+
+
+ final class UpdateModelValuesPhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0050");
+ UIViewRoot viewRoot = context.getViewRoot();
+ try {
+ viewRoot.processUpdates(context);
+ } catch (FacesException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw new FacesException(e);
+ }
+ logger.finest("PS_CSFP0051");
+ }
+
+ }
+
+
+ final class InvokeApplicationPhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0052");
+ UIViewRoot viewRoot = context.getViewRoot();
+ try {
+ viewRoot.processApplication(context);
+ } catch (FacesException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw new FacesException(e);
+ }
+ logger.finest("PS_CSFP0053");
+ }
+
+ }
+
+
+ final class RenderResponsePhase implements Phase {
+
+ public void execute(FacesContext context) throws FacesException {
+ logger.finest("PS_CSFP0054");
+ String requestURI = context.getViewRoot().getViewId();
+ logger.log(Level.INFO, "PS_CSFP0055", requestURI);
+ try {
+ context.getApplication().getViewHandler().
+ renderView(context, context.getViewRoot());
+ } catch (FacesException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new FacesException(e);
+ }
+ logger.finest("PS_CSFP0056");
+ }
+
+ }
+
+
+}
+
+
+// ------------------------------------------------------------- Private Classes
+
+
+/**
+ * <p>Private class to represent the JavaServer Faces specific information
+ * that is saved and restored for a particular window.
+ */
+
+final class FacesPortletState {
+
+
+ // Methods Saving and Restoring Messages
+ private Map messages = new HashMap(); // key=clientId, value=List of FacesMessage
+ public void addMessage(String clientId, FacesMessage message) {
+ List list = (List) messages.get(clientId);
+ if (list == null) {
+ list = new ArrayList();
+ messages.put(clientId, list);
+ }
+ list.add(message);
+ }
+ public Iterator getMessages(String clientId) {
+ List list = (List) messages.get(clientId);
+ if (list != null) {
+ return (list.iterator());
+ } else {
+ return (Collections.EMPTY_LIST.iterator());
+ }
+ }
+
+ public StringBuffer getMessagesBuffer(String clientId) {
+ List list = (List) messages.get(clientId);
+ StringBuffer buffer = new StringBuffer();
+ if (list != null) {
+ Iterator messages = list.iterator();
+ FacesMessage message;
+ while (messages.hasNext()) {
+ message = (FacesMessage) messages.next();
+ buffer.append(" ");
+ buffer.append(message.getDetail());
+ }
+ }
+ return buffer;
+ }
+
+ // Iterate over the client ids in this view
+ public Iterator getClientIds() {
+ return (messages.keySet().iterator());
+ }
+
+ // The UIViewRoot that is the root of our component tree
+ private UIViewRoot viewRoot;
+ public UIViewRoot getViewRoot() { return this.viewRoot; }
+ public void setViewRoot(UIViewRoot viewRoot) {
+ this.viewRoot = viewRoot; }
+
+}
Modified: trunk/a4j-portlet/src/test/java/org/ajax4jsf/PortletTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/PortletTest.java 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/PortletTest.java 2007-04-06 16:17:05 UTC (rev 55)
@@ -36,18 +36,11 @@
*
* @param testName name of the test case
*/
- public AppTest( String testName )
+ public PortletTest( String testName )
{
super( testName );
}
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
/**
* Rigourous Test :-)
Modified: trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/META-INF/maven/archetype.xml
===================================================================
--- trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/META-INF/maven/archetype.xml 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/META-INF/maven/archetype.xml 2007-04-06 16:17:05 UTC (rev 55)
@@ -9,6 +9,7 @@
<resources>
<resource>src/main/webapp/index.jsp</resource>
<resource>src/main/webapp/pages/index.jsp</resource>
+ <resource>src/main/webapp/pages/index.xhtml</resource>
<resource>src/main/webapp/WEB-INF/web.xml</resource>
<resource>src/main/webapp/WEB-INF/faces-config.xml</resource>
</resources>
Modified: trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/pom.xml
===================================================================
--- trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/pom.xml 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/pom.xml 2007-04-06 16:17:05 UTC (rev 55)
@@ -5,6 +5,9 @@
<version>${version}</version>
<packaging>war</packaging>
<name>JSF Maven Webapp</name>
+ <properties>
+ <jsfVersion>1.1</jsfVersion>
+ </properties>
<build>
<plugins>
<plugin>
@@ -52,6 +55,7 @@
<artifactId>ajax4jsf</artifactId>
<version>1.1.1-SNAPSHOT</version>
</dependency>
+#if(${facelets})
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
@@ -61,19 +65,141 @@
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>el-impl</groupId>
<artifactId>el-impl</artifactId>
<version>1.0</version>
- <scope>provided</scope>
+ <scope>runtime</scope>
</dependency>
+#end
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
- </dependencies>
+ </dependencies>
+<!--
+ <profiles>
+ <profile>
+ <id>jsf1_1</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ <property>
+ <name>jsfVersion</name>
+ <value>1.1</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>jsf12</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.2_04</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <version>1.2_04</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>myfaces</id>
+ <properties>
+ <myfaces>1.1.5</myfaces>
+ <tomahawk>1.1.5</tomahawk>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.ajax4jsf</groupId>
+ <artifactId>ajax4jsf</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-api</artifactId>
+ <version>${myfaces}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-impl</artifactId>
+ <version>${myfaces}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+-->
</project>
Modified: trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml 2007-04-06 16:17:05 UTC (rev 55)
@@ -10,6 +10,28 @@
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
+ <!--
+#if(${facelets})
+ -->
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>facelets.REFRESH_PERIOD</param-name>
+ <param-value>2</param-value>
+ </context-param>
+ <context-param>
+ <param-name>facelets.DEVELOPMENT</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
+ <param-value>com.sun.facelets.FaceletViewHandler</param-value>
+ </context-param>
+ <!--
+#end
+ -->
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
Modified: trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/index.jsp
===================================================================
--- trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/index.jsp 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/index.jsp 2007-04-06 16:17:05 UTC (rev 55)
@@ -5,9 +5,7 @@
<head></head>
<body>
-
<jsp:forward page="/pages/index.jsf" />
-
</body>
</html>
\ No newline at end of file
Added: trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/pages/index.xhtml
===================================================================
--- trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/pages/index.xhtml (rev 0)
+++ trunk/cdk/maven-archetype-jsfwebapp/src/main/resources/archetype-resources/src/main/webapp/pages/index.xhtml 2007-04-06 16:17:05 UTC (rev 55)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
+ xmlns:c="http://java.sun.com/jsp/jstl/core"
+ >
+ <f:view>
+
+ </f:view>
+</html>
\ No newline at end of file
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2007-04-04 17:11:37 UTC (rev 54)
+++ trunk/pom.xml 2007-04-06 16:17:05 UTC (rev 55)
@@ -98,7 +98,6 @@
<layout>legacy</layout>
</repository>
</repositories>
-
<scm>
<connection>
scm:svn:http://anonsvn.jboss.org/repos/ajax4jsf/trunk/
@@ -275,7 +274,7 @@
true
</includesAllSourceRoots>
<licenseLocation>
- ${cloverLicense}
+ ${clover.license.path}
</licenseLocation>
<jdk>1.5</jdk>
</configuration>
@@ -299,7 +298,7 @@
<artifactId>maven-clover-plugin</artifactId>
<!--
<configuration>
- <licenseLocation>${cloverLicense}</licenseLocation>
+ <licenseLocation>${clover.license.path}</licenseLocation>
<jdk>1.5</jdk>
</configuration>
-->
17 years, 8 months
JBoss Ajax4JSF SVN: r54 - trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat.
by ajax4jsf-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-04-04 13:11:37 -0400 (Wed, 04 Apr 2007)
New Revision: 54
Modified:
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
Log:
Fix RF-14 related bug : restore rowKey value after broadcast a AjaxEvent.
Modified: trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-04-04 12:08:19 UTC (rev 53)
+++ trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-04-04 17:11:37 UTC (rev 54)
@@ -1091,10 +1091,10 @@
FacesEvent rowEvent = revent.getTarget();
rowEvent.getComponent().broadcast(rowEvent);
// For Ajax events, keep row value.
- if (!(rowEvent instanceof AjaxEvent)) {
- setRowKey(faces, oldRowKey);
- restoreOrigValue(faces);
- }
+// if (!(rowEvent instanceof AjaxEvent)) {
+// setRowKey(faces, oldRowKey);
+// restoreOrigValue(faces);
+// }
return;
}
17 years, 9 months
JBoss Ajax4JSF SVN: r53 - trunk/cdk/generator/src/main/resources/META-INF/schema/entities.
by ajax4jsf-svn-commits@lists.jboss.org
Author: ilya_shaikovsky
Date: 2007-04-04 08:08:19 -0400 (Wed, 04 Apr 2007)
New Revision: 53
Modified:
trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ui_component_attributes.ent
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ui_component_attributes.ent
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ui_component_attributes.ent 2007-04-04 12:08:03 UTC (rev 52)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ui_component_attributes.ent 2007-04-04 12:08:19 UTC (rev 53)
@@ -12,7 +12,7 @@
<name>rendered</name>
<classname>boolean</classname>
<description>
- If "false", this component is rendered.
+ If "false", this component is not rendered.
</description>
</property>
<property existintag="true" exist="true" el="true" elonly="true">
17 years, 9 months
JBoss Ajax4JSF SVN: r52 - trunk/cdk/generator/src/main/resources/META-INF/schema/entities.
by ajax4jsf-svn-commits@lists.jboss.org
Author: ilya_shaikovsky
Date: 2007-04-04 08:08:03 -0400 (Wed, 04 Apr 2007)
New Revision: 52
Modified:
trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent 2007-04-04 11:57:16 UTC (rev 51)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent 2007-04-04 12:08:03 UTC (rev 52)
@@ -62,7 +62,7 @@
<property >
<name>data</name>
<classname>java.lang.Object</classname>
- <description>Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via this.data</description>
+ <description>Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax</description>
</property>
<property>
<name>ignoreDupResponses</name>
17 years, 9 months
JBoss Ajax4JSF SVN: r51 - trunk/test/src/main/java/org/ajax4jsf/tests.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-04 07:57:16 -0400 (Wed, 04 Apr 2007)
New Revision: 51
Added:
trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
Modified:
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
MockViewHandler created to handle resource requests in mock env. properly. writeState() stubbed also
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-03 16:47:13 UTC (rev 50)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-04 11:57:16 UTC (rev 51)
@@ -26,15 +26,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Random;
-import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -49,11 +44,9 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
import org.ajax4jsf.framework.ajax.AjaxViewRoot;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl;
-import org.ajax4jsf.framework.resource.FacesResourceContext;
import org.ajax4jsf.framework.resource.InternetResource;
import org.ajax4jsf.framework.resource.InternetResourceBuilder;
import org.ajax4jsf.framework.skin.SkinBean;
@@ -61,14 +54,11 @@
import org.ajax4jsf.framework.skin.VersionBean;
import org.ajax4jsf.framework.util.config.WebXml;
import org.ajax4jsf.tests.org.apache.shale.test.config.ConfigParser;
-import org.apache.commons.httpclient.Header;
import org.apache.shale.test.base.AbstractJsfTestCase;
-import org.apache.shale.test.mock.MockHttpServletResponse;
import org.apache.shale.test.mock.MockPrintWriter;
import org.apache.shale.test.mock.MockResponseWriter;
import org.apache.shale.test.mock.MockServletOutputStream;
-import com.gargoylesoftware.htmlunit.KeyValuePair;
import com.gargoylesoftware.htmlunit.MockWebConnection;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -91,7 +81,7 @@
public class AbstractAjax4JsfTestCase extends AbstractJsfTestCase {
protected final static String SLASHED_RESOURCE_URI_PREFIX = "/" + WebXml.RESOURCE_URI_PREFIX;
-
+
private File tmpRoot = null;
/**
@@ -122,7 +112,7 @@
ajaxContext = new AjaxContext();
request.setAttribute(AjaxContext.AJAX_CONTEXT_KEY, ajaxContext);
// Setup ViewHandler / ViewRoot.
- application.setViewHandler(new AjaxViewHandler(application.getViewHandler()));
+ application.setViewHandler(new MockViewHandler(application.getViewHandler()));
facesContext.setViewRoot(application.getViewHandler().createView(facesContext, facesContext.getViewRoot().getViewId()));
// Setup Skin avd version variables.
servletContext.setAttribute("a4j", new VersionBean());
@@ -179,7 +169,7 @@
InternetResourceBuilder.setInstance(null);
}
// setupWebClient();
-
+
ConfigParser parser = new ConfigParser();
parser.parse(parser.getPlatformURLs());
@@ -198,29 +188,29 @@
webClient = new WebClient();
webConnection = new MockWebConnection(webClient) {
public WebResponse getResponse(WebRequestSettings settings)
- throws IOException {
+ throws IOException {
if (settings.getURL().getFile().startsWith(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX)) {
InternetResource resource = InternetResourceBuilder.getInstance().getResource(
settings.getURL().getFile().substring(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX.length()));
-
+
final MockFacesResourceContext resourceContext = new MockFacesResourceContext(facesContext);
resource.sendHeaders(resourceContext);
-
+
return new WebResponseImpl(
new WebResponseData(
resource.getResourceAsStream(resourceContext),
HttpServletResponse.SC_OK,
"OK",
resourceContext.getHeaders()),
- settings.getURL(),
- settings.getSubmitMethod(),
- 0) {
-
+ settings.getURL(),
+ settings.getSubmitMethod(),
+ 0) {
+
public String getContentType() {
return resourceContext.getContentType();
}
};
-
+
} else {
return super.getResponse(settings);
}
Added: trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java (rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-04-04 11:57:16 UTC (rev 51)
@@ -0,0 +1,48 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.tests;
+
+import java.io.IOException;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+
+public class MockViewHandler extends AjaxViewHandler {
+
+ public MockViewHandler(ViewHandler parent) {
+ super(parent);
+ }
+
+ public void writeState(FacesContext context) throws IOException {
+ //System.out.println(".writeState()");
+ }
+
+ public String getResourceURL(FacesContext context, String url) {
+ return url;
+ }
+
+ public String getActionURL(FacesContext context, String url) {
+ return url;
+ }
+}
\ No newline at end of file
17 years, 9 months
JBoss Ajax4JSF SVN: r50 - trunk.
by ajax4jsf-svn-commits@lists.jboss.org
Author: SergeySmirnov
Date: 2007-04-03 12:47:13 -0400 (Tue, 03 Apr 2007)
New Revision: 50
Modified:
trunk/changelog.txt
Log:
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2007-04-03 00:27:24 UTC (rev 49)
+++ trunk/changelog.txt 2007-04-03 16:47:13 UTC (rev 50)
@@ -5,4 +5,7 @@
+ jsFunction
+ loadScript
+ loadStyle
- - New CDK core, based on template compiler and Maven2 plug-ins
\ No newline at end of file
+ - New CDK core, based on template compiler and Maven2 plug-ins
+ - The default value for a4j:region renderRegionOnly is false now
+ - forceparse set to false by default in the web.xml
+ - drag-n-drop API is added
\ No newline at end of file
17 years, 9 months
JBoss Ajax4JSF SVN: r49 - in trunk/test: src/main/java/org/ajax4jsf/tests and 5 other directories.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-02 20:27:24 -0400 (Mon, 02 Apr 2007)
New Revision: 49
Added:
trunk/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java
trunk/test/src/main/java/org/ajax4jsf/tests/org/
trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/
trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/
trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/
trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/
trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java
Modified:
trunk/test/
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
Initial faces artefacts configuration through ConfigParser added to AbstractAjax4JsfTestCase
Resources handling through ResourceBuilder added
Property changes on: trunk/test
___________________________________________________________________
Name: svn:ignore
- target
+ target
.settings
.clover
.classpath
.project
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-02 19:52:02 UTC (rev 48)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-03 00:27:24 UTC (rev 49)
@@ -26,9 +26,15 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Random;
+import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -40,24 +46,36 @@
import javax.faces.render.RenderKitFactory;
import javax.faces.render.Renderer;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
import org.ajax4jsf.framework.ajax.AjaxViewHandler;
import org.ajax4jsf.framework.ajax.AjaxViewRoot;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl;
+import org.ajax4jsf.framework.resource.FacesResourceContext;
+import org.ajax4jsf.framework.resource.InternetResource;
import org.ajax4jsf.framework.resource.InternetResourceBuilder;
import org.ajax4jsf.framework.skin.SkinBean;
import org.ajax4jsf.framework.skin.SkinFactory;
import org.ajax4jsf.framework.skin.VersionBean;
+import org.ajax4jsf.framework.util.config.WebXml;
+import org.ajax4jsf.tests.org.apache.shale.test.config.ConfigParser;
+import org.apache.commons.httpclient.Header;
import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.mock.MockHttpServletResponse;
import org.apache.shale.test.mock.MockPrintWriter;
import org.apache.shale.test.mock.MockResponseWriter;
import org.apache.shale.test.mock.MockServletOutputStream;
+import com.gargoylesoftware.htmlunit.KeyValuePair;
import com.gargoylesoftware.htmlunit.MockWebConnection;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebRequestSettings;
+import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.WebResponseData;
+import com.gargoylesoftware.htmlunit.WebResponseImpl;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
/**
@@ -72,6 +90,8 @@
*/
public class AbstractAjax4JsfTestCase extends AbstractJsfTestCase {
+ protected final static String SLASHED_RESOURCE_URI_PREFIX = "/" + WebXml.RESOURCE_URI_PREFIX;
+
private File tmpRoot = null;
/**
@@ -159,6 +179,14 @@
InternetResourceBuilder.setInstance(null);
}
// setupWebClient();
+
+ ConfigParser parser = new ConfigParser();
+ parser.parse(parser.getPlatformURLs());
+
+ Enumeration resources = getClass().getClassLoader().getResources("META-INF/faces-config.xml");
+ while (resources.hasMoreElements()) {
+ parser.parse((URL) resources.nextElement());
+ }
}
/**
@@ -168,7 +196,36 @@
ajaxContext = null;
// setup webClient for got response content.
webClient = new WebClient();
- webConnection = new MockWebConnection(webClient);
+ webConnection = new MockWebConnection(webClient) {
+ public WebResponse getResponse(WebRequestSettings settings)
+ throws IOException {
+ if (settings.getURL().getFile().startsWith(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX)) {
+ InternetResource resource = InternetResourceBuilder.getInstance().getResource(
+ settings.getURL().getFile().substring(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX.length()));
+
+ final MockFacesResourceContext resourceContext = new MockFacesResourceContext(facesContext);
+ resource.sendHeaders(resourceContext);
+
+ return new WebResponseImpl(
+ new WebResponseData(
+ resource.getResourceAsStream(resourceContext),
+ HttpServletResponse.SC_OK,
+ "OK",
+ resourceContext.getHeaders()),
+ settings.getURL(),
+ settings.getSubmitMethod(),
+ 0) {
+
+ public String getContentType() {
+ return resourceContext.getContentType();
+ }
+ };
+
+ } else {
+ return super.getResponse(settings);
+ }
+ }
+ };
webClient.setWebConnection(webConnection);
webConnection.setDefaultResponse("<html><body>not found</body></html>",404,"NOT FOUND","text/html");
webClient.setThrowExceptionOnFailingStatusCode(false);
Added: trunk/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java (rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java 2007-04-03 00:27:24 UTC (rev 49)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.tests;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.resource.FacesResourceContext;
+import org.apache.shale.test.mock.MockHttpServletResponse;
+
+import com.gargoylesoftware.htmlunit.KeyValuePair;
+
+/**
+ * @author Nick - mailto:nbelaevski@exadel.com
+ * created 03.04.2007
+ *
+ */
+public class MockFacesResourceContext extends FacesResourceContext {
+
+ private String contentType;
+ //used to encode headers properly
+ private MockHttpServletResponse mockResponse = new MockHttpServletResponse();
+ private Set headerSet = new LinkedHashSet();
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setDateHeader(String name, long value) {
+ headerSet.add(name);
+ mockResponse.setDateHeader(name, value);
+ }
+
+ public void setHeader(String name, String value) {
+ headerSet.add(name);
+ mockResponse.setHeader(name, value);
+ }
+
+ public void setIntHeader(String name, int value) {
+ headerSet.add(name);
+ mockResponse.setIntHeader(name, value);
+ }
+
+ public List getHeaders() {
+ List headers = new ArrayList();
+ for (Iterator iterator = headerSet.iterator(); iterator
+ .hasNext();) {
+ String headerName = (String) iterator.next();
+
+ String headerValue = mockResponse.getHeader(headerName);
+ if (headerValue != null) {
+ headers.add(new KeyValuePair(headerName, headerValue));
+ }
+ }
+
+ return headers;
+ }
+
+ public MockFacesResourceContext(FacesContext facesContext) {
+ super(facesContext);
+ }
+
+}
Added: trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java (rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java 2007-04-03 00:27:24 UTC (rev 49)
@@ -0,0 +1,502 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.ajax4jsf.tests.org.apache.shale.test.config;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.Renderer;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.Rule;
+import org.apache.shale.test.mock.MockRenderKit;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>Utility class to parse JavaServer Faces configuration resources, and
+ * register JSF artifacts with the mock object hierarchy.</p>
+ *
+ * <p>The following artifacts are registered:</p>
+ * <ul>
+ * <li><code>Converter</code> (by-id and by-class)</li>
+ * <li><code>RenderKit</code> and <code>Renderer</code></li>
+ * <li><code>UIComponent</code></li>
+ * <li><code>Validator</code></li>
+ * </ul>
+ *
+ * <p>Note that any declared <em>factory</em> instances are explicitly
+ * <strong>NOT</strong> registered, allowing the mock object hierarchy
+ * of the Shale Test Framework to manage these APIs.</p>
+ *
+ * <p><strong>USAGE NOTE</strong> - If you are using an instance of this
+ * class within a subclass of <code>AbstractJsfTestCase</code> or
+ * <code>AbstractJmockJsfTestCase</code>, be sure you have completed the
+ * <code>setUp()</code> processing in this base class before calling one
+ * of the <code>parse()</code> methods.</p>
+ *
+ * @since 1.1
+ */
+public final class ConfigParser {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /** Creates a new instance of ConfigParser */
+ public ConfigParser() {
+ }
+
+
+ // ------------------------------------------------------ Manifest Constants
+
+
+ /**
+ * <p>Configuration resource URLs for the JSF RI.</p>
+ */
+ private static final String[] JSFRI_RESOURCES =
+ { "/com/sun/faces/jsf-ri-runtime.xml",
+ };
+
+
+ /**
+ * <p>Configuration resource URLs for Apache MyFaces.</p>
+ */
+ private static final String[] MYFACES_RESOURCES =
+ { "/org/apache/myfaces/resource/standard-faces-config.xml",
+ };
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ /**
+ * <p>The <code>Digester</code> instance we will use for parsing.</p>
+ */
+ private Digester digester = null;
+
+
+ // ------------------------------------------------------- Public Properties
+
+
+ /**
+ * <p>Return the URLs of the platform configuration resources for this
+ * application. The following platforms are currently supported:</p>
+ * <ul>
+ * <li>JavaServer Faces Reference Implementation (version 1.0 - 1.2)</li>
+ * <li>MyFaces (version 1.1)</li>
+ * </ul>
+ *
+ * <p>If MyFaces (version 1.2), currently under development, does not change
+ * the name of the configuration resource, it will be supported as well.</p>
+ */
+ public URL[] getPlatformURLs() {
+
+ URL[] urls = translate(JSFRI_RESOURCES);
+ if (urls[0] == null) {
+ urls = translate(MYFACES_RESOURCES);
+ }
+ return urls;
+
+ }
+
+
+ // ---------------------------------------------------------- Public Methods
+
+
+ /**
+ * <p>Parse the specified JavaServer Faces configuration resource, causing
+ * the appropriate JSF artifacts to be registered with the mock object
+ * hierarchy.</p>
+ *
+ * @param url <code>URL</code> of the configuration resource to parse
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception SAXException if a parsing error occurs
+ */
+ public void parse(URL url) throws IOException, SAXException {
+
+ // Acquire and configure the Digester instance we will use
+ Digester digester = digester();
+ ApplicationFactory factory = (ApplicationFactory)
+ FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = factory.getApplication();
+ digester.push(application);
+
+ // Perform the required parsing
+ try {
+ digester.parse(new InputSource(url.openStream()));
+ } finally {
+ digester.clear();
+ }
+
+ }
+
+
+ /**
+ * <p>Parse the specified set of JavaServer Faces configuration resources,
+ * in the listed order, causing the appropriate JSF artifacts to be registered
+ * with the mock object hierarchy.</p>
+ *
+ * @param urls <code>URL</code>s of the configuration resources to parse
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception SAXException if a parsing error occurs
+ */
+ public void parse(URL[] urls) throws IOException, SAXException {
+
+ for (int i = 0; i < urls.length; i++) {
+ parse(urls[i]);
+ }
+
+ }
+
+
+ // --------------------------------------------------------- Private Methods
+
+
+ /**
+ * <p>Return the <code>Digester</code> instance we will use for parsing,
+ * creating and configuring a new instance if necessary.</p>
+ */
+ private Digester digester() {
+
+ if (this.digester == null) {
+ this.digester = new Digester();
+ digester.addRule("faces-config/component", new ComponentRule());
+ digester.addCallMethod
+ ("faces-config/component/component-type", "setComponentType", 0);
+ digester.addCallMethod
+ ("faces-config/component/component-class", "setComponentClass", 0);
+ digester.addRule("faces-config/converter", new ConverterRule());
+ digester.addCallMethod
+ ("faces-config/converter/converter-id", "setConverterId", 0);
+ digester.addCallMethod
+ ("faces-config/converter/converter-class", "setConverterClass", 0);
+ digester.addCallMethod
+ ("faces-config/converter/converter-for-class", "setConverterForClass", 0);
+ digester.addRule("faces-config/render-kit", new RenderKitRule());
+ digester.addRule("faces-config/render-kit/render-kit-id", new RenderKitIdRule());
+ digester.addRule("faces-config/render-kit/renderer", new RendererRule());
+ digester.addCallMethod
+ ("faces-config/render-kit/renderer/component-family", "setComponentFamily", 0);
+ digester.addCallMethod
+ ("faces-config/render-kit/renderer/renderer-class", "setRendererClass", 0);
+ digester.addCallMethod
+ ("faces-config/render-kit/renderer/renderer-type", "setRendererType", 0);
+ digester.addRule("faces-config/validator", new ValidatorRule());
+ digester.addCallMethod
+ ("faces-config/validator/validator-id", "setValidatorId", 0);
+ digester.addCallMethod
+ ("faces-config/validator/validator-class", "setValidatorClass", 0);
+ }
+ return this.digester;
+
+ }
+
+
+ /**
+ * <p>Translate an array of resource names into an array of resource URLs.</p>
+ *
+ * @param names Resource names to translate
+ */
+ private URL[] translate(String[] names) {
+
+ URL[] results = new URL[names.length];
+ for (int i = 0; i < names.length; i++) {
+ results[i] = this.getClass().getResource(names[i]);
+ }
+ return results;
+
+ }
+
+
+ // --------------------------------------------------------- Private Classes
+
+
+ /**
+ * <p>Data bean that stores information related to a component.</p>
+ */
+ class ComponentBean {
+
+ private String componentClass;
+ public String getComponentClass() {
+ return this.componentClass;
+ }
+ public void setComponentClass(String componentClass) {
+ this.componentClass = componentClass;
+ }
+
+ private String componentType;
+ public String getComponentType() {
+ return this.componentType;
+ }
+ public void setComponentType(String componentType) {
+ this.componentType = componentType;
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing components.</p>
+ */
+ class ComponentRule extends Rule {
+
+ public void begin(String namespace, String name, Attributes attributes) {
+ getDigester().push(new ComponentBean());
+ }
+
+ public void end(String namespace, String name) {
+ ComponentBean bean = (ComponentBean) getDigester().pop();
+ Application application = (Application) getDigester().peek();
+ application.addComponent(bean.getComponentType(), bean.getComponentClass());
+ }
+
+ }
+
+
+ /**
+ * <p>Data bean that stores information related to a converter.</p>
+ */
+ class ConverterBean {
+
+ private String converterClass;
+ public String getConverterClass() {
+ return this.converterClass;
+ }
+ public void setConverterClass(String converterClass) {
+ this.converterClass = converterClass;
+ }
+
+ private String converterForClass;
+ public String getConverterForClass() {
+ return this.converterForClass;
+ }
+ public void setConverterForClass(String converterForClass) {
+ this.converterForClass = converterForClass;
+ }
+
+ private String converterId;
+ public String getConverterId() {
+ return this.converterId;
+ }
+ public void setConverterId(String converterId) {
+ this.converterId = converterId;
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing converers.</p>
+ */
+ class ConverterRule extends Rule {
+
+ public void begin(String namespace, String name, Attributes attributes) {
+ getDigester().push(new ConverterBean());
+ }
+
+ public void end(String namespace, String name) {
+ ConverterBean bean = (ConverterBean) getDigester().pop();
+ Application application = (Application) getDigester().peek();
+ if (bean.getConverterId() != null) {
+ application.addConverter(bean.getConverterId(), bean.getConverterClass());
+ } else {
+ Class clazz = null;
+ try {
+ clazz = this.getClass().getClassLoader().loadClass(bean.getConverterForClass());
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("java.lang.ClassNotFoundException: "
+ + bean.getConverterForClass());
+ }
+ application.addConverter(clazz, bean.getConverterClass());
+ }
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing render kits.</p>
+ */
+ class RenderKitRule extends Rule {
+
+ public void begin(String namespace, String name, Attributes attributes) {
+ RenderKitFactory factory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ getDigester().push(factory.getRenderKit(null, RenderKitFactory.HTML_BASIC_RENDER_KIT));
+ }
+
+ public void end(String namespace, String name) {
+ getDigester().pop();
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing render kit identifiers.</p>
+ */
+ class RenderKitIdRule extends Rule {
+
+ public void body(String namespace, String name, String text) {
+ String renderKitId = text.trim();
+ RenderKitFactory factory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKit renderKit = factory.getRenderKit(null, renderKitId);
+ if (renderKit == null) {
+ renderKit = new MockRenderKit();
+ factory.addRenderKit(renderKitId, renderKit);
+ }
+ digester.pop();
+ digester.push(renderKit);
+ }
+
+ }
+
+
+ /**
+ * <p>Data bean that stores information related to a renderer.</p>
+ */
+ class RendererBean {
+
+ private String componentFamily;
+ public String getComponentFamily() {
+ return this.componentFamily;
+ }
+ public void setComponentFamily(String componentFamily) {
+ this.componentFamily = componentFamily;
+ }
+
+ private String rendererClass;
+ public String getRendererClass() {
+ return this.rendererClass;
+ }
+ public void setRendererClass(String rendererClass) {
+ this.rendererClass = rendererClass;
+ }
+
+ private String rendererType;
+ public String getRendererType() {
+ return this.rendererType;
+ }
+ public void setRendererType(String rendererType) {
+ this.rendererType = rendererType;
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing renderers.</p>
+ */
+ class RendererRule extends Rule {
+
+ public void begin(String namespace, String name, Attributes attributes) {
+ getDigester().push(new RendererBean());
+ }
+
+ public void end(String namespace, String name) {
+ RendererBean bean = (RendererBean) getDigester().pop();
+ RenderKit kit = (RenderKit) getDigester().peek();
+ Renderer renderer = null;
+ Class clazz = null;
+ try {
+ clazz = this.getClass().getClassLoader().loadClass(bean.getRendererClass());
+ renderer = (Renderer) clazz.newInstance();
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Exception while trying to instantiate"
+ + " renderer class '" + bean.getRendererClass() + "' : "
+ + e.getMessage());
+ }
+ kit.addRenderer(bean.getComponentFamily(), bean.getRendererType(),
+ renderer);
+ }
+
+ }
+
+
+ /**
+ * <p>Data bean that stores information related to a validator.</p>
+ */
+ class ValidatorBean {
+
+ private String validatorClass;
+ public String getValidatorClass() {
+ return this.validatorClass;
+ }
+ public void setValidatorClass(String validatorClass) {
+ this.validatorClass = validatorClass;
+ }
+
+ private String validatorId;
+ public String getValidatorId() {
+ return this.validatorId;
+ }
+ public void setValidatorId(String validatorId) {
+ this.validatorId = validatorId;
+ }
+
+ }
+
+
+ /**
+ * <p>Digester <code>Rule</code> for processing validators.</p>
+ */
+ class ValidatorRule extends Rule {
+
+ public void begin(String namespace, String name, Attributes attributes) {
+ getDigester().push(new ValidatorBean());
+ }
+
+ public void end(String namespace, String name) {
+ ValidatorBean bean = (ValidatorBean) getDigester().pop();
+ Application application = (Application) getDigester().peek();
+ application.addValidator(bean.getValidatorId(), bean.getValidatorClass());
+ }
+
+ }
+
+
+}
17 years, 9 months
JBoss Ajax4JSF SVN: r48 - trunk/test/src/main/java/org/ajax4jsf/tests.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-02 15:52:02 -0400 (Mon, 02 Apr 2007)
New Revision: 48
Modified:
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
Unpacking of /WEB-XML to temp folder implemented to configure env. when test is packed into JAR
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-03-31 00:27:58 UTC (rev 47)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-02 19:52:02 UTC (rev 48)
@@ -22,10 +22,15 @@
package org.ajax4jsf.tests;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Random;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
@@ -67,6 +72,8 @@
*/
public class AbstractAjax4JsfTestCase extends AbstractJsfTestCase {
+ private File tmpRoot = null;
+
/**
* @param name
*/
@@ -102,7 +109,50 @@
servletContext.setAttribute("a4jSkin", new SkinBean());
// Setup servlet context and testing web.xml
request.setPathElements("/testContext","/faces","/vievId.jsf","");
- servletContext.setDocumentRoot(new File(getClass().getResource("/WEB-INF/web.xml").getFile()).getParentFile().getParentFile());
+
+ File webRoot = new File(getClass().getResource("/WEB-INF/web.xml").getFile()).getParentFile().getParentFile();
+ if (webRoot.exists()) {
+ servletContext.setDocumentRoot(webRoot);
+ } else {
+ // Prepare WEB-ROOT in temp folder
+ tmpRoot = File.createTempFile("TmpTestRoot" + new Random().nextInt(), null);
+ tmpRoot.delete();
+ tmpRoot.mkdir();
+ servletContext.setDocumentRoot(tmpRoot);
+
+ URL jarUrl = AbstractAjax4JsfTestCase.class.getProtectionDomain().getCodeSource().getLocation();
+ ZipInputStream zis = new ZipInputStream(jarUrl.openStream());
+ try {
+ ZipEntry entry;
+ byte[] buffer = new byte[8192];
+ while ((entry = zis.getNextEntry()) != null) {
+ String name = entry.getName();
+ if (name.startsWith("WEB-INF/")) {
+ File out = new File(tmpRoot, name);
+ if (entry.isDirectory()) {
+ out.mkdirs();
+ } else {
+ out.getParentFile().mkdirs();
+ OutputStream os = new FileOutputStream(out);
+ try {
+ int count;
+ while ((count = zis.read(buffer)) > 0) {
+ os.write(buffer, 0, count);
+ }
+ } finally {
+ os.close();
+ }
+ zis.closeEntry();
+ }
+ }
+ }
+ } catch (IOException e) {
+ deleteRecursively(tmpRoot);
+ throw e;
+ }
+ servletContext.setDocumentRoot(tmpRoot);
+ }
+
try {
InternetResourceBuilder.getInstance().init(servletContext, "A4J");
} catch (ServletException e) {
@@ -125,7 +175,27 @@
webClient.setThrowExceptionOnScriptError(false);
}
+ private void deleteRecursively(File file) {
+ if (file != null) {
+ String[] list = file.list();
+ if (list != null) {
+ for (int i = 0; i < list.length; i++) {
+ String name = list[i];
+ File f = new File(file, name);
+ if (f.isDirectory()) {
+ deleteRecursively(f);
+ } else {
+ f.delete();
+ }
+ }
+ }
+
+ file.delete();
+ }
+ }
+
+
/* (non-Javadoc)
* @see org.apache.shale.test.base.AbstractJsfTestCase#tearDown()
*/
@@ -133,13 +203,15 @@
// This method MUST BE OVERRIDEN in any subclasses - since Junit see for it in class for call
super.tearDown();
vcpRenderKit = null;
-// Thread.currentThread().setContextClassLoader(threadContextClassLoader);
-// threadContextClassLoader = null;
- webClient = null;
- webConnection = null;
- writer = null;
+// Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+// threadContextClassLoader = null;
+ webClient = null;
+ webConnection = null;
+ writer = null;
SkinFactory.reset();
- InternetResourceBuilder.setInstance(null);
+ InternetResourceBuilder.setInstance(null);
+
+ deleteRecursively(tmpRoot);
}
// Protected configurations URL's
@@ -159,7 +231,7 @@
protected URL[] getImplementationUrls() {
return new URL[0];
}
-
+
/**
* Create component with given render kit and unique Id from ViewRoot.
* @param type - component type.
@@ -209,14 +281,14 @@
comp.setId(facesContext.getViewRoot().createUniqueId());
return comp;
}
-
- /**
- * Render all children for given component.
- * @param component
- * @throws IOException
- */
- protected void renderChildren(FacesContext context,
+
+ /**
+ * Render all children for given component.
+ * @param component
+ * @throws IOException
+ */
+ protected void renderChildren(FacesContext context,
UIComponent component) throws IOException {
if (component.getChildCount() > 0) {
for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
@@ -233,7 +305,7 @@
* @throws IOException
*/
protected void renderChild(FacesContext context, UIComponent child)
- throws IOException {
+ throws IOException {
if (!child.isRendered()) {
return;
}
@@ -246,7 +318,7 @@
}
child.encodeEnd(context);
}
-
+
/**
* Render test view and parse to htmlunit page structure.
* @return
@@ -280,7 +352,7 @@
facesContext.setResponseWriter(writer);
writer.startDocument();
}
-
+
/**
* Parse collected content of mock response to Page instance, used for check rendered html.
* @return
@@ -298,9 +370,9 @@
}
return webClient.getPage(page);
}
-
+
protected AjaxContext ajaxContext = null;
-
+
/**
* Initialised instance of VCP render kit.
*/
@@ -311,21 +383,21 @@
*/
protected MockResponseWriter writer;
- /**
- * <p>The htmlunit web client for this test case. </p>
- *
- */
- protected WebClient webClient = null;
-
- /**
- * Mock web connection for accept stored content of JSF encoding. For testing JavaScript code, all URL's for scripts must be
- * rregistered by {@link MockWebConnection#setResponse(java.net.URL, byte[], int, java.lang.String, java.lang.String, java.util.List)} method
- * By default, for unregistered pages return 404 - not found.
- */
- protected MockWebConnection webConnection = null;
+ /**
+ * <p>The htmlunit web client for this test case. </p>
+ *
+ */
+ protected WebClient webClient = null;
+ /**
+ * Mock web connection for accept stored content of JSF encoding. For testing JavaScript code, all URL's for scripts must be
+ * rregistered by {@link MockWebConnection#setResponse(java.net.URL, byte[], int, java.lang.String, java.lang.String, java.util.List)} method
+ * By default, for unregistered pages return 404 - not found.
+ */
+ protected MockWebConnection webConnection = null;
- // Thread context class loader saved and restored after each test
- private ClassLoader threadContextClassLoader = null;
-
+
+ // Thread context class loader saved and restored after each test
+ private ClassLoader threadContextClassLoader = null;
+
}
17 years, 9 months