Class AnnotationValidator

java.lang.Object
org.apache.pdfbox.preflight.annotation.AnnotationValidator
Direct Known Subclasses:
FreeTextAnnotationValidator, HighlightAnnotationValidator, InkAnnotationValidator, LineAnnotationValidator, LinkAnnotationValidator, PopupAnnotationValidator, PrintMarkAnnotationValidator, RubberStampAnnotationValidator, SquareCircleAnnotationValidator, SquigglyAnnotationValidator, StrikeoutAnnotationValidator, TextAnnotationValidator, TrapNetAnnotationValidator, UnderlineAnnotationValidator, WidgetAnnotationValidator

public abstract class AnnotationValidator extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.pdfbox.cos.COSDictionary
    COSDictionary of the annotation
     
    protected org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation
    Instance of PDAnnotation built using the annotDictionary
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnnotationValidator(PreflightContext context, org.apache.pdfbox.cos.COSDictionary annotDictionary)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Extract a list of ActionManager from the Annotation dictionary and valid them.
    protected boolean
    This method checks the AP entry of the Annotation Dictionary.
    protected boolean
    Check if the CA value is 1.0.
    protected boolean
    Return true if the C field is present in the Annotation dictionary and if the RGB profile is used in the DestOutputProfile of the OutputIntent dictionary.
    protected boolean
    Checks if flags of the annotation are authorized.
    protected boolean
    Checks if all mandatory fields of an annotation are present.
    protected boolean
    This method validates the Popup entry.
    protected boolean
    Override this method to check the presence of specific fields
    protected boolean
    Search the RGB Profile in OutputIntents dictionaries
    final void
    Initialize the annotFact attribute of this object.
    boolean
    Execute validation of the Annotation dictionary.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ctx

      protected PreflightContext ctx
    • annotDictionary

      protected org.apache.pdfbox.cos.COSDictionary annotDictionary
      COSDictionary of the annotation
    • pdAnnot

      protected org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation pdAnnot
      Instance of PDAnnotation built using the annotDictionary
  • Constructor Details

    • AnnotationValidator

      public AnnotationValidator(PreflightContext context, org.apache.pdfbox.cos.COSDictionary annotDictionary)
  • Method Details

    • checkFlags

      protected boolean checkFlags()
      Checks if flags of the annotation are authorized.
      • Print flag must be 1
      • NoView flag must be 0
      • Hidden flag must be 0
      • Invisible flag must be 0
      If one of these flags is invalid, the errors list is updated with the ERROR_ANNOT_FORBIDDEN_FLAG ValidationError code.
      Returns:
      false if a flag is invalid, true otherwise.
    • checkCA

      protected boolean checkCA()
      Check if the CA value is 1.0. Return true if the CA element is missing or if the value is 1.0. Return false otherwise and update the list of errors present in the DocumentHandler.
      Returns:
      true if the CA element is missing or if the value is 1.0.
    • checkColors

      protected boolean checkColors() throws ValidationException
      Return true if the C field is present in the Annotation dictionary and if the RGB profile is used in the DestOutputProfile of the OutputIntent dictionary.
      Returns:
      true if the C field is present and the RGB profile is used.
      Throws:
      ValidationException
    • searchRGBProfile

      protected boolean searchRGBProfile() throws ValidationException
      Search the RGB Profile in OutputIntents dictionaries
      Returns:
      true if a rgb profile is found, false otherwise.
      Throws:
      ValidationException
    • checkAP

      protected boolean checkAP() throws ValidationException
      This method checks the AP entry of the Annotation Dictionary. If the AP key is missing, this method returns true. If the AP key exists, only the N entry is authorized and must be a Stream which define the appearance of the annotation. (Currently, only the type of the N entry is checked because of the Appearance stream is a Form XObject, so it will be checked by the Graphics Helper) If the AP content isn't valid, this method return false and updates the errors list.
      Returns:
      the validation state of the AP content.
      Throws:
      ValidationException
    • checkActions

      protected boolean checkActions() throws ValidationException
      Extract a list of ActionManager from the Annotation dictionary and valid them. If an action is invalid, the errors list is updated and the method returns false. Otherwise, the method returns true and the errors list doesn't change.
      Returns:
      the validation state of the annotations actions.
      Throws:
      ValidationException
    • checkPopup

      protected boolean checkPopup() throws ValidationException
      This method validates the Popup entry. This entry shall contain an other Annotation. This annotation is validated with the right AnnotationValidator.
      Returns:
      true if the popup entry is valid, false if not.
      Throws:
      ValidationException
    • validate

      public boolean validate() throws ValidationException
      Execute validation of the Annotation dictionary.
      Returns:
      true if validation succeed, false otherwise.
      Throws:
      ValidationException
    • checkMandatoryFields

      protected boolean checkMandatoryFields()
      Checks if all mandatory fields of an annotation are present. If some fields are missing, the method returns false and the errors list is updated.
      Returns:
      true if validation succeed, false otherwise.
    • checkSpecificMandatoryFields

      protected boolean checkSpecificMandatoryFields()
      Override this method to check the presence of specific fields
      Returns:
      the presence of specific fields.
    • setFactory

      public final void setFactory(AnnotationValidatorFactory fact)
      Initialize the annotFact attribute of this object. This method must be called by the Factory at the creation of this object. Only the Factory should call this method.
      Parameters:
      fact -