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