UserDefinedXmlTokenBuilder.java

  1. /* Copyright 2002-2022 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. import java.util.Collections;
  19. import java.util.List;

  20. import org.orekit.files.ccsds.ndm.odm.UserDefined;
  21. import org.orekit.utils.units.Unit;
  22. import org.xml.sax.Attributes;

  23. /** Builder for user-defined parameters.
  24.  * <p>
  25.  * User-defined elements are of the form:
  26.  * </p>
  27.  * <pre>
  28.  *   &lt;USER_DEFINED parameter="SOME_PARAMETER_NAME"&gt;value&lt;/USER_DEFINED&gt;
  29.  * </pre>
  30.  * <p>
  31.  * This {@link XmlTokenBuilder token builder} will generate a single
  32.  * {@link ParseToken parse token} from this root element with name set to
  33.  * "SOME_PARAMETER_NAME", type set to {@link TokenType#ENTRY} and content
  34.  * set to {@code value}.
  35.  * </p>
  36.  * @author Luc Maisonobe
  37.  * @since 11.0
  38.  */
  39. public class UserDefinedXmlTokenBuilder implements XmlTokenBuilder {

  40.     /** {@inheritDoc} */
  41.     @Override
  42.     public List<ParseToken> buildTokens(final boolean startTag, final String qName,
  43.                                         final String content, final Attributes attributes,
  44.                                         final int lineNumber, final String fileName) {

  45.         // elaborate the token type
  46.         final TokenType tokenType = (content == null) ?
  47.                                     (startTag ? TokenType.START : TokenType.STOP) :
  48.                                     TokenType.ENTRY;

  49.         // final build
  50.         final String name = attributes.getValue(UserDefined.USER_DEFINED_XML_ATTRIBUTE);
  51.         final ParseToken token = new ParseToken(tokenType,
  52.                                                 UserDefined.USER_DEFINED_PREFIX + name,
  53.                                                 content, Unit.NONE,
  54.                                                 lineNumber, fileName);

  55.         return Collections.singletonList(token);

  56.     }

  57. }