| java.lang.Object dinamica.StringUtil
StringUtil | public class StringUtil (Code) | | Core-level framework class: String and Date basic utility methods.
Encapsulates utility methods for everyday programming tasks
with Strings, Dates and other common stuff.
Creation date: 18/09/2003
Last Update: 18/09/2003
(c) 2003 Martin Cordova
This code is released under the LGPL license
author: Martin Cordova (some code written by Carlos Pineda) |
Method Summary | |
public static String | formatDate(java.util.Date d, String format) | public static String | formatDate(java.util.Date d, String format, Locale loc) | public static String | formatNumber(Object value, String numberFormat) | public static String | formatNumber(Object value, String numberFormat, Locale loc) | public static java.util.Date | getDateObject(String dateValue, String dateFormat) | public static String | getResource(javax.servlet.ServletContext ctx, String path) | public static String | getResource(javax.servlet.ServletContext ctx, String path, String encoding) | public static String | httpGet(String url, boolean logStdout) Retrieve a text-based document using HTTP GET method.
May be used to retrieve XML documents, news feeds, etc. | public static String | replace(String source, String pattern, String newText) Replace ALL occurrences of [old value] with [new value]
This method was written by Carlos Pineda. | public static double | round(double n, int decimals) | public static synchronized void | saveMessage(String path, String message) | public static String[] | split(String s, String separator) Create an array of items from a string with delimiters to separate the items. |
formatDate | public static String formatDate(java.util.Date d, String format) throws Throwable(Code) | | Format date using a mask and the default locale
Parameters: d - Date object Parameters: format - Date mask, like yyyy-MM-dd or any valid java format String representing the formatted string throws: Throwable - |
formatDate | public static String formatDate(java.util.Date d, String format, Locale loc) throws Throwable(Code) | | Format date using a mask and locale
Parameters: d - Date object Parameters: format - Date mask, like yyyy-MM-dd or any valid java format Parameters: loc - Custom Locale String representing the formatted string throws: Throwable - |
formatNumber | public static String formatNumber(Object value, String numberFormat) throws Throwable(Code) | | Format a number using a valid Java format mask and the default Locale
Parameters: value - Double, Integer or another numeric value Parameters: numberFormat - Java numeric format mask like #,##0.00 String representing a formatted number acording to the numberFormat throws: Throwable - |
formatNumber | public static String formatNumber(Object value, String numberFormat, Locale loc) throws Throwable(Code) | | Format a number using a valid Java format mask and a custom Locale
Parameters: value - Double, Integer or another numeric value Parameters: numberFormat - Java numeric format mask like #,##0.00 Parameters: loc - Custom Locale to use when formatting the number String representing a formatted number acording to the numberFormat throws: Throwable - |
getDateObject | public static java.util.Date getDateObject(String dateValue, String dateFormat) throws Throwable(Code) | | Create a java.util.Date object from a String value and a format mask.
The java date formats are supported, for more information please consult the
reference guide for the class SimpleDateFormat.
Sample code:
java.util.Date d = StringUtil.getDateObject("2003-12-07 17:00:00","yyyy-MM-dd HH:mm:ss");
Parameters: dateValue - A String containg a valid date corresponding to dateFormat mask Parameters: dateFormat - The date format used to represent the date in dateValue A java.util.Date object representing the dateValue parameter throws: Throwable - if dateValue is not represented in dateFormat |
getResource | public static String getResource(javax.servlet.ServletContext ctx, String path, String encoding) throws Throwable(Code) | | Loads a text resource stored into the Web Application context paths
PATCH 2005-02-17 (v2.0.3) - encoding support
Parameters: ctx - Servlet context Parameters: path - Path to the resource Parameters: encoding - Canonical name of the encoding to be used to read the resource String containing the resource contents throws: Exception - |
httpGet | public static String httpGet(String url, boolean logStdout) throws Throwable(Code) | | Retrieve a text-based document using HTTP GET method.
May be used to retrieve XML documents, news feeds, etc.
Parameters: url - A valid URL Parameters: logStdout - if TRUE then this method will printa tracelog via STDOUT a String containing the whole document throws: Throwable - |
replace | public static String replace(String source, String pattern, String newText)(Code) | | Replace ALL occurrences of [old value] with [new value]
This method was written by Carlos Pineda.
Parameters: source - String to manipulate Parameters: pattern - Old value Parameters: newText - New value String with replaced text |
round | public static double round(double n, int decimals) throws Throwable(Code) | | Rounds a double to a given number of decimals.
Example: double x = StringUtil.round(100.0500023, 4);
yields: x = 100.0500
Parameters: n - Number Parameters: decimals - Number of decimals to use in the trim operation A double with trimmed decimals. throws: Throwable - |
saveMessage | public static synchronized void saveMessage(String path, String message)(Code) | | Append message to file, this method is usually
used to save log messages
Parameters: path - File name Parameters: message - String to append to file |
split | public static String[] split(String s, String separator)(Code) | | Create an array of items from a string with delimiters to separate the items.
This is a very simple wrapper around the native String.split method
Parameters: s - String to split or separate in its parts Parameters: separator - Delimiter string, like a pipe or a tabulator Array of strings containing the separated items |
|
|