/Users/lyon/j4p/src/xml/adbk/Main.java

1    package xml.adbk; 
2     
3    import futils.Futil; 
4    import org.xml.sax.SAXException; 
5    import org.xml.sax.SAXParseException; 
6     
7    import javax.xml.parsers.ParserConfigurationException; 
8    import java.io.File; 
9    import java.io.IOException; 
10    
11   import xml.Utils; 
12    
13   /** 
14    * Created by User: lyon Date: Jan 3, 2004 Time: 
15    * 10:58:16 AM 
16    */ 
17   public class Main { 
18       public static void main(String[] args) { 
19           try { 
20               testXmlReader(); 
21           } catch (SAXException e) { 
22               e.printStackTrace(); 
23           } catch (ParserConfigurationException e) { 
24               e.printStackTrace(); 
25           } catch (IOException e) { 
26               e.printStackTrace(); 
27           } 
28       } 
29       public static void main2(String argv []) 
30               throws IOException { 
31           try { 
32    
33               testXmlGenerator(); 
34    
35           } catch (SAXParseException e) { 
36               System.out.println("** Parsing error" 
37                                  + ", line " + 
38                                  e.getLineNumber() 
39                                  + ", uri " + e.getSystemId() 
40                                  + "   " + e.getMessage()); 
41    
42           } catch (SAXException e) { 
43               e.printStackTrace(); 
44           } catch (ParserConfigurationException e) { 
45               e.printStackTrace(); 
46           } 
47       } 
48    
49       private static void testXmlGenerator() 
50               throws SAXException, 
51                      ParserConfigurationException, 
52                      IOException { 
53           AddressBook ab = testXmlReader(); 
54           //System.out.println("AB (xml)=" + ab.toXml()); 
55           AddressBook ab2 = ab.search("yan"); 
56           ab.merge(ab2); 
57    
58           System.out.println( 
59                   "html=" + ab.toHtmlCsv()); 
60           gui.html.HtmlViewer hv = 
61                   new gui.html.HtmlViewer(); 
62           //hv.setHtml(ab.toHtmlCsv()); 
63           hv.setPlainText(ab.toXml()); 
64           Utils.writeXml(ab); 
65           //ab.saveAsXml( 
66           //        new File("c:\\lyon\\doug.xml")); 
67       } 
68    
69       private static AddressBook testXmlReader() throws SAXException, ParserConfigurationException, IOException { 
70           AddressBook ab = Xml2Address.read( 
71                   "file:" + 
72                   Futil.getReadFile( 
73                           "select an XML file") 
74                   .getAbsolutePath()); 
75           System.out.println( 
76                   "AB (csv)=" + ab.toCsv()); 
77           return ab; 
78       } 
79   } 
80