• 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

85.96
/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Delivery.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
package org.exist.xquery.functions.fn.transform;
25

26
import net.sf.saxon.s9api.*;
27
import net.sf.saxon.serialize.SerializationProperties;
28
import org.exist.dom.memtree.DocumentBuilderReceiver;
29
import org.exist.dom.memtree.DocumentImpl;
30
import org.exist.dom.memtree.MemTreeBuilder;
31
import org.exist.xquery.XPathException;
32
import org.exist.xquery.XQueryContext;
33
import org.exist.xquery.value.Sequence;
34
import org.exist.xquery.value.StringValue;
35

36
import java.io.StringWriter;
37
import java.util.Objects;
38

39
class Delivery {
40

41
    enum Format {
1✔
42
        DOCUMENT,
1✔
43
        SERIALIZED,
1✔
44
        RAW
1✔
45
    }
46

47
    final XQueryContext context;
48
    final Format format;
49
    final SerializationProperties serializationProperties;
50
    MemTreeBuilder builder;
51
    StringWriter stringWriter;
52

53
    RawDestination rawDestination;
54

55
    Delivery(final XQueryContext context, final Format format, final SerializationProperties serializationProperties) {
1✔
56
        this.context = context;
1✔
57
        this.format = format;
1✔
58
        this.serializationProperties = serializationProperties;
1✔
59
    }
1✔
60

61
    final Destination createDestination(final Xslt30Transformer xslt30Transformer, final boolean forceCreation) {
62
        switch (format) {
1!
63
            case DOCUMENT:
64
                if (!forceCreation) {
1✔
65
                    this.builder = context.getDocumentBuilder();
1✔
66
                } else {
1✔
67
                    this.builder = new MemTreeBuilder(context);
1✔
68
                    this.builder.startDocument();
1✔
69
                }
70
                return new SAXDestination(new DocumentBuilderReceiver(builder));
1✔
71
            case SERIALIZED:
72
                final Serializer serializer = xslt30Transformer.newSerializer();
1✔
73
                final SerializationProperties stylesheetProperties = serializer.getSerializationProperties();
1✔
74

75
                final SerializationProperties combinedProperties =
1✔
76
                        SerializationParameters.combinePropertiesAndCharacterMaps(
1✔
77
                                stylesheetProperties,
1✔
78
                                serializationProperties);
1✔
79

80
                serializer.setOutputProperties(combinedProperties);
1✔
81
                stringWriter = new StringWriter();
1✔
82
                serializer.setOutputWriter(stringWriter);
1✔
83
                return serializer;
1✔
84
            case RAW:
85
                this.rawDestination = new RawDestination();
1✔
86
                return rawDestination;
1✔
87
            default:
88
                return null;
×
89
        }
90
    }
91

92
    private String getSerializedString() {
93

94
        if (stringWriter == null) {
1!
95
            return null;
×
96
        }
97
        return stringWriter.getBuffer().toString();
1✔
98
    }
99

100
    private DocumentImpl getDocument() {
101
        if (builder == null) {
1!
102
            return null;
×
103
        }
104
        return builder.getDocument();
1✔
105
    }
106

107
    private XdmValue getXdmValue() {
108
        if (rawDestination == null) {
1!
109
            return null;
×
110
        }
111
        return rawDestination.getXdmValue();
1✔
112
    }
113

114
    Sequence convert() throws XPathException {
115

116
        switch (format) {
1✔
117
            case SERIALIZED:
118
                return new StringValue(getSerializedString());
1✔
119
            case RAW:
120
                return Convert.ToExist.of(Objects.requireNonNull(getXdmValue()));
1✔
121
            case DOCUMENT:
122
            default:
123
                return getDocument();
1✔
124
        }
125
    }
126
}
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