1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }