1 25 26 package org.snipsnap.net; 27 28 import org.snipsnap.app.Application; 29 import org.snipsnap.config.Configuration; 30 import org.snipsnap.snip.Snip; 31 import org.snipsnap.snip.SnipLink; 32 import org.snipsnap.snip.SnipSpaceFactory; 33 import org.snipsnap.snip.label.Label; 34 import org.snipsnap.snip.label.LabelManager; 35 import org.snipsnap.container.Components; 36 import org.snipsnap.net.filter.MultipartWrapper; 37 import org.radeox.util.logging.Logger; 38 39 import javax.servlet.RequestDispatcher ; 40 import javax.servlet.ServletException ; 41 import javax.servlet.http.HttpServlet ; 42 import javax.servlet.http.HttpServletRequest ; 43 import javax.servlet.http.HttpServletResponse ; 44 import java.io.IOException ; 45 46 51 public class AddLabelServlet extends HttpServlet { 52 protected void doPost(HttpServletRequest request, HttpServletResponse response) 53 throws ServletException , IOException { 54 Configuration config = Application.get().getConfiguration(); 55 String type = request.getHeader("Content-Type"); 57 if (type != null && type.startsWith("multipart/form-data")) { 58 try { 59 request = new MultipartWrapper(request, config.getEncoding() != null ? config.getEncoding() : "UTF-8"); 60 } catch (IllegalArgumentException e) { 61 Logger.warn("AddLabelServlet: multipart/form-data wrapper:" + e.getMessage()); 62 } 63 } 64 65 doGet(request, response); 66 } 67 68 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException { 69 Configuration config = Application.get().getConfiguration(); 70 71 String snipName = request.getParameter("snipname"); 72 if (null == snipName) { 73 response.sendRedirect(config.getUrl(config.getStartSnip())); 74 return; 75 } 76 if (null != request.getParameter("cancel")) { 78 response.sendRedirect(config.getUrl("/exec/labels?snipname=" + SnipLink.encode(snipName))); 79 return; 80 } 81 82 Snip snip = SnipSpaceFactory.getInstance().load(snipName); 83 request.setAttribute("snip", snip); 84 85 String labelType = request.getParameter("labeltype"); 86 LabelManager manager = (LabelManager)Components.getComponent(LabelManager.class); 87 Label label = manager.getLabel(labelType); 88 request.setAttribute("label", label); 89 90 RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/addlabel.jsp"); 91 dispatcher.forward(request, response); 92 } 93 94 } 95 | Popular Tags |