com.waveset.util
Class Util

java.lang.Object
  extended bycom.waveset.util.Util

public class Util
extends java.lang.Object

A bag of utilities.


Nested Class Summary
static class Util.StringComparator
          Internal class that implenents the Comparator interface for sorting the rows in the table.
static class Util.TimePeriod
          Used to represent a time period, such as number of days, weeks or months, relative to an arbitrary day.
static class Util.TimeUnit
          Used by the TimePeriod class to indicate the unit of the period counter.
 
Field Summary
static java.lang.String code_id
           
static java.lang.String DATE_FORMAT_AM_PM
           
static java.lang.String DATE_FORMAT_CANONICAL
          Deprecated. Will become a private constant since this doesn't handle parsing a general IS0-8601 format. (Only handles our subset). Instead always use the public methods stringToDate and getCanonicalDateString. (At some point we may want to handle parsing a general IS0-8601 format).
static java.lang.String DATE_FORMAT_COMPACT
          Year-month-day with twenty-four-hour time: "yyyyMMdd HH:mm:ss"
static java.lang.String DATE_FORMAT_DEFAULT
           
static java.lang.String DATE_FORMAT_MILLIS
          Timestamp in milliseconds (a stringified Java long value).
static java.lang.String DATE_FORMAT_NO_SPACE
           
static int INTERVAL_UNIT_HOURS
           
static int INTERVAL_UNIT_MILLISECONDS
           
static int INTERVAL_UNIT_MINUTES
           
static int INTERVAL_UNIT_SECONDS
           
static java.util.List stockDateTimePatterns
           
static java.util.TimeZone TIME_ZONE_CANONICAL
           
 
Constructor Summary
Util()
           
 
Method Summary
static void addElement(java.util.ArrayList list, int index, java.lang.Object o)
          Add an element to an array list at the given position, growing the array if necessary to avoid exceptions.
static java.lang.String[] addString(java.lang.String[] list, java.lang.String newString)
          Return a new string array with the string added.
static java.util.List addToken(java.util.List list, java.lang.String token, boolean trim, java.lang.String valWrapper)
           
static long appendFile(java.lang.String name, java.lang.String contents)
          Append to a file.
static long appendFile(java.lang.String name, java.lang.String contents, long maxLength)
          See appendFile, below.
static java.lang.String[] appendString(java.lang.String[] list, java.lang.String newString)
          Similar to addString but just appends the string to end of the list (no sorting, no check for duplicates, no guard against null values).
static boolean arrayEquals(java.lang.Object[] arr1, java.lang.Object[] arr2)
          Tests whether two arrays are equal.
static java.lang.String arrayToString(boolean[] array)
           
static java.lang.String arrayToString(byte[] array)
           
static java.lang.String arrayToString(long[] array)
           
static java.lang.String arrayToString(java.lang.Object[] array)
           
static double atod(java.lang.String a)
          Convert a String value into a primitive double value.
static double atod(java.lang.String a, double def)
          Convert a String value into a primitive double value.
static float atof(java.lang.String a)
          Convert a String value into a primitive float value.
static float atof(java.lang.String a, float def)
          Convert a String value into a primitive float value.
static int atoi(java.lang.String a)
          Convert a String value into a primitive integer value.
static int atoi(java.lang.String a, int def)
          Convert a String value into a primitive integer value.
static long atol(java.lang.String a)
          Convert a String value into a primitive integer value.
static long atol(java.lang.String a, long def)
          Convert a String value into a primitive long value.
static java.lang.Boolean autoBox(boolean b)
           
static java.lang.Integer autoBox(int i)
           
static java.lang.Long autoBox(long l)
           
static java.lang.String btoa(boolean b)
          Convert a primitive boolean value to a string.
static java.net.URL buildFTPURL(java.lang.String host, java.lang.String port, java.lang.String path, java.lang.String user, EncryptedData password, java.lang.String type)
           
static char[] byteToChar(byte[] inbytes)
          Converts a byte array to a char array.
static char[] byteToChar(byte[] inb, java.lang.String enc)
          Converts a byte array to character array.
static byte[] charToByte(char[] inchars)
          Converts a char array to a byte array.
static byte[] charToByte(char[] carray, java.lang.String enc)
          Converts a char array to a byte array.
static java.lang.String checkDirectory(java.io.File dir, boolean createIfMissing)
           
static long checksum(java.io.File file)
           
static long checksum(java.lang.String fileName)
          Calculates the CRC32 checksum of the specified file.
static java.util.List commaDelimitedStringToList(java.lang.String cds)
           
static java.lang.String compressToString(java.io.Serializable obj)
          Serializes obj, compresses it using gzip, and then base64 encodes it so that it can be cleanly stuck in XML.
static void confirmDirectory(java.io.File dir)
          Make sure the directory exists and is writable.
static void confirmDirectory(java.io.File dir, boolean createIfMissing)
          Make sure the directory exists (or can be created) and is writable.
static boolean contains(java.lang.Object[] objs, java.lang.Object obj)
           
static boolean containsAny(java.util.Collection containing, java.util.Collection query)
          Returns true if containing collection contains any of the items in the query collection.
static java.lang.String convertToJSName(java.lang.String in)
           
static java.util.ArrayList convertValuesToStringList(java.lang.Object value)
           
static java.lang.String convertValueToString(java.lang.Object value)
           
static boolean copyFile(java.io.File src, java.io.File dest)
          Copies a file to a destintation.
static int copyFile(java.io.InputStream fis, java.io.OutputStream fos)
          Copies one file to another.
static boolean copyFile(java.io.InputStream fis, java.io.OutputStream fos, int max)
          Copies one file to another up to a specified max.
static int copyFile(java.io.Reader reader, java.io.Writer writer)
          Copies one file to another.
static int copyFile(java.lang.String src, java.lang.String dest)
          Copies one file to another.
static int copyFileByBlockSize(java.io.InputStream fis, java.io.OutputStream fos, int bufferSize)
          Copies one file to another.
static int copyFileByBlockSize(java.io.Reader reader, java.io.Writer writer, int bufferSize)
          Copies one file to another.
static void createJarFile(java.io.File jarFile, java.io.File rootDir, java.util.List files)
          Archive and compress a data file.
static boolean dateAfter(java.util.Date date1, java.util.Date date2)
          Determine if date1 is after date2.
static boolean dateEquals(java.util.Date date1, java.util.Date date2)
          Determine if date1 is the same as date2.
static java.lang.String dateToString()
           
static java.lang.String dateToString(java.util.Date src)
          Format a Date value as a String, using the usual "American" format with the current time zone.
static java.lang.String dateToString(java.util.Date src, java.util.Locale locale)
          Format the given date using the given locale.
static java.lang.String dateToString(java.util.Date date, java.lang.String simpleDateFormatPattern)
           
static java.lang.String dateToString(java.util.Locale locale)
          Format the current date using the given locale.
static java.lang.String dateToString(long timeMillis)
           
static java.lang.String dateToString(long src_millis, java.util.Locale locale)
          Format the given date using the given locale.
static java.lang.String dateToString(long timeMillis, java.lang.String simpleDateFormatPattern)
           
static java.lang.String dateToString(java.lang.String simpleDateFormatPattern)
           
static void debug(java.lang.Object o)
          Deprecated. Use Debug or Trace instead.
static java.util.List decodeCommaString(java.lang.String src)
          Parse a comma delimited string into a List of strings.
static java.util.List decodeCommaString(java.lang.String src, boolean filterEmpty)
           
static java.util.List decodeNewlineString(java.lang.String data, boolean filterEmpty)
          Given a newline deliminted string, break it up into a List of Strings.
static java.lang.String demangle(java.lang.String mangledName)
          Restore special characters in a filename.
static java.lang.String dtoa(double d)
          Convert a primitive double value into a String.
static java.lang.String dumpBytes(byte[] bytes)
          Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left
static java.lang.String dumpBytes(byte[] bytes, int len)
          Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left
static java.lang.String dumpBytes(byte[] bytes, int start, int len)
          Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left
static void dumpProperties()
          Prints the current system properties to the system output device.
static void dumpProperties(java.io.PrintWriter out)
          Prints the current system properties to a writer object.
static java.lang.String encodeCommaString(java.lang.Object list)
          Convert a list of strings into a comma delimited list.
static java.lang.String encodeCommaString(java.lang.Object list, boolean filterEmpty)
           
static java.lang.String encodeCommaString(java.lang.Object o, boolean filterEmpty, boolean trailingSpace)
          Convert a list of strings to a comma delimited list.
static java.lang.String encodeNewlineString(java.util.List values, boolean filterEmpty)
          Given a List of Strings, convert them into a single String with elements seperated by newlines.
static boolean equals(java.lang.Object o1, java.lang.Object o2)
          Compares the 2 objects, handling nulls
static boolean equalStrings(java.lang.String s1, java.lang.String s2)
          Compares the 2 strings, handling nulls
static java.lang.String escape(java.lang.String src, char escapeThis, char prefixWith)
          Process a string to escape any occurrence of the specified character by prefixing it with the specified escape character.
static java.lang.String escapeCommas(java.lang.String src)
          Process a string to escape any comma (,) character.
static java.lang.String escapeForwardSlashes(java.lang.String src)
          Process a string to escape any forward slash (/) character.
static java.lang.String escapeNewlines(java.lang.String src)
          Process a string to escape newline characters.
