de.init.its.util
Class Util

java.lang.Object
  extended by de.init.its.util.Util

public final class Util
extends java.lang.Object

Support class to implement overall need functionality

Author:
mkandora

Nested Class Summary
static interface Util.Executor<T>
          Simple executor delegator interface
static interface Util.MatcherOp<T>
          Simple Boolean Matcher Executor Interface
 
Field Summary
static java.lang.String HOME
          The HOME directory java is working in
 
Method Summary
static boolean containsKeyPrefix(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String prefix)
          Returns true if the map contains a key with the provided prefix
static org.xml.sax.InputSource convertFrom(java.lang.String plainXMLRepresenation)
          Convenience Method to convert a string represenation of an xml document to an InputSource
static java.lang.String crop(java.lang.String input, java.lang.String begin, java.lang.String end)
          crops a string according to start and end (both exclusive) delimiters.
static java.lang.String cut(java.lang.String str, java.lang.String delim, int field)
          tokenizes a string by delimiter and returns the n th field (begin index with 0)
static java.lang.String escape(java.lang.String str)
          Escapes almost all possible occurences of: \t \r \n \s \d : , - =
static java.lang.String extractPath(java.lang.String path)
          Extracts the Path to a File (eg. the Parent Dir)
static java.io.File extractZipEntry(java.lang.String zipResource, java.lang.String entryName)
          Extracts an entry from a zip file and saves it as temporary resource.
static java.lang.String format(java.lang.String s, java.lang.Object... o)
          Formats a given String.
static java.lang.String getStringContent(java.io.File file)
          Returns the String representation of a File.
static java.lang.String join(java.lang.String a, java.lang.Object... b)
          Joins a String with given Object parameters
static
<T> boolean
matchesAny(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String... args)
          Returns true, if any of the supplied arguments are contained in the map
static
<T> boolean
matchSingle(Util.MatcherOp<T> executor, java.util.List<T> list)
          Uses a boolean delegate to evaluate all arguments, returns true if one of the arguments matches a condition defined by the delegate
static java.net.URI mkTmpCopy(java.net.URI uri, java.lang.String suffix)
          Copies a file
static java.net.URI prepreXLIFFOutput()
           
static void println(java.lang.String string, java.lang.Object... format)
          Calls System.out.printline with a more advanced formatting of objects (Backward compatibility for Java 5)
static java.lang.String rep(java.lang.String sym, int times)
          Repeats a string n times and returns it
static java.io.File toFile(java.lang.String resource)
          returns a file reference for a resource
static org.xml.sax.InputSource toInputSource(java.io.File resource)
          Returns a textual file as InputSource
static org.xml.sax.InputSource toInputSource(java.lang.String resource)
          Returns a textual file as InputSource
static org.xml.sax.InputSource toInputSourceFromZip(java.lang.String resource, java.lang.String zipEntry)
          Reads a zipFile and returns a specific Zip Entry as InputSource and returns it.
static void writeToDisk(java.lang.String path, java.lang.String content)
          Writes string content to disk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOME

public static final java.lang.String HOME
The HOME directory java is working in

Method Detail

toInputSource

public static org.xml.sax.InputSource toInputSource(java.lang.String resource)
                                             throws java.lang.Exception
Returns a textual file as InputSource

Parameters:
resource - the absolute path to a resource
Returns:
InputSource
Throws:
java.lang.Exception

mkTmpCopy

public static java.net.URI mkTmpCopy(java.net.URI uri,
                                     java.lang.String suffix)
Copies a file

Parameters:
uri -
suffix -
Returns:

toInputSource

public static org.xml.sax.InputSource toInputSource(java.io.File resource)
                                             throws java.lang.Exception
Returns a textual file as InputSource

Parameters:
resource -
Returns:
Throws:
java.lang.Exception

toInputSourceFromZip

public static org.xml.sax.InputSource toInputSourceFromZip(java.lang.String resource,
                                                           java.lang.String zipEntry)
                                                    throws java.lang.Exception
Reads a zipFile and returns a specific Zip Entry as InputSource and returns it.

Parameters:
resource - the zip file
zipEntry - the entry to be returned as InputSource
Returns:
Throws:
java.lang.Exception

extractZipEntry

public static java.io.File extractZipEntry(java.lang.String zipResource,
                                           java.lang.String entryName)
                                    throws java.lang.Exception
