www.element4solution.com

e4s.util
Class E4Util

java.lang.Object
  extended by e4s.util.E4Object
      extended by e4s.util.E4Util

public class E4Util
extends E4Object

General utility functionality.

Since:
JDK 1.4

Field Summary
 
Fields inherited from class e4s.util.E4Object
CRLF, E4S_CORE_SYSTEM_LANGUAGE, NBSP, NULLSTR, URL_ENCODING_CHARSET
 
Constructor Summary
E4Util()
           
 
Method Summary
static java.lang.String _decodeHtml(E4String s)
          Decode a string by replacing ä, ö, ü, Ä, Ö, Ü, SS, > ... to ä,ö,ü,Ä,Ö,Ü,ß,..
static java.lang.String _decodeHtml(java.lang.String s)
          Decode a string by replacing ä, ö, ü, Ä, Ö, Ü, SS, > ... to ä,ö,ü,Ä,Ö,Ü,ß,..
static java.lang.String _encodeHtml(E4String s)
          Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!
static java.lang.String _encodeHtml(java.lang.String s)
          Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!
static java.lang.String _encodeHtml(java.lang.String s, boolean escape_tags)
          Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!
static java.lang.String _getSVNVersionString()
           
static java.lang.String changeFileExtension(java.lang.String filename, java.lang.String ext)
          Change the extension of a filename, e.g. changeFileExtension("c:/myfile.doc","bak") returns "c:/myfile.bak".
static void clearTimeElements(java.util.Date d)
          Clear the date fields for hours, minutes, seconds and milliseconds.
static java.lang.String concatenatePath(E4String a, E4String b)
           
static java.lang.String concatenatePath(E4String a, E4StringImage b)
           
static java.lang.String concatenatePath(E4String a, java.lang.String b)
           
static java.lang.String concatenatePath(java.lang.String a, E4String b)
           
static java.lang.String concatenatePath(java.lang.String a, E4StringImage b)
           
static java.lang.String concatenatePath(java.lang.String a, java.io.File b)
          Concatenate a path by using the file name (File.getName()).
static java.lang.String concatenatePath(java.lang.String a, java.lang.String b)
          Concatenate two strings and treat them as OS-path notations.
static java.lang.String concatenatePath(java.lang.String a, java.lang.String b, java.lang.String c)
          Concatenate three strings and treat them as OS-path notations.
static boolean copyFile(java.io.File sourcefile, java.io.File destfile)
          Copy one single files, do not overwrite existing newer files.
static boolean copyFile(java.io.File sourcefile, java.io.File destfile, boolean ignoredate)
          Copy one single files
static boolean copyFile(java.lang.String sourcefile, java.lang.String destfile)
          Copy one single files, do not overwrite existing newer files.
static boolean copyFile(java.lang.String sourcefile, java.lang.String destfile, boolean ignoredate)
          Copy one single files
static java.lang.String Cr2Br(java.lang.String s)
          Replace CR by HTML tag <BR>.
static java.lang.String cut(java.lang.String s, int len)
          Deprecated. Use e4string#cut(String,int) instead
static java.lang.String empty2nbsp(java.lang.String s)
          Test a String, if it is null or blank (except blanks) then return a value of "&npsp;" or otherwise the String itself.
static java.lang.String escapeTag(java.lang.String s)
          Remove any HTML tags from given String, and replace them by < or >.
static java.lang.String fixed(E4String str, int len)
           
static java.lang.String fixed(java.lang.String str, int len)
          Deprecated. Use e4string#fixed(String,int) instead
static java.lang.String format(E4Long n, int places)
          Deprecated. Use E4Long.format(E4Long,int) instead
static java.lang.String format(long n, int places)
          Deprecated. Use E4Long.format(long,int) instead
static java.lang.String getClassBaseName(java.lang.Class clazz)
          Gets the base name for a class by removing the package information if available.
static long getFreeMemory()
          Get free memory.
static long getMaxMemory()
          Get max memory.
