package com.maxprograms.reportloader; import java.io.*; import javax.xml.parsers.*; import org.apache.serialize.*; import org.w3c.dom.*; import java.net.URL; import java.sql.*; /** * Insert the type's description here. * Creation date: (26/11/2000 17:56:33) * @author: Administrator */ public class ReportLoader { // SQL related variables private static java.lang.String url; private static java.lang.String driver; private static java.lang.String username; private static java.lang.String password; private static java.lang.String statement; // page releted variables private static Float pageWidth; private static Float pageHeight; private static Float headerHeight; private static Float detailHeight; private static Float footerHeight; private static Integer maxLines; /** * Starts the application. * @param args an array of command-line arguments */ public static void main(java.lang.String[] args) { if (args.length != 1) { System.out.println("Usage: java com.maxprograms.reportloader.ReportLoader [XML Report]"); System.exit(-1); } String reportFileName = args[0]; try { FileInputStream file = new FileInputStream(reportFileName); DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); dFactory.setValidating( true ); DocumentBuilder docBuilder = dFactory.newDocumentBuilder(); Document doc = docBuilder.parse( file ); Element root = doc.getDocumentElement(); // get page size from the document NodeList nl = root.getElementsByTagName("Page"); Element pg = (Element)nl.item(0); pageWidth = new Float( pg.getAttribute("Width") ); pageHeight = new Float( pg.getAttribute("Height") ); // read SQL related stuff from the document NodeList nl2 = root.getElementsByTagName("SQLStatement"); Element sql = (Element)nl2.item(0); driver = sql.getAttribute("Driver"); url = sql.getAttribute("URL"); statement = sql.getAttribute("Statement"); username = sql.getAttribute("Username"); password = sql.getAttribute("Password"); sql = null; nl2 = null; } catch ( java.io.FileNotFoundException e ) { System.out.println("Error: XML Report " + reportFileName + " not found."); } catch ( javax.xml.parsers.ParserConfigurationException e ) { System.out.println("Error instantiating parser class."); } catch ( org.xml.sax.SAXException e ) { System.out.println("Error parsing the document."); } catch ( java.io.IOException e ) { System.out.println("Error reading document."); } catch ( Exception e ) { e.printStackTrace(); } try { Class.forName ( driver ); DriverManager.setLogStream(System.out); Connection con = DriverManager.getConnection( url, username, password ); DatabaseMetaData dma = con.getMetaData (); System.out.println("\nConnected to " + dma.getURL()); System.out.println("Driver " + dma.getDriverName()); System.out.println("Version " + dma.getDriverVersion()); System.out.println(""); Statement stmt = con.createStatement (); ResultSet rs = stmt.executeQuery ( statement ); // Display all columns and rows from the result set // dispResultSet (rs); rs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.out.println ("\n*** SQLException caught ***\n"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } } catch (java.lang.Exception ex) { ex.printStackTrace (); } } /** * Insert the method's description here. * Creation date: (26/11/2000 21:58:23) * @param n org.w3c.dom.Node */ public static void recurseNodes( Element n) { System.out.println( n.getNodeName() ); NodeList list = n.getChildNodes(); int count = list.getLength(); for (int i = 0; i < count; i++){ recurseNodes( (Element)list.item(i) ); } } }