1 | package org.greenstone.admin.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Component;
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.GridLayout;
|
---|
8 |
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.awt.event.ActionListener;
|
---|
11 | import java.awt.event.ItemEvent;
|
---|
12 | import java.awt.event.ItemListener;
|
---|
13 | import java.io.BufferedReader;
|
---|
14 | import java.io.BufferedWriter;
|
---|
15 | import java.io.File;
|
---|
16 | import java.io.FileInputStream;
|
---|
17 | import java.io.FileOutputStream;
|
---|
18 | import java.io.IOException;
|
---|
19 | import java.io.InputStreamReader;
|
---|
20 | import java.io.OutputStreamWriter;
|
---|
21 | import java.io.Writer;
|
---|
22 |
|
---|
23 | import javax.swing.*;
|
---|
24 | import javax.xml.parsers.DocumentBuilder;
|
---|
25 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
26 | import javax.xml.transform.OutputKeys;
|
---|
27 | import javax.xml.transform.Transformer;
|
---|
28 | import javax.xml.transform.TransformerFactory;
|
---|
29 | import javax.xml.transform.dom.DOMSource;
|
---|
30 | import javax.xml.transform.stream.StreamResult;
|
---|
31 |
|
---|
32 | //import org.apache.tools.ant.Project;
|
---|
33 | //import org.apache.tools.ant.ProjectHelper;
|
---|
34 | import org.greenstone.gsdl3.util.GSPath;
|
---|
35 | import org.greenstone.gsdl3.util.GlobalProperties;
|
---|
36 |
|
---|
37 |
|
---|
38 | import org.w3c.dom.Document;
|
---|
39 | import org.w3c.dom.Element;
|
---|
40 | import org.w3c.dom.Node;
|
---|
41 | import org.w3c.dom.NodeList;
|
---|
42 | import org.w3c.dom.Text;
|
---|
43 |
|
---|
44 | import java.text.SimpleDateFormat;
|
---|
45 | import java.util.ArrayList;
|
---|
46 | import java.util.Calendar;
|
---|
47 | import java.util.Iterator;
|
---|
48 | import java.util.Properties;
|
---|
49 | import java.util.Set;
|
---|
50 |
|
---|
51 |
|
---|
52 | public class Mat extends adminUI_Pane{
|
---|
53 |
|
---|
54 | JButton start_button;
|
---|
55 | JButton enable_disable_button;
|
---|
56 | JButton option_button;
|
---|
57 | JButton description_control_button;
|
---|
58 | JButton control_description_button;
|
---|
59 | JPanel description_control_button_pane;
|
---|
60 |
|
---|
61 | JPanel control_content_pane;
|
---|
62 | JPanel control_button_pane;
|
---|
63 | JPanel control_description_pane;
|
---|
64 |
|
---|
65 | JLabel install_path;
|
---|
66 | JLabel oai_temp_directory;
|
---|
67 | JTextField install_path_text;
|
---|
68 | JTextField oai_temp_directory_text;
|
---|
69 | JCheckBox web_tool_checkbox;
|
---|
70 | JCheckBox java_tool_checkbox;
|
---|
71 | SimpleDateFormat sdf;
|
---|
72 |
|
---|
73 | private GlobalProperties globalProperty = null;
|
---|
74 | private final String fileSeparator = File.separator;
|
---|
75 | private GSPath gspath = null;
|
---|
76 |
|
---|
77 | static final int left_margin = 7;
|
---|
78 | static final int right_margin = 7;
|
---|
79 | static final int HORIZONTAL_GAP = 5;
|
---|
80 | static final int VERTICAL_GAP = 5;
|
---|
81 |
|
---|
82 | String install_options_filePath = null;
|
---|
83 | static String extension_list_path;
|
---|
84 | static String extension_buildProperty_path;
|
---|
85 | static String extension_runtimeProperty_path;
|
---|
86 | static String extension_log_path;
|
---|
87 | static String extension_log_directory;
|
---|
88 | static String extension_path;
|
---|
89 | static String os_type;
|
---|
90 | static String oai_folder;
|
---|
91 | static String web_xml_path;
|
---|
92 | static final String InstallCompleteMsg = "The extension (Mat) has been installed successfully.";
|
---|
93 | static final String InstallErrorMsg = "Sorry, the extension (Mat) could not be installed. Please try again!";
|
---|
94 |
|
---|
95 | static final String DownloadCompleteMsg = "The extension (Mat) has been downloaded successfully.";
|
---|
96 | static final String DownloadErrorMsg = "Sorry, the extension (Mat) could not be downloaded. Please try again!";
|
---|
97 |
|
---|
98 | public Mat(){}
|
---|
99 |
|
---|
100 | public Mat (String extensionName){
|
---|
101 |
|
---|
102 | group = new String();
|
---|
103 | description = new String();
|
---|
104 | download_type = new String();
|
---|
105 |
|
---|
106 | extension_name = extensionName;
|
---|
107 | url = new String();
|
---|
108 | configurable = new Boolean(false);
|
---|
109 |
|
---|
110 | os_type = System.getProperty("os.name");
|
---|
111 |
|
---|
112 | String gsdl3Home = get_GSDL3HOME();
|
---|
113 |
|
---|
114 | extension_list_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml";
|
---|
115 | extension_buildProperty_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"build.properties";
|
---|
116 | extension_runtimeProperty_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"properties.xml";
|
---|
117 | extension_log_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"logs"+fileSeparator+"mat"+fileSeparator+"extension_log.xml";
|
---|
118 | extension_log_directory = gsdl3Home+fileSeparator+"ext"+fileSeparator+"logs"+fileSeparator+"mat";
|
---|
119 | extension_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator;
|
---|
120 | oai_folder = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"tmp"+fileSeparator;
|
---|
121 | web_xml_path = gsdl3Home+fileSeparator+"web"+fileSeparator+"WEB-INF"+fileSeparator+"web.xml";
|
---|
122 |
|
---|
123 | start_button = new JButton("Analyse");
|
---|
124 | start_button.setPreferredSize(new Dimension(50,25));
|
---|
125 | start_button.setMaximumSize(new Dimension(50,25));
|
---|
126 | start_button.setName("Analyse");
|
---|
127 | start_button.setEnabled(false);
|
---|
128 | start_button.addActionListener(new aListener(this));
|
---|
129 |
|
---|
130 | enable_disable_button = new JButton("Enable");
|
---|
131 | enable_disable_button.setName("enable_disable");
|
---|
132 | enable_disable_button.setVisible(false);
|
---|
133 | enable_disable_button.addActionListener(new aListener(this));
|
---|
134 | enable_disable_button.setPreferredSize(new Dimension(50,25));
|
---|
135 | enable_disable_button.setMaximumSize(new Dimension(50,25));
|
---|
136 |
|
---|
137 | option_button = new JButton("Options");
|
---|
138 | option_button.setName("options");
|
---|
139 | option_button.addActionListener(new aListener(this));
|
---|
140 |
|
---|
141 | control_description_button = new JButton("Description");
|
---|
142 | control_description_button.setName("control_description");
|
---|
143 | control_description_button.addActionListener(new aListener(this));
|
---|
144 |
|
---|
145 | description_control_button = new JButton("Control Panel");
|
---|
146 | description_control_button.setName("description_control");
|
---|
147 | description_control_button.addActionListener(new aListener(this));
|
---|
148 | description_control_button.setEnabled(getCommandStatus("install"));
|
---|
149 | description_control_button_pane = new JPanel(new GridLayout(1,3));
|
---|
150 |
|
---|
151 | description_pane = new JScrollPane ();
|
---|
152 | control_pane = new JPanel ();
|
---|
153 | descriptionTextArea = new JTextArea();
|
---|
154 | button_pane = new JPanel();
|
---|
155 |
|
---|
156 | oai_temp_directory = new JLabel();
|
---|
157 | oai_temp_directory.setText("OAI temporary download directory:");
|
---|
158 | oai_temp_directory_text = new JTextField();
|
---|
159 | oai_temp_directory_text.setText(oai_folder);
|
---|
160 | oai_temp_directory_text.setEditable(false);
|
---|
161 | oai_temp_directory_text.setBackground(Color.WHITE);
|
---|
162 |
|
---|
163 | install_path = new JLabel();
|
---|
164 | install_path.setText("Metadata Quality Tool is installed in:");
|
---|
165 | install_path_text = new JTextField();
|
---|
166 | install_path_text.setText(extension_path);
|
---|
167 | install_path_text.setEditable(false);
|
---|
168 | install_path_text.setBackground(Color.WHITE);
|
---|
169 |
|
---|
170 | web_tool_checkbox = new JCheckBox("Web OAI Collection Building");
|
---|
171 | web_tool_checkbox.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
|
---|
172 | web_tool_checkbox.setVisible(false);
|
---|
173 | java_tool_checkbox = new JCheckBox("Local Collection Analysis");
|
---|
174 | java_tool_checkbox.addItemListener(new checkBoxStatus(this));
|
---|
175 | java_tool_checkbox.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
|
---|
176 |
|
---|
177 | GridLayout gridLayout3 = new GridLayout(3,3);
|
---|
178 | gridLayout3.setVgap(VERTICAL_GAP);
|
---|
179 | control_content_pane = new JPanel(gridLayout3);
|
---|
180 | control_content_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
|
---|
181 |
|
---|
182 | GridLayout gridLayout2 = new GridLayout(1,2);
|
---|
183 | gridLayout2.setHgap(HORIZONTAL_GAP);
|
---|
184 | control_button_pane = new JPanel(gridLayout2);
|
---|
185 | control_button_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
|
---|
186 |
|
---|
187 | GridLayout gridLayout1 = new GridLayout(2,2);
|
---|
188 | gridLayout1.setVgap(VERTICAL_GAP);
|
---|
189 | control_description_pane = new JPanel(gridLayout1);
|
---|
190 | control_description_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
|
---|
191 |
|
---|
192 | control_pane = new JPanel();
|
---|
193 | control_pane.setLayout(new BoxLayout(control_pane, BoxLayout.Y_AXIS));
|
---|
194 |
|
---|
195 | setup();
|
---|
196 | setupControlPane();
|
---|
197 | loadProjectInformation();
|
---|
198 |
|
---|
199 |
|
---|
200 | };
|
---|
201 |
|
---|
202 | public JPanel getControlPane(){
|
---|
203 |
|
---|
204 | return control_pane;
|
---|
205 | }
|
---|
206 |
|
---|
207 | public JPanel getButtonPane(){
|
---|
208 | return button_pane;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public JPanel getDescriptionPane(){
|
---|
212 |
|
---|
213 |
|
---|
214 | description_control_button_pane.add(Box.createRigidArea(new Dimension(18,5)));
|
---|
215 | description_control_button_pane.add(description_control_button);
|
---|
216 | description_control_button_pane.add(Box.createRigidArea(new Dimension(18,5)));
|
---|
217 |
|
---|
218 | main_pane = new JPanel(new BorderLayout());
|
---|
219 | main_pane.add(description_pane, BorderLayout.CENTER);
|
---|
220 | main_pane.add(description_control_button_pane, BorderLayout.SOUTH);
|
---|
221 | return main_pane;
|
---|
222 |
|
---|
223 | }
|
---|
224 |
|
---|
225 | private void setupControlPane(){
|
---|
226 |
|
---|
227 | control_content_pane.add(java_tool_checkbox);
|
---|
228 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
229 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
230 |
|
---|
231 | JPanel tempPane = new JPanel(new BorderLayout());
|
---|
232 | tempPane.add(Box.createRigidArea(new Dimension(18,5)), BorderLayout.WEST);
|
---|
233 | tempPane.add(start_button, BorderLayout.CENTER);
|
---|
234 | control_content_pane.add(tempPane);
|
---|
235 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
236 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
237 |
|
---|
238 |
|
---|
239 | //control_content_pane.add(web_tool_checkbox);
|
---|
240 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
241 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
242 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
243 | /*
|
---|
244 | JPanel tempPane2 = new JPanel(new BorderLayout());
|
---|
245 | tempPane2.add(Box.createRigidArea(new Dimension(18,5)), BorderLayout.WEST);
|
---|
246 | tempPane2.add(enable_disable_button, BorderLayout.CENTER);
|
---|
247 | control_content_pane.add(tempPane2);
|
---|
248 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
249 | control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
|
---|
250 | */
|
---|
251 | control_description_pane.add(install_path);
|
---|
252 | control_description_pane.add(install_path_text);
|
---|
253 |
|
---|
254 | control_description_pane.add(oai_temp_directory);
|
---|
255 | control_description_pane.add(oai_temp_directory_text);
|
---|
256 |
|
---|
257 | control_button_pane.add(control_description_button);
|
---|
258 | control_button_pane.add(option_button);
|
---|
259 |
|
---|
260 | control_content_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
|
---|
261 | control_pane.add(control_content_pane);
|
---|
262 |
|
---|
263 | control_description_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
|
---|
264 | control_pane.add(control_description_pane);
|
---|
265 |
|
---|
266 | control_button_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
|
---|
267 | control_pane.add(control_button_pane);
|
---|
268 |
|
---|
269 | }
|
---|
270 |
|
---|
271 | protected Object[][] getConfigureContent(){
|
---|
272 |
|
---|
273 | return null;
|
---|
274 |
|
---|
275 | }
|
---|
276 |
|
---|
277 | public Boolean isConfigurable(){
|
---|
278 |
|
---|
279 | return configurable ;
|
---|
280 |
|
---|
281 | }
|
---|
282 |
|
---|
283 | public String getDestinationLocation(){
|
---|
284 |
|
---|
285 | return destination_folder;
|
---|
286 | }
|
---|
287 |
|
---|
288 | public String getDownloadLocation(){
|
---|
289 |
|
---|
290 | return url;
|
---|
291 |
|
---|
292 | }
|
---|
293 |
|
---|
294 | public String getDownloadType(){
|
---|
295 |
|
---|
296 | return download_type;
|
---|
297 |
|
---|
298 | }
|
---|
299 |
|
---|
300 | protected void loadProjectInformation(){
|
---|
301 |
|
---|
302 | Element rootNode = getRootElement(extension_list_path);
|
---|
303 |
|
---|
304 | NodeList projectNodeList = rootNode.getElementsByTagName(EXTENSION);
|
---|
305 |
|
---|
306 | for(int i = 0; i < projectNodeList.getLength(); i++){
|
---|
307 |
|
---|
308 | Element projectNode = (Element)projectNodeList.item(i);
|
---|
309 | NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
|
---|
310 | String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
311 |
|
---|
312 | if(name.equalsIgnoreCase(extension_name)){
|
---|
313 | NodeList groupNodeList = projectNode.getElementsByTagName(GROUP);
|
---|
314 | group = groupNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
315 |
|
---|
316 |
|
---|
317 | NodeList stepList = projectNode.getElementsByTagName(STEP);
|
---|
318 | GridLayout gl = new GridLayout(stepList.getLength(),1);
|
---|
319 | gl.setVgap(5);
|
---|
320 | button_pane.setLayout(gl);
|
---|
321 |
|
---|
322 | for (int y = 0; y< stepList.getLength(); y++){
|
---|
323 |
|
---|
324 | Node e = stepList.item(y);
|
---|
325 | Element stepElement = (Element) e;
|
---|
326 | JButton button = new JButton();
|
---|
327 | String command = stepElement.getAttribute("action");
|
---|
328 | button.setText(stepElement.getAttribute("label"));
|
---|
329 | button.setName(command);
|
---|
330 |
|
---|
331 | button.addActionListener(new aListener(this));
|
---|
332 | boolean status = getCommandStatus(command);
|
---|
333 | button.setEnabled(status);
|
---|
334 |
|
---|
335 | if(stepElement.getAttribute("action").equalsIgnoreCase(DOWNLOAD)){
|
---|
336 | download_type = stepElement.getAttribute("method");
|
---|
337 | url = stepElement.getElementsByTagName("source").item(0).getChildNodes().item(0).getNodeValue();
|
---|
338 | //destination_folder = stepElement.getElementsByTagName("destination").item(0).getChildNodes().item(0).getNodeValue();
|
---|
339 | destination_folder = extension_path;
|
---|
340 | }
|
---|
341 |
|
---|
342 | if(stepElement.getAttribute("action").equalsIgnoreCase("Install_option")){
|
---|
343 | //install_options_filePath = stepElement.getAttribute("filePath");
|
---|
344 | install_options_filePath = extension_path+"build.properties";
|
---|
345 | }
|
---|
346 | button_pane.add(button);
|
---|
347 | }
|
---|
348 | }
|
---|
349 | }
|
---|
350 | }
|
---|
351 |
|
---|
352 | public boolean getCommandStatus (String command){
|
---|
353 |
|
---|
354 | Element root = getRootElement(extension_list_path);
|
---|
355 |
|
---|
356 | NodeList extensionList = root.getElementsByTagName("extension");
|
---|
357 |
|
---|
358 | boolean s = false;
|
---|
359 |
|
---|
360 | for(int i = 0; i < extensionList.getLength(); i++){
|
---|
361 |
|
---|
362 | Element projectNode = (Element)extensionList.item(i);
|
---|
363 | NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
|
---|
364 | String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
365 |
|
---|
366 | if(name.equalsIgnoreCase(extension_name)){
|
---|
367 |
|
---|
368 | Element actionElement = (Element)extensionList.item(0);
|
---|
369 | NodeList individual_extension_detail_list = actionElement.getElementsByTagName("sequence_list");
|
---|
370 | Node sequenceListNode = individual_extension_detail_list.item(0);
|
---|
371 | NodeList sequenceDetailList = sequenceListNode.getChildNodes();
|
---|
372 |
|
---|
373 | for(int j = 0; j < sequenceDetailList.getLength(); j++){
|
---|
374 | Node n = sequenceDetailList.item(j);
|
---|
375 |
|
---|
376 | if(n instanceof Element){
|
---|
377 |
|
---|
378 | Element e = (Element)n;
|
---|
379 | if(e.getAttribute("action").equalsIgnoreCase(command)){
|
---|
380 | String status = e.getAttribute("status");
|
---|
381 |
|
---|
382 | Boolean bv = Boolean.valueOf(status);
|
---|
383 | s = bv.booleanValue();
|
---|
384 | }
|
---|
385 | }
|
---|
386 | }
|
---|
387 | }
|
---|
388 | }//
|
---|
389 | return s;
|
---|
390 | }
|
---|
391 |
|
---|
392 | public void updateButtonPane(){
|
---|
393 |
|
---|
394 | String gsdl3Home = get_GSDL3HOME();
|
---|
395 | Element root = getRootElement(extension_list_path);
|
---|
396 | NodeList extensionList = root.getElementsByTagName("extension");
|
---|
397 |
|
---|
398 | for(int a = 0; a < extensionList.getLength(); a++){
|
---|
399 |
|
---|
400 | Element projectNode = (Element)extensionList.item(a);
|
---|
401 | NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
|
---|
402 | String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
403 | if(name.equalsIgnoreCase(extension_name)){
|
---|
404 | //System.out.println(extension_name);
|
---|
405 | NodeList actionList = projectNode.getElementsByTagName("sequence_list");
|
---|
406 | //System.out.println(actionList.getLength());
|
---|
407 | Node x = actionList.item(0);
|
---|
408 | NodeList stepList = x.getChildNodes();
|
---|
409 |
|
---|
410 | for(int i = 0; i<stepList.getLength(); i++){
|
---|
411 | Node n = stepList.item(i);
|
---|
412 | if(n instanceof Element){
|
---|
413 | Element actionElement = (Element) n;
|
---|
414 |
|
---|
415 | String action = actionElement.getAttribute("action");
|
---|
416 | boolean status = getCommandStatus(action);
|
---|
417 |
|
---|
418 | Component[] c = button_pane.getComponents();
|
---|
419 |
|
---|
420 | for(int j = 0; j<c.length; j++){
|
---|
421 | JButton button = (JButton)c[j];
|
---|
422 | if(button.getName().equalsIgnoreCase(action)){
|
---|
423 | button.setEnabled(status);
|
---|
424 | button_pane.updateUI();
|
---|
425 | }
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | }///
|
---|
430 | }
|
---|
431 | }
|
---|
432 |
|
---|
433 | }
|
---|
434 |
|
---|
435 | public void setCommandStatus(String command){
|
---|
436 |
|
---|
437 | String gsdl3Home = get_GSDL3HOME();
|
---|
438 | Element root = getRootElement(extension_list_path);
|
---|
439 | NodeList actionList = root.getElementsByTagName("sequence_list");
|
---|
440 |
|
---|
441 | if(command.equalsIgnoreCase("download")){
|
---|
442 |
|
---|
443 | Node x = actionList.item(0);
|
---|
444 | NodeList stepList = x.getChildNodes();
|
---|
445 |
|
---|
446 | for(int i = 0; i<stepList.getLength(); i++){
|
---|
447 | Node n = stepList.item(i);
|
---|
448 | if(n instanceof Element){
|
---|
449 | Element actionElement = (Element) n;
|
---|
450 |
|
---|
451 | String action = actionElement.getAttribute("action");
|
---|
452 |
|
---|
453 | if(!action.equalsIgnoreCase(command)){
|
---|
454 |
|
---|
455 | String status = actionElement.getAttribute("status");
|
---|
456 | actionElement.setAttribute("status", "true");
|
---|
457 | }
|
---|
458 | }
|
---|
459 | }
|
---|
460 | }
|
---|
461 |
|
---|
462 | else if(command.equalsIgnoreCase("uninstall")){
|
---|
463 | Node x = actionList.item(0);
|
---|
464 | NodeList stepList = x.getChildNodes();
|
---|
465 |
|
---|
466 | for(int i = 0; i<stepList.getLength(); i++){
|
---|
467 | Node n = stepList.item(i);
|
---|
468 | if(n instanceof Element){
|
---|
469 | Element actionElement = (Element) n;
|
---|
470 |
|
---|
471 | String action = actionElement.getAttribute("action");
|
---|
472 |
|
---|
473 | if(!action.equalsIgnoreCase("download")){
|
---|
474 |
|
---|
475 | String status = actionElement.getAttribute("status");
|
---|
476 | actionElement.setAttribute("status", "false");
|
---|
477 | }
|
---|
478 | }
|
---|
479 | }
|
---|
480 | }
|
---|
481 |
|
---|
482 | try{
|
---|
483 | TransformerFactory tf= TransformerFactory.newInstance();
|
---|
484 | Transformer transformer= tf.newTransformer();
|
---|
485 | DOMSource source= new DOMSource(root);
|
---|
486 | transformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
---|
487 |
|
---|
488 | Writer pwx= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(extension_list_path),"UTF-8"));
|
---|
489 | StreamResult result= new StreamResult(pwx);
|
---|
490 | transformer.transform(source,result);
|
---|
491 | pwx.close();
|
---|
492 |
|
---|
493 | updateButtonPane();
|
---|
494 | }catch(Exception ex){
|
---|
495 | ex.printStackTrace();
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | public Object[][] getConfiguration(String filePath){
|
---|
500 |
|
---|
501 | try{
|
---|
502 | Properties prop = new Properties();
|
---|
503 | FileInputStream fis = new FileInputStream(filePath);
|
---|
504 | prop.load(fis);
|
---|
505 | Set s = prop.keySet();
|
---|
506 | Object[][] properties = new Object[prop.size()][2];
|
---|
507 | Iterator i = s.iterator();
|
---|
508 | int counter = 0;
|
---|
509 |
|
---|
510 | while(i.hasNext()){
|
---|
511 | String setting = (String)i.next();
|
---|
512 | String value = prop.getProperty(setting);
|
---|
513 |
|
---|
514 | properties[counter][0] = setting;
|
---|
515 | properties[counter][1] = value;
|
---|
516 | counter++;
|
---|
517 | }
|
---|
518 |
|
---|
519 | return properties;
|
---|
520 | }catch(IOException ex){
|
---|
521 | ex.printStackTrace();
|
---|
522 | return new Object[0][0];
|
---|
523 | }
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | class checkBoxStatus implements ItemListener{
|
---|
528 |
|
---|
529 | private Mat adaptee;
|
---|
530 |
|
---|
531 | public checkBoxStatus(Mat adaptee){
|
---|
532 |
|
---|
533 | this.adaptee = adaptee;
|
---|
534 | }
|
---|
535 |
|
---|
536 | public void itemStateChanged(ItemEvent e) {
|
---|
537 |
|
---|
538 | JCheckBox source = (JCheckBox)e.getItemSelectable();
|
---|
539 |
|
---|
540 | if (source == adaptee.java_tool_checkbox) {
|
---|
541 | if(source.isSelected()){
|
---|
542 | adaptee.start_button.setEnabled(true);
|
---|
543 | }
|
---|
544 | else{
|
---|
545 | adaptee.start_button.setEnabled(false);
|
---|
546 | }
|
---|
547 | }
|
---|
548 | else{
|
---|
549 | }
|
---|
550 | }
|
---|
551 | }
|
---|
552 |
|
---|
553 | class aListener implements ActionListener {
|
---|
554 |
|
---|
555 | private Mat adaptee;
|
---|
556 | Calendar cl;
|
---|
557 | SimpleDateFormat sdf;
|
---|
558 | private final String fileSeparator = File.separator;
|
---|
559 |
|
---|
560 | aListener(Mat adaptee) {
|
---|
561 |
|
---|
562 | this.adaptee = adaptee;
|
---|
563 | cl=Calendar.getInstance();
|
---|
564 | sdf = new SimpleDateFormat("dd/MMM/yyyy 'at' HH:mm:ss z 'GMT'Z");
|
---|
565 | }
|
---|
566 |
|
---|
567 | public void actionPerformed(ActionEvent e) {
|
---|
568 |
|
---|
569 | JButton button = (JButton)e.getSource();
|
---|
570 |
|
---|
571 | if(button.getName().equalsIgnoreCase("Download")){
|
---|
572 | downloadExtension();
|
---|
573 |
|
---|
574 | String msg = createInfoMsg(button.getName());
|
---|
575 | String timestamp = getTimestamp();
|
---|
576 |
|
---|
577 | //updateLOG("Download",msg , timestamp);
|
---|
578 | //adaptee.setCommandStatus("Download");
|
---|
579 | }
|
---|
580 | else if(button.getName().equalsIgnoreCase("control_description") || button.getName().equalsIgnoreCase("description_control")){
|
---|
581 | ExtPane.updateExtensionContentPane();
|
---|
582 | }
|
---|
583 | else if(button.getName().equalsIgnoreCase("options")){
|
---|
584 | configure_option();
|
---|
585 | }
|
---|
586 | else if(button.getName().equalsIgnoreCase("Install")){
|
---|
587 | installExtension();
|
---|
588 | String msg = createInfoMsg(button.getName());
|
---|
589 | String timestamp = getTimestamp();
|
---|
590 | //updateLOG("Install", msg , timestamp);
|
---|
591 | }
|
---|
592 | else if(button.getName().equalsIgnoreCase("Install_option")){
|
---|
593 | //System.out.println("--------install options-------------");
|
---|
594 | install_configuration();
|
---|
595 | }
|
---|
596 | else if(button.getName().equalsIgnoreCase("Analyse")){
|
---|
597 | execute_application();
|
---|
598 | }
|
---|
599 | else if(button.getName().equalsIgnoreCase("Uninstall")){
|
---|
600 | String msg = createInfoMsg(button.getName());
|
---|
601 | String timestamp = getTimestamp();
|
---|
602 | uninstallExtension();
|
---|
603 | adaptee.setCommandStatus("Uninstall");
|
---|
604 | updateLOG("Unistall", msg , timestamp);
|
---|
605 | }
|
---|
606 | else if(button.getName().equalsIgnoreCase("disable")){
|
---|
607 | String msg = createInfoMsg(button.getName());
|
---|
608 | String timestamp = getTimestamp();
|
---|
609 | updateLOG("Disable", msg , timestamp);
|
---|
610 | }
|
---|
611 | else if(button.getName().equalsIgnoreCase("enable")){
|
---|
612 | String msg = createInfoMsg(button.getName());
|
---|
613 | String timestamp = getTimestamp();
|
---|
614 | updateLOG("Enable", msg , timestamp);
|
---|
615 | }
|
---|
616 | }
|
---|
617 |
|
---|
618 | public void uninstallExtension(){
|
---|
619 | File temp = new File(adaptee.extension_path);
|
---|
620 | deleteDir(temp);
|
---|
621 | }
|
---|
622 |
|
---|
623 | private static boolean deleteDir(File dir) {
|
---|
624 |
|
---|
625 | if (dir.isDirectory()) {
|
---|
626 | String[] children = dir.list();
|
---|
627 | for (int i=0; i<children.length; i++) {
|
---|
628 | boolean success = deleteDir(new File(dir, children[i]));
|
---|
629 | if (!success) {
|
---|
630 | return false;
|
---|
631 | }
|
---|
632 | }
|
---|
633 | }
|
---|
634 | return dir.delete();
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|
638 | public void downloadExtension(){
|
---|
639 | MatSVNDownloadThread download = new MatSVNDownloadThread(adaptee, ExtPane.message_textarea ,adaptee.url, adaptee.destination_folder, adaptee.extension_name);
|
---|
640 | download.start();
|
---|
641 | }
|
---|
642 |
|
---|
643 | public void installExtension(){
|
---|
644 | MatExtensionInstallation ei = new MatExtensionInstallation(adaptee);
|
---|
645 | ei.start();
|
---|
646 | adaptee.description_control_button.setEnabled(adaptee.getCommandStatus("install"));
|
---|
647 | }
|
---|
648 |
|
---|
649 | public void install_configuration(){
|
---|
650 | File buildProperty = new File (adaptee.install_options_filePath);
|
---|
651 | if(!buildProperty.exists()) { return; }
|
---|
652 | Object[][] temp = adaptee.getConfiguration(adaptee.install_options_filePath);
|
---|
653 | MatExtensionConfigurePrompt ecp = new MatExtensionConfigurePrompt(temp,adaptee.install_options_filePath,adaptee.extension_name,"Configure Install Settings");
|
---|
654 | ecp.display();
|
---|
655 | }
|
---|
656 |
|
---|
657 | public void configure_option(){
|
---|
658 | String gsdl3Home = adaptee.get_GSDL3HOME();
|
---|
659 | File buildProperty = new File (adaptee.extension_runtimeProperty_path);
|
---|
660 | if(!buildProperty.exists()) { return; }
|
---|
661 | Object[][] temp = adaptee.getConfiguration(adaptee.extension_runtimeProperty_path);
|
---|
662 | MatExtensionConfigurePrompt ecp = new MatExtensionConfigurePrompt(temp,adaptee.extension_runtimeProperty_path,adaptee.extension_name,"Configure Runtime Settings");
|
---|
663 | ecp.display();
|
---|
664 | }
|
---|
665 |
|
---|
666 | public void execute_application(){
|
---|
667 | MatLaunchApplication app = new MatLaunchApplication(adaptee);
|
---|
668 | app.start();
|
---|
669 | }
|
---|
670 |
|
---|
671 | public String createInfoMsg(String step){
|
---|
672 |
|
---|
673 | String info = new String();
|
---|
674 |
|
---|
675 | if(step.equalsIgnoreCase(adminUI_Pane.DOWNLOAD)){
|
---|
676 | info = "The extension Mat has been downloaded to local folder";
|
---|
677 | }
|
---|
678 | else if (step.equalsIgnoreCase(adminUI_Pane.INSTALL)){
|
---|
679 | info = "The extension Mat has been installed";
|
---|
680 | }
|
---|
681 | else if (step.equalsIgnoreCase(adminUI_Pane.UNINSTALL)){
|
---|
682 | info = "The extension Mat has been uninstalled";
|
---|
683 | }
|
---|
684 | else if (step.equalsIgnoreCase(adminUI_Pane.ENABLE)){
|
---|
685 | info = "The OAI Web Building has been enabled";
|
---|
686 | }
|
---|
687 | else if (step.equalsIgnoreCase(adminUI_Pane.DISABLE)){
|
---|
688 | info = "The OAI Web Building has been disabled";
|
---|
689 | }
|
---|
690 |
|
---|
691 | return info;
|
---|
692 | }
|
---|
693 |
|
---|
694 | public String getTimestamp(){
|
---|
695 |
|
---|
696 | String timestamp = sdf.format(cl.getTime());
|
---|
697 | return timestamp;
|
---|
698 | }
|
---|
699 |
|
---|
700 | public void updateLOG(String type , String info, String timestamp){
|
---|
701 |
|
---|
702 | Element root = null;
|
---|
703 |
|
---|
704 | try{
|
---|
705 | DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
|
---|
706 | DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
|
---|
707 | Document doc = docBuilder.newDocument();
|
---|
708 | String gsdl3Home = adaptee.get_GSDL3HOME();
|
---|
709 |
|
---|
710 | File logFile = new File(adaptee.extension_log_path);
|
---|
711 | boolean fileExist = logFile.exists();
|
---|
712 |
|
---|
713 | File logDir = new File(adaptee.extension_log_directory);
|
---|
714 | if(logDir.mkdirs()){}
|
---|
715 |
|
---|
716 | if(!fileExist){
|
---|
717 | logFile.createNewFile();
|
---|
718 | root = doc.createElement("log");
|
---|
719 | }
|
---|
720 | else{
|
---|
721 |
|
---|
722 | doc = docBuilder.parse (new File(adaptee.extension_log_path));
|
---|
723 | root = doc.getDocumentElement();
|
---|
724 | }
|
---|
725 |
|
---|
726 | Element actElement = doc.createElement("action");
|
---|
727 | actElement.setAttribute("type", type);
|
---|
728 | Element timeElement = doc.createElement("time");
|
---|
729 | Element infoElement = doc.createElement("info");
|
---|
730 | Text text_info = doc.createTextNode(info);
|
---|
731 | infoElement.appendChild(text_info);
|
---|
732 |
|
---|
733 | Text text_time = doc.createTextNode(timestamp);
|
---|
734 | timeElement.appendChild(text_time);
|
---|
735 | actElement.appendChild(infoElement);
|
---|
736 | actElement.appendChild(timeElement);
|
---|
737 | root.appendChild(actElement);
|
---|
738 |
|
---|
739 | TransformerFactory tf= TransformerFactory.newInstance();
|
---|
740 | Transformer transformer= tf.newTransformer();
|
---|
741 | DOMSource source= new DOMSource(root);
|
---|
742 | transformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
---|
743 |
|
---|
744 | Writer pwx= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(adaptee.extension_log_path),"UTF-8"));
|
---|
745 | StreamResult result= new StreamResult(pwx);
|
---|
746 | transformer.transform(source,result);
|
---|
747 | pwx.close();
|
---|
748 |
|
---|
749 | }catch(Exception ex){
|
---|
750 | ex.printStackTrace();
|
---|
751 | }
|
---|
752 | }
|
---|
753 | }
|
---|