static java.lang.String escapePoundSigns(java.lang.String src)
          Process a string to escape any hash mark (#) character.
static java.lang.String escapeSingleQuotes(java.lang.String src)
          Process a string to escape any apostrophe characters.
static void escapeString(java.lang.StringBuffer b, java.lang.String s)
          Render a quoted string with the usual escaping.
static java.lang.String exec(java.lang.String command)
          Execute a "shell" command, returning whatever it emitted to stdout as a string.
static void expandJarFile(java.io.File jarFile, java.io.File rootDir)
          Extract and uncompress all data files from an archive.
static void expandJarFile(java.io.File jarFile, java.io.File rootDir, java.util.List entryNames)
          Extract and uncompress specified data files from an archive.
static void filterStringList(java.util.List list, java.lang.String regexp)
          Remove all of the Strings in list that do not match the regular expression.
static int[] findClassName(java.lang.StringBuffer sb)
          Find something tkat looks like a classname (e.g., "com.waveset.Exception:" ).
static java.util.List findDuplicates(java.util.List list)
          return a list of duplicate entries in a list
static java.lang.String findFile(java.lang.String name)
          Attempt to derive the absolute path of a file.
static java.lang.String findFile(java.lang.String property, java.lang.String name)
          Attempt to derive the absolute path of a file.
static java.lang.String findFile(java.lang.String property, java.lang.String name, boolean searchClasspath)
          Attempt to derive the absolute path of a file.
static java.lang.String findIllegals(java.lang.String name, java.lang.String illegals)
           
static java.lang.String findOutputFile(java.lang.String name)
          Build an absolute path name for a file.
static java.lang.String format(double d, int decimalPlaces)
           
static java.lang.String format(java.lang.String s, int decimalPlaces)
           
static java.lang.String formatBytes(long bytes)
           
static java.lang.String formatElapsedTime(long from, long to)
           
static java.lang.String formatMemoryStatistics()
           
static void formatMemoryStatistics(java.lang.StringBuffer sb)
           
static java.lang.String formatTimeInterval(long millis)
           
static java.lang.String formatTimeInterval(long millis, int maxUnit, int granularity)
           
static java.lang.String ftoa(float f)
          Convert an primitive float value into a String.
static java.lang.String generateGUID()
           
static java.io.File getApplicationDataDirectory()
          Returns an os-specific application data directory for Identity Manager.
static java.lang.String getApplicationHome()
          Returns the value of the WSHOME environment variable.
static java.util.HashMap getAttributeMap(java.lang.String attrString)
          This routine will take a string of comma delimeted name value pairs and place them in a hashmap.
static java.lang.String getBaseName(java.lang.Class c)
           
static java.lang.String getBaseName(java.lang.String className)
           
static boolean getBoolean(java.lang.Object value)
          Coerce an Object to a boolean value.
static boolean getBoolean(java.lang.Object value, boolean dflt)
          Coerce an Object to a boolean value.
static java.text.DateFormat getCanonicalDateFormat()
          Deprecated. Will become a private method since this doesn't handle parsing a general IS0-8601 format. (Only handles our subset). Instead always use the public methods stringToDate and getCanonicalDateString. (At some point we may want to handle parsing a general IS0-8601 format).
static java.lang.String getCanonicalDateString(java.util.Date date)
           
static java.lang.String getCanonicalDateString(java.util.Date date, java.util.TimeZone timeZone)
           
static java.lang.String getCanonicalDateString(long timestamp)
           
static java.lang.String getCanonicalDateStringOnly(java.util.Date date)
           
static java.lang.String getCanonicalTimeStringOnly(java.util.Date date)
           
static java.lang.Class getClass(boolean b)
           
static java.lang.Class getClass(int i)
           
static java.lang.Class getClass(long l)
           
static java.lang.Class getClass(java.lang.Object o)
           
static java.lang.String getClassNameFromFilePath(java.lang.String path)
          Take a path name of a file and return the corresponding class name (e.g.
protected static java.lang.String getClassNameFromPath(java.lang.String path, java.lang.String separator)
          Take a path name of a file that uses the specified separator and return the corresponding class name (e.g.
static java.lang.String getClassNameFromZipPath(java.lang.String path)
          Take a path name of a file from a zip (jar) file and return the corresponding class name (e.g.
static java.lang.String getClasspathDirectory(int idx)
          Return the nth item on the CLASSPATH.
static java.util.List getClasspathList()
          Return a list of the items that are in the classpath.
static java.util.Date getDecrementedDate(java.lang.String numLogin)
           
static java.lang.String getDefaultEncoding()
           
static java.lang.String getenv(java.lang.String name)
          Return the value of an environment variable.
static java.lang.String getFileName(java.lang.String filePath)
           
static java.io.File getFontsDir()
          Returns the path to the WEB-INF/fonts directory.
static java.io.InputStream getInputStreamFromJar(java.lang.String jarfilename, java.lang.String entryName)
          Return an input stream for an entry in a jar file.
static int getInt(java.lang.Object v)
          Coerce an Object into an int primitive.
static java.util.jar.JarFile getLighthouseJar()
          Searches the classpath for idm.jar.
static java.lang.String getLocalHostName()
          Return the local host name.
static java.lang.String getLocalizedString(java.util.Locale locale, java.lang.Object value)
           
static long getLong(java.lang.Object v)
          Coerce an Object value into a long primitive.
static java.lang.String getMachineUser()
          Get the name of the user that is logged in to the host machine.
static long getMaxMemory()
           
static long getMaxMemory(boolean force)
           
static java.lang.String getOldCanonicalDateString(java.util.Date date, boolean absoluteTimezone)
          Deprecated. Use getCanonicalDateString
static java.util.Date getRelativeDate(int field, int amount)
          Generates a data string expressed as a number of units from now such as "5 minutes from now"
static java.util.Date getRelativeDate(int ord, int day, int mo)
          Generates a date string expressed in a future time such as "the second Monday in October".
static java.util.Date getRelativeDate(Util.TimePeriod period)
          Calculates a Date representing the current time plus the the amount of time represented by the TimePeriod.
static java.net.URL getResource(java.lang.String name)
           
static java.io.File getResourceFile(java.net.URL resoUrl)
           
static java.io.File getResourceFile(java.net.URL resoUrl, boolean mustExist)
           
static java.io.File getResourceFileIfFile(java.net.URL resoUrl)
           
static java.lang.String getResourcePath(java.lang.String name)
          Attempts to determine the absolute pathname of a resource file.
static java.lang.String getResourcePath(java.net.URL res)
           
static java.io.File getSavedObjectsDir()
          Returns the path to the savedObjects directory.
static java.lang.String getServerId()
          Return the "server id".
static java.lang.String getStringFromJar(java.lang.String jarfilename, java.lang.String entryName)
          Return the contents of an entry in a jar file as a string.
static java.lang.String getUniqueId()
          Generate a globally unique identifier.
static long getUsedMemory()
           
static long getUsedMemory(boolean force)
           
static java.net.URL getWavesetConfigURL()
          Get a URL that points to our config directory, should be a file URL that points to lighthouse/config.
static java.lang.String getWavesetHome()
           
static java.lang.String getWavesetHomePathIfFile()
          Convenience method.
static java.net.URL getWavesetHomeURL()
           
static java.net.URL getWavesetHomeURL(boolean ignoreAnyCached)
           
static java.net.URL getWavesetResource(java.lang.String name)
           
static java.io.File getWavesetResourceFile(java.lang.String name)
          Convenience method: equivalent to calling getWavesetResource(); and getResourceFile();.
static java.lang.String getWavesetResourcePath(java.lang.String name)
          Convenience method: equivalent to calling getWavesetResource(); and getResourcePath();.
static byte[] gzipCompress(byte[] inbytes)
           
static byte[] gzipDecompress(byte[] inBytes)
          Decompress an array of bytes, if possible.
static byte[] gzipDecompress(byte[] inbytes, int size)
           
static java.lang.Integer hashCode(java.lang.Object o)
           
static java.util.HashMap hashtableToMap(java.util.Hashtable hash)
          Convert a Hashtable into a HashMap.
static java.lang.String ignoreCase(java.lang.String s)
           
static int indexOf(java.lang.Object[] objs, java.lang.Object obj)
           
static boolean isASCIILetter(char in)
          Walk the string, converting any non-alpha or numeric char to an underscore.
static boolean isASCIILetterOrDigit(char in)
           
static boolean isNumeric(java.lang.String s)
           
static boolean isWindows()
          Are we running in windows?
static java.lang.String itoa(int i)
          Convert an primitive integer value into a String.
static java.lang.String legalizeResourceName(java.lang.String resoName)
           
static int length(byte[] array)
           
static int length(char[] array)
           
static int length(int[] array)
           
static int length(long[] array)
           
static int length(java.lang.Object[] array)
           
static int length(java.lang.String psz)
           
static int length(java.lang.StringBuffer sb)
           
static int lengthInUTF8(java.lang.String psz)
           
static java.util.List listAllFilenames(java.io.File dir, boolean relativeNames)
          List all of the filenames (not including directory names) in the specified directory and its subdirectories.
protected static java.util.List listAllFilenames(java.io.File dir, boolean relativeNames, java.lang.String basepath)
           
static java.util.List listClasses()
          List all of the classes in the classpath.
static java.util.List listClassesInDirectory(java.io.File dir)
          List all of the classes found in the specified directory or its subdirectories.
static java.util.List listClassesInZipFile(java.io.File file)
          List all of the classes in the specified zip (jar) file.
static java.util.List listClassNamesMatching(java.lang.String baseName)
           
static java.lang.String listToCommaDelimitedString(java.util.List list)
           
static java.lang.String listToString(java.util.List list, java.lang.String delim)
           
static java.lang.String listToString(java.util.List list, java.lang.String delim, int maxLen)
           
static java.lang.String listToString(java.util.List list, java.lang.String delim, int maxLen, java.lang.String valWrapper)
           
static java.lang.String lpad(java.lang.String str, int length)
          Left-pad a string to the specified length.
static java.lang.String lpad(java.lang.String str, int length, char padChar)
          Left-pad a string to the specified length with the specified character.
static java.lang.String ltoa(long l)
          Convert a primitive long value into a String.
static void main(java.lang.String[] args)
           
static java.util.List makeList(java.lang.Object[] array)
          Make a List out of an array.
static java.lang.String mangle(java.lang.String name)
          Replace special characters in a name or id so that it will be a valid filename.
static java.lang.String mapName(java.util.Locale locale, java.lang.String prefix, java.lang.String name)
          Given a name, try to map it using the catalog.
static java.lang.String mapToString(java.util.Map map)
           
static java.lang.String mapToString(java.util.Map map, java.lang.String separator)
           
static boolean matchSimpleWildcard(java.lang.String in, java.lang.String matchString)
          Very simple string matching, allows matchString to end in a * and match another string com.waveset.* matches com.waveset.util.Util.matchSimpleWildcard
static java.lang.String midString(java.lang.StringBuffer in, char delim, int start, int count)
          Given a string like aaa,bbb,ccc,ddd and a delim of ",", return a string containing the items between start and (start + count).
static java.lang.String normalizeString(java.lang.String str)
          Normalization of the string will be done using an implementation of RFC2253 which specifies the standard for the string representation of distinguished names handling issue such as capitalization, component ordering, special characters, internationalized characters, trimming leading and trailing spaces, etc.
static java.lang.String pad(java.lang.String s, int len, char pad, boolean leftPad)
           
static boolean pathIsAbsolute(java.lang.String path)
           
static boolean pathIsRelative(java.lang.String path)
           
static void print(java.lang.Object o)
           
static void println()
          Ubiquitous macro
static void println(java.lang.Object o)
           
static void printStackTrace()
          Debugging aid that dumps the current stack trace to the console.
static void putJarEntries(java.lang.String jarFileName, java.util.List entryNames, boolean jarMustExist, boolean overwriteEntry, boolean updateExistingJar)
          Archive and compress a data file.
static void putJarEntry(java.lang.String jarFileName, java.lang.String jarEntryName, boolean jarMustExist, boolean overwriteEntry)
          Archive and compress a data file.
static java.lang.String readFile(java.io.File file)
          Read the contents of a file and return it as a String.
static java.lang.String readFile(java.lang.String name)
          Read the contents of a file and return it as a String.
static byte[] readFileBytes(java.io.File file)
          Read the contents of a file and return it as a String.
static byte[] readFileBytes(java.lang.String name)
          Read the content of a file and return it as a String.
static java.lang.String readFileUtf8(java.io.File filename)
           
static java.lang.String readFileUtf8(java.io.InputStream in)
           
static java.lang.String readFileUtf8(java.lang.String filename)
           
static java.lang.String readInputStream(java.io.InputStream in)
          Read the contents of an input stream and return it as a String.
static byte[] readInputStreamBytes(java.io.InputStream is, boolean close)
           
static java.lang.String readResource(java.net.URL resoUrl)
           
static byte[] readURLBytes(java.net.URL url)
          Read the content of a URL.
static byte[] readURLBytesIfExists(java.net.URL url)
          Read the contents of a URL if there is something there.
static java.lang.String readWavesetResource(java.lang.String name)
          Convenience method: equivalent to calling getWavesetResource(); and readResource();.
static void removeDuplicates(java.util.List list)
          Remove the duplicates from a list, returning the duplicate-free list.
static void removeNulls(java.util.List list)
          Remove null elements from a list.
static boolean renameFileForBackup(java.io.File file)
          Renames the file using the following format: .backup.yyyyMMdd_HHmmss.
static boolean renameFileForBackup(java.lang.String path)
          Renames the file using the following format: .backup.yyyyMMdd_HHmmss.
static java.lang.String replaceChar(java.lang.String s, java.lang.String replaceMe, java.lang.String replaceWith)
          Replace all occurances of replaceMe with replaceWith
static java.lang.String replaceString(java.lang.String in, java.lang.String fromString, java.lang.String toString)
           
static boolean resourceExists(java.net.URL resoUrl)
           
static java.lang.String rfc2396URLPieceEncode(java.lang.String s)
          Deprecated. Use RFC2396URLPieceEncode class.
static java.lang.String rfc2396URLPieceEncode(java.lang.String s, java.lang.String dontEncode)
          Deprecated. Use RFC2396URLPieceEncode class.
static double roundTo(double d, int decimalPlaces)
           
static int roundToInt(double d)
           
static java.lang.String rpad(java.lang.String str, int length)
          Right-pad a string buffer to the specified length.
static java.lang.String rpad(java.lang.String str, int length, char padChar)
          Right-pad a string buffer to the specified length with the specified character.
static java.lang.String setWavesetHome(java.lang.String newValue)
          Set the application docroot.
static int size(java.util.Collection collection)
           
static int size(java.util.Map map)
           
static java.util.List sortList(java.util.List list)
          Sort a list
static java.lang.StringBuffer sprintf(java.lang.String format, java.lang.String[] args)
          A marginally functional attempt to provide "sprintf" in Java.
static java.lang.String stackToHtml(java.lang.Throwable th)
          Converts the stack trace of an exception to an HTML string
static java.lang.String stackToHtmlComment(java.lang.Throwable th)
          Converts the stack trace of an exception to an HTML string Bug #10499 If 'ui.web.disableStackTraceComments' property in waveset.properties is 'true' this returns an empty string.
static java.lang.String stackToString(java.lang.Throwable th)
          Converts the stack trace of an exception to a String
static java.lang.String[] stringToArray(java.lang.String s)
          Inverse of arrayToString (except that we cannot convert back to Object).
static java.util.Date stringToDate(java.lang.String src)
          Convert the string representation for a date into a Date object.
static java.util.Date stringToDate(java.lang.String src, java.lang.String format)
           
static java.util.Date stringToDate(java.lang.String src, java.lang.String format, java.lang.String timeZone)
           
static java.lang.String stringToHtmlComment(java.lang.String s)
          Converts the stack trace of an exception to an HTML string
static java.util.List stringToList(java.lang.String s, java.lang.String delim)
           
static java.util.List stringToList(java.lang.String s, java.lang.String delim, boolean trim)
           
static java.util.List stringToList(java.lang.String s, java.lang.String delim, boolean trim, java.lang.String valWrapper)
           
static java.lang.String strip(java.lang.Throwable th)
           
static java.lang.String stripClassName(java.lang.String in)
          Strip the classname off of the front of an error if it really looks like a classpath - and it looks like there is a real error out there.
static int strlen(java.lang.String inString)
          Returns the length of the specified string.
static java.lang.String strstr(java.lang.String inString, java.lang.String delimiter)
          Returns the last token in a string of tokens separated by the specified delimiter.
static java.lang.String timestampConvert(java.lang.String dText, java.lang.String tText, java.util.List formats, java.lang.String iTimezone, java.lang.String oMask, java.lang.String oTimezone)
           
static java.lang.String timestampConvert(java.lang.String dText, java.lang.String tText, java.lang.String iTimezone, java.lang.String oMask, java.lang.String oTimezone)
           
static java.lang.String topStackFrames(int num)
           
static java.lang.String toString(boolean b)
           
static java.lang.String toString(char c)
           
static java.lang.String toString(int i)
           
static java.lang.String toString(long l)
           
static java.lang.String toString(java.lang.Object o)
           
static byte[] toUpperByteArray(byte[] barray)
          Coverts all bytes to upper case.
static byte[] toUpperByteArray(byte[] barray, java.lang.String enc)
          Coverts all bytes to upper case.
static char[] toUpperCharArray(char[] carray)
          Converts all lower case characters to upper case.
static java.lang.String trimWhitespace(java.lang.String src)
          Trims trailing whitespace from a string.
static java.lang.String truncateAt(java.lang.String in, java.lang.String delim, int count)
          Given a string like aaa,bbb,ccc,ddd and a delim of ",", return a string containing the first count items.
static java.lang.String truncateEncodedString(java.lang.String psz, java.lang.String encoding, int maxbytes)
          Truncate string in encoding space, returning longest string that will fit in a byte buffer of the given size after it has been encoded.
static java.io.Serializable uncompressFromString(java.lang.String str)
          Called to retrieve the object passed into compressToString
static java.lang.String URLDecode(java.lang.String s)
          Process a string to decode all characters using the com.waveset.util.URLUTF8Decoder.decode method
static java.lang.String URLEncode(java.lang.String s)
          Process a string to encode all characters using the com.waveset.util.URLUTF8Encoder.encode method
static boolean wavesetResourceExists(java.lang.String name)
          Convenience method: equivalent to calling getWavesetResource(); and resourceExists();.
static void writeFile(java.io.File file, java.lang.String contents)
          Store the contents of a String in a file.
static void writeFile(java.lang.String name, byte[] contents)
          Store the contents of a String in a file.
static void writeFile(java.lang.String name, java.lang.String contents)
          Store the contents of a String in a file.
static void writeFileUtf8(java.lang.String name, java.lang.String contents)
           
static void writeResource(java.net.URL resoUrl, java.lang.String content)
          Replace the content of the specified URL with a String if that URL is a file.
static void writeWavesetResource(java.lang.String name, java.lang.String content)
          Convenience method: equivalent to calling getWavesetResource(); and writeResource();.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

DATE_FORMAT_COMPACT

public static final java.lang.String DATE_FORMAT_COMPACT
Year-month-day with twenty-four-hour time: "yyyyMMdd HH:mm:ss"

See Also:
Constant Field Values

DATE_FORMAT_DEFAULT

public static final java.lang.String DATE_FORMAT_DEFAULT
See Also:
Constant Field Values

DATE_FORMAT_AM_PM

public static final java.lang.String DATE_FORMAT_AM_PM
See Also:
Constant Field Values

DATE_FORMAT_NO_SPACE

public static final java.lang.String DATE_FORMAT_NO_SPACE
See Also:
Constant Field Values

DATE_FORMAT_CANONICAL

public static final java.lang.String DATE_FORMAT_CANONICAL
Deprecated. Will become a private constant since this doesn't handle parsing a general IS0-8601 format. (Only handles our subset). Instead always use the public methods stringToDate and getCanonicalDateString. (At some point we may want to handle parsing a general IS0-8601 format).

IS0-8601 date format.

See Also:
Constant Field Values

TIME_ZONE_CANONICAL

public static java.util.TimeZone TIME_ZONE_CANONICAL

DATE_FORMAT_MILLIS

public static final java.lang.String DATE_FORMAT_MILLIS
Timestamp in milliseconds (a stringified Java long value).

See Also:
Constant Field Values

INTERVAL_UNIT_HOURS

public static final int INTERVAL_UNIT_HOURS
See Also:
Constant Field Values

INTERVAL_UNIT_MINUTES

public static final int INTERVAL_UNIT_MINUTES
See Also:
Constant Field Values

INTERVAL_UNIT_SECONDS

public static final int INTERVAL_UNIT_SECONDS
See Also:
Constant Field Values

INTERVAL_UNIT_MILLISECONDS

public static final int INTERVAL_UNIT_MILLISECONDS
See Also:
Constant Field Values

stockDateTimePatterns

public static final java.util.List stockDateTimePatterns
Constructor Detail

Util

public Util()
Method Detail

getDefaultEncoding

public static java.lang.String getDefaultEncoding()

lengthInUTF8

public static int lengthInUTF8(java.lang.String psz)
                        throws InternalError
Throws:
InternalError

getUniqueId

public static java.lang.String getUniqueId()
Generate a globally unique identifier. Useful when using the WorkItemName feature to pre-generate a work item name for use in a URL.


length

public static int length(java.lang.String psz)

length

public static int length(java.lang.StringBuffer sb)

length

public static int length(byte[] array)

length

public static int length(char[] array)

length

public static int length(int[] array)

length

public static int length(long[] array)

length

public static int length(java.lang.Object[] array)

size

public static int size(java.util.Map map)

size

public static int size(java.util.Collection collection)

autoBox

public static java.lang.Long autoBox(long l)

autoBox

public static java.lang.Integer autoBox(int i)

autoBox

public static java.lang.Boolean autoBox(boolean b)

getClass

public static java.lang.Class getClass(java.lang.Object o)

getClass

public static java.lang.Class getClass(int i)

getClass

public static java.lang.Class getClass(long l)

getClass

public static java.lang.Class getClass(boolean b)

hashCode

public static java.lang.Integer hashCode(java.lang.Object o)

formatBytes

public static java.lang.String formatBytes(long bytes)

formatMemoryStatistics

public static void formatMemoryStatistics(java.lang.StringBuffer sb)

formatMemoryStatistics

public static java.lang.String formatMemoryStatistics()

getUsedMemory

public static long getUsedMemory()

getUsedMemory

public static long getUsedMemory(boolean force)

getMaxMemory

public static long getMaxMemory()

getMaxMemory

public static long getMaxMemory(boolean force)

getServerId

public static java.lang.String getServerId()
Return the "server id". This is expected to be a unique name that can be used to distinguish one JVM running Lighthouse from another. It is used primarily for obtaining repository locks. By default it will be the same as the value returned by getLocalHostName, but DO NOT ASSUME THIS IS A HOST NAME. It may be specified with the waveset.serverId property. Doing so is necessary if you have more than one instance of Lighthouse running in a cluster on the same multi-processor machine. Since the hostname in this scenario will be the same for all instances, it cannot be used for repository locking. In this situation, you must arrange for each application server instance to set the waveset.serverId to a unique value.


getLocalHostName

public static java.lang.String getLocalHostName()
Return the local host name.


exec

public static java.lang.String exec(java.lang.String command)
                             throws WavesetException
Execute a "shell" command, returning whatever it emitted to stdout as a string. Written to support Util.getenv, but may have other uses.

Throws:
WavesetException

getenv

public static java.lang.String getenv(java.lang.String name)
Return the value of an environment variable.

Now that Sun has thoughtfully decided to deprecate System.getenv, we have to kludge around the loss in other ways. This will work only on Unix and NT, but that's all we care about anyway. (Actually only NT at the moment).

This is NOT effecient, it will lauch a process for each request, so you should use this only for occasional lookups the values of which are then cached.

We could make this faster by reading the entire environment, and maintaining it in a Properties table, but then we'd have the problem of the values going stale.


addElement

public static void addElement(java.util.ArrayList list,
                              int index,
                              java.lang.Object o)
Add an element to an array list at the given position, growing the array if necessary to avoid exceptions.

This can be used to build "sparse" arrays, or to allow for the population of array elements in random order, something that can potentially happen when using XML to build lists.


findDuplicates

public static java.util.List findDuplicates(java.util.List list)
return a list of duplicate entries in a list


removeDuplicates

public static void removeDuplicates(java.util.List list)
Remove the duplicates from a list, returning the duplicate-free list.


removeNulls

public static void removeNulls(java.util.List list)
Remove null elements from a list.


makeList

public static java.util.List makeList(java.lang.Object[] array)
Make a List out of an array.


byteToChar

public static char[] byteToChar(byte[] inb,
                                java.lang.String enc)
Converts a byte array to character array.

Parameters:
inb - Byte array of input if this is null the return will null.
enc - Encoding to use while decoding the bytes.
Returns:
Returns a character array.

byteToChar

public static char[] byteToChar(byte[] inbytes)
Converts a byte array to a char array.

Note: This method is not safe for internationalization since it will use the default encoding of the machine it is running on.

Parameters:
inbytes - Byte array of input if this is null the return will be null.
Returns:
Returns a character array encoded in the default encoding of the machine its running on.

charToByte

public static byte[] charToByte(char[] inchars)
Converts a char array to a byte array.

Note: This method is not safe for internationalization since it will use the default encoding of the machine it is running on.

Parameters:
inchars - Character array of input if this is null the return will be null.
Returns:
Returns a byte array decoded in the default encoding of the machine its running on.

charToByte

public static byte[] charToByte(char[] carray,
                                java.lang.String enc)
Converts a char array to a byte array.

Parameters:
carray - Character array of input if this is null the return will be null.
Returns:
Returns a byte array decoded in the default encoding of the machine its running on.

toUpperCharArray

public static char[] toUpperCharArray(char[] carray)
Converts all lower case characters to upper case.

Parameters:
carray - Byte array of input if this is null the return will null.
Returns:
Returns an array of characters in upper case.

toUpperByteArray

public static byte[] toUpperByteArray(byte[] barray)
Coverts all bytes to upper case.

Note: This method is not safe for internationalization since it will use the default encoding of the machine it is running on.

Parameters:
barray - Byte array of input if this is null the return will be null.
Returns:
Returns a byte array of upper case.

toUpperByteArray

public static byte[] toUpperByteArray(byte[] barray,
                                      java.lang.String enc)
Coverts all bytes to upper case.

Parameters:
barray - Byte array of input if this is null the return will be null.
Returns:
Returns a byte array of upper case.

truncateEncodedString

public static java.lang.String truncateEncodedString(java.lang.String psz,
                                                     java.lang.String encoding,
                                                     int maxbytes)
                                              throws InvalidArgument
Truncate string in encoding space, returning longest string that will fit in a byte buffer of the given size after it has been encoded.

Parameters:
psz - String to be truncated.
encoding - to be used to convert to equivalent byte array.
maxbytes - allowed in byte array before truncation.
Returns:
the substring of psz, such that if the returned substring is encoded with the given encoding, it will result in a byte array <= maxbytes.
Throws:
InvalidArgument - - thrown if psz is null OR encoding is null OR maxbytes is negative OR encoding is not valid

decodeCommaString

public static java.util.List decodeCommaString(java.lang.String src)
Parse a comma delimited string into a List of strings.


decodeCommaString

public static java.util.List decodeCommaString(java.lang.String src,
                                               boolean filterEmpty)

encodeCommaString

public static java.lang.String encodeCommaString(java.lang.Object list)
Convert a list of strings into a comma delimited list.


encodeCommaString

public static java.lang.String encodeCommaString(java.lang.Object list,
                                                 boolean filterEmpty)

encodeCommaString

public static java.lang.String encodeCommaString(java.lang.Object o,
                                                 boolean filterEmpty,
                                                 boolean trailingSpace)
Convert a list of strings to a comma delimited list. If the filterEmpty flag is on we will remove any null elements in the list. If the "trailingSpace" flag is on we will add a space after the comma. Originally we always added a trailing space, but this broke some of the adapters that wanted to get CSV's without spaces. Rather than completely remove the space its now an option in case there is other code that likes the look of the space.


decodeNewlineString

public static java.util.List decodeNewlineString(java.lang.String data,
                                                 boolean filterEmpty)
Given a newline deliminted string, break it up into a List of Strings.


encodeNewlineString

public static java.lang.String encodeNewlineString(java.util.List values,
                                                   boolean filterEmpty)
Given a List of Strings, convert them into a single String with elements seperated by newlines.


itoa

public static java.lang.String itoa(int i)
Convert an primitive integer value into a String. This doesn't really save much space, but its the obvious inverse to atoi.


btoa

public static java.lang.String btoa(boolean b)
Convert a primitive boolean value to a string.


getInt

public static int getInt(java.lang.Object v)
Coerce an Object into an int primitive.


atoi

public static int atoi(java.lang.String a)
Convert a String value into a primitive integer value. Tolerate null strings, and invalid integer strings and return 0.


atoi

public static int atoi(java.lang.String a,
                       int def)
Convert a String value into a primitive integer value. If the string is invalid, the value of the "def" argument is returned.


ltoa

public static java.lang.String ltoa(long l)
Convert a primitive long value into a String. This doesn't really save much space, but its the obvious inverse to atol.


atol

public static long atol(java.lang.String a)
Convert a String value into a primitive integer value. Tolerate null strings, and invalid integer strings and return 0.


atol

public static long atol(java.lang.String a,
                        long def)
Convert a String value into a primitive long value. If the string is invalid, returns the specified default.


ftoa

public static java.lang.String ftoa(float f)
Convert an primitive float value into a String. This doesn't really save much space, but its the obvious inverse to atof.


atof

public static float atof(java.lang.String a)
Convert a String value into a primitive float value. Tolerate null strings, and invalid integer strings and return 0.


atof

public static float atof(java.lang.String a,
                         float def)
Convert a String value into a primitive float value. If the string is invalid, the value of the "def" argument is returned.


dtoa

public static java.lang.String dtoa(double d)
Convert a primitive double value into a String. This doesn't really save much space, but its the obvious inverse to atod.


atod

public static double atod(java.lang.String a)
Convert a String value into a primitive double value. Tolerate null strings, and invalid integer strings and return 0.


atod

public static double atod(java.lang.String a,
                          double def)
Convert a String value into a primitive double value. If the string is invalid, returns the specified default.


trimWhitespace

public static java.lang.String trimWhitespace(java.lang.String src)
Trims trailing whitespace from a string. String.trim() can be used if you want to trim from both sides of the string.


lpad

public static java.lang.String lpad(java.lang.String str,
                                    int length)
Left-pad a string to the specified length. Pad a numeric string with zeros, any other with the space character.

See Also:
isNumeric(String)

rpad

public static java.lang.String rpad(java.lang.String str,
                                    int length)
Right-pad a string buffer to the specified length. Pad a numeric string with zeros, any other with the space character.

See Also:
isNumeric(String)

lpad

public static java.lang.String lpad(java.lang.String str,
                                    int length,
                                    char padChar)
Left-pad a string to the specified length with the specified character.


rpad

public static java.lang.String rpad(java.lang.String str,
                                    int length,
                                    char padChar)
Right-pad a string buffer to the specified length with the specified character.


pad

public static java.lang.String pad(java.lang.String s,
                                   int len,
                                   char pad,
                                   boolean leftPad)
Parameters:
s - - the input string to pad.
len - - pad to this length.
pad - - pad with this character.
leftPad - - if true, prepend pad characters; otherwise, append.
Returns:
the input string, padded to a specified length.

isNumeric

public static boolean isNumeric(java.lang.String s)
Returns:
true if the specified string contains only digits or decimal points, and possibly a leading minus sign. Cheaper than catching an exception from a parse method.

strstr

public static java.lang.String strstr(java.lang.String inString,
                                      java.lang.String delimiter)
Returns the last token in a string of tokens separated by the specified delimiter.


equalStrings

public static boolean equalStrings(java.lang.String s1,
                                   java.lang.String s2)
Compares the 2 strings, handling nulls

Parameters:
s1 -
s2 -
Returns:
true if s1 equals s2; otherwise false.

equals

public static boolean equals(java.lang.Object o1,
                             java.lang.Object o2)
Compares the 2 objects, handling nulls

Parameters:
o1 -
o2 -
Returns:
true if o1 equals o2; otherwise false.

strlen

public static int strlen(java.lang.String inString)
Returns the length of the specified string. Returns zero if the specified string is null.


format

public static java.lang.String format(double d,
                                      int decimalPlaces)

format

public static java.lang.String format(java.lang.String s,
                                      int decimalPlaces)
Returns:
a string representing a numerical value padded to the specified number of decimal places.

roundTo

public static double roundTo(double d,
                             int decimalPlaces)

roundToInt

public static int roundToInt(double d)

truncateAt

public static java.lang.String truncateAt(java.lang.String in,
                                          java.lang.String delim,
                                          int count)
Given a string like aaa,bbb,ccc,ddd and a delim of ",", return a string containing the first count items. truncateAt("aaa,bbb,ccc,ddd", ",", 2) returns "aaa,bbb"


midString

public static java.lang.String midString(java.lang.StringBuffer in,
                                         char delim,
                                         int start,
                                         int count)
Given a string like aaa,bbb,ccc,ddd and a delim of ",", return a string containing the items between start and (start + count). midString("aaa,bbb,ccc,ddd", ",", 2,2) returns "ccc,ddd" midString("aaa,bbb,ccc,ddd", ",", 2,4) returns "ccc,ddd" midString("aaa,bbb,ccc,ddd", ",", 1,1) returns "aaa"


escapeString

public static void escapeString(java.lang.StringBuffer b,
                                java.lang.String s)
Render a quoted string with the usual escaping. Need to do more.


escapeNewlines

public static java.lang.String escapeNewlines(java.lang.String src)
Process a string to escape newline characters.

Ordinarily done if you want to store a string as a value in a property file, where the newline marks the end of the value.


escapeSingleQuotes

public static java.lang.String escapeSingleQuotes(java.lang.String src)
Process a string to escape any apostrophe characters.

Ordinarily done if you want to store a string as a value in a relational database, where single-quotes delimit each value.


escapePoundSigns

public static java.lang.String escapePoundSigns(java.lang.String src)
Process a string to escape any hash mark (#) character.


escapeForwardSlashes

public static java.lang.String escapeForwardSlashes(java.lang.String src)
Process a string to escape any forward slash (/) character.


escapeCommas

public static java.lang.String escapeCommas(java.lang.String src)
Process a string to escape any comma (,) character.


escape

public static java.lang.String escape(java.lang.String src,
                                      char escapeThis,
                                      char prefixWith)
Process a string to escape any occurrence of the specified character by prefixing it with the specified escape character.

Parameters:
escapeThis - - the target character to escape
prefixWith - - character to insert before each target

buildFTPURL

public static java.net.URL buildFTPURL(java.lang.String host,
                                       java.lang.String port,
                                       java.lang.String path,
                                       java.lang.String user,
                                       EncryptedData password,
                                       java.lang.String type)
                                throws WavesetException,
                                       java.net.MalformedURLException
Parameters:
host - - The name of the host to connect to. Cannot be empty or null.
port - - The optional port to connect to.
path - - The optional path to the object to retrieve. '/' characters are not encoded.
user - - The optional name of a user to login as.
password - - The encrypted password to use when logging in as a specific user.
type - - The optional single character indicating the type of data to get: "a" - ascii, * "i" - binary, or "d" - directory. Note: The code underneath java.net.URL that supports ftp doesn't seem to support the ";type=t" URL syntax, so you will need to pass in "null" for the type.
Returns:
a String containing an FTP URL that looks like this: ftp://user:password@host:port/path;type=t. Any special characters in the individual URL components (e.g. user) will be encoded appropriately.

Using java.net.URL doesn't work very well when downloading a text file that is in EBCDIC. It doesn't seem to support the ";type=t" syntax. The default when downloading from a mainframe seems to be binary which does not include any newline characters.

Throws:
WavesetException
java.net.MalformedURLException

rfc2396URLPieceEncode

public static java.lang.String rfc2396URLPieceEncode(java.lang.String s)
Deprecated. Use RFC2396URLPieceEncode class.

Calls RFC2396URLPieceEncode.encode(String, String) with a null 'dontEncode' argument.


rfc2396URLPieceEncode

public static java.lang.String rfc2396URLPieceEncode(java.lang.String s,
                                                     java.lang.String dontEncode)
Deprecated. Use RFC2396URLPieceEncode class.

Calls RFC2396URLPieceEncode(String, String, boolean) with a false 'encodeSpecial' argument.


URLEncode

public static java.lang.String URLEncode(java.lang.String s)
Process a string to encode all characters using the com.waveset.util.URLUTF8Encoder.encode method

null strings will be returned null


URLDecode

public static java.lang.String URLDecode(java.lang.String s)
Process a string to decode all characters using the com.waveset.util.URLUTF8Decoder.decode method

null strings will be returned null


ignoreCase

public static java.lang.String ignoreCase(java.lang.String s)
Parameters:
s - - input string This method hides whether we convert to upper case or to lower case for case-insensitive comparison (since we've waffled a bit on this issue).
Returns:
a value to use for case-insensitive comparison.

arrayToString

public static java.lang.String arrayToString(byte[] array)

arrayToString

public static java.lang.String arrayToString(boolean[] array)

arrayToString

public static java.lang.String arrayToString(long[] array)

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] array)

stringToArray

public static java.lang.String[] stringToArray(java.lang.String s)
Inverse of arrayToString (except that we cannot convert back to Object).


mapToString

public static java.lang.String mapToString(java.util.Map map)

mapToString

public static java.lang.String mapToString(java.util.Map map,
                                           java.lang.String separator)

findClassName

public static int[] findClassName(java.lang.StringBuffer sb)
Find something tkat looks like a classname (e.g., "com.waveset.Exception:" ).

It must start with java chars, include at least one period, and end in ": ".


matchSimpleWildcard

public static boolean matchSimpleWildcard(java.lang.String in,
                                          java.lang.String matchString)
Very simple string matching, allows matchString to end in a * and match another string com.waveset.* matches com.waveset.util.Util.matchSimpleWildcard


strip

public static java.lang.String strip(java.lang.Throwable th)

getBaseName

public static java.lang.String getBaseName(java.lang.Class c)

getBaseName

public static java.lang.String getBaseName(java.lang.String className)

getFileName

public static java.lang.String getFileName(java.lang.String filePath)
Returns:
just the "basename" from the specified file path.

stripClassName

public static java.lang.String stripClassName(java.lang.String in)
Strip the classname off of the front of an error if it really looks like a classpath - and it looks like there is a real error out there. While we are at it, translate some of the really common java errors to strings: java.lang.OutOfMemoryError, java.lang.NullPointerException;


toString

public static java.lang.String toString(java.lang.Object o)

toString

public static java.lang.String toString(int i)

toString

public static java.lang.String toString(long l)

toString

public static java.lang.String toString(boolean b)

toString

public static java.lang.String toString(char c)

convertValueToString

public static java.lang.String convertValueToString(java.lang.Object value)
                                             throws WavesetException
Throws:
WavesetException

filterStringList

public static void filterStringList(java.util.List list,
                                    java.lang.String regexp)
                             throws java.lang.Exception
Remove all of the Strings in list that do not match the regular expression.

Throws:
java.lang.Exception

convertValuesToStringList

public static java.util.ArrayList convertValuesToStringList(java.lang.Object value)
                                                     throws WavesetException
Throws:
WavesetException

isASCIILetter

public static boolean isASCIILetter(char in)
Walk the string, converting any non-alpha or numeric char to an underscore. They must start with a letter or _, then all chars must be a letter, number, or _


isASCIILetterOrDigit

public static boolean isASCIILetterOrDigit(char in)

convertToJSName

public static java.lang.String convertToJSName(java.lang.String in)

replaceChar

public static java.lang.String replaceChar(java.lang.String s,
                                           java.lang.String replaceMe,
                                           java.lang.String replaceWith)
Replace all occurances of replaceMe with replaceWith


getBoolean

public static boolean getBoolean(java.lang.Object value)
Coerce an Object to a boolean value.

Boolean truth is defined by having a string property value whose first character is one of the following: t, T, y, Y, 1 Any other value, including null, is considered false.


getBoolean

public static boolean getBoolean(java.lang.Object value,
                                 boolean dflt)
Coerce an Object to a boolean value. If the specified object is null, the supplied default value is used.

Boolean truth is defined as having a string value whose first character is one of the following: t, T, y, Y, 1. Any other value is considered false.


getLong

public static long getLong(java.lang.Object v)
Coerce an Object value into a long primitive.


readFileBytes

public static byte[] readFileBytes(java.io.File file)
                            throws IOException
Read the contents of a file and return it as a String.

Throws:
IOException

readURLBytes

public static byte[] readURLBytes(java.net.URL url)
                           throws IOException
Read the content of a URL.

Returns:
the content as an array of bytes.
Throws:
IOException

readURLBytesIfExists

public static byte[] readURLBytesIfExists(java.net.URL url)
Read the contents of a URL if there is something there. Do not throw exceptions if the URL does not resolve to a file. This is used for things like the help catalogs where we want to read a file if one exists, but don't want to throw a WavesetException (and provoke an exception breakpoint) if it doesn't.


readInputStreamBytes

public static byte[] readInputStreamBytes(java.io.InputStream is,
                                          boolean close)
                                   throws IOException
Parameters:
close - - if true, close when finished reading.
Returns:
input stream content.
Throws:
IOException

readFileBytes

public static byte[] readFileBytes(java.lang.String name)
                            throws IOException
Read the content of a file and return it as a String.

Throws:
IOException

readFile

public static java.lang.String readFile(java.lang.String name)
                                 throws IOException
Read the contents of a file and return it as a String.

Throws:
IOException

readFile

public static java.lang.String readFile(java.io.File file)
                                 throws IOException
Read the contents of a file and return it as a String.

Throws:
IOException

readInputStream

public static java.lang.String readInputStream(java.io.InputStream in)
                                        throws IOException
Read the contents of an input stream and return it as a String.

Throws:
IOException

writeFileUtf8

public static void writeFileUtf8(java.lang.String name,
                                 java.lang.String contents)
                          throws IOException
Throws:
IOException

readFileUtf8

public static java.lang.String readFileUtf8(java.io.File filename)
                                     throws IOException
Throws:
IOException

readFileUtf8

public static java.lang.String readFileUtf8(java.lang.String filename)
                                     throws IOException
Throws:
IOException

readFileUtf8

public static java.lang.String readFileUtf8(java.io.InputStream in)
                                     throws IOException
Throws:
IOException

writeFile

public static void writeFile(java.io.File file,
                             java.lang.String contents)
                      throws InvalidArgument,
                             IOException
Store the contents of a String in a file.

Throws:
InvalidArgument
IOException

writeFile

public static void writeFile(java.lang.String name,
                             java.lang.String contents)
                      throws IOException
Store the contents of a String in a file.

Throws:
IOException

writeFile

public static void writeFile(java.lang.String name,
                             byte[] contents)
                      throws IOException
Store the contents of a String in a file.

Throws:
IOException

appendFile

public static long appendFile(java.lang.String name,
                              java.lang.String contents,
                              long maxLength)
                       throws WavesetException,
                              IOException
See appendFile, below. This just truncates the file at a requested length if it grows too large.

Throws:
WavesetException
IOException

appendFile

public static long appendFile(java.lang.String name,
                              java.lang.String contents)
                       throws IOException
Append to a file.

Parameters:
name - - file name to log to. Created if des not exist
contents - - string to write out
Returns:
total length of the file (for trimming, if needed). 0 if no data written
Throws:
IOException

copyFile

public static int copyFile(java.lang.String src,
                           java.lang.String dest)
                    throws WavesetException,
                           IOException
Copies one file to another.

Returns:
total bytes copied.

I'm sort of suprised the JDK doesn't have something to do this. If this were used with large files, we'd want to do iterate over a fixed block size.

Throws:
WavesetException
IOException

copyFileByBlockSize

public static int copyFileByBlockSize(java.io.InputStream fis,
                                      java.io.OutputStream fos,
                                      int bufferSize)
                               throws java.io.IOException
Copies one file to another.

Returns:
total bytes copied.

Iterate over a fixed block size specified by bufferSize

Throws:
java.io.IOException

copyFile

public static int copyFile(java.io.InputStream fis,
                           java.io.OutputStream fos)
                    throws java.io.IOException
Copies one file to another.

Returns:
total bytes copied.

Iterate over a fixed block size.

Throws:
java.io.IOException

copyFile

public static boolean copyFile(java.io.InputStream fis,
                               java.io.OutputStream fos,
                               int max)
                        throws java.io.IOException
Copies one file to another up to a specified max.

Returns:
true if the entire input stream was copied before hitting max.
Throws:
java.io.IOException

copyFile

public static int copyFile(java.io.Reader reader,
                           java.io.Writer writer)
                    throws java.io.IOException
Copies one file to another.

Returns:
total bytes copied.

Iterate over a fixed block size.

Throws:
java.io.IOException

copyFileByBlockSize

public static int copyFileByBlockSize(java.io.Reader reader,
                                      java.io.Writer writer,
                                      int bufferSize)
                               throws java.io.IOException
Copies one file to another.

Returns:
total bytes copied.

Iterate over a fixed block size specified by bufferSize

Throws:
java.io.IOException

renameFileForBackup

public static boolean renameFileForBackup(java.io.File file)
Renames the file using the following format: .backup.yyyyMMdd_HHmmss. Returns whether or not the file was renamed.


renameFileForBackup

public static boolean renameFileForBackup(java.lang.String path)
Renames the file using the following format: .backup.yyyyMMdd_HHmmss. Returns whether or not the file was renamed.


checksum

public static long checksum(java.lang.String fileName)
                     throws java.io.IOException,
                            java.io.FileNotFoundException
Calculates the CRC32 checksum of the specified file.

Parameters:
fileName - - the path to the file on which to calculate the checksum
Throws:
java.io.IOException
java.io.FileNotFoundException

checksum

public static long checksum(java.io.File file)
                     throws java.io.IOException,
                            java.io.FileNotFoundException
Throws:
java.io.IOException
java.io.FileNotFoundException

putJarEntry

public static void putJarEntry(java.lang.String jarFileName,
                               java.lang.String jarEntryName,
                               boolean jarMustExist,
                               boolean overwriteEntry)
                        throws InvalidArgument,
                               WavesetException
Archive and compress a data file.

Parameters:
jarFileName - - the path to the Java ARchive file.
jarEntryName - - the path to a file to be placed in the jar file.
jarMustExist - - if true, the file named by jarFileName must exist.
overwriteEntry - - if true, the specified jarEntry may replace an existing entry with the same name.
Throws:
InvalidArgument - - thrown if jarMustExist is true and jar file is not found, or if overwriteEntry is false and an entry with the name specified by jarEntryName already exists.
WavesetException

putJarEntries

public static void putJarEntries(java.lang.String jarFileName,
                                 java.util.List entryNames,
                                 boolean jarMustExist,
                                 boolean overwriteEntry,
                                 boolean updateExistingJar)
                          throws InvalidArgument,
                                 WavesetException
Archive and compress a data file.

Parameters:
jarFileName - - the path to the Java ARchive file.
entryNames - - a list of files to be placed in the jar file.
jarMustExist - - if true, the file named by jarFileName must exist.
overwriteEntry - - if true, the specified jarEntry may replace an existing entry with the same name.
Throws:
InvalidArgument - - thrown if jarMustExist is true and jar file is not found, or if overwriteEntry is false and an entry with the name specified by jarEntryName already exists.
WavesetException

createJarFile

public static void createJarFile(java.io.File jarFile,
                                 java.io.File rootDir,
                                 java.util.List files)
                          throws InvalidArgument,
                                 WavesetException
Archive and compress a data file.

Parameters:
jarFile - - target output archive file.
rootDir - - source directory containing the data files.
files - - a list of files to be placed in the jar file.
Throws:
InvalidArgument - thrown if one of the listed files is not beneath rootDir.
WavesetException

expandJarFile

public static void expandJarFile(java.io.File jarFile,
                                 java.io.File rootDir)
                          throws InvalidArgument,
                                 WavesetException
Extract and uncompress all data files from an archive.

Parameters:
jarFile - - the source archive file.
rootDir - - the target directory beneath which to place the files.
Throws:
InvalidArgument
WavesetException

expandJarFile

public static void expandJarFile(java.io.File jarFile,
                                 java.io.File rootDir,
                                 java.util.List entryNames)
                          throws InvalidArgument,
                                 WavesetException
Extract and uncompress specified data files from an archive.

Parameters:
jarFile - - the source archive file.
rootDir - - the target directory beneath which to place the files.
entryNames - - a list of entry names to extract from the jar file. If this list is null, this method will extract all entries.
Throws:
InvalidArgument
WavesetException

listClasses

public static java.util.List listClasses()
                                  throws java.lang.Exception
List all of the classes in the classpath.

Throws:
java.lang.Exception

listClassesInZipFile

public static java.util.List listClassesInZipFile(java.io.File file)
                                           throws java.lang.Exception
List all of the classes in the specified zip (jar) file.

Throws:
java.lang.Exception

listClassesInDirectory

public static java.util.List listClassesInDirectory(java.io.File dir)
                                             throws java.lang.Exception
List all of the classes found in the specified directory or its subdirectories. The directory should be one that might be added to a classpath.

Throws:
java.lang.Exception

getClassNameFromZipPath

public static java.lang.String getClassNameFromZipPath(java.lang.String path)
Take a path name of a file from a zip (jar) file and return the corresponding class name (e.g. "com.waveset.util.Util") if the file name ends with ".class". Otherwise, return null.


getClassNameFromFilePath

public static java.lang.String getClassNameFromFilePath(java.lang.String path)
Take a path name of a file and return the corresponding class name (e.g. "com.waveset.util.Util") if the file name ends with ".class". Otherwise, return null.


getClassNameFromPath

protected static java.lang.String getClassNameFromPath(java.lang.String path,
                                                       java.lang.String separator)
Take a path name of a file that uses the specified separator and return the corresponding class name (e.g. "com.waveset.util.Util") if the file name ends with ".class". Otherwise, return null.


listAllFilenames

public static java.util.List listAllFilenames(java.io.File dir,
                                              boolean relativeNames)
                                       throws java.lang.Exception
List all of the filenames (not including directory names) in the specified directory and its subdirectories. Either return names relative to the directory or as canonical path names.

Throws:
java.lang.Exception

listAllFilenames

protected static java.util.List listAllFilenames(java.io.File dir,
                                                 boolean relativeNames,
                                                 java.lang.String basepath)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

getMachineUser

public static java.lang.String getMachineUser()
Get the name of the user that is logged in to the host machine.


mangle

public static java.lang.String mangle(java.lang.String name)
                               throws InternalError
Replace special characters in a name or id so that it will be a valid filename.

Returns:
name or id (mangled into a) valid filename.
Throws:
InternalError

demangle

public static java.lang.String demangle(java.lang.String mangledName)
Restore special characters in a filename.

Returns:
original item name or id (no longer mangled)
See Also:
mangle(String)

replaceString

public static java.lang.String replaceString(java.lang.String in,
                                             java.lang.String fromString,
                                             java.lang.String toString)
Returns:
a new string resulting from replacing all occurrences of fromString in the input string in with toString.

stringToList

public static java.util.List stringToList(java.lang.String s,
                                          java.lang.String delim)
Parameters:
s - - the input string
delim - - the delimiter string (NOTE: NOT as in StringTokenizer(s, delim). Instead, the entire string is taken as the separator.)
Returns:
a list of string tokens. Trims whitespace from the beginning and end of each token. Ignores any token that contains only white space.

stringToList

public static java.util.List stringToList(java.lang.String s,
                                          java.lang.String delim,
                                          boolean trim)
Parameters:
s - - the input string
delim - - the delimiter string (NOTE: NOT as in StringTokenizer(s, delim). Instead, the entire string is taken as the separator.)
trim - - if true, remove any whitespace from the beginning and the end of each token. Ignore any token that contains only white space.
Returns:
a list of string tokens.

stringToList

public static java.util.List stringToList(java.lang.String s,
                                          java.lang.String delim,
                                          boolean trim,
                                          java.lang.String valWrapper)
Parameters:
s - - the input string
delim - - the delimiter string (NOTE: NOT as in StringTokenizer(s, delim). Instead, the entire string is taken as the separator.)
trim - - if true, remove any whitespace from the beginning and the end of each token. Ignore any token that contains only white space.
valWrapper - - expected to precede and follow each token (e.g., a single-quote must precede and follow each literal value in an SQL "IN" expression).
Returns:
a list of string tokens.

addToken

public static java.util.List addToken(java.util.List list,
                                      java.lang.String token,
                                      boolean trim,
                                      java.lang.String valWrapper)

commaDelimitedStringToList

public static java.util.List commaDelimitedStringToList(java.lang.String cds)
Parameters:
cds - - a string of tokens separated by commas.

Will not return any token that contains only white space.

Returns:
a List of comma-delimited string tokens.

listToCommaDelimitedString

public static java.lang.String listToCommaDelimitedString(java.util.List list)
Parameters:
list - - a string of tokens separated by commas.

Will not return any token that contains only white space.

Returns:
a string containing comma-delimited string tokens.

listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String delim)
Parameters:
list - - the input list
delim - - the delimiter string
Returns:
a string containing delimited tokens.

listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String delim,
                                            int maxLen)
Parameters:
list - - the input list
delim - - the delimiter string
maxLen - - the maximum length of the resulting string.
Returns:
a string containing delimited tokens.

listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String delim,
                                            int maxLen,
                                            java.lang.String valWrapper)
Parameters:
list - - the input list
delim - - the delimiter string
maxLen - - the maximum length of the resulting string.
valWrapper - - precede and follow each value with this string (e.g., a single-quote must precede and follow each literal value in an SQL "IN" expression.)
Returns:
a string containing delimited tokens.

normalizeString

public static java.lang.String normalizeString(java.lang.String str)
Normalization of the string will be done using an implementation of RFC2253 which specifies the standard for the string representation of distinguished names handling issue such as capitalization, component ordering, special characters, internationalized characters, trimming leading and trailing spaces, etc.

This is being called to normalize all strings when doing AttributeCondition compares since we don't really care how the two strings (provided string and operand string) look as long as they compare if the same.

If string passed in is null, it is not normalized and null is returned.


dateToString

public static java.lang.String dateToString()
Returns:
a string formatting the current date according to the default pattern.

dateToString

public static java.lang.String dateToString(java.lang.String simpleDateFormatPattern)
Returns:
a string formatting the current date according to the specified pattern.

dateToString

public static java.lang.String dateToString(long timeMillis)
Returns:
a string formatting a specified timestamp according to the default pattern.

dateToString

public static java.lang.String dateToString(long timeMillis,
                                            java.lang.String simpleDateFormatPattern)
Returns:
a string formatting a specified time (in milliseconds) in the specified format (default is yyyyMMdd hh:mm:ss".

getOldCanonicalDateString

public static java.lang.String getOldCanonicalDateString(java.util.Date date,
                                                         boolean absoluteTimezone)
Deprecated. Use getCanonicalDateString

For legacy canonical format. We moved away from this in 5.0 SP1 since it is relative to the current timezone. We still have this method for use by the Log table since we could not force the huge upgrade time. Added an absolute timezone flag which will be used by all new Log entries. When querying on the Log table, need to know whether the date you are querying for is before or after the 5.0 SP1 upgrade, and pass in the appropriate value for absoluteTimezone.


getCanonicalDateFormat

public static java.text.DateFormat getCanonicalDateFormat()
Deprecated. Will become a private method since this doesn't handle parsing a general IS0-8601 format. (Only handles our subset). Instead always use the public methods stringToDate and getCanonicalDateString. (At some point we may want to handle parsing a general IS0-8601 format).

IS0-8601 date format.


getCanonicalDateString

public static java.lang.String getCanonicalDateString(long timestamp)
Returns:
An IS0-8601 formatted date string

getCanonicalDateString

public static java.lang.String getCanonicalDateString(java.util.Date date)
Returns:
An IS0-8601 formatted date string

getCanonicalDateString

public static java.lang.String getCanonicalDateString(java.util.Date date,
                                                      java.util.TimeZone timeZone)
Returns:
An IS0-8601 formatted date string

getCanonicalDateStringOnly

public static java.lang.String getCanonicalDateStringOnly(java.util.Date date)
Returns:
formatted string representing DATE in ISO-8601 format: yyyy-MM-dd.

getCanonicalTimeStringOnly

public static java.lang.String getCanonicalTimeStringOnly(java.util.Date date)
Returns:
formatted string representing the TIME in ISO-8601 format: HH:mm:ss.SSSZ.

dateToString

public static java.lang.String dateToString(java.util.Date date,
                                            java.lang.String simpleDateFormatPattern)
Returns:
a string representing a specified date in the specified format.

dateToString

public static java.lang.String dateToString(java.util.Date src)
Format a Date value as a String, using the usual "American" format with the current time zone. NOTE: The "American" format doesn't sort worth a damn.


dateToString

public static java.lang.String dateToString(java.util.Locale locale)
Format the current date using the given locale.


dateToString

public static java.lang.String dateToString(java.util.Date src,
                                            java.util.Locale locale)
Format the given date using the given locale.


dateToString

public static java.lang.String dateToString(long src_millis,
                                            java.util.Locale locale)
Format the given date using the given locale.


stringToDate

public static java.util.Date stringToDate(java.lang.String src,
                                          java.lang.String format)
                                   throws java.text.ParseException
Throws:
java.text.ParseException

stringToDate

public static java.util.Date stringToDate(java.lang.String src,
                                          java.lang.String format,
                                          java.lang.String timeZone)
                                   throws java.text.ParseException
Throws:
java.text.ParseException

stringToDate

public static java.util.Date stringToDate(java.lang.String src)
                                   throws java.text.ParseException
Convert the string representation for a date into a Date object. The string may be of the following forms: M/d/y H:m:s z M/d/y H:m:s M/d/y yyyyMMdd HH:mm:ss (default) yyyyMMdd HH:mm:ss.SSS (old canonical) yyyyMMddTHH:mm:ss.SSS (old canonical absolute) yyyy-MM-ddTHH:mm:ss.SSSZ (canonical, no offset) yyyy-MM-ddTHH:mm:ss.SSS+/-HHMM (canonical, offset) nnnnnnnnnnnnnnnnn (milliseconds)

Throws:
java.text.ParseException
See Also:
DATE_FORMAT_COMPACT, DATE_FORMAT_DEFAULT, DATE_FORMAT_MILLIS

getRelativeDate

public static java.util.Date getRelativeDate(int field,
                                             int amount)
Generates a data string expressed as a number of units from now such as "5 minutes from now"

Parameters:
field - Integer corresponding to the field of the date to increment. Legal values correspond with constants used by the Calendar class, namely: 0 (era) 1 (year) 2 (month) 3 (week of year) 4 (week of month) 5 (day of month) 6 (day of year) 7 (day of week) 8 (day of week in month) 9 (am/pm) 10 (hour) 11 (hour of day) 12 (minute) 13 (second) 14 (millisecond) 15 (zone offset) 16 (daylight savings time offset)
amount - Number representing the value to increment the current date by the units specified in field
Returns:
a time/date string in the future

getRelativeDate

public static java.util.Date getRelativeDate(int ord,
                                             int day,
                                             int mo)
Generates a date string expressed in a future time such as "the second Monday in October". If the current time is BEFORE the date requested by the input parameters, the date will be for the current year. If the current time is AFTER the date requested, the year will be incremented by one such that the date occurs in the future. The date returned will be rounded up to the day boundary.

Parameters:
ord - Integer representing the ordinal of the day of the week for the generated date and must be a number between 1 and 5 inclusive. If there are only four days in the month and the value of this parameter is 5, the result of this method call is undefined.
day - Integer representing a day of the week. Legal values correspond with constants used by the Calendar class, namely:
          1 (Sunday)
          2 (Monday)
          3 Tuesday)
          4 (Wednesday)
          5 (Thursday)
          6 (Friday)
          7 (Saturday)
        
mo - Integer representing a month. Legal values correspond with constants used by the Calendar class, namely:
          0 (January)
          1 (February)
          2 (March)
          3 (April)
          4 (May)
          5 (June)
          6 (July)
          7 (August)
          8 (September)
          9 (October)
          10 (November)
          11 (December)
        
Returns:
a time/date string

getRelativeDate

public static java.util.Date getRelativeDate(Util.TimePeriod period)
Calculates a Date representing the current time plus the the amount of time represented by the TimePeriod. If the unit of the specified TimePeriod is not MINUTES, the relative date returned will be rounded up to a day boundary so passwords won't expire until the second before midnight of the day the password is scheduled to expire.


dateEquals

public static boolean dateEquals(java.util.Date date1,
                                 java.util.Date date2)
Determine if date1 is the same as date2. This method is required as it only compares the month, day, and year components of a date (found that using the Date after & equals methods relies on a strait compare of the long UTC value of time which for some reason for the same date/time is not always the same)


dateAfter

public static boolean dateAfter(java.util.Date date1,
                                java.util.Date date2)
Determine if date1 is after date2. When comparing two dates, this method compares the seconds, minutes, hours, day, month, and year.


formatElapsedTime

public static java.lang.String formatElapsedTime(long from,
                                                 long to)
Returns:
a beautified string to display elapsed time.

formatTimeInterval

public static java.lang.String formatTimeInterval(long millis)
Returns:
a beautified string to display a time interval down to millisecond granularity.

formatTimeInterval

public static java.lang.String formatTimeInterval(long millis,
                                                  int maxUnit,
                                                  int granularity)
Returns:
a beautified string to display a time interval,

sprintf

public static java.lang.StringBuffer sprintf(java.lang.String format,
                                             java.lang.String[] args)
A marginally functional attempt to provide "sprintf" in Java. The format string is a blank delimited list of integer tokens that represent the field sizes. The args array contains the strings that will plug into the fields. Todo: take an Object[] array instead of a String[] array add format tokens for left/right justification allow literal text in the format string


println

public static void println()
Ubiquitous macro


println

public static void println(java.lang.Object o)

print

public static void print(java.lang.Object o)

debug

public static void debug(java.lang.Object o)
Deprecated. Use Debug or Trace instead.


getWavesetHome

public static java.lang.String getWavesetHome()
Returns:
the application docroot string.

NOTE: This string could be a file path or a URL.

See Also:
getWavesetHomePathIfFile(), getWavesetHomeURL()

getWavesetHomeURL

public static java.net.URL getWavesetHomeURL()
Returns:
the application docroot URL.

NOTE: This could be a file or a JAR (WARfile) URL.

See Also:
getWavesetHomePathIfFile()

setWavesetHome

public static java.lang.String setWavesetHome(java.lang.String newValue)
Set the application docroot.

Returns:
any previous value.

getWavesetHomeURL

public static java.net.URL getWavesetHomeURL(boolean ignoreAnyCached)
Parameters:
ignoreAnyCached - re-read SystemProperty

Try (in the following order):

  1. System property waveset.home
  2. environment variable "WS_HOME".
  3. parsing the URL to this class (as a resource).
Returns:
a URL for waveset.home (the application docroot).

getWavesetHomePathIfFile

public static java.lang.String getWavesetHomePathIfFile()
Convenience method. In the simple case where waveset.home is a directory that is available to the local file system, this method returns the path to that directory.

Returns:
the path to waveset.home if waveset.home is a file; otherwise null.

Originally, the value of waveset.home was always a String containing a file path to a local (or locally mounted) directory. Later, support for application-server-clustered environments required that we generalize waveset.home to a URL (and that we no longer assume access to the local file system).


getWavesetConfigURL

public static java.net.URL getWavesetConfigURL()
Get a URL that points to our config directory, should be a file URL that points to lighthouse/config.


getResource

public static java.net.URL getResource(java.lang.String name)
                                throws InvalidArgument
Returns:
the URL for the specified resource.

The call is delegated to the class loader for this class.

To get a URL for a Lighthouse application resource, call getWavesetResource(String).

Throws:
InvalidArgument

getWavesetResource

public static java.net.URL getWavesetResource(java.lang.String name)
                                       throws InvalidArgument,
                                              InternalError
Parameters:
name - relative to the application docroot (as specified by System Property waveset.home).

Returns:
a URL for the named resource
Throws:
InvalidArgument - if name is null.
InternalError - if waveset.home URL cannot be determined.

readResource

public static java.lang.String readResource(java.net.URL resoUrl)
                                     throws InvalidArgument,
                                            IOException,
                                            InternalError
Returns:
the content of the specified URL as a String.
Throws:
InvalidArgument
IOException
InternalError

readWavesetResource

public static java.lang.String readWavesetResource(java.lang.String name)
                                            throws InvalidArgument,
                                                   InternalError,
                                                   IOException
Convenience method: equivalent to calling getWavesetResource(); and readResource();.

Throws:
InvalidArgument
InternalError
IOException

writeResource

public static void writeResource(java.net.URL resoUrl,
                                 java.lang.String content)
                          throws InvalidArgument,
                                 ConfigurationError,
                                 IOException
Replace the content of the specified URL with a String if that URL is a file.

If Lighthouse is deployed as (expanded) Servlet files, then most resources can be written. However, if Lighthouse is deployed as some form of archive (e.g., a WAR or an EAR), then resources should not ordinarily be written.

Throws:
InvalidArgument - if either argument is null.
ConfigurationError - if the resource is not writable.
IOException - if an error occurs writing the resource.

writeWavesetResource

public static void writeWavesetResource(java.lang.String name,
                                        java.lang.String content)
                                 throws InvalidArgument,
                                        InternalError,
                                        ConfigurationError,
                                        IOException
Convenience method: equivalent to calling getWavesetResource(); and writeResource();.

Throws:
InvalidArgument
InternalError
ConfigurationError
IOException

getWavesetResourcePath

public static java.lang.String getWavesetResourcePath(java.lang.String name)
                                               throws InvalidArgument,
                                                      InternalError
Convenience method: equivalent to calling getWavesetResource(); and getResourcePath();.

Throws:
InvalidArgument
InternalError

getResourcePath

public static java.lang.String getResourcePath(java.lang.String name)
Attempts to determine the absolute pathname of a resource file.

Parameters:
name - path to a resource file that can be found in the CLASSPATH.

getResourcePath

public static java.lang.String getResourcePath(java.net.URL res)
Parameters:
res - the URL of a resource file.
Returns:
the absolute pathname of a resource file.

pathIsAbsolute

public static boolean pathIsAbsolute(java.lang.String path)
Returns:
true if the specified path appears to be an absolute path; otherwise false.

Don't bother to call this if you already have (or plan to construct) a File with the specified path. This method is a poor man's File.isAbsolute(), this method's advantage is that it avoids object construction.


pathIsRelative

public static boolean pathIsRelative(java.lang.String path)
Returns:
true if the specified path appears to be a relative path; otherwise false.

Don't bother to call this if you already have (or plan to construct) a File with the specified path. This method is a poor man's inverse of File.isAbsolute(), this method's advantage is that it avoids object construction.


wavesetResourceExists

public static boolean wavesetResourceExists(java.lang.String name)
                                     throws InvalidArgument,
                                            InternalError
Convenience method: equivalent to calling getWavesetResource(); and resourceExists();.

Throws:
InvalidArgument - if specified name is null.
InternalError - if waveset.home URL cannot be determined.

resourceExists

public static boolean resourceExists(java.net.URL resoUrl)
Returns:
true if we can connect to the specified resource; otherwise false.

getWavesetResourceFile

public static java.io.File getWavesetResourceFile(java.lang.String name)
                                           throws InvalidArgument,
                                                  InternalError,
                                                  ConfigurationError
Convenience method: equivalent to calling getWavesetResource(); and getResourceFile();.

Throws:
InvalidArgument
InternalError
ConfigurationError

getSavedObjectsDir

public static java.io.File getSavedObjectsDir()
                                       throws InvalidArgument,
                                              InternalError,
                                              ConfigurationError
Returns the path to the savedObjects directory.

Throws:
InvalidArgument
InternalError
ConfigurationError

getFontsDir

public static java.io.File getFontsDir()
                                throws InvalidArgument,
                                       InternalError,
                                       ConfigurationError
Returns the path to the WEB-INF/fonts directory.

Throws:
InvalidArgument
InternalError
ConfigurationError

getResourceFileIfFile

public static java.io.File getResourceFileIfFile(java.net.URL resoUrl)
                                          throws InvalidArgument
Returns:
handle to specified resource as a File. Return null if the specified URL is not a file.

Call method getResourceFile(URL) if the specified URL must be a file.

Throws:
InvalidArgument - if the specified URL is null.

getResourceFile

public static java.io.File getResourceFile(java.net.URL resoUrl)
                                    throws InvalidArgument,
                                           ConfigurationError
Returns:
handle to specified resource as a File.
Throws:
InvalidArgument - if the specified URL is null.
ConfigurationError - if the specified URL is not a file.

Call method getResourceFileIfFile(URL) if the URL need not specify a file.


getResourceFile

public static java.io.File getResourceFile(java.net.URL resoUrl,
                                           boolean mustExist)
                                    throws InvalidArgument,
                                           ConfigurationError
Parameters:
mustExist - if true, the specified file must exist.
Returns:
handle to specified resource as a File.
Throws:
InvalidArgument - if the specified URL is null.
ConfigurationError - if the specified URL is not a file or if mustExist is true and the file does not exist.

Call method getResourceFileIfFile(URL) if the URL need not specify a file.


legalizeResourceName

public static java.lang.String legalizeResourceName(java.lang.String resoName)

listClassNamesMatching

public static java.util.List listClassNamesMatching(java.lang.String baseName)
                                             throws InvalidArgument
Returns:
a list containing the fully-qualified names of classes in the Lighthouse archive (jar file) that contain the specified partial name.
Throws:
InvalidArgument

getLighthouseJar

public static java.util.jar.JarFile getLighthouseJar()
Searches the classpath for idm.jar.


getClasspathDirectory

public static java.lang.String getClasspathDirectory(int idx)
Return the nth item on the CLASSPATH. In addition to isolating the path, it will convert \ to / and trim the trailing slash if any.


getClasspathList

public static java.util.List getClasspathList()
Return a list of the items that are in the classpath.


getInputStreamFromJar

public static java.io.InputStream getInputStreamFromJar(java.lang.String jarfilename,
                                                        java.lang.String entryName)
                                                 throws java.lang.Exception
Return an input stream for an entry in a jar file.

Throws:
java.lang.Exception

getStringFromJar

public static java.lang.String getStringFromJar(java.lang.String jarfilename,
                                                java.lang.String entryName)
                                         throws java.lang.Exception
Return the contents of an entry in a jar file as a string.

Throws:
java.lang.Exception

findFile

public static java.lang.String findFile(java.lang.String property,
                                        java.lang.String name)
Attempt to derive the absolute path of a file. The "name" argument may be an absolute path or path fragment. If it is an absolute path, it is simply returned. If it is a path fragment, we will use the system property named in the "property" argument as the root directory, and add the path fragment. If a file cannot be found by combining the path fragment with the system property, the path fragment is passed to getResourcePath which will attempt to find it through the CLASSPATH. If getResourcePath fails, we just return the name argument.


findFile

public static java.lang.String findFile(java.lang.String property,
                                        java.lang.String name,
                                        boolean searchClasspath)
Attempt to derive the absolute path of a file. The "name" argument may be an absolute path or path fragment.

Parameters:
property - - a system property specifying a location to search.
name - - a path or path fragment.
searchClasspath - - if true, we next search the classpath.
Returns:
the absolute path of any file that is found; otherwise
  • if 'name' is an absolute path the fragment passed in as 'name'
  • if 'searchClassPath' is true, the fragment passed in as 'name'
  • if 'searchClassPath' is false, the path relative to 'property'.

If it is an absolute path, it is simply returned.

If it is a path fragment, we will use the system property named in the "property" argument as the root directory, and add the path fragment.

If the argument 'searchClasspath' is true, and a file cannot be found by combining the path fragment with the system property, then the path fragment is passed to getResourcePath, which will attempt to find it through the CLASSPATH. If getResourcePath fails, we just return the name argument.


findFile

public static java.lang.String findFile(java.lang.String name)
Attempt to derive the absolute path of a file. The "name" argument may be an absolute path or path fragment. If it is an absolute path, it is simply returned. If it is a path fragment, we will use the system property "user.dir" as the root directory and add the path fragment. If a file cannot be found by combining the path fragment with user.dir, the path fragment is passed to getResourcePath which will attempt to find it through the CLASSPATH. If getResourcePath fails, we just return the name argument.


findOutputFile

public static java.lang.String findOutputFile(java.lang.String name)
Build an absolute path name for a file. Typically used when you want to write an output file to the "current working directory". If the name is already an absolute path we use it, otherwise we use the system property "user.dir" as the root directory and add the name.


getApplicationHome

public static java.lang.String getApplicationHome()
                                           throws WavesetException
Returns the value of the WSHOME environment variable. System.getenv has been deprecated and doesn't appear to work anyway with JDK 1.2. We can fake it by assuming that WSHOME/java is on the CLASSPATH, and we use a ClassLoader to find a known file within that directory. This is however rather unreliable. Modified to do the "right" thing and look for a property that was passed on the java command line. The property we expect is"waveset.home".

Throws:
WavesetException

confirmDirectory

public static void confirmDirectory(java.io.File dir)
                             throws ConfigurationError
Make sure the directory exists and is writable.

Throws:
ConfigurationError

confirmDirectory

public static void confirmDirectory(java.io.File dir,
                                    boolean createIfMissing)
                             throws ConfigurationError
Make sure the directory exists (or can be created) and is writable.

Throws:
ConfigurationError

checkDirectory

public static java.lang.String checkDirectory(java.io.File dir,
                                              boolean createIfMissing)
Returns:
null if the directory exists (or can be created) and is writable. If not, return a message describing the problem.

dumpProperties

public static void dumpProperties(java.io.PrintWriter out)
Prints the current system properties to a writer object.


dumpProperties

public static void dumpProperties()
Prints the current system properties to the system output device.


dumpBytes

public static java.lang.String dumpBytes(byte[] bytes)
Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left

Parameters:
bytes - the bytes to print
Returns:
a string with the formatted output

dumpBytes

public static java.lang.String dumpBytes(byte[] bytes,
                                         int len)
Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left

Parameters:
bytes - the bytes to print
len - the number of bytes in the array to print
Returns:
a string with the formatted output

dumpBytes

public static java.lang.String dumpBytes(byte[] bytes,
                                         int start,
                                         int len)
Prints the provided bytes in a format using hex bytes on the right of the line and ASCII printable chars on the left

Parameters:
bytes - the bytes to print
start - the index in the array to start printing
len - the number of bytes in the array to print
Returns:
a string with the formatted output

hashtableToMap

public static java.util.HashMap hashtableToMap(java.util.Hashtable hash)
Convert a Hashtable into a HashMap. There are probably easier ways to do this with some of the newer collection methods.


stringToHtmlComment

public static java.lang.String stringToHtmlComment(java.lang.String s)
Converts the stack trace of an exception to an HTML string


stackToHtmlComment

public static java.lang.String stackToHtmlComment(java.lang.Throwable th)
Converts the stack trace of an exception to an HTML string Bug #10499 If 'ui.web.disableStackTraceComments' property in waveset.properties is 'true' this returns an empty string. By default the property is false, in which case the stack trace is returned as an HTML comment string.


stackToHtml

public static java.lang.String stackToHtml(java.lang.Throwable th)
Converts the stack trace of an exception to an HTML string


stackToString

public static java.lang.String stackToString(java.lang.Throwable th)
Converts the stack trace of an exception to a String


topStackFrames

public static java.lang.String topStackFrames(int num)
Returns:
a String of the the top num stack frames

printStackTrace

public static void printStackTrace()
Debugging aid that dumps the current stack trace to the console.


addString

public static java.lang.String[] addString(java.lang.String[] list,
                                           java.lang.String newString)
Return a new string array with the string added. Do the right thing for null list and/or null newString


appendString

public static java.lang.String[] appendString(java.lang.String[] list,
                                              java.lang.String newString)
Similar to addString but just appends the string to end of the list (no sorting, no check for duplicates, no guard against null values).


containsAny

public static boolean containsAny(java.util.Collection containing,
                                  java.util.Collection query)
Returns true if containing collection contains any of the items in the query collection. Note: List's can not specify a Comparator so the contains done herein may not be finding the value if you're expecting if the two objects need special handling (i.e. CaseIgnoreString). rwagner


indexOf

public static int indexOf(java.lang.Object[] objs,
                          java.lang.Object obj)

contains

public static boolean contains(java.lang.Object[] objs,
                               java.lang.Object obj)

findIllegals

public static java.lang.String findIllegals(java.lang.String name,
                                            java.lang.String illegals)

timestampConvert

public static java.lang.String timestampConvert(java.lang.String dText,
                                                java.lang.String tText,
                                                java.lang.String iTimezone,
                                                java.lang.String oMask,
                                                java.lang.String oTimezone)
Parameters:
dText - The date to use (must be in MM/dd/yyyy form)
tText - The time to use (must be in HH:mm, Hmm, or HHmm form)
iTimezone - What time zone the given time stamp is in
oMask - A SimpleDateFormat friendly format mask used to emit the time stamp in
oTimezone - The time zone the outputted time should be in
Returns:
The given time, or now (if the given time could not be parsed), formated as directed by oMask in the time zone specified in oTimezone

timestampConvert

public static java.lang.String timestampConvert(java.lang.String dText,
                                                java.lang.String tText,
                                                java.util.List formats,
                                                java.lang.String iTimezone,
                                                java.lang.String oMask,
                                                java.lang.String oTimezone)
Parameters:
dText - The date to attempt to parse
tText - The time to attempt to parse
formats - A list of Strings that will become the SimpleDateFormat objects used to parse dText/tText
iTimezone - What time zone the given time stamp is in
oMask - A SimpleDateFormat friendly format mask used to emit the time stamp in
oTimezone - The time zone the outputted time should be in
Returns:
The given time, or now (if the given time could not be parsed), formated as directed by oMask in the time zone specified in oTimezone

gzipCompress

public static byte[] gzipCompress(byte[] inbytes)
                           throws WavesetException
Throws:
WavesetException

gzipDecompress

public static byte[] gzipDecompress(byte[] inbytes,
                                    int size)
                             throws WavesetException
Throws:
WavesetException

gzipDecompress

public static byte[] gzipDecompress(byte[] inBytes)
                             throws WavesetException
Decompress an array of bytes, if possible.

Parameters:
inBytes -
Returns:
decompressed bytes
Throws:
WavesetException - on IOException. The underlying IOException is wrapped by the WavesetException.

compressToString

public static java.lang.String compressToString(java.io.Serializable obj)
Serializes obj, compresses it using gzip, and then base64 encodes it so that it can be cleanly stuck in XML. This should only be used if the object will compress well and profiling has shown that it's necessary. Call uncompressFromString to get the object back.


uncompressFromString

public static java.io.Serializable uncompressFromString(java.lang.String str)
Called to retrieve the object passed into compressToString


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

sortList

public static java.util.List sortList(java.util.List list)
Sort a list


getLocalizedString

public static java.lang.String getLocalizedString(java.util.Locale locale,
                                                  java.lang.Object value)

getAttributeMap

public static java.util.HashMap getAttributeMap(java.lang.String attrString)
This routine will take a string of comma delimeted name value pairs and place them in a hashmap.


getDecrementedDate

public static java.util.Date getDecrementedDate(java.lang.String numLogin)

getApplicationDataDirectory

public static java.io.File getApplicationDataDirectory()
Returns an os-specific application data directory for Identity Manager. That is ~/.idmgr on unix systems and Documents And Settings//.idmgr on windows systems.


isWindows

public static boolean isWindows()
Are we running in windows?


copyFile

public static boolean copyFile(java.io.File src,
                               java.io.File dest)
                        throws java.io.IOException
Copies a file to a destintation.

Parameters:
src - The source must be a file
dest - This can be a directory or a file.
Returns:
True if succeded otherwise false.
Throws:
java.io.IOException

generateGUID

public static java.lang.String generateGUID()

arrayEquals

public static boolean arrayEquals(java.lang.Object[] arr1,
                                  java.lang.Object[] arr2)
Tests whether two arrays are equal.


mapName

public static java.lang.String mapName(java.util.Locale locale,
                                       java.lang.String prefix,
                                       java.lang.String name)
Given a name, try to map it using the catalog.

Parameters:
name -
Returns: