1 40 package org.dspace.app.webui.servlet.admin; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 import java.util.LinkedList ; 45 import java.util.List ; 46 47 import javax.servlet.ServletException ; 48 import javax.servlet.http.HttpServletRequest ; 49 import javax.servlet.http.HttpServletResponse ; 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 65 public class BitstreamFormatRegistry extends DSpaceServlet 66 { 67 68 public static final int START_EDIT = 1; 69 70 71 public static final int START_DELETE = 2; 72 73 74 public static final int CONFIRM_EDIT = 3; 75 76 77 public static final int CONFIRM_DELETE = 4; 78 79 80 public static final int CREATE = 4; 81 82 83 private static Logger log = Logger.getLogger(BitstreamFormatRegistry.class); 84 85 protected void doDSGet(Context context, HttpServletRequest request, 86 HttpServletResponse response) throws ServletException , IOException , 87 SQLException , AuthorizeException 88 { 89 showFormats(context, request, response); 91 } 92 93 protected void doDSPost(Context context, HttpServletRequest request, 94 HttpServletResponse response) throws ServletException , IOException , 95 SQLException , AuthorizeException 96 { 97 String button = UIUtil.getSubmitButton(request, "submit"); 98 99 if (button.equals("submit_update")) 100 { 101 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 List extensions = new LinkedList (); 116 String 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 String [] extArray = (String []) extensions 139 .toArray(new String [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 BitstreamFormat bf = BitstreamFormat.create(context); 152 153 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 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 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 showFormats(context, request, response); 184 } 185 } 186 187 197 private void showFormats(Context context, HttpServletRequest request, 198 HttpServletResponse response) throws ServletException , IOException , 199 SQLException , 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 |