de.folt.util
Class OpenTMSSupportFunctions

java.lang.Object
  extended by de.folt.util.OpenTMSSupportFunctions

public class OpenTMSSupportFunctions
extends java.lang.Object


Constructor Summary
OpenTMSSupportFunctions()
           
 
Method Summary
static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String fileName)
          argumentReader reads arguments from a file into a hash table
static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String[] args)
          argumentReader stores a string array which is parameter encoded as key=value in a hash table the behavior is a follows
key starts with - ("-key") then the following string is the value of the key and stores as (key, value)
Exception is if the value after the key starts again with "-" the key is stored as (key, key) in the hash table
otherwise it is stored as (i, string) where i the string is the i-th element in the string array
static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String[] args, boolean combineArgs)
          argumentReader stores a string array which is parameter encoded as key=value in a hash table the behavior is a follows
key starts with - ("-key") then the following string is the value of the key and stores as (key, value)
Exception is if the value after the key starts again with "-" the key is stored as (key, key) in the hash table
otherwise it is stored as (i, string) where i the string is the i-th element in the string array
static void argumentReader(java.lang.String fileName, java.util.Hashtable<java.lang.String,java.lang.String> hashArgs)
          argumentReader reads arguments from a file into a given hash table
static java.lang.String checkUTF8Normal(java.lang.String file)
          checkUTF8Normal checks if an xml file is UTF-8 encoded; looks "encoding=\"UTF-8\""
static java.lang.String convertToDuration(long duration)
          convertToDuration converts a duration to a time string
static boolean copyFile(java.io.File in, java.io.File out)
          copyFile make a copy of a file
static boolean copyFile(java.lang.String inFile, java.lang.String outFile)
          copyFile make a copy of a file
static java.lang.String copyFileToString(java.lang.String filename)
          copyFileToString - copies the content of a file to a string (byte copy usage) encoded as Base64
static boolean copyStringToFile(java.lang.String content, java.lang.String filename)
          copyStringToFile copies a string to a file where the string is base64 encoded
static java.lang.String decodeBASE64(java.lang.String string)
          decodeBASE64 returns a decoded string from a Base64 encoded string
static java.lang.String determineBOMFromFile(java.lang.String file)
          determineBOMFromFile determines the format of a file; return values are:
"UTF-8-Nobom" for a standard xml file UTF-8encoded "UTF-8" Check: (bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) "UTF-16BE" Check: ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) "UTF-16LE" Check: ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) "UTF-32BE" Check: ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) "UTF-32LE" Check: ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) "Nobom" otherwise
static java.lang.String encodeBASE64(java.lang.String string)
          encodeBASE64 returns a string as Base64 encoded string
static java.lang.String exceptionToString(java.lang.Exception e)
          exceptionToString writes the stack trace to a string
