| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.dom; |
| 9 | |
| 10 | import net.sf.saxon.type.Type; |
| 11 | import org.w3c.dom.DOMException; |
| 12 | import org.w3c.dom.Node; |
| 13 | |
| 14 | /** |
| 15 | * This class represents a DOM text node that is the child of a DOM attribute node. The DOM attribute node |
| 16 | * will be a wrapper over a Saxon attribute node or namespace node. |
| 17 | */ |
| 18 | public class TextOverAttrInfo extends TextOverNodeInfo { |
| 19 | |
| 20 | private AttrOverNodeInfo attr; |
| 21 | |
| 22 | public TextOverAttrInfo(AttrOverNodeInfo attr) { |
| 23 | this.attr = attr; |
| 24 | this.node = attr.getUnderlyingNodeInfo(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'> |
| 29 | * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is |
| 30 | * determined to contain whitespace in element content during the load |
| 31 | * of the document or if validation occurs while using |
| 32 | * <code>Document.normalizeDocument()</code>. |
| 33 | * |
| 34 | * @since DOM Level 3 |
| 35 | */ |
| 36 | public boolean isElementContentWhitespace() { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Get the type of this node (node kind, in XPath terminology). |
| 42 | * Note, the numbers assigned to node kinds |
| 43 | * in Saxon (see {@link net.sf.saxon.type.Type}) are the same as those assigned in the DOM |
| 44 | */ |
| 45 | |
| 46 | public short getNodeType() { |
| 47 | return Type.TEXT; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Compare the position of the (other) node in document order with the reference node (this node). |
| 52 | * DOM Level 3 method. |
| 53 | * |
| 54 | * @param other the other node. |
| 55 | * @return Returns how the node is positioned relatively to the reference |
| 56 | * node. |
| 57 | * @throws org.w3c.dom.DOMException |
| 58 | */ |
| 59 | |
| 60 | public short compareDocumentPosition(Node other) throws DOMException { |
| 61 | final short DOCUMENT_POSITION_FOLLOWING = 0x04; |
| 62 | if (other instanceof TextOverAttrInfo) { |
| 63 | if (node.equals(((TextOverAttrInfo) other).node)) { |
| 64 | return 0; |
| 65 | } else { |
| 66 | return attr.compareDocumentPosition(((TextOverAttrInfo) other).attr); |
| 67 | } |
| 68 | } else if (other instanceof AttrOverNodeInfo) { |
| 69 | if (node.equals(((AttrOverNodeInfo) other).getUnderlyingNodeInfo())) { |
| 70 | return DOCUMENT_POSITION_FOLLOWING; |
| 71 | } |
| 72 | } |
| 73 | return attr.compareDocumentPosition(other); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Find the parent node of this node. |
| 78 | * |
| 79 | * @return The Node object describing the containing element or root node. |
| 80 | */ |
| 81 | |
| 82 | public Node getParentNode() { |
| 83 | return attr; |
| 84 | } |
| 85 | } |
| 86 |