Class XMPUtilsImpl

java.lang.Object
com.itextpdf.kernel.xmp.impl.XMPUtilsImpl
All Implemented Interfaces:
XMPConst

public final class XMPUtilsImpl extends Object implements XMPConst
Since:
11.08.2006
  • Field Details

    • UCK_NORMAL

      private static final int UCK_NORMAL
      See Also:
    • UCK_SPACE

      private static final int UCK_SPACE
      See Also:
    • UCK_COMMA

      private static final int UCK_COMMA
      See Also:
    • UCK_SEMICOLON

      private static final int UCK_SEMICOLON
      See Also:
    • UCK_QUOTE

      private static final int UCK_QUOTE
      See Also:
    • UCK_CONTROL

      private static final int UCK_CONTROL
      See Also:
    • SPACES

      private static final String SPACES
      U+0022 ASCII space
      U+3000, ideographic space
      U+303F, ideographic half fill space
      U+2000..U+200B, en quad through zero width space
      See Also:
    • COMMAS

      private static final String COMMAS
      U+002C, ASCII comma
      U+FF0C, full width comma
      U+FF64, half width ideographic comma
      U+FE50, small comma
      U+FE51, small ideographic comma
      U+3001, ideographic comma
      U+060C, Arabic comma
      U+055D, Armenian comma
      See Also:
    • SEMICOLA

      private static final String SEMICOLA
      U+003B, ASCII semicolon
      U+FF1B, full width semicolon
      U+FE54, small semicolon
      U+061B, Arabic semicolon
      U+037E, Greek "semicolon" (really a question mark)
      See Also:
    • QUOTES

      private static final String QUOTES
      U+0022 ASCII quote
      The square brackets are not interpreted as quotes anymore (bug #2674672) (ASCII '[' (0x5B) and ']' (0x5D) are used as quotes in Chinese and Korean.)
      U+00AB and U+00BB, guillemet quotes
      U+3008..U+300F, various quotes.
      U+301D..U+301F, double prime quotes.
      U+2015, dash quote.
      U+2018..U+201F, various quotes.
      U+2039 and U+203A, guillemet quotes.
      See Also:
    • CONTROLS

      private static final String CONTROLS
      U+0000..U+001F ASCII controls
      U+2028, line separator.
      U+2029, paragraph separator.
      See Also:
  • Constructor Details

    • XMPUtilsImpl

      private XMPUtilsImpl()
      Private constructor, as
  • Method Details

    • catenateArrayItems

      public static String catenateArrayItems(XMPMeta xmp, String schemaNS, String arrayName, String separator, String quotes, boolean allowCommas) throws XMPException
      Parameters:
      xmp - The XMP object containing the array to be catenated.
      schemaNS - The schema namespace URI for the array. Must not be null or the empty string.
      arrayName - The name of the array. May be a general path expression, must not be null or the empty string. Each item in the array must be a simple string value.
      separator - The string to be used to separate the items in the catenated string. Defaults to "; ", ASCII semicolon and space (U+003B, U+0020).
      quotes - The characters to be used as quotes around array items that contain a separator. Defaults to '"';
      allowCommas - Option flag to control the catenation.
      Returns:
      Returns the string containing the catenated array items.
      Throws:
      XMPException - Forwards the Exceptions from the metadata processing
      See Also:
    • separateArrayItems

      public static void separateArrayItems(XMPMeta xmp, String schemaNS, String arrayName, String catedStr, PropertyOptions arrayOptions, boolean preserveCommas) throws XMPException
      Parameters:
      xmp - The XMP object containing the array to be updated.
      schemaNS - The schema namespace URI for the array. Must not be null or the empty string.
      arrayName - The name of the array. May be a general path expression, must not be null or the empty string. Each item in the array must be a simple string value.
      catedStr - The string to be separated into the array items.
      arrayOptions - Option flags to control the separation.
      preserveCommas - Flag if commas shall be preserved
      Throws:
      XMPException - Forwards the Exceptions from the metadata processing
    • separateFindCreateArray

      private static XMPNode separateFindCreateArray(String schemaNS, String arrayName, PropertyOptions arrayOptions, XMPMetaImpl xmp) throws XMPException
      Utility to find or create the array used by separateArrayItems().
      Parameters:
      schemaNS - a the namespace fo the array
      arrayName - the name of the array
      arrayOptions - the options for the array if newly created
      xmp - the xmp object
      Returns:
      Returns the array node.
      Throws:
      XMPException - Forwards exceptions
    • removeProperties

      public static void removeProperties(XMPMeta xmp, String schemaNS, String propName, boolean doAllProperties, boolean includeAliases) throws XMPException
      Parameters:
      xmp - The XMP object containing the properties to be removed.
      schemaNS - Optional schema namespace URI for the properties to be removed.
      propName - Optional path expression for the property to be removed.
      doAllProperties - Option flag to control the deletion: do internal properties in addition to external properties.
      includeAliases - Option flag to control the deletion: Include aliases in the "named schema" case above.
      Throws:
      XMPException - If metadata processing fails
      See Also:
    • appendProperties

      public static void appendProperties(XMPMeta source, XMPMeta destination, boolean doAllProperties, boolean replaceOldValues, boolean deleteEmptyValues) throws XMPException
      Parameters:
      source - The source XMP object.
      destination - The destination XMP object.
      doAllProperties - Do internal properties in addition to external properties.
      replaceOldValues - Replace the values of existing properties.
      deleteEmptyValues - Delete destination values if source property is empty.
      Throws:
      XMPException - Forwards the Exceptions from the metadata processing
      See Also:
    • removeSchemaChildren

      private static boolean removeSchemaChildren(XMPNode schemaNode, boolean doAllProperties)
      Remove all schema children according to the flag doAllProperties. Empty schemas are automatically remove by XMPNode
      Parameters:
      schemaNode - a schema node
      doAllProperties - flag if all properties or only externals shall be removed.
      Returns:
      Returns true if the schema is empty after the operation.
    • appendSubtree

      private static void appendSubtree(XMPMetaImpl destXMP, XMPNode sourceNode, XMPNode destParent, boolean replaceOldValues, boolean deleteEmptyValues) throws XMPException
      Parameters:
      destXMP - The destination XMP object.
      sourceNode - the source node
      destParent - the parent of the destination node
      replaceOldValues - Replace the values of existing properties.
      deleteEmptyValues - flag if properties with empty values should be deleted in the destination object.
      Throws:
      XMPException
      See Also:
    • itemValuesMatch

      private static boolean itemValuesMatch(XMPNode leftNode, XMPNode rightNode) throws XMPException
      Compares two nodes including its children and qualifier.
      Parameters:
      leftNode - an XMPNode
      rightNode - an XMPNode
      Returns:
      Returns true if the nodes are equal, false otherwise.
      Throws:
      XMPException - Forwards exceptions to the calling method.
    • checkSeparator

      private static void checkSeparator(String separator) throws XMPException
      Make sure the separator is OK. It must be one semicolon surrounded by zero or more spaces. Any of the recognized semicolons or spaces are allowed.
      Parameters:
      separator -
      Throws:
      XMPException
    • checkQuotes

      private static char checkQuotes(String quotes, char openQuote) throws XMPException
      Make sure the open and close quotes are a legitimate pair and return the correct closing quote or an exception.
      Parameters:
      quotes - opened and closing quote in a string
      openQuote - the open quote
      Returns:
      Returns a corresponding closing quote.
      Throws:
      XMPException
    • classifyCharacter

      private static int classifyCharacter(char ch)
      Classifies the character into normal chars, spaces, semicola, quotes, control chars.
      Parameters:
      ch - a char
      Returns:
      Return the character kind.
    • getClosingQuote

      private static char getClosingQuote(char openQuote)
      Parameters:
      openQuote - the open quote char
      Returns:
      Returns the matching closing quote for an open quote.
    • applyQuotes

      private static String applyQuotes(String item, char openQuote, char closeQuote, boolean allowCommas)
      Add quotes to the item.
      Parameters:
      item - the array item
      openQuote - the open quote character
      closeQuote - the closing quote character
      allowCommas - flag if commas are allowed
      Returns:
      Returns the value in quotes.
    • isSurroundingQuote

      private static boolean isSurroundingQuote(char ch, char openQuote, char closeQuote)
      Parameters:
      ch - a character
      openQuote - the opening quote char
      closeQuote - the closing quote char
      Returns:
      Return it the character is a surrounding quote.
    • isClosingingQuote

      private static boolean isClosingingQuote(char ch, char openQuote, char closeQuote)
      Parameters:
      ch - a character
      openQuote - the opening quote char
      closeQuote - the closing quote char
      Returns:
      Returns true if the character is a closing quote.