Revision 83
Added by Matt Jones over 24 years ago
src/edu/ucsb/nceas/metacat/DBValidate.java | ||
---|---|---|
32 | 32 |
static int ERROR=1; |
33 | 33 |
static int FATAL_ERROR=2; |
34 | 34 |
|
35 |
static String defaultCatalog = "/home/httpd/html/xmltodb/catalog.txt"; |
|
36 |
|
|
37 | 35 |
Parser parser; |
38 | 36 |
ErrorStorer ef; |
39 | 37 |
String xml_doc; // document to be parsed |
40 | 38 |
|
41 |
public GenericXMLValidate( Parser parse) {
|
|
39 |
public GenericXMLValidate(Parser parse) { |
|
42 | 40 |
parser = parse; |
43 | 41 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
44 | 42 |
try { |
45 | 43 |
Catalog myCatalog = new Catalog(); |
46 | 44 |
myCatalog.loadSystemCatalogs(); |
47 |
myCatalog.parseCatalog(defaultCatalog); |
|
48 | 45 |
cer.setCatalog(myCatalog); |
49 | 46 |
} |
50 | 47 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
... | ... | |
70 | 67 |
*/ |
71 | 68 |
} |
72 | 69 |
|
70 |
public GenericXMLValidate(Parser parse, String xmlcatalogfile) { |
|
71 |
parser = parse; |
|
72 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
|
73 |
try { |
|
74 |
Catalog myCatalog = new Catalog(); |
|
75 |
myCatalog.loadSystemCatalogs(); |
|
76 |
myCatalog.parseCatalog(xmlcatalogfile); |
|
77 |
cer.setCatalog(myCatalog); |
|
78 |
} |
|
79 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
|
80 |
parser.setEntityResolver(cer); |
|
81 |
} |
|
82 |
|
|
73 | 83 |
public boolean validate(String doc) { |
74 | 84 |
xml_doc = doc; |
75 | 85 |
ef = new ErrorStorer(); |
src/edu/ucsb/nceas/metacat/GenericXMLValidate.java | ||
---|---|---|
32 | 32 |
static int ERROR=1; |
33 | 33 |
static int FATAL_ERROR=2; |
34 | 34 |
|
35 |
static String defaultCatalog = "/home/httpd/html/xmltodb/catalog.txt"; |
|
36 |
|
|
37 | 35 |
Parser parser; |
38 | 36 |
ErrorStorer ef; |
39 | 37 |
String xml_doc; // document to be parsed |
40 | 38 |
|
41 |
public GenericXMLValidate( Parser parse) {
|
|
39 |
public GenericXMLValidate(Parser parse) { |
|
42 | 40 |
parser = parse; |
43 | 41 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
44 | 42 |
try { |
45 | 43 |
Catalog myCatalog = new Catalog(); |
46 | 44 |
myCatalog.loadSystemCatalogs(); |
47 |
myCatalog.parseCatalog(defaultCatalog); |
|
48 | 45 |
cer.setCatalog(myCatalog); |
49 | 46 |
} |
50 | 47 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
... | ... | |
70 | 67 |
*/ |
71 | 68 |
} |
72 | 69 |
|
70 |
public GenericXMLValidate(Parser parse, String xmlcatalogfile) { |
|
71 |
parser = parse; |
|
72 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
|
73 |
try { |
|
74 |
Catalog myCatalog = new Catalog(); |
|
75 |
myCatalog.loadSystemCatalogs(); |
|
76 |
myCatalog.parseCatalog(xmlcatalogfile); |
|
77 |
cer.setCatalog(myCatalog); |
|
78 |
} |
|
79 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
|
80 |
parser.setEntityResolver(cer); |
|
81 |
} |
|
82 |
|
|
73 | 83 |
public boolean validate(String doc) { |
74 | 84 |
xml_doc = doc; |
75 | 85 |
ef = new ErrorStorer(); |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
67 | 67 |
String password = null; |
68 | 68 |
String defaultDB = null; |
69 | 69 |
String resultStyleURL = null; |
70 |
//String resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
|
|
70 |
String xmlcatalogfile = null;
|
|
71 | 71 |
PropertyResourceBundle options = null; |
72 | 72 |
|
73 | 73 |
/** |
... | ... | |
80 | 80 |
this.context = config.getServletContext(); |
81 | 81 |
System.out.println("Servlet Initialize"); |
82 | 82 |
|
83 |
// Get the configuration file |
|
83 |
// Get the configuration file information
|
|
84 | 84 |
options = (PropertyResourceBundle)PropertyResourceBundle.getBundle("edu.ucsb.nceas.metacat.metacat"); |
85 | 85 |
user = (String)options.handleGetObject("user"); |
86 | 86 |
password = (String)options.handleGetObject("password"); |
87 | 87 |
defaultDB = (String)options.handleGetObject("defaultDB"); |
88 | 88 |
resultStyleURL = (String)options.handleGetObject("resultStyleURL"); |
89 |
xmlcatalogfile = (String)options.handleGetObject("xmlcatalogfile"); |
|
89 | 90 |
|
90 | 91 |
try { |
91 | 92 |
// Open a connection to the database |
... | ... | |
170 | 171 |
nodelist = queryobj.findRootNodes(query); |
171 | 172 |
} else { |
172 | 173 |
out.println("Query Object Init failed."); |
174 |
/* |
|
173 | 175 |
out.println(user); |
174 | 176 |
out.println(defaultDB); |
177 |
out.println(xmlcatalogfile); |
|
178 |
*/ |
|
179 |
return; |
|
175 | 180 |
} |
176 | 181 |
|
177 | 182 |
// Create a buffer to hold the xml result |
... | ... | |
266 | 271 |
|
267 | 272 |
SAXParser parser = new SAXParser(); // works for both Xerces and Oracle |
268 | 273 |
parser.setValidationMode(true); // Oracle |
269 |
GenericXMLValidate gxv = new GenericXMLValidate(parser); |
|
274 |
GenericXMLValidate gxv = new GenericXMLValidate(parser, xmlcatalogfile);
|
|
270 | 275 |
boolean valid = gxv.validateString(valtext[0]); |
271 | 276 |
|
272 | 277 |
// set content type and other response header fields first |
GenericXMLValidate.java | ||
---|---|---|
32 | 32 |
static int ERROR=1; |
33 | 33 |
static int FATAL_ERROR=2; |
34 | 34 |
|
35 |
static String defaultCatalog = "/home/httpd/html/xmltodb/catalog.txt"; |
|
36 |
|
|
37 | 35 |
Parser parser; |
38 | 36 |
ErrorStorer ef; |
39 | 37 |
String xml_doc; // document to be parsed |
40 | 38 |
|
41 |
public GenericXMLValidate( Parser parse) {
|
|
39 |
public GenericXMLValidate(Parser parse) { |
|
42 | 40 |
parser = parse; |
43 | 41 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
44 | 42 |
try { |
45 | 43 |
Catalog myCatalog = new Catalog(); |
46 | 44 |
myCatalog.loadSystemCatalogs(); |
47 |
myCatalog.parseCatalog(defaultCatalog); |
|
48 | 45 |
cer.setCatalog(myCatalog); |
49 | 46 |
} |
50 | 47 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
... | ... | |
70 | 67 |
*/ |
71 | 68 |
} |
72 | 69 |
|
70 |
public GenericXMLValidate(Parser parse, String xmlcatalogfile) { |
|
71 |
parser = parse; |
|
72 |
CatalogEntityResolver cer = new CatalogEntityResolver(); |
|
73 |
try { |
|
74 |
Catalog myCatalog = new Catalog(); |
|
75 |
myCatalog.loadSystemCatalogs(); |
|
76 |
myCatalog.parseCatalog(xmlcatalogfile); |
|
77 |
cer.setCatalog(myCatalog); |
|
78 |
} |
|
79 |
catch (Exception e) {System.out.println("Problem creating Catalog!");} |
|
80 |
parser.setEntityResolver(cer); |
|
81 |
} |
|
82 |
|
|
73 | 83 |
public boolean validate(String doc) { |
74 | 84 |
xml_doc = doc; |
75 | 85 |
ef = new ErrorStorer(); |
validate.html | ||
---|---|---|
11 | 11 |
<input type="hidden" name="action" value="validate"> |
12 | 12 |
<p><textarea |
13 | 13 |
name="valtext" rows="16" cols="146"><?xml version="1.0"?> |
14 |
<!DOCTYPE eml-dataset SYSTEM "eml-dataset.dtd"> <eml-dataset> <meta_file_id>NCEAS-1998-2090-Dataset</meta_file_id>
|
|
14 |
<!DOCTYPE eml-dataset PUBLIC "-//NCEAS//eml-dataset//EN" "eml-dataset.dtd"> <eml-dataset> <meta_file_id>NCEAS-1998-2090-Dataset</meta_file_id>
|
|
15 | 15 |
<dataset_id>NCEAS-1998-2090</dataset_id> <title>Trapping locations, |
16 | 16 |
animal body mass, and breeding conditions of Neotoma fuscipes on Sedgwick |
17 | 17 |
Reserve</title> <originator> <party> <!--(party_individual|party_org)--> |
MetaCatServlet.java | ||
---|---|---|
67 | 67 |
String password = null; |
68 | 68 |
String defaultDB = null; |
69 | 69 |
String resultStyleURL = null; |
70 |
//String resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
|
|
70 |
String xmlcatalogfile = null;
|
|
71 | 71 |
PropertyResourceBundle options = null; |
72 | 72 |
|
73 | 73 |
/** |
... | ... | |
80 | 80 |
this.context = config.getServletContext(); |
81 | 81 |
System.out.println("Servlet Initialize"); |
82 | 82 |
|
83 |
// Get the configuration file |
|
83 |
// Get the configuration file information
|
|
84 | 84 |
options = (PropertyResourceBundle)PropertyResourceBundle.getBundle("edu.ucsb.nceas.metacat.metacat"); |
85 | 85 |
user = (String)options.handleGetObject("user"); |
86 | 86 |
password = (String)options.handleGetObject("password"); |
87 | 87 |
defaultDB = (String)options.handleGetObject("defaultDB"); |
88 | 88 |
resultStyleURL = (String)options.handleGetObject("resultStyleURL"); |
89 |
xmlcatalogfile = (String)options.handleGetObject("xmlcatalogfile"); |
|
89 | 90 |
|
90 | 91 |
try { |
91 | 92 |
// Open a connection to the database |
... | ... | |
170 | 171 |
nodelist = queryobj.findRootNodes(query); |
171 | 172 |
} else { |
172 | 173 |
out.println("Query Object Init failed."); |
174 |
/* |
|
173 | 175 |
out.println(user); |
174 | 176 |
out.println(defaultDB); |
177 |
out.println(xmlcatalogfile); |
|
178 |
*/ |
|
179 |
return; |
|
175 | 180 |
} |
176 | 181 |
|
177 | 182 |
// Create a buffer to hold the xml result |
... | ... | |
266 | 271 |
|
267 | 272 |
SAXParser parser = new SAXParser(); // works for both Xerces and Oracle |
268 | 273 |
parser.setValidationMode(true); // Oracle |
269 |
GenericXMLValidate gxv = new GenericXMLValidate(parser); |
|
274 |
GenericXMLValidate gxv = new GenericXMLValidate(parser, xmlcatalogfile);
|
|
270 | 275 |
boolean valid = gxv.validateString(valtext[0]); |
271 | 276 |
|
272 | 277 |
// set content type and other response header fields first |
lib/metacat.properties | ||
---|---|---|
8 | 8 |
defaultDB=jdbc:oracle:thin:@localhost:1521:test |
9 | 9 |
dbDriver=oracle.jdbc.driver.OracleDriver |
10 | 10 |
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl |
11 |
xmlcatalogfile=/home/httpd/html/xmltodb/catalog.txt |
lib/validate.html | ||
---|---|---|
11 | 11 |
<input type="hidden" name="action" value="validate"> |
12 | 12 |
<p><textarea |
13 | 13 |
name="valtext" rows="16" cols="146"><?xml version="1.0"?> |
14 |
<!DOCTYPE eml-dataset SYSTEM "eml-dataset.dtd"> <eml-dataset> <meta_file_id>NCEAS-1998-2090-Dataset</meta_file_id>
|
|
14 |
<!DOCTYPE eml-dataset PUBLIC "-//NCEAS//eml-dataset//EN" "eml-dataset.dtd"> <eml-dataset> <meta_file_id>NCEAS-1998-2090-Dataset</meta_file_id>
|
|
15 | 15 |
<dataset_id>NCEAS-1998-2090</dataset_id> <title>Trapping locations, |
16 | 16 |
animal body mass, and breeding conditions of Neotoma fuscipes on Sedgwick |
17 | 17 |
Reserve</title> <originator> <party> <!--(party_individual|party_org)--> |
metacat.properties | ||
---|---|---|
8 | 8 |
defaultDB=jdbc:oracle:thin:@localhost:1521:test |
9 | 9 |
dbDriver=oracle.jdbc.driver.OracleDriver |
10 | 10 |
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl |
11 |
xmlcatalogfile=/home/httpd/html/xmltodb/catalog.txt |
Also available in: Unified diff
changed location of catalog file to config parameter