KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * BitstreamFormatRegistry.java
3  *
4  * Version: $Revision: 1.7 $
5  *
6  * Date: $Date: 2005/04/20 14:22:31 $
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 import java.util.LinkedList JavaDoc;
45 import java.util.List JavaDoc;
46
47 import javax.servlet.ServletException JavaDoc;
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49 import javax.servlet.http.HttpServletResponse JavaDoc;
50
51 import org.apache.log4j.Logger;
52 import org.dspace.app.webui.servlet.DSpaceServlet;
53 import org.dspace.app.webui.util.JSPManager;
54 import org.dspace.app.webui.util.UIUtil;
55 import org.dspace.authorize.AuthorizeException;
56 import org.dspace.content.BitstreamFormat;
57 import org.dspace.core.Context;
58
59 /**
60  * Servlet for editing the bitstream format registry
61  *
62  * @author Robert Tansley
63  * @version $Revision: 1.7 $
64  */

65 public class BitstreamFormatRegistry extends DSpaceServlet
66 {
67     /** User wants to edit a format */
68     public static final int START_EDIT = 1;
69
70     /** User wants to delete a format */
71     public static final int START_DELETE = 2;
72
73     /** User confirms edit of a format */
74     public static final int CONFIRM_EDIT = 3;
75
76     /** User confirms delete of a format */
77     public static final int CONFIRM_DELETE = 4;
78
79     /** User wants to create a new format */
80     public static final int CREATE = 4;
81
82     /** Logger */
83     private static Logger log = Logger.getLogger(BitstreamFormatRegistry.class);
84
85     protected void doDSGet(Context context, HttpServletRequest JavaDoc request,
86             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
87             SQLException JavaDoc, AuthorizeException
88     {
89         // GET just displays the list of formats
90
showFormats(context, request, response);
91     }
92
93     protected void doDSPost(Context context, HttpServletRequest JavaDoc request,
94             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
95             SQLException JavaDoc, AuthorizeException
96     {
97         String JavaDoc button = UIUtil.getSubmitButton(request, "submit");
98
99         if (button.equals("submit_update"))
100         {
101             // Update the metadata for a bitstream format
102
BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
103                     .getIntParameter(request, "format_id"));
104
105             bf.setMIMEType(request.getParameter("mimetype"));
106             bf.setShortDescription(request.getParameter("short_description"));
107             bf.setDescription(request.getParameter("description"));
108             bf
109                     .setSupportLevel(UIUtil.getIntParameter(request,
110                             "support_level"));
111             bf.setInternal((request.getParameter("internal") != null)
112                     && request.getParameter("internal").equals("true"));
113
114             // Separate comma-separated extensions
115
List JavaDoc extensions = new LinkedList JavaDoc();
116             String JavaDoc extParam = request.getParameter("extensions");
117
118             while (extParam.length() > 0)
119             {
120                 int c = extParam.indexOf(',');
121
122                 if (c > 0)
123                 {
124                     extensions.add(extParam.substring(0, c).trim());
125                     extParam = extParam.substring(c + 1).trim();
126                 }
127                 else
128                 {
129                     if (extParam.trim().length() > 0)
130                     {
131                         extensions.add(extParam.trim());
132                         extParam = "";
133                     }
134                 }
135             }
136
137             // Set extensions in the format - convert to array
138
String JavaDoc[] extArray = (String JavaDoc[]) extensions
139                     .toArray(new String JavaDoc[extensions.size()]);
140             bf.setExtensions(extArray);
141
142             bf.update();
143
144             showFormats(context, request, response);
145             context.complete();
146         }
147         else if (button.equals("submit_add"))
148         {
149             // Add a new bitstream - simply add to the list, and let the user
150
// edit with the main form
151
BitstreamFormat bf = BitstreamFormat.create(context);
152
153             // We set the "internal" flag to true, so that the empty bitstream
154
// format doesn't show up in the submission UI yet
155
bf.setInternal(true);
156             bf.update();
157
158             showFormats(context, request, response);
159             context.complete();
160         }
161         else if (button.equals("submit_delete"))
162         {
163             // Start delete process - go through verification step
164
BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
165                     .getIntParameter(request, "format_id"));
166             request.setAttribute("format", bf);
167             JSPManager.showJSP(request, response,
168                     "/dspace-admin/confirm-delete-format.jsp");
169         }
170         else if (button.equals("submit_confirm_delete"))
171         {
172             // User confirms deletion of format
173
BitstreamFormat bf = BitstreamFormat.find(context, UIUtil
174                     .getIntParameter(request, "format_id"));
175             bf.delete();
176
177             showFormats(context, request, response);
178             context.complete();
179         }
180         else
181         {
182             // Cancel etc. pressed - show list again
183
showFormats(context, request, response);
184         }
185     }
186
187     /**
188      * Show list of bitstream formats
189      *
190      * @param context
191      * Current DSpace context
192      * @param request
193      * Current HTTP request
194      * @param response
195      * Current HTTP response
196      */

197     private void showFormats(Context context, HttpServletRequest JavaDoc request,
198             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
199             SQLException JavaDoc, AuthorizeException
200     {
201         BitstreamFormat[] formats = BitstreamFormat.findAll(context);
202
203         request.setAttribute("formats", formats);
204         JSPManager.showJSP(request, response, "/dspace-admin/list-formats.jsp");
205     }
206 }
207
Popular Tags