com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlHeaderFooter 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.xlsx.spreadsheetml;
import com.hfg.util.StringUtil;
import com.hfg.xml.msofficexml.xlsx.Xlsx;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML worksheet's header and footer (<ssml:headerFooter>) tag.
@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]
//------------------------------------------------------------------------------
// Ex:
//
// string
// string
// string
// string
// string
// string
//
public class SsmlHeaderFooter extends SsmlXMLTag
{
private SsmlXMLTag mOddHeaderTag;
private SsmlXMLTag mOddFooterTag;
//---------------------------------------------------------------------------
public SsmlHeaderFooter(Xlsx inXlsx)
{
super(SsmlXML.HEADER_FOOTER, inXlsx);
init();
}
//---------------------------------------------------------------------------
private void init()
{
}
//---------------------------------------------------------------------------
// Defaults to false
public SsmlHeaderFooter setDifferentOddEven(Boolean inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.DIFFERENT_ODD_EVEN_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.DIFFERENT_ODD_EVEN_ATT);
}
return this;
}
//---------------------------------------------------------------------------
// Defaults to false
public SsmlHeaderFooter setDifferentFirst(Boolean inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.DIFFERENT_FIRST_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.DIFFERENT_FIRST_ATT);
}
return this;
}
//---------------------------------------------------------------------------
// Defaults to true
public SsmlHeaderFooter setScaleWithDoc(Boolean inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.SCALE_WITH_DOC_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.SCALE_WITH_DOC_ATT);
}
return this;
}
//---------------------------------------------------------------------------
// Defaults to true
public SsmlHeaderFooter setAlignWithMargins(Boolean inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.ALIGN_WITH_MARGINS_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.ALIGN_WITH_MARGINS_ATT);
}
return this;
}
//---------------------------------------------------------------------------
// '&L' precedes the left header, '&C' precedes the center header, and '&R' precedes the right header
public SsmlHeaderFooter setHeader(String inValue)
{
SsmlXMLTag oddHeaderTag = null;
if (StringUtil.isSet(inValue))
{
oddHeaderTag = new SsmlXMLTag(SsmlXML.ODD_HEADER, getParentDoc());
oddHeaderTag.setContent(inValue);
}
setOddHeaderTag(oddHeaderTag);
setDifferentOddEven(null);
return this;
}
//---------------------------------------------------------------------------
public String getHeader()
{
SsmlXMLTag oddHeaderTag = getOddHeaderTag();
return (oddHeaderTag != null ? oddHeaderTag.getUnescapedContent() : null);
}
//---------------------------------------------------------------------------
// '&P' codes for the current page number
// '&N' codes for the number of pages
// '&L' precedes the left footer, '&C' precedes the center footer, and '&R' precedes the right footer
public SsmlHeaderFooter setFooter(String inValue)
{
SsmlXMLTag oddFooterTag = null;
if (StringUtil.isSet(inValue))
{
oddFooterTag = new SsmlXMLTag(SsmlXML.ODD_FOOTER, getParentDoc());
oddFooterTag.setContent(inValue);
}
setOddFooterTag(oddFooterTag);
setDifferentOddEven(null);
return this;
}
//---------------------------------------------------------------------------
public String getFooter()
{
SsmlXMLTag oddFooterTag = getOddFooterTag();
return (oddFooterTag != null ? oddFooterTag.getUnescapedContent() : null);
}
//###########################################################################
// PRIVATE METHODS
//###########################################################################
//---------------------------------------------------------------------------
private void setOddHeaderTag(SsmlXMLTag inTag)
{
// Remove the previous tag
SsmlXMLTag oddHeaderTag = getOddHeaderTag();
if (oddHeaderTag != null)
{
removeSubtag(oddHeaderTag);
}
if (inTag != null)
{
addSubtag(inTag);
}
mOddHeaderTag = inTag;
}
//---------------------------------------------------------------------------
private SsmlXMLTag getOddHeaderTag()
{
if (null == mOddHeaderTag)
{
// Check it it has been added via addSubtag()...
mOddHeaderTag = getOptionalSubtagByName(SsmlXML.ODD_HEADER);
}
return mOddHeaderTag;
}
//---------------------------------------------------------------------------
private void setOddFooterTag(SsmlXMLTag inTag)
{
// Remove the previous tag
SsmlXMLTag oddFooterTag = getOddFooterTag();
if (oddFooterTag != null)
{
removeSubtag(oddFooterTag);
}
if (inTag != null)
{
addSubtag(inTag);
}
mOddFooterTag = inTag;
}
//---------------------------------------------------------------------------
private SsmlXMLTag getOddFooterTag()
{
if (null == mOddFooterTag)
{
// Check it it has been added via addSubtag()...
mOddFooterTag = getOptionalSubtagByName(SsmlXML.ODD_FOOTER);
}
return mOddFooterTag;
}
}