Example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl.

Prototype

@Deprecated
public String encodeRedirectUrl(String url);

Source Link

Usage

From source file:org.etudes.mneme.tool.PoolPropertiesView.java

/**
 * {@inheritDoc}/* w ww  . ja  v a2s . c  om*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // pools sort, pool id
    if (params.length != 4)
        throw new IllegalArgumentException();
    String poolsSort = params[2];
    String pid = params[3];

    // get the pool
    Pool pool = this.poolService.getPool(pid);
    if (pool == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // if we start out, we are coming from an add
    boolean mint = pool.getMint();

    // check that the user can manage this pool
    if (!this.poolService.allowManagePools(pool.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // read the form
    context.put("pool", pool);
    String destination = uiService.decode(req, context);

    try {
        this.poolService.savePool(pool);
    } catch (AssessmentPermissionException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // change destination to edit if this is new
    if (mint) {
        // make sure we were not deleted
        pool = this.poolService.getPool(pid);
        if (pool != null) {
            // send them to edit pool
            destination = "/pool_edit/" + pool.getId() + "/-/-/-" + destination;
        }
    }

    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.muse.mneme.tool.FinalReviewView.java

/**
 * {@inheritDoc}/*  ww  w  . j  ava2 s . c  o m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need one parameter (sid)
    if (params.length != 3) {
        throw new IllegalArgumentException();
    }

    String submissionId = params[2];

    // 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("finalReview", Boolean.TRUE);

    // 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.ImportTqAssessmentView.java

/**
 * {@inheritDoc}//from  ww  w.  j  a  v  a 2 s  .c  o m
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] pools sort, [3] source context
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }
    String poolsSort = params[2];
    String sourceContext = params[3];

    if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    Values selectedPools = this.uiService.newValues();
    context.put("selectedAssessments", selectedPools);

    // read the form
    String destination = uiService.decode(req, context);

    // import the pools
    if ("IMPORT".equals(destination)) {
        for (String id : selectedPools.getValues()) {
            try {
                this.importService.importAssessment(id, toolManager.getCurrentPlacement().getContext());
            } catch (AssessmentPermissionException e) {
                // redirect to error
                res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
                return;
            }
        }

        destination = "/pools/" + poolsSort;
    }

    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.etudes.mneme.tool.TocView.java

/**
 * Handle the many cases of a post that completes the submission
 * /*from ww w.  jav a  2 s  .  co  m*/
 * @param req
 *        Servlet request.
 * @param res
 *        Servlet response.
 * @param context
 *        The UiContext.
 * @param submissionId
 *        the selected submission id.
 * @param uiService
 *        the UI service.
 * @param assessmentService
 *        the Assessment service.
 * @param returnDestination
 *        The final return destination path.
 */
protected static void submissionCompletePost(HttpServletRequest req, HttpServletResponse res, Context context,
        String submissionId, UiService uiService, SubmissionService assessmentService, String returnDestination)
        throws IOException {
    // if (!context.getPostExpected())
    // {
    // // redirect to error
    // res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unexpected)));
    // return;
    // }

    // read form
    String destination = uiService.decode(req, context);

    Boolean autoComplete = Boolean.FALSE;
    boolean destinationOkOverride = false;

    Submission submission = assessmentService.getSubmission(submissionId);

    if (destination.equals("SUBMIT")) {
        // if linear, or the submission is all answered, we can go to submitted
        if ((!submission.getAssessment().getRandomAccess()) || (submission.getIsAnswered())) {
            destination = "/submitted/" + submissionId + returnDestination;
            // we will complete below
        }

        // if not linear, and there are unanswered parts, send to final review
        else {
            destination = "/final_review/" + submissionId + returnDestination;

            // we do not want to complete - redirect now
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
            return;
        }
    }

    else if (destination.equals("AUTO")) {
        // check if this submission is really done (time over, past deadline)
        if (submission.getIsOver(new Date(), 0)) {
            autoComplete = Boolean.TRUE;
            destination = "/submitted/" + submissionId + returnDestination;
        } else {
            // if for some reason we are here (AUTO) but the submission is not yet really over, just return to list
            destination = "/list";

            // we do not want to complete - redirect now
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
            return;
        }
    }

    // we need to be headed to submitted...
    if (!destination.startsWith("/submitted")) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalidpost)));
        return;
    }

    try {
        assessmentService.completeSubmission(submission, autoComplete);

        // if no exception, it worked! redirect
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
        return;
    } catch (AssessmentClosedException e) {
    } catch (SubmissionCompletedException e) {
    } catch (AssessmentPermissionException e) {
    }

    // redirect to error
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
}

