Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.console.wizard.XmlWizard Class Reference

Collaboration diagram for org.objectweb.cjdbc.console.wizard.XmlWizard:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XmlWizard (String xmlFile) throws DocumentException, IOException
 XmlWizard ()
void actionPerformed (ActionEvent e)
void loadDocument (String xmlFile) throws DocumentException, IOException
void saveDocument (String xmlFile) throws IOException
void validateDocument (String xmlFile) throws IOException
void exportDocument (String xmlFile) throws IOException

Static Public Member Functions

void main (String[] args)

Detailed Description

This is the main class for the XmlWizard.

Author:
Nicolas Modrzyk
Version:
1.0

Definition at line 62 of file XmlWizard.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.console.wizard.XmlWizard.XmlWizard String  xmlFile  )  throws DocumentException, IOException
 

Creates a new XmlWizard object. The wizard will edit an already existing file

Parameters:
xmlFile XML file name
Exceptions:
IOException if the file cannot be read
DocumentException if the xml document cannot be parsed

Definition at line 77 of file XmlWizard.java.

References org.objectweb.cjdbc.console.wizard.XmlWizard.loadDocument().

00078   {
00079     this();
00080     loadDocument(xmlFile);
00081   }

org.objectweb.cjdbc.console.wizard.XmlWizard.XmlWizard  ) 
 

Creates a new XmlWizard object The wizard will create a new document from scratch

See also:
javax.swing.JFileChooser#accept(java.io.File)

Definition at line 87 of file XmlWizard.java.

Referenced by org.objectweb.cjdbc.console.wizard.XmlWizard.main().

00088   {
00089     // basic define
00090     super(WizardTranslate.get("init.title.main.frame"));
00091     chooser = new JFileChooser()
00092     {
00093       /**
00094        * @see javax.swing.JFileChooser#accept(java.io.File)
00095        */
00096       public boolean accept(File f)
00097       {
00098         if (f.isDirectory())
00099           return true;
00100         if (f.getName().endsWith(".xml"))
00101           return true;
00102         else
00103           return false;
00104       }
00105     };
00106 
00107     // set some fonts
00108 
00109     UIManager.getDefaults().put("Label.font",
00110         new Font("Helvetica", Font.BOLD, 10));
00111     UIManager.getDefaults().put("ComboBox.font",
00112         new Font("Helvetica", Font.BOLD, 10));
00113     UIManager.getDefaults().put("Border.font",
00114         new Font("Helvetica", Font.BOLD, 10));
00115     UIManager.getDefaults().put("Menu.font",
00116         new Font("Helvetica", Font.BOLD, 10));
00117     UIManager.getDefaults().put("Button.font",
00118         new Font("Helvetica", Font.BOLD, 10));
00119     UIManager.getDefaults().put("MenuItem.font",
00120         new Font("Helvetica", Font.BOLD, 10));
00121 
00122     this.setSize(WizardConstants.FRAME_WIDTH, WizardConstants.FRAME_HEIGHT);
00123     this.getContentPane().setLayout(new BorderLayout());
00124     GuiConstants.centerComponent(this, WizardConstants.FRAME_WIDTH,
00125         WizardConstants.FRAME_HEIGHT);
00126 
00127     // define the menu
00128     JMenuBar menuBar = new JMenuBar();
00129     JMenu menu = new JMenu(WizardTranslate.get("init.menu.1"));
00130     // quit
00131     JMenuItem item1 = new JMenuItem(WizardTranslate
00132         .get(WizardConstants.COMMAND_QUIT));
00133     item1.setActionCommand(WizardConstants.COMMAND_QUIT);
00134     // import
00135     JMenuItem item2 = new JMenuItem(WizardTranslate
00136         .get(WizardConstants.COMMAND_EXPORT_XML));
00137     item2.setActionCommand(WizardConstants.COMMAND_EXPORT_XML);
00138     // export
00139     JMenuItem item3 = new JMenuItem(WizardTranslate
00140         .get(WizardConstants.COMMAND_IMPORT_XML));
00141     item3.setActionCommand(WizardConstants.COMMAND_IMPORT_XML);
00142     // check
00143     JMenuItem item4 = new JMenuItem(WizardTranslate
00144         .get(WizardConstants.COMMAND_CHECK_WIZARD));
00145     item4.setActionCommand(WizardConstants.COMMAND_CHECK_WIZARD);
00146     //  validate
00147     JMenuItem item5 = new JMenuItem(WizardTranslate
00148         .get(WizardConstants.COMMAND_VALIDATE_XML));
00149     item5.setActionCommand(WizardConstants.COMMAND_VALIDATE_XML);
00150     menu.add(item1).addActionListener(this);
00151     menu.add(item2).addActionListener(this);
00152     menu.add(item3).addActionListener(this);
00153     menu.add(item4).addActionListener(this);
00154     menu.add(item5).addActionListener(this);
00155     menu.setVisible(true);
00156     menuBar.add(menu);
00157 
00158     // define the panel that contains the menu
00159     JPanel menuPane = new JPanel();
00160     menuPane.add(menuBar);
00161     this.getContentPane().add(menuPane, BorderLayout.NORTH);
00162 
00163     startWizardTabs();
00164 
00165     // Finish creating the frame
00166     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00167     this.validate();
00168     //this.pack();
00169     this.setVisible(true);
00170   }


