word.w2004.elements.AbstractHeading Maven / Gradle / Ivy
The newest version!
package word.w2004.elements;
import word.api.interfaces.IElement;
import word.api.interfaces.IFluentElementStylable;
import word.w2004.style.HeadingStyle;
/**
* @author leonardo
* @param
* Heading is utilized to organize documents the same way you do for web pages.
* You can use Heading1 to 3.
*/
public abstract class AbstractHeading implements IElement, IFluentElementStylable{
/**
* this is actual heading1, heading2 or heading3.
*/
private String headingType;
private String value; //value/text for the Heading
protected AbstractHeading(String headingType, String value){
this.headingType = headingType;
this.value = value;
}
private String template =
"\n"
+"\n "
+"\n "
+"\n {styleAlign}"
+"\n "
+"\n "
+"\n {styleText}"
+"\n {value} "
+"\n "
+"\n ";
private HeadingStyle style = new HeadingStyle();
@Override
public String getContent() {
if("".equals(this.value)){
return "";
}
//For convention, it should be the last thing before returning the xml content.
String txt = style.getNewContentWithStyle(getTemplate());
return txt.replace("{value}", this.value);
}
// #### Getters and setters ####
public String getTemplate() {
return this.template.replace("{heading}", this.headingType);
}
//Implements the stylable and the heading classes reuse it
@Override
@SuppressWarnings("unchecked")
public E withStyle() {
this.style.setElement(this); //, Heading1.class
return (E) this.style;
}
}