Class XMLUtils

java.lang.Object
org.semanticweb.owlapi.io.XMLUtils

public final class XMLUtils extends Object
This class contains various methods for checking QNames, NCNames etc. The implementation is based on the W3C namespaces in XML specification.
Since:
3.3.0
Author:
Matthew Horridge, The University of Manchester, Bio-Health Informatics Group
  • Field Details

  • Method Details

    • isXMLNameStartCharacter

      public static boolean isXMLNameStartCharacter(int codePoint)
      Determines if a character is an XML name start character.
      Parameters:
      codePoint - The code point of the character to be tested. For UTF-16 characters the code point corresponds to the value of the char that represents the character.
      Returns:
      true if codePoint is an XML name start character, otherwise false
    • isXMLNameChar

      public static boolean isXMLNameChar(int codePoint)
      Determines if a character is an XML name character.
      Parameters:
      codePoint - The code point of the character to be tested. For UTF-8 and UTF-16 characters the code point corresponds to the value of the char that represents the character.
      Returns:
      true if codePoint is an XML name start character, otherwise false
    • isNCNameStartChar

      public static boolean isNCNameStartChar(int codePoint)
      Determines if a character is an NCName (Non-Colonised Name) start character.
      Parameters:
      codePoint - The code point of the character to be tested. For UTF-8 and UTF-16 characters the code point corresponds to the value of the char that represents the character.
      Returns:
      true if codePoint is a NCName start character, otherwise false.
    • isNCNameChar

      public static boolean isNCNameChar(int codePoint)
      Determines if a character is an NCName (Non-Colonised Name) character.
      Parameters:
      codePoint - The code point of the character to be tested. For UTF-8 and UTF-16 characters the code point corresponds to the value of the char that represents the character.
      Returns:
      true if codePoint is a NCName character, otherwise false.
    • isNCName

      public static boolean isNCName(@Nullable CharSequence s)
      Determines if a character sequence is an NCName (Non-Colonised Name). An NCName is a string which starts with an NCName start character and is followed by zero or more NCName characters.
      Parameters:
      s - The character sequence to be tested.
      Returns:
      true if s is an NCName, otherwise false.
    • isQName

      public static boolean isQName(CharSequence s)
      Determines if a character sequence is a QName. A QName is either an NCName (LocalName), or an NCName followed by a colon followed by another NCName (where the first NCName is referred to as the 'Prefix Name' and the second NCName is referred to as the 'Local Name' - i.e. PrefixName:LocalName).
      Parameters:
      s - The character sequence to be tested.
      Returns:
      true if s is a QName, otherwise false.
    • isQName

      public static boolean isQName(CharSequence s, int start)
      Determines if a character sequence is a QName. A QName is either an NCName (LocalName), or an NCName followed by a colon followed by another NCName (where the first NCName is referred to as the 'Prefix Name' and the second NCName is referred to as the 'Local Name' - i.e. PrefixName:LocalName).
      Parameters:
      s - The character sequence to be tested.
      start - start index to check
      Returns:
      true if s is a QName, otherwise false.
    • hasNCNameSuffix

      public static boolean hasNCNameSuffix(CharSequence s)
      Determines if a character sequence has a suffix that is an NCName.
      Parameters:
      s - The character sequence.
      Returns:
      true if the character sequence s has a suffix that is an NCName.
    • getNCNameSuffixIndex

      public static int getNCNameSuffixIndex(CharSequence s)
      Gets the index of the longest NCName that is the suffix of a character sequence.
      Parameters:
      s - The character sequence.
      Returns:
      The index of the longest suffix of the specified character sequence s that is an NCName, or -1 if the character sequence s does not have a suffix that is an NCName.
    • getNCNameSuffix

      @Nullable public static String getNCNameSuffix(CharSequence s)
      Get the longest NCName that is a suffix of a character sequence.
      Parameters:
      s - The character sequence.
      Returns:
      The String which is the longest suffix of the character sequence s that is an NCName, or null if the character sequence s does not have a suffix that is an NCName.
    • isEmpty

      public static boolean isEmpty(@Nullable CharSequence s)
      Parameters:
      s - string
      Returns:
      true if the input is null, empty or blank, i.e., only containing whitespace characters
    • getNCNamePrefix

      public static String getNCNamePrefix(CharSequence s)
      utility to get the part of a char sequence that is not the NCName fragment.
      Parameters:
      s - the char sequence to split
      Returns:
      the prefix split at the last non-ncname character, or the whole input if no ncname is found
    • escapeXML

      public static String escapeXML(CharSequence s)
      Escapes a character sequence so that it is valid XML.
      Parameters:
      s - The character sequence.
      Returns:
      The escaped version of the character sequence.
    • escapeXML

      public static StringBuilder escapeXML(char[] chars, int start, int count, StringBuilder destination)
      Escapes a subset of a char sequence so that it is valid XML. Escaped or unchanged characters are added to destination.
      Parameters:
      chars - chars to check
      start - start index (inclusive)
      count - number of characters
      destination - destination for escaped chars
      Returns:
      The modified destination.
    • escapeXML

      public static void escapeXML(StringBuilder sb)
      Escapes a string builder so that it is valid XML.
      Parameters:
      sb - The string builder to escape.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable CharSequence s)
      Determines if a character sequence is null or empty.
      Parameters:
      s - The character sequence.
      Returns:
      true if the character sequence is null, true if the character sequence is empty, otherwise false.
    • iriWithTerminatingHash

      public static String iriWithTerminatingHash(@Nullable String iri)
      Parameters:
      iri - input to check and terminate with a hash
      Returns:
      input plus a hash if the input does not terminate with hash or slash; if the input contains a hash in a position aside from the last character, it is returned unchanged. If null is received, return "#".