• 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

55.56
/exist-core/src/main/java/org/exist/util/serializer/EXISerializer.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.util.serializer;
50

51
import java.io.IOException;
52
import java.io.InputStream;
53
import java.io.OutputStream;
54

55
import org.exist.dom.INodeHandle;
56
import org.exist.dom.QName;
57
import org.w3c.dom.Document;
58
import org.xml.sax.Attributes;
59
import org.xml.sax.ContentHandler;
60
import org.xml.sax.Locator;
61
import org.xml.sax.SAXException;
62
import org.xml.sax.helpers.AttributesImpl;
63

64
import com.siemens.ct.exi.core.EXIFactory;
65
import com.siemens.ct.exi.core.exceptions.EXIException;
66
import com.siemens.ct.exi.core.grammars.Grammars;
67
import com.siemens.ct.exi.core.helpers.DefaultEXIFactory;
68
import com.siemens.ct.exi.grammars.GrammarFactory;
69
import com.siemens.ct.exi.main.api.sax.SAXEncoder;
70

71
import javax.annotation.Nullable;
72

73
public class EXISerializer implements ContentHandler, Receiver {
74
        
75
        static final String UNKNOWN_TYPE = "";
76
        
77
        private SAXEncoder encoder;
78
        
79
        public EXISerializer(OutputStream exiOutputStream) throws EXIException, IOException {
1✔
80
                final EXIFactory exiFactory = DefaultEXIFactory.newInstance();
1✔
81
                encoder = new SAXEncoder(exiFactory);
1✔
82
                encoder.setOutputStream(exiOutputStream);
1✔
83
        }
1✔
84
        
85
        public EXISerializer(OutputStream exiOutputStream, InputStream xsdInputStream) throws EXIException, IOException {
×
86
                final EXIFactory exiFactory = DefaultEXIFactory.newInstance();
×
87
                final GrammarFactory grammarFactory = GrammarFactory.newInstance();
×
88
                final Grammars g = grammarFactory.createGrammars(xsdInputStream);
×
89
                exiFactory.setGrammars(g);
×
90
                encoder = new SAXEncoder(exiFactory);
×
91
                encoder.setOutputStream(exiOutputStream);
×
92
        }
×
93
        
94
        public void startDocument() throws SAXException {
95
                encoder.startDocument();
1✔
96
        }
1✔
97

98
        public void endDocument() throws SAXException {
99
                encoder.endDocument();
1✔
100
        }
1✔
101

102
        @Override
103
        public void declaration(@Nullable final String version, @Nullable final String encoding, @Nullable final String standalone) throws SAXException {
104
                encoder.declaration(version, encoding, standalone);
×
105
        }
×
106

107
        @Override
108
        public void startPrefixMapping(String prefix, String namespaceURI)
109
                        throws SAXException {
110
                encoder.startPrefixMapping(prefix, namespaceURI);
1✔
111
        }
1✔
112

113
        @Override
114
        public void endPrefixMapping(String prefix) throws SAXException {
115
                encoder.endPrefixMapping(prefix);
1✔
116
        }
1✔
117

118
        @Override
119
        public void startElement(QName qname, AttrList attribs) throws SAXException {
120
                AttributesImpl attributes = null;
1✔
121
                if(attribs != null) {
1!
122
                        attributes = new AttributesImpl();
1✔
123
                        for (int x = 0; x < attribs.getLength(); x++) {
1✔
124
                                final QName attribQName = attribs.getQName(x);
1✔
125
                                attributes.addAttribute(attribQName.getNamespaceURI(),
1✔
126
                                                attribQName.getLocalPart(),
1✔
127
                                                attribQName.getStringValue(),
1✔
128
                                                UNKNOWN_TYPE,
1✔
129
                                                attribs.getValue(x));
1✔
130
                        }
131
                }
132
                encoder.startElement(qname.getNamespaceURI(), qname.getLocalPart(), null, attributes);
1✔
133
                
134
        }
1✔
135

136
        @Override
137
        public void endElement(QName qname) throws SAXException {
138
                encoder.endElement(qname.getNamespaceURI(), qname.getLocalPart(), null);
1✔
139
                
140
        }
1✔
141

142
        @Override
143
        public void characters(CharSequence seq) throws SAXException {
144
                final String sequence = seq.toString();
1✔
145
                encoder.characters(sequence.toCharArray(), 0, sequence.length());
1✔
146
        }
1✔
147

148
        @Override
149
        public void attribute(QName qname, String value) throws SAXException {
150
                // TODO Auto-generated method stub
151
                
152
        }
×
153

154
        @Override
155
        public void comment(char[] ch, int start, int length) throws SAXException {
156
                // TODO Auto-generated method stub
157
        }
×
158

159
        @Override
160
        public void cdataSection(char[] ch, int start, int len) throws SAXException {
161
                // TODO Auto-generated method stub
162
        }
×
163

164
        @Override
165
        public void processingInstruction(String target, String data)
166
                        throws SAXException {
167
                // TODO Auto-generated method stub
168
        }
×
169

170
        @Override
171
        public void documentType(String name, String publicId, String systemId)
172
                        throws SAXException {
173
                // TODO Auto-generated method stub
174
                
175
        }
×
176

177
        @Override
178
        public void highlightText(CharSequence seq) throws SAXException {
179
                // TODO Auto-generated method stub
180
                
181
        }
×
182

183
        @Override
184
        public void setCurrentNode(INodeHandle node) {
185
                // TODO Auto-generated method stub
186
                
187
        }
×
188

189
        @Override
190
        public Document getDocument() {
191
                // TODO Auto-generated method stub
192
                return null;
×
193
        }
194

195
        @Override
196
        public void setDocumentLocator(Locator locator) {
197
                // TODO Auto-generated method stub
198
                
199
        }
×
200

201
        @Override
202
        public void startElement(String uri, String localName, String qName,
203
                        Attributes atts) throws SAXException {
204
                encoder.startElement(uri, localName, null, atts);
×
205
                
206
        }
×
207

208
        @Override
209
        public void endElement(String uri, String localName, String qName)
210
                        throws SAXException {
211
                encoder.endElement(uri, localName, null);
×
212
                
213
        }
×
214

215
        @Override
216
        public void characters(char[] ch, int start, int length)
217
                        throws SAXException {
218
                encoder.characters(ch, start, length);
×
219
                
220
        }
×
221

222
        @Override
223
        public void ignorableWhitespace(char[] ch, int start, int length)
224
                        throws SAXException {
225
                // TODO Auto-generated method stub
226
                
227
        }
×
228

229
        @Override
230
        public void skippedEntity(String name) throws SAXException {
231
                // TODO Auto-generated method stub
232
                
233
        }
×
234
        
235
        void setEncoder(SAXEncoder encoder) {
236
                this.encoder = encoder;
1✔
237
        }
1✔
238

239
}
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