lp.struct.util
Class LpHtmlPrinter<W extends Writer>

java.lang.Object
  extended by java.io.Writer
      extended by lp.struct.util.LpPrinter<W>
          extended by lp.struct.util.LpPrettyPrinter<W>
              extended by lp.struct.util.EvolpPrettyPrinter<W>
                  extended by lp.struct.util.LpHtmlPrinter<W>
All Implemented Interfaces:
Closeable, Flushable, Appendable, LpStructureUnitVisitor
Direct Known Subclasses:
DlpWebappHelper.TransDlpHtmlPrinter, EvolpVarWebappHelper.TransEvolpHtmlPrinter, EvolpWebappHelper.TransEvolpHtmlPrinter, JspPrinter

public class LpHtmlPrinter<W extends Writer>
extends EvolpPrettyPrinter<W>

Transforms a logic program (or its components} represented by objects implementing the LpStructureUnit interface into an HTML representation. Rules are surrounded by a <p class="rule"> element. Constants, variables, function symbols and predicate symbols are put inside a <span> element of the class "constant", "variable", "function" or "predicate", respectively. All dots, commas, parenthesis and head-body separators are put inside a <span class="puctuation"> element. The class also offers two convenience methods for appending a dynamic logic program and an evolving logic program (append(DynamicLogicProgram) and append(EvolpProgram)).

Version:
1.0.0
Author:
Martin Slota
See Also:
EvolpPrettyPrinter

Field Summary
 
Fields inherited from class lp.struct.util.EvolpPrettyPrinter
innerTermsLeft, trackPosition
 
Fields inherited from class lp.struct.util.LpPrettyPrinter
ARROW_STRING, SPACE_STRING
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
LpHtmlPrinter(W out)
          Creates a new instance of LpHtmlPrinter.
LpHtmlPrinter(W out, String arrow, boolean withSpaces)
          Creates a new instance of LpHtmlPrinter.
 
Method Summary
 void append(DynamicLogicProgram dlp)
          Appends a dynamic logic program.
 void append(EvolpProgram evolp)
          Appends an evolving logic program and a sequence of events.
protected  void appendOuterRule(LpRule rule)
          Takes care of writing an ordinary rule, just like LpPrettyPrinter does.
protected  void appendPunctuation(char punctuation)
          Appends punctuation surrounded by a <span class="punctuation"> element.
protected  void appendPunctuation(String punctuation)
          Appends punctuation surrounded by a <span class="punctuation"> element.
protected  void arrow()
          Appends the LpPrettyPrinter.ARROW_STRING enclosed in a <span class="punctuation"> element.
protected  void beginParen()
          Appends a left parenthesis enclosed in a <span class="punctuation"> element.
protected  void comma()
          Appends a comma enclosed in a <span class="punctuation"> element.
protected  void dot()
          Appends a dot enclosed in a <span class="punctuation"> element.
protected  void endParen()
          Appends a right parenthesis enclosed in a <span class="punctuation"> element.
static LpBuffer getBuffer()
          A convenience method that creates a new LpBuffer that uses a new LpHtmlPrinter instance to write LpStructureUnits.
static LpBuffer getBuffer(String arrow, boolean withSpaces)
          A convenience method that creates a new LpBuffer that uses a new LpHtmlPrinter instance to write LpStructureUnits.
protected  void literalPrefix(boolean positive)
          Appends an empty string when positive is true and the string "<span class=\"negLitPrefix\">not</span> " otherwise.
 void visit(LpConstant con)
          Appends an HTML form of a LpConstant instance to this LpHtmlPrinter.
 void visit(LpFunction fun)
          Appends an HTML form of a LpFunction instance to this LpHtmlPrinter.
 void visit(LpPredicate pred)
          Appends an HTML form of a LpPredicate instance to this LpHtmlPrinter.
 void visit(LpVariable var)
          Appends an HTML form of a LpVariable instance to this LpHtmlPrinter.
 
Methods inherited from class lp.struct.util.EvolpPrettyPrinter
appendInnerRule, registerTerm, visit, visit, write
 
Methods inherited from class lp.struct.util.LpPrettyPrinter
appendRuleNoDot, space, visit, visit, visitArgumentList
 
Methods inherited from class lp.struct.util.LpPrinter
append, append, append, append, close, flush, getOut, setOut, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LpHtmlPrinter

public LpHtmlPrinter(W out)
Creates a new instance of LpHtmlPrinter. It will use the string "<-" to separate the head and body of a rule. The output will also contain extra spaces to enhance readability.

Parameters:
out - the underlying writer into which everything will be written

LpHtmlPrinter

public LpHtmlPrinter(W out,
                     String arrow,
                     boolean withSpaces)
Creates a new instance of LpHtmlPrinter. It will use the string arrow to separate the head and body of a rule. If withSpaces is true, then the output will also contain extra spaces to enhance readability.

Parameters:
out - the underlying writer into which everything will be written
arrow - the string to separate the head and body of a rule
withSpaces - determines whether extra spaces should be added to places where they can make the output more readable
Throws:
IllegalArgumentException - if arrow is null
Method Detail

getBuffer

