View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  
22  package org.xmlhammer.gui.wizard;
23  
24  import java.awt.Frame;
25  import java.util.List;
26  
27  import org.xmlhammer.gui.util.wizard.HelpEnabledWizard;
28  import org.xmlhammer.model.jaxp.JAXPSAXParserFactory;
29  import org.xmlhammer.model.jaxp.JAXPSchemaFactory;
30  import org.xmlhammer.model.jaxp.Settings;
31  import org.xmlhammer.model.project.Document;
32  import org.xmlhammer.model.project.Input;
33  import org.xmlhammer.model.project.Project;
34  
35  public class NewSchemaValidatorWizard extends HelpEnabledWizard {
36  
37      private static final long serialVersionUID = -2924107376836737591L;
38      
39      private InputFilterPage filterPage = null;
40      private InputURIsPage urisPage = null;
41      private InputTypeSelectionPage typeSelectionPage = null;
42      private SchemaPage schemaPage = null;
43  
44      public NewSchemaValidatorWizard(Frame parent) {
45          super(parent);
46          
47          schemaPage = new SchemaPage("new.schema.specify");
48          filterPage = new InputFilterPage("new.schema.input.filter", schemaPage);
49          urisPage = new InputURIsPage("new.schema.input.specify", schemaPage);
50          typeSelectionPage = new InputTypeSelectionPage("new.schema.input.selection", filterPage, urisPage);
51  
52          addPage(typeSelectionPage);
53          addPage(urisPage);
54          addPage(filterPage);
55          addPage(schemaPage);
56          
57          setPage(typeSelectionPage);
58      }
59      
60      public String getWizardTitle() {
61          return "New Schema Validator";
62      }
63      
64      public Project getProject() {
65          Project project = new Project();
66          Settings settings = new Settings();
67          settings.setJAXPSAXParserFactory(new JAXPSAXParserFactory());
68          settings.setJAXPSchemaFactory(new JAXPSchemaFactory());
69          project.setJAXPSettings(settings);
70          project.setSchemaValidator(schemaPage.getSchemaValidator());
71          
72          // Set the input information
73          Input input = new Input();
74  
75          if (typeSelectionPage.isInputFilterSelected()) {
76              input.setFilter(filterPage.getFilter());
77          } else {
78              List<Document> uris = urisPage.getURIs();
79  
80              for (Document document : uris) {
81                  input.getSourceOrSourceAndResult().add(document);
82              }
83          }
84          
85          project.setInput(input);
86          
87          return project;
88      }
89  }