org.paneris.jal.model
Class HTMLUtil

java.lang.Object
  extended by org.paneris.jal.model.HTMLUtil

public final class HTMLUtil
extends java.lang.Object

Output format (HTML) dependant formatters.

Author:
Paneris, timp@paneris.org

Constructor Summary
HTMLUtil()
           
 
Method Summary
static java.lang.String escape(java.lang.String s, ExtendedHash h)
           
static java.lang.String escapeHTML(java.lang.String htm)
          Do basic escaping of html text
static java.lang.String escapeJavascript(java.lang.String s)
           
static java.lang.String getDropDown(DDField ddf, java.lang.String db, java.lang.String allName)
          Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field.
static java.lang.String getDropDown(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, java.lang.String allValue, java.lang.String allName)
           
static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name)
           
static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique)
           
static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName)
           
static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue)
          Return a drop down list (HTML select tag) where the options are the rows of a ResultSet.
static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue)
           
static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name)
          Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query.
static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique)
           
static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName)
           
static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue)
           
static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String allValue, java.lang.String selectValue)
           
static java.lang.String getHiddenValue(DDField ddf, java.lang.String db, java.text.SimpleDateFormat dateFormatter, java.text.SimpleDateFormat datetimeFormatter, java.lang.String postfix)
          Formats a DDField to be displayed on a html page as a hidden field
static java.lang.String getInputValue(DDField ddf, java.lang.String db, java.text.SimpleDateFormat dateFormatter, java.text.SimpleDateFormat datetimeFormatter, java.lang.String allValue, java.lang.String postfix)
          Formats a DDField to be displayed on a html page as in input box of the correct type
static java.lang.String getJSValidation(DDField ddf, java.lang.String fieldname, java.lang.String displayname, boolean mand)
          Returns a JavaScript tag which will validate the field using JS (remember to include the relevant functions to handle the validation request in your template).
static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String allName)
           
static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, boolean unique, java.lang.String allName)
          Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field.
static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, boolean unique, java.lang.String allValue, java.lang.String allName)
           
static java.lang.String getLinkedSelect(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue)
          Return a drop down list (HTML select tag) where the options are the rows of a ResultSet.
static java.lang.String getLinkedSelect(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue)
           
static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name)
           
static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique)
           
static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName)
          Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query.
static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLUtil

public HTMLUtil()
Method Detail

escapeHTML

public static java.lang.String escapeHTML(java.lang.String htm)
Do basic escaping of html text

Parameters:
htm - a String to escape
Returns:
the escaped string

escapeJavascript

public static java.lang.String escapeJavascript(java.lang.String s)

escape

public static java.lang.String escape(java.lang.String s,
                                      ExtendedHash h)

getLinkedSelect

public static java.lang.String getLinkedSelect(java.sql.ResultSet rs,
                                               java.lang.String name,
                                               boolean unique,
                                               java.lang.String allName,
                                               java.lang.String selectValue)
                                        throws java.lang.Exception
Return a drop down list (HTML select tag) where the options are the rows of a ResultSet. When an option is selected its value is copied into the input box called name.

Each row of the ResultSet should have only one value Each row becomes an HTML option tag

Unique only puts an element into the select box if it's value is not already

Takes a selectvalue so that the correct option can be chosen

You can also add an extra option using allName and allValue

Parameters:
rs - a list of value pairs
name - the name of the input box to copy to
unique - make sure that each entry has a different value
allValue - the value of first option on select
allName - the name of first value on select
selectValue - the entry to be selected by default
Returns:
a HTML select tag
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(java.sql.ResultSet rs,
                                               java.lang.String name,
                                               boolean unique,
                                               java.lang.String allValue,
                                               java.lang.String allName,
                                               java.lang.String selectValue)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(DDField ddf,
                                               java.lang.String db,
                                               java.lang.String fieldname,
                                               boolean mandatory,
                                               boolean unique,
                                               java.lang.String allName)
                                        throws java.lang.Exception
Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field.

You can add another option using allName and allValue so long as mandatory is not set

The current value of the DDField is used to decide which option is selected by default

