Example usage for javax.servlet.http HttpServletRequest getParameterValues

List of usage examples for javax.servlet.http HttpServletRequest getParameterValues

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:org.esgf.globusonline.GOFormView4Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request) {
    /* get model params here */
    String dataset_name = request.getParameter("id");
    String userCertificate = request.getParameter("usercertificate");
    String goUserName = request.getParameter("gousername");
    String target = request.getParameter("target");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");
    String[] endpointInfos = request.getParameterValues("endpointinfos");
    String endpoint = request.getParameter("endpointdropdown");
    String createdSrcEndpoint = null, createdDestEndpoint = null;

    //if this request comes via go form view 3, then obtain the request parameters for myproxy username
    String srcMyproxyUserName = request.getParameter("srcmyproxyuser");
    String srcMyproxyUserPass = request.getParameter("srcmyproxypass");
    String myProxyServerStr = request.getParameter("srcmyproxyserver");

    StringBuffer errorStatus = new StringBuffer("Steps leading up to the error are shown below:<br><br>");

    LOG.debug("GOFORMView4Controller got Certificate " + userCertificate);
    LOG.debug("GOFORMView4Controller got Target " + target);
    LOG.debug("GOFORMView4Controller got selected endpoint " + endpoint);
    LOG.debug("GOFORMView4Controller got Src Myproxy User " + srcMyproxyUserName);
    LOG.debug("GOFORMView4Controller got Src Myproxy Pass ******");
    LOG.debug("GOFORMView4Controller got Src Myproxy Server " + myProxyServerStr);

    System.out.println("GOFORMView4Controller got Certificate " + userCertificate);
    System.out.println("GOFORMView4Controller got Target " + target);
    System.out.println("GOFORMView4Controller got selected endpoint " + endpoint);
    System.out.println("GOFORMView4Controller got Src Myproxy User " + srcMyproxyUserName);
    System.out.println("GOFORMView4Controller got Src Myproxy Pass ******");
    System.out.println("GOFORMView4Controller got Src Myproxy Server " + myProxyServerStr);

    Map<String, Object> model = new HashMap<String, Object>();

    JGOTransfer transfer = new JGOTransfer(goUserName, userCertificate, userCertificate, CA_CERTIFICATE_FILE);
    transfer.setVerbose(true);//from   www.  ja  va  2  s  .  c o  m
    try {
        String newURL = null, goEP = null;
        String[] pieces = null;
        Vector<String> fileList = null;
        HashMap<String, String> sourceEpToGFTPMap = new HashMap<String, String>();
        HashMap<String, Vector<String>> sourceMap = new HashMap<String, Vector<String>>();

        transfer.initialize();

        // find the endpointInfo line that matches the endpoint the user selected
        String endpointInfo = Utils.getEndpointInfoFromEndpointStr(endpoint, endpointInfos);
        System.out.println("User selected endpoint that has the info: " + endpointInfo);
        LOG.debug("User selected endpoint that has the info: " + endpointInfo);

        boolean isGlobusConnect = endpointInfo.endsWith("true");

        // FIXME: Cache from previous time we called this?
        // or reconstruct from the other format of them that we have?
        Vector<EndpointInfo> goEndpointInfos = transfer.listEndpoints();

        // first pass, find all sources
        // we create a mapping of GO endpoints to Filelists

        for (String curURL : file_urls) {
            pieces = curURL.split("//");
            if ((pieces != null) && (pieces.length > 1)) {
                goEP = Utils.lookupGOEPBasedOnGridFTPURL(pieces[1], goEndpointInfos, true);
                if (goEP == null) {
                    goEP = Utils.lookupGOEPBasedOnGridFTPURL(pieces[1], goEndpointInfos, false);
                }

                if (!sourceMap.containsKey(goEP)) {
                    LOG.debug("Mapped GridFTP Server " + pieces[1] + " to GO EP " + goEP);
                    System.out.println("Mapped GridFTP Server " + pieces[1] + " to GO EP " + goEP);
                    sourceEpToGFTPMap.put(goEP, pieces[1]);
                    sourceMap.put(goEP, new Vector<String>());
                }

                fileList = sourceMap.get(goEP);
                newURL = "//" + pieces[2];

                LOG.debug("Transformed " + curURL + " into " + newURL);
                System.out.println("Transformed " + curURL + " into " + newURL);
                fileList.add(newURL);
            } else {
                LOG.debug("Failed to split URL on //: " + curURL);
                System.out.println("Failed to split URL on //: " + curURL);
            }
        }

        // For now we always just grab the first endpoint since we
        // can only handle a single source endpoint (per transfer)
        // ... break up into multiple transfers later when we
        // support transfers of multiple data sets at once
        Map.Entry<String, Vector<String>> entry = sourceMap.entrySet().iterator().next();
        String goSourceEndpoint = entry.getKey();
        Map.Entry<String, String> gftpEntry = sourceEpToGFTPMap.entrySet().iterator().next();
        String gftpServer = gftpEntry.getValue();

        System.out.println("Got GO Source EP: " + goSourceEndpoint);
        System.out.println("Got GFTP Server: " + gftpServer);
        if (goSourceEndpoint != null) {
            fileList = entry.getValue();
        } else {
            // create new endpoint using known information
            String srcEndpointInfo = "D^^" + gftpServer + "^^" + myProxyServerStr + "^^false";
            goSourceEndpoint = Utils.createGlobusOnlineEndpointFromEndpointInfo(transfer, goUserName,
                    srcEndpointInfo);
            createdSrcEndpoint = goSourceEndpoint;
        }

        LOG.debug("Using GO Source EP: " + goSourceEndpoint);
        System.out.println("Using GO Source EP: " + goSourceEndpoint);

        errorStatus.append("Source endpoint resolved as \"");
        errorStatus.append(goSourceEndpoint);
        errorStatus.append("\".<br>");

        // first activate the source endpoint
        LOG.debug("Activating source endpoint " + goSourceEndpoint);
        System.out.println("Activating source endpoint " + goSourceEndpoint);
        errorStatus.append("Attempting to activate Source Endpoint " + goSourceEndpoint + " ...<br>");
        try {
            // first try the activation as-is, with the 'original' myproxy info
            transfer.activateEndpoint(goSourceEndpoint, srcMyproxyUserName, srcMyproxyUserPass);
        } catch (Exception e) {
            // if that failed, manually override myproxy server to match user's
            // Create source endpoint matching first known Endpoint info
            LOG.debug("[*] Attempting newly created EP with MyProxy Server " + myProxyServerStr);
            System.out.println("[*] Attempting newly created EP with MyProxy Server " + myProxyServerStr);
            EndpointInfo info = goEndpointInfos.get(0);
            String srcEndpointInfo = info.getEPName() + "^^" + info.getHosts() + "^^" + myProxyServerStr + "^^"
                    + info.isGlobusConnect();
            goSourceEndpoint = Utils.createGlobusOnlineEndpointFromEndpointInfo(transfer, goUserName,
                    srcEndpointInfo);
            createdSrcEndpoint = goSourceEndpoint;

            LOG.debug("Activating source endpoint " + goSourceEndpoint);
            System.out.println("Activating source endpoint " + goSourceEndpoint);
            transfer.activateEndpoint(goSourceEndpoint, srcMyproxyUserName, srcMyproxyUserPass);
        }
        errorStatus.append("Source Endpoint activated properly!<br>");

        String[] endpointPieces = endpointInfo.split("\\^\\^");
        String destEPName = endpointPieces[0];

        // second, activate the target endpoint (special case GlobusConnect)
        if (isGlobusConnect == true) {
            LOG.debug("Detected Globus Connect target endpoint: " + destEPName);
            System.out.println("Detected Globus Connect target endpoint: " + destEPName);
            errorStatus.append("Detected Globus Connect target endpoint.<br>");
            errorStatus.append("Attempting to activate Destination Endpoint " + destEPName + " ...<br>");
            transfer.activateEndpoint(destEPName);
            errorStatus.append("Destination Endpoint activated properly!<br>");
        } else {
            // find if an existing endpoint exists in this user's namespace
            EndpointInfo destInfo = Utils.getLocalEndpointBasedOnGlobalName(goUserName, destEPName,
                    goEndpointInfos);
            if (destInfo == null) {
                destEPName = Utils.createGlobusOnlineEndpointFromEndpointInfo(transfer, goUserName,
                        endpointInfo);
                createdDestEndpoint = destEPName;
            } else {
                // if so, use it as the dest since it's presumably already configured
                destEPName = destInfo.getEPName();
            }

            LOG.debug("Activating destination endpoint " + destEPName);
            System.out.println("Activating destination endpoint " + destEPName);
            errorStatus.append("Attempting to activate Destination Endpoint " + destEPName + " ...<br>");
            transfer.activateEndpoint(destEPName, srcMyproxyUserName, srcMyproxyUserPass);
            errorStatus.append("Destination Endpoint activated properly!<br>");
        }

        // kick off the transfer here!
        errorStatus.append("Attempting to start Globus Online Transfer ...<br>");
        String taskID = transfer.transfer(goSourceEndpoint, destEPName, fileList, target);
        if (taskID != null) {
            errorStatus.append("Globus Online Transfer got TaskID " + taskID + ".<br>");
            String transferInfo1 = "The transfer has been accepted and a task has been "
                    + "created and queued for execution.";
            String transferInfo2 = "Globus Online TaskID: " + taskID;
            LOG.debug("Started Globus Online transfer with TaskID: " + taskID);

            if (request.getParameter(GOFORMVIEW_MODEL) != null) {
            } else {
                model.put(GOFORMVIEW_TRANSFER_INFO1, transferInfo1);
                model.put(GOFORMVIEW_TRANSFER_INFO2, transferInfo2);
            }
        } else {
            String error = errorStatus.toString() + "<br><b>Main Error:</b><br><br>Transfer failed";
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG, error);
            LOG.error("Failed to initiate Globus Online transfer.");
        }
    } catch (Exception e) {
        String error = errorStatus.toString() + "<br><b>Main Error:</b><br><br>" + e.toString();
        model.put(GOFORMVIEW_ERROR, "error");
        model.put(GOFORMVIEW_ERROR_MSG, error);
        LOG.error("Failed to initialize Globus Online: " + e);

        System.out.println("Trying to teardown created source endpoints ...");
        if (createdSrcEndpoint != null) {
            try {
                transfer.removeEndpoint(createdSrcEndpoint);
            } catch (Exception e1) {
            }
        }
        if (createdDestEndpoint != null) {
            try {
                transfer.removeEndpoint(createdDestEndpoint);
            } catch (Exception e2) {
            }
        }
        System.out.println("Attempted endpoint removal complete");
    }
    return new ModelAndView("goformview4", model);
}

