| java.lang.Object edu.indiana.lib.twinpeaks.util.DomUtils
DomUtils | public class DomUtils (Code) | | |
Method Summary | |
public static void | addEntity(Element element, String entity) Add an entity to a specified Element. | public static void | addText(Element element, String text) Add Text object to an Element. | public static void | copyDocument(Document source, Document target) | public static void | copyDocumentNode(Node source, Document target) | public static Element | createElement(Document document, String name) | public static Element | createElement(Element parent, String name) | public static Document | createXmlDocument() | public static Document | createXmlDocument(String rootName) Start a new XML Document. | public static String | getAllText(Node parent) Get any text associated with this element and it's children. | public static String | getAllTextAtNode(Node parent) | public static String | getAttribute(Element element, String name) Get an Attribute from an Element. | public static Node | getChildSiblingByName(Node currentNode, String tagName) | public static Element | getElement(Element element, String name) Return the first named Element found. | public static NodeList | getElementList(Element element, String name) Return a list of named Elements. | public static String | getFirstText(Node parent) | public static Node | getNextNodeByName(Node currentNode, String tagName) | public static Node | getNextSiblingByName(Node currentNode, String tagName) | public static Node | getPreviousNodeByName(Node currentNode, String tagName) | public static Node | getPreviousSiblingByName(Node currentNode, String tagName) | public static String | getText(Node parent) | public static String | getTextNodeByNumber(Node parent, int number) | public static DocumentBuilder | getXmlDocumentBuilder() Get a DOM Document builder. | public static String | normalizeText(String update) | public static String | normalizeText(String original, String update) | public static Document | parseHtmlBytes(byte[] html) Parse HTML text (from a raw byte array) into a Document. | public static Document | parseHtmlString(String html) Parse HTML text (from a String) into a Document. | public static Document | parseXmlBytes(byte[] xml) Parse XML text (from a raw byte array) into a Document. | public static Document | parseXmlFile(String filename) Parse an XML file into a Document. | public static Document | parseXmlReader(Reader xmlReader) Parse XML text (from a Reader) into a Document. | public static Document | parseXmlStream(InputStream xmlStream) Parse XML text (from an input stream) into a Document. | public static Document | parseXmlString(String xml) Parse XML text (from a string) into a Document. | public Node | removeNode(Node node) Remove this node from its parent. | public static List | selectElementsByAttributeValue(Element element, String name, String attribute, String value) Return a list of named Elements with a specific attribute value. | public static List | selectElementsByAttributeValue(Element element, String name, String attribute, String value, boolean returnFirst) Return a list of named Elements with a specific attribute value. | public static Element | selectFirstElementByAttributeValue(Element element, String name, String attribute, String value) Return the first named Element with a specific attribute value. | public static String | serialize(Object object) Write formatted XML text to a String. | public static void | serializeXml(Node node, OutputStream target) Write formatted XML text to supplied OutputStream. | public static void | serializeXml(Node node, Writer writer) Write formatted XML text to supplied Writer. | public static void | setAttribute(Element element, String name, String value) | public static String | textSearch(Node parent, boolean recursiveSearch) |
INPUT_ENCODING | final public static String INPUT_ENCODING(Code) | | |
addEntity | public static void addEntity(Element element, String entity)(Code) | | Add an entity to a specified Element.
(eg DomUtils.addEntity(element, "nbsp"); )
Parameters: element - the containing element Parameters: entity - the entity to add |
addText | public static void addText(Element element, String text)(Code) | | Add Text object to an Element.
Parameters: element - the containing element Parameters: text - the text to add |
copyDocument | public static void copyDocument(Document source, Document target)(Code) | | Copy an XML document, adding it as a child of the target document root
Parameters: source - Document to copy Parameters: target - Document to contain copy |
copyDocumentNode | public static void copyDocumentNode(Node source, Document target)(Code) | | Copy a Node from one source document, adding it to the document
root of a different, target Document
Parameters: source - Document to copy Parameters: target - Document to contain copy |
createElement | public static Element createElement(Document document, String name)(Code) | | Create a new element
Parameters: document - Document to contain the new element Parameters: name - the element name new Element |
createElement | public static Element createElement(Element parent, String name)(Code) | | Add a new element to the given parent
Parameters: parent - the parent Element Parameters: name - the child name new Element |
createXmlDocument | public static Document createXmlDocument(String rootName) throws DomException(Code) | | Start a new XML Document.
Parameters: rootName - The name of the Document root Element (created here) the Document throws: DomException - |
getAllText | public static String getAllText(Node parent)(Code) | | Get any text associated with this element and it's children. Null if none.
Parameters: parent - the node containing text Text |
getAllTextAtNode | public static String getAllTextAtNode(Node parent)(Code) | | Get the text associated with this element, at all suboordinate levels
Parameters: parent - the node containing text Text (trimmed of leading/trailing whitespace, null if none) |
getAttribute | public static String getAttribute(Element element, String name)(Code) | | Get an Attribute from an Element. Returns an empty String if none found
Parameters: element - the containing Element Parameters: name - the attribute name Attribute as a String |
getChildSiblingByName | public static Node getChildSiblingByName(Node currentNode, String tagName)(Code) | | Search for a named child of a given node
Parameters: currentNode - Starting point for our search Parameters: tagName - Node name to look up matching Node (null if none) |
getElement | public static Element getElement(Element element, String name)(Code) | | Return the first named Element found. Null if none.
Parameters: element - the containing Element Parameters: name - the tag name matching Element (null if none) |
getElementList | public static NodeList getElementList(Element element, String name)(Code) | | Return a list of named Elements.
Parameters: element - the containing Element Parameters: name - the tag name NodeList of matching elements |
getFirstText | public static String getFirstText(Node parent)(Code) | | Get the first text node associated with this element
Parameters: parent - the node containing text Text (trimmed of leanding/trailing whitespace, null if none) |
getNextSiblingByName | public static Node getNextSiblingByName(Node currentNode, String tagName)(Code) | | Search our next siblings for a given node
Parameters: currentNode - Starting point for our search Parameters: tagName - Node name to look up matching Node (null if none) |
getPreviousNodeByName | public static Node getPreviousNodeByName(Node currentNode, String tagName)(Code) | | Search up the tree for a given node
Parameters: currentNode - Starting point for our search Parameters: tagName - Node name to look up matching Node (null if none) |
getPreviousSiblingByName | public static Node getPreviousSiblingByName(Node currentNode, String tagName)(Code) | | Search earlier siblings for a given node
Parameters: currentNode - Starting point for our search Parameters: tagName - Node name to look up matching Node (null if none) |
getText | public static String getText(Node parent)(Code) | | Get the text associated with this element, at this level only
Parameters: parent - the node containing text Text (trimmed of leading/trailing whitespace, null if none) |
getTextNodeByNumber | public static String getTextNodeByNumber(Node parent, int number)(Code) | | Get the specified text node associated with this element
Parameters: parent - the node containing text Parameters: number - The text node to fetch (1st, 2nd, etc) Text (trimmed of leanding/trailing whitespace, null if none) |
normalizeText | public static String normalizeText(String update)(Code) | | "Normalize" XML text node content to create a simple string
Parameters: update - Text to add to the original string Concatenated contents (trimmed, pagination characters (\r, \n, etc.)removed, with a space seperator) |
normalizeText | public static String normalizeText(String original, String update)(Code) | | "Normalize" XML text node content to create a simple string
Parameters: original - Original text Parameters: update - Text to add to the original string Concatenated contents (trimmed, pagination characters (\r, \n, etc.)removed, with a space seperator) |
parseHtmlBytes | public static Document parseHtmlBytes(byte[] html) throws DomException(Code) | | Parse HTML text (from a raw byte array) into a Document.
Parameters: html - The HTML text DOM Document throws: DomException - The used to be:parseHtmlStream(new ByteArrayInputStream(html)); |
parseHtmlString | public static Document parseHtmlString(String html) throws DomException(Code) | | Parse HTML text (from a String) into a Document.
Parameters: html - The HTML text DOM Document throws: DomException - This used to be:return parseHtmlReader(new StringReader(html)); |
parseXmlBytes | public static Document parseXmlBytes(byte[] xml) throws DomException(Code) | | Parse XML text (from a raw byte array) into a Document.
Parameters: xml - The XML text DOM Document throws: DomException - |
removeNode | public Node removeNode(Node node)(Code) | | Remove this node from its parent.
Parameters: node - the node to remove Node removed |
selectElementsByAttributeValue | public static List selectElementsByAttributeValue(Element element, String name, String attribute, String value)(Code) | | Return a list of named Elements with a specific attribute value.
Parameters: element - the containing Element Parameters: name - the tag name Parameters: attribute - Attribute name Parameters: value - Attribute value List of matching elements |
selectElementsByAttributeValue | public static List selectElementsByAttributeValue(Element element, String name, String attribute, String value, boolean returnFirst)(Code) | | Return a list of named Elements with a specific attribute value.
Parameters: element - the containing Element Parameters: name - the tag name Parameters: attribute - Attribute name Parameters: value - Attribute value Parameters: returnFirst - Return only the first matching value? List of matching elements |
selectFirstElementByAttributeValue | public static Element selectFirstElementByAttributeValue(Element element, String name, String attribute, String value)(Code) | | Return the first named Element with a specific attribute value.
Parameters: element - the containing Element Parameters: name - the tag name Parameters: attribute - Attribute name Parameters: value - Attribute value The first matching Element (null if none) |
serialize | public static String serialize(Object object) throws DomException(Code) | | Write formatted XML text to a String.
Parameters: object - The XML Document, HTML Document, or Element to write String containing the formatted document text throws: DomException - |
serializeXml | public static void serializeXml(Node node, OutputStream target) throws DomException(Code) | | Write formatted XML text to supplied OutputStream.
Parameters: node - Node to write Parameters: target - stream to write to throws: DomException - |
serializeXml | public static void serializeXml(Node node, Writer writer) throws DomException(Code) | | Write formatted XML text to supplied Writer.
Parameters: node - the Node to write Parameters: writer - Writer the document is written to throws: DomException - |
setAttribute | public static void setAttribute(Element element, String name, String value)(Code) | | Set an Attribute in an Element
Parameters: element - the containing Element Parameters: name - the attribute name Parameters: value - the attribute value |
textSearch | public static String textSearch(Node parent, boolean recursiveSearch)(Code) | | Get the text associated with this element at this level only, or
recursivley, searching through all child elements
Parameters: parent - the node containing text Parameters: recursiveSearch - Search all child elements? Text (trimmed of leading/trailing whitespace, null if none) |
|
|