1 25 26 package org.snipsnap.net; 27 28 import org.snipsnap.snip.Snip; 29 import org.snipsnap.snip.SnipLink; 30 import org.snipsnap.snip.SnipSpaceFactory; 31 import org.snipsnap.app.Application; 32 import org.snipsnap.config.Configuration; 33 import org.snipsnap.net.filter.MultipartWrapper; 34 import org.radeox.util.logging.Logger; 35 36 import javax.servlet.RequestDispatcher ; 37 import javax.servlet.ServletException ; 38 import javax.servlet.http.HttpServlet ; 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 import java.io.IOException ; 42 43 48 public class RemoveLabelServlet extends HttpServlet { 49 protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) 50 throws ServletException , IOException { 51 doGet(httpServletRequest, httpServletResponse); 52 } 53 54 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException { 55 Configuration config = Application.get().getConfiguration(); 56 String type = request.getHeader("Content-Type"); 58 if (type != null && type.startsWith("multipart/form-data")) { 59 try { 60 request = new MultipartWrapper(request, config.getEncoding() != null ? config.getEncoding() : "UTF-8"); 61 } catch (IllegalArgumentException e) { 62 Logger.warn("RemoveLabelServlet: multipart/form-data wrapper:" + e.getMessage()); 63 } 64 } 65 66 String snipName = request.getParameter("snipname"); 67 if (null == snipName) { 68 response.sendRedirect(config.getUrl("/space/" + config.getStartSnip())); 69 return; 70 } 71 if (null != request.getParameter("cancel")) { 73 response.sendRedirect(config.getUrl("/exec/labels?snipname=" + SnipLink.encode(snipName))); 74 return; 75 } 76 77 Snip snip = SnipSpaceFactory.getInstance().load(snipName); 78 String labelName = request.getParameter("labelname"); 79 String labelValue = request.getParameter("labelvalue"); 80 snip.getLabels().removeLabel(labelName, labelValue); 81 82 RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/labels?snipname=" + SnipLink.encode(snipName)); 83 dispatcher.forward(request, response); 84 } 85 } 86 | Popular Tags |