enjoy 3.3 release ^_^
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
|
||||
package com.jfinal.template.stat.ast;
|
||||
|
||||
import java.io.Writer;
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.TemplateException;
|
||||
import com.jfinal.template.expr.ast.Expr;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.Location;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
@@ -34,21 +35,41 @@ import com.jfinal.template.stat.Scope;
|
||||
*/
|
||||
public class Output extends Stat {
|
||||
|
||||
private ExprList exprList;
|
||||
private Expr expr;
|
||||
|
||||
public Output(ExprList exprList, Location location) {
|
||||
if (exprList.length() == 0) {
|
||||
throw new ParseException("The expression of output directive like #(expression) can not be blank", location);
|
||||
}
|
||||
this.exprList = exprList;
|
||||
this.expr = exprList.getActualExpr();
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
try {
|
||||
Object value = exprList.eval(scope);
|
||||
if (value != null) {
|
||||
String str = value.toString();
|
||||
Object value = expr.eval(scope);
|
||||
|
||||
if (value instanceof String) {
|
||||
String str = (String)value;
|
||||
writer.write(str, 0, str.length());
|
||||
} else if (value instanceof Number) {
|
||||
Class<?> c = value.getClass();
|
||||
if (c == Integer.class) {
|
||||
writer.write((Integer)value);
|
||||
} else if (c == Long.class) {
|
||||
writer.write((Long)value);
|
||||
} else if (c == Double.class) {
|
||||
writer.write((Double)value);
|
||||
} else if (c == Float.class) {
|
||||
writer.write((Float)value);
|
||||
} else if (c == Short.class) {
|
||||
writer.write((Short)value);
|
||||
} else {
|
||||
writer.write(value.toString());
|
||||
}
|
||||
} else if (value instanceof Boolean) {
|
||||
writer.write((Boolean)value);
|
||||
} else if (value != null) {
|
||||
writer.write(value.toString());
|
||||
}
|
||||
} catch(TemplateException e) {
|
||||
throw e;
|
||||
|
Reference in New Issue
Block a user