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.JAXPDocumentBuilderFactory;
29  import org.xmlhammer.model.jaxp.JAXPSAXParserFactory;
30  import org.xmlhammer.model.jaxp.JAXPSchemaFactory;
31  import org.xmlhammer.model.jaxp.JAXPXPathFactory;
32  import org.xmlhammer.model.jaxp.Settings;
33  import org.xmlhammer.model.project.Document;
34  import org.xmlhammer.model.project.Input;
35  import org.xmlhammer.model.project.Parser;
36  import org.xmlhammer.model.project.Project;
37  import org.xmlhammer.model.project.Source;
38  
39  public class NewXPathWizard extends HelpEnabledWizard {
40  
41      private static final long serialVersionUID = -2924107376836737591L;
42      
43      private InputFilterPage filterPage = null;
44      private InputURIsPage urisPage = null;
45      private InputTypeSelectionPage typeSelectionPage = null;
46      private ParserPropertiesPage parserPropertiesPage = null;
47      private XPathPage xpathPage = null;
48      private ValidationSelectionPage validationSelectionPage = null;
49      private SchemaURIsPage schemaURIsPage = null;
50  
51      public NewXPathWizard(Frame parent) {
52          super(parent);
53          
54          xpathPage = new XPathPage("new.xpath.specification");
55          schemaURIsPage = new SchemaURIsPage("new.xpath.schema.specify", xpathPage);
56          validationSelectionPage = new ValidationSelectionPage("new.xpath.parser.validation", schemaURIsPage);
57          parserPropertiesPage = new ParserPropertiesPage("new.xpath.parser.properties", validationSelectionPage);
58          filterPage = new InputFilterPage("new.xpath.input.filter", parserPropertiesPage);
59          urisPage = new InputURIsPage("new.xpath.input.specify", parserPropertiesPage);
60          typeSelectionPage = new InputTypeSelectionPage("new.xpath.input.selection", filterPage, urisPage);
61  
62          addPage(typeSelectionPage);
63          addPage(urisPage);
64          addPage(filterPage);
65          addPage(parserPropertiesPage);
66          addPage(validationSelectionPage);
67          addPage(schemaURIsPage);
68          addPage(xpathPage);
69          
70          setPage(typeSelectionPage);
71      }
72      
73      public String getWizardTitle() {
74          return "New XPath Search";
75      }
76      
77      public Project getProject() {
78          Project project = new Project();
79          Settings settings = new Settings();
80          settings.setJAXPDocumentBuilderFactory( new JAXPDocumentBuilderFactory());
81          settings.setJAXPSAXParserFactory( new JAXPSAXParserFactory());
82          settings.setJAXPXPathFactory( new JAXPXPathFactory());
83          settings.setJAXPSchemaFactory( new JAXPSchemaFactory());
84          project.setJAXPSettings(settings);
85          
86          // Set the input information
87          Input input = new Input();
88  
89          if (typeSelectionPage.isInputFilterSelected()) {
90              input.setFilter(filterPage.getFilter());
91          } else {
92              List<Document> uris = urisPage.getURIs();
93  
94              for (Document document : uris) {
95                  input.getSourceOrSourceAndResult().add(document);
96              }
97          }
98          
99          project.setInput(input);
100         
101         Parser parser = new Parser();
102 
103         parser.setType("dom");
104         parser.setValidating(validationSelectionPage.isValidating());
105         parser.setNamespaceAware(parserPropertiesPage.isNamespaceAware());
106         parser.setXincludeAware(parserPropertiesPage.isXincludeAware());
107 
108         parser.setLanguage(validationSelectionPage.getSchemaLanguage());
109         
110         List<Source> documents = parser.getSource();
111         documents.clear();
112         
113         for (Document document : validationSelectionPage.getURIs()) {
114             if (document instanceof Source) {
115                 documents.add((Source)document);
116             }
117         }
118 
119         project.setParser(parser);
120         
121         project.setXPath(xpathPage.getXPath());
122 
123         return project;
124     }
125 }