sidekick.ecmascript.parser
Class Util

java.lang.Object
  extended by sidekick.ecmascript.parser.Util

public class Util
extends java.lang.Object

Collection of useful static utility methods.

Since:
JDK 1.4

Constructor Summary
Util()
           
 
Method Summary
static java.lang.String commonPathPrefix(java.lang.String path1, java.lang.String path2)
          Finds the common path prefix of two specified paths.
static java.lang.String commonPrefix(java.lang.String str1, java.lang.String str2)
          Finds the common prefix of two specified strings.
static void copyFile(java.lang.String srcFilename, java.lang.String dstFilename)
          Does a fast file copy from specified source to specified destination.
static boolean endsWith(java.lang.String aString, java.lang.String aSuffix)
          Tests if specified string ends with the specified suffix.
static java.lang.String escape2Html(java.lang.String plainString)
          Escapes a plain text string for html.
static java.lang.String getDateStamp()
          Creates a string representing a date stamp of the current system date and system time.
static boolean hasWildcards(java.lang.String filename)
          Returns true if the specified filename has wildcard characters in it, i.e.
static boolean isJavaIdentifier(java.lang.String candidate)
          Returns true if specified string is a valid identifier for java or javascript.
static boolean isLikelyIdentifier(java.lang.String candidate)
          Returns true if specified string is a mixed case string with case mixing happening in the middle of the string (starting with uppercase char and continuing with all lowercase chars does count).
static boolean isValidCompositeReference(java.lang.String candidate)
          Returns true if specified string is a valid composite reference where each part is a valid identifier for java or javascript.
static boolean isWhitespace(java.lang.String candidate)
          Returns true if specified string is whitespace
static java.lang.String millisToNice(long millis)
          Converts milliseconds to some more human readable representation.
static java.nio.CharBuffer readBytes(java.io.InputStream inputStream, java.nio.charset.CharsetDecoder decoder)
          Reads an input stream completely into memory and returns a CharBuffer instance with the contents.
static java.lang.String replaceSeparatedString(java.lang.String s, java.lang.String sub, java.lang.String with)
          Replaces occurences of substring sub with string with in specified string but only if substring is delimited by non-alphanumeric characters.
static java.lang.String replaceString(java.lang.String s, java.lang.String sub, java.lang.String with)
          Replaces occurences of substring sub with string with in specified string.
static java.io.File resolveWebURL(java.lang.String urlPath, java.lang.String webroot, java.util.Map webmaps)
          Resolves the specified url path to a file on the local file system.
static java.lang.String[] tokenizeCommaSepString(java.lang.String aString)
          Creates an array of strings from a string of comma-separated string tokens.
static java.lang.String wildCard2Pattern(java.lang.String wildcard)
          Transforms a user wildcard into a java.util.regex.Pattern pattern string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

millisToNice

public static final java.lang.String millisToNice(long millis)
Converts milliseconds to some more human readable representation.

Parameters:
millis - An amount of elapsed milliseconds
Returns:
A human readable time string

tokenizeCommaSepString

public static final java.lang.String[] tokenizeCommaSepString(java.lang.String aString)
Creates an array of strings from a string of comma-separated string tokens.

Parameters:
aString - string containing tokens separated by ","
Returns:
array containing string tokens, can be null if string empty

commonPrefix

public static final java.lang.String commonPrefix(java.lang.String str1,
                                                  java.lang.String str2)
Finds the common prefix of two specified strings.

Parameters:
str1 - first string
str2 - second string
Returns:
string which is a common prefix of the two strings, can be empty string, is never null

commonPathPrefix

public static final java.lang.String commonPathPrefix(java.lang.String path1,
                                                      java.lang.String path2)
Finds the common path prefix of two specified paths. Paths have to be canonical

Parameters:
path1 - first path
path2 - second path
Returns:
string which is a non-empty common path prefix of the two paths, or null if they don't have a non-empty common prefix

copyFile

public static final void copyFile(java.lang.String srcFilename,
                                  java.lang.String dstFilename)
                           throws java.io.IOException
