Revision 243
Added by Matt Jones over 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
32 | 32 |
implements LexicalHandler, DeclHandler { |
33 | 33 |
|
34 | 34 |
private boolean atFirstElement; |
35 |
private boolean processingDTD; |
|
35 | 36 |
private String docname = null; |
36 | 37 |
private String doctype; |
37 | 38 |
private String systemid; |
... | ... | |
52 | 53 |
public DBSAXHandler(Connection conn) { |
53 | 54 |
this.conn = conn; |
54 | 55 |
this.atFirstElement = true; |
56 |
this.processingDTD = false; |
|
55 | 57 |
|
56 | 58 |
// Create the stack for keeping track of node context |
57 | 59 |
// if it doesn't already exist |
... | ... | |
259 | 261 |
* SAX Handler that receives notification of the start of entities |
260 | 262 |
*/ |
261 | 263 |
public void startEntity(String name) throws SAXException { |
262 |
MetaCatUtil.debugMessage("start ENTITY"); |
|
264 |
MetaCatUtil.debugMessage("start ENTITY: " + name); |
|
265 |
if (name.equals("[dtd]")) { |
|
266 |
processingDTD = true; |
|
267 |
} |
|
263 | 268 |
} |
264 | 269 |
|
265 | 270 |
/** |
266 | 271 |
* SAX Handler that receives notification of the end of entities |
267 | 272 |
*/ |
268 | 273 |
public void endEntity(String name) throws SAXException { |
269 |
MetaCatUtil.debugMessage("end ENTITY"); |
|
274 |
MetaCatUtil.debugMessage("end ENTITY: " + name); |
|
275 |
if (name.equals("[dtd]")) { |
|
276 |
processingDTD = false; |
|
277 |
} |
|
270 | 278 |
} |
271 | 279 |
|
272 | 280 |
/** |
... | ... | |
274 | 282 |
*/ |
275 | 283 |
public void elementDecl(String name, String model) |
276 | 284 |
throws org.xml.sax.SAXException { |
277 |
MetaCatUtil.debugMessage("ELEMENTDECL");
|
|
285 |
MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model);
|
|
278 | 286 |
} |
279 | 287 |
|
280 | 288 |
/** |
... | ... | |
283 | 291 |
public void attributeDecl(String eName, String aName, |
284 | 292 |
String type, String valueDefault, String value) |
285 | 293 |
throws org.xml.sax.SAXException { |
286 |
MetaCatUtil.debugMessage("ATTRIBUTEDECL"); |
|
294 |
MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " " |
|
295 |
+ aName + " " + type + " " + valueDefault + " " |
|
296 |
+ value); |
|
287 | 297 |
} |
288 | 298 |
|
289 | 299 |
/** |
... | ... | |
291 | 301 |
*/ |
292 | 302 |
public void internalEntityDecl(String name, String value) |
293 | 303 |
throws org.xml.sax.SAXException { |
294 |
MetaCatUtil.debugMessage("INTERNENTITYDECL");
|
|
304 |
MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value);
|
|
295 | 305 |
} |
296 | 306 |
|
297 | 307 |
/** |
... | ... | |
300 | 310 |
public void externalEntityDecl(String name, String publicId, |
301 | 311 |
String systemId) |
302 | 312 |
throws org.xml.sax.SAXException { |
303 |
MetaCatUtil.debugMessage("EXTERNENTITYDECL"); |
|
313 |
MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId |
|
314 |
+ " " + systemId); |
|
304 | 315 |
} |
305 | 316 |
|
306 | 317 |
// |
... | ... | |
343 | 354 |
/** |
344 | 355 |
* get the document processing state |
345 | 356 |
*/ |
346 |
public boolean atFirstElement() {
|
|
347 |
return atFirstElement;
|
|
357 |
public boolean processingDTD() {
|
|
358 |
return processingDTD;
|
|
348 | 359 |
} |
349 | 360 |
} |
350 | 361 |
|
351 | 362 |
/** |
352 | 363 |
* '$Log$ |
364 |
* 'Revision 1.30 2000/06/28 03:14:35 jones |
|
365 |
* 'Fixed bug where TEXT nodes couldn't be longer than 4000 characters, which |
|
366 |
* 'is the maximum length of a VARCHAR2 field in Oracle. Now, if text |
|
367 |
* 'exceeds the field length, I break the text up into a series of TEXT |
|
368 |
* 'nodes each of the max field length, and the remainder in the last |
|
369 |
* 'TEXT node. The only problem with this is that our current search |
|
370 |
* 'algorithms only will find phrases within a single TEXT nodes, so if |
|
371 |
* 'the search term spans the node boundary, the search algorithm will not |
|
372 |
* 'return a hit. I expect this is extremely rare, basically inconsequential. |
|
373 |
* ' |
|
353 | 374 |
* 'Revision 1.29 2000/06/27 04:31:07 jones |
354 | 375 |
* 'Fixed bugs associated with the new UPDATE and DELETE functions of |
355 | 376 |
* 'DBWriter. There were problematic interactions between some static |
src/edu/ucsb/nceas/metacat/DBValidate.java | ||
---|---|---|
20 | 20 |
import java.util.*; |
21 | 21 |
import java.io.*; |
22 | 22 |
import java.lang.reflect.*; |
23 |
import java.sql.*; |
|
23 | 24 |
|
24 | 25 |
import org.w3c.dom.*; |
25 | 26 |
import org.xml.sax.*; |
... | ... | |
37 | 38 |
* Copyright: 2000 Regents of the University of California and the |
38 | 39 |
* National Center for Ecological Analysis and Synthesis |
39 | 40 |
* April 28, 2000 |
40 |
* |
|
41 |
* @author Dan Higgins |
|
42 |
* @version 1.0 |
|
41 |
* Authors: Dan Higgins, Matt Jones |
|
43 | 42 |
*/ |
44 | 43 |
public class DBValidate { |
45 | 44 |
|
... | ... | |
62 | 61 |
} catch (Exception e) { |
63 | 62 |
System.err.println("Could not create parser!!!"); |
64 | 63 |
} |
65 |
|
|
66 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
|
67 |
try { |
|
68 |
Catalog myCatalog = new Catalog(); |
|
69 |
myCatalog.loadSystemCatalogs(); |
|
70 |
cer.setCatalog(myCatalog); |
|
71 |
} catch (Exception e) {System.out.println("Problem creating Catalog!");} |
|
72 |
|
|
73 |
parser.setEntityResolver(cer); |
|
74 | 64 |
} |
75 | 65 |
|
76 |
/** Construct a new validation object */ |
|
66 |
/** Construct a new validation object using an OASIS catalog file */
|
|
77 | 67 |
public DBValidate(String parserName, String xmlcatalogfile) { |
68 |
this(parserName); |
|
78 | 69 |
|
79 |
try { |
|
80 |
// Get an instance of the parser |
|
81 |
parser = XMLReaderFactory.createXMLReader(parserName); |
|
82 |
parser.setFeature("http://xml.org/sax/features/validation",true); |
|
83 |
//parser.setValidationMode(true); // Oracle |
|
84 |
} catch (Exception e) { |
|
85 |
System.err.println("Could not create parser!!!"); |
|
86 |
} |
|
87 |
|
|
88 | 70 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
89 | 71 |
try { |
90 | 72 |
Catalog myCatalog = new Catalog(); |
... | ... | |
96 | 78 |
parser.setEntityResolver(cer); |
97 | 79 |
} |
98 | 80 |
|
81 |
/** Construct a new validation object using a database entity resolver */ |
|
82 |
public DBValidate(String parserName, Connection conn) { |
|
83 |
this(parserName); |
|
84 |
|
|
85 |
DBEntityResolver dbresolver = new DBEntityResolver(conn); |
|
86 |
parser.setEntityResolver(dbresolver); |
|
87 |
} |
|
88 |
|
|
99 | 89 |
/** |
100 | 90 |
* validate an xml document against its DTD |
101 | 91 |
* |
... | ... | |
111 | 101 |
} catch (IOException e) { |
112 | 102 |
System.out.println("IOException:Could not parse :"+xml_doc); |
113 | 103 |
ParseError eip = null; |
114 |
eip = new ParseError("",0,0,"",
|
|
104 |
eip = new ParseError("",0,0, |
|
115 | 105 |
"IOException:Could not parse :"+xml_doc); |
116 | 106 |
if (ef.errorNodes == null) ef.errorNodes = new Vector(); |
117 | 107 |
ef.errorNodes.addElement(eip); |
... | ... | |
153 | 143 |
} |
154 | 144 |
} |
155 | 145 |
|
156 |
/** provide a list of errors fromthe validation process */ |
|
146 |
/** provide a list of errors from the validation process */
|
|
157 | 147 |
public String returnErrors() { |
158 |
String errorstring = ""; |
|
148 |
StringBuffer errorstring = new StringBuffer(); |
|
149 |
errorstring.append("<?xml version=\"1.0\" ?>\n"); |
|
159 | 150 |
if (ef != null && ef.getErrorNodes()!=null && |
160 | 151 |
ef.getErrorNodes().size() > 0 ) { |
161 | 152 |
Vector errors = ef.getErrorNodes(); |
153 |
errorstring.append("<validationerrors>\n"); |
|
162 | 154 |
for (Enumeration e = errors.elements() ; e.hasMoreElements() ;) { |
163 |
errorstring = errorstring + |
|
164 |
((ParseError)(e.nextElement())).getMsg()+"\n"; |
|
165 |
errorstring = errorstring + "----\n"; |
|
155 |
errorstring.append( |
|
156 |
((ParseError)(e.nextElement())).toXML()); |
|
166 | 157 |
} |
158 |
errorstring.append("</validationerrors>\n"); |
|
167 | 159 |
} else { |
168 |
errorstring = "No errors were detected!!!";
|
|
160 |
errorstring.append("<valid />\n");
|
|
169 | 161 |
} |
170 |
return errorstring; |
|
162 |
return errorstring.toString();
|
|
171 | 163 |
} |
172 | 164 |
|
173 | 165 |
/** Create a URL object from either a URL string or a plain file name. */ |
... | ... | |
196 | 188 |
String doc = args[0]; |
197 | 189 |
|
198 | 190 |
MetaCatUtil util = new MetaCatUtil(); |
199 |
DBValidate gxv = new DBValidate(util.getOption("saxparser")); |
|
200 |
if (gxv.validate(doc)) { |
|
201 |
System.out.println("XML is valid."); |
|
202 |
} else { |
|
203 |
System.out.print(gxv.returnErrors()); |
|
191 |
try { |
|
192 |
Connection conn = util.openDBConnection(); |
|
193 |
|
|
194 |
DBValidate gxv = new DBValidate(util.getOption("saxparser"), conn); |
|
195 |
if (gxv.validate(doc)) { |
|
196 |
System.out.print(gxv.returnErrors()); |
|
197 |
} else { |
|
198 |
System.out.print(gxv.returnErrors()); |
|
199 |
} |
|
200 |
} catch (SQLException e) { |
|
201 |
System.out.println("<error>Couldn't open database connection.</error>"); |
|
202 |
} catch (ClassNotFoundException e) { |
|
203 |
System.out.println("<error>Couldn't open database connection.</error>"); |
|
204 | 204 |
} |
205 | 205 |
} |
206 | 206 |
|
... | ... | |
265 | 265 |
private void handleError(SAXParseException ex, int type) { |
266 | 266 |
// System.out.println("!!! handleError: "+ex.getMessage()); |
267 | 267 |
|
268 |
StringBuffer errorString = new StringBuffer(); |
|
269 |
errorString.append("at line number, "); |
|
270 |
errorString.append(ex.getLineNumber()); |
|
271 |
errorString.append(": "); |
|
272 |
errorString.append(ex.getMessage()); |
|
273 |
|
|
274 | 268 |
if (errorNodes == null) { |
275 | 269 |
errorNodes = new Vector(); |
276 | 270 |
} |
271 |
|
|
277 | 272 |
ParseError eip = null; |
278 |
eip = new ParseError(ex.getSystemId(),ex.getLineNumber(), |
|
279 |
ex.getColumnNumber(),"",errorString.toString());
|
|
273 |
eip = new ParseError(ex.getSystemId(), ex.getLineNumber(),
|
|
274 |
ex.getColumnNumber(), ex.getMessage());
|
|
280 | 275 |
|
281 | 276 |
// put it in the Hashtable. |
282 | 277 |
errorNodes.addElement(eip); |
... | ... | |
299 | 294 |
String fileName; |
300 | 295 |
int lineNo; |
301 | 296 |
int charOffset; |
302 |
Object key; |
|
303 | 297 |
String msg; |
304 | 298 |
|
305 | 299 |
/** |
306 | 300 |
* Constructor |
307 | 301 |
*/ |
308 |
public ParseError(String fileName, int lineNo, int charOffset, |
|
309 |
Object key, String msg) { |
|
310 |
this. fileName=fileName; |
|
311 |
this. lineNo=lineNo; |
|
312 |
this. charOffset=charOffset; |
|
313 |
this. key=key; |
|
314 |
this. msg=msg; |
|
302 |
public ParseError(String fileName, int lineNo, int charOffset, String msg) { |
|
303 |
this.fileName=fileName; |
|
304 |
this.lineNo=lineNo; |
|
305 |
this.charOffset=charOffset; |
|
306 |
this.msg=msg; |
|
315 | 307 |
} |
316 | 308 |
|
317 | 309 |
// |
... | ... | |
320 | 312 |
public String getFileName() { return fileName; } |
321 | 313 |
public int getLineNo() { return lineNo; } |
322 | 314 |
public int getCharOffset() { return charOffset;} |
323 |
public Object getKey() { return key; } |
|
324 | 315 |
public String getMsg() { return msg; } |
325 | 316 |
public void setMsg(String s) { msg = s; } |
317 |
|
|
318 |
/** Return the error message as an xml fragment */ |
|
319 |
public String toXML() { |
|
320 |
StringBuffer err = new StringBuffer(); |
|
321 |
err.append("<error>\n"); |
|
322 |
err.append("<filename>").append(getFileName()).append("</filename>\n"); |
|
323 |
err.append("<line>").append(getLineNo()).append("</line>\n"); |
|
324 |
err.append("<offset>").append(getCharOffset()).append("</offset>\n"); |
|
325 |
err.append("<message>").append(getMsg()).append("</message>\n"); |
|
326 |
err.append("</error>\n"); |
|
327 |
return err.toString(); |
|
328 |
} |
|
326 | 329 |
} |
327 | 330 |
} |
328 | 331 |
|
329 | 332 |
/** |
330 | 333 |
* '$Log$ |
334 |
* 'Revision 1.7 2000/06/26 10:35:05 jones |
|
335 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
|
336 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
|
337 |
* 'functions. The command line tools and the parameters for the |
|
338 |
* 'servlet have changed substantially. |
|
339 |
* ' |
|
331 | 340 |
* 'Revision 1.6.2.3 2000/06/25 23:38:16 jones |
332 | 341 |
* 'Added RCSfile keyword |
333 | 342 |
* ' |
src/edu/ucsb/nceas/metacat/DBEntityResolver.java | ||
---|---|---|
4 | 4 |
* for resolving external entities |
5 | 5 |
* Copyright: 2000 Regents of the University of California and the |
6 | 6 |
* National Center for Ecological Analysis and Synthesis |
7 |
* Authors: Jivka Bojilova |
|
7 |
* Authors: Jivka Bojilova, Matt Jones
|
|
8 | 8 |
* |
9 | 9 |
* '$Author$' |
10 | 10 |
* '$Date$' |
... | ... | |
16 | 16 |
import org.xml.sax.*; |
17 | 17 |
|
18 | 18 |
import java.sql.*; |
19 |
import java.io.File; |
|
20 |
import java.io.FileReader; |
|
21 |
import java.io.InputStream; |
|
22 |
import java.io.InputStreamReader; |
|
23 |
import java.io.IOException; |
|
19 | 24 |
import java.net.URL; |
20 | 25 |
import java.net.URLConnection; |
21 | 26 |
import java.net.MalformedURLException; |
22 |
import java.io.IOException; |
|
23 | 27 |
import java.util.Stack; |
24 | 28 |
import java.util.EmptyStackException; |
25 | 29 |
|
... | ... | |
32 | 36 |
public class DBEntityResolver implements EntityResolver |
33 | 37 |
{ |
34 | 38 |
private Connection conn = null; |
35 |
private DBSAXHandler handler; |
|
39 |
private DBSAXHandler handler = null;
|
|
36 | 40 |
|
37 |
/** Construct an instance of the DBEntityResolver clas |
|
41 |
/** |
|
42 |
* Construct an instance of the DBEntityResolver class |
|
38 | 43 |
* |
39 | 44 |
* @param conn the JDBC connection to which information is written |
40 | 45 |
*/ |
46 |
public DBEntityResolver(Connection conn) |
|
47 |
{ |
|
48 |
this.conn = conn; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Construct an instance of the DBEntityResolver class |
|
53 |
* |
|
54 |
* @param conn the JDBC connection to which information is written |
|
55 |
* @param handler the SAX handler to determine parsing context |
|
56 |
*/ |
|
41 | 57 |
public DBEntityResolver(Connection conn, DBSAXHandler handler) |
42 | 58 |
{ |
43 |
this.conn = conn;
|
|
59 |
this(conn);
|
|
44 | 60 |
this.handler = handler; |
45 | 61 |
} |
46 | 62 |
|
... | ... | |
51 | 67 |
* referenced within the document element) |
52 | 68 |
*/ |
53 | 69 |
public InputSource resolveEntity (String publicId, String systemId) |
54 |
throws MalformedURLException, IOException
|
|
70 |
throws SAXException, IOException
|
|
55 | 71 |
{ |
56 | 72 |
String dbSystemId; |
57 | 73 |
String doctype = null; |
58 | 74 |
|
59 |
// Only process entities if its the DTD |
|
60 |
if (handler.atFirstElement()) { |
|
61 |
if (publicId != null) { // If we have a public ID, use it |
|
62 |
doctype = publicId; |
|
63 |
MetaCatUtil.debugMessage("DOCTYPE-c: " + doctype); |
|
64 |
} else if ( systemId != null) { // Otherwise, use system id if we can |
|
65 |
doctype = handler.getDocname(); |
|
66 |
MetaCatUtil.debugMessage("DOCTYPE-d: " + doctype); |
|
67 |
} |
|
68 |
// look at the db XML Catalog and get dbSystemId for this doctype |
|
69 |
dbSystemId = getDTDSystemID (conn, doctype); |
|
70 |
if (dbSystemId == "") { |
|
71 |
// if it is not found inthe database, then |
|
72 |
// register publicId in db and use the provided systemId |
|
73 |
if (systemId != "") { |
|
74 |
checkURLConnection(systemId); |
|
75 |
registerDTDSystemID (conn, doctype, doctype, systemId); |
|
76 |
return null; |
|
77 |
} |
|
78 |
} else { |
|
79 |
// If it is in the database, return the systemid fromthe database |
|
80 |
checkURLConnection(dbSystemId); |
|
81 |
return new InputSource(dbSystemId); |
|
82 |
} |
|
75 |
if (publicId != null) { // If we have a public ID, use it |
|
76 |
doctype = publicId; |
|
77 |
MetaCatUtil.debugMessage("DOCTYPE-c: " + doctype); |
|
78 |
} else if (systemId != null) { // Otherwise, use system id if we can |
|
79 |
if (handler != null) { // Won't have a handler under all cases |
|
80 |
if (handler.processingDTD()) { // Assume the public ID is the docname |
|
81 |
doctype = handler.getDocname(); |
|
82 |
MetaCatUtil.debugMessage("DOCTYPE-d: " + doctype); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
// look at the db XML Catalog and get dbSystemId for this doctype |
|
88 |
if (doctype != null) { |
|
89 |
dbSystemId = getDTDSystemID (conn, doctype); |
|
90 |
if (dbSystemId == null) { |
|
91 |
MetaCatUtil.debugMessage(" RESOLVED NOTHING"); |
|
92 |
// if it is not found in the database, then |
|
93 |
// register publicId in db and use the provided systemId |
|
94 |
if (systemId != null) { |
|
95 |
InputStreamReader isr = checkURLConnection(systemId); |
|
96 |
if (handler != null) { // Won't have a handler under all cases |
|
97 |
if (handler.processingDTD()) { |
|
98 |
registerDTDSystemID (conn, doctype, doctype, systemId); |
|
99 |
} |
|
100 |
} |
|
101 |
return null; |
|
102 |
} |
|
103 |
} else { |
|
104 |
MetaCatUtil.debugMessage(" RESOLVED SYSTEMID: " + dbSystemId); |
|
105 |
// If it is in the database, return the systemid from the database |
|
106 |
InputStreamReader isr = checkURLConnection(dbSystemId); |
|
107 |
InputSource is = new InputSource(dbSystemId); |
|
108 |
is.setCharacterStream(isr); |
|
109 |
MetaCatUtil.debugMessage(" INPUTSOURCE SYSTEMID: " |
|
110 |
+ is.getSystemId()); |
|
111 |
return is; |
|
112 |
} |
|
83 | 113 |
} |
84 | 114 |
|
85 |
// use the default behaviour for other cases
|
|
86 |
checkURLConnection(systemId); |
|
115 |
// use the provided systemID for other cases
|
|
116 |
InputStreamReader isr = checkURLConnection(systemId);
|
|
87 | 117 |
return null; |
88 | 118 |
} |
89 | 119 |
|
... | ... | |
92 | 122 |
* Return empty string if there are not |
93 | 123 |
*/ |
94 | 124 |
private String getDTDSystemID (Connection conn, String doctype) { |
95 |
String system_id = "";
|
|
125 |
String system_id = null;
|
|
96 | 126 |
Statement stmt; |
97 | 127 |
try { |
98 | 128 |
stmt = conn.createStatement(); |
... | ... | |
123 | 153 |
} catch (SQLException e) { |
124 | 154 |
System.out.println("DBEntityResolver.getDTDSystemID() " + |
125 | 155 |
"- Error getting id: " + e.getMessage()); |
126 |
System.exit(1); |
|
127 | 156 |
} |
128 | 157 |
|
129 | 158 |
// return the selected System ID |
... | ... | |
136 | 165 |
private void registerDTDSystemID (Connection conn, String doctype, |
137 | 166 |
String publicId, String systemId) |
138 | 167 |
{ |
139 |
try {
|
|
140 |
PreparedStatement pstmt;
|
|
141 |
pstmt = conn.prepareStatement(
|
|
142 |
"INSERT INTO xml_catalog " +
|
|
143 |
"(catalog_id, entry_type, source_doctype, " +
|
|
144 |
"public_id, system_id) " +
|
|
145 |
"VALUES (null, 'DTD', ?, ?, ?)");
|
|
146 |
// Bind the values to the query
|
|
147 |
pstmt.setString(1, doctype);
|
|
148 |
pstmt.setString(2, publicId);
|
|
149 |
pstmt.setString(3, systemId);
|
|
150 |
// Do the insertion
|
|
151 |
pstmt.execute();
|
|
152 |
pstmt.close();
|
|
153 |
} catch (SQLException e) {
|
|
154 |
System.out.println(e.getMessage());
|
|
155 |
}
|
|
168 |
try { |
|
169 |
PreparedStatement pstmt; |
|
170 |
pstmt = conn.prepareStatement( |
|
171 |
"INSERT INTO xml_catalog " + |
|
172 |
"(catalog_id, entry_type, source_doctype, " + |
|
173 |
"public_id, system_id) " + |
|
174 |
"VALUES (null, 'DTD', ?, ?, ?)"); |
|
175 |
// Bind the values to the query |
|
176 |
pstmt.setString(1, doctype); |
|
177 |
pstmt.setString(2, publicId); |
|
178 |
pstmt.setString(3, systemId); |
|
179 |
// Do the insertion |
|
180 |
pstmt.execute(); |
|
181 |
pstmt.close(); |
|
182 |
} catch (SQLException e) { |
|
183 |
System.out.println(e.getMessage()); |
|
184 |
} |
|
156 | 185 |
} |
186 |
|
|
157 | 187 |
/** |
158 |
* Check URL Connection for systemId |
|
188 |
* Check URL Connection for systemId, and return an InputStreamReader |
|
189 |
* that can be used to read from the systemId URL. The parser ends |
|
190 |
* up using this via the InputSource to read the DTD. |
|
191 |
* |
|
192 |
* @param systemID a URI (in practice URL) to be checked and opened |
|
159 | 193 |
*/ |
160 |
private void checkURLConnection (String systemId)
|
|
194 |
private InputStreamReader checkURLConnection (String systemId)
|
|
161 | 195 |
throws MalformedURLException, IOException |
162 | 196 |
{ |
163 |
try { |
|
164 |
URLConnection urlConn = (new URL(systemId)).openConnection(); |
|
165 |
urlConn.connect(); |
|
166 |
} catch (MalformedURLException e) { |
|
167 |
System.out.println("from checkURLConnection(): " + e.getMessage()); |
|
168 |
throw e; |
|
169 |
} catch (IOException e) { |
|
170 |
System.out.println("from checkURLConnection(): " + e.getMessage()); |
|
171 |
throw e; |
|
172 |
} |
|
197 |
try { |
|
198 |
InputStreamReader isr = new InputStreamReader( |
|
199 |
new URL(systemId).openStream()); |
|
200 |
return isr; |
|
201 |
} catch (MalformedURLException e) { |
|
202 |
System.out.println("from checkURLConnection(): " + e.getMessage()); |
|
203 |
throw e; |
|
204 |
} catch (IOException e) { |
|
205 |
System.out.println("from checkURLConnection(): " + e.getMessage()); |
|
206 |
throw e; |
|
207 |
} |
|
173 | 208 |
} |
174 | 209 |
} |
175 | 210 |
|
176 | 211 |
/** |
177 | 212 |
* '$Log$ |
213 |
* 'Revision 1.12 2000/06/27 04:31:07 jones |
|
214 |
* 'Fixed bugs associated with the new UPDATE and DELETE functions of |
|
215 |
* 'DBWriter. There were problematic interactions between some static |
|
216 |
* 'variables used in DBEntityResolver and the way in which the |
|
217 |
* 'Servlet objects are re-used across multiple client invocations. |
|
218 |
* ' |
|
219 |
* 'Generally cleaned up error reporting. Now all errors and success |
|
220 |
* 'results are reported as XML documents from MetaCatServlet. Need |
|
221 |
* 'to make the command line tools do the same. |
|
222 |
* ' |
|
178 | 223 |
* 'Revision 1.11 2000/06/26 10:35:04 jones |
179 | 224 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
180 | 225 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
src/edu/ucsb/nceas/metacat/DBWriter.java | ||
---|---|---|
211 | 211 |
chandler); |
212 | 212 |
parser.setProperty("http://xml.org/sax/properties/lexical-handler", |
213 | 213 |
chandler); |
214 |
parser.setContentHandler(chandler); |
|
215 |
parser.setEntityResolver(dbresolver); |
|
216 |
parser.setDTDHandler(dtdhandler); |
|
214 |
parser.setContentHandler((ContentHandler)chandler);
|
|
215 |
parser.setEntityResolver((EntityResolver)dbresolver);
|
|
216 |
parser.setDTDHandler((DTDHandler)dtdhandler);
|
|
217 | 217 |
parser.setErrorHandler((ErrorHandler)chandler); |
218 | 218 |
|
219 | 219 |
} catch (Exception e) { |
... | ... | |
250 | 250 |
|
251 | 251 |
/** |
252 | 252 |
* '$Log$ |
253 |
* 'Revision 1.22 2000/06/27 04:31:07 jones |
|
254 |
* 'Fixed bugs associated with the new UPDATE and DELETE functions of |
|
255 |
* 'DBWriter. There were problematic interactions between some static |
|
256 |
* 'variables used in DBEntityResolver and the way in which the |
|
257 |
* 'Servlet objects are re-used across multiple client invocations. |
|
258 |
* ' |
|
259 |
* 'Generally cleaned up error reporting. Now all errors and success |
|
260 |
* 'results are reported as XML documents from MetaCatServlet. Need |
|
261 |
* 'to make the command line tools do the same. |
|
262 |
* ' |
|
253 | 263 |
* 'Revision 1.21 2000/06/26 10:35:05 jones |
254 | 264 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
255 | 265 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
559 | 559 |
valtext = docreader.readXMLDocument(docid); |
560 | 560 |
|
561 | 561 |
} catch (NullPointerException npe) { |
562 |
response.setContentType("text/html");
|
|
563 |
out.println("Error getting document ID: " + docid );
|
|
562 |
response.setContentType("text/xml");
|
|
563 |
out.println("<error>Error getting document ID: " + docid + "</error>");
|
|
564 | 564 |
} |
565 | 565 |
} |
566 | 566 |
|
567 | 567 |
try { |
568 |
DBValidate valobj = new DBValidate(saxparser,xmlcatalogfile);
|
|
568 |
DBValidate valobj = new DBValidate(saxparser,conn);
|
|
569 | 569 |
boolean valid = valobj.validateString(valtext); |
570 | 570 |
|
571 | 571 |
// set content type and other response header fields first |
572 |
response.setContentType("text/html"); |
|
573 |
out.println("<html>"); |
|
574 |
out.println("<head><link rel=\"stylesheet\" type=\"text/css\" " + |
|
575 |
"href=\"/xmltodb/rowcol.css\" /></head>"); |
|
576 |
out.println("<body class=\"emlbody\">"); |
|
577 |
|
|
578 |
if (valid) { |
|
579 |
out.println("The input XML is VALID!"); |
|
580 |
} else { |
|
581 |
out.println("The input XML is NOT VALID<br />\n<pre>\n" |
|
582 |
+ valobj.returnErrors() + "\n</pre>\n"); |
|
583 |
} |
|
584 |
out.println("</body></html>"); |
|
572 |
response.setContentType("text/xml"); |
|
573 |
out.println(valobj.returnErrors()); |
|
574 |
|
|
585 | 575 |
} catch (NullPointerException npe2) { |
586 | 576 |
// set content type and other response header fields first |
587 |
response.setContentType("text/html");
|
|
588 |
out.println("Error validating document.");
|
|
577 |
response.setContentType("text/xml");
|
|
578 |
out.println("<error>Error validating document.</error>");
|
|
589 | 579 |
} |
590 | 580 |
} |
591 | 581 |
|
... | ... | |
647 | 637 |
|
648 | 638 |
/** |
649 | 639 |
* '$Log$ |
640 |
* 'Revision 1.48 2000/06/29 20:04:51 bojilova |
|
641 |
* 'testing login |
|
642 |
* ' |
|
650 | 643 |
* 'Revision 1.36 2000/06/28 02:36:26 jones |
651 | 644 |
* 'Added feature to now ouput COMMENTs and PIs when the document is |
652 | 645 |
* 'read from the database with DBReader. |
bin/loadxml | ||
---|---|---|
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 |
export PARSER=/home/jones/software/xml-xerces/java/build/xerces.jar
|
|
3 |
export PARSER=/home/httpd/servlets/xerces.jar
|
|
4 | 4 |
export PDIR=/home/jones/projects/pbi/development/xmltodb |
5 | 5 |
export JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip |
6 | 6 |
|
Also available in: Unified diff
Fixed bug in DBEntityResolver so that it now properly delegates to
the system id found inthe database.
Changed DBValidate to use DBEntityResolver, rather than the OASIS
catalog, and to return validation results in XML format.