| java.lang.Object org.jaffa.util.StringHelper
StringHelper | public class StringHelper (Code) | | Utility Class for Common String Manipulation routines.
author: PaulE version: 1.0 |
Inner Class :public static class Line | |
Method Summary | |
public static String | addCommentWithStamp(String originalComment, String additionalComment, boolean lifo, String userId) This is a helper for combining old and additional comments.
A stamp containing the userId and current time will be inserted before the additional comment.
The additional comment will be inserted before the old comment if 'lifo' is true, otherwise it'll be appended.
If the input userId is null, then the userId will be obtained from the SecurityManager.
Parameters: originalComment - The original comment. Parameters: additionalComment - The additional comment. Parameters: lifo - This determines if the additional comment is inserted before or appended after the old comment. Parameters: userId - The userId. | public static String | addHTMLLineBreak(String s, int lineLimit) This method will add HTML line breaks in the input String at the specified limits. | public static String | convertFromHTML(String s) Convert a string that has XML (and HTML) entities in it, into a regular string
It will convert the following... | public static String | convertToHTML(String s) Convert a regular string into an XML (and HTML) based string
It will convert the following... | public static ArrayList | convertToList(String commaList) | public static String | findEol(String input) Returns the EOL character for the input String, if any.
The EOL character can be '\r', '\n' or '\r\n'.
the EOL character for the input String. | public static String | formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml) This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. | public static String | formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml, String beginMarker, String endMarker) This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. | public static String | formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml, String beginMarker, String endMarker, int limit, String truncateIndicator) This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. | public static String | getDefaultDescriptionBeginMarker() Returns the default String used in the formatDescription() methods placed at the beginning. | public static String | getDefaultDescriptionEndMarker() Returns the default String used in the formatDescription() methods placed at the end. | public static String | getLower(String input) | public static String | getLower1(String input) | public static String | getSpace(String input) | public static String | getStatic(String input) | public static String | getString(Reader reader) This returns the contents of a Reader as a String.
Parameters: reader - the input source. throws: IOException - if any error occurs in reading the contents of the input. | public static StringBuffer | getStringBuffer(Reader reader) This returns the contents of a Reader in a StringBuffer.
Parameters: reader - the input source. throws: IOException - if any error occurs in reading the contents of the input. | public static String | getUpper(String input) | public static String | getUpper1(String input) | public static String | linePad(String text, int indent) | public static String | linePad(String text, int indent, String indentWith) | public static String | linePad(String text, int indent, String indentWith, boolean supressFirst) | public static void | main(String[] args) | public static String | pad(int number) | public static String | pad(int number, int length) | public static String | pad(int number, int len, String padVal) | public static String[] | parseString(String s) | public static String[] | parseString(String s, String delim) | public static Line | readLine(PushbackReader reader) Reads a line from the input reader.
It'll return an instance of StringHelper.Line object, which has the contents and EOL of the line.
The EOL character can be '\r', '\n' or '\r\n'.
This method is used instead of the readLine() method of the BufferedReader, since there is no other way of finding out if the last line in a file ends with an EOL.
This also has the added benefit of knowing the exact EOL character.
A null will be returned if the EOF is reached.
a StringHelper.Line object containing the line contents and the EOL character. | public static String | replace(String source, String find, String replace) | public static String | replicate(String text, int count) |
addCommentWithStamp | public static String addCommentWithStamp(String originalComment, String additionalComment, boolean lifo, String userId)(Code) | | This is a helper for combining old and additional comments.
A stamp containing the userId and current time will be inserted before the additional comment.
The additional comment will be inserted before the old comment if 'lifo' is true, otherwise it'll be appended.
If the input userId is null, then the userId will be obtained from the SecurityManager.
Parameters: originalComment - The original comment. Parameters: additionalComment - The additional comment. Parameters: lifo - This determines if the additional comment is inserted before or appended after the old comment. Parameters: userId - The userId. The combination of the old comment and the additional comment. |
addHTMLLineBreak | public static String addHTMLLineBreak(String s, int lineLimit)(Code) | | This method will add HTML line breaks in the input String at the specified limits.
This is useful for wrapping long lines of text.
Parameters: s - String to modify Parameters: lineLimit - The interval at which the line breaks will be added. |
convertFromHTML | public static String convertFromHTML(String s)(Code) | | Convert a string that has XML (and HTML) entities in it, into a regular string
It will convert the following...
& to &
< to <
> to >
' to '
" to "
Parameters: s - String to convert converted string |
convertToHTML | public static String convertToHTML(String s)(Code) | | Convert a regular string into an XML (and HTML) based string
It will convert the following...
& to &
< to <
> to >
' to '
" to "
Parameters: s - String to convert converted string |
convertToList | public static ArrayList convertToList(String commaList)(Code) | | Converts a comma delimmitered string into an array of strings
Parameters: commaList - Source string List of strings |
findEol | public static String findEol(String input)(Code) | | Returns the EOL character for the input String, if any.
The EOL character can be '\r', '\n' or '\r\n'.
the EOL character for the input String. A null string will be returned in case no EOL charcater is found. |
formatDescription | public static String formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml)(Code) | | This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. If the String is truncated, then the truncateIndicator will be appended.
Finally the String will be packaged between the beginMarker and endMarker.
If the toHtml flag is true, then the result will made HTML safe.
This method will use the default values beginMarker=' (', endMarker=')', limit=25, truncateIndicator='...'
Parameters: field - The description of the field. Parameters: layout - The layout, if any to be used for formatting Parameters: domainClassWithPackage - The domainClass to determine the FieldMetaData object, to get a handle on the layout. Parameters: domainField - The domainField to determine the FieldMetaData object, to get a handle on the layout. Parameters: toHtml - if true, then the output will be converted to HTML. the formatted string packed between the markers. An empty String will be returned, in case the input field is null. |
formatDescription | public static String formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml, String beginMarker, String endMarker)(Code) | | This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. If the String is truncated, then the truncateIndicator will be appended.
Finally the String will be packaged between the beginMarker and endMarker.
If the toHtml flag is true, then the result will made HTML safe.
This method will use the default values limit=25, truncateIndicator='...'
Parameters: field - The description of the field. Parameters: layout - The layout, if any to be used for formatting Parameters: domainClassWithPackage - The domainClass to determine the FieldMetaData object, to get a handle on the layout. Parameters: domainField - The domainField to determine the FieldMetaData object, to get a handle on the layout. Parameters: toHtml - if true, then the output will be converted to HTML. Parameters: beginMarker - The marker at the start of the output. Default is ' (' Parameters: endMarker - The marker at the end of the output. Default is ')' the formatted string packed between the markers. An empty String will be returned, in case the input field is null. |
formatDescription | public static String formatDescription(Object field, String layout, String domainClassWithPackage, String domainField, boolean toHtml, String beginMarker, String endMarker, int limit, String truncateIndicator)(Code) | | This method is invoked in cases where 'description' field is appended to a 'code' field.
This method formats the input dexcriptionField based on the passed layout.
The layout can be passed directly or can be determined from the parameters domainClassWithPackage and domainField, through the appropriate FieldMetaData object.
It then truncates the formatted String to the input limit. If the String is truncated, then the truncateIndicator will be appended.
No truncation will be performed if the limit <= 0
Finally the String will be packaged between the beginMarker and endMarker.
If the toHtml flag is true, then the result will made HTML safe.
Parameters: field - The description of the field. Parameters: layout - The layout, if any to be used for formatting Parameters: domainClassWithPackage - The domainClass to determine the FieldMetaData object, to get a handle on the layout. Parameters: domainField - The domainField to determine the FieldMetaData object, to get a handle on the layout. Parameters: toHtml - if true, then the output will be converted to HTML. Parameters: beginMarker - The marker at the start of the output. Default is ' (' Parameters: endMarker - The marker at the end of the output. Default is ')' Parameters: limit - The limit for the formatted decription. Default is 25. Parameters: truncateIndicator - The string to append tot he formatted description, if exceeds the limit and is truncated. the formatted string packed between the markers. An empty String will be returned, in case the input field is null. |
getDefaultDescriptionBeginMarker | public static String getDefaultDescriptionBeginMarker()(Code) | | Returns the default String used in the formatDescription() methods placed at the beginning.
the default String used in the formatDescription() methods placed at the beginning. |
getDefaultDescriptionEndMarker | public static String getDefaultDescriptionEndMarker()(Code) | | Returns the default String used in the formatDescription() methods placed at the end.
the default String used in the formatDescription() methods placed at the end. |
getLower | public static String getLower(String input)(Code) | | A convenience method to translate the input String to LowerCase
Parameters: input - the string to process the modified string |
getLower1 | public static String getLower1(String input)(Code) | | A convenience method to translate the input String's 1st character to LowerCase,
the rest of the string is left the same
Parameters: input - the string to process the modified string |
getSpace | public static String getSpace(String input)(Code) | | A convenience method to translate the input String to words separated by spaces
For eg: "abcDef" would be translated to "abc Def"
Parameters: input - the string to process the modified string |
getStatic | public static String getStatic(String input)(Code) | | A convenience method to translate the input String to all UpperCase with underscores separating the words
For eg: "abcDef" would be translated to "ABC_DEF"
Parameters: input - the string to process the modified string |
getString | public static String getString(Reader reader) throws IOException(Code) | | This returns the contents of a Reader as a String.
Parameters: reader - the input source. throws: IOException - if any error occurs in reading the contents of the input. a String with the contents of the source. A null is returned if the input is null. |
getStringBuffer | public static StringBuffer getStringBuffer(Reader reader) throws IOException(Code) | | This returns the contents of a Reader in a StringBuffer.
Parameters: reader - the input source. throws: IOException - if any error occurs in reading the contents of the input. a StringBuffer with the contents of the source. A null is returned if the input is null. |
getUpper | public static String getUpper(String input)(Code) | | A convenience method to translate the input String to UpperCase
Parameters: input - the string to process the modified string |
getUpper1 | public static String getUpper1(String input)(Code) | | A convenience method to translate the input String's 1st character to UpperCase,
the rest of the string is left the same
Parameters: input - the string to process the modified string |
linePad | public static String linePad(String text, int indent)(Code) | | Pad each new line of the supplied string with the
specified number of spaces
Parameters: text - String to pad Parameters: indent - number of spaces to indent by the indented string |
linePad | public static String linePad(String text, int indent, String indentWith)(Code) | | Pad each new line of the supplied string with the
specified number of 'indent Strings'
Parameters: text - String to pad Parameters: indent - number of spaces to indent by Parameters: indentWith - String to use for indenting the indented string |
linePad | public static String linePad(String text, int indent, String indentWith, boolean supressFirst)(Code) | | Pad each new line of the supplied string with the specified number of the indent string,
but allows the suppression of the first line from indentation
Parameters: text - String to pad Parameters: indent - number of spaces to indent by Parameters: indentWith - String to use for indenting Parameters: supressFirst - true, if the first line should be skipped when indenting the indented string |
main | public static void main(String[] args)(Code) | | Test Routine
Parameters: args - no args required |
pad | public static String pad(int number)(Code) | | Pad a number to take up at least 2 characters
Parameters: number - the number to pad string representation of number padded to 2 characters |
pad | public static String pad(int number, int length)(Code) | | Pad a number to take up a specified length
Parameters: number - the number to pad Parameters: length - length of resulting string string representation of number padded to specified length |
pad | public static String pad(int number, int len, String padVal)(Code) | | Pad a number to take up a specified length
Parameters: number - the number to pad Parameters: len - length of resulting string Parameters: padVal - Character to be used for Padding string representation of number padded to specified length |
parseString | public static String[] parseString(String s)(Code) | | Tokenize the Input String with the default tokenizer (whitespace)
Parameters: s - String to tokenize string[] representation tokenized String |
parseString | public static String[] parseString(String s, String delim)(Code) | | Tokenize the Input String with the given delim
Parameters: s - String to tokenize Parameters: delim - Deliminator to use string[] representation tokenized String |
readLine | public static Line readLine(PushbackReader reader) throws IOException(Code) | | Reads a line from the input reader.
It'll return an instance of StringHelper.Line object, which has the contents and EOL of the line.
The EOL character can be '\r', '\n' or '\r\n'.
This method is used instead of the readLine() method of the BufferedReader, since there is no other way of finding out if the last line in a file ends with an EOL.
This also has the added benefit of knowing the exact EOL character.
A null will be returned if the EOF is reached.
a StringHelper.Line object containing the line contents and the EOL character. A null is returned if the end of file is reached. throws: IOException - if any IO error occurs. |
replace | public static String replace(String source, String find, String replace)(Code) | | Basic find and replace on a string, it will replace ALL occurences of the string
Parameters: source - original string Parameters: find - string to search for Parameters: replace - string to replace found strings with resultant string from the replace |
replicate | public static String replicate(String text, int count)(Code) | | Produce a string by replicating the specific string the specified
number of times
Parameters: text - String to replicate Parameters: count - number of times to replicate string final replicated string |
|
|