| 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.tree.tiny; |
| 9 | |
| 10 | import net.sf.saxon.event.Receiver; |
| 11 | import net.sf.saxon.expr.parser.Location; |
| 12 | import net.sf.saxon.om.AtomicSequence; |
| 13 | import net.sf.saxon.trans.XPathException; |
| 14 | import net.sf.saxon.tree.util.Navigator; |
| 15 | import net.sf.saxon.type.Type; |
| 16 | import net.sf.saxon.value.StringValue; |
| 17 | |
| 18 | /** |
| 19 | * TProcInstImpl is an implementation of ProcInstInfo |
| 20 | * |
| 21 | * @author Michael H. Kay |
| 22 | * @version 16 July 1999 |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | final class TinyProcInstImpl extends TinyNodeImpl { |
| 27 | |
| 28 | public TinyProcInstImpl(TinyTree tree, int nodeNr) { |
| 29 | this.tree = tree; |
| 30 | this.nodeNr = nodeNr; |
| 31 | } |
| 32 | |
| 33 | public String getStringValue() { |
| 34 | int start = tree.alpha[nodeNr]; |
| 35 | int len = tree.beta[nodeNr]; |
| 36 | if (len == 0) { |
| 37 | return ""; // need to special-case this for the Microsoft JVM |
| 38 | } |
| 39 | char[] dest = new char[len]; |
| 40 | tree.commentBuffer.getChars(start, start + len, dest, 0); |
| 41 | return new String(dest, 0, len); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get the typed value of this node. |
| 46 | * Returns the string value, as an instance of xs:string |
| 47 | */ |
| 48 | |
| 49 | public AtomicSequence atomize() { |
| 50 | return new StringValue(getStringValue()); |
| 51 | } |
| 52 | |
| 53 | public final int getNodeKind() { |
| 54 | return Type.PROCESSING_INSTRUCTION; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the base URI of this processing instruction node. |
| 59 | */ |
| 60 | |
| 61 | public String getBaseURI() { |
| 62 | return Navigator.getBaseURI(this); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Copy this node to a given outputter |
| 67 | */ |
| 68 | |
| 69 | public void copy(Receiver out, int copyOptions, Location locationId) throws XPathException { |
| 70 | out.processingInstruction(getDisplayName(), getStringValue(), locationId, 0); |
| 71 | } |
| 72 | |
| 73 | // DOM methods |
| 74 | |
| 75 | /** |
| 76 | * The target of this processing instruction. XML defines this as being |
| 77 | * the first token following the markup that begins the processing |
| 78 | * instruction. |
| 79 | * |
| 80 | * @return the "target", or in XDM terms, the name of the processing instruction |
| 81 | */ |
| 82 | |
| 83 | public String getTarget() { |
| 84 | return getDisplayName(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * The content of this processing instruction. This is from the first non |
| 89 | * white space character after the target to the character immediately |
| 90 | * preceding the <code>?></code> . |
| 91 | * |
| 92 | * @return the content of the processing instruction (in XDM this is the |
| 93 | * same as its string value) |
| 94 | */ |
| 95 | |
| 96 | /*@NotNull*/ |
| 97 | public String getData() { |
| 98 | return getStringValue(); |
| 99 | } |
| 100 | |
| 101 | } |
| 102 |