Does a fast file copy from specified source to specified destination. Uses nio API introduced in jdk 1.4.

Parameters:
srcFilename - file name of source file
dstFilename - file name of copy
Throws:
java.io.IOException - if an I/O error occurs

getDateStamp

public static final java.lang.String getDateStamp()
Creates a string representing a date stamp of the current system date and system time. Returned string is suitable to be used in a filename.

Returns:
string with date/time stamp

isJavaIdentifier

public static final boolean isJavaIdentifier(java.lang.String candidate)
Returns true if specified string is a valid identifier for java or javascript.

Parameters:
candidate - potential identifier
Returns:
true if it is in fact an identifier

isValidCompositeReference

public static final boolean isValidCompositeReference(java.lang.String candidate)
Returns true if specified string is a valid composite reference where each part is a valid identifier for java or javascript.

Parameters:
candidate - potential identifier
Returns:
true if it is in fact a valid composite reference

isWhitespace

public static final boolean isWhitespace(java.lang.String candidate)
Returns true if specified string is whitespace

Parameters:
candidate - potential whitespace
Returns:
true if it is in fact whitespace

isLikelyIdentifier

public static final boolean isLikelyIdentifier(java.lang.String candidate)
Returns true if specified string is a mixed case string with case mixing happening in the middle of the string (starting with uppercase char and continuing with all lowercase chars does count).

Parameters:
candidate - potential mixed case
Returns:
true if it is in fact mixed case

replaceString

public static java.lang.String replaceString(java.lang.String s,
                                             java.lang.String sub,
                                             java.lang.String with)
Replaces occurences of substring sub with string with in specified string.

Parameters:
s - string for replacement
sub - substring to replace
with - substring to take its place
Returns:
new string with replacements done

replaceSeparatedString

public static java.lang.String replaceSeparatedString(java.lang.String s,
                                                      java.lang.String sub,
                                                      java.lang.String with)
Replaces occurences of substring sub with string with in specified string but only if substring is delimited by non-alphanumeric characters.

Parameters:
s - string for replacement
sub - substring to replace
with - substring to take its place
Returns:
new string with replacements done

endsWith

public static boolean endsWith(java.lang.String aString,
                               java.lang.String aSuffix)
Tests if specified string ends with the specified suffix.

Parameters:
aString - string to test
aSuffix - suffix.
Returns:
true if the ends in suffix

hasWildcards

public static boolean hasWildcards(java.lang.String filename)
Returns true if the specified filename has wildcard characters in it, i.e. the name contains either "*" or "?" characters.

Parameters:
filename - filename
Returns:
true if has wildcard characters

wildCard2Pattern

public static java.lang.String wildCard2Pattern(java.lang.String wildcard)
Transforms a user wildcard into a java.util.regex.Pattern pattern string.

Parameters:
wildcard - wildcard string
Returns:
pattern string

resolveWebURL

public static java.io.File resolveWebURL(java.lang.String urlPath,
                                         java.lang.String webroot,
                                         java.util.Map webmaps)
Resolves the specified url path to a file on the local file system. Uses the specified web root and web map aliases to complete the resolution.

Parameters:
urlPath - a url path
webroot - directory path on local file system of the web root
webmaps - web map aliases
Returns:
a local File instance

readBytes

public static java.nio.CharBuffer readBytes(java.io.InputStream inputStream,
                                            java.nio.charset.CharsetDecoder decoder)
                                     throws java.io.IOException
Reads an input stream completely into memory and returns a CharBuffer instance with the contents.

Parameters:
inputStream - an input stream
decoder - charset decoder
Returns:
CharBuffer instance with the contents
Throws:
java.io.IOException - if reading from inputStream throws IOException

escape2Html

public static java.lang.String escape2Html(java.lang.String plainString)
Escapes a plain text string for html. Doesn't look into those funny characters like euro symbol, copyright symbol etc.

Parameters:
plainString - plain text string
Returns:
html-escaped string