Example usage for org.springframework.web.util WebUtils hasSubmitParameter

List of usage examples for org.springframework.web.util WebUtils hasSubmitParameter

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils hasSubmitParameter.

Prototype

public static boolean hasSubmitParameter(ServletRequest request, String name) 

Source Link

Document

Check if a specific input type="submit" parameter was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y").

Usage

From source file:morph.plugin.views.annotation.ServletAnnotationMappingUtils.java

/**
 * Check whether the given request matches the specified parameter conditions.
 * @param params  the parameter conditions, following
 *                {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()}
 * @param request the current HTTP request to check
 *///  ww w  . ja va 2 s  . c  o m
public static boolean checkParameters(String[] params, HttpServletRequest request) {
    if (!ObjectUtils.isEmpty(params)) {
        for (String param : params) {
            int separator = param.indexOf('=');
            if (separator == -1) {
                if (param.startsWith("!")) {
                    if (WebUtils.hasSubmitParameter(request, param.substring(1))) {
                        return false;
                    }
                } else if (!WebUtils.hasSubmitParameter(request, param)) {
                    return false;
                }
            } else {
                boolean negated = separator > 0 && param.charAt(separator - 1) == '!';
                String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1);
                String value = param.substring(separator + 1);
                if (!value.equals(request.getParameter(key))) {
                    return negated;
                }
            }
        }
    }
    return true;
}

From source file:com.icl.integrator.util.patch.ServletAnnotationMappingUtils.java

/**
 * Check whether the given request matches the specified parameter conditions.
 * @param params  the parameter conditions, following
 * {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()}
 * @param request the current HTTP request to check
 *//*w  ww. j  av a2  s. c  om*/
