Example usage for org.springframework.web.context.request WebRequest getParameterNames

List of usage examples for org.springframework.web.context.request WebRequest getParameterNames

Introduction

In this page you can find the example usage for org.springframework.web.context.request WebRequest getParameterNames.

Prototype

Iterator<String> getParameterNames();

Source Link

Document

Return a Iterator over request parameter names.

Usage

From source file:ch.silviowangler.dox.web.ImportController.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "performImport.html")
public ResponseEntity<String> importDocument(MultipartFile file, WebRequest request,
        @RequestParam("x_client") String client) {

    try {/* ww w  .j  a  va 2  s  .c om*/
        DocumentClass documentClass = new DocumentClass(request.getParameter(DOCUMENT_CLASS_SHORT_NAME));

        Iterator<String> params = request.getParameterNames();
        Map<TranslatableKey, DescriptiveIndex> indices = newHashMap();

        while (params.hasNext()) {
            String param = params.next();
            if (!DOCUMENT_CLASS_SHORT_NAME.endsWith(param) && !param.startsWith("x_")) {
                indices.put(new TranslatableKey(param), new DescriptiveIndex(
                        new String(request.getParameter(param).getBytes("iso-8859-1"), "utf-8")));
            }
        }

        PhysicalDocument physicalDocument = new PhysicalDocument(documentClass, file.getBytes(), indices,
                file.getOriginalFilename());
        physicalDocument.setClient(client);

        DocumentReference documentReference = documentService.importDocument(physicalDocument);

        logger.info("Successfully imported file {}. Id = {}", file.getOriginalFilename(),
                documentReference.getHash());
        return new ResponseEntity(CREATED);

    } catch (ValidationException | IOException | DocumentClassNotFoundException e) {
        logger.error("Unable to import document", e);
        return new ResponseEntity(e.getMessage(), CONFLICT);
    } catch (DocumentDuplicationException e) {
        logger.error("Unable to import document. Duplicate document detected", e);
        return new ResponseEntity(e.getMessage(), CONFLICT);
    }
}

From source file:cz.strmik.cmmitool.web.controller.EvidenceController.java

@RequestMapping(method = RequestMethod.POST, value = "/link.do")
public String linkEvidence(@ModelAttribute(Attribute.EVIDENCE) Evidence evidence, ModelMap modelMap,
        HttpSession session, WebRequest request) {
    Iterator<String> it = request.getParameterNames();
    Map<Practice, Set<ProcessInstantiation>> pis = new HashMap<Practice, Set<ProcessInstantiation>>();
    while (it.hasNext()) {
        String param = it.next();
        if (!param.matches("^practice-\\d+?,inst-\\d+$")) {
            log.debug("skipping parameter " + param);
            continue;
        }/*from   w w w .  j a v  a  2s. c  om*/
        String[] params = param.split(",");
        Long id = Long.parseLong(params[0].substring(9));
        Practice practice = practiceDao.read(id);
        if (!pis.containsKey(practice)) {
            pis.put(practice, new HashSet<ProcessInstantiation>());
        }
        id = Long.parseLong(params[1].substring(5));
        ProcessInstantiation pi = processInstantiationDao.read(id);
        pis.get(practice).add(pi);
    }
    evidenceService.linkEvidenceToPractices(evidence, pis);
    return "redirect:/appraisal/evidence/";
}

From source file:uk.co.grahamcox.yui.YuiController.java

/**
 * Perform the combo request for a set of modules
 * @param group the group to request/*from w  ww  .  j  a v  a  2  s  . c o m*/
 * @param webRequest the means to get the module list
 * @param response the response to write to
 * @throws IOException if an error occurs
 */
@RequestMapping("/combo/{group}")
public void getComboModules(@PathVariable("group") String group, WebRequest webRequest,
        HttpServletResponse response) throws IOException {
    Iterator<String> names = webRequest.getParameterNames();
    boolean missing = false;
    while (names.hasNext()) {
        String next = names.next();
        Matcher matcher = COMBO_MODULE_PATTERN.matcher(next);
        if (matcher.matches()) {
            String moduleName = matcher.group(1);
            Filter filter = Filter.RAW;
            if (matcher.group(3) != null) {
                switch (matcher.group(3)) {
                case "debug":
                    filter = Filter.DEBUG;
                    break;
                case "min":
                    filter = Filter.MINIFY;
                    break;
                }
            }
            getModule(group, moduleName, filter, response);
        } else {
            matcher = COMBO_LANGUAGE_PATTERN.matcher(next);
            if (matcher.matches()) {
                String moduleName = matcher.group(1);
                String language = matcher.group(3);
                Filter filter = Filter.RAW;
                if (matcher.group(5) != null) {
                    switch (matcher.group(5)) {
                    case "debug":
                        filter = Filter.DEBUG;
                        break;
                    case "min":
                        filter = Filter.MINIFY;
                        break;
                    }
                }
                getModuleLanguage(group, moduleName, language, filter, response);
            } else {
                missing = true;
            }
        }
    }
    if (missing) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid modules were requested");
    }
}

From source file:cz.strmik.cmmitool.web.controller.EvidenceController.java

@RequestMapping(method = RequestMethod.POST, value = "/characterize.do")
public String characterizeEvidenceSave(@ModelAttribute(Attribute.PROJECT) Project project, ModelMap modelMap,
        HttpSession session, WebRequest request) {
    project = projectDao.read(project.getId());
    checkIsAudior(project);//w ww . j  a v a2s  .com
    Iterator<String> it = request.getParameterNames();
    while (it.hasNext()) {
        String param = it.next();
        String value = request.getParameter(param);
        if (log.isDebugEnabled()) {
            log.debug("Read parameter: " + param + " = " + value);
        }
        if (param.matches("^practice-char-\\d+?-\\d+$")) {
            setPracticeChar(param, value, project);
        } else if (param.matches("^practice-adequacy-\\d+?-\\d+$")) {
            setPracticeAdequacy(param, value, project);
        } else if (param.matches("^evidence-char-\\d+#\\d+#\\d+$")) {
            setEvidenceChar(param, value, project);
        } else if (param.matches("^evidence-ind-\\d+#\\d+#\\d+$")) {
            setEvidenceInd(param, value, project);
        } else {
            log.debug("skipping parameter " + param);
        }
    }
    projectDao.update(project);
    return "redirect:/appraisal/evidence/";
}

From source file:org.springframework.amqp.rabbit.stocks.web.EnvironmentController.java

/**
 * Use this endpoint to refresh the cron trigger that is used to send market data to the broker. It builds a refresh
 * request and sends it to the broker using the AMQP template provided.
 * //from ww w .  jav a2  s.c om
 * @param bean a bean id
 * @return a refresh request object (as information for the caller)
 * 
 * @see #handleRefresh(RefreshRequest) a handler for the request generated here
 */
@RequestMapping(value = "/refresh/{bean}", method = RequestMethod.POST)
@ResponseBody
public RefreshRequest refresh(@PathVariable String bean, WebRequest webRequest) {
    RefreshRequest request = new RefreshRequest();
    Properties updates = new Properties();
    Properties oldValues = new Properties();
    for (Iterator<String> keys = webRequest.getParameterNames(); keys.hasNext();) {
        String key = keys.next();
        updates.setProperty(key, webRequest.getParameter(key));
        String value = environmentProperties.getProperty(key);
        if (value != null) {
            oldValues.setProperty(key, value);
        }
    }
    request.setUpdates(updates);
    request.setOldValues(oldValues);
    request.setBeanName(bean);
    if (amqpTemplate != null) {
        amqpTemplate.convertAndSend(request);
    }
    return request;
}