org.alicebot.server.core.responder
Class AbstractMarkupResponder

java.lang.Object
  extended by org.alicebot.server.core.responder.AbstractMarkupResponder
All Implemented Interfaces:
Responder
Direct Known Subclasses:
FlashResponder, HTMLResponder

public abstract class AbstractMarkupResponder
extends java.lang.Object
implements Responder

Contains common methods of template parsing and processing that are generic for all responders that deal with markup output, and which use a three-part template, such as HTMLResponder, FlashResponder, etc.

Uses a very simple parser that scans a template file and looks for pseudo-tags with which values can be substituted.

Author:
Kim Sullivan, Noel Bush

Field Summary
protected static java.lang.String ALICE_IN
          The string "alice_in" (deprecated).
protected static java.lang.String ALICE_OUT
          The string "alice_out" (deprecated).
protected static java.lang.String ATOMIC_MARKER_END
          The string ">".
protected  Bot bot
           
protected static java.lang.String BOT_
          The string "bot_" (deprecated).
protected static java.lang.String BOT_NAME_EQUALS
          The string "bot name="".
protected  java.lang.String botid
           
protected static java.lang.String EMPTY_STRING
          An empty string.
protected  java.util.LinkedList footer
          The footer part of a chat response.
protected  java.util.LinkedList header
          The header part of a chat response.
protected static java.lang.String HNAME
          The string "hname" (deprecated).
protected  java.lang.String hostName
          The host name to use.
protected static java.lang.String HOSTNAME
          The string "hostname".
protected static java.lang.String MARKER_END
          The string ">".
protected static java.lang.String MARKER_START
          The string "<".
protected static java.lang.String QUOTE_MARK
          A quote mark.
protected static java.lang.String REPLY_END
          The string "/reply".
protected static java.lang.String REPLY_START
          The string "reply".
protected  java.util.LinkedList replyPart
          The reply part of a chat response.
protected  java.lang.StringBuffer response
          An entire bot response.
protected static java.lang.String RESPONSE
          The string "response/".
protected static java.lang.String SPACE
          A space.
protected static java.lang.String[] tags
          Tags to process from the template.
protected static java.lang.String UNDERSCORE
          The string "_".
protected static java.lang.String USERINPUT
          The string "userinput/".
 
Constructor Summary
AbstractMarkupResponder(java.lang.String botid)
          Initializes an AbstractMarkupResponder.
 
Method Summary
 java.lang.String append(java.lang.String input, java.lang.String reply, java.lang.String appendTo)
           Response by a Responder is considered an "append" to some previous string.
protected static java.util.LinkedList loadTemplate(java.lang.String path)
          Loads a template from a file.
 void log(java.lang.String input, java.lang.String reply, java.lang.String hostname, java.lang.String userid, java.lang.String botid)
          Logs an input/response pair to the appropriate place.
protected  void parse(java.io.FileReader file)
          Parses a template into the header, reply part and footer Lists.
protected  void parseTemplate(java.lang.String path)
          Parses a template given a path.
 java.lang.String postprocess(java.lang.String reply)
           Postprocesses a message from a bot as appropriate for a given channel.
 java.lang.String preprocess(java.lang.String input, java.lang.String hostname)
           Preprocesses a message from a bot as appropriate for a given channel.
protected static java.util.HashMap registerTemplates(java.lang.String directoryName, SuffixFilenameFilter filter)
          Scans a given directory for templates that match a given filename filter and returns a map of template names (filenames minus suffixes) to filenames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

header

protected java.util.LinkedList header
The header part of a chat response.


replyPart

protected java.util.LinkedList replyPart
The reply part of a chat response.


footer

protected java.util.LinkedList footer
The footer part of a chat response.


response

protected java.lang.StringBuffer response
An entire bot response.


hostName

protected java.lang.String hostName
The host name to use.


botid

protected java.lang.String botid

bot

protected Bot bot

EMPTY_STRING

protected static final java.lang.String EMPTY_STRING
An empty string.

See Also:
Constant Field Values

HOSTNAME

protected static final java.lang.String HOSTNAME
The string "hostname".

See Also:
Constant Field Values

HNAME

protected static final java.lang.String HNAME
The string "hname" (deprecated).

See Also:
Constant Field Values

REPLY_START

protected static final java.lang.String REPLY_START
The string "reply".

See Also:
Constant Field Values

