org.webmacro.servlet
Class TextTool

java.lang.Object
  extended byorg.webmacro.ContextTool
      extended byorg.webmacro.servlet.TextTool
All Implemented Interfaces:
ContextObjectFactory

public class TextTool
extends ContextTool

A ContextTool for String manipulation.

Author:
Eric B. Ridge (mailto:ebr@tcdi.com)

Constructor Summary
TextTool()
          default contsructor.
TextTool(Context context)
          public constructor.
 
Method Summary
static java.lang.String bytesToString(byte[] bytes)
          convert a byte[] to a String using the system-default encoding
static java.lang.String bytesToString(byte[] bytes, java.lang.String encoding)
          convert a byte[] to a String using the specified encoding
static java.lang.String formatDate(java.util.Date date, java.lang.String format)
          Format a java.util.Date object using the specified date format string.
static TextTool getInstance()
           
static java.lang.String[] getLines(java.lang.String block)
          converts a block of text into an array of strings by tokenizing using \r\n as the delimiter If no \r\n, it will look for \n or \r and use them instead.
static java.lang.String HTMLEncode(java.lang.String input)
          HTMLEncode will encode the specified input String per the magic of org.webmacro.util.HTMLEscaper.
 java.lang.Object init(Context context)
          Tool initialization method.
static java.lang.String join(java.lang.String[] input, java.lang.String delimiter)
          Join the input String[] into a single String, using the specified delimiter between each value of the array.
static java.lang.String ltrim(java.lang.String s)
          remove any leading whitespace from a string
static java.lang.String ltrimBlock(java.lang.String block)
          remove the leading whitespace from each line in a block of text
static void main(java.lang.String[] args)
           
static java.lang.String makeBlock(java.lang.String[] lines)
          convert an array of strings into a block of text delimited by \r\n
static java.lang.String replace(java.lang.String src, java.lang.String from, java.lang.String to)
          replace all occurrences of from to to in src.
static java.lang.String rtrim(java.lang.String s)
          remove the trailing whitespace from a string
static java.lang.String rtrimBlock(java.lang.String block)
          remove the trailing whitespace from each line in a block of text
static java.lang.String[] split(java.lang.String input, java.lang.String delimiter)
          Split the input String into a String[] at each instance of delimiter.
static java.lang.String streamToString(java.io.InputStream in)
          Write the bytes of the specified InputStream into a String using the default character encoding of your platform.
static java.lang.String streamToString(java.io.InputStream in, java.lang.String encoding)
          Write the bytes of the specified InputStream into a String using the specified character encoding.
static java.lang.String toLowerCase(java.lang.String s)
          Returns a new string which is in lower case.
static java.lang.String toUpperCase(java.lang.String s)
          Returns a new string which is in upper case.
static java.lang.String trim(java.lang.String s)
          remove any leading and trailing whitespace from a string
static java.lang.String trimBlock(java.lang.String block)
          remove the leading and trailing whitespace from each line in a block of text
static java.lang.String URLDecode(java.lang.String input)
          Decode a URLEncoded input String.
static java.lang.String URLEncode(java.lang.String input)
          URLEncode the specified input String.
 
Methods inherited from class org.webmacro.ContextTool
get
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextTool

public TextTool()
default contsructor. Does nothing


TextTool

public TextTool(Context context)
public constructor. Does nothing. The TextTool doesn't interact with the Context, so it is ignored

Method Detail

getInstance

public static TextTool getInstance()
Returns:
the static instance of the MathTool

split

public static java.lang.String[] split(java.lang.String input,
                                       java.lang.String delimiter)
Split the input String into a String[] at each instance of delimiter. The delimiter string is not included in the returned array.

If either parameter is null, split() returns a String[] of zero elements.


join

public static java.lang.String join(java.lang.String[] input,
                                    java.lang.String delimiter)
Join the input String[] into a single String, using the specified delimiter between each value of the array.

If either parameter is null, join() returns null.


replace

public static java.lang.String replace(java.lang.String src,
                                       java.lang.String from,
                                       java.lang.String to)
replace all occurrences of from to to in src.

If any paramer is null, replace() returns the value of src.

Returns:
String with all occurrences of from replaced with to in src or src if from not found

URLEncode

public static java.lang.String URLEncode(java.lang.String input)
URLEncode the specified input String.

If input is null, URLEncode() will return null.

See Also:
URLEncoder

URLDecode

public static java.lang.String URLDecode(java.lang.String input)
Decode a URLEncoded input String.

If input is null, URLEncode() will return null.

See Also:
URLDecoder

HTMLEncode

public static java.lang.String HTMLEncode(java.lang.String input)
HTMLEncode will encode the specified input String per the magic of org.webmacro.util.HTMLEscaper.

If the input is null, HTMLEncode() will return an empty string.

See Also:
HTMLEscaper

formatDate

public static java.lang.String formatDate(java.util.Date date,
                                          java.lang.String format)
Format a java.util.Date object using the specified date format string.

See Also:
Date, SimpleDateFormat

streamToString

public static java.lang.String streamToString(java.io.InputStream in)
                                       throws java.io.IOException
Write the bytes of the specified InputStream into a String using the default character encoding of your platform. Upon completion, (or in the event of an Exception) this method will close the input stream.

Throws:
java.io.IOException - if the stream cannot be read

streamToString

public static java.lang.String streamToString(java.io.InputStream in,
                                              java.lang.String encoding)
                                       throws java.io.IOException
Write the bytes of the specified InputStream into a String using the specified character encoding. Upon completion (or in the event of an Exception), this method will close the input stream.

Throws:
java.io.IOException - if the stream cannot be read

bytesToString

public static java.lang.String bytesToString(byte[] bytes)
convert a byte[] to a String using the system-default encoding


bytesToString

public static java.lang.String bytesToString(byte[] bytes,
                                             java.lang.String encoding)
                                      throws java.io.UnsupportedEncodingException
convert a byte[] to a String using the specified encoding

Throws:
java.io.UnsupportedEncodingException

trim

public static java.lang.String trim(java.lang.String s)
remove any leading and trailing whitespace from a string


ltrim

public static java.lang.String ltrim(java.lang.String s)
remove any leading whitespace from a string


rtrim

public static java.lang.String rtrim(java.lang.String s)
remove the trailing whitespace from a string


getLines

public static java.lang.String[] getLines(java.lang.String block)
converts a block of text into an array of strings by tokenizing using \r\n as the delimiter If no \r\n, it will look for \n or \r and use them instead.


makeBlock

public static java.lang.String makeBlock(java.lang.String[] lines)
convert an array of strings into a block of text delimited by \r\n


trimBlock

public static java.lang.String trimBlock(java.lang.String block)
remove the leading and trailing whitespace from each line in a block of text


ltrimBlock

public static java.lang.String ltrimBlock(java.lang.String block)
remove the leading whitespace from each line in a block of text


rtrimBlock

public static java.lang.String rtrimBlock(java.lang.String block)
remove the trailing whitespace from each line in a block of text


toUpperCase

public static java.lang.String toUpperCase(java.lang.String s)
Returns a new string which is in upper case.


toLowerCase

public static java.lang.String toLowerCase(java.lang.String s)
Returns a new string which is in lower case.


init

public java.lang.Object init(Context context)
                      throws PropertyException
Tool initialization method. The TextTool doesn't interact with the context, so the context parameter is ignored.

Specified by:
init in class ContextTool
Throws:
PropertyException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 1999-2006 WebMacro. All Rights Reserved.