source: gs3-extensions/mat/trunk/src/org/greenstone/admin/guiext/Mat.java@ 21921

Last change on this file since 21921 was 21921, checked in by sjm84, 14 years ago

Moving these file to here temporarily, most of them will be deleted later

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