List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl
@Deprecated
public String encodeRedirectUrl(String url);
From source file:org.etudes.mneme.tool.ImporteCollegeTextView.java
/** * {@inheritDoc}//from w w w . j av a2 s. c om */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2] pools sort if (params.length != 3) { throw new IllegalArgumentException(); } String poolsSort = params[2]; context.put("poolsSort", poolsSort); if (this.instructionsUrl != null) context.put("instructionsUrl", this.instructionsUrl); if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // render uiService.render(ui, context); }
From source file:org.etudes.mneme.tool.QuestionsCopyMoveView.java
/** * {@inheritDoc}/*from w ww.ja v a 2s . c om*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [, question_move, pool_edit, 21(pool id), 2A, 1-30, pools, 0A, 56] - last parameter is the list of question ids if (params.length < 4) { throw new IllegalArgumentException(); } // check security if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } String questionIds = params[params.length - 2]; // for the selected pool Value value = this.uiService.newValue(); context.put("selectedPoolId", value); // read form String destination = this.uiService.decode(req, context); if (destination.equals("DOIT")) { String selectedPoolId = value.getValue(); if (selectedPoolId != null) { Pool pool = this.poolService.getPool(selectedPoolId); try { String qids[] = StringUtil.split(questionIds, "+"); for (String qid : qids) { // get the question Question question = this.questionService.getQuestion(qid); if (question != null) { // which function to perform if (path.startsWith("question_copy")) { this.questionService.copyQuestion(question, pool); } else if (path.startsWith("question_move")) { this.questionService.moveQuestion(question, pool); } } } // back to the pool destination = "/" + StringUtil.unsplit(params, 2, params.length - 4, "/"); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } } } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.PoolsView.java
/** * {@inheritDoc}//from w w w. j a v a 2s . c om */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // sort optional if ((params.length != 2) && (params.length != 3)) { throw new IllegalArgumentException(); } // security if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // sort parameter String sortCode = "0A"; if (params.length > 2) sortCode = params[2]; // for the selected pools to delete Values values = this.uiService.newValues(); context.put("poolids", values); // read form String destination = this.uiService.decode(req, context); if (destination.equals("DELETE")) { for (String id : values.getValues()) { Pool pool = this.poolService.getPool(id); if (pool != null) { try { this.poolService.removePool(pool); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect( res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } } } destination = context.getDestination(); } else if (destination.equals("ADD")) { try { // create new pool Pool newPool = this.poolService.newPool(toolManager.getCurrentPlacement().getContext()); // edit it next destination = "/pool_properties/" + sortCode + "/" + newPool.getId(); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } } else if (destination.equals("COMBINE")) { try { // create a new pool Pool newPool = this.poolService.newPool(toolManager.getCurrentPlacement().getContext()); // copy in all the questions for (String id : values.getValues()) { Pool sourcePool = this.poolService.getPool(id); this.questionService.copyPoolQuestions(sourcePool, newPool); } // edit it next destination = "/pool_properties/" + sortCode + "/" + newPool.getId(); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } } else if (destination.startsWith("DUPLICATE:")) { String[] parts = StringUtil.split(destination, ":"); if (parts.length != 2) { throw new IllegalArgumentException(); } String pid = parts[1]; try { Pool pool = this.poolService.getPool(pid); if (pool != null) { this.poolService.copyPool(toolManager.getCurrentPlacement().getContext(), pool); } // stay here destination = context.getDestination(); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.ImportMnemeSiteView.java
/** * {@inheritDoc}/*from ww w . jav a 2 s .co m*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { String destination = null; if (params.length > 2) { destination = "/" + StringUtil.unsplit(params, 2, params.length - 2, "/"); } // if not specified, go to the main assessments page else { destination = "/assessments"; } context.put("return", destination); if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // the list of site for this user with Mneme access List<Ent> sites = this.importService.getMnemeSites(null, toolManager.getCurrentPlacement().getContext()); context.put("sites", sites); // render uiService.render(ui, context); }
From source file:org.muse.mneme.tool.AssessmentSpecialView.java
/** * {@inheritDoc}/*from w ww . j a va2 s. c o m*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { if (params.length != 4) { throw new IllegalArgumentException(); } // sort parameter for return view String sort = params[2]; // assessment id parameter String aid = params[3]; Assessment assessment = assessmentService.getAssessment(aid); if (assessment == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // security check if (!assessmentService.allowEditAssessment(assessment)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // for the ids selected for delete Values values = this.uiService.newValues(); context.put("ids", values); // read form String destination = this.uiService.decode(req, context); if ("DEL".equals(destination)) { // delete the selected ids String[] ids = values.getValues(); if (ids != null && (ids.length > 0)) { for (String id : ids) { AssessmentAccess access = assessment.getSpecialAccess().getAccess(id); if (access != null) { assessment.getSpecialAccess().removeAccess(access); } } } // make sure any undefined user ids or users without permissions are removed assessment.getSpecialAccess().assureValidUsers(); // save try { this.assessmentService.saveAssessment(assessment); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } catch (AssessmentPolicyException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy))); return; } destination = context.getDestination(); } // deal with add else if ("ADD".equals(destination)) { AssessmentAccess access = assessment.getSpecialAccess().addAccess(); // save try { this.assessmentService.saveAssessment(assessment); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } catch (AssessmentPolicyException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy))); return; } // go edit it destination = "/assessment_access/" + sort + "/" + aid + "/" + access.getId(); } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.muse.mneme.tool.InstructionsView.java
/** * {@inheritDoc}//from w w w . java2 s. c o m */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // we need two parameters (submissionId, sectionId) if (params.length < 4) { throw new IllegalArgumentException(); } String submissionId = params[2]; String returnDestination = "/" + StringUtil.unsplit(params, 3, params.length - 3, "/"); // collect the submission Submission submission = submissionService.getSubmission(submissionId); if (submission == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } if (!submissionService.allowCompleteSubmission(submission)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } context.put("submission", submission); context.put("destination", returnDestination); // for the tool navigation if (this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) { context.put("maintainer", Boolean.TRUE); } // render uiService.render(ui, context); }
From source file:org.etudes.mneme.tool.FreezeView.java
/** * {@inheritDoc}// w w w. j av a 2 s . c o m */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2]sort for /grades, [3]aid if (params.length != 4) throw new IllegalArgumentException(); // grades sort parameter String gradesSortCode = params[2]; // security if (!this.submissionService.allowEvaluate(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } Assessment assessment = this.assessmentService.getAssessment(params[3]); if (assessment == null) { res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // check that we have a survey if (assessment.getType() != AssessmentType.survey) { res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // check that the assessment is not a formal course evaluation if (assessment.getFormalCourseEval()) { res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // check that it has NOT been frozen if (assessment.getFrozen()) { res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // read the form String destination = uiService.decode(req, context); // if publish, set if ("FREEZE".equals(destination)) { assessment.setFrozen(); destination = "/assessment_stats/" + gradesSortCode + "/" + assessment.getId(); // commit the save try { this.assessmentService.saveAssessment(assessment); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } catch (AssessmentPolicyException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy))); return; } } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.InstructionsView.java
/** * {@inheritDoc}/*from w w w. j a v a2s.c om*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // sid and return if (params.length < 4) { throw new IllegalArgumentException(); } String submissionId = params[2]; String returnDestination = "/" + StringUtil.unsplit(params, 3, params.length - 3, "/"); // collect the submission Submission submission = submissionService.getSubmission(submissionId); if (submission == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } if (!submissionService.allowCompleteSubmission(submission)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // Separate out the final return path from the immediate return - the timers that submit need to know the final return path (like /list) // Note: this is nasty hard coded to all the places that instructions can be called from. String finalReturn = "/list"; if ("part_instructions".equals(params[3])) { finalReturn = "/" + StringUtil.unsplit(params, 6, params.length - 6, "/"); } else if ("question".equals(params[3])) { finalReturn = "/" + StringUtil.unsplit(params, 7, params.length - 7, "/"); } else if ("toc".equals(params[3])) { finalReturn = "/" + StringUtil.unsplit(params, 5, params.length - 5, "/"); } context.put("return", finalReturn); context.put("submission", submission); context.put("destination", returnDestination); // for the tool navigation if (this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) { context.put("maintainer", Boolean.TRUE); } // render uiService.render(ui, context); }
From source file:org.etudes.mneme.tool.InstructionsEditView.java
/** * {@inheritDoc}//from w w w . jav a 2 s . c om */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // aid, return if (params.length < 3) { throw new IllegalArgumentException(); } String assessmentId = params[2]; final Assessment assessment = assessmentService.getAssessment(assessmentId); if (assessment == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // security check if (!assessmentService.allowEditAssessment(assessment)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // setup the model: the selected assessment context.put("assessment", assessment); // for editing the parts titles PopulatingSet parts = uiService.newPopulatingSet(new Factory() { public Object get(String id) { Part part = assessment.getParts().getPart(id); return part; } }, new Id() { public String getId(Object o) { return ((Part) o).getId(); } }); context.put("parts", parts); // read the form String destination = uiService.decode(req, context); // // handle an attachments remove // if (destination.startsWith("REMOVE:")) // { // String[] parts = StringUtil.split(destination, ":"); // if (parts.length != 2) // { // throw new IllegalArgumentException(); // } // String refString = parts[1]; // Reference ref = this.entityManager.newReference(refString); // // // remove from the assessment // assessment.getPresentation().removeAttachment(ref); // // // remove the attachment // // TODO: really? // this.attachmentService.removeAttachment(ref); // // // stay here // destination = context.getDestination(); // } try { if (destination.equals("SAVE")) { this.assessmentService.saveAssessment(assessment); destination = context.getDestination(); } else { this.assessmentService.saveAssessment(assessment); } } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } catch (AssessmentPolicyException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy))); return; } // redirect to the next destination res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.muse.mneme.tool.AssessmentEditView.java
/** * {@inheritDoc}/*w w w . j av a 2s .co m*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // sort, aid if (params.length != 4) { throw new IllegalArgumentException(); } String sort = params[2]; String assessmentId = params[3]; Assessment assessment = assessmentService.getAssessment(assessmentId); if (assessment == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // security check if (!assessmentService.allowEditAssessment(assessment)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // clear the assessment of any empty parts (if not mint, which would end up causing it to become a stale mint and vanish!) if (!assessment.getMint()) { try { assessment.getParts().removeEmptyParts(); this.assessmentService.saveAssessment(assessment); } catch (AssessmentPermissionException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } catch (AssessmentPolicyException e) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy))); return; } } // collect information: the selected assessment context.put("assessment", assessment); context.put("sortcode", sort); // value holders for the selection checkboxes Values values = this.uiService.newValues(); context.put("ids", values); // render uiService.render(ui, context); }