org.jscience.ml.cml.util
Class CMLUtils

java.lang.Object
  extended by org.jscience.ml.cml.util.CMLUtils

public class CMLUtils
extends java.lang.Object

A number of miscellaneous tools. Originally devised for jumbo.sgml, now rewritten for jumbo.xml. Use these at your peril - some will be phased out


Field Summary
static java.lang.String AMP
          Description of the Field
static java.lang.String APOS
          Description of the Field
static java.lang.String ATSIGN
          Description of the Field
static java.lang.String BACKSLASH
          Description of the Field
static int BR_LOOKAHEAD
          lookahead for bufferedReader
static java.lang.String CARET
          Description of the Field
static int CASE
          case sensitivity flags - used throughout jumbo.xml
static java.lang.String COLON
          Description of the Field
static java.lang.String COMMA
          Description of the Field
static java.lang.String DOLLAR
          Description of the Field
static java.lang.String DOS
          Description of the Field
static java.lang.String EQUALS
          Description of the Field
static java.lang.String FORMAT_ASCII
          Description of the Field
static java.lang.String FORMAT_DOS
          Description of the Field
static java.lang.String FORMAT_EQUALS
          Description of the Field
static java.lang.String FORMFEED
          Description of the Field
static java.lang.String HASH
          Description of the Field
static int IGNORECASE
          Description of the Field
static java.lang.String LANGLE
          Description of the Field
static java.lang.String LBRAK
          Description of the Field
static java.lang.String LCURLY
          Description of the Field
static java.lang.String LSQUARE
          Description of the Field
static java.lang.String MINUS
          Description of the Field
static java.lang.String NEWLINE
          Description of the Field
static java.lang.String NONWHITEPUNC
          Description of the Field
static java.lang.String PERCENT
          Description of the Field
static java.lang.String PERIOD
          Description of the Field
static java.lang.String PIPE
          Description of the Field
static java.lang.String PLUS
          Description of the Field
static java.lang.String POUND
          Description of the Field
static java.lang.String PUNC
          Description of the Field
static java.lang.String QUERY
          Description of the Field
static java.lang.String QUOT
          Description of the Field
static java.lang.String RANGLE
          Description of the Field
static java.lang.String RBRAK
          Description of the Field
static java.lang.String RCURLY
          Description of the Field
static java.lang.String RETURN
          Description of the Field
static java.lang.String[] ROMAN_NUMERALS
          a list of the first few Roman numerals (for example for chapters)
static java.lang.String RSQUARE
          Description of the Field
static java.lang.String SEMICOLON
          Description of the Field
static java.lang.String SHRIEK
          Description of the Field
static java.lang.String SLASH
          Description of the Field
static java.lang.String SPACE
          Description of the Field
static java.lang.String STAR
          Description of the Field
static java.lang.String TAB
          Description of the Field
static java.lang.String TILDE
          Description of the Field
static java.lang.String UNDER
          Description of the Field
static int UNKNOWN
          general code for unset or unknown variables
static java.lang.String WHITESPACE
          Description of the Field
static java.lang.String X_COMMENTC
          Description of the Field
static java.lang.String X_COMMENTO
          Description of the Field
static java.lang.String X_DOCTYPEE
          Description of the Field
static java.lang.String X_DOCTYPEO
          Description of the Field
static java.lang.String X_ELEMDEFC
          Description of the Field
static java.lang.String X_ELEMDEFO
          Description of the Field
static java.lang.String X_EMPTAGC
          Description of the Field
static java.lang.String X_EMPTAGO
          Description of the Field
static java.lang.String X_ENTDEFC
          Description of the Field
static java.lang.String X_ENTDEFO
          Description of the Field
static java.lang.String X_ETAGC
          Description of the Field
static java.lang.String X_ETAGO
          Description of the Field
static java.lang.String X_GENENTC
          Description of the Field
static java.lang.String X_GENENTO
          Description of the Field
static java.lang.String X_PARAMENTC
          Description of the Field
static java.lang.String X_PARAMENTDEFC
          Description of the Field
static java.lang.String X_PARAMENTDEFO
          Description of the Field
static java.lang.String X_PARAMENTO
          Description of the Field
static java.lang.String X_STAGC
          Description of the Field
static java.lang.String X_STAGO
          Description of the Field
static java.lang.String X_STARTDEF
          Description of the Field
 
Constructor Summary
CMLUtils()
           
 
Method Summary
static void addEnumerationToVector(java.util.Vector v, java.util.Enumeration e)
          add the elements of an Enumeration to a Vector.
 java.lang.String addToClasspath(java.lang.String extraPath)
          adds to the classpath and resets the system property
static void addToSystemProperties(java.lang.String urlString)
          load a file/url into the system properties,
static java.util.Vector alternativeStringTokenizer(java.lang.String s, char delim)
          tokenize the string including adjacent delimiters (for example "foo$$bar$", "$" would contain the tokens "foo", "", "bar" and "")
static java.util.Hashtable and(java.util.Hashtable h1, java.util.Hashtable h2)
          create Hashtable with elements common to h1 and h2.
static java.util.Vector and(java.util.Vector v1, java.util.Vector v2)
          create Vector with elements common to v1 and v2.
