You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2015/02/16 16:55:02 UTC
[20/22] portals-pluto git commit: Some restructuring & clean up work
Some restructuring & clean up work
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/aef314f7
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/aef314f7
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/aef314f7
Branch: refs/heads/V3Prototype
Commit: aef314f75b82533ed38e799922f576a19cd4daa3
Parents: 40d76d3
Author: Scott Nicklous <ms...@apache.org>
Authored: Sun Feb 15 22:28:24 2015 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Sun Feb 15 22:28:24 2015 +0100
----------------------------------------------------------------------
.../pluto/container/PortletURLProvider.java | 5 -
.../container/PortletURLProviderImpl.java | 188 +++-------------
.../driver/url/impl/RelativePortalURLImpl.java | 218 +++++++------------
.../pluto/driver/core/PortalRequestContext.java | 8 -
.../org/apache/pluto/driver/url/PortalURL.java | 9 -
.../driver/url/PortletParameterFactory.java | 169 ++++++++++++++
6 files changed, 275 insertions(+), 322 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-container-api/src/main/java/org/apache/pluto/container/PortletURLProvider.java
----------------------------------------------------------------------
diff --git a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletURLProvider.java b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletURLProvider.java
index 330ad1a..ae211ca 100644
--- a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletURLProvider.java
+++ b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletURLProvider.java
@@ -86,11 +86,6 @@ public interface PortletURLProvider {
* @return
*/
boolean isPublicRenderParameter(String windowId, String name);
-
- /**
- * Clears public render parameters except those that are marked for removal.
- */
- void clearPublicRenderParameters();
/**
* Retrieves the available private parameter names for the given window ID
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
index 5b42263..81bdedf 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,6 +39,7 @@ import org.apache.pluto.driver.url.PortalURL;
import org.apache.pluto.driver.url.PortalURL.URLType;
import org.apache.pluto.driver.url.PortalURLParameter;
import org.apache.pluto.driver.url.PortalURLPublicParameter;
+import org.apache.pluto.driver.url.PortletParameterFactory;
/**
*
@@ -48,23 +48,14 @@ public class PortletURLProviderImpl implements PortletURLProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(PortletURLProviderImpl.class);
private static final boolean isDebug = LOGGER.isDebugEnabled();
private static final boolean isTrace = LOGGER.isTraceEnabled();
-
- private final static HashMap<PortalURL.URLType, String> urlTypeMap =
- new HashMap<PortalURL.URLType, String>();
- static {
- urlTypeMap.put(URLType.Action, PortalURLParameter.PARAM_TYPE_ACTION);
- urlTypeMap.put(URLType.Render, PortalURLParameter.PARAM_TYPE_RENDER);
- urlTypeMap.put(URLType.Resource, PortalURLParameter.PARAM_TYPE_RESOURCE);
- }
private final PortalURL url;
+ private final PortletParameterFactory paramFactory;
private final TYPE type;
private final String window;
private Map<String, List<String>> properties;
- private final Set<PortalURLPublicParameter> prpSet = new HashSet<PortalURLPublicParameter>();
-
// Hack: called to force class loading in Container thread
protected static final void load() {
if (isDebug) {
@@ -77,6 +68,7 @@ public class PortletURLProviderImpl implements PortletURLProvider {
this.url = url.clone();
this.type = type;
this.window = portletWindow.getId().getStringId();
+ this.paramFactory = url.getPortletParameterFactory();
if (isDebug) {
StringBuilder txt = new StringBuilder("Constructing PortalURLProviderImpl. ");
@@ -237,175 +229,53 @@ public class PortletURLProviderImpl implements PortletURLProvider {
return properties;
}
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#addPublicRenderParameter(java.lang.String, java.lang.String, java.lang.String[])
+ */
public void addPublicRenderParameter(String windowId, String name, String[] values) {
- PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Add PRP. Window: ");
- txt.append(windowId).append(", name: ").append(name)
- .append(", values = ").append(Arrays.toString(values));
- LOGGER.debug(txt.toString());
- }
- int index = prpMapper.getIndex(windowId, name);
- if (index >= 0) {
- prpMapper.setValues(index, values);
- } else {
- StringBuilder txt = new StringBuilder(
- "Public render parameter for window: ");
- txt.append(windowId).append(", name: ").append(name)
- .append(" not found in mapper");
- LOGGER.warn(txt.toString());
- }
+ paramFactory.addPublicRenderParameter(windowId, name, values);
}
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#removePublicRenderParameter(java.lang.String, java.lang.String)
+ */
public void removePublicRenderParameter(String windowId, String name) {
- PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Remove PRP. Window: ");
- txt.append(windowId).append(", name: ").append(name);
- LOGGER.debug(txt.toString());
- }
- int index = prpMapper.getIndex(windowId, name);
- if (index >= 0) {
- prpMapper.setRemoved(index, true);
- } else {
- StringBuilder txt = new StringBuilder("Public render parameter for window: ");
- txt.append(windowId).append(", name: ").append(name)
- .append(" not found in mapper");
- LOGGER.warn(txt.toString());
- }
+ paramFactory.removePublicRenderParameter(windowId, name);
}
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#isPublicRenderParameter(java.lang.String, java.lang.String)
+ */
public boolean isPublicRenderParameter(String windowId, String name) {
- PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
- if (isDebug) {
- StringBuilder txt = new StringBuilder(
- "isPublicRenderParameter Window: ");
- txt.append(windowId).append(", name: ").append(name);
- LOGGER.debug(txt.toString());
- }
- int index = prpMapper.getIndex(windowId, name);
- return (index >= 0);
+ return paramFactory.isPublicRenderParameter(windowId, name);
}
- /**
- * Clear public render parameters except those marked for removal
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#getPrivateParameterNames(java.lang.String)
*/
- public void clearPublicRenderParameters() {
- for (PortalURLPublicParameter prp : prpSet) {
- if (!prp.isRemoved()) {
- prpSet.remove(prp);
- }
- }
- }
-
- // This method is for V2 compatibility. It always returns the private
- // parameter names for the active URL type - Render parameters for a render URL,
- // Action parameters for an action URL, and resouce parameters for a Resource URL.
public Set<String> getPrivateParameterNames(String windowId) {
- HashSet<String> names = new HashSet<String>();
- String type = urlTypeMap.get(url.getType());
-
- for (PortalURLParameter p : url.getParameters()) {
- if (p.getWindowId().equals(windowId) && p.getType().equals(type)) {
- names.add(p.getName());
- }
- }
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder();
- txt.append("Window ID: ").append(windowId);
- txt.append(", URL / Parameter type: ").append(type);
- txt.append(", names: ").append(names.toString());
- LOGGER.debug(txt.toString());
- }
-
- return names;
+ return paramFactory.getPrivateParameterNames(windowId);
}
- // This method is for V2 compatibility. It always returns the private
- // parameter values for the active URL type - Render parameters for a render URL,
- // Action parameters for an action URL, and resouce parameters for a Resource URL.
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#getParameterValues(java.lang.String, java.lang.String)
+ */
public String[] getParameterValues(String windowId, String name) {
- PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
- String type = urlTypeMap.get(url.getType());
- String[] vals = null;
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Setting ");
- txt.append("name: ").append(name);
- txt.append(", URL / Parameter type: ").append(type);
- txt.append(", window ID: ").append(windowId);
- LOGGER.debug(txt.toString());
- }
-
- if (isPublicRenderParameter(windowId, name)) {
- int index = prpMapper.getIndex(windowId, name);
- if (index >= 0) {
- vals = prpMapper.getValues(index).clone();
- } else {
- LOGGER.debug("Public render parameter name not found in index.");
- }
- } else {
- for (PortalURLParameter p : url.getParameters()) {
- if (p.getWindowId().equals(windowId)
- && p.getName().equals(name) && p.getType().equals(type)) {
- vals = p.getValues().clone();
- }
- }
- }
-
- return vals;
+ return paramFactory.getParameterValues(windowId, name);
}
- /**
- * Sets a parameter. This method sets a parameter
- * of type corresponding to the URL type - Action parameter for an Action URL, etc.
- * V2 compatibility method.
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#setParameter(java.lang.String, java.lang.String, java.lang.String[])
*/
public void setParameter(String windowId, String name, String[] values) {
- String type = urlTypeMap.get(url.getType());
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Setting ");
- txt.append("name: ").append(name);
- txt.append(", values: ").append(Arrays.toString(values));
- txt.append(", type: ").append(type);
- txt.append(", window ID: ").append(windowId);
- LOGGER.debug(txt.toString());
- }
-
- if (url.getType() == URLType.Render && isPublicRenderParameter(windowId, name)) {
- addPublicRenderParameter(windowId, name, values);
- } else {
- if (urlTypeMap.containsKey(url.getType())) {
- PortalURLParameter pup = new PortalURLParameter(windowId, name, values, type);
- url.setParameter(pup);
- } else {
- LOGGER.warn("Unsupported URL / Parameter type: " + url.getType());
- }
- }
+ paramFactory.setParameter(windowId, name, values);
}
- /**
- * Remove parameter. If the parameter is a public render parameter,
- * an <code>IllegalArgumentException</code> is thrown. This method removes a parameter
- * of type corresponding to the URL type - Action parameter for an Action URL, etc.
- * (V3 Spec errata)
+ /* (non-Javadoc)
+ * @see org.apache.pluto.container.PortletURLProvider#removeParameter(java.lang.String, java.lang.String)
*/
public void removeParameter(String windowId, String name) {
- String type = urlTypeMap.get(url.getType());
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Removing ");
- txt.append("name: ").append(name);
- txt.append(", type: ").append(type);
- txt.append(", window ID: ").append(windowId);
- LOGGER.debug(txt.toString());
- }
- if (isPublicRenderParameter(windowId, name)) {
- throw new IllegalArgumentException("Cannot set a public render parameter to null. Parameter name: " + name);
- } else {
- PortalURLParameter pup = new PortalURLParameter(windowId, name, null, type);
- url.removeParameter(pup);
- }
+ paramFactory.removeParameter(windowId, name);
}
+
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
index 1655bf0..74a67a0 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
@@ -212,49 +212,6 @@ public class RelativePortalURLImpl implements PortalURL {
return renderPath;
}
- protected void addParameter(PortalURLParameter param) {
- if (isDebug) {
- StringBuilder txt = new StringBuilder(
- "Adding private parameter: ");
- txt.append(" window ID: " + param.getWindowId());
- txt.append(", Name: " + param.getName());
- String vals = (param.getValues() == null)
- ? "null" : Arrays.toString(param.getValues());
- txt.append(", Values: " + vals);
- txt.append(", Type: " + param.getType());
- txt.append(", Clone ID: " + cloneId);
- LOG.debug(txt.toString());
- }
-
- // If present, remove old value before adding new
- if (parameters.contains(param)) {
- parameters.remove(param);
- }
- parameters.add(param);
- }
-
- public void setParameter(PortalURLParameter param) {
- handleServletRequestParams();
- if (isDebug) {
- StringBuilder txt = new StringBuilder(
- "Setting private parameter: ");
- txt.append(" window ID: " + param.getWindowId());
- txt.append(", Name: " + param.getName());
- String vals = (param.getValues() == null)
- ? "null" : Arrays.toString(param.getValues());
- txt.append(", Values: " + vals);
- txt.append(", Type: " + param.getType());
- txt.append(", Clone ID: " + cloneId);
- LOG.debug(txt.toString());
- }
-
- // If present, remove old value before adding new
- if (parameters.contains(param)) {
- parameters.remove(param);
- }
- parameters.add(param);
- }
-
public Collection<PortalURLParameter> getParameters() {
handleServletRequestParams();
return parameters;
@@ -307,27 +264,6 @@ public class RelativePortalURLImpl implements PortalURL {
this.windowStates.put(windowId, windowState);
}
- /**
- * Clear parameters of the specified window.
- *
- * @param windowId
- * the window ID.
- */
- public void clearParameters(String windowId) {
- HashSet<PortalURLParameter> rem = new HashSet<PortalURLParameter>();
- for (PortalURLParameter p : parameters) {
- if (p.getWindowId().equals(windowId)) {
- rem.add(p);
- }
- }
- if (isDebug) {
- StringBuilder txt = new StringBuilder("Removing ");
- txt.append(rem.size()).append(" elements. Window ID: ").append(windowId);
- LOG.debug(txt.toString());
- }
- parameters.removeAll(rem);
- }
-
public void setCacheability(String cacheLevel) {
this.cacheLevel = cacheLevel;
}
@@ -431,7 +367,7 @@ public class RelativePortalURLImpl implements PortalURL {
portalURL.cloneId = ++cloneCtr;
- if (isDebug) {
+ if (isTrace) {
long tid = Thread.currentThread().getId();
StringBuilder txt = new StringBuilder();
txt.append("Created clone ID= ").append(portalURL.cloneId);
@@ -444,7 +380,7 @@ public class RelativePortalURLImpl implements PortalURL {
public PageConfig getPageConfig(ServletContext servletContext) {
String requestedPageId = getRenderPath();
- if (isDebug) {
+ if (isTrace) {
LOG.debug("Requested Page: " + requestedPageId);
}
@@ -459,82 +395,9 @@ public class RelativePortalURLImpl implements PortalURL {
return paco;
}
- public synchronized void merge(PortalURL url, String windowId) {
- if (isDebug) {
- if (url.getClass().isInstance(this)) {
- long tid = Thread.currentThread().getId();
- RelativePortalURLImpl turl = (RelativePortalURLImpl) url;
- StringBuilder txt = new StringBuilder();
- txt.append("Merging URL with clone ID= ").append(turl.cloneId);
- txt.append(" into URL with clone ID= ").append(cloneId);
- txt.append(". ThreadId=").append(tid);
- LOG.debug(txt.toString());
- }
- }
- type = url.getType();
- targetWindow = url.getTargetWindow();
- setPortletMode(windowId, url.getPortletMode(windowId));
- setWindowState(windowId, url.getWindowState(windowId));
- setCacheability(url.getCacheability());
- setResourceID(url.getResourceID());
- clearParameters(windowId);
- for (PortalURLParameter param : url.getParameters()) {
- if (windowId.equals(param.getWindowId())) {
- addParameter(param.clone());
- }
- }
- PublicRenderParameterMapper prpm = url.getPublicRenderParameterMapper();
- List<Integer> activePrps = prpm.getActiveIndexes();
- for (int ii = 0; ii < prpm.getNumberOfGroups(); ii++) {
- if (activePrps.contains(ii)) {
- prpMapper.setValues(ii, prpm.getValues(ii));
- } else {
- prpMapper.setRemoved(ii, true);
- }
- }
- }
-
- public void addPublicRenderParameter(PortalURLPublicParameter pup) {
- handleServletRequestParams();
- if (isDebug) {
- StringBuilder txt = new StringBuilder(
- "Setting public render parameter: ");
- txt.append(" window ID: " + pup.getWindowId());
- txt.append(", Name: " + pup.getName());
- txt.append(", QName: " + pup.getQName());
- txt.append(", Values: " + Arrays.toString(pup.getValues()));
- LOG.debug(txt.toString());
- }
- int ind = prpMapper.getIndex(pup);
- if (ind >= 0) {
- if (pup.isRemoved()) {
- prpMapper.setRemoved(ind, true);
- } else {
- prpMapper.setValues(ind, pup.getValues());
- }
- } else {
- StringBuilder txt = new StringBuilder(
- "Public render parameter is not contained in mapper.");
- txt.append(" window ID: " + pup.getWindowId());
- txt.append(", Name: " + pup.getName());
- txt.append(", QName: " + pup.getQName());
- txt.append(", Values: " + Arrays.toString(pup.getValues()));
- LOG.warn(txt.toString());
- }
- }
-
- public void setPublicRenderParameterMapper(PublicRenderParameterMapper prpm) {
- prpMapper = prpm;
- }
-
- public PublicRenderParameterMapper getPublicRenderParameterMapper() {
- handleServletRequestParams();
- return prpMapper;
- }
-
public void setPortletIds(Collection<String> portletIds) {
this.portletIds.addAll(portletIds);
- if (isDebug) {
+ if (isTrace) {
LOG.debug("Stored " + this.portletIds.size() + " IDs: "
+ Arrays.toString(this.portletIds.toArray()));
}
@@ -613,6 +476,27 @@ public class RelativePortalURLImpl implements PortalURL {
return targetWindow;
}
+ /**
+ * Clear parameters of the specified window.
+ *
+ * @param windowId
+ * the window ID.
+ */
+ public void clearParameters(String windowId) {
+ HashSet<PortalURLParameter> rem = new HashSet<PortalURLParameter>();
+ for (PortalURLParameter p : parameters) {
+ if (p.getWindowId().equals(windowId)) {
+ rem.add(p);
+ }
+ }
+ if (isTrace) {
+ StringBuilder txt = new StringBuilder("Removing ");
+ txt.append(rem.size()).append(" elements. Window ID: ").append(windowId);
+ LOG.debug(txt.toString());
+ }
+ parameters.removeAll(rem);
+ }
+
/*
* (non-Javadoc)
*
@@ -629,7 +513,7 @@ public class RelativePortalURLImpl implements PortalURL {
rem.add(pup);
}
}
- if (isDebug) {
+ if (isTrace) {
StringBuilder txt = new StringBuilder("Removing ");
txt.append(rem.size()).append(" elements. Window ID: ").append(window);
LOG.debug(txt.toString());
@@ -637,11 +521,63 @@ public class RelativePortalURLImpl implements PortalURL {
parameters.removeAll(rem);
}
+ protected void addParameter(PortalURLParameter param) {
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder(
+ "Adding private parameter: ");
+ txt.append(" window ID: " + param.getWindowId());
+ txt.append(", Name: " + param.getName());
+ String vals = (param.getValues() == null)
+ ? "null" : Arrays.toString(param.getValues());
+ txt.append(", Values: " + vals);
+ txt.append(", Type: " + param.getType());
+ txt.append(", Clone ID: " + cloneId);
+ LOG.debug(txt.toString());
+ }
+
+ // If present, remove old value before adding new
+ if (parameters.contains(param)) {
+ parameters.remove(param);
+ }
+ parameters.add(param);
+ }
+
+ public void setParameter(PortalURLParameter param) {
+ handleServletRequestParams();
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder(
+ "Setting private parameter: ");
+ txt.append(" window ID: " + param.getWindowId());
+ txt.append(", Name: " + param.getName());
+ String vals = (param.getValues() == null)
+ ? "null" : Arrays.toString(param.getValues());
+ txt.append(", Values: " + vals);
+ txt.append(", Type: " + param.getType());
+ txt.append(", Clone ID: " + cloneId);
+ LOG.debug(txt.toString());
+ }
+
+ // If present, remove old value before adding new
+ if (parameters.contains(param)) {
+ parameters.remove(param);
+ }
+ parameters.add(param);
+ }
+
public PortletParameterFactory getPortletParameterFactory() {
handleServletRequestParams();
return new PortletParameterFactory(this);
}
+ public void setPublicRenderParameterMapper(PublicRenderParameterMapper prpm) {
+ prpMapper = prpm;
+ }
+
+ public PublicRenderParameterMapper getPublicRenderParameterMapper() {
+ handleServletRequestParams();
+ return prpMapper;
+ }
+
public void removeParameter(PortalURLParameter param) {
handleServletRequestParams();
if (isDebug) {
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalRequestContext.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalRequestContext.java b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalRequestContext.java
index 4be17d2..fab553b 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalRequestContext.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalRequestContext.java
@@ -132,14 +132,6 @@ public class PortalRequestContext {
public synchronized void mergePortalURL(PortalURL portalURL, String windowId){
requestedPortalURL = portalURL;
-// if (requestedPortalURL == null)
-// {
-// requestedPortalURL = portalURL;
-// }
-// else
-// {
-// requestedPortalURL.merge(portalURL, windowId);
-// }
}
public ServletContext getServletContext() {
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
index caa123c..20a3b9b 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
@@ -89,13 +89,6 @@ public interface PortalURL extends Cloneable {
public void removePublicRenderParameter(PortalURLPublicParameter param);
/**
- * Adds a new public render parameter.
- *
- * @param pup
- */
- public void addPublicRenderParameter(PortalURLPublicParameter pup);
-
- /**
* Add the PRP mapper for the page being processed
* @param prpm
*/
@@ -180,8 +173,6 @@ public interface PortalURL extends Cloneable {
void setResourceID(String resourceID);
String getResourceID();
- void merge(PortalURL url, String windowId);
-
/**
* @param window
*/
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/aef314f7/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortletParameterFactory.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortletParameterFactory.java b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortletParameterFactory.java
index dbcb7ec..a872478 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortletParameterFactory.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortletParameterFactory.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.pluto.driver.services.portal.PublicRenderParameterMapper;
import org.apache.pluto.driver.url.PortalURL.URLType;
@@ -55,6 +56,14 @@ public class PortletParameterFactory {
actionTypes.add(URLType.PartialAction);
}
+ private final static HashMap<PortalURL.URLType, String> urlTypeMap =
+ new HashMap<PortalURL.URLType, String>();
+ static {
+ urlTypeMap.put(URLType.Action, PortalURLParameter.PARAM_TYPE_ACTION);
+ urlTypeMap.put(URLType.Render, PortalURLParameter.PARAM_TYPE_RENDER);
+ urlTypeMap.put(URLType.Resource, PortalURLParameter.PARAM_TYPE_RESOURCE);
+ }
+
public PortletParameterFactory(PortalURL url) {
this.url = url;
}
@@ -198,4 +207,164 @@ public class PortletParameterFactory {
return parameters;
}
+ public void addPublicRenderParameter(String windowId, String name, String[] values) {
+ PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder("Add PRP. Window: ");
+ txt.append(windowId).append(", name: ").append(name)
+ .append(", values = ").append(Arrays.toString(values));
+ LOGGER.debug(txt.toString());
+ }
+ int index = prpMapper.getIndex(windowId, name);
+ if (index >= 0) {
+ prpMapper.setValues(index, values);
+ } else {
+ StringBuilder txt = new StringBuilder(
+ "Public render parameter for window: ");
+ txt.append(windowId).append(", name: ").append(name)
+ .append(" not found in mapper");
+ LOGGER.warn(txt.toString());
+ }
+ }
+
+ public void removePublicRenderParameter(String windowId, String name) {
+ PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder("Remove PRP. Window: ");
+ txt.append(windowId).append(", name: ").append(name);
+ LOGGER.debug(txt.toString());
+ }
+ int index = prpMapper.getIndex(windowId, name);
+ if (index >= 0) {
+ prpMapper.setRemoved(index, true);
+ } else {
+ StringBuilder txt = new StringBuilder("Public render parameter for window: ");
+ txt.append(windowId).append(", name: ").append(name)
+ .append(" not found in mapper");
+ LOGGER.warn(txt.toString());
+ }
+ }
+
+ public boolean isPublicRenderParameter(String windowId, String name) {
+ PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder(
+ "isPublicRenderParameter Window: ");
+ txt.append(windowId).append(", name: ").append(name);
+ LOGGER.debug(txt.toString());
+ }
+ int index = prpMapper.getIndex(windowId, name);
+ return (index >= 0);
+ }
+
+ // This method is for V2 compatibility. It always returns the private
+ // parameter names for the active URL type - Render parameters for a render URL,
+ // Action parameters for an action URL, and resouce parameters for a Resource URL.
+ public Set<String> getPrivateParameterNames(String windowId) {
+ HashSet<String> names = new HashSet<String>();
+ String type = urlTypeMap.get(url.getType());
+
+ for (PortalURLParameter p : url.getParameters()) {
+ if (p.getWindowId().equals(windowId) && p.getType().equals(type)) {
+ names.add(p.getName());
+ }
+ }
+
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder();
+ txt.append("Window ID: ").append(windowId);
+ txt.append(", URL / Parameter type: ").append(type);
+ txt.append(", names: ").append(names.toString());
+ LOGGER.debug(txt.toString());
+ }
+
+ return names;
+ }
+
+ // This method is for V2 compatibility. It always returns the private
+ // parameter values for the active URL type - Render parameters for a render URL,
+ // Action parameters for an action URL, and resouce parameters for a Resource URL.
+ public String[] getParameterValues(String windowId, String name) {
+ PublicRenderParameterMapper prpMapper = url.getPublicRenderParameterMapper();
+ String type = urlTypeMap.get(url.getType());
+ String[] vals = null;
+
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder("Setting ");
+ txt.append("name: ").append(name);
+ txt.append(", URL / Parameter type: ").append(type);
+ txt.append(", window ID: ").append(windowId);
+ LOGGER.debug(txt.toString());
+ }
+
+ if (isPublicRenderParameter(windowId, name)) {
+ int index = prpMapper.getIndex(windowId, name);
+ if (index >= 0) {
+ vals = prpMapper.getValues(index).clone();
+ } else {
+ LOGGER.debug("Public render parameter name not found in index.");
+ }
+ } else {
+ for (PortalURLParameter p : url.getParameters()) {
+ if (p.getWindowId().equals(windowId)
+ && p.getName().equals(name) && p.getType().equals(type)) {
+ vals = p.getValues().clone();
+ }
+ }
+ }
+
+ return vals;
+ }
+
+ /**
+ * Sets a parameter. This method sets a parameter
+ * of type corresponding to the URL type - Action parameter for an Action URL, etc.
+ * V2 compatibility method.
+ */
+ public void setParameter(String windowId, String name, String[] values) {
+ String type = urlTypeMap.get(url.getType());
+
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder("Setting ");
+ txt.append("name: ").append(name);
+ txt.append(", values: ").append(Arrays.toString(values));
+ txt.append(", type: ").append(type);
+ txt.append(", window ID: ").append(windowId);
+ LOGGER.debug(txt.toString());
+ }
+
+ if (url.getType() == URLType.Render && isPublicRenderParameter(windowId, name)) {
+ addPublicRenderParameter(windowId, name, values);
+ } else {
+ if (urlTypeMap.containsKey(url.getType())) {
+ PortalURLParameter pup = new PortalURLParameter(windowId, name, values, type);
+ url.setParameter(pup);
+ } else {
+ LOGGER.warn("Unsupported URL / Parameter type: " + url.getType());
+ }
+ }
+ }
+
+ /**
+ * Remove parameter. If the parameter is a public render parameter,
+ * an <code>IllegalArgumentException</code> is thrown. This method removes a parameter
+ * of type corresponding to the URL type - Action parameter for an Action URL, etc.
+ * (V3 Spec errata)
+ */
+ public void removeParameter(String windowId, String name) {
+ String type = urlTypeMap.get(url.getType());
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder("Removing ");
+ txt.append("name: ").append(name);
+ txt.append(", type: ").append(type);
+ txt.append(", window ID: ").append(windowId);
+ LOGGER.debug(txt.toString());
+ }
+ if (isPublicRenderParameter(windowId, name)) {
+ throw new IllegalArgumentException("Cannot set a public render parameter to null. Parameter name: " + name);
+ } else {
+ PortalURLParameter pup = new PortalURLParameter(windowId, name, null, type);
+ url.removeParameter(pup);
+ }
+ }
}