01: package xmlc.demo;
02:
03: import javax.servlet.http.HttpServlet;
04: import javax.servlet.http.HttpServletRequest;
05: import javax.servlet.http.HttpServletResponse;
06: import javax.servlet.ServletException;
07: import org.enhydra.xml.xmlc.servlet.XMLCContext;
08: import org.enhydra.xml.xmlc.XMLObject;
09: import org.enhydra.xml.xmlc.XMLCFactory;
10: import org.enhydra.xml.xmlc.deferredparsing.XMLCDeferredParsingFactory;
11:
12: public class ReloadTest extends HttpServlet {
13:
14: protected void service(HttpServletRequest req,
15: HttpServletResponse resp) throws ServletException {
16: XMLCContext context = XMLCContext.getContext(this );
17: XMLCFactory factory = context.getXMLCFactory();
18:
19: req.getSession(true);
20:
21: String docClass = req.getParameter("docClass");
22: String doc = req.getParameter("doc");
23:
24: XMLObject xmlObj = null;
25: if (docClass != null) {
26: xmlObj = factory.create(docClass);
27: } else {
28: if ((doc != null)
29: && (factory instanceof XMLCDeferredParsingFactory)) {
30: XMLCDeferredParsingFactory dpFactory = (XMLCDeferredParsingFactory) factory;
31: xmlObj = dpFactory.createFromFile(doc);
32: }
33: }
34:
35: try {
36:
37: if (xmlObj == null) {
38: if ((docClass == null) && (doc == null)) {
39: resp.sendError(404,
40: "Must set 'docClass' or 'doc' parameter");
41: } else if (docClass != null) {
42: resp.sendError(404, "docClass '" + docClass
43: + "' not found");
44: } else if (doc != null) {
45: resp.sendError(404, "doc '" + doc + "' not found");
46: }
47: } else {
48: context.writeDOM(req, resp, xmlObj);
49: }
50: } catch (Exception e) {
51: e.printStackTrace();
52: }
53: }
54:
55: }
|