• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/exist-core/src/main/java/org/exist/dom/persistent/ProcessingInstructionImpl.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.dom.persistent;
50

51
import org.exist.numbering.NodeId;
52
import org.exist.storage.Signatures;
53
import org.exist.util.ByteConversion;
54
import org.exist.util.pool.NodePool;
55
import org.exist.xquery.Expression;
56
import org.w3c.dom.DOMException;
57
import org.w3c.dom.Node;
58
import org.w3c.dom.ProcessingInstruction;
59

60
import static java.nio.charset.StandardCharsets.UTF_8;
61

62
/**
63
 * Persistent implementation of a DOM processing-instruction node.
64
 *
65
 * @author wolf
66
 */
67
public class ProcessingInstructionImpl extends StoredNode<ProcessingInstructionImpl> implements ProcessingInstruction {
68

69
    public static final int LENGTH_TARGET_DATA = 4; //Sizeof int;
70

71
    protected String target = null;
1✔
72
    protected String data = null;
1✔
73

74
    public ProcessingInstructionImpl() {
75
        this(null);
×
76
    }
×
77

78
    public ProcessingInstructionImpl(final Expression expression) {
79
        super(expression, Node.PROCESSING_INSTRUCTION_NODE);
1✔
80
    }
1✔
81

82
    public ProcessingInstructionImpl(final NodeId nodeId, final String target, final String data) {
83
        this(null, nodeId, target, data);
×
84
    }
×
85

86
    public ProcessingInstructionImpl(final Expression expression, final NodeId nodeId, final String target, final String data) {
87
        super(expression, Node.PROCESSING_INSTRUCTION_NODE, nodeId);
1✔
88
        this.target = target;
1✔
89
        this.data = data;
1✔
90
    }
1✔
91

92
    public ProcessingInstructionImpl(final String target, final String data) {
93
        this((Expression) null, target, data);
×
94
    }
×
95

96
    public ProcessingInstructionImpl(final Expression expression, final String target, final String data) {
97
        this(expression, null, target, data);
1✔
98
    }
1✔
99

100
    @Override
101
    public void clear() {
102
        super.clear();
1✔
103
        target = null;
1✔
104
        data = null;
1✔
105
    }
1✔
106

107
    /**
108
     * Gets the target attribute of the ProcessingInstructionImpl object
109
     *
110
     * @return The target value
111
     */
112
    @Override
113
    public String getTarget() {
114
        return target;
1✔
115
    }
116

117
    /**
118
     * Sets the target attribute of the ProcessingInstructionImpl object
119
     *
120
     * @param target The new target value
121
     */
122
    public void setTarget(final String target) {
123
        this.target = target;
1✔
124
    }
1✔
125

126
    @Override
127
    public String getNodeValue() throws DOMException {
128
        return getData();
×
129
    }
130

131
    /**
132
     * Gets the data attribute of the ProcessingInstructionImpl object
133
     *
134
     * @return The data value
135
     */
136
    @Override
137
    public String getData() {
138
        return data;
1✔
139
    }
140

141
    /**
142
     * Sets the data attribute of the ProcessingInstructionImpl object
143
     *
144
     * @param data The new data value
145
     */
146
    @Override
147
    public void setData(final String data) {
148
        this.data = data;
×
149
    }
×
150

151
    /**
152
     * ? @see org.w3c.dom.Node#getBaseURI()
153
     */
154
    @Override
155
    public String getBaseURI() {
156
        final StoredNode parent = getParentStoredNode();
×
157
        if(parent != null) {
×
158
            return parent.getBaseURI();
×
159
        } else {
160
            return getOwnerDocument().getBaseURI();
×
161
        }
162
    }
163

164
    @Override
165
    public String toString() {
166
        final StringBuilder buf = new StringBuilder();
×
167
        buf.append("<?");
×
168
        buf.append(target);
×
169
        buf.append(" ");
×
170
        buf.append(data);
×
171
        buf.append(" ?>");
×
172
        return buf.toString();
×
173
    }
174

175
    /**
176
     * Serializes a (persistent DOM) Processing Instruction to a byte array
177
     *
178
     * data = signature nodeIdUnitsLength nodeId targetLength target contentLength content
179
     *
180
     * signature = [byte] 0x40
181
     *
182
     * nodeIdUnitsLength = [short] (2 bytes) The number of units of the processing instruction's NodeId
183
     * nodeId = @see org.exist.numbering.DLNBase#serialize(byte[], int)
184
     *
185
     * targetLength = [int] (4 bytes) The length of the target string in bytes
186
     * target = jUtf8
187
     *
188
     * contentLength = [int] (4 bytes) The length of the data string in bytes
189
     * content = jUtf8
190
     *
191
     * jUtf8 = @see java.io.DataOutputStream#writeUTF(java.lang.String)
192
     */
193
    @Override
194
    public byte[] serialize() {
195

196
        final byte[] td = target.getBytes(UTF_8);
1✔
197
        final byte[] dd = data.getBytes(UTF_8);
1✔
198

199
        final int nodeIdLen = nodeId.size();
1✔
200
        final byte[] d = new byte[td.length + dd.length + nodeIdLen + 7];
1✔
201
        int pos = 0;
1✔
202
        d[pos] = (byte) (Signatures.Proc << 0x5);
1✔
203
        pos += LENGTH_SIGNATURE_LENGTH;
1✔
204
        ByteConversion.shortToByte((short) nodeId.units(), d, pos);
1✔
205
        pos += NodeId.LENGTH_NODE_ID_UNITS;
1✔
206
        nodeId.serialize(d, pos);
1✔
207
        pos += nodeIdLen;
1✔
208
        ByteConversion.intToByte(td.length, d, pos);
1✔
209
        pos += LENGTH_TARGET_DATA;
1✔
210
        System.arraycopy(td, 0, d, pos, td.length);
1✔
211
        pos += td.length;
1✔
212
        System.arraycopy(dd, 0, d, pos, dd.length);
1✔
213
        return d;
1✔
214
    }
215

216
    public static StoredNode deserialize(final byte[] data, final int start, final int len, final DocumentImpl doc, final boolean pooled) {
217
        int pos = start;
1✔
218
        pos += LENGTH_SIGNATURE_LENGTH;
1✔
219

220
        final int dlnLen = ByteConversion.byteToShort(data, pos);
1✔
221
        pos += NodeId.LENGTH_NODE_ID_UNITS;
1✔
222

223
        final NodeId dln = doc.getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
1✔
224
        final int nodeIdLen = dln.size();
1✔
225
        pos += nodeIdLen;
1✔
226

227
        final int l = ByteConversion.byteToInt(data, pos);
1✔
228
        pos += LENGTH_TARGET_DATA;
1✔
229

230
        final String target = new String(data, pos, l, UTF_8);
1✔
231
        pos += l;
1✔
232

233
        final String cdata = new String(data, pos, len - (pos - start), UTF_8);
1✔
234

235
        //OK : we have the necessary material to build the processing instruction
236
        final ProcessingInstructionImpl pi;
237
        if(pooled) {
1!
238
            pi = (ProcessingInstructionImpl) NodePool.getInstance().borrowNode(Node.PROCESSING_INSTRUCTION_NODE);
×
239
        } else {
×
240
            pi = new ProcessingInstructionImpl(null);
1✔
241
        }
242

243
        pi.setTarget(target);
1✔
244
        pi.data = cdata;
1✔
245
        pi.setNodeId(dln);
1✔
246

247
        return pi;
1✔
248
    }
249

250
    @Override
251
    public int getChildCount() {
252
        return 0;
×
253
    }
254

255
    @Override
256
    public Node getFirstChild() {
257
        return null;
×
258
    }
259
}
260

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc