Revision 4425
Added by daigle about 16 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package edu.ucsb.nceas.metacat; |
29 | 29 |
|
30 |
import java.sql.PreparedStatement; |
|
31 | 30 |
import java.sql.ResultSet; |
32 |
import java.sql.SQLException; |
|
33 | 31 |
import java.sql.Statement; |
34 | 32 |
import java.util.EmptyStackException; |
35 | 33 |
import java.util.Enumeration; |
... | ... | |
38 | 36 |
import java.util.Vector; |
39 | 37 |
|
40 | 38 |
import edu.ucsb.nceas.metacat.service.PropertyService; |
39 |
import edu.ucsb.nceas.metacat.service.XMLSchema; |
|
41 | 40 |
import edu.ucsb.nceas.metacat.util.MetaCatUtil; |
42 | 41 |
import edu.ucsb.nceas.morpho.datapackage.Triple; |
43 | 42 |
import edu.ucsb.nceas.morpho.datapackage.TripleCollection; |
44 | 43 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
44 |
import edu.ucsb.nceas.utilities.StringUtil; |
|
45 | 45 |
|
46 | 46 |
import org.apache.log4j.Logger; |
47 | 47 |
import org.xml.sax.Attributes; |
... | ... | |
124 | 124 |
// private static final int MAXTITLELEN = 1000; |
125 | 125 |
|
126 | 126 |
private boolean isRevisionDoc = false; |
127 |
|
|
128 |
protected Vector<XMLSchema> schemaList = new Vector<XMLSchema>(); |
|
127 | 129 |
|
128 | 130 |
//HandlerTriple stuff |
129 | 131 |
TripleCollection tripleList = new TripleCollection(); |
... | ... | |
254 | 256 |
throw new SAXException("Failed to write triples into relation table " |
255 | 257 |
+ e.getMessage()); |
256 | 258 |
} |
259 |
|
|
260 |
// If we get here, the document and schema parsed okay. If there are |
|
261 |
// any schemas in the schema list, they are new and need to be registered. |
|
262 |
for (XMLSchema xmlSchema : schemaList) { |
|
263 |
String externalFileUri = xmlSchema.getExternalFileUri(); |
|
264 |
String fileNamespace = xmlSchema.getFileNamespace(); |
|
265 |
SchemaLocationResolver resolver = |
|
266 |
new SchemaLocationResolver(fileNamespace, externalFileUri); |
|
267 |
resolver.resolveNameSpace(); |
|
268 |
} |
|
257 | 269 |
} |
258 | 270 |
|
259 | 271 |
/** SAX Handler that is called at the start of Namespace */ |
... | ... | |
405 | 417 |
docid); |
406 | 418 |
|
407 | 419 |
// To handle name space and schema location if the attribute name |
408 |
// is |
|
409 |
// xsi:schemaLocation. If the name space is in not in catalog table |
|
410 |
// it will be regeistered. |
|
420 |
// is xsi:schemaLocation. If the name space is in not in catalog |
|
421 |
// table it will be registered. |
|
411 | 422 |
if (attributeName != null |
412 | 423 |
&& attributeName |
413 | 424 |
.indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1) { |
414 |
SchemaLocationResolver resolver = new SchemaLocationResolver( |
|
415 |
attributeValue); |
|
416 |
resolver.resolveNameSpace(); |
|
417 |
|
|
425 |
// These schemas will be registered in the end endDocument() method |
|
426 |
// assuming parsing is successful. |
|
427 |
// each namespace could have several schema locations. parsedUri will |
|
428 |
// hold a list of uri and files. |
|
429 |
attributeValue = StringUtil.replaceTabsNewLines(attributeValue); |
|
430 |
attributeValue = StringUtil.replaceDuplicateSpaces(attributeValue); |
|
431 |
Vector<String> parsedUri = StringUtil.toVector(attributeValue, ' '); |
|
432 |
for (int j = 0; j < parsedUri.size(); j = j + 2 ) { |
|
433 |
if (j + 1 >= parsedUri.size()) { |
|
434 |
throw new SAXException("Odd number of elements found when parsing schema location: " + |
|
435 |
attributeValue + ". There should be an even number of uri/files in location."); |
|
436 |
} |
|
437 |
XMLSchema xmlSchema = |
|
438 |
new XMLSchema(parsedUri.get(j), parsedUri.get(j + 1)); |
|
439 |
schemaList.add(xmlSchema); |
|
440 |
} |
|
418 | 441 |
} |
419 | 442 |
} |
420 | 443 |
|
Also available in: Unified diff
Store schemaLocations as they are found in startElement. Save them in endDocument. In this way, schemas will only get saved locally if the document parses successfully.