Example usage for org.springframework.web.servlet.view RedirectView setUrl

List of usage examples for org.springframework.web.servlet.view RedirectView setUrl

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view RedirectView setUrl.

Prototype

public void setUrl(@Nullable String url) 

Source Link

Document

Set the URL of the resource that this view wraps.

Usage

From source file:ru.mystamps.web.controller.AccountController.java

@GetMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY)
public View showActivationFormWithKey(@PathVariable("key") String activationKey,
        RedirectAttributes redirectAttributes) {

    redirectAttributes.addAttribute("key", activationKey);

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.ACTIVATE_ACCOUNT_PAGE);

    return view;/*w w  w .  ja va 2 s.  co  m*/
}

From source file:ru.mystamps.web.controller.CategoryController.java

@GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE)
public View showInfoById(@Category @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }//  ww w .j  a v  a2  s.c om

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_CATEGORY_PAGE);

    return view;
}

From source file:ru.mystamps.web.controller.CollectionController.java

@GetMapping(Url.INFO_COLLECTION_BY_ID_PAGE)
public View showInfoById(@PathVariable("slug") String slug, HttpServletResponse response) throws IOException {

    if (slug == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }//  ww w.  j av a  2 s  .com

    CollectionInfoDto collection = collectionService.findBySlug(slug);
    if (collection == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_COLLECTION_PAGE);

    return view;
}

From source file:ru.mystamps.web.controller.CountryController.java

/**
 * @author Aleksander Parkhomenko//from   w w  w.j  a v a2  s.c  om
 */
@GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE)
public View showInfoById(@Country @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_COUNTRY_PAGE);

    return view;
}

From source file:org.zilverline.web.CacheController.java

/**
 * Handles form submission by extracting the corresponding archive.
 * /*  w w  w .j  a va 2 s . c o  m*/
 * @param command the DocumentFromCacheForm, containing document information.
 * 
 * @return ModelAndView the view with updated model
 * 
 * @throws ServletException on error
 */
public ModelAndView onSubmit(Object command) throws ServletException {
    DocumentFromCacheForm df = (DocumentFromCacheForm) command;
    String colName = df.getCollection();

    log.debug("CacheController for " + colName);

    FileSystemCollection thisCollection = (FileSystemCollection) collectionManager.getCollectionByName(colName);
    boolean canForward = false;

    try {
        if (thisCollection != null) {
            if (!thisCollection.getArchiveCache().contains(df.getArchive())) {
                // not already in cache for this collection
                log.debug("CacheController cache miss for " + colName);

                // but the file might be there from a previous time, before
                // possible restart
                File f = new File(thisCollection.getCacheDirWithManagerDefaults(), df.getFile());

                if (f.exists()) {
                    log.debug("CacheController cache from previous life for " + f);
                    canForward = true;

                    // the file must be from archive, add the zip to the
                    // cache, without having extracted it.
                    // this is a risk, since the some files from the archive
                    // in cache may have been deleted
                    thisCollection.getArchiveCache().add(df.getArchive());
                } else {
                    File zipFile = new File(thisCollection.getContentDir(), df.getArchive());

                    if (collectionManager.expandArchive(thisCollection, zipFile)) {
                        thisCollection.getArchiveCache().add(df.getArchive());
                        canForward = true;
                    } else {
                        log.debug("CacheController can't get file from archive for: " + zipFile);
                    }
                }
            } else {
                log.debug("CacheController cache hit for " + colName);
                canForward = true;
            }
        } else {
            log.error("no valid collection");
        }
    } catch (IndexException e) {
        throw new ServletException(e);
    }

    if (canForward) {
        // the archive has been extracted, redirect to file
        log.debug("redirecting from CacheController to:  " + thisCollection.getCacheUrlWithManagerDefaults()
                + df.getFile());

        RedirectView v = new RedirectView();

        v.setUrl(thisCollection.getCacheUrlWithManagerDefaults() + df.getFile());

        return new ModelAndView(v);
    }

    log.debug("returning from CacheController to view:  " + getSuccessView() + " with " + colName);

    return new ModelAndView(getSuccessView(), "document", df);
}

From source file:de.interseroh.report.controller.ReportController.java