Parameters:
dd - a DDField which we want to create a select box for This may be a field in a lookup table
db - name of the database to query
fieldname - the name of the field (and the select tag) This may be the name of the field containing the lookup
mandatory - if 'false' then a default extra option ("None") is added, unless allName is set
unique - ensure that each entry has a different value
allValue - the value of first option on select
allName - the name of first value on select
Returns:
a HTML select tag
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(DDField ddf,
                                               java.lang.String db,
                                               java.lang.String allName)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(DDField ddf,
                                               java.lang.String db,
                                               java.lang.String fieldname,
                                               boolean mandatory,
                                               boolean unique,
                                               java.lang.String allValue,
                                               java.lang.String allName)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(java.lang.String db,
                                               java.lang.String sqlString,
                                               java.lang.String name,
                                               boolean unique,
                                               java.lang.String allName)
                                        throws java.lang.Exception
Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query.

Unique only puts an element into the select box if it's value is not already

Parameters:
db - name of the database to query
sqlString - the SQL query to evaluate
name - the name of the select tag
unique - make sure that each entry has a different value
allValue - the value of first option on select
allName - the name of first value on select
selectValue - the value which should be selected
Returns:
a HTML select tag
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(java.lang.String db,
                                               java.lang.String sqlString,
                                               java.lang.String name,
                                               boolean unique)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(java.lang.String db,
                                               java.lang.String sqlString,
                                               java.lang.String name)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getLinkedSelect

public static java.lang.String getLinkedSelect(java.lang.String db,
                                               java.lang.String sqlString,
                                               java.lang.String name,
                                               boolean unique,
                                               java.lang.String allValue,
                                               java.lang.String allName,
                                               java.lang.String selectValue)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.sql.ResultSet rs,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allName,
                                           java.lang.String selectValue)
                                    throws java.lang.Exception
Return a drop down list (HTML select tag) where the options are the rows of a ResultSet.

It is assumed that each row of the ResultSet has at least 2 fields in it - the first is used as the value of the option, the 2nd is the displayed value. Each row becomes a HTML option tag

Unique only puts an element into the select box if it's value is not already

Takes a selectvalue so that the correct option can be chosen

You can also add an extra option using allName and allValue

Parameters:
rs - a list of value/display pairs
name - the name of the select tag
unique - make sure that each entry has a different value
allValue - the value of first option on select
allName - the name of first value on select
selectValue - a String indicating the entry to be selected by default
Returns:
a HTML select tag
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.sql.ResultSet rs,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allName)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.sql.ResultSet rs,
                                           java.lang.String name,
                                           boolean unique)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.sql.ResultSet rs,
                                           java.lang.String name)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.sql.ResultSet rs,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allValue,
                                           java.lang.String allName,
                                           java.lang.String selectValue)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.lang.String db,
                                           java.lang.String sqlString,
                                           java.lang.String name)
                                    throws java.lang.Exception
Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query.

It is assumed that the query returns a ResultSet in which each row has at least 2 fields in it - the first is used as the value of the option, the 2nd is the displayed value. Each row becomes a HTML option tag

Unique only puts an element into the select box if it's value is not already

Parameters:
db - name of the database to query
sqlString - the SQL query to evaluate
name - the name of the select tag
unique - ensure that each entry has a different value
allValue - the value of first option on select
allName - the name of first value on select
selectValue - The String to be selected by default
Returns:
a HTML select tag
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.lang.String db,
                                           java.lang.String sqlString,
                                           java.lang.String name,
                                           boolean unique)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.lang.String db,
                                           java.lang.String sqlString,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allName)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.lang.String db,
                                           java.lang.String sqlString,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allName,
                                           java.lang.String selectValue)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(java.lang.String db,
                                           java.lang.String sqlString,
                                           java.lang.String name,
                                           boolean unique,
                                           java.lang.String allName,
                                           java.lang.String allValue,
                                           java.lang.String selectValue)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(DDField ddf,
                                           java.lang.String db,
                                           java.lang.String allName)
                                    throws java.lang.Exception
Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field.

This field should be a field linked (in the datadictionary) to another table. The contents of (each record of) that table are used to create the select box. Also, the field could be a boolean field.

You can add another option using allName and allValue if mandatory is not set

The current value of the DDField is used to decide which option is selected by default