static java.lang.reflect.Field[] getNonStaticVisibleFields(java.lang.Class clazz, boolean include_arrays)
          Get all fields of the given Class that are declared public, not final and not static.
static int getRevisionCodeFromSVN(java.lang.Class clazz)
          Try to call "public static String _getSVNVersionString()" within the spezified class.
static int getRevisionCodeFromSVN(java.lang.String s)
          If String is in the format "$LastChangedRevision: 6155 $" then the revision is returned as a code.
static long getTotalMemory()
          Get total memory.
static boolean hasInterface(java.lang.Class clazz, java.lang.Class testclass)
           
static boolean isClass(java.lang.Class clazz, java.lang.Class compare)
          Similar to Object instanceof Object, works with classes
static java.lang.String left(java.lang.String s, int chars)
          Deprecated.  
static java.lang.String[] listFilesRecursivley(java.lang.String path)
          Get a list of files in a specified path by running recursivley throught all sub directories.
static java.lang.String[] listFilesRecursivley(java.lang.String path, java.lang.String extension)
          Get a list of files in a specified path by running recursivley throught all sub directories.
static java.lang.String makePath(java.lang.String path)
          Append a slash if required.
static org.xml.sax.XMLReader makeXMLReader()
          Create a XML reader.
static void mkdir(java.io.File fname)
          Make a directory for the specified filename (not a path-name !).
static void mkdir(java.lang.String fname)
          Make a directory for the specified filename (not a path-name !).
static void removeDirectories(java.io.File path)
          Goes recursivley throught each folder and removes all files and folders.
static void removeDirectories(java.lang.String path)
          Goes recursivley throught each folder and removes all files and folders.
static java.lang.String toString(org.xml.sax.SAXParseException spe)
           
 
Methods inherited from class e4s.util.E4Object
Calendar, CName, CName, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelSys, E4LabelSys, e4sCopyright, e4sVersion, encode, encode, encode, encodeHtml, encodeHtml, encodeHtml, encodeURL, encodeURL, encodeURL, finalize, getLINE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTraceMemory, HtmlEncode, HtmlEncode, HtmlEncode, isdecimal, isdigit, isnotok, isnotok, isnumeric, isok, isok, isok, isok, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingStack, mkdirs, null2nbsp, null2nbsp, null2nbsp, ok, ok, ok, ok, outPrintln, setLogFile4Trace, setTraceMemory, STACKTRACE, toDebug, toDouble, toFloat, toFloat, toString, TRACE_CALLS, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, wait
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

E4Util

public E4Util()
Method Detail

isClass

public static boolean isClass(java.lang.Class clazz,
                              java.lang.Class compare)
Similar to Object instanceof Object, works with classes

Parameters:
clazz - Class to compare with
compare - Class to compare to
Returns:
true, if clazz.getName() == compare.getName()

hasInterface

public static boolean hasInterface(java.lang.Class clazz,
                                   java.lang.Class testclass)

makeXMLReader

public static final org.xml.sax.XMLReader makeXMLReader()
                                                 throws javax.xml.parsers.ParserConfigurationException,
                                                        org.xml.sax.SAXException
Create a XML reader.

Returns:
the new created reader
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException

Cr2Br

public static java.lang.String Cr2Br(java.lang.String s)
Replace CR by HTML tag <BR>.

Parameters:
s - the string to replace.
Returns:
the string with <BR> instead CR, or null if s == null
See Also:
E4Object.CRLF

escapeTag

public static java.lang.String escapeTag(java.lang.String s)
Remove any HTML tags from given String, and replace them by < or >.

Parameters:
s - the String where replacements need to be done
Returns:
null if s was null, String with all < and > replaced.

empty2nbsp

public static java.lang.String empty2nbsp(java.lang.String s)
Test a String, if it is null or blank (except blanks) then return a value of "&npsp;" or otherwise the String itself.

Parameters:
s - value to be tested
Returns:
NBSP or the String

_encodeHtml

public static java.lang.String _encodeHtml(E4String s)
Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!

