Author: julien_viet
Date: 2010-11-03 09:55:37 -0400 (Wed, 03 Nov 2010)
New Revision: 4920
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/MimeType.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
Log:
introduce MimeType enum for configuring the mimetype for which the URL should be generated
for
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java 2010-11-03
11:45:36 UTC (rev 4919)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java 2010-11-03
13:55:37 UTC (rev 4920)
@@ -47,6 +47,9 @@
/** . */
protected ParameterMap queryParams;
+ /** . */
+ protected MimeType mimeType;
+
/**
* Create a resource URL instance.
*
@@ -66,6 +69,7 @@
this.ajax = ajax;
this.confirm = null;
this.queryParams = null;
+ this.mimeType = null;
}
/**
@@ -144,6 +148,28 @@
return this;
}
+ /**
+ * Returns the current mime type that this URL will be generated for, or null if none
is set (which means
+ * there is no guarantees about the mime type that will be used as target but it's
likely to be {@link MimeType#XHTML}}).
+ *
+ * @return the current mime type
+ */
+ public MimeType getMimeType()
+ {
+ return mimeType;
+ }
+
+ /**
+ * Set the mime type on this URL. The mime type will be used when URL is generated to
encode the URL for the specified
+ * mime type.
+ *
+ * @param mimeType the new mime type
+ */
+ public void setMimeType(MimeType mimeType)
+ {
+ this.mimeType = mimeType;
+ }
+
public Map<String, String[]> getQueryParameters()
{
if (queryParams == null)
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/MimeType.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/MimeType.java
(rev 0)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/MimeType.java 2010-11-03
13:55:37 UTC (rev 4920)
@@ -0,0 +1,33 @@
+/*
+ * 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.web.url;
+
+/**
+ * A simple mime type enumeration that is used when a URL is generated.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public enum MimeType
+{
+
+ XHTML, PLAIN
+
+}
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-11-03
11:45:36 UTC (rev 4919)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-11-03
13:55:37 UTC (rev 4920)
@@ -26,8 +26,10 @@
import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.controller.router.SimpleRenderContext;
import org.exoplatform.web.url.ControllerURL;
+import org.exoplatform.web.url.MimeType;
import org.exoplatform.web.url.ResourceLocator;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
@@ -39,6 +41,15 @@
{
/** . */
+ private static final Map<MimeType, String> AMP_MAP = new EnumMap<MimeType,
String>(MimeType.class);
+
+ static
+ {
+ AMP_MAP.put(MimeType.XHTML, "&");
+ AMP_MAP.put(MimeType.PLAIN, "&");
+ }
+
+ /** . */
private final ControllerContext controllerContext;
/** . */
@@ -93,8 +104,6 @@
}
//
-
- //
if (ajax)
{
buffer.append("javascript:");
@@ -137,13 +146,21 @@
controllerContext.renderURL(parameters, renderContext);
//
+ MimeType mt = mimeType;
+ if (mt == null)
+ {
+ mt = MimeType.XHTML;
+ }
+ String amp = AMP_MAP.get(mt);
+
+ //
boolean questionMarkDone = false;
Map<String, String> queryParams = renderContext.getQueryParams();
if (queryParams.size() > 0)
{
for (Map.Entry<String, String> entry : queryParams.entrySet())
{
- buffer.append(questionMarkDone ? Constants.AMPERSAND :
org.exoplatform.portal.Constants.QMARK);
+ buffer.append(questionMarkDone ? amp : "?");
buffer.append(entry.getKey());
buffer.append('=');
buffer.append(entry.getValue());
@@ -156,7 +173,7 @@
{
for (String value : entry.getValue())
{
- buffer.append(questionMarkDone ? Constants.AMPERSAND :
org.exoplatform.portal.Constants.QMARK);
+ buffer.append(questionMarkDone ? amp : "?");
buffer.append(entry.getKey());
buffer.append("=");
buffer.append(value);
@@ -167,7 +184,7 @@
//
if (ajax)
{
- buffer.append(questionMarkDone ? Constants.AMPERSAND :
org.exoplatform.portal.Constants.QMARK);
+ buffer.append(questionMarkDone ? amp : "?");
buffer.append("ajaxRequest=true");
buffer.append("')");
}