org.alicebot.server.core.parser
Class GenericParser

java.lang.Object
  extended by org.alicebot.server.core.parser.GenericParser
Direct Known Subclasses:
StartupFileParser, TemplateParser

public abstract class GenericParser
extends java.lang.Object

A generic parser.

Since:
4.1.3

Field Summary
protected static java.lang.String ATOMIC_MARKER_END
          The end of a tag marker for an "atomic" tag.
protected static java.lang.String CLOSE_MARKER_START
          The start of a tag marker for an element close tag.
protected static java.lang.String COLON
          A colon, for convenience.
protected static java.lang.String COMMA
          A comma, for convenience.
protected static java.lang.String EMPTY_STRING
          An empty string, for convenience.
protected static java.lang.String INDEX
          The word "index", for convenience.
protected static java.lang.String NONATOMIC_MARKER_END
          The end of a tag marker for a "non-atomic" tag.
protected static java.lang.String OPEN_MARKER_START
          The start of a tag marker for an element open tag.
protected  ClassRegistry processorRegistry
          Each subclass should set this.
 
Constructor Summary
GenericParser()
           
 
Method Summary
 java.lang.String evaluate(int level, java.util.LinkedList list)
           Recursively evaluates an XML trie.; Both the level and the client id are carried through recursion.
 java.lang.String formatTag(int level, XMLNode tag)
           Formats a tag from an XML node into "pure" ????.
 XMLNode getNode(java.lang.String tagname, java.util.LinkedList list, int ordernode)
           Retrieves the ordernode-th node of a given tag at a particular level of the XML trie.
static int getValid1dIndex(XMLNode tag)
          Corrects a tag to use a valid 1-dimensional index, and returns the index.
static int[] getValid2dIndex(XMLNode tag)
          Corrects a tag to use a valid 2-dimensional index, and returns the indices.
 int nodeCount(java.lang.String tagname, java.util.LinkedList list, boolean allnodes)
           Counts the number of nodes of a given type at a particular level of the XML trie.
 java.lang.String processResponse(java.lang.String content)
           Processes a given XML content string for a given identifier.
 java.lang.String processTag(int level, XMLNode tag)
          Processes a given XML node for a given identifier.
 java.lang.String shortcutTag(int level, java.lang.String rootTag, int rootType, java.lang.String rootAttr, java.lang.String childTag, int childType)
           Creates a "mini-template" with a given tag and an optional child tag, then evaluates it recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

processorRegistry

protected ClassRegistry processorRegistry
Each subclass should set this.


EMPTY_STRING

protected static final java.lang.String EMPTY_STRING
An empty string, for convenience.

See Also:
Constant Field Values

OPEN_MARKER_START

protected static final java.lang.String OPEN_MARKER_START
The start of a tag marker for an element open tag.

See Also:
Constant Field Values

CLOSE_MARKER_START

protected static final java.lang.String CLOSE_MARKER_START
The start of a tag marker for an element close tag.

See Also:
Constant Field Values

NONATOMIC_MARKER_END

protected static final java.lang.String NONATOMIC_MARKER_END
The end of a tag marker for a "non-atomic" tag.

See Also:
Constant Field Values

ATOMIC_MARKER_END

protected static final java.lang.String ATOMIC_MARKER_END
The end of a tag marker for an "atomic" tag.

See Also:
Constant Field Values

INDEX

protected static final java.lang.String INDEX
The word "index", for convenience.

See Also:
Constant Field Values

COMMA

protected static final java.lang.String COMMA
A comma, for convenience.

See Also:
Constant Field Values

COLON

protected static final java.lang.String COLON
A colon, for convenience.

See Also:
Constant Field Values
Constructor Detail

GenericParser

public GenericParser()
Method Detail

processResponse

public java.lang.String processResponse(java.lang.String content)
                                 throws ProcessorException

Processes a given XML content string for a given identifier.

This is the general access method for external classes.

Parameters:
content - the XML content
Returns:
the result of processing the XML content for the given id
Throws:
ProcessorException - if the content cannot be processed

processTag

public java.lang.String processTag(int level,
                                   XMLNode tag)
                            throws ProcessorException
Processes a given XML node for a given identifier.

Parameters:
level - the current level in the XML trie
tag - the tag being evaluated
Returns:
the result of processing the tag
Throws:
ProcessorException - if the content cannot be processed

evaluate

public java.lang.String evaluate(int level,
                                 java.util.LinkedList list)

Recursively evaluates an XML trie.; Both the level and the client id are carried through recursion.

Depending on whether the engine is at load-time or run time, determines whether or not to process the tag. When the tag is processed, returns the result of processing it.

Parameters:
level - the current level in the XML trie
list - the XML trie to parse
Returns:
the result of processing the tag

formatTag

public java.lang.String formatTag(int level,
                                  XMLNode tag)

Formats a tag from an XML node into "pure" ????. Mostly used when a tag cannot be evaluated and then literally included in the input.

THIS WORDING NEEDS TO BE CLARIFIED.

Parameters:
level - index of the current level in the XML trie (just passed through)
tag - the tag to format
Returns:
the formatted result

nodeCount

public int nodeCount(java.lang.String tagname,
                     java.util.LinkedList list,
                     boolean allnodes)

Counts the number of nodes of a given type at a particular level of the XML trie.

Used mostly in connection with the <random/> tag in order to see how many candidate listItem structures are beneath it and to set the upper limit on the random number roll.

Parameters:
tagname - the name of the tag sought
list - the XML trie
allnodes - if false, only count one of the desired type (just see if any are there)
Returns:
the number of nodes of the given type at this level (or 1 if at least one node is present and allnodes is false

getNode

public XMLNode getNode(java.lang.String tagname,
                       java.util.LinkedList list,
                       int ordernode)

Retrieves the ordernode-th node of a given tag at a particular level of the XML trie.

Typically used to find specific tags beneath a given tag being evaluated (e.g., an <li/> beneath a <random/>).

Parameters:
tagname - the name of the tag sought
list - the XML trie
ordernode - index of the node we sought
Returns:
the node sought

shortcutTag

public java.lang.String shortcutTag(int level,
                                    java.lang.String rootTag,
                                    int rootType,
                                    java.lang.String rootAttr,
                                    java.lang.String childTag,
                                    int childType)

Creates a "mini-template" with a given tag and an optional child tag, then evaluates it recursively.

This method is used mostly to map certain tags as combinations of other tags (as in short-cut elements), as well as various "AIML 0.9" tags.

Parameters:
level - the current level in the XML trie
rootTag - the name of the root tag
rootType - the type of the root tag
rootAttr - an optional attribute on the root tag (use "" if no attribute)
childTag - the name of the child tag
childType - the type of the child tag
Returns:
the result of processing this structure

getValid2dIndex

public static int[] getValid2dIndex(XMLNode tag)
Corrects a tag to use a valid 2-dimensional index, and returns the indices. If either index is invalid or missing, it is set to 1.

Parameters:
tag - the tag whose 2-dimensional index we want
Returns:
a valid 2-dimensional index
Since:
4.1.3

getValid1dIndex

public static int getValid1dIndex(XMLNode tag)
Corrects a tag to use a valid 1-dimensional index, and returns the index. If the index is missing or valid, 1 is returned.

Parameters:
tag - the element whose 1-dimensional index we want
Returns:
a valid 1-dimensional index
Since:
4.1.3