private void showReportForm(@PathVariable("reportName") String reportName,
        @ModelAttribute("parameterForm") ParameterForm form, ModelAndView modelAndView) {
    RedirectView redirectView = new RedirectView();
    redirectView.setUrl("/reports/{reportName}");
    redirectView.setContextRelative(true);
    redirectView.setPropagateQueryParams(false);
    redirectView.setExposeModelAttributes(true);
    modelAndView.addAllObjects(new ParameterValueMapBuilder().build(form));
    modelAndView.addObject("reportName", reportName);
    modelAndView.setView(redirectView);/*from w  ww .  j ava 2s.  c om*/
}

From source file:org.shareok.data.webserv.RestDspaceDataController.java

@RequestMapping(value = "/rest/{repoTypeStr}/{jobType}", method = RequestMethod.POST)
public ModelAndView sshDspaceSaFImporter(HttpServletRequest request, RedirectAttributes redirectAttrs,
        @PathVariable("repoTypeStr") String repoTypeStr,
        @RequestParam(value = "localFile", required = false) MultipartFile file,
        @PathVariable("jobType") String jobType, @ModelAttribute("SpringWeb") DspaceApiJob job) {
    ModelAndView model = new ModelAndView();

    String filePath = "";

    logger.debug("Start to process the DSpace Rest API request...");

    try {/*from ww  w. ja  v  a  2s  . co  m*/
        if (null == file || file.isEmpty()) {
            String localFile = (String) request.getParameter("localFile");
            if (!DocumentProcessorUtil.isEmptyString(localFile)) {
                filePath = localFile;
                String safDir = (String) request.getParameter("localSafDir");
                if (!DocumentProcessorUtil.isEmptyString(safDir)) {
                    filePath = safDir + File.separator + filePath;
                }
                String folder = (String) request.getParameter("localFolder");
                if (!DocumentProcessorUtil.isEmptyString(folder)) {
                    filePath = folder + File.separator + filePath;
                }
                String journalSearch = (String) request.getParameter("journalSearch");
                if (null != journalSearch && journalSearch.equals("1")) {
                    filePath = ShareokdataManager.getDspaceUploadPath() + File.separator + filePath;
                } else {
                    filePath = ShareokdataManager.getOuhistoryUploadPath() + File.separator + filePath;
                }
            } else {
                filePath = (String) request.getParameter("remoteFileUri");
            }
        } else {
            filePath = ServiceUtil.saveUploadedFile(file,
                    ShareokdataManager.getDspaceRestImportPath(jobType + "-" + repoTypeStr));
        }
    } catch (Exception ex) {
        logger.error("Cannot upload the file for DSpace import using REST API.", ex);
        model.addObject("errorMessage", "Cannot get the server list");
        model.setViewName("serverError");
        return model;
    }

    DspaceRepoServer server = (DspaceRepoServer) serverService.findServerById(job.getServerId());
    String userId = String.valueOf(request.getSession().getAttribute("userId"));
    job.setUserId(Long.valueOf(userId));
    job.setCollectionId(server.getPrefix() + "/" + job.getCollectionId());
    job.setRepoType(DataUtil.getRepoTypeIndex(repoTypeStr));
    job.setType(DataUtil.getJobTypeIndex(jobType, repoTypeStr));
    job.setStatus(Arrays.asList(RedisUtil.REDIS_JOB_STATUS).indexOf("created"));
    job.setFilePath(filePath);
    job.setStartTime(new Date());
    job.setEndTime(null);

    try {
        RedisJob returnedJob = taskManager.execute(job);

        if (null == returnedJob) {
            throw new JobProcessingException("Null job object returned after processing!");
        }

        int statusIndex = job.getStatus();
        String isFinished = (statusIndex == 2 || statusIndex == 6) ? "true" : "false";

        RedirectView view = new RedirectView();
        view.setContextRelative(true);
        view.setUrl("/report/job/" + String.valueOf(returnedJob.getJobId()));
        model.setView(view);
        redirectAttrs.addFlashAttribute("host",
                serverService.findServerById(returnedJob.getServerId()).getHost());
        redirectAttrs.addFlashAttribute("collection",
                DspaceDataUtil.DSPACE_REPOSITORY_HANDLER_ID_PREFIX + job.getCollectionId());
        redirectAttrs.addFlashAttribute("isFinished", isFinished);
        redirectAttrs.addFlashAttribute("reportPath", DataHandlersUtil
                .getJobReportFilePath(DataUtil.JOB_TYPES[returnedJob.getType()], returnedJob.getJobId()));
        WebUtil.outputJobInfoToModel(redirectAttrs, returnedJob);
    } catch (Exception ex) {
        logger.error("Cannot process the job of DSpace import using REST API.", ex);
        model.addObject("errorMessage", "Cannot process the job of DSpace import using REST API.");
        model.setViewName("serverError");
    }
    return model;
}

