Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/tripi/asp/OutputNode.java


1   /**
2    * ArrowHead ASP Server 
3    * This is a source file for the ArrowHead ASP Server - an 100% Java
4    * VBScript interpreter and ASP server.
5    *
6    * For more information, see http://www.tripi.com/arrowhead
7    *
8    * Copyright (C) 2002  Terence Haddock
9    *
10   * This program is free software; you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation; either version 2 of the License, or
13   * (at your option) any later version.
14   *
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   *
20   * You should have received a copy of the GNU General Public License
21   * along with this program; if not, write to the Free Software
22   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23   *
24   */
25  package com.tripi.asp;
26  
27  import java.io.IOException;
28  
29  /**
30   * OutputNode handles the ASP notation <%= value %> to directly output 
31   * an expression's value.
32   * @author Terence Haddock
33   * @version 0.9
34   */
35  public class OutputNode extends DefaultNode
36  {
37      /** Expression to output */
38      Node expr;
39  
40      /** Debugging context, location of output node in asp code. */
41      DebugContext dbgCtx;
42  
43      /**
44       * Constructor.
45       * @param expr Expression to output.
46       * @param dbgCtx Context of expression in ASP file.
47       */
48      public OutputNode(Object expr, DebugContext dbgCtx)
49      {
50          this.expr = (Node)expr;
51      }
52  
53      /**
54       * Dumps the representation of this node.
55       * @throws AspException in case of error
56       * @see Node#dump
57       */
58      public void dump() throws AspException
59      {
60          System.out.print("<%=");
61          expr.dump();
62          System.out.print("%>");
63      }
64  
65      /**
66       * Executes this output node.
67       * @param context AspContext under which to execute this node.
68       * @return return value, for this node always null
69       * @throws AspException in case of error
70       * @see Node#execute
71       */
72      public Object execute(AspContext context) throws AspException
73      {
74          final IdentNode respIdent = new IdentNode("response");
75          try {
76              Object obj = expr.execute(context);
77              String str = Types.coerceToString(obj);
78              JavaObjectNode respObj = (JavaObjectNode)context.getValue(respIdent);
79              Response resp = (Response)respObj.getSubObject();
80              resp.Write(str);
81          } catch (IOException ex) {
82              throw new AspNestedException(ex, dbgCtx);
83          } catch (AspException ex) {
84              if (!ex.hasContext()) {
85                  ex.setContext(dbgCtx);
86              }
87              throw ex;
88          }
89          return null;
90      }
91  };
92