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