public static LpBuffer getBuffer()
A convenience method that creates a new LpBuffer that uses a new LpHtmlPrinter instance to write LpStructureUnits. It will use the string "<-" to separate the head and body of a rule. The output will also contain extra spaces to enhance readability.

Returns:
as specified above
See Also:
LpBuffer

getBuffer

public static LpBuffer getBuffer(String arrow,
                                 boolean withSpaces)
A convenience method that creates a new LpBuffer that uses a new LpHtmlPrinter instance to write LpStructureUnits. It will use the string arrow to separate the head and body of a rule. If withSpaces is true, then the output will also contain extra spaces to enhance readability.

Parameters:
arrow - the string to separate the head and body of a rule
withSpaces - determines whether extra spaces should be added to places where they can make the output more readable
Returns:
as specified above
See Also:
LpBuffer

append

public void append(DynamicLogicProgram dlp)
Appends a dynamic logic program. Each program in the sequence is surrounded by a <div class="ruleGroup"> element whose first child is a <p class="comment"> element containing the text "% Program no. $i" where $i is the number of the program. The other children of the <div> are the rules of the program.

Parameters:
dlp - dynamic logic program to be appended
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

append

public void append(EvolpProgram evolp)
Appends an evolving logic program and a sequence of events. The base program and each of the events is surrounded by a <div class="ruleGroup"> element whose first child is a <p class="comment"> containing either "% Base program" or "% Event no. $i" where $i is the number of the event. The other children of the <div> are the rules of the base program or event.

Parameters:
evolp - evolving logic program to be appended
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

appendPunctuation

protected void appendPunctuation(String punctuation)
Appends punctuation surrounded by a <span class="punctuation"> element.

Parameters:
punctuation - string to be appended as punctuation
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

appendPunctuation

protected void appendPunctuation(char punctuation)
Appends punctuation surrounded by a <span class="punctuation"> element.

Parameters:
punctuation - character to be appended as punctuation
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

beginParen

protected void beginParen()
Appends a left parenthesis enclosed in a <span class="punctuation"> element.

Overrides:
beginParen in class LpPrettyPrinter<W extends Writer>
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

endParen

protected void endParen()
Appends a right parenthesis enclosed in a <span class="punctuation"> element.

Overrides:
endParen in class LpPrettyPrinter<W extends Writer>
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

comma

protected void comma()
Appends a comma enclosed in a <span class="punctuation"> element.

Overrides:
comma in class LpPrettyPrinter<W extends Writer>
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

literalPrefix

protected void literalPrefix(boolean positive)
Appends an empty string when positive is true and the string "<span class=\"negLitPrefix\">not</span> " otherwise.

Overrides:
literalPrefix in class LpPrettyPrinter<W extends Writer>
Parameters:
positive - identifies whether a prefix for a positive or a negative literal should be appended
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

arrow

protected void arrow()
Appends the LpPrettyPrinter.ARROW_STRING enclosed in a <span class="punctuation"> element.

Overrides:
arrow in class LpPrettyPrinter<W extends Writer>
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

dot

protected void dot()
Appends a dot enclosed in a <span class="punctuation"> element.

Overrides:
dot in class LpPrettyPrinter<W extends Writer>
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

visit

public void visit(LpConstant con)
Appends an HTML form of a LpConstant instance to this LpHtmlPrinter. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. The natural form of a constant is its name (see LpConstant.getName()) enclosed in a <span class="constant"> element.

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class EvolpPrettyPrinter<W extends Writer>
Parameters:
con - the LpConstant instance whose HTML representation should be appended to the underlying Writer
Throws:
NullPointerException - if con is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpConstant)

visit

public void visit(LpVariable var)
Appends an HTML form of a LpVariable instance to this LpHtmlPrinter. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. The HTML of a variable is its name (see LpVariable.getName()) enclosed in a <span class="variable"> element.

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class EvolpPrettyPrinter<W extends Writer>
Parameters:
var - the LpVariable instance whose HTML representation should be appended to the underlying Writer
Throws:
NullPointerException - if var is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpVariable)

visit

public void visit(LpFunction fun)
Appends an HTML form of a LpFunction instance to this LpHtmlPrinter. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. The HTML form of a function is its name (see LpFunction.getName()) enclosed in a <span class="function"> element.

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class EvolpPrettyPrinter<W extends Writer>
Parameters:
fun - the LpFunction instance whose HTML representation should be appended to the underlying Writer
Throws:
NullPointerException - if fun is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpFunction)

visit

public void visit(LpPredicate pred)
Appends an HTML form of a LpPredicate instance to this LpHtmlPrinter. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. The natural form of a predicate is its name (see LpPredicate.getName()) enclosed in a <span class="predicate"> element.

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class EvolpPrettyPrinter<W extends Writer>
Parameters:
pred - the LpPredicate instance whose HTML representation should be appended to the underlying Writer
Throws:
NullPointerException - if pred is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpPredicate)

appendOuterRule

protected void appendOuterRule(LpRule rule)
Takes care of writing an ordinary rule, just like LpPrettyPrinter does. The rule is enclosed in a <p class="rule"> element.

Overrides:
appendOuterRule in class EvolpPrettyPrinter<W extends Writer>
Parameters:
rule - the rule to write
Throws:
NullPointerException - if rule is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer