org.fosstrak.hal.util
Class Tools

java.lang.Object
  extended by org.fosstrak.hal.util.Tools

public class Tools
extends java.lang.Object

Collection of usefull methods needed by several servlets.

Version:
1.0, 08/99
Author:
Matthias Lampe, lampe@lampe.net

Constructor Summary
Tools()
           
 
Method Summary
static java.lang.String convertHtmlToText(java.lang.String text)
          converts HTML to a string.
static java.util.Hashtable convertTableToHTML(java.util.Hashtable table)
          converts the values of the keys of the given hashtable to HTML.
static java.util.Hashtable convertTableToText(java.util.Hashtable table)
          converts the values of the keys of the given hashtable from HTML to text.
static java.lang.String convertTextToHtml(java.lang.String text)
          converts the string to HTML, i.e. replaces newline with
tag.
static java.lang.String decodeURL(java.lang.String string)
          decodes a URL encoded string.
static java.lang.String encodeURL(java.lang.String string)
          encodes a string in URL encoding.
static java.lang.String getKeyValuePairs(java.util.Hashtable table)
          returns a string that contains all the key-value pairs of the given hashtable.
static java.util.Date getTime()
          returns the current date and time.
static java.util.Vector getTokens(java.lang.String list)
          returns a vector of strings that are the tokens of the original string delimeted by whitespaces.
static boolean isValidName(java.lang.String name)
          checks if a string is a valid Chat file name
static java.lang.String readFile(java.lang.String filename)
          reads the content of a text file into a string.
static java.lang.String replaceString(java.lang.String text, java.lang.String searchFor, java.lang.String replaceBy)
          replaces the string xx in the text by the string yy.
static java.lang.String replaceStrings(java.lang.String text, java.util.Hashtable table)
          replaces the keys of the given hashtable in the text by the values.
static void writeFile(java.lang.String filename, java.lang.String text)
          writes the content of a string to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

replaceStrings

public static java.lang.String replaceStrings(java.lang.String text,
                                              java.util.Hashtable table)
replaces the keys of the given hashtable in the text by the values. All occurances of the keys will be replaced.

Parameters:
text - the text containing strings to be replaced
table - the hashtable containing the key-value pairs for the replacement
Returns:
the new text with the replaced strings

replaceString

public static java.lang.String replaceString(java.lang.String text,
                                             java.lang.String searchFor,
                                             java.lang.String replaceBy)
replaces the string xx in the text by the string yy. All occurances of xx will be replaced.

Parameters:
text - the text containing strings to be replaced
searchFor - string to be replaced by replaceBy
replaceBy - string that will replace searchFor
Returns:
the new text with the replaced strings

getTokens

public static java.util.Vector getTokens(java.lang.String list)
returns a vector of strings that are the tokens of the original string delimeted by whitespaces.

Parameters:
list - the string to be tokenized.
Returns:
the vector of tokens.

readFile

public static java.lang.String readFile(java.lang.String filename)
                                 throws java.io.IOException
reads the content of a text file into a string.

Parameters:
filename - the filename of the file.
Returns:
the string containing the content of the file.
Throws:
java.io.IOException

writeFile

public static void writeFile(java.lang.String filename,
                             java.lang.String text)
                      throws java.io.IOException
writes the content of a string to a file.

Parameters:
filename - the filename of the file.
text - the string to be written to the file.
Throws:
java.io.IOException

convertTableToHTML

public static java.util.Hashtable convertTableToHTML(java.util.Hashtable table)
converts the values of the keys of the given hashtable to HTML.

Parameters:
table - the hashtable containing the key-value pairs
Returns:
the hashtable with the converted values

convertTextToHtml

public static java.lang.String convertTextToHtml(java.lang.String text)
converts the string to HTML, i.e. replaces newline with
tag.

Parameters:
text - the string to be converted
Returns:
the converted string

convertTableToText

public static java.util.Hashtable convertTableToText(java.util.Hashtable table)
converts the values of the keys of the given hashtable from HTML to text.

Parameters:
table - the hashtable containing the key-value pairs
Returns:
the hashtable with the converted values

convertHtmlToText

public static java.lang.String convertHtmlToText(java.lang.String text)
converts HTML to a string. The
and

tags are replaced with newline.

Parameters:
text - the html text to be converted
Returns:
the converted string

getKeyValuePairs

public static java.lang.String getKeyValuePairs(java.util.Hashtable table)
returns a string that contains all the key-value pairs of the given hashtable.

Parameters:
table - the hashtable containing the key-value pairs
Returns:
the text output of the key-value paris

getTime

public static java.util.Date getTime()
returns the current date and time.

Returns:
the current date and time.

encodeURL

public static java.lang.String encodeURL(java.lang.String string)
encodes a string in URL encoding. The mapping is the following: a-z,A-Z - a-z,A-Z No Changes 0-9 - 0-9 No Changes SPACE - + Spaces are mapped to the character '+' All Others - %?? The ascii value of the character is converted into hex and is preceded by a '%'

Parameters:
string - the original string.
Returns:
the URL encoded string.

decodeURL

public static java.lang.String decodeURL(java.lang.String string)
decodes a URL encoded string.

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

isValidName

public static boolean isValidName(java.lang.String name)
checks if a string is a valid Chat file name

Parameters:
name - the string to test
Returns:
true if name is valid, false otherwise


Copyright © 2008. All Rights Reserved.