1
15
16 package gate;
17
18 import java.io.*;
19 import java.net.*;
20 import java.util.*;
21 import org.jdom.Element;
22 import org.jdom.JDOMException;
23 import org.jdom.input.SAXBuilder;
24
25 import gate.config.ConfigDataProcessor;
26 import gate.creole.CreoleRegisterImpl;
27 import gate.creole.ResourceData;
28 import gate.event.CreoleListener;
29 import gate.util.*;
30
31
35 public class Gate implements GateConstants
36 {
37
38 private static final boolean DEBUG = false;
39
40
45 public static final int STRINGBUFFER_SIZE = 1024;
46
47
53 public static final int HASH_STH_SIZE = 4;
54
55
56
62 public static final String DB_OWNER = "gateadmin";
63
64
65
66 private static String builtinCreoleDirectoryUrls[] = {
67
69 };
73
74
75
76 public static final String URI = "http://www.gate.ac.uk";
77
78
79 protected static final String MIN_JDK_VERSION = "1.4";
80
81
82 public static String getMinJdkVersion() { return MIN_JDK_VERSION; }
83
84
89 public static void init() throws GateException {
90 initLocalPaths();
92
93 System.setProperty(
95 "java.protocol.handler.pkgs",
96 System.getProperty("java.protocol.handler.pkgs")
97 + "|" + "gate.util.protocols"
98 );
99
100
103 lastSym = 0;
105
106 if(classLoader == null)
108 classLoader = new GateClassLoader(Gate.class.getClassLoader());
109 if(creoleRegister == null)
110 creoleRegister = new CreoleRegisterImpl();
111 if(knownPlugins == null) knownPlugins = new ArrayList();
112 if(autoloadPlugins == null) autoloadPlugins = new ArrayList();
113 if(pluginData == null) pluginData = new HashMap();
114 initCreoleRegister();
116 initDataStoreRegister();
118 initConfigData();
121
122 initCreoleRepositories();
123 dataStoreRegister.addCreoleListener(creoleRegister);
125
126 Factory.addCreoleListener(creoleRegister);
128
129 if(System.getProperty("java.version").compareTo(MIN_JDK_VERSION) < 0) {
131 throw new GateException(
132 "GATE requires JDK " + MIN_JDK_VERSION + " or newer"
133 );
134 }
135
136 try{
138 registerIREngine("gate.creole.ir.lucene.LuceneIREngine");
139 }catch(ClassNotFoundException cnfe){
140 throw new GateRuntimeException(cnfe);
141 }
142 }
144
148 protected static void initLocalPaths(){
149 if(gateHome == null){
151 String gateHomeStr = System.getProperty(GATE_HOME_PROPERTY_NAME);
152 if(gateHomeStr != null && gateHomeStr.length() > 0){
153 gateHome = new File(gateHomeStr);
154 }
155 if(gateHome == null || !gateHome.exists()){
157 System.err.println("GATE home system property (\"" +
158 GATE_HOME_PROPERTY_NAME + "\") not set.\nAttempting to guess...");
159 URL gateURL = Thread.currentThread().getContextClassLoader().
160 getResource("gate/Gate.class");
161 try{
162 if(gateURL.getProtocol().equals("jar")){
163 String gateURLStr = gateURL.getFile();
165 File gateJarFile = new File(
166 new URL(gateURLStr.substring(0, gateURLStr.indexOf('!'))).
167 getFile());
168 gateHome = gateJarFile.getParentFile().getParentFile();
169 }else if(gateURL.getProtocol().equals("file")){
170 File gateClassFile = new File(gateURL.getFile());
172 gateHome = gateClassFile.getParentFile().
173 getParentFile().getParentFile();
174 }
175 System.err.println("Using \"" +
176 gateHome.getCanonicalPath() +
177 "\" as GATE Home.\nIf this is not correct please set it manually" +
178 " using the -D" + GATE_HOME_PROPERTY_NAME +
179 " option in your start-up script");
180 }catch(Throwable thr){
181 throw new GateRuntimeException(
182 "Cannot guess GATE Home. Pease set it manually!", thr);
183 }
184 }
185 }
186 System.out.println("Using " + gateHome.toString() + " as GATE home");
187
188 if(pluginsHome == null){
190 String pluginsHomeStr = System.getProperty(PLUGINS_HOME_PROPERTY_NAME);
191 if(pluginsHomeStr != null && pluginsHomeStr.length() > 0){
192 File homeFile = new File(pluginsHomeStr);
193 if(homeFile.exists() && homeFile.isDirectory()){
194 pluginsHome = homeFile;
195 }
196 }
197 if(pluginsHome == null){
199 File homeFile = new File(gateHome, PLUGINS);
200 if(homeFile.exists() && homeFile.isDirectory()){
201 pluginsHome = homeFile;
202 }
203 }
204 if(pluginsHome == null){
206 throw new GateRuntimeException(
207 "Could not infer installed plug-ins home!\n" +
208 "Please set it manually using the -D" +
209 PLUGINS_HOME_PROPERTY_NAME + " option in your start-up script.");
210 }
211 }
212 System.out.println("Using " + pluginsHome.toString() +
213 " as installed plug-ins directory.");
214
215 if(siteConfigFile == null){
217 String siteConfigStr = System.getProperty(SITE_CONFIG_PROPERTY_NAME);
218 if(siteConfigStr != null && siteConfigStr.length() > 0){
219 File configFile = new File(siteConfigStr);
220 if(configFile.exists()) siteConfigFile = configFile;
221 }
222 if(siteConfigFile == null){
224 File configFile = new File(gateHome, GATE_DOT_XML);
225 if(configFile.exists()) siteConfigFile = configFile;
226 }
227 if(siteConfigFile == null){
229 throw new GateRuntimeException(
230 "Could not locate the site configuration file!\n" +
231 "Please create it at " +
232 new File(gateHome, GATE_DOT_XML).toString() +
233 " or point to an existing one using the -D" +
234 SITE_CONFIG_PROPERTY_NAME + " option in your start-up script!");
235 }
236 }
237 System.out.println("Using " + siteConfigFile.toString() +
238 " as site configuration file.");
239
240 if(userConfigFile == null){
242 String userConfigStr = System.getProperty(USER_CONFIG_PROPERTY_NAME);
243 if(userConfigStr != null && userConfigStr.length() > 0){
244 File configFile = new File(userConfigStr);
245 if(configFile.exists()) userConfigFile = configFile;
246 }
247 if(userConfigFile == null){
249 userConfigFile = new File(
250 System.getProperty("user.home") +
251 Strings.getFileSep() +
252 (runningOnUnix() ? "." : "") +
253 GATE_DOT_XML);
254 }
255 System.out.println("Using " + userConfigFile + " as user configuration file");
256 }
257 }
258
259
264 protected static void initCreoleRepositories(){
265
272 String knownPluginsPath = (String)getUserConfig().get(KNOWN_PLUGIN_PATH_KEY);
274 if(knownPluginsPath != null && knownPluginsPath.length() > 0){
275 StringTokenizer strTok = new StringTokenizer(knownPluginsPath, ";", false);
276 while(strTok.hasMoreTokens()){
277 String aKnownPluginPath = strTok.nextToken();
278 try{
279 URL aPluginURL = new URL(aKnownPluginPath);
280 addKnownPlugin(aPluginURL);
281 }catch(MalformedURLException mue){
282 Err.prln("Plugin error: " + aKnownPluginPath + " is an invalid URL!");
283 }
284 }
285 }
286 File pluginsHome = new File(System.getProperty(GATE_HOME_PROPERTY_NAME),
288 "plugins");
289 File[] dirs = pluginsHome.listFiles();
290 for(int i = 0; i < dirs.length; i++){
291 File creoleFile = new File(dirs[i], "creole.xml");
292 if(creoleFile.exists()){
293 try{
294 URL pluginURL = dirs[i].toURL();
295 addKnownPlugin(pluginURL);
296 }catch(MalformedURLException mue){
297 throw new GateRuntimeException(mue);
299 }
300 }
301 }
302
303 String pluginPath = getUserConfig().getString(AUTOLOAD_PLUGIN_PATH_KEY);
305 String prop = System.getProperty(AUTOLOAD_PLUGIN_PATH_PROPERTY_NAME);
307 if(prop != null && prop.length() > 0) pluginPath = prop;
308
309 if(pluginPath == null || pluginPath.length() == 0){
310 try{
312 pluginPath = new File(pluginsHome, "ANNIE/").toURL().toString();
313 getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, pluginPath);
314 }catch(MalformedURLException mue){
315 throw new GateRuntimeException(mue);
316 }
317 }
318
319 StringTokenizer strTok = new StringTokenizer(pluginPath,
321 ";", false);
322 while(strTok.hasMoreTokens()){
323 String aDir = strTok.nextToken();
324 try{
325 URL aPluginURL = new URL(aDir);
326 addAutoloadPlugin(aPluginURL);
327 }catch(MalformedURLException mue){
328 System.err.println("Cannot load " + aDir + " CREOLE repository.");
329 mue.printStackTrace();
330 }
331 try{
332 Iterator loadPluginsIter = getAutoloadPlugins().iterator();
333 while(loadPluginsIter.hasNext()){
334 getCreoleRegister().registerDirectories((URL)loadPluginsIter.next());
335 }
336 }catch(GateException ge){
337 System.err.println("Cannot load " + aDir + " CREOLE repository.");
338 ge.printStackTrace();
339 }
340 }
341 }
342
343
344 public static void initCreoleRegister() throws GateException {
345
346 for(int i=0; i<builtinCreoleDirectoryUrls.length; i++)
348 try {
349 creoleRegister.addDirectory(
350 new URL(builtinCreoleDirectoryUrls[i])
351 );
352 } catch(MalformedURLException e) {
353 throw new GateException(e);
354 }
355
356
360
364 creoleRegister.registerBuiltins();
366 }
368
369 public static void initDataStoreRegister() {
370 dataStoreRegister = new DataStoreRegister();
371 }
373
388 public static void initConfigData() throws GateException {
389 ConfigDataProcessor configProcessor = new ConfigDataProcessor();
390 URL configURL;
392 try{
393 configURL = siteConfigFile.toURL();
394 }catch(MalformedURLException mue){
395 throw new GateRuntimeException(mue);
397 }
398 try {
399 InputStream configStream = new FileInputStream(siteConfigFile);
400 configProcessor.parseConfigFile(configStream, configURL);
401 } catch(IOException e) {
402 throw new GateException(
403 "Couldn't open site configuration file: " + configURL + " " + e
404 );
405 }
406
407 if(userConfigFile != null && userConfigFile.exists()){
409 try{
410 configURL = userConfigFile.toURL();
411 }catch(MalformedURLException mue){
412 throw new GateRuntimeException(mue);
414 }
415 try {
416 InputStream configStream = new FileInputStream(userConfigFile);
417 configProcessor.parseConfigFile(configStream, configURL);
418 } catch(IOException e) {
419 throw new GateException(
420 "Couldn't open user configuration file: " + configURL + " " + e
421 );
422 }
423 }
424
425 originalUserConfig.putAll(userConfig);
427
428 if(DEBUG) {
429 Out.prln(
430 "user config loaded; DBCONFIG=" + DataStoreRegister.getConfigData()
431 );
432 }
433 }
435
438 public static String guessUnicodeFont(){
439 String[] fontNames = java.awt.GraphicsEnvironment.
441 getLocalGraphicsEnvironment().
442 getAvailableFontFamilyNames();
443 String unicodeFontName = null;
444 for(int i = 0; i < fontNames.length; i++){
445 if(fontNames[i].equalsIgnoreCase("Arial Unicode MS")){
446 unicodeFontName = fontNames[i];
447 break;
448 }
449 if(fontNames[i].toLowerCase().indexOf("unicode") != -1){
450 unicodeFontName = fontNames[i];
451 }
452 } return unicodeFontName;
454 }
455
456
484 public static URL getUrl() throws GateException {
485 if(urlBase != null) return urlBase;
486
487 try {
488
489 if(isNetConnected()) {
491 if(
492 tryNetServer("gate-internal.dcs.shef.ac.uk", 80, "/") ||
493 tryNetServer("gate.ac.uk", 80, "/")
495 ) {
496 if(DEBUG) Out.prln("getUrl() returned " + urlBase);
497 return urlBase;
498 }
499 }
501 if(
505 isLocalWebServer() &&
506 tryNetServer(
507 InetAddress.getLocalHost().getHostName(), 80, "/gate.ac.uk/"
508 )
509 ) {
510 if(DEBUG) Out.prln("getUrlBase() returned " + urlBase);
511 return urlBase;
512 }
513
514 tryFileSystem();
516
517 } catch(MalformedURLException e) {
518 throw new GateException("Bad URL, getUrlBase(): " + urlBase + ": " + e);
519 } catch(UnknownHostException e) {
520 throw new GateException("No host, getUrlBase(): " + urlBase + ": " + e);
521 }
522
523 if(DEBUG) Out.prln("getUrlBase() returned " + urlBase);
525 return urlBase;
526 }
528
535 public static URL getUrl(String path) throws GateException {
536 getUrl();
537 if(urlBase == null)
538 return null;
539
540 URL newUrl = null;
541 try {
542 newUrl = new URL(urlBase, path);
543 } catch(MalformedURLException e) {
544 throw new GateException("Bad URL, getUrl( " + path + "): " + e);
545 }
546
547 if(DEBUG) Out.prln("getUrl(" + path + ") returned " + newUrl);
548 return newUrl;
549 }
551
554 private static boolean netConnected = true;
555
556 private static int lastSym;
557
558
562 private static Set registeredIREngines = new HashSet();
563
564
572 public static void registerIREngine(String className)
573 throws GateException, ClassNotFoundException{
574 Class aClass = Class.forName(className);
575 if(gate.creole.ir.IREngine.class.isAssignableFrom(aClass)){
576 registeredIREngines.add(className);
577 }else{
578 throw new GateException(className + " does not implement the " +
579 gate.creole.ir.IREngine.class.getName() +
580 " interface!");
581 }
582 }
583
584
590 public static boolean unregisterIREngine(String className){
591 return registeredIREngines.remove(className);
592 }
593
594
598 public static Set getRegisteredIREngines(){
599 return Collections.unmodifiableSet(registeredIREngines);
600 }
601
602
606 public static File getGateHome(){
607 return gateHome;
608 }
609
610
611 public static boolean isNetConnected() { return netConnected; }
612
613
617 public static void setNetConnected(boolean b) { netConnected = b; }
618
619
624 private static boolean localWebServer = true;
625
626
627 public static boolean isLocalWebServer() { return localWebServer; }
628
629
630 public static void setLocalWebServer(boolean b) { localWebServer = b; }
631
632
640 public static boolean tryNetServer(
641 String hostName, int serverPort, String path
642 ) throws MalformedURLException {
643 Socket socket = null;
644 if(DEBUG)
645 Out.prln(
646 "tryNetServer(hostName=" + hostName + ", serverPort=" + serverPort +
647 ", path=" + path +")"
648 );
649
650 try{
652 URL url = new URL("http://" + hostName + ":" + serverPort + "/");
653 URLConnection uConn = url.openConnection();
654 HttpURLConnection huConn = null;
655 if(uConn instanceof HttpURLConnection)
656 huConn = (HttpURLConnection)uConn;
657 if(huConn.getResponseCode() == -1) return false;
658 } catch (IOException e){
659 return false;
660 }
661
662 urlBase = new URL("http", hostName, serverPort, path);
664 return true;
665
667 }
670
671 protected static boolean tryFileSystem() throws MalformedURLException {
672 String urlBaseName = locateGateFiles();
673 if(DEBUG) Out.prln("tryFileSystem: " + urlBaseName);
674
675 urlBase = new URL(urlBaseName + "gate/resources/gate.ac.uk/");
676 return urlBase == null;
677 }
679
683 public static String locateGateFiles() {
684 String aGateResourceName = "gate/resources/creole/creole.xml";
685 URL resourcesUrl = Gate.getClassLoader().getResource(aGateResourceName);
686
687 StringBuffer basePath = new StringBuffer(resourcesUrl.toExternalForm());
688 String urlBaseName =
689 basePath.substring(0, basePath.length() - aGateResourceName.length());
690
691 return urlBaseName;
692 }
694
697 public static boolean isGateType(String classname){
698 boolean res = getCreoleRegister().containsKey(classname);
699 if(!res){
700 try{
701 Class aClass = Class.forName(classname);
702 res = Resource.class.isAssignableFrom(aClass) ||
703 Controller.class.isAssignableFrom(aClass) ||
704 DataStore.class.isAssignableFrom(aClass);
705 }catch(ClassNotFoundException cnfe){
706 return false;
707 }
708 }
709 return res;
710 }
711
712
713 static public boolean getHiddenAttribute(FeatureMap fm){
714 if(fm == null) return false;
715 Object value = fm.get("gate.HIDDEN");
716 return value != null &&
717 value instanceof String &&
718 ((String)value).equals("true");
719 }
720
721
722 static public void setHiddenAttribute(FeatureMap fm, boolean hidden){
723 if(hidden){
724 fm.put("gate.HIDDEN", "true");
725 }else{
726 fm.remove("gate.HIDDEN");
727 }
728 }
729
730
731
733 public static synchronized void addCreoleListener(CreoleListener l){
734 creoleRegister.addCreoleListener(l);
735 }
737
738 public static void setUrlBase(URL urlBase) { Gate.urlBase = urlBase; }
739
740
741 private static URL urlBase = null;
742
743
746 private static GateClassLoader classLoader = null;
747
748
749 public static GateClassLoader getClassLoader() { return classLoader; }
750
751
752 private static CreoleRegister creoleRegister = null;
753
754
755 public static CreoleRegister getCreoleRegister() { return creoleRegister; }
756
757
758 private static DataStoreRegister dataStoreRegister = null;
759
760
763 private static gate.Executable currentExecutable;
764
765
766 public static DataStoreRegister getDataStoreRegister() {
767 return dataStoreRegister;
768 }
770
777 public synchronized static void setExecutable(gate.Executable executable) {
778 if(executable == null) currentExecutable = executable;
779 else{
780 while(getExecutable() != null){
781 try{
782 Thread.sleep(200);
783 }catch(InterruptedException ie){
784 throw new LuckyException(ie.toString());
785 }
786 }
787 currentExecutable = executable;
788 }
789 }
791
795 public synchronized static gate.Executable getExecutable() {
796 return currentExecutable;
797 }
799
800
803 public synchronized static String genSym() {
804 StringBuffer buff = new StringBuffer(Integer.toHexString(lastSym++).
805 toUpperCase());
806 for(int i = buff.length(); i <= 4; i++) buff.insert(0, '0');
807 return buff.toString();
808 }
810
811 private static OptionsMap userConfig = new OptionsMap();
812
813
817 private static OptionsMap originalUserConfig = new OptionsMap();
818
819
820 private static String userConfigElement = "GATECONFIG";
821
822
826 public static String getUserConfigElement() { return userConfigElement; }
827
828
834 public static File getSiteConfigFile() {
835 if(siteConfigFile == null) {
836 String gateConfigProperty = System.getProperty(GATE_CONFIG_PROPERTY);
837 if(gateConfigProperty != null)
838 siteConfigFile = new File(gateConfigProperty);
839 }
840 return siteConfigFile;
841 }
843
844 public static void setSiteConfigFile(File siteConfigFile) {
845 Gate.siteConfigFile = siteConfigFile;
846 }
848
849 private static String nl = Strings.getNl();
850
851
852 private static String emptyConfigFile =
853 "<?xml version=\"1.0\"?>" + nl +
854 "<!-- " + GATE_DOT_XML + ": GATE configuration data -->" + nl +
855 "<GATE>" + nl +
856 "" + nl +
857 "<!-- NOTE: the next element may be overwritten by the GUI!!! -->" + nl +
858 "<" + userConfigElement + "/>" + nl +
859 "" + nl +
860 "</GATE>" + nl;
861
862
866 public static String getEmptyConfigFile() { return emptyConfigFile; }
867
868
872 public static OptionsMap getUserConfig() { return userConfig; }
873
874
879 public static OptionsMap getOriginalUserConfig() {
880 return originalUserConfig;
881 }
883
887 public static void writeUserConfig() throws GateException {
888 String pluginsHomeStr;
889 try{
890 pluginsHomeStr = pluginsHome.getCanonicalPath();
891 }catch(IOException ioe){
892 throw new GateRuntimeException("Problem while locating the plug-ins home!",
893 ioe);
894 }
895 String knownPluginPath = "";
897 Iterator pluginIter = getKnownPlugins().iterator();
898 while(pluginIter.hasNext()){
899 URL aPluginURL = (URL)pluginIter.next();
900 if(aPluginURL.getProtocol().equals("file")){
902 File pluginDirectory = new File(aPluginURL.getFile());
903 try{
904 if(pluginDirectory.getCanonicalPath().startsWith(pluginsHomeStr)) continue;
905 }catch(IOException ioe){
906 throw new GateRuntimeException("Problem while locating the plug-in" +
907 aPluginURL.toString(),
908 ioe);
909 }
910 }
911 if(knownPluginPath.length() > 0) knownPluginPath += ";";
912 knownPluginPath += aPluginURL.toExternalForm();
913 }
914 getUserConfig().put(KNOWN_PLUGIN_PATH_KEY, knownPluginPath);
915
916 String loadPluginPath = "";
918 pluginIter = getAutoloadPlugins().iterator();
919 while(pluginIter.hasNext()){
920 URL aPluginURL = (URL)pluginIter.next();
921 if(loadPluginPath.length() > 0) loadPluginPath += ";";
922 loadPluginPath += aPluginURL.toExternalForm();
923 }
924 getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, loadPluginPath);
925
926 String configFileName = getUserConfigFileName();
928 File configFile = new File(configFileName);
929
930 try {
932 if(! configFile.exists()) {
934 FileWriter writer = new FileWriter(configFile);
935 writer.write(emptyConfigFile);
936 writer.close();
937 }
938
939 Files.updateXmlElement(
941 new File(configFileName), userConfigElement, userConfig
942 );
943
944 } catch(IOException e) {
945 throw new GateException(
946 "problem writing user " + GATE_DOT_XML + ": " + nl + e.toString()
947 );
948 }
949 }
951
955 public static String getUserConfigFileName() {
956 String filePrefix = "";
957 if(runningOnUnix()) filePrefix = ".";
958
959 String userConfigName =
960 System.getProperty("user.home") + Strings.getFileSep() +
961 filePrefix + GATE_DOT_XML;
962 return userConfigName;
963 }
965
969 public static String getUserSessionFileName() {
970 String filePrefix = "";
971 if(runningOnUnix()) filePrefix = ".";
972
973 String userSessionName =
974 System.getProperty("user.home") + Strings.getFileSep() +
975 filePrefix + GATE_DOT_SER;
976 return userSessionName;
977 }
979
987 public static boolean runningOnUnix() {
988 return Strings.getFileSep().equals("/");
989 }
991
997 public static List getKnownPlugins(){
998 return knownPlugins;
999 }
1000
1001
1005 public static void addKnownPlugin(URL pluginURL){
1006 pluginURL = normaliseCreoleUrl(pluginURL);
1007 if(knownPlugins.contains(pluginURL)) return;
1008 knownPlugins.add(pluginURL);
1009 }
1010
1011
1017 private static URL normaliseCreoleUrl(URL url){
1018 String urlName = url.toExternalForm();
1020 String separator = "/";
1021 if(urlName.endsWith(separator)){
1022 return url;
1023 }else{
1024 urlName += separator;
1025 try{
1026 return new URL(urlName);
1027 }catch(MalformedURLException mue){
1028 throw new GateRuntimeException(mue);
1029 }
1030 }
1031 }
1032
1033
1038 public static List getAutoloadPlugins(){
1039 return autoloadPlugins;
1040 }
1041
1042
1047 public static void addAutoloadPlugin(URL pluginUrl){
1048 pluginUrl = normaliseCreoleUrl(pluginUrl);
1049 if(autoloadPlugins.contains(pluginUrl))return;
1050 addKnownPlugin(pluginUrl);
1052 autoloadPlugins.add(pluginUrl);
1054 }
1055
1056
1061 public static DirectoryInfo getDirectoryInfo(URL directory){
1062 if(!knownPlugins.contains(directory)) return null;
1063 DirectoryInfo dInfo = (DirectoryInfo)pluginData.get(directory);
1064 if(dInfo == null){
1065 dInfo = new DirectoryInfo(directory);
1066 pluginData.put(directory, dInfo);
1067 }
1068 return dInfo;
1069 }
1070
1071
1078 public static void removeKnownPlugin(URL pluginURL){
1079 pluginURL = normaliseCreoleUrl(pluginURL);
1080 knownPlugins.remove(pluginURL);
1081 autoloadPlugins.remove(pluginURL);
1082 creoleRegister.removeDirectory(pluginURL);
1083 pluginData.remove(pluginURL);
1084 }
1085
1086
1092 public static void removeAutoloadPlugin(URL pluginURL){
1093 pluginURL = normaliseCreoleUrl(pluginURL);
1094 autoloadPlugins.remove(pluginURL);
1095 }
1096
1097
1100 public static class DirectoryInfo{
1101 public DirectoryInfo(URL url){
1102 this.url = url;
1103 valid = true;
1104 resourceInfoList = new ArrayList();
1105 parseCreole();
1107 }
1108
1109
1113 protected void parseCreole(){
1114 SAXBuilder builder = new SAXBuilder(false);
1115 try{
1116 if(!url.getPath().endsWith("/"))
1117 url = new URL(url.getProtocol(), url.getHost(),
1118 url.getPort(), url.getPath() + "/");
1119 URL creoleFileURL = new URL(url, "creole.xml");
1120 org.jdom.Document creoleDoc = builder.build(creoleFileURL);
1121 List jobsList = new ArrayList();
1122 jobsList.add(creoleDoc.getRootElement());
1123 while(!jobsList.isEmpty()){
1124 Element currentElem = (Element)jobsList.remove(0);
1125 if(currentElem.getName().equalsIgnoreCase("RESOURCE")){
1126 String resName = currentElem.getChildTextTrim("NAME");
1128 String resClass = currentElem.getChildTextTrim("CLASS");
1129 String resComment = currentElem.getChildTextTrim("COMMENT");
1130 ResourceInfo rHandler = new ResourceInfo(resName, resClass,
1132 resComment);
1133 resourceInfoList.add(rHandler);
1134 }else{
1135 List newJobsList = new ArrayList(currentElem.getChildren());
1138 newJobsList.addAll(jobsList);
1139 jobsList = newJobsList;
1140 }
1141 }
1142 }catch(IOException ioe){
1143 valid = false;
1144 ioe.printStackTrace();
1145 }catch(JDOMException jde){
1146 valid = false;
1147 jde.printStackTrace();
1148 }
1149 }
1150
1151
1154 public List getResourceInfoList(){
1155 return resourceInfoList;
1156 }
1157
1160 public URL getUrl(){
1161 return url;
1162 }
1163
1166 public boolean isValid(){
1167 return valid;
1168 }
1169
1172 protected URL url;
1173
1174
1178 protected boolean valid;
1179
1180
1183 protected List resourceInfoList;
1184 }
1185
1186
1192 public static class ResourceInfo{
1193 public ResourceInfo(String name, String className, String comment){
1194 this.resourceClassName = className;
1195 this.resourceName = name;
1196 this.resourceComment = comment;
1197 }
1198
1199
1202 public String getResourceClassName(){
1203 return resourceClassName;
1204 }
1205
1208 public String getResourceComment(){
1209 return resourceComment;
1210 }
1211
1214 public String getResourceName(){
1215 return resourceName;
1216 }
1217
1220 protected String resourceClassName;
1221
1222
1225 protected String resourceName;
1226
1227
1230 protected String resourceComment;
1231 }
1232
1233
1236 protected static File gateHome;
1237
1238
1239
1240 private static File siteConfigFile;
1241
1242
1243 private static File userConfigFile;
1244
1245
1246
1249 protected static File pluginsHome;
1250
1251
1255 protected static List knownPlugins;
1256
1257
1262 protected static List autoloadPlugins;
1263
1264
1265
1268 protected static Map pluginData;
1269
1270
1271
1272
1273 private static boolean slugGui = false;
1274
1275
1276 public static boolean isSlugGui() { return slugGui; }
1277
1278
1279 public static void setSlugGui(boolean b) { slugGui = b; }
1280
1281
1282 private static boolean enableJapeDebug = true;
1283
1284
1285 public static boolean isEnableJapeDebug() { return enableJapeDebug; }
1286
1287
1288 public static void setEnableJapeDebug(boolean b) { enableJapeDebug = b; }
1289
1290
1294 private static boolean useXMLSerialization = true;
1295
1296
1299 public static void setUseXMLSerialization(boolean useXMLSerialization) {
1300 Gate.useXMLSerialization = useXMLSerialization;
1301 }
1302
1303
1306 public static boolean getUseXMLSerialization() {
1307 return useXMLSerialization;
1308 }
1309
1310}