com.jalios.util
Class Util

java.lang.Object
  extended by com.jalios.util.Util

public class Util
extends Object

This class provides a set of static methods which perform various utility operations.

Version:
$Revision: 30458 $
Author:
Olivier Dedieu , Jean-Philippe Encausse , Olivier Jaquemet

Field Summary
static HashMap basicEntitiesDecodingMap
           
static HashMap basicEntitiesEncodingMap
           
static HashMap<String,String> cookieTransTable
           
static TreeSet EMPTY_TREESET
          The empty TreeSet (immutable).
Use emptyTreeSet() for generics compliance.
static char ESCAPE_CHAR
           
protected static org.apache.oro.text.regex.Perl5Compiler hexaPercentCompiler
           
protected static org.apache.oro.text.regex.Pattern hexaPercentPattern
           
protected static org.apache.oro.text.regex.Perl5Substitution hexaPercentSubst
           
static HashMap<String,String> isoLatin1_xml
           
static HashMap<String,String> regexpEscaped1
           
static HashMap<String,String> regexpEscaped2
           
static HashMap<String,String> regexpEscaped3
           
static String REVISION
           
 
Method Summary
static
<T> Collection<T>
addAll(Collection<T> collection, Enumeration<T> enu)
          Add all element of the enumerate to the collection return the collection modified.
static
<T> Collection<T>
addAll(Collection<T> collection, Iterator<T> it)
          Add all element of the iterator to the collection return the collection modified.
static
<T> Collection<T>
addAll(T[] array, Collection<T> coll)
          Copy all non-null objects from the given array to given collection.
static
<K,V> void
addInMapHashSet(Map<K,Set<V>> map, K key, V value)
          A convenient method that add the given value to a set bound to the given key in the given map.
static
<K,V> void
addInMapLinkedHashSet(Map<K,LinkedHashSet<V>> map, K key, V value)
          A convenient method that add the given value to a set bound to the given key in the given map.
static boolean arrayContains(Object[] array, Object key)
          Test if an array contains a given object.
static String asciiIndent(String text, int cols, int rows, String tailString)
          Indent a given text according a number of column and row.
static String buildCamelID(String str)
          Build a Camel Case ID from the given String: remove the blanks, unaccentuates, removes non-alphanum chars.
static String buildID(String str)
          Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes non-alphanum chars and lowercases.
static String buildID(String str, String charRange)
          Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes chars out of the given range and lowercases.
static String buildUID(String str, Set<String> strSet)
          Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes non-alphanum chars and lowercases.
static
<T> Collection<T>
cleanCollection(Collection<T> coll)
          Remove the null entries of the given collection.
static Object[] cleanObjectArray(Object[] array)
          Creates a new array that contains all elements of the given array without null.
static String[] cleanStringArray(String[] array)
          Creates a new array that contains all elements of the given array except empty Strings (ie null or empty).
static
<T> Set<T>
collectionToCleanSet(Collection<T> coll)
          Returns a set which contains all the non empty element of the given collection.
static
<K,V> Map.Entry<K,V>
compareMap(Map<K,V> map1, Map<K,V> map2)
          Returns the first common Map.Entry of the given maps.
static String conceal(String clearStr)
          Conceal the given string with an internally choosen encryption algorithm.

WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
static String cryptMD5(String str)
          Encrypt the given string with the MD5 algorithm and BASE64
static String cryptUnix(String str)
          Encrypt the given string with the Unix crypt algorithm
static String decodeBASE64(String str)
          Decode the given string using BASE64 algorithm
static String decodeCookie(String src)
           
static String decodeHtmlBasicEntities(String src)
          Does the opposite job of encodeHtmlBasicEntities.
static int[] decodeIntArray(String param)
           
static int[] decodeIntArray(String param, char separator)
           
static Object decodeObject(String encoded)
          Returns the object decoded from the given String.
static String[] decodeStringArray(String param)
           
static String[] decodeStringArray(String param, char separator)
           
static String decodeUrl(String str)
           
static String decryptDES3(String encryptedStr)
          Decrypt the specified string using DESede StringEncrypter using same internal key used by encryptDES3(String).
static
<T> TreeSet<T>
emptyTreeSet()
          Returns the empty TreeSet (immutable).
static String encodeBASE64(String str)
          Encode the given string using BASE64 algorithm.
static String encodeBASE64(String str, boolean isChunck)
          Encode the given string using BASE64 algorithm.
static String encodeCookie(String src)
           
static String encodeHtmlBasicEntities(String src)
          Encode given string according to the following table.
static String encodeIntArray(int[] array)
           
static String encodeIntArray(int[] array, char separator)
           
static String encodeJavaScriptQuote(String str)
          Encode JavaScript quotes for JavaScript that using Labels with beautification ' -> ’ " -> ’’
static String encodeObject(Object obj)
          Returns the encoded objected as a String.
static String encodeStringArray(String[] array)
           
static String encodeStringArray(String[] array, char separator)
           
static String encodeUrl(String s)
          Same implementation as URLEncoder.encode(String, String), but space is encoded with %20 and '/' is not encoded.
static String encodeUrl(String s, String enc)
          Same implementation as URLEncoder.encode(String, String), but space is encoded with %20 and '/' is not encoded.
static String encryptDES3(String clearStr)
          Encrypt the specified string using DESede StringEncrypter with an internal key.

WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
static String entitiesToIsoLatin1(String src)
          Does the opposite of isoLatin1ToEntities.
static String escapeBackslash(String str)
          Escape all the '\' in the given String ('\\')
static String escapeChars(String str, String charsToEscape)
          Escape specified characters in a String.
static String escapeHtml(String str)
          Escapes some special HTML characters such as <, >, & and ".
static String escapeHtmlQuote(String str)
          Escape simple and double quote as HTML entity.