From source file:ru.org.linux.tracker.TrackerController.java

@RequestMapping("/tracker.jsp")
public View trackerOldUrl(@RequestParam(value = "filter", defaultValue = "all") String filterAction)
        throws UnsupportedEncodingException {
    RedirectView redirectView = new RedirectView("/tracker/");

    redirectView.setExposeModelAttributes(false);

    if (filterValues.contains(filterAction) && !filterAction.equals("all")) {
        redirectView.setUrl("/tracker/?filter=" + URLEncoder.encode(filterAction, "UTF-8"));
    }//from ww  w  . j  a  v  a  2  s. co m

    return redirectView;
}

From source file:de.interseroh.report.controller.ReportController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView showReportForm(
        ///*from  ww w .  java2s .  co  m*/
        @ModelAttribute ParameterForm parameterForm, //
        @RequestParam MultiValueMap<String, String> requestParams,
        @PathVariable("reportName") String reportName, BindingResult errors) throws BirtReportException {

    logger.debug("executing show report for " + reportName);

    checkPermisionFor(reportName);

    ModelAndView modelAndView = new ModelAndView();

    parameterFormBinder.bind(parameterForm, requestParams, errors);
    parameterFormConverter.convert(parameterForm, errors);

    if (parameterForm.isValid()) {
        Pagination pagination = reportService.getPageInfos(reportName, parameterForm);

        // TODO reportPage
        // if (reportPage.getCurrentPageNumber() > reportPage
        // .getPageNumbers()) {
        // throw new BirtReportException(String.format(
        // "For this report: %s no more pages available",
        // reportName));
        // }
        modelAndView.addObject("pagination", pagination);
        modelAndView.setViewName("/report");
        injectReportUri(parameterForm, modelAndView, reportName);
        configSetter.setVersion(modelAndView);
        configSetter.setBranding(modelAndView);
    } else {
        // show parameters
        RedirectView redirectView = new RedirectView();
        redirectView.setUrl("/reports/{reportName}/params");
        redirectView.setContextRelative(true);
        redirectView.setPropagateQueryParams(false);
        redirectView.setExposeModelAttributes(true);
        modelAndView.setView(redirectView);
        modelAndView.addAllObjects(new ParameterValueMapBuilder().build(parameterForm));
    }

    parameterFormFormatter.format(parameterForm);
    modelAndView.addObject("reportName", reportName);

    return modelAndView;
}

From source file:de.drv.dsrv.utility.spring.web.EnhancedRedirectInternalResourceViewResolver.java

protected View checkAndEnhanceRedirectView(final View view) {
    // Prfe, ob die ber die Basisklasse ermittelte View einen Redirect
    // reprsentiert
    if (view instanceof RedirectView) {
        // Fhre Typumwandlung durch und ermittle gespeicherte URL
        final RedirectView redirectView = (RedirectView) view;
        final String url = redirectView.getUrl();

        // Prfe, ob die gespeicherte URL den Prfix fr eine Pfadangabe
        // relativ zur Basis-URI des Servers ist
        if (url != null && url.startsWith(SERVER_REL_PREFIX)) {
            // Entferne Prfix
            redirectView.setUrl(url.substring(SERVER_REL_PREFIX.length()));

            // URL ist nicht reletiv zur Context Root
            redirectView.setContextRelative(false);
        }/*from   w  ww  .  ja v a2  s .  c  om*/
    }

    // Gebe View zurck
    return view;
}