Parameters:
s - the string to be converted
Returns:
null, if s == null or the String with replaces special characters

_encodeHtml

public static java.lang.String _encodeHtml(java.lang.String s)
Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!

Parameters:
s - the string to be converted
Returns:
null, if s == null or the String with replaces special characters
See Also:
_encodeHtml(e4s.util.E4String), _decodeHtml(String)

_encodeHtml

public static java.lang.String _encodeHtml(java.lang.String s,
                                           boolean escape_tags)
Encode a string by replacing ä,ö,ü,Ä,Ö,Ü,ß,>,< to ä, ö, ü, Ä, Ö, Ü, SS, >, < TODO: Note: this is not a complete implementation!

Parameters:
s - the string to be converted
Returns:
null, if s == null or the String with replaces special characters
See Also:
_encodeHtml(e4s.util.E4String), _decodeHtml(String)

_decodeHtml

public static java.lang.String _decodeHtml(E4String s)
Decode a string by replacing ä, ö, ü, Ä, Ö, Ü, SS, > ... to ä,ö,ü,Ä,Ö,Ü,ß,.. TODO: Note: this is not a complete implementation!

Parameters:
s - the string to be converted
Returns:
null, if s == null or the String with replaced special characters
See Also:
_decodeHtml(String)

_decodeHtml

public static java.lang.String _decodeHtml(java.lang.String s)
Decode a string by replacing ä, ö, ü, Ä, Ö, Ü, SS, > ... to ä,ö,ü,Ä,Ö,Ü,ß,.. TODO: Note: this is not a complete implementation!

Parameters:
s - the string to be converted
Returns:
null, if s == null or the String with replaced special characters
See Also:
_decodeHtml(e4s.util.E4String), _encodeHtml(String)

fixed

public static java.lang.String fixed(java.lang.String str,
                                     int len)
Deprecated. Use e4string#fixed(String,int) instead


format

public static java.lang.String format(long n,
                                      int places)
Deprecated. Use E4Long.format(long,int) instead


format

public static java.lang.String format(E4Long n,
                                      int places)
Deprecated. Use E4Long.format(E4Long,int) instead

Format a long using leading '0'.

Parameters:
n - the long to be formatted
places - number of characters (a value between 1 and 30)
Returns:
the formatted value, e.g. format(123,6) returns 000123

fixed

public static java.lang.String fixed(E4String str,
                                     int len)

getNonStaticVisibleFields

public static java.lang.reflect.Field[] getNonStaticVisibleFields(java.lang.Class clazz,
                                                                  boolean include_arrays)
Get all fields of the given Class that are declared public, not final and not static.

Parameters:
clazz - the Class to be analyzed
include_arrays - if true, also include array elements
Returns:
an array of fields matching the above criterias, null if none

concatenatePath

public static java.lang.String concatenatePath(java.lang.String a,
                                               java.lang.String b)
Concatenate two strings and treat them as OS-path notations. Avoid, that two slashes will put together (if a ends with and b starts with) but ensure, that one slash is between the two strings. Can handle / or \ characters.

Parameters:
a - the first (left) part of the path
b - the second (right) part of the path or a file name
Returns:
null, if both are null, a if b is null, b if a is null or the concatenation

concatenatePath

public static java.lang.String concatenatePath(E4String a,
                                               java.lang.String b)

concatenatePath

public static java.lang.String concatenatePath(java.lang.String a,
                                               E4String b)

makePath

public static java.lang.String makePath(java.lang.String path)
Append a slash if required.

Parameters:
a - the first (left) part of the path
Returns:
null, if both are null, a if b is null, b if a is null or the concatenation

concatenatePath

public static java.lang.String concatenatePath(java.lang.String a,
                                               java.io.File b)
Concatenate a path by using the file name (File.getName()).

Parameters:
a - the left part of the path
b - the file whose name becomes the right part of the path
Returns:
the concatenated path
See Also:
concatenatePath(String, String)

concatenatePath

