001: /*
002: * BitstreamFormatRegistry.java
003: *
004: * Version: $Revision: 1189 $
005: *
006: * Date: $Date: 2005-04-20 09:23:44 -0500 (Wed, 20 Apr 2005) $
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: import java.util.LinkedList;
045: import java.util.List;
046:
047: import javax.servlet.ServletException;
048: import javax.servlet.http.HttpServletRequest;
049: import javax.servlet.http.HttpServletResponse;
050:
051: import org.apache.log4j.Logger;
052: import org.dspace.app.webui.servlet.DSpaceServlet;
053: import org.dspace.app.webui.util.JSPManager;
054: import org.dspace.app.webui.util.UIUtil;
055: import org.dspace.authorize.AuthorizeException;
056: import org.dspace.content.BitstreamFormat;
057: import org.dspace.core.Context;
058:
059: /**
060: * Servlet for editing the bitstream format registry
061: *
062: * @author Robert Tansley
063: * @version $Revision: 1189 $
064: */
065: public class BitstreamFormatRegistry extends DSpaceServlet {
066: /** User wants to edit a format */
067: public static final int START_EDIT = 1;
068:
069: /** User wants to delete a format */
070: public static final int START_DELETE = 2;
071:
072: /** User confirms edit of a format */
073: public static final int CONFIRM_EDIT = 3;
074:
075: /** User confirms delete of a format */
076: public static final int CONFIRM_DELETE = 4;
077:
078: /** User wants to create a new format */
079: public static final int CREATE = 4;
080:
081: /** Logger */
082: private static Logger log = Logger
083: .getLogger(BitstreamFormatRegistry.class);
084:
085: protected void doDSGet(Context context, HttpServletRequest request,
086: HttpServletResponse response) throws ServletException,
087: IOException, SQLException, AuthorizeException {
088: // GET just displays the list of formats
089: showFormats(context, request, response);
090: }
091:
092: protected void doDSPost(Context context,
093: HttpServletRequest request, HttpServletResponse response)
094: throws ServletException, IOException, SQLException,
095: AuthorizeException {
096: String button = UIUtil.getSubmitButton(request, "submit");
097:
098: if (button.equals("submit_update")) {
099: // Update the metadata for a bitstream format
100: BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
101: .getIntParameter(request, "format_id"));
102:
103: bf.setMIMEType(request.getParameter("mimetype"));
104: bf.setShortDescription(request
105: .getParameter("short_description"));
106: bf.setDescription(request.getParameter("description"));
107: bf.setSupportLevel(UIUtil.getIntParameter(request,
108: "support_level"));
109: bf.setInternal((request.getParameter("internal") != null)
110: && request.getParameter("internal").equals("true"));
111:
112: // Separate comma-separated extensions
113: List extensions = new LinkedList();
114: String extParam = request.getParameter("extensions");
115:
116: while (extParam.length() > 0) {
117: int c = extParam.indexOf(',');
118:
119: if (c > 0) {
120: extensions.add(extParam.substring(0, c).trim());
121: extParam = extParam.substring(c + 1).trim();
122: } else {
123: if (extParam.trim().length() > 0) {
124: extensions.add(extParam.trim());
125: extParam = "";
126: }
127: }
128: }
129:
130: // Set extensions in the format - convert to array
131: String[] extArray = (String[]) extensions
132: .toArray(new String[extensions.size()]);
133: bf.setExtensions(extArray);
134:
135: bf.update();
136:
137: showFormats(context, request, response);
138: context.complete();
139: } else if (button.equals("submit_add")) {
140: // Add a new bitstream - simply add to the list, and let the user
141: // edit with the main form
142: BitstreamFormat bf = BitstreamFormat.create(context);
143:
144: // We set the "internal" flag to true, so that the empty bitstream
145: // format doesn't show up in the submission UI yet
146: bf.setInternal(true);
147: bf.update();
148:
149: showFormats(context, request, response);
150: context.complete();
151: } else if (button.equals("submit_delete")) {
152: // Start delete process - go through verification step
153: BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
154: .getIntParameter(request, "format_id"));
155: request.setAttribute("format", bf);
156: JSPManager.showJSP(request, response,
157: "/dspace-admin/confirm-delete-format.jsp");
158: } else if (button.equals("submit_confirm_delete")) {
159: // User confirms deletion of format
160: BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
161: .getIntParameter(request, "format_id"));
162: bf.delete();
163:
164: showFormats(context, request, response);
165: context.complete();
166: } else {
167: // Cancel etc. pressed - show list again
168: showFormats(context, request, response);
169: }
170: }
171:
172: /**
173: * Show list of bitstream formats
174: *
175: * @param context
176: * Current DSpace context
177: * @param request
178: * Current HTTP request
179: * @param response
180: * Current HTTP response
181: */
182: private void showFormats(Context context,
183: HttpServletRequest request, HttpServletResponse response)
184: throws ServletException, IOException, SQLException,
185: AuthorizeException {
186: BitstreamFormat[] formats = BitstreamFormat.findAll(context);
187:
188: request.setAttribute("formats", formats);
189: JSPManager.showJSP(request, response,
190: "/dspace-admin/list-formats.jsp");
191: }
192: }
|