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 Preview extends HttpServlet { 13 14 protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException { 15 XMLObject xmlObj = null; 16 17 18 XMLCContext context = XMLCContext.getContext(this); 19 XMLCFactory factory = context.getXMLCFactory(); 20 21 22 XMLCDeferredParsingFactory dpFactory = null; 23 if (factory instanceof XMLCDeferredParsingFactory) { 24 dpFactory = (XMLCDeferredParsingFactory)factory; 25 } 26 27 30 String path = req.getPathInfo(); 31 32 try { 33 if (path != null) { 34 path = path.substring(1); 35 xmlObj = dpFactory.createFromFile(path); 36 if (xmlObj != null) { 37 try { 38 context.writeDOM(req, resp, xmlObj); 39 } catch (Exception e) { 40 resp.sendError(resp.SC_NOT_FOUND, "doc '" + path + "' has error"); 41 } 42 } else { 43 resp.sendError(resp.SC_NOT_FOUND, "doc '" + path + "' not found"); 44 } 45 } else { 46 resp.sendError(resp.SC_NOT_FOUND, "specify '" + path + "'"); 47 } 48 } catch (java.io.IOException ioe) { 49 new ServletException (ioe); 50 } 51 } 52 } 53 54 | Popular Tags |