From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java

private String getFullRequestURL(HttpServletRequest request) throws UnsupportedEncodingException {
    StringBuilder builder = new StringBuilder(request.getRequestURL());

    // For backwards compatibility; return query parameters in exact same sequence.
    if ("GET".equalsIgnoreCase(request.getMethod())) {
        if (request.getQueryString() != null) {
            builder.append("?").append(request.getQueryString());
        }/*from  w w w  . ja v a  2  s .  c o  m*/
        return builder.toString();
    }

    builder.append("?");

    Enumeration<?> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        String[] paramValues = request.getParameterValues(paramName);
        for (String paramValue : paramValues) {
            String p = URLEncoder.encode(paramValue, "UTF-8");
            builder.append(paramName).append("=").append(p).append("&");
        }
    }

    return builder.toString();
}

From source file:com.sun.faban.harness.webclient.ResultAction.java

String editAnalysis(String process, HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    EditAnalysisModel model = new EditAnalysisModel();
    model.head = process;/*w w w.j  ava2s  .  c o m*/
    model.type = process.toLowerCase();

    model.runIds = request.getParameterValues("select");
    if (model.runIds == null || model.runIds.length < 2) {
        String msg;
        msg = "Select at least 2 runs to " + model.type + ".";
        response.getOutputStream().println(msg);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
        return null;
    }

    StringBuilder runList = new StringBuilder();

    for (String runId : model.runIds)
        runList.append(runId).append(", ");

    runList.setLength(runList.length() - 2); //Strip off the last comma
    model.runList = runList.toString();

    model.name = RunAnalyzer.suggestName(RunAnalyzer.Type.COMPARE, model.runIds);
    request.setAttribute("editanalysis.model", model);

    return "/edit_analysis.jsp";
}

