com.hfg.xml.msofficexml.docx.wordprocessingml.WmlParagraphProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
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 mContextualSpacingTag;
private XMLTag mTabsTag;
private XMLTag mOutlineLevelTag;
private WmlParagraphBorder mBorderTag;
private WmlTextRunProperties mRunProperties;
private WmlSectionProperties mSectionProperties;
private WmlNumberingProperties mNumberingProperties;
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//---------------------------------------------------------------------------
public WmlParagraphProperties(Docx inDocx)
{
super(WmlXML.PARAGRAPH_PROPS, inDocx);
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//---------------------------------------------------------------------------
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 WmlParagraphProperties setOutlineLevel(Integer inValue)
{
if (null == inValue)
{
mOutlineLevelTag = null;
removeSubtagsByName(WmlXML.OUTLINE_LEVEL);
}
else
{
if (null == mOutlineLevelTag)
{
// Check it it has been added via addSubtag()...
mOutlineLevelTag = getOptionalSubtagByName(WmlXML.OUTLINE_LEVEL);
if (null == mOutlineLevelTag)
{
mOutlineLevelTag = new XMLTag(WmlXML.OUTLINE_LEVEL);
addSubtag(mOutlineLevelTag);
}
}
mOutlineLevelTag.setAttribute(WmlXML.VALUE, inValue);
}
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 that this paragraph should use contextual spacing.
*/
public WmlParagraphProperties setContextualSpacing(boolean inValue)
{
if (inValue)
{
if (null == mContextualSpacingTag)
{
// Check it it has been added via addSubtag()...
mContextualSpacingTag = getOptionalSubtagByName(WmlXML.CONTEXTUAL_SPACING);
if (null == mContextualSpacingTag)
{
mContextualSpacingTag = new XMLTag(WmlXML.CONTEXTUAL_SPACING);
addSubtag(mContextualSpacingTag);
}
}
}
else
{
removeSubtagsByName(WmlXML.CONTEXTUAL_SPACING);
mContextualSpacingTag = null;
}
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 numbering properties tag if one exists or else instantiates a new one.
* @return the numbering properties for this table
*/
public WmlNumberingProperties getNumberingProperties()
{
if (null == mNumberingProperties)
{
// Check it it has been added via addSubtag()...
mNumberingProperties = getOptionalSubtagByName(WmlXML.NUMBERING_PROPERTIES);
if (null == mNumberingProperties)
{
mNumberingProperties = new WmlNumberingProperties(getParentDoc());
addSubtag(mNumberingProperties);
}
}
return mNumberingProperties;
}
//---------------------------------------------------------------------------
/**
* 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;
}
}