de.infinityloop.util
Class Utility

java.lang.Object
  extended by de.infinityloop.util.Utility

public class Utility
extends java.lang.Object

Collection of (static) Utility methods.


Constructor Summary
Utility()
           
 
Method Summary
static java.util.Vector arr2Vector(java.lang.Object[] arr)
          Convert an array to a Vector.
static void benchmark(int repetitions)
           
static java.lang.String convertCSS2IdentifierOrString(java.lang.String s)
          Converts the passed CSS string to the internal format: unquote, resolve escapes etc.
static java.util.Stack convertHashMapToStack(java.util.HashMap ht)
          Converts a HashMap to a Stack of Pair's.
static java.util.Stack convertHashtableToStack(java.util.Hashtable ht)
          Converts a Hashtable to a Stack of Pair's.
static java.util.Stack convertHashtableToStackSorted(java.util.Hashtable ht)
          Converts a Hashtable to a Stack of Pair's, with sorted keys in natural order.
static java.lang.String convertLineEndings(java.lang.String s, java.lang.String lineEnding)
          Converts the lines in the passed string into a form using the specified line ending string
static java.util.Hashtable convertStackToHashtable(java.util.Vector v)
          Converts a Vector of Pair()s to a Hashtable.
static java.util.Stack convertTreeMapToStack(java.util.TreeMap ht)
          Converts a TreeMap to a Stack of Pair's.
static int countOccurrences(java.lang.String s, char c)
          Returns the number of occurrences of a specified character in a String.
static int dayDifference(java.util.Calendar one, java.util.Calendar two)
          Calculates the difference in days between the two dates passed in (one - two).
static void debugMessage(java.lang.String msg)
          Issue a debug level message to the current active log.
static void errorMessage(java.lang.String msg)
          Issue a error level message to the current active log.
static int executeCommand(java.util.Vector theCommand, boolean wait, java.lang.StringBuffer stdout, java.lang.StringBuffer stderr)
          executes the passed commandline via Runtime.exec().
static java.lang.String expandString(java.lang.String src, java.util.Hashtable variables)
          Expands a string that might contain variables.
static void fatalMessage(java.lang.String msg)
          Issue a fatal level message to the current active log.
static java.lang.String getCurrentMethodName()
          Return the name of the routine that called getCurrentMethodName
static java.lang.String getJREversionString()
          Returns the JRE version as in the system property.
static java.lang.String getMangledComponent(int n, java.lang.String s)
          Retrieves the n-th component of a mangled string, with n starting at 0.
static java.lang.String getTimerInfoString()
          prints current Timer information
static int hourDifference(java.util.Calendar one, java.util.Calendar two)
          Calculates the difference in days between the two dates passed in (one - two). does not take into account leap years, leap seconds etc.
static java.lang.String indentation(int steps, java.lang.String indentationElement)
          Calculates indentation string based on passed values: (steps * indentatationElement) as String
static void infoMessage(java.lang.String msg)
          Issue a info level message to the current active log.
static boolean isDocFile(DiskFile file)
          determines if the passed file is a DOC file
static boolean isHexCharacter(char c)
          Determines whether the passed character is a hex representation character, i.e. if it is within [0-9A-Fa-f].
static boolean isRTFFile(DiskFile file)
          determines if the passed file is an RTF file
static boolean isWordFile(DiskFile file)
          determines if the passed file is a Word document file, i.e.
static boolean isWordFilePlatform(DiskFile file)
          determines if the passed file is a readable Word document file, i.e.
static int makeDTTMFromRFCDate(java.lang.String s)
          translates an RFC date to DTTM.
static java.lang.String makeRFCDateFromDTTM(int value)
          translates a DTTM bitfield to a RFC date.
static java.lang.String makeRFCDateString(java.util.Calendar cld)
          Makes an RFC-1123 compliant date from a Java Calendar object.
static java.lang.String makeVersionString(int version)
          Tranforms the integer version into a human readable version string.
static java.lang.String makeVersionString(int version, java.lang.String build)
          Tranforms the integer version into a human readable version string, including the build number.
static java.lang.String minimizeWhitespace(java.lang.String src)
          Minimizes whitespace in a string, i.e. condenses all whitespace characters to one single WS character.
static java.lang.String parseCSS2Identifier(java.lang.String src)
          Parses a CSS2 (class-)identifier, resolving all hex escapes it might have.
