info.bliki.wiki.template.If Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bliki-core Show documentation
Show all versions of bliki-core Show documentation
This is the core project.
The newest version!
package info.bliki.wiki.template;
import info.bliki.wiki.model.Configuration;
import info.bliki.wiki.model.IWikiModel;
import java.util.List;
/**
* A template parser function for {{ #if: ... }}
syntax. See Mediwiki's
* Help:Extension:ParserFunctions
*
*/
public class If extends AbstractTemplateFunction {
public final static ITemplateFunction CONST = new If();
@Override
public String parseFunction(List list, IWikiModel model, char[] src, int beginIndex, int endIndex, boolean isSubst) {
if (list.size() > 1) {
String ifCondition = "";
try {
ifCondition = isSubst ? list.get(0) : parseTrim(list.get(0), model);
if (ifCondition.length() > 0) {
// <then text>
return isSubst ? list.get(1) : parseTrim(list.get(1), model);
} else {
if (list.size() >= 3) {
// <else text>
return isSubst ? list.get(2) : parseTrim(list.get(2), model);
}
}
} catch (Exception e) {
if (Configuration.DEBUG) {
System.out.println("#if error: " + ifCondition);
}
if (Configuration.STACKTRACE) {
e.printStackTrace();
}
return "Expression error: " + e.getMessage() + "";
}
}
return null;
}
}