com.cbse.jeasy
Class JEUtil

java.lang.Object
  extended by com.cbse.jeasy.JEUtil

public class JEUtil
extends java.lang.Object

A few basic functions used by the JEObjects.

Version:
%I%, %G%
Author:
H.P.

Field Summary
static java.util.Comparator stringCmp
          A Comperator used for sorting a list.
 
Constructor Summary
JEUtil()
           
 
Method Summary
static java.awt.Point adjustLocationToScreen(java.awt.Component cmp, int xposition, int yposition)
          To position a component always inside the screen.
 byte[] compress(byte[] ba)
           
 byte[] compress(byte[] ba, javax.crypto.Cipher ec)
           
 byte[] compress(java.lang.String s)
           
 byte[] compress(java.lang.String s, javax.crypto.Cipher ec)
           
static boolean copyFile(java.lang.String source, java.lang.String destination)
          copy a file
 void customizeObject(java.lang.String s)
          An easy XML interface to customize JEasy objects.
 byte[] decompress(byte[] ba)
           
 java.lang.String decompress(java.io.InputStream in)
           
 java.lang.String decompress(java.io.InputStream in, javax.crypto.Cipher dc)
           
 byte[] decrypt(byte[] ba, javax.crypto.Cipher decryptCipher)
           
static boolean deleteFile(java.lang.String source)
          delete a file or (empty) directory
 byte[] encrypt(byte[] ba, javax.crypto.Cipher encryptCipher)
           
static boolean existsFile(java.lang.String source)
          tests if a file exists
static java.lang.String f2str(java.lang.String source)
          Reads a file into a String
static java.lang.String getDateTime()
          Gets a formatted date time in format yyyy-MM-dd HH:mm:ss.S
static java.lang.String getDateTime(java.lang.String format)
          Gets a formatted date time String Example yyyy-MM-dd HH:mm:ss.S --> 2006-11-26 17:13:26.143
static java.lang.String getFormattedSum(java.util.Vector v)
          Reads Strings of a vector and tries to build a formattad sum The method should build a sum out of formatted values and a String behind example 1.234,56 EUR or 1,234.56 $
static java.util.Hashtable getHashtable()
          Gets the static Hashtable
static JEObject getJO(java.lang.String s)
          Gets a jeasy object out of the hashtable und prints a warning out of the console
static JEObject getJO(java.lang.String s, boolean quiet)
          Gets a jeasy object out of the hashtable und prints a warning out of the console if quiet is false
static javax.swing.JLayeredPane getLayeredPane()
          Gets the JLayeredPane of the main frame
static java.lang.String getMemory()
           
static java.lang.String getMemory(java.lang.String label)
          Gets the used memorys
static JECallBack getRegisteredJECallBack(java.lang.String jeasyId)
          Gets the JECallBack object that is registered to the given JEasy object or his parent
static javax.swing.JRootPane getRootPane()
          Gets the JRootpane of the main frame or if it is an applet of the main panel
static java.util.Vector getSeparatedList(java.util.Vector v, java.lang.String entries, java.lang.String separator)
          Appends the entries out of a string separated by separator string to a vector or creates a new vector