public static boolean checkParameters(String[] params, HttpServletRequest request) {
    if (!ObjectUtils.isEmpty(params)) {
        for (String param : params) {
            int separator = param.indexOf('=');
            if (separator == -1) {
                if (param.startsWith("!")) {
                    if (WebUtils.hasSubmitParameter(request, param.substring(1))) {
                        return false;
                    }
                } else if (!WebUtils.hasSubmitParameter(request, param)) {
                    return false;
                }
            } else {
                boolean negated = separator > 0 && param.charAt(separator - 1) == '!';
                String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1);
                String value = param.substring(separator + 1);
                boolean match = value.equals(request.getParameter(key));
                if (negated) {
                    match = !match;
                }
                if (!match) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:gov.nih.nci.cabig.caaers.web.admin.AgentEditController.java

@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
    super.formBackingObject(request);

    Agent agent = null;/*from   w  w  w  .j  a  v a 2  s.co m*/
    agent = agentRepository.getAgentByID(Integer.parseInt(request.getParameter("agentID")));

    AgentCommand c = new AgentCommand();
    c.setAgent(agent);
    c.setAgentSpecificTerms(new ArrayList<AgentSpecificTerm>());
    List<AgentSpecificTerm> agentSpecificTerms = new ArrayList<AgentSpecificTerm>();
    agentSpecificTerms = service.getListByAgent(agent.getId());
    Collections.sort(agentSpecificTerms, new AgentSpecificTermSorter());
    c.getAgentSpecificTerms().addAll(agentSpecificTerms);
    c.takeExpectednessSnapshot();

    // need to determine the category of the first element in the previous list
    if (c.getAgentSpecificTerms().size() > 0) {
        AgentSpecificTerm at = c.getAgentSpecificTerms().get(0);
        if (at instanceof AgentSpecificCtcTerm) {
            AgentSpecificCtcTerm t = (AgentSpecificCtcTerm) at;
            c.setTerminology(Term.CTC);
            c.setCtcVersion(ctcDao.getById(t.getTerm().getCategory().getCtc().getId()));
            // c.setMeddraVersion(meddraVersionDao.getById(10));
        } else {
            AgentSpecificMeddraLowLevelTerm t = (AgentSpecificMeddraLowLevelTerm) at;
            c.setTerminology(Term.MEDDRA);
            c.setMeddraVersion(meddraVersionDao.getById(t.getTerm().getMeddraVersion().getId()));
        }
    } else if (WebUtils.hasSubmitParameter(request, "terminologyName")) {
        c.setTerminology(Term.valueOf(request.getParameter("terminologyName")));
        c.setCtcVersion(ctcDao.getById(Integer.parseInt(request.getParameter("terminologyId"))));
    }

    if (WebUtils.hasSubmitParameter(request, "showSuccessMessage")) {
        request.setAttribute("flashMessage", "Information saved successfully");
    }

    return c;
}

From source file:edu.duke.cabig.c3pr.web.SearchParticipantController.java

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object oCommand,
        BindException errors) throws Exception {
    SearchCommand searchParticipantCommand = (SearchCommand) oCommand;
    Participant participant = new Participant();
    String text = searchParticipantCommand.getSearchText().trim();
    String type = searchParticipantCommand.getSearchType();
    Map<String, List<Lov>> configMap = configurationProperty.getMap();

    log.debug("search string = " + text + "; type = " + type);

    if ("N".equals(type)) {
        participant.setLastName(text);//from  w w  w  .j  a  v a 2 s .  co  m
    }
    if ("F".equals(type)) {
        participant.setFirstName(text);
    }
    if ("Identifier".equals(type)) {
        SystemAssignedIdentifier identifier = new SystemAssignedIdentifier();
        identifier.setValue(text);
        // FIXME:
        participant.addIdentifier(identifier);
    }

    List<Participant> participants = participantDao.searchByExample(participant);
    Set<Participant> participantSet = new TreeSet<Participant>();
    participantSet.addAll(participants);
    List<Participant> uniqueParticipants = new ArrayList<Participant>();
    uniqueParticipants.addAll(participantSet);
    Iterator<Participant> participantIter = participants.iterator();
    log.debug("Search results size " + uniqueParticipants.size());
    Map map = errors.getModel();
    map.put("participants", uniqueParticipants);
    map.put("searchTypeRefData", configMap.get("participantSearchType"));
    if (WebUtils.hasSubmitParameter(request, "async")) {
        return new ModelAndView("/registration/subjectResultsAsync", map);
    }
    ModelAndView modelAndView = new ModelAndView(getSuccessView(), map);
    return modelAndView;
}

From source file:edu.duke.cabig.c3pr.web.study.EditStudyController.java

@Override
protected boolean shouldPersist(HttpServletRequest request, StudyWrapper command, Tab<StudyWrapper> tab) {
    boolean shouldSave = super.shouldSave(request, command, tab)
            && StringUtils.isBlank(request.getParameter("_action"));
    if (WebUtils.hasSubmitParameter(request, DO_NOT_SAVE)
            && StringUtils.equals(request.getParameter(DO_NOT_SAVE), "true")) {
        shouldSave = false;/*w  w  w .  j a  va  2  s  .  c om*/
    }
    return shouldSave;
}

From source file:gov.nih.nci.cabig.caaers.web.filters.CsrfPreventionFilter.java

protected String getCSRFToken(HttpServletRequest request) {
    if (WebUtils.hasSubmitParameter(request, CSRF_TOKEN)) {
        return request.getParameter(CSRF_TOKEN);
    }/*w w w.  j  a  va 2 s .  com*/
    if (!StringUtils.isEmpty(request.getHeader(CSRF_TOKEN_HEADER))) {
        return request.getHeader(CSRF_TOKEN_HEADER);
    }
    //process multipart form for imports
    /*try {
    List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
    for (FileItem item : items) {
        if (item.isFormField()) {
            // Process regular form field (input type="text|radio|checkbox|etc", select, etc).
            if(item.getFieldName().equals(CSRF_TOKEN)){
               return item.getString();
            }
        } 
    }
     } catch (FileUploadException e) {
        // this might mean the request is not multipart
    // do nothing let the process flow continue
     } */

    return null;
}

From source file:edu.duke.cabig.c3pr.web.ViewParticipantController.java

@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
    ParticipantWrapper participantWrapper = new ParticipantWrapper();
    Participant participant = null;//ww  w  .ja  v a 2 s  .  co m
    List<Participant> participants = new ArrayList<Participant>();

    if (WebUtils.hasSubmitParameter(request, ControllerTools.IDENTIFIER_VALUE_PARAM_NAME)) {
        Identifier identifier = ControllerTools.getIdentifierInRequest(request);
        List<Identifier> identifiers = new ArrayList<Identifier>();
        identifiers.add(identifier);
        participant = participantRepository.getUniqueParticipant(identifiers);
    } else {
        String name = null;
        if (request.getParameter("systemName") != null) {
            name = request.getParameter("systemName");
        } else if (request.getParameter("organizationNciId") != null) {
            name = request.getParameter("organizationNciId");
        }
        String type = null;
        if (request.getParameter("identifierType") != null) {
            type = request.getParameter("identifierType");
        } else {
            request.setAttribute("identifierTypeRequired", "identifierTypeRequired");
        }

        String value = null;
        if (request.getParameter("identifier") != null) {
            value = request.getParameter("identifier");
        } else {
            request.setAttribute("identifierRequired", "identifierRequired");
        }

        if (request.getParameter("assignedBy") != null) {
            String assignedBy = request.getParameter("assignedBy");
            if (request.getParameter("identifierType") != null && request.getParameter("identifier") != null) {
                if (assignedBy.equals("system")) {
                    if (request.getParameter("systemName") != null) {
                        SystemAssignedIdentifier sysIdentifier = new SystemAssignedIdentifier();
                        sysIdentifier.setSystemName(name);
                        sysIdentifier.setType(type);
                        sysIdentifier.setValue(value);

                        participants = participantDao.searchBySystemAssignedIdentifier(sysIdentifier);
                        if (participants.size() < 1) {
                            request.setAttribute("noParticipant", "noParticipant");
                            return new Participant();
                        } else {
                            return participants.get(0);
                        }
                    } else {
                        request.setAttribute("systemNameRequired", "systemNameRequired");
                    }

                } else if (assignedBy.equals("organization")) {
                    if (request.getParameter("organizationNciId") != null) {
                        OrganizationAssignedIdentifier orgIdentifier = new OrganizationAssignedIdentifier();
                        HealthcareSite healthcareSite = healthcareSiteDao.getByPrimaryIdentifier(name);
                        orgIdentifier.setHealthcareSite(healthcareSite);
                        orgIdentifier.setType(
                                OrganizationAssignedIdentifier.getOrganizationIdentifierEnumByCode(type));
                        orgIdentifier.setValue(value);

                        participants = participantDao.searchByOrgIdentifier(orgIdentifier);
                        if (participants.size() < 1) {
                            request.setAttribute("noParticipant", "noParticipant");
                            return new Participant();
                        } else {
                            return participants.get(0);
                        }
                    } else {
                        request.setAttribute("organizationNciIdRequired", "organizationNciIdRequired");
                    }
                } else {
                    request.setAttribute("assignedByValueRequired", "assignedByValueRequired");
                    return new Participant();
                }
            }
        } else {
            request.setAttribute("assignedByRequired", "assignedByRequired");
        }
    }
    if (participant != null) {
        participantDao.initialize(participant);
    } else {
        participant = new Participant();
    }
    participantWrapper.setParticipant(participant);
    return participantWrapper;
}

