You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2007/02/13 22:47:46 UTC
svn commit: r507278 - in
/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal:
config/ config/dispatch/ config/upload/ context/external/
Author: awiner
Date: Tue Feb 13 14:47:45 2007
New Revision: 507278
URL: http://svn.apache.org/viewvc?view=rev&rev=507278
Log:
ADFFACES-374: In JSF1.2, configurators should use setRequest and setResponse where possible
Patch from Scott O'Bryan
Code simplifies configurators to use getRequest and setRequest instead of overriding the
entire ExternalContext - and complicates it a bit to deal with JSF RI bug 493 (fixed
in the forthcoming 1.2_04 release).
Added:
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java
Removed:
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java
Modified:
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java
incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java Tue Feb 13 14:47:45 2007
@@ -1,501 +1,815 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.myfaces.trinidadinternal.config;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-
-import org.apache.myfaces.trinidad.config.Configurator;
-import org.apache.myfaces.trinidad.context.RequestContext;
-import org.apache.myfaces.trinidad.context.RequestContextFactory;
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidad.skin.SkinFactory;
-import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
-import org.apache.myfaces.trinidadinternal.context.RequestContextFactoryImpl;
-import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
-import org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl;
-import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
-import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
-
-/**
- * This is the implementation of the Trinidad's Global configurator. It provides the entry point for
- * all other configurators. This class is responsible for enforcing the contract outlined by the
- * Configurator abstract class, but allows a more "relaxed" implementation of the APIs called for by
- * the Configurator class, making it more convenient to use ConfiguratorServices from within the
- * Trinidad renderkit. Where appropriate, these differences will be documented for the benifit of
- * the Trindad developer.
- *
- * @see org.apache.myfaces.trinidad.config.Configurator
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public class GlobalConfiguratorImpl extends Configurator
-{
- /**
- * Returns a GlobalConfigurator instance for the current context's class loader. The
- * GlobalConfigurator is responsible for enforcing the contract on the other methods of this
- * class. This means that if {@link #init(ExternalContext)} is called multiple times, the global
- * configurator will call all subordinate configurators only once.
- *
- * Likewise, the GlobalConfigurator will return exceptions when the contract is expressly violated
- * (like if {@link #getExternalContext(ExternalContext)} is called before a {{@link #beginRequest(ExternalContext)}.
- *
- * @return a GlobalConfigurator or <code>null</code> is one was unable to be obtained.
- */
- static public final GlobalConfiguratorImpl getInstance()
- {
- final ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- if (loader == null)
- {
- _LOG.severe("Could not find context class loader.");
- }
- else
- {
- synchronized (_CONFIGURATORS)
- {
- GlobalConfiguratorImpl config = _CONFIGURATORS.get(loader);
- if (config == null)
- {
- try
- {
- config = new GlobalConfiguratorImpl();
- _CONFIGURATORS.put(loader, config);
- }
- catch (final RuntimeException e)
- {
- // OC4J was not reporting these errors properly:
- _LOG.severe(e);
- throw e;
- }
- _LOG.fine("GlobalConfigurator has been created.");
- }
- return config;
- }
- }
- return null;
- }
-
- /**
- * Returns true if the request has not been stated for the current "virtual"
- * request. In the servlet environment this will be true after
- * {@link #beginRequest(ExternalContext)} is executed and before
- * {@link #endRequest(ExternalContext)} is executed. This will generally
- * happen once per request. In the Portlet Environment, the request must be
- * be started and ended at the beginning and end of both the actionRequest
- * and the RenderRequest.
- *
- * @param ec
- * @return
- */
- static public boolean isRequestStarted(final ExternalContext ec)
- {
- return (RequestType.getType(ec) != null);
- }
-
- /**
- * Returns "true" if the services should be considered enabled or disabled.
- *
- * @param ec
- * @return
- */
- static private final boolean _isDisabled(final ExternalContext ec)
- {
- final Boolean inRequest = (Boolean) ec.getRequestMap().get(_IN_REQUEST);
-
- if (inRequest == null)
- {
- return isConfiguratorServiceDisabled(ec);
- }
- else
- {
- final boolean disabled = inRequest.booleanValue();
- if (disabled != isConfiguratorServiceDisabled(ec))
- {
- _LOG
- .warning("Configurator services were disabled after beginRequest was executed. Cannot disable configurator services");
- }
-
- return disabled;
- }
- }
-
- /**
- * Private default constructor. Right now this class is not serializable. If serialization is
- * required, we may wish to make this public. We really don't want people using this though.
- */
- private GlobalConfiguratorImpl()
- {}
-
- /**
- * Executes the beginRequest methods of all of the configurator services. This method will also
- * initizlize the configurator if it has not already been initialized, so there may be no need to
- * call the {@link #init(ExternalContext)} method directly.
- *
- * This method also ensures that the requestContext is attached before the beginRequest methods
- * are called, so there is no reason to initialize the request context before calling this method.
- * In portal environments, it is important to execute this method once for each Portlet action and
- * render request so that the requestContext may be properly initialized even though the
- * underlying services will be called only once per physical request.
- *
- * @param externalContext
- * the externalContext to use to begin the request.
- *
- * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
- */
- @SuppressWarnings("unchecked") // TODO: remove this for Faces 1.2
- @Override
- public void beginRequest(final ExternalContext externalContext)
- {
- // asserts for debug which disappear in production
- assert externalContext != null;
-
- // Do per-virtual request stuff
- if (RequestType.getType(externalContext) == null)
- {
- // RequestType may change in a portal environment. Make sure it's set up to enforce the
- // contracts
- RequestType.setType(externalContext);
-
- // By contract, Configurators beginRequest is only called once per physical request.
- // The globalConfigurator may be called multiple times, however, so we need to enforce
- // the contract.
- if (!_isDisabled(externalContext))
- {
- if (!_initialized)
- {
- init(externalContext);
- }
-
- // If this hasn't been initialized then please initialize
- _attachRequestContext(externalContext);
-
- if (externalContext.getRequestMap().get(_IN_REQUEST) == null)
- {
- _startConfiguratorServiceRequest(externalContext);
- }
- }
- else
- {
- _LOG.fine("GlobalConfigurator: Configurators have been disabled for this request.");
- }
- }
- else if (!RequestType.isCorrectType(externalContext))
- {
- // This will happen if the actionRequest was not ended before dispatching to the render
- // request
- throw new IllegalStateException("The previous action request was not ended.");
- }
- else
- {
- _LOG.fine("BeginRequest called multiple times for this request");
- }
- }
-
- /**
- * Cleans up the current configurator. This will execute the destroy method on all of the
- * configurator services. Generally this will be called by Trinidad's context listener when the
- * context is destroyed, but it may be used manually to allow the configurator to be
- * re-initialized.
- *
- * Calling this method while the configurator is not initialized will not re-execute the destroy
- * methods on the services.
- *
- * @see org.apache.myfaces.trinidad.config.Configurator#destroy()
- */
- @Override
- public void destroy()
- {
- if (_initialized)
- {
- for (final Configurator config : _services)
- {
- try
- {
- config.destroy();
- }
- catch (final Throwable t)
- {
- // we always want to continue to destroy things, so log errors and continue
- _LOG.severe(t);
- }
- }
- _services = null;
- _initialized = false;
- }
- }
-
- /**
- * Ends the currently begun request. It is important to note that this should be executed only
- * once per physical request.
- *
- * @see org.apache.myfaces.trinidad.config.Configurator#endRequest(javax.faces.context.ExternalContext)
- */
- @Override
- public void endRequest(final ExternalContext externalContext)
- {
- // do per virtual-request stuff
- if (RequestType.getType(externalContext) != null)
- {
- if (!_isDisabled(externalContext))
- {
- final RequestType type = RequestType.getType(externalContext);
-
- // Do not end services at the end of a portal action request
- if (type != RequestType.PORTAL_ACTION)
- {
- _endConfiguratorServiceRequest(externalContext);
- }
-
- final RequestContext context = RequestContext.getCurrentInstance();
- if (context != null)
- {
- context.release();
- assert RequestContext.getCurrentInstance() == null;
- }
- }
- RequestType.clearType(externalContext);
- }
- }
-
- /**
- * Returns an externalContext for this configurator and all of the configurator services. If this
- * method is executed before {@link #beginRequest(ExternalContext)} then this method will call
- * beginRequest(). It is important to note, however, that even though beginRequest does not need
- * to be explicitly called, {{@link #endRequest(ExternalContext)} does need to be called when the
- * request has completed or the contract to the configurators will be broken.
- *
- * @param externalContext
- * the ExternalContext object that should be wrapped.
- *
- * @return a decorated ExternalContext object
- */
- @Override
- public ExternalContext getExternalContext(ExternalContext externalContext)
- {
- if (RequestType.getType(externalContext) == null)
- {
- beginRequest(externalContext);
- }
-
- if (!_isDisabled(externalContext))
- {
- // Wrap ExternalContexts
- for (final Configurator config : _services)
- {
- externalContext = config.getExternalContext(externalContext);
- }
- }
-
- return externalContext;
- }
-
- /**
- * Initializes the global configurator and the configurator services. This method need not be
- * called directly as it will be called from {@link #beginRequest(ExternalContext)} if needed. It
- * is also possible to execute this method more then once, although if initialization has already
- * happened then a call to this method will not do anything. To re-initialize this class, call
- * {@link #destroy()} first and then call this method.
- *
- * @param externalContext
- * the externalContext needed to initialize this class
- *
- * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
- */
- @Override
- public void init(final ExternalContext externalContext)
- {
- assert externalContext != null;
-
- if (!_initialized)
- {
- _services = ClassLoaderUtils.getServices(Configurator.class.getName());
-
- // Create a new RequestContextFactory is needed
- if (RequestContextFactory.getFactory() == null)
- {
- RequestContextFactory.setFactory(new RequestContextFactoryImpl());
- }
-
- // Create a new SkinFactory if needed.
- if (SkinFactory.getFactory() == null)
- {
- SkinFactory.setFactory(new SkinFactoryImpl());
- }
-
- // register the base skins
- SkinUtils.registerBaseSkins();
-
- for (final Configurator config : _services)
- {
- config.init(externalContext);
- }
-
- // after the 'services' filters are initialized, then register
- // the skin extensions found in trinidad-skins.xml. This
- // gives a chance to the 'services' filters to create more base
- // skins that the skins in trinidad-skins.xml can extend.
- SkinUtils.registerSkinExtensions(externalContext);
-
- _initialized = true;
- }
- else
- {
- _LOG.warning("Configurator services already initialized.");
- }
- }
-
- /**
- * @param externalContext
- * @return
- */
- @SuppressWarnings("unchecked")
- private void _attachRequestContext(final ExternalContext externalContext)
- {
- // If someone didn't release the RequestContext on an earlier request,
- // then it'd still be around, and trying to create a new one
- // would trigger an exception. We don't want to take down
- // this thread for all eternity, so clean up after poorly-behaved code.
- RequestContext context = RequestContext.getCurrentInstance();
- if (context != null)
- {
- if (_LOG.isWarning())
- {
- _LOG.warning("RequestContext had not been properly released on earlier " + "request.");
- }
- context.release();
- }
-
- // See if we've got a cached RequestContext instance; if so,
- // reattach it
- final Object cachedRequestContext = externalContext.getRequestMap().get(
- TrinidadPhaseListener.CACHED_REQUEST_CONTEXT);
-
- // Catch both the null scenario and the
- // RequestContext-from-a-different-classloader scenario
- if (cachedRequestContext instanceof RequestContext)
- {
- context = (RequestContext) cachedRequestContext;
- context.attach();
- }
- else
- {
- final RequestContextFactory factory = RequestContextFactory.getFactory();
- assert factory != null;
- context = factory.createContext(externalContext);
- externalContext.getRequestMap().put(TrinidadPhaseListener.CACHED_REQUEST_CONTEXT, context);
- }
-
- assert RequestContext.getCurrentInstance() == context;
- }
-
- private void _endConfiguratorServiceRequest(final ExternalContext ec)
- {
- // Physical request has now ended
- // Clear the in-request flag
- ec.getRequestMap().remove(_IN_REQUEST);
- for (final Configurator config : _services)
- {
- config.endRequest(ec);
- }
- }
-
- @SuppressWarnings("unchecked")
- private void _startConfiguratorServiceRequest(final ExternalContext ec)
- {
- // Physical request has now begun
- final boolean disabled = isConfiguratorServiceDisabled(ec);
-
- // Tell whether the services were disabled when the requests had begun
- ec.getRequestMap().put(_IN_REQUEST, disabled);
-
- // If this hasn't been initialized then please initialize
- for (final Configurator config : _services)
- {
- config.beginRequest(ec);
- }
- }
-
- private boolean _initialized;
-
- private List<Configurator> _services;
-
- static private final Map<ClassLoader, GlobalConfiguratorImpl> _CONFIGURATORS = new HashMap<ClassLoader, GlobalConfiguratorImpl>();
-
- static private final String _IN_REQUEST = GlobalConfiguratorImpl.class
- .getName()
- + ".IN_REQUEST";
-
- static private final TrinidadLogger _LOG = TrinidadLogger
- .createTrinidadLogger(GlobalConfiguratorImpl.class);
-
- private enum RequestType
- {
- PORTAL_ACTION,
- PORTAL_RENDER,
- SERVLET;
-
- public static void clearType(final ExternalContext ec)
- {
- ec.getRequestMap().remove(_REQUEST_TYPE);
- }
-
- public static RequestType getType(final ExternalContext ec)
- {
- return (RequestType) ec.getRequestMap().get(_REQUEST_TYPE);
- }
-
- public static boolean isCorrectType(final ExternalContext ec)
- {
- return _findType(ec) == getType(ec);
- }
-
- @SuppressWarnings("unchecked")
- public static void setType(final ExternalContext ec)
- {
- ec.getRequestMap().put(_REQUEST_TYPE, _findType(ec));
- }
-
- private static final RequestType _findType(final ExternalContext ec)
- {
- if (ExternalContextUtils.isPortlet(ec))
- {
- if (ExternalContextUtils.isAction(ec))
- {
- return PORTAL_ACTION;
- }
- else
- {
- return PORTAL_RENDER;
- }
- }
- else
- {
- return SERVLET;
- }
- }
-
- static private final String _REQUEST_TYPE = GlobalConfiguratorImpl.class.getName()
- + ".REQUEST_TYPE";
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.trinidadinternal.config;
+
+import java.io.IOException;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.PortletContext;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import javax.servlet.ServletRequest;
+
+import javax.servlet.ServletRequestWrapper;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.config.Configurator;
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.context.RequestContextFactory;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.skin.SkinFactory;
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidadinternal.context.RequestContextFactoryImpl;
+import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
+import org.apache.myfaces.trinidadinternal.context.external.ServletCookieMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestHeaderMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestHeaderValuesMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterValuesMap;
+import org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl;
+import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
+import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletContextWrapper;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletRequestWrapper;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletResponseWrapper;
+
+/**
+ * This is the implementation of the Trinidad's Global configurator. It provides the entry point for
+ * all other configurators. This class is responsible for enforcing the contract outlined by the
+ * Configurator abstract class, but allows a more "relaxed" implementation of the APIs called for by
+ * the Configurator class, making it more convenient to use ConfiguratorServices from within the
+ * Trinidad renderkit. Where appropriate, these differences will be documented for the benifit of
+ * the Trindad developer.
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class GlobalConfiguratorImpl extends Configurator
+{
+ /**
+ * Returns a GlobalConfigurator instance for the current context's class loader. The
+ * GlobalConfigurator is responsible for enforcing the contract on the other methods of this
+ * class. This means that if {@link #init(ExternalContext)} is called multiple times, the global
+ * configurator will call all subordinate configurators only once.
+ *
+ * Likewise, the GlobalConfigurator will return exceptions when the contract is expressly violated
+ * (like if {@link #getExternalContext(ExternalContext)} is called before a {{@link #beginRequest(ExternalContext)}.
+ *
+ * @return a GlobalConfigurator or <code>null</code> is one was unable to be obtained.
+ */
+ static public final GlobalConfiguratorImpl getInstance()
+ {
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ if (loader == null)
+ {
+ _LOG.severe("Could not find context class loader.");
+ }
+ else
+ {
+ synchronized (_CONFIGURATORS)
+ {
+ GlobalConfiguratorImpl config = _CONFIGURATORS.get(loader);
+ if (config == null)
+ {
+ try
+ {
+ config = new GlobalConfiguratorImpl();
+ _CONFIGURATORS.put(loader, config);
+ }
+ catch (final RuntimeException e)
+ {
+ // OC4J was not reporting these errors properly:
+ _LOG.severe(e);
+ throw e;
+ }
+ _LOG.fine("GlobalConfigurator has been created.");
+ }
+ return config;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns true if the request has not been stated for the current "virtual"
+ * request. In the servlet environment this will be true after
+ * {@link #beginRequest(ExternalContext)} is executed and before
+ * {@link #endRequest(ExternalContext)} is executed. This will generally
+ * happen once per request. In the Portlet Environment, the request must be
+ * be started and ended at the beginning and end of both the actionRequest
+ * and the RenderRequest.
+ *
+ * @param ec
+ * @return
+ */
+ static public boolean isRequestStarted(final ExternalContext ec)
+ {
+ return (RequestType.getType(ec) != null);
+ }
+
+ /**
+ * Returns "true" if the services should be considered enabled or disabled.
+ *
+ * @param ec
+ * @return
+ */
+ static private final boolean _isDisabled(final ExternalContext ec)
+ {
+ final Boolean inRequest = (Boolean) ec.getRequestMap().get(_IN_REQUEST);
+
+ if (inRequest == null)
+ {
+ return isConfiguratorServiceDisabled(ec);
+ }
+ else
+ {
+ final boolean disabled = inRequest.booleanValue();
+ if (disabled != isConfiguratorServiceDisabled(ec))
+ {
+ _LOG
+ .warning("Configurator services were disabled after beginRequest was executed. Cannot disable configurator services");
+ }
+
+ return disabled;
+ }
+ }
+
+ /**
+ * Private default constructor. Right now this class is not serializable. If serialization is
+ * required, we may wish to make this public. We really don't want people using this though.
+ */
+ private GlobalConfiguratorImpl()
+ {}
+
+ /**
+ * Executes the beginRequest methods of all of the configurator services. This method will also
+ * initizlize the configurator if it has not already been initialized, so there may be no need to
+ * call the {@link #init(ExternalContext)} method directly.
+ *
+ * This method also ensures that the requestContext is attached before the beginRequest methods
+ * are called, so there is no reason to initialize the request context before calling this method.
+ * In portal environments, it is important to execute this method once for each Portlet action and
+ * render request so that the requestContext may be properly initialized even though the
+ * underlying services will be called only once per physical request.
+ *
+ * @param externalContext
+ * the externalContext to use to begin the request.
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
+ */
+ @SuppressWarnings("unchecked") // TODO: remove this for Faces 1.2
+ @Override
+ public void beginRequest(final ExternalContext externalContext)
+ {
+ // asserts for debug which disappear in production
+ assert externalContext != null;
+
+ // Do per-virtual request stuff
+ if (RequestType.getType(externalContext) == null)
+ {
+ // RequestType may change in a portal environment. Make sure it's set up to enforce the
+ // contracts
+ RequestType.setType(externalContext);
+
+ // By contract, Configurators beginRequest is only called once per physical request.
+ // The globalConfigurator may be called multiple times, however, so we need to enforce
+ // the contract.
+ if (!_isDisabled(externalContext))
+ {
+ if (!_initialized)
+ {
+ init(externalContext);
+ }
+
+ // If this hasn't been initialized then please initialize
+ _attachRequestContext(externalContext);
+
+ if (externalContext.getRequestMap().get(_IN_REQUEST) == null)
+ {
+ _startConfiguratorServiceRequest(externalContext);
+ }
+ }
+ else
+ {
+ _LOG.fine("GlobalConfigurator: Configurators have been disabled for this request.");
+ }
+ }
+ else if (!RequestType.isCorrectType(externalContext))
+ {
+ // This will happen if the actionRequest was not ended before dispatching to the render
+ // request
+ throw new IllegalStateException("The previous action request was not ended.");
+ }
+ else
+ {
+ _LOG.fine("BeginRequest called multiple times for this request");
+ }
+ }
+
+ /**
+ * Cleans up the current configurator. This will execute the destroy method on all of the
+ * configurator services. Generally this will be called by Trinidad's context listener when the
+ * context is destroyed, but it may be used manually to allow the configurator to be
+ * re-initialized.
+ *
+ * Calling this method while the configurator is not initialized will not re-execute the destroy
+ * methods on the services.
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator#destroy()
+ */
+ @Override
+ public void destroy()
+ {
+ if (_initialized)
+ {
+ for (final Configurator config : _services)
+ {
+ try
+ {
+ config.destroy();
+ }
+ catch (final Throwable t)
+ {
+ // we always want to continue to destroy things, so log errors and continue
+ _LOG.severe(t);
+ }
+ }
+ _services = null;
+ _initialized = false;
+ }
+ }
+
+ /**
+ * Ends the currently begun request. It is important to note that this should be executed only
+ * once per physical request.
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator#endRequest(javax.faces.context.ExternalContext)
+ */
+ @Override
+ public void endRequest(final ExternalContext externalContext)
+ {
+ // do per virtual-request stuff
+ if (RequestType.getType(externalContext) != null)
+ {
+ if (!_isDisabled(externalContext))
+ {
+ final RequestType type = RequestType.getType(externalContext);
+
+ // Do not end services at the end of a portal action request
+ if (type != RequestType.PORTAL_ACTION)
+ {
+ _endConfiguratorServiceRequest(externalContext);
+ }
+
+ final RequestContext context = RequestContext.getCurrentInstance();
+ if (context != null)
+ {
+ context.release();
+ assert RequestContext.getCurrentInstance() == null;
+ }
+ }
+ RequestType.clearType(externalContext);
+ }
+ }
+
+ /**
+ * Returns an externalContext for this configurator and all of the configurator services. If this
+ * method is executed before {@link #beginRequest(ExternalContext)} then this method will call
+ * beginRequest(). It is important to note, however, that even though beginRequest does not need
+ * to be explicitly called, {{@link #endRequest(ExternalContext)} does need to be called when the
+ * request has completed or the contract to the configurators will be broken.
+ *
+ * @param externalContext
+ * the ExternalContext object that should be wrapped.
+ *
+ * @return a decorated ExternalContext object
+ */
+ @Override
+ public ExternalContext getExternalContext(ExternalContext externalContext)
+ {
+ if (RequestType.getType(externalContext) == null)
+ {
+ beginRequest(externalContext);
+ }
+
+ if (!_isDisabled(externalContext))
+ {
+ if(ExternalContextUtils.isPortlet(externalContext))
+ {
+ //This handles Trinidad Portlet Request/Response wrappers in a portal
+ //environment.
+
+ //TODO sobryan this should be removed when JSR-286 is available
+ externalContext = new WrapperCompatibleExternalContext(externalContext);
+ }
+ else if(_isSetRequestBugPresent(externalContext))
+ {
+ //This handles bug 493 against the JSF-RI 1.2_03 and earlier. If the bug
+ //is present in the current system, add a wrapper to fix it
+
+ //TODO sobryan this is somewhat inefficient so should be removed when we
+ //are no longer dependant on JSF1.2_03 or earlier. Still, we only wrap
+ //when we have to so it should be no biggy under normal circumstances.
+ externalContext = new ClearRequestExternalContext(externalContext);
+ }
+
+ // Wrap ExternalContexts
+ for (final Configurator config : _services)
+ {
+ externalContext = config.getExternalContext(externalContext);
+ }
+ }
+
+ return externalContext;
+ }
+
+ /**
+ * Initializes the global configurator and the configurator services. This method need not be
+ * called directly as it will be called from {@link #beginRequest(ExternalContext)} if needed. It
+ * is also possible to execute this method more then once, although if initialization has already
+ * happened then a call to this method will not do anything. To re-initialize this class, call
+ * {@link #destroy()} first and then call this method.
+ *
+ * @param externalContext
+ * the externalContext needed to initialize this class
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
+ */
+ @Override
+ public void init(final ExternalContext externalContext)
+ {
+ assert externalContext != null;
+
+ if (!_initialized)
+ {
+ _services = ClassLoaderUtils.getServices(Configurator.class.getName());
+
+ // Create a new RequestContextFactory is needed
+ if (RequestContextFactory.getFactory() == null)
+ {
+ RequestContextFactory.setFactory(new RequestContextFactoryImpl());
+ }
+
+ // Create a new SkinFactory if needed.
+ if (SkinFactory.getFactory() == null)
+ {
+ SkinFactory.setFactory(new SkinFactoryImpl());
+ }
+
+ // register the base skins
+ SkinUtils.registerBaseSkins();
+
+ for (final Configurator config : _services)
+ {
+ config.init(externalContext);
+ }
+
+ // after the 'services' filters are initialized, then register
+ // the skin extensions found in trinidad-skins.xml. This
+ // gives a chance to the 'services' filters to create more base
+ // skins that the skins in trinidad-skins.xml can extend.
+ SkinUtils.registerSkinExtensions(externalContext);
+
+ _initialized = true;
+ }
+ else
+ {
+ _LOG.warning("Configurator services already initialized.");
+ }
+ }
+
+ /**
+ * @param externalContext
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private void _attachRequestContext(final ExternalContext externalContext)
+ {
+ // If someone didn't release the RequestContext on an earlier request,
+ // then it'd still be around, and trying to create a new one
+ // would trigger an exception. We don't want to take down
+ // this thread for all eternity, so clean up after poorly-behaved code.
+ RequestContext context = RequestContext.getCurrentInstance();
+ if (context != null)
+ {
+ if (_LOG.isWarning())
+ {
+ _LOG.warning("RequestContext had not been properly released on earlier " + "request.");
+ }
+ context.release();
+ }
+
+ // See if we've got a cached RequestContext instance; if so,
+ // reattach it
+ final Object cachedRequestContext = externalContext.getRequestMap().get(
+ TrinidadPhaseListener.CACHED_REQUEST_CONTEXT);
+
+ // Catch both the null scenario and the
+ // RequestContext-from-a-different-classloader scenario
+ if (cachedRequestContext instanceof RequestContext)
+ {
+ context = (RequestContext) cachedRequestContext;
+ context.attach();
+ }
+ else
+ {
+ final RequestContextFactory factory = RequestContextFactory.getFactory();
+ assert factory != null;
+ context = factory.createContext(externalContext);
+ externalContext.getRequestMap().put(TrinidadPhaseListener.CACHED_REQUEST_CONTEXT, context);
+ }
+
+ assert RequestContext.getCurrentInstance() == context;
+ }
+
+ private void _endConfiguratorServiceRequest(final ExternalContext ec)
+ {
+ // Physical request has now ended
+ // Clear the in-request flag
+ ec.getRequestMap().remove(_IN_REQUEST);
+ for (final Configurator config : _services)
+ {
+ config.endRequest(ec);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void _startConfiguratorServiceRequest(final ExternalContext ec)
+ {
+ // Physical request has now begun
+ final boolean disabled = isConfiguratorServiceDisabled(ec);
+
+ // Tell whether the services were disabled when the requests had begun
+ ec.getRequestMap().put(_IN_REQUEST, disabled);
+
+ // If this hasn't been initialized then please initialize
+ for (final Configurator config : _services)
+ {
+ config.beginRequest(ec);
+ }
+ }
+
+ static private boolean _isSetRequestBugPresent(ExternalContext ec)
+ {
+ // This first check is here in order to skip synchronization until
+ // absolutely necessary.
+ if(!_setRequestBugTested)
+ {
+ synchronized(GlobalConfiguratorImpl.class)
+ {
+ //This second check is here in case a couple of things enter before the
+ //boolean is set. This is only an exception case and will make it so
+ //the initialization code runs only once.
+ if(!_setRequestBugTested)
+ {
+ ServletRequest orig = (ServletRequest)ec.getRequest();
+ Map m = ec.getInitParameterMap();
+
+ ec.setRequest(new TestRequest(orig));
+
+ _hasSetRequestBug = !TestRequest.isTestParamPresent(ec);
+ _setRequestBugTested = true;
+
+ ec.setRequest(orig);
+ }
+ }
+ }
+
+ return _hasSetRequestBug;
+ }
+
+ // This handles an issue with the ExternalContext object prior to
+ // JSF1.2_04.
+ static private class ClearRequestExternalContext extends ExternalContextDecorator
+ {
+ private ExternalContext _ec;
+ private ServletRequest _request;
+ private HttpServletRequest _hRequest;
+ private Map<String, Object> _requestCookieMap;
+ private Map<String, String> _requestHeaderMap;
+ private Map<String, String[]> _requestHeaderValuesMap;
+ private Map<String, Object> _requestMap;
+ private Map<String, String> _requestParameterMap;
+ private Map<String, String[]> _requestParameterValuesMap;
+
+ public ClearRequestExternalContext(ExternalContext ec)
+ {
+ _ec = ec;
+ }
+
+ @Override
+ protected ExternalContext getExternalContext()
+ {
+ return _ec;
+ }
+
+ @Override
+ public void setRequest(Object request)
+ {
+ super.setRequest(request);
+
+ // And clear out any of the cached maps, since we should
+ // go back and look in the map
+ _requestCookieMap = null;
+ _requestHeaderMap = null;
+ _requestHeaderValuesMap = null;
+ _requestMap = null;
+ _requestParameterMap = null;
+ _requestParameterValuesMap = null;
+ }
+
+ @Override
+ public Map<String, Object> getRequestCookieMap()
+ {
+ _checkRequest();
+ if (_requestCookieMap == null)
+ {
+
+ _requestCookieMap = new ServletCookieMap(_getHttpServletRequest());
+ }
+ return _requestCookieMap;
+ }
+
+ @Override
+ public Map<String, String> getRequestHeaderMap()
+ {
+ if (_requestHeaderMap == null)
+ {
+ _requestHeaderMap = new ServletRequestHeaderMap(_getHttpServletRequest());
+ }
+ return _requestHeaderMap;
+ }
+
+ @Override
+ public Map<String, String[]> getRequestHeaderValuesMap()
+ {
+ if (_requestHeaderMap == null)
+ {
+ _requestHeaderValuesMap = new ServletRequestHeaderValuesMap(_getHttpServletRequest());
+ }
+ return _requestHeaderValuesMap;
+ }
+
+ @Override
+ public Map<String, Object> getRequestMap()
+ {
+ _checkRequest();
+ if (_requestMap == null)
+ {
+ _requestMap = new ServletRequestMap((ServletRequest)getRequest());
+ }
+ return _requestMap;
+ }
+
+ @Override
+ public Map<String, String> getRequestParameterMap()
+ {
+ _checkRequest();
+ if (_requestParameterMap == null)
+ {
+ _requestParameterMap = new ServletRequestParameterMap((ServletRequest)getRequest());
+ }
+ return _requestParameterMap;
+ }
+
+ @Override
+ public Map<String, String[]> getRequestParameterValuesMap()
+ {
+ _checkRequest();
+ if (_requestParameterValuesMap == null)
+ {
+ _requestParameterValuesMap = new ServletRequestParameterValuesMap((ServletRequest)getRequest());
+ }
+ return _requestParameterValuesMap;
+ }
+
+ private void _checkRequest()
+ {
+ if(super.getRequest() == null)
+ {
+ throw new UnsupportedOperationException("Request is null on this context.");
+ }
+ }
+
+ private HttpServletRequest _getHttpServletRequest()
+ {
+ _checkRequest();
+ if ( !(getRequest() instanceof HttpServletRequest))
+ {
+ throw new IllegalArgumentException("Only HttpServletRequest supported");
+ }
+
+ return (HttpServletRequest)getRequest();
+ }
+ }
+
+ // This is a PortletExternalContext decorator that allows the getting
+ // and setting of the Trinidad Portal wrapper classes. It does this
+ // by automatically using the PortletContextWrapper for purposes of
+ // request dispatch.
+ static private class WrapperCompatibleExternalContext extends ExternalContextDecorator
+ {
+ private ExternalContext _ec;
+ private PortletContextWrapper _context;
+
+ public WrapperCompatibleExternalContext(ExternalContext ec)
+ {
+ _ec = ec;
+ }
+
+ protected ExternalContext getExternalContext()
+ {
+ return _ec;
+ }
+
+ @Override
+ public void setRequest(Object request)
+ {
+ if(_context == null)
+ {
+ if(request instanceof PortletRequestWrapper)
+ {
+ _context = new PortletContextWrapper((PortletContext)getExternalContext().getContext());
+ }
+ }
+
+ super.setRequest(request);
+ }
+
+ @Override
+ public void setResponse(Object response)
+ {
+ if(_context == null)
+ {
+ if(response instanceof PortletResponseWrapper)
+ {
+ _context = new PortletContextWrapper((PortletContext)getExternalContext().getContext());
+ }
+ }
+
+ super.setResponse(response);
+ }
+
+ @Override
+ public Object getContext()
+ {
+ if(_context != null)
+ {
+ return _context;
+ }
+
+ return super.getContext();
+ }
+
+ @Override
+ public void dispatch(String path)
+ throws IOException
+ {
+ if(_context != null)
+ {
+ final PortletRequestDispatcher requestDispatcher =
+ _context.getRequestDispatcher(path);
+ try
+ {
+ requestDispatcher.include((RenderRequest)getRequest(), (RenderResponse)getResponse());
+ }
+ catch (final PortletException e)
+ {
+ if (e.getMessage() != null)
+ {
+ throw new FacesException(e.getMessage(), e);
+ }
+ else
+ {
+ throw new FacesException(e);
+ }
+ }
+ }
+ else
+ {
+ getExternalContext().dispatch(path);
+ }
+ }
+ }
+
+ private static boolean _setRequestBugTested = false;
+ private static boolean _hasSetRequestBug = false;
+
+ private boolean _initialized;
+ private List<Configurator> _services;
+ static private final Map<ClassLoader, GlobalConfiguratorImpl> _CONFIGURATORS = new HashMap<ClassLoader, GlobalConfiguratorImpl>();
+ static private final String _IN_REQUEST = GlobalConfiguratorImpl.class
+ .getName()
+ + ".IN_REQUEST";
+
+ static private final TrinidadLogger _LOG = TrinidadLogger
+ .createTrinidadLogger(GlobalConfiguratorImpl.class);
+
+ private enum RequestType
+ {
+ PORTAL_ACTION,
+ PORTAL_RENDER,
+ SERVLET;
+
+ public static void clearType(final ExternalContext ec)
+ {
+ ec.getRequestMap().remove(_REQUEST_TYPE);
+ }
+
+ public static RequestType getType(final ExternalContext ec)
+ {
+ return (RequestType) ec.getRequestMap().get(_REQUEST_TYPE);
+ }
+
+ public static boolean isCorrectType(final ExternalContext ec)
+ {
+ return _findType(ec) == getType(ec);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void setType(final ExternalContext ec)
+ {
+ ec.getRequestMap().put(_REQUEST_TYPE, _findType(ec));
+ }
+
+ private static final RequestType _findType(final ExternalContext ec)
+ {
+ if (ExternalContextUtils.isPortlet(ec))
+ {
+ if (ExternalContextUtils.isAction(ec))
+ {
+ return PORTAL_ACTION;
+ }
+ else
+ {
+ return PORTAL_RENDER;
+ }
+ }
+ else
+ {
+ return SERVLET;
+ }
+ }
+
+ static private final String _REQUEST_TYPE = GlobalConfiguratorImpl.class.getName()
+ + ".REQUEST_TYPE";
+ }
+
+ static private class TestRequest extends ServletRequestWrapper
+ {
+ public TestRequest(ServletRequest request)
+ {
+ super(request);
+ }
+
+ @Override
+ public String getParameter(String string)
+ {
+ if(_TEST_PARAM.equals(string))
+ {
+ return "passed";
+ }
+
+ return super.getParameter(string);
+ }
+
+ static public final boolean isTestParamPresent(ExternalContext ec)
+ {
+ return ec.getRequestParameterMap().get(_TEST_PARAM) != null;
+ }
+
+ static private String _TEST_PARAM = TestRequest.class.getName()+".TEST_PARAM";
+ }
+}
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java Tue Feb 13 14:47:45 2007
@@ -29,7 +29,6 @@
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import javax.servlet.ServletResponse;
import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
@@ -49,28 +48,23 @@
@Override
public ExternalContext getExternalContext(ExternalContext externalContext)
{
- // TODO sobryan (dependency = JSF 1.2)
- // For JSF 1.2, we can probably simply wrap the request objects and set them on
- // the existing ExternalContext.
- if(!isApplied(externalContext))
{
if(ExternalContextUtils.isPortlet(externalContext))
{
if(!ExternalContextUtils.isAction(externalContext))
{
- apply(externalContext);
- return new PortletExternalContext(externalContext);
+ externalContext.setResponse(new DispatchRenderResponse(externalContext));
}
}
else
{
- apply(externalContext);
- return new ServletExternalContext(externalContext);
+ externalContext.setResponse(new DispatchServletResponse(externalContext));
}
- }
+ apply(externalContext);
+ }
- //return the origional
+ //return the original
return externalContext;
}
@@ -80,104 +74,6 @@
{
Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
return (String) requestMap.get(__CONTENT_TYPE_KEY);
- }
-
- private class ServletExternalContext extends ExternalContextDecorator
- {
- public ServletExternalContext(ExternalContext ec)
- {
- _ec = ec;
- }
-
- @Override
- public Object getResponse()
- {
- if(_response == null)
- {
- _response = new DispatchServletResponse(_ec);
- }
-
- return _response;
- }
-
- @Override
- protected ExternalContext getExternalContext()
- {
- return _ec;
- }
-
- private ServletResponse _response;
- private ExternalContext _ec;
- }
-
- private class PortletExternalContext extends ExternalContextDecorator
- {
- public PortletExternalContext(ExternalContext ec)
- {
- _ec = ec;
- }
-
- @Override
- public Object getContext()
- {
- return _getPortletContext();
- }
-
- @Override
- public Object getResponse()
- {
- return _getRenderResponse();
- }
-
- @Override
- public void dispatch(String path) throws IOException
- {
- final PortletRequestDispatcher requestDispatcher =
- ((PortletContext)getContext()).getRequestDispatcher(path);
- try
- {
- requestDispatcher.include((RenderRequest)getRequest(), (RenderResponse)getResponse());
- }
- catch (final PortletException e)
- {
- if (e.getMessage() != null)
- {
- throw new FacesException(e.getMessage(), e);
- }
- else
- {
- throw new FacesException(e);
- }
- }
- }
-
- @Override
- protected ExternalContext getExternalContext()
- {
- return _ec;
- }
-
- private PortletContext _getPortletContext()
- {
- if(_context == null)
- {
- _context = new PortletContextWrapper((PortletContext)_ec.getContext());
- }
- return _context;
- }
-
- private RenderResponse _getRenderResponse()
- {
- if(_response == null)
- {
- _response = new DispatchRenderResponse(_ec);
- }
- return _response;
- }
-
- private ExternalContext _ec;
- private RenderResponse _response;
- private PortletContext _context;
}
/**
Added: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java?view=auto&rev=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java (added)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java Tue Feb 13 14:47:45 2007
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.UnsupportedEncodingException;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.ActionRequestWrapper;
+
+public class ActionUploadRequestWrapper
+ extends ActionRequestWrapper
+{
+ public ActionUploadRequestWrapper(
+ ExternalContext ec,
+ Map<String, String[]> params)
+ {
+ super((ActionRequest)ec.getRequest());
+ _response = (ActionResponse)ec.getResponse();
+
+ @SuppressWarnings("unchecked")
+ Map<String, String[]> origionalMap = super.getParameterMap();
+
+ _extractedParams = new HashMap<String, String[]>(origionalMap);
+ _extractedParams.putAll(params);
+
+ //add these params to the render request
+ _response.setRenderParameters(_extractedParams);
+ }
+
+ /**
+ * Hide the content type so that no one tries to re-download the
+ * uploaded files.
+ */
+ @Override
+ public String getContentType()
+ {
+ return _WWW_FORM_URLENCODED_TYPE;
+ }
+
+ /**
+ * Trap calls to setCharacterEncoding() to decode parameters correctly
+ */
+ @Override
+ public void setCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException
+ {
+ super.setCharacterEncoding(encoding);
+ if (_LOG.isFine())
+ _LOG.fine("Switching encoding of wrapper to " + encoding);
+
+ _extractedAndDecodedParams =
+ new HashMap<String, String[]>(_extractedParams.size());
+
+ byte[] buffer = new byte[256];
+
+ for(Map.Entry<String, String[]> entry : _extractedParams.entrySet())
+ {
+ String key = entry.getKey();
+ key = CaboHttpUtils.decodeRequestParameter(key, encoding, buffer);
+
+ String[] oldValue = entry.getValue();
+ int length = oldValue.length;
+ String[] newValue = new String[length];
+ for (int i = 0; i < length; i++)
+ {
+ newValue[i] = CaboHttpUtils.decodeRequestParameter(oldValue[i],
+ encoding,
+ buffer);
+ if (_LOG.isFinest())
+ _LOG.finest("Parameter " + key + ":" + newValue[i]);
+ }
+
+ _extractedAndDecodedParams.put(key, newValue);
+ _response.setRenderParameters(_extractedAndDecodedParams);
+ }
+
+ // Let the UploadedFiles know, so it can fix up filenames
+ UploadedFiles.setCharacterEncoding(this, encoding);
+ }
+
+ @Override
+ public String getParameter(String param)
+ {
+ String[] value = _getParameterValues(param);
+ if (value == null)
+ return null;
+
+ return value[0];
+ }
+
+ @Override
+ public Map<String, String[]> getParameterMap()
+ {
+ Map<String, String[]> map = _getMap();
+ return Collections.unmodifiableMap(map);
+ }
+
+ @Override
+ public Enumeration<String> getParameterNames()
+ {
+ return Collections.enumeration(_getMap().keySet());
+ }
+
+ @Override
+ public String[] getParameterValues(String param)
+ {
+ String[] value = _getParameterValues(param);
+ if (value == null)
+ return null;
+
+ return (String[]) value.clone();
+ }
+
+ private String[] _getParameterValues(String param)
+ {
+ return _getMap().get(param);
+ }
+
+ /**
+ * Get the correct map of parameters whether or not setCharacterEncoding()
+ * was called.
+ */
+ private Map<String, String[]> _getMap()
+ {
+ if (_extractedAndDecodedParams != null)
+ return _extractedAndDecodedParams;
+
+ return _extractedParams;
+ }
+
+ private Map<String, String[]> _extractedAndDecodedParams;
+ private Map<String, String[]> _extractedParams;
+ private ActionResponse _response;
+ private static final String _WWW_FORM_URLENCODED_TYPE =
+ "application/x-www-form-urlencoded";
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(ActionUploadRequestWrapper.class);
+}
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java Tue Feb 13 14:47:45 2007
@@ -1,285 +1,296 @@
-/*
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.trinidadinternal.config.upload;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.myfaces.trinidad.config.Configurator;
-import org.apache.myfaces.trinidad.context.RequestContext;
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidad.model.UploadedFile;
-import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
-import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
-import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
-
-/**
- * This configurator will handle the FileUploads for Trinidad.
- *
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public class FileUploadConfiguratorImpl extends Configurator
-{
-
- /**
- * Returns the added parameters
- *
- * @param externalContext
- * @return
- */
- static public Map<String, String[]> getAddedParameters(ExternalContext externalContext)
- {
- @SuppressWarnings("unchecked")
- Map<String, String[]> map = (Map<String, String[]>) externalContext.getRequestMap().get(_PARAMS);
-
- return map;
- }
-
- /**
- * Returns <code>true</code> if the request wrapper has been applied.
- *
- * @param context
- * @return
- */
- static public boolean isApplied(ExternalContext context)
- {
- return (context.getRequestMap().get(_APPLIED)!=null);
- }
-
- /**
- *
- */
- @SuppressWarnings("unchecked")
- static public void apply(ExternalContext context)
- {
- context.getRequestMap().put(_APPLIED, Boolean.TRUE);
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
- */
- @Override
- @SuppressWarnings("unchecked")
- public void beginRequest(ExternalContext externalContext)
- {
- /*
- * Note: This class does not do a dispose on the file uploads. The
- * reason for this is that in a portal environment, multiple render-requests
- * may depend on the same set of files being available to the view layer.
- * Instead the files will be automatically cleaned up when the portlet
- * generated the next request. If we need to clean up sooner then we should
- * clean up on the end-request.
- */
- // FIXME AdamWiner We should clean up ASAP - these are potentially very
- // large allocations of memory and file, so cleaning up as soon
- // as possible is a good thing
- //Process MultipartForm if need be
- if (MultipartFormHandler.isMultipartRequest(externalContext) &&
- (externalContext.getRequest() instanceof HttpServletRequest ||
- ExternalContextUtils.isPortlet(externalContext)))
- {
- try
- {
- final MultipartFormHandler mfh = new MultipartFormHandler(externalContext);
-
- // TODO: How is this set?
- // AdamWiner: looks like the previous Trinidad incarnation
- // of this code didn't have any allowed configuration...
- mfh.setMaximumAllowedBytes(_maxAllowedBytes);
- mfh.setCharacterEncoding(ExternalContextUtils.getCharacterEncoding(externalContext));
-
- final HashMap<String, String[]> parameters = new HashMap<String, String[]>();
- MultipartFormItem item;
- final UploadedFiles files = new UploadedFiles(externalContext);
- while ((item = mfh.getNextPart()) != null)
- {
- final String name = item.getName();
- String value = null;
- // No filename - it's not a file uploaded field
- if (item.getFilename() == null)
- {
- value = item.getValue();
- final Object oldValue = parameters.get(name);
- if (oldValue == null)
- {
- parameters.put(name, new String[]{value});
- }
- else
- {
- final String[] oldArray = (String[]) oldValue;
- final String[] newArray = new String[oldArray.length + 1];
- System.arraycopy(oldArray, 0, newArray, 1, oldArray.length);
- newArray[0] = value;
- parameters.put(name, newArray);
- }
- }
- // Upload a file
- else if (item.getFilename().length() > 0)
- {
- _doUploadFile(RequestContext.getCurrentInstance(), externalContext, files, item);
- }
- }
- externalContext.getRequestMap().put(_PARAMS, parameters);
- }
- catch (Throwable t)
- {
- if(_LOG.isSevere())
- {
- _LOG.severe(t);
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#getExternalContext(javax.faces.context.ExternalContext)
- */
- @Override
- public ExternalContext getExternalContext(ExternalContext externalContext)
- {
- //Wrap only if there are parameters present
- Map<String, String[]> addedParams = getAddedParameters(externalContext);
-
- if(addedParams != null)
- {
- @SuppressWarnings("unchecked")
- Map<String, String[]> parameters = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
- parameters.putAll(addedParams);
-
- // TODO sobryan (dependency = JSF 1.2)
- // For JSF 1.2, we can probably simply wrap the request objects and set them on
- // the existing ExternalContext.
- return _getExternalContextWrapper(externalContext, addedParams);
- }
-
- return externalContext;
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
- */
- @Override
- public void init(ExternalContext externalContext)
- {
- super.init(externalContext);
- //TODO initialize _maxAllowedBytes
- }
-
- private void _doUploadFile(
- final RequestContext context,
- final ExternalContext externalContext,
- final UploadedFiles files,
- final MultipartFormItem item) throws IOException
- {
- final UploadedFile temp = new TempUploadedFile(item);
-
- final UploadedFile file =
- context.getUploadedFileProcessor().processFile(externalContext.getRequest(), temp);
-
- if (file != null)
- {
- // Store the file.
- files.__put(item.getName(), file);
-
- if (_LOG.isFine())
- {
- _LOG.fine("Uploaded file " + file.getFilename() + "(" +
- file.getLength() + " bytes) for ID " + item.getName());
- }
- }
- }
-
- static private ExternalContext _getExternalContextWrapper(ExternalContext externalContext, Map<String, String[]> addedParams)
- {
- if(!isApplied(externalContext))
- {
- if(!ExternalContextUtils.isPortlet(externalContext))
- {
- return new ServletUploadedExternalContext(externalContext, addedParams);
- }
- else if(ExternalContextUtils.isAction(externalContext))
- {
- /*
- * We only need to do this if we have an action request. Why?
- * Because durring the ActionRequest, the wrapper will set the
- * RenderParameters. This is a cool thing because subsequent
- * render requests will retain these parameters for us.
- */
- return new PortletUploadedExternalContext(externalContext, addedParams);
- }
- }
-
- //If we don't have any wrapped params or we have a render portal request,
- //return the origional external context
- return externalContext;
- }
-
- static private class TempUploadedFile implements UploadedFile
- {
- public TempUploadedFile(MultipartFormItem item)
- {
- _item = item;
- assert(item.getValue() == null);
- }
-
- public String getFilename()
- {
- return _item.getFilename();
- }
-
- public String getContentType()
- {
- return _item.getContentType();
- }
-
- public long getLength()
- {
- // The length is not known yet.
- return -1L;
- }
-
- public Object getOpaqueData()
- {
- return null;
- }
-
- public InputStream getInputStream() throws IOException
- {
- return _item.getInputStream();
- }
-
- public void dispose()
- {
- throw new UnsupportedOperationException();
- }
-
- private MultipartFormItem _item;
- }
- static private final String _APPLIED = FileUploadConfiguratorImpl.class.getName()+".APPLIED";
- static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileUploadConfiguratorImpl.class);
- static public final String _PARAMS = FileUploadConfiguratorImpl.class.getName()+".PARAMS";
- private long _maxAllowedBytes = 1L << 27;
-}
+/*
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ActionRequest;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.config.Configurator;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.model.UploadedFile;
+import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
+import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
+import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
+
+/**
+ * This configurator will handle the FileUploads for Trinidad.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FileUploadConfiguratorImpl extends Configurator
+{
+
+ /**
+ * Returns the added parameters
+ *
+ * @param externalContext
+ * @return
+ */
+ static public Map<String, String[]> getAddedParameters(ExternalContext externalContext)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, String[]> map = (Map<String, String[]>) externalContext.getRequestMap().get(_PARAMS);
+
+ return map;
+ }
+
+ /**
+ * Returns <code>true</code> if the request wrapper has been applied.
+ *
+ * @param context
+ * @return
+ */
+ static public boolean isApplied(ExternalContext context)
+ {
+ return (context.getRequestMap().get(_APPLIED)!=null);
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("unchecked")
+ static public void apply(ExternalContext context)
+ {
+ context.getRequestMap().put(_APPLIED, Boolean.TRUE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void beginRequest(ExternalContext externalContext)
+ {
+ /*
+ * Note: This class does not do a dispose on the file uploads. The
+ * reason for this is that in a portal environment, multiple render-requests
+ * may depend on the same set of files being available to the view layer.
+ * Instead the files will be automatically cleaned up when the portlet
+ * generated the next request. If we need to clean up sooner then we should
+ * clean up on the end-request.
+ */
+ // FIXME AdamWiner We should clean up ASAP - these are potentially very
+ // large allocations of memory and file, so cleaning up as soon
+ // as possible is a good thing
+ //Process MultipartForm if need be
+ if (MultipartFormHandler.isMultipartRequest(externalContext) &&
+ (externalContext.getRequest() instanceof HttpServletRequest ||
+ ExternalContextUtils.isPortlet(externalContext)))
+ {
+ try
+ {
+ final MultipartFormHandler mfh = new MultipartFormHandler(externalContext);
+
+ // TODO: How is this set?
+ // AdamWiner: looks like the previous Trinidad incarnation
+ // of this code didn't have any allowed configuration...
+ mfh.setMaximumAllowedBytes(_maxAllowedBytes);
+ mfh.setCharacterEncoding(ExternalContextUtils.getCharacterEncoding(externalContext));
+
+ final HashMap<String, String[]> parameters = new HashMap<String, String[]>();
+ MultipartFormItem item;
+ final UploadedFiles files = new UploadedFiles(externalContext);
+ while ((item = mfh.getNextPart()) != null)
+ {
+ final String name = item.getName();
+ String value = null;
+ // No filename - it's not a file uploaded field
+ if (item.getFilename() == null)
+ {
+ value = item.getValue();
+ final Object oldValue = parameters.get(name);
+ if (oldValue == null)
+ {
+ parameters.put(name, new String[]{value});
+ }
+ else
+ {
+ final String[] oldArray = (String[]) oldValue;
+ final String[] newArray = new String[oldArray.length + 1];
+ System.arraycopy(oldArray, 0, newArray, 1, oldArray.length);
+ newArray[0] = value;
+ parameters.put(name, newArray);
+ }
+ }
+ // Upload a file
+ else if (item.getFilename().length() > 0)
+ {
+ _doUploadFile(RequestContext.getCurrentInstance(), externalContext, files, item);
+ }
+ }
+ externalContext.getRequestMap().put(_PARAMS, parameters);
+ }
+ catch (Throwable t)
+ {
+ if(_LOG.isSevere())
+ {
+ _LOG.severe(t);
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.myfaces.trinidad.config.Configurator#getExternalContext(javax.faces.context.ExternalContext)
+ */
+ @Override
+ public ExternalContext getExternalContext(ExternalContext externalContext)
+ {
+ //Wrap only if there are parameters present
+ Map<String, String[]> addedParams = getAddedParameters(externalContext);
+
+ if(addedParams != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, String[]> parameters = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+ parameters.putAll(addedParams);
+
+ // TODO sobryan (dependency = JSF 1.2)
+ // For JSF 1.2, we can probably simply wrap the request objects and set them on
+ // the existing ExternalContext.
+ return _getExternalContextWrapper(externalContext, addedParams);
+ }
+
+ return externalContext;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
+ */
+ @Override
+ public void init(ExternalContext externalContext)
+ {
+ super.init(externalContext);
+ //TODO initialize _maxAllowedBytes
+ }
+
+ private void _doUploadFile(
+ final RequestContext context,
+ final ExternalContext externalContext,
+ final UploadedFiles files,
+ final MultipartFormItem item) throws IOException
+ {
+ final UploadedFile temp = new TempUploadedFile(item);
+
+ final UploadedFile file =
+ context.getUploadedFileProcessor().processFile(externalContext.getRequest(), temp);
+
+ if (file != null)
+ {
+ // Store the file.
+ files.__put(item.getName(), file);
+
+ if (_LOG.isFine())
+ {
+ _LOG.fine("Uploaded file " + file.getFilename() + "(" +
+ file.getLength() + " bytes) for ID " + item.getName());
+ }
+ }
+ }
+
+ static private ExternalContext _getExternalContextWrapper(ExternalContext externalContext, Map<String, String[]> addedParams)
+ {
+ if(!isApplied(externalContext))
+ {
+ Map<String, String[]> params = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+ params.putAll(addedParams);
+
+ if(!ExternalContextUtils.isPortlet(externalContext))
+ {
+ externalContext.setRequest(new UploadRequestWrapper(
+ (HttpServletRequest)externalContext.getRequest(),
+ params));
+ }
+ else if(ExternalContextUtils.isAction(externalContext))
+ {
+ /*
+ * We only need to do this if we have an action request. Why?
+ * Because durring the ActionRequest, the wrapper will set the
+ * RenderParameters. This is a cool thing because subsequent
+ * render requests will retain these parameters for us.
+ */
+ externalContext.setRequest(new ActionUploadRequestWrapper(externalContext,
+ params));
+ }
+ apply(externalContext);
+ }
+
+ //If we don't have any wrapped params or we have a render portal request,
+ //return the origional external context
+ return externalContext;
+ }
+
+ static private class TempUploadedFile implements UploadedFile
+ {
+ public TempUploadedFile(MultipartFormItem item)
+ {
+ _item = item;
+ assert(item.getValue() == null);
+ }
+
+ public String getFilename()
+ {
+ return _item.getFilename();
+ }
+
+ public String getContentType()
+ {
+ return _item.getContentType();
+ }
+
+ public long getLength()
+ {
+ // The length is not known yet.
+ return -1L;
+ }
+
+ public Object getOpaqueData()
+ {
+ return null;
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ return _item.getInputStream();
+ }
+
+ public void dispose()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ private MultipartFormItem _item;
+ }
+ static private final String _APPLIED = FileUploadConfiguratorImpl.class.getName()+".APPLIED";
+ static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileUploadConfiguratorImpl.class);
+ static public final String _PARAMS = FileUploadConfiguratorImpl.class.getName()+".PARAMS";
+ private long _maxAllowedBytes = 1L << 27;
+}
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java Tue Feb 13 14:47:45 2007
@@ -30,9 +30,9 @@
* @author Anton Koinov
* @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
*/
-class ServletCookieMap extends AbstractAttributeMap<String, Object>
+public class ServletCookieMap extends AbstractAttributeMap<String, Object>
{
- ServletCookieMap(final HttpServletRequest httpServletRequest)
+ public ServletCookieMap(final HttpServletRequest httpServletRequest)
{
_httpServletRequest = httpServletRequest;
}
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java Tue Feb 13 14:47:45 2007
@@ -28,9 +28,9 @@
* @author Anton Koinov (latest modification by $Author: oros $)
* @version $Revision: 278654 $ $Date: 2005-09-04 18:32:35 -0600 (Sun, 04 Sep 2005) $
*/
-class ServletRequestHeaderMap extends AbstractAttributeMap<String, String>
+public class ServletRequestHeaderMap extends AbstractAttributeMap<String, String>
{
- ServletRequestHeaderMap(final HttpServletRequest httpServletRequest)
+ public ServletRequestHeaderMap(final HttpServletRequest httpServletRequest)
{
_httpServletRequest = httpServletRequest;
}
Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java?view=diff&rev=507278&r1=507277&r2=507278
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java Tue Feb 13 14:47:45 2007
@@ -1,85 +1,85 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.trinidadinternal.context.external;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-
-/**
- * HttpServletRequest header values (multi-value headers) as Map of String[].
- *
- * @author Anton Koinov (latest modification by $Author: matze $)
- * @version $Revision: 167257 $ $Date: 2004-10-13 05:51:02 -0600 (Wed, 13 Oct 2004) $
- */
-class ServletRequestHeaderValuesMap extends AbstractAttributeMap<String, String[]>
-{
- ServletRequestHeaderValuesMap(final HttpServletRequest httpServletRequest)
- {
- _httpServletRequest = httpServletRequest;
- }
-
- @Override
- protected String[] getAttribute(final Object key)
- {
- if (key.toString().equals(key))
- {
- final String k = key.toString();
- String[] ret = _valueCache.get(k);
- if (ret == null)
- {
- @SuppressWarnings("unchecked")
- final Enumeration<String> headers = _httpServletRequest.getHeaders(k);
- ret = _toArray(headers);
- _valueCache.put(k, ret);
- }
-
- return ret;
- }
- return null;
- }
-
- @Override
- protected Enumeration<String> getAttributeNames()
- {
- @SuppressWarnings("unchecked")
- Enumeration<String> headerNames = _httpServletRequest.getHeaderNames();
- return headerNames;
- }
-
- private String[] _toArray(final Enumeration<String> e)
- {
- final List<String> ret = new ArrayList<String>();
-
- while (e.hasMoreElements())
- {
- ret.add(e.nextElement());
- }
-
- return ret.toArray(new String[ret.size()]);
- }
-
- private final HttpServletRequest _httpServletRequest;
- private final Map<String, String[]> _valueCache = new HashMap<String, String[]>();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidadinternal.context.external;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * HttpServletRequest header values (multi-value headers) as Map of String[].
+ *
+ * @author Anton Koinov (latest modification by $Author: matze $)
+ * @version $Revision: 167257 $ $Date: 2004-10-13 05:51:02 -0600 (Wed, 13 Oct 2004) $
+ */
+public class ServletRequestHeaderValuesMap extends AbstractAttributeMap<String, String[]>
+{
+ public ServletRequestHeaderValuesMap(final HttpServletRequest httpServletRequest)
+ {
+ _httpServletRequest = httpServletRequest;
+ }
+
+ @Override
+ protected String[] getAttribute(final Object key)
+ {
+ if (key.toString().equals(key))
+ {
+ final String k = key.toString();
+ String[] ret = _valueCache.get(k);
+ if (ret == null)
+ {
+ @SuppressWarnings("unchecked")
+ final Enumeration<String> headers = _httpServletRequest.getHeaders(k);
+ ret = _toArray(headers);
+ _valueCache.put(k, ret);
+ }
+
+ return ret;
+ }
+ return null;
+ }
+
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> headerNames = _httpServletRequest.getHeaderNames();
+ return headerNames;
+ }
+
+ private String[] _toArray(final Enumeration<String> e)
+ {
+ final List<String> ret = new ArrayList<String>();
+
+ while (e.hasMoreElements())
+ {
+ ret.add(e.nextElement());
+ }
+
+ return ret.toArray(new String[ret.size()]);
+ }
+
+ private final HttpServletRequest _httpServletRequest;
+ private final Map<String, String[]> _valueCache = new HashMap<String, String[]>();
+}