KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
40 import javax.servlet.ServletException JavaDoc;
41 import javax.servlet.http.HttpServlet JavaDoc;
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43 import javax.servlet.http.HttpServletResponse JavaDoc;
44 import java.io.IOException JavaDoc;
45
46 /**
47  * Adding a label to a snip
48  * @author Stephan J. Schmidt
49  * @version $Id: AddLabelServlet.java 1606 2004-05-17 10:56:18Z leo $
50  */

51 public class AddLabelServlet extends HttpServlet JavaDoc {
52   protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
53     throws ServletException JavaDoc, IOException JavaDoc {
54     Configuration config = Application.get().getConfiguration();
55     // If this is not a multipart/form-data request continue
56
String JavaDoc 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 JavaDoc 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 JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc {
69     Configuration config = Application.get().getConfiguration();
70
71     String JavaDoc snipName = request.getParameter("snipname");
72     if (null == snipName) {
73       response.sendRedirect(config.getUrl(config.getStartSnip()));
74       return;
75     }
76     // cancel pressed
77
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 JavaDoc 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 JavaDoc dispatcher = request.getRequestDispatcher("/exec/addlabel.jsp");
91     dispatcher.forward(request, response);
92   }
93
94 }
95
Popular Tags