public static java.lang.String concatenatePath(java.lang.String a,
                                               E4StringImage b)

concatenatePath

public static java.lang.String concatenatePath(E4String a,
                                               E4String b)

concatenatePath

public static java.lang.String concatenatePath(E4String a,
                                               E4StringImage b)

concatenatePath

public static java.lang.String concatenatePath(java.lang.String a,
                                               java.lang.String b,
                                               java.lang.String c)
Concatenate three strings and treat them as OS-path notations. Avoid, that two slashes will put together (if a ends with and b starts with) but ensure, that one slash is between the two strings. Can handle / or \ characters.

Parameters:
a - the first (left) part of the path
b - the middle part of the path
c - the second (right) part of the path or a file name
Returns:
null, if both are null, a if b is null, b if a is null or the concatenation

clearTimeElements

public static void clearTimeElements(java.util.Date d)
Clear the date fields for hours, minutes, seconds and milliseconds.

Parameters:
d - the date to be modified

toString

public static java.lang.String toString(org.xml.sax.SAXParseException spe)

getFreeMemory

public static long getFreeMemory()
Get free memory.

Returns:
Runtime.getFreeMemory()
See Also:
getTotalMemory()

getTotalMemory

public static long getTotalMemory()
Get total memory.

Returns:
Runtime.getTotalMemory()
See Also:
getFreeMemory()

getMaxMemory

public static long getMaxMemory()
Get max memory.

Returns:
Runtime.getMaxMemory()
See Also:
getFreeMemory()

copyFile

public static boolean copyFile(java.lang.String sourcefile,
                               java.lang.String destfile)
                        throws java.lang.Exception
Copy one single files, do not overwrite existing newer files.

Parameters:
sourcefile - the source file to be copied from
destfile - the destination file to be copied to
Returns:
true if the file has been copied, false is not (e.g. timestamp o.k.)
Throws:
java.lang.Exception

copyFile

public static boolean copyFile(java.io.File sourcefile,
                               java.io.File destfile)
                        throws java.lang.Exception
Copy one single files, do not overwrite existing newer files.

Parameters:
sourcefile - the source file to be copied from
destfile - the destination file to be copied to
Returns:
true if the file has been copied, false is not (e.g. timestamp o.k.)
Throws:
java.lang.Exception

copyFile

public static boolean copyFile(java.lang.String sourcefile,
                               java.lang.String destfile,
                               boolean ignoredate)
                        throws java.lang.Exception
Copy one single files

Parameters:
sourcefile - the source file to be copied from
destfile - the destination file to be copied to
ignoredate - true: copy file also if the source file is older than the new file
Returns:
true if the file has been copied, false is not (e.g. timestamp o.k.)
Throws:
java.lang.Exception

copyFile

public static boolean copyFile(java.io.File sourcefile,
                               java.io.File destfile,
                               boolean ignoredate)
                        throws java.lang.Exception
Copy one single files

Parameters:
sourcefile - the source file to be copied from
destfile - the destination file to be copied to
ignoredate - true: copy file also if the source file is older than the new file
Returns:
true if the file has been copied, false is not (e.g. timestamp o.k.)
Throws:
java.lang.Exception

mkdir

public static void mkdir(java.io.File fname)
Make a directory for the specified filename (not a path-name !). e.g. mkdir("c:\temp\read.me") would create the directory "c:\temp".

Parameters:
fname - the filename which path shall be created
See Also:
mkdir(String)

mkdir

public static void mkdir(java.lang.String fname)
Make a directory for the specified filename (not a path-name !). e.g. mkdir("c:\temp\read.me") would create the directory "c:\temp".

Parameters:
fname - the filename which path shall be created
See Also:
mkdir(String)

left

public static java.lang.String left(java.lang.String s,
                                    int chars)
Deprecated. 

See Also:
E4String.left(String,int)

cut

public static java.lang.String cut(java.lang.String s,
                                   int len)
Deprecated. Use e4string#cut(String,int) instead


removeDirectories

