Author: alexsmirnov
Date: 2007-10-30 20:58:31 -0400 (Tue, 30 Oct 2007)
New Revision: 3629
Added:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortalActionURL.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortalActionUrlTest.java
Removed:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java
trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml
Log:
Continue to implement JSR-301 bridge. Finish requrements from PLT 5.
Deleted:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-30
23:16:49 UTC (rev 3628)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -1,93 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.portlet;
-
-import java.util.Map;
-
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.context.AjaxContextImpl;
-import org.ajax4jsf.portlet.context.AbstractExternalContext;
-import org.ajax4jsf.webapp.WebXml;
-
-/**
- * @author asmirnov
- *
- */
-public class PortletAjaxContext extends AjaxContextImpl {
- public String getAjaxActionURL(FacesContext context) {
- // Check arguments
- if (null == context) {
- throw new NullPointerException(
- "Faces context for build AJAX Action URL is null");
- }
-// if (context.getExternalContext().getContext() instanceof PortletContext) {
- UIViewRoot viewRoot = context.getViewRoot();
- if (null == viewRoot) {
- throw new NullPointerException(
- "Faces view tree for build AJAX Action URL is null");
- }
- String viewId = viewRoot.getViewId();
- if (null == viewId) {
- throw new NullPointerException(
- "View id for build AJAX Action URL is null");
- }
- if (!viewId.startsWith("/")) {
- throw new IllegalArgumentException(
- "Illegal view Id for build AJAX Action URL: " + viewId);
- }
- ExternalContext externalContext = context.getExternalContext();
- WebXml webXml = (WebXml) externalContext.getApplicationMap().get(
- WebXml.CONTEXT_ATTRIBUTE);
- if (null == webXml) {
- throw new NullPointerException(
- "Ajax Filter not properly configured for web application");
- }
- StringBuffer actionUrl = new StringBuffer(externalContext
- .getRequestContextPath());
- if (webXml.isPrefixMapping()) {
- String facesFilterPrefix = webXml.getFacesFilterPrefix();
- if (facesFilterPrefix.endsWith("/")) {
- facesFilterPrefix = facesFilterPrefix.substring(0,facesFilterPrefix.length()-1);
- }
- actionUrl.append(facesFilterPrefix).append(viewId);
- } else {
- int dot = viewId.lastIndexOf('.');
- if (dot < 0) {
- actionUrl.append(viewId).append(
- webXml.getFacesFilterSuffix());
- } else {
- actionUrl.append(viewId.substring(0, dot)).append(
- webXml.getFacesFilterSuffix());
- }
- }
- // ViewHandler viewHandler =
- // context.getApplication().getViewHandler();
- // TODO - append optional seam/portlet.. parameters
- return externalContext.encodeActionURL(actionUrl.toString());
-// } else {
-// return super.getAjaxActionURL(context);
-// }
- }
-
- public Map getCommonAjaxParameters() {
- Map map = super.getCommonAjaxParameters();
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String namespace = AjaxFacesPortlet.getPortletNamespace(facesContext);
- if (null != namespace) {
- map.put(AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
- }
- String actionUrl = (String)
facesContext.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.ACTION__PARAMETER);
- if(null != actionUrl){
- map.put(AbstractExternalContext.ACTION__PARAMETER, actionUrl);
- }
- String portletMode = (String)
facesContext.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.PORTLET_MODE_PARAMETER);
- if(null != actionUrl){
- map.put(AbstractExternalContext.PORTLET_MODE_PARAMETER, portletMode);
- }
- return map;
- }
-}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-30
23:16:49 UTC (rev 3628)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -12,67 +12,64 @@
import javax.faces.context.FacesContext;
import javax.portlet.PortletURL;
import javax.portlet.RenderResponse;
+import javax.portlet.faces.Bridge;
import org.ajax4jsf.application.AjaxViewHandler;
+import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.portlet.component.UIPortletViewRoot;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
/**
* @author asmirnov
- *
+ *
*/
public class PortletViewHandler extends AjaxViewHandler {
- /**
- * @param parent
- */
- public PortletViewHandler(ViewHandler parent) {
- super(parent);
- }
-
-
- public void initView(FacesContext context) throws FacesException {
- super.initView(context);
- }
-
- public UIViewRoot createView(FacesContext facesContext, String viewId) {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
- boolean ajaxRequest = ajaxContext.isAjaxRequest(facesContext);
- UIViewRoot root = new UIPortletViewRoot(super.createView(facesContext, viewId));
- if(ajaxRequest && null != ajaxContext.getViewIdHolder()){
- // Store new viewId for a portlet.
- }
- return root;
- }
+ /**
+ * @param parent
+ */
+ public PortletViewHandler(ViewHandler parent) {
+ super(parent);
+ }
- public void renderView(FacesContext context, UIViewRoot root) throws IOException,
FacesException {
- super.renderView(context, root);
- // Save view to use in portlet rendering phases
-// PortletViewState state = new PortletViewState();
-// state.save(context);
-// context.getExternalContext().getSessionMap().put(
-// PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
+ public void initView(FacesContext context) throws FacesException {
+ super.initView(context);
+ }
- }
-
- public String getActionURL(FacesContext context, String url) {
- ExternalContext externalContext = context.getExternalContext();
- String portalActionURL = (String)
externalContext.getRequestParameterMap().get(AbstractExternalContext.ACTION__PARAMETER);
- Object response = externalContext.getResponse();
- if (response instanceof RenderResponse) {
- RenderResponse renderResponse = (RenderResponse) response;
- PortletURL portletURL = renderResponse.createActionURL();
-// portletURL.setParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
context.getViewRoot().getViewId());
- portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
renderResponse.getNamespace());
- return portletURL.toString();
- } else if(null!=portalActionURL){
- return portalActionURL;
- } else {
- return super.getActionURL(context, url);
+ public UIViewRoot createView(FacesContext facesContext, String viewId) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ boolean ajaxRequest = ajaxContext.isAjaxRequest(facesContext);
+ UIViewRoot root = super.createView(facesContext, viewId);
+ Class<? extends UIViewRoot> rootClass = root.getClass();
+ if (rootClass == AjaxViewRoot.class || rootClass == UIViewRoot.class) {
+ root = new UIPortletViewRoot(root);
+ }
+ if (ajaxRequest && null != ajaxContext.getViewIdHolder()) {
+ // Store new viewId for a portlet.
+ }
+ return root;
}
- }
-
- protected synchronized void fillChain(FacesContext context) {
- // Do nothing - chain must be filled in AjaxViewHandler
- }
+
+ public void renderView(FacesContext context, UIViewRoot root)
+ throws IOException, FacesException {
+ super.renderView(context, root);
+ // Save view to use in portlet rendering phases
+ // PortletViewState state = new PortletViewState();
+ // state.save(context);
+ // context.getExternalContext().getSessionMap().put(
+ // PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
+
+ }
+
+ public String getActionURL(FacesContext context, String url) {
+ String actionURL = super.getActionURL(context, url);
+ if( null !=
context.getExternalContext().getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE)){
+ actionURL = actionURL +
((actionURL.lastIndexOf('?')>0)?"&":"?")+AbstractExternalContext.VIEW_ID_PARAMETER+"="+url;
+ }
+ return actionURL;
+ }
+
+ protected synchronized void fillChain(FacesContext context) {
+ // Do nothing - chain must be filled in AjaxViewHandler
+ }
}
Added:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortalActionURL.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortalActionURL.java
(rev 0)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortalActionURL.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -0,0 +1,190 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.collections.map.LinkedMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortalActionURL {
+
+ private static final Pattern urlPattern = Pattern
+ .compile("^(\\w*:)?(//[\\w\\._-]+[^/:])?((?:\\:)(\\d+))?([^?]*)?((?:\\?)(.*))?$");
+
+ private static final String NULL = "";
+
+ private String protocol;
+
+ private String host;
+
+ private int port = -1;
+
+ /**
+ * The authority part of this URL.
+ *
+ * @serial
+ */
+ private String authority;
+
+ /**
+ * The path part of this URL.
+ */
+ private transient String path;
+
+ /**
+ * The userinfo part of this URL.
+ */
+ private transient String userInfo;
+
+ private Map<String, String> parameters;
+
+ private String queryString;
+
+ private int _length;
+
+ /**
+ * @param url
+ */
+ public PortalActionURL(String url) throws MalformedURLException {
+ Matcher urlMatcher = urlPattern.matcher(url);
+ if (!urlMatcher.matches()) {
+ throw new MalformedURLException(url);
+ }
+ _length = url.length();
+ this.protocol = urlMatcher.group(1);
+ this.host = urlMatcher.group(2);
+ String portStr = urlMatcher.group(4);
+ if (null != portStr && portStr.length() > 0) {
+ this.port = Integer.parseInt(portStr);
+ }
+ this.path = urlMatcher.group(5);
+ queryString = urlMatcher.group(7);
+ parameters = new LinkedMap(30);
+ if (null != queryString) {
+ String[] queryParams = queryString.split("&");
+ for (int i = 0; i < queryParams.length; i++) {
+ String par = queryParams[i];
+ int eqIndex = par.indexOf('=');
+ if(eqIndex>=0){
+ parameters.put(par.substring(0, eqIndex), par.substring(eqIndex+1));
+ } else {
+ parameters.put(par, NULL);
+ }
+ }
+ }
+ }
+
+ /**
+ * @return the protocol
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * @return the host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * @return the port
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * @return the authority
+ */
+ public String getAuthority() {
+ return authority;
+ }
+
+ /**
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * @return the userInfo
+ */
+ public String getUserInfo() {
+ return userInfo;
+ }
+
+ /**
+ * @return the queryString
+ */
+ public String getQueryString() {
+ return queryString;
+ }
+
+ public String getParameter(String name) {
+ return parameters.get(name);
+ }
+
+ public void addParameter(String name, String value){
+ parameters.put(name, value);
+ }
+
+ public String removeParameter(String name){
+ return parameters.remove(name);
+ }
+
+ public int parametersSize() {
+ return parameters.size();
+ }
+
+ public boolean isInContext(String context) {
+ return host==null && protocol == null && port == -1 &&
path.startsWith(context+"/");
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer url = new StringBuffer(_length);
+ if(null != protocol){
+ url.append(protocol);
+ }
+ if (null!=host) {
+ url.append(host);
+ }
+ if(port>0){
+ url.append(':').append(port);
+ }
+ url.append(path);
+ if(parameters.size()>0){
+ url.append('?');
+ for (Iterator<Entry<String, String>> iterator =
parameters.entrySet().iterator(); iterator.hasNext();) {
+ Entry<String, String> param = iterator.next();
+ url.append(param.getKey());
+ if(param.getValue() != NULL){
+ url.append('=').append(param.getValue());
+ }
+ if (iterator.hasNext()) {
+ url.append('&');
+ }
+ }
+ }
+ return url.toString();
+ }
+
+ public Map<String,String> getParameters() {
+ return parameters;
+ }
+}
Property changes on:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortalActionURL.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-30
23:16:49 UTC (rev 3628)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -16,8 +16,11 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContextFactory;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletContext;
@@ -28,8 +31,11 @@
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.faces.Bridge;
/**
+ * Version of the {@link ExternalContext} for a Portlet request. {@link
FacesContextFactory} will create instance of this class
+ * for a portal <code>action</code> phase.
* @author asmirnov
*
*/
@@ -47,47 +53,26 @@
}
public String getResponseCharacterEncoding() {
- PortletResponse portletResponse = getPortletResponse();
- if (portletResponse instanceof RenderResponse) {
- RenderResponse renderResponse = (RenderResponse) portletResponse;
- return renderResponse.getCharacterEncoding();
- } else {
return null;
- }
}
public String getResponseContentType() {
- PortletResponse portletResponse = getPortletResponse();
- if (portletResponse instanceof RenderResponse) {
- RenderResponse renderResponse = (RenderResponse) portletResponse;
- return renderResponse.getContentType();
- } else {
return null;
- }
}
public void setRequestCharacterEncoding(String encoding)
throws UnsupportedEncodingException {
- PortletRequest portletRequest = getPortletRequest();
- if (portletRequest instanceof ActionRequest) {
try {
- ActionRequest actionRequest = (ActionRequest) portletRequest;
+ ActionRequest actionRequest = (ActionRequest) getPortletRequest();
actionRequest.setCharacterEncoding(encoding);
-
} catch (IllegalStateException e) {
// TODO: handle exception
}
- }
}
public String getRequestCharacterEncoding() {
- PortletRequest portletRequest = getPortletRequest();
- if (portletRequest instanceof ActionRequest) {
- ActionRequest actionRequest = (ActionRequest) portletRequest;
+ ActionRequest actionRequest = (ActionRequest) getPortletRequest();
return actionRequest.getCharacterEncoding();
- } else {
- return null;
- }
}
public String getRequestContentType() {
@@ -112,16 +97,12 @@
protected String getNamespace() {
if (null == namespace) {
- if (getResponse() instanceof RenderResponse) {
- namespace = ((RenderResponse) getResponse()).getNamespace();
- } else {
namespace = (String) getRequestParameter(
AbstractExternalContext.NAMESPACE_PARAMETER);
if(null == namespace){
throw new IllegalStateException(
"Can not determine portlet namespace");
}
- }
}
return namespace;
}
@@ -232,30 +213,62 @@
if (null == path) {
throw new NullPointerException("Path to new view is null");
}
- if (!(getRequest() instanceof RenderRequest && getResponse() instanceof
RenderResponse)) {
throw new IllegalStateException(
"Dispatch to new view not at render phase");
- }
- PortletRequestDispatcher dispatcher = getPortletContext()
- .getRequestDispatcher(path);
- if (null == dispatcher) {
- throw new IllegalStateException(
- "Dispatcher for render request is not created");
- }
- try {
- dispatcher.include((RenderRequest) getRequest(),
- (RenderResponse) getResponse());
- } catch (PortletException e) {
- throw new FacesException(e);
- }
}
+ private static final Pattern absoluteUrl = Pattern.compile("");
+ private static final Pattern directLink = Pattern.compile("");
+ private static final Pattern viewIdParam = Pattern.compile("");
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
+ * JSR-301 requirements, PLT 6.1.3.1 :
+ * Return the inputURL, after performing any rewriting needed to ensure that it will
correctly identify an addressable URL in the current application. The inputURL is
expected to conform to standard URI syntax or more specifically not be the result of
calling PortletURL.toString(). When called during the RenderPhase, the inputURL is
transformed, encoded, and returned so it can be used as markup into the response. When
called during the ActionPhase, the inputURL is transformed and encoded into the
ActionResponse as the Faces navigation which resulted from processing the action. To
process such an inputURL correctly, this method must:
+ o If the inputURL starts with the # character or the inputURL is an absolute
path external to this portlet application return the inputURL unchanged.
+ o If the inputURL contains the parameter javax.portlet.faces.DirectLink and its
value is true then return it without removing this parameter. If the inputURL contains
the parameter javax.portlet.faces.DirectLink and its value is false then remove the
javax.portlet.faces.DirectLink parameter and value from the queryString and continue
processing.
+ o Otherwise:
+ + Identify the viewId within the inputURL.
+ # If the inputURL contains a bridge encoded viewId then extract it
from the URL and use this as the viewId.
+ # Otherwise if the inputURL is a full path within the portlet
application, use the servlet definitions from the web application's web.xml to
determine both how the Faces servlet is mapped and whether this URL resolves to the Faces
servlet. Derive the view identifier that corresponds to this URL, as follows:
+ Note: all resulting viewIds start with a "/".
+ * If prefix mapping (such as “/faces/*”) is used for
FacesServlet, the viewId is set from the extra path information of the request URI. This
corresponds to the path that follows the prefix mapping.
+ * If suffix mapping (such as “*.faces”) is used for
FacesServlet, the viewId is set from the servlet path information of the request URI,
after replacing the suffix with the value of the context initialization parameter named by
the symbolic constant ViewHandler.DEFAULT_SUFFIX_PARAM_NAME (if no such context
initialization parameter is present, use the value of the symbolic constant
ViewHandler.DEFAULT_SUFFIX as the replacement suffix). This corresponds to the path that
follows the context path.
+ * If the URL doesn't reference a FacesServlet mapping
then the viewId is the path that follows the context path.
+ + Process the viewId based URL
+ # If executed during the ActionPhase, encode the viewId and any
additional querystring parameters in the ActionResponse in a way that not only ensures
that the appropriate subsequent render will be based on these but also that inappropriate
subsequent renders will not. (See section 5.1 concerning request scopes). Return a
non-null URL string whose value isn't equal to the inputURL.
+ # If executed during the RenderPhase, construct an actionURL by
calling getResponse().createActionURL(). Encode the viewId and any additional querystring
parameters in this actionURL in a way that not only ensures that the appropriate
subsequent render will be based on these parameters but also that inappropriate subsequent
renders will not. (See section 5.1 concerning request scopes).. And return
actionURL.toString().
+
+ Note: the result must not contain doubly encoded querystring
parameter values and hence additional processing is required to detect and undo such
double encoding when the inputURL is already encoded and the actionURL.toString() does
reencoding.
+
+ */
public String encodeActionURL(String url) {
if (null == url) {
throw new NullPointerException();
}
- return url;
+ String actionUrl = url;
+ if(!actionUrl.startsWith("#") ){
+ try {
+ PortalActionURL portalUrl = new PortalActionURL(url);
+ if(portalUrl.isInContext(getRequestContextPath()) ||
!(Boolean.parseBoolean(portalUrl.getParameter(Bridge.DIRECT_LINK)))){
+ portalUrl.removeParameter(Bridge.DIRECT_LINK);
+ String viewId = portalUrl.getParameter(VIEW_ID_PARAMETER);
+ actionUrl = createActionUrl(portalUrl.getParameters());
+ }
+ } catch (MalformedURLException e) {
+ throw new FacesException(e);
+ }
+ }
+ return getPortletResponse().encodeURL(actionUrl);
}
+
+ /**
+ * @param parameters
+ * @return
+ */
+ protected String createActionUrl(Map parameters){
+ return "/ajax4jsfPortletBridge/actionUrl/do/nothitg";
+ }
public String encodeResourceURL(String url) {
return getPortletResponse().encodeURL(url);
@@ -317,10 +330,6 @@
if (null == url) {
throw new NullPointerException("Path to redirect is null");
}
- if (!(getRequest() instanceof ActionRequest && getResponse() instanceof
ActionResponse)) {
- throw new IllegalStateException(
- "Redirect to new url not at action phase");
- }
((ActionResponse) getResponse()).sendRedirect(url);
}
}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java 2007-10-30
23:16:49 UTC (rev 3628)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -3,17 +3,30 @@
*/
package org.ajax4jsf.portlet.context;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Pattern;
+import javax.faces.FacesException;
import javax.faces.render.ResponseStateManager;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
import javax.portlet.faces.Bridge;
import org.ajax4jsf.portlet.application.PortletViewState;
@@ -24,6 +37,29 @@
*/
public class PortletRenderContextImpl extends PortletContextImpl {
+ public String getResponseCharacterEncoding() {
+ RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+ return renderResponse.getCharacterEncoding();
+ }
+
+ public String getResponseContentType() {
+ RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+ return renderResponse.getContentType();
+ }
+
+ public void setRequestCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException {
+ // Do nothing.
+ }
+
+ public String getRequestCharacterEncoding() {
+ return null;
+ }
+
+ protected String getNamespace() {
+ return ((RenderResponse)getPortletResponse()).getNamespace();
+ }
+
private Map<String, String[]> _requestParameters;
public PortletRenderContextImpl(PortletContext context,
@@ -49,6 +85,43 @@
}
}
+ @Override
+ public void redirect(String url) throws IOException {
+ throw new IllegalStateException(
+ "Redirect to new url not at action phase");
+ }
+
+
+ @Override
+ protected String createActionUrl(Map parameters) {
+ RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+ PortletURL portletURL = renderResponse.createActionURL();
+ portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
renderResponse.getNamespace());
+ for (Iterator<Entry<String, String>> param =
parameters.entrySet().iterator(); param.hasNext();) {
+ Entry<String, String> parameter = param.next();
+ portletURL.setParameter(parameter.getKey(), parameter.getValue());
+ }
+ return portletURL.toString();
+ }
+
+ public void dispatch(String path) throws IOException {
+ if (null == path) {
+ throw new NullPointerException("Path to new view is null");
+ }
+ PortletRequestDispatcher dispatcher = getPortletContext()
+ .getRequestDispatcher(path);
+ if (null == dispatcher) {
+ throw new IllegalStateException(
+ "Dispatcher for render request is not created");
+ }
+ try {
+ dispatcher.include((RenderRequest) getRequest(),
+ (RenderResponse) getResponse());
+ } catch (PortletException e) {
+ throw new FacesException(e);
+ }
+ }
+
/**
* @return
*/
Modified: trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml
===================================================================
--- trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml 2007-10-30
23:16:49 UTC (rev 3628)
+++ trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml 2007-10-31
00:58:31 UTC (rev 3629)
@@ -11,17 +11,11 @@
org.ajax4jsf.portlet.context.FacesContextFactoryImpl
</faces-context-factory>
</factory>
-<lifecycle>
-
<phase-listener>org.ajax4jsf.portlet.lifecycle.PortalPhaseListener</phase-listener>
-</lifecycle>
- <managed-bean>
- <managed-bean-name>ajaxContext</managed-bean-name>
- <managed-bean-class>
- org.ajax4jsf.portlet.PortletAjaxContext
- </managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
-
+ <lifecycle>
+ <phase-listener>
+ org.ajax4jsf.portlet.lifecycle.PortalPhaseListener
+ </phase-listener>
+ </lifecycle>
<render-kit>
<renderer>
Added:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortalActionUrlTest.java
===================================================================
---
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortalActionUrlTest.java
(rev 0)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortalActionUrlTest.java 2007-10-31
00:58:31 UTC (rev 3629)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortalActionUrlTest extends TestCase {
+
+ /**
+ * @param name
+ */
+ public PortalActionUrlTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testActionUrl() throws Exception {
+ PortalActionURL url = new
PortalActionURL("ftp://foo.bar:90/some/path/index.jsf?a=b&cd=ef");
+ assertEquals("ftp:", url.getProtocol());
+ assertEquals("//foo.bar", url.getHost());
+ assertEquals(90, url.getPort());
+ assertEquals("/some/path/index.jsf", url.getPath());
+ assertEquals("a=b&cd=ef", url.getQueryString());
+ }
+ public void testActionUrl1() throws Exception {
+ PortalActionURL url = new
PortalActionURL("//foo.bar:90/some/path/index.jsf?a=b&cd=ef");
+ assertNull( url.getProtocol());
+ assertEquals("//foo.bar", url.getHost());
+ assertEquals(90, url.getPort());
+ assertEquals("/some/path/index.jsf", url.getPath());
+ assertEquals("a=b&cd=ef", url.getQueryString());
+ }
+ public void testActionUrl2() throws Exception {
+ PortalActionURL url = new
PortalActionURL("//foo.bar/some/path/index.jsf?a=b&cd=ef");
+ assertNull( url.getProtocol());
+ assertEquals("//foo.bar", url.getHost());
+ assertEquals(-1, url.getPort());
+ assertEquals("/some/path/index.jsf", url.getPath());
+ assertEquals("a=b&cd=ef", url.getQueryString());
+ }
+ public void testActionUrl3() throws Exception {
+ PortalActionURL url = new
PortalActionURL("/some/path/index.jsf?a=b&cd=ef");
+ assertNull( url.getProtocol());
+ assertNull( url.getHost());
+ assertEquals(-1, url.getPort());
+ assertEquals("/some/path/index.jsf", url.getPath());
+ assertEquals("a=b&cd=ef", url.getQueryString());
+ }
+ public void testActionUrl4() throws Exception {
+ PortalActionURL url = new PortalActionURL("/some/path/index.jsf");
+ assertNull( url.getProtocol());
+ assertNull( url.getHost());
+ assertEquals(-1, url.getPort());
+ assertEquals("/some/path/index.jsf", url.getPath());
+ assertNull( url.getQueryString());
+ }
+
+ public void testParseQueryString() throws Exception {
+ PortalActionURL url = new
PortalActionURL("/some/path/index.jsf?a=b&cd=ef");
+ assertEquals(2, url.parametersSize());
+ assertEquals("b", url.getParameter("a"));
+ assertEquals("ef", url.getParameter("cd"));
+ assertNull(url.getParameter("xxx"));
+ }
+ public void testParseQueryString1() throws Exception {
+ PortalActionURL url = new PortalActionURL("/some/path/index.jsf?a=b");
+ assertEquals(1, url.parametersSize());
+ assertEquals("b", url.getParameter("a"));
+ assertNull(url.getParameter("cd"));
+ }
+}
Property changes on:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortalActionUrlTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author