1 | package org.greenstone.admin.guiext;
|
---|
2 |
|
---|
3 | import org.w3c.dom.Element;
|
---|
4 | import org.w3c.dom.NodeList;
|
---|
5 |
|
---|
6 | import java.net.URLClassLoader;
|
---|
7 | import java.net.URL;
|
---|
8 |
|
---|
9 | import java.lang.reflect.Method;
|
---|
10 | import java.lang.reflect.Constructor;
|
---|
11 |
|
---|
12 | import java.io.File;
|
---|
13 |
|
---|
14 | import java.awt.BorderLayout;
|
---|
15 |
|
---|
16 | import javax.swing.JTextArea;
|
---|
17 | import javax.swing.JPanel;
|
---|
18 |
|
---|
19 | import org.greenstone.admin.GAI;
|
---|
20 |
|
---|
21 | public class ExtensionInformation
|
---|
22 | {
|
---|
23 | protected String _name = null;
|
---|
24 | protected String _group = null;
|
---|
25 | protected String _fileStem = null;
|
---|
26 | protected String _description = null;
|
---|
27 | protected String _baseURL = null;
|
---|
28 | protected SequenceList _sequenceList= null;
|
---|
29 | protected boolean _guiExtLoaded = false;
|
---|
30 |
|
---|
31 | protected static JPanel _extPane = new JPanel();
|
---|
32 |
|
---|
33 | public ExtensionInformation(Element extensionElement, String baseURL){
|
---|
34 | if(extensionElement != null){
|
---|
35 | _name = ExtXMLHelper.getValueFromSingleElement(extensionElement, ExtXMLHelper.NAME, true);
|
---|
36 | _group = ExtXMLHelper.getValueFromSingleElement(extensionElement, ExtXMLHelper.GROUP, true);
|
---|
37 | _fileStem = ExtXMLHelper.getValueFromSingleElement(extensionElement, ExtXMLHelper.FILE_STEM, true);
|
---|
38 | _description = ExtXMLHelper.getValueFromSingleElement(extensionElement, ExtXMLHelper.DESCRIPTION, true);
|
---|
39 | _baseURL = baseURL;
|
---|
40 | _sequenceList = new SequenceList(ExtXMLHelper.getSingleChildElement(extensionElement, ExtXMLHelper.SEQUENCE_LIST, true), this);
|
---|
41 | }
|
---|
42 | else{
|
---|
43 | System.err.println("<" + ExtXMLHelper.EXTENSION + "> element is null");
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public String getBaseURL()
|
---|
48 | {
|
---|
49 | return _baseURL;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public String getName()
|
---|
53 | {
|
---|
54 | return _name;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public String getGroup()
|
---|
58 | {
|
---|
59 | return _group;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public String getFileStem()
|
---|
63 | {
|
---|
64 | return _fileStem;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public String getDescription()
|
---|
68 | {
|
---|
69 | return _description;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public SequenceList getSequenceList()
|
---|
73 | {
|
---|
74 | return _sequenceList;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void loadExternalJar(String filename){
|
---|
78 | //Load the dynamic jar loader
|
---|
79 | URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
---|
80 | Class sysclass = URLClassLoader.class;
|
---|
81 | final Class[] parameters = new Class[]{URL.class};
|
---|
82 | Method method = null;
|
---|
83 | try{
|
---|
84 | method = sysclass.getDeclaredMethod("addURL", parameters);
|
---|
85 | }
|
---|
86 | catch(Exception ex){
|
---|
87 | ex.printStackTrace();
|
---|
88 | }
|
---|
89 | method.setAccessible(true);
|
---|
90 |
|
---|
91 | File externalFile = new File(filename);
|
---|
92 | if(!externalFile.exists()){
|
---|
93 | System.err.println("Cannot load the external jar file at " + filename + " as it does not exist");
|
---|
94 | return;
|
---|
95 | }
|
---|
96 |
|
---|
97 | try {
|
---|
98 | URL u = new URL(externalFile.toURI().toURL().toString());
|
---|
99 | method.invoke(sysloader, new Object[]{u});
|
---|
100 | } catch (Throwable t) {
|
---|
101 | t.printStackTrace();
|
---|
102 | }
|
---|
103 |
|
---|
104 | _guiExtLoaded = true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | public void loadGuiExtFile()
|
---|
108 | {
|
---|
109 | if(!_guiExtLoaded){
|
---|
110 | loadExternalJar(getExtensionDirectory() + System.getProperty("file.separator") + "guiext.jar");
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | public boolean isGuiExtLoaded()
|
---|
115 | {
|
---|
116 | return _guiExtLoaded;
|
---|
117 | }
|
---|
118 |
|
---|
119 | public void changeExtPane(JPanel extPane)
|
---|
120 | {
|
---|
121 | _extPane.removeAll();
|
---|
122 | _extPane.add(extPane, BorderLayout.CENTER);
|
---|
123 | _extPane.revalidate();
|
---|
124 | _extPane.repaint();
|
---|
125 | }
|
---|
126 |
|
---|
127 | public static void setExtPane(JPanel extPane)
|
---|
128 | {
|
---|
129 | _extPane = extPane;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public JPanel getExtPane()
|
---|
133 | {
|
---|
134 | return _extPane;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public String getExtensionDirectory()
|
---|
138 | {
|
---|
139 | return GAI.getGSDL3ExtensionHome() + System.getProperty("file.separator") + _fileStem;
|
---|
140 | }
|
---|
141 | } |
---|