1 /* Copyright 2002-2025 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.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.orekit.files.ccsds.ndm.odm.UserDefined;
25 import org.orekit.utils.units.Unit;
26
27 /** Builder for user-defined parameters.
28 * <p>
29 * User-defined elements are of the form:
30 * </p>
31 * <pre>
32 * <USER_DEFINED parameter="SOME_PARAMETER_NAME">value</USER_DEFINED>
33 * </pre>
34 * <p>
35 * This {@link XmlTokenBuilder token builder} will generate a single
36 * {@link ParseToken parse token} from this root element with name set to
37 * "SOME_PARAMETER_NAME", type set to {@link TokenType#ENTRY} and content
38 * set to {@code value}.
39 * </p>
40 * @author Luc Maisonobe
41 * @since 11.0
42 */
43 public class UserDefinedXmlTokenBuilder implements XmlTokenBuilder {
44
45 /** Empty constructor.
46 * <p>
47 * This constructor is not strictly necessary, but it prevents spurious
48 * javadoc warnings with JDK 18 and later.
49 * </p>
50 * @since 12.0
51 */
52 public UserDefinedXmlTokenBuilder() {
53 // nothing to do
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 public List<ParseToken> buildTokens(final boolean startTag, final boolean isLeaf, final String qName,
59 final String content, final Map<String, String> attributes,
60 final int lineNumber, final String fileName) {
61
62 // elaborate name
63 final String name = UserDefined.USER_DEFINED_PREFIX +
64 attributes.get(UserDefined.USER_DEFINED_XML_ATTRIBUTE);
65
66 if (startTag) {
67 return Collections.singletonList(new ParseToken(TokenType.START, name, content, Unit.NONE, lineNumber, fileName));
68 } else {
69 final List<ParseToken> built = new ArrayList<>(2);
70 if (isLeaf) {
71 built.add(new ParseToken(TokenType.ENTRY, name, content, Unit.NONE, lineNumber, fileName));
72 }
73 built.add(new ParseToken(TokenType.STOP, name, null, Unit.NONE, lineNumber, fileName));
74 return built;
75 }
76
77 }
78
79 }