REPLY_END

protected static final java.lang.String REPLY_END
The string "/reply".

See Also:
Constant Field Values

USERINPUT

protected static final java.lang.String USERINPUT
The string "userinput/".

See Also:
Constant Field Values

ALICE_IN

protected static final java.lang.String ALICE_IN
The string "alice_in" (deprecated).

See Also:
Constant Field Values

RESPONSE

protected static final java.lang.String RESPONSE
The string "response/".

See Also:
Constant Field Values

ALICE_OUT

protected static final java.lang.String ALICE_OUT
The string "alice_out" (deprecated).

See Also:
Constant Field Values

BOT_NAME_EQUALS

protected static final java.lang.String BOT_NAME_EQUALS
The string "bot name="".

See Also:
Constant Field Values

BOT_

protected static final java.lang.String BOT_
The string "bot_" (deprecated).

See Also:
Constant Field Values

tags

protected static java.lang.String[] tags
Tags to process from the template.


UNDERSCORE

protected static final java.lang.String UNDERSCORE
The string "_".

See Also:
Constant Field Values

QUOTE_MARK

protected static final java.lang.String QUOTE_MARK
A quote mark.

See Also:
Constant Field Values

MARKER_START

protected static final java.lang.String MARKER_START
The string "<".

See Also:
Constant Field Values

MARKER_END

protected static final java.lang.String MARKER_END
The string ">".

See Also:
Constant Field Values

ATOMIC_MARKER_END

protected static final java.lang.String ATOMIC_MARKER_END
The string ">".

See Also:
Constant Field Values

SPACE

protected static final java.lang.String SPACE
A space.

See Also:
Constant Field Values
Constructor Detail

AbstractMarkupResponder

public AbstractMarkupResponder(java.lang.String botid)
Initializes an AbstractMarkupResponder.

Method Detail

parseTemplate

protected void parseTemplate(java.lang.String path)
Parses a template given a path.

Parameters:
path - the template path

preprocess

public java.lang.String preprocess(java.lang.String input,
                                   java.lang.String hostname)
Description copied from interface: Responder

Preprocesses a message from a bot as appropriate for a given channel.

For some channels, this may involve doing substitutions on the message; for some channels this may mean formatting the message in a particular way, etc.

Specified by:
preprocess in interface Responder
Parameters:
input - the message to be formatted
hostname - the name of the host that is generating the message
Returns:
the result of preprocessing the message

append

public java.lang.String append(java.lang.String input,
                               java.lang.String reply,
                               java.lang.String appendTo)
Description copied from interface: Responder

Response by a Responder is considered an "append" to some previous string. That string might be some form of the previous exchange, or it might be nothing.

Specified by:
append in interface Responder
Parameters:
input - an input from the client
reply - a reply from the bot
appendTo - the string to which the client of the Responder may expect the reply to be appended
Returns:
the reply, in whatever fashion the Responder has decided to modify it

log

public void log(java.lang.String input,
                java.lang.String reply,
                java.lang.String hostname,
                java.lang.String userid,
                java.lang.String botid)
Description copied from interface: Responder
Logs an input/response pair to the appropriate place.

Specified by:
log in interface Responder
Parameters:
input - the client's input
reply - the bot's response
hostname - the name of the host

postprocess

public java.lang.String postprocess(java.lang.String reply)
Description copied from interface: Responder

Postprocesses a message from a bot as appropriate for a given channel.

For some channels, this may involve doing substitutions on the message; for some channels this may mean formatting the message in a particular way, etc.

Specified by:
postprocess in interface Responder
Returns:
the result of postprocessing the message

parse

protected void parse(java.io.FileReader file)
              throws java.io.IOException
Parses a template into the header, reply part and footer Lists.

Parameters:
file - a FileReader for the chat template.
Throws:
java.io.IOException

loadTemplate

protected static java.util.LinkedList loadTemplate(java.lang.String path)
Loads a template from a file.

Parameters:
path - the path to the file
Returns:
the loaded template

registerTemplates

protected static java.util.HashMap registerTemplates(java.lang.String directoryName,
                                                     SuffixFilenameFilter filter)
Scans a given directory for templates that match a given filename filter and returns a map of template names (filenames minus suffixes) to filenames.

Parameters:
directoryName - the name of the directory to scan
filter - the filename filter to use
Returns:
a map of template names (filenames minus suffixes) to filenames.