KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > RemoveLabelServlet


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
37 import javax.servlet.ServletException JavaDoc;
38 import javax.servlet.http.HttpServlet JavaDoc;
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40 import javax.servlet.http.HttpServletResponse JavaDoc;
41 import java.io.IOException JavaDoc;
42
43 /**
44  * Removing a label from a snip
45  * @author Marco Mosconi
46  * @version $Id: RemoveLabelServlet.java 1609 2004-05-18 13:28:38Z stephan $
47  */

48 public class RemoveLabelServlet extends HttpServlet JavaDoc {
49   protected void doPost(HttpServletRequest JavaDoc httpServletRequest, HttpServletResponse JavaDoc httpServletResponse)
50     throws ServletException JavaDoc, IOException JavaDoc {
51     doGet(httpServletRequest, httpServletResponse);
52   }
53
54   public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc {
55     Configuration config = Application.get().getConfiguration();
56     // If this is not a multipart/form-data request continue
57
String JavaDoc 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 JavaDoc e) {
62         Logger.warn("RemoveLabelServlet: multipart/form-data wrapper:" + e.getMessage());
63       }
64     }
65
66     String JavaDoc snipName = request.getParameter("snipname");
67     if (null == snipName) {
68       response.sendRedirect(config.getUrl("/space/" + config.getStartSnip()));
69       return;
70     }
71     // cancel pressed
72
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 JavaDoc labelName = request.getParameter("labelname");
79     String JavaDoc labelValue = request.getParameter("labelvalue");
80     snip.getLabels().removeLabel(labelName, labelValue);
81
82     RequestDispatcher JavaDoc dispatcher = request.getRequestDispatcher("/exec/labels?snipname=" + SnipLink.encode(snipName));
83     dispatcher.forward(request, response);
84   }
85 }
86
Popular Tags