org.melati.util
Class HTMLUtils

Package class diagram package HTMLUtils
java.lang.Object
  extended by org.melati.util.HTMLUtils

public final class HTMLUtils
extends Object

An assortment of useful things to do with HTML.


Nested Class Summary
static class HTMLUtils.TagInstance
          An Instance of a tag.
 
Field Summary
static String dtdNameForHTMLParser
          The DTD name.
 
Method Summary
static void add(ContentModel cm, Element existing, Element alt)
          Add an Element to the ContentModel.
static void addToContentModels(DTD dtd, Element existing, Element alt)
          Add element to a DTD.
static DTD dtdForHTMLParser()
           
static String entitied(String s)
          Escape the given string as PCDATA without regard for any characters that cannot be encoded in some required character set.
static String entitied(String s, boolean mapBR, String encoding, boolean markup)
          Return the String with all high value ASCII characters replaced with HTML entities.
static String entityFor(char c, boolean mapBR, CharsetEncoder ce, boolean markup)
          If the given character has special meaning in HTML or will not necessarily encode in the character set, then return an escape string.
static String jsEscaped(String s)
          Javascript escape a String.
static String jsEscapeFor(char c)
          Javascript escape sequence for a character, if any, otherwise null.
static String stringOf(HTML.Tag tag, AttributeSet attributes)
           
static void write(Writer w, HTML.Tag tag, AttributeSet attributes)
          Write a tag to a Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dtdNameForHTMLParser

public static final String dtdNameForHTMLParser
The DTD name.

See Also:
Constant Field Values
Method Detail

add

public static void add(ContentModel cm,
                       Element existing,
                       Element alt)
Add an Element to the ContentModel.

Parameters:
cm - the ContentModel to add to
existing - existing element
alt - alternate element

addToContentModels

public static void addToContentModels(DTD dtd,
                                      Element existing,
                                      Element alt)
Add element to a DTD.

Parameters:
dtd - DTD to add to
existing - existing element
alt - alternate element

dtdForHTMLParser

public static DTD dtdForHTMLParser()
Returns:
a DTD

entityFor

public static String entityFor(char c,
                               boolean mapBR,
                               CharsetEncoder ce,
                               boolean markup)
If the given character has special meaning in HTML or will not necessarily encode in the character set, then return an escape string.

The name of this method implies the character is escaped as a character entity but if the second argument is true then newlines are encoded as <BR>. This is not required for attribute values.

Which characters will necessarily encode depends on the charset. For backward compatibility if a charset is not passed we assume the character will encode. If a charset is passed and a character does not encode then we replace it with a numeric character reference (not an entity either but pretty similar).

Parameters:
c - character to lookup entity for
mapBR - whether to replace line ends
ce - an encoder
markup - whether string contains markup
Returns:
an entity or null

entitied

public static String entitied(String s,
                              boolean mapBR,
                              String encoding,
                              boolean markup)
Return the String with all high value ASCII characters replaced with HTML entities.

Parameters:
s - input String
mapBR - whether to replace line ends with html breaks
encoding - the encoding of the input string
markup - whether string is an sgml fragment
Returns:
the input with appropriate substitutions

entitied

public static String entitied(String s)
Escape the given string as PCDATA without regard for any characters that cannot be encoded in some required character set.

This is for backward compatibility as it is used below.

Parameters:
s - the String to replace special characters from
Returns:
a new String with special characters replaced with entities
See Also:
entitied(String, boolean, String, boolean)

jsEscapeFor

public static String jsEscapeFor(char c)
Javascript escape sequence for a character, if any, otherwise null.

Parameters:
c - the character
Returns:
an escape sequence or null

jsEscaped

public static String jsEscaped(String s)
Javascript escape a String.

Parameters:
s - the String to escape
Returns:
the escaped String

write

public static void write(Writer w,
                         HTML.Tag tag,
                         AttributeSet attributes)
                  throws IOException
Write a tag to a Writer.

Parameters:
w - the Writer to write to
tag - the Tag to write
attributes - the Tag's attributes
Throws:
IOException - if there is a problem writing

stringOf

public static String stringOf(HTML.Tag tag,
                              AttributeSet attributes)
Parameters:
tag - the Tag
attributes - the Tag's attributes
Returns:
a String version of the Tag


Copyright © 2000-2010 PanEris. All Rights Reserved.