| 906 | | // Now we are connected. Need to tell fedora where to find the FedoraMETS |
|---|
| 907 | | // files for ingestion |
|---|
| 908 | | |
|---|
| 909 | | //Fedora needs an xml file: |
|---|
| 910 | | // FEDORA_HOME/tomcat/conf/Catalina/<fedora-hostname OR localhost>/gsdl.xml |
|---|
| 911 | | // (which is to be wherever fedora.xml is situated) in order to know where |
|---|
| 912 | | // to get the collection contents from. |
|---|
| 913 | | writeGsdlXmlFile(); |
|---|
| 914 | | |
|---|
| 915 | | } |
|---|
| 916 | | |
|---|
| 917 | | /** Fedora needs an xml file: |
|---|
| 918 | | * FEDORA_HOME/tomcat/conf/Catalina/[fedora-hostname OR localhost]/gsdl.xml |
|---|
| 919 | | * (host folder is the one wherever fedora.xml is found) in order to know where |
|---|
| 920 | | * to get the collection contents from. |
|---|
| 921 | | * This method generates the necessary gsdl.xml file which points Fedora to the |
|---|
| 922 | | * parent of the collect folder. |
|---|
| 923 | | */ |
|---|
| 924 | | private static void writeGsdlXmlFile() { |
|---|
| 925 | | // System.getenv(FEDORA_HOME) is deprecated in Java v4 (but is back in v5). |
|---|
| 926 | | // But fedora_info.getHome() will return FEDORA_HOME. |
|---|
| 927 | | |
|---|
| 928 | | // To do the following, we actually need to stop and restart the Fedora server. |
|---|
| 929 | | // Why should FLI have to do all this, or even know that it needs doing? |
|---|
| 930 | | String execExtension = Utility.isWindows() ? "bat" : "sh"; |
|---|
| 931 | | String fedoraProcess = Configuration.fedora_info.getHome()+"tomcat" |
|---|
| 932 | | +File.separator+"bin"+File.separator; |
|---|
| 933 | | String fedoraStop = fedoraProcess+"shutdown."+execExtension; |
|---|
| 934 | | String fedoraStart = fedoraProcess+"startup."+execExtension; |
|---|
| 935 | | String errorMessage = ""; |
|---|
| 936 | | |
|---|
| 937 | | try{ |
|---|
| 938 | | // (1) stop the fedora server |
|---|
| 939 | | errorMessage = "Failed to stop the fedora server."; |
|---|
| 940 | | |
|---|
| 941 | | Process process = Runtime.getRuntime().exec(fedoraStop); |
|---|
| 942 | | System.err.println("*****Stopping the fedora server: " + fedoraStop); |
|---|
| 943 | | int exitValue = -1; |
|---|
| 944 | | if((exitValue = process.waitFor()) != 0) { |
|---|
| 945 | | throw new Exception(errorMessage); |
|---|
| 946 | | } |
|---|
| 947 | | System.out.println("Exit value is: " + exitValue); |
|---|
| 948 | | |
|---|
| 949 | | // (2) See if the folder for the host contains fedora.xml, if it doesn't, |
|---|
| 950 | | // then don't write gsdl.xml in there, try folder "localhost" instead |
|---|
| 951 | | String pathPrefix = Configuration.fedora_info.getHome()+"tomcat"+File.separator+"conf" |
|---|
| 952 | | +File.separator+"Catalina"; |
|---|
| 953 | | String gsdlHostFolderPath = pathPrefix+File.separator+Configuration.fedora_info.getHostname(); |
|---|
| 954 | | File fedoraXML = new File(gsdlHostFolderPath,"fedora.xml"); |
|---|
| 955 | | if(!fedoraXML.exists()) { |
|---|
| 956 | | // prepare the errorMessage just in case we need it |
|---|
| 957 | | errorMessage = "Directory " + gsdlHostFolderPath + " is the wrong place to put" |
|---|
| 958 | | + " the crucial gsdl.xml file as it doesn't contain the example file fedora.xml\n"; |
|---|
| 959 | | |
|---|
| 960 | | // no default fedora.xml file in the folder we want to write gsdl.xml to |
|---|
| 961 | | // so we may be in the wrong place |
|---|
| 962 | | if(Configuration.fedora_info.getHostname().equals("localhost")) { |
|---|
| 963 | | // if we just tried localhost and then failed |
|---|
| 964 | | // we can't continue |
|---|
| 965 | | fedoraXML = null; |
|---|
| 966 | | throw new Exception(errorMessage); |
|---|
| 967 | | } else { |
|---|
| 968 | | System.err.println("*** Folder " + gsdlHostFolderPath |
|---|
| 969 | | +"\nis the wrong location for gsdl.xml. Trying folder localhost."); |
|---|
| 970 | | // we just tried a folder of a different hostname, |
|---|
| 971 | | // let's try "localhost" as a last ditch effort |
|---|
| 972 | | gsdlHostFolderPath = pathPrefix+File.separator+"localhost"; |
|---|
| 973 | | fedoraXML = new File(gsdlHostFolderPath,"fedora.xml"); |
|---|
| 974 | | if(!fedoraXML.exists()){ |
|---|
| 975 | | fedoraXML = null; |
|---|
| 976 | | throw new Exception(errorMessage); |
|---|
| 977 | | } // else we found the location for gsdl.xml |
|---|
| 978 | | } |
|---|
| 979 | | } |
|---|
| 980 | | |
|---|
| 981 | | // If we made it here, we found the correct folder to write gsdl.xml to |
|---|
| 982 | | errorMessage = ""; |
|---|
| 983 | | fedoraXML = null; |
|---|
| 984 | | File gsdlXMLPath = new File(gsdlHostFolderPath); |
|---|
| 985 | | if(!gsdlXMLPath.exists()) { |
|---|
| 986 | | // make sure all the intermediate directories exist |
|---|
| 987 | | // (should be the case when fedoraXML exists in it) |
|---|
| 988 | | gsdlXMLPath.mkdirs(); |
|---|
| 989 | | } |
|---|
| 990 | | String gsdlXMLFile = gsdlXMLPath+File.separator+"gsdl.xml"; |
|---|
| 991 | | |
|---|
| 992 | | // (3) We write xml out containing the location of the parent folder of the collect dir |
|---|
| 993 | | String collectParent = Configuration.gsdl_path; |
|---|
| 994 | | if(Gatherer.GS3){ // Collect dir's parent folder is web/sites/localsite, which is GSDL3HOME/sites/localsite |
|---|
| 995 | | collectParent = Configuration.gsdl3_path+"sites"+File.separator+"localsite"; |
|---|
| 996 | | } |
|---|
| 997 | | System.err.println("****CollectParent folder: " + collectParent + "\n****gsdlXMLFile: " + gsdlXMLFile); |
|---|
| 998 | | |
|---|
| 999 | | // The contents we are going to write out to the file: <Context docBase="collectParent" path="/gsdl"></Context> |
|---|
| 1000 | | // Does Fedora expect a / in the path to gsdl, does Fedora deal with "/gsdl" or do I need to use a File.separator? |
|---|
| 1001 | | String contents = "<?xml version='1.0' encoding='utf-8'?>\n<Context docBase=\"" |
|---|
| 1002 | | +collectParent+"\" path=\""+File.separator+"gsdl\"></Context>"; |
|---|
| 1003 | | |
|---|
| 1004 | | // even if the file exists, we overwrite it, because we may have changed GS versions |
|---|
| 1005 | | // and collect dir would have changed though there'd still be a gsdl.xml file |
|---|
| 1006 | | errorMessage = "Failed to create the essential file: " + gsdlXMLFile; |
|---|
| 1007 | | java.io.OutputStream gsdlXMLFileOut = new java.io.FileOutputStream(gsdlXMLFile); |
|---|
| 1008 | | gsdlXMLFileOut.write(contents.getBytes()); |
|---|
| 1009 | | gsdlXMLFileOut.close(); |
|---|
| 1010 | | gsdlXMLFileOut = null; |
|---|
| 1011 | | |
|---|
| 1012 | | // Otherwise, restart the fedora server again |
|---|
| 1013 | | errorMessage = "Failed to stop the fedora server."; |
|---|
| 1014 | | process = Runtime.getRuntime().exec(fedoraStart); |
|---|
| 1015 | | System.err.println("*****Restarting the fedora server: " + fedoraStart); |
|---|
| 1016 | | if((exitValue = process.waitFor()) != 0) { |
|---|
| 1017 | | throw new Exception(errorMessage); |
|---|
| 1018 | | } |
|---|
| 1019 | | System.out.println("Exit value is: " + exitValue); |
|---|
| 1020 | | }catch(Exception e){ |
|---|
| 1021 | | System.err.println("****"); |
|---|
| 1022 | | System.err.println("* " + errorMessage + "\n" + e.getMessage()); |
|---|
| 1023 | | System.err.println("***"); |
|---|
| 1024 | | e.printStackTrace(); |
|---|
| 1025 | | DebugStream.printStackTrace(e); |
|---|
| 1026 | | // We can't continue, so we exit |
|---|
| 1027 | | System.exit(1); |
|---|
| 1028 | | } |
|---|
| | 906 | // Now we are connected. |
|---|