/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2002,2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Some useful utility methods.
* This class was modified in Xerces2 with a view to abstracting as
* much as possible away from the representation of the underlying
* parsed structure (i.e., the DOM). This was done so that, if Xerces
* ever adopts an in-memory representation more efficient than the DOM
* (such as a DTM), we should easily be able to convert our schema
* parsing to utilize it.
*
* @version $Id: DOMUtil.java,v 1.7 2010-11-01 04:40:14 joehw Exp $
*/
public class DOMUtil {
//
// Constructors
//
/** This class cannot be instantiated. */
protected DOMUtil() {}
//
// Public static methods
//
/**
* Copies the source tree into the specified place in a destination
* tree. The source node and its children are appended as children
* of the destination node.
* <p>
* <em>Note:</em> This is an iterative implementation.
*/
// get node factory
// placement variables
// traverse source tree
// copy this node
switch (type) {
case Node.CDATA_SECTION_NODE: {
break;
}
case Node.COMMENT_NODE: {
break;
}
case Node.ELEMENT_NODE: {
for (int i = 0; i < attrCount; i++) {
}
}
break;
}
case Node.ENTITY_REFERENCE_NODE: {
break;
}
case Node.PROCESSING_INSTRUCTION_NODE: {
place.getNodeValue());
break;
}
break;
}
default: {
throw new IllegalArgumentException("can't copy node type, "+
type+" ("+
}
}
// iterate over children
if (place.hasChildNodes()) {
}
// advance
else {
}
}
}
} // copyInto(Node,Node)
/** Finds and returns the first child element node. */
// search for node
}
}
// not found
return null;
} // getFirstChildElement(Node):Element
/** Finds and returns the first visible child element node. */
// search for node
}
}
// not found
return null;
} // getFirstChildElement(Node):Element
/** Finds and returns the first visible child element node. */
// search for node
}
}
// not found
return null;
} // getFirstChildElement(Node):Element
/** Finds and returns the last child element node.
* Overload previous method for non-Xerces node impl.
*/
// search for node
}
}
// not found
return null;
} // getLastChildElement(Node):Element
/** Finds and returns the last visible child element node. */
// search for node
}
}
// not found
return null;
} // getLastChildElement(Node):Element
/** Finds and returns the last visible child element node.
* Overload previous method for non-Xerces node impl
*/
// search for node
}
}
// not found
return null;
} // getLastChildElement(Node):Element
/** Finds and returns the next sibling element node. */
// search for node
}
}
// not found
return null;
} // getNextSiblingElement(Node):Element
// get next visible (un-hidden) node.
// search for node
}
}
// not found
return null;
} // getNextSiblingdElement(Node):Element
// get next visible (un-hidden) node, overload previous method for non Xerces node impl
// search for node
}
}
// not found
return null;
} // getNextSiblingdElement(Node):Element
// set this Node as being hidden
} // setHidden(node):void
// set this Node as being hidden, overloaded method
}
else {
}
} // setHidden(node):void
// set this Node as being visible
} // setVisible(node):void
// set this Node as being visible, overloaded method
}
else {
}
} // setVisible(node):void
// is this node hidden?
return false;
} // isHidden(Node):boolean
// is this node hidden? overloaded method
}
else {
}
} // isHidden(Node):boolean
/** Finds and returns the first child node with the given name. */
// search for node
}
}
}
// not found
return null;
} // getFirstChildElement(Node,String):Element
/** Finds and returns the last child node with the given name. */
// search for node
}
}
}
// not found
return null;
} // getLastChildElement(Node,String):Element
/** Finds and returns the next sibling node with the given name. */
// search for node
}
}
}
// not found
return null;
} // getNextSiblingdElement(Node,String):Element
/** Finds and returns the first child node with the given qualified name. */
// search for node
}
}
}
// not found
return null;
} // getFirstChildElementNS(Node,String,String):Element
/** Finds and returns the last child node with the given qualified name. */
// search for node
}
}
}
// not found
return null;
} // getLastChildElementNS(Node,String,String):Element
/** Finds and returns the next sibling node with the given qualified name. */
// search for node
}
}
}
// not found
return null;
} // getNextSiblingdElementNS(Node,String,String):Element
/** Finds and returns the first child node with the given name. */
// search for node
}
}
}
}
// not found
return null;
} // getFirstChildElement(Node,String[]):Element
/** Finds and returns the last child node with the given name. */
// search for node
}
}
}
}
// not found
return null;
} // getLastChildElement(Node,String[]):Element
/** Finds and returns the next sibling node with the given name. */
// search for node
}
}
}
}
// not found
return null;
} // getNextSiblingdElement(Node,String[]):Element
/** Finds and returns the first child node with the given qualified name. */
// search for node
}
}
}
}
// not found
return null;
} // getFirstChildElementNS(Node,String[][]):Element
/** Finds and returns the last child node with the given qualified name. */
// search for node
}
}
}
}
// not found
return null;
} // getLastChildElementNS(Node,String[][]):Element
/** Finds and returns the next sibling node with the given qualified name. */
// search for node
}
}
}
}
// not found
return null;
} // getNextSiblingdElementNS(Node,String[][]):Element
/**
* Finds and returns the first child node with the given name and
* attribute name, value pair.
*/
// search for node
return element;
}
}
}
// not found
return null;
} // getFirstChildElement(Node,String,String,String):Element
/**
* Finds and returns the last child node with the given name and
* attribute name, value pair.
*/
// search for node
return element;
}
}
}
// not found
return null;
} // getLastChildElement(Node,String,String,String):Element
/**
* Finds and returns the next sibling node with the given name and
* attribute name, value pair. Since only elements have attributes,
* the node returned will be of type Node.ELEMENT_NODE.
*/
// search for node
return element;
}
}
}
// not found
return null;
} // getNextSiblingElement(Node,String,String,String):Element
/**
* Returns the concatenated child text of the specified node.
* This method only looks at the immediate children of type
* <code>Node.TEXT_NODE</code> or the children of any child
* node that is of type <code>Node.CDATA_SECTION_NODE</code>
* for the concatenation.
*
* @param node The node to look at.
*/
// is there anything to do?
return null;
}
// concatenate children text
}
}
}
// return text value
} // getChildText(Node):String
// return the name of this element
return node.getNodeName();
} // getLocalName(Element): String
/** returns local name of this element if not null, otherwise
returns the name of the node
*/
} // getLocalName(Element): String
return null;
} // getParent(Element):Element
// get the Document of which this Node is a part
return node.getOwnerDocument();
} // getDocument(Node):Document
// return this Document's root node
return doc.getDocumentElement();
} // getRoot(Document(: Element
// some methods for handling attributes:
// return the right attribute node
} // getAttr(Element, String):Attr
// return the right attribute node
} // getAttrNS(Element, String):Attr
// get all the attributes for an Element
return attrArray;
} // getAttrs(Element): Attr[]
// get attribute's value
} // getValue(Attr):String
// It is noteworthy that, because of the way the DOM specs
// work, the next two methods return the empty string (not
// null!) when the attribute with the specified name does not
// exist on an element. Beware!
// return the value of the attribute of the given element
// with the given name
} // getAttr(Element, String):Attr
// return the value of the attribute of the given element
// with the given name
} // getAttrValueNS(Element, String):Attr
// return the prefix
}
// return the namespace URI
return node.getNamespaceURI();
}
// return annotation
if (node instanceof ElementImpl) {
}
return null;
}
// return synthetic annotation
if (node instanceof ElementImpl) {
}
return null;
}
/**
* Creates a DOMException. On J2SE 1.4 and above the cause for the exception will be set.
*/
try {
}
// Something went wrong. There's not much we can do about it.
catch (Exception e) {}
}
return de;
}
/**
* Creates an LSException. On J2SE 1.4 and above the cause for the exception will be set.
*/
try {
}
// Something went wrong. There's not much we can do about it.
catch (Exception e) {}
}
return lse;
}
/**
* Holder of methods from java.lang.Throwable.
*/
static class ThrowableMethods {
// Method: java.lang.Throwable.initCause(java.lang.Throwable)
// Flag indicating whether or not Throwable methods available.
private static boolean fgThrowableMethodsAvailable = false;
private ThrowableMethods() {}
// Attempt to get methods for java.lang.Throwable on class initialization.
static {
try {
fgThrowableInitCauseMethod = Throwable.class.getMethod("initCause", new Class [] {Throwable.class});
fgThrowableMethodsAvailable = true;
}
// ClassNotFoundException, NoSuchMethodException or SecurityException
// Whatever the case, we cannot use java.lang.Throwable.initCause(java.lang.Throwable).
fgThrowableMethodsAvailable = false;
}
}
}
} // class DOMUtil