| 1 6 7 package com.quikj.application.utilities.form; 8 9 import com.quikj.client.beans.*; 10 import java.awt.*; 11 import java.io.*; 12 import net.n3.nanoxml.*; 13 14 18 public class TestXML 19 { 20 21 22 public TestXML() 23 { 24 } 25 26 29 public static void main(String [] args) 30 { 31 Frame frame = new Frame("XML Form Tester"); 32 String path = null; 33 34 if (args.length == 0) 35 { 36 FileDialog fd = new FileDialog(frame, "Select XML form", 37 FileDialog.LOAD); 38 fd.show(); 39 40 String file = fd.getFile(); 41 if (file == null) 42 { 43 new InformationDialog (frame, "Argument Error", 44 "File name has not been specified", 45 true); 46 System.exit(1); 47 } 48 49 String dir = fd.getDirectory(); 50 51 if (dir.endsWith(File.separator) == true) 52 { 53 path = dir + file; 54 } 55 else 56 { 57 path = dir + File.separator + file; 58 } 59 } 60 else 61 { 62 path = args[0]; 63 } 64 65 try 66 { 67 IXMLParser test_parser = XMLParserFactory.createDefaultXMLParser(); 68 IXMLReader test_reader = StdXMLReader.fileReader(path); 69 test_parser.setReader(test_reader); 70 IXMLElement root_element = (IXMLElement)test_parser.parse(); 71 72 if (root_element.getName().equals("xml-form-req") == false) 73 { 74 new InformationDialog(frame, "XML error!", 75 "Node xml-form-req does not found", 76 true); 77 System.exit(1); 78 } 79 80 String form_string = root_element.getContent(); 81 if (form_string == null) 82 { 83 new InformationDialog(frame, "XML error!", 84 "Node xml-form-req does not have a body", 85 true); 86 System.exit(1); 87 } 88 89 XMLFormUser form_user = new XMLFormUser(); 90 IXMLParser form_parser = XMLParserFactory.createDefaultXMLParser(); 91 IXMLReader form_reader = StdXMLReader.stringReader(form_string); 92 form_parser.setReader(form_reader); 93 IXMLElement form_element = (IXMLElement)form_parser.parse(); 94 95 XMLForm test_form = new XMLForm(form_element, form_user, form_element, null, null); 96 } 97 catch (FileNotFoundException exc) 98 { 99 new InformationDialog(frame, "File not found!", 100 "Can't find input file:" + exc, 101 true); 102 System.exit(1); 103 } 104 catch (IOException exc) 105 { 106 new InformationDialog(frame, "IO Error", 107 "Can't open input file:" + exc, 108 true); 109 System.exit(1); 110 } 111 catch (Exception ex) 112 { 113 new InformationDialog(frame, "Exception", 114 ex.getClass().getName() + ": " + ex.getMessage(), 115 true); 116 System.exit(1); 117 } 118 catch (Error ex) 119 { 120 new InformationDialog(frame, "Exception", 121 ex.getClass().getName() + ": " + ex.getMessage(), 122 true); 123 System.exit(1); 124 } 125 } 126 } 127 | Popular Tags |