1 /* Copyright 2002-2021 CS GROUP
2 * Licensed to CS GROUP (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.files.ccsds.utils.lexical;
18
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.orekit.files.ccsds.ndm.odm.UserDefined;
23 import org.orekit.utils.units.Unit;
24 import org.xml.sax.Attributes;
25
26 /** Builder for user-defined parameters.
27 * <p>
28 * User-defined elements are of the form:
29 * </p>
30 * <pre>
31 * <USER_DEFINED parameter="SOME_PARAMETER_NAME">value</USER_DEFINED>
32 * </pre>
33 * <p>
34 * This {@link XmlTokenBuilder token builder} will generate a single
35 * {@link ParseToken parse token} from this root element with name set to
36 * "SOME_PARAMETER_NAME", type set to {@link TokenType#ENTRY} and content
37 * set to {@code value}.
38 * </p>
39 * @author Luc Maisonobe
40 * @since 11.0
41 */
42 public class UserDefinedXmlTokenBuilder implements XmlTokenBuilder {
43
44 /** {@inheritDoc} */
45 @Override
46 public List<ParseToken> buildTokens(final boolean startTag, final String qName,
47 final String content, final Attributes attributes,
48 final int lineNumber, final String fileName) {
49
50 // elaborate the token type
51 final TokenType tokenType = (content == null) ?
52 (startTag ? TokenType.START : TokenType.STOP) :
53 TokenType.ENTRY;
54
55 // final build
56 final String name = attributes.getValue(UserDefined.USER_DEFINED_XML_ATTRIBUTE);
57 final ParseToken token = new ParseToken(tokenType,
58 UserDefined.USER_DEFINED_PREFIX + name,
59 content, Unit.NONE,
60 lineNumber, fileName);
61
62 return Collections.singletonList(token);
63
64 }
65
66 }