From source file:edu.duke.cabig.c3pr.web.EditParticipantController.java

@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
    ParticipantWrapper participantWrapper = new ParticipantWrapper();
    Participant participant = null;/*  ww  w  . j a  v a  2 s  .  co  m*/

    if (WebUtils.hasSubmitParameter(request, ControllerTools.IDENTIFIER_VALUE_PARAM_NAME)) {
        Identifier identifier = ControllerTools.getIdentifierInRequest(request);
        List<Identifier> identifiers = new ArrayList<Identifier>();
        identifiers.add(identifier);
        participant = participantRepository.getUniqueParticipant(identifiers);
        participantDao.initialize(participant);
        log.debug(" Participant's ID is:" + participant.getId());
    } else {
        participant = new Participant();
    }
    participantWrapper.setParticipant(participant);
    return participantWrapper;
}

From source file:edu.duke.cabig.c3pr.web.admin.CreateNotificationController.java

protected Object formBackingObject(HttpServletRequest request) throws Exception {
    NotificationWrapper wrapper = new NotificationWrapper();
    gov.nih.nci.security.authorization.domainobjects.User user = (gov.nih.nci.security.authorization.domainobjects.User) request
            .getSession().getAttribute("userObject");
    try {//w ww .j av  a  2s  .  c  o  m
        if (WebUtils.hasSubmitParameter(request, "organization")) {
            HealthcareSite healthcareSite = healthcareSiteDao
                    .getById(Integer.parseInt(request.getParameter("organization")));
            wrapper.setHealthcareSite(healthcareSite);
        } else {
            //get the logged in users site.If the logged in user is not yet associated to a site then get the hosting site.
            PersonUser personUser = (PersonUser) userDao.getByLoginId(user.getUserId().longValue());
            if (personUser.getHealthcareSites().size() > 0) {
                wrapper.setHealthcareSite(personUser.getHealthcareSites().get(0));
            } else {
                log.debug(
                        "Logged in User is not associated to a site, so getting the hosting site organization");
                String localNciCode = this.configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE);
                HealthcareSite hcs = healthcareSiteDao.getByPrimaryIdentifier(localNciCode);
                wrapper.setHealthcareSite(hcs);
            }
        }
    } catch (C3PRNoSuchUserException e) {
        log.debug(e.getMessage());
        //if logged in user has no site(in future) get the hosting site.
        String localNciCode = this.configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE);
        HealthcareSite hcs = healthcareSiteDao.getByPrimaryIdentifier(localNciCode);
        wrapper.setHealthcareSite(hcs);
    }
    return wrapper;
}

