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.1";
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 URI(
167 gateURLStr.substring(0, gateURLStr.indexOf('!'))));
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(getDefaultUserConfigFileName());
250 }
251 System.out.println("Using " + userConfigFile + " as user configuration file");
252 }
253 }
254
255
260 protected static void initCreoleRepositories(){
261
268 String knownPluginsPath = (String)getUserConfig().get(KNOWN_PLUGIN_PATH_KEY);
270 if(knownPluginsPath != null && knownPluginsPath.length() > 0){
271 StringTokenizer strTok = new StringTokenizer(knownPluginsPath, ";", false);
272 while(strTok.hasMoreTokens()){
273 String aKnownPluginPath = strTok.nextToken();
274 try{
275 URL aPluginURL = new URL(aKnownPluginPath);
276 addKnownPlugin(aPluginURL);
277 }catch(MalformedURLException mue){
278 Err.prln("Plugin error: " + aKnownPluginPath + " is an invalid URL!");
279 }
280 }
281 }
282 File[] dirs = pluginsHome.listFiles();
287 for(int i = 0; i < dirs.length; i++){
288 File creoleFile = new File(dirs[i], "creole.xml");
289 if(creoleFile.exists()){
290 try{
291 URL pluginURL = dirs[i].toURL();
292 addKnownPlugin(pluginURL);
293 }catch(MalformedURLException mue){
294 throw new GateRuntimeException(mue);
296 }
297 }
298 }
299
300 String pluginPath = getUserConfig().getString(AUTOLOAD_PLUGIN_PATH_KEY);
302 String prop = System.getProperty(AUTOLOAD_PLUGIN_PATH_PROPERTY_NAME);
304 if(prop != null && prop.length() > 0) pluginPath = prop;
305
306 if(pluginPath == null || pluginPath.length() == 0){
307 try{
309 pluginPath = new File(pluginsHome, "ANNIE/").toURL().toString();
310 getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, pluginPath);
311 }catch(MalformedURLException mue){
312 throw new GateRuntimeException(mue);
313 }
314 }
315
316 StringTokenizer strTok = new StringTokenizer(pluginPath,
318 ";", false);
319 while(strTok.hasMoreTokens()){
320 String aDir = strTok.nextToken();
321 try{
322 URL aPluginURL = new URL(aDir);
323 addAutoloadPlugin(aPluginURL);
324 }catch(MalformedURLException mue){
325 System.err.println("Cannot load " + aDir + " CREOLE repository.");
326 mue.printStackTrace();
327 }
328 try{
329 Iterator loadPluginsIter = getAutoloadPlugins().iterator();
330 while(loadPluginsIter.hasNext()){
331 getCreoleRegister().registerDirectories((URL)loadPluginsIter.next());
332 }
333 }catch(GateException ge){
334 System.err.println("Cannot load " + aDir + " CREOLE repository.");
335 ge.printStackTrace();
336 }
337 }
338 }
339
340
341 public static void initCreoleRegister() throws GateException {
342
343 for(int i=0; i<builtinCreoleDirectoryUrls.length; i++)
345 try {
346 creoleRegister.addDirectory(
347 new URL(builtinCreoleDirectoryUrls[i])
348 );
349 } catch(MalformedURLException e) {
350 throw new GateException(e);
351 }
352
353
357
361 creoleRegister.registerBuiltins();
363 }
365
366 public static void initDataStoreRegister() {
367 dataStoreRegister = new DataStoreRegister();
368 }
370
385 public static void initConfigData() throws GateException {
386 ConfigDataProcessor configProcessor = new ConfigDataProcessor();
387 URL configURL;
389 try{
390 configURL = siteConfigFile.toURL();
391 }catch(MalformedURLException mue){
392 throw new GateRuntimeException(mue);
394 }
395 try {
396 InputStream configStream = new FileInputStream(siteConfigFile);
397 configProcessor.parseConfigFile(configStream, configURL);
398 } catch(IOException e) {
399 throw new GateException(
400 "Couldn't open site configuration file: " + configURL + " " + e
401 );
402 }
403
404 if(userConfigFile != null && userConfigFile.exists()){
406 try{
407 configURL = userConfigFile.toURL();
408 }catch(MalformedURLException mue){
409 throw new GateRuntimeException(mue);
411 }
412 try {
413 InputStream configStream = new FileInputStream(userConfigFile);
414 configProcessor.parseConfigFile(configStream, configURL);
415 } catch(IOException e) {
416 throw new GateException(
417 "Couldn't open user configuration file: " + configURL + " " + e
418 );
419 }
420 }
421
422 originalUserConfig.putAll(userConfig);
424
425 if(DEBUG) {
426 Out.prln(
427 "user config loaded; DBCONFIG=" + DataStoreRegister.getConfigData()
428 );
429 }
430 }
432
435 public static String guessUnicodeFont(){
436 String[] fontNames = java.awt.GraphicsEnvironment.
438 getLocalGraphicsEnvironment().
439 getAvailableFontFamilyNames();
440 String unicodeFontName = null;
441 for(int i = 0; i < fontNames.length; i++){
442 if(fontNames[i].equalsIgnoreCase("Arial Unicode MS")){
443 unicodeFontName = fontNames[i];
444 break;
445 }
446 if(fontNames[i].toLowerCase().indexOf("unicode") != -1){
447 unicodeFontName = fontNames[i];
448 }
449 } return unicodeFontName;
451 }
452
453
481 public static URL getUrl() throws GateException {
482 if(urlBase != null) return urlBase;
483
484 try {
485
486 if(isNetConnected()) {
488 if(
489 tryNetServer("gate.ac.uk", 80, "/")
492 ) {
493 if(DEBUG) Out.prln("getUrl() returned " + urlBase);
494 return urlBase;
495 }
496 }
498 if(
502 isLocalWebServer() &&
503 tryNetServer(
504 InetAddress.getLocalHost().getHostName(), 80, "/gate.ac.uk/"
505 )
506 ) {
507 if(DEBUG) Out.prln("getUrlBase() returned " + urlBase);
508 return urlBase;
509 }
510
511 tryFileSystem();
513
514 } catch(MalformedURLException e) {
515 throw new GateException("Bad URL, getUrlBase(): " + urlBase + ": " + e);
516 } catch(UnknownHostException e) {
517 throw new GateException("No host, getUrlBase(): " + urlBase + ": " + e);
518 }
519
520 if(DEBUG) Out.prln("getUrlBase() returned " + urlBase);
522 return urlBase;
523 }
525
532 public static URL getUrl(String path) throws GateException {
533 getUrl();
534 if(urlBase == null)
535 return null;
536
537 URL newUrl = null;
538 try {
539 newUrl = new URL(urlBase, path);
540 } catch(MalformedURLException e) {
541 throw new GateException("Bad URL, getUrl( " + path + "): " + e);
542 }
543
544 if(DEBUG) Out.prln("getUrl(" + path + ") returned " + newUrl);
545 return newUrl;
546 }
548
551 private static boolean netConnected = true;
552
553 private static int lastSym;
554
555
559 private static Set registeredIREngines = new HashSet();
560
561
570 public static void registerIREngine(String className)
571 throws GateException, ClassNotFoundException{
572 Class aClass = Class.forName(className, true, Gate.getClassLoader());
573 if(gate.creole.ir.IREngine.class.isAssignableFrom(aClass)){
574 registeredIREngines.add(className);
575 }else{
576 throw new GateException(className + " does not implement the " +
577 gate.creole.ir.IREngine.class.getName() +
578 " interface!");
579 }
580 }
581
582
588 public static boolean unregisterIREngine(String className){
589 return registeredIREngines.remove(className);
590 }
591
592
596 public static Set getRegisteredIREngines(){
597 return Collections.unmodifiableSet(registeredIREngines);
598 }
599
600
604 public static File getGateHome(){
605 return gateHome;
606 }
607
608
609 public static boolean isNetConnected() { return netConnected; }
610
611
615 public static void setNetConnected(boolean b) { netConnected = b; }
616
617
622 private static boolean localWebServer = true;
623
624
625 public static boolean isLocalWebServer() { return localWebServer; }
626
627
628 public static void setLocalWebServer(boolean b) { localWebServer = b; }
629
630
638 public static boolean tryNetServer(
639 String hostName, int serverPort, String path
640 ) throws MalformedURLException {
641
642 if(DEBUG)
643 Out.prln(
644 "tryNetServer(hostName=" + hostName + ", serverPort=" + serverPort +
645 ", path=" + path +")"
646 );
647
648 try{
650 URL url = new URL("http://" + hostName + ":" + serverPort + "/");
651 URLConnection uConn = url.openConnection();
652 HttpURLConnection huConn = null;
653 if(uConn instanceof HttpURLConnection)
654 huConn = (HttpURLConnection)uConn;
655 if(huConn.getResponseCode() == -1) return false;
656 } catch (IOException e){
657 return false;
658 }
659
660 urlBase = new URL("http", hostName, serverPort, path);
662 return true;
663
665 }
668
669 protected static boolean tryFileSystem() throws MalformedURLException {
670 String urlBaseName = locateGateFiles();
671 if(DEBUG) Out.prln("tryFileSystem: " + urlBaseName);
672
673 urlBase = new URL(urlBaseName + "gate/resources/gate.ac.uk/");
674 return urlBase == null;
675 }
677
681 public static String locateGateFiles() {
682 String aGateResourceName = "gate/resources/creole/creole.xml";
683 URL resourcesUrl = Gate.getClassLoader().getResource(aGateResourceName);
684
685 StringBuffer basePath = new StringBuffer(resourcesUrl.toExternalForm());
686 String urlBaseName =
687 basePath.substring(0, basePath.length() - aGateResourceName.length());
688
689 return urlBaseName;
690 }
692
695 public static boolean isGateType(String classname){
696 boolean res = getCreoleRegister().containsKey(classname);
697 if(!res){
698 try{
699 Class aClass = Class.forName(classname, true, Gate.getClassLoader());
700 res = Resource.class.isAssignableFrom(aClass) ||
701 Controller.class.isAssignableFrom(aClass) ||
702 DataStore.class.isAssignableFrom(aClass);
703 }catch(ClassNotFoundException cnfe){
704 return false;
705 }
706 }
707 return res;
708 }
709
710
711 static public boolean getHiddenAttribute(FeatureMap fm){
712 if(fm == null) return false;
713 Object value = fm.get("gate.HIDDEN");
714 return value != null &&
715 value instanceof String &&
716 ((String)value).equals("true");
717 }
718
719
720 static public void setHiddenAttribute(FeatureMap fm, boolean hidden){
721 if(hidden){
722 fm.put("gate.HIDDEN", "true");
723 }else{
724 fm.remove("gate.HIDDEN");
725 }
726 }
727
728
729
731 public static synchronized void addCreoleListener(CreoleListener l){
732 creoleRegister.addCreoleListener(l);
733 }
735
736 public static void setUrlBase(URL urlBase) { Gate.urlBase = urlBase; }
737
738
739 private static URL urlBase = null;
740
741
744 private static GateClassLoader classLoader = null;
745
746
747 public static GateClassLoader getClassLoader() { return classLoader; }
748
749
750 private static CreoleRegister creoleRegister = null;
751
752
753 public static CreoleRegister getCreoleRegister() { return creoleRegister; }
754
755
756 private static DataStoreRegister dataStoreRegister = null;
757
758
761 private static gate.Executable currentExecutable;
762
763
764 public static DataStoreRegister getDataStoreRegister() {
765 return dataStoreRegister;
766 }
768
775 public synchronized static void setExecutable(gate.Executable executable) {
776 if(executable == null) currentExecutable = executable;
777 else{
778 while(getExecutable() != null){
779 try{
780 Thread.sleep(200);
781 }catch(InterruptedException ie){
782 throw new LuckyException(ie.toString());
783 }
784 }
785 currentExecutable = executable;
786 }
787 }
789
793 public synchronized static gate.Executable getExecutable() {
794 return currentExecutable;
795 }
797
798
801 public synchronized static String genSym() {
802 StringBuffer buff = new StringBuffer(Integer.toHexString(lastSym++).
803 toUpperCase());
804 for(int i = buff.length(); i <= 4; i++) buff.insert(0, '0');
805 return buff.toString();
806 }
808
809 private static OptionsMap userConfig = new OptionsMap();
810
811
815 private static OptionsMap originalUserConfig = new OptionsMap();
816
817
818 private static String userConfigElement = "GATECONFIG";
819
820
824 public static String getUserConfigElement() { return userConfigElement; }
825
826
832 public static File getSiteConfigFile() {
833 if(siteConfigFile == null) {
834 String gateConfigProperty = System.getProperty(GATE_CONFIG_PROPERTY);
835 if(gateConfigProperty != null)
836 siteConfigFile = new File(gateConfigProperty);
837 }
838 return siteConfigFile;
839 }
841
842 public static void setSiteConfigFile(File siteConfigFile) {
843 Gate.siteConfigFile = siteConfigFile;
844 }
846
847 private static String nl = Strings.getNl();
848
849
850 private static String emptyConfigFile =
851 "<?xml version=\"1.0\"?>" + nl +
852 "<!-- " + GATE_DOT_XML + ": GATE configuration data -->" + nl +
853 "<GATE>" + nl +
854 "" + nl +
855 "<!-- NOTE: the next element may be overwritten by the GUI!!! -->" + nl +
856 "<" + userConfigElement + "/>" + nl +
857 "" + nl +
858 "</GATE>" + nl;
859
860
864 public static String getEmptyConfigFile() { return emptyConfigFile; }
865
866
870 public static OptionsMap getUserConfig() { return userConfig; }
871
872
877 public static OptionsMap getOriginalUserConfig() {
878 return originalUserConfig;
879 }
881
885 public static void writeUserConfig() throws GateException {
886 String pluginsHomeStr;
887 try{
888 pluginsHomeStr = pluginsHome.getCanonicalPath();
889 }catch(IOException ioe){
890 throw new GateRuntimeException("Problem while locating the plug-ins home!",
891 ioe);
892 }
893 String knownPluginPath = "";
895 Iterator pluginIter = getKnownPlugins().iterator();
896 while(pluginIter.hasNext()){
897 URL aPluginURL = (URL)pluginIter.next();
898 if(aPluginURL.getProtocol().equals("file")){
900 File pluginDirectory = new File(aPluginURL.getFile());
901 try{
902 if(pluginDirectory.getCanonicalPath().startsWith(pluginsHomeStr)) continue;
903 }catch(IOException ioe){
904 throw new GateRuntimeException("Problem while locating the plug-in" +
905 aPluginURL.toString(),
906 ioe);
907 }
908 }
909 if(knownPluginPath.length() > 0) knownPluginPath += ";";
910 knownPluginPath += aPluginURL.toExternalForm();
911 }
912 getUserConfig().put(KNOWN_PLUGIN_PATH_KEY, knownPluginPath);
913
914 String loadPluginPath = "";
916 pluginIter = getAutoloadPlugins().iterator();
917 while(pluginIter.hasNext()){
918 URL aPluginURL = (URL)pluginIter.next();
919 if(loadPluginPath.length() > 0) loadPluginPath += ";";
920 loadPluginPath += aPluginURL.toExternalForm();
921 }
922 getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, loadPluginPath);
923
924 File configFile = getUserConfigFile();
928
929 try {
931 if(! configFile.exists()) {
933 FileWriter writer = new FileWriter(configFile);
934 writer.write(emptyConfigFile);
935 writer.close();
936 }
937
938 Files.updateXmlElement(
940 configFile, userConfigElement, userConfig
941 );
942
943 } catch(IOException e) {
944 throw new GateException(
945 "problem writing user " + GATE_DOT_XML + ": " + nl + e.toString()
946 );
947 }
948 }
950
956 public static String getUserConfigFileName() {
957 return getDefaultUserConfigFileName();
958 }
960
967 public static String getDefaultUserConfigFileName() {
968 String filePrefix = "";
969 if(runningOnUnix()) filePrefix = ".";
970
971 String userConfigName =
972 System.getProperty("user.home") + Strings.getFileSep() +
973 filePrefix + GATE_DOT_XML;
974 return userConfigName;
975 }
977
981 public static String getUserSessionFileName() {
982 String filePrefix = "";
983 if(runningOnUnix()) filePrefix = ".";
984
985 String userSessionName =
986 System.getProperty("user.home") + Strings.getFileSep() +
987 filePrefix + GATE_DOT_SER;
988 return userSessionName;
989 }
991
999 public static boolean runningOnUnix() {
1000 return Strings.getFileSep().equals("/");
1001 }
1003
1009 public static List getKnownPlugins(){
1010 return knownPlugins;
1011 }
1012
1013
1017 public static void addKnownPlugin(URL pluginURL){
1018 pluginURL = normaliseCreoleUrl(pluginURL);
1019 if(knownPlugins.contains(pluginURL)) return;
1020 knownPlugins.add(pluginURL);
1021 }
1022
1023
1029 private static URL normaliseCreoleUrl(URL url){
1030 String urlName = url.toExternalForm();
1032 String separator = "/";
1033 if(urlName.endsWith(separator)){
1034 return url;
1035 }else{
1036 urlName += separator;
1037 try{
1038 return new URL(urlName);
1039 }catch(MalformedURLException mue){
1040 throw new GateRuntimeException(mue);
1041 }
1042 }
1043 }
1044
1045
1050 public static List getAutoloadPlugins(){
1051 return autoloadPlugins;
1052 }
1053
1054
1059 public static void addAutoloadPlugin(URL pluginUrl){
1060 pluginUrl = normaliseCreoleUrl(pluginUrl);
1061 if(autoloadPlugins.contains(pluginUrl))return;
1062 addKnownPlugin(pluginUrl);
1064 autoloadPlugins.add(pluginUrl);
1066 }
1067
1068
1073 public static DirectoryInfo getDirectoryInfo(URL directory){
1074 if(!knownPlugins.contains(directory)) return null;
1075 DirectoryInfo dInfo = (DirectoryInfo)pluginData.get(directory);
1076 if(dInfo == null){
1077 dInfo = new DirectoryInfo(directory);
1078 pluginData.put(directory, dInfo);
1079 }
1080 return dInfo;
1081 }
1082
1083
1090 public static void removeKnownPlugin(URL pluginURL){
1091 pluginURL = normaliseCreoleUrl(pluginURL);
1092 knownPlugins.remove(pluginURL);
1093 autoloadPlugins.remove(pluginURL);
1094 creoleRegister.removeDirectory(pluginURL);
1095 pluginData.remove(pluginURL);
1096 }
1097
1098
1104 public static void removeAutoloadPlugin(URL pluginURL){
1105 pluginURL = normaliseCreoleUrl(pluginURL);
1106 autoloadPlugins.remove(pluginURL);
1107 }
1108
1109
1112 public static class DirectoryInfo{
1113 public DirectoryInfo(URL url){
1114 this.url = normaliseCreoleUrl(url);
1115 valid = true;
1116 resourceInfoList = new ArrayList();
1117 parseCreole();
1119 }
1120
1121
1125 protected void parseCreole(){
1126 SAXBuilder builder = new SAXBuilder(false);
1127 try{
1128 URL creoleFileURL = new URL(url, "creole.xml");
1129 org.jdom.Document creoleDoc = builder.build(creoleFileURL);
1130 List jobsList = new ArrayList();
1131 jobsList.add(creoleDoc.getRootElement());
1132 while(!jobsList.isEmpty()){
1133 Element currentElem = (Element)jobsList.remove(0);
1134 if(currentElem.getName().equalsIgnoreCase("RESOURCE")){
1135 String resName = currentElem.getChildTextTrim("NAME");
1137 String resClass = currentElem.getChildTextTrim("CLASS");
1138 String resComment = currentElem.getChildTextTrim("COMMENT");
1139 ResourceInfo rHandler = new ResourceInfo(resName, resClass,
1141 resComment);
1142 resourceInfoList.add(rHandler);
1143 }else{
1144 List newJobsList = new ArrayList(currentElem.getChildren());
1147 newJobsList.addAll(jobsList);
1148 jobsList = newJobsList;
1149 }
1150 }
1151 }catch(IOException ioe){
1152 valid = false;
1153 Err.prln("Problem while parsing plugin " + url.toExternalForm() +
1154 "!\n" + ioe.toString() + "\nPlugin not available!");
1155 }catch(JDOMException jde){
1156 valid = false;
1157 Err.prln("Problem while parsing plugin " + url.toExternalForm() +
1158 "!\n" + jde.toString() + "\nPlugin not available!");
1159 }
1160 }
1161
1162
1165 public List getResourceInfoList(){
1166 return resourceInfoList;
1167 }
1168
1171 public URL getUrl(){
1172 return url;
1173 }
1174
1177 public boolean isValid(){
1178 return valid;
1179 }
1180
1183 protected URL url;
1184
1185
1189 protected boolean valid;
1190
1191
1194 protected List resourceInfoList;
1195 }
1196
1197
1203 public static class ResourceInfo{
1204 public ResourceInfo(String name, String className, String comment){
1205 this.resourceClassName = className;
1206 this.resourceName = name;
1207 this.resourceComment = comment;
1208 }
1209
1210
1213 public String getResourceClassName(){
1214 return resourceClassName;
1215 }
1216
1219 public String getResourceComment(){
1220 return resourceComment;
1221 }
1222
1225 public String getResourceName(){
1226 return resourceName;
1227 }
1228
1231 protected String resourceClassName;
1232
1233
1236 protected String resourceName;
1237
1238
1241 protected String resourceComment;
1242 }
1243
1244
1247 protected static File gateHome;
1248
1249
1250
1251 private static File siteConfigFile;
1252
1253
1254 private static File userConfigFile;
1255
1256
1257
1260 protected static File pluginsHome;
1261
1262
1267 public static void setGateHome(File gateHome) {
1268 if(Gate.gateHome != null) {
1269 throw new IllegalStateException("gateHome has already been set");
1270 }
1271 Gate.gateHome = gateHome;
1272 }
1273
1274
1279 public static void setPluginsHome(File pluginsHome) {
1280 if(Gate.pluginsHome != null) {
1281 throw new IllegalStateException("pluginsHome has already been set");
1282 }
1283 Gate.pluginsHome = pluginsHome;
1284 }
1285
1286
1292 public static File getPluginsHome() {
1293 return pluginsHome;
1294 }
1295
1296
1301 public static void setUserConfigFile(File userConfigFile) {
1302 if(Gate.userConfigFile != null) {
1303 throw new IllegalStateException("userConfigFile has already been set");
1304 }
1305 Gate.userConfigFile = userConfigFile;
1306 }
1307
1308
1314 public static File getUserConfigFile() {
1315 return userConfigFile;
1316 }
1317
1318
1322 protected static List knownPlugins;
1323
1324
1329 protected static List autoloadPlugins;
1330
1331
1332
1335 protected static Map pluginData;
1336
1337
1338
1339
1340 private static boolean slugGui = false;
1341
1342
1343 public static boolean isSlugGui() { return slugGui; }
1344
1345
1346 public static void setSlugGui(boolean b) { slugGui = b; }
1347
1348
1349 private static boolean enableJapeDebug = true;
1350
1351
1352 public static boolean isEnableJapeDebug() { return enableJapeDebug; }
1353
1354
1355 public static void setEnableJapeDebug(boolean b) { enableJapeDebug = b; }
1356
1357
1361 private static boolean useXMLSerialization = true;
1362
1363
1366 public static void setUseXMLSerialization(boolean useXMLSerialization) {
1367 Gate.useXMLSerialization = useXMLSerialization;
1368 }
1369
1370
1373 public static boolean getUseXMLSerialization() {
1374 return useXMLSerialization;
1375 }
1376
1377}