本文整理匯總了Java中org.w3c.dom.Node.getOwnerDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getOwnerDocument方法的具體用法?Java Node.getOwnerDocument怎麽用?Java Node.getOwnerDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getOwnerDocument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dereference
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Dereference the given uri within the document of the given root element.
* <p>
* Currently this method only supports XPointer-ID-references and the special SignatureInfo-URI.
*
* @param uri the uri to dereference
* @param root the root node whose owner document is searched for dereferenciation
* @return the dereferenced node
* @throws RedactableXMLSignatureException if the given URI cannot be resolved or is not supported
*/
public static Node dereference(String uri, Node root) throws RedactableXMLSignatureException {
if (uri == null || uri.length() == 0) {
throw new RedactableXMLSignatureException("unsupported URI");
} else if (isRootNodeXPointer(uri)) {
return root;
} else if (isIdXPointer(uri)) {
Document doc = root.getOwnerDocument();
String id = extractId(uri);
Element element = doc.getElementById(id);
if (element == null) {
throw new RedactableXMLSignatureException("Cannot resolve element with ID " + id);
}
return element;
} else if (isSignatureInfoURI(uri)) {
return dereferenceSignatureInfo(root);
}
throw new RedactableXMLSignatureException("unsupported URI");
}
示例2: getOwnerDocument
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* This method returns the first non-null owner document of the Nodes in this Set.
* This method is necessary because it <I>always</I> returns a
* {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
* if the {@link Node} is a {@link Document}.
*
* @param xpathNodeSet
* @return the owner document
*/
public static Document getOwnerDocument(Set<Node> xpathNodeSet) {
NullPointerException npe = null;
for (Node node : xpathNodeSet) {
int nodeType = node.getNodeType();
if (nodeType == Node.DOCUMENT_NODE) {
return (Document) node;
}
try {
if (nodeType == Node.ATTRIBUTE_NODE) {
return ((Attr)node).getOwnerElement().getOwnerDocument();
}
return node.getOwnerDocument();
} catch (NullPointerException e) {
npe = e;
}
}
throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0")
+ " Original message was \""
+ (npe == null ? "" : npe.getMessage()) + "\"");
}
示例3: features
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static final NodeList features(ExpressionContext ctx) {
NodeSet result = new NodeSet();
Node node = ctx.getContextNode();
Element elt = getElement(node);
if (elt != null) {
Document doc = node.getOwnerDocument();
for (String name : elt.getFeatureKeys()) {
for (String value : elt.getFeature(name)) {
org.w3c.dom.Element e = doc.createElementNS(ALVISNLP_PROXY_NAMESPACE_URI, "feature");
e.setAttribute("name", name);
e.setAttribute("value", value);
result.addElement(e);
}
}
}
return result;
}
示例4: format
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Formats the input array value as xml elements of a parent node.
*/
@SuppressWarnings("unchecked")
public Node format(Object value, Node parent) {
if (value != null) {
T[] arr = (T[]) value;
Document document = parent.getOwnerDocument();
for (int i = 0; i < arr.length; i++) {
Element element = document.createElement(this.xmlName);
this.componentAdapter.format(arr[i], element);
parent.appendChild(element);
}
}
return parent;
}
示例5: Dom2SaxAdapter
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* @param node
* Nodes will be created and added under this object.
*/
public Dom2SaxAdapter(Node node)
{
_node = node;
_nodeStk.push(_node);
if( node instanceof Document )
this._document = (Document)node;
else
this._document = node.getOwnerDocument();
}
示例6: format
import org.w3c.dom.Node; //導入方法依賴的package包/類
public Node format(Object value, Node parent) {
if (this.xmlAdapter instanceof XmlAspect<?>) {
return ((XmlAspect<?>) this.xmlAdapter).format(
this.xmlName,
value,
parent);
} else {
Document document = parent.getOwnerDocument();
Element element = document.createElement(this.xmlName);
this.xmlAdapter.format(value, element);
parent.appendChild(element);
return element;
}
}
示例7: selectList
import org.w3c.dom.Node; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public List<Node> selectList(Node contextNode, String xpath) {
@SuppressWarnings("rawtypes")
List nodes;
try {
nodes = JXPathContext.newContext(contextNode).selectNodes(xpath);
int i = 0;
for (Object node: nodes) {
if (node instanceof Number) {
Number num = (Number) node;
if (num.intValue() == num.doubleValue()) {
node = Integer.toString(num.intValue());
} else {
node = Double.toString(num.doubleValue());
}
} else if (node instanceof Boolean) {
node = node.toString();
}
if (node instanceof String) {
Document doc = contextNode instanceof Document ? (Document)contextNode : contextNode.getOwnerDocument();
node = doc.createTextNode((String) node);
nodes.set(i, node);
}
i++;
}
} catch (Exception e) {
nodes = Collections.emptyList();
}
return (List<Node>) nodes;
}
示例8: addDependency
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void addDependency(Node moduleDependencies, Dep inject, StringBuilder log) {
Document nbprj = moduleDependencies.getOwnerDocument();
Element nueDep = nbprj.createElement("dependency");
moduleDependencies.appendChild(nueDep);
Element nueCnb = nbprj.createElement("code-name-base");
nueCnb.setTextContent(inject.getCodenameBase());
nueDep.appendChild(nueCnb);
log.append(inject.getCodenameBase());
Element nueBuildPrerequisite = nbprj.createElement("build-prerequisite");
nueDep.appendChild(nueBuildPrerequisite);
Element nueCompileDep = nbprj.createElement("compile-dependency");
nueDep.appendChild(nueCompileDep);
Element nueRunDep = nbprj.createElement("run-dependency");
nueDep.appendChild(nueRunDep);
Element nueRelease = nbprj.createElement("release-version");
String nue = checkReleaseVersion(inject.getRelease());
nueRelease.setTextContent(nue);
nueRunDep.appendChild(nueRelease);
log.append('/').append(nue);
if (inject.isImplementation()) {
nueRunDep.appendChild(nbprj.createElement("implementation-version"));
log.append(" = impl");
} else {
Element nueSpec = nbprj.createElement("specification-version");
nue = checkSpecificationVersion(inject.getSpecification());
nueSpec.setTextContent(nue);
nueRunDep.appendChild(nueSpec);
log.append(" >= " + nue);
}
}
示例9: getNodeHelper
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Gets the node for the given path.
*/
protected Node getNodeHelper(final String path, final boolean bCreate, final boolean bNew)
{
if( path == null )
{
throw new IllegalArgumentException("Path must not be null");
}
// Split on the path identifier
final List<String> pathComponents = DOMHelper.splitPath(path);
Node node = m_elRoot;
final Document doc = node.getOwnerDocument();
final Iterator<String> iter = pathComponents.iterator();
while( iter.hasNext() && node != null )
{
final String[] aszNodeName = new String[2];
aszNodeName[0] = iter.next();
// Extract the index if that exists
final int nIndex = getIndexValue(aszNodeName);
if( bNew && !iter.hasNext() )
{
final Node child = doc.createElement(aszNodeName[1]);
node.appendChild(child);
return child;
}
else
{
node = lookupNode(node, aszNodeName[1], nIndex, bCreate);
}
}
return node;
}
示例10: setStartAfter
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void setStartAfter(Node refNode)
throws RangeException
{
if (fDocument.errorChecking) {
if (fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
if ( !hasLegalRootContainer(refNode) ||
!isLegalContainedNode(refNode)) {
throw new RangeExceptionImpl(
RangeException.INVALID_NODE_TYPE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
}
if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
throw new DOMException(
DOMException.WRONG_DOCUMENT_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
}
}
fStartContainer = refNode.getParentNode();
int i = 0;
for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
i++;
}
fStartOffset = i;
// If one boundary-point of a Range is set to have a root container
// other
// than the current one for the Range, the Range should be collapsed to
// the new position.
// The start position of a Range should never be after the end position.
if (getCommonAncestorContainer() == null
|| (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
collapse(true);
}
}
示例11: replaceWith
import org.w3c.dom.Node; //導入方法依賴的package包/類
void replaceWith(XmlNode other) {
Node replacement = other.dom;
if (replacement.getOwnerDocument() != this.dom.getOwnerDocument()) {
replacement = this.dom.getOwnerDocument().importNode(replacement, true);
}
this.dom.getParentNode().replaceChild(replacement, this.dom);
}
示例12: selectNodeContents
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void selectNodeContents(Node refNode)
throws RangeException
{
if (fDocument.errorChecking) {
if( fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
if ( !isLegalContainer(refNode)) {
throw new RangeExceptionImpl(
RangeException.INVALID_NODE_TYPE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
}
if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
throw new DOMException(
DOMException.WRONG_DOCUMENT_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
}
}
fStartContainer = refNode;
fEndContainer = refNode;
Node first = refNode.getFirstChild();
fStartOffset = 0;
if (first == null) {
fEndOffset = 0;
} else {
int i = 0;
for (Node n = first; n!=null; n = n.getNextSibling()) {
i++;
}
fEndOffset = i;
}
}
示例13: writeToDOM
import org.w3c.dom.Node; //導入方法依賴的package包/類
private synchronized void writeToDOM(Node target, short type) {
Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT) ?
target.getOwnerDocument() : (Document)target;
DOMParser parser = fGrammar.getDOMParser();
StringReader aReader = new StringReader(fData);
InputSource aSource = new InputSource(aReader);
try {
parser.parse(aSource);
}
catch (SAXException e) {
// this should never happen!
// REVISIT: what to do with this?; should really not
// eat it...
}
catch (IOException i) {
// ditto with above
}
Document aDocument = parser.getDocument();
parser.dropDocumentReferences();
Element annotation = aDocument.getDocumentElement();
Node newElem = null;
if (futureOwner instanceof CoreDocumentImpl) {
newElem = futureOwner.adoptNode(annotation);
// adoptNode will return null when the DOM implementations are not compatible.
if (newElem == null) {
newElem = futureOwner.importNode(annotation, true);
}
}
else {
newElem = futureOwner.importNode(annotation, true);
}
target.insertBefore(newElem, target.getFirstChild());
}
示例14: SAX2DOM
import org.w3c.dom.Node; //導入方法依賴的package包/類
public SAX2DOM(Node root, Node nextSibling, boolean useServicesMechanism) throws ParserConfigurationException {
_root = root;
if (root instanceof Document) {
_document = (Document)root;
}
else if (root != null) {
_document = root.getOwnerDocument();
}
else {
_document = createDocument(useServicesMechanism);
_root = _document;
}
_nextSibling = nextSibling;
}
示例15: _getXmlEncoding
import org.w3c.dom.Node; //導入方法依賴的package包/類
private String _getXmlEncoding(Node node) {
Document doc = (node.getNodeType() == Node.DOCUMENT_NODE)
? (Document) node : node.getOwnerDocument();
if (doc != null) {
try {
return doc.getXmlEncoding();
} // The VM ran out of memory or there was some other serious problem. Re-throw.
catch (VirtualMachineError | ThreadDeath vme) {
throw vme;
} // Ignore all other exceptions and errors
catch (Throwable t) {
}
}
return null;
}