ccc.plugins.markup
Class XHTML

java.lang.Object
  extended by ccc.plugins.markup.XHTML

public final class XHTML
extends java.lang.Object

Helper methods for working with XHTML.

Author:
Civic Computing Ltd

Method Summary
static java.lang.String cleanUpContent(java.lang.String content)
          Clean up invalid characters and HTML tags.
static char[] escape(char character)
          Escape a html/xhtml character.
static java.lang.String escape(java.lang.String string)
          Escape a html/xhtml string.
static java.lang.String evaluateXPath(java.io.InputStream page, java.lang.String xpathExpression)
          Apply an xPath expression to an xhtml page.
static org.w3c.dom.NodeList evaluateXPathToNodeList(org.w3c.dom.Document doc, java.lang.String xpathExpression)
          Apply an xPath expression to an xhtml page.
static boolean isValid(java.io.InputStream page)
          Test whether an xhtml page is valid.
static void printErrors(java.io.InputStream page, java.io.PrintStream out)
          Validate an xhtml page and print any errors to the specified PrintStream.
static java.lang.String sanitize(java.lang.String raw)
          Sanitize a html/xhtml string.
static java.lang.String sanitizeUrl(java.lang.String raw)
          Sanitize a string representation of a URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isValid

public static boolean isValid(java.io.InputStream page)
Test whether an xhtml page is valid.

Parameters:
page - The page to be validated, as an input stream.
Returns:
True if the page is valid, false otherwise.

evaluateXPath

public static java.lang.String evaluateXPath(java.io.InputStream page,
                                             java.lang.String xpathExpression)
Apply an xPath expression to an xhtml page.

Parameters:
page - The page to which we'll apply the expression.
xpathExpression - The expression to apply.
Returns:
The results of evaluating the expression, as a String. See XPath.evaluate(String, Object) for further details.

evaluateXPathToNodeList

public static org.w3c.dom.NodeList evaluateXPathToNodeList(org.w3c.dom.Document doc,
                                                           java.lang.String xpathExpression)
Apply an xPath expression to an xhtml page. TODO: Rename method.

Parameters:
doc - The document to which we'll apply the expression.
xpathExpression - The expression to apply.
Returns:
The results of evaluating the expression, as a String. See XPath.evaluate(String, Object) for further details.

printErrors

public static void printErrors(java.io.InputStream page,
                               java.io.PrintStream out)
Validate an xhtml page and print any errors to the specified PrintStream.

Parameters:
page - The page to validate.
out - The print stream to which errors will be written.

escape

public static java.lang.String escape(java.lang.String string)
Escape a html/xhtml string.

This method converts all HTML 4.01 'markup significant' characters to their equivalent entities, as follows:

    " -> "
    & -> &
    < -> &lt;
    > -> &gt;

Parameters:
string - The string to escape.
Returns:
The escaped string.

escape

public static char[] escape(char character)
Escape a html/xhtml character.

This method converts all HTML 4.01 'markup significant' characters to their equivalent entities, as follows:

    " -> &quot;
    & -> &amp;
    < -> &lt;
    > -> &gt;

Parameters:
character - The character to escape.
Returns:
The equivalent escaped characters.

cleanUpContent

public static java.lang.String cleanUpContent(java.lang.String content)
Clean up invalid characters and HTML tags.

Parameters:
content - The content to clean up.
Returns:
Cleaned up content.

sanitize

public static java.lang.String sanitize(java.lang.String raw)
Sanitize a html/xhtml string.

Parameters:
raw - The un-sanitized string.
Returns:
The sanitized string.

sanitizeUrl

public static java.lang.String sanitizeUrl(java.lang.String raw)
Sanitize a string representation of a URL.

This method only allows correctly form HTTP URLs.

Parameters:
raw - The un-sanitized string.
Returns:
The input string or a zero length string if the URL is sanitized.


Copyright © 2010. All Rights Reserved.