ccs.http
Class HUtil

java.lang.Object
  extended by ccs.http.HUtil

public class HUtil
extends java.lang.Object

Utilities for webapps (HTML as much as HTTP).


Method Summary
static java.lang.String forceGetBrowserCmd()
           
static java.lang.String getBrowserCmd()
           
static void launchURL(java.lang.String url)
          Launch the external browser with the specified URL string.
static java.lang.String multipartName(HeaderedEntity he)
          For a HeaderedEntity that is part of a multipart form, extract the name of the control for which this part contains the value.
static java.lang.String multipartStringValue(HeaderedEntity he, java.lang.String charset)
          For a HeaderedEntity that is part of a multipart form, extract the information which the user placed in the control - the "value" - provided that value is a text string.
static java.util.HashMap parseMultipartForm(java.io.InputStream src, int len, java.lang.String contentTypeRaw, java.lang.String charset)
          Deprecated. All webapps should be using Pasiphae now rather than trying to do this themselves. Pasiphae handles input type=file too, which this doesn't.
static void registerURLHandlerPackage(java.lang.String pkg)
          Utility function to register a URL handler package.
static java.lang.String sanex(java.lang.String src, java.lang.String loseMsg)
          Returns a version of the source string which has been sanitised.
static java.lang.String sanitise(java.lang.String src)
          Returns a trimmed version of the source from which any characters which we have deemed objectionable have been removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseMultipartForm

public static java.util.HashMap parseMultipartForm(java.io.InputStream src,
                                                   int len,
                                                   java.lang.String contentTypeRaw,
                                                   java.lang.String charset)
                                            throws java.io.IOException
Deprecated. All webapps should be using Pasiphae now rather than trying to do this themselves. Pasiphae handles input type=file too, which this doesn't.

Parse the return from an HTML form using the multipart/form-data return type. The return maps input names to returned values (all as Strings).

Parameters:
src - The raw form data which was POSTed to you.
len - The length of the form data in src, if known (otherwise the whole stream is assumed; this can hang under some conditions, persistent connections in paticular).
contentTypeRaw - The complete body of the "Content-Type" header which came as part of the HTTP request.
charset - The charset of the form; unless specified otherwise, this is the charset of the page the form is on. If the decoding fails, the method will try again under ISO-8859-1. This is a workaround for bugs in certain current browsers we have decided to support (notably Opera 5.12). NB. Restrict input names to US-ASCII; internationalised names are not supported (although internationalised content is fine).
Returns:
The name=value map. All values are sanitised and trimmed. Names are raw.
Throws:
java.io.IOException

multipartName

public static java.lang.String multipartName(HeaderedEntity he)
                                      throws java.io.IOException
For a HeaderedEntity that is part of a multipart form, extract the name of the control for which this part contains the value. In most cases, it's easier to use parseMultipartForm, which converts the entire form into an easy-to-use hashmap. The only place you can't do this is where your form contains an input of type file; in this case, you must use rawMultipartSet to obtain the HeaderedEntity list, and then use this to extract the names. For all elements that aren't of type file, you can then use multipartStringValue to obtain the value - this is exactly what parseMultipartForm does. For the ones that are files, use HeaderedEntity.writeContentTo to obtain the file contents. This does not return null - if there is no name, it throws HException.

Parameters:
he - The HeaderedEntity from which to extract the control's name.
Throws:
java.io.IOException

multipartStringValue

public static java.lang.String multipartStringValue(HeaderedEntity he,
                                                    java.lang.String charset)
                                             throws java.io.IOException
For a HeaderedEntity that is part of a multipart form, extract the information which the user placed in the control - the "value" - provided that value is a text string. In most cases, it's easier to use parseMultipartForm, which converts the entire form into an easy-to-use hashmap. The only place you can't do this is where your form contains an input of type file; in this case, you must use rawMultipartSet to obtain the HeaderedEntity list, and then use this to extract the values of all elements that aren't files - this is exactly what parseMultipartForm does. For the ones that are files, use HeaderedEntity.writeContentTo to obtain the file contents.

Parameters:
he - The HeaderedEntity from which to extract the control's value.
charset - The charset of the form; unless specified otherwise, this is the charset of the page the form is on. If the decoding fails, the method will try again under ISO-8859-1. This is a workaround for bugs in certain current browsers we have decided to support (notably Opera 5.12). NB. Restrict input names to US-ASCII; internationalised names are not supported (although internationalised content is fine).
Throws:
java.io.IOException

sanitise

public static java.lang.String sanitise(java.lang.String src)
Returns a trimmed version of the source from which any characters which we have deemed objectionable have been removed. These objectionables are characters which could in theory be used to mount some kind of attack, most probably against a third party reading the attack string rather than against the system which processes and stores it. We also cull out \r chars, so that the stored versions only have \n, consistent with the Java standard. The returned string may be zero-length. If no changes are required, the source string itself is returned.

Parameters:
src - The source string.
Returns:
The sanitised, trimmed version of src.

sanex

public static java.lang.String sanex(java.lang.String src,
                                     java.lang.String loseMsg)
                              throws LoseException
Returns a version of the source string which has been sanitised. If this string is zero-length, throws LoseException with the specified error message.

Throws:
LoseException

registerURLHandlerPackage

public static void registerURLHandlerPackage(java.lang.String pkg)
Utility function to register a URL handler package. Classes in subpackages of this package will be used to handle novel protocols. Two such are the classbase and mux protocols.

Parameters:
pkg - The parent package of your handler.
See Also:
URL.URL(java.lang.String, java.lang.String, int, java.lang.String)

launchURL

public static void launchURL(java.lang.String url)
                      throws java.io.IOException
Launch the external browser with the specified URL string.

Throws:
java.io.IOException

getBrowserCmd

public static java.lang.String getBrowserCmd()
Returns:
The current browser command string, if there is one, else null.

forceGetBrowserCmd

public static java.lang.String forceGetBrowserCmd()
Returns:
The current browser command string, forcibly re-reading it from disk rather than using any cached copy. Most apps should use getBrowserCmd instead; it has better performance.