1 package xmlc.demo; 2 3 import javax.servlet.http.HttpServlet ; 4 import javax.servlet.http.HttpServletRequest ; 5 import javax.servlet.http.HttpServletResponse ; 6 import javax.servlet.ServletException ; 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 { 13 14 protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException { 15 XMLCContext context = XMLCContext.getContext(this); 16 XMLCFactory factory = context.getXMLCFactory(); 17 18 req.getSession(true); 19 20 String docClass = req.getParameter("docClass"); 21 String 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 e) { 48 e.printStackTrace(); 49 } 50 } 51 52 } 53 54 | Popular Tags |