com.floreysoft.jmte.token.ElseToken Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmte Show documentation
Show all versions of jmte Show documentation
To build and locally install jar, javadoc and sources, please use:
mvn clean javadoc:jar source:jar install -Dmaven.test.skip=true
Tested on Maven 2.0.9, JDK 1.7
package com.floreysoft.jmte.token;
import com.floreysoft.jmte.TemplateContext;
public class ElseToken extends AbstractToken {
public static final String ELSE = "else";
protected IfToken ifToken = null;
@Override
public String getText() {
if (text == null) {
text = ELSE + getIfToken() != null ? "(" + getIfToken().getText()
+ ")" : "";
}
return text;
}
@Override
public Object evaluate(TemplateContext context) {
Boolean evaluated = !(Boolean) getIfToken().evaluate(context);
return evaluated;
}
public void setIfToken(IfToken ifToken) {
this.ifToken = ifToken;
}
public IfToken getIfToken() {
if (ifToken == null) {
throw new IllegalStateException(
"An else token can only be evaluated using an associated if token - which is missing");
}
return ifToken;
}
@Override
public String emit() {
return ELSE;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy