You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by il...@apache.org on 2001/03/16 01:02:09 UTC
cvs commit: jakarta-turbine/src/java/org/apache/turbine/util CookieParser.java DataStreamParser.java DynamicURI.java ParameterParser.java ValueParser.java
ilkka 01/03/15 16:02:08
Modified: src/java/org/apache/turbine/util CookieParser.java
DataStreamParser.java DynamicURI.java
ParameterParser.java ValueParser.java
Log:
ValueParser, ParameterParser and CookieParser are now interfaces,
DataStreamParser and DynamicURI required some modifications to
accept the change
Revision Changes Path
1.4 +23 -67 jakarta-turbine/src/java/org/apache/turbine/util/CookieParser.java
Index: CookieParser.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/CookieParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CookieParser.java 2001/03/06 06:13:24 1.3
+++ CookieParser.java 2001/03/16 00:02:02 1.4
@@ -54,17 +54,10 @@
* <http://www.apache.org/>.
*/
-// JDK Classes
-import java.util.*;
-
-// Java Servlet Classes
-import javax.servlet.*;
-import javax.servlet.http.*;
-
/**
- * CookieParser is used to get and set values of Cookies on the Client
- * Browser. You can use CookieParser to convert Cookie values to
- * various types or to set Bean values with setParameters(). See the
+ * CookieParser is an interface to a utility to to get and set values
+ * of Cookies on the Client Browser. You can use CookieParser to convert
+ * Cookie values to various types or to set Bean values with setParameters().
* Servlet Spec for more information on Cookies.
* <p>
* Use set() or unset() to Create or Destroy Cookies.
@@ -84,92 +77,55 @@
*
* In the above example, result is 2.
*
+ * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
* @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
- * @version $Id: CookieParser.java,v 1.3 2001/03/06 06:13:24 chrise Exp $
+ * @version $Id: CookieParser.java,v 1.4 2001/03/16 00:02:02 ilkka Exp $
*/
-public class CookieParser extends ValueParser
+public interface CookieParser
+ extends ValueParser
{
public static final int AGE_SESSION = -1;
public static final int AGE_DELETE = 0;
- private HttpServletRequest req = null;
- private HttpServletResponse res = null;
-
- private DynamicURI cookiePath = null;
-
/**
- * Constructs a new Cookieparser using RunData. This constructor is called
- * when data.getCookies() is called, and you should usually not construct a
- * CookieParser manually.
+ * Gets the parsed RunData.
+ *
+ * @return the parsed RunData object or null.
*/
- public CookieParser (RunData data)
- {
- this.req = data.getRequest();
- this.res = data.getResponse();
-
- if (req.getCharacterEncoding() != null)
- setCharacterEncoding (req.getCharacterEncoding());
-
- cookiePath = new DynamicURI(data);
-
- Cookie[] cookies = req.getCookies();
+ public RunData getRunData();
- Log.info ("Number of Cookies "+cookies.length);
-
- for (int i=0; i<cookies.length; i++)
- {
- String name = convert (cookies[i].getName());
- String value = cookies[i].getValue();
- Log.info ("Adding "+name+"="+value);
- add (name,value);
- }
-
- }
+ /**
+ * Sets the RunData to be parsed.
+ * All previous cookies will be cleared.
+ *
+ * @param data the RunData object.
+ */
+ public void setRunData (RunData data);
/**
* Get the Path where cookies will be stored
*/
- public DynamicURI getCookiePath()
- {
- return cookiePath;
- }
+ public DynamicURI getCookiePath();
/**
* Set the path for cookie storage
*/
- public void setCookiePath (DynamicURI path)
- {
- cookiePath = path;
- }
+ public void setCookiePath (DynamicURI path);
/**
* Set a cookie that will be stored on the client for
* the duration of the session.
*/
- public void set (String name, String value)
- {
- set (name,value,AGE_SESSION);
- }
+ public void set (String name, String value);
/**
* Set a persisten cookie on the client that will expire
* after a maximum age (given in seconds).
*/
- public void set (String name, String value, int seconds_age)
- {
- Cookie cookie = new Cookie (name,value);
- cookie.setMaxAge (seconds_age);
- cookie.setPath (cookiePath.getScriptName());
- res.addCookie (cookie);
-
- }
+ public void set (String name, String value, int seconds_age);
/**
* Remove a previously set cookie from the client machine.
*/
- public void unset (String name)
- {
- set (name," ",AGE_DELETE);
- }
-
+ public void unset (String name);
}
1.5 +4 -2 jakarta-turbine/src/java/org/apache/turbine/util/DataStreamParser.java
Index: DataStreamParser.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/DataStreamParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DataStreamParser.java 2001/03/06 06:13:25 1.4
+++ DataStreamParser.java 2001/03/16 00:02:02 1.5
@@ -64,6 +64,8 @@
import java.util.List;
import java.util.NoSuchElementException;
+import org.apache.turbine.util.parser.BaseValueParser;
+
/**
* DataStreamParser is used to parse a stream with a fixed format and
* generate ValueParser objects which can be used to extract the values
@@ -84,7 +86,7 @@
* </pre>
*
* @author <a href="mailto:sean@informage.net">Sean Legassick</a>
- * @version $Id: DataStreamParser.java,v 1.4 2001/03/06 06:13:25 chrise Exp $
+ * @version $Id: DataStreamParser.java,v 1.5 2001/03/16 00:02:02 ilkka Exp $
*/
public abstract class DataStreamParser implements Iterator
{
@@ -213,7 +215,7 @@
throw new NoSuchElementException();
if (lineValues == null)
- lineValues = new ValueParser(characterEncoding);
+ lineValues = new BaseValueParser(characterEncoding);
else
lineValues.clear();
1.12 +5 -4 jakarta-turbine/src/java/org/apache/turbine/util/DynamicURI.java
Index: DynamicURI.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/DynamicURI.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DynamicURI.java 2001/03/06 06:13:25 1.11
+++ DynamicURI.java 2001/03/16 00:02:03 1.12
@@ -67,6 +67,7 @@
import javax.servlet.http.HttpServletResponse;
//Turbine Resources class
+import org.apache.turbine.util.parser.BaseValueParser;
import org.apache.turbine.services.resources.TurbineResources;
/**
@@ -89,7 +90,7 @@
*
* @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: DynamicURI.java,v 1.11 2001/03/06 06:13:25 chrise Exp $
+ * @version $Id: DynamicURI.java,v 1.12 2001/03/16 00:02:03 ilkka Exp $
*/
public class DynamicURI
{
@@ -363,7 +364,7 @@
String value )
{
Object[] tmp = new Object[2];
- tmp[0] = (Object) ParameterParser.convert(name);
+ tmp[0] = (Object) BaseValueParser.convertAndTrim(name);
tmp[1] = (Object) value;
switch (type)
{
@@ -663,7 +664,7 @@
e.hasMoreElements() ;)
{
Object[] tmp = (Object[]) e.nextElement();
- if ( ParameterParser.convert(name)
+ if ( BaseValueParser.convertAndTrim(name)
.equals ( (String)tmp[0] ) )
{
this.pathInfo.removeElement ( tmp );
@@ -679,7 +680,7 @@
e.hasMoreElements() ;)
{
Object[] tmp = (Object[]) e.nextElement();
- if ( ParameterParser.convert(name)
+ if ( BaseValueParser.convertAndTrim(name)
.equals ( (String)tmp[0] ) )
{
this.queryData.removeElement ( tmp );
1.29 +17 -165 jakarta-turbine/src/java/org/apache/turbine/util/ParameterParser.java
Index: ParameterParser.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/ParameterParser.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- ParameterParser.java 2001/03/06 06:13:28 1.28
+++ ParameterParser.java 2001/03/16 00:02:03 1.29
@@ -54,28 +54,14 @@
* <http://www.apache.org/>.
*/
-// Java Core Classes
-import java.io.*;
-import java.util.*;
-import java.beans.*;
-import java.lang.reflect.*;
-import java.text.*;
-import java.math.*;
-
// Java Servlet Classes
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-// JServ Utilities
-import org.apache.jserv.*;
+import javax.servlet.http.HttpServletRequest;
// Turbine stuff
-import org.apache.turbine.services.resources.*;
-import org.apache.turbine.services.upload.*;
-import org.apache.turbine.util.upload.*;
+import org.apache.turbine.util.upload.FileItem;
/**
- * ParameterParser is a utility object to handle parsing and
+ * ParameterParser is an interface to a utility to handle parsing and
* retrieving the data passed via the GET/POST/PATH_INFO arguments.
*
* <p>NOTE: The name= portion of a name=value pair may be converted
@@ -93,46 +79,23 @@
*
* In the above example, result is 2.
*
+ * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
* @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
* @author <a href="mailto:sean@informage.net">Sean Legassick</a>
- * @version $Id: ParameterParser.java,v 1.28 2001/03/06 06:13:28 chrise Exp $
+ * @version $Id: ParameterParser.java,v 1.29 2001/03/16 00:02:03 ilkka Exp $
*/
-public class ParameterParser extends ValueParser
+public interface ParameterParser
+ extends ValueParser
{
- /**
- * The raw data of a file upload.
- */
- private byte[] uploadData = null;
-
- /**
- * Create a new empty instance of ParameterParser. Uses the
- * default character encoding (US-ASCII).
- *
- * <p>To add name/value pairs to this set of parameters, use the
- * <code>add()</code> methods.
- *
- */
- public ParameterParser()
- {
- }
-
/**
- * Create a new empty instance of ParameterParser. Takes a
- * character encoding name to use when converting strings to
- * bytes.
+ * Gets the parsed servlet request.
*
- * <p>To add name/value pairs to this set of parameters, use the
- * <code>add()</code> methods.
- *
- * @param characterEncoding The character encoding of strings.
+ * @return the parsed servlet request or null.
*/
- public ParameterParser(String characterEncoding)
- {
- super (characterEncoding);
- }
+ public HttpServletRequest getRequest();
/**
- * Create a new instance of ParameterParser. This requires a
+ * Sets the servlet request to be parser. This requires a
* valid HttpServletRequest object. It will attempt to parse out
* the GET/POST/PATH_INFO data and store the data into a Hashtable.
* There are convenience methods for retrieving the data as a
@@ -144,91 +107,21 @@
*
* @param req An HttpServletRequest.
*/
- public ParameterParser(HttpServletRequest req)
- {
- if (req.getCharacterEncoding() != null)
- setCharacterEncoding (req.getCharacterEncoding());
-
- // String object re-use at its best.
- String tmp = null;
-
- tmp = req.getHeader("Content-type");
- if (tmp != null && tmp.startsWith("multipart/form-data") &&
- TurbineUpload.getAutomatic())
- {
- try
- {
- TurbineUpload.parseRequest(req, this);
- }
- catch(TurbineException e)
- {
- Log.error(new TurbineException("File upload failed", e));
- }
- }
-
- Enumeration names = req.getParameterNames();
- if ( names != null )
- {
- while(names.hasMoreElements())
- {
- tmp = (String) names.nextElement();
- parameters.put( convert(tmp), (Object) req.getParameterValues(tmp) );
- }
- }
-
- // Also cache any pathinfo variables that are passed around as
- // if they are query string data.
- try
- {
- StringTokenizer st = new StringTokenizer(req.getPathInfo(), "/");
- boolean name = true;
- String tmp2 = null;
- while(st.hasMoreTokens())
- {
- if ( name == true )
- {
- tmp = JServUtils.URLDecode(st.nextToken());
- name = false;
- }
- else
- {
- tmp2 = JServUtils.URLDecode(st.nextToken());
- if ( tmp.length() != 0 )
- {
- add (convert(tmp), tmp2);
- }
- name = true;
- }
- }
- }
- catch ( Exception e )
- {
- // If anything goes wrong above, don't worry about it.
- // Chances are that the path info was wrong anyways and
- // things that depend on it being right will fail later
- // and should be caught later.
- }
- }
+ public void setRequest(HttpServletRequest req);
/**
* Sets the uploadData byte[]
*
* @param uploadData A byte[] with data.
*/
- public void setUploadData ( byte[] uploadData )
- {
- this.uploadData = uploadData;
- }
+ public void setUploadData ( byte[] uploadData );
/**
* Gets the uploadData byte[]
*
* @returns uploadData A byte[] with data.
*/
- public byte[] setUploadData ()
- {
- return this.uploadData;
- }
+ public byte[] setUploadData ();
/**
@@ -241,23 +134,7 @@
* @param value A FileItem with the value.
*/
public void append( String name,
- FileItem value )
- {
- FileItem[] items = this.getFileItems(name);
- if(items == null)
- {
- items = new FileItem[1];
- items[0] = value;
- parameters.put( convert(name), items );
- }
- else
- {
- FileItem[] newItems = new FileItem[items.length+1];
- System.arraycopy(items, 0, newItems, 0, items.length);
- newItems[items.length] = value;
- parameters.put( convert(name), newItems );
- }
- }
+ FileItem value );
/**
@@ -267,21 +144,7 @@
* @param name A String with the name.
* @return A FileItem.
*/
- public FileItem getFileItem(String name)
- {
- try
- {
- FileItem value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- value = ((FileItem[])object)[0];
- return value;
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public FileItem getFileItem(String name);
/**
* Return an array of FileItem objects for the given name. If the
@@ -291,16 +154,5 @@
* @param name A String with the name.
* @return A FileItem[].
*/
- public FileItem[] getFileItems(String name)
- {
- try
- {
- return (FileItem[])parameters.get(convert(name));
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
-
+ public FileItem[] getFileItems(String name);
}
1.5 +77 -690 jakarta-turbine/src/java/org/apache/turbine/util/ValueParser.java
Index: ValueParser.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/ValueParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ValueParser.java 2001/03/09 11:46:58 1.4
+++ ValueParser.java 2001/03/16 00:02:04 1.5
@@ -55,106 +55,68 @@
*/
// Java Core Classes
-import java.io.*;
-import java.util.*;
-import java.beans.*;
-import java.lang.reflect.*;
-import java.text.*;
-import java.math.*;
-
-// Java Servlet Classes
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.util.Date;
+import java.util.Enumeration;
+import java.text.DateFormat;
+import java.math.BigDecimal;
+import java.io.UnsupportedEncodingException;
-// JServ Utilities
-import org.apache.jserv.*;
-
// Turbine stuff
-import org.apache.turbine.services.resources.*;
import org.apache.turbine.om.NumberKey;
import org.apache.turbine.om.StringKey;
/**
- * ValueParser is a base class for classes that need to parse
+ * ValueParser is a base interface for classes that need to parse
* name/value Parameters, for example GET/POST data or Cookies
* (ParameterParser and CookieParser)
*
- * <p>It can also be used standalone, for an example see DataStreamParser.
- *
* <p>NOTE: The name= portion of a name=value pair may be converted
* to lowercase or uppercase when the object is initialized and when
* new data is added. This behaviour is determined by the url.case.folding
* property in TurbineResources.properties. Adding a name/value pair may
* overwrite existing name=value pairs if the names match:
- *
- * <pre>
- * ValueParser vp = new ValueParser();
- * bp.add("ERROR",1);
- * bp.add("eRrOr",2);
- * int result = vp.getInt("ERROR");
- * </pre>
*
- * In the above example, result is 2.
- *
+ * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
* @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
* @author <a href="mailto:sean@informage.net">Sean Legassick</a>
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: ValueParser.java,v 1.4 2001/03/09 11:46:58 jmcnally Exp $
+ * @version $Id: ValueParser.java,v 1.5 2001/03/16 00:02:04 ilkka Exp $
*/
-public class ValueParser
+public interface ValueParser
{
- /**
- * Random access storage for parameter data.
- */
- protected Hashtable parameters = new Hashtable();
/**
- * The character encoding to use when converting to byte arrays
+ * The case folding property specifying the case folding
+ * to apply to value keys of the parser.
*/
- private String characterEncoding = "US-ASCII";
-
public static final String URL_CASE_FOLDING = "url.case.folding";
public static final String URL_CASE_FOLDING_NONE = "none";
public static final String URL_CASE_FOLDING_LOWER = "lower";
public static final String URL_CASE_FOLDING_UPPER = "upper";
/**
- * Default constructor
- */
- public ValueParser()
- {
- }
-
- /**
- * Constructor that takes a character encoding
- */
- public ValueParser(String characterEncoding)
- {
- setCharacterEncoding(characterEncoding);
- }
-
- /**
* Clear all name/value pairs out of this object.
*/
- public void clear()
- {
- parameters.clear();
- }
+ public void clear();
/**
* Set the character encoding that will be used by this ValueParser.
*/
- public void setCharacterEncoding (String s)
- {
- characterEncoding = s;
- }
+ public void setCharacterEncoding (String s);
/**
* Get the character encoding that will be used by this ValueParser.
+ */
+ public String getCharacterEncoding ();
+
+ /**
+ * Trims the string data and applies the conversion specified in
+ * the property given by URL_CASE_FOLDING. It returns a new
+ * string so that it does not destroy the value data.
+ *
+ * @param value A String to be processed.
+ * @return A new String converted to lowercase and trimmed.
*/
- public String getCharacterEncoding ()
- {
- return characterEncoding;
- }
+ public String convert ( String value );
/**
* Add a name/value pair into this object.
@@ -163,10 +125,7 @@
* @param value A double with the value.
*/
public void add ( String name,
- double value )
- {
- add ( name, Double.toString(value));
- }
+ double value );
/**
* Add a name/value pair into this object.
@@ -175,10 +134,7 @@
* @param value An int with the value.
*/
public void add ( String name,
- int value )
- {
- add ( name, Integer.toString(value));
- }
+ int value );
/**
* Add a name/value pair into this object.
@@ -187,10 +143,7 @@
* @param value An Integer with the value.
*/
public void add ( String name,
- Integer value )
- {
- add ( name, value.toString());
- }
+ Integer value );
/**
* Add a name/value pair into this object.
@@ -199,10 +152,7 @@
* @param value A long with the value.
*/
public void add ( String name,
- long value )
- {
- add ( name, Long.toString(value));
- }
+ long value );
/**
* Add a name/value pair into this object.
@@ -211,10 +161,7 @@
* @param value A long with the value.
*/
public void add ( String name,
- String value )
- {
- append ( name, value);
- }
+ String value );
/**
* Add a String parameters. If there are any Strings already
@@ -225,23 +172,7 @@
* @param value A String with the value.
*/
public void append( String name,
- String value )
- {
- String[] items = this.getStrings(name);
- if(items == null)
- {
- items = new String[1];
- items[0] = value;
- parameters.put( convert(name), items );
- }
- else
- {
- String[] newItems = new String[items.length+1];
- System.arraycopy(items, 0, newItems, 0, items.length);
- newItems[items.length] = value;
- parameters.put( convert(name), newItems );
- }
- }
+ String value );
/**
* Removes the named parameter from the contained hashtable. Wraps to the
@@ -251,36 +182,9 @@
* @return The value that was mapped to the key (a <code>String[]</code>)
* or <code>null</code> if the key was not mapped.
*/
- public Object remove(String name)
- {
- return parameters.remove( convert(name) );
- }
+ public Object remove(String name);
/**
- * Trims the string data and applies the conversion specified in
- * the property given by URL_CASE_FOLDING. It returns a new
- * string so that it does not destroy the value data.
- *
- * @param value A String to be processed.
- * @return A new String converted to lowercase and trimmed.
- */
- public static String convert ( String value )
- {
- String tmp = value.trim();
- String fold =
- TurbineResources.getString(URL_CASE_FOLDING, "")
- .toLowerCase();
- if ((fold == null) ||
- (fold.equals("")) ||
- (fold.equals(URL_CASE_FOLDING_LOWER)))
- return (tmp.toLowerCase());
- else if (fold.equals(URL_CASE_FOLDING_UPPER))
- return (tmp.toUpperCase());
-
- return (tmp);
- }
-
- /**
* Determine whether a given key has been inserted. All keys are
* stored in lowercase strings, so override method to account for
* this.
@@ -288,10 +192,7 @@
* @param key An Object with the key to search for.
* @return True if the object is found.
*/
- public boolean containsKey( Object key )
- {
- return parameters.containsKey(convert((String)key));
- }
+ public boolean containsKey( Object key );
/**
* Check for existence of key_day, key_month and key_year
@@ -300,12 +201,7 @@
* @param key A String with the selector name.
* @return True if keys are found.
*/
- public boolean containsDateSelectorKeys(String key)
- {
- return (containsKey(key + DateSelector.DAY_SUFFIX) &&
- containsKey(key + DateSelector.MONTH_SUFFIX) &&
- containsKey(key + DateSelector.YEAR_SUFFIX));
- }
+ public boolean containsDateSelectorKeys(String key);
/*
* Get an enumerator for the parameter keys. Wraps to the
@@ -313,20 +209,14 @@
*
* @return An <code>enumerator</code> of the keys.
*/
- public Enumeration keys()
- {
- return parameters.keys();
- }
+ public Enumeration keys();
/*
* Returns all the available parameter names.
*
* @return A object array with the keys.
*/
- public Object[] getKeys()
- {
- return parameters.keySet().toArray();
- }
+ public Object[] getKeys();
/**
* Return a boolean for the given name. If the name does not
@@ -337,27 +227,7 @@
* @return A boolean.
*/
public boolean getBoolean(String name,
- boolean defaultValue)
- {
- boolean value = defaultValue;
- Object object = parameters.get(convert(name));
- if (object != null)
- {
- String tmp = getString(name);
- if ( tmp.equalsIgnoreCase ("1") ||
- tmp.equalsIgnoreCase ("true") ||
- tmp.equalsIgnoreCase ("on") )
- {
- value = true;
- }
- if ( tmp.equalsIgnoreCase ("0") ||
- tmp.equalsIgnoreCase ("false") )
- {
- value = false;
- }
- }
- return value;
- }
+ boolean defaultValue);
/**
* Return a boolean for the given name. If the name does not
@@ -366,10 +236,7 @@
* @param name A String with the name.
* @return A boolean.
*/
- public boolean getBoolean(String name)
- {
- return getBoolean(name, false);
- }
+ public boolean getBoolean(String name);
/**
* Return a Boolean for the given name. If the name does not
@@ -380,10 +247,7 @@
* @return A Boolean.
*/
public Boolean getBool(String name,
- boolean defaultValue)
- {
- return new Boolean(getBoolean(name, defaultValue));
- }
+ boolean defaultValue);
/**
* Return a Boolean for the given name. If the name does not
@@ -392,10 +256,7 @@
* @param name A String with the name.
* @return A Boolean.
*/
- public Boolean getBool(String name)
- {
- return new Boolean(getBoolean(name, false));
- }
+ public Boolean getBool(String name);
/**
* Return a double for the given name. If the name does not
@@ -406,20 +267,7 @@
* @return A double.
*/
public double getDouble(String name,
- double defaultValue)
- {
- double value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = Double.valueOf(((String[])object)[0]).doubleValue();
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ double defaultValue);
/**
* Return a double for the given name. If the name does not
@@ -428,10 +276,8 @@
* @param name A String with the name.
* @return A double.
*/
- public double getDouble(String name)
- {
- return getDouble(name, 0.0);
- }
+ public double getDouble(String name);
+
/**
* Return a float for the given name. If the name does not
* exist, return defaultValue.
@@ -441,22 +287,8 @@
* @return A float.
*/
public float getFloat(String name,
- float defaultValue)
- {
- float value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = Float.valueOf(((String[])object)[0]).floatValue();
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ float defaultValue);
-
/**
* Return a float for the given name. If the name does not
* exist, return 0.0.
@@ -464,10 +296,7 @@
* @param name A String with the name.
* @return A float.
*/
- public float getFloat(String name)
- {
- return getFloat(name, 0.0f);
- }
+ public float getFloat(String name);
/**
* Return a BigDecimal for the given name. If the name does not
@@ -478,20 +307,7 @@
* @return A BigDecimal.
*/
public BigDecimal getBigDecimal(String name,
- BigDecimal defaultValue)
- {
- BigDecimal value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = new BigDecimal(((String[])object)[0]);
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ BigDecimal defaultValue);
/**
* Return a BigDecimal for the given name. If the name does not
@@ -500,10 +316,7 @@
* @param name A String with the name.
* @return A BigDecimal.
*/
- public BigDecimal getBigDecimal(String name)
- {
- return getBigDecimal(name, new BigDecimal(0.0));
- }
+ public BigDecimal getBigDecimal(String name);
/**
* Return an array of BigDecimals for the given name. If the name
@@ -512,19 +325,7 @@
* @param name A String with the name.
* @return A BigDecimal[].
*/
- public BigDecimal[] getBigDecimals(String name)
- {
- BigDecimal[] value = null;
- Object object = getStrings(convert(name));
- if (object != null)
- {
- String[] temp = (String[])object;
- value = new BigDecimal[temp.length];
- for (int i=0; i<temp.length; i++)
- value[i] = new BigDecimal( temp[i] );
- }
- return value;
- }
+ public BigDecimal[] getBigDecimals(String name);
/**
* Return an int for the given name. If the name does not exist,
@@ -535,20 +336,7 @@
* @return An int.
*/
public int getInt(String name,
- int defaultValue )
- {
- int value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = Integer.valueOf(((String[])object)[0]).intValue();
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ int defaultValue );
/**
* Return an int for the given name. If the name does not exist,
@@ -557,10 +345,7 @@
* @param name A String with the name.
* @return An int.
*/
- public int getInt(String name)
- {
- return getInt(name, 0);
- }
+ public int getInt(String name);
/**
* Return an Integer for the given name. If the name does not
@@ -571,10 +356,7 @@
* @return An Integer.
*/
public Integer getInteger(String name,
- int defaultValue)
- {
- return new Integer(getInt(name, defaultValue));
- }
+ int defaultValue);
/**
* Return an Integer for the given name. If the name does not
@@ -586,10 +368,7 @@
* @return An Integer.
*/
public Integer getInteger(String name,
- Integer def)
- {
- return new Integer(getInt(name, def.intValue()));
- }
+ Integer def);
/**
* Return an Integer for the given name. If the name does not
@@ -598,10 +377,7 @@
* @param name A String with the name.
* @return An Integer.
*/
- public Integer getInteger(String name)
- {
- return new Integer(getInt(name, 0));
- }
+ public Integer getInteger(String name);
/**
* Return an array of ints for the given name. If the name does
@@ -610,19 +386,7 @@
* @param name A String with the name.
* @return An int[].
*/
- public int[] getInts(String name)
- {
- int[] value = null;
- Object object = getStrings(convert(name));
- if (object != null)
- {
- String[] temp = (String[])object;
- value = new int[temp.length];
- for (int i=0; i<temp.length; i++)
- value[i] = Integer.parseInt( temp[i] );
- }
- return value;
- }
+ public int[] getInts(String name);
/**
* Return an array of Integers for the given name. If the name
@@ -631,19 +395,7 @@
* @param name A String with the name.
* @return An Integer[].
*/
- public Integer[] getIntegers(String name)
- {
- Integer[] value = null;
- Object object = getStrings(convert(name));
- if (object != null)
- {
- String[] temp = (String[])object;
- value = new Integer[temp.length];
- for (int i=0; i<temp.length; i++)
- value[i] = Integer.valueOf( temp[i] );
- }
- return value;
- }
+ public Integer[] getIntegers(String name);
/**
* Return a long for the given name. If the name does not exist,
@@ -654,20 +406,7 @@
* @return A long.
*/
public long getLong(String name,
- long defaultValue )
- {
- long value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = Long.valueOf(((String[])object)[0]).longValue();
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ long defaultValue );
/**
* Return a long for the given name. If the name does not exist,
@@ -676,10 +415,7 @@
* @param name A String with the name.
* @return A long.
*/
- public long getLong(String name)
- {
- return getLong(name, 0);
- }
+ public long getLong(String name);
/**
* Return an array of longs for the given name. If the name does
@@ -688,19 +424,7 @@
* @param name A String with the name.
* @return A long[].
*/
- public long[] getLongs(String name)
- {
- long[] value = null;
- Object object = getStrings(convert(name));
- if (object != null)
- {
- String[] temp = (String[])object;
- value = new long[temp.length];
- for (int i=0; i<temp.length; i++)
- value[i] = Long.parseLong( temp[i] );
- }
- return value;
- }
+ public long[] getLongs(String name);
/**
* Return an array of Longs for the given name. If the name does
@@ -709,19 +433,7 @@
* @param name A String with the name.
* @return A Long[].
*/
- public Long[] getLongObjects(String name)
- {
- Long[] value = null;
- Object object = getStrings(convert(name));
- if (object != null)
- {
- String[] temp = (String[])object;
- value = new Long[temp.length];
- for (int i=0; i<temp.length; i++)
- value[i] = Long.valueOf( temp[i] );
- }
- return value;
- }
+ public Long[] getLongObjects(String name);
/**
* Return a byte for the given name. If the name does not exist,
@@ -732,20 +444,7 @@
* @return A byte.
*/
public byte getByte(String name,
- byte defaultValue )
- {
- byte value = defaultValue;
- try
- {
- Object object = parameters.get(convert(name));
- if (object != null)
- value = Byte.valueOf(((String[])object)[0]).byteValue();
- }
- catch (NumberFormatException exception)
- {
- }
- return value;
- }
+ byte defaultValue );
/**
* Return a byte for the given name. If the name does not exist,
@@ -754,10 +453,7 @@
* @param name A String with the name.
* @return A byte.
*/
- public byte getByte(String name)
- {
- return getByte(name, (byte) 0);
- }
+ public byte getByte(String name);
/**
* Return an array of bytes for the given name. If the name does
@@ -769,13 +465,7 @@
* @exception UnsupportedEncodingException.
*/
public byte[] getBytes(String name)
- throws UnsupportedEncodingException
- {
- String tempStr = getString(name);
- if ( tempStr != null )
- return tempStr.getBytes(characterEncoding);
- return null;
- }
+ throws UnsupportedEncodingException;
/**
* Return a String for the given name. If the name does not
@@ -784,23 +474,7 @@
* @param name A String with the name.
* @return A String.
*/
- public String getString(String name)
- {
- try
- {
- String value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- value = ((String[])object)[0];
- if (value == null || value.equals("null"))
- return null;
- return value;
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public String getString(String name);
/**
* Return a String for the given name. If the name does not
@@ -814,10 +488,7 @@
* @param name A String with the name.
* @return A String.
*/
- public String get (String name)
- {
- return getString(name);
- }
+ public String get (String name);
/**
* Return a String for the given name. If the name does not
@@ -828,16 +499,7 @@
* @return A String.
*/
public String getString(String name,
- String defaultValue)
- {
- String value = getString(name);
- if (value == null ||
- value.length() == 0 ||
- value.equals("null"))
- return defaultValue;
- else
- return value;
- }
+ String defaultValue);
/**
* Set a parameter to a specific value.
@@ -847,13 +509,7 @@
* @param name The name of the parameter.
* @param value The value to set.
*/
- public void setString(String name, String value)
- {
- if(value != null)
- {
- parameters.put(convert(name), new String[] {value} );
- }
- }
+ public void setString(String name, String value);
/**
* Return an array of Strings for the given name. If the name
@@ -862,14 +518,7 @@
* @param name A String with the name.
* @return A String[].
*/
- public String[] getStrings(String name)
- {
- String[] value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- value = ((String[])object);
- return value;
- }
+ public String[] getStrings(String name);
/**
* Return an array of Strings for the given name. If the name
@@ -880,15 +529,7 @@
* @return A String[].
*/
public String[] getStrings(String name,
- String[] defaultValue)
- {
- String[] value = getStrings(name);
- if (value == null ||
- value.length == 0)
- return defaultValue;
- else
- return value;
- }
+ String[] defaultValue);
/**
* Set a parameter to a specific value.
@@ -898,13 +539,7 @@
* @param name The name of the parameter.
* @param values The value to set.
*/
- public void setStrings(String name, String[] values)
- {
- if(values != null)
- {
- parameters.put(convert(name), values);
- }
- }
+ public void setStrings(String name, String[] values);
/**
* Return an Object for the given name. If the name does not
@@ -913,21 +548,7 @@
* @param name A String with the name.
* @return An Object.
*/
- public Object getObject(String name)
- {
- try
- {
- Object value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- value = ((Object[])object)[0];
- return value;
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public Object getObject(String name);
/**
* Return an array of Objects for the given name. If the name
@@ -936,17 +557,7 @@
* @param name A String with the name.
* @return An Object[].
*/
- public Object[] getObjects(String name)
- {
- try
- {
- return (Object[])parameters.get(convert(name));
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public Object[] getObjects(String name);
/**
* Returns a java.util.Date object. String is parsed by supplied
@@ -960,29 +571,7 @@
*/
public Date getDate(String name,
DateFormat df,
- Date defaultValue)
- {
- Date date = null;
-
- if (containsKey(name))
- {
- try
- {
- // Reject invalid dates.
- df.setLenient(false);
- date = df.parse(getString(name));
- }
- catch (ParseException e)
- {
- // Thrown if couldn't parse date.
- date = defaultValue;
- }
- }
- else
- date = defaultValue;
-
- return date;
- }
+ Date defaultValue);
/**
* Returns a java.util.Date object. If there are DateSelector
@@ -993,36 +582,7 @@
* @param name A String with the name.
* @return A Date.
*/
- public Date getDate(String name)
- {
- Date date = null;
-
- if (containsDateSelectorKeys(name))
- {
- try
- {
- Calendar cal = new GregorianCalendar(
- getInt(name + DateSelector.YEAR_SUFFIX),
- getInt(name + DateSelector.MONTH_SUFFIX),
- getInt(name + DateSelector.DAY_SUFFIX));
-
- // Reject invalid dates.
- cal.setLenient(false);
- date = cal.getTime();
- }
- catch (IllegalArgumentException e)
- {
- // Thrown if an invalid date.
- }
- }
- else
- {
- DateFormat df = DateFormat.getDateInstance();
- date = getDate(name, df, null);
- }
-
- return date;
- }
+ public Date getDate(String name);
/**
* Returns a java.util.Date object. String is parsed by supplied
@@ -1033,10 +593,7 @@
* @return A Date.
*/
public Date getDate(String name,
- DateFormat df)
- {
- return getDate(name, df, null);
- }
+ DateFormat df);
/**
* Return an NumberKey for the given name. If the name does not
@@ -1045,23 +602,7 @@
* @param name A String with the name.
* @return An NumberKey.
*/
- public NumberKey getNumberKey(String name)
- {
- try
- {
- String value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- {
- value = ((String[])object)[0];
- }
- return new NumberKey(value);
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public NumberKey getNumberKey(String name);
/**
* Return an NumberKey for the given name. If the name does not
@@ -1070,23 +611,7 @@
* @param name A String with the name.
* @return An StringKey.
*/
- public StringKey getStringKey(String name)
- {
- try
- {
- String value = null;
- Object object = parameters.get(convert(name));
- if (object != null)
- {
- value = ((String[])object)[0];
- }
- return new StringKey(value);
- }
- catch ( ClassCastException e )
- {
- return null;
- }
- }
+ public StringKey getStringKey(String name);
/**
* Uses bean introspection to set writable properties of bean from
@@ -1097,151 +622,13 @@
* @exception Exception, a generic exception.
*/
public void setProperties(Object bean)
- throws Exception
- {
- Class beanClass = bean.getClass();
- PropertyDescriptor[] props
- = Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
-
- for (int i = 0; i < props.length; i++)
- {
- String propname = props[i].getName();
- Method setter = props[i].getWriteMethod();
- if (setter != null &&
- (containsKey(propname) ||
- containsDateSelectorKeys(propname)))
- {
- setProperty(bean, props[i]);
- }
- }
- }
-
- /**
- * Set the property 'prop' in the bean to the value of the
- * corresponding parameters. Supports all types supported by
- * getXXX methods plus a few more that come for free because
- * primitives have to be wrapped before being passed to invoke
- * anyway.
- *
- * @param bean An Object.
- * @param prop A PropertyDescriptor.
- * @exception Exception, a generic exception.
- */
- private void setProperty(Object bean,
- PropertyDescriptor prop)
- throws Exception
- {
- if (prop instanceof IndexedPropertyDescriptor)
- {
- throw new Exception(prop.getName() +
- " is an indexed property (not supported)");
- }
-
- Method setter = prop.getWriteMethod();
- if (setter == null)
- {
- throw new Exception(prop.getName() +
- " is a read only property");
- }
-
- Class propclass = prop.getPropertyType();
- Object[] args = { null };
-
- if (propclass == String.class)
- {
- args[0] = getString(prop.getName());
- }
- else if (propclass == Integer.class || propclass == Integer.TYPE)
- {
- args[0] = getInteger(prop.getName());
- }
- else if (propclass == Long.class || propclass == Long.TYPE)
- {
- args[0] = new Long(getLong(prop.getName()));
- }
- else if (propclass == Boolean.class || propclass == Boolean.TYPE)
- {
- args[0] = getBool(prop.getName());
- }
- else if (propclass == Double.class || propclass == Double.TYPE)
- {
- args[0] = new Double(getDouble(prop.getName()));
- }
- else if (propclass == String[].class)
- {
- args[0] = getStrings(prop.getName());
- }
- else if (propclass == Object.class)
- {
- args[0] = getObject(prop.getName());
- }
- else if (propclass == int[].class)
- {
- args[0] = getInts(prop.getName());
- }
- else if (propclass == Integer[].class)
- {
- args[0] = getIntegers(prop.getName());
- }
- else if (propclass == Date.class)
- {
- args[0] = getDate(prop.getName());
- }
- else if (propclass == NumberKey.class)
- {
- args[0] = getNumberKey(prop.getName());
- }
- else if (propclass == StringKey.class)
- {
- args[0] = getStringKey(prop.getName());
- }
- else
- {
- throw new Exception("property "
- + prop.getName()
- + " is of unsupported type "
- + propclass.toString());
- }
+ throws Exception;
- setter.invoke(bean, args);
- }
-
/**
* Simple method that attempts to get a toString() representation
* of this object. It doesn't do well with String[]'s though.
*
* @return A String.
*/
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- for (Enumeration e = parameters.keys() ; e.hasMoreElements() ;)
- {
- String name = (String) e.nextElement();
- try
- {
- sb.append ("{");
- sb.append(name);
- sb.append("=");
- sb.append(this.getString(name));
- sb.append ("}\n");
- }
- catch ( Exception ee)
- {
- try
- {
- sb.append ("{");
- sb.append(name);
- sb.append("=");
- sb.append ("ERROR?");
- sb.append ("}\n");
- }
- catch ( Exception eee )
- {
- }
- }
- }
- return sb.toString();
- }
-
+ public String toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org