Member Function Documentation

void org.objectweb.cjdbc.console.wizard.XmlWizard.actionPerformed ActionEvent  e  ) 
 

See also:
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)

Definition at line 183 of file XmlWizard.java.

References org.objectweb.cjdbc.console.wizard.XmlWizard.exportDocument(), org.objectweb.cjdbc.console.wizard.XmlWizard.loadDocument(), and org.objectweb.cjdbc.console.wizard.XmlWizard.validateDocument().

00184   {
00185     String command = e.getActionCommand();
00186     if (command.equals(WizardConstants.COMMAND_QUIT))
00187       System.exit(1);
00188     else if (command.equals(WizardConstants.COMMAND_EXPORT_XML))
00189       try
00190       {
00191         chooser.showSaveDialog(this);
00192         File document = chooser.getSelectedFile();
00193         if (document != null)
00194           exportDocument(document.getAbsolutePath());
00195       }
00196       catch (IOException e1)
00197       {
00198         e1.printStackTrace();
00199       }
00200     else if (command.equals(WizardConstants.COMMAND_IMPORT_XML))
00201     {
00202       try
00203       {
00204         chooser.showOpenDialog(this);
00205         File document = chooser.getSelectedFile();
00206         if (document != null)
00207           loadDocument(document.getAbsolutePath());
00208       }
00209       catch (Exception e2)
00210       {
00211         e2.printStackTrace();
00212       }
00213     }
00214     else if (command.equals(WizardConstants.COMMAND_CHECK_WIZARD))
00215     {
00216       chooser.showOpenDialog(this);
00217       File document = chooser.getSelectedFile();
00218       if (document != null)
00219       {
00220         try
00221         {
00222           loadDocument(document.getAbsolutePath());
00223           String newDoc = document.getParentFile().getAbsolutePath()
00224               + File.separator + document.getName() + ".check";
00225           exportDocument(newDoc);
00226           validateDocument(newDoc);
00227         }
00228         catch (Exception e2)
00229         {
00230           e2.printStackTrace();
00231         }
00232       }
00233     }
00234     else if (command.equals(WizardConstants.COMMAND_VALIDATE_XML))
00235     {
00236       chooser.showOpenDialog(this);
00237       File document = chooser.getSelectedFile();
00238       if (document != null)
00239         try
00240         {
00241           validateDocument(document.getAbsolutePath());
00242         }
00243         catch (IOException e2)
00244         {
00245           e2.printStackTrace();
00246         }
00247     }
00248   }

void org.objectweb.cjdbc.console.wizard.XmlWizard.exportDocument String  xmlFile  )  throws IOException
 

Save the document to an xml file

Parameters:
xmlFile the path to the xml file to save to
Exceptions:
IOException if fails to write

Definition at line 335 of file XmlWizard.java.

References org.objectweb.cjdbc.console.wizard.WizardTabs.exportDocumentToXml(), and org.objectweb.cjdbc.console.wizard.XmlWizard.saveDocument().

Referenced by org.objectweb.cjdbc.console.wizard.XmlWizard.actionPerformed().

00336   {
00337     this.document = wizardTabs.exportDocumentToXml();
00338     if (document != null)
00339       saveDocument(xmlFile);
00340   }

void org.objectweb.cjdbc.console.wizard.XmlWizard.loadDocument String  xmlFile  )  throws DocumentException, IOException
 

Load document from a xml file

Parameters:
xmlFile the path to the xml document
Exceptions:
DocumentException if fails to parse
IOException if fails to read

Definition at line 257 of file XmlWizard.java.

References org.objectweb.cjdbc.console.wizard.WizardTabs.importDocumentFromXml().