static java.lang.String fillParam(java.util.Hashtable hash, java.lang.String type)
          fillParam
 java.util.Vector<java.lang.String> getAllFiles(java.lang.String sourcepath)
          initial method to start getting all files in for a directory and its sub directories
 void getAllRecFiles(java.io.File file, java.lang.String sourcepath)
          Get all the files in the directory (file) specified and its sub directories sourcepath is the start path of file (to determine the absolute pathname for a file
static java.lang.String getArgumentsConcatenationString()
           
static java.lang.String getCallingMethod(int iLevel)
          getCallingMethod
static java.util.Date getCompileDate(java.lang.Class classname)
          getCompileDate get the compile time of a class
static java.lang.String getCurrentDirectory()
          getCurrentDirectory return the current directory
static java.lang.reflect.Method getCurrentMethod()
          getCurrentMethod get the method of the currently executing method
static java.lang.String getCurrentMethodName()
          getCurrentMethodName get the method name of the currently executing method
static java.lang.String getCurrentUser()
          getCurrentUser returns the currently set user = System.getProperty("user.name")
static java.lang.String getDateString()
          getDateString - returns a date formated as 11.08.2008 23:54:23:1234
static java.lang.String getDateStringFine()
          getDateStringFine returns date as 110820082354231234 (see also getDateString)
static java.lang.String[] getItemsFromFile(java.lang.String fileName)
          readLanguageCodesFromFile read the language codes from a file
static java.lang.reflect.Method getMethod(java.lang.String methodName, java.lang.Class classformethod)
          getMethod get the method for a given Class
 java.lang.String getVersionfinal(java.lang.Class classe)
          getVersionfinal from http://stackoverflow.com/questions/1917686/compile-date-and-time
static int iGetThreadNumber(int iMaxThreads)
          iGetThreadNumber returns the number of threads to use min(Runtime.getRuntime().availableProcessors(), iMaxThreads)
static void printParameterInfoFor(java.lang.reflect.Method method)
           
static java.lang.String quoteForCSVSExport(java.lang.String string)
          quoteForCSVSExport quotes a String for CSV export
LF = \n CR = \r tab = \t \ = \\
static java.lang.String quoteForCSVSExport(java.lang.String string, java.lang.String nullValue)
          quoteForCSVSExport quotes a String for CSV export
LF = \n CR = \r tab = \t \ = \\
static java.lang.String readFileIntoString(java.lang.String filename, java.lang.String encoding)
          readFileIntoString reads the contents of a file into a string
static java.util.Vector<java.lang.String> readFileIntoVector(java.lang.String filename, java.lang.String encoding)
          readFileIntoVector
static java.lang.String removeBOMFromFile(java.lang.String file)
          removeBOMFromFile removes the bom indicators from a file; problem is that Java does not handle them correctly but reads them...
static void replaceStringInFile(java.lang.String filename, java.lang.String[] oldPattern, java.lang.String[] replPattern)
          replaceStringInFile replaces a given string from an array with another string array in a file.
static void replaceStringInFile(java.lang.String filename, java.lang.String oldPattern, java.lang.String replPattern)
          replaceStringInFile replaces a given string with another string in a file
static void replaceStringInFile(java.lang.String filename, java.lang.String oldPattern, java.lang.String replPattern, boolean bWritePerLine, java.lang.String unicodeEncoding)
          replaceStringInFile replaces a given string with another string in a file
static void replaceStringInFileMultiLine(java.lang.String filename, java.lang.String oldPattern, java.lang.String replPattern)
          replaceStringInFile replaces a given string with another string in a file using MULTILINE regexp expressions
static byte[] returnBOMFromFile(java.lang.String file)
          Method determines the BOM (Byte Order Mark of a file and returns it
static java.lang.String returnCurrentDate()
          returnCurrentDate
static void setArgumentsConcatenationString(java.lang.String argumentsConcatenationString)
           
static boolean simpleCopyStringToFile(java.lang.String content, java.lang.String filename)
          simpleCopyStringToFile copies a string to a file where the string is base64 encoded
static boolean writeBOMToFile(java.lang.String filename, byte[] bom)
          Write a bom to a file
static void writeToOut(java.io.DataOutputStream out, java.lang.String string)
          writeToOut
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenTMSSupportFunctions

public OpenTMSSupportFunctions()
Method Detail

argumentReader

public static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String fileName)
argumentReader reads arguments from a file into a hash table

Parameters:
fileName - the name of the file containing the arguments
Returns:
a hash table with with arguments

argumentReader

public static void argumentReader(java.lang.String fileName,
                                  java.util.Hashtable<java.lang.String,java.lang.String> hashArgs)
argumentReader reads arguments from a file into a given hash table

Parameters:
fileName - the name of the file containing the arguments
hashArgs - the hash table where to add the arguments

argumentReader

public static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String[] args)
argumentReader stores a string array which is parameter encoded as key=value in a hash table the behavior is a follows
key starts with - ("-key") then the following string is the value of the key and stores as (key, value)
Exception is if the value after the key starts again with "-" the key is stored as (key, key) in the hash table
otherwise it is stored as (i, string) where i the string is the i-th element in the string array

Parameters:
args - a string array which is parameter as described above
Returns:
the arguments in a hash table

argumentReader

public static java.util.Hashtable<java.lang.String,java.lang.String> argumentReader(java.lang.String[] args,
                                                                                    boolean combineArgs)
argumentReader stores a string array which is parameter encoded as key=value in a hash table the behavior is a follows
key starts with - ("-key") then the following string is the value of the key and stores as (key, value)
Exception is if the value after the key starts again with "-" the key is stored as (key, key) in the hash table
otherwise it is stored as (i, string) where i the string is the i-th element in the string array

