| java.lang.Object org.jamwiki.utils.Utilities
Utilities | public class Utilities (Code) | | This class provides a variety of basic utility methods that are not
dependent on any other classes within the org.jamwiki package structure.
|
Method Summary | |
public static String | convertEncoding(String text, String fromEncoding, String toEncoding) Convert a string value from one encoding to another.
Parameters: text - The string that is to be converted. Parameters: fromEncoding - The encoding that the string is currently encoded in. Parameters: toEncoding - The encoding that the string is to be encoded to. | public static String | decodeFromRequest(String url, boolean decodeUnderlines) Decode a value that has been retrieved from a servlet request. | public static String | decodeFromURL(String url, boolean decodeUnderlines) Decode a value that has been retrieved directly from a URL or file
name. | public static String | encodeForFilename(String name) Convert a topic name or other value into a value suitable for use as a
file name. | public static String | encodeForURL(String url) Encode a topic name for use in a URL. | public static String | extractTrailingPunctuation(String text) Returns any trailing period, comma, semicolon, or colon characters
from the given string. | public static String | formatMessage(String key, Locale locale) Given a message key and locale return a locale-specific message.
Parameters: key - The message key that corresponds to the formatted messagebeing retrieved. Parameters: locale - The locale for the message that is to be retrieved. | public static String | formatMessage(String key, Locale locale, Object[] params) Given a message key, locale, and formatting parameters, return a
locale-specific message.
Parameters: key - The message key that corresponds to the formatted messagebeing retrieved. Parameters: locale - The locale for the message that is to be retrieved. Parameters: params - An array of formatting parameters to use in the messagebeing returned. | public static File | getClassLoaderFile(String filename) Given a file name for a file that is located somewhere in the application
classpath, return a File object representing the file.
Parameters: filename - The name of the file (relative to the classpath) that isto be retrieved. | public static File | getClassLoaderRoot() Attempt to get the class loader root directory. | public static File | getWebappRoot() Retrieve the webapp root. | public static Map | intersect(Map map1, Map map2) Utility method for determining common elements in two Map objects. | public static boolean | isIpAddress(String ipAddress) Determine if the given string is a valid IPv4 or IPv6 address. | public static String | readFile(String filename) Utility method for reading a file from a classpath directory and returning
its contents as a String.
Parameters: filename - The name of the file to be read, either as an absolute filepath or relative to the classpath. | public static String | stripMarkup(String value) Strip all HTML tags from a string. |
convertEncoding | public static String convertEncoding(String text, String fromEncoding, String toEncoding)(Code) | | Convert a string value from one encoding to another.
Parameters: text - The string that is to be converted. Parameters: fromEncoding - The encoding that the string is currently encoded in. Parameters: toEncoding - The encoding that the string is to be encoded to. The encoded string. |
decodeFromRequest | public static String decodeFromRequest(String url, boolean decodeUnderlines)(Code) | | Decode a value that has been retrieved from a servlet request. This
method will replace any underscores with spaces.
Parameters: url - The encoded value that is to be decoded. Parameters: decodeUnderlines - Set to true if underlines shouldbe automatically converted to spaces. A decoded value. |
decodeFromURL | public static String decodeFromURL(String url, boolean decodeUnderlines)(Code) | | Decode a value that has been retrieved directly from a URL or file
name. This method will URL decode the value and then replace any
underscores with spaces. Note that this method SHOULD NOT be called
for values retrieved using request.getParameter(), but only values
taken directly from a URL.
Parameters: url - The encoded value that is to be decoded. Parameters: decodeUnderlines - Set to true if underlines shouldbe automatically converted to spaces. A decoded value. |
encodeForFilename | public static String encodeForFilename(String name)(Code) | | Convert a topic name or other value into a value suitable for use as a
file name. This method replaces spaces with underscores, and then URL
encodes the value.
Parameters: name - The value that is to be encoded for use as a file name. The encoded value. |
encodeForURL | public static String encodeForURL(String url)(Code) | | Encode a topic name for use in a URL. This method will replace spaces
with underscores and URL encode the value, but it will not URL encode
colons.
Parameters: url - The topic name to be encoded for use in a URL. The encoded topic name value. |
extractTrailingPunctuation | public static String extractTrailingPunctuation(String text)(Code) | | Returns any trailing period, comma, semicolon, or colon characters
from the given string. This method is useful when parsing raw HTML
links, in which case trailing punctuation must be removed.
Parameters: text - The text from which trailing punctuation should be returned. Any trailing punctuation from the given text, or an empty stringotherwise. |
formatMessage | public static String formatMessage(String key, Locale locale)(Code) | | Given a message key and locale return a locale-specific message.
Parameters: key - The message key that corresponds to the formatted messagebeing retrieved. Parameters: locale - The locale for the message that is to be retrieved. A formatted message string that is specific to the locale. |
formatMessage | public static String formatMessage(String key, Locale locale, Object[] params)(Code) | | Given a message key, locale, and formatting parameters, return a
locale-specific message.
Parameters: key - The message key that corresponds to the formatted messagebeing retrieved. Parameters: locale - The locale for the message that is to be retrieved. Parameters: params - An array of formatting parameters to use in the messagebeing returned. A formatted message string that is specific to the locale. |
getClassLoaderFile | public static File getClassLoaderFile(String filename) throws Exception(Code) | | Given a file name for a file that is located somewhere in the application
classpath, return a File object representing the file.
Parameters: filename - The name of the file (relative to the classpath) that isto be retrieved. A file object representing the requested filename throws: Exception - Thrown if the classloader can not be found or ifthe file can not be found in the classpath. |
getClassLoaderRoot | public static File getClassLoaderRoot() throws Exception(Code) | | Attempt to get the class loader root directory. This method works
by searching for a file that MUST exist in the class loader root
and then returning its parent directory.
Returns a file indicating the directory of the class loader. throws: Exception - Thrown if the class loader can not be found. |
getWebappRoot | public static File getWebappRoot() throws Exception(Code) | | Retrieve the webapp root.
The default webapp root directory. |
intersect | public static Map intersect(Map map1, Map map2)(Code) | | Utility method for determining common elements in two Map objects.
|
isIpAddress | public static boolean isIpAddress(String ipAddress)(Code) | | Determine if the given string is a valid IPv4 or IPv6 address. This method
uses pattern matching to see if the given string could be a valid IP address.
Parameters: ipAddress - A string that is to be examined to verify whether or notit could be a valid IP address. true if the string is a value that is a valid IP address,false otherwise. |
readFile | public static String readFile(String filename) throws Exception(Code) | | Utility method for reading a file from a classpath directory and returning
its contents as a String.
Parameters: filename - The name of the file to be read, either as an absolute filepath or relative to the classpath. A string representation of the file contents. throws: Exception - Thrown if the file cannot be found or if an I/O exceptionoccurs. |
stripMarkup | public static String stripMarkup(String value)(Code) | | Strip all HTML tags from a string. For example, "A bold word" will be
returned as "A bold word". This method treats an tags that are between brackets
as HTML, whether it is valid HTML or not.
Parameters: value - The value that will have HTML stripped from it. The value submitted to this method with all HTML tags removed from it. |
|
|