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.xslt;
23
24 import java.awt.event.ItemEvent;
25 import java.net.URI;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Set;
30
31 import javax.swing.JPanel;
32
33 import org.xmlhammer.gui.ProjectView;
34 import org.xmlhammer.gui.overview.OverviewNode;
35 import org.xmlhammer.gui.preferences.PropertiesDialog;
36 import org.xmlhammer.gui.util.SelectionPage;
37 import org.xmlhammer.model.tools.xslt.OutputProperties;
38 import org.xmlhammer.model.tools.xslt.OutputProperty;
39
40 /***
41 * Input Panel.
42 *
43 * Allows to select either one URI, multiple URIs or
44 * a range of files.
45 *
46 * @version $Revision$, $Date$
47 * @author Edwin Dankert <edankert@gmail.com>
48 */
49
50 public class OutputPage extends SelectionPage implements OverviewNode {
51 private static final long serialVersionUID = 3257852090755134776L;
52
53 private XMLOutputPropertiesDialog propertiesDialog = null;
54
55 private boolean initialised = false;
56 private HashMap<String,OutputProperty> properties = null;
57 private XMLOutputPanel defaultOutputPanel = null;
58 private XMLOutputPanel xmlOutputPanel = null;
59 private XMLOutputPanel htmlOutputPanel = null;
60 private XMLOutputPanel textOutputPanel = null;
61 private XMLOutputPanel otherOutputPanel = null;
62
63 /***
64 * Constructs a new Input Panel.
65 */
66 public OutputPage( ProjectView view) {
67 super(view, "Output Method:", true);
68
69 defaultOutputPanel = new XMLOutputPanel(this, XMLOutputPanel.OUTPUT_METHOD_DEFAULT);
70 xmlOutputPanel = new XMLOutputPanel(this, XMLOutputPanel.OUTPUT_METHOD_XML);
71 htmlOutputPanel = new XMLOutputPanel(this, XMLOutputPanel.OUTPUT_METHOD_HTML);
72 textOutputPanel = new XMLOutputPanel(this, XMLOutputPanel.OUTPUT_METHOD_TEXT);
73 otherOutputPanel = new XMLOutputPanel(this, XMLOutputPanel.OUTPUT_METHOD_OTHER);
74
75 addPanel( "default", defaultOutputPanel);
76 addPanel( "xml", xmlOutputPanel);
77 addPanel( "html", htmlOutputPanel);
78 addPanel( "text", textOutputPanel);
79 addPanel( "other", otherOutputPanel);
80
81 properties = new HashMap<String,OutputProperty>();
82
83 initialised = true;
84 }
85
86 /***
87 * Sets the input model.
88 * Null resets current values.
89 *
90 * @param input the input model.
91 */
92 public void setOutputProperties(URI base, OutputProperties outputProperties) {
93 if (outputProperties != null) {
94 setOutputProperties(base, outputProperties.getOutputProperty());
95 } else {
96 setOutputProperties(base, (List<OutputProperty>)null);
97 }
98 }
99
100 private void setOutputProperties(URI base, List<OutputProperty> outputProperties) {
101 if (outputProperties != null) {
102 for (OutputProperty property : outputProperties) {
103 properties.put(property.getName(), property);
104 }
105 }
106
107 OutputProperty method = properties.get("method");
108
109 if (method == null) {
110 setSelectedPanel(defaultOutputPanel);
111 } else if (method.getValue().equals("xml")) {
112 setSelectedPanel(xmlOutputPanel);
113 } else if (method.getValue().equals("html")) {
114 setSelectedPanel(htmlOutputPanel);
115 } else if (method.getValue().equals("text")) {
116 setSelectedPanel(textOutputPanel);
117 } else {
118 setSelectedPanel(otherOutputPanel);
119 }
120
121 XMLOutputPanel panel = (XMLOutputPanel)getSelectedPanel();
122 panel.setProperties(outputProperties);
123
124
125 if (xmlOutputPanel != panel) {
126 xmlOutputPanel.setProperties(null);
127 }
128
129 if (defaultOutputPanel != panel) {
130 defaultOutputPanel.setProperties(null);
131 }
132
133 if (htmlOutputPanel != panel) {
134 htmlOutputPanel.setProperties(null);
135 }
136
137 if (textOutputPanel != panel) {
138 textOutputPanel.setProperties(null);
139 }
140
141 if (otherOutputPanel != panel) {
142 otherOutputPanel.setProperties(null);
143 }
144 }
145
146 public OutputProperties getOutputProperties(URI base) {
147 OutputProperties outputProperties = new OutputProperties();
148
149 synchronizeProperties(base);
150
151 Set<String> keys = properties.keySet();
152 for (String key : keys) {
153 outputProperties.getOutputProperty().add(properties.get(key));
154 }
155
156 return outputProperties;
157 }
158
159 /***
160 * Shows the properties dialog.
161 */
162 public void showPropertiesDialog() {
163 if (propertiesDialog == null) {
164 propertiesDialog = new XMLOutputPropertiesDialog(getProjectView().getProjectsView().getRoot());
165 }
166
167 OutputProperties props = getOutputProperties(null);
168
169 propertiesDialog.setOutputProperties(props.getOutputProperty());
170
171 if (propertiesDialog.open() == PropertiesDialog.OK_OPTION) {
172 getProjectView().getFieldManager().setPropertiesChanged(true);
173 setOutputProperties(null, propertiesDialog.getOutputProperties());
174 }
175 }
176
177 private void synchronizeProperties(URI base) {
178 XMLOutputPanel panel = (XMLOutputPanel)getSelectedPanel();
179
180 properties.remove("omit-xml-declaration");
181 properties.remove("version");
182 properties.remove("encoding");
183 properties.remove("standalone");
184 properties.remove("doctype-system");
185 properties.remove("doctype-public");
186 properties.remove("indent");
187 properties.remove("cdata-section-elements");
188 properties.remove("media-type");
189
190 if (panel.getMethod() == XMLOutputPanel.OUTPUT_METHOD_XML) {
191 properties.put("method", createOutputProperty("method", "xml"));
192 } else if (panel.getMethod() == XMLOutputPanel.OUTPUT_METHOD_HTML) {
193 properties.put("method", createOutputProperty("method", "html"));
194 } else if (panel.getMethod() == XMLOutputPanel.OUTPUT_METHOD_TEXT) {
195 properties.put("method", createOutputProperty("method", "text"));
196 } else if (panel.getMethod() == XMLOutputPanel.OUTPUT_METHOD_DEFAULT) {
197 properties.remove("method");
198 }
199
200 List<OutputProperty> list = panel.getProperties(base);
201 for (OutputProperty property : list) {
202 properties.put(property.getName(), createOutputProperty(property.getName(), property.getValue()));
203 }
204 }
205
206 public String getShortName() {
207 return "Output";
208 }
209
210
211
212
213 public String getNodeName() {
214 return "Output Properties ("+((XMLOutputPanel)getSelectedPanel()).getMethod()+")";
215 }
216
217
218
219
220 public ArrayList<OverviewNode> getChildNodes() {
221 JPanel panel = getSelectedPanel();
222
223 if ( panel instanceof XMLOutputPanel) {
224 return ((XMLOutputPanel)panel).getNodes();
225
226
227 }
228
229 return new ArrayList<OverviewNode>();
230 }
231
232 public OverviewNode getParentNode() {
233 if ( initialised) {
234 return getProjectView().getOverviewPanel().getModel().getRoot();
235 }
236
237 return null;
238 }
239
240 public String getError() {
241 return null;
242 }
243
244 public void itemStateChanged(ItemEvent e) {
245 super.itemStateChanged( e);
246
247 if ( initialised) {
248 ProjectView view = getProjectView();
249
250
251 view.getOverviewPanel().getModel().structureChanged( this);
252 view.getOverviewPanel().expandAll();
253 }
254 }
255
256 public void dispose() {
257
258 }
259
260 @Override
261 public String getHelpID() {
262 return getProjectView().getHelpID()+".output";
263 }
264
265 private OutputProperty createOutputProperty(String name, String value) {
266 OutputProperty property = new OutputProperty();
267 property.setName(name);
268 property.setValue(value);
269
270 return property;
271 }
272 }