You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2008/04/18 00:15:36 UTC
svn commit: r649306 [2/2] - in /myfaces/portlet-bridge/core/trunk_2.0.x:
api/src/main/java/javax/portlet/faces/
api/src/main/java/javax/portlet/faces/event/ api/src/main/resources/META-INF/
impl/src/main/java/org/apache/myfaces/portlet/faces/applicatio...
Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=649306&r1=649305&r2=649306&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java Thu Apr 17 15:15:26 2008
@@ -32,7 +32,6 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -45,6 +44,8 @@
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
+import javax.portlet.ClientDataRequest;
+import javax.portlet.MimeResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
@@ -55,6 +56,7 @@
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.ResourceURL;
import javax.portlet.WindowState;
import javax.portlet.faces.Bridge;
import javax.portlet.faces.BridgeDefaultViewNotSpecifiedException;
@@ -92,7 +94,8 @@
Bridge.BRIDGE_PACKAGE_PREFIX + "." + Bridge.RENDER_POLICY;
// Render parameter to store the viewId
- public static final String ACTION_ID_PARAMETER_NAME = "_xACTION_ID";
+ public static final String ACTION_ID_PARAMETER_NAME = "_xBridgeActionID";
+ public static final String RESOURCE_ACTION_ID_PARAMETER_NAME = "_xBridgeResourceActionID";
public static final String REDIRECT_ID_PARAMETER_NAME = "org.apache.myfaces.portlet.faces.redirectViewParams";
@@ -412,6 +415,8 @@
public String encodeResourceURL(String s)
{
boolean containsBackLinkMarker = false, isViewLink = false;
+ boolean isOutOfProtocolResource = false;
+
if (s.indexOf(Bridge.BACK_LINK) != -1)
{
containsBackLinkMarker = true;
@@ -421,6 +426,13 @@
{
// Only non-external URLs can be viewLinks
isViewLink = isViewLink(s);
+
+ // Non-Faces links are out of protocol by default
+ if (!isFacesURL(s))
+ {
+ isOutOfProtocolResource = !isInProtocolResourceLink(s);
+ s = removeInProtocolResourceLink(s);
+ }
if (!s.startsWith("/"))
{
@@ -446,15 +458,10 @@
path = path.substring(0, path.lastIndexOf("/"));
s = URLUtils.convertFromRelative(path, s);
}
-
- // prepend the context path since portletResponse.encodeURL() requires a full path URI
- // Don't need to check return from getRequestContextPath because there must
- // always be a vlaue even if an empty string
- String ctxPath = getRequestContextPath();
- if (ctxPath.length() > 0 && !s.startsWith(ctxPath))
- {
- s = ctxPath + s;
- }
+ }
+ else
+ {
+ isOutOfProtocolResource = true;
}
// Check for backlink and viewlink markers -- if they exist replace
@@ -463,9 +470,12 @@
s = replaceResourceQueryStringMarkers(s, containsBackLinkMarker, isViewLink);
}
- if (!isViewLink)
+ if (isOutOfProtocolResource)
{
s = mPortletResponse.encodeURL(s);
+ } else if (!isViewLink)
+ {
+ s = encodePortletResourceURL(s);
}
else
{
@@ -477,6 +487,104 @@
return s;
}
+
+ private String encodePortletResourceURL(String url)
+ {
+ // If a Faces resource, we assume that clients have called
+ // ViewHandler.getActionURL() before calling encodeResourceURL when
+ // doing a partial page URL. Hence all other framework queryString
+ // params should already be encoded.
+
+ // Though might prefer to defer this analysis until the request is
+ // submitted this info is available within ExternalContext but not the
+ // bridge code -- so we would have to reestablish the faces context to
+ // do it then even if we subsequently don't need it because its not a
+ // Faces resource.
+
+ // Determine if there is a target viewId
+ String viewId = null, path = null;
+ QueryString queryStr = null;
+ int queryStart = -1;
+
+ // First: split URL into path and query string
+ // Hold onto QueryString for later processing
+ queryStart = url.indexOf('?');
+
+ if (queryStart != -1)
+ {
+ // Get the query string
+ queryStr = new QueryString(url.substring(queryStart + 1), "UTF8");
+ path = url.substring(0, queryStart);
+ }
+ else
+ {
+ path = url;
+ // construct an empty queryString to hold the viewId
+ queryStr = new QueryString("UTF8");
+ }
+
+ // Now remove up through the ContextPath as we don't want it
+ String ctxPath = getRequestContextPath();
+ int i = path.indexOf(ctxPath);
+ if (i != -1)
+ {
+ path = path.substring(i + ctxPath.length());
+ }
+
+ // Determine the viewId by inspecting the URL
+ // Can't be relative by the time we get here so don't check
+ viewId = getViewIdFromPath(path);
+
+ if (viewId != null)
+ {
+ // This is a Faces resource
+ // put the viewId in the QueryStr.
+ queryStr.addParameter(RESOURCE_ACTION_ID_PARAMETER_NAME, viewId);
+ queryStr.removeParameter(Bridge.PORTLET_MODE_PARAMETER);
+ queryStr.removeParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
+ }
+
+
+ // Encode the URL
+
+ ResourceURL resource = ((MimeResponse) mPortletResponse).createResourceURL();
+ resource.setResourceID(path);
+
+ // Walk through the queryStr Params and add as resourceParams
+ // remove any attempt to set Mode/WindowState/etc. as
+ // not feasible here
+ // Add parameters so they don't get lost
+ Enumeration<String> list = queryStr.getParameterNames();
+ while (list.hasMoreElements())
+ {
+ String param = list.nextElement().toString();
+ if (param.equals(Bridge.PORTLET_MODE_PARAMETER))
+ {
+ // do nothing -- just ignore -- can't encode in a resourceURL
+ }
+ else if (param.equals(Bridge.PORTLET_WINDOWSTATE_PARAMETER))
+ {
+ // do nothing -- just ignore -- can't encode in a resourceURL
+ }
+ else if (param.equals(Bridge.PORTLET_SECURE_PARAMETER))
+ {
+ try
+ {
+ resource.setSecure(Boolean.getBoolean(queryStr.getParameter(param)));
+ }
+ catch (Exception e)
+ {
+ ; // do nothing -- just ignore
+ }
+ }
+ else
+ {
+ resource.setParameter(param, queryStr.getParameter(param));
+ }
+ }
+
+ return resource.toString();
+ }
@Override
public void dispatch(String requestURI)
@@ -487,11 +595,6 @@
throw new java.lang.NullPointerException();
}
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
- {
- throw new IllegalStateException("Request cannot be an ActionRequest");
- }
-
PortletRequestDispatcher prd = mPortletContext.getRequestDispatcher(requestURI);
if (prd == null)
@@ -502,7 +605,7 @@
try
{
- prd.include((RenderRequest) mOrigPortletRequest, (RenderResponse) mOrigPortletResponse);
+ prd.include((PortletRequest) getRequest(), (PortletResponse) getResponse());
}
catch (PortletException e)
{
@@ -683,14 +786,7 @@
public String encodeNamespace(String s)
{
- if (BridgeUtil.getPortletRequestPhase() != Bridge.PortletPhase.RENDER_PHASE)
- {
- throw new IllegalStateException("Only RenderResponse can be used to encode a namespace");
- }
- else
- {
- return ((RenderResponse) mPortletResponse).getNamespace() + s;
- }
+ return ((PortletResponse) mPortletResponse).getNamespace() + s;
}
@Override
@@ -821,21 +917,9 @@
public void setRequestCharacterEncoding(String encoding)
throws UnsupportedEncodingException, IllegalStateException
{
- /* TODO: Temporary workaround for JIRA PORTLETBRIDGE-14 until EG
- * decides on best course of action.
- *
- if (mPhase != Bridge.PortletPhase.ACTION_PHASE)
- {
-
- throw new IllegalStateException(
- "PortletExternalContextImpl.setRequestCharacterEncoding(): Request must be an ActionRequest");
- }
- */
-
- //Part of temp workaround. Do a noop if we are not in action phase
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
+ if (mPhase != null && mPortletRequest instanceof ClientDataRequest)
{
- ((ActionRequest) mPortletRequest).setCharacterEncoding(encoding);
+ ((ClientDataRequest) mPortletRequest).setCharacterEncoding(encoding);
}
}
@@ -866,13 +950,13 @@
@Override
public String getRequestCharacterEncoding()
{
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
+ if (mPhase != null && mPortletRequest instanceof ClientDataRequest)
{
- return ((ActionRequest) mPortletRequest).getCharacterEncoding();
+ return ((ClientDataRequest) mPortletRequest).getCharacterEncoding();
}
else
{
- // RENDER_PHASE -- return null as per spec
+ // other phases -- return null as per spec
return null;
}
}
@@ -904,13 +988,13 @@
@Override
public String getRequestContentType()
{
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
+ if (mPhase != null && mPortletRequest instanceof ClientDataRequest)
{
- return ((ActionRequest) mPortletRequest).getContentType();
+ return ((ClientDataRequest) mPortletRequest).getContentType();
}
else
{
- // RENDER_PHASE: return null as per spec
+ // Other PHASEs: return null as per spec
return null;
}
}
@@ -943,12 +1027,12 @@
@Override
public String getResponseCharacterEncoding()
{
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
+ if (mPhase != null && mPortletRequest instanceof MimeResponse)
{
throw new IllegalStateException("PortletExternalContextImpl.getResponseCharacterEncoding(): Response must be a RenderRequest");
}
- return ((RenderResponse) mPortletResponse).getCharacterEncoding();
+ return ((MimeResponse) mPortletResponse).getCharacterEncoding();
}
/**
@@ -978,12 +1062,12 @@
@Override
public String getResponseContentType()
{
- if (mPhase == Bridge.PortletPhase.ACTION_PHASE)
+ if (mPhase != null && mPortletRequest instanceof MimeResponse)
{
throw new IllegalStateException("PortletExternalContextImpl.getResponseContentType(): Response must be a RenderRequest");
}
- return ((RenderResponse) mPortletResponse).getContentType();
+ return ((MimeResponse) mPortletResponse).getContentType();
}
/**
@@ -1049,6 +1133,12 @@
// where we couldn't update the ACTION_ID
String viewId = mPortletRequest.getParameter(REDIRECT_ID_PARAMETER_NAME);
+ // Next Possibility is its a Resource Request
+ if (viewId == null)
+ {
+ viewId = mPortletRequest.getParameter(RESOURCE_ACTION_ID_PARAMETER_NAME);
+ }
+
// Normal case is its returned in the render parameter
if (viewId == null)
{
@@ -1273,8 +1363,8 @@
}
else
{
- // Set to what follows the URL
- viewId = url;
+ // Not a Faces URL
+ viewId = null;
}
return viewId;
}
@@ -1475,6 +1565,12 @@
return isTokenLink(Bridge.DIRECT_LINK, url);
}
+ private boolean isInProtocolResourceLink(String url)
+ {
+ return isTokenLink(Bridge.IN_PROTOCOL_RESOURCE_LINK, url);
+ }
+
+
private boolean isViewLink(String url)
{
return isTokenLink(Bridge.VIEW_LINK, url);
@@ -1499,6 +1595,11 @@
private String removeDirectLink(String url)
{
return removeTokenLink(Bridge.DIRECT_LINK, url);
+ }
+
+ private String removeInProtocolResourceLink(String url)
+ {
+ return removeTokenLink(Bridge.IN_PROTOCOL_RESOURCE_LINK, url);
}
private String removeTokenLink(String token, String url)
Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java?rev=649306&r1=649305&r2=649306&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java Thu Apr 17 15:15:26 2008
@@ -26,8 +26,11 @@
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+
import javax.portlet.PortletContext;
import javax.xml.parsers.SAXParser;
@@ -46,6 +49,7 @@
private static final String FACES_CONFIG_METAINF_PATH = "META-INF/faces-config.xml";
private static final String FACES_CONFIG_WEBINF_PATH = "/WEB-INF/faces-config.xml";
private List<String> mExcludedAttributes = null;
+ private Map<String, String> mPublicParameterMappings = null;
/**
* <p>
@@ -63,12 +67,17 @@
{
scanForFacesMappings(context);
}
- } // END WebXmlProcessor
+ }
public List<String> getExcludedAttributes()
{
return mExcludedAttributes;
- } // END getFacesMappings
+ }
+
+ public Map<String,String> getPublicParameterMappings()
+ {
+ return mPublicParameterMappings;
+ }
/**
* <p>
@@ -163,18 +172,31 @@
private static final String APP_EXTENSION_ELEMENT = "application-extension";
private static final String EXCLUDED_ATTRIBUTES_ELEMENT = "excluded-attributes";
private static final String EXCLUDED_ATTRIBUTE_ELEMENT = "excluded-attribute";
+ private static final String PUBLIC_PARAMETER_MAPPINGS_ELEMENT = "public-parameter-mappings";
+ private static final String PUBLIC_PARAMETER_MAPPING_ELEMENT = "public-parameter-mapping";
+ private static final String PARAMETER_ELEMENT = "parameter";
+ private static final String MODEL_EL_ELEMENT = "model-el";
+
private boolean mInApplicationElement = false;
private boolean mInApplicationExtensionElement = false;
private boolean mInExcludedAttributesElement = false;
+ private boolean mInPublicParameterMappings = false;
+ private boolean mInPublicParameterMapping = false;
+ private boolean mInParameter = false;
+ private boolean mInModelEL = false;
+
private StringBuilder mContent;
+ private String mContent1;
+ private String mContent2;
public void reset()
{
mInApplicationElement = mInApplicationExtensionElement =
- mInExcludedAttributesElement = false;
+ mInExcludedAttributesElement = mInPublicParameterMappings =
+ mInPublicParameterMapping = mInParameter = mInModelEL = false;
}
@Override
@@ -202,6 +224,23 @@
{
mInExcludedAttributesElement = true;
}
+ else if (PUBLIC_PARAMETER_MAPPINGS_ELEMENT.equals(localName))
+ {
+ mInPublicParameterMappings = true;
+ }
+ else if (PUBLIC_PARAMETER_MAPPING_ELEMENT.equals(localName))
+ {
+ mInPublicParameterMapping = true;
+ }
+ else if (PARAMETER_ELEMENT.equals(localName) ||
+ MODEL_EL_ELEMENT.equals(localName))
+ {
+ if (mInApplicationElement && mInApplicationExtensionElement &&
+ mInPublicParameterMappings && mInPublicParameterMapping)
+ {
+ mContent = new StringBuilder();
+ }
+ }
else if (EXCLUDED_ATTRIBUTE_ELEMENT.equals(localName))
{
if (mInApplicationElement && mInApplicationExtensionElement &&
@@ -254,6 +293,40 @@
{
mExcludedAttributes.add(excludedAttribute);
}
+ }
+ else if (PUBLIC_PARAMETER_MAPPINGS_ELEMENT.equals(localName))
+ {
+ mInPublicParameterMappings = false;
+ }
+ else if (PUBLIC_PARAMETER_MAPPING_ELEMENT.equals(localName))
+ {
+ if (mContent1 != null && mContent2 != null)
+ {
+ if (mPublicParameterMappings == null)
+ {
+ mPublicParameterMappings = (Map<String, String> )new HashMap(5);
+ }
+
+ if (!mPublicParameterMappings.containsKey(mContent1))
+ {
+ mPublicParameterMappings.put(mContent1, mContent2);
+ }
+ }
+ mContent1 = mContent2 = null;
+
+ mInPublicParameterMappings = false;
+ }
+ else if (PARAMETER_ELEMENT.equals(localName) && mContent != null
+ && mContent.length() > 0)
+ {
+ // hold mContent to add as pair later
+ mContent1 = mContent.toString().trim();
+ }
+ else if (MODEL_EL_ELEMENT.equals(localName) && mContent != null
+ && mContent.length() > 0)
+ {
+ // hold mContent to add as pair later
+ mContent2 = mContent.toString().trim();
}
mContent = null;
Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestParameterMap.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestParameterMap.java?rev=649306&r1=649305&r2=649306&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestParameterMap.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestParameterMap.java Thu Apr 17 15:15:26 2008
@@ -21,9 +21,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
import javax.portlet.PortletRequest;
/**
@@ -33,6 +36,7 @@
{
private final PortletRequest mPortletRequest;
private final Map<String, String> mInternalAttributes;
+ private Map<String,String[]> mPrivateParameters;
public PortletRequestParameterMap(Object request, Map<String, String> internal)
{
@@ -64,8 +68,21 @@
{
return value;
}
-
- return mPortletRequest.getParameter(key);
+
+ if (mPrivateParameters == null)
+ {
+ mPrivateParameters = mPortletRequest.getPrivateParameterMap();
+ }
+ String[] params = mPrivateParameters.get(key);
+ if (params != null)
+ {
+ return params[0];
+ }
+ else
+ {
+ return null;
+ }
+
}
else
{
@@ -90,16 +107,15 @@
public Enumeration<String> getAttributeNames()
{
if (mPortletRequest != null)
- {
+ {
// merged list of internal parameters & request parameters
List<String> attrNames = new ArrayList<String>(5);
- Enumeration<String> requestAttrNames = mPortletRequest.getParameterNames();
- while (requestAttrNames.hasMoreElements())
+ if (mPrivateParameters == null)
{
- attrNames.add(requestAttrNames.nextElement());
+ mPrivateParameters = mPortletRequest.getPrivateParameterMap();
}
-
+ attrNames.addAll(mPrivateParameters.keySet());
attrNames.addAll(mInternalAttributes.keySet());
return Collections.enumeration(attrNames);