• 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

45.39
/exist-core/src/main/java/org/exist/dom/persistent/AbstractCharacterData.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.btree.Value;
53
import org.exist.util.UTF8;
54
import org.exist.util.XMLString;
55
import org.exist.xquery.Expression;
56
import org.w3c.dom.CharacterData;
57
import org.w3c.dom.DOMException;
58
import org.w3c.dom.Node;
59

60
public abstract class AbstractCharacterData<T extends AbstractCharacterData<T>> extends StoredNode<T> implements CharacterData {
61

62
    protected XMLString cdata = null;
1✔
63

64
    protected AbstractCharacterData(final short nodeType) {
65
        this(null, nodeType);
×
66
    }
×
67

68
    protected AbstractCharacterData(final Expression expression, final short nodeType) {
69
        super(expression, nodeType);
1✔
70
    }
1✔
71

72
    protected AbstractCharacterData(final short nodeType, final NodeId nodeId) {
73
        this(null, nodeType, nodeId);
×
74
    }
×
75

76
    protected AbstractCharacterData(final Expression expression, final short nodeType, final NodeId nodeId) {
77
        super(expression, nodeType, nodeId);
1✔
78
    }
1✔
79

80
    protected AbstractCharacterData(final short nodeType, final NodeId nodeId, final String data) {
81
        this(null, nodeType, nodeId, data);
×
82
    }
×
83

84
    protected AbstractCharacterData(final Expression expression, final short nodeType, final NodeId nodeId, final String data) {
85
        super(expression, nodeType, nodeId);
1✔
86
        cdata = new XMLString(data.toCharArray());
1✔
87
    }
1✔
88

89
    protected AbstractCharacterData(final short nodeType, final String data) {
90
        this(null, nodeType, data);
×
91
    }
×
92

93
    protected AbstractCharacterData(final Expression expression, final short nodeType, final String data) {
94
        super(expression, nodeType);
1✔
95
        cdata = new XMLString(data.toCharArray());
1✔
96
    }
1✔
97

98
    protected AbstractCharacterData(final short nodeType, final char[] data, final int start, final int howmany) {
99
        this(null, nodeType, data, start, howmany);
×
100
    }
×
101

102
    protected AbstractCharacterData(final Expression expression, final short nodeType, final char[] data, final int start, final int howmany) {
103
        super(expression, nodeType);
1✔
104
        cdata = new XMLString(data, start, howmany);
1✔
105
    }
1✔
106

107
    @Override
108
    public final int getChildCount() {
109
        return 0;
×
110
    }
111

112
    @Override
113
    public final Node getFirstChild() {
114
        return null;
1✔
115
    }
116

117
    @Override
118
    public void clear() {
119
        super.clear();
1✔
120
        cdata.reset();
1✔
121
    }
1✔
122

123
    @Override
124
    public void appendData(final String arg) throws DOMException {
125
        if(cdata == null) {
1✔
126
            cdata = new XMLString(arg.toCharArray());
1✔
127
        } else {
1✔
128
            cdata.append(arg);
1✔
129
        }
130
    }
1✔
131

132
    @Override
133
    public void deleteData(final int offset, final int count) throws DOMException {
134
        if(offset < 0 || count < 0) {
×
135
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
136
        }
137

138
        if(cdata != null) {
×
139
            if(offset > cdata.length()) {
×
140
                throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
141
            }
142

143
            if(offset + count > cdata.length()) {
×
144
                cdata.delete(offset, cdata.length() - offset);
×
145
            } else {
×
146
                cdata.delete(offset, count);
×
147
            }
148
        }
149
    }
×
150

151
    @Override
152
    public String getData() throws DOMException {
153
        if(cdata == null) {
1!
154
            return null;
×
155
        }
156
        return cdata.toString();
1✔
157
    }
158

159
    public XMLString getXMLString() {
160
        return cdata;
1✔
161
    }
162

163
    @Override
164
    public int getLength() {
165
        return cdata.length();
×
166
    }
167

168
    @Override
169
    public String getNodeValue() {
170
        return cdata.toString();
1✔
171
    }
172

173
    @Override
174
    public void setNodeValue(final String value) throws DOMException {
175
        setData(value);
×
176
    }
×
177

178
    @Override
179
    public String getTextContent() throws DOMException {
180
        return getNodeValue();
1✔
181
    }
182

183
    @Override
184
    public void setTextContent(final String textContent) throws DOMException {
185
        setNodeValue(textContent);
×
186
    }
×
187

188
    @Override
189
    public void insertData(final int offset, final String arg) throws DOMException {
190
        if(offset < 0) {
1!
191
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
192
        }
193

194
        if(cdata == null) {
1!
195
            cdata = new XMLString(arg.toCharArray());
×
196
        } else {
×
197
            if(offset > cdata.length()) {
1✔
198
                throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
1✔
199
            }
200
            cdata.insert(offset, arg);
1✔
201
        }
202
    }
1✔
203

204
    @Override
205
    public void replaceData(final int offset, int count, final String arg) throws DOMException {
206
        if(offset < 0 || count < 0) {
1!
207
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
208
        }
209

210
        if(cdata == null) {
1!
211
            throw new DOMException(DOMException.DOMSTRING_SIZE_ERR, "string index out of bounds");
×
212
        } else {
213
            if (offset > cdata.length()) {
1!
214
                throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
215
            }
216

217
            if(offset + count > cdata.length()) {
1✔
218
                count = cdata.length() - offset;
1✔
219
            }
220

221
            cdata.replace(offset, count, arg);
1✔
222
        }
223
    }
1✔
224

225
    @Override
226
    public void setData(final String data) throws DOMException {
227
        if(cdata == null) {
1!
228
            cdata = new XMLString(data.toCharArray());
×
229
        } else {
×
230
            cdata.setData(data.toCharArray(), 0, data.length());
1✔
231
        }
232
    }
1✔
233

234
    public void setData(final XMLString data) throws DOMException {
235
        cdata = data;
1✔
236
    }
1✔
237

238
    public void setData(final char[] data, final int start, final int howmany) throws DOMException {
239
        if(cdata == null) {
×
240
            cdata = new XMLString(data, start, howmany);
×
241
        } else {
×
242
            cdata.setData(data, start, howmany);
×
243
        }
244
    }
×
245

246
    @Override
247
    public String substringData(final int offset, int count) throws DOMException {
248
        if(offset < 0 || count < 0) {
×
249
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
250
        }
251

252
        if(cdata == null) {
×
253
            throw new DOMException(DOMException.DOMSTRING_SIZE_ERR, "string index out of bounds");
×
254
        }
255

256
        if(offset > cdata.length()) {
×
257
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "offset is out of bounds");
×
258
        }
259

260
        if(offset + count > cdata.length()) {
×
261
            count = cdata.length() - offset;
×
262
        }
263

264
        return cdata.substring(offset, count);
×
265
    }
266

267
    @Override
268
    public String toString() {
269
        if(cdata == null) {
1!
270
            return "";
×
271
        }
272
        return cdata.toString();
1✔
273
    }
274

275
    /**
276
     * Release all resources hold by this object.
277
     */
278
    @Override
279
    public void release() {
280
        cdata.reset();
1✔
281
        super.release();
1✔
282
    }
1✔
283

284
    public static XMLString readData(final NodeId nodeId, final Value value, final XMLString string) {
285
        final int nodeIdLen = nodeId.size();
1✔
286
        UTF8.decode(value.data(), value.start() + 3 + nodeIdLen, value.getLength() - 3 - nodeIdLen, string);
1✔
287
        return string;
1✔
288
    }
289

290
    public static int getStringLength(final NodeId nodeId, final Value value) {
291
        final int nodeIdLen = nodeId.size();
×
292
        return value.getLength() - 3 - nodeIdLen;
×
293
    }
294
}
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