KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > servlet > admin > NewsEditServlet


1 /*
2  * NewsEditServlet.java
3  *
4  * Version: $Revision: 1.6 $
5  *
6  * Date: $Date: 2005/04/20 14:22:30 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.webui.servlet.admin;
41
42 import java.io.IOException JavaDoc;
43 import java.sql.SQLException JavaDoc;
44
45 import javax.servlet.ServletException JavaDoc;
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47 import javax.servlet.http.HttpServletResponse JavaDoc;
48
49 import org.apache.log4j.Logger;
50 import org.dspace.app.webui.servlet.DSpaceServlet;
51 import org.dspace.app.webui.util.JSPManager;
52 import org.dspace.app.webui.util.UIUtil;
53 import org.dspace.authorize.AuthorizeException;
54 import org.dspace.core.ConfigurationManager;
55 import org.dspace.core.Context;
56
57 /**
58  * Servlet for editing the front page news
59  *
60  * @author gcarpent
61  */

62 public class NewsEditServlet extends DSpaceServlet
63 {
64     private static Logger log = Logger.getLogger(NewsEditServlet.class);
65
66     protected void doDSGet(Context c, HttpServletRequest JavaDoc request,
67             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
68             SQLException JavaDoc, AuthorizeException
69     {
70         //always go first to news-main.jsp
71
JSPManager.showJSP(request, response, "/dspace-admin/news-main.jsp");
72     }
73
74     protected void doDSPost(Context c, HttpServletRequest JavaDoc request,
75             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
76             SQLException JavaDoc, AuthorizeException
77     {
78         //Get submit button
79
String JavaDoc button = UIUtil.getSubmitButton(request, "submit");
80
81         String JavaDoc news = "";
82
83         //Are we editing the top news or the sidebar news?
84
int position = UIUtil.getIntParameter(request, "position");
85
86         if (button.equals("submit_edit"))
87         {
88             //get the existing text from the file
89
news = ConfigurationManager.readNewsFile(position);
90
91             //pass the position back to the JSP
92
request.setAttribute("position", new Integer JavaDoc(position));
93
94             //pass the existing news back to the JSP
95
request.setAttribute("news", news);
96
97             //show news edit page
98
JSPManager
99                     .showJSP(request, response, "/dspace-admin/news-edit.jsp");
100         }
101         else if (button.equals("submit_save"))
102         {
103             //get text string from form
104
news = (String JavaDoc) request.getParameter("news");
105
106             //write the string out to file
107
ConfigurationManager.writeNewsFile(position, news);
108
109             JSPManager
110                     .showJSP(request, response, "/dspace-admin/news-main.jsp");
111         }
112         else
113         {
114             //the user hit cancel, so return to the main news edit page
115
JSPManager
116                     .showJSP(request, response, "/dspace-admin/news-main.jsp");
117         }
118
119         c.complete();
120     }
121 }
122
Popular Tags