You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2009/05/11 20:32:46 UTC
svn commit: r773647 [2/2] - in /myfaces/trinidad/trunk: ./
trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/
trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/
trinidad-examples/ trinidad-examples/trinidad-demo/ trinidad-exampl...
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java Mon May 11 18:32:44 2009
@@ -18,14 +18,13 @@
*/
package org.apache.myfaces.trinidadinternal.config.dispatch;
-import java.util.Map;
-
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.util.ExternalContextUtils;
import org.apache.myfaces.trinidad.util.RequestStateMap;
+import org.apache.myfaces.trinidad.util.RequestType;
/**
* TODO: Document this
@@ -41,18 +40,27 @@
{
if(!isApplied(externalContext))
{
- if(ExternalContextUtils.isPortlet(externalContext))
- {
- if(!ExternalContextUtils.isAction(externalContext))
- {
- externalContext.setResponse(new DispatchRenderResponse(externalContext));
- }
- }
- else
+ RequestType type = ExternalContextUtils.getRequestType(externalContext);
+
+ switch(type)
{
- externalContext.setResponse(new DispatchServletResponse(externalContext));
+ case RESOURCE:
+ externalContext.setResponse(new DispatchResourceResponse(externalContext));
+ break;
+ case SERVLET:
+ externalContext.setResponse(new DispatchServletResponse(externalContext));
+ break;
+ case RENDER:
+ //Are we in a portlet 2.0 container? If we are not there is no need to provide a
+ //wrapper. This confgigurator is intended to work around an issue with WLS where
+ //the content type is reset durring a forward. In Portlet 1.0, the bridge performs
+ //an inlcude rather then a forward.
+ if(_PORTLET2)
+ {
+ //spec is Portlet 2.0 or above. Use the real wrappers
+ externalContext.setResponse(new DispatchRenderResponse(externalContext));
+ }
}
-
apply(externalContext);
}
@@ -66,7 +74,7 @@
{
return (String) RequestStateMap.getInstance(context.getExternalContext()).get(__CONTENT_TYPE_KEY);
}
-
+
/**
* Returns <code>true</code> if the request wrapper has been applied.
*
@@ -89,6 +97,7 @@
static private final String _APPLIED =
DispatchResponseConfiguratorImpl.class.getName()+".APPLIED";
+ static private final boolean _PORTLET2 = ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE);
static final String __CONTENT_TYPE_KEY =
DispatchResponseConfiguratorImpl.class.getName() + ".CONTENT_TYPE";
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java Mon May 11 18:32:44 2009
@@ -18,9 +18,6 @@
*/
package org.apache.myfaces.trinidadinternal.config.dispatch;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -39,45 +36,21 @@
public void setContentType(
String contentTypeAndCharset)
{
+ ContentTypeAndCharacterSet ct = new ContentTypeAndCharacterSet(contentTypeAndCharset);
+
// Ignore all calls to setContentType() if they come in the scope
// of a Servlet include (generally a jsp:include). The JSP
// engine will ignore them, and in a .jspx, the default contentType
// is text/xml! So as a result, the absence of a contentType
// in included jspx files was sometimes leading us to turn on
// XHTML!
- if ((_request.getAttribute("javax.servlet.include.request_uri") == null) &&
- (contentTypeAndCharset != null))
+ if((_request.getAttribute("javax.servlet.include.request_uri")) == null && (ct.getContentType() != null))
{
- Matcher matcher = _CONTENT_TYPE_PATTERN.matcher(contentTypeAndCharset);
- if (matcher.matches())
- {
- String contentType = matcher.group(1);
- String charset = (matcher.groupCount() > 1) ? matcher.group(2) : null;
-
- // capture the content type on the request
- _request.setAttribute(DispatchResponseConfiguratorImpl.__CONTENT_TYPE_KEY, contentType);
-
- // TODO: use Agent APIs when available
- if ("application/xhtml+xml".equals(contentType))
- {
- String userAgent = _request.getHeader("User-agent");
- if (userAgent.indexOf("compatible; MSIE") != -1)
- {
- // IE must serve XHTML as text/html
- contentTypeAndCharset = "text/html";
-
- if (charset != null)
- contentTypeAndCharset += ";charset=" + charset;
- }
- }
- }
+ _request.setAttribute(DispatchResponseConfiguratorImpl.__CONTENT_TYPE_KEY, ct.getContentType());
}
- super.setContentType(contentTypeAndCharset);
+
+ super.setContentType(ct.toString());
}
private final HttpServletRequest _request;
-
-
- static private final Pattern _CONTENT_TYPE_PATTERN =
- Pattern.compile("([^;]+)(?:;charset=(.*))?");
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java Mon May 11 18:32:44 2009
@@ -21,6 +21,9 @@
import java.io.IOException;
import java.io.InputStream;
+
+import java.lang.reflect.Proxy;
+
import java.util.HashMap;
import java.util.Map;
@@ -34,8 +37,10 @@
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.trinidad.util.ClassLoaderUtils;
import org.apache.myfaces.trinidad.util.ExternalContextUtils;
import org.apache.myfaces.trinidad.util.RequestStateMap;
+import org.apache.myfaces.trinidad.util.RequestType;
import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
@@ -226,22 +231,32 @@
{
if(!isApplied(externalContext))
{
- if(!ExternalContextUtils.isPortlet(externalContext))
- {
- externalContext.setRequest(new UploadRequestWrapper(
- (HttpServletRequest)externalContext.getRequest(),
- addedParams));
- }
- else if(ExternalContextUtils.isAction(externalContext))
+ RequestType type = ExternalContextUtils.getRequestType(externalContext);
+
+ switch(type)
{
- /*
- * 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,
- addedParams));
+ case SERVLET:
+ externalContext.setRequest(new UploadRequestWrapper(externalContext, addedParams));
+ break;
+ case RESOURCE:
+ externalContext.setRequest(new UploadResourceRequest(externalContext, addedParams));
+ break;
+ case ACTION:
+ //Portlet 2.0 should use the framework provided wrapper. Portlet 1.0 needs to implement
+ //the interface. Because we need to compile against Portlet 2.0, we implement the Portlet
+ //1.0 scenario using a Proxy.
+ Object req;
+
+ if(_ENHANCED_PORTLET_SUPPORTED)
+ {
+ req = _getActionRequestWrapper(externalContext, addedParams);
+ }
+ else
+ {
+ req = _getActionRequestProxy(externalContext, addedParams);
+ }
+
+ externalContext.setRequest(req);
}
apply(externalContext);
}
@@ -251,6 +266,32 @@
return externalContext;
}
+ static private Object _getActionRequestProxy(ExternalContext ec, Map<String, String[]> params)
+ {
+ try
+ {
+ Class<?> actionRequestClass = ClassLoaderUtils.loadClass("javax.portlet.ActionRequest");
+ return Proxy.newProxyInstance(ClassLoaderUtils.getContextClassLoader(), new Class<?>[]{actionRequestClass}, new UploadActionInvocationHandler(ec, params));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static private Object _getActionRequestWrapper(ExternalContext ec, Map<String, String[]> params)
+ {
+ try
+ {
+ Class<?> wrapperClass = ClassLoaderUtils.loadClass("org.apache.myfaces.trinidadinternal.config.upload.UploadActionRequestWrapper");
+ return wrapperClass.getConstructor(ExternalContext.class, Map.class).newInstance(ec, params);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
//This will ensure the property is removed on the next request
@ExcludeFromManagedRequestScope
static private class AppliedClass
@@ -302,6 +343,7 @@
static private final String _APPLIED = FileUploadConfiguratorImpl.class.getName()+".APPLIED";
static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileUploadConfiguratorImpl.class);
static private final String _PARAMS = FileUploadConfiguratorImpl.class.getName()+".PARAMS";
+ static private final boolean _ENHANCED_PORTLET_SUPPORTED = ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE);
private long _maxAllowedBytes = 1L << 27;
}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionInvocationHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionInvocationHandler.java?rev=773647&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionInvocationHandler.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionInvocationHandler.java Mon May 11 18:32:44 2009
@@ -0,0 +1,112 @@
+/*
+ * 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.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.RenderRequest;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+class UploadActionInvocationHandler
+ implements InvocationHandler
+{
+ private Object _request;
+ private Object _response;
+ private UploadRequestManager _manager;
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(UploadActionInvocationHandler.class);
+
+ public UploadActionInvocationHandler(ExternalContext ec, Map<String, String[]> params)
+ {
+ _request = ec.getRequest();
+ _response = ec.getResponse();
+ _manager = new UploadRequestManager(ec, params);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable
+ {
+ String methodName = method.getName();
+ int paramCount = method.getParameterTypes().length;
+
+ switch(paramCount)
+ {
+ case 0:
+ if("getContentType".equals(methodName))
+ {
+ return _manager.getContentType();
+ }
+ else if ("getCharacterEncoding".equals(methodName))
+ {
+ return _manager.getCharacterEncoding();
+ }
+ else if("getParameterMap".equals(methodName))
+ {
+ return _manager.getParameterMap();
+ }
+
+ break;
+
+ case 1:
+ if("setCharacterEncoding".equals(methodName))
+ {
+ String encoding = (String)args[0];
+ //Don't do anything if we are trying to set the character encoding to what is already set
+ if (encoding.equals(_manager.getCharacterEncoding()))
+ {
+ return null;
+ }
+
+ // It is illegal to set the character encoding after parameters
+ // have been retrieved. This is an annoying restriction,
+ // but we shouldn't break it
+ if (_manager.isParameterRetrieved())
+ {
+ _LOG.warning("UNABLE_SET_REQUEST_CHARACTER", encoding);
+ return null;
+ }
+
+ _manager.setCharacterEncoding(encoding);
+
+ Method m = _response.getClass().getMethod("setRenderParameters", Map.class);
+ m.invoke(_response, _manager.getParameterMap());
+
+ // Let the UploadedFiles know, so it can fix up filenames
+ UploadedFiles.setCharacterEncoding((RenderRequest)_request, encoding);
+ return null;
+ }
+ else if("getParameterValues".equals(methodName))
+ {
+ return _manager.getParameterValues((String)args[0]);
+ }
+ else if("getParameter".equals(methodName))
+ {
+ return _manager.getParameter((String)args[0]);
+ }
+ }
+
+ return method.invoke(_request, args);
+ }
+}
Copied: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionRequestWrapper.java (from r762834, myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java)
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionRequestWrapper.java?p2=myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionRequestWrapper.java&p1=myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java&r1=762834&r2=773647&rev=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadActionRequestWrapper.java Mon May 11 18:32:44 2009
@@ -20,9 +20,7 @@
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;
@@ -30,27 +28,18 @@
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;
+import javax.portlet.filter.ActionRequestWrapper;
-public class ActionUploadRequestWrapper
+public class UploadActionRequestWrapper
extends ActionRequestWrapper
{
- public ActionUploadRequestWrapper(
+ public UploadActionRequestWrapper(
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);
-
- _encoding = super.getCharacterEncoding();
+ _manager = new UploadRequestManager(ec, params);
}
/**
@@ -60,16 +49,15 @@
@Override
public String getContentType()
{
- return _WWW_FORM_URLENCODED_TYPE;
+ return _manager.getContentType();
}
@Override
public String getCharacterEncoding()
{
- return _encoding;
+ return _manager.getCharacterEncoding();
}
-
/**
* Trap calls to setCharacterEncoding() to decode parameters correctly
*/
@@ -77,41 +65,13 @@
public void setCharacterEncoding(String encoding)
throws UnsupportedEncodingException
{
- // If the encoding is already right, we can bail
- if (encoding.equals(_encoding))
- return;
-
- // Don't call super.setCharacterEncoding() - it's too late
- // and we'll get a warning
- _encoding = 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())
+ if(getCharacterEncoding().equals(encoding))
{
- 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);
+ return;
}
+
+ _manager.setCharacterEncoding(encoding);
+ _response.setRenderParameters(_manager.getParameterMap());
// Let the UploadedFiles know, so it can fix up filenames
UploadedFiles.setCharacterEncoding(this, encoding);
@@ -120,59 +80,27 @@
@Override
public String getParameter(String param)
{
- String[] value = _getParameterValues(param);
- if (value == null)
- return null;
-
- return value[0];
+ return _manager.getParameter(param);
}
@Override
public Map<String, String[]> getParameterMap()
{
- Map<String, String[]> map = _getMap();
- return Collections.unmodifiableMap(map);
+ return _manager.getParameterMap();
}
@Override
public Enumeration<String> getParameterNames()
{
- return Collections.enumeration(_getMap().keySet());
+ return _manager.getParameterNames();
}
@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;
+ return _manager.getParameterValues(param);
}
- private Map<String, String[]> _extractedAndDecodedParams;
- private Map<String, String[]> _extractedParams;
+ private UploadRequestManager _manager;
private ActionResponse _response;
- private String _encoding;
- private static final String _WWW_FORM_URLENCODED_TYPE =
- "application/x-www-form-urlencoded";
- private static final TrinidadLogger _LOG =
- TrinidadLogger.createTrinidadLogger(ActionUploadRequestWrapper.class);
}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestManager.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestManager.java?rev=773647&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestManager.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestManager.java Mon May 11 18:32:44 2009
@@ -0,0 +1,195 @@
+/*
+ * 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.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+
+public class UploadRequestManager
+{
+ public UploadRequestManager(ExternalContext ec, Map<String, String[]> params)
+ {
+ _params = params;
+ setRequest(ec);
+ }
+
+ public UploadRequestManager(HttpServletRequest req, Map<String, String[]> params)
+ {
+ _params = params;
+ setRequest(req);
+ }
+
+ /**
+ * Hide the content type so that no one tries to re-download the
+ * uploaded files.
+ */
+ public String getContentType()
+ {
+ return _WWW_FORM_URLENCODED_TYPE;
+ }
+
+ public String getCharacterEncoding()
+ {
+ return _encoding;
+ }
+
+ /**
+ * Trap calls to setCharacterEncoding() to decode parameters correctly
+ */
+ public void setCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException
+ {
+ // If the encoding is already right, we can bail
+ if (encoding.equals(_encoding))
+ return;
+
+ // Don't call super.setCharacterEncoding() - it's too late
+ // and we'll get a warning
+ _encoding = encoding;
+
+ if (_LOG.isFine())
+ {
+ _LOG.fine("Switching encoding of wrapper to " + encoding);
+ }
+
+ Map<String, String[]>decodedParams = 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);
+ }
+ _extractedAndDecodedParams = Collections.unmodifiableMap(decodedParams);
+ }
+
+ public String getParameter(String param)
+ {
+ String[] value = _getParameterValues(param);
+ if (value == null)
+ return null;
+
+ return value[0];
+ }
+
+ public Map<String, String[]> getParameterMap()
+ {
+ // Mark that parameters have been retrieved so we
+ // can log a proper warning
+ _parametersRetrieved = true;
+
+ if(_extractedParams == null)
+ {
+ Map<String, String[]> m = new HashMap<String, String[]>(_requestParams);
+ m.putAll(_params);
+ _extractedParams = Collections.unmodifiableMap(m);
+ }
+
+ if (_extractedAndDecodedParams != null)
+ return _extractedAndDecodedParams;
+
+ return _extractedParams;
+ }
+
+ public Enumeration<String> getParameterNames()
+ {
+ return Collections.enumeration(getParameterMap().keySet());
+ }
+
+ public String[] getParameterValues(String param)
+ {
+ String[] value = _getParameterValues(param);
+
+ if (value == null)
+ return null;
+
+ return value.clone();
+ }
+
+ public boolean isParameterRetrieved()
+ {
+ return _parametersRetrieved;
+ }
+
+ public void setRequest(ExternalContext ec)
+ {
+ _clearMap();
+ _requestParams = ec.getRequestParameterValuesMap();
+ _encoding = ec.getRequestCharacterEncoding();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setRequest(HttpServletRequest req)
+ {
+ _clearMap();
+ _requestParams = req.getParameterMap();
+ _encoding = req.getCharacterEncoding();
+ }
+
+ private String[] _getParameterValues(String param)
+ {
+ return getParameterMap().get(param);
+ }
+
+ private void _clearMap()
+ {
+ _parametersRetrieved = false;
+ _extractedAndDecodedParams = null;
+ _extractedParams = null;
+ }
+
+ private boolean _parametersRetrieved = false;
+ private Map<String, String[]> _extractedAndDecodedParams;
+ private Map<String, String[]> _extractedParams;
+ private Map<String, String[]> _params;
+ private Map<String, String[]> _requestParams;
+ private String _encoding;
+
+ private static final String _WWW_FORM_URLENCODED_TYPE =
+ "application/x-www-form-urlencoded";
+
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(UploadRequestManager.class);
+}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java Mon May 11 18:32:44 2009
@@ -24,6 +24,10 @@
import java.util.HashMap;
import java.util.Map;
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ActionResponse;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
@@ -40,21 +44,19 @@
@SuppressWarnings("deprecation")
public class UploadRequestWrapper extends HttpServletRequestWrapper
{
- public UploadRequestWrapper(
- HttpServletRequest request,
- Map<String, String[]> params)
+ public UploadRequestWrapper(ExternalContext ec, Map<String, String[]> params)
{
- super(request);
+ this((HttpServletRequest) ec.getRequest(), params);
- @SuppressWarnings("unchecked")
- // Merge in all the original parameters
- Map<String, String[]> originalMap = super.getParameterMap();
-
- _extractedParams = new HashMap<String, String[]>(originalMap);
- _extractedParams.putAll(params);
- _encoding = super.getCharacterEncoding();
}
+ public UploadRequestWrapper(HttpServletRequest req, Map<String, String[]> params)
+ {
+ super(req);
+ _manager = new UploadRequestManager(req, params);
+
+ }
+
/**
* Hide the content type so that no one tries to re-download the
* uploaded files.
@@ -62,13 +64,13 @@
@Override
public String getContentType()
{
- return _WWW_FORM_URLENCODED_TYPE;
+ return _manager.getContentType();
}
@Override
public String getCharacterEncoding()
{
- return _encoding;
+ return _manager.getCharacterEncoding();
}
/**
@@ -78,52 +80,21 @@
public void setCharacterEncoding(String encoding)
throws UnsupportedEncodingException
{
- // If the encoding is already right, we can bail
- if (encoding.equals(_encoding))
+ if (getCharacterEncoding().equals(encoding))
+ {
return;
-
+ }
+
// It is illegal to set the character encoding after parameters
// have been retrieved. This is an annoying restriction,
// but we shouldn't break it
- if (_parametersRetrieved)
+ if (_manager.isParameterRetrieved())
{
_LOG.warning("UNABLE_SET_REQUEST_CHARACTER", encoding);
return;
}
-
- // Don't call super.setCharacterEncoding() - it's too late
- // and we'll get a warning
- _encoding = encoding;
- if (_LOG.isFine())
- _LOG.fine("Switching encoding of wrapper to " + encoding);
-
- _extractedAndDecodedParams =
- new HashMap<String, String[]>(_extractedParams.size());
-
- byte[] buffer = new byte[256];
- // FIXME: decodeRequestParameter() assumes the incoming
- // character set is ISO-8859-1 - but this is not
- // necessarily true!
- 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);
- }
+ _manager.setCharacterEncoding(encoding);
// Let the UploadedFiles know, so it can fix up filenames
UploadedFiles.setCharacterEncoding(this, encoding);
@@ -132,62 +103,28 @@
@Override
public String getParameter(String param)
{
- String[] value = _getParameterValues(param);
- if (value == null)
- return null;
-
- return value[0];
+ return _manager.getParameter(param);
}
@Override
public Map<String, String[]> getParameterMap()
{
- Map<String, String[]> map = _getMap();
- return Collections.unmodifiableMap(map);
+ return _manager.getParameterMap();
}
@Override
public Enumeration<String> getParameterNames()
{
- return Collections.enumeration(_getMap().keySet());
+ return _manager.getParameterNames();
}
@Override
public String[] getParameterValues(String param)
{
- String[] value = _getParameterValues(param);
- if (value == null)
- return null;
-
- return value.clone();
- }
-
- private String[] _getParameterValues(String param)
- {
- return _getMap().get(param);
+ return _manager.getParameterValues(param);
}
- /**
- * Get the correct map of parameters whether or not setCharacterEncoding()
- * was called.
- */
- private Map<String, String[]> _getMap()
- {
- // Mark that parameters have been retrieved so we
- // can log a proper warning
- _parametersRetrieved = true;
- if (_extractedAndDecodedParams != null)
- return _extractedAndDecodedParams;
-
- return _extractedParams;
- }
-
- private Map<String, String[]> _extractedAndDecodedParams;
- private Map<String, String[]> _extractedParams;
- private String _encoding;
- private boolean _parametersRetrieved;
-
- private static final String _WWW_FORM_URLENCODED_TYPE =
- "application/x-www-form-urlencoded";
- private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UploadRequestWrapper.class);
+ private UploadRequestManager _manager;
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(UploadRequestWrapper.class);
}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadResourceRequest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadResourceRequest.java?rev=773647&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadResourceRequest.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadResourceRequest.java Mon May 11 18:32:44 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.Enumeration;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.filter.ResourceRequestWrapper;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+public class UploadResourceRequest
+ extends ResourceRequestWrapper
+{
+ public UploadResourceRequest(ExternalContext ec, Map<String, String[]> params)
+ {
+ super((ResourceRequest) ec.getRequest());
+ _response = (ActionResponse) ec.getResponse();
+ _manager = new UploadRequestManager(ec, params);
+ }
+
+ /**
+ * Hide the content type so that no one tries to re-download the
+ * uploaded files.
+ */
+ @Override
+ public String getContentType()
+ {
+ return _manager.getContentType();
+ }
+
+ @Override
+ public String getCharacterEncoding()
+ {
+ return _manager.getCharacterEncoding();
+ }
+
+ /**
+ * Trap calls to setCharacterEncoding() to decode parameters correctly
+ */
+ @Override
+ public void setCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException
+ {
+ if (getCharacterEncoding().equals(encoding))
+ {
+ return;
+ }
+
+ // It is illegal to set the character encoding after parameters
+ // have been retrieved. This is an annoying restriction,
+ // but we shouldn't break it
+ if (_manager.isParameterRetrieved())
+ {
+ _LOG.warning("UNABLE_SET_REQUEST_CHARACTER", encoding);
+ return;
+ }
+
+ _manager.setCharacterEncoding(encoding);
+ _response.setRenderParameters(_manager.getParameterMap());
+
+ // Let the UploadedFiles know, so it can fix up filenames
+ UploadedFiles.setCharacterEncoding(this, encoding);
+ }
+
+ @Override
+ public String getParameter(String param)
+ {
+ return _manager.getParameter(param);
+ }
+
+ @Override
+ public Map<String, String[]> getParameterMap()
+ {
+ return _manager.getParameterMap();
+ }
+
+ @Override
+ public Enumeration<String> getParameterNames()
+ {
+ return _manager.getParameterNames();
+ }
+
+ @Override
+ public String[] getParameterValues(String param)
+ {
+ return _manager.getParameterValues(param);
+ }
+
+ private UploadRequestManager _manager;
+ private ActionResponse _response;
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(UploadRequestManager.class);
+ }
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java Mon May 11 18:32:44 2009
@@ -23,6 +23,8 @@
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+
import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
@@ -33,18 +35,16 @@
import javax.servlet.jsp.JspException;
+import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
+import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit;
import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.XmlResponseWriter;
-/**
- * Though a configurator in spirit, at this point it purely exposes
- * Servlet functionality, and is only used to wrap the servlet response.
- *
- * TODO: support portlets, and make this a true configurator.
- */
-public class XmlHttpConfigurator
- /*extends Configurator*/
+public class XmlHttpConfigurator extends Configurator
{
public XmlHttpConfigurator()
{
@@ -54,18 +54,34 @@
{
return new XmlHttpServletRequest(request);
}
-
- public static void beginRequest(ExternalContext externalContext)
- {
- StateManagerImpl.reuseRequestTokenForResponse(externalContext);
- Object response = externalContext.getResponse();
- if (response instanceof ServletResponse)
- {
- externalContext.setResponse(
- new XmlHttpServletResponse((ServletResponse) response));
+
+ @Override
+ public ExternalContext getExternalContext(ExternalContext externalContext)
+ {
+ if(CoreRenderKit.isPartialRequest(externalContext))
+ {
+ StateManagerImpl.reuseRequestTokenForResponse(externalContext);
+
+ RequestType type = ExternalContextUtils.getRequestType(externalContext);
+
+ switch(type)
+ {
+ case SERVLET:
+ if(ExternalContextUtils.isHttpServletRequest(externalContext))
+ {
+ externalContext.setResponse(new XmlHttpServletResponse(externalContext));
+ }
+ break;
+ case RESOURCE:
+ externalContext = new XmlHttpPortletExternalContext(externalContext);
+ externalContext.setResponse(new XmlHttpResourceResponse(externalContext));
+ }
}
+
+ return externalContext;
}
-
+
+
/**
* Sends a <redirect> element to the server
*/
@@ -159,7 +175,6 @@
static private int _ERROR_COUNT = 0;
-
static private final TrinidadLogger _LOG =
TrinidadLogger.createTrinidadLogger(XmlHttpConfigurator.class);
}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpPortletExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpPortletExternalContext.java?rev=773647&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpPortletExternalContext.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpPortletExternalContext.java Mon May 11 18:32:44 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.xmlHttp;
+
+import java.io.IOException;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ResourceResponse;
+
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
+
+/**
+ * This ExternalContext allows redirects to be sent on a resource request. Normally this is not
+ * allowed, but we do this by sending a redirect xml message.
+ */
+public class XmlHttpPortletExternalContext
+ extends ExternalContextDecorator
+{
+ private ExternalContext _ec;
+
+ public XmlHttpPortletExternalContext(ExternalContext ec)
+ {
+ _ec = ec;
+ }
+
+ @Override
+ public void redirect(String url)
+ throws IOException
+ {
+ PrintWriter writer = ((ResourceResponse)_ec.getResponse()).getWriter();
+ XmlHttpConfigurator.sendXmlRedirect(writer, url);
+ }
+
+ protected ExternalContext getExternalContext()
+ {
+ return _ec;
+ }
+}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpResourceResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpResourceResponse.java?rev=773647&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpResourceResponse.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpResourceResponse.java Mon May 11 18:32:44 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.xmlHttp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ResourceResponse;
+import javax.portlet.filter.ResourceResponseWrapper;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+public class XmlHttpResourceResponse
+ extends ResourceResponseWrapper
+{
+ public XmlHttpResourceResponse(ExternalContext ec)
+ {
+ super((ResourceResponse) ec.getResponse());
+
+ _contentType = "text/xml;charset=utf-8";
+
+ // must set contentType here since
+ // setContentType is ignored when inside an included page (bug 5591124)
+ super.setContentType(_contentType);
+ }
+
+ @Override
+ public OutputStream getPortletOutputStream()
+ throws IOException
+ {
+ OutputStream base = super.getPortletOutputStream();
+ return new XmlOutput(base).getOutputStream();
+ }
+
+ @Override
+ public PrintWriter getWriter()
+ throws IOException
+ {
+ PrintWriter base = super.getWriter();
+ return new XmlOutput(base).getWriter();
+ }
+
+ @Override
+ public void setContentType(final String type)
+ {
+ // the reason we're using XmlHttpServletResponse is because
+ // we're producing a ppr xml response, so ignore any
+ // attempts to set the contentType, since the contentType
+ // must be text/xml:
+ _LOG.finer("ignoring setContentType:{0}", type);
+ super.setContentType(_contentType);
+ }
+
+ private String _contentType = null;
+ static private final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(XmlHttpServletResponse.class);
+}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java Mon May 11 18:32:44 2009
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.PrintWriter;
+import javax.faces.context.ExternalContext;
+
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
@@ -32,9 +34,9 @@
@SuppressWarnings("deprecation")
final class XmlHttpServletResponse extends HttpServletResponseWrapper
{
- XmlHttpServletResponse(ServletResponse response)
+ XmlHttpServletResponse(ExternalContext ec)
{
- super((HttpServletResponse)response);
+ super((HttpServletResponse)ec.getResponse());
_contentType = "text/xml;charset=utf-8";
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java Mon May 11 18:32:44 2009
@@ -83,18 +83,6 @@
ExternalContext ec = context.getExternalContext();
// Assume it's not a postback request
ec.getRequestMap().put(_POSTBACK_KEY, Boolean.FALSE);
-
- // And initialize XmlHttp. We wait until beforePhase()
- // of RESTORE_VIEW, instead of doing this in the filter,
- // so that we don't get a request parameter before ViewHandler.initView()
- // has been called: doing that leads to big problems. Note
- // that with the 1.2_03 RI, this will still be too early,
- // as it called initView() after beforePhase()
- if (CoreRenderKit.isPartialRequest(ec))
- {
- XmlHttpConfigurator.beginRequest(ec);
- }
-
}
// If we've reached "apply request values", this is definitely a
// postback (the ViewHandler should have reached the same conclusion too,
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Mon May 11 18:32:44 2009
@@ -43,6 +43,8 @@
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinFactory;
import org.apache.myfaces.trinidad.style.Styles;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgentImpl;
@@ -656,7 +658,15 @@
}
else if (CoreRenderKit.OUTPUT_MODE_PORTLET.equals(outputMode))
{
- return AgentUtil.mergeCapabilities(agent, _PORTLET_CAPABILITIES);
+ if(ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE))
+ {
+ //Set things up for the Portlet 2.0 container.
+ return AgentUtil.mergeCapabilities(agent, _ENHANCED_PORTLET_CAPABILITIES);
+ }
+ else
+ {
+ return AgentUtil.mergeCapabilities(agent, _PORTLET_CAPABILITIES);
+ }
}
else
{
@@ -802,6 +812,9 @@
static private final Map<Object, Object> _PORTLET_CAPABILITIES =
new HashMap<Object, Object>();
+
+ static private final Map<Object, Object> _ENHANCED_PORTLET_CAPABILITIES =
+ new HashMap<Object, Object>();
static
{
@@ -835,6 +848,9 @@
Boolean.FALSE);
_PORTLET_CAPABILITIES.put(TrinidadAgent.CAP_MULTIPLE_WINDOWS,
Boolean.FALSE);
+
+ _ENHANCED_PORTLET_CAPABILITIES.put(TrinidadAgent.CAP_MULTIPLE_WINDOWS,
+ Boolean.FALSE);
}
static private final TrinidadLogger _LOG =
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java Mon May 11 18:32:44 2009
@@ -29,6 +29,7 @@
import javax.faces.component.ActionSource;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
@@ -47,6 +48,8 @@
import org.apache.myfaces.trinidad.context.FormData;
import org.apache.myfaces.trinidad.context.PartialPageContext;
import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreResponseStateManager;
import org.apache.myfaces.trinidadinternal.renderkit.uix.SubformRenderer;
@@ -168,6 +171,7 @@
FacesBean bean) throws IOException
{
ResponseWriter rw = context.getResponseWriter();
+ ExternalContext ec = context.getExternalContext();
String formName = arc.getFormData().getName();
@@ -241,6 +245,15 @@
String action =
context.getApplication().getViewHandler().getActionURL(context, viewId);
renderEncodedActionURI(context, "action", action);
+
+ RequestType type = ExternalContextUtils.getRequestType(ec);
+
+ //Always add expando to portlet form
+ if(type.isPortlet())
+ {
+ renderEncodedResourceURI(context, "_trinPPRAction", action);
+ }
+
if (supportsTarget(arc))
{
rw.writeAttribute("target", getTargetFrame(bean), "targetFrame");
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java Mon May 11 18:32:44 2009
@@ -27,12 +27,15 @@
import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
-/**
- * TODO: Document this
- *
- * @version $Revision$ $Date$
- */
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
+ /**
+ * Wrapper for the native PortletContext object. Unlike the other Portlet Wrapper classes in
+ * this package, this class may be used for both Portlet 1.0 and 2.0 containers.
+ *
+ * @version $Revision$ $Date$
+ */
public class PortletContextWrapper implements PortletContext
{
public PortletContextWrapper(PortletContext context)
@@ -56,7 +59,7 @@
* @return
* @see javax.portlet.PortletContext#getAttributeNames()
*/
- public Enumeration<?> getAttributeNames()
+ public Enumeration<String> getAttributeNames()
{
return _context.getAttributeNames();
}
@@ -75,7 +78,7 @@
* @return
* @see javax.portlet.PortletContext#getInitParameterNames()
*/
- public Enumeration<?> getInitParameterNames()
+ public Enumeration<String> getInitParameterNames()
{
return _context.getInitParameterNames();
}
@@ -115,7 +118,7 @@
*/
public PortletRequestDispatcher getNamedDispatcher(String arg0)
{
- return new PortletRequestDispatcherWrapper(_context.getNamedDispatcher(arg0));
+ return _context.getNamedDispatcher(arg0);
}
/**
@@ -144,7 +147,7 @@
*/
public PortletRequestDispatcher getRequestDispatcher(String arg0)
{
- return new PortletRequestDispatcherWrapper(_context.getRequestDispatcher(arg0));
+ return _context.getRequestDispatcher(arg0);
}
/**
@@ -227,4 +230,20 @@
{
_context.setAttribute(arg0, arg1);
}
+
+ /**
+ * Portlet 2.0 only functionality. These wrappers are not intended for Portlet 2.0. Marked
+ * final in order to prevent overloading.
+ */
+ public Enumeration<String> getContainerRuntimeOptions()
+ {
+ if(!_PORTLET_2_CONTAINER)
+ {
+ throw new UnsupportedOperationException("This method is only supported in Portlet 2.0 containers");
+ }
+
+ return _context.getContainerRuntimeOptions();
+ }
+
+ private static final boolean _PORTLET_2_CONTAINER = ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE);
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Mon May 11 18:32:44 2009
@@ -134,11 +134,18 @@
headerParams
)
{
+ //this retrieves the action url for PPR. Generally this will be the action property on
+ //actionForm, however in the case of a Portal 2.0 environment, this could be a special
+ //expando property encoded as a ResourceUrl. As such, if the expando is available, use it
+ //for PPR
+ var pprURL = actionForm.getAttribute("_trinPPRAction");
+ var action = pprURL?pprURL:actionForm.action;
+
if (this._isMultipartForm(actionForm))
{
// TODO: log a warning if we're dropping any headers? Or
// come up with a hack to send "headers" via a multipart request?
- this.sendMultipartRequest(context, method, actionForm.action, actionForm, params);
+ this.sendMultipartRequest(context, method, action, actionForm, params);
}
else
{
@@ -148,7 +155,7 @@
if(_agent.isIE)
this._autoCompleteForm(actionForm);
- this.sendRequest(context, method, actionForm.action, content, headerParams);
+ this.sendRequest(context, method, action, content, headerParams);
}
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator?rev=773647&r1=773646&r2=773647&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator Mon May 11 18:32:44 2009
@@ -1,3 +1,4 @@
org.apache.myfaces.trinidadinternal.config.upload.FileUploadConfiguratorImpl
org.apache.myfaces.trinidadinternal.config.dispatch.DispatchResponseConfiguratorImpl
+org.apache.myfaces.trinidadinternal.config.xmlHttp.XmlHttpConfigurator
org.apache.myfaces.trinidadinternal.config.CheckSerializationConfigurator