From source file:com.virtusa.akura.common.controller.ManageGradeController.java

/**
 * This method handles Add/Edit Grade and ClassGrade details.
 * //from  w  w  w .  j av  a 2  s . c  o m
 * @param grade - Grade obj.
 * @param request - HttpServletRequest
 * @param model {@link ModelMap}
 * @param bindingResult - holds errors
 * @return name of the view which is redirected to.
 * @throws AkuraAppException - throw detailed exception.
 */
@RequestMapping(value = REQ_MAP_VALUE_SAVEORUPDATE, method = RequestMethod.POST)
public String saveOrUpdateClassGrade(@ModelAttribute(MODEL_ATT_GRADE) Grade grade, BindingResult bindingResult,
        HttpServletRequest request, ModelMap model) throws AkuraAppException {

    gradeValidator.validate(grade, bindingResult);
    String gradeName = grade.getDescription().trim();
    String selectedGradeName = request.getParameter(REQ_SELECTEDGRADE);

    if (bindingResult.hasErrors() || (request.getParameterValues(REQ_CLASS_ID) == null)
            || "".equals(gradeName)) {
        if ((request.getParameterValues(REQ_CLASS_ID) == null) || "".equals(gradeName)) {

            model.addAttribute(EDITPANE, EDITPANE);
            model.addAttribute(SELECTED_OBJ_ID, selectedGradeName);
            bindingResult.rejectValue(FIELD_NAME, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE);
        }
        // model.addAttribute(EDITPANE, grade.getGradeId());
        model.addAttribute(EDITPANE, EDITPANE);
        model.addAttribute(SELECTED_OBJ_ID, selectedGradeName);
        return VIEW_GET_MANAGE_GRADE;
    } else {

        // Check whether the grade is already exist and populate a message
        // to user.
        if (isExistsGrade(gradeName, selectedGradeName)) {
            String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_KEY);
            Grade newGrade = new Grade();

            model.addAttribute(EDITPANE, EDITPANE);
            model.addAttribute(SELECTED_OBJ_ID, selectedGradeName);
            model.addAttribute(MODEL_ATT_GRADE, newGrade);
            model.addAttribute(MESSAGE, message);
            return VIEW_GET_MANAGE_GRADE;
        } else {

            try {
                // If selectedGradeName is empty, add a new grade otherwise
                // update already existing grade.
                grade = saveorUpdateGrade(grade, gradeName, selectedGradeName);

                // Gets the classes for the selected grade.
                String[] oldClassIds = getClassesForGrade(grade);

                // There is no update for class_grade table, we have
                // add/remove or add&remove, so that we use the below logic to be done.

                // checked(from check boxes) new ids of classes
                String[] classIds = request.getParameterValues(REQ_CLASS_ID);

                // add new classes for the garde.
                addClassesForGrade(grade, classIds, oldClassIds);

                // Remove old clsses from the grade.
                removeClassesFromGrade(grade, oldClassIds, classIds);

                // update ClassGrade description of existing records.
                updateClassGradeDescription(grade);

            } catch (AkuraAppException e) {
                if (e.getCause() instanceof DataIntegrityViolationException) {
                    String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_EDIT);
                    Grade newGrade = new Grade();
                    model.addAttribute(EDITPANE, EDITPANE);
                    model.addAttribute(SELECTED_OBJ_ID, selectedGradeName);
                    model.addAttribute(MODEL_ATT_GRADE, newGrade);
                    model.addAttribute(MESSAGE, message);

                    return VIEW_GET_MANAGE_GRADE;
                } else {
                    throw e;
                }
            }
        }
    }
    return VIEW_POST_MANAGE_GRADE;
}

