Class XMPNormalizer

java.lang.Object
com.itextpdf.xmp.impl.XMPNormalizer

public class XMPNormalizer extends Object
Since:
Aug 18, 2006
  • Field Details

    • dcArrayForms

      private static Map dcArrayForms
      caches the correct dc-property array forms
  • Constructor Details

    • XMPNormalizer

      private XMPNormalizer()
      Hidden constructor
  • Method Details

    • process

      static XMPMeta process(XMPMetaImpl xmp, ParseOptions options) throws XMPException
      Normalizes a raw parsed XMPMeta-Object
      Parameters:
      xmp - the raw metadata object
      options - the parsing options
      Returns:
      Returns the normalized metadata object
      Throws:
      XMPException - Collects all severe processing errors.
    • tweakOldXMP

      private static void tweakOldXMP(XMPNode tree) throws XMPException
      Tweak old XMP: Move an instance ID from rdf:about to the xmpMM:InstanceID property. An old instance ID usually looks like "uuid:bac965c4-9d87-11d9-9a30-000d936b79c4", plus InDesign 3.0 wrote them like "bac965c4-9d87-11d9-9a30-000d936b79c4". If the name looks like a UUID simply move it to xmpMM:InstanceID, don't worry about any existing xmpMM:InstanceID. Both will only be present when a newer file with the xmpMM:InstanceID property is updated by an old app that uses rdf:about.
      Parameters:
      tree - the root of the metadata tree
      Throws:
      XMPException - Thrown if tweaking fails.
    • touchUpDataModel

      private static void touchUpDataModel(XMPMetaImpl xmp) throws XMPException
      Visit all schemas to do general fixes and handle special cases.
      Parameters:
      xmp - the metadata object implementation
      Throws:
      XMPException - Thrown if the normalisation fails.
    • normalizeDCArrays

      private static void normalizeDCArrays(XMPNode dcSchema) throws XMPException
      Undo the denormalization performed by the XMP used in Acrobat 5.
      If a Dublin Core array had only one item, it was serialized as a simple property.
      The xml:lang attribute was dropped from an alt-text item if the language was x-default.
      Parameters:
      dcSchema - the DC schema node
      Throws:
      XMPException - Thrown if normalization fails
    • repairAltText

      private static void repairAltText(XMPNode arrayNode) throws XMPException
      Make sure that the array is well-formed AltText. Each item must be simple and have an "xml:lang" qualifier. If repairs are needed, keep simple non-empty items by adding the "xml:lang" with value "x-repair".
      Parameters:
      arrayNode - the property node of the array to repair.
      Throws:
      XMPException - Forwards unexpected exceptions.
    • moveExplicitAliases

      private static void moveExplicitAliases(XMPNode tree, ParseOptions options) throws XMPException
      Visit all of the top level nodes looking for aliases. If there is no base, transplant the alias subtree. If there is a base and strict aliasing is on, make sure the alias and base subtrees match.
      Parameters:
      tree - the root of the metadata tree
      options - th parsing options
      Throws:
      XMPException - Forwards XMP errors
    • transplantArrayItemAlias

      private static void transplantArrayItemAlias(Iterator propertyIt, XMPNode childNode, XMPNode baseArray) throws XMPException
      Moves an alias node of array form to another schema into an array
      Parameters:
      propertyIt - the property iterator of the old schema (used to delete the property)
      childNode - the node to be moved
      baseArray - the base array for the array item
      Throws:
      XMPException - Forwards XMP errors
    • fixGPSTimeStamp

      private static void fixGPSTimeStamp(XMPNode exifSchema) throws XMPException
      Fixes the GPS Timestamp in EXIF.
      Parameters:
      exifSchema - the EXIF schema node
      Throws:
      XMPException - Thrown if the date conversion fails.
    • deleteEmptySchemas

      private static void deleteEmptySchemas(XMPNode tree)
      Remove all empty schemas from the metadata tree that were generated during the rdf parsing.
      Parameters:
      tree - the root of the metadata tree
    • compareAliasedSubtrees

      private static void compareAliasedSubtrees(XMPNode aliasNode, XMPNode baseNode, boolean outerCall) throws XMPException
      The outermost call is special. The names almost certainly differ. The qualifiers (and hence options) will differ for an alias to the x-default item of a langAlt array.
      Parameters:
      aliasNode - the alias node
      baseNode - the base node of the alias
      outerCall - marks the outer call of the recursion
      Throws:
      XMPException - Forwards XMP errors
    • migrateAudioCopyright

      private static void migrateAudioCopyright(XMPMeta xmp, XMPNode dmCopyright)
      The initial support for WAV files mapped a legacy ID3 audio copyright into a new xmpDM:copyright property. This is special case code to migrate that into dc:rights['x-default']. The rules:
       1. If there is no dc:rights array, or an empty array -
          Create one with dc:rights['x-default'] set from double linefeed and xmpDM:copyright.
       
       2. If there is a dc:rights array but it has no x-default item -
          Create an x-default item as a copy of the first item then apply rule #3.
       
       3. If there is a dc:rights array with an x-default item, 
          Look for a double linefeed in the value.
           A. If no double linefeed, compare the x-default value to the xmpDM:copyright value.
               A1. If they match then leave the x-default value alone.
               A2. Otherwise, append a double linefeed and 
                   the xmpDM:copyright value to the x-default value.
           B. If there is a double linefeed, compare the trailing text to the xmpDM:copyright value.
               B1. If they match then leave the x-default value alone.
               B2. Otherwise, replace the trailing x-default text with the xmpDM:copyright value.
       
       4. In all cases, delete the xmpDM:copyright property.
       
      Parameters:
      xmp - the metadata object
      dmCopyright - the "dm:copyright"-property
    • initDCArrays

      private static void initDCArrays()
      Initializes the map that contains the known arrays, that are fixed by normalizeDCArrays(XMPNode).