com.ibm.as400.webaccess.util
Class URLGenerator

java.lang.Object
  |
  +--com.ibm.as400.webaccess.util.URLGenerator

public class URLGenerator
extends java.lang.Object

The URLGenerator class is used to generate URL strings for the documented iSeries Access for Web servlet functions and their parameters.

      // Example 1: Generate the URL String for 'Create Copy Data Request'
      ServletDescriptor descriptor = URLGenerator.getDescriptor("iWADbUpload")[0];
      URLGenerator gen = new URLGenerator(descriptor);
      gen.setBaseURI("http://system:8080/webaccess/");
      gen.setPathInfo("xx");
      ServletParameter parm = descriptor.getParameter("request");
      gen.addServletParameter(parm, "mySavedRequest");
      String url = gen.generate();
      System.out.println("'"+url+"'");

      // Example 2: List all the registered iSeries Access for Web servlet descriptors.
      ServletDescriptor[] sds = URLGenerator.getDescriptors();
      for (int i=0; i<sds.length; ++i)
      {
        String translatedTitle = sds[i].getTitle(gen.getBundle());
        String translatedDescription = sds[i].getDescription(gen.getBundle());
        String servletURI = sds[i].getURI();
        System.out.println(translatedTitle+" ("+servletURI+") - "+translatedDescription);
      }
 


Field Summary
static java.util.ListResourceBundle US_ENGLISH_BUNDLE
           
 
Constructor Summary
URLGenerator(ServletDescriptor descriptor)
          Constructs a URLGenerator using the default English resource bundle.
URLGenerator(ServletDescriptor descriptor, java.util.ResourceBundle bundle)
          Constructs a URLGenerator using the provided resource bundle.
 
Method Summary
 void addServletParameter(ServletParameter parm)
          Adds a parameter with a default value for the servlet that is having its URL generated.
 void addServletParameter(ServletParameter parm, java.lang.Object value)
          Adds a parameter and its value for the servlet that is having its URL generated.
 void addServletParameter(ServletParameter parm, ServletParameterValue value)
          Adds a parameter and its value for the servlet that is having its URL generated.
 java.lang.String generate()
          Generates the URL string given the current servlet descriptor, path info, and parameters.
 java.util.ResourceBundle getBundle()
          Returns the resource bundle in use by this generator.
static ServletDescriptor[] getDescriptor(java.lang.String uri)
          Returns a descriptor for the given servlet URI, or null if no match was found.
static ServletDescriptor[] getDescriptors()
          Returns an array of all known servlet descriptors.
static ServletDescriptor[] getDescriptors(int category)
          Returns an array of descriptors for the given servlet category, or an empty array if none are found (i.e. the category is not valid).
static void main(java.lang.String[] args)
          Main.
 void setBaseURI(java.lang.String uri)
          Sets the base URI to prepend to any URLs that are generated.
 void setPathInfo(java.lang.String pathInfo)
          Sets the path information to add to any URLs that are generated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

US_ENGLISH_BUNDLE

public static final java.util.ListResourceBundle US_ENGLISH_BUNDLE
Constructor Detail

URLGenerator

public URLGenerator(ServletDescriptor descriptor)
Constructs a URLGenerator using the default English resource bundle. The descriptor is the servlet used to generate the URL. The parameters that are added to this generator must be valid parameters for the given servlet. Also, any parameters that are required by this servlet need to be added.

See Also:
addServletParameter(com.ibm.as400.webaccess.util.ServletParameter), generate()

URLGenerator

public URLGenerator(ServletDescriptor descriptor,
                    java.util.ResourceBundle bundle)
Constructs a URLGenerator using the provided resource bundle. Setting the bundle to null will cause the US English MRI to be used. The descriptor is the servlet used to generate the URL. The parameters that are added to this generator must be valid parameters for the given servlet. Also, any parameters that are required by this servlet need to be added.

See Also:
addServletParameter(com.ibm.as400.webaccess.util.ServletParameter), generate()
Method Detail

main

public static void main(java.lang.String[] args)
Main.


addServletParameter

public void addServletParameter(ServletParameter parm)
                         throws URLParseException
Adds a parameter with a default value for the servlet that is having its URL generated. If the specified parameter does not have a default value but has a specific list of valid values, an exception is thrown. Otherwise, the parameter is added with a value of "".

URLParseException
See Also:
addServletParameter(ServletParameter,Object), generate()

addServletParameter

public void addServletParameter(ServletParameter parm,
                                ServletParameterValue value)
                         throws URLParseException
Adds a parameter and its value for the servlet that is having its URL generated. If the value is not one of the valid values for the parameter, an exception is thrown.

URLParseException
See Also:
generate()

addServletParameter

public void addServletParameter(ServletParameter parm,
                                java.lang.Object value)
                         throws URLParseException
Adds a parameter and its value for the servlet that is having its URL generated.

URLParseException
See Also:
generate()

generate

public java.lang.String generate()
                          throws URLParseException
Generates the URL string given the current servlet descriptor, path info, and parameters. An exception is thrown if any of the servlet's required parameters are missing or if any parameters were added that do not belong to the specified servlet.

URLParseException

getBundle

public java.util.ResourceBundle getBundle()
Returns the resource bundle in use by this generator.


getDescriptor

public static ServletDescriptor[] getDescriptor(java.lang.String uri)
Returns a descriptor for the given servlet URI, or null if no match was found. Typically this will only return an array of size 1, but in some cases there can be multiple ServletDescriptors registered for the same servlet URI.


getDescriptors

public static ServletDescriptor[] getDescriptors()
Returns an array of all known servlet descriptors. The order in which they are returned is not defined.


getDescriptors

public static ServletDescriptor[] getDescriptors(int category)
Returns an array of descriptors for the given servlet category, or an empty array if none are found (i.e. the category is not valid).


setBaseURI

public void setBaseURI(java.lang.String uri)
Sets the base URI to prepend to any URLs that are generated. Setting it to null will cause no base URI to be generated.

See Also:
generate()

setPathInfo

public void setPathInfo(java.lang.String pathInfo)
Sets the path information to add to any URLs that are generated. Setting it to null will cause no path info to be generated.

See Also:
generate()