Parameters:
args - a string array which is parameter as described above
combineArgs - if true then multiple arguments following -key arg1 arg2 arg3 are concatenated into a string "arg1;arg2;arg3" otherwise default behavior (multiple arguments get just a key counter as key
Returns:
the arguments in a hash table

checkUTF8Normal

public static java.lang.String checkUTF8Normal(java.lang.String file)
checkUTF8Normal checks if an xml file is UTF-8 encoded; looks "encoding=\"UTF-8\""

Parameters:
file - the file to check
Returns:
String "UTF-8-Nobom" if UTF-8 xml file, otherwise string "Nobom" otherwise

convertToDuration

public static java.lang.String convertToDuration(long duration)
convertToDuration converts a duration to a time string

Parameters:
duration - the duration time in seconds
Returns:
the time as a string xxh:mm:yys

copyFile

public static boolean copyFile(java.io.File in,
                               java.io.File out)
                        throws java.lang.Exception
copyFile make a copy of a file

Parameters:
inFile - file to be copies
outFile - target file
Returns:
true when successful
Throws:
java.lang.Exception

copyFile

public static boolean copyFile(java.lang.String inFile,
                               java.lang.String outFile)
                        throws java.lang.Exception
copyFile make a copy of a file

Parameters:
inFile - file to be copies
outFile - target file
Returns:
true when successful
Throws:
java.lang.Exception

copyFileToString

public static java.lang.String copyFileToString(java.lang.String filename)
copyFileToString - copies the content of a file to a string (byte copy usage) encoded as Base64

Parameters:
filename - the file to copy to the string
Returns:
the content of the file as a string

copyStringToFile

public static boolean copyStringToFile(java.lang.String content,
                                       java.lang.String filename)
copyStringToFile copies a string to a file where the string is base64 encoded

Parameters:
content - the base64 encoded string
filename - output file name
Returns:

decodeBASE64

public static java.lang.String decodeBASE64(java.lang.String string)
decodeBASE64 returns a decoded string from a Base64 encoded string

Parameters:
string - the encoded string
Returns:
the decoded string

determineBOMFromFile

public static java.lang.String determineBOMFromFile(java.lang.String file)
determineBOMFromFile determines the format of a file; return values are:
 "UTF-8-Nobom" for a standard xml file UTF-8encoded
 "UTF-8"    Check: (bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF))
 "UTF-16BE" Check: ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF))
 "UTF-16LE" Check: ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE))
 "UTF-32BE" Check: ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF))
 "UTF-32LE" Check: ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00))
 "Nobom" otherwise
 

Parameters:
file -
Returns:
the bom of the file as a string indicator

encodeBASE64

public static java.lang.String encodeBASE64(java.lang.String string)
encodeBASE64 returns a string as Base64 encoded string

Parameters:
string - string to encode
Returns:
the encoded string

exceptionToString

public static java.lang.String exceptionToString(java.lang.Exception e)
exceptionToString writes the stack trace to a string

Parameters:
e - - the exception to print
Returns:
the stack trace as string

fillParam

public static java.lang.String fillParam(java.util.Hashtable hash,
                                         java.lang.String type)
fillParam

Parameters:
hash -
type -
Returns:
value of the type

getArgumentsConcatenationString

public static java.lang.String getArgumentsConcatenationString()

getCallingMethod

public static java.lang.String getCallingMethod(int iLevel)
getCallingMethod

Parameters:
iLevel -
Returns:

getCompileDate

public static java.util.Date getCompileDate(java.lang.Class classname)
getCompileDate get the compile time of a class

Parameters:
classname - the class name
Returns:
the date of the compile time

getCurrentDirectory

public static java.lang.String getCurrentDirectory()
getCurrentDirectory return the current directory

Returns:
the current directory name

getCurrentMethod

public static java.lang.reflect.Method getCurrentMethod()
getCurrentMethod get the method of the currently executing method

Returns:
the method called

getCurrentMethodName

public static java.lang.String getCurrentMethodName()
getCurrentMethodName get the method name of the currently executing method

Returns:

getCurrentUser

public static java.lang.String getCurrentUser()
getCurrentUser returns the currently set user = System.getProperty("user.name")

Returns:

getDateString

public static java.lang.String getDateString()
getDateString - returns a date formated as 11.08.2008 23:54:23:1234

Returns:
a date formated as 11.08.2008 23:54:23:1234

getDateStringFine

public static java.lang.String getDateStringFine()
getDateStringFine returns date as 110820082354231234 (see also getDateString)

Returns:
date as 110820082354231234 (see also getDateString)

getItemsFromFile

public static java.lang.String[] getItemsFromFile(java.lang.String fileName)
readLanguageCodesFromFile read the language codes from a file

Parameters:
fileName - the file name to use
Returns:
a hash table key short code - value long language code - Key: Abkhazian ab Value: ab

getMethod

public static java.lang.reflect.Method getMethod(java.lang.String methodName,
                                                 java.lang.Class classformethod)
getMethod get the method for a given Class

Parameters:
methodName - the method name as string
classformethod - the class to search for method
Returns:
the method of the class

iGetThreadNumber

public static int iGetThreadNumber(int iMaxThreads)
iGetThreadNumber returns the number of threads to use min(Runtime.getRuntime().availableProcessors(), iMaxThreads)

Parameters:
iMaxThreads - maximum number of threads
Returns:
threads possible to use

printParameterInfoFor

public static void printParameterInfoFor(java.lang.reflect.Method method)

quoteForCSVSExport

public static java.lang.String quoteForCSVSExport(java.lang.String string)
quoteForCSVSExport quotes a String for CSV export
LF = \n CR = \r tab = \t \ = \\

