01: /* XelNode.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Sat Sep 17 15:47:54 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2004 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.web.servlet.dsp.impl;
20:
21: import java.io.Writer;
22: import java.io.IOException;
23:
24: import org.zkoss.xel.Expression;
25: import org.zkoss.xel.ExpressionFactory;
26: import org.zkoss.xel.FunctionMapper;
27: import org.zkoss.xel.XelException;
28: import org.zkoss.util.logging.Log;
29: import org.zkoss.web.servlet.ServletException;
30:
31: /**
32: * Represents an expression.
33: *
34: * @author tomyeh
35: * @since 3.0.0
36: */
37: class XelNode extends Node {
38: private static final Log log = Log.lookup(XelNode.class);
39: private final Expression _expr;
40:
41: XelNode(String expr, ParseContext ctx) throws XelException {
42: _expr = ctx.getExpressionFactory().parseExpression(ctx, expr,
43: String.class);
44: }
45:
46: //-- super --//
47: void interpret(InterpretContext ic)
48: throws javax.servlet.ServletException, IOException {
49: try {
50: final String result = (String) _expr.evaluate(ic.xelc);
51: if (result != null)
52: ic.dc.getOut().write(result);
53: } catch (XelException ex) {
54: //we have to log since Tomcat 'eats' the real cause
55: log.realCause(ex);
56: throw new ServletException(
57: "Unable to evaluate an EL expression: " + _expr, ex);
58: }
59: }
60:
61: void addChild(Node node) {
62: throw new IllegalStateException("No child allowed");
63: }
64:
65: public String toString() {
66: return "EL[" + _expr + ']';
67: }
68: }
|