From source file:de.ingrid.interfaces.csw.admin.EditTestSuiteHarvesterController.java

@RequestMapping(value = TEMPLATE_EDIT_HARVESTER, method = RequestMethod.POST)
public String step1Post(final HttpServletRequest request, final HttpSession session, final ModelMap modelMap,
        @ModelAttribute("harvester") final TestSuiteHarvesterCommandObject harvester, final Errors errors)
        throws Exception {

    if (WebUtils.hasSubmitParameter(request, "back")) {
        return "redirect:" + ManageHarvesterController.TEMPLATE_LIST_HARVESTER;
    }/*from   w  w w .  j  av a2  s  .  c om*/

    if (_validatorStep1.validate(errors).hasErrors()) {
        return "/edit_testsuite_harvester";
    }

    // transform to absolute path
    harvester.setWorkingDirectory((new File(harvester.getWorkingDirectory())).getAbsolutePath());
    RecordCacheConfiguration rcc = new RecordCacheConfiguration();
    rcc.setCachePath(new File(harvester.getWorkingDirectory(), "records").getAbsoluteFile());
    harvester.setCacheConfiguration(rcc);

    Configuration configuration = cProvider.getConfiguration();
    List<HarvesterConfiguration> hConfigs = configuration.getHarvesterConfigurations();
    hConfigs.set(harvester.getId(), (HarvesterConfiguration) harvester);
    if (log.isDebugEnabled()) {
        log.debug("Save configuration to: " + cProvider.getConfigurationFile());
    }
    cProvider.write(configuration);

    return "/edit_testsuite_harvester";

}