Revision 68
Added by higgins almost 25 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
35 | 35 |
import oracle.xml.parser.v2.XSLException; |
36 | 36 |
import oracle.xml.parser.v2.XMLDocumentFragment; |
37 | 37 |
import oracle.xml.parser.v2.XSLProcessor; |
38 |
import oracle.xml.parser.v2.*; //Oracle parser - DFH |
|
38 | 39 |
|
39 | 40 |
/** |
40 | 41 |
* A metadata catalog server implemented as a Java Servlet |
... | ... | |
49 | 50 |
* docid=34 -- display the document with the document ID number 34<br> |
50 | 51 |
* action=putdocument -- load an XML document into the database store<br> |
51 | 52 |
* doctext -- XML text ofthe document to load into the database<br> |
53 |
* query -- actual query text (to go with 'action=query')<br> |
|
54 |
* action=validate -- vallidate the xml contained in validatetext<br> |
|
55 |
* valtext -- XML text to be validated |
|
52 | 56 |
*/ |
53 | 57 |
public class MetaCatServlet extends HttpServlet { |
54 | 58 |
|
... | ... | |
70 | 74 |
super.init( config ); |
71 | 75 |
this.config = config; |
72 | 76 |
this.context = config.getServletContext(); |
73 |
|
|
77 |
System.out.println("Servlet Initialize"); |
|
74 | 78 |
try { |
75 | 79 |
// Open a connection to the database |
76 | 80 |
conn = MetaCatUtil.openDBConnection( |
... | ... | |
79 | 83 |
|
80 | 84 |
queryobj = new DBSimpleQuery(conn); |
81 | 85 |
docreader = new DBReader(conn); |
86 |
|
|
82 | 87 |
} catch (Exception e) { |
83 | 88 |
} |
84 | 89 |
} catch ( ServletException ex ) { |
... | ... | |
130 | 135 |
handleGetDocumentAction(out, params, response); |
131 | 136 |
} else if (action.equals("putdocument")) { |
132 | 137 |
handlePutDocumentAction(out, params, response); |
138 |
} else if (action.equals("validate")) { |
|
139 |
handleValidateAction(out, params, response); |
|
133 | 140 |
} else { |
134 | 141 |
out.println("Error: action not registered. Please report this error."); |
135 | 142 |
} |
... | ... | |
227 | 234 |
|
228 | 235 |
out.println(doctext[0]); |
229 | 236 |
} |
237 |
|
|
238 |
/** |
|
239 |
* Handle the validtion request and return the results |
|
240 |
* to the requestor - DFH |
|
241 |
*/ |
|
242 |
private void handleValidateAction(PrintWriter out, Hashtable params, HttpServletResponse response) { |
|
243 |
|
|
244 |
// Get the document indicated |
|
245 |
String[] valtext = (String[])params.get("valtext"); |
|
246 |
|
|
247 |
|
|
248 |
SAXParser parser = new SAXParser(); // works for both Xerces and Oracle |
|
249 |
parser.setValidationMode(true); // Oracle |
|
250 |
GenericXMLValidate gxv = new GenericXMLValidate(parser); |
|
251 |
boolean valid = gxv.validateString(valtext[0]); |
|
252 |
|
|
253 |
// set content type and other response header fields first |
|
254 |
response.setContentType("text/plain"); |
|
255 |
|
|
256 |
if (valid) { |
|
257 |
out.println("The input XML is VALID!"); |
|
258 |
} |
|
259 |
else { |
|
260 |
out.println("The input XML is NOT VALID\n" + gxv.returnErrors()); |
|
261 |
} |
|
262 |
} |
|
230 | 263 |
} |
MetaCatServlet.java | ||
---|---|---|
35 | 35 |
import oracle.xml.parser.v2.XSLException; |
36 | 36 |
import oracle.xml.parser.v2.XMLDocumentFragment; |
37 | 37 |
import oracle.xml.parser.v2.XSLProcessor; |
38 |
import oracle.xml.parser.v2.*; //Oracle parser - DFH |
|
38 | 39 |
|
39 | 40 |
/** |
40 | 41 |
* A metadata catalog server implemented as a Java Servlet |
... | ... | |
49 | 50 |
* docid=34 -- display the document with the document ID number 34<br> |
50 | 51 |
* action=putdocument -- load an XML document into the database store<br> |
51 | 52 |
* doctext -- XML text ofthe document to load into the database<br> |
53 |
* query -- actual query text (to go with 'action=query')<br> |
|
54 |
* action=validate -- vallidate the xml contained in validatetext<br> |
|
55 |
* valtext -- XML text to be validated |
|
52 | 56 |
*/ |
53 | 57 |
public class MetaCatServlet extends HttpServlet { |
54 | 58 |
|
... | ... | |
70 | 74 |
super.init( config ); |
71 | 75 |
this.config = config; |
72 | 76 |
this.context = config.getServletContext(); |
73 |
|
|
77 |
System.out.println("Servlet Initialize"); |
|
74 | 78 |
try { |
75 | 79 |
// Open a connection to the database |
76 | 80 |
conn = MetaCatUtil.openDBConnection( |
... | ... | |
79 | 83 |
|
80 | 84 |
queryobj = new DBSimpleQuery(conn); |
81 | 85 |
docreader = new DBReader(conn); |
86 |
|
|
82 | 87 |
} catch (Exception e) { |
83 | 88 |
} |
84 | 89 |
} catch ( ServletException ex ) { |
... | ... | |
130 | 135 |
handleGetDocumentAction(out, params, response); |
131 | 136 |
} else if (action.equals("putdocument")) { |
132 | 137 |
handlePutDocumentAction(out, params, response); |
138 |
} else if (action.equals("validate")) { |
|
139 |
handleValidateAction(out, params, response); |
|
133 | 140 |
} else { |
134 | 141 |
out.println("Error: action not registered. Please report this error."); |
135 | 142 |
} |
... | ... | |
227 | 234 |
|
228 | 235 |
out.println(doctext[0]); |
229 | 236 |
} |
237 |
|
|
238 |
/** |
|
239 |
* Handle the validtion request and return the results |
|
240 |
* to the requestor - DFH |
|
241 |
*/ |
|
242 |
private void handleValidateAction(PrintWriter out, Hashtable params, HttpServletResponse response) { |
|
243 |
|
|
244 |
// Get the document indicated |
|
245 |
String[] valtext = (String[])params.get("valtext"); |
|
246 |
|
|
247 |
|
|
248 |
SAXParser parser = new SAXParser(); // works for both Xerces and Oracle |
|
249 |
parser.setValidationMode(true); // Oracle |
|
250 |
GenericXMLValidate gxv = new GenericXMLValidate(parser); |
|
251 |
boolean valid = gxv.validateString(valtext[0]); |
|
252 |
|
|
253 |
// set content type and other response header fields first |
|
254 |
response.setContentType("text/plain"); |
|
255 |
|
|
256 |
if (valid) { |
|
257 |
out.println("The input XML is VALID!"); |
|
258 |
} |
|
259 |
else { |
|
260 |
out.println("The input XML is NOT VALID\n" + gxv.returnErrors()); |
|
261 |
} |
|
262 |
} |
|
230 | 263 |
} |
Also available in: Unified diff
MetaCatServlet Modifications for XML Validation;