static java.util.Calendar parseRFCDateString(java.lang.String date)
          Parses an RFC-1123 compliant date string into a Calendar object.
static void resetTimer(java.lang.String key)
          resets the timer with name key
static void resetTimers()
          resets all timing info
static java.lang.String[] resolveArgumentString(java.lang.String params, java.util.Vector charsNeedingQuoting)
          Resolves a (commandline-) String into an array of Strings with the single arguments.
static java.lang.String resolveExpression(java.lang.String expression, java.lang.String srcfile, java.lang.String destDir, java.lang.String imageDir)
          Resolves the passed string, which may contain placeholders, to the final command line.
static java.lang.String resolveNumericalEntities(java.lang.String s)
          Replaces numerical entities in the passed string (&#decdigits;) into a Unicode character.
static java.util.Stack resolveParameters(java.lang.String params)
          Resolves a string into a Stack of Pair()s of parameter-name, parameter-value.
static java.lang.String setMangledComponent(java.lang.String dest, int n, java.lang.String val)
          Sets the nth component in the passed string to the indicated value.
static void startTimer(java.lang.String key)
          start a cumulative timer of key key
static long stopTimer(java.lang.String key)
          stops a cumulative timer of key key and returns the length of the just stopped timing action in milliseconds.
static java.lang.String toHexString(long number, int length, boolean truncate)
          Converts the passed long to a hex string with the specified length, with leading zeros if necessary.
static void warnMessage(java.lang.String msg)
          Issue a warning level message to the current active log.
static void writeTextLinesStringPlatform(java.lang.String s, java.io.Writer w)
          Writes a string containing Java GUI newline characters (\n) to the specified OutputWriter, replacing Java GUI newlines by platform newlines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

convertTreeMapToStack

public static java.util.Stack convertTreeMapToStack(java.util.TreeMap ht)
Converts a TreeMap to a Stack of Pair's.


convertHashtableToStack

public static java.util.Stack convertHashtableToStack(java.util.Hashtable ht)
Converts a Hashtable to a Stack of Pair's.


convertHashMapToStack

public static java.util.Stack convertHashMapToStack(java.util.HashMap ht)
Converts a HashMap to a Stack of Pair's.


convertHashtableToStackSorted

public static java.util.Stack convertHashtableToStackSorted(java.util.Hashtable ht)
Converts a Hashtable to a Stack of Pair's, with sorted keys in natural order.


convertStackToHashtable

public static java.util.Hashtable convertStackToHashtable(java.util.Vector v)
Converts a Vector of Pair()s to a Hashtable.


countOccurrences

public static int countOccurrences(java.lang.String s,
                                   char c)
Returns the number of occurrences of a specified character in a String.


makeRFCDateFromDTTM

public static java.lang.String makeRFCDateFromDTTM(int value)
translates a DTTM bitfield to a RFC date.
 DTTM format:
 wwwyyyyy yyyymmmm dddddhhh hhmmmmmm

 w day of week (0 Sun - 6 Sat)
 y year-1900
 m month (1-12)
 d day of month (1-31)
 h hour 0-23
 m minute 0-59

   0-5  Minute  0-59
   6-10 Hour    0-23
   11-15        Day of month    1-31
   16-19        Month   1-12
   20-28        Year    = Year-1900
   29-31        Day of week     0 (Sun)-6 (Sat)
 


makeDTTMFromRFCDate

public static int makeDTTMFromRFCDate(java.lang.String s)
translates an RFC date to DTTM.
  DTTM format:
  wwwyyyyy yyyymmmm dddddhhh hhmmmmmm
 
  w day of week (0 Sun - 6 Sat)
  y year-1900
  m month (1-12)
  d day of month (1-31)
  h hour 0-23
  m minute 0-59
 
    0-5 Minute  0-59
    6-10        Hour    0-23
    11-15       Day of month    1-31
    16-19       Month   1-12
    20-28       Year    = Year-1900
    29-31       Day of week     0 (Sun)-6 (Sat)
 


convertCSS2IdentifierOrString

public static java.lang.String convertCSS2IdentifierOrString(java.lang.String s)
Converts the passed CSS string to the internal format: unquote, resolve escapes etc.


parseCSS2Identifier

public static java.lang.String parseCSS2Identifier(java.lang.String src)
Parses a CSS2 (class-)identifier, resolving all hex escapes it might have.


isHexCharacter

public static boolean isHexCharacter(char c)
Determines whether the passed character is a hex representation character, i.e. if it is within [0-9A-Fa-f].


dayDifference

public static int dayDifference(java.util.Calendar one,
                                java.util.Calendar two)
Calculates the difference in days between the two dates passed in (one - two). Does not take into account leap years, leap seconds etc.


hourDifference

public static int hourDifference(java.util.Calendar one,
                                 java.util.Calendar two)
Calculates the difference in days between the two dates passed in (one - two). does not take into account leap years, leap seconds etc.


indentation

public static java.lang.String indentation(int steps,
                                           java.lang.String indentationElement)
Calculates indentation string based on passed values: (steps * indentatationElement) as String

Parameters:
steps - number of steps to indent
indentationElement - for each indentation step, this String is written
Returns:
the full indentation string

resolveParameters

public static java.util.Stack resolveParameters(java.lang.String params)
Resolves a string into a Stack of Pair()s of parameter-name, parameter-value. Syntax: [name '=' '"' value '"']? [ '[;,]' name '=' '"' value '"' ]*


resolveArgumentString

public static java.lang.String[] resolveArgumentString(java.lang.String params,
                                                       java.util.Vector charsNeedingQuoting)
Resolves a (commandline-) String into an array of Strings with the single arguments. Use double quotes for arguments containing spaces. Whitespace delimits arguments. Use the backslash character for escaping (i.e. \\ for the backslash and \" for double quotes).


arr2Vector

public static java.util.Vector arr2Vector(java.lang.Object[] arr)
Convert an array to a Vector.

Parameters:
arr - the Object array
Returns:
the Vector

getJREversionString

public static java.lang.String getJREversionString()
Returns the JRE version as in the system property.


makeRFCDateString

public static java.lang.String makeRFCDateString(java.util.Calendar cld)
Makes an RFC-1123 compliant date from a Java Calendar object.

Format: "Wkd, dd Mon yyyy hh:mm:ss GMT"


parseRFCDateString

public static java.util.Calendar parseRFCDateString(java.lang.String date)
Parses an RFC-1123 compliant date string into a Calendar object.

Format: "Wkd, dd Mon yyyy hh:mm:ss GMT"


makeVersionString

public static java.lang.String makeVersionString(int version)
Tranforms the integer version into a human readable version string.


makeVersionString

public static java.lang.String makeVersionString(int version,
                                                 java.lang.String build)
Tranforms the integer version into a human readable version string, including the build number.


writeTextLinesStringPlatform

public static void writeTextLinesStringPlatform(java.lang.String s,
                                                java.io.Writer w)
                                         throws java.io.IOException
Writes a string containing Java GUI newline characters (\n) to the specified OutputWriter, replacing Java GUI newlines by platform newlines.

Throws:
java.io.IOException

minimizeWhitespace

public static java.lang.String minimizeWhitespace(java.lang.String src)
Minimizes whitespace in a string, i.e. condenses all whitespace characters to one single WS character.


resolveNumericalEntities

public static java.lang.String resolveNumericalEntities(java.lang.String s)
                                                 throws java.lang.Exception
Replaces numerical entities in the passed string (&#decdigits;) into a Unicode character.

Throws:
java.lang.Exception

getMangledComponent

public static java.lang.String getMangledComponent(int n,
                                                   java.lang.String s)
Retrieves the n-th component of a mangled string, with n starting at 0. Returns null if that component is not found.


setMangledComponent

public static java.lang.String setMangledComponent(java.lang.String dest,
                                                   int n,
                                                   java.lang.String val)
Sets the nth component in the passed string to the indicated value. It replaces any value the string might have, or fills with empty components to be able to set the n-th component.

Note: n is 0-based.


toHexString

public static java.lang.String toHexString(long number,
                                           int length,
                                           boolean truncate)
Converts the passed long to a hex string with the specified length, with leading zeros if necessary. The value will be truncated if for representing the number, more than length characters are needed and truncate is true. Otherwise, the needed length for representing the number will be used. If length is negative, leading zeros will be suppressed (and a correspondingly shorter string is returned).


getCurrentMethodName

public static java.lang.String getCurrentMethodName()
Return the name of the routine that called getCurrentMethodName


startTimer

public static void startTimer(java.lang.String key)
start a cumulative timer of key key


stopTimer

public static long stopTimer(java.lang.String key)
stops a cumulative timer of key key and returns the length of the just stopped timing action in milliseconds. Returns 0 if that timer was not running.


resetTimers

public static void resetTimers()
resets all timing info


resetTimer

public static void resetTimer(java.lang.String key)
resets the timer with name key


getTimerInfoString

public static java.lang.String getTimerInfoString()
prints current Timer information


isRTFFile

public static boolean isRTFFile(DiskFile file)
determines if the passed file is an RTF file

Parameters:
file - the file to test
Returns:
true if it is an RTF file, false otherwise

isDocFile

public static boolean isDocFile(DiskFile file)
determines if the passed file is a DOC file

Parameters:
file - the file to test
Returns:
true if it is a Word binary (.doc) file, false otherwise

isWordFile

public static boolean isWordFile(DiskFile file)
determines if the passed file is a Word document file, i.e. either a Word binary (.doc) file or an RTF file.

Parameters:
file - the file to test
Returns:
true if it is an RTF file, false otherwise

isWordFilePlatform

public static boolean isWordFilePlatform(DiskFile file)
determines if the passed file is a readable Word document file, i.e. either a Word binary (.doc, on Windows platform only!) file or an RTF file.

Parameters:
file - the file to test
Returns:
true if it is an RTF file, false otherwise

resolveExpression

public static java.lang.String resolveExpression(java.lang.String expression,
                                                 java.lang.String srcfile,
                                                 java.lang.String destDir,
                                                 java.lang.String imageDir)
Resolves the passed string, which may contain placeholders, to the final command line. Supported placeholders:

Parameters:
expression - - the String expression to resolve
srcfile - - the sourcefile of the conversion
destDir - - the destination directory of the current conversion
imageDir -
Returns:
the resolved string or null, if that is not possible

expandString

public static java.lang.String expandString(java.lang.String src,
                                            java.util.Hashtable variables)
Expands a string that might contain variables. Expressions of the form ${name} expand to the contents of an earlier defined variable name, e.g. with the element anywhere in a BCF file. Recursion is not tracked, but recursion depth is limited to a depth of 256 calls, at which an error is issued. When a variable is undefined or possible recursion is detected, an error is written to the log and null returned. The only character needed to be quoted is $, which when used literally must be written as $$

NOTE: We do not track recursion/execute recursion at all: Only one pass is executed currently.

Variables not known are left unexpanded.

Parameters:
src - the source string to expand
variables - a hashtable of variable name/variable value pairs that should get expanded
Returns:
the expansion result as String

executeCommand

public static int executeCommand(java.util.Vector theCommand,
                                 boolean wait,
                                 java.lang.StringBuffer stdout,
                                 java.lang.StringBuffer stderr)
                          throws java.lang.Exception
executes the passed commandline via Runtime.exec(). It optionally waits until the command terminates and in that case returns the result code. Otherwise (not waiting) it always returns 0 (=ok). You can pass in StringBuffer() objects for the process's stdout and stderr stream, which will be filled accordingly. You should set wait to true in this case as otherwise, the method will return immediately and the string buffers will not be filled completely. If you do not want to capture the output, pass null. The output will then be written to the log file.

Throws:
java.lang.Exception

debugMessage

public static void debugMessage(java.lang.String msg)
Issue a debug level message to the current active log.

Parameters:
msg - the message to log
Since:
5.3.3 / 1.6.3

infoMessage

public static void infoMessage(java.lang.String msg)
Issue a info level message to the current active log.

Parameters:
msg - the message to log
Since:
5.3.3 / 1.6.3

errorMessage

public static void errorMessage(java.lang.String msg)
Issue a error level message to the current active log.

Parameters:
msg - the message to log
Since:
5.3.3 / 1.6.3

warnMessage

public static void warnMessage(java.lang.String msg)
Issue a warning level message to the current active log.

Parameters:
msg - the message to log
Since:
5.3.3 / 1.6.3

fatalMessage

public static void fatalMessage(java.lang.String msg)
Issue a fatal level message to the current active log.

Parameters:
msg - the message to log
Since:
5.3.3 / 1.6.3

convertLineEndings

public static java.lang.String convertLineEndings(java.lang.String s,
                                                  java.lang.String lineEnding)
Converts the lines in the passed string into a form using the specified line ending string


benchmark

public static void benchmark(int repetitions)