Referenced by org.objectweb.cjdbc.console.wizard.XmlWizard.actionPerformed(), and org.objectweb.cjdbc.console.wizard.XmlWizard.XmlWizard().

00259   {
00260     SAXReader reader = new SAXReader();
00261     this.document = reader.read(new FileReader(xmlFile));
00262     if (document != null)
00263     {
00264       startWizardTabs();
00265       wizardTabs.importDocumentFromXml(document);
00266     }
00267   }

void org.objectweb.cjdbc.console.wizard.XmlWizard.main String[]  args  )  [static]
 

Start the XmlWizard

Parameters:
args Command line arguments

Definition at line 347 of file XmlWizard.java.

References org.objectweb.cjdbc.console.wizard.XmlWizard.XmlWizard().

00348   {
00349 
00350     if (args == null || args.length == 0)
00351       new XmlWizard();
00352     else
00353     {
00354       try
00355       {
00356         new XmlWizard(args[0]);
00357       }
00358       catch (DocumentException e)
00359       {
00360         System.out.println(WizardTranslate.get("init.error.parse.failed"));
00361         new XmlWizard();
00362       }
00363       catch (IOException e)
00364       {
00365         System.out.println(WizardTranslate.get("init.error.read.failed"));
00366         new XmlWizard();
00367       }
00368     }
00369   }

void org.objectweb.cjdbc.console.wizard.XmlWizard.saveDocument String  xmlFile  )  throws IOException
 

Save the document to an xml file

Parameters:
xmlFile the path to the xml file to save to
Exceptions:
IOException if fails to write

Definition at line 275 of file XmlWizard.java.

Referenced by org.objectweb.cjdbc.console.wizard.XmlWizard.exportDocument().

00276   {
00277     OutputFormat format = OutputFormat.createPrettyPrint();
00278     XMLWriter writer = new XMLWriter(new FileWriter(xmlFile), format);
00279     writer.write(document);
00280     writer.close();
00281   }

void org.objectweb.cjdbc.console.wizard.XmlWizard.validateDocument String  xmlFile  )  throws IOException
 

Validate the given XML document contained in the given file.

Parameters:
xmlFile XML file name
Exceptions:
IOException if an error occurs

Definition at line 289 of file XmlWizard.java.

References org.objectweb.cjdbc.common.xml.XmlValidator.getExceptions(), org.objectweb.cjdbc.common.xml.XmlValidator.getWarnings(), org.objectweb.cjdbc.common.xml.XmlValidator.isDtdValid, org.objectweb.cjdbc.common.xml.XmlValidator.isXmlValid, org.objectweb.cjdbc.console.wizard.XmlValidatorFrame.setWarning(), and org.objectweb.cjdbc.console.wizard.XmlValidatorFrame.writeLine().

Referenced by org.objectweb.cjdbc.console.wizard.XmlWizard.actionPerformed().

00290   {
00291     XmlValidator validator = new XmlValidator(Constants.C_JDBC_DTD_FILE,
00292         new FileReader(new File(xmlFile)));
00293     XmlValidatorFrame frame = new XmlValidatorFrame(xmlFile);
00294 
00295     if (validator.isDtdValid())
00296       frame.writeLine(Translate.get("virtualdatabase.xml.dtd.validated"));
00297     if (validator.isXmlValid())
00298       frame.writeLine(Translate.get("virtualdatabase.xml.document.validated"));
00299 
00300     if (validator.getWarnings().size() > 0)
00301     {
00302       frame.setWarning();
00303       ArrayList warnings = validator.getWarnings();
00304       for (int i = 0; i < warnings.size(); i++)
00305         frame.writeLine(Translate.get("virtualdatabase.xml.parsing.warning",
00306             warnings.get(i)));
00307     }
00308 
00309     if (!validator.isDtdValid())
00310     {
00311       frame.setWarning();
00312       frame.writeLine(Translate.get("virtualdatabase.xml.dtd.not.validated"));
00313     }
00314     if (!validator.isXmlValid())
00315     {
00316       frame.setWarning();
00317       frame.writeLine(Translate
00318           .get("virtualdatabase.xml.document.not.validated"));
00319     }
00320 
00321     ArrayList errors = validator.getExceptions();
00322     if (errors.size() > 0)
00323       frame.setWarning();
00324     for (int i = 0; i < errors.size(); i++)
00325       frame.writeLine(((Exception) errors.get(i)).getMessage());
00326 
00327   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:03:20 2005 for C-JDBC by  doxygen 1.3.9.1