source: greenstone3/trunk/src/java/org/greenstone/admin/gui/Mat.java@ 18240

Last change on this file since 18240 was 18240, checked in by cc108, 15 years ago

fix some bugs

File size: 24.0 KB
Line 
1package org.greenstone.admin.gui;
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;
34import org.greenstone.gsdl3.util.GSPath;
35import org.greenstone.gsdl3.util.GlobalProperties;
36
37
38import org.w3c.dom.Document;
39import org.w3c.dom.Element;
40import org.w3c.dom.Node;
41import org.w3c.dom.NodeList;
42import org.w3c.dom.Text;
43
44import java.text.SimpleDateFormat;
45import java.util.ArrayList;
46import java.util.Calendar;
47import java.util.Iterator;
48import java.util.Properties;
49import java.util.Set;
50
51
52public 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 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
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
519class 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
545class 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 SVNDownloadThread download = new SVNDownloadThread(adaptee, ExtPane.message_textarea ,adaptee.url, adaptee.destination_folder, adaptee.extension_name);
632 download.start();
633 }
634
635 public void installExtension(){
636 ExtensionInstallation ei = new ExtensionInstallation(adaptee);
637 ei.start();
638 adaptee.description_control_button.setEnabled(adaptee.getCommandStatus("install"));
639 }
640
641 public void install_configuration(){
642 File buildProperty = new File (adaptee.install_options_filePath);
643 if(!buildProperty.exists()) { return; }
644 Object[][] temp = adaptee.getConfiguration(adaptee.install_options_filePath);
645 ExtensionConfigurePrompt ecp = new ExtensionConfigurePrompt(temp,adaptee.install_options_filePath,adaptee.extension_name,"Configure Install Settings");
646 ecp.display();
647 }
648
649 public void configure_option(){
650 String gsdl3Home = adaptee.get_GSDL3HOME();
651 File buildProperty = new File (adaptee.extension_runtimeProperty_path);
652 if(!buildProperty.exists()) { return; }
653 Object[][] temp = adaptee.getConfiguration(adaptee.extension_runtimeProperty_path);
654 ExtensionConfigurePrompt ecp = new ExtensionConfigurePrompt(temp,adaptee.extension_runtimeProperty_path,adaptee.extension_name,"Configure Runtime Settings");
655 ecp.display();
656 }
657
658 public void execute_application(){
659 LaunchApplication app = new LaunchApplication(adaptee);
660 app.start();
661 }
662
663 public String createInfoMsg(String step){
664
665 String info = new String();
666
667 if(step.equalsIgnoreCase(adminUI_Pane.DOWNLOAD)){
668 info = "The extension Mat has been downloaded to local folder";
669 }
670 else if (step.equalsIgnoreCase(adminUI_Pane.INSTALL)){
671 info = "The extension Mat has been installed";
672 }
673 else if (step.equalsIgnoreCase(adminUI_Pane.UNINSTALL)){
674 info = "The extension Mat has been uninstalled";
675 }
676 else if (step.equalsIgnoreCase(adminUI_Pane.ENABLE)){
677 info = "The OAI Web Building has been enabled";
678 }
679 else if (step.equalsIgnoreCase(adminUI_Pane.DISABLE)){
680 info = "The OAI Web Building has been disabled";
681 }
682
683 return info;
684 }
685
686 public String getTimestamp(){
687
688 String timestamp = sdf.format(cl.getTime());
689 return timestamp;
690 }
691
692 public void updateLOG(String type , String info, String timestamp){
693
694 Element root = null;
695
696 try{
697 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
698 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
699 Document doc = docBuilder.newDocument();
700 String gsdl3Home = adaptee.get_GSDL3HOME();
701
702 File logFile = new File(adaptee.extension_log_path);
703 boolean fileExist = logFile.exists();
704
705 File logDir = new File(adaptee.extension_log_directory);
706 if(logDir.mkdirs()){}
707
708 if(!fileExist){
709 logFile.createNewFile();
710 root = doc.createElement("log");
711 }
712 else{
713
714 doc = docBuilder.parse (new File(adaptee.extension_log_path));
715 root = doc.getDocumentElement();
716 }
717
718 Element actElement = doc.createElement("action");
719 actElement.setAttribute("type", type);
720 Element timeElement = doc.createElement("time");
721 Element infoElement = doc.createElement("info");
722 Text text_info = doc.createTextNode(info);
723 infoElement.appendChild(text_info);
724
725 Text text_time = doc.createTextNode(timestamp);
726 timeElement.appendChild(text_time);
727 actElement.appendChild(infoElement);
728 actElement.appendChild(timeElement);
729 root.appendChild(actElement);
730
731 TransformerFactory tf= TransformerFactory.newInstance();
732 Transformer transformer= tf.newTransformer();
733 DOMSource source= new DOMSource(root);
734 transformer.setOutputProperty(OutputKeys.INDENT,"yes");
735
736 Writer pwx= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(adaptee.extension_log_path),"UTF-8"));
737 StreamResult result= new StreamResult(pwx);
738 transformer.transform(source,result);
739 pwx.close();
740
741 }catch(Exception ex){
742 ex.printStackTrace();
743 }
744 }
745}
Note: See TracBrowser for help on using the repository browser.