OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 180
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.xml;
14
 package org.openconcerto.xml;
15
 
15
 
-
 
16
import org.openconcerto.utils.Tuple2.List2;
-
 
17
 
16
import javax.xml.stream.XMLStreamConstants;
18
import javax.xml.stream.XMLStreamConstants;
17
import javax.xml.stream.XMLStreamException;
19
import javax.xml.stream.XMLStreamException;
18
import javax.xml.stream.XMLStreamReader;
20
import javax.xml.stream.XMLStreamReader;
19
 
21
 
20
public class XMLUtils {
22
public class XMLUtils {
Line 115... Line 117...
115
            }
117
            }
116
        }
118
        }
117
        return sb.toString();
119
        return sb.toString();
118
    }
120
    }
119
 
121
 
-
 
122
    /**
-
 
123
     * Split prefix and local name.
-
 
124
     * 
-
 
125
     * @param qName a qualified name, e.g. "ns:foo" or "foo".
-
 
126
     * @return first the prefix (<code>null</code> if none), then the local name
-
 
127
     * @throws IllegalArgumentException if invalid syntax.
-
 
128
     * @see <a href="https://www.w3.org/TR/xml-names/#ns-qualnames">Qualified Names</a>
-
 
129
     */
-
 
130
    public static List2<String> splitQualifiedName(final String qName) throws IllegalArgumentException {
-
 
131
        final int indexOfColon = qName.indexOf(':');
-
 
132
        if (indexOfColon < 0)
-
 
133
            return new List2<>(null, qName);
-
 
134
 
-
 
135
        if (indexOfColon == 0)
-
 
136
            throw new IllegalArgumentException("Starts with colon : '" + qName + "'");
-
 
137
        final int l = qName.length();
-
 
138
        assert indexOfColon < l;
-
 
139
        if (indexOfColon == l - 1)
-
 
140
            throw new IllegalArgumentException("Ends with colon : '" + qName + "'");
-
 
141
        final int secondColon = qName.indexOf(':', indexOfColon + 1);
-
 
142
        if (secondColon >= 0)
-
 
143
            throw new IllegalArgumentException("Two colons : '" + qName + "'");
-
 
144
        return new List2<>(qName.substring(0, indexOfColon), qName.substring(indexOfColon + 1));
-
 
145
    }
-
 
146
 
120
    public static final void skipToEndElement(final XMLStreamReader reader) throws XMLStreamException {
147
    public static final void skipToEndElement(final XMLStreamReader reader) throws XMLStreamException {
121
        if (!reader.isStartElement())
148
        if (!reader.isStartElement())
122
            throw new IllegalStateException("Not at a start of an element : " + reader.getEventType() + ", " + reader.getLocation());
149
            throw new IllegalStateException("Not at a start of an element : " + reader.getEventType() + ", " + reader.getLocation());
123
        final String name = reader.getLocalName();
150
        final String name = reader.getLocalName();
124
        int depth = 1;
151
        int depth = 1;