001: /*
002: * LicenseEditServlet.java
003: *
004: * Version: $Revision$
005: *
006: * Date: $Date$
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:
049: import org.apache.log4j.Logger;
050: import org.dspace.app.webui.servlet.DSpaceServlet;
051: import org.dspace.app.webui.util.JSPManager;
052: import org.dspace.app.webui.util.UIUtil;
053: import org.dspace.authorize.AuthorizeException;
054: import org.dspace.core.ConfigurationManager;
055: import org.dspace.core.Context;
056:
057: /**
058: * Servlet for editing the default license
059: *
060: * @author Stuart Lewis
061: */
062: public class LicenseEditServlet extends DSpaceServlet {
063: /** The logger */
064: private static Logger log = Logger
065: .getLogger(LicenseEditServlet.class);
066:
067: /**
068: * Handle GET requests. This does nothing but forwards
069: * the request on to the POST handler.
070: */
071: protected void doDSGet(Context c, HttpServletRequest request,
072: HttpServletResponse response) throws ServletException,
073: IOException, SQLException, AuthorizeException {
074: // Forward on to the post handler
075: this .doDSPost(c, request, response);
076: }
077:
078: /**
079: * Handle the POST requests.
080: */
081: protected void doDSPost(Context c, HttpServletRequest request,
082: HttpServletResponse response) throws ServletException,
083: IOException, SQLException, AuthorizeException {
084: //Get submit button
085: String button = UIUtil.getSubmitButton(request, "submit");
086:
087: if (button.equals("submit_cancel")) {
088: // Show main admin index
089: JSPManager.showJSP(request, response,
090: "/dspace-admin/index.jsp");
091: } else if (!button.equals("submit_save")) {
092: // Get the existing text from the ConfigurationManager
093: String license = ConfigurationManager
094: .getDefaultSubmissionLicense();
095:
096: // Pass the existing license back to the JSP
097: request.setAttribute("license", license);
098:
099: // Show edit page
100: JSPManager.showJSP(request, response,
101: "/dspace-admin/license-edit.jsp");
102: } else {
103: // Get text string from form
104: String license = (String) request.getParameter("license");
105:
106: // Is the license empty?
107: if (license.trim().equals("")) {
108: // Get the existing text from the ConfigurationManager
109: license = ConfigurationManager
110: .getDefaultSubmissionLicense();
111:
112: // Pass the existing license back to the JSP
113: request.setAttribute("license", license);
114:
115: // Pass the 'empty' message back
116: request.setAttribute("empty", "true");
117:
118: // Show edit page
119: JSPManager.showJSP(request, response,
120: "/dspace-admin/license-edit.jsp");
121: } else {
122: // Write the string out to file
123: ConfigurationManager.writeLicenseFile(license);
124:
125: // Pass the existing license back to the JSP
126: request.setAttribute("license", license);
127:
128: // Pass the 'edited' message back
129: request.setAttribute("edited", "true");
130:
131: // Show edit page
132: JSPManager.showJSP(request, response,
133: "/dspace-admin/license-edit.jsp");
134: }
135: }
136: }
137: }
|