Class ParsingUtils

java.lang.Object
de.iip_ecosphere.platform.configuration.aas.ParsingUtils

class ParsingUtils extends Object
Utilities for text parsing.
Author:
Holger Eichelberger, SSE
  • Field Details

    • IRI_MARKER_TEXT

      public static final String IRI_MARKER_TEXT
      See Also:
    • IRDI_MARKER_TEXT

      public static final String IRDI_MARKER_TEXT
      See Also:
    • SEMANTICID_MARKER

      public static final String[] SEMANTICID_MARKER
    • SEMANTICID_MARKER_WITH_PATH

      public static final String[] SEMANTICID_MARKER_WITH_PATH
    • BRACKETS_WIITH_FOOTNOTE

      private static final Pattern BRACKETS_WIITH_FOOTNOTE
    • ENUM_LITERAL_PATTERN

      private static final Pattern ENUM_LITERAL_PATTERN
  • Constructor Details

    • ParsingUtils

      ParsingUtils()
  • Method Details

    • toIdentifier

      static String toIdentifier(String name)
      Turns name into a valid Java/IVML identifier.
      Parameters:
      name - the name to be processed
      Returns:
      the identifier based on name
    • removeLinebreaks

      static String removeLinebreaks(String data)
      Removes linebreaks from data replacing them by a single whitespace.
      Parameters:
      data - the data
      Returns:
      the modified version of data
    • replaceWhitespace

      static String replaceWhitespace(String data, String replacement)
      Replaces whitespaces in data.
      Parameters:
      data - the data (may be null)
      replacement - the replacement for whitespaces
      Returns:
      the modified version of data
    • removeWhitespace

      static String removeWhitespace(String data)
      Removes whitespaces from data.
      Parameters:
      data - the data
      Returns:
      the modified version of data
    • consumeWhitespaces

      static int consumeWhitespaces(String data, int pos)
      Consumes whitespaces starting at pos.
      Parameters:
      data - the text to iterate over
      pos - the position to start at
      Returns:
      the next position in data that is not a whitespace, may be after string length
    • consumeNonWhitespaces

      static int consumeNonWhitespaces(String data, int pos)
      Consumes not-whitespaces starting at pos.
      Parameters:
      data - the text to iterate over
      pos - the position to start at
      Returns:
      the next position in data that is a whitespace, may be after string length
    • toNullIfEmpty

      static String toNullIfEmpty(String data)
      Turns data to null if data is empty.
      Parameters:
      data - the string
      Returns:
      data or null
    • toLines

      static String[] toLines(String data)
      Splits a string into an array of individual lines.
      Parameters:
      data - the string to be split (may be null)
      Returns:
      the lines or null if data was null
    • removeBrackets

      static String removeBrackets(String data)
      Removes surrounding brackets from data.
      Parameters:
      data - the data to be processed
      Returns:
      data or data with surrounding brackets, then whitespaces removed
      See Also:
    • fixTypeName

      static String fixTypeName(String name)
      Checks and fixes a type name. In some specs, there is additional information or typos such as cardinalities. Is some specs, the type name is in brackets. This information is removed.
      Parameters:
      name - the type name
      Returns:
      name or a shortened version
      See Also:
    • getLastNoteComment

      static String getLastNoteComment(String text)
      Returns the last "Note :" comment in text.
      Parameters:
      text - the text to take the comment from
      Returns:
      the comment including "Note: ", null if there is none
    • hasFixedIdShort

      static boolean hasFixedIdShort(String noteComment)
      Analyzes an AAS type idShort comment for a note.
      Parameters:
      noteComment - the note comment
      Returns:
      true for fixed idShort, false for free idShort
    • inferEnum

      static String inferEnum(String data, String description, AasField field, ParsingUtils.AasEnumResultHandler aasEnums, boolean atBeginning)
      Tries to infer an enumeration description from the given descriptionRest based on the defined enum kinds.
      Parameters:
      data - the actual part containing the enumeration text
      description - the actual description text
      field - the target field (to be modified as a side effect)
      aasEnums - the known enums, to be modified as a side effect
      atBeginning - whether the enum marker may be at the very beginning of data or not
      Returns:
      description or an updated/modified text
    • inferEnum

      static String inferEnum(ParsingEnumKind kind, String descriptionRest, String idShort, String semanticId, String description, ParsingUtils.AasEnumResultHandler aasEnums, boolean isOpen)
      Tries to infer an enumeration description from the given descriptionRest.
      Parameters:
      kind - the enumeration kind
      descriptionRest - the description rest that potentially contains a flattened, comma-separated description of enum literals
      idShort - the idShort of the containing field
      semanticId - optional semantic id of the enum
      description - the description of the enum
      aasEnums - the known enums, to be modified as a side effect
      isOpen - whether the enum is considered to be "open" for extensions
      Returns:
      the type name of the enum (for now, just idShort)
    • tokenizeEnumSpec

      private static Enumeration<Object> tokenizeEnumSpec(String text, ParsingEnumKind enumKind)
      Tokenizes an enum specification. Prevents token splitting within parentheses.
      Parameters:
      text - the text to tokenize
      enumKind - the kind of enum to tokenize
      Returns:
      the token enumeration (compliant to StringTokenizer
    • tokenizeEnumSpecValueList2

      private static void tokenizeEnumSpecValueList2(String text, Vector<Object> tokens)
      Tokenizes an enum specification according to ParsingEnumKind.VALUE_LIST2.
      Parameters:
      text - the text to tokenize
      tokens - the tokens (compliant to StringTokenizer
    • inferEnumLiteralFromToken

      private static void inferEnumLiteralFromToken(String token, AasEnum en)
      Infers enumeration literals from a token according to ParsingEnumKind.ENUM.
      Parameters:
      token - the token
      en - the enumeration to add the literals to
    • inferValueList2EntriesLiteralFromToken

      private static void inferValueList2EntriesLiteralFromToken(String token, AasEnum en)
      Infers value list (2) entries. IDTA-02010-1-0
      Parameters:
      token - the token
      en - the enumeration to be modified as a side effect
    • inferEnumIrdiLiteralsFromToken

      private static void inferEnumIrdiLiteralsFromToken(String token, AasEnum en)
      Infers an enumeration literal based on IRDI values. IDTA-02004-1-2.
      Parameters:
      token - the token containing the literal(s)
      en - the enum to complement with literals
    • getSemanticIdPrefix

      private static String getSemanticIdPrefix(String text)
      Infers the semanticId prefix of text.
      Parameters:
      text - the text to use as basis
      Returns:
      the semanticId prefix as in IdentifierType, may be null for none
    • inferEnumEntriesLiteralFromToken

      private static void inferEnumEntriesLiteralFromToken(String token, AasEnum en)
      Infers enumeration literals from a token according to ParsingEnumKind.ENUM_ENTRIES.
      Parameters:
      token - the token
      en - the enumeration to add the literals to
    • removeQuotes

      static String removeQuotes(String value)
      Removes beautified paired quotes.
      Parameters:
      value - the value to be processed
      Returns:
      the processed value
    • parseEnumEntriesLiteralFromToken

      private static void parseEnumEntriesLiteralFromToken(String token, AasEnum en)
      Parses enum literals via ENUM_LITERAL_PATTERN a given token.
      Parameters:
      token - the token
      en - the enumeration to add the literal to
    • toLiteralName

      private static String toLiteralName(String description)
      Tries to infer an enum field name from description.
      Parameters:
      description - the description
      Returns:
      the field name or description
    • filterLanguage

      static String filterLanguage(String description)
      Filter English or any other language from description if given in multi languages, prefer "definition @" if given.
      Parameters:
      description - the description
      Returns:
      the last language-specific description
    • filterLanguageImpl

      private static String filterLanguageImpl(String description)
      Filter English or any other language from description if given in multi languages.
      Parameters:
      description - the description
      Returns:
      the last language-specific description
    • isGenericIdShort

      static boolean isGenericIdShort(String idShort)
      Whether a field shall be ignored.
      Parameters:
      idShort - the idShort to test (may be null)
      Returns:
      true for ignore, false else
    • toSemanticIdMarker

      private static String toSemanticIdMarker(String value)
      Turns value into a semanticID marker.
      Parameters:
      value - the value
      Returns:
      the marker
    • getSemanticIdMarkers

      static String[] getSemanticIdMarkers(String value)
      Returns the sequence of semantic ID markers in value.
      Parameters:
      value - the value
      Returns:
      the number of semantic IDs
    • countSemanticIdMarker

      static int countSemanticIdMarker(String value)
      Returns the number of semantic ID markers in value.
      Parameters:
      value - the value
      Returns:
      the number of semantic IDs
    • hasSemanticIdMarker

      static boolean hasSemanticIdMarker(String value)
      Returns whether string starts with one of the markers in SEMANTICID_MARKER.
      Parameters:
      value - the value to check
      Returns:
      true if a semanticId marker was found, false else
    • removeSuffix

      static String removeSuffix(String text, String suffix)
      If text has suffix, return text without suffix.
      Parameters:
      text - the text
      suffix - the suffix
      Returns:
      text or text without suffix
    • removePrefix

      static String removePrefix(String text, String prefix)
      If text has prefix, return text without prefix.
      Parameters:
      text - the text
      prefix - the prefix
      Returns:
      text or text without prefix
    • contains

      static boolean contains(String[] data, String item)
      Returns whether data contains item through equals.
      Parameters:
      data - the data to search
      item - the item to look for
      Returns:
      true if contained, false else
    • isValue

      static boolean isValue(String val)
      Returns whether val is an value to be emitted.
      Parameters:
      val - the value
      Returns:
      true for emitting, false for skipping
    • isValue

      static boolean isValue(Object[] val)
      Returns whether val is an value to be emitted.
      Parameters:
      val - the value
      Returns:
      true for emitting, false for skipping
    • stripRefBy

      static String stripRefBy(String type)
      Strips an IVML refBy declaration and returns the contained type.
      Parameters:
      type - the type
      Returns:
      type or type without refBy
    • getLogger

      private static de.iip_ecosphere.platform.support.logging.Logger getLogger()
      Returns the logger of this class.
      Returns:
      the logger