All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.floreysoft.jmte.token.ElseToken Maven / Gradle / Ivy

Go to download

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

There is a newer version: 7.0.3
Show newest version
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