Revision 85
Added by Matt Jones about 24 years ago
MetaCatServlet.java | ||
---|---|---|
21 | 21 |
import java.util.PropertyResourceBundle; |
22 | 22 |
import java.net.URL; |
23 | 23 |
import java.net.MalformedURLException; |
24 |
import java.sql.PreparedStatement; |
|
25 |
import java.sql.ResultSet; |
|
24 | 26 |
import java.sql.Connection; |
25 | 27 |
import java.sql.SQLException; |
26 | 28 |
|
... | ... | |
225 | 227 |
String docid = ((String[])params.get("docid"))[0]; |
226 | 228 |
String doc = docreader.readXMLDocument((new Long(docid)).longValue()); |
227 | 229 |
|
228 |
// set content type and other response header fields first |
|
229 |
response.setContentType("text/xml"); |
|
230 |
|
|
231 |
String qformat = ((String[])params.get("qformat"))[0]; |
|
232 |
if (qformat.equals("xml")) { |
|
233 |
// set content type and other response header fields first |
|
234 |
response.setContentType("text/xml"); |
|
235 |
out.println(doc); |
|
236 |
} else if (qformat.equals("html")) { |
|
237 |
// set content type and other response header fields first |
|
238 |
response.setContentType("text/html"); |
|
239 |
//out.println("Converting to HTML..."); |
|
240 |
XMLDocumentFragment htmldoc = null; |
|
241 |
|
|
242 |
// Look up the System ID of the XSL sheet |
|
243 |
PreparedStatement pstmt; |
|
244 |
String xsl_system_id = null; |
|
230 | 245 |
|
231 |
out.println(doc); |
|
246 |
try { |
|
247 |
pstmt = |
|
248 |
conn.prepareStatement("SELECT system_id " + |
|
249 |
"FROM xml_catalog_entities " + |
|
250 |
"WHERE source_doctype LIKE ? " + |
|
251 |
"AND target_doctype LIKE ?"); |
|
252 |
// Bind the values to the query |
|
253 |
pstmt.setString(1, "-//NCEAS//eml-dataset//EN"); |
|
254 |
pstmt.setString(2, "-//W3C//HTML//EN"); |
|
255 |
|
|
256 |
pstmt.execute(); |
|
257 |
try { |
|
258 |
ResultSet rs = pstmt.getResultSet(); |
|
259 |
try { |
|
260 |
boolean tableHasRows = rs.next(); |
|
261 |
if (tableHasRows) { |
|
262 |
try { |
|
263 |
xsl_system_id = rs.getString(1); |
|
264 |
} catch (SQLException e) { |
|
265 |
System.out.println("Error with getString: " + e.getMessage()); |
|
266 |
} |
|
267 |
} |
|
268 |
} catch (SQLException e) { |
|
269 |
System.out.println("Error with next: " + e.getMessage()); |
|
270 |
} |
|
271 |
} catch (SQLException e) { |
|
272 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
273 |
} |
|
274 |
pstmt.close(); |
|
275 |
} catch (SQLException e) { |
|
276 |
System.out.println("Error getting id: " + e.getMessage()); |
|
277 |
} |
|
278 |
|
|
279 |
// Try to apply the style |
|
280 |
try { |
|
281 |
XSLStylesheet style = new XSLStylesheet(new URL(xsl_system_id), null); |
|
282 |
htmldoc = (new XSLProcessor()).processXSL(style, |
|
283 |
(Reader)(new StringReader(doc)),null); |
|
284 |
htmldoc.print(out); |
|
285 |
} catch (Exception e) { |
|
286 |
out.println("Error transforming document:\n" + e.getMessage()); |
|
287 |
} |
|
288 |
} |
|
232 | 289 |
} |
233 | 290 |
|
234 | 291 |
/** |
Also available in: Unified diff
creating automatic transformation for XML docs retreived from catalog