package contrib; /** * @author Phill Perryman * * This is a simple demo program to test out the features * of the extended jdom classes. * */ import java.io.StringReader; import org.jdom.output.XMLOutputter; public class Testerx { public static void main(String[] args) { // create a simple xml string String xml = ""; // create a string reader StringReader sr = new StringReader(xml); // create a factory that will return the extended classes JDOMFactoryx factory = new JDOMFactoryx(); // now create a builder and assign the factory to it SAXBuilderx esb = new SAXBuilderx(); esb.setFactory(factory); // parse in the test document Documentx doc = null; try { // parse in the test document doc = (Documentx) esb.build(sr); } catch (Exception e) { e.printStackTrace(); }; // now print it to standard out XMLOutputter outputter = new XMLOutputter(); try { outputter.setTextNormalize(true); outputter.setNewlines(true); outputter.output(doc, System.out); } catch (Exception e) { e.printStackTrace(); }; // test the subclassing of the root Elementx root = doc.getRootElementx(); System.out.println(root.getName()); // test setting and getting an int attribute Elementx child = (Elementx) root.getChild("child"); child.setInt("int",42); System.out.println(child.getInt("int")+""); //test the int with default //print the element to make sure it is not there child.setInt("default",61,61); System.out.println(child.getInt("default", 57)+""); try { outputter.output(child, System.out); } catch (Exception e) { e.printStackTrace(); }; System.out.println(); //test the boolean child.setBoolean("bool",true); System.out.println(child.getBoolean("bool")); //test the boolean with default //print the element to make sure it is not there child.setBoolean("default",false,false); System.out.println(child.getBoolean("default")); System.out.println(child.getBoolean("default", true)); try { outputter.output(child, System.out); } catch (Exception e) { e.printStackTrace(); } // try the Chooser Chooser ch = new Chooser(root); root.setDescriptor(new IdElementDescriptor()); Elementx e = ch.messagebox(null, "title", "message"); System.out.println(e); } }