org.kefirsf.bb.TemplateElementFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kefirbb Show documentation
Show all versions of kefirbb Show documentation
KefirBB is a Java-library for text processing. Initially it was developed for BB2HTML translation.
But flexible configuration allows to use it in different cases. For example for parsing Markdown, Textile,
and for HTML filtration.
The newest version!
package org.kefirsf.bb;
import org.kefirsf.bb.conf.Constant;
import org.kefirsf.bb.conf.If;
import org.kefirsf.bb.conf.NamedValue;
import org.kefirsf.bb.conf.TemplateElement;
import org.kefirsf.bb.proc.IfExpression;
import org.kefirsf.bb.proc.ProcNamedValue;
import org.kefirsf.bb.proc.ProcTemplateElement;
import org.kefirsf.bb.proc.TemplateConstant;
import java.util.ArrayList;
import java.util.List;
class TemplateElementFactory {
public TemplateElementFactory() {
}
List createTemplateList(List extends TemplateElement> templateElements) {
List elements = new ArrayList();
for (TemplateElement element : templateElements) {
elements.add(create(element));
}
return elements;
}
private ProcTemplateElement create(TemplateElement element) {
if (element instanceof Constant) {
return new TemplateConstant(((Constant) element).getValue());
} else if (element instanceof NamedValue) {
NamedValue el = (NamedValue) element;
return new ProcNamedValue(el.getName(), el.getFunction());
} else if (element instanceof If) {
return createIf((If) element);
} else {
throw new TextProcessorFactoryException("Unknown template element " + element.getClass().getName() + ".");
}
}
private ProcTemplateElement createIf(If element) {
return new IfExpression(element.getName(), createTemplateList(element.getElements()));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy