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.PoolsView.java

/**
 * {@inheritDoc}/* w w  w  .  j  a v a 2 s .c  o m*/
 */
public void get(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];
    if ((sortCode == null) || (sortCode.length() != 2)) {
        throw new IllegalArgumentException();
    }
    context.put("sort_column", sortCode.charAt(0));
    context.put("sort_direction", sortCode.charAt(1));

    // 0 is title
    PoolService.FindPoolsSort sort = null;
    if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) {
        sort = PoolService.FindPoolsSort.title_a;
    } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) {
        sort = PoolService.FindPoolsSort.title_d;
    } else if ((sortCode.charAt(0) == '2') && (sortCode.charAt(1) == 'A')) {
        sort = PoolService.FindPoolsSort.created_a;
    } else if ((sortCode.charAt(0) == '2') && (sortCode.charAt(1) == 'D')) {
        sort = PoolService.FindPoolsSort.created_d;
    } else {
        throw new IllegalArgumentException();
    }

    // collect the pools to show
    List<Pool> pools = this.poolService.findPools(toolManager.getCurrentPlacement().getContext(), sort, null);
    context.put("pools", pools);

    // disable the tool navigation to this view
    context.put("disablePools", Boolean.TRUE);

    // pre-read question counts per pool
    this.questionService.preCountContextQuestions(toolManager.getCurrentPlacement().getContext());

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

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

/**
 * {@inheritDoc}//from   w  ww . j  a  v a2  s  . c  om
 */
public void get(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;
    }

    // make sure any undefined user ids or users without permissions are removed
    assessment.getSpecialAccess().assureValidUsers();

    // collect information: the selected assessment
    context.put("assessment", assessment);
    context.put("sort", sort);

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

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

/**
 * {@inheritDoc}/*  w  w w .  j  av  a  2  s .  c o 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;
    }

    // format an invalid message
    if ((!assessment.getIsValid()) && (!assessment.getPublished())) {
        context.put("invalidMsg", AssessmentInvalidView.formatInvalidDisplay(assessment, this.messages));
    }

    // format part list of zero parts
    if (assessment.getHasPoints() && assessment.getParts().getHasZeroPointParts()) {
        StringBuilder buf = new StringBuilder("<ul>");
        Object args[] = new Object[1];
        for (Part part : assessment.getParts().getParts()) {
            if ((part.getTotalPoints().floatValue() == 0f) && (part.getIsValid())) {
                args[0] = part.getTitle();
                if (args[0] == null)
                    args[0] = part.getOrdering().getPosition().toString();
                buf.append("<li>" + this.messages.getFormattedMessage("part", args) + "</li>");
            }
        }
        buf.append("</ul>");
        context.put("zeroMsg", buf.toString());
    }

    // collect information: the selected assessment
    context.put("assessment", assessment);
    context.put("sort", sort);

    // check if we have gradebook
    context.put("gradebookAvailable", this.gradesService.available(assessment.getContext()));

    // if we have a focus parameter
    String focus = req.getParameter("focus");
    if (focus != null)
        context.addFocusId(focus);

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

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

/**
 * {@inheritDoc}//from w  ww  .ja va  2 s. com
 */
public void post(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;
    }

    // setup the model: the selected assessment
    context.put("assessment", assessment);

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

    // if publish, set
    if ("PUBLISH".equals(destination)) {
        assessment.setPublished(Boolean.TRUE);
        destination = "/assessments/" + sort;
    }

    // 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;
    }

    // if destination became null
    if (destination == null) {
        destination = context.getDestination();
    }

    // if destination is stay here
    else if (destination.startsWith("STAY:")) {
        String[] parts = StringUtil.splitFirst(destination, ":");
        destination = context.getDestination() + "?focus=" + parts[1];
    }

    // redirect to the next destination
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

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

/**
 * {@inheritDoc}//from  w ww.  j  a v a2  s  .c  o m
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (sid/quesiton selector)
    if (params.length != 3) {
        throw new IllegalArgumentException();
    }

    // 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;
    }

    String submissionId = params[2];

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

From source file:org.wso2.carbon.identity.authenticator.InweboAuthenticator.java

/**
 * initiate the authentication request/* ww w.j  a  va2s .  c  om*/
 */
@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {
    String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL();
    loginPage = loginPage.replace(InweboConstants.INWEBO_LOGINPAGE, InweboConstants.INWEBO_PAGE);
    try {
        String retryParam = "";
        if (context.isRetrying()) {
            retryParam = InweboConstants.RETRY_PARAM;
        }
        response.sendRedirect(response.encodeRedirectURL(loginPage + "?" + FrameworkConstants.SESSION_DATA_KEY
                + "=" + context.getContextIdentifier() + retryParam));
    } catch (IOException e) {
        throw new AuthenticationFailedException("Error while redirecting", e);
    }
}

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

/**
 * {@inheritDoc}// w  w w. java  2 s.  c om
 */
public void get(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;
    }

    // not for formal course evaluation
    if (assessment.getFormalCourseEval()) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // make sure any undefined user ids or users without permissions are removed
    assessment.getSpecialAccess().assureValidUsers();

    // collect information: the selected assessment
    context.put("assessment", assessment);
    context.put("sort", sort);

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

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

/**
 * {@inheritDoc}/*ww w  .  j  a  v a  2s. c  o  m*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need an aid, then any number of parameters to form the return destination
    if (params.length < 2) {
        throw new IllegalArgumentException();
    }

    // read form
    String destination = uiService.decode(req, context);
    StringBuffer buf = new StringBuffer();
    buf.append(destination);
    buf.append("/" + req.getParameter("printformat"));
    destination = buf.toString();

    // go there!
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

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

/**
 * {@inheritDoc}/*from   w  w w.  ja  v a  2s  .  c o  m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (submissionId, partId)
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }

    String submissionId = params[2];
    String partId = params[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;
    }

    // make sure by-question is valid for this assessment
    if (submission.getAssessment().getQuestionGrouping() != QuestionGrouping.question) {
        // 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;
    }

    // collect the part
    Part part = submission.getAssessment().getParts().getPart(partId);
    if (part == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    context.put("submission", submission);
    context.put("part", part);

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

/**
 * {@inheritDoc}//from   ww w . j  ava2s.c o m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    if (params.length < 5) {
        throw new IllegalArgumentException();
    }

    Assessment assessment = (Assessment) assessmentService
            .newEmptyAssessment(this.toolManager.getCurrentPlacement().getContext());
    if (assessment == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    // collect information: the selected assessment
    context.put("assessment", assessment);

    // check if we have gradebook
    context.put("gradebookAvailable", this.gradesService.available(assessment.getContext()));

    // we carry sort and assmtIds for the /tests mode
    String sort = "";
    String assmtIds = "";
    String choiceSettings = "";
    if (params.length == 5) {
        sort = params[2];
        assmtIds = params[3];
        choiceSettings = params[4];
    }
    context.put("sort", sort);
    context.put("assmtIds", assmtIds);

    String chSets[] = StringUtil.split(choiceSettings, "+");
    //This sets the included values
    for (String chSet : chSets) {
        context.put(chSet, chSet);
    }

    // if we have a focus parameter
    String focus = req.getParameter("focus");
    if (focus != null)
        context.addFocusId(focus);
    new CKSetup().setCKCollectionAttrib(getDocsPath(), toolManager.getCurrentPlacement().getContext());

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