com.cleancode.html
Class Generator

java.lang.Object
  extended by com.cleancode.html.Generator

public class Generator
extends Object

Provides output formatted for web browsers using HTML. It derives from the Perl module of the same name, but contains only a subset of the methods defined there.
TODO convert remaining description from Perl

Since:
CleanCode 0.9
Version:
$Revision: 9 $
Author:
Michael Sorens

Nested Class Summary
static class Generator.Test
          TODO -- nested test class--move to JUnit.
 
Field Summary
static String VERSION
          Current version of this class.
 
Constructor Summary
Generator()
          Creates a Generator object to generate HTML output.
 
Method Summary
 String emphasis(String msg)
          Builds an italic element.
 String escapeHTML(String msg)
          Escapes symbols that have special meaning in HTML.
 String generic(String tag, String msg)
          Builds a generic tag without attributes.
 String generic(String tag, String msg, HashMap<String,String> attributes)
          Builds a generic tag with attributes.
 String genericNL(String tag, String msg)
          Builds a generic tag without attributes but with embedded newlines.
 String genericNL(String tag, String msg, HashMap<String,String> attributes)
          Builds a generic tag with attributes and embedded newlines.
 boolean isFormatted(String msg)
          Returns a boolean indicating whether the msg is already formatted by this formatter class.
 String line(String msg)
          Builds a paragraph element without attributes.
 String line(String msg, HashMap<String,String> attributes)
          Builds a paragraph element with attributes.
 String styleLine(String msg, String style)
          Builds a paragraph with the specified CSS style but no other attributes.
 String styleLine(String msg, String style, HashMap<String,String> attributes)
          Builds a paragraph with the specified CSS style and other attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Current version of this class.

Constructor Detail

Generator

public Generator()
Creates a Generator object to generate HTML output.

Method Detail

escapeHTML

public String escapeHTML(String msg)
Escapes symbols that have special meaning in HTML. Very basic: handles ampersand (&), less-than, greater-than, and the quotation character ("). See the Perl module CGI.pm for more advanced information.

Parameters:
msg - message to process
Returns:
message with special symbols escaped

isFormatted

public boolean isFormatted(String msg)
Returns a boolean indicating whether the msg is already formatted by this formatter class. This determination is made just by checking whether the first character is a less-than symbol. (Probably should enhance this to look for <x>...</x> | <x...>.)

Parameters:
msg - message to check
Returns:
boolean indicating whether input message is already formatted

generic

public String generic(String tag,
                      String msg,
                      HashMap<String,String> attributes)
Builds a generic tag with attributes. Returns <tag attributes>msg or <tag attributes>msg</tag> controlled by inclusion in the list of singleton tags.

Parameters:
tag - name of tag to generate
msg - content of element
attributes - attributes for element
Returns:
generated element as a string

generic

public String generic(String tag,
                      String msg)
Builds a generic tag without attributes.

Parameters:
tag - name of tag to generate
msg - content of element
Returns:
generated element as a string
See Also:
generic(String, String, HashMap)

genericNL

public String genericNL(String tag,
                        String msg,
                        HashMap<String,String> attributes)
Builds a generic tag with attributes and embedded newlines. Returns <tag attributes>\nmsg\n or <tag attributes>\nmsg\n</tag>\n; controlled by inclusion in the list of singleton tags.

Parameters:
tag - name of tag to generate
msg - content of element
attributes - attributes for element
Returns:
generated element as a string

genericNL

public String genericNL(String tag,
                        String msg)
Builds a generic tag without attributes but with embedded newlines.

Parameters:
tag - name of tag to generate
msg - content of element
Returns:
generated element as a string
See Also:
genericNL(String, String, HashMap)

line

public String line(String msg,
                   HashMap<String,String> attributes)
Builds a paragraph element with attributes.

Parameters:
msg - content of element
attributes - attributes for element
Returns:
generated element as a string

line

public String line(String msg)
Builds a paragraph element without attributes.

Parameters:
msg - content of element
Returns:
generated element as a string

styleLine

public String styleLine(String msg,
                        String style,
                        HashMap<String,String> attributes)
Builds a paragraph with the specified CSS style and other attributes.

Parameters:
msg - content of element
style - CSS style name
attributes - attributes for element
Returns:
generated element as a string

styleLine

public String styleLine(String msg,
                        String style)
Builds a paragraph with the specified CSS style but no other attributes.

Parameters:
msg - content of element
style - CSS style name
Returns:
generated element as a string

emphasis

public String emphasis(String msg)
Builds an italic element.

Parameters:
msg - content of element
Returns:
generated element as a string


CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads