de.innovationgate.utils
public abstract class WGUtils extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
WGUtils.RunnableWithExceptions
Interface for a runnable to use with
executeWithTimeout(RunnableWithExceptions, long) |
static class |
WGUtils.WGTimeoutException
Thrown when
executeWithTimeout(RunnableWithExceptions, long) runs on the timeout |
Modifier and Type | Field and Description |
---|---|
static java.text.DateFormat |
DATEFORMAT_FULL
A full german date/time format: dd.MM.yyyy HH:mm:ss SSS
|
static java.text.DateFormat |
DATEFORMAT_STANDARD
A normal german date format: dd.MM.yyyy
|
static java.text.DecimalFormat |
DECIMALFORMAT_STANDARD
A normal decimal format including a thousands separator character
|
static java.lang.String |
DIRLINK_FILE
Name of a directory link file, used by
createDirLink(File, String) and resolveDirLink(File) |
static java.util.regex.Pattern |
ILLEGAL_HTML_CHARS_PATTERN |
static int |
LINEFEEDS_CONVERT_TO_BR
For
encodeHTML(String, boolean, int) , to let linefeeds be converted to tags |
static int |
LINEFEEDS_KEEP
For
encodeHTML(String, boolean, int) , to let linefeeds be kept untouched |
static int |
LINEFEEDS_REMOVE
For
encodeHTML(String, boolean, int) , to let linefeeds be removed from the output |
static java.text.DateFormat |
TIMEFORMAT_STANDARD
A normal german time format: HH:mm:ss
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
base64toString(java.lang.String base64)
Converts a base64-encoded string into bytes, then constructs a string
from these bytes and returns it
|
static java.lang.String |
clearStrings(java.lang.String colString,
char stringDelimiter,
char replaceChar)
Clears out "internal strings" from a text that contains some kind of
program code.
|
static java.lang.Object |
containsAny(java.util.Collection col1,
java.util.Collection col2)
Tests if any value in one collection is part of another collection
|
static void |
copyDirContent(java.io.File source,
java.io.File targetDir)
Copies the contents of a directory into a target directory.
|
static void |
copyFile(java.io.File source,
java.io.File target)
Copies a file from source to target.
|
static void |
copyFile(java.lang.String source,
java.lang.String target)
Variant of
copyFile(File, File) that takes file paths as argument |
static java.lang.String |
countEnding(int no)
Returns english counting endings for numbers "st", "nd", "rd" and "th" like in "1st", "2nd", "3rd", "4th", "21st" etc.
|
static java.lang.String |
countFormat(int no)
Returns a formatted number inclusive counting ending (see
countEnding(int) . |
static java.lang.String |
countFormat(java.lang.String noStr)
Variant of
countFormat(int) that takes a string that will be parsed to an integer |
static int |
countOccurences(java.lang.String text,
java.lang.String subtext)
Counts the occurences of a special text phrase in another text
|
static void |
createDirLink(java.io.File parentDir,
java.lang.String target)
Creates a directory link file pointing to a target path
|
static java.lang.String |
createMD5HEX(byte[] input)
Converts a byte array to a MD5 hexadecimal string
|
static java.lang.String |
createMD5HEX(java.io.InputStream input)
Converts an inputstream to a MD5 hex string
the inputstream is implicit closed after reading
|
static java.util.Map |
createSynchronizedMap()
Deprecated.
As the minimum Java version for WGA is now at least 5
|
static TemporaryFile |
createTempFile(java.lang.String name)
Creates an empty temporary file with the given name
|
static TemporaryFile |
createTempFile(java.lang.String name,
java.io.InputStream data)
Creates a temporary file with the given name and fills it with the data from the given stream
|
static java.util.Date |
cutoffDateMillis(java.util.Date date)
Cutoff milliseconds from a date
|
static long |
cutoffTimeMillis(long time)
Cutoff milliseconds from a time value
|
static java.util.Date |
dateOnly(java.util.Date date)
Removes daytime information from a date, leaving date information only
|
static java.lang.String |
decodeURI(java.lang.CharSequence uriCharSequence,
java.lang.String charset)
Decodes an encoded URI sequence according to the given charset
This is able to decode URL-encoded characters but also leaves existing Non-ASCII characters intact (unlike Common HttpClients URIUtil)
|
static void |
delTree(java.io.File file)
Deletes the given file.
|
static void |
delTree(java.io.File file,
boolean deleteFileItself)
Deletes the given file or the contents of a folder.
|
static java.util.List<java.lang.String> |
deserializeCollection(java.lang.String colString,
java.lang.String divider)
Creates a List based on string, that contains substrings divided by a
special divider string.
|
static java.util.List<java.lang.String> |
deserializeCollection(java.lang.String colString,
java.lang.String divider,
boolean trimTokens)
Creates a List based on string, that contains substrings divided by a
special divider string.
|
static java.util.List<java.lang.String> |
deserializeCollection(java.lang.String colString,
java.lang.String divider,
boolean trimTokens,
java.lang.Character stringDelimiter)
Creates a List based on string, that contains substrings divided by a
special divider string.
|
static java.util.List<java.lang.String> |
deserializeCollection(java.lang.String colString,
java.lang.String divider,
boolean trimTokens,
java.lang.Character stringDelimiter,
boolean removeTokenStringDelimiter)
Creates a List based on string, that contains substring tokens divided by a
special divider string.
|
static java.lang.String |
encodeHTML(java.lang.String input)
Encodes an input string of plain text to it's HTML representation.
|
static java.lang.String |
encodeHTML(java.lang.String input,
boolean reduceToASCII)
Encodes an input string of plain text to it's HTML representation.
|
static java.lang.String |
encodeHTML(java.lang.String input,
boolean reduceToASCII,
boolean useHTMLTags)
Encodes an input string of plain text to it's HTML representation.
|
static java.lang.String |
encodeHTML(java.lang.String input,
boolean reduceToASCII,
int lineFeedTreatment)
Encodes an input string of plain text to it's HTML representation.
|
static java.lang.String |
encodeHTML(java.lang.String input,
boolean reduceToASCII,
int lineFeedTreatment,
java.util.Set<java.lang.Integer> additionalCharsToEncode) |
static java.lang.String |
encodeJS(java.lang.String str)
Encodes some string to be safely used inside a JavaScript literal
|
static java.lang.String |
encodeJSON(java.lang.String str)
Encodes some string to be safely used inside a JSON literal
JSON encoding has subtile differences from JavaScript (no encoding of single quotes).
|
static java.lang.String |
encodeXML(java.lang.String input)
Encodes an input string of plain text to it's XML representation.
|
static java.lang.String |
escapeASN1(java.lang.String str)
Escapes Strings to be used in ASN.1 attributes (like LDAP attributes)
|
static java.lang.String |
escapeJsString(java.lang.String value)
Deprecated.
Use
encodeJS(String) instead |
static java.lang.String |
escapeSQ(java.lang.String strName)
Removes single quotes from a string
|
static void |
executeWithTimeout(WGUtils.RunnableWithExceptions runnable,
long timeout)
executes the given runnable with timeout
|
static java.util.List |
extractEntryList(java.util.Enumeration en)
Version of
extractEntryList(Iterator) which takes an Enumeration instead |
static java.util.List |
extractEntryList(java.util.Iterator iterator)
Extracts a list of entries from any iterator.
|
static java.util.Map |
extractMapByPrefix(java.util.Map map,
java.lang.String prefix)
Searches a map for entries whose string keys start with the given prefix.
|
static java.util.List |
extractMessages(java.lang.Throwable th)
Extracts the messages of an Throwable and it's causes.
|
static java.lang.Object |
findObjectByHash(java.util.Collection col,
int hash)
Finds an object inside any collection based on its hashcode.
|
static boolean |
getBooleanMapValue(java.util.Map options,
java.lang.String name,
boolean defaultValue)
Retrieves a boolean value from a map value.
|
static <CauseType extends java.lang.Throwable> |
getCauseOfType(java.lang.Throwable e,
java.lang.Class<? extends CauseType> type)
Returns a cause of the given throwable (or the throwable itself) which is of the given type.
|
static java.lang.reflect.Field |
getClassField(java.lang.Class theClass,
java.lang.String name)
Returns the field reflection object of the field of the given name.
|
static long |
getMaxHeap()
Retrieves the value of java.lang.Runtime.maxMemory() which is only
available if using a JRE of version 1.4 or higher.
|
static org.dom4j.Attribute |
getOrCreateAttribute(org.dom4j.Element element,
java.lang.String name,
java.lang.String defaultValue)
Retrieves a DOM attribute with a given name.
|
static org.dom4j.Element |
getOrCreateElement(org.dom4j.Element parent,
java.lang.String name)
Retrieves an DOM Element with a given name.
|
static org.apache.commons.vfs2.FileObject |
getOrCreateFolder(org.apache.commons.vfs2.FileObject parent,
java.lang.String name)
Returns a VFS file object for a folder.
|
static java.io.File |
getOrCreateFolder(java.io.File parent,
java.lang.String name)
Returns a file for a folder.
|
static java.lang.String |
getPackagePath(java.lang.Class<? extends java.lang.Object> clazz)
Return the path of the given classes package, that must be used when loading resources from it
This returns the name of the package of the given class, converted to a resource path.
|
static java.lang.Throwable |
getRootCause(java.lang.Throwable e)
Returns the root cause throwable for the given throwable
|
static <T extends java.lang.Throwable> |
getRootCause(java.lang.Throwable e,
java.lang.Class<T> throwableClass)
Returns the root cause throwable for the given throwable of a given type
|
static <X> X |
getValueOrDefault(X value,
X defaultValue)
Very simple method returning a parameter value if it is non null, or else a default value
|
static java.lang.String |
hashPassword(java.lang.String pwd)
Hashes a given password using the SHA-1 algorithm.
|
static void |
inToOut(java.io.InputStream read,
java.io.OutputStream write,
int bufferSize)
Writes all data from an input stream to an output stream
|
static void |
inToOut(java.io.Reader read,
java.io.Writer write,
int bufferSize)
Writes all data from a reader to a writer
|
static void |
inToOutLimited(java.io.InputStream read,
java.io.OutputStream write,
int length,
int bufferSize)
Writes a chosen amount of data from an input stream to an output stream
|
static boolean |
isBooleanValue(java.lang.String expr)
checks if the given string can be interpreted as boolean
accepting "true", "t", "1", "yes" and "y", "false", "f", "0", "no", "n"
|
static boolean |
isCollection(java.lang.Object obj)
Determines if the given object is any kind of collection
|
static boolean |
isEmpty(java.lang.Object obj)
Tests the object for "emptiness" which is defined as one of the following conditions
The object is null
|
static boolean |
isEmptyNotesField(java.util.Collection col)
Tests a collection retrieved by lotus.domino.Document.getItemValue() if
it is an empty notes field.
|
static boolean |
isSerializable(java.lang.Object obj)
This method tests if an object is serializable via the standard Java serialisation mechanism by attempting a serialisation
|
static java.lang.String |
joinRemainingTokens(java.util.StringTokenizer tokenizer,
java.lang.String delim)
Joins the remaining tokens of a StringTokenizer, using the given divider
|
static void |
logCategoryInfo(org.apache.log4j.Logger log,
java.lang.String msg,
int level)
Tool function to log category headers to a logger
|
static void |
lowerCaseList(java.util.List list)
Lowercases the string elements of a list.
|
static java.lang.String |
normalizeUnicode(java.lang.String input)
performs a unicode normalization to NFC form (java.text.Normalizer.Form.NFC) for the given input
|
static boolean |
nullSafeEquals(java.lang.Object obj1,
java.lang.Object obj2)
Does a null safe compare on two objects.
|
static boolean |
nullSafeEquals(java.lang.Object obj1,
java.lang.Object obj2,
boolean ignoreCase)
Does a null safe compare on two objects.
|
static int |
parseInt(java.lang.String str)
Parses an integer from a string.
|
static java.util.Set |
putAllNonNullValues(java.util.Map source,
java.util.Map target)
Puts all entries from map source to map target whose values are non-null.
|
static java.lang.String |
readString(java.io.InputStream in,
java.lang.String encoding)
Readers data from an input stream into a string
|
static java.lang.String |
readString(java.io.Reader reader)
Reads data from a reader into a string
|
static java.lang.String |
reduce(java.lang.String str,
int length)
Reduces a string to a given maximum length.
|
static java.lang.String |
reduceUserAgentString(java.lang.String str,
int len)
Reduces a user agent string to a given size and keeping the basic syntax intact when possible
The method tries to reduce the content of the outer bracket content so the user agent is still parseable
|
static java.lang.String |
relativeFilePath(java.lang.String path,
java.lang.String parentPath)
A variant of
relativeFilePath(String, String, boolean) which always throws a IllegalArgumentException if the
parent path is not valid. |
static java.lang.String |
relativeFilePath(java.lang.String path,
java.lang.String parentPath,
boolean failIfNoParent)
Calculates a relative file path, relative to the given parent path.
|
static java.lang.String |
removeFileNameSuffix(java.lang.String name)
Removes the suffix part (i.e. the part after the last ".") from a file name
|
static void |
removeThreadLocalValue(java.lang.ThreadLocal tl)
Deprecated.
since Java 5 is minimum dependency of OpenWGA
|
static java.io.File |
resolveDirLink(java.io.File file)
Resolves an eventually present directory link file.
|
static org.apache.commons.vfs2.FileObject |
resolveDirLink(org.apache.commons.vfs2.FileObject file)
Resolves an eventually present directory link file (variant with Commons VFS file objects).
|
static java.util.Date |
roundMillisUp(java.util.Date lastModified)
Fills the millisecond part of a date value with 999 if it is 000.
|
static java.lang.String |
serializeCollection(java.util.Collection col,
java.lang.String divider)
Serializes a collection (containing strings) to a single String using the
given divider.
|
static java.lang.String |
serializeCollection(java.util.Collection col,
java.lang.String divider,
ObjectFormatter formatter)
Serializes a collection to a single String using the given divider.
|
static java.lang.String |
serializeCollection(java.util.Collection col,
java.lang.String divider,
ObjectFormatter formatter,
boolean includeNulls)
Serializes a collection to a single String using the given divider.
|
static void |
setAllEnabled(java.awt.Container con,
boolean enabled)
Sets a swing/awt container and all of its child components enabled or
disabled
|
static void |
setDefaultProperty(java.util.Map props,
java.lang.Object key,
java.lang.Object value)
Sets a property to a map only if the map does not yet contain the
property key.
|
static void |
setJListSelection(java.util.List selection,
javax.swing.JList list)
Sets the selected items on a
JList , which is a tedious task to do by hand. |
static java.util.List |
sortByProperty(java.util.Collection col,
java.lang.String property)
Sorts a collection by a property of the collection contents.
|
static void |
sortChildElements(org.dom4j.Element parent,
java.lang.String xpath)
Sorts the child elements of an element based on their indiviual XPath
result.
|
static java.lang.String |
stdDateFormat(java.util.Date date)
Formats a date by WGAs default date format dd.MM.yyyy
|
static java.lang.String |
stdFormat(java.lang.Number num)
Formats a number by WGAs default decimal format #,##0
|
static java.lang.String |
stdTimeFormat(java.util.Date date)
Formats a date by WGAs default time format HH:mm:SS
|
static boolean |
stringToBoolean(java.lang.String expr)
Converts a string to a boolean value, accepting "true", "t", "1", "yes"
and "y" as true, accepting "false", "f", "0", "no", "n" as false, and
throwing an IllegalArgumentException when none of these strings match.
|
static java.lang.String |
strReplace(java.lang.String text,
java.lang.String substring,
ReplaceProcessor proc,
boolean multiple)
Replaces occurences of a substring inside a string by another substring.
|
static java.lang.String |
strReplace(java.lang.String strText,
java.lang.String strFrom,
ReplaceProcessor proc,
boolean bMultiple,
boolean exactCase)
Replaces occurences of a substring inside a string by another substring.
|
static java.lang.String |
strReplace(java.lang.String strText,
java.lang.String strFrom,
java.lang.String strTo,
boolean bMultiple)
Replaces occurences of a substring inside a string by another substring.
|
static java.lang.String |
strReplace(java.lang.String strText,
java.lang.String strFrom,
java.lang.String strTo,
boolean bMultiple,
boolean exactCase)
Replaces occurences of a substring inside a string by another substring.
|
static java.lang.String |
strReplaceOld(java.lang.String strText,
java.lang.String strFrom,
java.lang.String strTo,
boolean bMultiple)
Deprecated.
|
static boolean |
testBits(int bitset1,
int bitset2)
Makes a bitsise compare of two bitsets, represented by ints.
|
static java.util.Date |
timeOnly(java.util.Date date)
Removes date information from a date, leaving daytime information only
|
static boolean |
toBoolean(java.lang.Object obj,
boolean def)
Converts arbitrary objects into their boolean counterpart
Boolean true are:
Boolean.TRUE
All strings that
stringToBoolean(String) thinks are true
The numbers 1 and -1
All other objects evaluate to the default given as argument. |
static java.lang.String |
toHexString(byte[] bytes)
Converts a byte array to a hexadecimal string
|
static java.lang.Integer |
toInteger(java.lang.Object obj,
int def)
Converts arbitrary objects into their integer counterpart
Interpretable as integer are all
Number instances and all strings that represent representations of numbers,
also all other objects whose Object.toString() returns somthing that may be interpreted as number. |
static java.util.List |
toLowerCase(java.util.List listOriginal)
Creates a new list that contains the same elements than the parameter
list, but with all string elements converted to lower case
|
static java.lang.String |
toPlainText(java.lang.String html,
java.lang.String divider,
boolean ignoreWhitespace)
Converts a HTML to plain text by removing all HTML tags.
|
static java.util.List |
toString(java.util.List listOriginal)
Creates a new list that contains the string representations
of all elements of the original list
|
static java.lang.String |
toValidXmlString(java.lang.String str)
Removes C0 control characters that are invalid in XML 1.0 and not even allowed as escaped entities from the string
This method removes all characters from U+0000 to U+001F except U+0009, U+000A, U+000D.
|
static java.lang.String |
unzipString(byte[] input)
Unzips a string from bytes previously produced by
zipString(String) |
static void |
updateList(java.util.List list,
java.util.Collection newCol)
Updates a list with the state represented by another list, with as less
changes as possible.
|
static java.lang.String |
which(java.lang.String className,
java.lang.Class refClass)
Determines the location of the classfile that defines the given class.
|
static java.lang.String |
which(java.lang.String className,
java.lang.ClassLoader cl)
Determines the location of the classfile that defines the given class.
|
static void |
zipDirectory(java.io.File zipDir,
java.util.zip.ZipOutputStream zos)
Zips the contents of a directory to a ZipOutputStream.
|
static byte[] |
zipString(java.lang.String input)
Zips a string input to compressed bytes
|
public static final java.lang.String DIRLINK_FILE
createDirLink(File, String)
and resolveDirLink(File)
public static final java.util.regex.Pattern ILLEGAL_HTML_CHARS_PATTERN
public static final java.text.DateFormat DATEFORMAT_FULL
public static final java.text.DateFormat DATEFORMAT_STANDARD
public static final java.text.DecimalFormat DECIMALFORMAT_STANDARD
public static final java.text.DateFormat TIMEFORMAT_STANDARD
public static final int LINEFEEDS_CONVERT_TO_BR
encodeHTML(String, boolean, int)
, to let linefeeds be converted to public static final int LINEFEEDS_KEEP
encodeHTML(String, boolean, int)
, to let linefeeds be kept untouchedpublic static final int LINEFEEDS_REMOVE
encodeHTML(String, boolean, int)
, to let linefeeds be removed from the outputpublic static void delTree(java.io.File file, boolean deleteFileItself)
file
- The file or folder to delete/cleardeleteFileItself
- Setting this to false will only delete the files in the given folder (if it is one), but not the folder itself. If it is no folder this is a noop.public static void delTree(java.io.File file)
file
- The file to delete.public static boolean isCollection(java.lang.Object obj)
obj
- The object to testpublic static java.lang.String serializeCollection(java.util.Collection col, java.lang.String divider, ObjectFormatter formatter, boolean includeNulls)
deserializeCollection
.
This version takes a special object formatter object, that formats the
collection elements before they are added to the result string. The
formatter can be used to convert non-string values in the collection to
strings by a special method.col
- The collectiondivider
- The dividerformatter
- The formatterincludeNulls
- Specify null to treat null values in the collection as emtpy strings, false to omit them in outputpublic static java.lang.String serializeCollection(java.util.Collection col, java.lang.String divider, ObjectFormatter formatter)
deserializeCollection
.
This version takes a special object formatter object, that formats the
collection elements before they are added to the result string. The
formatter can be used to convert non-string values in the collection to
strings by a special method.
This method version omits null values in the collection.col
- The collectiondivider
- The dividerformatter
- The formatterpublic static java.util.List<java.lang.String> deserializeCollection(java.lang.String colString, java.lang.String divider, boolean trimTokens, java.lang.Character stringDelimiter, boolean removeTokenStringDelimiter)
serializeCollection
.
This command: WGUtils.deserializeCollection("a;b;c", ";")
Would create a list containing the three strings "a", "b" and "c".colString
- The string that contains the list informationdivider
- divider string that separates the substrings.trimTokens
- Decides if the tokens are trimmed (via String.trim())
before they are put into the liststringDelimiter
- Describes a character that should be treated as string
delimiter, like " or '. Text contained in these signs will be
ignored when the split operation is done. Use null if you do
not want to ignore strings.removeTokenStringDelimiter
- If true and a string delimiter was given will remove delimiters that wrap whole tokens on output. So input string "'a','b'" will return strings "a" and "b" on deserialisation if the ' character was given as delimiter.public static java.util.List<java.lang.String> deserializeCollection(java.lang.String colString, java.lang.String divider, boolean trimTokens, java.lang.Character stringDelimiter)
serializeCollection
.
This command: WGUtils.deserializeCollection("a;b;c", ";")
Would create a list containing the three strings "a", "b" and "c".colString
- The string that contains the list informationdivider
- divider string that separates the substrings.trimTokens
- Decides if the substrings are trimmed (via String.trim())
before they are put into the liststringDelimiter
- Describes a character that should be treated as string
delimiter, like " or '. Text contained in these signs will be
ignored when the split operation is done. Use null if you do
not want to ignore strings.public static java.lang.String clearStrings(java.lang.String colString, char stringDelimiter, char replaceChar)
colString
- The textstringDelimiter
- The character that introduces and closes strings inside the
textreplaceChar
- The character that is used to clear out strings.public static java.util.List<java.lang.String> deserializeCollection(java.lang.String colString, java.lang.String divider, boolean trimTokens)
serializeCollection
.
This command: WGUtils.deserializeCollection("a;b;c", ";")
Would create a list containing the three strings "a", "b" and "c".colString
- The string that contains the list informationdivider
- divider string that separates the substrings.trimTokens
- Decides if the substrings are trimmed (via String.trim())
before they are put into the listpublic static java.util.List<java.lang.String> deserializeCollection(java.lang.String colString, java.lang.String divider)
serializeCollection
.
This command: WGUtils.deserializeCollection("a;b;c", ";")
Would create a list containing the three strings "a", "b" and "c".colString
- The string that contains the list informationdivider
- divider string that separates the substrings.public static java.lang.String serializeCollection(java.util.Collection col, java.lang.String divider)
deserializeCollection
.col
- The collectiondivider
- The dividerpublic static java.lang.String encodeXML(java.lang.String input)
input
- The plain text string to convertpublic static java.lang.String joinRemainingTokens(java.util.StringTokenizer tokenizer, java.lang.String delim)
tokenizer
- The StringTokenizerdelim
- The dividerpublic static java.lang.String strReplaceOld(java.lang.String strText, java.lang.String strFrom, java.lang.String strTo, boolean bMultiple)
strText
- strFrom
- strTo
- bMultiple
- public static java.lang.String strReplace(java.lang.String strText, java.lang.String strFrom, ReplaceProcessor proc, boolean bMultiple, boolean exactCase)
strText
- The text to search for occurences of the substringstrFrom
- The substring to search forproc
- The processor that will make the replacement and tell the
method where to continue searching.bMultiple
- Specify true if multiple occurences should be replaced.
Specify false if only the first occurence should be replaced.exactCase
- Determines if strings should be compared with exact case.
If false, string are matched case insensitivepublic static java.lang.String strReplace(java.lang.String text, java.lang.String substring, ReplaceProcessor proc, boolean multiple)
text
- The text to search for occurences of the substringsubstring
- The substring to search forproc
- The processor that will make the replacement and tell the
method where to continue searching.multiple
- Specify true if multiple occurences should be replaced.
Specify false if only the first occurence should be replaced.public static java.lang.String strReplace(java.lang.String strText, java.lang.String strFrom, java.lang.String strTo, boolean bMultiple, boolean exactCase)
strText
- The text to search for occurences of the substringstrFrom
- The substring to search forstrTo
- The substring used to replace the string in strFrombMultiple
- Specify true if multiple occurences should be replaced.
Specify false if only the first occurence should be replaced.exactCase
- Determines if strings should be compared with exact case.
If false, string are matched case insensitivepublic static java.lang.String strReplace(java.lang.String strText, java.lang.String strFrom, java.lang.String strTo, boolean bMultiple)
strText
- The text to search for occurences of the substringstrFrom
- The substring to search forstrTo
- The substring used to replace the string in strFrombMultiple
- Specify true if multiple occurences should be replaced.
Specify false if only the first occurence should be replaced.public static java.lang.String base64toString(java.lang.String base64)
base64
- base64-encoded information as stringpublic static java.lang.String which(java.lang.String className, java.lang.Class refClass)
className
- The class to find.refClass
- The class that itself will use this class in its code. It's
classloader will be used to find the locationpublic static java.lang.String which(java.lang.String className, java.lang.ClassLoader cl)
className
- The class to find.cl
- The classloader to use to load the classpublic static int countOccurences(java.lang.String text, java.lang.String subtext)
text
- The text, in which will be searchedsubtext
- The text phrase, that is searched in the text of the first
parameterpublic static boolean isEmptyNotesField(java.util.Collection col)
col
- The collectionpublic static boolean isEmpty(java.lang.Object obj)
obj
- public static java.lang.String encodeHTML(java.lang.String input, boolean reduceToASCII, boolean useHTMLTags)
input
- The plain text string to convertreduceToASCII
- true if you want all non-ASCII characters to be converted to entitiesuseHTMLTags
- true if you want line feeds to be converted to public static java.lang.String encodeHTML(java.lang.String input, boolean reduceToASCII, int lineFeedTreatment)
input
- The plain text string to convertreduceToASCII
- true if you want all non-ASCII characters to be converted to entitieslineFeedTreatment
- Way how line feeds are treated in the source. Use constants LINEFEEDS_... if you want them to be converted, ignored or removedpublic static java.lang.String encodeHTML(java.lang.String input, boolean reduceToASCII, int lineFeedTreatment, java.util.Set<java.lang.Integer> additionalCharsToEncode)
public static java.lang.String encodeHTML(java.lang.String input, boolean reduceToASCII)
input
- The plain text string to convertreduceToASCII
- true if you want all non-ASCII characters to be converted to entitiespublic static java.lang.String encodeHTML(java.lang.String input)
input
- The plain text string to convertpublic static java.lang.Object containsAny(java.util.Collection col1, java.util.Collection col2)
col1
- First collectioncol2
- Second collectionpublic static java.util.List sortByProperty(java.util.Collection col, java.lang.String property)
col
- The collection to sortproperty
- The property to use for sorting, specified as JXPath.public static void setDefaultProperty(java.util.Map props, java.lang.Object key, java.lang.Object value)
props
- The mapkey
- The property keyvalue
- The value of the propertypublic static java.lang.String hashPassword(java.lang.String pwd)
pwd
- The passwordjava.security.NoSuchAlgorithmException
public static java.lang.String createMD5HEX(byte[] input) throws java.security.NoSuchAlgorithmException
input
- The byte inputjava.security.NoSuchAlgorithmException
public static java.lang.String createMD5HEX(java.io.InputStream input) throws java.security.NoSuchAlgorithmException, java.io.IOException
input
- java.security.NoSuchAlgorithmException
java.io.IOException
public static java.lang.String toHexString(byte[] bytes)
bytes
- The byte arraypublic static long getMaxHeap()
public static java.lang.String toPlainText(java.lang.String html, java.lang.String divider, boolean ignoreWhitespace) throws java.io.IOException
html
- The htmldivider
- The divider by which separate text fragments that were parsed
from the HTML should be divided.ignoreWhitespace
- Specify true if pure whitespace text fragments should be
ignoredjava.io.IOException
public static void copyFile(java.io.File source, java.io.File target) throws java.io.IOException
source is regular file. Target is regular file or nonexistent:
Source file is copied to target file. Target is overwritten if it already exists.
source is regular file. Target is directory:
Source file is copied into target directory. Gets the same name as the source file.
source is directory.. Target is directory or nonexistent:
Complete source directory is copied into the target directory. The copied directory becomes a sub directory of the target which is created if it does not yet exist.
source
- Source file or directorytarget
- Target file or directoryjava.io.IOException
public static void copyDirContent(java.io.File source, java.io.File targetDir) throws java.io.IOException
source
- The source directorytargetDir
- The target directoryjava.io.IOException
public static void copyFile(java.lang.String source, java.lang.String target) throws java.io.IOException
copyFile(File, File)
that takes file paths as argumentsource
- File path of source filetarget
- File path of target filejava.io.IOException
public static java.lang.String countEnding(int no)
no
- The number to determine ending forpublic static java.lang.String countFormat(int no)
countEnding(int)
.no
- The number to formatpublic static java.lang.String countFormat(java.lang.String noStr)
countFormat(int)
that takes a string that will be parsed to an integernoStr
- A string that is parsable as integerpublic static void inToOut(java.io.Reader read, java.io.Writer write, int bufferSize) throws java.io.IOException
read
- The readerwrite
- The writerbufferSize
- The size of the buffer to use for data transferjava.io.IOException
public static void inToOut(java.io.InputStream read, java.io.OutputStream write, int bufferSize) throws java.io.IOException
read
- The input streamwrite
- The output streambufferSize
- The size of the buffer to use for data transferjava.io.IOException
public static void inToOutLimited(java.io.InputStream read, java.io.OutputStream write, int length, int bufferSize) throws java.io.IOException
read
- The input streamwrite
- The output streamlength
- number of bytes to writebufferSize
- The size of the buffer to use for data transferjava.io.IOException
public static java.util.Map extractMapByPrefix(java.util.Map map, java.lang.String prefix)
map
- The map to searchprefix
- The prefix. Entries with a string key that starts with this
prefix will get extracted.public static java.io.File getOrCreateFolder(java.io.File parent, java.lang.String name) throws java.io.IOException
parent
- The parent folder of the retrieved foldername
- The name of the folder to retrievejava.io.IOException
public static org.apache.commons.vfs2.FileObject getOrCreateFolder(org.apache.commons.vfs2.FileObject parent, java.lang.String name) throws java.io.IOException
parent
- The parent folder of the retrieved foldername
- The name of the folder to retrievejava.io.IOException
public static long cutoffTimeMillis(long time)
time
- The time valuepublic static java.util.Date cutoffDateMillis(java.util.Date date)
date
- The datepublic static void setAllEnabled(java.awt.Container con, boolean enabled)
con
- The containerenabled
- The state to set. true for enabled. false for disabledpublic static void updateList(java.util.List list, java.util.Collection newCol)
list
- newCol
- public static java.util.List toLowerCase(java.util.List listOriginal)
listOriginal
- public static java.util.List toString(java.util.List listOriginal)
listOriginal
- public static boolean testBits(int bitset1, int bitset2)
bitset1
- The bitset 1bitset2
- The int whose bits should be testedpublic static java.lang.String reduce(java.lang.String str, int length)
str
- The string to reducelength
- The maximum length of the stringpublic static boolean stringToBoolean(java.lang.String expr)
expr
- The boolean stringpublic static boolean isBooleanValue(java.lang.String expr)
expr
- public static boolean getBooleanMapValue(java.util.Map options, java.lang.String name, boolean defaultValue)
options
- The options map.name
- The name of the optiondefaultValue
- The default value to use if the option is not set or it's
boolean value is not determinablepublic static <X> X getValueOrDefault(X value, X defaultValue)
value
- The value, returned when != nulldefaultValue
- The default value, returned when value == nullpublic static java.lang.String escapeSQ(java.lang.String strName)
strName
- The stringpublic static java.lang.String escapeASN1(java.lang.String str)
str
- The string to escapepublic static java.lang.String escapeJsString(java.lang.String value)
encodeJS(String)
insteadvalue
- The string literalpublic static java.lang.String removeFileNameSuffix(java.lang.String name)
name
- The file namepublic static java.lang.String readString(java.io.Reader reader) throws java.io.IOException
reader
- The readerjava.io.IOException
public static java.lang.String readString(java.io.InputStream in, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
in
- The input streamencoding
- The text encoding of the streamjava.io.IOException
java.io.UnsupportedEncodingException
public static void sortChildElements(org.dom4j.Element parent, java.lang.String xpath)
parent
- The parent elementxpath
- The xpath that is evaluated on each child elementpublic static void zipDirectory(java.io.File zipDir, java.util.zip.ZipOutputStream zos) throws java.io.IOException
DirZipper
class with default settings. Use the class directly for more control.zipDir
- The directory to zip upzos
- The ZipOutputStream where the data is written tojava.io.IOException
public static java.lang.String relativeFilePath(java.lang.String path, java.lang.String parentPath, boolean failIfNoParent)
relativeFilePath("D:\Daten\WGAConfig\WGA32Test\designsync\mysql", "D:\Daten\WGAConfig\WGA32Test")
returns "designsync\mysql"
This works only when
If these conditions are not met, the method either throws an IllegalArgumentException (if param failIfNoParent==true) or just returns the path again completely (if param failIfNoParent==false)
path
- The path from which a relative path should be extractedparentPath
- A parent path of path, to which the calculated relative path should be relative tofailIfNoParent
- Controls the failure behaviour. See method description.public static java.lang.String relativeFilePath(java.lang.String path, java.lang.String parentPath)
relativeFilePath(String, String, boolean)
which always throws a IllegalArgumentException if the
parent path is not valid.path
- parentPath
- public static java.lang.Object findObjectByHash(java.util.Collection col, int hash)
col
- The collection to searchhash
- HashCode of the searched objectpublic static org.dom4j.Element getOrCreateElement(org.dom4j.Element parent, java.lang.String name)
parent
- The parent element of the element to retrievename
- The name of the elementpublic static org.dom4j.Attribute getOrCreateAttribute(org.dom4j.Element element, java.lang.String name, java.lang.String defaultValue)
element
- The element containing the attributename
- The name of the attributedefaultValue
- The default value of the attribute, used when it must be createdpublic static void setJListSelection(java.util.List selection, javax.swing.JList list)
JList
, which is a tedious task to do by hand.selection
- The items that should be selected in the listlist
- The list itselfpublic static java.util.List extractMessages(java.lang.Throwable th)
th
- The throwablepublic static java.util.Date roundMillisUp(java.util.Date lastModified)
lastModified
- public static boolean nullSafeEquals(java.lang.Object obj1, java.lang.Object obj2, boolean ignoreCase)
obj1
- Compared object 1obj2
- Compared object 2ignoreCase
- If true and both objects are strings, will use equalsIgnoreCase()public static boolean nullSafeEquals(java.lang.Object obj1, java.lang.Object obj2)
nullSafeEquals(Object, Object, boolean)
which will not use case-insensitive compare.obj1
- Compared object 1obj2
- Compared object 2public static java.lang.Throwable getRootCause(java.lang.Throwable e)
e
- The throwablepublic static <T extends java.lang.Throwable> T getRootCause(java.lang.Throwable e, java.lang.Class<T> throwableClass)
e
- The throwablethrowableClass
- The class that is searched as causepublic static <CauseType extends java.lang.Throwable> CauseType getCauseOfType(java.lang.Throwable e, java.lang.Class<? extends CauseType> type)
e
- The exceptiontype
- The type of exception searchedpublic static java.util.Map createSynchronizedMap()
public static void removeThreadLocalValue(java.lang.ThreadLocal tl)
tl
- The ThreadLocal whose value to clearpublic static java.util.Date dateOnly(java.util.Date date)
date
- The date to strip daytime information frompublic static java.util.Date timeOnly(java.util.Date date)
date
- The date to strip date information frompublic static java.lang.String stdDateFormat(java.util.Date date)
public static java.lang.String stdTimeFormat(java.util.Date date)
public static java.lang.String stdFormat(java.lang.Number num)
public static java.util.Set putAllNonNullValues(java.util.Map source, java.util.Map target)
source
- Map providing the entriestarget
- Map getting all entriespublic static java.util.List extractEntryList(java.util.Iterator iterator)
iterator
- The iterator whose elements are put to the listpublic static java.util.List extractEntryList(java.util.Enumeration en)
extractEntryList(Iterator)
which takes an Enumeration insteadpublic static int parseInt(java.lang.String str)
str
- A string representing a number.public static void createDirLink(java.io.File parentDir, java.lang.String target) throws java.io.IOException
parentDir
- The directory to contain the link filetarget
- The target path that the directory link should point tojava.io.IOException
public static java.io.File resolveDirLink(java.io.File file)
file
- The directory that might contain a directory link file.public static org.apache.commons.vfs2.FileObject resolveDirLink(org.apache.commons.vfs2.FileObject file) throws org.apache.commons.vfs2.FileSystemException
file
- The directory that might contain a directory link file.org.apache.commons.vfs2.FileSystemException
public static java.lang.String getPackagePath(java.lang.Class<? extends java.lang.Object> clazz)
clazz
- The class whose package is usedpublic static void lowerCaseList(java.util.List list)
public static java.lang.String reduceUserAgentString(java.lang.String str, int len)
str
- User agent stringlen
- Maximum length allowedpublic static void executeWithTimeout(WGUtils.RunnableWithExceptions runnable, long timeout) throws java.lang.Throwable
runnable
- The runnable to executetimeout
- The timeout in ms.WGUtils.WGTimeoutException
- when timeout occurs.java.lang.InterruptedException
- when the runnable before timeout occurs.java.lang.Throwable
- on errors of runnable execution.public static void logCategoryInfo(org.apache.log4j.Logger log, java.lang.String msg, int level)
log
- The loggermsg
- The title of the category headerlevel
- The level of category info, resulting in different category characters. Use 1 or 2.public static java.lang.reflect.Field getClassField(java.lang.Class theClass, java.lang.String name)
theClass
- The class searched for the fieldname
- The field namepublic static java.lang.String encodeJS(java.lang.String str)
str
- The string to encodepublic static java.lang.String encodeJSON(java.lang.String str)
str
- The string to encodepublic static TemporaryFile createTempFile(java.lang.String name, java.io.InputStream data) throws java.io.IOException
name
- The file namedata
- The data for the filejava.io.IOException
public static TemporaryFile createTempFile(java.lang.String name) throws java.io.IOException
name
- The file namejava.io.IOException
public static java.lang.String normalizeUnicode(java.lang.String input)
input
- The input stringpublic static boolean toBoolean(java.lang.Object obj, boolean def)
stringToBoolean(String)
thinks are true
obj
- Input objectdef
- Default for returning on unconvertible objects (and null objects)public static java.lang.Integer toInteger(java.lang.Object obj, int def)
Number
instances and all strings that represent representations of numbers,
also all other objects whose Object.toString()
returns somthing that may be interpreted as number.
Non-interpretable objects and null return the default given as argumentobj
- Input objectdef
- Default for returning on unconvertible objects (and null objects)public static boolean isSerializable(java.lang.Object obj)
obj
- Object to testpublic static java.lang.String decodeURI(java.lang.CharSequence uriCharSequence, java.lang.String charset) throws java.io.UnsupportedEncodingException, java.net.MalformedURLException
uriCharSequence
- The URI sequencecharset
- The charset used to decodejava.io.UnsupportedEncodingException
java.net.MalformedURLException
public static byte[] zipString(java.lang.String input)
input
- The stringpublic static java.lang.String unzipString(byte[] input)
zipString(String)
input
- The bytespublic static java.lang.String toValidXmlString(java.lang.String str)
str
- Input string