From source file:fr.paris.lutece.plugins.workflow.modules.reassignment.web.ReassignmentTaskComponent.java

/**
 * {@inheritDoc}/*from ww  w  .  j a  v a  2  s .  c  o  m*/
 */
@Override
public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task) {
    String strError = StringUtils.EMPTY;
    String strTitle = request.getParameter(PARAMETER_TITLE);
    String strIsNotification = request.getParameter(PARAMETER_IS_NOTIFICATION);
    String strIsUseUserName = request.getParameter(PARAMETER_IS_USE_USER_NAME);
    String strMessage = request.getParameter(PARAMETER_MESSAGE);
    String strSubject = request.getParameter(PARAMETER_SUBJECT);
    String[] tabWorkgroups = request.getParameterValues(PARAMETER_WORKGROUPS);

    if (StringUtils.isBlank(strTitle)) {
        strError = FIELD_TITLE;
    }

    if (StringUtils.isNotBlank(strIsNotification) && StringUtils.isBlank(strSubject)) {
        strError = FIELD_MAILINGLIST_SUBJECT;
    }

    if (StringUtils.isNotBlank(strIsNotification) && StringUtils.isBlank(strMessage)) {
        strError = FIELD_MAILINGLIST_MESSAGE;
    }

    if (StringUtils.isNotBlank(strError)) {
        Object[] tabRequiredFields = { I18nService.getLocalizedString(strError, locale) };

        return AdminMessageService.getMessageUrl(request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
                AdminMessage.TYPE_STOP);
    }

    TaskReassignmentConfig config = _taskReassignementConfigService.findByPrimaryKey(task.getId());
    Boolean bCreate = false;

    if (config == null) {
        config = new TaskReassignmentConfig();
        config.setIdTask(task.getId());
        bCreate = true;
    }

    //add workgroups
    List<WorkgroupConfig> listWorkgroupConfig = new ArrayList<WorkgroupConfig>();
    WorkgroupConfig workgroupConfig;

    if (tabWorkgroups != null) {
        for (int i = 0; i < tabWorkgroups.length; i++) {
            workgroupConfig = new WorkgroupConfig();
            workgroupConfig.setIdTask(task.getId());
            workgroupConfig.setWorkgroupKey(tabWorkgroups[i]);

            if (strIsNotification != null) {
                if (WorkflowUtils.convertStringToInt(
                        request.getParameter(PARAMETER_ID_MAILING_LIST + "_" + tabWorkgroups[i])) != -1) {
                    workgroupConfig.setIdMailingList(WorkflowUtils.convertStringToInt(
                            request.getParameter(PARAMETER_ID_MAILING_LIST + "_" + tabWorkgroups[i])));
                } else {
                    return AdminMessageService.getMessageUrl(request, MESSAGE_NO_MAILINGLIST_FOR_WORKGROUP,
                            AdminMessage.TYPE_STOP);
                }
            }

            listWorkgroupConfig.add(workgroupConfig);
        }
    }

    config.setTitle(strTitle);
    config.setNotify(strIsNotification != null);
    config.setWorkgroups(listWorkgroupConfig);
    config.setMessage(strMessage);
    config.setSubject(strSubject);
    config.setUseUserName(strIsUseUserName != null);

    if (bCreate) {
        _taskReassignementConfigService.create(config);
    } else {
        _taskReassignementConfigService.update(config);
    }

    return null;
}

