All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.docx.wordprocessingml.WmlParagraphProperties Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.docx.wordprocessingml;


import java.util.List;

import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.docx.Docx;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlIndentation;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlJustification;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlParagraphBorder;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlShading;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlSpacing;

//------------------------------------------------------------------------------
/**
 Represents an Office Open XML paragraph properties (<w:pPr>) tag.
 
From Ecma Office Open XML Part 1 - 17.3.1.26 pPr (Paragraph Properties):
"This element specifies a set of paragraph properties which shall be applied to the contents of the parent paragraph after all style/numbering/table properties have been applied to the text. These properties are defined as direct formatting, since they are directly applied to the paragraph and supersede any formatting from styles."
@author J. Alex Taylor, hairyfatguy.com */ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class WmlParagraphProperties extends WmlXMLTag { private XMLTag mStyle; private XMLTag mJustificationTag; private WmlIndentation mIndentationTag; private WmlSpacing mSpacingTag; private WmlShading mShadingTag; private XMLTag mKeepLinesTag; private XMLTag mKeepNextTag; private XMLTag mPageBreakBeforeTag; private XMLTag mTabsTag; private WmlParagraphBorder mBorderTag; private WmlTextRunProperties mRunProperties; private WmlSectionProperties mSectionProperties; //--------------------------------------------------------------------------- public WmlParagraphProperties(Docx inDocx) { super(WmlXML.PARAGRAPH_PROPS, inDocx); } //--------------------------------------------------------------------------- public WmlParagraphProperties setStyle(String inStyleId) { if (null == mStyle) { mStyle = new XMLTag(WmlXML.PARAGRAPH_STYLE); addSubtag(mStyle); } mStyle.setAttribute(WmlXML.VALUE_ATT, inStyleId); return this; } //--------------------------------------------------------------------------- public WmlParagraphBorder getBorders() { if (null == mBorderTag) { // Check it it has been added via addSubtag()... mBorderTag = getOptionalSubtagByName(WmlXML.PARAGRAPH_BORDER); if (null == mBorderTag) { mBorderTag = new WmlParagraphBorder(getParentDoc()); addSubtag(mBorderTag); } } return mBorderTag; } //--------------------------------------------------------------------------- public WmlShading getShading() { if (null == mShadingTag) { // Check it it has been added via addSubtag()... mShadingTag = getOptionalSubtagByName(WmlXML.SHADING); if (null == mShadingTag) { mShadingTag = new WmlShading(); addSubtag(mShadingTag); } } return mShadingTag; } //--------------------------------------------------------------------------- public WmlSpacing getSpacing() { if (null == mSpacingTag) { // Check it it has been added via addSubtag()... mSpacingTag = getOptionalSubtagByName(WmlXML.SPACING); if (null == mSpacingTag) { mSpacingTag = new WmlSpacing(); addSubtag(mSpacingTag); } } return mSpacingTag; } //--------------------------------------------------------------------------- public WmlIndentation getIndentation() { if (null == mIndentationTag) { // Check it it has been added via addSubtag()... mIndentationTag = getOptionalSubtagByName(WmlXML.INDENTATION); if (null == mIndentationTag) { mIndentationTag = new WmlIndentation(); addSubtag(mIndentationTag); } } return mIndentationTag; } //--------------------------------------------------------------------------- public WmlParagraphProperties setJustification(WmlJustification inValue) { if (null == mJustificationTag) { // Check it it has been added via addSubtag()... mJustificationTag = getOptionalSubtagByName(WmlXML.JUSTIFICATION); if (null == mJustificationTag) { mJustificationTag = new XMLTag(WmlXML.JUSTIFICATION); addSubtag(mJustificationTag); } } mJustificationTag.setAttribute(WmlXML.VALUE_ATT, inValue); return this; } //--------------------------------------------------------------------------- /** * Specifies that this paragraph should not be separated by a page break from the one that follows it. */ public WmlParagraphProperties setKeepNext() { if (null == mKeepNextTag) { // Check it it has been added via addSubtag()... mKeepNextTag = getOptionalSubtagByName(WmlXML.KEEP_NEXT); if (null == mKeepNextTag) { mKeepNextTag = new XMLTag(WmlXML.KEEP_NEXT); addSubtag(mKeepNextTag); } } return this; } //--------------------------------------------------------------------------- /** * Specifies that this paragraph's lines should be kept on one page. */ public WmlParagraphProperties setKeepLines() { if (null == mKeepLinesTag) { // Check it it has been added via addSubtag()... mKeepLinesTag = getOptionalSubtagByName(WmlXML.KEEP_LINES); if (null == mKeepLinesTag) { mKeepLinesTag = new XMLTag(WmlXML.KEEP_LINES); addSubtag(mKeepLinesTag); } } return this; } //--------------------------------------------------------------------------- /** * Specifies whether or not this paragraph should be preceded by a page break. */ public WmlParagraphProperties setPageBreakBefore(boolean inValue) { if (null == mPageBreakBeforeTag) { // Check it it has been added via addSubtag()... mPageBreakBeforeTag = getOptionalSubtagByName(WmlXML.PAGE_BREAK_BEFORE); if (null == mPageBreakBeforeTag) { mPageBreakBeforeTag = new XMLTag(WmlXML.PAGE_BREAK_BEFORE); addSubtag(mPageBreakBeforeTag); } } mPageBreakBeforeTag.setAttribute(WmlXML.VALUE_ATT, inValue ? "true" : "false"); return this; } //--------------------------------------------------------------------------- /** * Returns the section properties tag if one exists or else instantiates a new one. * @return the section properties for this table */ public WmlSectionProperties getSectionProperties() { if (null == mSectionProperties) { // Check it it has been added via addSubtag()... mSectionProperties = getOptionalSubtagByName(WmlXML.SECT_PROPS); if (null == mSectionProperties) { mSectionProperties = new WmlSectionProperties(getParentDoc()); addSubtag(0, mSectionProperties); } } return mSectionProperties; } //--------------------------------------------------------------------------- /** * Returns the run properties tag if one exists or else instantiates a new one. * @return the run properties for this table */ public WmlTextRunProperties getRunProperties() { if (null == mRunProperties) { // Check it it has been added via addSubtag()... mRunProperties = getOptionalSubtagByName(WmlXML.RUN_PROPS); if (null == mRunProperties) { mRunProperties = new WmlTextRunProperties(getParentDoc()); addSubtag(mRunProperties); } } return mRunProperties; } //--------------------------------------------------------------------------- /** Adds a tab stop definition. */ public WmlParagraphProperties addTab(WmlTab inValue) { if (null == mTabsTag) { // Check it it has been added via addSubtag()... mTabsTag = getOptionalSubtagByName(WmlXML.TABS); if (null == mTabsTag) { mTabsTag = new XMLTag(WmlXML.TABS); addSubtag(mTabsTag); } } mTabsTag.addSubtag(inValue); return this; } //--------------------------------------------------------------------------- /** Adds a tab stop definition. */ public List getTabs() { List tabTags = null; if (null == mTabsTag) { // Check it it has been added via addSubtag()... mTabsTag = getOptionalSubtagByName(WmlXML.TABS); } if (mTabsTag != null) { tabTags = mTabsTag.getSubtagsByName(WmlXML.TAB); } return tabTags; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy