001package com.hfg.xml.msofficexml.docx.wordprocessingml;
002
003
004import com.hfg.xml.msofficexml.OfficeXML;
005import com.hfg.xml.msofficexml.docx.Docx;
006import com.hfg.xml.msofficexml.docx.RelationshipXML;
007import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
008import com.hfg.xml.msofficexml.docx.part.FooterPart;
009import com.hfg.xml.msofficexml.docx.wordprocessingml.field.WmlSimpleField;
010
011//------------------------------------------------------------------------------
012/**
013 Represents an Office Open XML footer (<w:ftr>) tag.
014
015 @author J. Alex Taylor, hairyfatguy.com
016 */
017//------------------------------------------------------------------------------
018// com.hfg XML/HTML Coding Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class WmlFooter extends WmlContentContainer
039{
040   //###########################################################################
041   // CONSTRUCTORS
042   //###########################################################################
043
044   //---------------------------------------------------------------------------
045   public WmlFooter(Docx inDocx)
046   {
047      super(WmlXML.FOOTER, inDocx);
048      // Word is sensitive to the namespace prefixes being used.
049      // To ensure that tags are prefixed, we pre-define the namespace.
050      addXMLNamespaceDeclaration(WmlXML.WORDPROCESSINGML_NAMESPACE);
051
052      addXMLNamespaceDeclaration(RelationshipXML.RELATIONSHIP_NAMESPACE);
053      addXMLNamespaceDeclaration(OfficeXML.OFFICE_NAMESPACE);
054      addXMLNamespaceDeclaration(WmlXML.WORDPROCESSING_DRAWING_NAMESPACE);
055      addXMLNamespaceDeclaration(DmlXML.DRAWINGML_NAMESPACE);
056      addXMLNamespaceDeclaration(DmlXML.PIC_NAMESPACE);
057
058      setPart(new FooterPart(inDocx, this));
059   }
060
061
062   //###########################################################################
063   // PUBLIC METHODS
064   //###########################################################################
065
066   //---------------------------------------------------------------------------
067   @Override
068   public FooterPart getPart()
069   {
070      return (FooterPart) super.getPart();
071   }
072
073   //---------------------------------------------------------------------------
074   /**
075    Calls generatePage_X_of_Y() and then adds it to the footer.
076    */
077   public WmlParagraph addPage_X_of_Y()
078   {
079      WmlParagraph p = generatePage_X_of_Y();
080      addSubtag(p);
081
082      return p;
083   }
084
085   //---------------------------------------------------------------------------
086   /*
087   <w:p>
088     <w:pPr><w:pBdr><w:top w:val="single" w:sz="4" w:space="1" w:color="auto"/></w:pBdr></w:pPr>
089     <w:r><w:t xml:space="preserve">Page </w:t></w:r>
090     <w:fldSimple w:instr=" PAGE "><w:r><w:rPr><w:noProof/></w:rPr><w:t>1</w:t></w:r></w:fldSimple>
091     <w:r><w:t xml:space="preserve"> of </w:t></w:r>
092     <w:fldSimple w:instr=" NUMPAGES "><w:r><w:rPr><w:noProof/></w:rPr><w:t>1</w:t></w:r></w:fldSimple>
093   </w:p>
094    */
095   public WmlParagraph generatePage_X_of_Y()
096   {
097      WmlParagraph p = new WmlParagraph(getParentDoc());
098
099      p.addTextRun("Page ");
100
101      WmlSimpleField simpleField = new WmlSimpleField(getParentDoc())
102            .setInstruction(" PAGE ");
103
104      WmlTextRun run = new WmlTextRun(getParentDoc()).addText("1");
105      run.getProperties().disableSpellingAndGrammarChecks();
106      simpleField.addSubtag(run);
107      p.addSubtag(simpleField);
108
109      p.addTextRun(" of ");
110
111      simpleField = new WmlSimpleField(getParentDoc())
112            .setInstruction(" NUMPAGES ");
113
114      run = new WmlTextRun(getParentDoc()).addText("1");
115      run.getProperties().disableSpellingAndGrammarChecks();
116      simpleField.addSubtag(run);
117      p.addSubtag(simpleField);
118
119      return p;
120   }
121
122   //---------------------------------------------------------------------------
123   public WmlParagraph addParagraph()
124   {
125      WmlParagraph p = new WmlParagraph(getParentDoc());
126      addSubtag(p);
127
128      return p;
129   }
130
131   //---------------------------------------------------------------------------
132   public WmlParagraph addParagraph(String inContent)
133   {
134      WmlParagraph p = addParagraph();
135      p.addTextRun().addText(inContent);
136
137      return p;
138   }
139
140   //---------------------------------------------------------------------------
141   public WmlTable addTable()
142   {
143      WmlTable table = new WmlTable(getParentDoc());
144      addSubtag(table);
145
146      return table;
147   }
148
149}