static String escapeInputQuote(String str)
          Escapes the quote (") character from the specified string.
If str is null return an empty string.
static String escapeJavaScriptQuote(String str)
          Escape JavaScript quotes ' -> \' " -> \"
static String escapeJavaStringChar(String str)
          Escape all the invalide char in Java String: '\' -> "\\" CR -> "\n" '"' -> \"
static String escapeLuceneQuery(String str)
          Escape Lucene special chars.
static String escapePercent(String url)
          This method replace % in wrong hexa character by '_' character
static String escapeRegexp(String string)
          Escape a (OROMatcher) regular expression with support of basic regexp (* and ?).
static String escapeRegexp(String string, boolean basicRegexp)
          Escape a (OROMatcher) regular expression with support of basic regexp (* and ?).
static int exec(String... cmdarray)
          Executes the specified command and arguments in a separate process.
static int exec(String[] cmdarray, OutputStream stdout, OutputStream stderr)
          Executes the specified command and arguments in a separate process.
static int exec(String[] cmdarray, StringBuilder stdout, StringBuilder stderr)
          Executes the specified command and arguments in a separate process.
static boolean forceFullGarbageCollection(long timeout)
          Force the garbage collection
static String formatDuration(Date begin, Date end)
          Deprecated. Use DateUtil.formatDuration(Date,Date) instead
static String formatDuration(Date begin, Date end, Locale locale)
          Deprecated. Use DateUtil.formatDuration(Date,Date,Locale) instead
static String formatDuration(long time)
          Deprecated. Use DateUtil.formatDuration(long) instead
static String formatDuration(long time, Locale locale)
          Deprecated. Use DateUtil.formatDuration(long,Locale) instead
static String formatFileSize(long size)
          This method format the given size on the greatest unit.
static String formatFileSize(long size, Locale locale)
          This method format the given size on the greatest unit.
static String formatFileSize(long size, Locale locale, boolean htmlDisplay)
          This method format the given size on the greatest unit.
static String formatIso8601Date(Date date)
          Deprecated. Use DateUtil.formatIso8601Date(Date) instead
static String formatNoSpaceDate(Date date)
          Deprecated. Use DateUtil.formatNoSpaceDate(Date) instead
static String formatRfc822Date(Date date)
          Deprecated. Use DateUtil.formatRfc822Date(Date) instead
static String formatSize(long size, Locale locale)
          This method format the given size on the greatest unit.
static String formatW3cDate(Date date)
          Deprecated. Use DateUtil.formatW3cDate(Date) instead
static String generatePassword()
           
static String generatePassword(int length)
           
static String generatePronounceablePassword(int pwdLength)
          Generates pronounceable passwords of specified length.
static Set getAllChildren(TreeNode node, Set nodeSet)
          Fill the given set with every children of the given treenode, including the node itself, returns the filled set.
static TreeSet getAllChildrenSet(TreeNode node)
          Returns a TreeSet with all children of the given treenode, (including the node itself)
static
<T> ArrayList<T>
getArrayList(T... array)
          Returns a new ArrayList filled with the given objects (skip null object).
static boolean getBoolean(boolean[] array, int index, boolean defaultValue)
           
static Object getChildListMap(Map map, String key)
          Returns the first Value matching the given key
static List getChildrenListMap(Map map, String key)
          Returns values matching the given key.
static List getChildrenListMap(Map map, String[] keys)
          Returns a new List of values matching the ordered given keys.
static Set<String> getClassFiles(String realPath, String fullname, boolean java)
          Returns a Set of relative path to all class files including inner class and java.
static String getClassNameFromFilename(String filename)
          Returns the class name from the filename of a class (e.g.
static String getClassShortName(Class clazz)
          Returns the short name of the given class (e.g.
static String getClassShortName(Object object)
          Returns the short name of the given object's class (e.g.
static String getClassShortName(String fullname)
          Returns the short name of the given class name (e.g.
static String getCurrentStackTrace()
          Returns the current StackTrace in a String.
static
<T> T
getFirst(Collection<T> coll)
          Returns the first itemp of the given collection (or null if the collection is empty).
static
<T> T
getFirst(T[] array)
          Returns the first itemp of the given array (or null if the array is empty).
static Class getFirstCommonClass(Class parent, Class child)
          Follow class tree of parent to find a class or an interface that is also parent of the child.
static String getFirstSentences(String text, int limit)
          Get the first sentences in a given string.
static
<K,V> HashMap<K,V>
getHashMap(K key, V value)
          Returns a new HashMap filled with the given key/value pair (if the key is not null).
static
<K,V> HashMap<K,V>
getHashMap(Map<K,V> map)
          Returns a new HashMap filled with the given map (if it is not null)
static
<T> HashSet<T>
getHashSet(T... array)
          Returns a new HashSet filled with the given objects (skip null object).
static String getHtmlIcon(String src, String alt)
          Build an icon
static int getInt(int[] array, int index, int defaultValue)
           
static
<K,V> Object
getKey(Map<K,V> map, V value)
          Iterate over a Map, looking for a Key associated to a given value.
static
<K,V> Set<K>
getKeys(Map<K,V> map, V value)
          Iterate over a Map, looking for a Keys associated to a given value.
static
<K,V> LinkedHashMap<K,V>
getLinkedHashMap(K key, V value)
          Returns a new LinkedHashMap filled with the given key/value pair (if the key is not null).
static
<K,V> LinkedHashMap<K,V>
getLinkedHashMap(Map<K,V> map)
          Returns a new LinkedHashMap filled with the given map (if it is not null)
static String getMatch(Pattern pattern, String str, int group)
          Return the group matching the given regexp for the given String or null if do not match or exception happens
static String getMatch(String regexp, String str, int group)
          Return the group matching the given regexp for the given String or null if do not match or exception happens
static Date getNewDateWithoutMillis()
          Deprecated. Use DateUtil.getNewDateWithoutMillis() instead
static Object getObject(Object[] array, int index, Object defaultValue)
           
static int getSize(boolean[] array)
          Returns the size of the given array.
static int getSize(byte[] array)
          Returns the size of the given array.
static int getSize(char[] array)
          Returns the size of the given array.
static int getSize(Collection coll)
          Returns the size of the given collection.
static int getSize(double[] array)
          Returns the size of the given array.
static int getSize(float[] array)
          Returns the size of the given array.
static int getSize(int[] array)
          Returns the size of the given array.
static int getSize(long[] array)
          Returns the size of the given array.
static int getSize(Map map)
          Returns the size of the given map.
static int getSize(Object[] array)
          Returns the size of the given array.
static int getSize(short[] array)
          Returns the size of the given array.
static int getSize(String str)
          Returns the size of the given String.
static String getStackTrace(Throwable throwable)
          This method print the stack trace into a String and return it.
static String getString(Object[] array, int index, String defaultValue)
          Call the method getString() with the Object in the array specified at the given index.
static String getString(Object obj, String defaultValue)
          Return the String representation of the given object if it is not null nor empty, otherwise it returns the default value.
static List getSuperclassList(Class clazz, Class ancestor, boolean addClass, boolean addAncestor)
          Returns a list of classes the given class is an ancestor of.
static TreeSet getTreeDescendantSet(TreeNode node)
          Returns a TreeSet with all descendant of the given treenode, (excluding the node itself)
static Set getTreeDescendantSet(TreeNode node, Set nodeSet)
           
static
<K,V> TreeMap<K,V>
getTreeMap(K key, V value)
          Returns a new TreeMap filled with the given key/value pair (if the key is not null).
static
<K,V> TreeMap<K,V>
getTreeMap(Map<K,V> map)
          Returns a new TreeMap filled with the given map (if it is not null)
static
<T> TreeSet<T>
getTreeSet(T... array)
          Returns a new TreeSet filled with the given objects (skip null object).
static boolean hasAppenderDefined(org.apache.log4j.Logger logger)
          Checks if the given Logger has any appender defined.
static String html2Ascii(String text)
          Convert a given text from HTML to ASCII.
static int indexOf(Object elem, Object[] array)
          Searches for the first occurence of the given argument in a given array, testing for equality using the equals method.
static boolean[] insertArray(boolean[] array, int index, boolean elt)
          Insert an element into a boolean array and return a duplicate copy of it.
static int[] insertArray(int[] array, int index, int elt)
          Insert an element into an int array and return a duplicate copy of it.
static Object[] insertArray(Object[] array, int index, Object elt)
          Insert an element into an Object array and return a duplicate copy of it.
static
<K,V> Map<? extends K,? extends V>
interMap(Map<? extends K,? extends V> map, Set<? extends K> keys)
          This method will return a new Map containing only values of specified map with given keys.
static Set interSet(Set... sets)
          Returns the intersection of an array of Set.
static Set interSet(Set set1, Set set2)
          Returns the intersection of two Set.
static Set interSet(Set set1, Set set2, Set set3)
          Returns the intersection of three Set.
static boolean isChildNode(TreeNode node, TreeNode child)
          Test if a node is a child of an other node
Return false if child == node
static boolean isEmpty(boolean[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(byte[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(char[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(Collection<?> c)
          Returns true if this collection is null or empty.
static boolean isEmpty(Collection<?> c, boolean deep)
          Returns true if this collection is null or empty.
static boolean isEmpty(double[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(File file)
          Returns true if this file is null or empty.
static boolean isEmpty(File file, FileFilter fileFilter)
          Returns true if this file is null or empty.
static boolean isEmpty(float[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(int[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(long[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(Map<?,?> map)
          Returns true if this map is null or empty.
static boolean isEmpty(Object object)
          Returns true if this object is null or empty.
static boolean isEmpty(Object[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(Object[] array, boolean recursive)
          Returns true if this array is null or empty.
static boolean isEmpty(short[] array)
          Returns true if this array is null or empty.
static boolean isEmpty(SQLQueryResult sqr)
          Returns true if this SQLQueryResult is null or empty.
static boolean isEmpty(String s)
          Returns true if this string is null or empty (once trimmed).
static
<K,V> boolean
isMapFilled(Map<K,V> map)
          Returns true if the given map contains at least one value not empty.
static boolean isNumber(String str)
          Returns true if the given string only contains 0-9 characters
static String isoLatin1ToEntities(String src)
          Convert all the isoLatin1 accent into XML entities (e.g.
static boolean isSameContent(boolean[] array1, boolean[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(byte[] array1, byte[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(char[] array1, char[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(Date date1, Date date2)
          Returns true if date1 has same content than date2.
static boolean isSameContent(double[] array1, double[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(org.jdom.Element elt1, org.jdom.Element elt2)
          Returns true if elt1 has same content than elt2.
static boolean isSameContent(float[] array1, float[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(int[] array1, int[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(List list1, List list2)
          Returns true if list1 has same content than list2.
static boolean isSameContent(long[] array1, long[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(Map map1, Map map2)
          Returns true if map1 has same content than map2.
static boolean isSameContent(Object[] array1, Object[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(Set set1, Set set2)
          Returns true if set1 has same content than set2.
static boolean isSameContent(short[] array1, short[] array2)
          Returns true if array1 has same content than array2.
static boolean isSameContent(String str1, String str2)
          Returns true if str1 has same content than str2.
static boolean isSameDay(Date date1, Date date2)
          Deprecated. Use DateUtil.isSameDay(Date,Date) instead
static boolean isToday(Date date)
          Deprecated. Use DateUtil.isToday(Date) instead
static boolean isTomorrow(Date date)
          Deprecated. Use DateUtil.isTomorrow(Date) instead
static boolean isYesterday(Date date)
          Deprecated. Use DateUtil.isYesterday(Date) instead
static String join(boolean[] array, String sep)
          Joins an array of boolean with the given separator.
static String join(boolean[] array, String sep, int max, String suffix)
          Joins an array of boolean with the given separator.
static String join(Collection<?> col, String sep)
          Joins a collection of Object with the given separator into a String.
static String join(Collection<?> col, String sep, int max, String suffix)
          Joins a collection of Object with the given separator into a String.
static String join(double[] array, String sep)
          Joins an array of double with the given separator.
static String join(double[] array, String sep, int max, String suffix)
          Joins an array of double with the given separator.
static String join(int[] array, String sep)
          Joins an array of int with the given separator.
static String join(int[] array, String sep, int max, String suffix)
          Joins an array of int with the given separator.
static String join(Iterator<?> it, String sep)
          Joins a collection of Object with the given separator into a String.
static String join(Iterator<?> it, String sep, int max, String suffix)
          Joins a collection of Object with the given separator into a String.
static String join(long[] array, String sep)
          Joins an array of long with the given separator.
static String join(long[] array, String sep, int max, String suffix)
          Joins an array of long with the given separator.
static String join(Object[] array, String sep)
          Joins an array of String with the given separator.
static String join(Object[] array, String sep, int max, String suffix)
          Joins an array of String with the given separator.
static String join(String... str)
          Join String with a given separator First String is the separator Always return a String If Str1 or Str2 is null then return the other value without separator
static String joinMap(Map<? extends Object,? extends Object> map, String keyValueSep, String entrySep)
          Joins the entries of a map into a String.
static void listDictionary(Dictionary<?,?> dict)
          Lists a Dictionnary on System.out.
static void listDictionary(Dictionary<?,?> dict, PrintStream out)
          Lists a Dictionnary on the given PrintStream.
static void listDictionary(Dictionary<?,?> dict, PrintStream out, String sep)
          Lists a dictionnary on the given PrintStream with the given separator.
static void listMap(Map<?,?> map)
          Lists a map on System.out.
static void listMap(Map<?,?> map, PrintStream out)
          Lists a map on the given PrintStream.
static void listMap(Map<?,?> map, PrintStream out, String sep)
          Lists a map on the given PrintStream with the given separator.
static void mainRemoveArray(String[] args)
           
static void mainSwapArray(String[] args)
           
static void mainTestBuildID(String[] args)
           
static void mainTestEmpty(String[] args)
           
static void mainTestEscapeLuceneQuery(String[] args)
           
static void mainTestFormatDuration(String[] args)
          Deprecated. Use DateUtil.mainTestFormatDuration(String[]) instead
static void mainTestGeneratePassword(String[] args)
           
static void mainTestInterUnionSubSet(String[] args)
           
static void mainTestJoin(String[] args)
           
static boolean notEmpty(Collection<?> c)
          Returns true if this collection is not null nor empty.
static boolean notEmpty(File file)
          Returns true if this File is not null nor empty.
static boolean notEmpty(File file, FileFilter fileFilter)
          Returns true if this File is not null nor empty.
static boolean notEmpty(int[] array)
          Returns true if this array is not null nor empty.
static boolean notEmpty(Map<?,?> map)
          Returns true if this map is not null nor empty.
static boolean notEmpty(Object object)
          Returns true if this object is not null nor empty.
static boolean notEmpty(Object[] array)
          Returns true if this array is not null nor empty.
static boolean notEmpty(Object[] array, boolean recursive)
          Returns true if this array is not null nor empty.
static boolean notEmpty(SQLQueryResult map)
          Returns true if this SQLQueryResult is not null nor empty.
static boolean notEmpty(String s)
          Returns true if this string is not null nor empty (once trimmed).
static Date parseIso8601Date(String source)
          Deprecated. Use DateUtil.parseIso8601Date(String) instead
static Date parseNoSpaceDate(String source)
          Deprecated. Use DateUtil.parseNoSpaceDate(String) instead
static Date parseRfc822Date(String source)
          Deprecated. Use DateUtil.parseRfc822Date(String) instead
static Date parseW3cDate(String source)
          Deprecated. Use DateUtil.parseW3cDate(String) instead
static String performDecoding(String src, HashMap transMap)
          Replace all occurences of values found in transMap with their assiocated keys.
static String performEncodeDecode(String src, HashMap transMap, boolean decode)
          Encode or decode the given String using the given translation Map.
static String performEncoding(String src, HashMap transMap)
          Replace all occurences of keys found in transMap with their assiocated values.
static Set<String> prefixSet(Set<String> set, String prefix)
          Prefix all elements of a Set of String with a given prefix
static
<K,V> Map<K,V>
putAll(K[] array, Map<K,V> map, V value)
          Copy all non-null objects from the given array to given map with a given value.
static String randomString(int length)
           
static String recapitalize(String str)
          Force the first char of a String to be a uppercase char.
static String reduceBlankLines(String text)
          Right trim all the lines in the message and reduced many CRLF to only one line.
static boolean[] removeArray(boolean[] array, int index)
          Remove an element of an Array of boolean
static boolean[] removeArray(boolean[] array, int from, int to)
          Remove n elements of an Array of boolean
static int[] removeArray(int[] array, int index)
          Remove an element of an Array of int
static int[] removeArray(int[] array, int from, int to)
          Remove n elements of an Array of int
static Object[] removeArray(Object[] array, int index)
          Remove an element of an Array of object
static Object[] removeArray(Object[] array, int from, int to)
          Remove n elements of an Array of object
static Object[] removeArray(Object[] array, Object obj)
          Remove an element of an Array of object
static String removeBlankLines(String str)
          Cleans the given string : remove pure blank lines and remove leadings white spaces.
static
<K,V> void
removeFromMapHashSet(Map<K,Set<V>> map, K key, V value)
          A convenient method that remove the given value to a set bound to the given key in the given map.
static
<K,V> void
removeFromMapLinkedHashSet(Map<K,LinkedHashSet<V>> map, K key, V value)
          A convenient method that remove the given value to a set bound to the given key in the given map.
static String removeJavaScriptQuote(String str)
          Remove JavaScript quotes
static String repeat(String pattern, int count)
          Repeat a String pattern count times
static String replace(String text, org.apache.oro.text.regex.Pattern pattern, RegexpSubstitution substitution)
          Replaces the given pattern in the given text with the given substitution function.
static String replace(String str, String pattern)
          Search and replace a string by another one
static String replace(String text, String regexp, RegexpSubstitution substitution)
          Replaces the given regexp in the given text with the given substitution function.
static String replace(String str, String match, String rep)
          Search and replace a string by another one (Note the input string must not contains '#' char)
static String replaceAll(String input, String searchString, String replaceString)
          Replace all occurence of searchString with replaceString in input string.
static String reveal(String concealedStr)
          Reveal the specified hidden string with an internally choosen encryption algorithm.
static
<K,V> Map<V,K>
reverseMap(Map<K,V> originalMap, Map<V,K> reverseMap)
          Fill the reverse map with the original map replacing keys by values and values by keys.
static long roundDuration(long duration)
          Deprecated. Use DateUtil.roundDuration(long) instead
static String[] split(String str, char delim, String emptyToken)
          Splits a String into an array of String.
static String[] split(String str, String delim)
          Splits a String into an array of String.
static int[] splitToIntArray(String str, String delim)
          Splits a String into an array of int.
static ArrayList<String> splitToList(String str, String delim)
          Splits a String into a list of String.
static String[] splitWithPattern(String text, String pattern)
          Splits a String according a given pattern and returns an array of String.
static String startsWith(String str, Collection<String> coll)
          Returns the String in the given collection that is a starting string og given str
static Set<String> stringArrayToCleanSet(String[] array)
          Returns a set which contains all the non empty cells of the given array.
static
<K,V> Map<K,V>
subMap(Map<K,V> map, Set<K> keys)
          This method will return a new Map containing all values of specified map without given keys.
static Set subSet(Set... sets)
          Returns the subset of an array of Set.
static Set subSet(Set set1, Set set2)
          Returns the subset of an array of Set.
static Set subSet(Set set1, Set set2, Set set3)
          Returns the subset of an array of Set.
static String surround(String inside, String begin, String end)
          Surround a given text (the first argument) with the two other arguments, only if the given text is not empty.
static String surroundWithTag(String inside, String tag)
          Surround a given text (the first argument) with a html tag.
static boolean[] swapArray(boolean[] array, int from, int to, boolean roll, boolean copy)
          Swap two cells of a boolean array.
static int[] swapArray(int[] array, int from, int to, boolean roll, boolean copy)
          Swap two cells of an int array.
static Object[] swapArray(Object[] array, int from, int to, boolean roll, boolean copy)
          Swap two cells of an Object array.
static boolean toBoolean(Object obj, boolean def)
          Convert an Object (assert to be either a String or a Boolean) to a boolean
static byte toByte(Object obj, byte def)
          Convert an Object (assert to be either a String or a Byte) to a byte
static char toChar(Object obj, char def)
          Convert an Object (assert to be either a String or a Character) to a char
static Date toDate(String str, String format, Locale loc, Date def)
          Parse a String and Convert it into a Date
static double toDouble(Object obj, double def)
          Convert an Object (assert to be either a String or a Double) to a double
static float toFloat(Object obj, float def)
          Convert an Object (assert to be either a String or a Float) to a float
static int toInt(Object obj, int def)
          Convert an Object (assert to be either a String or a Integer) to a int
static int[] toIntArray(Object[] objs, int def)
          Convert an Object[] (assert to be either a String or a Integer) to a int
static Locale toLocale(String str, Locale def)
           
static long toLong(Object obj, long def)
          Convert an Object (assert to be either a String or a Long) to a long
static short toShort(Object obj, short def)
          Convert an Object (assert to be either a String or a Short) to a short
static String toWordLine(String str)
          Split a text in a String with one word by line (used for diffing 2 strings at word level).
static String[] trim(String[] array)
          Remove the trailing empty cells of the given String array.
static
<T> List<T>
trimList(List<T> list)
          Returns a copy of the given list without any null values at the end.
static String[] trimStringArray(String[] array)
          Remove the trailing empty cells of the given String array.
static String truncate(String str, int length)
          Truncates the given String.
static String truncate(String str, int length, String suffix)
          Truncates the given String
static String truncateHtml(String text, int length, boolean trim)
          Truncate an HTML string.
static String unaccentuate(String str)
          Removes all the accentuate chars of the given string.
static String unaccentuateRegexp(String str)
          Build an unaccentuated version of the given regexp.
static String uncapitalize(String str)
          Force the first char of a String to be a lowercase char.
static String unescapeChar(String str)
          Unescape escaped character in a String.
static Set<?> unionSet(Set<?>... sets)
          Returns the union of an array of Set.
static Set unionSet(Set set1, Set set2)
          Returns the union of two Set.
static Set unionSet(Set set1, Set set2, Set set3)
          Returns the union of three Set.
static void updateListMap(Map map, Object key, Object value, boolean lazy)
          Updated Map with the given key/value pair.
static boolean validateRegexp(String regexp)
          Tell if a String is a valid Perl 5 regexp.
static String wordWrap(String str, int width)
          Wraps a single line of text, identifying words by ' '.
static String wordWrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords)
          Wraps a single line of text, identifying words by ' '.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

EMPTY_TREESET

public static final TreeSet EMPTY_TREESET
The empty TreeSet (immutable).
Use emptyTreeSet() for generics compliance.


regexpEscaped1

public static final HashMap<String,String> regexpEscaped1

regexpEscaped2

public static final HashMap<String,String> regexpEscaped2

regexpEscaped3

public static final HashMap<String,String> regexpEscaped3

hexaPercentPattern

protected static org.apache.oro.text.regex.Pattern hexaPercentPattern

hexaPercentSubst

protected static org.apache.oro.text.regex.Perl5Substitution hexaPercentSubst

hexaPercentCompiler

protected static org.apache.oro.text.regex.Perl5Compiler hexaPercentCompiler

ESCAPE_CHAR

public static final char ESCAPE_CHAR
See Also:
Constant Field Values

cookieTransTable

public static final HashMap<String,String> cookieTransTable

isoLatin1_xml

public static final HashMap<String,String> isoLatin1_xml

basicEntitiesEncodingMap

public static final HashMap basicEntitiesEncodingMap

basicEntitiesDecodingMap

public static final HashMap basicEntitiesDecodingMap
Method Detail

emptyTreeSet

public static final <T> TreeSet<T> emptyTreeSet()
Returns the empty TreeSet (immutable). Unlike the like-named field, this method is parameterized.

This example illustrates the type-safe way to obtain an empty set:

     TreeSet<String> s = Util.emptyTreeSet();
 

See Also:
EMPTY_TREESET

getKey

public static <K,V> Object getKey(Map<K,V> map,
                                  V value)
Iterate over a Map, looking for a Key associated to a given value.

Parameters:
map - the Map to searhc on
value - the value to search
Returns:
the key associated to a given value

getKeys

public static <K,V> Set<K> getKeys(Map<K,V> map,
                                   V value)
Iterate over a Map, looking for a Keys associated to a given value.

Parameters:
map - the Map to searhc on
value - the value to search
Returns:
a Set of keys associated to a the given value

updateListMap

public static void updateListMap(Map map,
                                 Object key,
                                 Object value,
                                 boolean lazy)
Updated Map with the given key/value pair. Create a List of values if key already exists. If boolean "lazy" is false always create a List.

Parameters:
map - Map to work with
key - Object key of the Map
value - Object value of the map
lazy - boolean true to create List only after 2 elements

getChildListMap

public static Object getChildListMap(Map map,
                                     String key)
Returns the first Value matching the given key

Parameters:
map - the Map
key - Object key of the Map
Returns:
Object or null if key does not match

getChildrenListMap

public static List getChildrenListMap(Map map,
                                      String key)
Returns values matching the given key.

Parameters:
map - the Map
key - Object key of the Map
Returns:
List or null if key does not match

getChildrenListMap

public static List getChildrenListMap(Map map,
                                      String[] keys)
Returns a new List of values matching the ordered given keys.

Parameters:
map - the Map
keys - Object key of the Map
Returns:
List or null if key does not match

reverseMap

public static <K,V> Map<V,K> reverseMap(Map<K,V> originalMap,
                                        Map<V,K> reverseMap)
Fill the reverse map with the original map replacing keys by values and values by keys.

Type Parameters:
K -
V -
Parameters:
originalMap -
reverseMap -
Returns:
the reverse map
Since:
jcms-4.0

compareMap

public static <K,V> Map.Entry<K,V> compareMap(Map<K,V> map1,
                                              Map<K,V> map2)
Returns the first common Map.Entry of the given maps.

Parameters:
map1 - the first map
map2 - the second map.
Returns:
the common entry (from map1) or null.
Since:
jcms-5.7.0

isMapFilled

public static <K,V> boolean isMapFilled(Map<K,V> map)
Returns true if the given map contains at least one value not empty.

Parameters:
map - the map.
Returns:
true if the given map contains at least one value not empty.
Since:
jcms-5.7.0

addAll

public static <T> Collection<T> addAll(Collection<T> collection,
                                       Enumeration<T> enu)
Add all element of the enumerate to the collection return the collection modified.

Parameters:
collection -
enu -
Returns:
Collection
Since:
jcms-4.0

addAll

public static <T> Collection<T> addAll(Collection<T> collection,
                                       Iterator<T> it)
Add all element of the iterator to the collection return the collection modified.

Parameters:
collection - the collection
it - the iterator
Returns:
the collection
Since:
jcms-6.0.0

startsWith

public static String startsWith(String str,
                                Collection<String> coll)
Returns the String in the given collection that is a starting string og given str

Parameters:
str - the String to match
coll - a Collection of String that may be start of str
Returns:
The matching starting string or null
Since:
jcms-5.7.0

getString

public static String getString(Object obj,
                               String defaultValue)
Return the String representation of the given object if it is not null nor empty, otherwise it returns the default value.

Parameters:
obj - the object
defaultValue - the default value
Returns:
the default value if the given object is null or if obj.toString() is null or empty

getString

public static String getString(Object[] array,
                               int index,
                               String defaultValue)
Call the method getString() with the Object in the array specified at the given index. Check that the index, array are valid.

Parameters:
array - the object array
index - the index
defaultValue - the default value
Returns:
String
Since:
jcms-4.0

getObject

public static Object getObject(Object[] array,
                               int index,
                               Object defaultValue)

getInt

public static int getInt(int[] array,
                         int index,
                         int defaultValue)

getBoolean

public static boolean getBoolean(boolean[] array,
                                 int index,
                                 boolean defaultValue)

getSize

public static int getSize(String str)
Returns the size of the given String. Returns 0 if the String is null.

Parameters:
str - the String.
Returns:
the size of the given String. Returns 0 if the String is null.
Since:
jcms-6.0.0

getSize

public static int getSize(Object[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - the array.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-6.0.0

getSize

public static int getSize(byte[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of byte.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(short[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of short.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(int[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of int.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(long[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of long.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(float[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of float.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(double[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of double.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(boolean[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of boolean.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(char[] array)
Returns the size of the given array. Returns 0 if the array is null.

Parameters:
array - an array of char.
Returns:
the size of the given array. Returns 0 if the array is null.
Since:
jcms-7.0.0

getSize

public static int getSize(Collection coll)
Returns the size of the given collection. Returns 0 if the collection is null.

Parameters:
coll - the collection.
Returns:
the size of the given collection. Returns 0 if the collection is null.
Since:
jcms-6.0.0

getSize

public static int getSize(Map map)
Returns the size of the given map. Returns 0 if the map is null.

Parameters:
map - the map.
Returns:
the size of the given map. Returns 0 if the map is null.
Since:
jcms-6.0.0

notEmpty

public static boolean notEmpty(File file)
Returns true if this File is not null nor empty.

Parameters:
file - the file to test
Returns:
true if the file is not empty.

isEmpty

public static boolean isEmpty(File file)
Returns true if this file is null or empty.

Parameters:
file - the file to test
Returns:
true if the file is empty.

notEmpty

public static boolean notEmpty(File file,
                               FileFilter fileFilter)
Returns true if this File is not null nor empty.

Parameters:
file - the file to test
fileFilter - the filter
Returns:
true if the file is not empty.

isEmpty

public static boolean isEmpty(File file,
                              FileFilter fileFilter)
Returns true if this file is null or empty.

Parameters:
file - the file to test
fileFilter - the filter
Returns:
true if the file is empty.

notEmpty

public static boolean notEmpty(Object object)
Returns true if this object is not null nor empty.

Parameters:
object - the object to test
Returns:
true if the object is not empty.

isEmpty

public static boolean isEmpty(Object object)
Returns true if this object is null or empty.

Parameters:
object - the object to test
Returns:
true if the object is empty.

notEmpty

public static boolean notEmpty(int[] array)
Returns true if this array is not null nor empty.

Parameters:
array - the array to test
Returns:
true

isEmpty

public static boolean isEmpty(int[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(long[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(byte[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(short[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(float[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(double[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(boolean[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

isEmpty

public static boolean isEmpty(char[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

notEmpty

public static boolean notEmpty(Object[] array)
Returns true if this array is not null nor empty.

Parameters:
array - the array to test
Returns:
true if the array is not empty.

isEmpty

public static boolean isEmpty(Object[] array)
Returns true if this array is null or empty.

Parameters:
array - the array to test
Returns:
true if the array is empty.

notEmpty

public static boolean notEmpty(Object[] array,
                               boolean recursive)
Returns true if this array is not null nor empty.

Parameters:
array - the array to test
recursive - check if arrays elements are empty
Returns:
true if the array is not empty.

isEmpty

public static boolean isEmpty(Object[] array,
                              boolean recursive)
Returns true if this array is null or empty.

Parameters:
array - the array to test
recursive - check if arrays elements are empty
Returns:
true if the array is empty.

notEmpty

public static boolean notEmpty(Collection<?> c)
Returns true if this collection is not null nor empty.

Parameters:
c - the collection to test
Returns:
true if the collection is not empty.

isEmpty

public static boolean isEmpty(Collection<?> c)
Returns true if this collection is null or empty.

Parameters:
c - the collection to test
Returns:
true if the collection is empty.

isEmpty

public static boolean isEmpty(Collection<?> c,
                              boolean deep)
Returns true if this collection is null or empty.

Parameters:
c - the collection to test
deep - to call Util.isEmpty on content otherwise check only == null
Returns:
true if the collection is empty.
Since:
jcms-4.2

notEmpty

public static boolean notEmpty(Map<?,?> map)
Returns true if this map is not null nor empty.

Parameters:
map - the map to test
Returns:
true if the map is not empty.
Since:
jcms-4.1

isEmpty

public static boolean isEmpty(SQLQueryResult sqr)
Returns true if this SQLQueryResult is null or empty.

Parameters:
sqr - the SQLQueryResult to test
Returns:
true if the SQLQueryResult is empty.
Since:
jcms-4.1

notEmpty

public static boolean notEmpty(SQLQueryResult map)
Returns true if this SQLQueryResult is not null nor empty.

Parameters:
map - the SQLQueryResult to test
Returns:
true if the SQLQueryResult is empty.
Since:
jcms-4.1

isEmpty

public static boolean isEmpty(Map<?,?> map)
Returns true if this map is null or empty.

Parameters:
map - the map to test
Returns:
true if the map is empty.
Since:
jcms-4.1

mainTestEmpty

public static void mainTestEmpty(String[] args)

join

public static String join(Collection<?> col,
                          String sep)
Joins a collection of Object with the given separator into a String. Uses the toString() method for each iterated Object.

Parameters:
col - the collection
sep - the separator
Returns:
a String which contains all the iterated objects.

join

public static String join(Collection<?> col,
                          String sep,
                          int max,
                          String suffix)
Joins a collection of Object with the given separator into a String. Uses the toString() method for each iterated Object.

Parameters:
col - the collection
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
a String which contains all the iterated objects.
Since:
jcms-4.0

join

public static String join(Iterator<?> it,
                          String sep)
Joins a collection of Object with the given separator into a String. Uses the toString() method for each iterated Object.

Parameters:
it - the iterator of the collection
sep - the separator
Returns:
a String which contains all the iterated objects.

join

public static String join(Iterator<?> it,
                          String sep,
                          int max,
                          String suffix)
Joins a collection of Object with the given separator into a String. Uses the toString() method for each iterated Object.

Parameters:
it - the iterator of the collection
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
a String which contains all the iterated objects.
Since:
jcms-4.0

joinMap

public static String joinMap(Map<? extends Object,? extends Object> map,
                             String keyValueSep,
                             String entrySep)
Joins the entries of a map into a String.
   Map map = new LinkedHashMap();
   map.put("simpleobject", "bar");
   map.put("stringarray", new String[] { "hi", "hello" } );
   List list = new ArrayList();
   list.add("John");
   list.add("Doe");
   map.put("collection", list );
   
   String output = "{" + Util.joinMap(map, "=>", ", ") + "}";
   output == "{ simpleobject=>bar, stringarray=>[hi, hello], collection=>[John, Doe] }"
 

Parameters:
map - the map to join a
keyValueSep - the separator to use between key and the value
entrySep - the separator to use between each entry
Returns:
a new string (returns an empty string if map was null or empty)

listMap

public static void listMap(Map<?,?> map)
Lists a map on System.out.

Parameters:
map - the map to list

listMap

public static void listMap(Map<?,?> map,
                           PrintStream out)
Lists a map on the given PrintStream.

Parameters:
map - the map to list
out - the PrintStream to use to list the map

listMap

public static void listMap(Map<?,?> map,
                           PrintStream out,
                           String sep)
Lists a map on the given PrintStream with the given separator.

Parameters:
map - the map to list
out - the PrintStream to use to list the map
sep - the separator

listDictionary

public static void listDictionary(Dictionary<?,?> dict)
Lists a Dictionnary on System.out.

Parameters:
dict - the Dictionnary to list

listDictionary

public static void listDictionary(Dictionary<?,?> dict,
                                  PrintStream out)
Lists a Dictionnary on the given PrintStream.

Parameters:
dict - the Dictionnary to list
out - the PrintStream to use to list the dictionnary

listDictionary

public static void listDictionary(Dictionary<?,?> dict,
                                  PrintStream out,
                                  String sep)
Lists a dictionnary on the given PrintStream with the given separator.

Parameters:
dict - the dictionnary to list
out - the PrintStream to use to list the dictionnar
sep - the separator

subMap

public static <K,V> Map<K,V> subMap(Map<K,V> map,
                                    Set<K> keys)
This method will return a new Map containing all values of specified map without given keys.

Parameters:
map - Map to work on
keys - Set of key to remove
Returns:
Map a new HashMap or TreeMap contain map values without specified keys

interMap

public static <K,V> Map<? extends K,? extends V> interMap(Map<? extends K,? extends V> map,
                                                          Set<? extends K> keys)
This method will return a new Map containing only values of specified map with given keys.

Parameters:
map - Map to work on
keys - Set of key
Returns:
Map a new HashMap or TreeMap contain map values with specified keys

prefixSet

public static Set<String> prefixSet(Set<String> set,
                                    String prefix)
Prefix all elements of a Set of String with a given prefix

Parameters:
set - Set of String
prefix - a String to prefix
Returns:
Set a new set

unionSet

public static Set<?> unionSet(Set<?>... sets)
Returns the union of an array of Set. The result set does not contains null item.

Parameters:
sets - an array of Set
Returns:
the union Set (same class as the first set)

unionSet

public static Set unionSet(Set set1,
                           Set set2)
Returns the union of two Set.

Parameters:
set1 - the first Set
set2 - the second Set
Returns:
the union Set

unionSet

public static Set unionSet(Set set1,
                           Set set2,
                           Set set3)
Returns the union of three Set.

Parameters:
set1 - the first Set
set2 - the second Set
set3 - the thrid Set
Returns:
the union Set

interSet

public static Set interSet(Set... sets)
Returns the intersection of an array of Set.

Parameters:
sets - an array of Set
Returns:
a new Set (same class as the first set, with same comparator for TreeSet) containing only element presents in all the given set. does not return a new set if only one set was given, instead return the given set.

interSet

public static Set interSet(Set set1,
                           Set set2)
Returns the intersection of two Set.

Parameters:
set1 - the first Set
set2 - the second Set
Returns:
the intersection Set

interSet

public static Set interSet(Set set1,
                           Set set2,
                           Set set3)
Returns the intersection of three Set.

Parameters:
set1 - the first Set
set2 - the second Set
set3 - the thrid Set
Returns:
the intersection Set

subSet

public static Set subSet(Set... sets)
Returns the subset of an array of Set. The subset contains all the elements of the first Set without those of the other Set.

Parameters:
sets - an array of Set
Returns:
the subset Set (same class as the first set)

subSet

public static Set subSet(Set set1,
                         Set set2)
Returns the subset of an array of Set. The subset contains all the elements of the first Set without those of the second Set.

Parameters:
set1 - the first Set
set2 - the second Set
Returns:
the subset Set

subSet

public static Set subSet(Set set1,
                         Set set2,
                         Set set3)
Returns the subset of an array of Set. The subset contains all the elements of the first Set without those of the second and third Set.

Parameters:
set1 - the first Set
set2 - the second Set
set3 - the third Set
Returns:
the subset Set

getArrayList

public static <T> ArrayList<T> getArrayList(T... array)
Returns a new ArrayList filled with the given objects (skip null object).

Type Parameters:
T - any type
Parameters:
array - a varargs of objects
Returns:
a new ArrayList filled with the given objects.
Since:
jcms-6.1.0

getHashSet

public static <T> HashSet<T> getHashSet(T... array)
Returns a new HashSet filled with the given objects (skip null object).

Type Parameters:
T - any type
Parameters:
array - a varargs of objects
Returns:
a new HashSet filled with the given objects.
Since:
jcms-6.0.1

getTreeSet

public static <T> TreeSet<T> getTreeSet(T... array)
Returns a new TreeSet filled with the given objects (skip null object).

Type Parameters:
T - any type
Parameters:
array - a varargs of objects
Returns:
a new TreeSet filled with the given objects.
Since:
jcms-6.0.1

getHashMap

public static <K,V> HashMap<K,V> getHashMap(K key,
                                            V value)
Returns a new HashMap filled with the given key/value pair (if the key is not null).

Type Parameters:
K - any type
V - any type
Parameters:
key - the first key to be added
value - the first value to be added
Returns:
a HashMap filled with the given key/value pair.
Since:
jcms-5.7.3

getHashMap

public static <K,V> HashMap<K,V> getHashMap(Map<K,V> map)
Returns a new HashMap filled with the given map (if it is not null)

Type Parameters:
K - any type
V - any type
Parameters:
map - the map to be added
Returns:
a new HashMap filled with the given map.
Since:
jcms-6.0.0

getTreeMap

public static <K,V> TreeMap<K,V> getTreeMap(K key,
                                            V value)
Returns a new TreeMap filled with the given key/value pair (if the key is not null).

Type Parameters:
K - any type
V - any type
Parameters:
key - the first key to be added
value - the first value to be added
Returns:
a TreeMap filled with the given key/value pair.
Since:
jcms-5.7.3

getTreeMap

public static <K,V> TreeMap<K,V> getTreeMap(Map<K,V> map)
Returns a new TreeMap filled with the given map (if it is not null)

Type Parameters:
K - any type
V - any type
Parameters:
map - the map to be added
Returns:
a new TreeMap filled with the given map.
Since:
jcms-6.0.0

getLinkedHashMap

public static <K,V> LinkedHashMap<K,V> getLinkedHashMap(K key,
                                                        V value)
Returns a new LinkedHashMap filled with the given key/value pair (if the key is not null).

Type Parameters:
K - any type
V - any type
Parameters:
key - the first key to be added
value - the first value to be added
Returns:
a LinkedHashMap filled with the given key/value pair.
Since:
jcms-5.7.3

getLinkedHashMap

public static <K,V> LinkedHashMap<K,V> getLinkedHashMap(Map<K,V> map)
Returns a new LinkedHashMap filled with the given map (if it is not null)

Type Parameters:
K - any type
V - any type
Parameters:
map - the map to be added
Returns:
a new LinkedHashMap filled with the given map.
Since:
jcms-6.0.0

getFirst

public static <T> T getFirst(Collection<T> coll)
Returns the first itemp of the given collection (or null if the collection is empty).

Parameters:
coll - the collection
Returns:
the first itemp of the given collection (or null if the collection is empty).
Since:
jcms-6.0.0

getFirst

public static <T> T getFirst(T[] array)
Returns the first itemp of the given array (or null if the array is empty).

Parameters:
array - the array
Returns:
the first itemp of the given array (or null if the array is empty).
Since:
jcms-6.0.0

addInMapHashSet

public static <K,V> void addInMapHashSet(Map<K,Set<V>> map,
                                         K key,
                                         V value)
A convenient method that add the given value to a set bound to the given key in the given map.

Parameters:
map - the map
key - the key
value - the value
Since:
jcms-7.0.0

removeFromMapHashSet

public static <K,V> void removeFromMapHashSet(Map<K,Set<V>> map,
                                              K key,
                                              V value)
A convenient method that remove the given value to a set bound to the given key in the given map.

Parameters:
map - the map
key - the key
value - the value
Since:
jcms-7.0.0

addInMapLinkedHashSet

public static <K,V> void addInMapLinkedHashSet(Map<K,LinkedHashSet<V>> map,
                                               K key,
                                               V value)
A convenient method that add the given value to a set bound to the given key in the given map. This method have an underlying LinkedHashSEt to guarantee iteration order.

Parameters:
map - the map
key - the key
value - the value
Since:
jcms-7.0.0

removeFromMapLinkedHashSet

public static <K,V> void removeFromMapLinkedHashSet(Map<K,LinkedHashSet<V>> map,
                                                    K key,
                                                    V value)
A convenient method that remove the given value to a set bound to the given key in the given map. This method have an underlying LinkedHashSet to guarantee iteration order.

Parameters:
map - the map
key - the key
value - the value
Since:
jcms-7.0.0

mainTestInterUnionSubSet

public static void mainTestInterUnionSubSet(String[] args)

cleanCollection

public static <T> Collection<T> cleanCollection(Collection<T> coll)
Remove the null entries of the given collection. Caution, this method changes the content of the given collection.

Parameters:
coll - the collection to be cleaned
Returns:
the given collection without null entries.
Since:
jcms-4.1

collectionToCleanSet

public static <T> Set<T> collectionToCleanSet(Collection<T> coll)
Returns a set which contains all the non empty element of the given collection.

Parameters:
coll - the collection
Returns:
a set which contains all the non empty element of the given collection.
Since:
jcms-5.5.0

stringArrayToCleanSet

public static Set<String> stringArrayToCleanSet(String[] array)
Returns a set which contains all the non empty cells of the given array.

Parameters:
array - the array
Returns:
a set which contains all the non empty cells of the given array.
Since:
jcms-5.5.0

addAll

public static <T> Collection<T> addAll(T[] array,
                                       Collection<T> coll)
Copy all non-null objects from the given array to given collection.

Parameters:
array - the array to copy from
coll - the collection to copy to
Returns:
the collection
Since:
jcms-4.1.1

putAll

public static <K,V> Map<K,V> putAll(K[] array,
                                    Map<K,V> map,
                                    V value)
Copy all non-null objects from the given array to given map with a given value.

Parameters:
array - the array to copy from
map - the collection to copy to
value - the value to set
Returns:
the collection
Since:
jcms-5.7

swapArray

public static int[] swapArray(int[] array,
                              int from,
                              int to,
                              boolean roll,
                              boolean copy)
Swap two cells of an int array.

Parameters:
array - the array
from - the location of the first element (< 0 not to swap)
to - the location of the element to swap with (-2 to roll back, -1 to roll forward)
roll - if should roll from end to start
copy - return a copy of of the array
Returns:
int[]

swapArray

public static boolean[] swapArray(boolean[] array,
                                  int from,
                                  int to,
                                  boolean roll,
                                  boolean copy)
Swap two cells of a boolean array.

Parameters:
array - the array of array
from - the location of the first element (< 0 not to swap)
to - the location of the element to swap with (-2 to roll back, -1 to roll forward)
roll - if should roll from end to start
copy - return a copy of of the array
Returns:
boolean[]

swapArray

public static Object[] swapArray(Object[] array,
                                 int from,
                                 int to,
                                 boolean roll,
                                 boolean copy)
Swap two cells of an Object array.

Parameters:
array - the array of array
from - the location of the first element (< 0 not to swap)
to - the location of the element to swap with (-2 to roll back, -1 to roll forward)
roll - if should roll from end to start
copy - return a copy of of the array
Returns:
Object[]

insertArray

public static int[] insertArray(int[] array,
                                int index,
                                int elt)
Insert an element into an int array and return a duplicate copy of it.

Parameters:
array - the array
index - the location where the element must be inserted (use -1 to insert ahead and array.length (or greater) to insert at the end)
elt - the element to be inserted
Returns:
a new int[]

insertArray

public static boolean[] insertArray(boolean[] array,
                                    int index,
                                    boolean elt)
Insert an element into a boolean array and return a duplicate copy of it.

Parameters:
array - the array
index - the location where the element must be inserted (use -1 to insert ahead, array.length (or greater) to insert at the end)
elt - the element to be inserted
Returns:
a new boolean[]

insertArray

public static Object[] insertArray(Object[] array,
                                   int index,
                                   Object elt)
Insert an element into an Object array and return a duplicate copy of it.

Parameters:
array - the array
index - the location where the element must be inserted (use -1 to insert ahead, array.length (or greater) to insert at the end)
elt - the element to be inserted
Returns:
Object[]

removeArray

public static Object[] removeArray(Object[] array,
                                   int index)
Remove an element of an Array of object

Parameters:
array - the array of object
index - the location of the element to be removed from
Returns:
Object[] remove a copy of the array without the element. If the index is bad then return the original array

removeArray

public static Object[] removeArray(Object[] array,
                                   Object obj)
Remove an element of an Array of object

Parameters:
array - the array of object
obj - the object to be removed
Returns:
Object[] remove a copy of the array without the element. If the index is bad then return the original array

removeArray

public static int[] removeArray(int[] array,
                                int index)
Remove an element of an Array of int

Parameters:
array - the array of int
index - the location of the element to be removed from
Returns:
int[] remove a copy of the array without the element. If the index is bad then return the original array

removeArray

public static boolean[] removeArray(boolean[] array,
                                    int index)
Remove an element of an Array of boolean

Parameters:
array - the array of boolean
index - the location of the element to be removed from
Returns:
boolean[] remove a copy of the array without the element. If the index is bad then return the original array

removeArray

public static Object[] removeArray(Object[] array,
                                   int from,
                                   int to)
Remove n elements of an Array of object

Parameters:
array - the array of int
from - the location of the first element to be removed from
to - the location of the last element to be removed from
Returns:
Object[] remove a copy of the array without the element. If the from or to is bad then return the original array

removeArray

public static int[] removeArray(int[] array,
                                int from,
                                int to)
Remove n elements of an Array of int

Parameters:
array - the array of int
from - the location of the first element to be removed from
to - the location of the last element to be removed from
Returns:
int[] remove a copy of the array without the element. If the from or to is bad then return the original array

removeArray

public static boolean[] removeArray(boolean[] array,
                                    int from,
                                    int to)
Remove n elements of an Array of boolean

Parameters:
array - the array of boolean
from - the location of the first element to be removed from
to - the location of the last element to be removed from
Returns:
boolean[] remove a copy of the array without the element. If the from or to is bad then return the original array

isSameContent

public static boolean isSameContent(boolean[] array1,
                                    boolean[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a boolean array
array2 - a boolean array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(byte[] array1,
                                    byte[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a byte array
array2 - a byte array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(char[] array1,
                                    char[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a char array
array2 - a char array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(double[] array1,
                                    double[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a double array
array2 - a double array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(float[] array1,
                                    float[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a float array
array2 - a float array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(int[] array1,
                                    int[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - an int array
array2 - an int array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(long[] array1,
                                    long[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a long array
array2 - a long array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(short[] array1,
                                    short[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - a short array
array2 - a short array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(Object[] array1,
                                    Object[] array2)
Returns true if array1 has same content than array2.

Parameters:
array1 - an object array
array2 - an object array
Returns:
true if array1 has same content than array2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(Set set1,
                                    Set set2)
Returns true if set1 has same content than set2.

Parameters:
set1 - a Set
set2 - a Set
Returns:
true if set1 has same content than set2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(List list1,
                                    List list2)
Returns true if list1 has same content than list2.

Parameters:
list1 - a List
list2 - a List
Returns:
true if list1 has same content than list2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(Map map1,
                                    Map map2)
Returns true if map1 has same content than map2.

Parameters:
map1 - a Map
map2 - a Map
Returns:
true if map1 has same content than map2 (note: null == empty)
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(String str1,
                                    String str2)
Returns true if str1 has same content than str2.

Parameters:
str1 - a String
str2 - a String
Returns:
true if str1 has same content than str2
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(Date date1,
                                    Date date2)
Returns true if date1 has same content than date2.

Parameters:
date1 - a Date
date2 - a Date
Returns:
true if date1 has same content than date2
Since:
jcms-2.2

isSameContent

public static boolean isSameContent(org.jdom.Element elt1,
                                    org.jdom.Element elt2)
Returns true if elt1 has same content than elt2.

Parameters:
elt1 - a JDom Element
elt2 - a JDom Element
Returns:
true if elt1 has same content than elt2
Since:
jcms-2.2

getTreeDescendantSet

public static TreeSet getTreeDescendantSet(TreeNode node)
Returns a TreeSet with all descendant of the given treenode, (excluding the node itself)

Parameters:
node - the node
Returns:
a TreeSet with all descendant of the given treenode, (excluding the node itself)

getTreeDescendantSet

public static Set getTreeDescendantSet(TreeNode node,
                                       Set nodeSet)

getAllChildrenSet

public static TreeSet getAllChildrenSet(TreeNode node)
Returns a TreeSet with all children of the given treenode, (including the node itself)

Parameters:
node - the node
Returns:
a TreeSet with all children of the given treenode, (including the node itself)

getAllChildren

public static Set getAllChildren(TreeNode node,
                                 Set nodeSet)
Fill the given set with every children of the given treenode, including the node itself, returns the filled set.

Parameters:
node - the parent node
nodeSet - the set to fill, if null, returns null
Returns:
the given set, filled with children and node.

isChildNode

public static boolean isChildNode(TreeNode node,
                                  TreeNode child)
Test if a node is a child of an other node
Return false if child == node

Parameters:
node - the parent node
child - the node to seek
Returns:
boolean if the child is a child or subchild of node

getHtmlIcon

public static String getHtmlIcon(String src,
                                 String alt)
Build an icon

Parameters:
src - the image source
alt - the iamge title
Returns:
the image tag representation

notEmpty

public static boolean notEmpty(String s)
Returns true if this string is not null nor empty (once trimmed).

Parameters:
s - the string to test
Returns:
true if the string is not empty.

isEmpty

public static boolean isEmpty(String s)
Returns true if this string is null or empty (once trimmed).

Parameters:
s - the string to test
Returns:
true if the string is empty.

splitToIntArray

public static int[] splitToIntArray(String str,
                                    String delim)
Splits a String into an array of int.

Parameters:
str - the String to split
delim - the delimiter (same as StringTokenizer)
Returns:
an array of String.
See Also:
splitToList(String, String), StringTokenizer

split

public static String[] split(String str,
                             String delim)
Splits a String into an array of String.

Parameters:
str - the String to split
delim - the delimiter (same as StringTokenizer)
Returns:
an array of String.
See Also:
splitToList(String, String), StringTokenizer

splitToList

public static ArrayList<String> splitToList(String str,
                                            String delim)
Splits a String into a list of String.

Parameters:
str - the String to split
delim - the delimiter (same as StringTokenizer)
Returns:
an ArrayList of String.
See Also:
StringTokenizer

split

public static String[] split(String str,
                             char delim,
                             String emptyToken)
Splits a String into an array of String. This method does NOT work as split(str, delim) based on StringTokenizer. This one, checks for empty token. For instance, splitting "A||BC|" with '|' as delim and "EMPTY" as empty token will return: String[] {"A", "EMPTY", "BC", "EMPTY"}

Parameters:
str - the String to split
delim - the delimiter
emptyToken - the value to used when encounter an empty token
Returns:
an array of String.
Since:
jcms-3.0

splitWithPattern

public static String[] splitWithPattern(String text,
                                        String pattern)
Splits a String according a given pattern and returns an array of String. For each match, add group(1) if not empty otherwise adds group(0).
Example1 (without group(1)):
text: foo [one: 1] [two: 2] bar [three: 3] bar
pattern: "\\[([^\\]]+)\\]"
returns String[] {"one: 1", "two: 2", "three: 3" }

Example2 (with group(1)):
text: foo [one: 1] [two: 2] bar [three: 3] bar
pattern: "\\[[^\\]]+\\]"
returns String[] {"[one: 1]", "[two: 2]", "[three: 3]" }

Parameters:
text - the text to split.
pattern - the pattern to split with.
Returns:
an array of String (never null)
Since:
jcms-5.7.2

getMatch

public static String getMatch(String regexp,
                              String str,
                              int group)
Return the group matching the given regexp for the given String or null if do not match or exception happens

Parameters:
regexp - the regular expression
str - the String to match
group - the group to match
Returns:
String the matching group

getMatch

public static String getMatch(Pattern pattern,
                              String str,
                              int group)
Return the group matching the given regexp for the given String or null if do not match or exception happens

Parameters:
pattern - java.util.regex.Pattern
str - the String to match
group - the group to match
Returns:
String the matching group

wordWrap

public static String wordWrap(String str,
                              int width)

Wraps a single line of text, identifying words by ' '.

New lines will be separated by the system property line separator. Very long words, such as URLs will not be wrapped.

Leading spaces on a new line are stripped. Trailing spaces are not stripped.

 Util.wordWrap(null, *) = null
 Util.wordWrap("", *) = ""
 

Parameters:
str - the String to be word wrapped, may be null
width - the column to wrap the words at, less than 1 is treated as 1
Returns:
a line with newlines inserted, null if null input TODO: replace with jakarta WordUtils.wrap()

wordWrap

public static String wordWrap(String str,
                              int wrapLength,
                              String newLineStr,
                              boolean wrapLongWords)

Wraps a single line of text, identifying words by ' '.

Leading spaces on a new line are stripped. Trailing spaces are not stripped.

 Util.wordWrap(null, *, *, *) = null
 Util.wordWrap("", *, *, *) = ""
 

Parameters:
str - the String to be word wrapped, may be null
wrapLength - the column to wrap the words at, less than 1 is treated as 1
newLineStr - the string to insert for a new line, null uses the system property line separator
wrapLongWords - true if long words (such as URLs) should be wrapped
Returns:
a line with newlines inserted, null if null input TODO: replace with jakarta WordUtils.wrap()

mainTestGeneratePassword

public static void mainTestGeneratePassword(String[] args)

mainTestJoin

public static void mainTestJoin(String[] args)

join

public static String join(Object[] array,
                          String sep)
Joins an array of String with the given separator.

Parameters:
array - the array of String to join.
sep - the separator
Returns:
the join String.

join

public static String join(Object[] array,
                          String sep,
                          int max,
                          String suffix)
Joins an array of String with the given separator.

Parameters:
array - the array of String to join.
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
the join String.
Since:
jcms-4.0

join

public static String join(int[] array,
                          String sep)
Joins an array of int with the given separator.

Parameters:
array - the array of int to join.
sep - the separator
Returns:
the join String.

join

public static String join(int[] array,
                          String sep,
                          int max,
                          String suffix)
Joins an array of int with the given separator.

Parameters:
array - the array of int to join.
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
the join String.
Since:
jcms-4.0

join

public static String join(String... str)
Join String with a given separator
  • First String is the separator
  • Always return a String
  • If Str1 or Str2 is null then return the other value without separator

Returns:
String

join

public static String join(long[] array,
                          String sep)
Joins an array of long with the given separator.

Parameters:
array - the array of long to join.
sep - the separator
Returns:
the join String.
Since:
jcms-5.5

join

public static String join(long[] array,
                          String sep,
                          int max,
                          String suffix)
Joins an array of long with the given separator.

Parameters:
array - the array of long to join.
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
the join String.
Since:
jcms-5.5

join

public static String join(double[] array,
                          String sep)
Joins an array of double with the given separator.

Parameters:
array - the array of long to join.
sep - the separator
Returns:
the join String.
Since:
jcms-5.5

join

public static String join(double[] array,
                          String sep,
                          int max,
                          String suffix)
Joins an array of double with the given separator.

Parameters:
array - the array of double to join.
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
the join String.
Since:
jcms-5.5

join

public static String join(boolean[] array,
                          String sep)
Joins an array of boolean with the given separator.

Parameters:
array - the array of boolean to join.
sep - the separator
Returns:
the join String.

join

public static String join(boolean[] array,
                          String sep,
                          int max,
                          String suffix)
Joins an array of boolean with the given separator.

Parameters:
array - the array of boolean to join.
sep - the separator
max - the maximum of item to join
suffix - the suffix to add if the maximum has been reached
Returns:
the join String.
Since:
jcms-4.0

toWordLine

public static String toWordLine(String str)
Split a text in a String with one word by line (used for diffing 2 strings at word level).

Parameters:
str - the string to split
Returns:
the result String
Since:
jcms-2.2

repeat

public static String repeat(String pattern,
                            int count)
Repeat a String pattern count times

Parameters:
pattern - the pattern
count - the number of times the pattern must be repeated
Returns:
a String containing the result

arrayContains

public static boolean arrayContains(Object[] array,
                                    Object key)
Test if an array contains a given object. Return true if the test with '==' operator or 'equals' method returns true.

Parameters:
array - the array to be searched.
key - the value to be searched for.
Returns:
true if the array contains the given object.

trim

public static String[] trim(String[] array)
Remove the trailing empty cells of the given String array. E.g. trimString(new String[] {"", "x", "", "y", null, ""}) returns {"", "x", "y"}.

Parameters:
array - the array to be trimmed
Returns:
the trimmed array

trimStringArray

public static String[] trimStringArray(String[] array)
Remove the trailing empty cells of the given String array. E.g. trimString(new String[] {"", "x", "", "y", null, ""}) returns {"", "x", "y"}.

Parameters:
array - the array to be trimmed
Returns:
the trimmed array

trimList

public static <T> List<T> trimList(List<T> list)
Returns a copy of the given list without any null values at the end.

Type Parameters:
T - any type
Parameters:
list - the list to be trimmed
Returns:
a copy of the given list without any null values at the end.
Since:
jcms-5.7.0

cleanStringArray

public static String[] cleanStringArray(String[] array)
Creates a new array that contains all elements of the given array except empty Strings (ie null or empty). Each string is trimed.

Parameters:
array - the array to be cleaned
Returns:
the cleaned array

cleanObjectArray

public static Object[] cleanObjectArray(Object[] array)
Creates a new array that contains all elements of the given array without null.

Parameters:
array - the array to be cleaned
Returns:
the cleaned array
Since:
jcms-5.0.5

unaccentuate

public static String unaccentuate(String str)
Removes all the accentuate chars of the given string. The following accentuate chars are supported: À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Œ Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö œ ù ú û ü ý þ ÿ

Parameters:
str - the String to unaccentuate.
Returns:
an unaccentuate String.

unaccentuateRegexp

public static String unaccentuateRegexp(String str)
Build an unaccentuated version of the given regexp. E.g. char 'e' is replaced by (e|é|è|ê|ë).

Parameters:
str - the String of the regexp to unaccentuate.
Returns:
an unaccentuate String.

recapitalize

public static String recapitalize(String str)
Force the first char of a String to be a uppercase char.

Parameters:
str - the String to proceed
Returns:
the result String

uncapitalize

public static String uncapitalize(String str)
Force the first char of a String to be a lowercase char.

Parameters:
str - the String to proceed
Returns:
the result String
Since:
jcms-2.2

asciiIndent

public static String asciiIndent(String text,
                                 int cols,
                                 int rows,
                                 String tailString)
Indent a given text according a number of column and row.
Caution: This method does not support unicode code point encoded on two chars and may cut unicode surrogate pair in two.

Parameters:
text - the text to indent
cols - Number of column
rows - Number of rows
tailString - the string to append if the text has been truncated
Returns:
the indented text

cryptUnix

public static String cryptUnix(String str)
Encrypt the given string with the Unix crypt algorithm

Parameters:
str - the String to encrypt
Returns:
the encrypted string
Since:
jcms-4.0

cryptMD5

public static String cryptMD5(String str)
Encrypt the given string with the MD5 algorithm and BASE64

Parameters:
str - the String to encrypt
Returns:
the encrypted string
Since:
jcms-4.0

encodeBASE64

public static String encodeBASE64(String str)
Encode the given string using BASE64 algorithm. The output is chuncked every 76 character. Equivalent to 'Util.encodeBase64(str, true)'

Parameters:
str - the String to encode
Returns:
the encoded string
Since:
jcms-5.5.0

encodeBASE64

public static String encodeBASE64(String str,
                                  boolean isChunck)
Encode the given string using BASE64 algorithm.

Parameters:
str - the string to encode
isChunck - - if true this encoder will chunk the base64 output into 76 character blocks
Returns:
the encoded string
Since:
jcms-6.0

decodeBASE64

public static String decodeBASE64(String str)
Decode the given string using BASE64 algorithm

Parameters:
str - the String to decode
Returns:
the decoded string
Since:
jcms-5.5.0

encryptDES3

public static String encryptDES3(String clearStr)
                          throws StringEncrypter.EncryptionException
Encrypt the specified string using DESede StringEncrypter with an internal key.

WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.

Parameters:
clearStr - the string to encrypt.
Returns:
the encrypted string prefixed, or null/empty string if the specified clearStr was null/empty.
Throws:
StringEncrypter.EncryptionException - if the encryption could not be performed
Since:
jcms-5.7.0

decryptDES3

public static String decryptDES3(String encryptedStr)
                          throws StringEncrypter.EncryptionException
Decrypt the specified string using DESede StringEncrypter using same internal key used by encryptDES3(String).

Parameters:
encryptedStr - the encrypted string to decrypt. if null or empty, the return
Returns:
the decrypted string, or null/empty string if the specified encryptedStr was null/empty
Throws:
StringEncrypter.EncryptionException - if the decryption could not be performed
Since:
jcms-5.7.0

conceal

public static String conceal(String clearStr)
Conceal the given string with an internally choosen encryption algorithm.

WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
WARNING: This method will return the clear text string if the string could not be encrypted.

Parameters:
clearStr - the String to encrypt
Returns:
the encrypted string
Since:
jcms-5.7

reveal

public static String reveal(String concealedStr)
Reveal the specified hidden string with an internally choosen encryption algorithm.

Parameters:
concealedStr - the String to encrypt
Returns:
the encrypted string
Since:
jcms-5.7

buildID

public static String buildID(String str,
                             String charRange)
Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes chars out of the given range and lowercases.

Parameters:
str - the String to used as base for the ID
charRange - a perl5 char range. All the chars out of this range will be ignored (e.g. "0-9a-z_A-Z" to keep only alpha-num chars)
Returns:
the ID
Since:
jcms-4.0.1

buildID

public static String buildID(String str)
Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes non-alphanum chars and lowercases.

Parameters:
str - the String to used as base for the ID
Returns:
the ID
Since:
jcms-4.0

buildCamelID

public static String buildCamelID(String str)
Build a Camel Case ID from the given String: remove the blanks, unaccentuates, removes non-alphanum chars.

Parameters:
str - the String to used as base for the ID
Returns:
the ID
Since:
jcms-5.7.0

buildUID

public static String buildUID(String str,
                              Set<String> strSet)
Build an ID from the given String: replaces the blanks with '_', unaccentuates, removes non-alphanum chars and lowercases. Add a number to the id if it already exists.

Parameters:
str - the String to used as base for the ID
strSet - the set of String of existing ids
Returns:
the ID

mainTestBuildID

public static void mainTestBuildID(String[] args)

escapePercent

public static String escapePercent(String url)
This method replace % in wrong hexa character by '_' character

Parameters:
url - the utf-8 string to escape
Returns:
String the escaped String

escapeRegexp

public static String escapeRegexp(String string)
Escape a (OROMatcher) regular expression with support of basic regexp (* and ?). Example: (a*b?) will be escaped into \(a.*b.?\).

Parameters:
string - the regexp string to be escaped
Returns:
the escaped string
See Also:
escapeRegexp(String,boolean)

escapeRegexp

public static String escapeRegexp(String string,
                                  boolean basicRegexp)
Escape a (OROMatcher) regular expression with support of basic regexp (* and ?). Example: (a*b?) will be escaped into \(a.*b.?\).

Parameters:
string - the regexp string to be escaped
basicRegexp - if true convert * and ? to Perl5 regular expression
Returns:
the escaped string
Since:
jcms-4.1

escapeChars

public static String escapeChars(String str,
                                 String charsToEscape)
Escape specified characters in a String.

Example:

 Util.escapeChar("ab|cde%fg|hi=j", "|="); // -> ab%7ccde%25fg%7chi%3dj
 

Parameters:
str - the string
charsToEscape - a string containing all the chararacters to escape
Returns:
a new String with all charToEscape escaped

unescapeChar

public static String unescapeChar(String str)
Unescape escaped character in a String. Character to unescape are prepended with ESCAPE_CHAR.

Example:

 Util.unescapeChar("ab%7ccde%25fg%7chij"); // ->  ab|cde%fg|hij
 

Parameters:
str - the string
Returns:
a new String with all charToUnescape unescaped

escapeLuceneQuery

public static String escapeLuceneQuery(String str)
Escape Lucene special chars. I.e. + - && || ! ( ) { } [ ] ^ " ~ * ? : \ (see http://jakarta.apache.org/lucene/docs/queryparsersyntax.html)

Parameters:
str - the string to escape
Returns:
the escaped string
Since:
jcms-4.0

mainTestEscapeLuceneQuery

public static void mainTestEscapeLuceneQuery(String[] args)

replace

public static String replace(String str,
                             String match,
                             String rep)
Search and replace a string by another one (Note the input string must not contains '#' char)

Parameters:
str - the input String
match - a Perl5 regexp
rep - a Perl5 replace pattern
Returns:
the modified String

replace

public static String replace(String str,
                             String pattern)
Search and replace a string by another one

Parameters:
str - the input String
pattern - the Perl5 substitution pattern (e.g. s!regexp!replace!)
Returns:
the modified String

replace

public static String replace(String text,
                             String regexp,
                             RegexpSubstitution substitution)
                      throws org.apache.oro.text.regex.MalformedPatternException
Replaces the given regexp in the given text with the given substitution function.

Parameters:
text - the text
regexp - the regexp
substitution - the RegexpSubstitution function called.
Returns:
the result text or the given text if there is null parameter
Throws:
org.apache.oro.text.regex.MalformedPatternException
Since:
jcms-6.0.0

replace

public static String replace(String text,
                             org.apache.oro.text.regex.Pattern pattern,
                             RegexpSubstitution substitution)
Replaces the given pattern in the given text with the given substitution function.

Parameters:
text - the text
pattern - the pattern
substitution - the RegexpSubstitution function called.
Returns:
the result text or the given text if there is null parameter
Since:
jcms-6.0.0

replaceAll

public static String replaceAll(String input,
                                String searchString,
                                String replaceString)
Replace all occurence of searchString with replaceString in input string. DO NOT use any regular expressions.

Parameters:
input - represents input string
searchString - represents substring for replace
replaceString - represents replaced string value
Returns:
new string with replaced values
Since:
jcms-5.5.0

removeBlankLines

public static String removeBlankLines(String str)
Cleans the given string : remove pure blank lines and remove leadings white spaces. This method has been rewritten in jcms-5.0.1 and is about twice faster than the previous implementation.

Parameters:
str - the String to be cleaned
Returns:
the cleaned String
Since:
jcms-4.0

escapeBackslash

public static String escapeBackslash(String str)
Escape all the '\' in the given String ('\\')

Parameters:
str - the String to escape
Returns:
the escaped String

removeJavaScriptQuote

public static String removeJavaScriptQuote(String str)
Remove JavaScript quotes

Parameters:
str - the String to escape
Returns:
the escaped String
Since:
jcms-4.0

encodeJavaScriptQuote

public static String encodeJavaScriptQuote(String str)
Encode JavaScript quotes for JavaScript that using Labels with beautification
  • ' -> ’
  • " -> ’’

    Parameters:
    str - the String to encode
    Returns:
    the encoded String
    Since:
    jcms-5.0

  • escapeJavaScriptQuote

    public static String escapeJavaScriptQuote(String str)
    Escape JavaScript quotes
  • ' -> \'
  • " -> \"

    Parameters:
    str - the String to escape
    Returns:
    the escaped String
    Since:
    jcms-2.2

  • escapeJavaStringChar

    public static String escapeJavaStringChar(String str)
    Escape all the invalide char in Java String:
  • '\' -> "\\"
  • CR -> "\n"
  • '"' -> \"

    Parameters:
    str - the String to escape
    Returns:
    the escaped String

  • getFirstSentences

    public static String getFirstSentences(String text,
                                           int limit)
    Get the first sentences in a given string.

    Parameters:
    text - the string to get the first sentence.
    limit - how many sentences to get (return the original text if limit <0).
    Returns:
    a string containing the first sentences.

    mainSwapArray

    public static void mainSwapArray(String[] args)

    mainRemoveArray

    public static void mainRemoveArray(String[] args)

    truncateHtml

    public static String truncateHtml(String text,
                                      int length,
                                      boolean trim)
    Truncate an HTML string.

    - Prevents html tags to be split in the middle of the attributes.
    That is, the string "the image: <img src='some.jpg' border='0'>"
    will end "the image: "

    - Warning: do not prevent opened tag not to be closed:
    with a string "go there: <a href='hello'>a link</a>"
    you can end with "go there: <a href='hello'>a lin" which is invalid html

    Parameters:
    text - the HTML content to be truncated
    length - the length to keep.
    trim - if true trims the input text
    Returns:
    the truncated text

    truncate

    public static String truncate(String str,
                                  int length)
    Truncates the given String.

    Parameters:
    str - the String to truncate
    length - the length to truncate to
    Returns:
    the truncated string
    Since:
    jcms-6.1.0

    truncate

    public static String truncate(String str,
                                  int length,
                                  String suffix)
    Truncates the given String

    Parameters:
    str - the String to truncate
    length - the length to truncate to
    suffix - the suffix to add if the string has been truncated
    Returns:
    the truncated string
    Since:
    jcms-4.0.2

    html2Ascii

    public static String html2Ascii(String text)
    Convert a given text from HTML to ASCII.

    Parameters:
    text - the text to convert
    Returns:
    the text converted

    surround

    public static String surround(String inside,
                                  String begin,
                                  String end)
    Surround a given text (the first argument) with the two other arguments, only if the given text is not empty. Otherwise, returns an empty text.

    Parameters:
    inside - The text to be surrounded.
    begin - The text at the beginning.
    end - The text at the end.
    Returns:
    The given text surrounded.

    surroundWithTag

    public static String surroundWithTag(String inside,
                                         String tag)
    Surround a given text (the first argument) with a html tag. If the text is empty, returns an empty text. If the tag is empty, returns the original text.

    Parameters:
    inside - The text to be surrounded.
    tag - The tag
    Returns:
    The text surrounded.

    decodeUrl

    public static String decodeUrl(String str)

    encodeUrl

    public static String encodeUrl(String s)
    Same implementation as URLEncoder.encode(String, String), but space is encoded with %20 and '/' is not encoded.

    Parameters:
    s - String to be translated.
    Returns:
    the translated String.

    encodeUrl

    public static String encodeUrl(String s,
                                   String enc)
    Same implementation as URLEncoder.encode(String, String), but space is encoded with %20 and '/' is not encoded.

    Parameters:
    s - String to be translated.
    enc - String encoding
    Returns:
    the translated String.

    encodeCookie

    public static String encodeCookie(String src)

    decodeCookie

    public static String decodeCookie(String src)

    isoLatin1ToEntities

    public static String isoLatin1ToEntities(String src)
    Convert all the isoLatin1 accent into XML entities (e.g. 'é' -> é)

    Parameters:
    src - the String to convert
    Returns:
    the converted String

    entitiesToIsoLatin1

    public static String entitiesToIsoLatin1(String src)
    Does the opposite of isoLatin1ToEntities.

    Parameters:
    src - the String to convert
    Returns:
    the converted String

    encodeHtmlBasicEntities

    public static String encodeHtmlBasicEntities(String src)
    Encode given string according to the following table.
    • " : &quot;
    • ' : &#039;
    • < : &lt;
    • > : &gt;
    • & : &amp;

    Parameters:
    src - the String to convert
    Returns:
    the converted String

    decodeHtmlBasicEntities

    public static String decodeHtmlBasicEntities(String src)
    Does the opposite job of encodeHtmlBasicEntities.

    Parameters:
    src - the String to convert
    Returns:
    the converted String

    performEncoding

    public static String performEncoding(String src,
                                         HashMap transMap)
    Replace all occurences of keys found in transMap with their assiocated values.

    Parameters:
    src - the String to convert
    transMap - the translation map
    Returns:
    the converted String

    performDecoding

    public static String performDecoding(String src,
                                         HashMap transMap)
    Replace all occurences of values found in transMap with their assiocated keys.

    Parameters:
    src - the String to convert
    transMap - the translation map
    Returns:
    the converted String

    performEncodeDecode

    public static String performEncodeDecode(String src,
                                             HashMap transMap,
                                             boolean decode)
    Encode or decode the given String using the given translation Map. If encoding replace occurence of keys with values. If decoding replace occurence of values with keys

    Parameters:
    src - the String to convert
    transMap - the translation map
    decode - if true use values else use keys
    Returns:
    the converted String

    encodeIntArray

    public static String encodeIntArray(int[] array)

    decodeIntArray

    public static int[] decodeIntArray(String param)

    encodeIntArray

    public static String encodeIntArray(int[] array,
                                        char separator)

    decodeIntArray

    public static int[] decodeIntArray(String param,
                                       char separator)

    encodeStringArray

    public static String encodeStringArray(String[] array)

    decodeStringArray

    public static String[] decodeStringArray(String param)

    encodeStringArray

    public static String encodeStringArray(String[] array,
                                           char separator)

    decodeStringArray

    public static String[] decodeStringArray(String param,
                                             char separator)

    encodeObject

    public static String encodeObject(Object obj)
    Returns the encoded objected as a String.

    Parameters:
    obj - the object to be encoded
    Returns:
    the encoded objected as a String.
    Since:
    jcms-6.0.0

    decodeObject

    public static Object decodeObject(String encoded)
    Returns the object decoded from the given String.

    Parameters:
    encoded - the String that contains the encoded object
    Returns:
    the object decoded from the given String.
    Since:
    jcms-6.0.0

    isNumber

    public static boolean isNumber(String str)
    Returns true if the given string only contains 0-9 characters

    Parameters:
    str - the String to be checked
    Returns:
    true if the given string only contains 0-9 characters

    toIntArray

    public static int[] toIntArray(Object[] objs,
                                   int def)
    Convert an Object[] (assert to be either a String or a Integer) to a int

    Parameters:
    objs - the object array to convert
    def - default int value to use is object is empty, not a String nor a Integer
    Returns:
    a int[] or null if objs is null
    Since:
    jcms-5.6.0
    See Also:
    toInt(Object, int)

    toInt

    public static int toInt(Object obj,
                            int def)
    Convert an Object (assert to be either a String or a Integer) to a int

    Parameters:
    obj - the object to convert
    def - default int value to use is object is empty, not a String nor a Integer
    Returns:
    a int
    Since:
    jcms-4.0

    toFloat

    public static float toFloat(Object obj,
                                float def)
    Convert an Object (assert to be either a String or a Float) to a float

    Parameters:
    obj - the object to convert
    def - default float value to use is object is empty, not a String nor a Float
    Returns:
    a float
    Since:
    jcms-4.0

    toByte

    public static byte toByte(Object obj,
                              byte def)
    Convert an Object (assert to be either a String or a Byte) to a byte

    Parameters:
    obj - the object to convert
    def - default byte value to use is object is empty, not a String nor a Byte
    Returns:
    a byte
    Since:
    jcms-4.0

    toShort

    public static short toShort(Object obj,
                                short def)
    Convert an Object (assert to be either a String or a Short) to a short

    Parameters:
    obj - the object to convert
    def - default short value to use is object is empty, not a String nor a Short
    Returns:
    a short
    Since:
    jcms-4.0

    toLong

    public static long toLong(Object obj,
                              long def)
    Convert an Object (assert to be either a String or a Long) to a long

    Parameters:
    obj - the object to convert
    def - default long value to use is object is empty, not a String nor a Long
    Returns:
    a long
    Since:
    jcms-4.0

    toDouble

    public static double toDouble(Object obj,
                                  double def)
    Convert an Object (assert to be either a String or a Double) to a double

    Parameters:
    obj - the object to convert
    def - default double value to use is object is empty, not a String nor a Double
    Returns:
    a double
    Since:
    jcms-4.0

    toChar

    public static char toChar(Object obj,
                              char def)
    Convert an Object (assert to be either a String or a Character) to a char

    Parameters:
    obj - the object to convert
    def - default char value to use is object is empty, not a String nor a Character
    Returns:
    a char
    Since:
    jcms-4.0

    toBoolean

    public static boolean toBoolean(Object obj,
                                    boolean def)
    Convert an Object (assert to be either a String or a Boolean) to a boolean

    Parameters:
    obj - the object to convert
    def - default boolean value to use is object is empty, not a String nor a Boolean
    Returns:
    a boolean
    Since:
    jcms-4.0

    toDate

    public static Date toDate(String str,
                              String format,
                              Locale loc,
                              Date def)
    Parse a String and Convert it into a Date

    Parameters:
    str - the String to parse
    format - the date Format (can be null)
    loc - the Locale tio use (can be null)
    def - the default Date to return if errors append.
    Returns:
    the converted Date

    toLocale

    public static Locale toLocale(String str,
                                  Locale def)

    formatSize

    public static String formatSize(long size,
                                    Locale locale)
    This method format the given size on the greatest unit. Example: 4096 -> 4 K, 532923 -> 520.43 K

    Parameters:
    size - the size to format
    locale - the locale to use for the unit
    Returns:
    the formatted file size

    formatFileSize

    public static String formatFileSize(long size)
    This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB. Use default locale.

    The format used is plain text.

    Parameters:
    size - the size to format
    Returns:
    the formatted file size

    formatFileSize

    public static String formatFileSize(long size,
                                        Locale locale)
    This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB

    The format used is HTML (with detailled abbreviations).

    Parameters:
    size - the size to format
    locale - the locale to use for the unit
    Returns:
    the formatted file size

    formatFileSize

    public static String formatFileSize(long size,
                                        Locale locale,
                                        boolean htmlDisplay)
    This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB

    Parameters:
    size - the size to format
    locale - the locale to use for the unit
    htmlDisplay - if true, uses an html format, with detailled abbreviation, otherwise, use only plain text
    Returns:
    the formatted file size

    formatDuration

    @Deprecated
    public static String formatDuration(Date begin,
                                                   Date end)
    Deprecated. Use DateUtil.formatDuration(Date,Date) instead

    Format a duration (i.e split the given time into days, hours, minutes and seconds) E.g.: 124532923 -> 1 day 10 h 35 min 32 s. Use default locale.

    Parameters:
    begin - the begin date
    end - the end date
    Returns:
    the formatted String

    formatDuration

    @Deprecated
    public static String formatDuration(Date begin,
                                                   Date end,
                                                   Locale locale)
    Deprecated. Use DateUtil.formatDuration(Date,Date,Locale) instead

    Format a duration (i.e split the given time into days, hours, minutes and seconds) E.g.: 124532923 -> 1 day 10 h 35 min 32 s

    Parameters:
    begin - the begin date
    end - the end date
    locale - the locale to use
    Returns:
    the formatted String

    formatDuration

    @Deprecated
    public static String formatDuration(long time)
    Deprecated. Use DateUtil.formatDuration(long) instead

    Format a duration (i.e split the given time into days, hours, minutes and seconds) E.g.: 124532923 -> 1 day 10 h 35 min 32 s. Use default locale.

    Parameters:
    time - the duration to format (in milliseconds)
    Returns:
    the formatted String

    formatDuration

    @Deprecated
    public static String formatDuration(long time,
                                                   Locale locale)
    Deprecated. Use DateUtil.formatDuration(long,Locale) instead

    Format a duration (i.e split the given time into days, hours, minutes and seconds) E.g.: 124532923 -> 1 day 10 h 35 min 32 s

    Parameters:
    time - the duration to format (in milliseconds)
    locale - the locale to use
    Returns:
    the formatted String

    mainTestFormatDuration

    @Deprecated
    public static void mainTestFormatDuration(String[] args)
    Deprecated. Use DateUtil.mainTestFormatDuration(String[]) instead


    roundDuration

    @Deprecated
    public static long roundDuration(long duration)
    Deprecated. Use DateUtil.roundDuration(long) instead

    Round a duration in order to remove irrelevant information for duration which do not need to be accurate (usually when duration is formatted for the UI).

    As of current implementation, the following rules are applied

    • Seconds are removed for duration longer than 5 minutes.
    • Minutes are rounded for duration longer than 2 hours (to current hour if minutes are below 30, to next 1 hour if minutes above 30)
    • Minutes are removed for duration longer than a day
    • Hours are removed for duration longer than a week
    Examples :
      Util.formatDuration(Util.roundDuration(38000)); // 38 s
      => 38 s
    
      Util.formatDuration(Util.roundDuration(76000)); // 1 min 16 s
      => 1 min 16 s
    
      Util.formatDuration(Util.roundDuration(1564512)); // 26 min 4 s
      => 26 min
    
      Util.formatDuration(Util.roundDuration(5890000)); // 1 h 38 min 10 s
      => 1 h 38 min
    
      Util.formatDuration(Util.roundDuration(33165000)); // 9 h 12 min 45 s
      => 9 h
    
      Util.formatDuration(Util.roundDuration(35025000)); // 9 h 43 min 45 s
      => 10 h
    
      Util.formatDuration(Util.roundDuration(130993000)); // 1 day 12 h 23 min 13 s
      => 1 day 12 h
    
      Util.formatDuration(Util.roundDuration(236158000)); // 2 days 17 h 35 min 58 s
      => 2 days 18 h
    
      Util.formatDuration(Util.roundDuration(731675000)); // 8 days 11 h 14 min 35 s
      => 8 days
    
      Util.formatDuration(Util.roundDuration(5934547000L)); // 68 days 16 h 29 min 7 s
      => 68 days
     

    Parameters:
    duration - a duration in milliseconds
    Returns:
    the duration rounded.
    Since:
    jcms-6.0.2

    generatePassword

    public static String generatePassword()

    generatePassword

    public static String generatePassword(int length)

    generatePronounceablePassword

    public static String generatePronounceablePassword(int pwdLength)
    Generates pronounceable passwords of specified length. See www.multicians.org/thvv/gpw.html for history and info. Tom Van Vleck

    Parameters:
    pwdLength - The length of the password to be generated
    Returns:
    The generated password
    Since:
    jcms-4.0

    getStackTrace

    public static String getStackTrace(Throwable throwable)
    This method print the stack trace into a String and return it. This is a convenient method for JSP that doesn't have PrintWriter.

    Parameters:
    throwable - the exception or throwable to print
    Returns:
    String the full stack trace.

    getCurrentStackTrace

    public static String getCurrentStackTrace()
    Returns the current StackTrace in a String.

    Returns:
    the current StackTrace in a String.
    Since:
    jcms-6.1.2

    forceFullGarbageCollection

    public static boolean forceFullGarbageCollection(long timeout)
    Force the garbage collection

    Parameters:
    timeout - in millisecond if timeout is reached stop the GC forcing
    Returns:
    false if the timeout has been reached

    getClassShortName

    public static String getClassShortName(Object object)
    Returns the short name of the given object's class (e.g. String for java.lang.String)

    Parameters:
    object - the object
    Returns:
    the short name of the object's class
    Since:
    jcms-4.1

    getClassShortName

    public static String getClassShortName(Class clazz)
    Returns the short name of the given class (e.g. String for java.lang.String)

    Parameters:
    clazz - the class
    Returns:
    the short name of the class

    getClassShortName

    public static String getClassShortName(String fullname)
    Returns the short name of the given class name (e.g. String for java.lang.String)

    Parameters:
    fullname - the full class name
    Returns:
    the short name of the class

    getClassFiles

    public static Set<String> getClassFiles(String realPath,
                                            String fullname,
                                            boolean java)
    Returns a Set of relative path to all class files including inner class and java. Pay attention to ending / to parameter.

    Parameters:
    realPath - the Webapp realpath (i.e. C:/project/appserver/webapps/webapp-name)
    fullname - the Class fullname (i.e. com.jalios.jcms.Category)
    java - boolean true to include java file
    Returns:
    Set a set of relative path (i.e. WEB-INF/classes/com/jalios/jcms/Category.class)

    getClassNameFromFilename

    public static String getClassNameFromFilename(String filename)
    Returns the class name from the filename of a class (e.g. it returns "com.jalios.util.Util" for "com/jalios/util/Util.class")

    Parameters:
    filename - the filename of the class
    Returns:
    the class name or null if an error occurred.
    Since:
    jcms-5.5.0

    getFirstCommonClass

    public static Class getFirstCommonClass(Class parent,
                                            Class child)
    Follow class tree of parent to find a class or an interface that is also parent of the child. If child is null return parent.

    Parameters:
    parent -
    child -
    Returns:
    Class

    getSuperclassList

    public static List getSuperclassList(Class clazz,
                                         Class ancestor,
                                         boolean addClass,
                                         boolean addAncestor)
    Returns a list of classes the given class is an ancestor of.

    Parameters:
    clazz - the class to extract the ancestors
    ancestor - the greater ancestor
    addClass - if true, add the class in the list
    addAncestor - if true, add the ancestor in the list
    Returns:
    a list from the given class to the ancestor class
    Since:
    jcms-4.2

    escapeHtml

    public static String escapeHtml(String str)
    Escapes some special HTML characters such as <, >, & and ". If str is null return an empty string.

    Parameters:
    str - the string to escape
    Returns:
    the escaped string

    escapeHtmlQuote

    public static String escapeHtmlQuote(String str)
    Escape simple and double quote as HTML entity.

    Parameters:
    str - the String to escape
    Returns:
    the escaped String

    escapeInputQuote

    public static String escapeInputQuote(String str)
    Escapes the quote (") character from the specified string.
    If str is null return an empty string.

    Parameters:
    str - the string to escape, e.g. : 'Hello "World" !'
    Returns:
    the escaped string, e.g. : 'Hello &quot;World&quot; !'

    indexOf

    public static int indexOf(Object elem,
                              Object[] array)
    Searches for the first occurence of the given argument in a given array, testing for equality using the equals method.

    Parameters:
    elem - an object.
    array - an array that may contain elem
    Returns:
    the index of the first occurrence of the argument in this * list; returns -1 if the object is not found.
    See Also:
    Object.equals(Object)

    formatIso8601Date

    @Deprecated
    public static String formatIso8601Date(Date date)
    Deprecated. Use DateUtil.formatIso8601Date(Date) instead

    Returns a date formated with the ISO 8601 Date Time format (eg 1999-01-01T14:07:00+0100).
    For more details, see http://en.wikipedia.org/wiki/ISO_8601
    This method is thread safe.

    Parameters:
    date - the date to format.
    Returns:
    a String with the formated date.
    Since:
    jcms-5.7.2
    See Also:
    DateUtil.parseIso8601Date(String)

    parseIso8601Date

    @Deprecated
    public static Date parseIso8601Date(String source)
    Deprecated. Use DateUtil.parseIso8601Date(String) instead

    Returns the date parsed from the given string with the ISO 8601 Date Time format (eg 1999-01-01T14:07:00+0100).
    For more details, see http://en.wikipedia.org/wiki/ISO_8601
    This method is thread safe.

    Parameters:
    source - the string to be parsed
    Returns:
    a Date
    Since:
    jcms-5.7.2
    See Also:
    DateUtil.formatIso8601Date(Date)

    formatW3cDate

    @Deprecated
    public static String formatW3cDate(Date date)
    Deprecated. Use DateUtil.formatW3cDate(Date) instead

    Returns a date formated with the W3C Date Time format (eg 1999-01-01T14:07:00+01:00).
    For more details, see http://www.w3.org/TR/NOTE-datetime
    This method is thread safe.

    Parameters:
    date - the date to format.
    Returns:
    a String with the formated date.
    See Also:
    DateUtil.parseW3cDate(String)

    parseW3cDate

    @Deprecated
    public static Date parseW3cDate(String source)
    Deprecated. Use DateUtil.parseW3cDate(String) instead

    Returns the date parsed from the given string with the W3C Date Time format (eg 1999-01-01T14:07:00+01:00).
    For more details, see http://www.w3.org/TR/NOTE-datetime
    This method is thread safe.

    Parameters:
    source - the string to be parsed
    Returns:
    a Date
    Since:
    jcms-5.7.2
    See Also:
    DateUtil.formatW3cDate(Date)

    formatRfc822Date

    @Deprecated
    public static String formatRfc822Date(Date date)
    Deprecated. Use DateUtil.formatRfc822Date(Date) instead

    Returns a date formated with the RFC 822 Date Time format (eg Fri, 1 Jan 1999 14:07:00 +0100). For more details, see http://www.w3.org/Protocols/rfc822/rfc822.txt section 5.1
    This method is thread safe.

    Parameters:
    date - the date to format.
    Returns:
    a String with the formated date.

    parseRfc822Date

    @Deprecated
    public static Date parseRfc822Date(String source)
    Deprecated. Use DateUtil.parseRfc822Date(String) instead

    Returns the date parsed from the given string with the RFC 822 Date Time format (eg "Fri, 1 Jan 1999 14:07:00 +0100"). http://www.w3.org/Protocols/rfc822/rfc822.txt section 5.1
    This method is thread safe.

    Parameters:
    source - the string to be parsed
    Returns:
    a Date
    Since:
    jcms-5.7.2

    formatNoSpaceDate

    @Deprecated
    public static String formatNoSpaceDate(Date date)
    Deprecated. Use DateUtil.formatNoSpaceDate(Date) instead

    Returns a date formated with the following Date Time format: yyyy-MM-dd_hh-mm-ss
    This method is thread safe.

    Parameters:
    date - the date to format.
    Returns:
    a String with the formated date.
    Since:
    jcms-5.0.2

    parseNoSpaceDate

    @Deprecated
    public static Date parseNoSpaceDate(String source)
    Deprecated. Use DateUtil.parseNoSpaceDate(String) instead

    Returns the date parsed from the given string with the following Date Time format: yyyy-MM-dd_hh-mm-ss
    This method is thread safe.

    Parameters:
    source - the string to be parsed
    Returns:
    a Date
    Since:
    jcms-5.7.2

    isToday

    @Deprecated
    public static boolean isToday(Date date)
    Deprecated. Use DateUtil.isToday(Date) instead

    Check if a given date is the same day as today (from 0h00 included to 0h00 excluded)

    Parameters:
    date - the date to check
    Returns:
    true if the given date is today

    isYesterday

    @Deprecated
    public static boolean isYesterday(Date date)
    Deprecated. Use DateUtil.isYesterday(Date) instead

    Check if a given date is the same day as yesterday (from 0h00 included to 0h00 excluded)

    Parameters:
    date - the date to check
    Returns:
    true if the given date is yesterday
    Since:
    jcms-6.0.1

    isTomorrow

    @Deprecated
    public static boolean isTomorrow(Date date)
    Deprecated. Use DateUtil.isTomorrow(Date) instead

    Check if a given date is the same day as tomorrow (from 0h00 included to 0h00 excluded)

    Parameters:
    date - the date to check
    Returns:
    true if the given date is tomorrow
    Since:
    jcms-6.0.1

    isSameDay

    @Deprecated
    public static boolean isSameDay(Date date1,
                                               Date date2)
    Deprecated. Use DateUtil.isSameDay(Date,Date) instead

    Check if the 2 given dates are the same day (from 0h00 included to 0h00 excluded)

    Parameters:
    date1 - the first date to check
    date2 - the second date to check
    Returns:
    true if the given date is today
    Since:
    jcms-6.0.1

    hasAppenderDefined

    public static boolean hasAppenderDefined(org.apache.log4j.Logger logger)
    Checks if the given Logger has any appender defined.

    Parameters:
    logger - the Logger to check
    Returns:
    true if logger has any appender defined, false otherwise
    Since:
    jcms-5.0.5

    getNewDateWithoutMillis

    @Deprecated
    public static Date getNewDateWithoutMillis()
    Deprecated. Use DateUtil.getNewDateWithoutMillis() instead

    Returns the current date with milliseconds reset to 0.

    Returns:
    the current date with milliseconds reset to 0.
    Since:
    jcms-6.0.0

    validateRegexp

    public static boolean validateRegexp(String regexp)
    Tell if a String is a valid Perl 5 regexp.

    Parameters:
    regexp - The pattern to validate
    Returns:
    true if it is a valid Perl 5 syntax
    Since:
    JCMS-6.0

    reduceBlankLines

    public static String reduceBlankLines(String text)
    Right trim all the lines in the message and reduced many CRLF to only one line.

    Parameters:
    text - the original text
    Returns:
    the text, right trimed and with less line feed.

    randomString

    public static String randomString(int length)

    exec

    public static int exec(String... cmdarray)
                    throws IOException,
                           InterruptedException
    Executes the specified command and arguments in a separate process.

    Parameters:
    cmdarray - array containing the command to call and its arguments.
    Throws:
    IOException
    InterruptedException
    Since:
    jcms-6.1.2

    exec

    public static int exec(String[] cmdarray,
                           OutputStream stdout,
                           OutputStream stderr)
                    throws IOException,
                           InterruptedException
    Executes the specified command and arguments in a separate process.

    Parameters:
    cmdarray - array containing the command to call and its arguments.
    stdout - the OutputStream for stdout (ignored if null)
    stderr - the OutputStream for stderr (ignored if null)
    Throws:
    IOException
    InterruptedException
    Since:
    jcms-6.1.2

    exec

    public static int exec(String[] cmdarray,
                           StringBuilder stdout,
                           StringBuilder stderr)
                    throws IOException,
                           InterruptedException
    Executes the specified command and arguments in a separate process.

    Parameters:
    cmdarray - array containing the command to call and its arguments.
    stdout - the result of the stdout (ignored if null)
    stderr - the result of the stderr (ignored if null)
    Throws:
    IOException
    InterruptedException
    Since:
    jcms-6.1.2


    Copyright © 2001-2010 Jalios SA. All Rights Reserved.