1 package com.piratepete.util; 2 3 import java.io.File ; 4 import java.io.FileWriter ; 5 import org.jdom.Comment; 6 import org.jdom.Document; 7 import org.jdom.Element; 8 import org.jdom.output.XMLOutputter; 9 10 36 public class DefaultDBConfig 37 { 38 static Document xmldoc; 39 static Element xmlroot; 40 static String sfile = ""; 41 42 48 public static void main(String [] args) 49 { 50 sfile = args[0]; 51 52 createXMLDoc(); 53 addDatabases(); 54 writeXMLDoc(); 55 } 56 57 59 public static void createXMLDoc() 60 { 61 xmldoc = new Document(); 62 Comment nchg = new Comment("Example Database Configuratin File"); 63 xmldoc.addContent(nchg); 64 xmlroot = new Element("databases"); 65 xmldoc.setRootElement(xmlroot); 66 } 67 68 71 public static void addDatabases() 72 { 73 Comment mysqlc = new Comment("MySQL Database Configuration"); 74 Comment oraclec = new Comment("Oracle Database Configuration"); 75 Comment postgresqlc = new Comment("PostgreSQL Database Configuration"); 76 77 Element name = new Element("name"); 78 Element classpath = new Element("classpath"); 79 Element url = new Element("url"); 80 Element database; 81 82 xmlroot.addContent(mysqlc); 84 database = new Element("database"); 85 name = new Element("name").addContent("MySQL"); 86 classpath = new Element("classpath").addContent("com.mysql.jdbc.Driver"); 87 url = new Element("url").addContent("jdbc:mysql://#host#/#sid#?user=#user#^password=#pass#"); 88 database.addContent(name); 89 database.addContent(classpath); 90 database.addContent(url); 91 xmlroot.addContent(database); 92 93 xmlroot.addContent(oraclec); 95 database = new Element("database"); 96 name = new Element("name").addContent("Oracle"); 97 classpath = new Element("classpath").addContent("oracle.jdbc.OracleDriver"); 98 url = new Element("url").addContent("jdbc:oracle:thin@#host#:1521:#sid#:#user#:#pass#"); 99 database.addContent(name); 100 database.addContent(classpath); 101 database.addContent(url); 102 xmlroot.addContent(database); 103 104 xmlroot.addContent(postgresqlc); 106 database = new Element("database"); 107 name = new Element("name").addContent("PostgreSQL"); 108 classpath = new Element("classpath").addContent("org.postgresql.Driver"); 109 url = new Element("url").addContent("jdbc:postgresql://#host#/#sid#?user=#user#^password=#pass#"); 110 database.addContent(name); 111 database.addContent(classpath); 112 database.addContent(url); 113 xmlroot.addContent(database); 114 } 115 116 118 public static void writeXMLDoc() 119 { 120 File nconf = new File (sfile); 121 122 try 123 { 124 XMLOutputter outputter = new XMLOutputter(" ", true); 125 FileWriter writer = new FileWriter (nconf); 126 127 outputter.output(xmldoc, writer); 128 writer.close(); 130 } 131 catch (java.io.IOException e) 132 { 133 e.printStackTrace(); 134 } 135 } 136 } 137 | Popular Tags |