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.JAXPTransformerFactory;
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  import org.xmlhammer.model.tools.xslt.XSLT;
39  
40  public class NewXSLTransformationWizard extends HelpEnabledWizard {
41  
42      private static final long serialVersionUID = -2924107376836737591L;
43      
44      private OtherOutputPropertiesPage otherOutputPropertiesPage = null;
45      private HTMLOutputPropertiesPage htmlOutputPropertiesPage = null;
46      private TextOutputPropertiesPage textOutputPropertiesPage = null;
47      private XMLOutputPropertiesPage xmlOutputPropertiesPage = null;
48      private OutputPropertiesSelectionPage outputPropertiesSelectionPage = null;
49  
50      private AssociatedStylesheetPage associatedStylesheetPage = null;
51      private StylesheetURIsPage stylesheetURIsPage = null;
52      private StylesheetSelectionPage stylesheetSelectionPage = null;
53  
54      private InputFilterPage filterPage = null;
55      private InputURIsPage urisPage = null;
56      private InputTypeSelectionPage typeSelectionPage = null;
57      private ParserSelectionPage parserSelectionPage = null;
58      private ParserPropertiesPage parserPropertiesPage = null;
59      private ValidationSelectionPage validationSelectionPage = null;
60      private SchemaURIsPage schemaURIsPage = null;
61  
62      public NewXSLTransformationWizard(Frame parent) {
63          super(parent);
64          
65          otherOutputPropertiesPage = new OtherOutputPropertiesPage("new.trax.other.output-method");
66          htmlOutputPropertiesPage = new HTMLOutputPropertiesPage("new.trax.html.output-method");
67          textOutputPropertiesPage = new TextOutputPropertiesPage("new.trax.text.output-method");
68          xmlOutputPropertiesPage = new XMLOutputPropertiesPage("new.trax.xml.output-method");
69          outputPropertiesSelectionPage = new OutputPropertiesSelectionPage("new.trax.select.output-method", xmlOutputPropertiesPage, htmlOutputPropertiesPage, textOutputPropertiesPage, otherOutputPropertiesPage);
70  
71          associatedStylesheetPage = new AssociatedStylesheetPage("new.trax.associated.stylesheet", outputPropertiesSelectionPage);
72          stylesheetURIsPage = new StylesheetURIsPage("new.trax.select.uris", outputPropertiesSelectionPage);
73          stylesheetSelectionPage = new StylesheetSelectionPage("new.trax.select", stylesheetURIsPage, associatedStylesheetPage, outputPropertiesSelectionPage);
74          
75          schemaURIsPage = new SchemaURIsPage("new.trax.schema.specify", stylesheetSelectionPage);
76  
77          validationSelectionPage = new ValidationSelectionPage("new.trax.parser.validation", schemaURIsPage);
78          parserPropertiesPage = new ParserPropertiesPage("new.trax.parser.properties", validationSelectionPage);
79          parserSelectionPage = new ParserSelectionPage("new.trax.parser.select", parserPropertiesPage);
80          filterPage = new InputFilterPage("new.trax.input.filter", parserSelectionPage, true);
81          urisPage = new InputURIsPage("new.trax.input.specify", parserSelectionPage, true);
82          typeSelectionPage = new InputTypeSelectionPage("new.trax.input.selection", filterPage, urisPage);
83  
84          addPage(typeSelectionPage);
85          addPage(urisPage);
86          addPage(filterPage);
87          addPage(parserSelectionPage);
88          addPage(parserPropertiesPage);
89          addPage(validationSelectionPage);
90          addPage(schemaURIsPage);
91          addPage(stylesheetSelectionPage);
92          addPage(stylesheetURIsPage);
93          addPage(associatedStylesheetPage);
94          addPage(outputPropertiesSelectionPage);
95          addPage(otherOutputPropertiesPage);
96          addPage(xmlOutputPropertiesPage);
97          addPage(htmlOutputPropertiesPage);
98          addPage(textOutputPropertiesPage);
99  
100         setPage(typeSelectionPage);
101     }
102     
103     public String getWizardTitle() {
104         return "New XSL Transformation";
105     }
106     
107     public Project getProject() {
108         Project project = new Project();
109         Settings settings = new Settings();
110         settings.setJAXPDocumentBuilderFactory(new JAXPDocumentBuilderFactory());
111         settings.setJAXPSAXParserFactory(new JAXPSAXParserFactory());
112         settings.setJAXPTransformerFactory(new JAXPTransformerFactory());
113         settings.setJAXPSchemaFactory(new JAXPSchemaFactory());
114         project.setJAXPSettings(settings);
115         
116         // Set the input information
117         Input input = new Input();
118 
119         if (typeSelectionPage.isInputFilterSelected()) {
120             input.setFilter(filterPage.getFilter());
121         } else {
122             List<Document> uris = urisPage.getURIs();
123 
124             for (Document document : uris) {
125                 input.getSourceOrSourceAndResult().add(document);
126             }
127         }
128         
129         project.setInput(input);
130         
131         Parser parser = new Parser();
132         if (parserSelectionPage.isDOMSelected()) {
133             parser.setType("dom");
134         } else {
135             parser.setType("sax");
136         }
137         
138         parser.setValidating(validationSelectionPage.isValidating());
139         parser.setNamespaceAware(parserPropertiesPage.isNamespaceAware());
140         parser.setXincludeAware(parserPropertiesPage.isXincludeAware());
141 
142         parser.setLanguage(validationSelectionPage.getSchemaLanguage());
143         
144         List<Source> documents = parser.getSource();
145         documents.clear();
146         
147         for (Document document : validationSelectionPage.getURIs()) {
148             if (document instanceof Source) {
149                 documents.add((Source)document);
150             }
151         }
152 
153         project.setParser(parser);
154 
155         XSLT xslt = new XSLT();
156         project.setXSLT(xslt);
157         
158         xslt.setOutputProperties(outputPropertiesSelectionPage.getOutputProperties());
159         xslt.setTransform(stylesheetSelectionPage.getTransform());
160 
161         project.setXSLT(xslt);
162 
163         return project;
164     }
165 }