1 16 package org.apache.roller.webservices.adminapi; 17 18 import java.io.IOException ; 19 import java.io.InputStreamReader ; 20 import java.io.Writer ; 21 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServlet ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.jdom.Document; 29 import org.jdom.output.XMLOutputter; 30 import org.jdom.output.Format; 31 import org.apache.roller.webservices.adminapi.sdk.EntrySet; 32 33 42 public class AtomAdminServlet extends HttpServlet { 43 private static Log logger = LogFactory.getFactory().getInstance(AtomAdminServlet.class); 44 45 48 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException { 49 try { 50 Handler handler = Handler.getHandler(req); 51 String userName = handler.getUserName(); 52 53 EntrySet c = handler.processGet(); 54 55 res.setStatus(HttpServletResponse.SC_OK); 56 res.setContentType("application/xml; charset=utf-8"); 57 String s = c.toString(); 58 Writer writer = res.getWriter(); 59 writer.write(s); 60 writer.close(); 61 } catch (HandlerException he) { 62 res.sendError(he.getStatus(), he.getMessage()); 63 he.printStackTrace(res.getWriter()); 64 logger.error(he); 65 } 66 } 67 68 72 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException { 73 try { 74 Handler handler = Handler.getHandler(req); 75 String userName = handler.getUserName(); 76 77 EntrySet c = handler.processPost(new InputStreamReader (req.getInputStream())); 78 79 res.setStatus(HttpServletResponse.SC_CREATED); 80 res.setContentType("application/xml; charset=utf-8"); 81 String s = c.toString(); 82 Writer writer = res.getWriter(); 83 writer.write(s); 84 writer.close(); 85 } catch (HandlerException he) { 86 res.sendError(he.getStatus(), he.getMessage()); 87 he.printStackTrace(res.getWriter()); 88 logger.error(he); 89 } 90 } 91 92 96 protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException { 97 try { 98 Handler handler = Handler.getHandler(req); 99 String userName = handler.getUserName(); 100 101 EntrySet c = handler.processPut(new InputStreamReader (req.getInputStream())); 102 103 res.setStatus(HttpServletResponse.SC_OK); 104 res.setContentType("application/xml; charset=utf-8"); 105 String s = c.toString(); 106 Writer writer = res.getWriter(); 107 writer.write(s); 108 writer.close(); 109 } catch (HandlerException he) { 110 res.sendError(he.getStatus(), he.getMessage()); 111 he.printStackTrace(res.getWriter()); 112 logger.error(he); 113 } 114 } 115 116 119 protected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException { 120 try { 121 Handler handler = Handler.getHandler(req); 122 String userName = handler.getUserName(); 123 124 EntrySet es = handler.processDelete(); 125 126 res.setStatus(HttpServletResponse.SC_OK); 127 res.setContentType("application/xml; charset=utf-8"); 128 String s = es.toString(); 129 Writer writer = res.getWriter(); 130 writer.write(s); 131 writer.close(); 132 } catch (HandlerException he) { 133 res.sendError(he.getStatus(), he.getMessage()); 134 he.printStackTrace(res.getWriter()); 135 logger.error(he); 136 } 137 } 138 } 139 | Popular Tags |