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.
Author:
jharrop
  • Field Details

    • fldName

      protected String fldName
  • 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)
    • 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)