001: /*
002: * NewsEditServlet.java
003: *
004: * Version: $Revision: 1947 $
005: *
006: * Date: $Date: 2007-05-18 08:50:29 -0500 (Fri, 18 May 2007) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.webui.servlet.admin;
041:
042: import java.io.IOException;
043: import java.sql.SQLException;
044:
045: import javax.servlet.ServletException;
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048: import javax.servlet.jsp.jstl.fmt.LocaleSupport;
049:
050: import org.apache.log4j.Logger;
051: import org.dspace.app.webui.servlet.DSpaceServlet;
052: import org.dspace.app.webui.util.JSPManager;
053: import org.dspace.app.webui.util.UIUtil;
054: import org.dspace.authorize.AuthorizeException;
055: import org.dspace.core.ConfigurationManager;
056: import org.dspace.core.Constants;
057: import org.dspace.core.Context;
058:
059: /**
060: * Servlet for editing the front page news
061: *
062: * @author gcarpent
063: */
064: public class NewsEditServlet extends DSpaceServlet {
065: private static Logger log = Logger.getLogger(NewsEditServlet.class);
066:
067: protected void doDSGet(Context c, HttpServletRequest request,
068: HttpServletResponse response) throws ServletException,
069: IOException, SQLException, AuthorizeException {
070: //always go first to news-main.jsp
071: JSPManager.showJSP(request, response,
072: "/dspace-admin/news-main.jsp");
073: }
074:
075: protected void doDSPost(Context c, HttpServletRequest request,
076: HttpServletResponse response) throws ServletException,
077: IOException, SQLException, AuthorizeException {
078: //Get submit button
079: String button = UIUtil.getSubmitButton(request, "submit");
080:
081: String news = "";
082:
083: //Are we editing the top news or the sidebar news?
084: String position = request.getParameter("position");
085:
086: if (button.equals("submit_edit")) {
087: //get the existing text from the file
088: news = ConfigurationManager.readNewsFile(position);
089:
090: //pass the position back to the JSP
091: request.setAttribute("position", position);
092:
093: //pass the existing news back to the JSP
094: request.setAttribute("news", news);
095:
096: //show news edit page
097: JSPManager.showJSP(request, response,
098: "/dspace-admin/news-edit.jsp");
099: } else if (button.equals("submit_save")) {
100: //get text string from form
101: news = (String) request.getParameter("news");
102:
103: //write the string out to file
104: ConfigurationManager.writeNewsFile(position, news);
105:
106: JSPManager.showJSP(request, response,
107: "/dspace-admin/news-main.jsp");
108: } else {
109: //the user hit cancel, so return to the main news edit page
110: JSPManager.showJSP(request, response,
111: "/dspace-admin/news-main.jsp");
112: }
113:
114: c.complete();
115: }
116: }
|