📄 cybertesterutils.java
字号:
* Gets the data of tests, under a owner hierarchy node, that are <b>not</b> assigned to a user. * @param ownerHierId Owner hierarchy ID * @param userId User ID to exclude. * @return Array of TestData instances, or empty array if there is an error. */ public static TestData[] getTestsDataForNotUser(String ownerHierId, Integer userId) { TestData[] testDataArr = null; try { TestManager testMgr = (TestManager)s_testMgrHome.create(); testDataArr = testMgr.getTestsForNotUser( ownerHierId, userId); } catch (Exception ex) { s_logger.log( Level.SEVERE, "Error getting tests for ownerHeirId "+ownerHierId+", EXCLUDING user "+userId, ex); testDataArr = new TestData[0]; } return testDataArr; } /** * Safely converts an Object to an Integer instance. If not successful, it returns * null. This method does not throw exception. * @param src Source object to convert. * @return An Integer instance that is converted from str. */ public static Integer convertToInteger(Object src) { Integer result = null; if (src!=null) { if (src instanceof Integer) { result = (Integer)src; } else if (src instanceof Number) { result = new Integer(((Number)src).intValue()); } else { try { result = new Integer(src.toString()); } catch (NumberFormatException nfex) { result = null; } } } return result; } /** * Convenience method to convert a ChartRenderingInfo object containing rendered * chart elements into a list of image map area HTML tags. * @param info ChartRenderingInfo object containing rendered chart elements * @return List of image map area HTML tags. */ public static List getImageMapAreaList(ChartRenderingInfo info) { List areaTagList = new ArrayList(); Iterator oitr = info.getEntityCollection().iterator(); while (oitr.hasNext()) { String areaTag = ((ChartEntity)oitr.next()).getImageMapAreaTag(new StandardToolTipTagFragmentGenerator(),new StandardURLTagFragmentGenerator()); areaTagList.add(areaTag); } return areaTagList; } /** * Convenience method to first search for a request parameter with the * specified key. If this parameter is not present, search for a * request attribute (of type String) with the same key. * @param request Request from client. * @param key Key to search request parameter and attribute for. * @return Parameter or attribute String value, or null if the key is not present in both request parameter or attribute. */ public static String getParameterOrRequestAttribute(HttpServletRequest request, String key) { String val = request.getParameter(key); if (val==null) { val = (String)request.getAttribute(key); } return val; } /** * Convenience method to first search for a request parameter with the * specified key. If this parameter is found, it is converted to an Integer object. * If this parameter is not present, search for a request attribute with the same key * and try to convert it to an Integer object. * @param request Request from client. * @param key Key to search request parameter and attribute for. * @return Parameter or attribute String value, or null if the key is not present in both request parameter or attribute, or it cannot be converted to an Integer. */ public static Integer getIntegerParameterOrRequestAttribute(HttpServletRequest request, String key) { String valStr = request.getParameter(key); if ((valStr!=null) && (valStr.length()>0)) { return convertToInteger(valStr); } return convertToInteger(request.getAttribute(key)); } /** * Performs validation on a form parameter to ensure that it has a numeric value. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param errors ActionErrors instance to store any errors. * @return true if the form parameter has a valid numeric value. */ public static boolean validateRequiredFormNumericParam(String paramName, String value, ActionErrors errors) { boolean success = true; if ((value == null) || (value.length() < 1)) { errors.add(paramName, new ActionError("error.form.missingParam.enter",paramName)); success = false; } else { try { Double.parseDouble(value); } catch (NumberFormatException nfex) { errors.add(paramName, new ActionError("error.form.nonNumericParam",paramName,value)); success = false; } } return success; } /** * Performs validation on a form parameter to ensure that it has an integer value. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param negativeAllowed true to allow negative integers to be treated as valid, false to treat negative integers as invalid. * @param errors ActionErrors instance to store any errors. * @return true if the form parameter has a valid integer value. */ public static boolean validateRequiredFormIntegerParam(String paramName, String value, boolean negativeAllowed, ActionErrors errors) { boolean success = false; if ((value == null) || (value.length() < 1)) { errors.add(paramName, new ActionError("error.form.missingParam.enter",paramName)); } else if (value.indexOf(".")>=0) { try { int intVal = Integer.parseInt(value); if ( negativeAllowed || (intVal>=0) ) { success = true; } else { errors.add(paramName, new ActionError("error.form.negativeIntegerParam",paramName,value)); } } catch (NumberFormatException nfex) { errors.add(paramName, new ActionError("error.form.nonIntegerParam",paramName,value)); } } else { errors.add(paramName, new ActionError("error.form.nonIntegerParam",paramName,value)); } return success; } /** * Performs validation on a form parameter to ensure that it has an numeric value within a given range. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param lower Lower limit of the range (inclusive). * @param upper Upper limit of the range (inclusive). * @param errors ActionErrors instance to store any errors. * @return true if the form parameter has a valid numeric value within the range. */ public static boolean validateRequiredFormNumericParamInRange(String paramName, String value, double lower, double upper, ActionErrors errors) { boolean success = true; success = validateRequiredFormNumericParam(paramName, value, errors); if (success) { double val = Double.parseDouble(value); if ((val<lower) || (val>upper)) { errors.add(paramName, new ActionError("error.form.outOfRangeNumericParam",paramName,value,String.valueOf(lower),String.valueOf(upper))); success = false; } } return success; } /** * Performs validation on a form parameter to ensure that it exists and is not an empty String. * This form parameter value is entered from a text-field in the GUI. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param errors ActionErrors instance to store any errors. * @return true if the form parameter has a valid integer value. */ public static boolean validateRequiredFormEnteredParam(String paramName, String value, ActionErrors errors) { return validateRequiredFormParam(paramName, value, errors, "error.form.missingParam.enter"); } /** * Performs validation on a form parameter to ensure that it exists and is not an empty String. * This form parameter value is selected from a multi-value selector in the GUI. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param errors ActionErrors instance to store any errors. * @return true if the form parameter has a valid integer value. */ public static boolean validateRequiredFormSelectedParam(String paramName, String value, ActionErrors errors) { return validateRequiredFormParam(paramName, value, errors, "error.form.missingParam.select"); } /** * Performs validation on a form parameter to ensure that it exists and is not an empty String. * @param paramName Parameter name for logging and error reporting purposes. * @param value The parameter value to be validated. * @param errors ActionErrors instance to store any errors. * @param errMsgKey Key to Struts error message resource to be used as error message. * @return true if the form parameter has a valid integer value. */ private static boolean validateRequiredFormParam(String paramName, String value, ActionErrors errors, String errMsgKey) { boolean success = true; if ((value == null) || (value.length() < 1)) { errors.add(paramName, new ActionError(errMsgKey,paramName)); success = false; } return success; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -