Revision 4502
Added by daigle about 16 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.io.FileInputStream; |
32 | 32 |
import java.io.FileReader; |
33 |
import java.io.FileWriter; |
|
34 | 33 |
import java.io.IOException; |
35 | 34 |
import java.io.OutputStreamWriter; |
36 | 35 |
import java.io.PrintWriter; |
... | ... | |
65 | 64 |
|
66 | 65 |
import org.apache.log4j.Logger; |
67 | 66 |
import org.apache.log4j.PropertyConfigurator; |
68 |
//import org.ecoinformatics.eml.EMLParser;
|
|
67 |
import org.ecoinformatics.eml.EMLParser; |
|
69 | 68 |
|
70 | 69 |
import au.com.bytecode.opencsv.CSVWriter; |
71 | 70 |
|
... | ... | |
1717 | 1716 |
ZipOutputStream zout, boolean withInlineData, Hashtable<String, String[]> params) |
1718 | 1717 |
throws ClassNotFoundException, IOException, SQLException, |
1719 | 1718 |
McdbException, Exception { |
1720 |
String documentDir = PropertyService.getProperty("application.documentfilepath"); |
|
1721 | 1719 |
|
1722 | 1720 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
1723 | 1721 |
try { |
... | ... | |
1802 | 1800 |
|
1803 | 1801 |
// Try to get the metadata file from disk. If it isn't |
1804 | 1802 |
// found, create it from the db and write it to disk then. |
1805 |
String documentPath = documentDir + FileUtil.getFS() + docid; |
|
1806 | 1803 |
try { |
1807 |
if (FileUtil.getFileStatus(documentPath) == FileUtil.DOES_NOT_EXIST) { |
|
1808 |
FileWriter fileWriter = new FileWriter(documentPath); |
|
1809 |
doc.toXml(fileWriter, user, groups, withInlineData); |
|
1810 |
} |
|
1811 |
|
|
1812 | 1804 |
PrintWriter out = new PrintWriter(streamOut); |
1813 |
doc.readFromFileSystem(out, user, groups, documentPath);
|
|
1805 |
doc.toXml(out, user, groups, withInlineData);
|
|
1814 | 1806 |
} catch (Exception e) { |
1815 | 1807 |
// any exceptions in reading the xml from disc, and we go back to the |
1816 | 1808 |
// old way of creating the xml directly. |
1817 |
logMetacat.error("could not read from document file " + documentPath
|
|
1809 |
logMetacat.error("could not read from document file " + docid
|
|
1818 | 1810 |
+ ": " + e.getMessage()); |
1819 | 1811 |
PrintWriter out = new PrintWriter(streamOut); |
1820 |
doc.toXml(out, user, groups, withInlineData); |
|
1812 |
doc.toXmlFromDb(out, user, groups, withInlineData);
|
|
1821 | 1813 |
} |
1822 | 1814 |
} else { |
1823 | 1815 |
// TODO MCD, this should read from disk as well? |
... | ... | |
2135 | 2127 |
// set eml2 base validation parser |
2136 | 2128 |
String rule = DocumentImpl.EML200; |
2137 | 2129 |
// using emlparser to check id validation |
2138 |
// EMLParser parser = new EMLParser(doctext[0]);
|
|
2130 |
EMLParser parser = new EMLParser(doctext[0]); |
|
2139 | 2131 |
documentWrapper = new DocumentImplWrapper(rule, true); |
2140 | 2132 |
} else if (namespace.compareTo( |
2141 | 2133 |
DocumentImpl.EML2_1_0NAMESPACE) == 0) { |
2142 | 2134 |
// set eml2 base validation parser |
2143 | 2135 |
String rule = DocumentImpl.EML210; |
2144 | 2136 |
// using emlparser to check id validation |
2145 |
// EMLParser parser = new EMLParser(doctext[0]);
|
|
2137 |
EMLParser parser = new EMLParser(doctext[0]); |
|
2146 | 2138 |
documentWrapper = new DocumentImplWrapper(rule, true); |
2147 | 2139 |
} else { |
2148 | 2140 |
// set schema base validation parser |
... | ... | |
2182 | 2174 |
|
2183 | 2175 |
newdocid = documentWrapper.write(dbConn, xml, pub, dtd, |
2184 | 2176 |
doAction, accNumber, user, groups); |
2185 |
|
|
2186 |
// write the document to disk |
|
2187 |
FileWriter fileWriter = null; |
|
2188 |
try { |
|
2189 |
String documentDir = |
|
2190 |
PropertyService.getProperty("application.documentfilepath"); |
|
2191 |
String documentPath = documentDir + FileUtil.getFS() + accNumber; |
|
2192 |
|
|
2193 |
if (accNumber != null |
|
2194 |
&& FileUtil.getFileStatus(documentPath) == FileUtil.DOES_NOT_EXIST) { |
|
2195 |
fileWriter = new FileWriter(documentPath); |
|
2196 |
fileWriter.write(doctext[0]); |
|
2197 |
} |
|
2198 |
} catch (IOException ioe) { |
|
2199 |
logMetacat.error("Did not write " + accNumber |
|
2200 |
+ " to file system: " + ioe.getMessage()); |
|
2201 |
} finally { |
|
2202 |
if (fileWriter != null) { |
|
2203 |
fileWriter.close(); |
|
2204 |
} |
|
2205 |
} |
|
2206 | 2177 |
|
2207 | 2178 |
EventLog.getInstance().log(request.getRemoteAddr(), |
2208 | 2179 |
user, accNumber, action[0]); |
Also available in: Unified diff
Remove the code to read and write metadata to disk. It is getting put into DocumentImpl