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.section;
18
19 import org.orekit.files.ccsds.utils.FileFormat;
20 import org.orekit.files.ccsds.utils.lexical.ParseToken;
21 import org.orekit.files.ccsds.utils.lexical.TokenType;
22 import org.orekit.files.ccsds.utils.parsing.AbstractConstituentParser;
23
24 /** Keys for {@link FileFormat#XML} format structure.
25 * @author Luc Maisonobe
26 * @since 11.0
27 */
28 public enum XmlStructureKey {
29
30 /** Body structure. */
31 body((token, parser) -> true),
32
33 /** Segment structure. */
34 segment((token, parser) -> true),
35
36 /** Header structure. */
37 header((token, parser) -> {
38 if (token.getType() == TokenType.START) {
39 return parser.prepareHeader();
40 } else if (token.getType() == TokenType.STOP) {
41 return parser.finalizeHeader();
42 }
43 return false;
44 }),
45
46 /** XML metadata structure. */
47 metadata((token, parser) -> {
48 if (token.getType() == TokenType.START) {
49 return parser.prepareMetadata();
50 } else if (token.getType() == TokenType.STOP) {
51 return parser.finalizeMetadata();
52 }
53 return false;
54 }),
55
56 /** XML data structure. */
57 data((token, parser) -> {
58 if (token.getType() == TokenType.START) {
59 return parser.prepareData();
60 } else if (token.getType() == TokenType.STOP) {
61 return parser.finalizeData();
62 }
63 return false;
64 });
65
66 /** Processing method. */
67 private final transient TokenProcessor processor;
68
69 /** Simple constructor.
70 * @param processor processing method
71 */
72 XmlStructureKey(final TokenProcessor processor) {
73 this.processor = processor;
74 }
75
76 /** Process an token.
77 * @param token token to process
78 * @param parser file parser
79 * @return true of token was accepted
80 */
81 public boolean process(final ParseToken token, final AbstractConstituentParser<?, ?, ?> parser) {
82 return processor.process(token, parser);
83 }
84
85 /** Interface for processing one token. */
86 interface TokenProcessor {
87 /** Process one token.
88 * @param token token to process
89 * @param parser file parser
90 * @return true of token was accepted
91 */
92 boolean process(ParseToken token, AbstractConstituentParser<?, ?, ?> parser);
93 }
94
95 }