[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet ...
Julien Viet
julien at jboss.com
Sun Jul 30 20:20:50 EDT 2006
User: julien
Date: 06/07/30 20:20:50
Modified: portlet/src/main/org/jboss/portal/portlet
ParametersStateString.java
PortletRequestDecoder.java
Added: portlet/src/main/org/jboss/portal/portlet Parameters.java
Log:
move the Parameters class to org.jboss.portal.portlet package
Revision Changes Path
1.8 +1 -2 jboss-portal/portlet/src/main/org/jboss/portal/portlet/ParametersStateString.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ParametersStateString.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/portlet/src/main/org/jboss/portal/portlet/ParametersStateString.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ParametersStateString.java 31 Jul 2006 00:05:40 -0000 1.7
+++ ParametersStateString.java 31 Jul 2006 00:20:50 -0000 1.8
@@ -22,7 +22,6 @@
package org.jboss.portal.portlet;
import org.jboss.portal.common.util.Base64;
-import org.jboss.portal.server.util.Parameters;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -38,7 +37,7 @@
* A set of parameters.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class ParametersStateString extends StateString implements Serializable
{
1.3 +1 -2 jboss-portal/portlet/src/main/org/jboss/portal/portlet/PortletRequestDecoder.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PortletRequestDecoder.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/portlet/src/main/org/jboss/portal/portlet/PortletRequestDecoder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- PortletRequestDecoder.java 9 Jul 2006 12:04:15 -0000 1.2
+++ PortletRequestDecoder.java 31 Jul 2006 00:20:50 -0000 1.3
@@ -21,7 +21,6 @@
*/
package org.jboss.portal.portlet;
-import org.jboss.portal.server.util.Parameters;
import org.jboss.portal.server.request.RequestParameter;
import java.util.Iterator;
@@ -32,7 +31,7 @@
* Which means that this implementation does not preclude other implementations.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class PortletRequestDecoder
{
1.1 date: 2006/07/31 00:20:50; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/Parameters.java
Index: Parameters.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., 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.portlet;
import org.jboss.portal.common.util.ParameterMap;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Arrays;
/**
* A set of parameters.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class Parameters extends ParameterMap implements Serializable
{
/** The serialVersionUID */
private static final long serialVersionUID = -8529807471117491810L;
/** The data. */
private Map map;
/** Creates an empty parameter set. */
public Parameters()
{
this.map = new HashMap();
}
/**
* Copy constructor.
*
* @throws IllegalArgumentException if the parameters is null
*/
public Parameters(Parameters parameters)
{
if (parameters == null)
{
throw new IllegalArgumentException();
}
this.map = new HashMap(parameters.map);
}
/**
* Copy the parameter map to initialize the object state.
*
* @throws IllegalArgumentException if the parameter map is null or not valid
*/
public Parameters(Map parameterMap)
{
this.map = new HashMap();
replace(parameterMap);
}
protected Map getDelegate()
{
return map;
}
/**
* Return the parameter value or null if it does not exist.
*
* @param name the parameter name
* @return the parameter value or null if it does not exist
* @throws IllegalArgumentException if the name is null
*/
public String getValue(String name) throws IllegalArgumentException
{
if (name == null)
{
throw new IllegalArgumentException("name cannot be null");
}
String[] value = (String[])map.get(name);
return value == null ? null : value[0];
}
/**
* Return the parameter values or null if it does not exist.
*
* @param name the value to get
* @return the parameter values
* @throws IllegalArgumentException if the name is null
*/
public String[] getValues(String name) throws IllegalArgumentException
{
if (name == null)
{
throw new IllegalArgumentException("name cannot be null");
}
return (String[])map.get(name);
}
/**
* Set the a parameter value.
*
* @param name the parameter name
* @param value the parameter value
* @throws IllegalArgumentException if the name is null
* @throws IllegalArgumentException if the value is null
*/
public void setValue(String name, String value)
{
if (name == null)
{
throw new IllegalArgumentException("name must not be null");
}
if (value == null)
{
throw new IllegalArgumentException("value must not be null");
}
else
{
map.put(name, new String[]{value});
}
}
/**
* Set the parameter values. This method does not make a defensive copy of the values.
*
* @param name the parameter name
* @param values the parameter values
* @throws IllegalArgumentException if the name is null
*/
public void setValues(String name, String[] values)
{
if (name == null)
{
throw new IllegalArgumentException("name must not be null");
}
assertValue(values);
map.put(name, values);
}
/**
* Remove a parameter.
*
* @throws IllegalArgumentException if the name is null
*/
public void remove(String name)
{
if (name == null)
{
throw new IllegalArgumentException("name must not be null");
}
if (map != null)
{
map.remove(name);
}
}
/**
* Append the parameters to this object. All the entries will be inserted
* in the current map. If a collision occurs then the new values will be
* appended to the existing ones.
*
* @param params
* @throws IllegalArgumentException if the params is null
*/
public void append(Parameters params) throws IllegalArgumentException
{
if (params == null)
{
throw new IllegalArgumentException("Parameters to merge must be null");
}
internalAppend(params.map);
}
/**
* @param params the parameters to appends
* @throws IllegalArgumentException if the params argument is not valid
*/
public void append(Map params) throws IllegalArgumentException
{
assertMap(params);
internalAppend(params);
}
/**
* Append actual implementation.
*/
private void internalAppend(Map params)
{
for (Iterator entries = params.entrySet().iterator();entries.hasNext();)
{
Map.Entry entry = (Map.Entry)entries.next();
String name = (String)entry.getKey();
String[] appendedValues = (String[])entry.getValue();
// Merge or use appended values
String[] values = (String[])map.get(name);
if (values != null)
{
String[] tmp = new String[values.length + appendedValues.length];
System.arraycopy(values, 0, tmp, 0, values.length);
System.arraycopy(appendedValues, 0, tmp, values.length, appendedValues.length);
values = tmp;
}
else
{
values = appendedValues;
}
//
map.put(name, values);
}
}
/**
* Replace all the exisint parameters with the new ones.
*
* @throws IllegalArgumentException if the map is not valid
*/
public void replace(Map params)
{
assertMap(params);
internalReplace(params);
}
/**
* Replace all the parameters with the new ones.
*
* @throws IllegalArgumentException if the parameters is not valid
*/
public void replace(Parameters params)
{
if (params == null)
{
throw new IllegalArgumentException("parameters must not be null");
}
internalReplace(params.map);
}
/**
* Replace actual implementation.
*/
private void internalReplace(Map params)
{
map.clear();
for (Iterator i = params.entrySet().iterator(); i.hasNext();)
{
Map.Entry entry = (Entry)i.next();
String name = (String)entry.getKey();
String values[] = (String[])entry.getValue();
map.put(name, values.clone());
}
}
/**
* Compare to parameters objects.
*/
public boolean equals(Object o)
{
if (o == this)
{
return true;
}
if (o instanceof Parameters)
{
Parameters that = (Parameters)o;
if (that.map == null)
{
return map == null || map.size() == 0;
}
else if (map == null)
{
return that.map.size() == 0;
}
else if (that.map.size() != map.size())
{
return false;
}
for (Iterator i = that.map.entrySet().iterator(); i.hasNext();)
{
Map.Entry entry = (Map.Entry)i.next();
String[] values2 = (String[])map.get(entry.getKey());
if (values2 == null)
{
return false;
}
String[] values1 = (String[])entry.getValue();
if (!Arrays.equals(values1, values2))
{
return false;
}
}
return true;
}
return false;
}
public String toString()
{
StringBuffer buffer = new StringBuffer("Parameters[");
if (map != null)
{
for (Iterator i = map.entrySet().iterator(); i.hasNext();)
{
Map.Entry entry = (Map.Entry)i.next();
String name = (String)entry.getKey();
String[] values = (String[])entry.getValue();
buffer.append(name);
for (int j = 0; j < values.length; j++)
{
buffer.append(j > 0 ? ',' : '=').append(values[j]);
}
if (i.hasNext())
{
buffer.append(" | ");
}
}
}
buffer.append(']');
return buffer.toString();
}
protected void assertMap(Map that) throws IllegalArgumentException
{
if (that == null)
{
throw new IllegalArgumentException("Map cannot be null");
}
for (Iterator i = that.entrySet().iterator(); i.hasNext();)
{
Entry entry = (Entry)i.next();
assertKey(entry.getKey());
assertValue(entry.getValue());
}
}
}
More information about the jboss-cvs-commits
mailing list