Extracts an entry from a zip file and saves it as temporary resource. returns a file reference to the temp resource

Parameters:
zipResource - the zip file (like an odt file)
entryName - the name of the entry to extract
Returns:
the temporary resource
Throws:
java.lang.Exception

convertFrom

public static org.xml.sax.InputSource convertFrom(java.lang.String plainXMLRepresenation)
                                           throws java.lang.Exception
Convenience Method to convert a string represenation of an xml document to an InputSource

Parameters:
plainXMLRepresenation -
Returns:
Throws:
java.lang.Exception

join

public static java.lang.String join(java.lang.String a,
                                    java.lang.Object... b)
Joins a String with given Object parameters

Parameters:
a - a String as start
b - various elements to join with String a
Returns:

containsKeyPrefix

public static boolean containsKeyPrefix(java.util.Map<java.lang.String,java.lang.String> map,
                                        java.lang.String prefix)
Returns true if the map contains a key with the provided prefix

Parameters:
map - the map to check for a key with a given prefix
prefix - the prefix to check for existence
Returns:
true, if key with prefix exists

crop

public static java.lang.String crop(java.lang.String input,
                                    java.lang.String begin,
                                    java.lang.String end)
crops a string according to start and end (both exclusive) delimiters. if input string does not match both delimiters the input string will be returned unmodified.

Parameters:
input - the input to be cropped
begin - the start delimiter
end - the end delimiter
Returns:
the cropped string

cut

public static java.lang.String cut(java.lang.String str,
                                   java.lang.String delim,
                                   int field)
tokenizes a string by delimiter and returns the n th field (begin index with 0)

Parameters:
str - the string to be cut
delim - the delimiter to split the string
field - the field, that needs to be returned
Returns:
the nth field of the string

escape

public static java.lang.String escape(java.lang.String str)
Escapes almost all possible occurences of:

Parameters:
str - the string that may contain possible control characters
Returns:
the fully escaped string

format

public static java.lang.String format(java.lang.String s,
                                      java.lang.Object... o)
Formats a given String. Backward Compatibility to Support Java 1.5 Projects See String.format(String, Object...) for Java 1.6

Parameters:
s - the simple string with {} as replacement symbol
o - a variable number of parameters
Returns:
the formatted String

matchesAny

public static <T> boolean matchesAny(java.util.Map<java.lang.String,java.lang.String> map,
                                     java.lang.String... args)
Returns true, if any of the supplied arguments are contained in the map

Parameters:
map - the map to look for key entries
args - the arguments to match any of the key entries
Returns:
true, if a single argument matches an entry in the map

matchSingle

public static <T> boolean matchSingle(Util.MatcherOp<T> executor,
                                      java.util.List<T> list)
Uses a boolean delegate to evaluate all arguments, returns true if one of the arguments matches a condition defined by the delegate

Parameters:
executor - a delegate to match a single argument in list
list - a list of argument values
Returns:
true, if one argument matches the condition by the delegate

extractPath

public static java.lang.String extractPath(java.lang.String path)
Extracts the Path to a File (eg. the Parent Dir)

Parameters:
path -
Returns:

writeToDisk

public static void writeToDisk(java.lang.String path,
                               java.lang.String content)
                        throws java.lang.Exception
Writes string content to disk

Parameters:
path -
content -
Throws:
java.lang.Exception

rep

public static java.lang.String rep(java.lang.String sym,
                                   int times)
Repeats a string n times and returns it

Parameters:
sym -
times -
Returns:

toFile

public static java.io.File toFile(java.lang.String resource)
                           throws java.io.FileNotFoundException
returns a file reference for a resource

Parameters:
resource -
Returns:
Throws:
java.io.FileNotFoundException

getStringContent

public static java.lang.String getStringContent(java.io.File file)
                                         throws java.lang.Exception
Returns the String representation of a File. Might only be useful for textual files.

Parameters:
file - the source file
Returns:
the String content of the file
Throws:
java.lang.Exception

prepreXLIFFOutput

public static java.net.URI prepreXLIFFOutput()

println

public static void println(java.lang.String string,
                           java.lang.Object... format)
Calls System.out.printline with a more advanced formatting of objects (Backward compatibility for Java 5)

Parameters:
string - the string containing {} as placeholder for values
format - the formatting values, can be empty (not null)