public static void removeDirectories(java.lang.String path)
Goes recursivley throught each folder and removes all files and folders.

Parameters:
path - the path to be removed (must be an absolute path)
See Also:
removeDirectories(File)

removeDirectories

public static void removeDirectories(java.io.File path)
Goes recursivley throught each folder and removes all files and folders.

Parameters:
path - the path to be removed (must be an absolute path)
See Also:
removeDirectories(String)

changeFileExtension

public static java.lang.String changeFileExtension(java.lang.String filename,
                                                   java.lang.String ext)
Change the extension of a filename, e.g. changeFileExtension("c:/myfile.doc","bak") returns "c:/myfile.bak".

Parameters:
filename - the original filename.
ext - if null, the return value will be the filename truncated before the last point, or extension will be appended to the filename (if ext does not start with a point it will be appended between the truncated filename and the extension)
Returns:
the changed filename or the filename itself if a point couldn't be found

getClassBaseName

public static java.lang.String getClassBaseName(java.lang.Class clazz)
Gets the base name for a class by removing the package information if available. E.g. the base name for "java.util.Date" is "Date".

Parameters:
clazz - is typically a built in or user defined class
Returns:
the class base name

getRevisionCodeFromSVN

public static int getRevisionCodeFromSVN(java.lang.String s)
If String is in the format "$LastChangedRevision: 6155 $" then the revision is returned as a code. For SVN (Subversion), the string will be in a form like "$LastChangedRevision: 1234$" and will be patched when the java source file is checked in to the SVN. This function is used when an error occurs, the stack trace will look for the versions and keep this information within the sent error email to the administrator. Subversion requires a property (in eclipse: Team -> Show Property) which is named "svn:keywords" and the value is something like "LastChangedDate LastChangedRevision LastChangedBy" but at least "LastChangedRevision"

Parameters:
s - the revision code (created by CVS)
Returns:
the revision code if applicable
See Also:
getRevisionCodeFromSVN(Class)

getRevisionCodeFromSVN

public static int getRevisionCodeFromSVN(java.lang.Class clazz)
Try to call "public static String _getSVNVersionString()" within the spezified class. The class is not beeing instanciated, as this function is static. For SVN (Subversion), the string will be in a form like "$LastChangedRevision: 6155 $" and will be patched when the java source file is checked in to the SVN. This function is used when an error occurs, the stack trace will look for the versions and keep this information within the sent error email to the administrator. Subversion requires a property (in eclipse: Team -> Show Property) which is named "svn:keywords" and the value is something like "LastChangedDate LastChangedRevision LastChangedBy" but at least "LastChangedRevision"

Parameters:
clazz - the class to be analysed
Returns:
-1 when the class is not found, or the function is not declared (e.g. missing, not static, not public, different return types, ..), 0 if the function is o.k. but the version string is invalid (see getRevisionCodeFromSVN(String) or the revision code.
See Also:
_getSVNVersionString(), getRevisionCodeFromSVN(String), E4ServletImplementation_Servlet.sendmail(Throwable,String)

listFilesRecursivley

public static java.lang.String[] listFilesRecursivley(java.lang.String path)
Get a list of files in a specified path by running recursivley throught all sub directories. Ignores hidden files and directories.

Parameters:
path - the absolute path to look for files in
Returns:
an array of filenames with their relative names in aspect to the specified path, does not contain directories
See Also:
listFilesRecursivley(String,String)

listFilesRecursivley

public static java.lang.String[] listFilesRecursivley(java.lang.String path,
                                                      java.lang.String extension)
Get a list of files in a specified path by running recursivley throught all sub directories. Ignores hidden files and directories.

Parameters:
path - the absolute path to look for files in
extension - if null takes all files, otherwise only matching file extension (not case-sensitive)
Returns:
an array of filenames with their relative names in aspect to the specified path, does not contain directories
See Also:
listFilesRecursivley(String)

_getSVNVersionString

public static java.lang.String _getSVNVersionString()

www.element4solution.com