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