File: TestCalc.java

package info (click to toggle)
libbsf-java 1%3A2.3.0%2Bcvs20050308a-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,460 kB
  • ctags: 1,264
  • sloc: java: 7,643; cpp: 2,514; xml: 1,773; jsp: 463; ansic: 182; makefile: 61; python: 45; sh: 29
file content (61 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import org.apache.bsf.*;
import org.apache.bsf.util.*;

public class TestCalc extends Frame {

  static final protected Hashtable extensionmap= new Hashtable();
  static
  {
    extensionmap.put("pl", "perlscript");
    extensionmap.put("vbs", "vbscript");
    extensionmap.put("js", "jscript");
  }
  static final String languageFromExtension( String s) throws Exception
  {
    int dot= s.lastIndexOf('.');
    if(dot != -1) s= s.substring( dot+1);
    String lang= (String) extensionmap.get(s);
    if(null == lang) throw new BSFException(BSFException.REASON_OTHER_ERROR, "File extension " + s + " unknown language!"); 
 
    return lang; 
    
  }

  public TestCalc (String fileName) throws Exception {
    BSFManager manager = new BSFManager ();
    manager.declareBean("frame", this, this.getClass());
    try
    {
     manager.exec(manager.getLangFromFilename(fileName), fileName, 0, 0, 
                 IOUtils.getStringFromReader(new FileReader(fileName)));
    }catch(BSFException e )
    {
     
     System.out.println("exception: " + e.getMessage());
     Throwable oe= e.getTargetException();
     if(null != oe) System.out.println("\nOriginal Exception:"+ oe.getMessage());
              e.printStackTrace();

    }
  }

  public static void main (String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Missing file name");
      System.exit(1);
    }

    Frame f = new TestCalc(args[0]);
    f.show();

    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    } );
  }

}