protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { Integer itemID = UIUtil.getIntParameter(request, "itemID"); Item item = Item.find(context, itemID); String submit = UIUtil.getSubmitButton(request, "submit"); if (submit != null && submit.equals("submit")) { request.setAttribute("itemID", itemID); JSPManager.showJSP(request, response, "/tools/version-summary.jsp"); return; } String summary = request.getParameter("summary"); if (submit != null && submit.equals("submit_version")) { Integer wsid = VersionUtil.processCreateNewVersion(context, itemID, summary); response.sendRedirect(request.getContextPath() + "/submit?resume=" + wsid); context.complete(); return; } else if (submit != null && submit.equals("submit_update_version")) { String versionID = request.getParameter("versionID"); request.setAttribute("itemID", itemID); request.setAttribute("versionID", versionID); JSPManager.showJSP(request, response, "/tools/version-update-summary.jsp"); return; } // Send us back to the item page if we cancel ! response.sendRedirect(request.getContextPath() + "/handle/" + item.getHandle()); context.complete(); }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // check if ldap is enables and forward to the correct login form boolean ldap_enabled = ConfigurationManager.getBooleanProperty("ldap.enable"); if (ldap_enabled) { JSPManager.showJSP(request, response, "/login/ldap.jsp"); } else { JSPManager.showJSP(request, response, "/login/password.jsp"); } }
/** * show the workspace item home page * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showMainPage(Context c, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // get the value from the request int wsItemID = UIUtil.getIntParameter(request, "workspace_id"); // get the workspace item, item and collections from the request value WorkspaceItem wsItem = WorkspaceItem.find(c, wsItemID); Item item = wsItem.getItem(); // Collection[] collections = item.getCollections(); Collection[] collections = {wsItem.getCollection()}; // Ensure the user has authorisation AuthorizeManager.authorizeAction(c, item, Constants.READ); log.info( LogManager.getHeader(c, "View Workspace Item Metadata", "workspace_item_id=" + wsItemID)); // Full or simple display? boolean displayAll = false; String button = UIUtil.getSubmitButton(request, "submit_simple"); if (button.equalsIgnoreCase("submit_full")) { displayAll = true; } // FIXME: we need to synchronise with the handle servlet to use the // display item JSP for both handled and un-handled items // Set attributes and display // request.setAttribute("wsItem", wsItem); request.setAttribute("display.all", Boolean.valueOf(displayAll)); request.setAttribute("item", item); request.setAttribute("collections", collections); request.setAttribute("workspace_id", Integer.valueOf(wsItem.getID())); JSPManager.showJSP(request, response, "/display-item.jsp"); }
/** * Show list of bitstream formats * * @param context Current DSpace context * @param request Current HTTP request * @param response Current HTTP response */ private void showFormats( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { List<BitstreamFormat> formats = bitstreamFormatService.findAll(context); request.setAttribute("formats", formats); JSPManager.showJSP(request, response, "/dspace-admin/list-formats.jsp"); }
/** * Show error page if nothing has been <code>POST</code>ed to servlet * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showErrorPage( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { int wsItemID = UIUtil.getIntParameter(request, "workspace_id"); log.error( LogManager.getHeader( context, "View Workspace Item Metadata Failed", "workspace_item_id=" + wsItemID)); JSPManager.showJSP(request, response, "/workspace/wsv-error.jsp"); }
/** * Displays the list of current settings for supervisors * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showListPage( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // get all the supervised items SupervisedItem[] si = SupervisedItem.getAll(context); // set the attributes for the JSP request.setAttribute("supervised", si); JSPManager.showJSP(request, response, "/dspace-admin/supervise-list.jsp"); }
protected void doDSPost(Context c, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Get submit button String button = UIUtil.getSubmitButton(request, "submit"); String news = ""; // Are we editing the top news or the sidebar news? String position = request.getParameter("position"); if (button.equals("submit_edit")) { // get the existing text from the file news = newsService.readNewsFile(position); // pass the position back to the JSP request.setAttribute("position", position); // pass the existing news back to the JSP request.setAttribute("news", news); // show news edit page JSPManager.showJSP(request, response, "/dspace-admin/news-edit.jsp"); } else if (button.equals("submit_save")) { // get text string from form news = (String) request.getParameter("news"); // write the string out to file newsService.writeNewsFile(position, news); JSPManager.showJSP(request, response, "/dspace-admin/news-main.jsp"); } else { // the user hit cancel, so return to the main news edit page JSPManager.showJSP(request, response, "/dspace-admin/news-main.jsp"); } c.complete(); }
/** * validate the submitted form to ensure that there is not a supervision order for this already. * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private boolean validateAddForm( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { int groupID = UIUtil.getIntParameter(request, "TargetGroup"); int wsItemID = UIUtil.getIntParameter(request, "TargetWSItem"); boolean invalid = Supervisor.isOrder(context, wsItemID, groupID); if (invalid) { JSPManager.showJSP(request, response, "/dspace-admin/supervise-duplicate.jsp"); return false; } else { return true; } }
/** * Displays the form to link groups to workspace items * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showLinkPage( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // get all the groups Group[] groups = Group.findAll(context, 1); // get all the workspace items WorkspaceItem[] wsItems = WorkspaceItem.findAll(context); // set the attributes for the JSP request.setAttribute("groups", groups); request.setAttribute("wsItems", wsItems); JSPManager.showJSP(request, response, "/dspace-admin/supervise-link.jsp"); }
/** * Show a community home page, or deal with button press on home page * * @param context Context object * @param request the HTTP request * @param response the HTTP response * @param community the community */ private void communityHome( Context context, HttpServletRequest request, HttpServletResponse response, Community community) throws ServletException, IOException, SQLException { // Handle click on a browse or search button if (!handleButton(request, response, IdentifierService.getURL(community))) { // No button pressed, display community home page log.info( LogManager.getHeader(context, "view_community", "community_id=" + community.getID())); // Get the collections within the community Collection[] collections = (Collection[]) community.getCollections().toArray(); // get any subcommunities of the community Community[] subcommunities = (Community[]) community.getSubCommunities().toArray(); // perform any necessary pre-processing preProcessCommunityHome(context, request, response, community); // is the user a COMMUNITY_EDITOR? // if (community.canEditBoolean()) if (AuthorizeManager.canEdit(community, context)) { // set a variable to create an edit button request.setAttribute("editor_button", new Boolean(true)); } // can they add to this community? if (AuthorizeManager.authorizeActionBoolean(context, community, Constants.ADD)) { // set a variable to create an edit button request.setAttribute("add_button", new Boolean(true)); } // can they remove from this community? if (AuthorizeManager.authorizeActionBoolean(context, community, Constants.REMOVE)) { // set a variable to create an edit button request.setAttribute("remove_button", new Boolean(true)); } // Forward to community home page request.setAttribute("community", community); request.setAttribute("collections", collections); request.setAttribute("subcommunities", subcommunities); JSPManager.showJSP(request, response, "/community-home.jsp"); } }
/** * Confirms the removal of a supervision order * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showConfirmRemovePage( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // get the values from the request int wsItemID = UIUtil.getIntParameter(request, "siID"); int groupID = UIUtil.getIntParameter(request, "gID"); // get the workspace item and the group from the request values WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID); Group group = Group.find(context, groupID); // set the attributes for the JSP request.setAttribute("wsItem", wsItem); request.setAttribute("group", group); JSPManager.showJSP(request, response, "/dspace-admin/supervise-confirm-remove.jsp"); }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Are we for selecting a single or multiple groups? boolean multiple = UIUtil.getBoolParameter(request, "multiple"); // What's the index of the first group to show? Default is 0 int first = UIUtil.getIntParameter(request, "first"); if (first == -1) first = 0; // What are we sorting by? Name is default // int sortBy = Group.NAME; // int sortBy = 1; String sbParam = request.getParameter("sortby"); Group[] groups; if (sbParam != null && sbParam.equals("id")) { // sortBy = Group.ID; // sortBy = 0; groups = (Group[]) ApplicationService.findAllGroupsSortedById(context).toArray(); request.setAttribute("sortby", 0); } else { groups = (Group[]) ApplicationService.findAllGroupsSortedByName(context).toArray(); request.setAttribute("sortby", 1); } // Retrieve the e-people in the specified order // Group[] groups = Group.findAll(context, sortBy); // Set attributes for JSP // request.setAttribute("sortby", new Integer(sortBy)); request.setAttribute("first", new Integer(first)); request.setAttribute("groups", groups); if (multiple) { request.setAttribute("multiple", new Boolean(true)); } JSPManager.showJSP(request, response, "/tools/group-select-list.jsp"); }
protected void doDSPost(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Process the POSTed email and password String netid = request.getParameter("login_netid"); String password = request.getParameter("login_password"); String jsp = null; // Locate the eperson int status = AuthenticationManager.authenticate(context, netid, password, null, request); if (status == AuthenticationMethod.SUCCESS) { // Logged in OK. Authenticate.loggedIn(context, request, context.getCurrentUser()); // Set the Locale according to user preferences Locale epersonLocale = I18nUtil.getEPersonLocale(context.getCurrentUser()); context.setCurrentLocale(epersonLocale); Config.set(request.getSession(), Config.FMT_LOCALE, epersonLocale); log.info(LogManager.getHeader(context, "login", "type=explicit")); // resume previous request Authenticate.resumeInterruptedRequest(request, response); return; } else if (status == AuthenticationMethod.CERT_REQUIRED) { jsp = "/error/require-certificate.jsp"; } else { jsp = "/login/incorrect.jsp"; } // If we reach here, supplied email/password was duff. log.info( LogManager.getHeader( context, "failed_login", "netid=" + netid + ", result=" + String.valueOf(status))); JSPManager.showJSP(request, response, jsp); }
/** * GET request is only ever used to show the upload form * * @param context a DSpace Context object * @param request the HTTP request * @param response the HTTP response * @throws ServletException * @throws IOException * @throws SQLException * @throws AuthorizeException */ @Override protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Get all collections List<Collection> collections = null; String colIdS = request.getParameter("colId"); if (colIdS != null) { collections = new ArrayList<>(); collections.add(collectionService.findByIdOrLegacyId(context, colIdS)); } else { collections = collectionService.findAll(context); } request.setAttribute("collections", collections); // Get all the possible data loaders from the Spring configuration BTEBatchImportService dls = new DSpace().getSingletonService(BTEBatchImportService.class); List<String> inputTypes = dls.getFileDataLoaders(); request.setAttribute("input-types", inputTypes); // Show the upload screen JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); }
/** * Show an item page * * @param context Context object * @param request the HTTP request * @param response the HTTP response * @param item the item * @param identifier a persistent identifier that belongs to the item */ private void displayItem( Context context, HttpServletRequest request, HttpServletResponse response, Item item) throws ServletException, IOException, SQLException, AuthorizeException { // Tombstone? if (item.isWithdrawn()) { JSPManager.showJSP(request, response, "/tombstone.jsp"); return; } // Ensure the user has authorisation AuthorizeManager.authorizeAction(context, item, Constants.READ); log.info( LogManager.getHeader( context, "view_item", "uri=" + item.getIdentifier().getCanonicalForm())); // show edit link if (item.canEdit()) { // set a variable to create an edit button request.setAttribute("admin_button", new Boolean(true)); } // Get the collections Collection[] collections = (Collection[]) item.getCollections().toArray(); // For the breadcrumbs, get the first collection and the first community // that is in. FIXME: Not multiple-inclusion friendly--should be // smarter, context-sensitive request.setAttribute("dspace.collection", item.getOwningCollection()); Collection collection = item.getOwningCollection(); if (collection != null) { Community[] comms = (Community[]) collection.getCommunities().toArray(); if (comms.length > 0) { request.setAttribute("dspace.community", comms[0]); /* * Find all the "parent" communities for the collection */ request.setAttribute("dspace.communities", getParents(comms[0], true)); } } // Full or simple display? boolean displayAll = false; String modeParam = request.getParameter("mode"); if ((modeParam != null) && modeParam.equalsIgnoreCase("full")) { displayAll = true; } // Enable suggest link or not boolean suggestEnable = false; if (!ConfigurationManager.getBooleanProperty("webui.suggest.enable")) { // do nothing, the suggestLink is allready set to false } else { // it is in general enabled suggestEnable = true; // check for the enable only for logged in users option if (!ConfigurationManager.getBooleanProperty("webui.suggest.loggedinusers.only")) { // do nothing, the suggestLink stays as it is } else { // check whether there is a logged in user suggestEnable = (context.getCurrentUser() == null ? false : true); } } // Set attributes and display request.setAttribute("suggest.enable", new Boolean(suggestEnable)); request.setAttribute("display.all", new Boolean(displayAll)); request.setAttribute("item", item); request.setAttribute("collections", collections); JSPManager.showJSP(request, response, "/display-item.jsp"); }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { includeAll = ConfigurationManager.getBooleanProperty("harvest.includerestricted.rss", true); String path = request.getPathInfo(); String feedType = null; String handle = null; // build label map from localized Messages resource bundle Locale locale = request.getLocale(); ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale); Map<String, String> labelMap = new HashMap<String, String>(); labelMap.put(SyndicationFeed.MSG_UNTITLED, msgs.getString(clazz + ".notitle")); labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, msgs.getString(clazz + ".logo.title")); labelMap.put( SyndicationFeed.MSG_FEED_DESCRIPTION, msgs.getString(clazz + ".general-feed.description")); labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI); for (String selector : SyndicationFeed.getDescriptionSelectors()) { labelMap.put("metadata." + selector, msgs.getString(SyndicationFeed.MSG_METADATA + selector)); } if (path != null) { // substring(1) is to remove initial '/' path = path.substring(1); int split = path.indexOf('/'); if (split != -1) { feedType = path.substring(0, split); handle = path.substring(split + 1); } } DSpaceObject dso = null; // as long as this is not a site wide feed, // attempt to retrieve the Collection or Community object if (handle != null && !handle.equals(SITE_FEED_KEY)) { // Determine if handle is a valid reference dso = HandleManager.resolveToObject(context, handle); if (dso == null) { log.info(LogManager.getHeader(context, "invalid_handle", "path=" + path)); JSPManager.showInvalidIDError(request, response, handle, -1); return; } } if (!enabled || (dso != null && (dso.getType() != Constants.COLLECTION && dso.getType() != Constants.COMMUNITY))) { log.info(LogManager.getHeader(context, "invalid_id", "path=" + path)); JSPManager.showInvalidIDError(request, response, path, -1); return; } // Determine if requested format is supported if (feedType == null || !formats.contains(feedType)) { log.info(LogManager.getHeader(context, "invalid_syndformat", "path=" + path)); JSPManager.showInvalidIDError(request, response, path, -1); return; } if (dso != null && dso.getType() == Constants.COLLECTION) { labelMap.put( SyndicationFeed.MSG_FEED_TITLE, MessageFormat.format( msgs.getString(clazz + ".feed.title"), msgs.getString(clazz + ".feed-type.collection"), dso.getMetadata("short_description"))); } else if (dso != null && dso.getType() == Constants.COMMUNITY) { labelMap.put( SyndicationFeed.MSG_FEED_TITLE, MessageFormat.format( msgs.getString(clazz + ".feed.title"), msgs.getString(clazz + ".feed-type.community"), dso.getMetadata("short_description"))); } // Lookup or generate the feed // Cache key is handle + locale String cacheKey = (handle == null ? "site" : handle) + "." + locale.toString(); SyndicationFeed feed = null; if (feedCache != null) { CacheFeed cFeed = feedCache.get(cacheKey); if (cFeed != null) // cache hit, but... { // Is the feed current? boolean cacheFeedCurrent = false; if (cFeed.timeStamp + (cacheAge * HOUR_MSECS) < System.currentTimeMillis()) { cacheFeedCurrent = true; } // Not current, but have any items changed since feed was created/last checked? else if (!itemsChanged(context, dso, cFeed.timeStamp)) { // no items have changed, re-stamp feed and use it cFeed.timeStamp = System.currentTimeMillis(); cacheFeedCurrent = true; } if (cacheFeedCurrent) { feed = cFeed.access(); } } } // either not caching, not found in cache, or feed in cache not current if (feed == null) { feed = new SyndicationFeed(SyndicationFeed.UITYPE_JSPUI); feed.populate(request, dso, getItems(context, dso), labelMap); if (feedCache != null) { cache(cacheKey, new CacheFeed(feed)); } } // set the feed to the requested type & return it try { feed.setType(feedType); response.setContentType("text/xml; charset=UTF-8"); feed.output(response.getWriter()); } catch (FeedException fex) { throw new IOException(fex.getMessage(), fex); } }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { ExternalIdentifierDAO identifierDAO = ExternalIdentifierDAOFactory.getInstance(context); Item item = null; Bitstream bitstream = null; String idString = request.getPathInfo(); String filenameNoPath = null; String fullpath = null; String uri = null; // Parse URL if (idString != null) { // Remove leading slash if (idString.startsWith("/")) { idString = idString.substring(1); } // Get uri and full file path int slashIndex = idString.indexOf('/'); if (slashIndex != -1) { slashIndex = idString.indexOf('/', slashIndex + 1); if (slashIndex != -1) { uri = idString.substring(0, slashIndex); fullpath = URLDecoder.decode(idString.substring(slashIndex + 1), Constants.DEFAULT_ENCODING); // Get filename with no path slashIndex = fullpath.indexOf('/'); if (slashIndex != -1) { String[] pathComponents = fullpath.split("/"); if (pathComponents.length <= maxDepthGuess + 1) { filenameNoPath = pathComponents[pathComponents.length - 1]; } } } } } if (uri != null && fullpath != null) { // Find the item try { /* * If the original item doesn't have a persistent identifier * yet (because it's in the workflow) what we actually have is * a URL of the form: db-id/1234 where 1234 is the database ID * of the item. * * FIXME: This first part could be totally omitted now that we * have the dsi:x/y format of identification. */ if (uri.startsWith("db-id")) { String dbIDString = uri.substring(uri.indexOf('/') + 1); int dbID = Integer.parseInt(dbIDString); item = ItemDAOFactory.getInstance(context).retrieve(dbID); } else { ExternalIdentifier identifier = identifierDAO.retrieve(uri); ObjectIdentifier oi = identifier.getObjectIdentifier(); item = (Item) oi.getObject(context); } } catch (NumberFormatException nfe) { // Invalid ID - this will be dealt with below } } if (item != null) { // Try to find bitstream with exactly matching name + path bitstream = getItemBitstreamByName(item, fullpath); if (bitstream == null && filenameNoPath != null) { // No match with the full path, but we can try again with // only the filename bitstream = getItemBitstreamByName(item, filenameNoPath); } } // Did we get a bitstream? if (bitstream != null) { log.info( LogManager.getHeader( context, "view_html", "uri=" + uri + ",bitstream_id=" + bitstream.getID())); // Set the response MIME type response.setContentType(bitstream.getFormat().getMIMEType()); // Response length response.setHeader("Content-Length", String.valueOf(bitstream.getSize())); // Pipe the bits InputStream is = bitstream.retrieve(); Utils.bufferedCopy(is, response.getOutputStream()); is.close(); response.getOutputStream().flush(); } else { // No bitstream - we got an invalid ID log.info(LogManager.getHeader(context, "view_html", "invalid_bitstream_id=" + idString)); JSPManager.showInvalidIDError(request, response, idString, Constants.BITSTREAM); } }
/** * Respond to a post request for metadata bulk importing via csv * * @param context a DSpace Context object * @param request the HTTP request * @param response the HTTP response * @throws ServletException * @throws IOException * @throws SQLException * @throws AuthorizeException */ @Override protected void doDSPost(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // First, see if we have a multipart request (uploading a metadata file) String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") != -1)) { String message = null; // Process the file uploaded try { // Wrap multipart request to get the submission info FileUploadRequest wrapper = new FileUploadRequest(request); String inputType = wrapper.getParameter("inputType"); List<String> reqCollectionsTmp = getRepeatedParameter(wrapper, "collections", "collections"); String[] reqCollections = new String[reqCollectionsTmp.size()]; reqCollectionsTmp.toArray(reqCollections); // Get all collections List<Collection> collections = null; String colIdS = wrapper.getParameter("colId"); if (colIdS != null) { collections = new ArrayList<>(); collections.add(collectionService.findByIdOrLegacyId(context, colIdS)); } else { collections = collectionService.findAll(context); } request.setAttribute("collections", collections); Collection owningCollection = null; if (wrapper.getParameter("collection") != null) { owningCollection = collectionService.findByIdOrLegacyId(context, wrapper.getParameter("collection")); } // Get all the possible data loaders from the Spring configuration BTEBatchImportService dls = new DSpace().getSingletonService(BTEBatchImportService.class); List<String> inputTypes = dls.getFileDataLoaders(); request.setAttribute("input-types", inputTypes); if (reqCollectionsTmp != null) request.setAttribute("otherCollections", reqCollectionsTmp); if (owningCollection != null) request.setAttribute("owningCollection", owningCollection.getID()); request.setAttribute("inputType", inputType); File f = null; String zipurl = null; if (inputType.equals("saf")) { zipurl = wrapper.getParameter("zipurl"); if (StringUtils.isEmpty(zipurl)) { request.setAttribute("has-error", "true"); Locale locale = request.getLocale(); ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale); try { message = msgs.getString("jsp.layout.navbar-admin.batchimport.fileurlempty"); } catch (Exception e) { message = "???jsp.layout.navbar-admin.batchimport.fileurlempty???"; } request.setAttribute("message", message); JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); return; } } else { f = wrapper.getFile("file"); if (f == null) { request.setAttribute("has-error", "true"); Locale locale = request.getLocale(); ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale); try { message = msgs.getString("jsp.layout.navbar-admin.batchimport.fileempty"); } catch (Exception e) { message = "???jsp.layout.navbar-admin.batchimport.fileempty???"; } request.setAttribute("message", message); JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); return; } else if (owningCollection == null) { request.setAttribute("has-error", "true"); Locale locale = request.getLocale(); ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale); try { message = msgs.getString("jsp.layout.navbar-admin.batchimport.owningcollectionempty"); } catch (Exception e) { message = "???jsp.layout.navbar-admin.batchimport.owningcollectionempty???"; } request.setAttribute("message", message); JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); return; } } String uploadId = wrapper.getParameter("uploadId"); if (uploadId != null) { request.setAttribute("uploadId", uploadId); } if (owningCollection == null && reqCollections != null && reqCollections.length > 0) { request.setAttribute("has-error", "true"); Locale locale = request.getLocale(); ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale); String ms = msgs.getString("jsp.layout.navbar-admin.batchimport.owningcollection"); if (ms == null) { ms = "???jsp.layout.navbar-admin.batchimport.owningcollection???"; } request.setAttribute("message", ms); JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); return; } try { String finalInputType = "saf"; String filePath = zipurl; if (f != null) { finalInputType = inputType; filePath = f.getAbsolutePath(); } itemImportService.processUIImport( filePath, owningCollection, reqCollections, uploadId, finalInputType, context, true); request.setAttribute("has-error", "false"); request.setAttribute("uploadId", null); } catch (Exception e) { request.setAttribute("has-error", "true"); message = e.getMessage(); e.printStackTrace(); } } catch (FileSizeLimitExceededException e) { request.setAttribute("has-error", "true"); message = e.getMessage(); e.printStackTrace(); } catch (Exception e) { request.setAttribute("has-error", "true"); message = e.getMessage(); e.printStackTrace(); } request.setAttribute("message", message); // Show the upload screen JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); } else { request.setAttribute("has-error", "true"); // Show the upload screen JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); } }
@Override protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); if (!AuthorizeManager.isAdmin(context)) { throw new AuthorizeException("Вы должны быть администратором просматривать журнал импорта"); } String area = request.getParameter("area"); String action = request.getParameter("action"); String dateStr = request.getParameter("date"); Date date = null; try { if (dateStr != null) { DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); date = df.parse(dateStr); } } catch (Exception e) { } if (area != null && area.equals("errors")) { if (date == null) { date = ImportErrorLog.getLastDate(context); if (date == null) date = Calendar.getInstance().getTime(); } } else { if (date == null) { date = ImportLog.getLastDate(context); if (date == null) date = Calendar.getInstance().getTime(); } } request.setAttribute("date", date); if (area != null && area.equals("errors")) { if (action == null) { JSPManager.showJSP(request, response, "/importlog/errors.jsp"); } else { String id = request.getParameter("id"); Integer page = request.getParameter("page") != null ? Integer.valueOf(request.getParameter("page")) : 1; JsonObject json = new JsonObject(); JsonArray items = new JsonArray(); String[] ids = ImportErrorLog.getReportsId(context, date); if (id == null && ids.length > 0) { id = ids[0]; } for (int i = 0; i < ids.length; i++) { if (ids[i].equals(id)) { String prevId = null; String nextId = null; if (i > 0) { prevId = ids[i - 1]; } if (i < (ids.length - 1)) { nextId = ids[i + 1]; } json.addProperty("prevId", prevId); json.addProperty("nextId", nextId); } } if (id != null) { int limit = 100; int offset = (page - 1) * limit; ImportErrorLog[] report = ImportErrorLog.getReport(context, id, offset, limit); for (ImportErrorLog record : report) { items.add(new JsonPrimitive(record.getFile())); } json.addProperty("page", page); if (offset == 0) { int count = ImportErrorLog.getReportLength(context, id); json.addProperty("count", count); json.addProperty( "pages", Math.ceil( Integer.valueOf(count).doubleValue() / Integer.valueOf(limit).doubleValue())); DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm"); json.addProperty("firstDate", df.format(report[0].getDate())); } } json.add("items", items); json.addProperty("id", id); response.setContentType("application/json"); response.getWriter().write(json.toString()); } } else { if (action == null) { JSPManager.showJSP(request, response, "/importlog/log.jsp"); } else { String id = request.getParameter("id"); Integer page = request.getParameter("page") != null ? Integer.valueOf(request.getParameter("page")) : 1; JsonObject json = new JsonObject(); JsonArray items = new JsonArray(); String[] ids = ImportLog.getReportsId(context, date); if (id == null && ids.length > 0) { id = ids[0]; } for (int i = 0; i < ids.length; i++) { if (ids[i].equals(id)) { String prevId = null; String nextId = null; if (i > 0) { prevId = ids[i - 1]; } if (i < (ids.length - 1)) { nextId = ids[i + 1]; } json.addProperty("prevId", prevId); json.addProperty("nextId", nextId); } } if (id != null) { int limit = 100; int offset = (page - 1) * limit; ImportLog[] report = ImportLog.getReport(context, id, offset, limit); for (ImportLog record : report) { JsonObject recordJson = new JsonObject(); recordJson.addProperty("year", record.getYear()); recordJson.addProperty("name", record.getName()); recordJson.addProperty("authors", record.getAuthors()); Item item = record.getItem(context); String link = (item != null ? request.getContextPath() + "/handle/" + item.getHandle() : null); recordJson.addProperty("link", link); recordJson.addProperty("duplicate", record.getDuplicate()); items.add(recordJson); } json.addProperty("page", page); if (offset == 0) { int count = ImportLog.getReportLength(context, id); json.addProperty("count", count); json.addProperty( "pages", Math.ceil( Integer.valueOf(count).doubleValue() / Integer.valueOf(limit).doubleValue())); DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm"); json.addProperty("firstDate", df.format(report[0].getDate())); } } json.add("items", items); json.addProperty("id", id); response.setContentType("application/json"); response.getWriter().write(json.toString()); } } }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Obtain information from request // The page where the user came from String fromPage = request.getHeader("Referer"); // Prevent spammers and splogbots from poisoning the feedback page String host = ConfigurationManager.getProperty("dspace.hostname"); String basicHost = ""; if (host.equals("localhost") || host.equals("127.0.0.1") || host.equals(InetAddress.getLocalHost().getHostAddress())) basicHost = host; else { // cut off all but the hostname, to cover cases where more than one URL // arrives at the installation; e.g. presence or absence of "www" int lastDot = host.lastIndexOf("."); basicHost = host.substring(host.substring(0, lastDot).lastIndexOf(".")); } if (fromPage == null || fromPage.indexOf(basicHost) == -1) { throw new AuthorizeException(); } // The email address they provided String formEmail = request.getParameter("email"); // Browser String userAgent = request.getHeader("User-Agent"); // Session id String sessionID = request.getSession().getId(); // User email from context EPerson currentUser = context.getCurrentUser(); String authEmail = null; if (currentUser != null) { authEmail = currentUser.getEmail(); } // Has the user just posted their feedback? if (request.getParameter("submit") != null) { EmailValidator ev = EmailValidator.getInstance(); String feedback = request.getParameter("feedback"); // Check all data is there if ((formEmail == null) || formEmail.equals("") || (feedback == null) || feedback.equals("") || !ev.isValid(formEmail)) { log.info(LogManager.getHeader(context, "show_feedback_form", "problem=true")); request.setAttribute("feedback.problem", new Boolean(true)); JSPManager.showJSP(request, response, "/feedback/form.jsp"); return; } // All data is there, send the email try { Email email = ConfigurationManager.getEmail( I18nUtil.getEmailFilename(context.getCurrentLocale(), "feedback")); email.addRecipient(ConfigurationManager.getProperty("feedback.recipient")); email.addArgument(new Date()); // Date email.addArgument(formEmail); // Email email.addArgument(authEmail); // Logged in as email.addArgument(fromPage); // Referring page email.addArgument(userAgent); // User agent email.addArgument(sessionID); // Session ID email.addArgument(feedback); // The feedback itself // Replying to feedback will reply to email on form email.setReplyTo(formEmail); email.send(); log.info(LogManager.getHeader(context, "sent_feedback", "from=" + formEmail)); JSPManager.showJSP(request, response, "/feedback/acknowledge.jsp"); } catch (MessagingException me) { log.warn(LogManager.getHeader(context, "error_mailing_feedback", ""), me); JSPManager.showInternalError(request, response); } } else { // Display feedback form log.info(LogManager.getHeader(context, "show_feedback_form", "problem=false")); request.setAttribute("authenticated.email", authEmail); JSPManager.showJSP(request, response, "/feedback/form.jsp"); } }
/** * Show a collection home page, or deal with button press on home page * * @param context Context object * @param request the HTTP request * @param response the HTTP response * @param community the community * @param collection the collection */ private void collectionHome( Context context, HttpServletRequest request, HttpServletResponse response, Community community, Collection collection) throws ServletException, IOException, SQLException, AuthorizeException { // Handle click on a browse or search button if (!handleButton(request, response, IdentifierService.getURL(community))) { // Will need to know whether to commit to DB boolean updated = false; // No search or browse button pressed, check for if (request.getParameter("submit_subscribe") != null) { // Subscribe button pressed. // Only registered can subscribe, so redirect unless logged in. if (context.getCurrentUser() == null && !Authenticate.startAuthentication(context, request, response)) return; else { SubscriptionManager.subscribe(context, context.getCurrentUser(), collection); updated = true; } } else if (request.getParameter("submit_unsubscribe") != null) { SubscriptionManager.unsubscribe(context, context.getCurrentUser(), collection); updated = true; } // display collection home page log.info( LogManager.getHeader(context, "view_collection", "collection_id=" + collection.getID())); // perform any necessary pre-processing preProcessCollectionHome(context, request, response, collection); // Is the user logged in/subscribed? EPerson e = context.getCurrentUser(); boolean subscribed = false; if (e != null) { subscribed = SubscriptionManager.isSubscribed(context, e, collection); // is the user a COLLECTION_EDITOR? // if (collection.canEditBoolean()) if (AuthorizeManager.canEdit(collection, context)) { // set a variable to create an edit button request.setAttribute("editor_button", new Boolean(true)); } // can they admin this collection? if (AuthorizeManager.authorizeActionBoolean( context, collection, Constants.COLLECTION_ADMIN)) { request.setAttribute("admin_button", new Boolean(true)); // give them a button to manage submitter list // what group is the submitter? Group group = collection.getSubmitters(); if (group != null) { request.setAttribute("submitters", group); } } // can they submit to this collection? if (AuthorizeManager.authorizeActionBoolean(context, collection, Constants.ADD)) { request.setAttribute("can_submit_button", new Boolean(true)); } else { request.setAttribute("can_submit_button", new Boolean(false)); } } // Forward to collection home page request.setAttribute("collection", collection); request.setAttribute("community", community); request.setAttribute("logged.in", new Boolean(e != null)); request.setAttribute("subscribed", new Boolean(subscribed)); JSPManager.showJSP(request, response, "/collection-home.jsp"); if (updated) { context.complete(); } } }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // We will resolve the HTTP request parameters into a scope BrowseScope scope = new BrowseScope(context); // Will need to know whether to highlight the "focus" point boolean highlight = false; // Build up log information String logInfo = ""; // For browse by date, we'll need to work out the URL query string to // use when the user swaps the ordering, so that they stay at the same // point in the index String flipOrderingQuery = ""; // Grab HTTP request parameters String focus = request.getParameter("focus"); String startsWith = request.getParameter("starts_with"); String top = request.getParameter("top"); String bottom = request.getParameter("bottom"); // The following three are specific to browsing items by date String month = request.getParameter("month"); String year = request.getParameter("year"); String order = request.getParameter("order"); // For browse by date: oldest item first? boolean oldestFirst = false; if ((order != null) && order.equalsIgnoreCase("oldestfirst")) { oldestFirst = true; } if (browseDates && (year != null) && !year.equals("") && ((startsWith == null) || startsWith.equals(""))) { // We're browsing items by date, the user hasn't typed anything // into the "year" text box, and they've selected a year from // the drop-down list. From this we work out where to start // the browse. startsWith = year; if ((month != null) & !month.equals("-1")) { // They've selected a month as well if (month.length() == 1) { // Ensure double-digit month number month = "0" + month; } startsWith = year + "-" + month; } } // Set the scope according to the parameters passed in if (focus != null) { // ---------------------------------------------- // Browse should start at a specified focus point // ---------------------------------------------- if (browseAuthors || browseSubjects) { // For browsing authors, focus is just a text value scope.setFocus(focus); } else { // For browsing items by title or date, focus is a Handle Item item = (Item) HandleManager.resolveToObject(context, focus); if (item == null) { // Handle is invalid one. Show an error. JSPManager.showInvalidIDError(request, response, focus, Constants.ITEM); return; } scope.setFocus(item); } // Will need to highlight the focus highlight = true; logInfo = "focus=" + focus + ","; if (browseDates) { // if the date order is flipped, we'll keep the same focus flipOrderingQuery = "focus=" + URLEncoder.encode(focus, Constants.DEFAULT_ENCODING) + "&"; } } else if (startsWith != null) { // ---------------------------------------------- // Start the browse using user-specified text // ---------------------------------------------- if (browseDates) { // if the date order is flipped, we'll keep the same focus flipOrderingQuery = "starts_with=" + URLEncoder.encode(startsWith, Constants.DEFAULT_ENCODING) + "&"; /* * When the user is browsing with the most recent items first, * the browse code algorithm doesn't quite do what some people * might expect. For example, if in the index there are entries: * * Mar-2000 15-Feb-2000 6-Feb-2000 15-Jan-2000 * * and the user has selected "Feb 2000" as the start point for * the browse, the browse algorithm will start at the first * point in that index *after* "Feb 2000". "Feb 2000" would * appear in the index above between 6-Feb-2000 and 15-Jan-2000. * So, the browse code in this case will start the browse at * "15-Jan-2000". This isn't really what users are likely to * want: They're more likely to want the browse to start at the * first Feb 2000 date, i.e. 15-Feb-2000. A similar scenario * occurs when the user enters just a year. Our quick hack to * produce this behaviour is to add "-32" to the startsWith * variable, when sorting with most recent items first. This * means the browse code starts at the topmost item in the index * that matches the user's input, rather than the point in the * index where the user's input would appear. */ if (!oldestFirst) { startsWith = startsWith + "-32"; } } scope.setFocus(startsWith); highlight = true; logInfo = "starts_with=" + startsWith + ","; } else if ((top != null) || (bottom != null)) { // ---------------------------------------------- // Paginating: put specified entry at top or bottom // ---------------------------------------------- // Use a single value and a boolean to simplify the code below String val = bottom; boolean isTop = false; if (top != null) { val = top; isTop = true; } if (browseAuthors || browseSubjects) { // Value will be a text value for author browse scope.setFocus(val); } else { // Value is Handle if we're browsing items by title or date Item item = (Item) HandleManager.resolveToObject(context, val); if (item == null) { // Handle is invalid one. Show an error. JSPManager.showInvalidIDError(request, response, focus, Constants.ITEM); return; } scope.setFocus(item); } // This entry appears at the top or bottom, and so needs to have // 0 or 20 entries shown before it scope.setNumberBefore(isTop ? 0 : 20); logInfo = (isTop ? "top" : "bottom") + "=" + val + ","; if (browseDates) { // If the date order is flipped, we'll flip the table upside // down - i.e. the top will become the bottom and the bottom // the top. if (top != null) { flipOrderingQuery = "bottom=" + URLEncoder.encode(top, Constants.DEFAULT_ENCODING) + "&"; } else { flipOrderingQuery = "top=" + URLEncoder.encode(bottom, Constants.DEFAULT_ENCODING) + "&"; } } } // ---------------------------------------------- // If none of the above apply, no positioning parameters // set - use start of index // ---------------------------------------------- // Are we in a community or collection? Community community = UIUtil.getCommunityLocation(request); Collection collection = UIUtil.getCollectionLocation(request); if (collection != null) { logInfo = logInfo + ",collection_id=" + collection.getID() + ","; scope.setScope(collection); } else if (community != null) { logInfo = logInfo + ",community_id=" + community.getID() + ","; scope.setScope(community); } BrowseInfo browseInfo; try { // Query the browse index if (browseAuthors) { browseInfo = Browse.getAuthors(scope); } else if (browseDates) { browseInfo = Browse.getItemsByDate(scope, oldestFirst); } else if (browseSubjects) { browseInfo = Browse.getSubjects(scope); } else { browseInfo = Browse.getItemsByTitle(scope); } } catch (SQLException sqle) { // An invalid scope was given JSPManager.showIntegrityError(request, response); return; } // Write log entry String what = "title"; if (browseAuthors) { what = "author"; } else if (browseSubjects) { what = "subject"; } else if (browseDates) { what = "date"; } log.info( LogManager.getHeader( context, "browse_" + what, logInfo + "results=" + browseInfo.getResultCount())); if (browseInfo.getResultCount() == 0) { // No results! request.setAttribute("community", community); request.setAttribute("collection", collection); JSPManager.showJSP(request, response, "/browse/no-results.jsp"); } else { // Work out what the query strings will be for the previous // and next pages if (!browseInfo.isFirst()) { // Not the first page, so we'll need a "previous page" button // The top entry of the current page becomes the bottom // entry of the "previous page" String s; if (browseAuthors || browseSubjects) // aneesh { s = (browseInfo.getStringResults())[0]; } else { Item firstItem = (browseInfo.getItemResults())[0]; s = firstItem.getHandle(); } if (browseDates && oldestFirst) { // For browsing by date, oldest first, we need // to add the ordering parameter request.setAttribute( "previous.query", "order=oldestfirst&bottom=" + URLEncoder.encode(s, Constants.DEFAULT_ENCODING)); } else { request.setAttribute( "previous.query", "bottom=" + URLEncoder.encode(s, Constants.DEFAULT_ENCODING)); } } if (!browseInfo.isLast()) { // Not the last page, so we'll need a "next page" button // The bottom entry of the current page will be the top // entry in the next page String s; if (browseAuthors) { String[] authors = browseInfo.getStringResults(); s = authors[authors.length - 1]; } else if (browseSubjects) { String[] subjects = browseInfo.getStringResults(); s = subjects[subjects.length - 1]; } else { Item[] items = browseInfo.getItemResults(); Item lastItem = items[items.length - 1]; s = lastItem.getHandle(); } if (browseDates && oldestFirst) { // For browsing by date, oldest first, we need // to add the ordering parameter request.setAttribute( "next.query", "order=oldestfirst&top=" + URLEncoder.encode(s, Constants.DEFAULT_ENCODING)); } else { request.setAttribute( "next.query", "top=" + URLEncoder.encode(s, Constants.DEFAULT_ENCODING)); } } // Set appropriate attributes and forward to results page request.setAttribute("community", community); request.setAttribute("collection", collection); request.setAttribute("browse.info", browseInfo); request.setAttribute("highlight", new Boolean(highlight)); if (browseAuthors) { JSPManager.showJSP(request, response, "/browse/authors.jsp"); } else if (browseSubjects) { JSPManager.showJSP(request, response, "/browse/subjects.jsp"); } else if (browseDates) { request.setAttribute("oldest.first", new Boolean(oldestFirst)); request.setAttribute("flip.ordering.query", flipOrderingQuery); JSPManager.showJSP(request, response, "/browse/items-by-date.jsp"); } else { JSPManager.showJSP(request, response, "/browse/items-by-title.jsp"); } } }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { ExternalIdentifierDAO identifierDAO = ExternalIdentifierDAOFactory.getInstance(context); // Obtain information from request String uri = request.getParameter("uri"); ExternalIdentifier identifier = identifierDAO.retrieve(uri); ObjectIdentifier oi = identifier.getObjectIdentifier(); // Lookup Item title & collection Item item = null; String link = ""; String title = null; String collName = null; if (identifier != null) { item = (Item) oi.getObject(context); link = item.getIdentifier().getURL().toString(); request.setAttribute("link", link); if (item != null) { DCValue[] titleDC = item.getDC("title", null, Item.ANY); if (titleDC != null || titleDC.length > 0) { title = titleDC[0].value; } Collection[] colls = item.getCollections(); collName = colls[0].getMetadata("name"); } } else { String path = request.getPathInfo(); log.info(LogManager.getHeader(context, "invalid_id", "path=" + path)); JSPManager.showInvalidIDError(request, response, path, -1); return; } if (title == null) { title = ""; } if (collName == null) { collName = ""; } request.setAttribute("suggest.title", title); // User email from context EPerson currentUser = context.getCurrentUser(); String authEmail = null; String userName = null; if (currentUser != null) { authEmail = currentUser.getEmail(); userName = currentUser.getFullName(); } if (request.getParameter("submit") != null) { String recipAddr = request.getParameter("recip_email"); // the only required field is recipient email address if (recipAddr == null || recipAddr.equals("")) { log.info(LogManager.getHeader(context, "show_suggest_form", "problem=true")); request.setAttribute("suggest.problem", new Boolean(true)); JSPManager.showJSP(request, response, "/suggest/suggest.jsp"); return; } String recipName = request.getParameter("recip_name"); if (recipName == null || "".equals(recipName)) { try { recipName = I18nUtil.getMessage("org.dspace.app.webui.servlet.SuggestServlet.recipient", context); } catch (MissingResourceException e) { log.warn( LogManager.getHeader( context, "show_suggest_form", "Missing Resource: org.dspace.app.webui.servlet.SuggestServlet.sender")); recipName = "colleague"; } } String senderName = request.getParameter("sender_name"); if (senderName == null || "".equals(senderName)) { // use userName if available if (userName != null) { senderName = userName; } else { try { senderName = I18nUtil.getMessage("org.dspace.app.webui.servlet.SuggestServlet.sender", context); } catch (MissingResourceException e) { log.warn( LogManager.getHeader( context, "show_suggest_form", "Missing Resource: org.dspace.app.webui.servlet.SuggestServlet.sender")); senderName = "A DSpace User"; } } } String senderAddr = request.getParameter("sender_email"); if (senderAddr == null || "".equals(senderAddr)) { // use authEmail if available if (authEmail != null) { senderAddr = authEmail; } } String itemUri = identifier.getURI().toString(); String message = request.getParameter("message"); String siteName = ConfigurationManager.getProperty("dspace.name"); // All data is there, send the email try { Email email = ConfigurationManager.getEmail( I18nUtil.getEmailFilename(context.getCurrentLocale(), "suggest")); email.addRecipient(recipAddr); // recipient address email.addArgument(recipName); // 1st arg - recipient name email.addArgument(senderName); // 2nd arg - sender name email.addArgument(siteName); // 3rd arg - repository name email.addArgument(title); // 4th arg - item title email.addArgument(itemUri); // 5th arg - item identifier URI email.addArgument(link); // 6th arg - item local URL email.addArgument(collName); // 7th arg - collection name email.addArgument(message); // 8th arg - user comments // Set sender's address as 'reply-to' address if supplied if (senderAddr != null && !"".equals(senderAddr)) { email.setReplyTo(senderAddr); } // Only actually send the email if feature is enabled if (ConfigurationManager.getBooleanProperty("webui.suggest.enable", false)) { email.send(); } else { throw new MessagingException( "Suggest item email not sent - webui.suggest.enable = false"); } log.info(LogManager.getHeader(context, "sent_suggest", "from=" + senderAddr)); JSPManager.showJSP(request, response, "/suggest/suggest_ok.jsp"); } catch (MessagingException me) { log.warn(LogManager.getHeader(context, "error_mailing_suggest", ""), me); JSPManager.showInternalError(request, response); } } else { // Display suggest form log.info(LogManager.getHeader(context, "show_suggest_form", "problem=false")); request.setAttribute("authenticated.email", authEmail); request.setAttribute("eperson.name", userName); JSPManager.showJSP(request, response, "/suggest/suggest.jsp"); // asd } }
protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // Get the query String query = request.getParameter("query"); int start = UIUtil.getIntParameter(request, "start"); String advanced = request.getParameter("advanced"); String fromAdvanced = request.getParameter("from_advanced"); int sortBy = UIUtil.getIntParameter(request, "sort_by"); String order = request.getParameter("order"); int rpp = UIUtil.getIntParameter(request, "rpp"); String advancedQuery = ""; HashMap queryHash = new HashMap(); // can't start earlier than 0 in the results! if (start < 0) { start = 0; } int collCount = 0; int commCount = 0; int itemCount = 0; Item[] resultsItems; Collection[] resultsCollections; Community[] resultsCommunities; QueryResults qResults = null; QueryArgs qArgs = new QueryArgs(); SortOption sortOption = null; if (request.getParameter("etal") != null) qArgs.setEtAl(UIUtil.getIntParameter(request, "etal")); try { if (sortBy > 0) { sortOption = SortOption.getSortOption(sortBy); qArgs.setSortOption(sortOption); } if (SortOption.ASCENDING.equalsIgnoreCase(order)) { qArgs.setSortOrder(SortOption.ASCENDING); } else { qArgs.setSortOrder(SortOption.DESCENDING); } } catch (Exception e) { } if (rpp > 0) { qArgs.setPageSize(rpp); } // if the "advanced" flag is set, build the query string from the // multiple query fields if (advanced != null) { query = qArgs.buildQuery(request); advancedQuery = qArgs.buildHTTPQuery(request); } // Ensure the query is non-null if (query == null) { query = ""; } // Get the location parameter, if any String location = request.getParameter("location"); String newURL; // If there is a location parameter, we should redirect to // do the search with the correct location. if ((location != null) && !location.equals("")) { String url = ""; if (!location.equals("/")) { // Location points to a resource url = "/resource/" + location; } // Encode the query query = URLEncoder.encode(query, Constants.DEFAULT_ENCODING); if (advancedQuery.length() > 0) { query = query + "&from_advanced=true&" + advancedQuery; } // Do the redirect response.sendRedirect( response.encodeRedirectURL( request.getContextPath() + url + "/simple-search?query=" + query)); return; } // Build log information String logInfo = ""; // Get our location Community community = UIUtil.getCommunityLocation(request); Collection collection = UIUtil.getCollectionLocation(request); // get the start of the query results page // List resultObjects = null; qArgs.setQuery(query); qArgs.setStart(start); // Perform the search if (collection != null) { logInfo = "collection_id=" + collection.getID() + ","; // Values for drop-down box request.setAttribute("community", community); request.setAttribute("collection", collection); qResults = DSQuery.doQuery(context, qArgs, collection); } else if (community != null) { logInfo = "community_id=" + community.getID() + ","; request.setAttribute("community", community); // Get the collections within the community for the dropdown box request.setAttribute("collection.array", community.getCollections()); qResults = DSQuery.doQuery(context, qArgs, community); } else { // Get all communities for dropdown box // Community[] communities = Community.findAll(context); Community[] communities = (Community[]) ApplicationService.findAllCommunities(context).toArray(); request.setAttribute("community.array", communities); qResults = DSQuery.doQuery(context, qArgs); } // now instantiate the results and put them in their buckets for (int i = 0; i < qResults.getHitTypes().size(); i++) { String myURI = (String) qResults.getHitURIs().get(i); Integer myType = (Integer) qResults.getHitTypes().get(i); // add the URI to the appropriate lists switch (myType.intValue()) { case Constants.ITEM: itemCount++; break; case Constants.COLLECTION: collCount++; break; case Constants.COMMUNITY: commCount++; break; } } // Make objects from the URIs - make arrays, fill them out resultsCommunities = new Community[commCount]; resultsCollections = new Collection[collCount]; resultsItems = new Item[itemCount]; for (int i = 0; i < qResults.getHitTypes().size(); i++) { Integer myId = (Integer) qResults.getHitIds().get(i); String myURI = (String) qResults.getHitURIs().get(i); Integer myType = (Integer) qResults.getHitTypes().get(i); switch (myType.intValue()) { case Constants.ITEM: if (myId != null) { // resultsItems[itemCount] = Item.find(context, myId); resultsItems[itemCount] = ApplicationService.get(context, Item.class, myId); } else { ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI); resultsItems[itemCount] = (Item) oi.getObject(context); } if (resultsItems[itemCount] == null) { throw new SQLException("Query \"" + query + "\" returned unresolvable item"); } itemCount++; break; case Constants.COLLECTION: if (myId != null) { // resultsCollections[collCount] = Collection.find(context, myId); resultsCollections[collCount] = ApplicationService.get(context, Collection.class, myId); } else { ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI); resultsCollections[collCount] = (Collection) oi.getObject(context); } if (resultsCollections[collCount] == null) { throw new SQLException("Query \"" + query + "\" returned unresolvable collection"); } collCount++; break; case Constants.COMMUNITY: if (myId != null) { // resultsCommunities[commCount] = Community.find(context, myId); resultsCommunities[commCount] = ApplicationService.get(context, Community.class, myId); } else { ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI); resultsCommunities[commCount] = (Community) oi.getObject(context); } if (resultsCommunities[commCount] == null) { throw new SQLException("Query \"" + query + "\" returned unresolvable community"); } commCount++; break; } } // Log log.info( LogManager.getHeader( context, "search", logInfo + "query=\"" + query + "\",results=(" + resultsCommunities.length + "," + resultsCollections.length + "," + resultsItems.length + ")")); // Pass in some page qualities // total number of pages int pageTotal = 1 + ((qResults.getHitCount() - 1) / qResults.getPageSize()); // current page being displayed int pageCurrent = 1 + (qResults.getStart() / qResults.getPageSize()); // pageLast = min(pageCurrent+9,pageTotal) int pageLast = ((pageCurrent + 9) > pageTotal) ? pageTotal : (pageCurrent + 9); // pageFirst = max(1,pageCurrent-9) int pageFirst = ((pageCurrent - 9) > 1) ? (pageCurrent - 9) : 1; // Pass the results to the display JSP request.setAttribute("items", resultsItems); request.setAttribute("communities", resultsCommunities); request.setAttribute("collections", resultsCollections); request.setAttribute("pagetotal", new Integer(pageTotal)); request.setAttribute("pagecurrent", new Integer(pageCurrent)); request.setAttribute("pagelast", new Integer(pageLast)); request.setAttribute("pagefirst", new Integer(pageFirst)); request.setAttribute("queryresults", qResults); // And the original query string request.setAttribute("query", query); request.setAttribute("order", qArgs.getSortOrder()); request.setAttribute("sortedBy", sortOption); if ((fromAdvanced != null) && (qResults.getHitCount() == 0)) { // send back to advanced form if no results Community[] communities = (Community[]) ApplicationService.findAllCommunities(context).toArray(); // Community[] communities = Community.findAll(context); request.setAttribute("communities", communities); request.setAttribute("no_results", "yes"); queryHash = qArgs.buildQueryHash(request); Iterator i = queryHash.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String value = (String) queryHash.get(key); request.setAttribute(key, value); } JSPManager.showJSP(request, response, "/search/advanced.jsp"); } else { JSPManager.showJSP(request, response, "/search/results.jsp"); } }
/** * Displays the options you have in the supervisor admin area * * @param context the context of the request * @param request the servlet request * @param response the servlet response */ private void showMainPage( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { JSPManager.showJSP(request, response, "/dspace-admin/supervise-main.jsp"); }
public void processDSpaceObject( Context context, HttpServletRequest request, HttpServletResponse response, DSpaceObject dso, String extraPathInfo) throws ServletException, IOException, SQLException, AuthorizeException { // OK, we have a valid URI. What is it? if (dso.getType() == Constants.BITSTREAM) { // FIXME: Check for if-modified-since header Bitstream bitstream = (Bitstream) dso; log.info( LogManager.getHeader(context, "view_bitstream", "bitstream_id=" + bitstream.getID())); // Pipe the bits // InputStream is = bitstream.retrieve(); InputStream is = BitstreamStorageManager.retrieve(context, bitstream); // Set the response MIME type response.setContentType(bitstream.getFormat().getMIMEType()); response.setHeader("Content-Length", String.valueOf(bitstream.getSize())); response.setHeader("Content-disposition", "attachment; filename=" + bitstream.getName()); Utils.bufferedCopy(is, response.getOutputStream()); is.close(); response.getOutputStream().flush(); } else if (dso.getType() == Constants.ITEM) { Item item = (Item) dso; response.setDateHeader("Last-Modified", item.getLastModified().getTime()); // Check for if-modified-since header long modSince = request.getDateHeader("If-Modified-Since"); if (modSince != -1 && item.getLastModified().getTime() < modSince) { // Item has not been modified since requested date, // hence bitstream has not; return 304 response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } else { // Display the item page displayItem(context, request, response, item); } } else if (dso.getType() == Constants.COLLECTION) { Collection c = (Collection) dso; // Store collection location in request request.setAttribute("dspace.collection", c); /* * Find the "parent" community the collection, mainly for * "breadcrumbs" FIXME: At the moment, just grab the first community * the collection is in. This should probably be more context * sensitive when we have multiple inclusion. */ Community[] parents = (Community[]) c.getCommunities().toArray(); request.setAttribute("dspace.community", parents[0]); /* * Find all the "parent" communities for the collection for * "breadcrumbs" */ request.setAttribute("dspace.communities", getParents(parents[0], true)); // home page, or forward to another page? if ((extraPathInfo == null) || (extraPathInfo.equals("/"))) { collectionHome(context, request, response, parents[0], c); } else { // Forward to another servlet request.getRequestDispatcher(extraPathInfo).forward(request, response); } } else if (dso.getType() == Constants.COMMUNITY) { Community c = (Community) dso; // Store collection location in request request.setAttribute("dspace.community", c); /* * Find all the "parent" communities for the community */ request.setAttribute("dspace.communities", getParents(c, false)); // home page, or forward to another page? if ((extraPathInfo == null) || (extraPathInfo.equals("/"))) { communityHome(context, request, response, c); } else { // Forward to another servlet request.getRequestDispatcher(extraPathInfo).forward(request, response); } } else { // Shouldn't happen. Log and treat as invalid ID log.info( LogManager.getHeader( context, "URI not an item, collection or community", "identifier=" + dso.getIdentifier().toString())); JSPManager.showInvalidIDError(request, response, request.getPathInfo(), -1); return; } }
protected void doDSGet(Context c, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // always go first to news-main.jsp JSPManager.showJSP(request, response, "/dspace-admin/news-main.jsp"); }
@Override protected void doDSPost(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { String button = UIUtil.getSubmitButton(request, "submit"); if (button.equals("submit_update")) { // Update the metadata for a bitstream format BitstreamFormat bf = bitstreamFormatService.find(context, UIUtil.getIntParameter(request, "format_id")); bf.setMIMEType(request.getParameter("mimetype")); bf.setShortDescription(context, request.getParameter("short_description")); bf.setDescription(request.getParameter("description")); bf.setSupportLevel(UIUtil.getIntParameter(request, "support_level")); bf.setInternal( (request.getParameter("internal") != null) && request.getParameter("internal").equals("true")); // Separate comma-separated extensions List<String> extensions = new LinkedList<>(); String extParam = request.getParameter("extensions"); while (extParam.length() > 0) { int c = extParam.indexOf(','); if (c > 0) { extensions.add(extParam.substring(0, c).trim()); extParam = extParam.substring(c + 1).trim(); } else { if (extParam.trim().length() > 0) { extensions.add(extParam.trim()); extParam = ""; } } } bf.setExtensions(extensions); bitstreamFormatService.update(context, bf); showFormats(context, request, response); context.complete(); } else if (button.equals("submit_add")) { // Add a new bitstream - simply add to the list, and let the user // edit with the main form BitstreamFormat bf = bitstreamFormatService.create(context); // We set the "internal" flag to true, so that the empty bitstream // format doesn't show up in the submission UI yet bf.setInternal(true); bitstreamFormatService.update(context, bf); showFormats(context, request, response); context.complete(); } else if (button.equals("submit_delete")) { // Start delete process - go through verification step BitstreamFormat bf = bitstreamFormatService.find(context, UIUtil.getIntParameter(request, "format_id")); request.setAttribute("format", bf); JSPManager.showJSP(request, response, "/dspace-admin/confirm-delete-format.jsp"); } else if (button.equals("submit_confirm_delete")) { // User confirms deletion of format BitstreamFormat bf = bitstreamFormatService.find(context, UIUtil.getIntParameter(request, "format_id")); bitstreamFormatService.delete(context, bf); showFormats(context, request, response); context.complete(); } else { // Cancel etc. pressed - show list again showFormats(context, request, response); } }
@Override protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { Item item = null; Bitstream bitstream = null; // Get the ID from the URL String idString = request.getPathInfo(); String handle = ""; String sequenceText = ""; String filename = null; int sequenceID; // Parse 'handle' and 'sequence' (bitstream seq. number) out // of remaining URL path, which is typically of the format: // {handle}/{sequence}/{bitstream-name} // But since the bitstream name MAY have any number of "/"s in // it, and the handle is guaranteed to have one slash, we // scan from the start to pick out handle and sequence: // Remove leading slash if any: if (idString.startsWith("/")) { idString = idString.substring(1); } // skip first slash within handle int slashIndex = idString.indexOf('/'); if (slashIndex != -1) { slashIndex = idString.indexOf('/', slashIndex + 1); if (slashIndex != -1) { handle = idString.substring(0, slashIndex); int slash2 = idString.indexOf('/', slashIndex + 1); if (slash2 != -1) { sequenceText = idString.substring(slashIndex + 1, slash2); filename = idString.substring(slash2 + 1); } } } try { sequenceID = Integer.parseInt(sequenceText); } catch (NumberFormatException nfe) { sequenceID = -1; } // Now try and retrieve the item DSpaceObject dso = HandleManager.resolveToObject(context, handle); // Make sure we have valid item and sequence number if (dso != null && dso.getType() == Constants.ITEM && sequenceID >= 0) { item = (Item) dso; if (item.isWithdrawn()) { log.info( LogManager.getHeader( context, "view_bitstream", "handle=" + handle + ",withdrawn=true")); JSPManager.showJSP(request, response, "/tombstone.jsp"); return; } boolean found = false; Bundle[] bundles = item.getBundles(); for (int i = 0; (i < bundles.length) && !found; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); for (int k = 0; (k < bitstreams.length) && !found; k++) { if (sequenceID == bitstreams[k].getSequenceID()) { bitstream = bitstreams[k]; found = true; } } } } if (bitstream == null || filename == null || !filename.equals(bitstream.getName())) { // No bitstream found or filename was wrong -- ID invalid log.info(LogManager.getHeader(context, "invalid_id", "path=" + idString)); JSPManager.showInvalidIDError(request, response, idString, Constants.BITSTREAM); return; } log.info(LogManager.getHeader(context, "view_bitstream", "bitstream_id=" + bitstream.getID())); // Modification date // Only use last-modified if this is an anonymous access // - caching content that may be generated under authorisation // is a security problem if (context.getCurrentUser() == null) { // TODO: Currently the date of the item, since we don't have dates // for files response.setDateHeader("Last-Modified", item.getLastModified().getTime()); // Check for if-modified-since header long modSince = request.getDateHeader("If-Modified-Since"); if (modSince != -1 && item.getLastModified().getTime() < modSince) { // Item has not been modified since requested date, // hence bitstream has not; return 304 response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } // Pipe the bits InputStream is = bitstream.retrieve(); // Set the response MIME type response.setContentType(bitstream.getFormat().getMIMEType()); // Response length response.setHeader("Content-Length", String.valueOf(bitstream.getSize())); if (threshold != -1 && bitstream.getSize() >= threshold) { setBitstreamDisposition(bitstream.getName(), request, response); } Utils.bufferedCopy(is, response.getOutputStream()); is.close(); response.getOutputStream().flush(); }