Parameters:
string - the string to replace the characters in
Returns:
the quoted string

quoteForCSVSExport

public static java.lang.String quoteForCSVSExport(java.lang.String string,
                                                  java.lang.String nullValue)
quoteForCSVSExport quotes a String for CSV export
LF = \n CR = \r tab = \t \ = \\

Parameters:
string - the string to replace the characters in
nullValue - the string to use for null value
Returns:
the quoted string

readFileIntoString

public static java.lang.String readFileIntoString(java.lang.String filename,
                                                  java.lang.String encoding)
readFileIntoString reads the contents of a file into a string

Parameters:
encoding - the encoding to use; if null UTF-8 is assumed
Returns:
the file content as a string

readFileIntoVector

public static java.util.Vector<java.lang.String> readFileIntoVector(java.lang.String filename,
                                                                    java.lang.String encoding)
readFileIntoVector

Parameters:
encoding -
Returns:

removeBOMFromFile

public static java.lang.String removeBOMFromFile(java.lang.String file)
removeBOMFromFile removes the bom indicators from a file; problem is that Java does not handle them correctly but reads them...

Parameters:
file - the file to check for the bom and possible remove it
Returns:
the file name

replaceStringInFile

public static void replaceStringInFile(java.lang.String filename,
                                       java.lang.String oldPattern,
                                       java.lang.String replPattern)
replaceStringInFile replaces a given string with another string in a file

Parameters:
filename - filename where replacements should be done
oldPattern - the old pattern
replPattern - the new pattern

replaceStringInFile

public static void replaceStringInFile(java.lang.String filename,
                                       java.lang.String[] oldPattern,
                                       java.lang.String[] replPattern)
replaceStringInFile replaces a given string from an array with another string array in a file.

Parameters:
filename - filename where replacements should be done
oldPattern - the old pattern array
replPattern - the new pattern array; oldPattern size must be equals to replPattern size

replaceStringInFile

public static void replaceStringInFile(java.lang.String filename,
                                       java.lang.String oldPattern,
                                       java.lang.String replPattern,
                                       boolean bWritePerLine,
                                       java.lang.String unicodeEncoding)
replaceStringInFile replaces a given string with another string in a file

Parameters:
filename - filename where replacements should be done
oldPattern - the old pattern
replPattern - the new pattern
unicodeEncoding -

replaceStringInFileMultiLine

public static void replaceStringInFileMultiLine(java.lang.String filename,
                                                java.lang.String oldPattern,
                                                java.lang.String replPattern)
replaceStringInFile replaces a given string with another string in a file using MULTILINE regexp expressions

Parameters:
filename - filename where replacements should be done
oldPattern - the old pattern
replPattern - the new pattern

returnBOMFromFile

public static byte[] returnBOMFromFile(java.lang.String file)
Method determines the BOM (Byte Order Mark of a file and returns it

Parameters:
file -
Returns:
the BOM of a file

returnCurrentDate

public static java.lang.String returnCurrentDate()
returnCurrentDate

Returns:
current date string padded with "0" if length of month etc. == 1 28.03.2003 04:06:07

setArgumentsConcatenationString

public static void setArgumentsConcatenationString(java.lang.String argumentsConcatenationString)

simpleCopyStringToFile

public static boolean simpleCopyStringToFile(java.lang.String content,
                                             java.lang.String filename)
simpleCopyStringToFile copies a string to a file where the string is base64 encoded

Parameters:
content - the base64 encoded string
filename - output file name
Returns:

writeBOMToFile

public static boolean writeBOMToFile(java.lang.String filename,
                                     byte[] bom)
Write a bom to a file

Parameters:
filename - the filename
bom - the bom to write to the file
Returns:
true if successfule

writeToOut

public static void writeToOut(java.io.DataOutputStream out,
                              java.lang.String string)
writeToOut

Parameters:
out -
string -

getAllFiles

public java.util.Vector<java.lang.String> getAllFiles(java.lang.String sourcepath)
initial method to start getting all files in for a directory and its sub directories

Parameters:
file - directory where the search should start from
Returns:
the vector containing all the file names found

getAllRecFiles

public void getAllRecFiles(java.io.File file,
                           java.lang.String sourcepath)
Get all the files in the directory (file) specified and its sub directories sourcepath is the start path of file (to determine the absolute pathname for a file

Parameters:
file - directory where the search should start from
sourcepath - sourcepath is the start path of file (to determine the absolute pathname for a file)

getVersionfinal

public java.lang.String getVersionfinal(java.lang.Class classe)
getVersionfinal from http://stackoverflow.com/questions/1917686/compile-date-and-time

Parameters:
classe -
Returns: