Class PMRDOMUtils
java.lang.Object
org.episteme.natural.chemistry.loaders.cml.util.PMRDOMUtils
re-usable routines to support PMR* interfaces
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Nodeclones node in context of new document.static Attr[]copyAttributes(Element e, Picker p) copies attributes chosen via aPickercallback.createVector(NamedNodeMap nodeMap) converts a NamedNodeMap to a vectorcreateVector(NodeList nodes) converts a NodeList to a vectorstatic Attr[]cutAttributes(Element e, Picker p) copies and removes attributes chosen via aPickercallback.static Stringconvenience routine to output a Node as a Stringstatic voiddeleteWhitespaceDescendants(Document document) recursively removes all whitespace nodesstatic voiddeleteWhitespaceDescendants(Element element) recursively deletes all whitespace descendantsstatic Enumeration<Node> depthFirstEnumeration(Element element) return all descendants in document orderstatic ElementgetAncestor(Element element, String tagName) gets first ancestor of 'element' with tagName; [element is not its own ancestor]getAncestors(Element element) gets all ancestors of 'element' including the document Element but not Document.static StringgetAttribute(Element element, String attName) Kludge to overcome cases where getAttribute(attName) has been subvertedstatic StringgetAttributeString(Attr att) returns a string representing a single attribute in a start tag, for example foo=bar plugh"; String starts with space and delimiters are QUOT, not APOSstatic StringgetAttributeString(Element element) returns the attributes in concatenated text form (suitable for insertion to start tags).static ElementgetChildElement(Element element, int index) get the index'th Element child If none returns null Count ignores non-Element nodesgetChildElements(Element element) get all Element children If none, returns empty VectorgetChildrenWithElementName(Element element, String name) gets vector of Element children with given element name (ignored if name is null or bad value of sensitivity).static ElementgetFirstChildWithElementName(Element element, String name) gets first child with given element name (ignored if name is null).static TextgetPCDATAChildNode(Element element) if this has a single PCDATA child, returns it, else nullstatic StringgetPCDATAContent(Element element) if this has a single PCDATA child, returns its string value, else nullstatic booleanisEmptyAttribute(String attributeValue) Gets the emptyAttribute attribute of the PMRDOMUtils classstatic booleanisEmptyElement(Element element) Gets the emptyElement attribute of the PMRDOMUtils classstatic Stringnormalizes all whitespace in a string to single spacesstatic Stringconvenience routinestatic Stringconvenience routine to output a Node as a Stringstatic Stringconvenience routinestatic voidoutputChildContent(Element element, Writer w, int type, int level) subclassed by specialist classesstatic voidoutputEmptyTag(Element element, Writer w, int type, int level) subclassed by specialist classesstatic voidoutputEndElement(Element element, Writer w, int level) for building the tree If writer is null, noop; else outputs an end tagstatic voidoutputEndTag(Element element, Writer w, int type, int level) subclassed by specialist classesstatic StringoutputEventStream(Node node, Writer w, int type, int level) Description of the Methodstatic StringoutputEventStream(Node node, Writer w, int type, int level, String encoding, boolean xmlDecl, String dtd) same as above but also outputs XMLDeclaration and DOCTYPEstatic voidoutputStartElement(Element element, Writer w, Element parentNode, int level) for building the tree If writer is null, builds a tree by adding this to parentNode, else outputs a start tag.static voidoutputStartTag(Element element, Writer w, int type, int level) subclassed by specialist classesstatic voidpasteAttributes(Element e, Attr[] attrs) adds Attributes to a given Element.pickElements(Element rootElement, Picker p) match decendent elements.static voidremoveChildNodes(Element element) remove all child nodesstatic voidremoveNode(Node node) remove a node from its parentstatic voidsetPCDATAContent(Element element, String s) Sets a string to be the content of an existing single PCDATANode If there are no children, create a new PCDATANode.
-
Field Details
-
PRETTY
public static final int PRETTYDescription of the Field- See Also:
-
-
Constructor Details
-
PMRDOMUtils
public PMRDOMUtils()
-
-
Method Details
-
deleteWhitespaceDescendants
recursively deletes all whitespace descendants- Parameters:
element- Description of the Parameter
-
removeNode
remove a node from its parent- Parameters:
node- to be removed
-
removeChildNodes
remove all child nodes- Parameters:
element- to remove child nodes from
-
depthFirstEnumeration
return all descendants in document order- Parameters:
element- Description of the Parameter- Returns:
- Description of the Return Value
-
getChildElements
-
getChildElement
-
getAncestors
-
getAncestor
-
createVector
-
createVector
converts a NamedNodeMap to a vector the vector (but not its elements) is safely mutable. shallowCopies the items in the nodemap- Parameters:
nodeMap- NodeMap to copy- Returns:
- the equiavlent vector
-
getAttribute
-
getAttributeString
returns the attributes in concatenated text form (suitable for insertion to start tags). If none, returns "". Example:
xml:link="simple" href="http://www.some/where"- Parameters:
element- Description of the Parameter- Returns:
- String the attribute String
-
getAttributeString
-
normalizeString
-
getChildrenWithElementName
gets vector of Element children with given element name (ignored if name is null or bad value of sensitivity).- Parameters:
element- Description of the Parametername- Description of the Parameter- Returns:
- Vector the vector of children (empty if none)
-
getFirstChildWithElementName
-
getPCDATAContent
-
getPCDATAChildNode
-
setPCDATAContent
Sets a string to be the content of an existing single PCDATANode If there are no children, create a new PCDATANode. If there are non-PCDATA children or more than one PCDATANode child, return without action.- Parameters:
element- The new pCDATAContent values- The new pCDATAContent value
-
outputEventStream
Description of the Method- Parameters:
node- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameter- Returns:
- Description of the Return Value
- Throws:
IOException- Description of the Exception
-
debug
-
output
-
output
convenience routine- Parameters:
document- Description of the Parameterw- Description of the Parameter- Returns:
- Description of the Return Value
- Throws:
IOException- Description of the Exception
-
output
convenience routine- Parameters:
node- Description of the Parameterw- Description of the Parameter- Returns:
- Description of the Return Value
- Throws:
IOException- Description of the Exception
-
outputEventStream
public static String outputEventStream(Node node, Writer w, int type, int level, String encoding, boolean xmlDecl, String dtd) throws IOException same as above but also outputs XMLDeclaration and DOCTYPE- Parameters:
node- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameterencoding- Description of the ParameterxmlDecl- Description of the Parameterdtd- Description of the Parameter- Returns:
- Description of the Return Value
- Throws:
IOException- Description of the Exception
-
isEmptyElement
Gets the emptyElement attribute of the PMRDOMUtils class- Parameters:
element- Description of the Parameter- Returns:
- The emptyElement value
-
outputStartTag
public static void outputStartTag(Element element, Writer w, int type, int level) throws IOException subclassed by specialist classes- Parameters:
element- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
outputEmptyTag
public static void outputEmptyTag(Element element, Writer w, int type, int level) throws IOException subclassed by specialist classes- Parameters:
element- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
outputStartElement
public static void outputStartElement(Element element, Writer w, Element parentNode, int level) throws IOException for building the tree If writer is null, builds a tree by adding this to parentNode, else outputs a start tag.- Parameters:
element- Description of the Parameterw- Description of the ParameterparentNode- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
outputChildContent
public static void outputChildContent(Element element, Writer w, int type, int level) throws IOException subclassed by specialist classes- Parameters:
element- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
outputEndTag
subclassed by specialist classes- Parameters:
element- Description of the Parameterw- Description of the Parametertype- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
outputEndElement
for building the tree If writer is null, noop; else outputs an end tag- Parameters:
element- Description of the Parameterw- Description of the Parameterlevel- Description of the Parameter- Throws:
IOException- Description of the Exception
-
deleteWhitespaceDescendants
recursively removes all whitespace nodes- Parameters:
document- Description of the Parameter
-
isEmptyAttribute
Gets the emptyAttribute attribute of the PMRDOMUtils class- Parameters:
attributeValue- Description of the Parameter- Returns:
- The emptyAttribute value
-
cloneNode
clones node in context of new document. provides workaraound for setDocument(newDocument) which is DOM3 uses document.createFoo() does not maintain namespaces only does Element, Text, Comment, ProcessingInstruction at present creates W3C classes, not subclasses cannot clone Document node and returns null cloned node will have no parent- Parameters:
node- to clonedocument- context document- Returns:
- new node
-
pickElements
match decendent elements. Finds all decendent elements of rootElement that match the criteria defined by p.- Parameters:
rootElement- the element who along with its children will be processed.p- thePickerused to match the elements- Returns:
- a List of the matching elements, or null if none matched.
-
copyAttributes
copies attributes chosen via aPickercallback. Using the Picker, choose a set of Attributes to be copied from the Element.- Parameters:
e- the element whose Attributes are to be processedp- the picker that determines whether to choose the attribute- Returns:
- an array of the matching Attributes, or null if none matched.
-
cutAttributes
copies and removes attributes chosen via aPickercallback. Using the Picker, choose a set of Attributes to be removed from the Element. These Attributes are then returned- Parameters:
e- the element whose attributes are to be processedp- thePickerthat determines whether to choose the attribute- Returns:
- an array of the matching Attributes, or null if none matched.
- Throws:
DOMException- propagated from the call to remove the Attribute node from the Element.
-
pasteAttributes
adds Attributes to a given Element. Adds a set of Attributes to an Element.- Parameters:
e- the element whose attributes are to be processedattrs- an array of the Attributes to be added- Throws:
DOMException- propagated from the call to add the Attribute node to the Element.
-