From source file:com.virtusa.akura.student.controller.StudentAssignmentMarkController.java

/**
 * Update student assignment marks./*  ww w. j ava  2  s . com*/
 * 
 * @param modelMap the model map
 * @param request the request
 * @return the model and view
 * @throws AkuraAppException the akura app exception
 */
@RequestMapping(UPDATE_STUDENT_ASSIGNMENT_MARKS_HTM)
public ModelAndView updateStudentAssignmentMarks(ModelMap modelMap, HttpServletRequest request)
        throws AkuraAppException {

    String[] studentAssignmentMarksKey = request.getParameterValues(ASSIGNMENT_MARK_KEY);
    String[] studentAssignmentMarksValue = request.getParameterValues(ASSIGNMENT_MARK_VALUE);
    String isMarks = request.getParameter(MARKS_TYPE);
    List<StudentAssignmentMark> studentAssignmentMarksList = new ArrayList<StudentAssignmentMark>();

    int count = 0;

    for (String strStudentAssignmentMark : studentAssignmentMarksKey) {

        StudentAssignmentMark studentAssignmentMark = studentService
                .getStudentAssignmentMarkById(Integer.parseInt(strStudentAssignmentMark));

        if (AkuraWebConstant.ABSENT_STRING.equalsIgnoreCase(studentAssignmentMarksValue[count])) {
            studentAssignmentMark.setIsAbsent(true);
            if (TRUE.equals(isMarks)) {
                studentAssignmentMark.setMarks(null);
            } else {
                studentAssignmentMark.setGradingId(null);
            }
        } else {
            studentAssignmentMark.setIsAbsent(false); // added to fix the issue not update ab in
            // report
            if (TRUE.equals(isMarks)) {
                String mark = studentAssignmentMarksValue[count].trim();
                Pattern numbersOnly = Pattern.compile(REGEX_PATTERN);
                Matcher makeMatch = numbersOnly.matcher(mark);
                boolean match = makeMatch.find();
                if (match) {
                    String message = new ErrorMsgLoader().getErrorMessage(STUDENT_ASSIGNMENT_MARKS_INVALID);
                    modelMap.addAttribute(MESSAGE, message);
                    studentAssignmentMark.setMarks(null);
                } else {

                    // adds the mark if mark is not empty.
                    addMark(modelMap, studentAssignmentMark, mark);
                }
            } else {

                Map<String, Integer> gradingmap = gradingMap();

                if (gradingmap.get(studentAssignmentMarksValue[count]) != null) {
                    studentAssignmentMark.setGradingId(gradingmap.get(studentAssignmentMarksValue[count]));
                    studentAssignmentMark.setIsAbsent(false);
                } else {
                    if ("".equals(studentAssignmentMarksValue[count])) {
                        studentAssignmentMark.setGradingId(null);
                        studentAssignmentMark.setIsAbsent(false);
                    } else {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("[");

                        for (Entry<String, Integer> entry : gradingmap.entrySet()) {
                            stringBuilder.append(entry.getKey());
                        }
                        stringBuilder.append("]");

                        Pattern acronymsOnly = Pattern.compile(stringBuilder.toString());
                        Matcher matcher = acronymsOnly.matcher(studentAssignmentMarksValue[count]);

                        if (!matcher.matches()) {
                            String message = new ErrorMsgLoader()
                                    .getErrorMessage(REF_UI_STUDENT_MARKASSIGN_INVALIDGRADING);
                            modelMap.addAttribute(MESSAGE, message);
                        }
                    }
                }
            }
        }

        studentAssignmentMarksList.add(studentAssignmentMark);
        count++;
    }

    studentService.saveStudentAssignmentMarksList(studentAssignmentMarksList);
    searchStudentAssignmentMarks(modelMap, request);
    return new ModelAndView(STUDENT_STUDENT_ASSIGNMENT_MARKS);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.ManageLessonDA.java

public ActionForward deleteLessonInstances(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    final SortedSet<NextPossibleSummaryLessonsAndDatesBean> set = new TreeSet<NextPossibleSummaryLessonsAndDatesBean>();
    for (final String lessonDate : request.getParameterValues("lessonDatesToDelete")) {
        set.add(NextPossibleSummaryLessonsAndDatesBean.getNewInstance(lessonDate));
    }/*from  w w  w.  j  a  va  2 s.co  m*/

    try {
        DeleteLessonInstance.run(set);
        ActionErrors actionErrors = new ActionErrors();
        for (final NextPossibleSummaryLessonsAndDatesBean n : set) {
            actionErrors.add(null, new ActionError("message.deleteLesson", n.getDate()));
        }
        saveErrors(request, actionErrors);
    } catch (UnsupportedOperationException unsupportedOperationException) {
        ActionErrors actionErrors = new ActionErrors();
        for (final NextPossibleSummaryLessonsAndDatesBean n : set) {
            actionErrors.add(unsupportedOperationException.getMessage(),
                    new ActionError("error.Lesson.not.instanced", n.getDate()));
        }
        saveErrors(request, actionErrors);
    } catch (DomainException domainException) {
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add(domainException.getMessage(), new ActionError(domainException.getMessage()));
        saveErrors(request, actionErrors);
    }

    return viewAllLessonDates(mapping, form, request, response);
}

From source file:edu.cornell.mannlib.vedit.controller.OperationController.java

private boolean populateObjectFromRequestParamsAndValidate(EditProcessObject epo, Object newObj,
        HttpServletRequest request) {
    boolean valid = true;
    String currParam = "";
    Enumeration penum = request.getParameterNames();
    while (penum.hasMoreElements()) {
        currParam = (String) penum.nextElement();
        if (!(currParam.indexOf("_") == 0)) {
            String currValue = request.getParameterValues(currParam)[0];
            // "altnew" values come in with the same input name but at position 1 of the array
            if (currValue.length() == 0 && request.getParameterValues(currParam).length > 1) {
                currValue = request.getParameterValues(currParam)[1];
            }/*from   ww w.  ja va2  s  .c o  m*/
            //validate the entry
            boolean fieldValid = true;
            if (request.getParameter("_delete") == null) { // don't do validation if we're deleting
                List validatorList = (List) epo.getValidatorMap().get(currParam);
                if (validatorList != null) {
                    Iterator valIt = validatorList.iterator();
                    String errMsg = "";
                    while (valIt.hasNext()) {
                        Validator val = (Validator) valIt.next();
                        ValidationObject vo = val.validate(currValue);
                        if (!vo.getValid()) {
                            valid = false;
                            fieldValid = false;
                            errMsg += vo.getMessage() + " ";
                            epo.getBadValueMap().put(currParam, currValue);
                        } else {
                            try {
                                epo.getBadValueMap().remove(currParam);
                                epo.getErrMsgMap().remove(currParam);
                            } catch (Exception e) {
                            }
                        }
                    }
                    if (errMsg.length() > 0) {
                        epo.getErrMsgMap().put(currParam, errMsg);
                        log.info("doPost() putting error message " + errMsg + " for " + currParam);
                    }
                }
            }
            if (fieldValid) {
                if (currValue.length() == 0) {
                    Map<String, String> defaultHash = epo.getDefaultValueMap();
                    try {
                        String defaultValue = defaultHash.get(currParam);
                        if (defaultValue != null)
                            currValue = defaultValue;
                    } catch (Exception e) {
                    }
                }
                try {
                    FormUtils.beanSet(newObj, currParam, currValue, epo);
                    epo.getErrMsgMap().remove(currParam);
                    epo.getBadValueMap().remove(currParam);
                } catch (NumberFormatException e) {
                    if (currValue.length() > 0) {
                        valid = false;
                        epo.getErrMsgMap().put(currParam, "Please enter an integer");
                        epo.getBadValueMap().put(currParam, currValue);
                    }
                } catch (NegativeIntegerException nie) {
                    valid = false;
                    epo.getErrMsgMap().put(currParam, "Please enter a positive integer");
                    epo.getBadValueMap().put(currParam, currValue);
                } catch (IllegalArgumentException f) {
                    valid = false;
                    log.error("doPost() reports IllegalArgumentException for " + currParam);
                    log.debug("doPost() error message: " + f.getMessage());
                    epo.getErrMsgMap().put(currParam, f.getMessage());
                    epo.getBadValueMap().put(currParam, currValue);
                }
            }
        }
    }
    return valid;
}

From source file:com.sun.faban.harness.webclient.ResultAction.java

/**
 * This method is responsible for archiving the runs to the repository.
 * @param request/*from   ww w . j a v  a 2 s.c  o  m*/
 * @param response
 * @return String
 * @throws java.io.IOException
 * @throws java.io.FileNotFoundException
 * @throws java.text.ParseException
 * @throws java.lang.ClassNotFoundException
 */
public String archive(HttpServletRequest request, HttpServletResponse response)
        throws IOException, FileNotFoundException, ParseException, ClassNotFoundException {
    //Reading values from request
    String[] duplicateIds = request.getParameterValues("duplicates");
    String[] replaceIds = request.getParameterValues("replace");
    String[] runIds = request.getParameterValues("select");
    String submitAction = request.getParameter("process");

    HashSet<String> modelDuplicates = new HashSet<String>();
    HashSet<String> replaceSet = new HashSet<String>();
    HashSet<File> uploadSet = new HashSet<File>();
    HashSet<String> uploadedRuns = new HashSet<String>();
    HashSet<String> duplicateSet = new HashSet<String>();
    if (replaceIds != null) {
        for (String replaceId : replaceIds) {
            replaceSet.add(replaceId);
        }
    }

    EditArchiveModel model = new EditArchiveModel();
    model.runIds = runIds;
    if (duplicateIds != null) {
        for (String duplicateId : duplicateIds) {
            modelDuplicates.add(duplicateId);
        }
    }
    model.duplicates = modelDuplicates;
    if (Config.repositoryURLs != null && Config.repositoryURLs.length > 1)
        model.head = "Repositories";
    else
        model.head = "Repository";

    model.results = new RunResult[runIds.length];
    for (int i = 0; i < runIds.length; i++) {
        model.results[i] = RunResult.getInstance(new RunId(runIds[i]));
    }

    if (submitAction.equals("Archive")) {
        for (int i = 0; i < model.runIds.length; i++) {
            String runId = model.runIds[i];
            if (model.duplicates.contains(runId)) {
                if (replaceIds != null) {
                    if (replaceSet.contains(runId)) {
                        prepareUpload(request, model.results[i], uploadedRuns, uploadSet);
                    } else { // Description or tags got changed, replace anyway...
                        if (!model.results[i].description.equals(request.getParameter(runId + "_description"))
                                || !model.results[i].tags.toString()
                                        .equals(request.getParameter(runId + "_tags"))) {
                            replaceSet.add(runId);
                            prepareUpload(request, model.results[i], uploadedRuns, uploadSet);
                        }
                    }
                } else { // Single run, description changed, replace anyway.
                    if (!model.results[i].description.equals(request.getParameter(runId + "_description"))
                            || !model.results[i].tags.toString()
                                    .equals(request.getParameter(runId + "_tags"))) {
                        replaceSet.add(runId);
                        prepareUpload(request, model.results[i], uploadedRuns, uploadSet);
                    }
                }
            } else {
                prepareUpload(request, model.results[i], uploadedRuns, uploadSet);
            }
        }
    }
    duplicateSet = uploadRuns(runIds, uploadSet, replaceSet);
    request.setAttribute("archive.model", model);
    request.setAttribute("uploadedRuns", uploadedRuns);
    request.setAttribute("duplicateRuns", duplicateSet);
    return "/archive_results.jsp";
}