Class DocxContextImpl<T>

    • Field Detail

      • myPackage

        protected final org.docx4j.openpackaging.packages.WordprocessingMLPackage myPackage
      • myDocumentPart

        protected final org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart myDocumentPart
      • myFactory

        protected final org.docx4j.wml.ObjectFactory myFactory
      • myDocxHelper

        protected final DocxHelper myDocxHelper
      • myHyperlinks

        protected final java.util.HashMap<org.docx4j.openpackaging.parts.relationships.RelationshipsPart,​java.util.HashMap<java.lang.String,​org.docx4j.relationships.Relationship>> myHyperlinks
      • myBlockFormatProviders

        protected java.util.HashMap<T,​BlockFormatProvider<T>> myBlockFormatProviders
      • myRunFormatProviders

        protected java.util.HashMap<T,​RunFormatProvider<T>> myRunFormatProviders
      • myFootnoteRef

        protected int myFootnoteRef
      • myBookmarkID

        protected java.util.concurrent.atomic.AtomicInteger myBookmarkID
    • Constructor Detail

      • DocxContextImpl

        public DocxContextImpl​(org.docx4j.openpackaging.packages.WordprocessingMLPackage out,
                               DataHolder options)
    • Method Detail

      • setParent

        public void setParent​(DocxContext<?> parent)
      • getProviderFrame

        public T getProviderFrame()
        Description copied from interface: FormatProvider
        get the node for this formatting block
        Specified by:
        getProviderFrame in interface FormatProvider<T>
        Returns:
        node for this format provider
      • addContentElement

        public void addContentElement​(java.lang.Object element)
        Description copied from interface: ContentContainer
        Add element to content

        May not be added at the end of content but inserted into the content list

        Specified by:
        addContentElement in interface ContentContainer
        Parameters:
        element - element to add
      • open

        public void open()
        Description copied from interface: FormatProvider
        initialize internal stuff based on the parent for future use optionally add elements to doc before main elements any P creates will call the getPPr(), getParaRPr() and addP() for this provider so don't create elements until you are ready to handle these calls
        Specified by:
        open in interface FormatProvider<T>
      • close

        public void close()
        Description copied from interface: FormatProvider
        finalize, add elements to the document after main part as needed after this method returns no more calls will be made to this provider
        Specified by:
        close in interface FormatProvider<T>
      • getStyleId

        public java.lang.String getStyleId()
        Description copied from interface: FormatProvider
        these are the hard-coded styles on which this block is based used for reference purposes by children to figure out what they need to combine
        Specified by:
        getStyleId in interface FormatProvider<T>
        Returns:
        style id
      • addP

        public void addP​(org.docx4j.wml.P p)
        Description copied from interface: ParaContainer
        add a new P. Don't change anything about it, just add it to its proper container
        Specified by:
        addP in interface ParaContainer
        Parameters:
        p - to be added to its parent container
      • addR

        public void addR​(org.docx4j.wml.R r)
        Description copied from interface: RunContainer
        add a new R. Don't change anything about it, just add it to its proper container
        Specified by:
        addR in interface RunContainer
        Parameters:
        r - to be added to its parent container
      • getLastP

        public org.docx4j.wml.P getLastP()
        Description copied from interface: ParaContainer
        Get the last P of the container or null if there is none
        Specified by:
        getLastP in interface ParaContainer
        Returns:
        last P or none
      • getLastR

        public org.docx4j.wml.R getLastR()
        Description copied from interface: RunContainer
        Get the last R of the container or null if there is none
        Specified by:
        getLastR in interface RunContainer
        Returns:
        last R or none
      • createPStyle

        public org.docx4j.wml.PPrBase.PStyle createPStyle​(java.lang.String style)
        Specified by:
        createPStyle in interface DocxContext<T>
      • createP

        public org.docx4j.wml.P createP()
        Description copied from interface: DocxContext
        Get a new P element for the current block
        Specified by:
        createP in interface DocxContext<T>
        Returns:
        current P element or null if none is open
      • createP

        public org.docx4j.wml.P createP​(java.lang.String style)
        Specified by:
        createP in interface DocxContext<T>
      • getP

        public org.docx4j.wml.P getP()
        Description copied from interface: DocxContext
        Get the last P element for the current block
        Specified by:
        getP in interface DocxContext<T>
        Returns:
        current P element or null if none is open
      • createR

        public org.docx4j.wml.R createR()
        Description copied from interface: DocxContext
        Create R element, with an RPr and add it to current P element
        Specified by:
        createR in interface DocxContext<T>
        Returns:
        R element
      • getR

        public org.docx4j.wml.R getR()
        Description copied from interface: DocxContext
        Get last R element of current P or create a new one
        Specified by:
        getR in interface DocxContext<T>
        Returns:
        R element
      • getRPr

        public org.docx4j.wml.RPr getRPr()
        Specified by:
        getRPr in interface DocxContext<T>
      • getBooleanDefaultTrue

        public org.docx4j.wml.BooleanDefaultTrue getBooleanDefaultTrue​(boolean value)
        Specified by:
        getBooleanDefaultTrue in interface DocxContext<T>
      • getCTShd

        public org.docx4j.wml.CTShd getCTShd()
        Description copied from interface: DocxContext
        Get CTShd from current R or create rPr if none and CTShd if none
        Specified by:
        getCTShd in interface DocxContext<T>
        Returns:
        CTShd
      • getNextBookmarkId

        public int getNextBookmarkId()
        Description copied from interface: DocxContext
        Increment the last id and return the id
        Specified by:
        getNextBookmarkId in interface DocxContext<T>
        Returns:
        next bookmark id
      • getBookmarkIdAtomic

        public java.util.concurrent.atomic.AtomicInteger getBookmarkIdAtomic()
        Description copied from interface: DocxContext
        get the atomic integer used to generate bookmark ids
        Specified by:
        getBookmarkIdAtomic in interface DocxContext<T>
        Returns:
        the id atomic integer
      • createBookmarkStart

        public org.docx4j.wml.CTBookmark createBookmarkStart​(java.lang.String bookmarkName,
                                                             boolean isBlockBookmark)
        Insert bookmark start into current P
        Specified by:
        createBookmarkStart in interface DocxContext<T>
        Parameters:
        bookmarkName - name of the bookmark (optional), if not given the it will be BM_{id}
        isBlockBookmark - true if block bookmark
        Returns:
        CTBookmark
      • createBookmarkEnd

        public org.docx4j.wml.CTMarkupRange createBookmarkEnd​(org.docx4j.wml.CTBookmark bookmarkStart,
                                                              boolean isBlockBookmark)
        Description copied from interface: DocxContext
        Insert bookmark end into current P for given bookmark
        Specified by:
        createBookmarkEnd in interface DocxContext<T>
        Parameters:
        bookmarkStart - starting bookmark to close
        isBlockBookmark - true if block bookmark
        Returns:
        CTMarkupRange
      • createBookmarkHyperlink

        public org.docx4j.wml.P.Hyperlink createBookmarkHyperlink​(java.lang.String bookmarkName,
                                                                  java.lang.String linkText)
        Description copied from interface: DocxContext
        Get a hyperlink to a bookmark in the document
        Specified by:
        createBookmarkHyperlink in interface DocxContext<T>
        Parameters:
        bookmarkName - name of the bookmark to link to
        linkText - text of the link
        Returns:
        hyperlink
      • getFactory

        public org.docx4j.wml.ObjectFactory getFactory()
        Description copied from interface: DocxContext
        Get the wml object factory
        Specified by:
        getFactory in interface DocxContext<T>
        Returns:
        object factory
      • addBlankLine

        public void addBlankLine​(int size,
                                 java.lang.String styleId)
        Specified by:
        addBlankLine in interface DocxContext<T>
      • addBlankLine

        public void addBlankLine​(long size,
                                 java.lang.String styleId)
        Specified by:
        addBlankLine in interface DocxContext<T>
      • addBlankLine

        public void addBlankLine​(java.math.BigInteger size,
                                 java.lang.String styleId)
        Specified by:
        addBlankLine in interface DocxContext<T>
      • addText

        public org.docx4j.wml.Text addText​(java.lang.String value,
                                           boolean noProofRPr,
                                           boolean createR)
        Description copied from interface: DocxContext
        Create and add wrapped Text element to R element set value and optionally space preserve if value starts or ends in a space
        Specified by:
        addText in interface DocxContext<T>
        Parameters:
        value - value to set
        noProofRPr - if true will add rPr with noProof tag to R
        createR - if true then create a new R, otherwise add to existing one
        Returns:
        Text element
      • addInstrText

        public org.docx4j.wml.Text addInstrText​(java.lang.String value,
                                                boolean noProofRPr,
                                                boolean createR)
        Description copied from interface: DocxContext
        Create and add wrapped Text element to R element as RInstrText set value and optionally space preserve if value starts or ends in a space
        Specified by:
        addInstrText in interface DocxContext<T>
        Parameters:
        value - instrText Value
        noProofRPr - if true will add rPr with noProof #BooleanDefaultTrue
        createR - if true then create a new R, otherwise add to existing one
        Returns:
        Text element
      • addFldChar

        public org.docx4j.wml.FldChar addFldChar​(org.docx4j.wml.STFldCharType charType,
                                                 boolean createR)
        Description copied from interface: DocxContext
        Create and add wrapped Text element to R element as RInstrText
        Specified by:
        addFldChar in interface DocxContext<T>
        Parameters:
        charType - char type to set
        createR - if true then create a new R, otherwise add to existing one
        Returns:
        FldChar element
      • addLineBreak

        public void addLineBreak()
        Description copied from interface: DocxContext
        Add a line break to current R
        Specified by:
        addLineBreak in interface DocxContext<T>
      • contextFramed

        public void contextFramed​(java.lang.Runnable runnable)
        Description copied from interface: DocxContext
        Run within a context, after run the format providers and containers will be restored.

        Use when you need to create a container or format provider but only for a part of the node rendering process.

        Specified by:
        contextFramed in interface DocxContext<T>
        Parameters:
        runnable - code to run
      • addBreak

        public void addBreak​(org.docx4j.wml.STBrType breakType)
        Specified by:
        addBreak in interface DocxContext<T>
      • addBold

        public org.docx4j.wml.RPr addBold()
        Specified by:
        addBold in interface DocxContext<T>
      • createHpsMeasure

        public org.docx4j.wml.HpsMeasure createHpsMeasure​(long val)
        Specified by:
        createHpsMeasure in interface DocxContext<T>
      • createHorizontalLine

        public void createHorizontalLine()
      • getPackage

        public org.docx4j.openpackaging.packages.WordprocessingMLPackage getPackage()
        Specified by:
        getPackage in interface DocxContext<T>
        Returns:
        the Wordprocessing package
      • getDocxDocument

        public org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart getDocxDocument()
        Specified by:
        getDocxDocument in interface DocxContext<T>
        Returns:
        the main document
      • getStyle

        public org.docx4j.wml.Style getStyle​(java.lang.String styleName)
        Description copied from interface: DocxContext
        Get a paragraph style of given name
        Specified by:
        getStyle in interface DocxContext<T>
        Parameters:
        styleName - name of the style
        Returns:
        style
      • getRelationshipsPart

        public org.docx4j.openpackaging.parts.relationships.RelationshipsPart getRelationshipsPart()
        Description copied from interface: ContentContainer
        Get the containers relationship. Needed for footnotes that contain links and probably images
        Specified by:
        getRelationshipsPart in interface ContentContainer
        Returns:
        relationship part for the container.
      • getHyperlinkRelationship

        public org.docx4j.relationships.Relationship getHyperlinkRelationship​(java.lang.String url)
        Description copied from interface: DocxContext
        Get an external hyperlink relationship for the given url
        Specified by:
        getHyperlinkRelationship in interface DocxContext<T>
        Parameters:
        url - url
        Returns:
        relationship
      • renderFencedCodeLines

        public void renderFencedCodeLines​(java.util.List<? extends java.lang.CharSequence> lines)
        Specified by:
        renderFencedCodeLines in interface DocxContext<T>
      • getFootnotesPart

        public org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart getFootnotesPart()
                                                                                       throws org.docx4j.openpackaging.exceptions.Docx4JException
        Description copied from interface: DocxContext
        Get or create FootnotesPart for the document
        Specified by:
        getFootnotesPart in interface DocxContext<T>
        Returns:
        footnotes part
        Throws:
        org.docx4j.openpackaging.exceptions.Docx4JException - if cannot create part
      • addFootnote

        public org.docx4j.wml.CTFtnEdn addFootnote​(java.math.BigInteger footnoteID)
                                            throws org.docx4j.openpackaging.exceptions.Docx4JException
        Description copied from interface: DocxContext
        Add footnote and return it
        Specified by:
        addFootnote in interface DocxContext<T>
        Parameters:
        footnoteID - re-use footnote id or 0 if new footnote
        Returns:
        footnote element
        Throws:
        org.docx4j.openpackaging.exceptions.Docx4JException - thrown if cannot get or create footnotes part of the document