• 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

69.66
/exist-core/src/main/java/org/exist/xmlrpc/ACEAiderParser.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.xmlrpc;
25

26
import org.apache.ws.commons.util.NamespaceContextImpl;
27
import org.apache.xmlrpc.common.TypeFactory;
28
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
29
import org.apache.xmlrpc.parser.RecursiveTypeParserImpl;
30
import org.exist.security.ACLPermission.ACE_ACCESS_TYPE;
31
import org.exist.security.ACLPermission.ACE_TARGET;
32
import org.exist.security.internal.aider.ACEAider;
33
import org.xml.sax.Attributes;
34
import org.xml.sax.SAXException;
35
import org.xml.sax.SAXParseException;
36

37
import javax.xml.XMLConstants;
38
import javax.xml.namespace.QName;
39
import java.util.ArrayList;
40
import java.util.List;
41

42
/**
43
 * XML-RPC type parser for objects of
44
 * {@link org.exist.security.internal.aider.ACEAider}.
45
 *
46
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
47
 */
48
class ACEAiderParser extends RecursiveTypeParserImpl {
49
    private int level = 0;
1✔
50
    private List<Object> list;
51

52
    /**
53
     * Creates a new instance.
54
     *
55
     * @param context The namespace context.
56
     * @param config  The request or response configuration.
57
     * @param factory The type factory.
58
     */
59
    ACEAiderParser(final XmlRpcStreamConfig config, final NamespaceContextImpl context, final TypeFactory factory) {
60
        super(config, context, factory);
1✔
61
    }
1✔
62

63
    @Override
64
    public void startDocument() throws SAXException {
65
        level = 0;
1✔
66
        list = new ArrayList<>();
1✔
67
        super.startDocument();
1✔
68
    }
1✔
69

70
    @Override
71
    protected void addResult(final Object value) {
72
        list.add(value);
1✔
73
    }
1✔
74

75
    @Override
76
    public void endElement(final String uri, final String localName, final String qname) throws SAXException {
77
        switch (--level) {
1✔
78
            case 0:
79
                setResult(toAceAider(list));
1✔
80
                break;
1✔
81
            case 1:
82
                break;
1✔
83
            case 2:
84
                endValueTag();
1✔
85
                break;
1✔
86
            default:
87
                super.endElement(uri, localName, qname);
1✔
88
        }
89
    }
1✔
90

91
    @Override
92
    public void startElement(final String uri, final String localName, final String qname, final Attributes attrs) throws SAXException {
93
        switch (level++) {
1✔
94
            case 0:
95
                if (!XMLConstants.NULL_NS_URI.equals(uri) || !ACEAiderSerializer.ACEAIDER_TAG.equals(localName)) {
1!
96
                    throw new SAXParseException("Expected aceAider element, got "
×
97
                            + new QName(uri, localName),
×
98
                            getDocumentLocator());
×
99
                }
100
                break;
101
            case 1:
102
                if (!XMLConstants.NULL_NS_URI.equals(uri) || !ACEAiderSerializer.DATA_TAG.equals(localName)) {
1!
103
                    throw new SAXParseException("Expected data element, got "
×
104
                            + new QName(uri, localName),
×
105
                            getDocumentLocator());
×
106
                }
107
                break;
108
            case 2:
109
                if (!XMLConstants.NULL_NS_URI.equals(uri) || !ACEAiderSerializer.VALUE_TAG.equals(localName)) {
1!
110
                    throw new SAXParseException("Expected value element, got "
×
111
                            + new QName(uri, localName),
×
112
                            getDocumentLocator());
×
113
                }
114
                startValueTag();
1✔
115
                break;
1✔
116
            default:
117
                super.startElement(uri, localName, qname, attrs);
1✔
118
                break;
119
        }
120
    }
1✔
121

122
    private static ACEAider toAceAider(final List<Object> list) throws SAXException {
123
        if (list.size() != 4) {
1!
124
            throw new SAXException("Inavlis list size for ACEAider");
×
125
        }
126

127
        Object object = list.get(0);
1✔
128
        final ACE_ACCESS_TYPE aceAccessType;
129
        if (object instanceof String) {
1!
130
            try {
131
                aceAccessType = ACE_ACCESS_TYPE.valueOf((String) object);
1✔
132
            } catch (final IllegalArgumentException e) {
1✔
133
                throw new SAXException(e);
×
134
            }
135
        } else {
136
            throw new SAXException("Expected ACE_ACCESS_TYPE");
×
137
        }
138

139
        object = list.get(1);
1✔
140
        final ACE_TARGET aceTarget;
141
        if (object instanceof String) {
1!
142
            try {
143
                aceTarget = ACE_TARGET.valueOf((String) object);
1✔
144
            } catch (final IllegalArgumentException e) {
1✔
145
                throw new SAXException(e);
×
146
            }
147
        } else {
148
            throw new SAXException("Expected ACE_TARGET");
×
149
        }
150

151
        object = list.get(2);
1✔
152
        final String aceWho;
153
        if (object instanceof String) {
1!
154
            aceWho = (String) object;
1✔
155
        } else {
1✔
156
            throw new SAXException("Expected String");
×
157
        }
158

159
        object = list.get(3);
1✔
160
        final int aceMode;
161
        if (object instanceof Integer) {
1!
162
            aceMode = (Integer) object;
1✔
163
        } else {
1✔
164
            throw new SAXException("Expected Integer");
×
165
        }
166

167
        return new ACEAider(aceAccessType, aceTarget, aceWho, aceMode);
1✔
168
    }
169
}
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