JBoss Portal SVN: r10327 - in modules/portlet/trunk: portal and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-19 06:21:01 -0400 (Wed, 19 Mar 2008)
New Revision: 10327
Modified:
modules/portlet/trunk/controller/pom.xml
modules/portlet/trunk/portal/pom.xml
Log:
improved pom of portlet/portal that was using the wrong jar due to some odd dependency resolution mechanism
Modified: modules/portlet/trunk/controller/pom.xml
===================================================================
--- modules/portlet/trunk/controller/pom.xml 2008-03-19 09:31:44 UTC (rev 10326)
+++ modules/portlet/trunk/controller/pom.xml 2008-03-19 10:21:01 UTC (rev 10327)
@@ -33,7 +33,7 @@
<artifactId>portlet-portlet</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
- <!--<scope>test</scope>-->
+ <scope>test</scope>
</dependency>
<!--TEST SCOPE-->
Modified: modules/portlet/trunk/portal/pom.xml
===================================================================
--- modules/portlet/trunk/portal/pom.xml 2008-03-19 09:31:44 UTC (rev 10326)
+++ modules/portlet/trunk/portal/pom.xml 2008-03-19 10:21:01 UTC (rev 10327)
@@ -200,7 +200,6 @@
</execution>
</executions>
</plugin>
-
</plugins>
</build>
16 years, 3 months
JBoss Portal SVN: r10326 - modules/portlet/trunk.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-19 05:31:44 -0400 (Wed, 19 Mar 2008)
New Revision: 10326
Modified:
modules/portlet/trunk/pom.xml
Log:
renamed "simple-portal" profile to just "portal"
Modified: modules/portlet/trunk/pom.xml
===================================================================
--- modules/portlet/trunk/pom.xml 2008-03-19 09:21:14 UTC (rev 10325)
+++ modules/portlet/trunk/pom.xml 2008-03-19 09:31:44 UTC (rev 10326)
@@ -63,7 +63,7 @@
</modules>
</profile>
<profile>
- <id>simple-portal</id>
+ <id>portal</id>
<modules>
<module>build</module>
<module>portlet</module>
16 years, 3 months
JBoss Portal SVN: r10325 - modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-19 05:21:14 -0400 (Wed, 19 Mar 2008)
New Revision: 10325
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/ContentType.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java
Log:
minor update + javadoc update
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/ContentType.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/ContentType.java 2008-03-19 01:19:29 UTC (rev 10324)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/ContentType.java 2008-03-19 09:21:14 UTC (rev 10325)
@@ -28,25 +28,43 @@
import java.util.Iterator;
/**
+ * Represent a content type header value as defined by the section 5 of the
+ * <a href="http://tools.ietf.org/html/rfc2045#section-5">RFC2045</a>
+ *
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
* @version $Revision: 630 $
*/
public class ContentType
{
- public static ContentType create(String contentTypeValue)
+ /**
+ * Creates a content type header value by parsing a content type value. The content type value format is defined
+ * by the section 5.1 of the <a href="http://tools.ietf.org/html/rfc2045#section-5.1">RFC2045</a> but does not
+ * take in account the prefix "Content-Type" ":" of the content production rule of the grammar.
+ *
+ * @param contentTypeValue the content type value
+ * @return
+ * @throws IllegalArgumentException if the
+ */
+ public static ContentType create(String contentTypeValue) throws IllegalArgumentException
{
+ if (contentTypeValue == null)
+ {
+ throw new IllegalArgumentException("No null content type value accepted");
+ }
+
+ //
int slashIndex = contentTypeValue.indexOf('/');
-
if (slashIndex == -1)
{
-
+ throw new IllegalArgumentException("The content type " + contentTypeValue + " does not contain a /");
}
+ //
String typeName = contentTypeValue.substring(0, slashIndex);
+ //
int semiColonIndex = contentTypeValue.indexOf(';', slashIndex + 1);
-
if (semiColonIndex == -1)
{
return new ContentType(MediaType.create(typeName, contentTypeValue.substring(slashIndex + 1)));
@@ -62,6 +80,7 @@
//
List<Parameter> parameters = null;
+ //
for (int i = semiColonIndex + 1;semiColonIndex != -1;i = semiColonIndex + 1)
{
semiColonIndex = contentTypeValue.indexOf(';', i);
@@ -152,10 +171,16 @@
return parameters;
}
+ /**
+ * Returns the value of the content type which is the concatenation of the media type name
+ * followed by the parameters.
+ *
+ * @return the value
+ */
public String getValue()
{
StringBuilder builder = new StringBuilder();
- builder.append(mediaType.getType().getName()).append('/').append(mediaType.getSubtype().getName());
+ builder.append(mediaType.getValue());
for (Iterator<Parameter> i = parameters.iterator();;)
{
Parameter parameter = i.next();
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-19 01:19:29 UTC (rev 10324)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-19 09:21:14 UTC (rev 10325)
@@ -23,6 +23,8 @@
package org.jboss.portal.common.net.media;
/**
+ * An immutable media type class.
+ *
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
* @version $Revision: 630 $
*/
@@ -41,22 +43,18 @@
/** . */
public static final MediaType APPLICATION_X_WWW_FORM_URLENCODED = new MediaType(TypeDef.APPLICATION, SubtypeDef.X_WWW_FORM_URLENCODED);
- /** The type identifier. */
- private final TypeDef type;
-
- /** The sub type identifier. */
- private final SubtypeDef subtype;
-
- /** . */
- private volatile Integer hashCode;
-
- /** . */
- private volatile String toString;
-
- /** . */
- private volatile String value;
-
- public static MediaType create(String mediaTypeName)
+ /**
+ * Create a media type object by parsing a media type name. The media type name format is defined by the
+ * section 5.1 of the <a href="http://tools.ietf.org/html/rfc2045#section-5.1">RFC2045</a> but is limited
+ * to a subset of the grammar, the starting production rule being:
+ *
+ * media-type: type "/" subtype
+ *
+ * @param mediaTypeName the media type name value
+ * @return the media type object
+ * @throws IllegalArgumentException if the argument is null or is not valid
+ */
+ public static MediaType create(String mediaTypeName) throws IllegalArgumentException
{
if (mediaTypeName == null)
{
@@ -78,7 +76,15 @@
return create(typeName, subtypeName);
}
- public static MediaType create(String typeName, String subtypeName)
+ /**
+ * Create a media type object by using the provided type name and subtype name.
+ *
+ * @param typeName the type name
+ * @param subtypeName the subtype name
+ * @return the media type object
+ * @throws IllegalArgumentException if any argument is null or not valid
+ */
+ public static MediaType create(String typeName, String subtypeName) throws IllegalArgumentException
{
if (typeName == null)
{
@@ -103,7 +109,15 @@
return new MediaType(type, subtype);
}
- public static MediaType create(TypeDef type, SubtypeDef subtype)
+ /**
+ * Create a media type object using the provided type and subtype objects.
+ *
+ * @param type the type
+ * @param subtype the subtype
+ * @return the media type object
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public static MediaType create(TypeDef type, SubtypeDef subtype) throws IllegalArgumentException
{
if (type == null)
{
@@ -118,6 +132,21 @@
return new MediaType(type, subtype);
}
+ /** The type identifier. */
+ private final TypeDef type;
+
+ /** The sub type identifier. */
+ private final SubtypeDef subtype;
+
+ /** The cached hashCode. */
+ private volatile Integer hashCode;
+
+ /** the cached toString. */
+ private volatile String toString;
+
+ /** the cached value. */
+ private volatile String value;
+
MediaType(TypeDef type, SubtypeDef subtype)
{
this.type = type;
@@ -134,6 +163,11 @@
return subtype;
}
+ /**
+ * Returns the value which is a concatenation ofthe type name, a slash char and the subtype name.
+ *
+ * @return the value
+ */
public String getValue()
{
if (value == null)
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java 2008-03-19 01:19:29 UTC (rev 10324)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java 2008-03-19 09:21:14 UTC (rev 10325)
@@ -32,6 +32,8 @@
import java.util.Collections;
/**
+ * An implementation of the media type map interface.
+ *
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
* @version $Revision: 630 $
*/
16 years, 3 months
JBoss Portal SVN: r10324 - in branches/JBoss_Portal_2_6_3_JBPORTAL-1956: core/src/main/org/jboss/portal/core/model/portal/navstate and 3 other directories.
by portal-commits@lists.jboss.org
Author: mmillson
Date: 2008-03-18 21:19:29 -0400 (Tue, 18 Mar 2008)
New Revision: 10324
Added:
branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java
Modified:
branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/PortalConstants.java
branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
Log:
Fix Portal navigational state replication for [JBPORTAL-1952] and [JBPORTAL-1956].
Modified: branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
===================================================================
--- branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2008-03-19 01:11:08 UTC (rev 10323)
+++ branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2008-03-19 01:19:29 UTC (rev 10324)
@@ -162,7 +162,7 @@
return render;
}
- private static class ControllerActionContext extends AbstractActionContext
+ public static class ControllerActionContext extends AbstractActionContext
{
private InvokePortletCommandFactory cmdFactory;
private ControllerContext controllerContext;
@@ -199,7 +199,7 @@
}
}
- private static class ControllerRenderContext extends AbstractRenderContext
+ public static class ControllerRenderContext extends AbstractRenderContext
{
private InvokePortletCommandFactory cmdFactory;
private ControllerContext controllerContext;
Modified: branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
===================================================================
--- branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-03-19 01:11:08 UTC (rev 10323)
+++ branches/JBoss_Portal_2_6_3_JBPORTAL-1956/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-03-19 01:19:29 UTC (rev 10324)
@@ -28,6 +28,7 @@
import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.navstate.NavigationalStateKey;
import org.jboss.portal.core.navstate.NavigationalStateObjectChange;
+import org.jboss.portal.core.model.portal.PortalObjectId;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -83,7 +84,8 @@
}
//
- return store.getAttribute(nsKey);
+ PortalObjectId id = (PortalObjectId)nsKey.getId();
+ return store.getAttribute(id.toString());
}
public void setAttribute(Object attrKey, Object attrValue) throws IllegalArgumentException
@@ -198,7 +200,10 @@
maximizedKey = change.getKey();
}
}
- store.setAttribute(change.getKey(), change.getNewValue());
+
+ //
+ PortalObjectId id = (PortalObjectId)change.getKey().getId();
+ store.setAttribute(id.toString(), change.getNewValue());
}
// Unmaximize other windows if necessary
Modified: branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/PortalConstants.java
===================================================================
--- branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/PortalConstants.java 2008-03-19 01:11:08 UTC (rev 10323)
+++ branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/PortalConstants.java 2008-03-19 01:19:29 UTC (rev 10324)
@@ -60,6 +60,6 @@
/** Generic session objects. */
public static final String PORTAL_SESSION_MAP_KEY = "portal.session";
- /** Navigational state objects. */
- public static final String NAVIGATIONAL_STATE_MAP_KEY = "portal.navigationalstate";
+ /** Generic session objects. */
+ public static final String PORTAL_PRINCIPAL_MAP_KEY = "portal.principal";
}
Modified: branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
===================================================================
--- branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2008-03-19 01:11:08 UTC (rev 10323)
+++ branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2008-03-19 01:19:29 UTC (rev 10324)
@@ -23,9 +23,7 @@
package org.jboss.portal.server.impl;
import org.jboss.portal.common.invocation.AbstractInvocationContext;
-import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
import org.jboss.portal.common.invocation.resolver.RequestAttributeResolver;
-import org.jboss.portal.common.invocation.resolver.SessionAttributeResolver;
import org.jboss.portal.common.text.CharBuffer;
import org.jboss.portal.common.text.FastURLEncoder;
import org.jboss.portal.common.util.ParameterMap;
@@ -33,6 +31,7 @@
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.ServerURL;
+import org.jboss.portal.server.impl.invocation.SessionAttributeResolver;
import org.jboss.portal.server.request.URLContext;
import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.web.WebRequest;
@@ -133,8 +132,8 @@
//
addResolver(ServerInvocation.REQUEST_SCOPE, new RequestAttributeResolver(req));
- addResolver(ServerInvocation.SESSION_SCOPE, new SessionAttributeResolver(req, PortalConstants.PORTAL_SESSION_MAP_KEY));
- addResolver(ServerInvocation.PRINCIPAL_SCOPE, new PrincipalAttributeResolver(req));
+ addResolver(ServerInvocation.SESSION_SCOPE, new SessionAttributeResolver(req, PortalConstants.PORTAL_SESSION_MAP_KEY, false));
+ addResolver(ServerInvocation.PRINCIPAL_SCOPE, new SessionAttributeResolver(req, PortalConstants.PORTAL_PRINCIPAL_MAP_KEY, true));
}
public WebRequest getWebRequest()
Added: branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java
===================================================================
--- branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java (rev 0)
+++ branches/JBoss_Portal_2_6_3_JBPORTAL-1956/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java 2008-03-19 01:19:29 UTC (rev 10324)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.server.impl.invocation;
+
+import org.jboss.portal.common.invocation.AttributeResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.security.Principal;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class SessionAttributeResolver implements AttributeResolver
+{
+
+ /** . */
+ protected final HttpServletRequest req;
+
+ /** . */
+ protected final String prefix;
+
+ public SessionAttributeResolver(
+ HttpServletRequest req,
+ String prefix,
+ boolean principalScoped)
+ {
+ if (req == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (prefix == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (principalScoped)
+ {
+ Principal principal = req.getUserPrincipal();
+ if (principal != null)
+ {
+ prefix = prefix + principal.getName();
+ }
+ }
+
+ //
+ this.req = req;
+ this.prefix = prefix;
+ }
+
+ public Set getKeys()
+ {
+ HttpSession session = req.getSession(false);
+
+ //
+ if (session == null)
+ {
+ return Collections.EMPTY_SET;
+ }
+
+ //
+ Set keys = new HashSet();
+ for (Enumeration e = session.getAttributeNames();e.hasMoreElements();)
+ {
+ String key = (String)e.nextElement();
+
+ //
+ if (key.startsWith(prefix))
+ {
+ keys.add(key);
+ }
+ }
+
+ //
+ return keys;
+ }
+
+ public Object getAttribute(Object o) throws IllegalArgumentException
+ {
+ HttpSession session = req.getSession(false);
+
+ //
+ if (session == null)
+ {
+ return null;
+ }
+
+ //
+ return session.getAttribute(prefix + o);
+ }
+
+ public void setAttribute(Object o, Object o1) throws IllegalArgumentException
+ {
+ req.getSession().setAttribute(prefix + o, o1);
+ }
+}
\ No newline at end of file
16 years, 3 months
JBoss Portal SVN: r10323 - in modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal: test/portlet and 1 other directory.
by portal-commits@lists.jboss.org
Author: mmillson
Date: 2008-03-18 21:11:08 -0400 (Tue, 18 Mar 2008)
New Revision: 10323
Modified:
modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
Log:
Fix Portal navigational state replication for [JBPORTAL-1956].
Modified: modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
===================================================================
--- modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2008-03-19 01:02:18 UTC (rev 10322)
+++ modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2008-03-19 01:11:08 UTC (rev 10323)
@@ -25,6 +25,9 @@
import org.jboss.portal.common.util.ParameterMap;
import java.io.Serializable;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -149,4 +152,26 @@
return new PortletParameters(map);
}
}
+
+ private void writeObject(ObjectOutputStream out) throws IOException
+ {
+ out.writeInt(size());
+ for (Iterator i = entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Entry)i.next();
+ out.writeObject(entry.getKey());
+ out.writeObject(entry.getValue());
+ }
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ int size = in.readInt();
+ while (size-- > 0)
+ {
+ String key = (String)in.readObject();
+ String[] values = (String[])in.readObject();
+ put(key, values);
+ }
+ }
}
Modified: modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
===================================================================
--- modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-03-19 01:02:18 UTC (rev 10322)
+++ modules/portlet/branches/JBP_PORTLET_1_0_1_JBPORTAL-1956/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-03-19 01:11:08 UTC (rev 10323)
@@ -23,11 +23,15 @@
package org.jboss.portal.test.portlet;
import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.PortletParameters;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Collections;
+import java.util.Set;
+import java.io.IOException;
import junit.framework.TestCase;
@@ -300,6 +304,17 @@
assertNull(param.getValue("a"));
}
+ public void testSerialization() throws IOException
+ {
+ param.setValue("foo", "bar");
+ PortletParameters clone = (PortletParameters)IOTools.clone(param);
+ assertNotNull(clone);
+ Set keys = clone.keySet();
+ assertEquals(1, keys.size());
+ assertTrue(keys.contains("foo"));
+ assertEquals("bar", clone.getValue("foo"));
+ }
+
public Class[] buildExceptionClasses()
{
return new Class[]
16 years, 3 months
JBoss Portal SVN: r10322 - in modules/portlet/trunk: portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-18 21:02:18 -0400 (Tue, 18 Mar 2008)
New Revision: 10322
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/AbstractPortletControllerContext.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
Log:
updated portlet module to use the new media type and media type map
Modified: modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/AbstractPortletControllerContext.java
===================================================================
--- modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/AbstractPortletControllerContext.java 2008-03-19 00:41:18 UTC (rev 10321)
+++ modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/AbstractPortletControllerContext.java 2008-03-19 01:02:18 UTC (rev 10322)
@@ -24,8 +24,8 @@
package org.jboss.portal.portlet.controller.impl;
import org.jboss.portal.common.util.MarkupInfo;
-import org.jboss.portal.common.util.MediaType;
import org.jboss.portal.common.io.Serialization;
+import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.controller.PortletControllerContext;
@@ -70,7 +70,7 @@
public static final PortalContext PORTAL_CONTEXT = new AbstractPortalContext(Collections.singletonMap("javax.portlet.markup.head.element.support", "true"));
/** . */
- public static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML, "UTF8");
+ public static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.TEXT_HTML, "UTF8");
/** . */
public static final int NAV_SCOPE = 0;
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-03-19 00:41:18 UTC (rev 10321)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-03-19 01:02:18 UTC (rev 10322)
@@ -28,7 +28,6 @@
import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.common.util.SimpleMultiValuedPropertyMap;
import org.jboss.portal.common.util.ContentInfo;
-import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
@@ -366,7 +365,7 @@
public String getResponseContentType()
{
- return invocation.getContext().getMarkupInfo().getContentType().toString();
+ return invocation.getContext().getMarkupInfo().getContentType().getValue();
}
public Enumeration<String> getResponseContentTypes()
@@ -579,17 +578,13 @@
{
// Get content type
ContentInfo si = invocation.getContext().getMarkupInfo();
- String contentType = si.getContentType().toString();
- //
- MediaType mediaType = MediaType.create(contentType);
-
// Get the modes for this content type
CapabilitiesInfo capabilities = container.getInfo().getCapabilities();
// Add all the modes
Set<Mode> modes = new HashSet<Mode>();
- for (ModeInfo modeInfo : capabilities.getModes(mediaType))
+ for (ModeInfo modeInfo : capabilities.getModes(si.getContentType()))
{
modes.add(modeInfo.getMode());
}
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-03-19 00:41:18 UTC (rev 10321)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-03-19 01:02:18 UTC (rev 10322)
@@ -31,11 +31,9 @@
import org.jboss.portal.portlet.info.ModeInfo;
import org.jboss.portal.portlet.cache.CacheControl;
import org.jboss.portal.Mode;
-import org.jboss.portal.common.util.MediaType;
import javax.portlet.RenderResponse;
import javax.portlet.PortletMode;
-import javax.activation.MimeTypeParseException;
import java.util.Collection;
import java.util.Set;
import java.util.LinkedHashSet;
@@ -104,58 +102,45 @@
public void setContentType(String contentType)
{
- try
+ // Remove the unused appended charset first
+ int index = contentType.indexOf(';');
+ if (index != -1)
{
- // Remove the unused appended charset first
- int index = contentType.indexOf(';');
- if (index != -1)
- {
- contentType = contentType.substring(0, index);
- }
+ contentType = contentType.substring(0, index);
+ }
- // Find the content type among the media type we know
- MediaType requestedMediaType = MediaType.parseMimeType(contentType);
-
- // Get the response media type
+ // Get the response media type
// ContentInfo info = invocation.getContext().getMarkupInfo();
// MediaType responseMediaType = info.getContentType();
- // Check if the requested media type is allowed as a subtype of the main response
+ // Check if the requested media type is allowed as a subtype of the main response
// if (!responseMediaType.isAllowedSubType(requestedMediaType))
// {
// throw new IllegalArgumentException("Content type not accepted");
// }
- //
- Mode currentMode = preq.invocation.getMode();
+ //
+ Mode currentMode = preq.invocation.getMode();
- org.jboss.portal.common.net.media.MediaType mediaType = org.jboss.portal.common.net.media.MediaType.create(contentType);
+ org.jboss.portal.common.net.media.MediaType mediaType = org.jboss.portal.common.net.media.MediaType.create(contentType);
- PortletInfo info = preq.container.getInfo();
- CapabilitiesInfo capabilities = info.getCapabilities();
- Set<ModeInfo> compatibleModes = capabilities.getModes(mediaType);
- for (ModeInfo modeInfo : compatibleModes)
+ PortletInfo info = preq.container.getInfo();
+ CapabilitiesInfo capabilities = info.getCapabilities();
+ Set<ModeInfo> compatibleModes = capabilities.getModes(mediaType);
+ for (ModeInfo modeInfo : compatibleModes)
+ {
+ if (currentMode.equals(modeInfo.getMode()))
{
- if (currentMode.equals(modeInfo.getMode()))
- {
- // Set the content type
- super.setContentType(contentType);
+ // Set the content type
+ super.setContentType(contentType);
- //
- return;
- }
+ //
+ return;
}
-
- //
- throw new IllegalArgumentException("Mime type " + contentType + " not accepted as content type");
-
}
- catch (MimeTypeParseException e)
- {
- IllegalArgumentException ex = new IllegalArgumentException("Content type not accepted");
- ex.initCause(e);
- throw ex;
- }
+
+ //
+ throw new IllegalArgumentException("Mime type " + contentType + " not accepted as content type");
}
protected ContentResponse createMarkupResponse(ResponseProperties properties, Map<String, Object> attributeMap, String contentType, byte[] bytes, String chars, CacheControl cacheControl)
16 years, 3 months
JBoss Portal SVN: r10321 - in modules/common/trunk/common/src/main/java/org/jboss/portal/common: util and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-18 20:41:18 -0400 (Tue, 18 Mar 2008)
New Revision: 10321
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ContentInfo.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MarkupInfo.java
Log:
corrected a few minor issues in the argument type check
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-18 23:30:27 UTC (rev 10320)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-19 00:41:18 UTC (rev 10321)
@@ -58,10 +58,16 @@
public static MediaType create(String mediaTypeName)
{
+ if (mediaTypeName == null)
+ {
+ throw new IllegalArgumentException("No null media type value accepted");
+ }
+
+ //
int slashIndex = mediaTypeName.indexOf('/');
if (slashIndex == -1)
{
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("The media type " + mediaTypeName + " does not contain a /");
}
//
@@ -74,12 +80,20 @@
public static MediaType create(String typeName, String subtypeName)
{
- TypeDef type = TypeDef.create(typeName);
+ if (typeName == null)
+ {
+ throw new IllegalArgumentException("No null type name accepted");
+ }
+ if (subtypeName == null)
+ {
+ throw new IllegalArgumentException("No null subtype name accepted");
+ }
//
+ TypeDef type = TypeDef.create(typeName);
if (type == null)
{
- return null;
+ throw new IllegalArgumentException("Type not recognized in content type " + typeName + "/" + subtypeName);
}
//
@@ -99,6 +113,8 @@
{
throw new IllegalArgumentException("No null subtype accepted");
}
+
+ //
return new MediaType(type, subtype);
}
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ContentInfo.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ContentInfo.java 2008-03-18 23:30:27 UTC (rev 10320)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ContentInfo.java 2008-03-19 00:41:18 UTC (rev 10321)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.common.util;
+import org.jboss.portal.common.net.media.MediaType;
+
/**
* Describe how content should be interpreted.
*
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MarkupInfo.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MarkupInfo.java 2008-03-18 23:30:27 UTC (rev 10320)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MarkupInfo.java 2008-03-19 00:41:18 UTC (rev 10321)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.common.util;
+import org.jboss.portal.common.net.media.MediaType;
+
/**
* Extends content to describe markup content.
*
16 years, 3 months
JBoss Portal SVN: r10320 - in modules/portlet/trunk/portlet/src: main/java/org/jboss/portal/portlet/impl/jsr168/api and 4 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-18 19:30:27 -0400 (Tue, 18 Mar 2008)
New Revision: 10320
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerInfoBuilder.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/info/CapabilitiesInfo.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/info/CapabilitiesInfoSupport.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ContentTypesTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/CapabilitiesInfoTest.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/ModeInfoTest.java
Log:
updated portlet module to use the new media type and media type map
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -24,15 +24,13 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.net.media.MediaTypeMapImpl;
+import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import org.jboss.portal.portlet.info.ModeInfo;
import org.jboss.portal.portlet.info.WindowStateInfo;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import java.util.Locale;
@@ -49,49 +47,29 @@
{
/** . */
- private static Set<WindowStateInfo> WINDOW_STATES;
+ private final MediaTypeMapImpl<ModeInfo> supportedModes;
/** . */
- private static final String ANY = "*";
+ private final MediaTypeMapImpl<WindowStateInfo> supportedWindowStates;
/** . */
- private static final String ANY_ANY = "*/*";
-
- /** . */
- private static final char SEPARATOR = '/';
-
- static
- {
- Set<WindowStateInfo> tmp = new HashSet<WindowStateInfo>();
- tmp.add(new ContainerWindowStateInfo(WindowState.MAXIMIZED));
- tmp.add(new ContainerWindowStateInfo(WindowState.MINIMIZED));
- tmp.add(new ContainerWindowStateInfo(WindowState.NORMAL));
- WINDOW_STATES = Collections.unmodifiableSet(tmp);
- }
-
- /** Maps MIME Type (String) -> Modes (Set), excluding multiple MIME Types ("*", "* / *", "type / *"). */
- protected final Map<String, Set<Mode>> singleTypeToPortletModes;
-
- /** Maps MIME Type (String) -> Modes (Set), including multiple MIME Types ("*", "* / *", "type / *"). */
- protected final Map<String, Set<Mode>> allTypeToPortletModes;
-
- /** . */
- protected final Set<Mode> allModes;
-
- /** . */
private final Set<Locale> supportedLocales;
- // case-insensitive
- // CONTENT TYPE = TYPE / SUBTYPE
- // SUBTYPE = any char except a TSPECIALS or SPACE or CTLS (??)
- // TSPECIALS ( ) < > @ , ; : \ " / [ ] ? . =
-
public ContainerCapabilitiesInfo()
{
- this.singleTypeToPortletModes = new HashMap<String, Set<Mode>>();
- this.allTypeToPortletModes = new HashMap<String, Set<Mode>>(); // Including *
- this.allModes = new HashSet<Mode>();
+ MediaTypeMapImpl<ModeInfo> supportedModes = new MediaTypeMapImpl<ModeInfo>();
+ supportedModes.put(new ContainerModeInfo(Mode.VIEW));
+
+ //
+ MediaTypeMapImpl<WindowStateInfo> supportedWindowStates = new MediaTypeMapImpl<WindowStateInfo>();
+ supportedWindowStates.put(new ContainerWindowStateInfo(WindowState.MAXIMIZED));
+ supportedWindowStates.put(new ContainerWindowStateInfo(WindowState.NORMAL));
+ supportedWindowStates.put(new ContainerWindowStateInfo(WindowState.MINIMIZED));
+
+ //
this.supportedLocales = new HashSet<Locale>();
+ this.supportedModes = supportedModes;
+ this.supportedWindowStates = supportedWindowStates;
}
public void addLocale(Locale locale)
@@ -101,281 +79,68 @@
public void add(String contentType, Mode mode)
{
- // Determines which map and key to store the mode under
- String key;
- if (ANY.equals(contentType) || ANY_ANY.equals(contentType))
+ try
{
- key = ANY;
+ supportedModes.put(contentType, new ContainerModeInfo(mode));
}
- else
+ catch (IllegalArgumentException e)
{
- int index = contentType.indexOf(SEPARATOR);
- if (index == -1)
- {
- System.out.println("'" + contentType + "' is not a valid MIME type: ignoring!");
- return;
- }
+ e.printStackTrace();
- String type = contentType.substring(0, index);
- String subtype = contentType.substring(index + 1);
-
- if (ANY.equals(subtype))
- {
- key = type;
- }
- else
- {
- key = contentType;
- // This is a single content type so we need to add it to the single mappings in addition to all
- addMode(singleTypeToPortletModes, key, mode);
- }
+ //
+ System.out.println("'" + contentType + "' is not a valid MIME type: ignoring!");
}
-
- // Store the mode in the complete mapping
- addMode(allTypeToPortletModes, key, mode);
-
- // Add the mode to the known modes
- allModes.add(mode);
}
- private void addMode(Map<String, Set<Mode>> map, String key, Mode mode)
+ public void add(String contentType, WindowState windowState)
{
- Set<Mode> modes = map.get(key);
- if (modes == null)
+ try
{
- modes = new HashSet<Mode>();
- map.put(key, modes);
+ supportedWindowStates.put(contentType, new ContainerWindowStateInfo(windowState));
}
- modes.add(mode);
- }
+ catch (IllegalArgumentException e)
+ {
+ e.printStackTrace();
- /**
- * Return all modes.
- *
- * @return all modes
- */
- public Collection<Mode> getModes()
- {
- return Collections.unmodifiableCollection(allModes);
+ //
+ System.out.println("'" + contentType + "' is not a valid MIME type: ignoring!");
+ }
}
- /**
- * Return all content types.
- *
- * @return all content types
- */
- public Collection<String> getAllContentTypes()
- {
- return Collections.unmodifiableCollection(allTypeToPortletModes.keySet());
- }
+ // CapabilitiesInfo implementation **********************************************************************************
- /**
- * Return true if the mode is supported
- *
- * @param mode the mode to check
- * @return true if the mode is supported
- * @throws IllegalArgumentException if the mode is null
- */
- public boolean isModeSupported(Mode mode)
+ public Set<ModeInfo> getModes(MediaType mimeType)
{
- if (mode == null)
- {
- throw new IllegalArgumentException("Mode must not be null");
- }
- return allModes.contains(mode);
+ return supportedModes.resolve(mimeType);
}
- /**
- * Return all the supported modes for this content type.
- *
- * @param contentType the content type to check
- * @throws IllegalArgumentException if the content type is null
- * @return the set of modes matching the content types support
- */
- public Set<Mode> getSupportedModes(String contentType)
+ public Set<WindowStateInfo> getWindowStates(MediaType mimeType)
{
- if (contentType == null)
- {
- throw new IllegalArgumentException("Content type must not be null");
- }
-
- int index = contentType.indexOf(SEPARATOR);
- if (index == -1)
- {
- // Not valid content type so return empty set
- return Collections.emptySet();
- }
-
- //
- Set<Mode> set = new HashSet<Mode>();
-
- //
- Set<Mode> contentTypeModes = singleTypeToPortletModes.get(contentType.toLowerCase());
- if (contentTypeModes != null)
- {
- set.addAll(contentTypeModes);
- }
-
- //
- Set<Mode> typeModes = allTypeToPortletModes.get(contentType.substring(0, index).toLowerCase());
- if (typeModes != null)
- {
- set.addAll(typeModes);
- }
-
- Set<Mode> wildcardModes = allTypeToPortletModes.get(ANY);
- if (wildcardModes != null)
- {
- set.addAll(wildcardModes);
- }
-
- return set;
+ return supportedWindowStates.resolve(mimeType);
}
- /**
- * Return true if the content type is supported.
- *
- * @param contentType the content type
- * @return true is it is supported
- * @throws IllegalArgumentException if the content type is null
- */
- public boolean isContentTypeSupported(String contentType)
+ public Set<Locale> getLocales(MediaType mimeType)
{
- Collection allContentTypes = getAllContentTypes();
- if (contentType == null)
- {
- throw new IllegalArgumentException("Content type must not be null");
- }
-
- int index = contentType.indexOf(SEPARATOR);
- if (index == -1)
- {
- // Not valid content type so return false
- return false;
- }
-
- // Try the content type, * or */*
- if (allContentTypes.contains(contentType) |
- allContentTypes.contains(contentType.toLowerCase()) |
- allContentTypes.contains(ANY) |
- allContentTypes.contains(ANY_ANY))
- {
- return true;
- }
-
- // Try xxx/*
- String wildcard = contentType.substring(0, index) + "/*";
- return allContentTypes.contains(wildcard) | allContentTypes.contains(wildcard.toLowerCase());
+ return supportedLocales;
}
- /**
- * Return true if the given content type is supported for the given mode.
- *
- * @param mode the mode to check
- * @param contentType the content type to check
- * @return true if is it supported
- * @throws IllegalArgumentException if the content type or the mode is null
- */
- public boolean isSupported(Mode mode, String contentType)
+ public Set<MediaType> getMimeTypes()
{
- if (mode == null)
- {
- throw new IllegalArgumentException("Mode must not be null");
- }
- if (contentType == null)
- {
- throw new IllegalArgumentException("Content type must not be null");
- }
-
- int index = contentType.indexOf(SEPARATOR);
- if (index == -1)
- {
- // Not valid content type so return false
- return false;
- }
-
- // Try full name matching
- Set<Mode> contentTypeModes = singleTypeToPortletModes.get(contentType);
- if (contentTypeModes != null && contentTypeModes.contains(mode))
- {
- return true;
- }
-
- // Try full name lowercase matching
- Set<Mode> lowercaseContentTypeModes = singleTypeToPortletModes.get(contentType.toLowerCase());
- if (lowercaseContentTypeModes != null && lowercaseContentTypeModes.contains(mode))
- {
- return true;
- }
-
- // Try type matching
- String type = contentType.substring(0, index);
- Set<Mode> typeMode = allTypeToPortletModes.get(type);
- if (typeMode != null && typeMode.contains(mode))
- {
- return true;
- }
-
- // Try type matching
- Set<Mode> lowercaseTypeMode = allTypeToPortletModes.get(type.toLowerCase());
- if (lowercaseTypeMode != null && lowercaseTypeMode.contains(mode))
- {
- return true;
- }
-
- // Try wildcard matching
- Set<Mode> wildcardMode = allTypeToPortletModes.get(ANY);
- return wildcardMode != null && wildcardMode.contains(mode);
+ return supportedModes.getMediaTypes();
}
- // CapabilitiesInfo implementation **********************************************************************************
-
- public Set<String> getMimeTypes()
- {
- return new HashSet<String>(getAllContentTypes());
- }
-
public Set<ModeInfo> getAllModes()
{
- Set<ModeInfo> infos = new HashSet<ModeInfo>();
- for (Mode mode : getModes())
- {
- infos.add(new ContainerModeInfo(mode));
- }
- return infos;
+ return supportedModes.getValues();
}
- public Set<ModeInfo> getModes(String mimeType)
- {
- Set<ModeInfo> infos = new HashSet<ModeInfo>();
- for (Mode mode : getSupportedModes(mimeType))
- {
- infos.add(new ContainerModeInfo(mode));
- }
- return infos;
- }
-
public Set<WindowStateInfo> getAllWindowStates()
{
- return WINDOW_STATES;
+ return supportedWindowStates.getValues();
}
- public Set<WindowStateInfo> getWindowStates(String mimeType)
- {
- if (isContentTypeSupported(mimeType))
- {
- return getAllWindowStates();
- }
- return Collections.emptySet();
- }
-
public Set<Locale> getAllLocales()
{
return supportedLocales;
}
-
- public Set<Locale> getLocales(String mimeType)
- {
- return supportedLocales;
- }
}
\ No newline at end of file
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerInfoBuilder.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerInfoBuilder.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerInfoBuilder.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -53,6 +53,7 @@
import org.jboss.portal.common.i18n.ResourceBundleManager;
import org.jboss.portal.common.reflect.NoSuchClassException;
import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
import org.apache.log4j.Logger;
import javax.xml.namespace.QName;
@@ -798,6 +799,17 @@
{
capabilities.add(mimeType, modeMD.getPortletMode());
}
+
+ //
+ capabilities.add(mimeType, WindowState.NORMAL);
+ capabilities.add(mimeType, WindowState.MINIMIZED);
+ capabilities.add(mimeType, WindowState.MAXIMIZED);
+
+ // Then process each window state
+ for (WindowStateMetaData windowStateMD : supportsMD.getWindowStates())
+ {
+ capabilities.add(mimeType, windowStateMD.getWindowState());
+ }
}
//
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -28,6 +28,7 @@
import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.common.util.SimpleMultiValuedPropertyMap;
import org.jboss.portal.common.util.ContentInfo;
+import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
@@ -580,12 +581,15 @@
ContentInfo si = invocation.getContext().getMarkupInfo();
String contentType = si.getContentType().toString();
+ //
+ MediaType mediaType = MediaType.create(contentType);
+
// Get the modes for this content type
CapabilitiesInfo capabilities = container.getInfo().getCapabilities();
// Add all the modes
Set<Mode> modes = new HashSet<Mode>();
- for (ModeInfo modeInfo : capabilities.getModes(contentType))
+ for (ModeInfo modeInfo : capabilities.getModes(mediaType))
{
modes.add(modeInfo.getMode());
}
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -129,9 +129,11 @@
//
Mode currentMode = preq.invocation.getMode();
+ org.jboss.portal.common.net.media.MediaType mediaType = org.jboss.portal.common.net.media.MediaType.create(contentType);
+
PortletInfo info = preq.container.getInfo();
CapabilitiesInfo capabilities = info.getCapabilities();
- Set<ModeInfo> compatibleModes = capabilities.getModes(contentType);
+ Set<ModeInfo> compatibleModes = capabilities.getModes(mediaType);
for (ModeInfo modeInfo : compatibleModes)
{
if (currentMode.equals(modeInfo.getMode()))
Modified: modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/info/CapabilitiesInfo.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/info/CapabilitiesInfo.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/info/CapabilitiesInfo.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -22,11 +22,13 @@
******************************************************************************/
package org.jboss.portal.portlet.info;
+import org.jboss.portal.common.net.media.MediaType;
+
import java.util.Set;
import java.util.Locale;
/**
- * Gathers capability information (portlet modes, window states, supported MIME types and locales) regarding a portlet.
+ * Gathers capability information (portlet modes, window states, supported media types and locales) regarding a portlet.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5448 $
@@ -39,7 +41,7 @@
*
* @return a Set of String representation of supported MIME types
*/
- Set<String> getMimeTypes();
+ Set<MediaType> getMimeTypes();
/**
* Retrieves all the portlet modes supported by the associated Portlet.
@@ -54,7 +56,7 @@
* @param mimeType the mime type
* @return a Set of {@link ModeInfo} reprensenting the supported portlet modes for the specified MIME type
*/
- Set<ModeInfo> getModes(String mimeType);
+ Set<ModeInfo> getModes(MediaType mimeType);
/**
* Retrieves all the window states supported by the associated Portlet.
@@ -69,7 +71,7 @@
* @param mimeType the mime type
* @return a Set of {@link ModeInfo} reprensenting the supported window states for the specified MIME type
*/
- Set<WindowStateInfo> getWindowStates(String mimeType);
+ Set<WindowStateInfo> getWindowStates(MediaType mimeType);
/**
* Retrieves all the locales supported by the associated Portlet.
@@ -84,5 +86,5 @@
* @param mimeType the mime type
* @return a Set of supported {@link java.util.Locale}s for the specified MIME type
*/
- Set<Locale> getLocales(String mimeType);
+ Set<Locale> getLocales(MediaType mimeType);
}
Modified: modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/info/CapabilitiesInfoSupport.java
===================================================================
--- modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/info/CapabilitiesInfoSupport.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/info/CapabilitiesInfoSupport.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -27,6 +27,7 @@
import org.jboss.portal.portlet.info.WindowStateInfo;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.net.media.MediaType;
import java.util.Set;
import java.util.HashSet;
@@ -41,7 +42,7 @@
{
/** . */
- private Set<String> mimeTypes;
+ private Set<MediaType> mimeTypes;
/** . */
private Set<ModeInfo> modes;
@@ -54,8 +55,8 @@
public CapabilitiesInfoSupport()
{
- mimeTypes = new HashSet<String>();
- mimeTypes.add("text/html");
+ mimeTypes = new HashSet<MediaType>();
+ mimeTypes.add(MediaType.TEXT_HTML);
//
this.modes = new HashSet<ModeInfo>();
@@ -74,7 +75,7 @@
locales.add(Locale.ENGLISH);
}
- public Set<String> getMimeTypes()
+ public Set<MediaType> getMimeTypes()
{
return mimeTypes;
}
@@ -84,7 +85,7 @@
return modes;
}
- public Set<ModeInfo> getModes(String mimeType)
+ public Set<ModeInfo> getModes(MediaType mimeType)
{
if (mimeTypes.contains(mimeType))
{
@@ -98,7 +99,7 @@
return windowStates;
}
- public Set<WindowStateInfo> getWindowStates(String mimeType)
+ public Set<WindowStateInfo> getWindowStates(MediaType mimeType)
{
if (mimeTypes.contains(mimeType))
{
@@ -112,7 +113,7 @@
return locales;
}
- public Set<Locale> getLocales(String mimeType)
+ public Set<Locale> getLocales(MediaType mimeType)
{
if (mimeTypes.contains(mimeType))
{
Modified: modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ContentTypesTestCase.java
===================================================================
--- modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ContentTypesTestCase.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ContentTypesTestCase.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -68,18 +68,6 @@
}
@Test
- public void testGetAllContentTypes()
- {
- Collection types = contentTypes.getAllContentTypes();
- assertEquals(5, types.size());
- assertTrue(types.contains("text/html"));
- assertTrue(types.contains("text/xml"));
- assertTrue(types.contains("pipo/pipo"));
- assertTrue(types.contains("*"));
- assertTrue(types.contains("text"));
- }
-
- @Test
public void testIsModeSupported()
{
}
Modified: modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/CapabilitiesInfoTest.java
===================================================================
--- modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/CapabilitiesInfoTest.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/CapabilitiesInfoTest.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -25,6 +25,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.container.managed.ManagedPortletContainer;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import org.jboss.portal.portlet.info.ModeInfo;
@@ -63,7 +64,7 @@
assertTrue(allLocales.contains(Locale.ENGLISH));
//check mime types
- Set types = capInfo.getMimeTypes();
+ Set<MediaType> types = capInfo.getMimeTypes();
String[] mt = new String[types.size()];
int count = 0;
for (Iterator i = types.iterator(); i.hasNext();)
@@ -82,21 +83,21 @@
assertTrue(modes.contains(Mode.EDIT));
//check text/html modes
- modeInfos = capInfo.getModes("text/html");
+ modeInfos = capInfo.getModes(MediaType.TEXT_HTML);
modes = extractModes(modeInfos);
assertEquals(2, modes.size());
assertTrue(modes.contains(Mode.VIEW));
assertTrue(modes.contains(Mode.HELP));
//check text/vnd.wap.wml modes
- modeInfos = capInfo.getModes("text/vnd.wap.wml");
+ modeInfos = capInfo.getModes(MediaType.create("text/vnd.wap.wml"));
modes = extractModes(modeInfos);
assertEquals(2, modes.size());
assertTrue(modes.contains(Mode.VIEW));
assertTrue(modes.contains(Mode.EDIT));
//check undeclared
- modeInfos = capInfo.getModes("text/undeclared");
+ modeInfos = capInfo.getModes(MediaType.create("text/undeclared"));
modes = extractModes(modeInfos);
assertEquals(0, modes.size());
@@ -109,7 +110,7 @@
assertTrue(states.contains(WindowState.MAXIMIZED));
//check for text/html
- stateInfos = capInfo.getWindowStates("text/html");
+ stateInfos = capInfo.getWindowStates(MediaType.TEXT_HTML);
states = extractWindowStates(stateInfos);
assertEquals(3, states.size());
assertTrue(states.contains(WindowState.NORMAL));
@@ -118,11 +119,11 @@
//simple check for text/vnd.wap.wml
//TODO:is this really expected behaviour? shouldn't it return no states as this is unsupported by portal one?
- states = capInfo.getWindowStates("text/vnd.wap.wml");
+ states = capInfo.getWindowStates(MediaType.create("text/vnd.wap.wml"));
assertEquals(3, states.size());
//check undeclared
- states = capInfo.getWindowStates("undeclared/mime");
+ states = capInfo.getWindowStates(MediaType.create("undeclared/mime"));
assertEquals(0, states.size());
//fail();
Modified: modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/ModeInfoTest.java
===================================================================
--- modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/ModeInfoTest.java 2008-03-18 22:44:34 UTC (rev 10319)
+++ modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/info/ModeInfoTest.java 2008-03-18 23:30:27 UTC (rev 10320)
@@ -23,6 +23,7 @@
package org.jboss.portal.test.portlet.info;
import org.jboss.portal.Mode;
+import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.portlet.container.managed.ManagedPortletContainer;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import org.jboss.portal.portlet.info.ModeInfo;
@@ -52,7 +53,7 @@
CapabilitiesInfo capaInfo = container1.getInfo().getCapabilities();
//Portlet 1 with VIEW, EDIT, HELP
- Set modeInfos = capaInfo.getModes("text/html");
+ Set modeInfos = capaInfo.getModes(MediaType.TEXT_HTML);
//shoule be 3 modes
assertEquals(3, modeInfos.size());
@@ -72,7 +73,7 @@
//Portlet 2 with only VIEW
capaInfo = container2.getInfo().getCapabilities();
- modeInfos = capaInfo.getModes("text/html");
+ modeInfos = capaInfo.getModes(MediaType.TEXT_HTML);
//shoule be 1 mode
assertEquals(1, modeInfos.size());
16 years, 3 months
JBoss Portal SVN: r10319 - in modules/common/trunk/common/src: main/java/org/jboss/portal/common/util and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-18 18:44:34 -0400 (Tue, 18 Mar 2008)
New Revision: 10319
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java
Log:
added factory method with media type name on media type class
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-18 22:27:37 UTC (rev 10318)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-18 22:44:34 UTC (rev 10319)
@@ -56,6 +56,22 @@
/** . */
private volatile String value;
+ public static MediaType create(String mediaTypeName)
+ {
+ int slashIndex = mediaTypeName.indexOf('/');
+ if (slashIndex == -1)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String typeName = mediaTypeName.substring(0, slashIndex);
+ String subtypeName = mediaTypeName.substring(slashIndex + 1);
+
+ //
+ return create(typeName, subtypeName);
+ }
+
public static MediaType create(String typeName, String subtypeName)
{
TypeDef type = TypeDef.create(typeName);
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java 2008-03-18 22:27:37 UTC (rev 10318)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java 2008-03-18 22:44:34 UTC (rev 10319)
@@ -33,6 +33,8 @@
import java.util.Set;
/**
+ * This class is going to be removed any time soon in favoir of org.jboss.portal.common.net.media.MediaType
+ *
* This is a immutable wrapper to the activation MimeTpye.
* <p>This class contains some extensions to the activation MimeType, such as the typesafe enum
* pattern, and allows for a mime type to specify allowed sub types.</p>
@@ -42,6 +44,7 @@
* @see javax.activation.MimeType
* see also ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/
*/
+@Deprecated
public final class MediaType
{
private static Map allowedTypes = new HashMap();
Modified: modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java
===================================================================
--- modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java 2008-03-18 22:27:37 UTC (rev 10318)
+++ modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java 2008-03-18 22:44:34 UTC (rev 10319)
@@ -45,6 +45,11 @@
assertEquals(SubtypeDef.HTML, textHTML2.getSubtype());
//
+ MediaType textHTML3 = MediaType.create("text/html");
+ assertEquals(TypeDef.TEXT, textHTML3.getType());
+ assertEquals(SubtypeDef.HTML, textHTML3.getSubtype());
+
+ //
assertEquals(MediaType.TEXT_HTML, textHTML);
assertEquals(MediaType.TEXT_HTML, textHTML2);
}
@@ -93,5 +98,40 @@
catch (Exception e)
{
}
+ try
+ {
+ MediaType.create(null);
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("text");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("text/");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("/text");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("foo/html");
+ }
+ catch (Exception e)
+ {
+ }
}
}
16 years, 3 months
JBoss Portal SVN: r10318 - in modules/common/trunk/common/src: test/java/org/jboss/portal/test/common/net/media and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-03-18 18:27:37 -0400 (Tue, 18 Mar 2008)
New Revision: 10318
Added:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMap.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java
Removed:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMap.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapImpl.java
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapTestCase.java
Log:
the classes were added in the wrong package (test)
Copied: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMap.java (from rev 10317, modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMap.java)
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMap.java (rev 0)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMap.java 2008-03-18 22:27:37 UTC (rev 10318)
@@ -0,0 +1,194 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.common.net.media;
+
+import org.jboss.portal.common.net.media.MediaType;
+import org.jboss.portal.common.net.media.TypeDef;
+
+import java.util.Set;
+
+/**
+ * A map containing values associated with media types. The map has the capability to map wildcard subtypes
+ * (for instance text / *) or the wildcard type (* / *). In order to make the distinction between what the map
+ * declares and what it supports it is possible to query the map with resolution or not.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface MediaTypeMap<V>
+{
+
+ /**
+ * Returns true if the map declares the specified media type.
+ *
+ * @param mediaType the media type
+ * @return true if the map declares the media type
+ * @throws IllegalArgumentException if the argument is null
+ */
+ boolean contains(MediaType mediaType) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map declares the specified type. It is equivalent to check if the map
+ * contains a wildard subtype of a type.
+ *
+ * @param type the type
+ * @return true if the map declares the type
+ * @throws IllegalArgumentException if the argument is null
+ */
+ boolean contains(TypeDef type) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map declares the specified media type with a specified value.
+ *
+ * @param mediaType the media type
+ * @param value the value
+ * @return true if the map declares the media type and the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean contains(MediaType mediaType, V value) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map declares the specified type with a specific value. It is equivalent to check if the map
+ * contains a wildard subtype of a type with a specific value.
+ *
+ * @param type the type
+ * @param value the value
+ * @return true if the map declares the media type and the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean contains(TypeDef type, V value) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map declares the specified value for any media type or any type. It is equivalent to check
+ * if the map contains a wildcard type with a specific value.
+ *
+ * @param value the value
+ * @return true if the map declares the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean contains(V value) throws IllegalArgumentException;
+
+ /**
+ * Returns the set of values declared for a given media type.
+ *
+ * @param mediaType the media type
+ * @return the values declared
+ * @throws IllegalArgumentException if any argument is null
+ */
+ Set<V> get(MediaType mediaType) throws IllegalArgumentException;
+
+ /**
+ * Returns the set of values declared for a given type.
+ *
+ * @param type the type
+ * @return the values declared
+ * @throws IllegalArgumentException if any argument is null
+ */
+ Set<V> get(TypeDef type) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map supports the specified media type.
+ *
+ * @param mediaType the media type
+ * @return true if the map supports the media type
+ * @throws IllegalArgumentException if the argument is null
+ */
+ boolean isSupported(MediaType mediaType) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map supports the specified type.
+ *
+ * @param type the type
+ * @return true if the map declares the type
+ * @throws IllegalArgumentException if the argument is null
+ */
+ boolean isSupported(TypeDef type) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map supports the specified media type with a specified value.
+ *
+ * @param mediaType the media type
+ * @param value the value
+ * @return true if the map supports the media type and the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean isSupported(MediaType mediaType, V value) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map supports the specified type with a specific value.
+ *
+ * @param type the type
+ * @param value the value
+ * @return true if the map supports the media type and the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean isSupported(TypeDef type, V value) throws IllegalArgumentException;
+
+ /**
+ * Returns true if the map supports the specified value for any media type or any type.
+ *
+ * @param value the value
+ * @return true if the map supports the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ boolean isSupported(V value) throws IllegalArgumentException;
+
+ /**
+ * Returns the set of values supported for a given media type.
+ *
+ * @param mediaType the media type
+ * @return the values supported
+ * @throws IllegalArgumentException if any argument is null
+ */
+ Set<V> resolve(MediaType mediaType) throws IllegalArgumentException;
+
+ /**
+ * Returns the set of values supported for a given type.
+ *
+ * @param type the type
+ * @return the values supported
+ * @throws IllegalArgumentException if any argument is null
+ */
+ Set<V> resolve(TypeDef type) throws IllegalArgumentException;
+
+ /**
+ * Returns the set of declared media types.
+ *
+ * @return the media types
+ */
+ Set<MediaType> getMediaTypes();
+
+ /**
+ * Returns the set of declared types.
+ *
+ * @return the types
+ */
+ Set<TypeDef> getTypes();
+
+ /**
+ * Returns the set of declared values.
+ *
+ * @return the values
+ */
+ Set<V> getValues();
+}
Copied: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java (from rev 10317, modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapImpl.java)
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java (rev 0)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaTypeMapImpl.java 2008-03-18 22:27:37 UTC (rev 10318)
@@ -0,0 +1,397 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.common.net.media;
+
+import org.jboss.portal.common.net.media.MediaType;
+import org.jboss.portal.common.net.media.TypeDef;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MediaTypeMapImpl<V> implements MediaTypeMap<V>
+{
+
+ /** . */
+ private static final String ANY = "*";
+
+ /** . */
+ private static final String ANY_ANY = "*/*";
+
+ /** . */
+ private static final char SEPARATOR = '/';
+
+ /** . */
+ private final Map<MediaType, Set<V>> mediaTypeToValues = new HashMap<MediaType,Set<V>>();
+
+ /** . */
+ private final Map<TypeDef, Set<V>> typeToValues = new HashMap<TypeDef,Set<V>>();
+
+ /** . */
+ private final Map<MediaType, Set<V>> combinedMediaTypeToValues = new HashMap<MediaType,Set<V>>();
+
+ /** . */
+ private final Map<TypeDef, Set<V>> combinedTypeToValues = new HashMap<TypeDef,Set<V>>();
+
+ /** . */
+ private final Set<V> anyTypeValues = new HashSet<V>();
+
+ /**
+ * Adds a value to the map using a media type pattern.
+ *
+ * @param mediaTypePattern the media type pattern
+ * @param value the value
+ * @throws IllegalArgumentException if any argument is null or the media type pattern is not valid
+ */
+ public void put(String mediaTypePattern, V value) throws IllegalArgumentException
+ {
+ if (mediaTypePattern == null)
+ {
+ throw new IllegalArgumentException("No null media type pattern accepted");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ if (ANY.equals(mediaTypePattern) || ANY_ANY.equals(mediaTypePattern))
+ {
+ put(value);
+ }
+ else
+ {
+ int index = mediaTypePattern.indexOf(SEPARATOR);
+
+ //
+ if (index == -1)
+ {
+ throw new IllegalArgumentException("Not a valid media type pattern value:" + mediaTypePattern);
+ }
+
+ //
+ String type = mediaTypePattern.substring(0, index);
+ String subtype = mediaTypePattern.substring(index + 1);
+
+ //
+ if (ANY.equals(subtype))
+ {
+ put(TypeDef.create(type), value);
+ }
+ else
+ {
+ put(MediaType.create(type, subtype), value);
+ }
+ }
+ }
+
+ /**
+ * Adds a value to the map.
+ *
+ * @param mediaType the media type
+ * @param value the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public void put(MediaType mediaType, V value) throws IllegalArgumentException
+ {
+ if (mediaType == null)
+ {
+ throw new IllegalArgumentException("No null media type accepted");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ Set<V> mediaTypeValues = mediaTypeToValues.get(mediaType);
+ if (mediaTypeValues == null)
+ {
+ mediaTypeValues = new HashSet<V>();
+ mediaTypeToValues.put(mediaType, mediaTypeValues);
+ }
+ mediaTypeValues.add(value);
+
+ //
+ Set<V> combinedMediaTypeValues = combinedMediaTypeToValues.get(mediaType);
+ if (combinedMediaTypeValues == null)
+ {
+ combinedMediaTypeValues = new HashSet<V>();
+ combinedMediaTypeToValues.put(mediaType, combinedMediaTypeValues);
+ }
+ combinedMediaTypeValues.add(value);
+
+ //
+ Set<V> combinedTypeValues = combinedTypeToValues.get(mediaType.getType());
+ if (combinedTypeValues != null)
+ {
+ combinedMediaTypeValues.addAll(combinedTypeValues);
+ }
+
+ //
+ combinedMediaTypeValues.addAll(anyTypeValues);
+ }
+
+ /**
+ * Adds a value to the map.
+ *
+ * @param type the type
+ * @param value the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public void put(TypeDef type, V value) throws IllegalArgumentException
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("No null type accepted");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ Set<V> typeValues = typeToValues.get(type);
+ if (typeValues == null)
+ {
+ typeValues = new HashSet<V>();
+ typeToValues.put(type, typeValues);
+ }
+ typeValues.add(value);
+
+ //
+ Set<V> combinedTypeValues = combinedTypeToValues.get(type);
+ if (combinedTypeValues == null)
+ {
+ combinedTypeValues = new HashSet<V>();
+ combinedTypeToValues.put(type, combinedTypeValues);
+ }
+ combinedTypeValues.add(value);
+
+ //
+ for (Map.Entry<MediaType, Set<V>> entry : combinedMediaTypeToValues.entrySet())
+ {
+ if (entry.getKey().getType().equals(type))
+ {
+ entry.getValue().add(value);
+ }
+ }
+ }
+
+ /**
+ * Adds a value to the map.
+ *
+ * @param value the value
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public void put(V value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ anyTypeValues.add(value);
+
+ //
+ for (Set<V> combinedTypeValues : combinedTypeToValues.values())
+ {
+ combinedTypeValues.add(value);
+ }
+
+ //
+ for (Set<V> combinedMediaTypeValues : combinedMediaTypeToValues.values())
+ {
+ combinedMediaTypeValues.add(value);
+ }
+ }
+
+ public Set<V> resolve(MediaType mediaType)
+ {
+ if (mediaType == null)
+ {
+ throw new IllegalArgumentException("No null media type accepted");
+ }
+
+ //
+ Set<V> values = combinedMediaTypeToValues.get(mediaType);
+
+ //
+ if (values == null)
+ {
+ values = resolve(mediaType.getType());
+ }
+
+ //
+ return values;
+ }
+
+ public Set<V> resolve(TypeDef type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("No null type accepted");
+ }
+
+ //
+ Set<V> values = combinedTypeToValues.get(type);
+
+ //
+ if (values == null)
+ {
+ values = getValues();
+ }
+
+ //
+ return values;
+ }
+
+ public Set<V> get(MediaType mediaType)
+ {
+ if (mediaType == null)
+ {
+ throw new IllegalArgumentException("No null media type accepted");
+ }
+
+ //
+ Set<V> values = combinedMediaTypeToValues.get(mediaType);
+
+ //
+ if (values == null)
+ {
+ values = Collections.emptySet();
+ }
+
+ //
+ return values;
+ }
+
+ public Set<V> get(TypeDef type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("No null type accepted");
+ }
+
+ //
+ Set<V> values = combinedTypeToValues.get(type);
+
+ //
+ if (values == null)
+ {
+ values = Collections.emptySet();
+ }
+
+ //
+ return values;
+ }
+
+ public Set<V> getValues()
+ {
+ return anyTypeValues;
+ }
+
+ public boolean isSupported(MediaType mediaType)
+ {
+ return resolve(mediaType).size() > 0;
+ }
+
+ public boolean isSupported(TypeDef type)
+ {
+ return resolve(type).size() > 0;
+ }
+
+ public boolean isSupported(MediaType mediaType, V value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ return resolve(mediaType).contains(value);
+ }
+
+ public boolean isSupported(TypeDef type, V value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ return resolve(type).contains(value);
+ }
+
+ public boolean isSupported(V value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+
+ //
+ return getValues().contains(value);
+ }
+
+ public boolean contains(MediaType mediaType)
+ {
+ return get(mediaType).size() > 0;
+ }
+
+ public boolean contains(TypeDef type)
+ {
+ return get(type).size() > 0;
+ }
+
+ public boolean contains(MediaType mediaType, V value)
+ {
+ return get(mediaType).contains(value);
+ }
+
+ public boolean contains(TypeDef type, V value)
+ {
+ return get(type).contains(value);
+ }
+
+ public boolean contains(V value)
+ {
+ return getValues().contains(value);
+ }
+
+ public Set<MediaType> getMediaTypes()
+ {
+ return combinedMediaTypeToValues.keySet();
+ }
+
+ public Set<TypeDef> getTypes()
+ {
+ return combinedTypeToValues.keySet();
+ }
+}
Deleted: modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMap.java
===================================================================
--- modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMap.java 2008-03-18 22:05:40 UTC (rev 10317)
+++ modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMap.java 2008-03-18 22:27:37 UTC (rev 10318)
@@ -1,194 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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.jboss.portal.test.common.net.media;
-
-import org.jboss.portal.common.net.media.MediaType;
-import org.jboss.portal.common.net.media.TypeDef;
-
-import java.util.Set;
-
-/**
- * A map containing values associated with media types. The map has the capability to map wildcard subtypes
- * (for instance text / *) or the wildcard type (* / *). In order to make the distinction between what the map
- * declares and what it supports it is possible to query the map with resolution or not.
- *
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface MediaTypeMap<V>
-{
-
- /**
- * Returns true if the map declares the specified media type.
- *
- * @param mediaType the media type
- * @return true if the map declares the media type
- * @throws IllegalArgumentException if the argument is null
- */
- boolean contains(MediaType mediaType) throws IllegalArgumentException;
-
- /**
- * Returns true if the map declares the specified type. It is equivalent to check if the map
- * contains a wildard subtype of a type.
- *
- * @param type the type
- * @return true if the map declares the type
- * @throws IllegalArgumentException if the argument is null
- */
- boolean contains(TypeDef type) throws IllegalArgumentException;
-
- /**
- * Returns true if the map declares the specified media type with a specified value.
- *
- * @param mediaType the media type
- * @param value the value
- * @return true if the map declares the media type and the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean contains(MediaType mediaType, V value) throws IllegalArgumentException;
-
- /**
- * Returns true if the map declares the specified type with a specific value. It is equivalent to check if the map
- * contains a wildard subtype of a type with a specific value.
- *
- * @param type the type
- * @param value the value
- * @return true if the map declares the media type and the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean contains(TypeDef type, V value) throws IllegalArgumentException;
-
- /**
- * Returns true if the map declares the specified value for any media type or any type. It is equivalent to check
- * if the map contains a wildcard type with a specific value.
- *
- * @param value the value
- * @return true if the map declares the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean contains(V value) throws IllegalArgumentException;
-
- /**
- * Returns the set of values declared for a given media type.
- *
- * @param mediaType the media type
- * @return the values declared
- * @throws IllegalArgumentException if any argument is null
- */
- Set<V> get(MediaType mediaType) throws IllegalArgumentException;
-
- /**
- * Returns the set of values declared for a given type.
- *
- * @param type the type
- * @return the values declared
- * @throws IllegalArgumentException if any argument is null
- */
- Set<V> get(TypeDef type) throws IllegalArgumentException;
-
- /**
- * Returns true if the map supports the specified media type.
- *
- * @param mediaType the media type
- * @return true if the map supports the media type
- * @throws IllegalArgumentException if the argument is null
- */
- boolean isSupported(MediaType mediaType) throws IllegalArgumentException;
-
- /**
- * Returns true if the map supports the specified type.
- *
- * @param type the type
- * @return true if the map declares the type
- * @throws IllegalArgumentException if the argument is null
- */
- boolean isSupported(TypeDef type) throws IllegalArgumentException;
-
- /**
- * Returns true if the map supports the specified media type with a specified value.
- *
- * @param mediaType the media type
- * @param value the value
- * @return true if the map supports the media type and the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean isSupported(MediaType mediaType, V value) throws IllegalArgumentException;
-
- /**
- * Returns true if the map supports the specified type with a specific value.
- *
- * @param type the type
- * @param value the value
- * @return true if the map supports the media type and the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean isSupported(TypeDef type, V value) throws IllegalArgumentException;
-
- /**
- * Returns true if the map supports the specified value for any media type or any type.
- *
- * @param value the value
- * @return true if the map supports the value
- * @throws IllegalArgumentException if any argument is null
- */
- boolean isSupported(V value) throws IllegalArgumentException;
-
- /**
- * Returns the set of values supported for a given media type.
- *
- * @param mediaType the media type
- * @return the values supported
- * @throws IllegalArgumentException if any argument is null
- */
- Set<V> resolve(MediaType mediaType) throws IllegalArgumentException;
-
- /**
- * Returns the set of values supported for a given type.
- *
- * @param type the type
- * @return the values supported
- * @throws IllegalArgumentException if any argument is null
- */
- Set<V> resolve(TypeDef type) throws IllegalArgumentException;
-
- /**
- * Returns the set of declared media types.
- *
- * @return the media types
- */
- Set<MediaType> getMediaTypes();
-
- /**
- * Returns the set of declared types.
- *
- * @return the types
- */
- Set<TypeDef> getTypes();
-
- /**
- * Returns the set of declared values.
- *
- * @return the values
- */
- Set<V> getValues();
-}
Deleted: modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapImpl.java
===================================================================
--- modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapImpl.java 2008-03-18 22:05:40 UTC (rev 10317)
+++ modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapImpl.java 2008-03-18 22:27:37 UTC (rev 10318)
@@ -1,397 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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.jboss.portal.test.common.net.media;
-
-import org.jboss.portal.common.net.media.MediaType;
-import org.jboss.portal.common.net.media.TypeDef;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class MediaTypeMapImpl<V> implements MediaTypeMap<V>
-{
-
- /** . */
- private static final String ANY = "*";
-
- /** . */
- private static final String ANY_ANY = "*/*";
-
- /** . */
- private static final char SEPARATOR = '/';
-
- /** . */
- private final Map<MediaType, Set<V>> mediaTypeToValues = new HashMap<MediaType,Set<V>>();
-
- /** . */
- private final Map<TypeDef, Set<V>> typeToValues = new HashMap<TypeDef,Set<V>>();
-
- /** . */
- private final Map<MediaType, Set<V>> combinedMediaTypeToValues = new HashMap<MediaType,Set<V>>();
-
- /** . */
- private final Map<TypeDef, Set<V>> combinedTypeToValues = new HashMap<TypeDef,Set<V>>();
-
- /** . */
- private final Set<V> anyTypeValues = new HashSet<V>();
-
- /**
- * Adds a value to the map using a media type pattern.
- *
- * @param mediaTypePattern the media type pattern
- * @param value the value
- * @throws IllegalArgumentException if any argument is null or the media type pattern is not valid
- */
- public void put(String mediaTypePattern, V value) throws IllegalArgumentException
- {
- if (mediaTypePattern == null)
- {
- throw new IllegalArgumentException("No null media type pattern accepted");
- }
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- if (ANY.equals(mediaTypePattern) || ANY_ANY.equals(mediaTypePattern))
- {
- put(value);
- }
- else
- {
- int index = mediaTypePattern.indexOf(SEPARATOR);
-
- //
- if (index == -1)
- {
- throw new IllegalArgumentException("Not a valid media type pattern value:" + mediaTypePattern);
- }
-
- //
- String type = mediaTypePattern.substring(0, index);
- String subtype = mediaTypePattern.substring(index + 1);
-
- //
- if (ANY.equals(subtype))
- {
- put(TypeDef.create(type), value);
- }
- else
- {
- put(MediaType.create(type, subtype), value);
- }
- }
- }
-
- /**
- * Adds a value to the map.
- *
- * @param mediaType the media type
- * @param value the value
- * @throws IllegalArgumentException if any argument is null
- */
- public void put(MediaType mediaType, V value) throws IllegalArgumentException
- {
- if (mediaType == null)
- {
- throw new IllegalArgumentException("No null media type accepted");
- }
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- Set<V> mediaTypeValues = mediaTypeToValues.get(mediaType);
- if (mediaTypeValues == null)
- {
- mediaTypeValues = new HashSet<V>();
- mediaTypeToValues.put(mediaType, mediaTypeValues);
- }
- mediaTypeValues.add(value);
-
- //
- Set<V> combinedMediaTypeValues = combinedMediaTypeToValues.get(mediaType);
- if (combinedMediaTypeValues == null)
- {
- combinedMediaTypeValues = new HashSet<V>();
- combinedMediaTypeToValues.put(mediaType, combinedMediaTypeValues);
- }
- combinedMediaTypeValues.add(value);
-
- //
- Set<V> combinedTypeValues = combinedTypeToValues.get(mediaType.getType());
- if (combinedTypeValues != null)
- {
- combinedMediaTypeValues.addAll(combinedTypeValues);
- }
-
- //
- combinedMediaTypeValues.addAll(anyTypeValues);
- }
-
- /**
- * Adds a value to the map.
- *
- * @param type the type
- * @param value the value
- * @throws IllegalArgumentException if any argument is null
- */
- public void put(TypeDef type, V value) throws IllegalArgumentException
- {
- if (type == null)
- {
- throw new IllegalArgumentException("No null type accepted");
- }
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- Set<V> typeValues = typeToValues.get(type);
- if (typeValues == null)
- {
- typeValues = new HashSet<V>();
- typeToValues.put(type, typeValues);
- }
- typeValues.add(value);
-
- //
- Set<V> combinedTypeValues = combinedTypeToValues.get(type);
- if (combinedTypeValues == null)
- {
- combinedTypeValues = new HashSet<V>();
- combinedTypeToValues.put(type, combinedTypeValues);
- }
- combinedTypeValues.add(value);
-
- //
- for (Map.Entry<MediaType, Set<V>> entry : combinedMediaTypeToValues.entrySet())
- {
- if (entry.getKey().getType().equals(type))
- {
- entry.getValue().add(value);
- }
- }
- }
-
- /**
- * Adds a value to the map.
- *
- * @param value the value
- * @throws IllegalArgumentException if any argument is null
- */
- public void put(V value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- anyTypeValues.add(value);
-
- //
- for (Set<V> combinedTypeValues : combinedTypeToValues.values())
- {
- combinedTypeValues.add(value);
- }
-
- //
- for (Set<V> combinedMediaTypeValues : combinedMediaTypeToValues.values())
- {
- combinedMediaTypeValues.add(value);
- }
- }
-
- public Set<V> resolve(MediaType mediaType)
- {
- if (mediaType == null)
- {
- throw new IllegalArgumentException("No null media type accepted");
- }
-
- //
- Set<V> values = combinedMediaTypeToValues.get(mediaType);
-
- //
- if (values == null)
- {
- values = resolve(mediaType.getType());
- }
-
- //
- return values;
- }
-
- public Set<V> resolve(TypeDef type)
- {
- if (type == null)
- {
- throw new IllegalArgumentException("No null type accepted");
- }
-
- //
- Set<V> values = combinedTypeToValues.get(type);
-
- //
- if (values == null)
- {
- values = getValues();
- }
-
- //
- return values;
- }
-
- public Set<V> get(MediaType mediaType)
- {
- if (mediaType == null)
- {
- throw new IllegalArgumentException("No null media type accepted");
- }
-
- //
- Set<V> values = combinedMediaTypeToValues.get(mediaType);
-
- //
- if (values == null)
- {
- values = Collections.emptySet();
- }
-
- //
- return values;
- }
-
- public Set<V> get(TypeDef type)
- {
- if (type == null)
- {
- throw new IllegalArgumentException("No null type accepted");
- }
-
- //
- Set<V> values = combinedTypeToValues.get(type);
-
- //
- if (values == null)
- {
- values = Collections.emptySet();
- }
-
- //
- return values;
- }
-
- public Set<V> getValues()
- {
- return anyTypeValues;
- }
-
- public boolean isSupported(MediaType mediaType)
- {
- return resolve(mediaType).size() > 0;
- }
-
- public boolean isSupported(TypeDef type)
- {
- return resolve(type).size() > 0;
- }
-
- public boolean isSupported(MediaType mediaType, V value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- return resolve(mediaType).contains(value);
- }
-
- public boolean isSupported(TypeDef type, V value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- return resolve(type).contains(value);
- }
-
- public boolean isSupported(V value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("No null value accepted");
- }
-
- //
- return getValues().contains(value);
- }
-
- public boolean contains(MediaType mediaType)
- {
- return get(mediaType).size() > 0;
- }
-
- public boolean contains(TypeDef type)
- {
- return get(type).size() > 0;
- }
-
- public boolean contains(MediaType mediaType, V value)
- {
- return get(mediaType).contains(value);
- }
-
- public boolean contains(TypeDef type, V value)
- {
- return get(type).contains(value);
- }
-
- public boolean contains(V value)
- {
- return getValues().contains(value);
- }
-
- public Set<MediaType> getMediaTypes()
- {
- return combinedMediaTypeToValues.keySet();
- }
-
- public Set<TypeDef> getTypes()
- {
- return combinedTypeToValues.keySet();
- }
-}
Modified: modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapTestCase.java
===================================================================
--- modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapTestCase.java 2008-03-18 22:05:40 UTC (rev 10317)
+++ modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeMapTestCase.java 2008-03-18 22:27:37 UTC (rev 10318)
@@ -26,6 +26,8 @@
import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.common.net.media.TypeDef;
import org.jboss.portal.common.net.media.SubtypeDef;
+import org.jboss.portal.common.net.media.MediaTypeMap;
+import org.jboss.portal.common.net.media.MediaTypeMapImpl;
import org.jboss.portal.common.util.Tools;
import java.util.Set;
16 years, 3 months