File: TableFiller.java

package info (click to toggle)
libbsf-java 1%3A2.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 3,028 kB
  • ctags: 2,480
  • sloc: java: 5,373; xml: 226; ansic: 182; python: 57; makefile: 18
file content (56 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download | duplicates (4)
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
/**
 * This is an example of using an XSL script to fill in a Java
 * table with data obtained from an XML file.
 */

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import org.apache.bsf.*;
import org.apache.bsf.util.IOUtils;

public class TableFiller {
  public static void main (String[] args) throws Exception {
    if (args.length != 2) {
      System.err.println ("Usage: java TableFiller xslfilename xmlfilename");
      System.exit (0);
    }
    String xslfilename = args[0];
    String xmlfilename = args[1];

    Frame frame = new Frame ("Table Filler");
    frame.addWindowListener (new WindowAdapter () {
      public void windowClosing (WindowEvent e) {
	System.exit (0);
      }
    });
    Panel panel = new Panel (new GridLayout (-1, 2));
    Font f = new Font ("SansSerif", Font.BOLD, 14);
    Label l = new Label ("First");
    l.setFont (f);
    panel.add (l);
    l = new Label ("Last");
    l.setFont (f);
    panel.add (l);
    frame.add ("Center", panel);

    BSFManager mgr = new BSFManager ();

    // make the panel available for playing in XSL
    mgr.declareBean ("panel", panel, panel.getClass ());

    // tell lotusxsl what the input xml file is
    mgr.registerBean ("xslt:src", new FileReader (xmlfilename));

    // load and run the xsl file to fill in the table. Note that we're
    // running the xsl script for its side effect of filling in the table
    // and so we don't care what the resulting document is.
    mgr.exec ("xslt", xslfilename, 0, 0,
	      IOUtils.getStringFromReader (new FileReader (xslfilename)));

    // display the frame
    frame.pack ();
    // frame.show(); // javac 1.5 warns to use f.show(), Apache build scripts abort as a result :(
    frame.setVisible(true);     // available since Java 1.1
  }
}