static java.lang.String getXMLElement(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Element inside and
static java.lang.String[] getXMLElementArray(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Elements and returns a String array
static java.lang.String getXMLElementAttribute(java.lang.String source, java.lang.String attribut)
          Parses the String for the attribut (attribut="value") inside the the given String inside
static java.lang.String getXMLElementAttribute(java.lang.String source, java.lang.String element, java.lang.String attribut)
          Parses the String for the attribut inside the the given XML-Element inside
static java.lang.String getXMLElementByAttributeValue(java.lang.String source, java.lang.String element, java.lang.String attribute, java.lang.String value)
          Parses the String for the given XML-Elements.
static java.lang.String getXMLElementNoReplace(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Element inside and without replacing XML entities
static java.util.Vector getXMLElementVector(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag
static java.util.Vector getXMLElementVectorNoReplace(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag The special charcters begunning with &...; are not replaced
static java.util.Vector getXMLTagVector(java.lang.String source, java.lang.String tagname)
          Parses the String for the given XML-Tagname and returns a vector with a string containing the starttag with attributes, the element and the endtag
static java.util.Vector getXMLVector(java.lang.String source, java.lang.String tag, java.lang.String innerTag)
          Searches the source for the element with the given tag and parses it for the given XML-Elements innertag and returns a vector with all text between the start-innertag and the end-innertag
static java.lang.Object invoke(JEObject jo, java.lang.String function, java.lang.Object[] oa)
           
static java.lang.Object invokeAll(JEObject jeo, java.lang.String function, java.lang.Object[] oa, java.lang.Object until)
          Invokes a method for all components of an object until return equals "until"
static java.lang.String is2s(java.io.InputStream is)
          Reads an InputStream into a String and appends a after each line
static java.lang.String isr2str(java.io.InputStreamReader isr)
          Reads all char out of an InputStreamReader to a string
static java.lang.String it(java.lang.String tag, java.lang.String value)
          returns an xml element with tag and value
static java.lang.String itt(java.lang.String tag, java.lang.String value)
          returns an xml element with tag and value if value !
static java.lang.String itv(java.lang.String tagroot, java.lang.String tagelement, java.util.Vector v)
          returns an xml element with tagroot and a number of tagelement containig the string in the vector
static java.lang.String l2s(java.io.BufferedReader din, java.lang.String end)
          Reads lines in din until end was found.
static java.lang.String l2s(java.io.BufferedReader din, java.lang.String end, java.lang.String separator)
          Reads lines in din until end was found.
static void log(char d, java.lang.String method, java.lang.String id, java.lang.String text)
           
static boolean messageMatch(java.lang.String searchmessage, java.lang.String message)
          Searches the string search in the source and gives the following chars until the seperator back as a string
static boolean moveFile(java.lang.String source, java.lang.String destination)
          move a file
static java.util.Hashtable newHashtable()
          Creates the static Hashtable
static java.awt.Color parseColor(java.lang.String hexcolor)
          parse a hexstring into a Color
static int readJEObj(java.io.BufferedReader din, java.util.Hashtable oht)
          Reads out of din all JEObject.
static java.lang.String regardLocale(java.lang.String message, java.lang.String locale)
          Excludes all locales exclude the given locale out of the message
static boolean registerJECallBack(JECallBack jeCallBack, java.lang.String jeasyId)
          Registers a JECallBack to a JEasyId.
static java.lang.String removeLocales(java.lang.String message)
           
static boolean renameFile(java.lang.String source, java.lang.String destination)
          rename a file
static java.lang.String replace(java.lang.String target, java.lang.String from, java.lang.String to)
          replaces String in String
static java.lang.String replaceTagId(java.lang.String source, java.lang.String tag, java.lang.String id, java.lang.String newString)
          replaces the tag tag with the tag id inside with newString and copys all tag after the root tag ...
static java.lang.String replaceXMLGeneralEntities(java.lang.String s, boolean b)
          replaces general XML entities in a String
static java.util.Vector replaceXMLGeneralEntities(java.util.Vector v, boolean b)
          replaces general XML entities in a Vector containing String
static java.lang.String separateLocales(JEObject jeo, java.lang.String message)
          Separates a JEObject xml message in a part without any locale properties and returns this xml message.
static java.util.Hashtable setHashtable(java.util.Hashtable poht)
          Sets the static Hashtable
static boolean str2f(java.lang.String source, java.lang.String destination)
          copy a String to a file
static boolean writeFile(java.lang.String s, java.lang.String destination)
          writes a file
static java.lang.Object XMLMethodInvocation(java.lang.Object object, java.lang.String xmi)
          Invokes a method defined in the XML-String xmi of the given Object object
static java.lang.Object XMLMethodInvocation(java.lang.String xmi)
          Invokes a method of an JEasyObject out of an XML string.
static boolean XMLVectorMatch(java.util.Vector v_search, java.util.Vector v_tags)
          Matching of two Vectors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringCmp

public static java.util.Comparator stringCmp
A Comperator used for sorting a list. Example: Collections.sort(list, JEUtil.stringCmp);

Constructor Detail

JEUtil

public JEUtil()
Method Detail

XMLMethodInvocation

public static java.lang.Object XMLMethodInvocation(java.lang.String xmi)
Invokes a method of an JEasyObject out of an XML string. See JEMethodinvocation for description of the XML string If the given methodid (tagname id) exists in the hashtable built from the initial XML-File, the parameters JEObject, method, param1Class, param1value, ... are filled first out of the JEMethodinvocation object in the hashtable. If the same parameters are defined in the string xmi the entries will override the initial values. If no methodid is define all parameters for the specified method have to be defined in the string xmi

Parameters:
xmi - XML-String

XMLMethodInvocation

public static java.lang.Object XMLMethodInvocation(java.lang.Object object,
                                                   java.lang.String xmi)
Invokes a method defined in the XML-String xmi of the given Object object

Parameters:
obj - object where the method is implemented
xmi - XML-String that defines the method and params

getRootPane

public static javax.swing.JRootPane getRootPane()
Gets the JRootpane of the main frame or if it is an applet of the main panel

Returns:

getLayeredPane

public static javax.swing.JLayeredPane getLayeredPane()
Gets the JLayeredPane of the main frame

Returns:

getXMLElement

public static java.lang.String getXMLElement(java.lang.String source,
                                             java.lang.String element)
Parses the String for the given XML-Element inside and

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getXMLElementNoReplace

public static java.lang.String getXMLElementNoReplace(java.lang.String source,
                                                      java.lang.String element)
Parses the String for the given XML-Element inside and without replacing XML entities

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getXMLElementByAttributeValue

public static java.lang.String getXMLElementByAttributeValue(java.lang.String source,
                                                             java.lang.String element,
                                                             java.lang.String attribute,
                                                             java.lang.String value)
Parses the String for the given XML-Elements. If the element has the attribute and the value the element will be returned

Parameters:
source - the string where it will be searched
element - the XML element to look for
attribute - the attibute the element must have
value - and its value
Returns:
the XML string matching element , attribute and value

getXMLElementAttribute

public static java.lang.String getXMLElementAttribute(java.lang.String source,
                                                      java.lang.String element,
                                                      java.lang.String attribut)
Parses the String for the attribut inside the the given XML-Element inside

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getXMLElementAttribute

public static java.lang.String getXMLElementAttribute(java.lang.String source,
                                                      java.lang.String attribut)
Parses the String for the attribut (attribut="value") inside the the given String inside

Parameters:
source - the string where it will be searched
Returns:
the string inside the tag or null

getXMLElementArray

public static java.lang.String[] getXMLElementArray(java.lang.String source,
                                                    java.lang.String element)
Parses the String for the given XML-Elements and returns a String array

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the Vector of found strings between the tag element

getXMLTagVector

public static java.util.Vector getXMLTagVector(java.lang.String source,
                                               java.lang.String tagname)
Parses the String for the given XML-Tagname and returns a vector with a string containing the starttag with attributes, the element and the endtag

Parameters:
source - the string where it will be searched
tagname - the XML tagname to look for
Returns:
the Vector of found strings including the tags

getXMLVector

public static java.util.Vector getXMLVector(java.lang.String source,
                                            java.lang.String tag,
                                            java.lang.String innerTag)
Searches the source for the element with the given tag and parses it for the given XML-Elements innertag and returns a vector with all text between the start-innertag and the end-innertag

Parameters:
source - the string where it will be searched
tag - the XML element to look for
innerTag - the XML element given back as a Vector
Returns:

getXMLElementVectorNoReplace

public static java.util.Vector getXMLElementVectorNoReplace(java.lang.String source,
                                                            java.lang.String element)
Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag The special charcters begunning with &...; are not replaced

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the Vector of found strings between the tag element

getXMLElementVector

public static java.util.Vector getXMLElementVector(java.lang.String source,
                                                   java.lang.String element)
Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the Vector of found strings between the tag element

XMLVectorMatch

public static boolean XMLVectorMatch(java.util.Vector v_search,
                                     java.util.Vector v_tags)
Matching of two Vectors

Parameters:
source - the string where it will be searched
Returns:
the vector

messageMatch

public static boolean messageMatch(java.lang.String searchmessage,
                                   java.lang.String message)
Searches the string search in the source and gives the following chars until the seperator back as a string

Parameters:
source - the string where it will be searched
search - the string to look for
separator - the string to look for
Returns:
the string is filled from the end of search until the first occurance of the separator.

getFormattedSum

public static java.lang.String getFormattedSum(java.util.Vector v)
Reads Strings of a vector and tries to build a formattad sum The method should build a sum out of formatted values and a String behind example 1.234,56 EUR or 1,234.56 $


is2s

public static java.lang.String is2s(java.io.InputStream is)
Reads an InputStream into a String and appends a

after each line


l2s

public static java.lang.String l2s(java.io.BufferedReader din,
                                   java.lang.String end)
                            throws java.io.IOException
Reads lines in din until end was found. Comments after // are ignored. White spaces from both ends of the lines will be removed.

Parameters:
din - read by readLine()
end - terminates reading
Returns:
the string containing the lines
Throws:
java.io.IOException

l2s

public static java.lang.String l2s(java.io.BufferedReader din,
                                   java.lang.String end,
                                   java.lang.String separator)
                            throws java.io.IOException
Reads lines in din until end was found. Comments after // are ignored. White spaces from both ends of the lines will be removed.

Parameters:
din - read by readLine()
end - terminates reading
Returns:
the string containing the lines separated by separator
Throws:
java.io.IOException

log

public static void log(char d,
                       java.lang.String method,
                       java.lang.String id,
                       java.lang.String text)

newHashtable

public static java.util.Hashtable newHashtable()
Creates the static Hashtable

Returns:
a new Hashtable

getHashtable

public static java.util.Hashtable getHashtable()
Gets the static Hashtable

Returns:
the Hashtable

setHashtable

public static java.util.Hashtable setHashtable(java.util.Hashtable poht)
Sets the static Hashtable

Returns:
the Hashtable

getJO

public static JEObject getJO(java.lang.String s)
Gets a jeasy object out of the hashtable und prints a warning out of the console

Parameters:
name - Meldung

getJO

public static JEObject getJO(java.lang.String s,
                             boolean quiet)
Gets a jeasy object out of the hashtable und prints a warning out of the console if quiet is false

Parameters:
name - Meldung

getDateTime

public static java.lang.String getDateTime(java.lang.String format)
Gets a formatted date time String Example yyyy-MM-dd HH:mm:ss.S --> 2006-11-26 17:13:26.143

Parameters:
format -
Returns:

getDateTime

public static java.lang.String getDateTime()
Gets a formatted date time in format yyyy-MM-dd HH:mm:ss.S

Parameters:
format -
Returns:

isr2str

public static java.lang.String isr2str(java.io.InputStreamReader isr)
Reads all char out of an InputStreamReader to a string

Returns:
string

invokeAll

public static java.lang.Object invokeAll(JEObject jeo,
                                         java.lang.String function,
                                         java.lang.Object[] oa,
                                         java.lang.Object until)
Invokes a method for all components of an object until return equals "until"


parseColor

public static java.awt.Color parseColor(java.lang.String hexcolor)
parse a hexstring into a Color


invoke

public static java.lang.Object invoke(JEObject jo,
                                      java.lang.String function,
                                      java.lang.Object[] oa)

it

public static java.lang.String it(java.lang.String tag,
                                  java.lang.String value)
returns an xml element with tag and value

Parameters:
tag -
value -
Returns:

itt

public static java.lang.String itt(java.lang.String tag,
                                   java.lang.String value)
returns an xml element with tag and value if value != ""

Parameters:
tag -
value -
Returns:

itv

public static java.lang.String itv(java.lang.String tagroot,
                                   java.lang.String tagelement,
                                   java.util.Vector v)
returns an xml element with tagroot and a number of tagelement containig the string in the vector

Parameters:
tagroot -
tagelement -
v -
Returns:

readJEObj

public static int readJEObj(java.io.BufferedReader din,
                            java.util.Hashtable oht)
                     throws java.io.IOException
Reads out of din all JEObject. They will be created by there constructor. The id and the JEObject will be put to the static Hashtable

Returns:
0
Throws:
java.io.IOException - when reading out of din is not possible
See Also:

replace

public static java.lang.String replace(java.lang.String target,
                                       java.lang.String from,
                                       java.lang.String to)
replaces String in String

Parameters:
s - String which is to be parsed
old - String which will be replaced by
Returns:
new String

replaceXMLGeneralEntities

public static java.lang.String replaceXMLGeneralEntities(java.lang.String s,
                                                         boolean b)
replaces general XML entities in a String

Parameters:
s - xml-String which is to be parsed and whose xml entities are to be replaced
b - true special characters are replaced by the entity, false the entities are replaced by the special characters
Returns:
the new String

replaceXMLGeneralEntities

public static java.util.Vector replaceXMLGeneralEntities(java.util.Vector v,
                                                         boolean b)
replaces general XML entities in a Vector containing String

Parameters:
v - Vector containing string-objects to be parsed and and whose xml entities are to be replaced
b - true special characters are replaced by the entity, false the entities are replaced by the special characters
Returns:
a new Vector containing the new Strings

existsFile

public static boolean existsFile(java.lang.String source)
tests if a file exists

Parameters:
source - source-file
Returns:
boolean true if the file exists false otherwise

copyFile

public static boolean copyFile(java.lang.String source,
                               java.lang.String destination)
copy a file

Parameters:
source - source-file
destination - destination-file
Returns:
boolean true if the file could be copied false otherwise

writeFile

public static boolean writeFile(java.lang.String s,
                                java.lang.String destination)
writes a file

Parameters:
data - string to write
destination - destination-file
Returns:
boolean true if the file could be copied false otherwise

str2f

public static boolean str2f(java.lang.String source,
                            java.lang.String destination)
copy a String to a file

Parameters:
source - String
destination - destination-file
Returns:
boolean true if the file could be copied false otherwise

deleteFile

public static boolean deleteFile(java.lang.String source)
delete a file or (empty) directory

Parameters:
source - source-file
Returns:
boolean true if the file could be deleted or no file was found false otherwise

moveFile

public static boolean moveFile(java.lang.String source,
                               java.lang.String destination)
move a file

Parameters:
source - source-file
destination - destination-file
Returns:
boolean true if the file could be removed false otherwise

renameFile

public static boolean renameFile(java.lang.String source,
                                 java.lang.String destination)
rename a file

Parameters:
source - source-file
destination - destination-file
Returns:
boolean true if the file could be renamed false otherwise

f2str

public static java.lang.String f2str(java.lang.String source)
Reads a file into a String

Parameters:
file - file
Returns:
String file as a String or null if file couldn't be read

replaceTagId

public static java.lang.String replaceTagId(java.lang.String source,
                                            java.lang.String tag,
                                            java.lang.String id,
                                            java.lang.String newString)
replaces the tag tag with the tag id inside with newString and copys all tag after the root tag ...id...... --> newString

Parameters:
source - String where to replace
tag - tagname to replace
id - the id of the tag id
newString - the String wich replaces the old

customizeObject

public void customizeObject(java.lang.String s)
An easy XML interface to customize JEasy objects.

It should be used to change properties of jeasy objects. You define the jeasy object the propertie and the value. The method will perform the setting of the propertie. You may define the customize string as a JEString object in JEasy or read it out of a file. The example explains the syntax:

         <custom>
 
<id>JEasyObjectId</id>
<method>methodname</method>
<param>String</param>
<method>methodname</method>
<param>true|false</param>
</custom>
Example:
<pre><custom>
<id>DF_Name</id>
<method>setText</method>
<param>Miller</param>
<method>setEnabled</method>
<param>false</param>
</custom>
</pre>


separateLocales

public static java.lang.String separateLocales(JEObject jeo,
                                               java.lang.String message)
Separates a JEObject xml message in a part without any locale properties and returns this xml message. The locale properties are stored in the variable objLocal

Parameters:
jeo -
message -
Returns:

regardLocale

public static java.lang.String regardLocale(java.lang.String message,
                                            java.lang.String locale)
Excludes all locales exclude the given locale out of the message

Parameters:
message -
locale -
Returns:
the message except of all locales that are not the given locale

removeLocales

public static java.lang.String removeLocales(java.lang.String message)

compress

public byte[] compress(byte[] ba,
                       javax.crypto.Cipher ec)
                throws java.lang.Exception
Throws:
java.lang.Exception

compress

public byte[] compress(java.lang.String s)
                throws java.lang.Exception
Throws:
java.lang.Exception

compress

public byte[] compress(java.lang.String s,
                       javax.crypto.Cipher ec)
                throws java.lang.Exception
Throws:
java.lang.Exception

decompress

public java.lang.String decompress(java.io.InputStream in)
                            throws java.lang.Exception
Throws:
java.lang.Exception

decompress

public java.lang.String decompress(java.io.InputStream in,
                                   javax.crypto.Cipher dc)
                            throws java.lang.Exception
Throws:
java.lang.Exception

compress

public byte[] compress(byte[] ba)

decompress

public byte[] decompress(byte[] ba)

decrypt

public byte[] decrypt(byte[] ba,
                      javax.crypto.Cipher decryptCipher)
               throws java.lang.Exception
Throws:
java.lang.Exception

encrypt

public byte[] encrypt(byte[] ba,
                      javax.crypto.Cipher encryptCipher)
               throws java.lang.Exception
Throws:
java.lang.Exception

registerJECallBack

public static boolean registerJECallBack(JECallBack jeCallBack,
                                         java.lang.String jeasyId)
Registers a JECallBack to a JEasyId.

Parameters:
jeCallBack -
jeasyId -
Returns:

getRegisteredJECallBack

public static JECallBack getRegisteredJECallBack(java.lang.String jeasyId)
Gets the JECallBack object that is registered to the given JEasy object or his parent

Parameters:
jeCallBack -
jeasyId -
Returns:

getSeparatedList

public static java.util.Vector getSeparatedList(java.util.Vector v,
                                                java.lang.String entries,
                                                java.lang.String separator)
Appends the entries out of a string separated by separator string to a vector or creates a new vector

Parameters:
v -
entries -
separator -
Returns:

getMemory

public static java.lang.String getMemory()

getMemory

public static java.lang.String getMemory(java.lang.String label)
Gets the used memorys

Parameters:
label -

adjustLocationToScreen

public static java.awt.Point adjustLocationToScreen(java.awt.Component cmp,
                                                    int xposition,
                                                    int yposition)
To position a component always inside the screen.

Parameters:
cmp - Component to show
xposition - desired x position
yposition - desired y position
Returns: