Class XfdfAnnotation


  • public final class XfdfAnnotation
    extends java.lang.Object
    One <annots> entry (or a nested <popup>) -- a plain, generic bag of the XFDF attributes and child elements defined across every markup annotation type in ISO 19444-1 §6.4, rather than a separate Java class per PDF annotation subtype. The handful of type-specific pieces of data that don't fit a flat string attribute (vertices, ink gestures, quad points, and the nested popup) get their own typed fields; everything else -- including attributes only some types use -- lives in getAttributes().

    getType() is the lower-case XFDF element name (e.g. "square", "freetext", "popup") that both XfdfReader/ XfdfWriter and internal.AnnotationMapper key their dispatch on.

    • Constructor Summary

      Constructors 
      Constructor Description
      XfdfAnnotation​(java.lang.String type)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addGesture​(float[] points)
      Appends one <gesture> stroke (a flat [x1, y1, x2, y2, ...] point list) to the ink list, creating it if this is the first.
      static java.lang.String formatFloat​(float value)
      Trims a clean integer-valued float down to "100" rather than "100.0", matching real producers' output.
      static java.lang.String formatFloatList​(float[] values, java.lang.String separator)
      The inverse of parseFloatList(String, int): joins values with separator, or returns null if values is null.
      java.lang.String getAttribute​(java.lang.String name)
      The raw string value of attribute name, or null if this annotation doesn't carry it.
      java.util.Map<java.lang.String,​java.lang.String> getAttributes()
      Every XFDF attribute this annotation carries (raw attribute name, e.g.
      java.lang.String getContents()
      Plain-text <contents> body, or null.
      java.lang.String getContentsRichText()
      Raw inner XML of <contents-richtext> (the /RC rich text string), or null.
      java.lang.String getDefaultAppearance()
      Raw <defaultappearance> text (the /DA string), or null.
      java.util.List<float[]> getInkList()
      Ink <inklist>: one flat [x1, y1, x2, y2, ...] array per <gesture> stroke, or null.
      java.lang.String getName()
      The name attribute -- the annotation's PDF /NM unique identifier.
      int getPage()
      Zero-based page index (the page attribute), or -1 if absent/unparseable.
      XfdfAnnotation getPopup()
      The nested <popup> child, if this annotation has its own popup window, or null.
      float[] getQuadPoints()
      Highlight/Underline/Squiggly/StrikeOut/Redact/Link quad points, flat 8-per-quad, or null.
      float[] getRect()
      The rect attribute as [llx, lly, urx, ury], or null if absent/unparseable.
      java.lang.String getType()
      The lower-case XFDF element name, e.g.
      float[] getVertices()
      Polygon/Polyline <vertices> as a flat [x1, y1, x2, y2, ...] array, or null.
      static float[] parseFloatList​(java.lang.String csv, int expectedLength)
      Parses a comma-separated list of floats (the shape of rect, coords, start/end, fringe, callout, ...) into an array, or returns null if it's blank, malformed, or (when expectedLength > 0) not exactly that many values.
      void setAttribute​(java.lang.String name, java.lang.String value)
      Sets (or, with a null value, removes) one raw XFDF attribute directly -- what the typed setters below all funnel through.
      void setContents​(java.lang.String contents)
      Sets the plain-text <contents> body -- see getContents().
      void setContentsRichText​(java.lang.String contentsRichText)
      Sets the raw <contents-richtext> inner XML -- see getContentsRichText().
      void setDefaultAppearance​(java.lang.String defaultAppearance)
      Sets the raw <defaultappearance> text -- see getDefaultAppearance().
      void setInkList​(java.util.List<float[]> inkList)
      Replaces the whole ink gesture list -- see getInkList(); prefer addGesture(float[]) to append one stroke at a time.
      void setName​(java.lang.String name)
      Sets the name attribute -- see getName().
      void setPage​(int page)
      Sets the zero-based page attribute -- see getPage().
      void setPopup​(XfdfAnnotation popup)
      Sets the nested <popup> child -- see getPopup().
      void setQuadPoints​(float[] quadPoints)
      Sets the quad points list -- see getQuadPoints().
      void setRect​(float[] rect)
      Sets the rect attribute from [llx, lly, urx, ury] -- see getRect().
      void setVertices​(float[] vertices)
      Sets the Polygon/Polyline vertex list -- see getVertices().
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • XfdfAnnotation

        public XfdfAnnotation​(java.lang.String type)
        Parameters:
        type - the lower-case XFDF element name, e.g. "square", "freetext", "popup"
    • Method Detail

      • getType

        public java.lang.String getType()
        The lower-case XFDF element name, e.g. "square", "freetext", "popup".
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        Every XFDF attribute this annotation carries (raw attribute name, e.g. "interior-color", to its raw string value).
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String name)
        The raw string value of attribute name, or null if this annotation doesn't carry it.
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.String value)
        Sets (or, with a null value, removes) one raw XFDF attribute directly -- what the typed setters below all funnel through.
      • getName

        public java.lang.String getName()
        The name attribute -- the annotation's PDF /NM unique identifier.
      • setName

        public void setName​(java.lang.String name)
        Sets the name attribute -- see getName().
      • getPage

        public int getPage()
        Zero-based page index (the page attribute), or -1 if absent/unparseable.
      • setPage

        public void setPage​(int page)
        Sets the zero-based page attribute -- see getPage().
      • getRect

        public float[] getRect()
        The rect attribute as [llx, lly, urx, ury], or null if absent/unparseable.
      • setRect

        public void setRect​(float[] rect)
        Sets the rect attribute from [llx, lly, urx, ury] -- see getRect().
      • getContents

        public java.lang.String getContents()
        Plain-text <contents> body, or null.
      • setContents

        public void setContents​(java.lang.String contents)
        Sets the plain-text <contents> body -- see getContents().
      • getContentsRichText

        public java.lang.String getContentsRichText()
        Raw inner XML of <contents-richtext> (the /RC rich text string), or null.
      • setContentsRichText

        public void setContentsRichText​(java.lang.String contentsRichText)
        Sets the raw <contents-richtext> inner XML -- see getContentsRichText().
      • getDefaultAppearance

        public java.lang.String getDefaultAppearance()
        Raw <defaultappearance> text (the /DA string), or null.
      • setDefaultAppearance

        public void setDefaultAppearance​(java.lang.String defaultAppearance)
        Sets the raw <defaultappearance> text -- see getDefaultAppearance().
      • getVertices

        public float[] getVertices()
        Polygon/Polyline <vertices> as a flat [x1, y1, x2, y2, ...] array, or null.
      • setVertices

        public void setVertices​(float[] vertices)
        Sets the Polygon/Polyline vertex list -- see getVertices().
      • getQuadPoints

        public float[] getQuadPoints()
        Highlight/Underline/Squiggly/StrikeOut/Redact/Link quad points, flat 8-per-quad, or null.
      • setQuadPoints

        public void setQuadPoints​(float[] quadPoints)
        Sets the quad points list -- see getQuadPoints().
      • getInkList

        public java.util.List<float[]> getInkList()
        Ink <inklist>: one flat [x1, y1, x2, y2, ...] array per <gesture> stroke, or null.
      • setInkList

        public void setInkList​(java.util.List<float[]> inkList)
        Replaces the whole ink gesture list -- see getInkList(); prefer addGesture(float[]) to append one stroke at a time.
      • addGesture

        public void addGesture​(float[] points)
        Appends one <gesture> stroke (a flat [x1, y1, x2, y2, ...] point list) to the ink list, creating it if this is the first.
      • getPopup

        public XfdfAnnotation getPopup()
        The nested <popup> child, if this annotation has its own popup window, or null.
      • parseFloatList

        public static float[] parseFloatList​(java.lang.String csv,
                                             int expectedLength)
        Parses a comma-separated list of floats (the shape of rect, coords, start/end, fringe, callout, ...) into an array, or returns null if it's blank, malformed, or (when expectedLength > 0) not exactly that many values.
        Parameters:
        expectedLength - the required element count, or <= 0 to accept any length
      • formatFloatList

        public static java.lang.String formatFloatList​(float[] values,
                                                       java.lang.String separator)
        The inverse of parseFloatList(String, int): joins values with separator, or returns null if values is null.
      • formatFloat

        public static java.lang.String formatFloat​(float value)
        Trims a clean integer-valued float down to "100" rather than "100.0", matching real producers' output.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object