source: greenstone3/trunk/src/java/org/greenstone/admin/gui/adminUI_Pane.java@ 18158

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

change the snytax of regular expression

File size: 4.0 KB
Line 
1package org.greenstone.admin.gui;
2
3import java.awt.Insets;
4import java.io.File;
5
6import javax.swing.JPanel;
7import javax.swing.JScrollPane;
8import javax.swing.JTextArea;
9import javax.xml.parsers.DocumentBuilder;
10import javax.xml.parsers.DocumentBuilderFactory;
11
12import org.greenstone.gsdl3.util.GSPath;
13import org.greenstone.gsdl3.util.GlobalProperties;
14import org.w3c.dom.*;
15
16public abstract class adminUI_Pane {
17
18 static JScrollPane description_pane;
19 static JPanel main_pane;
20 static JPanel control_pane;
21 static JTextArea descriptionTextArea;
22 static String description;
23
24 JPanel button_pane;
25 String extension_name;
26 String destination_folder;
27 String url;
28 String group;
29 String download_type;
30 Boolean configurable;
31
32 static final String EXTENSION = "extension";
33 static final String GROUP = "group";
34 static final String ADMIN_UI = "admin_ui";
35 static final String NAME = "name";
36 static final String DOWNLOAD = "download";
37 static final String INSTALL = "install";
38 static final String UNINSTALL = "uninstall";
39 static final String ENABLE = "enable";
40 static final String DISABLE = "disable";
41 static final String DESTINATION = "destination";
42 static final String DESCRIPTION = "description";
43 static final String PROPERTY = "property";
44 static final String STEP ="step";
45
46 GlobalProperties globalProperty = null;
47 String fileSeparator = File.separator;
48 GSPath gspath = null;
49
50 public adminUI_Pane(){
51
52 }
53
54 public void setup(){
55
56 descriptionTextArea.setText("");
57 description = loadDescription(extension_name);
58 descriptionTextArea = new JTextArea();
59 descriptionTextArea.setText("");
60 descriptionTextArea.append(description);
61 descriptionTextArea.setEditable(false);
62 descriptionTextArea.setLineWrap(true);
63 descriptionTextArea.setWrapStyleWord(true);
64 descriptionTextArea.setMargin(new Insets(0,ExtPane.left_padding,0,0));
65
66 description_pane = new JScrollPane(descriptionTextArea);
67 description_pane.setAutoscrolls(true);
68 }
69
70 public JPanel getControlPane(){
71 return control_pane;
72 }
73
74
75 public String get_GSDL3HOME(){
76
77 String gsdl3Home = globalProperty.getGSDL3Home();
78 String os = "linux";
79
80 if(System.getProperty("os.name").toLowerCase().indexOf("windows")!=-1){
81 gsdl3Home = gsdl3Home.replaceAll("\\\\", "/");
82 os = "windows";
83
84 }
85
86 gsdl3Home = gspath.removeLastLink(gsdl3Home);
87
88 if(os.equals("windows")){
89 gsdl3Home = gsdl3Home.replaceAll("/", "\\\\");
90 }
91
92 return gsdl3Home;
93 }
94
95 public String loadDescription(String className){
96
97 String gsdl3Home = get_GSDL3HOME();
98 Element rootNode = getRootElement(gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml");
99 NodeList projectNodeList = rootNode.getElementsByTagName(EXTENSION);
100
101 for(int i = 0; i < projectNodeList.getLength(); i++){
102
103 Element projectNode = (Element)projectNodeList.item(i);
104 NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
105 String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
106
107 if(name.equals(className)){
108 NodeList descriptionNodeList = projectNode.getElementsByTagName(DESCRIPTION);
109 description = descriptionNodeList.item(0).getChildNodes().item(0).getNodeValue();
110 }
111 }
112 return description;
113 }
114
115 protected Element getRootElement(String url){
116
117 Element rootNode = null;
118 try{
119 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
120 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
121 Document doc = docBuilder.newDocument();
122 doc = docBuilder.parse (new File(url));
123 rootNode = doc.getDocumentElement();
124 return rootNode;
125 }catch (Exception e) {
126 e.printStackTrace();
127 return null;
128 }
129 }
130
131 protected abstract Object[][] getConfigureContent();
132
133 protected abstract Boolean isConfigurable();
134
135 public JPanel getButtonPane(){
136 return button_pane;
137 }
138}
Note: See TracBrowser for help on using the repository browser.