Class FieldRef

java.lang.Object
org.docx4j.model.fields.FieldRef

public class FieldRef extends Object
The objective of this class is to represent a complex field (containing nested fields, if any; nested fields are represented by FieldRef object of their own). TODO, consider whether to make this abstract, with differing concrete implementations for top level and nested fields. Background. There are simple fields: <w:fldSimple w:instr=" DATE "> <w:r> <w:rPr> <w:noProof/> </w:rPr> <w:instrText>4/12/2011</w:instrText> </w:r> </w:fldSimple> and there are complex fields: <w:p> <w:r> <w:fldChar w:fldCharType="begin"/> </w:r> <w:r> <w:instrText xml:space="preserve"> REF hi \h </w:instrText> </w:r> <w:r> <w:fldChar w:fldCharType="separate"/> </w:r> <w:r> <w:t>Hello</w:t> </w:r> </w:p> A simple field can also take the complex form: <w:r> <w:fldChar w:fldCharType="begin"/> <w:instrText xml:space="preserve">DATE </w:instrText> <w:fldChar w:fldCharType="separate"/> </w:r> <w:r> <w:t>4/12/2011</w:t> </w:r> <w:r> <w:fldChar w:fldCharType="end"/> </w:r> A complex field can contain nested fields, in either its instruction part, or result part. we need to represent nest fields in the instructions part only (since nested fields in the results part get re-generated). An example of a nested field in the instructions part: <w:p> <w:r> <w:fldChar w:fldCharType="begin"/> </w:r> <w:r> <w:instrText xml:space="preserve"> IF </w:instrText> </w:r> <w:fldSimple w:instr=" DATE "> <w:r> <w:rPr> <w:noProof/> </w:rPr> <w:instrText>4/12/2011</w:instrText> </w:r> </w:fldSimple> <w:r> <w:instrText xml:space="preserve">="4/12/2011" "it is 4/12" "not 4/12" </w:instrText> </w:r> <w:r> <w:fldChar w:fldCharType="separate"/> </w:r> <w:r> <w:rPr> <w:noProof/> </w:rPr> <w:t>today</w:t> </w:r> <w:r> <w:fldChar w:fldCharType="end"/> </w:r> </w:p> An example of nested fields in the results part: <w:p w:rsidR="00BA0732" w:rsidRDefault="00BA0732"> <w:pPr> <w:pStyle w:val="TOC1"/> <w:tabs> <w:tab w:val="right" w:leader="dot" w:pos="9016"/> </w:tabs> <w:rPr> <w:noProof/> </w:rPr> </w:pPr> <w:r> <w:fldChar w:fldCharType="begin"/> </w:r> <w:r> <w:instrText xml:space="preserve"> TOC \o "1-3" \h \z \ u</w:instrText> </w:r> <w:r> <w:fldChar w:fldCharType="separate"/> </w:r> <w:hyperlink w:anchor="_Toc310757867" w:history="1"> <w:r w:rsidRPr="0061726E"> <w:rPr> <w:rStyle w:val="Hyperlink"/> <w:noProof/> </w:rPr> <w:t>one</w:t> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:tab/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="begin"/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:instrText xml:space="preserve"> PAGEREF _Toc310757867 \h </w:instrText> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="separate"/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:t>1</w:t> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="end"/> </w:r> </w:hyperlink> </w:p> <w:p w:rsidR="00BA0732" w:rsidRDefault="00BA0732"> <w:pPr> <w:pStyle w:val="TOC2"/> <w:tabs> <w:tab w:val="right" w:leader="dot" w:pos="9016"/> </w:tabs> <w:rPr> <w:noProof/> </w:rPr> </w:pPr> <w:hyperlink w:anchor="_Toc310757868" w:history="1"> <w:r w:rsidRPr="0061726E"> <w:rPr> <w:rStyle w:val="Hyperlink"/> <w:noProof/> </w:rPr> <w:t>oneone</w:t> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:tab/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="begin"/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:instrText xml:space="preserve"> PAGEREF _Toc310757868 \h </w:instrText> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="separate"/> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:t>1</w:t> </w:r> <w:r> <w:rPr> <w:noProof/> <w:webHidden/> </w:rPr> <w:fldChar w:fldCharType="end"/> </w:r> </w:hyperlink> </w:p> <w:p w:rsidR="00BA0732" w:rsidRDefault="00BA0732" w:rsidP="00BA0732"> <w:r> <w:fldChar w:fldCharType="end"/> </w:r> </w:p> In general, you can "canonicalise" the field representation to be (i) instructions, contained within a single run (ii) results, immediately following, though not nec just as following siblings (iii) the final <w:fldChar w:fldCharType="end"/> Since the purpose of our field support is to update the field results, we can delete (ii) and (iii) before adding them in again. The document is preprocessed to put it into this form.
  • Field Details

    • log

      private static org.slf4j.Logger log
    • fldCharBegin

      private FldChar fldCharBegin
    • fldName

      protected String fldName
    • parent

      private ContentAccessor parent
    • beginRun

      private R beginRun
      The run <w:r> <w:fldChar w:fldCharType="begin"/> <w:instrText xml:space="preserve"> ... </w:instrText> <w:fldChar w:fldCharType="separate"/> </w:r>
    • seenSeparate

      private boolean seenSeparate
    • mergeFormat

      private Boolean mergeFormat
    • dirty

      private boolean dirty
    • lock

      private boolean lock
    • customFieldData

      private Text customFieldData
    • formFieldProperties

      private CTFFData formFieldProperties
    • endRun

      private R endRun
      The run <w:r> <w:fldChar w:fldCharType="end"/> </w:r> Store a reference to it so we can delete it.
    • instructions

      private List<Object> instructions
      A list of the content between the outermost w:fldChar begin and separate elements; in the simplest case, this will be a single w:instrText object; in a more general case it will be a mixture of w:instrText and FieldRef objects (and possibly other things such as w:br).
    • resultsSlot

      private R resultsSlot
  • Constructor Details

    • FieldRef

      public FieldRef(FldChar fldCharBegin)
  • Method Details

    • getFldName

      public String getFldName()
      The name of the (outer most) field, for example DATE, MERGEFIELD. Assume for now that this is contained in instructions.get(0).
      Returns:
      See Also:
    • getParent

      public ContentAccessor getParent()
    • setParent

      public void setParent(ContentAccessor parent)
    • getBeginRun

      public R getBeginRun()
    • setBeginRun

      public void setBeginRun(R beginRun)
    • haveSeenSeparate

      public boolean haveSeenSeparate()
    • setSeenSeparate

      public void setSeenSeparate(boolean seenSeparate)
    • processFldBegin

      private void processFldBegin()
    • isMergeFormat

      public Boolean isMergeFormat()
      Returns:
      whether \* MERGEFORMAT is set
    • isDirty

      public boolean isDirty()
      Specifies that this field has been flagged by an application to indicate that its current results are invalid (stale) due to other modifications made to the document, and these contents should be updated before they are displayed.
      Returns:
      whether stale
      See Also:
    • setDirty

      public void setDirty(boolean dirty)
      Parameters:
      whether - stale
      See Also:
    • isLock

      public boolean isLock()
      Returns:
      the lock
      See Also:
    • setLock

      public void setLock(boolean lock)
      Specifies that the parent complex field shall not have its field result recalculated, even if an application attempts to recalculate the results of all fields in the document or a recalculation is explicitly requested.
      Parameters:
      lock - the lock to set
      See Also:
    • getCustomFieldData

      public Text getCustomFieldData()
      application-specific data associated with this field.
      Returns:
      the customFieldData
      See Also:
    • setCustomFieldData

      public void setCustomFieldData(Text customFieldData)
      Parameters:
      customFieldData - the customFieldData to set
      See Also:
    • getFormFieldProperties

      public CTFFData getFormFieldProperties()
      Properties specific to FORMCHECKBOX, FORMDROPDOWN, FORMTEXT
      Returns:
      the formFieldProperties
      See Also:
    • setFormFieldProperties

      public void setFormFieldProperties(CTFFData formFieldProperties)
      Parameters:
      formFieldProperties - the formFieldProperties to set
      See Also:
    • getEndRun

      public R getEndRun()
    • setEndRun

      public void setEndRun(R endRun)
    • getInstructions

      public List<Object> getInstructions()
      Returns:
      the instructions
    • getResultsSlot

      public R getResultsSlot()
    • setResultsSlot

      public void setResultsSlot(R resultsSlot)
    • setResult

      public void setResult(String val)