Parameters:
ddf - a DDField which we want to create a select box for This is a field in a lookup table
db - name of the database to query
fieldname - the name of the field (and the select tag) This is the name of the field containing the lookup
mandatory - if 'false' then a default extra option ("None") is added, unless allName is set
allValue - the value of first option on select
allName - the name of first value on select
Returns:
a HTML select tag
Throws:
java.lang.Exception

getDropDown

public static java.lang.String getDropDown(DDField ddf,
                                           java.lang.String db,
                                           java.lang.String fieldname,
                                           boolean mandatory,
                                           java.lang.String allValue,
                                           java.lang.String allName)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getInputValue

public static java.lang.String getInputValue(DDField ddf,
                                             java.lang.String db,
                                             java.text.SimpleDateFormat dateFormatter,
                                             java.text.SimpleDateFormat datetimeFormatter,
                                             java.lang.String allValue,
                                             java.lang.String postfix)
                                      throws java.lang.Exception
Formats a DDField to be displayed on a html page as in input box of the correct type

Parameters:
ddf - a DDField which we want to create an input box for
db - name of the database to query
dateFormatter - format for dates
dateTimeFormatter - format for date and times
Returns:
a HTML input tag
Throws:
java.lang.Exception

getHiddenValue

public static java.lang.String getHiddenValue(DDField ddf,
                                              java.lang.String db,
                                              java.text.SimpleDateFormat dateFormatter,
                                              java.text.SimpleDateFormat datetimeFormatter,
                                              java.lang.String postfix)
                                       throws java.lang.Exception
Formats a DDField to be displayed on a html page as a hidden field

Parameters:
ddf - The DDField to create an input box for
db - name of the database to query
dateFormatter - format for dates
dateTimeFormatter - format for date and times
Returns:
a HTML input tag
Throws:
java.lang.Exception

getJSValidation

public static java.lang.String getJSValidation(DDField ddf,
                                               java.lang.String fieldname,
                                               java.lang.String displayname,
                                               boolean mand)
Returns a JavaScript tag which will validate the field using JS (remember to include the relevant functions to handle the validation request in your template). This file is also the place to look for the most up-to-date documentation.

Presently the returned String should look like:

 
The first 2 arguments are strings which contain the name of the input field and what to call it. These should be the params fieldname and displayname for this function, but remember to wrap quotes around them!

The third argument should be 0 if mand is false, 1 otherwise (actually, javascript treats anything other than 0, "0", false and the null object as true).

The fourth argument is a regular expression which any value entered into the HTML form must match against for validation to succeed. Note that this needs to have quotes wrapped around it. Since this ends up as a JavaScript string, we also need to escape special characters with '\', including '\' itself (hence the '\\w' in the example above - we want the expression to contain the 2 characters '\w', not CTRL-w. If you put brackets into your expression then JavaScript will allow you to access them through the global (to each window) variable RegExp as RegExp.$1 ... RegExp.$9. You can leave this out if you only want to check if a a mandatory value is set or not.

The fifth argument is the body of JavaScript function. You can use this to perform more general validation tests than just matching a regular expression, or you can leave it out altogether. It has access to one formal paramater, 'value' - the value of the input field being validated. It also has access to global variables such as RegExp.$1. It should return nothing (or an empty string) if validation succeeds, otherwise it should return a string to be shown to the user explaining the problem. Remeber to print double quotes around it.

Because we've got to escape all these quotes and escapes in this function, the strings are a bit messy, especially since there are a few '\n's to improve readability in the HTML source. Be careful.

ALTERNATIVELY, you can use some rules which are predefined in the javascript: add_integer("fieldname_1", "Display Name", 0); add_number("fieldname_1", "Display Name", 0); add_date("fieldname_1", "Display Name", 0); add_datetime("fieldname_1", "Display Name", 0);

Parameters:
ddf - A DDField representing a field in the datadictionary
fieldname - The name of the input tag to be validated
displayname - What to call the input field for the user's benefit
mand - Whether the field is mandatory (cannot be empty)
Returns:
A JavaScript tag which will validate ddf on the client side when the form is submitted.


Copyright © 2000-2008 PanEris. All Rights Reserved.