static java.util.Hashtable andTables(java.util.Hashtable a, java.util.Hashtable b)
          AND 2 Hashtables - inefficient except for small tables.
static java.util.Vector andVectors(java.util.Vector a, java.util.Vector b)
          finds elements common to 2 vectors.
static void bug(java.lang.Exception e)
          Description of the Method
static void bug(java.lang.String s)
          record that we have hit a program bug!!!
static java.lang.String capitalise(java.lang.String s)
          capitalise a String (whatever the starting case)
static java.util.Vector convertFormat(java.util.Vector vector, java.lang.String format)
          converts character format within a Vector of Strings.
static void copyFile(java.io.File inFile, java.io.File outFile)
          copy one file to another (I suspect there is a better way
static double cos(java.lang.String fString)
          Description of the Method
static java.lang.String createCommaSeparatedStrings(java.util.Vector v)
          Description of the Method
static java.io.File createNewFile(java.lang.String fileName)
          create new file, including making directory if required This seems to be a mess - f.createNewFile() doesn't seem to work A directory should have a trailing file.separator
static boolean deleteFile(java.io.File file, boolean deleteDirectory)
          delete a file If directory==true then file will be recursively deleted
static java.lang.String deQuote(java.lang.String s)
          remove balanced quotes from ends of (trimmed) string, else no action
static java.lang.String dump(java.net.URL url)
          reads a stream from url and outputs it as integer values of the characters and as strings.
static boolean equals(java.lang.Object obj1, java.lang.Object obj2)
          compares two objects using equals() allows for null objects.
static boolean equals(java.lang.String string1, java.lang.String string2, int sensitivity)
          convenience function for comparing strings using CMLUtils.CASE/IGNORECASE
static void error(java.lang.String s)
          Error message - nothing fancy at present.
static java.lang.String escape(java.lang.String s)
          default escape characters in an XML string (' -> ' , etc); also escape non-XML characters (for example eacute => é)
static java.lang.String escape(java.lang.String s, char[] escapes, java.lang.String[] escape1)
          escape characters in an XML string; also escape non-XML characters (for example eacute => é).
static void flush(java.lang.String s)
          output String and flush()
static void freeMemory(long mem)
          runs the garbage collector if memory drops below mem.
static java.util.Vector getCommaSeparatedStrings(java.lang.String s)
          parse comma-separated Strings Note fields can be "" (as in ,,,) and fields can be quoted "...".
static java.io.FileOutputStream getFileOutputStream(java.lang.String fileName)
          get an OutputStream from a file or URL.
static int getIntegerFromRoman(java.lang.String roman)
          translate Roman Numerals up to 50 Some normalisation is performed Failure returns -1
static int getIntFromHex(java.lang.String hex)
          Translates a Hex number to its int equivalent.
static java.lang.Object getNewInstance(java.lang.String className)
          gets a new instance of a class from a hashtable because normal methods are very slow
static java.lang.String getPWDName()
          get current directory
static java.util.Vector getRepeatedValues(java.util.Vector v)
          returns a vector of all repeated values in v.
static java.lang.String getSuffix(java.lang.String filename)
          gets suffix from filename
static int indexOf(java.lang.String string, java.lang.String[] strings, int caseSensitivity)
          get the index of a String in an array
static int indexOfBalancedBracket(char lbrack, java.lang.String s)
          return index of balanced bracket -1 for none.
static java.util.Hashtable invert(java.util.Hashtable table)
          invert a Hashtable by interchanging keys and values.
static boolean isAllowedFormat(java.lang.String format)
          Gets the allowedFormat attribute of the CMLUtils class
static boolean isRegisteredApplet(java.applet.Applet applet)
          retrive that an object is an applet rather than an application must have been registered above
static boolean isRightMouseClick(java.awt.event.MouseEvent event)
          a crude way of identifying a right mouse click (because I left the Java book behind)
static java.lang.String leftTrim(java.lang.String s)
          remove leading blanks
static double log(java.lang.String fString)
          Description of the Method
static void main(java.lang.String[] args)
          Description of the Method
static java.lang.String makeAbsoluteURL(java.applet.Applet applet, java.lang.String url)
          If a URL is relative, make it absolute against either the current directory (application) or codebase (applet)
static java.lang.String makeAbsoluteURL(java.lang.String url)
          If a URL is relative, make it absolute against the current directory.
static java.lang.String makeDirectory(java.lang.String urlString)
          truncate filename suffix to make a directory name (without file.separator)
static void message(java.lang.String s)
          message - nothing fancy at present
static java.lang.String normaliseWhitespace(java.lang.String s)
          normalise whitespace in a String (all whitespace is transformed to single spaces and the string is NOT trimmed
static java.util.Hashtable not(java.util.Hashtable h1, java.util.Hashtable h2)
          create Hashtable with elements in to h1 but not h2.
static java.util.Vector not(java.util.Vector v1, java.util.Vector v2)
          create Vector with elements in v1 but not v2.
static java.util.Hashtable or(java.util.Hashtable h1, java.util.Hashtable h2)
          create Hashtable with elements in to h1 but not h2.
static java.util.Vector or(java.util.Vector v1, java.util.Vector v2)
          create Vector with elements in v1 but not v2.
static java.util.Hashtable orTables(java.util.Hashtable a, java.util.Hashtable b)
          OR 2 Hashtables - inefficient except for small tables.
static java.lang.String outputFloat(int nPlaces, int nDec, double value)
          format for example f8.3 this is a mess; if cannot fit, then either right-truncates or when that doesn't work, returns ****
static java.lang.String outputInteger(int nPlaces, int value)
          this is a mess
static java.lang.String outputNumber(int nPlaces, int nDec, double c)
          as above, but trims trailing zeros
static java.util.Vector parseWhitespaceQuotedFields(java.lang.String s)
          parse whitespace-separated tokens interspersed with quoted strings, for example
this is "a quoted string" and 'another token' as well
parses to:
this/is/a quoted string/and/another token/as well
static void printChar()
          Description of the Method
static java.lang.String quoteConcatenate(java.lang.String[] s)
          concatenate strings into quote-separated string
static byte[] readByteArray(java.io.DataInputStream d)
          reads a byte array from DataInputStream, *including* line feeds
static byte[] readByteArray(java.lang.String filename)
          reads a byte array from file, *including* line feeds
static void readZip(java.lang.String fileName)
          read a Zipfile
static void registerApplet(java.applet.Applet applet)
          record that an object is an applet rather than an application call from applet's init() method
static java.lang.String removeHTML(java.lang.String s)
          remove balanced (well-formed) markup from a string.
static java.lang.String rightTrim(java.lang.String s)
          remove trailing blanks
static void setSystemProperty(java.lang.String property, java.lang.String value)
          add a property to the System ones Don't know if this is a good idea...
static double sin(java.lang.String fString)
          Description of the Method
static int skipWhite(java.io.BufferedReader bReader)
          skip white lines and end with first non-white line Leaves bReader ready to read first non-white line
static void sort(java.lang.Object[] objs)
          sort an object array - very inefficient
static void sortVector(java.util.Vector v)
          sort a Vector - VERY crude and inefficient
static java.lang.String spaces(int nspace)
          make a String of a given number of spaces
static java.lang.String[] split(java.lang.String s)
          splits a whitespace-separated set of tokens into a String[]
static java.lang.String stripISOControls(java.lang.String s)
          remove all control (non-printing) characters
static byte[] stripNewlines(byte[] b)
          strip linefeeds from a byte array
static java.lang.String substituteDOSbyAscii(java.lang.String s)
          substitute certain DOS-compatible diacriticals by the Unicode value.
static java.lang.String substituteEquals(java.lang.String s)
          substitute hex representation of character, for example =2E by char(46).
static java.lang.String substituteString(java.lang.String s, java.lang.String oldSubstring, java.lang.String newSubstring, int count)
          make substitutions in a string.
static java.lang.String substituteStrings(java.lang.String s, java.lang.String[] oldSubstrings, java.lang.String[] newSubstrings)
          make substitutions in a string.
static java.lang.String substring(java.lang.String string, java.lang.String startPos, java.lang.String lenString)
          supports XSL substring
static java.lang.String toCamelCase(java.lang.String s)
          Description of the Method
static java.lang.String truncate(java.lang.String s, int maxlength)
          return the first n characters of a string and add ellipses if truncated
static void warning(java.lang.String s)
          Warning message - nothing fancy at present
static java.util.Hashtable xorTables(java.util.Hashtable a, java.util.Hashtable b)
          XOR 2 Hashtables inefficient except for small tables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_ASCII

public static final java.lang.String FORMAT_ASCII
Description of the Field

See Also:
Constant Field Values

FORMAT_DOS

public static final java.lang.String FORMAT_DOS
Description of the Field

See Also:
Constant Field Values

FORMAT_EQUALS

public static final java.lang.String FORMAT_EQUALS
Description of the Field

See Also:
Constant Field Values

SPACE

public static final java.lang.String SPACE
Description of the Field

See Also:
Constant Field Values

TAB

public static final java.lang.String TAB
Description of the Field

See Also:
Constant Field Values

RETURN

public static final java.lang.String RETURN
Description of the Field

See Also:
Constant Field Values

NEWLINE

public static final java.lang.String NEWLINE
Description of the Field

See Also:
Constant Field Values

FORMFEED

public static final java.lang.String FORMFEED
Description of the Field

See Also:
Constant Field Values

WHITESPACE

public static final java.lang.String WHITESPACE
Description of the Field

See Also:
Constant Field Values

LBRAK

public static final java.lang.String LBRAK
Description of the Field

See Also:
Constant Field Values

RBRAK

public static final java.lang.String RBRAK
Description of the Field

See Also:
Constant Field Values

SHRIEK

public static final java.lang.String SHRIEK
Description of the Field

See Also:
Constant Field Values

QUOT

public static final java.lang.String QUOT
Description of the Field

See Also:
Constant Field Values

POUND

public static final java.lang.String POUND
Description of the Field

See Also:
Constant Field Values

DOLLAR

public static final java.lang.String DOLLAR
Description of the Field

See Also:
Constant Field Values

PERCENT

public static final java.lang.String PERCENT
Description of the Field

See Also:
Constant Field Values

CARET

public static final java.lang.String CARET
Description of the Field

See Also:
Constant Field Values

AMP

public static final java.lang.String AMP
Description of the Field

See Also:
Constant Field Values

STAR

public static final java.lang.String STAR
Description of the Field

See Also:
Constant Field Values

UNDER

public static final java.lang.String UNDER
Description of the Field

See Also:
Constant Field Values

MINUS

public static final java.lang.String MINUS
Description of the Field

See Also:
Constant Field Values

PLUS

public static final java.lang.String PLUS
Description of the Field

See Also:
Constant Field Values

EQUALS

public static final java.lang.String EQUALS
Description of the Field

See Also:
Constant Field Values

LCURLY

public static final java.lang.String LCURLY
Description of the Field

See Also:
Constant Field Values

RCURLY

public static final java.lang.String RCURLY
Description of the Field

See Also:
Constant Field Values

LSQUARE

public static final java.lang.String LSQUARE
Description of the Field

See Also:
Constant Field Values

RSQUARE

public static final java.lang.String RSQUARE
Description of the Field

See Also:
Constant Field Values

TILDE

public static final java.lang.String TILDE
Description of the Field

See Also:
Constant Field Values

HASH

public static final java.lang.String HASH
Description of the Field

See Also:
Constant Field Values

COLON

public static final java.lang.String COLON
Description of the Field

See Also:
Constant Field Values

SEMICOLON

public static final java.lang.String SEMICOLON
Description of the Field

See Also:
Constant Field Values

ATSIGN

public static final java.lang.String ATSIGN
Description of the Field

See Also:
Constant Field Values

APOS

public static final java.lang.String APOS
Description of the Field

See Also:
Constant Field Values

COMMA

public static final java.lang.String COMMA
Description of the Field

See Also:
Constant Field Values

PERIOD

public static final java.lang.String PERIOD
Description of the Field

See Also:
Constant Field Values

SLASH

public static final java.lang.String SLASH
Description of the Field

See Also:
Constant Field Values

QUERY

public static final java.lang.String QUERY
Description of the Field

See Also:
Constant Field Values

LANGLE

public static final java.lang.String LANGLE
Description of the Field

See Also:
Constant Field Values

RANGLE

public static final java.lang.String RANGLE
Description of the Field

See Also:
Constant Field Values

PIPE

public static final java.lang.String PIPE
Description of the Field

See Also:
Constant Field Values

BACKSLASH

public static final java.lang.String BACKSLASH
Description of the Field

See Also:
Constant Field Values

NONWHITEPUNC

public static final java.lang.String NONWHITEPUNC
Description of the Field

See Also:
Constant Field Values

PUNC

public static final java.lang.String PUNC
Description of the Field

See Also:
Constant Field Values

X_STAGO

public static final java.lang.String X_STAGO
Description of the Field

See Also:
Constant Field Values

X_STAGC

public static final java.lang.String X_STAGC
Description of the Field

See Also:
Constant Field Values

X_ETAGO

public static final java.lang.String X_ETAGO
Description of the Field

See Also:
Constant Field Values

X_ETAGC

public static final java.lang.String X_ETAGC
Description of the Field

See Also:
Constant Field Values

X_EMPTAGO

public static final java.lang.String X_EMPTAGO
Description of the Field

See Also:
Constant Field Values

X_EMPTAGC

public static final java.lang.String X_EMPTAGC
Description of the Field

See Also:
Constant Field Values

X_STARTDEF

public static final java.lang.String X_STARTDEF
Description of the Field

See Also:
Constant Field Values

X_COMMENTO

public static final java.lang.String X_COMMENTO
Description of the Field

See Also:
Constant Field Values

X_COMMENTC

public static final java.lang.String X_COMMENTC
Description of the Field

See Also:
Constant Field Values

X_ENTDEFO

public static final java.lang.String X_ENTDEFO
Description of the Field

See Also:
Constant Field Values

X_ENTDEFC

public static final java.lang.String X_ENTDEFC
Description of the Field

See Also:
Constant Field Values

X_PARAMENTDEFO

public static final java.lang.String X_PARAMENTDEFO
Description of the Field

See Also:
Constant Field Values

X_PARAMENTDEFC

public static final java.lang.String X_PARAMENTDEFC
Description of the Field

See Also:
Constant Field Values

X_ELEMDEFO

public static final java.lang.String X_ELEMDEFO
Description of the Field

See Also:
Constant Field Values

X_ELEMDEFC

public static final java.lang.String X_ELEMDEFC
Description of the Field

See Also:
Constant Field Values

X_PARAMENTO

public static final java.lang.String X_PARAMENTO
Description of the Field

See Also:
Constant Field Values

X_PARAMENTC

public static final java.lang.String X_PARAMENTC
Description of the Field

See Also:
Constant Field Values

X_GENENTO

public static final java.lang.String X_GENENTO
Description of the Field

See Also:
Constant Field Values

X_GENENTC

public static final java.lang.String X_GENENTC
Description of the Field

See Also:
Constant Field Values

X_DOCTYPEO

public static final java.lang.String X_DOCTYPEO
Description of the Field

See Also:
Constant Field Values

X_DOCTYPEE

public static final java.lang.String X_DOCTYPEE
Description of the Field

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
general code for unset or unknown variables

See Also:
Constant Field Values

CASE

public static final int CASE
case sensitivity flags - used throughout jumbo.xml

See Also:
Constant Field Values

IGNORECASE

public static final int IGNORECASE
Description of the Field

See Also:
Constant Field Values

BR_LOOKAHEAD

public static final int BR_LOOKAHEAD
lookahead for bufferedReader

See Also:
Constant Field Values

ROMAN_NUMERALS

public static java.lang.String[] ROMAN_NUMERALS
a list of the first few Roman numerals (for example for chapters)


DOS

public static final java.lang.String DOS
Description of the Field

See Also:
Constant Field Values
Constructor Detail

CMLUtils

public CMLUtils()
Method Detail

deleteFile

public static boolean deleteFile(java.io.File file,
                                 boolean deleteDirectory)
delete a file If directory==true then file will be recursively deleted

Parameters:
file - Description of the Parameter
deleteDirectory - Description of the Parameter
Returns:
Description of the Return Value

copyFile

public static void copyFile(java.io.File inFile,
                            java.io.File outFile)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
copy one file to another (I suspect there is a better way

Parameters:
inFile - Description of the Parameter
outFile - Description of the Parameter
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

dump

public static java.lang.String dump(java.net.URL url)
                             throws java.lang.Exception
reads a stream from url and outputs it as integer values of the characters and as strings. Emulates UNIX od().

Parameters:
url - Description of the Parameter
Returns:
String tabular version of input (in 10-column chunks)
Throws:
java.lang.Exception - Description of the Exception

flush

public static void flush(java.lang.String s)
output String and flush()

Parameters:
s - Description of the Parameter

spaces

public static java.lang.String spaces(int nspace)
make a String of a given number of spaces

Parameters:
nspace - Description of the Parameter
Returns:
Description of the Return Value

getSuffix

public static java.lang.String getSuffix(java.lang.String filename)
gets suffix from filename

Parameters:
filename - Description of the Parameter
Returns:
The suffix value

skipWhite

public static int skipWhite(java.io.BufferedReader bReader)
                     throws java.lang.Exception
skip white lines and end with first non-white line Leaves bReader ready to read first non-white line

Parameters:
bReader - Description of the Parameter
Returns:
int number of lines skipped
Throws:
java.lang.Exception - Description of the Exception

truncate

public static java.lang.String truncate(java.lang.String s,
                                        int maxlength)
return the first n characters of a string and add ellipses if truncated

Parameters:
s - Description of the Parameter
maxlength - Description of the Parameter
Returns:
String the (possibly) truncated string

getIntegerFromRoman

public static int getIntegerFromRoman(java.lang.String roman)
translate Roman Numerals up to 50 Some normalisation is performed Failure returns -1

Parameters:
roman - Description of the Parameter
Returns:
The integerFromRoman value

setSystemProperty

public static void setSystemProperty(java.lang.String property,
                                     java.lang.String value)
add a property to the System ones Don't know if this is a good idea...

Parameters:
property - The new systemProperty value
value - The new systemProperty value

addToSystemProperties

public static void addToSystemProperties(java.lang.String urlString)
                                  throws java.io.IOException
load a file/url into the system properties,

Parameters:
urlString - The feature to be added to the ToSystemProperties attribute
Throws:
java.io.IOException - Description of the Exception

getNewInstance

public static java.lang.Object getNewInstance(java.lang.String className)
                                       throws java.lang.Exception
gets a new instance of a class from a hashtable because normal methods are very slow

Parameters:
className - Description of the Parameter
Returns:
The newInstance value
Throws:
java.lang.Exception - Description of the Exception

deQuote

public static java.lang.String deQuote(java.lang.String s)
remove balanced quotes from ends of (trimmed) string, else no action

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

rightTrim

public static java.lang.String rightTrim(java.lang.String s)
remove trailing blanks

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

leftTrim

public static java.lang.String leftTrim(java.lang.String s)
remove leading blanks

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

indexOfBalancedBracket

public static int indexOfBalancedBracket(char lbrack,
                                         java.lang.String s)
return index of balanced bracket -1 for none. String MUST start with '('

Parameters:
lbrack - Description of the Parameter
s - Description of the Parameter
Returns:
Description of the Return Value

getCommaSeparatedStrings

public static java.util.Vector getCommaSeparatedStrings(java.lang.String s)
                                                 throws java.lang.Exception
parse comma-separated Strings Note fields can be "" (as in ,,,) and fields can be quoted "...". If so, embedded quotes are represented as "", for example A," this is a ""B"" character",C. An unbalanced quote returns a mess

Parameters:
s - Description of the Parameter
Returns:
Vector the vector of Strings - any error returns null
Throws:
java.lang.Exception - Description of the Exception

createCommaSeparatedStrings

public static java.lang.String createCommaSeparatedStrings(java.util.Vector v)
                                                    throws java.lang.Exception
Description of the Method

Parameters:
v - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.lang.Exception - Description of the Exception

alternativeStringTokenizer

public static java.util.Vector alternativeStringTokenizer(java.lang.String s,
                                                          char delim)
tokenize the string including adjacent delimiters (for example "foo$$bar$", "$" would contain the tokens "foo", "", "bar" and "")

Parameters:
s - Description of the Parameter
delim - Description of the Parameter
Returns:
Description of the Return Value

parseWhitespaceQuotedFields

public static java.util.Vector parseWhitespaceQuotedFields(java.lang.String s)
parse whitespace-separated tokens interspersed with quoted strings, for example
this is "a quoted string" and 'another token' as well
parses to:
this/is/a quoted string/and/another token/as well

Parameters:
s - Description of the Parameter
Returns:
Vector of strings (size = 0 if s is whitespace);

quoteConcatenate

public static java.lang.String quoteConcatenate(java.lang.String[] s)
concatenate strings into quote-separated string

Parameters:
s - Description of the Parameter
Returns:
String concatenated string

split

public static java.lang.String[] split(java.lang.String s)
splits a whitespace-separated set of tokens into a String[]

Parameters:
s - Description of the Parameter
Returns:
String[] result of splitting (null if s==null)

indexOf

public static int indexOf(java.lang.String string,
                          java.lang.String[] strings,
                          int caseSensitivity)
get the index of a String in an array

Parameters:
string - Description of the Parameter
strings - Description of the Parameter
caseSensitivity - Description of the Parameter
Returns:
index of string else -1 if not found

equals

public static boolean equals(java.lang.String string1,
                             java.lang.String string2,
                             int sensitivity)
convenience function for comparing strings using CMLUtils.CASE/IGNORECASE

Parameters:
string1 - Description of the Parameter
string2 - Description of the Parameter
sensitivity - Description of the Parameter
Returns:
boolean true if IGNORECASE ans string1.equalsIgnoreCase(string2) or string1.equals(string2)

removeHTML

public static java.lang.String removeHTML(java.lang.String s)
remove balanced (well-formed) markup from a string. Crude (that is not fully XML-compliant);
Example: "This is <A HREF="foo">bar</A> and </BR> a break" goes to "This is bar and a break"

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

warning

public static void warning(java.lang.String s)
Warning message - nothing fancy at present

Parameters:
s - Description of the Parameter

message

public static void message(java.lang.String s)
message - nothing fancy at present

Parameters:
s - Description of the Parameter

error

public static void error(java.lang.String s)
Error message - nothing fancy at present. Display in Text frame

Parameters:
s - Description of the Parameter

bug

public static void bug(java.lang.String s)
record that we have hit a program bug!!!

Parameters:
s - Description of the Parameter

bug

public static void bug(java.lang.Exception e)
Description of the Method

Parameters:
e - Description of the Parameter

createNewFile

public static java.io.File createNewFile(java.lang.String fileName)
                                  throws java.io.IOException
create new file, including making directory if required This seems to be a mess - f.createNewFile() doesn't seem to work A directory should have a trailing file.separator

Parameters:
fileName - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

getPWDName

public static java.lang.String getPWDName()
get current directory

Returns:
The pWDName value

substituteString

public static java.lang.String substituteString(java.lang.String s,
                                                java.lang.String oldSubstring,
                                                java.lang.String newSubstring,
                                                int count)
make substitutions in a string. If oldSubtrings = "A" and newSubstrings = "aa" then count occurrences of "A" in s are replaced with "aa", etc. "AAA" count=2 would be replaced by "aaaaA"

Parameters:
s - Description of the Parameter
oldSubstring - Description of the Parameter
newSubstring - Description of the Parameter
count - Description of the Parameter
Returns:
Description of the Return Value

substituteStrings

public static java.lang.String substituteStrings(java.lang.String s,
                                                 java.lang.String[] oldSubstrings,
                                                 java.lang.String[] newSubstrings)
make substitutions in a string. If oldSubtrings = {"A", "BB", "C"} and newSubstrings = {"aa", "b", "zz"} then every occurrence of "A" in s is replaced with "aa", etc. "BBB" would be replaced by "bB"

Parameters:
s - Description of the Parameter
oldSubstrings - Description of the Parameter
newSubstrings - Description of the Parameter
Returns:
Description of the Return Value

substituteDOSbyAscii

public static java.lang.String substituteDOSbyAscii(java.lang.String s)
substitute certain DOS-compatible diacriticals by the Unicode value. Not guaranteed to be correct. Example 130 is e-acute (==

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

substituteEquals

public static java.lang.String substituteEquals(java.lang.String s)
substitute hex representation of character, for example =2E by char(46). If line ends with =, ignore that character.

Parameters:
s - Description of the Parameter
Returns:
String result

isAllowedFormat

public static boolean isAllowedFormat(java.lang.String format)
Gets the allowedFormat attribute of the CMLUtils class

Parameters:
format - Description of the Parameter
Returns:
The allowedFormat value

convertFormat

public static java.util.Vector convertFormat(java.util.Vector vector,
                                             java.lang.String format)
converts character format within a Vector of Strings. Some formats such as '=' escaping may require lines to be joined. Original Vector is unaltered.

Parameters:
vector - Description of the Parameter
format - Description of the Parameter
Returns:
Description of the Return Value

capitalise

public static java.lang.String capitalise(java.lang.String s)
capitalise a String (whatever the starting case)

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

toCamelCase

public static java.lang.String toCamelCase(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

escape

public static java.lang.String escape(java.lang.String s,
                                      char[] escapes,
                                      java.lang.String[] escape1)
escape characters in an XML string; also escape non-XML characters (for example eacute => é). If escapes==null only escape non-XML

Parameters:
s - Description of the Parameter
escapes - Description of the Parameter
escape1 - Description of the Parameter
Returns:
Description of the Return Value

escape

public static java.lang.String escape(java.lang.String s)
default escape characters in an XML string (' -> ' , etc); also escape non-XML characters (for example eacute => é)

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

equals

public static boolean equals(java.lang.Object obj1,
                             java.lang.Object obj2)
compares two objects using equals() allows for null objects. if either object is null returns false

Parameters:
obj1 - Description of the Parameter
obj2 - Description of the Parameter
Returns:
Description of the Return Value

freeMemory

public static void freeMemory(long mem)
runs the garbage collector if memory drops below mem. (I use a value of 300000 - your mileage may vary). Potentially used in loops for processing input and creation of objects

Parameters:
mem - Description of the Parameter

addToClasspath

public java.lang.String addToClasspath(java.lang.String extraPath)
adds to the classpath and resets the system property

Parameters:
extraPath - The feature to be added to the ToClasspath attribute
Returns:
String the new classpath

getIntFromHex

public static int getIntFromHex(java.lang.String hex)
Translates a Hex number to its int equivalent. Thus "FE" translates to 254. Horrid, but I couldn't find if Java reads hex. All results are >= 0. Errors return -1

Parameters:
hex - Description of the Parameter
Returns:
The intFromHex value

readByteArray

public static byte[] readByteArray(java.lang.String filename)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException
reads a byte array from file, *including* line feeds

Parameters:
filename - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

readByteArray

public static byte[] readByteArray(java.io.DataInputStream d)
                            throws java.io.IOException
reads a byte array from DataInputStream, *including* line feeds

Parameters:
d - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

stripISOControls

public static java.lang.String stripISOControls(java.lang.String s)
remove all control (non-printing) characters

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

normaliseWhitespace

public static java.lang.String normaliseWhitespace(java.lang.String s)
normalise whitespace in a String (all whitespace is transformed to single spaces and the string is NOT trimmed

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

stripNewlines

public static byte[] stripNewlines(byte[] b)
strip linefeeds from a byte array

Parameters:
b - Description of the Parameter
Returns:
Description of the Return Value

isRightMouseClick

public static boolean isRightMouseClick(java.awt.event.MouseEvent event)
a crude way of identifying a right mouse click (because I left the Java book behind)

Parameters:
event - Description of the Parameter
Returns:
The rightMouseClick value

registerApplet

public static void registerApplet(java.applet.Applet applet)
record that an object is an applet rather than an application call from applet's init() method

Parameters:
applet - Description of the Parameter

isRegisteredApplet

public static boolean isRegisteredApplet(java.applet.Applet applet)
retrive that an object is an applet rather than an application must have been registered above

Parameters:
applet - Description of the Parameter
Returns:
The registeredApplet value

makeDirectory

public static java.lang.String makeDirectory(java.lang.String urlString)
truncate filename suffix to make a directory name (without file.separator)

Parameters:
urlString - Description of the Parameter
Returns:
Description of the Return Value

makeAbsoluteURL

public static java.lang.String makeAbsoluteURL(java.lang.String url)
                                        throws java.net.MalformedURLException
If a URL is relative, make it absolute against the current directory. If url already has a protocol, return unchanged

Parameters:
url - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.net.MalformedURLException - Description of the Exception

makeAbsoluteURL

public static java.lang.String makeAbsoluteURL(java.applet.Applet applet,
                                               java.lang.String url)
                                        throws java.net.MalformedURLException
If a URL is relative, make it absolute against either the current directory (application) or codebase (applet)

Parameters:
applet - Description of the Parameter
url - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.net.MalformedURLException - Description of the Exception

getFileOutputStream

public static java.io.FileOutputStream getFileOutputStream(java.lang.String fileName)
                                                    throws java.io.FileNotFoundException
get an OutputStream from a file or URL. Required (I think) because strings of the sort "file:/C:\foo\bat.txt" crash FileOutputStream, so this strips off the file:/ stuff for Windows-like stuff

Parameters:
fileName - Description of the Parameter
Returns:
FileOutputStream a new (opened) FileOutputStream
Throws:
java.io.FileNotFoundException - Description of the Exception

readZip

public static void readZip(java.lang.String fileName)
                    throws java.io.IOException
read a Zipfile

Parameters:
fileName - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

outputInteger

public static java.lang.String outputInteger(int nPlaces,
                                             int value)
                                      throws java.lang.IllegalArgumentException
this is a mess

Parameters:
nPlaces - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.lang.IllegalArgumentException - Description of the Exception

outputFloat

public static java.lang.String outputFloat(int nPlaces,
                                           int nDec,
                                           double value)
                                    throws java.lang.IllegalArgumentException
format for example f8.3 this is a mess; if cannot fit, then either right-truncates or when that doesn't work, returns ****

Parameters:
nPlaces - Description of the Parameter
nDec - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.lang.IllegalArgumentException - Description of the Exception

outputNumber

public static java.lang.String outputNumber(int nPlaces,
                                            int nDec,
                                            double c)
as above, but trims trailing zeros

Parameters:
nPlaces - Description of the Parameter
nDec - Description of the Parameter
c - Description of the Parameter
Returns:
Description of the Return Value

invert

public static java.util.Hashtable invert(java.util.Hashtable table)
invert a Hashtable by interchanging keys and values. This assumes a 1;1 mapping - if not the result is probably garbage.

Parameters:
table - Description of the Parameter
Returns:
Description of the Return Value

andTables

public static java.util.Hashtable andTables(java.util.Hashtable a,
                                            java.util.Hashtable b)
AND 2 Hashtables - inefficient except for small tables. Finds entries with the same key and value.

Parameters:
a - Description of the Parameter
b - Description of the Parameter
Returns:
Hashtable contains only common entries. null if none

orTables

public static java.util.Hashtable orTables(java.util.Hashtable a,
                                           java.util.Hashtable b)
OR 2 Hashtables - inefficient except for small tables. Merges entries. if entry with the same key and different value is found, take value from first table.

Parameters:
a - Description of the Parameter
b - Description of the Parameter
Returns:
Hashtable contains all entries. null if none

xorTables

public static java.util.Hashtable xorTables(java.util.Hashtable a,
                                            java.util.Hashtable b)
XOR 2 Hashtables inefficient except for small tables. omit

Parameters:
a - Description of the Parameter
b - Description of the Parameter
Returns:
Hashtable contains no common entries.

getRepeatedValues

public static java.util.Vector getRepeatedValues(java.util.Vector v)
returns a vector of all repeated values in v.

Parameters:
v - Description of the Parameter
Returns:
Vector containing duplicate values. If none, returns null

andVectors

public static java.util.Vector andVectors(java.util.Vector a,
                                          java.util.Vector b)
finds elements common to 2 vectors. Very crude (O(n^2));

Parameters:
a - Description of the Parameter
b - Description of the Parameter
Returns:
Description of the Return Value

addEnumerationToVector

public static void addEnumerationToVector(java.util.Vector v,
                                          java.util.Enumeration e)
add the elements of an Enumeration to a Vector.

Parameters:
v - The feature to be added to the EnumerationToVector attribute
e - The feature to be added to the EnumerationToVector attribute

sort

public static void sort(java.lang.Object[] objs)
sort an object array - very inefficient

Parameters:
objs - Description of the Parameter

printChar

public static void printChar()
Description of the Method


sortVector

public static void sortVector(java.util.Vector v)
sort a Vector - VERY crude and inefficient

Parameters:
v - Description of the Parameter

and

public static java.util.Vector and(java.util.Vector v1,
                                   java.util.Vector v2)
create Vector with elements common to v1 and v2. SLOW. Comparison is done with equals()

Parameters:
v1 - Description of the Parameter
v2 - Description of the Parameter
Returns:
Description of the Return Value

not

public static java.util.Vector not(java.util.Vector v1,
                                   java.util.Vector v2)
create Vector with elements in v1 but not v2. SLOW. Comparison is done with equals()

Parameters:
v1 - Description of the Parameter
v2 - Description of the Parameter
Returns:
Description of the Return Value

or

public static java.util.Vector or(java.util.Vector v1,
                                  java.util.Vector v2)
create Vector with elements in v1 but not v2. SLOW. Comparison is done with equals()

Parameters:
v1 - Description of the Parameter
v2 - Description of the Parameter
Returns:
Description of the Return Value

and

public static java.util.Hashtable and(java.util.Hashtable h1,
                                      java.util.Hashtable h2)
create Hashtable with elements common to h1 and h2. The keys are taken from h1. SLOW. Comparison is done with equals()

Parameters:
h1 - Description of the Parameter
h2 - Description of the Parameter
Returns:
Description of the Return Value

not

public static java.util.Hashtable not(java.util.Hashtable h1,
                                      java.util.Hashtable h2)
create Hashtable with elements in to h1 but not h2. The keys are taken from h1 SLOW. Comparison is done with equals()

Parameters:
h1 - Description of the Parameter
h2 - Description of the Parameter
Returns:
Description of the Return Value

or

public static java.util.Hashtable or(java.util.Hashtable h1,
                                     java.util.Hashtable h2)
create Hashtable with elements in to h1 but not h2. The keys are taken from h1 SLOW. Comparison is done with equals()

Parameters:
h1 - Description of the Parameter
h2 - Description of the Parameter
Returns:
Description of the Return Value

sin

public static double sin(java.lang.String fString)
Description of the Method

Parameters:
fString - Description of the Parameter
Returns:
Description of the Return Value

cos

public static double cos(java.lang.String fString)
Description of the Method

Parameters:
fString - Description of the Parameter
Returns:
Description of the Return Value

log

public static double log(java.lang.String fString)
Description of the Method

Parameters:
fString - Description of the Parameter
Returns:
Description of the Return Value

substring

public static java.lang.String substring(java.lang.String string,
                                         java.lang.String startPos,
                                         java.lang.String lenString)
supports XSL substring

Parameters:
string - Description of the Parameter
startPos - Description of the Parameter
lenString - Description of the Parameter
Returns:
Description of the Return Value

main

public static void main(java.lang.String[] args)
Description of the Method

Parameters:
args - Description of the Parameter