KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xmlc > demo > ReloadTest


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