1 /*** 2 * ExpressionShell.java 3 * 4 * $Author: mballesteros $ 5 * $Date: 2003/11/28 19:18:03 $ 6 * $Revision: 1.1 $ 7 */ 8 package net.sf.jec; 9 10 import java.io.BufferedReader; 11 import java.io.InputStreamReader; 12 import java.util.HashMap; 13 14 import javax.xml.parsers.DocumentBuilder; 15 import javax.xml.parsers.DocumentBuilderFactory; 16 17 import org.w3c.dom.Document; 18 import org.w3c.dom.Element; 19 20 /*** 21 * 22 * @author mballesteros 23 */ 24 public class ExpressionShell { 25 26 public static void main(String[] args) { 27 try { 28 System.out.println("------------------------------------------------"); 29 System.out.println(" ExpressionShell"); 30 System.out.println("------------------------------------------------"); 31 32 DocumentBuilderFactory nonValidatingFactory = DocumentBuilderFactory.newInstance(); 33 DocumentBuilder docBuilder = nonValidatingFactory.newDocumentBuilder(); 34 Document doc = docBuilder.newDocument(); 35 Element el; 36 el = doc.createElement("root"); 37 doc.appendChild(el); 38 el.appendChild(doc.createElement("book")); 39 el.appendChild(doc.createElement("person")); 40 el.appendChild(doc.createElement("person")); 41 42 43 HashMap h = new HashMap(); 44 h.put("book", Book.getExample()); 45 h.put("ebook", ExtendedBook.getExtendedExample()); 46 h.put("intIndex", "0"); 47 h.put("strIndex", "1"); 48 h.put("value1", "100,01 EUR"); 49 h.put("value2", "100 EUR"); 50 h.put("value3", "100,01"); 51 h.put("value4", "100"); 52 h.put("now", new java.util.Date()); 53 h.put("root", el); 54 55 56 System.out.println("Context: "+h); 57 System.out.println("------------------------------------------------"); 58 59 ExpressionEval exprEval = ExpressionEval.getDefaultInstance(false); 60 61 62 //================================================================= 63 // Tests 64 //================================================================= 65 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 66 boolean debug = false; 67 boolean keep = true; 68 Operator op; 69 Operator.showFunctionString = true; 70 String line; 71 while (keep) { 72 try { 73 line = br.readLine(); 74 if (line.equals("exit") || line.equals("quit")) { 75 System.out.println("\n\nExiting... bye!"); 76 keep = false; 77 } else { 78 if (line.equals("debug")) debug = !debug; 79 System.out.println("> "+line); 80 System.out.println( exprEval.get(h, line) ); 81 } 82 } catch (Exception e) { 83 System.out.flush(); 84 e.printStackTrace(); 85 } 86 } 87 } catch (Exception ex) { 88 System.out.flush(); 89 ex.printStackTrace(); 90 } 91 } 92 }

This page was automatically generated by Maven