|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.alicebot.server.core.util.Toolkit
public class Toolkit
Contains various utilities.
Field Summary | |
---|---|
protected static java.lang.String |
EQUAL_QUOTE
A common string we search for when parsing attributes in tags. |
protected static char |
QUOTE_MARK
A quote mark, for convenience. |
Constructor Summary | |
---|---|
Toolkit()
|
Method Summary | |
---|---|
static java.lang.String[] |
breakLines(java.lang.String input)
Breaks a message into multiple lines at any tag, except if the tag comes at the beginning of the message. |
static void |
checkOrCreate(java.lang.String path,
java.lang.String description)
Checks whether a file given by a path exists, and if not, creates it, along with any necessary subdirectories. |
static java.lang.String |
convertXMLUnicodeEntities(java.lang.String input)
Converts XML Unicode character entities into their character equivalents within a given string. |
static java.lang.String |
escapeXMLChars(java.lang.String input)
Replaces the following characters with their "escaped" equivalents: |
static java.lang.String |
filterWhitespace(java.lang.String input)
Filters all whitespace: line separators and multiple consecutive spaces are replaced with a single space, and any leading or trailing whitespace characters are removed. |
static java.lang.String |
formatAIML(java.util.LinkedList trie,
int level,
boolean atStart)
Formats AIML from a trie into a nicely indented multi-line string. |
static java.lang.String |
formatAIML(java.lang.String content)
Formats AIML from a single long string into a nicely indented multi-line string. |
static java.lang.String |
getAttributeValue(java.lang.String attributeName,
java.lang.String args)
Gets value of an attribute by name. |
static java.lang.String |
getDeclaredXMLEncoding(java.io.InputStream in)
Returns the declared encoding string from the XML resource supposedly connected to a given InputStream, or the system default if none is found. |
static java.lang.String |
getFileContents(java.lang.String path)
Returns the entire contents of a file as a String. |
static java.lang.Class[] |
getImplementorsOf(java.lang.String interfaceName,
boolean showFound)
Scans the classpath for classes that implement a given interface. |
static java.lang.String[] |
glob(java.lang.String path,
java.lang.String workingDirectory)
Expands a localized file name that may contain wildcards to an array of file names without wildcards. |
static java.lang.String |
removeMarkup(java.lang.String input)
Removes all tags from a string (retains character content of tags, however). |
static java.lang.String |
tab(int level)
Returns a tab of the specified length. |
static java.lang.String |
unescapeXMLChars(java.lang.String input)
Replaces the following "escape" strings with their character equivalents: |
static java.util.ArrayList |
wordSplit(java.lang.String input)
Splits an input into words, breaking at spaces. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String EQUAL_QUOTE
protected static final char QUOTE_MARK
Constructor Detail |
---|
public Toolkit()
Method Detail |
---|
public static java.lang.String filterWhitespace(java.lang.String input) throws java.lang.StringIndexOutOfBoundsException
Filters all whitespace: line separators
and multiple consecutive spaces are replaced with a single
space, and any leading or trailing whitespace characters are removed.
Any data enclosed in <![CDATA[
]]>
sections,
however, is left as-is (including the CDATA markers).
input
- the input to filter
java.lang.StringIndexOutOfBoundsException
- (from removeAll
if there is malformed text in the input.public static java.lang.String[] breakLines(java.lang.String input)
Breaks a message into multiple lines at any tag, except if the tag comes at the beginning of the message.
Generally used to format output nicely for a console.
input
- the string to break
public static java.lang.String removeMarkup(java.lang.String input)
input
- the string from which to remove markup
public static java.lang.String unescapeXMLChars(java.lang.String input)
Replaces the following "escape" strings with their character equivalents:
- & with &
- < with <
- > with >
- ' with '
- " with "
input
- the string on which to perform the replacement
public static java.lang.String escapeXMLChars(java.lang.String input)
Replaces the following characters with their "escaped" equivalents:
- & with &
- < with <
- > with >
- ' with '
- " with "
input
- the string on which to perform the replacement
public static java.lang.String convertXMLUnicodeEntities(java.lang.String input)
Converts XML Unicode character entities into their character equivalents within a given string.
This will handle entities in the form &#xxxx;
(decimal character code, where xxxx is a valid character code),
or &#xxxxx
(hexadecimal character code, where
xxxx is a valid character code).
input
- the string to process
public static java.lang.String getDeclaredXMLEncoding(java.io.InputStream in) throws java.io.IOException
in
- the input stream
java.io.IOException
public static java.lang.String getAttributeValue(java.lang.String attributeName, java.lang.String args)
Gets value of an attribute by name.
This method looks in the supplied argument string, and parses it looking for the structure "attributeName=", returning whatever is after the "=" until the next blank or the end of the string. This is mostly useful for extracting attributes from AIML tags.
attribute
- the attribute whose value is wantedargs
- the argument string
public static java.lang.String formatAIML(java.lang.String content)
content
- the AIML content to formatpublic static java.lang.String formatAIML(java.util.LinkedList trie, int level, boolean atStart)
trie
- the trie containing the AIMLlevel
- the level (for indenting)atStart
- whether the whole XML string is at its beginningpublic static java.lang.String tab(int level)
length
- the length of the tabpublic static java.util.ArrayList wordSplit(java.lang.String input)
input
- the input to split
public static java.lang.Class[] getImplementorsOf(java.lang.String interfaceName, boolean showFound)
Scans the classpath for classes that implement a given interface.
Note that this does not make sense for all class loaders. In cases where it doesn't make sense, the return value will be null.
This can also be a very slow method if the classpath is long.
interfaceName
- the fully-qualified name of the interface whose implementations are wantedshowFound
- whether to output a devinfo message when implementations are found
public static java.lang.String[] glob(java.lang.String path, java.lang.String workingDirectory) throws java.io.FileNotFoundException
Expands a localized file name that may contain wildcards to an array of file names without wildcards. All file separators in the file name must preceed any wildcard.
Adapted, with gratitude, from the JMK project. (Under the GNU LGPL)
path
- localized file name that may contain wildcardsworkingDirectory
- the path to which relative paths should be considered relative
java.io.FileNotFoundException
- if wild card is misusedpublic static void checkOrCreate(java.lang.String path, java.lang.String description)
path
- denoting the file to createdescription
- describes what the file is for, for trace
messages. Should fit into a sentence like,
"created new description".
May be null (which will result in less informative messages).public static java.lang.String getFileContents(java.lang.String path)
path
- the path to the file (local file or URL)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |