uk.ac.starlink.util
Class CgiQuery

java.lang.Object
  extended byuk.ac.starlink.util.CgiQuery

public class CgiQuery
extends Object

Utility class for constructing CGI query strings.

Since:
1 Oct 2004

Constructor Summary
CgiQuery(String base)
          Constructs a CGI query.
 
Method Summary
 CgiQuery addArgument(String name, double value)
          Adds a floating point argument to this query.
 CgiQuery addArgument(String name, float value)
          Adds a single-precision floating point argument to this query.
 CgiQuery addArgument(String name, long value)
          Adds an integer argument to this query.
 CgiQuery addArgument(String name, String value)
          Adds a string argument to this query.
 boolean equals(Object o)
           
static String formatDouble(double value)
          Formats a double precision value.
static String formatDouble(double value, int nsf, int maxleng)
          Formats a floating point value.
static String formatFloat(float value)
          Formats a single precision value.
 int hashCode()
           
 String toString()
          Returns this query as a string.
 URL toURL()
          Returns this query as a URL.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CgiQuery

public CgiQuery(String base)
Constructs a CGI query. The submitted base argument may optionally be a partially-formed CGI-query, that is, one ending in a '?' and zero or more '&name=value' pairs.

Parameters:
base - base part of the CGI URL
Throws:
IllegalArgumentException - if base is not a legal base URL
Method Detail

addArgument

public CgiQuery addArgument(String name,
                            long value)
Adds an integer argument to this query. For convenience the return value is this query.

Parameters:
name - argument name
value - value for the argument
Returns:
this query

addArgument

public CgiQuery addArgument(String name,
                            double value)
Adds a floating point argument to this query. For convenience the return value is this query.

Parameters:
name - argument name
value - value for the argument
Returns:
this query

addArgument

public CgiQuery addArgument(String name,
                            float value)
Adds a single-precision floating point argument to this query. For convenience the return value is this query.

Parameters:
name - argument name
value - value for the argument
Returns:
this query

addArgument

public CgiQuery addArgument(String name,
                            String value)
Adds a string argument to this query. For convenience the return value is this query.

Parameters:
name - argument name
value - unescaped value for the argument
Returns:
this query

toURL

public URL toURL()
Returns this query as a URL.

Returns:
query URL

equals

public boolean equals(Object o)

hashCode

public int hashCode()

toString

public String toString()
Returns this query as a string.

Returns:
query string

formatDouble

public static String formatDouble(double value)
Formats a double precision value.

Parameters:
value - value
Returns:
string representation

formatFloat

public static String formatFloat(float value)
Formats a single precision value.

Parameters:
value - value
Returns:
string representation

formatDouble

public static String formatDouble(double value,
                                  int nsf,
                                  int maxleng)
Formats a floating point value. It will be done in fixed point format if it can be done within the given number of characters, else exponential notation.

Parameters:
value - value
nsf - number of significant figures
maxleng - maximum length of string - if longer than this, will return to exponential notation
Returns:
fixed format string representation

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.