From source file:com.expressflow.servlets.ExecProcessServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
        performRequest(request, response);
        try {//  w ww  .j  a  va2  s .com
            response.getOutputStream().println(new JSONObject().put("result", "success").toString());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace(System.err);
        }
    } else {
        response.sendRedirect(response.encodeRedirectURL(userService.createLoginURL(request.getRequestURI())));
    }
}

From source file:org.etudes.mneme.tool.ImportOfflineView.java

/**
 * {@inheritDoc}/*from  w  w w  .j  av  a  2  s .  c o  m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    if (!this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    String returnUrl = (params.length > 3) ? params[2] : "";
    String sort = (params.length > 3) ? params[3] : "0A";

    context.put("returnUrl", returnUrl);
    context.put("sort", sort);

    // render
    uiService.render(ui, context);
}

From source file:org.muse.mneme.tool.AssessmentStatsView.java

/**
 * {@inheritDoc}/* www .  jav  a 2  s.  c o  m*/
 */
public void get(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];
    context.put("sort_grades", gradesSortCode);

    Assessment assessment = this.assessmentService.getAssessment(params[3]);
    if (assessment == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check for user permission to access the submission for grading
    if (!this.submissionService.allowEvaluate(assessment.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("assessment", assessment);

    // collect all the submissions for the assessment
    List<Submission> submissions = this.submissionService.findAssessmentSubmissions(assessment,
            SubmissionService.FindAssessmentSubmissionsSort.sdate_a, Boolean.FALSE, null, null, null);
    context.put("submissions", submissions);

    computePercentComplete(submissions, context);

    uiService.render(ui, context);
}

From source file:com.basicservice.controller.UserController.java

@RequestMapping(value = "/registrationConfirmation", method = RequestMethod.GET)
public ResponseEntity<String> confirmEmail(HttpServletRequest request,
        @RequestParam(value = "key") UUIDValidatedString key, HttpServletResponse response) {
    String validatdKey = Utils.getValueFromValidatedString(key);
    if (validatdKey != null) {
        String userId = confirmationEmailService.confirmEmail(key);
        if (userId != null) {
            User user = userService.get(userId);
            user.setEmailConfirmed(true);
            userService.save(user);//from w ww .ja v a  2  s.co  m
        }
    }
    String uri = Utils.getBasicPath(request);
    try {
        response.sendRedirect(response.encodeRedirectURL(uri));
    } catch (IOException e) {
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}

From source file:org.etudes.mneme.tool.ExportDataView.java

/**
 * {@inheritDoc}//from  w w w  .ja va 2  s. c  om
 */
public void get(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];
    context.put("sort_grades", gradesSortCode);

    Assessment assessment = this.assessmentService.getAssessment(params[3]);
    if (assessment == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check for user permission to access the submission for grading
    if (!this.submissionService.allowEvaluate(assessment.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        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 if a survey, the assessment has been frozen
    if ((assessment.getType() == AssessmentType.survey) && (!assessment.getFrozen())) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // validity check
    if (!assessment.getIsValid()) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("assessment", assessment);

    // collect all the submissions for the assessment
    /*List<Submission> submissions = this.submissionService.findAssessmentSubmissions(assessment,
    SubmissionService.FindAssessmentSubmissionsSort.sdate_a, Boolean.FALSE, null, null, null, null);
    context.put("submissions", submissions);
            
    computePercentComplete(assessment, submissions, context);*/

    uiService.render(ui, context);
}

From source file:org.muse.mneme.tool.InstructionsView.java

/**
 * {@inheritDoc}// w ww  . ja v a2 s . co m
 */
public void post(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];

    // read form
    String destination = this.uiService.decode(req, context);

    // if other than the /submitted destination, just go there
    if (!destination.startsWith("/submitted")) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
        return;
    }

    // this post is from the timer, and completes the submission
    TocView.submissionCompletePost(req, res, context, submissionId, this.uiService, this.submissionService);
}