com.google.caja.parser.html
Class Nodes

java.lang.Object
  extended by com.google.caja.parser.html.Nodes

public class Nodes
extends java.lang.Object

Utilities for dealing with HTML/XML DOM trees.

Author:
mikesamuel@gmail.com

Field Summary
private static java.lang.String FP_KEY
           
private static java.lang.String RAW_TEXT_KEY
           
private static FilePosition UNKNOWN_START_OF_FILE
           
 
Constructor Summary
private Nodes()
           
 
Method Summary
static java.lang.Iterable<? extends org.w3c.dom.Attr> attributesOf(org.w3c.dom.Element el)
          An Iterable over the attributes of the given element.
static java.lang.Iterable<? extends org.w3c.dom.Node> childrenOf(org.w3c.dom.Node n)
          A left to right Iterable over the children of the given node.
static java.lang.String decode(java.lang.String html)
          Replace entity references in HTML CDATA with their plain text equivalents.
static java.lang.String encode(java.lang.String raw)
          Convert HTML to plain text by replacing HTML special characters with HTML entities.
static FilePosition getFilePositionFor(org.w3c.dom.Node node)
          Returns the last file position associated with the given node by setFilePositionFor(org.w3c.dom.Node, com.google.caja.lexer.FilePosition) or related methods.
static FilePosition getFilePositionForValue(org.w3c.dom.Attr a)
          The file position of the value of the given attribute.
static java.lang.String getRawText(org.w3c.dom.Text cd)
           
static java.lang.String getRawValue(org.w3c.dom.Attr a)
           
static
<T extends org.w3c.dom.Node>
java.lang.Iterable<T>
nodeListIterable(org.w3c.dom.NodeList nl, java.lang.Class<? extends T> outType)
          An Iterable over the elements of the given node list.
static java.lang.String render(org.w3c.dom.Node node)
           
static java.lang.String render(org.w3c.dom.Node node, boolean asXml)
          Deprecated. 
static java.lang.String render(org.w3c.dom.Node node, MarkupRenderMode renderMode)
           
static void render(org.w3c.dom.Node node, Namespaces ns, RenderContext rc)
          Serializes the given DOM node to HTML or XML.
static void render(org.w3c.dom.Node node, RenderContext rc)
          Serializes the given DOM node to HTML or XML.
static void setFilePositionFor(org.w3c.dom.Node node, FilePosition pos)
           
static void setFilePositionForValue(org.w3c.dom.Attr a, FilePosition pos)
           
static void setRawText(org.w3c.dom.Text cd, java.lang.String html)
          Associates the HTML textual value as parsed with the given node.
static void setRawValue(org.w3c.dom.Attr a, java.lang.String html)
          Associates the HTML textual value as parsed with the given attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FP_KEY

private static final java.lang.String FP_KEY
See Also:
Constant Field Values

RAW_TEXT_KEY

private static final java.lang.String RAW_TEXT_KEY
See Also:
Constant Field Values

UNKNOWN_START_OF_FILE

private static final FilePosition UNKNOWN_START_OF_FILE
Constructor Detail

Nodes

private Nodes()
Method Detail

childrenOf

public static java.lang.Iterable<? extends org.w3c.dom.Node> childrenOf(org.w3c.dom.Node n)
A left to right Iterable over the children of the given node.


attributesOf

public static java.lang.Iterable<? extends org.w3c.dom.Attr> attributesOf(org.w3c.dom.Element el)
An Iterable over the attributes of the given element.


nodeListIterable

public static <T extends org.w3c.dom.Node> java.lang.Iterable<T> nodeListIterable(org.w3c.dom.NodeList nl,
                                                                                  java.lang.Class<? extends T> outType)
An Iterable over the elements of the given node list.

Throws:
java.lang.ClassCastException - if a member is fetched that is not an instance of outType/

getFilePositionFor

public static FilePosition getFilePositionFor(org.w3c.dom.Node node)
Returns the last file position associated with the given node by setFilePositionFor(org.w3c.dom.Node, com.google.caja.lexer.FilePosition) or related methods.


getFilePositionForValue

public static FilePosition getFilePositionForValue(org.w3c.dom.Attr a)
The file position of the value of the given attribute.


setFilePositionFor

public static void setFilePositionFor(org.w3c.dom.Node node,
                                      FilePosition pos)
See Also:
getFilePositionFor(org.w3c.dom.Node)

setFilePositionForValue

public static void setFilePositionForValue(org.w3c.dom.Attr a,
                                           FilePosition pos)

setRawValue

public static void setRawValue(org.w3c.dom.Attr a,
                               java.lang.String html)
Associates the HTML textual value as parsed with the given attribute. If a client may have called Node.setNodeValue(String) or an alias since parsing, the output should not be trusted.


getRawValue

public static java.lang.String getRawValue(org.w3c.dom.Attr a)
See Also:
setRawValue(org.w3c.dom.Attr, java.lang.String)

setRawText

public static void setRawText(org.w3c.dom.Text cd,
                              java.lang.String html)
Associates the HTML textual value as parsed with the given node. If a client may have called Node.setNodeValue(String) or an alias since parsing, the output should not be trusted.


getRawText

public static java.lang.String getRawText(org.w3c.dom.Text cd)
See Also:
setRawText(org.w3c.dom.Text, java.lang.String)

decode

public static java.lang.String decode(java.lang.String html)
Replace entity references in HTML CDATA with their plain text equivalents.


encode

public static java.lang.String encode(java.lang.String raw)
Convert HTML to plain text by replacing HTML special characters with HTML entities.


render

public static void render(org.w3c.dom.Node node,
                          Namespaces ns,
                          RenderContext rc)
Serializes the given DOM node to HTML or XML.

Parameters:
rc - a context where the token consumer is typically a Concatenator, and the RenderContext.asXml() is significant.

render

public static void render(org.w3c.dom.Node node,
                          RenderContext rc)
Serializes the given DOM node to HTML or XML.

Parameters:
rc - a context where the token consumer is typically a Concatenator, and the RenderContext.asXml() is significant.

render

public static java.lang.String render(org.w3c.dom.Node node)

render

@Deprecated
public static java.lang.String render(org.w3c.dom.Node node,
                                                 boolean asXml)
Deprecated. 


render

public static java.lang.String render(org.w3c.dom.Node node,
                                      MarkupRenderMode renderMode)


Copyright (C) 2008 Google Inc.
Licensed under the Apache License, Version 2.0