List of usage examples for javax.servlet.http HttpServletRequest getParameterValues
public String[] getParameterValues(String name);
String
objects containing all of the values the given request parameter has, or null
if the parameter does not exist. From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.DuplicateCommand.java
@Override public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { String[] targets = request.getParameterValues("targets[]"); List<FsItemEx> added = new ArrayList<FsItemEx>(); for (String target : targets) { FsItemEx fsi = super.findItem(fsService, target); String name = fsi.getName(); String baseName = FilenameUtils.getBaseName(name); String extension = FilenameUtils.getExtension(name); int i = 1; FsItemEx newFile = null;//from w ww. j a v a 2 s .c o m baseName = baseName.replaceAll("\\(\\d+\\)$", ""); while (true) { String newName = String.format("%s(%d)%s", baseName, i, (extension == null || extension.isEmpty() ? "" : "." + extension)); newFile = new FsItemEx(fsi.getParent(), newName); if (!newFile.exists()) { break; } i++; } createAndCopy(fsi, newFile); added.add(newFile); } json.put("added", files2JsonArray(request, added)); }
From source file:org.osmsurround.ae.search.SearchController.java
@RequestMapping(value = "/search", method = RequestMethod.GET) public @ResponseBody List<Amenity> get(BoundingBox boundingBox, HttpServletRequest request, HttpServletResponse resp) throws IOException { long time = System.currentTimeMillis(); String[] show = request.getParameterValues("show"); String[] hide = request.getParameterValues("hide"); List<Amenity> amenities = searchService.findAmenities(boundingBox, new FilterSet(show, hide)); log.info("found: " + amenities.size() + " in " + (System.currentTimeMillis() - time) + " ms"); resp.setContentType("application/json"); resp.setCharacterEncoding("UTF-8"); resp.addHeader("Cache-Control", "no-cache"); resp.addHeader("Pragma", "no-cache"); return amenities; }
From source file:org.tapestry.surveys.DoSurveyAction.java
/** * @return the next url to go to, excluding contextPath */// ww w. jav a2 s.com public static ModelAndView execute(HttpServletRequest request, String documentId, TapestryPHRSurvey currentSurvey, PHRSurvey templateSurvey) throws Exception { ModelAndView m = new ModelAndView(); final String questionId = request.getParameter("questionid"); String direction = request.getParameter("direction"); String observerNotes = request.getParameter("observernote"); if (direction == null) direction = "forward"; if (documentId == null) { logger.error("no selected survey? documentId=" + documentId); m.setViewName("failed"); return m; } String[] answerStrs = request.getParameterValues("answer"); String nextQuestionId = questionId; //if requested survey does not exist if (currentSurvey == null) { logger.error("Cannot find requested survey. documentId=" + documentId); m.setViewName("failed"); return m; } //if requested survey is completed if (currentSurvey.isComplete()) logger.error("trying to complete already completed survey?"); boolean saved = false; //if starting/continuing survey, clear session if (questionId == null) { //if just starting/continuing(from before) the survey, direct to last question String lastQuestionId; if (currentSurvey.getQuestions().size() == 0) { boolean moreQuestions = addNextQuestion(null, currentSurvey, templateSurvey); if (!moreQuestions) { logger.error("Survey has no questions?"); m.setViewName("failed"); return m; } } if (currentSurvey.isComplete()) { //if complete show first question lastQuestionId = currentSurvey.getQuestions().get(0).getId(); m.addObject("hideObservernote", true); } else { //if not complete show next question lastQuestionId = currentSurvey.getQuestions().get(currentSurvey.getQuestions().size() - 1).getId(); //logic for displaying Observer Notes button if (isFirstQuestionId(lastQuestionId, '0')) m.addObject("hideObservernote", true); else m.addObject("hideObservernote", false); } m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", lastQuestionId); m.addObject("resultid", documentId); m.setViewName("/surveys/show_survey"); return m; } //end of questionId == null; String errMsg = null; //if continuing survey (just submitted an answer) if (questionId != null && direction.equalsIgnoreCase("forward")) { if (currentSurvey.getQuestionById(questionId).getQuestionType().equals(SurveyQuestion.ANSWER_CHECK) && answerStrs == null) answerStrs = new String[0]; if (answerStrs != null && (currentSurvey.getQuestionById(questionId).getQuestionType() .equals(SurveyQuestion.ANSWER_CHECK) || !answerStrs[0].equals(""))) { SurveyQuestion question = currentSurvey.getQuestionById(questionId); String questionText = question.getQuestionText(); //append observernote to question text if (!Utils.isNullOrEmpty(questionText)) { String separator = "/observernote/ "; StringBuffer sb = new StringBuffer(); sb.append(questionText); sb.append(separator); sb.append(observerNotes); questionText = sb.toString(); question.setQuestionText(questionText); } ArrayList<SurveyAnswer> answers = convertToSurveyAnswers(answerStrs, question); boolean goodAnswerFormat = true; if (answers == null) goodAnswerFormat = false; //check each answer for validation if (goodAnswerFormat && question.validateAnswers(answers)) { boolean moreQuestions; //see if the user went back (if current question the last question in user's question profile) if (!currentSurvey.getQuestions().get(currentSurvey.getQuestions().size() - 1) .equals(question)) { ArrayList<SurveyAnswer> existingAnswers = currentSurvey.getQuestionById(questionId) .getAnswers(); //if user hit back, and then forward, and answer wasn't changed if (StringUtils.join(answerStrs, ", ").equals(StringUtils.join(existingAnswers, ", ")) || currentSurvey.isComplete()) { logger.debug("user hit back and went forward, no answer was changed"); moreQuestions = true; //if the user hit "back" and changed the answer - remove all questions after it } else { ArrayList<SurveyQuestion> tempquestions = new ArrayList<SurveyQuestion>(); //Create a temp array list to transfer answered questions //remove all future answers logger.debug("user hit back and changed an answer"); //clear all questions following it int currentSurveySize = currentSurvey.getQuestions().size(); //stores number of questions int currentQuestionIndex = currentSurvey.getQuestions().indexOf(question); //gets the current question index for (int i = currentQuestionIndex + 1; i < currentSurveySize; i++) { tempquestions.add(currentSurvey.getQuestions().get(currentQuestionIndex + 1)); currentSurvey.getQuestions().remove(currentQuestionIndex + 1); //goes through quesitons list and removes each question after it } //save answers modified/input by user into question question.setAnswers(answers); saved = true; //add new question moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); //check if old index and new index contain same questions in the same list int sizeofcurrentquestionslist = currentSurvey.getQuestions().size(); //Size of new getQuestions aftre removing future questions if (currentSurvey.getQuestions().get(sizeofcurrentquestionslist - 1).getId() .equals(tempquestions.get(0).getId())) { currentSurvey.getQuestions().remove(sizeofcurrentquestionslist - 1); for (int y = 0; y < tempquestions.size(); y++) currentSurvey.getQuestions().add(tempquestions.get(y)); moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); } //if same then replace temp list with new list //if not then add the one new item. } //if user didn't go back, and requesting the next question } else { logger.debug("user hit forward, and requested the next question"); question.setAnswers(answers); saved = true; moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); } //finished survey if (!moreQuestions) { if (!currentSurvey.isComplete()) { SurveyAction.updateSurveyResult(currentSurvey); m.addObject("survey_completed", true); m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); m.addObject("message", "SURVEY FINISHED - Please click SUBMIT"); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } else { m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); m.addObject("message", "End of Survey"); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } } int questionIndex = currentSurvey.getQuestionIndexbyId(questionId); nextQuestionId = currentSurvey.getQuestions().get(questionIndex + 1).getId(); logger.debug("Next question id: " + nextQuestionId); //save to indivo if (saved && questionIndex % SAVE_INTERVAL == 0 && !currentSurvey.isComplete()) SurveyAction.updateSurveyResult(currentSurvey); //if answer fails validation } // end of validation answers else { m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); if (question.getRestriction() != null && question.getRestriction().getInstruction() != null) m.addObject("message", question.getRestriction().getInstruction()); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } //if answer not specified, and hit forward } else errMsg = "You must supply an answer"; } //end of forward action else if (direction.equalsIgnoreCase("backward")) { int questionIndex = currentSurvey.getQuestionIndexbyId(questionId); if (questionIndex > 0) nextQuestionId = currentSurvey.getQuestions().get(questionIndex - 1).getId(); } //backward to the description page(before the first qustion) if ((questionId != null) && ("backward".equals(direction)) && (isFirstQuestionId(questionId, '0'))) m.addObject("hideObservernote", true); else m.addObject("hideObservernote", false); m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", nextQuestionId); m.addObject("resultid", documentId); if (errMsg != null) m.addObject("message", errMsg); m.setViewName("/surveys/show_survey"); return m; }
From source file:com.pkrete.locationservice.admin.controller.mvc.HandleLocationController.java
/** * Parses SubjectMatters objects from the Request object and sets them to * the given Location.//from w w w. j a va2 s . c o m * * @param request request with the necessary parameters * @param location Location that owns the SubjectMatters */ protected void parseSubjectMatters(HttpServletRequest request, Location location) { String[] values = request.getParameterValues("subjectMatters"); List<SubjectMatter> subjects = new ArrayList<SubjectMatter>(); if (values != null) { for (int i = 0; i < values.length; i++) { subjects.add(this.subjectMattersService.getSubjectMatter(this.converterService.strToInt(values[i]), location.getOwner())); } } location.setSubjectMatters(subjects); }
From source file:org.openmrs.module.dms.web.controller.main.DeleteUnitController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, HttpServletRequest request) { DmsService dmsService = Context.getService(DmsService.class); DmsOpdUnit dmsopdunit = new DmsOpdUnit(); String select[] = request.getParameterValues("showResultsn"); if (select != null && select.length != 0) { for (int i = 0; i < select.length; i++) { Integer unitid = Integer.parseInt(select[i]); dmsopdunit = dmsService.getDmsOpd(unitid); dmsService.deleteDmsOpdUnit(dmsopdunit); }//from w w w . j av a 2 s . c om } HttpSession httpSession = request.getSession(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.delete.success"); return "redirect:/module/dms/deleteUnit.form"; }
From source file:com.pureinfo.tgirls.servlet.SendSystemMsgServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String[] uids = request.getParameterValues("uids"); String msg = request.getParameter("msg"); JsonBase result = new JsonBase(); response.setContentType("text/json; charset=utf-8"); logger.debug("to send msg[" + msg + "] to uids[" + Arrays.toString(uids) + "]"); try {/* w ww . ja v a 2 s . c om*/ if (uids == null || uids.length == 0 || StringUtils.isEmpty(msg)) { throw new Exception("??"); } String sessionId = (String) CookieUtils.getRequestCookieValue(request, SessionConstants.TAOBAO_SESSION_ID); for (int i = 0; i < uids.length; i++) { String uid = uids[i]; try { ObjResponse<Boolean> or = TOPAPI.getInstance().sendSysMsg(Long.parseLong(uid), msg, sessionId); if (or.isSuccess()) { logger.info("msg send success for[" + uid + "]"); } else { logger.info("msg send error for[" + uid + "]"); logger.info(or.getMsg()); } } catch (Exception e) { logger.error("error when send msg.skip this msg.", e); } } } catch (Exception e) { logger.error("error when send msg.", e); result.setErrorCode(ErrorCode.ERROR.getCode()); if (StringUtils.isNotEmpty(e.getMessage())) { result.setErrorMsg(e.getMessage()); } else { result.setErrorMsg(""); } } response.getWriter().write(result.toString()); return; }
From source file:com.intel.cosbench.controller.web.MatrixPageController.java
@Override protected ModelAndView process(HttpServletRequest req, HttpServletResponse res) throws Exception { ModelAndView result = new ModelAndView("matrix"); String[] ops = req.getParameterValues("ops"); if (ops != null && ops.length > 0) for (String op : ops) result.addObject(op, true);//from ww w .jav a2 s. c o m else result.addObject("allOps", true); String[] metrics = req.getParameterValues("metrics"); if (metrics != null && metrics.length > 0) for (String metric : metrics) result.addObject(metric, true); else result.addObject("allMetrics", true); String[] rthistos = req.getParameterValues("rthisto"); if (rthistos != null && rthistos.length > 0) for (String rthisto : rthistos) result.addObject(rthisto, true); String[] others = req.getParameterValues("others"); if (others != null && others.length > 0) for (String other : others) result.addObject(other, true); if (req.getParameter("type").equals("histo")) result.addObject("hInfos", controller.getHistoryWorkloads()); else if (req.getParameter("type").equals("arch")) { for (WorkloadInfo info : controller.getArchivedWorkloads()) { if (info.getReport().getAllMetrics().length == 0) { try { controller.getWorkloadLoader().loadWorkloadPageInfo(info); } catch (IOException e) { e.printStackTrace(); } } } result.addObject("hInfos", controller.getArchivedWorkloads()); } result.addObject("type", req.getParameter("type")); return result; }
From source file:net.duckling.ddl.web.api.APIShareController.java
/** * //w ww . j av a2s . c o m * @param request * @return */ @ResponseBody @RequestMapping(params = "func=delete") @SuppressWarnings("unchecked") public JSONObject deleteShareResource(HttpServletRequest request) { String[] rs = request.getParameterValues("rids[]"); int[] rids = new int[rs.length]; for (int i = 0; i < rs.length; i++) { rids[i] = Integer.parseInt(rs[i]); } for (int rid : rids) { shareResourceService.delete(rid); } JSONObject obj = new JSONObject(); obj.put("success", true); return obj; }
From source file:org.openmrs.module.dms.web.controller.main.DeActivatedUnitListController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, HttpServletRequest request) { DmsService dmsService = Context.getService(DmsService.class); DmsOpdUnit dmsopdunit = new DmsOpdUnit(); String select[] = request.getParameterValues("showResultsn"); if (select != null && select.length != 0) { for (int i = 0; i < select.length; i++) { Integer unitid = Integer.parseInt(select[i]); dmsopdunit = dmsService.getDmsOpd(unitid); dmsopdunit.setUnitActiveDate(new Date()); dmsopdunit.setUnitDeactiveDate(null); dmsService.saveOrUpdateUnit(dmsopdunit); }//from w ww . ja v a 2 s. co m } HttpSession httpSession = request.getSession(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.activate.success"); return "redirect:/module/dms/deActivatedUnitList.form"; }
From source file:org.openmrs.module.dms.web.controller.main.DeActivateUnitController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, HttpServletRequest request) { DmsService dmsService = Context.getService(DmsService.class); DmsOpdUnit dmsopdunit = new DmsOpdUnit(); String select[] = request.getParameterValues("showResultsn"); if (select != null && select.length != 0) { for (int i = 0; i < select.length; i++) { Integer unitid = Integer.parseInt(select[i]); dmsopdunit = dmsService.getDmsOpd(unitid); dmsopdunit.setUnitActiveDate(null); dmsopdunit.setUnitDeactiveDate(new Date()); dmsService.saveOrUpdateUnit(dmsopdunit); }//from w w w . ja v a2 s. c o m } HttpSession httpSession = request.getSession(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "dms.deactivate.success"); return "redirect:/module/dms/deActivateUnit.form"; }