Author: julien_viet
Date: 2010-09-14 14:44:36 -0400 (Tue, 14 Sep 2010)
New Revision: 4194
Added:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/component/
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/component/ComponentLocatorPlugin.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRenderContext.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/application/UIComponentURLBuilder.java
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/url/ComponentLocator.java
portal/branches/navcontroller/webui/portal/src/main/java/conf/portal/configuration.xml
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalURLBuilder.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
Log:
use component locator for webui portal side
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -96,7 +96,10 @@
for (RequestParamDef requestParamDef : requestParamDefs.values())
{
String s = blah.get(requestParamDef.getName());
- renderContext.appendQueryParameter(requestParamDef.getMatchName(), s);
+ if (s != null)
+ {
+ renderContext.appendQueryParameter(requestParamDef.getMatchName(), s);
+ }
}
}
@@ -157,11 +160,14 @@
{
if (requestParamDef.matchValue(a))
{
- //
abc.remove(requestParamDef.name);
continue;
}
}
+ else if (!requestParamDef.isRequired())
+ {
+ continue;
+ }
return null;
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRenderContext.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRenderContext.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRenderContext.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -31,18 +31,23 @@
{
/** . */
- private StringBuilder sb = null;
+ private static final Map<String, String> EMPTY = Collections.emptyMap();
/** . */
- private Map<String, String> queryParams = Collections.emptyMap();
+ private StringBuilder sb;
+ /** . */
+ private Map<String, String> queryParams;
+
public SimpleRenderContext()
{
+ this(null);
}
public SimpleRenderContext(StringBuilder sb)
{
this.sb = sb;
+ this.queryParams = EMPTY;
}
public String getPath()
@@ -87,7 +92,7 @@
public void appendQueryParameter(String parameterName, String paramaterValue)
{
- if (queryParams.isEmpty())
+ if (queryParams == EMPTY)
{
queryParams = new HashMap<String, String>();
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -138,7 +138,6 @@
router.render(Collections.singletonMap(QualifiedName.parse("foo"),
"a"), renderContext1);
assertEquals("/a", renderContext1.getPath());
assertEquals(Collections.singletonMap("a", "a"),
renderContext1.getQueryParams());
-
SimpleRenderContext renderContext2 = new SimpleRenderContext();
router.render(expectedParameters, renderContext2);
assertEquals("/a/b", renderContext2.getPath());
@@ -157,6 +156,16 @@
//
assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.route("/", Collections.<String, String[]>emptyMap()));
assertEquals(Collections.singletonMap(QualifiedName.parse("foo"),
"a"), router.route("/", Collections.singletonMap("a", new
String[]{"a"})));
+
+ //
+ SimpleRenderContext renderContext1 = new SimpleRenderContext();
+ router.render(Collections.<QualifiedName, String>emptyMap(),
renderContext1);
+ assertEquals("/", renderContext1.getPath());
+ assertEquals(Collections.<String, String>emptyMap(),
renderContext1.getQueryParams());
+ SimpleRenderContext renderContext2 = new SimpleRenderContext();
+ router.render(Collections.singletonMap(QualifiedName.parse("foo"),
"a"), renderContext2);
+ assertEquals("/", renderContext2.getPath());
+ assertEquals(Collections.singletonMap("a", "a"),
renderContext2.getQueryParams());
}
}
Modified:
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml
===================================================================
---
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml 2010-09-14
18:44:36 UTC (rev 4194)
@@ -6,21 +6,17 @@
<route path="/public/{{gtn}sitename}{{gtn}path:.*}">
<param name="{gtn}handler" value="portal"/>
<param name="{gtn}access" value="public"/>
-<!--
<request-param name="{gtn}componentid"
matchName="portal:componentId" required="false"/>
<request-param name="{gtn}action" matchName="portal:action"
required="false"/>
<request-param name="{gtn}objectid" matchName="objectId"
required="false"/>
--->
</route>
<route path="/private/{{gtn}sitename}{{gtn}path:.*}">
<param name="{gtn}handler" value="portal"/>
<param name="{gtn}access" value="private"/>
-<!--
<request-param name="{gtn}componentid"
matchName="portal:componentId" required="false"/>
<request-param name="{gtn}action" matchName="portal:action"
required="false"/>
<request-param name="{gtn}objectid" matchName="objectId"
required="false"/>
--->
</route>
<route path="/upload">
Modified:
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/application/UIComponentURLBuilder.java
===================================================================
---
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/application/UIComponentURLBuilder.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/application/UIComponentURLBuilder.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -35,19 +35,12 @@
/** . */
private final ResourceURL<UIComponent, ComponentLocator> url;
-/*
public UIComponentURLBuilder(ResourceURL<UIComponent, ComponentLocator> url)
{
- this.url = url;
- }
-*/
+ super("foo");
- public UIComponentURLBuilder(String baseURL)
- {
- super(baseURL);
-
//
- url = null;
+ this.url = url;
}
@Override
@@ -74,9 +67,14 @@
//
locator.setAction(action);
locator.setTargetBeanId(targetBeanId);
- for (Parameter param : params)
+
+ //
+ if (params != null)
{
- locator.addParameter(param);
+ for (Parameter param : params)
+ {
+ locator.addParameter(param);
+ }
}
//
Modified:
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/url/ComponentLocator.java
===================================================================
---
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/url/ComponentLocator.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/framework/src/main/java/org/exoplatform/webui/url/ComponentLocator.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -59,18 +59,6 @@
this.parameters = new HashMap<QualifiedName, String>();
}
- private void setParameter(QualifiedName parameterName, String parameterValue)
- {
- if (parameterValue == null)
- {
- parameters.remove(parameterName);
- }
- else
- {
- parameters.put(parameterName, parameterValue);
- }
- }
-
public UIComponent getResource()
{
return resource;
@@ -78,7 +66,7 @@
public void setResource(UIComponent resource)
{
- setParameter(COMPONENT, resource != null ? resource.getId() : null);
+ setParameterValue(COMPONENT, resource != null ? resource.getId() : null);
//
this.resource = resource;
@@ -91,7 +79,7 @@
public void setAction(String action)
{
- setParameter(ACTION, action);
+ setParameterValue(ACTION, action);
}
public String getTargetBeanId()
@@ -101,7 +89,7 @@
public void setTargetBeanId(String targetBeanId)
{
- setParameter(TARGET, targetBeanId);
+ setParameterValue(TARGET, targetBeanId);
}
public void addParameter(Parameter param)
@@ -118,4 +106,16 @@
{
return parameters.get(parameterName);
}
+
+ public void setParameterValue(QualifiedName parameterName, String parameterValue)
+ {
+ if (parameterValue == null)
+ {
+ parameters.remove(parameterName);
+ }
+ else
+ {
+ parameters.put(parameterName, parameterValue);
+ }
+ }
}
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/conf/portal/configuration.xml
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/conf/portal/configuration.xml 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/portal/src/main/java/conf/portal/configuration.xml 2010-09-14
18:44:36 UTC (rev 4194)
@@ -46,6 +46,11 @@
<set-method>addPlugin</set-method>
<type>org.exoplatform.portal.url.navigation.NavigationLocatorPlugin</type>
</component-plugin>
+ <component-plugin>
+ <name>navigation.locator.plugin</name>
+ <set-method>addPlugin</set-method>
+
<type>org.exoplatform.portal.url.component.ComponentLocatorPlugin</type>
+ </component-plugin>
</component-plugins>
</component>
</configuration>
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -47,6 +47,7 @@
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.url.ComponentLocator;
import org.gatein.common.http.QueryStringParser;
import org.w3c.dom.Element;
@@ -260,8 +261,7 @@
}
//
- urlBuilder = new PortalURLBuilder(requestURI_);
-// urlBuilder = new PortalURLBuilder(createURL(ComponentLocator.TYPE));
+ urlBuilder = new PortalURLBuilder(this, createURL(ComponentLocator.TYPE));
}
@Override
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalURLBuilder.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalURLBuilder.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalURLBuilder.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -20,8 +20,10 @@
package org.exoplatform.portal.application;
import org.exoplatform.web.application.Parameter;
-import org.exoplatform.web.application.URLBuilder;
+import org.exoplatform.web.url.ResourceURL;
+import org.exoplatform.webui.application.UIComponentURLBuilder;
import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.url.ComponentLocator;
import java.net.URLEncoder;
@@ -29,14 +31,24 @@
* Created by The eXo Platform SAS
* Apr 3, 2007
*/
-public class PortalURLBuilder extends URLBuilder<UIComponent>
+public class PortalURLBuilder extends UIComponentURLBuilder
{
- public PortalURLBuilder(String baseURL)
+ public PortalURLBuilder(PortalRequestContext ctx, ResourceURL<UIComponent,
ComponentLocator> url)
{
- super(baseURL);
+ super(configure(ctx, url));
}
+ /*
+ * This is a hack.
+ */
+ private static ResourceURL<UIComponent, ComponentLocator>
configure(PortalRequestContext prc, ResourceURL<UIComponent, ComponentLocator> url)
+ {
+ String path = prc.getNodePath();
+ url.getResourceLocator().setParameterValue(PortalRequestHandler.REQUEST_PATH,
path);
+ return url;
+ }
+
@SuppressWarnings("unused")
public String createURL(String action, Parameter[] params)
{
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-14
16:47:03 UTC (rev 4193)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -91,12 +91,30 @@
}
//
+
+ //
if (ajax)
{
- buffer.append("javascript:ajaxGet('");
+ buffer.append("javascript:");
+ if (confirm != null && confirm.length() > 0)
+ {
+
buffer.append("if(confirm('").append(confirm.replaceAll("'",
"\\\\'")).append("'))");
+ }
+ buffer.append("ajaxGet('");
}
+ else
+ {
+ if (confirm != null && confirm.length() > 0)
+ {
+ // Need to find a way to make the confirm message appear
+ // I think we could use :
+ // 1/ the if(confirm('')) ...
+ // 2/ a call function that updates window.location
+ // for now it is disabled
+ }
+ }
- // julien : find out how to change the hardcoded "classic"
+ //
Map<QualifiedName, String> parameters = new HashMap<QualifiedName,
String>();
parameters.put(WebAppController.HANDLER_PARAM, "portal");
parameters.put(PortalRequestHandler.ACCESS, access);
@@ -113,9 +131,26 @@
requestContext.getControllerContext().renderURL(parameters, renderContext);
//
+ boolean questionMarkDone = false;
+ Map<String, String> queryParams = renderContext.getQueryParams();
+ System.out.println("queryParams = " + queryParams);
+ if (queryParams.size() > 0)
+ {
+ for (Map.Entry<String, String> entry : queryParams.entrySet())
+ {
+ buffer.append(questionMarkDone ? "&" : "?");
+ buffer.append(entry.getKey());
+ buffer.append('=');
+ buffer.append(entry.getValue());
+ questionMarkDone = true;
+ }
+ }
+
+ //
if (ajax)
{
- buffer.append("?ajaxRequest=true");
+ buffer.append(questionMarkDone ? "&" : "?");
+ buffer.append("ajaxRequest=true");
buffer.append("')");
}
Added:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/component/ComponentLocatorPlugin.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/component/ComponentLocatorPlugin.java
(rev 0)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/component/ComponentLocatorPlugin.java 2010-09-14
18:44:36 UTC (rev 4194)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.url.component;
+
+import org.exoplatform.portal.url.ResourceLocatorPlugin;
+import org.exoplatform.web.url.ResourceType;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.url.ComponentLocator;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ComponentLocatorPlugin extends ResourceLocatorPlugin<UIComponent,
ComponentLocator>
+{
+
+ @Override
+ protected ResourceType<UIComponent, ComponentLocator> getResourceType()
+ {
+ return ComponentLocator.TYPE;
+ }
+
+ @Override
+ protected ComponentLocator newLocator()
+ {
+ return new ComponentLocator();
+ }
+}