public static Map<String, String> toRequestMap(List paypalClassicModelList, String format) { Map<String, String> returnMap = new HashMap<>(); if (paypalClassicModelList != null) { for (int i = 0; i < paypalClassicModelList.size(); i++) { if (paypalClassicModelList.get(i) instanceof PaypalClassicModel) { if (StringUtils.isNoneEmpty(format)) { returnMap.putAll( toRequestMap( (PaypalClassicModel) paypalClassicModelList.get(i), format + String.valueOf(i))); } else { returnMap.putAll( toRequestMap( (PaypalClassicModel) paypalClassicModelList.get(i), String.valueOf(i))); } } if (paypalClassicModelList.get(i) instanceof List) { if (StringUtils.isNoneEmpty(format)) { returnMap.putAll( toRequestMap((List) paypalClassicModelList.get(i), format + String.valueOf(i))); } else { returnMap.putAll(toRequestMap((List) paypalClassicModelList.get(i), String.valueOf(i))); } } } } return returnMap; }
/** * 获取请求url参数,用于去除分页参数 * * @param request * @param reqPageName 分页名称 * @return */ public static String rePageUrlParame(HttpServletRequest request, String reqPageName) { if (!StringUtils.isNoneEmpty(reqPageName)) { reqPageName = "p"; } String qs = request.getQueryString(); Map modelMap = RequestUtils.getRequestMap(request); Map<String, String> urlParameter = new HashMap(); if (StringUtils.isNoneEmpty(qs)) { String[] qsArray = qs.split("&"); for (String parame : qsArray) { String[] pArray = parame.split("="); if (pArray.length == 2) { if (!pArray[0].equals(reqPageName)) { if (modelMap.containsKey(pArray[0])) { urlParameter.put(pArray[0], (String) modelMap.get(pArray[0])); } } } } } StringBuffer urlSB = new StringBuffer(); if (urlParameter.size() > 0) { for (String key : urlParameter.keySet()) { urlSB.append(key); urlSB.append("="); urlSB.append(urlParameter.get(key)); urlSB.append("&"); } return urlSB.substring(0, urlSB.length() - 1); } return ""; }
@Override public boolean isValid() { return StringUtils.isNoneEmpty(m_sName) && m_aPassword != null && StringUtils.isNoneEmpty(m_sEmail) && getRole() != null; }
/** * Returns a handler for the given entity and action.<br> * <br> * Throws an {@link UnsupportedCommandException} if no handler for the given entity, action * combination can be found. * * @param entity the entity to lookup the handler, must be given. * @param action the action to lookup the handler, must be given. */ @Nonnull public NewCommandSourceHandler getHandler( @Nonnull final String entity, @Nonnull final String action) { Preconditions.checkArgument(StringUtils.isNoneEmpty(entity), "An entity must be given!"); Preconditions.checkArgument(StringUtils.isNoneEmpty(action), "An action must be given!"); final String key = entity + "|" + action; if (!this.registeredHandlers.containsKey(key)) { throw new UnsupportedCommandException(key); } return (NewCommandSourceHandler) this.applicationContext.getBean(this.registeredHandlers.get(key)); }
/** * 获取请求url参数,用于去除分页参数 * * @param request * @param reqPageName 分页名称 * @return */ public static String getPageUrlParame( HttpServletRequest request, String reqPageName, String url) { String parame = rePageUrlParame(request, reqPageName); if (StringUtils.isNoneEmpty(url)) { if (url.indexOf("?") > -1) { return url + "&" + parame + "&" + reqPageName + "="; } else if (StringUtils.isNoneEmpty(parame)) { return url + "?" + parame + "&" + reqPageName + "="; } else { return url + "?" + reqPageName + "="; } } return parame; }
/** * 去除给定参数 * * @param request * @param defaultParamName * @return */ public static String dislodgeParam(HttpServletRequest request, String defaultParamName) { String qs = request.getQueryString(); if (StringUtils.isNoneEmpty(qs)) { Map<String, String> urlParameter = new HashMap(); String[] qsArray = qs.split("&"); for (String parame : qsArray) { String[] pArray = parame.split("="); if (pArray.length == 2) { if (!pArray[0].equals(defaultParamName)) { urlParameter.put(pArray[0], pArray[1]); } } } StringBuffer urlSB = new StringBuffer(); if (urlParameter.size() > 0) { for (String key : urlParameter.keySet()) { urlSB.append(key); urlSB.append("="); urlSB.append(urlParameter.get(key)); urlSB.append("&"); } return urlSB.substring(0, urlSB.length() - 1); } } return null; }
public WikipediaElement from(WikiArticle article) { String infobox = WikipediaElementTransformer.toWikipediaElement(this, article); if (StringUtils.isNoneEmpty(infobox)) { this.settlement = WikipediaSettlementInfoboxParser.parse(infobox); } return this; }
private static String[] addCLIParamters(SeleneseMethodInfo seleneseMethodInfo) { if (seleneseMethodInfo == null) { return new String[0]; } List<String> cliArgs = new ArrayList<String>(); if (StringUtils.isNoneEmpty(seleneseMethodInfo.driver())) { cliArgs.add("-d"); cliArgs.add(seleneseMethodInfo.driver()); } cliArgs.addAll(Arrays.asList(seleneseMethodInfo.configArgs())); return cliArgs.toArray(new String[cliArgs.size()]); }
private Set<BlueprintParameterJson> convertInputParameters(Json inputParameters) throws IOException { Set<BlueprintParameterJson> result = new HashSet<>(); if (inputParameters != null && StringUtils.isNoneEmpty(inputParameters.getValue())) { BlueprintInputParameters inputParametersObj = inputParameters.get(BlueprintInputParameters.class); List<BlueprintParameter> parameters = inputParametersObj.getParameters(); for (BlueprintParameter record : parameters) { BlueprintParameterJson json = new BlueprintParameterJson(); json.setDescription(record.getDescription()); json.setName(record.getName()); json.setReferenceConfiguration(record.getReferenceConfiguration()); result.add(json); } } return result; }
private void testDataValue( final String id, final long lineNumber, final String value, final Field column, final Date startTime, final String fileName, final boolean isReleaseInputFile) { final ColumnType columnType = getColumnType(column); final PatternTest columnTest = columnTests.get(columnType); if (columnTest != null) { if (canBeBlank(value, column) || columnTest.validate(column, lineNumber, value)) { testReport.addSuccess( id, startTime, fileName, resourceManager.getFilePath(), column.getName(), columnTest.getTestType(), columnTest.getPatternString()); } else { final String testedValue = StringUtils.isNoneEmpty(value) ? value : "No Value"; validationLog.assertionError(columnTest.getMessage(), columnTest.getErrorArgs()); testReport.addError( id, startTime, fileName, resourceManager.getFilePath(), column.getName(), columnTest.getTestType(), columnTest.getPatternString(), testedValue, columnTest.getExpectedValue()); } } }
public static Map<String, String> toRequestMap( PaypalClassicModel paypalClassicModel, String format) { Map<String, String> returnMap = new HashMap<>(); if (paypalClassicModel == null) { return returnMap; } ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); // ValidatorFactory factory = Validation.byDefaultProvider() // .configure() // .messageInterpolator( new MyMessageInterpolator() ) // .buildValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<PaypalClassicModel>> violations = validator.validate(paypalClassicModel); if (violations.size() == 0) { try { for (Field field : FieldUtils.getAllFields(paypalClassicModel.getClass())) { if (field.getType().isAssignableFrom(String.class)) { if (BeanUtils.getProperty(paypalClassicModel, field.getName()) != null) { if (StringUtils.isNumeric(format)) { returnMap.put( field.getName().toUpperCase() + format, BeanUtils.getProperty(paypalClassicModel, field.getName())); } else { returnMap.put( getFormatedKeyName(format, field.getName(), null), BeanUtils.getProperty(paypalClassicModel, field.getName())); } } } if (PaypalClassicModel.class.isAssignableFrom(field.getType())) { if (PropertyUtils.getProperty(paypalClassicModel, field.getName()) != null) { returnMap.putAll( toRequestMap( (PaypalClassicModel) PropertyUtils.getProperty(paypalClassicModel, field.getName()), format)); } } if (List.class.isAssignableFrom(field.getType())) { List listItem = (List) PropertyUtils.getProperty(paypalClassicModel, field.getName()); if (listItem != null) { for (int i = 0; i < listItem.size(); i++) { if (listItem.get(i) instanceof PaypalClassicModel) { PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class); if (paypalCollection != null && StringUtils.isNotEmpty(paypalCollection.format())) { String formatStr = field.getAnnotation(PaypalCollection.class).format(); returnMap.putAll( toRequestMap( (PaypalClassicModel) listItem.get(i), getFormatedKeyName(formatStr, null, i))); } else { if (StringUtils.isNoneEmpty(format)) { returnMap.putAll( toRequestMap( (PaypalClassicModel) listItem.get(i), format + String.valueOf(i))); } else { returnMap.putAll( toRequestMap((PaypalClassicModel) listItem.get(i), String.valueOf(i))); } } } if (listItem.get(i) instanceof List) { PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class); if (paypalCollection != null && StringUtils.isNotEmpty(paypalCollection.format())) { String formatStr = field.getAnnotation(PaypalCollection.class).format(); returnMap.putAll( toRequestMap( (List) listItem.get(i), getFormatedKeyName(formatStr, null, i))); } else { if (StringUtils.isNoneEmpty(format)) { returnMap.putAll( toRequestMap((List) listItem.get(i), format + String.valueOf(i))); } else { returnMap.putAll(toRequestMap((List) listItem.get(i), String.valueOf(i))); } } } if (listItem.get(i) instanceof String) { PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class); if (paypalCollection != null && StringUtils.isNotEmpty(paypalCollection.format())) { String formatStr = paypalCollection.format(); formatStr = getFormatedKeyName(formatStr, field.getName(), i); returnMap.put( getFormatedKeyName(format, formatStr, null), listItem.get(i).toString()); } else { returnMap.put( getFormatedKeyName(format, field.getName(), null) + i, listItem.get(i).toString()); } } } } } } } catch (IllegalAccessException e) { throw new ValidationException(e.getMessage()); } catch (InvocationTargetException e) { throw new ValidationException(e.getMessage()); } catch (NoSuchMethodException e) { throw new ValidationException(e.getMessage()); } } else { StringBuffer buf = new StringBuffer(); for (ConstraintViolation<PaypalClassicModel> violation : violations) { buf.append(violation.getMessage() + "\n"); } throw new ValidationException(buf.toString()); } return returnMap; }
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { int iconId = getArguments().getInt(ICON_ID, 0); String title = getArguments().getString(TITLE); String message = getArguments().getString(MESSAGE); boolean hasPositive = getArguments().getBoolean(HAS_POSITIVE, false); boolean hasNeutral = getArguments().getBoolean(HAS_NEUTRAL, false); boolean hasNegative = getArguments().getBoolean(HAS_NEGATIVE, false); String positiveText = getArguments().getString(POSITIVE_TEXT); String neutralText = getArguments().getString(NEUTRAL_TEXT); String negativeText = getArguments().getString(NEGATIVE_TEXT); boolean cancelable = getArguments().getBoolean(CANCELABLE, true); boolean canceledOnTouchOutside = getArguments().getBoolean(CANCELED_ON_TOUCH_OUTSIDE, false); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (iconId > 0) { builder.setIcon(iconId); } if (StringUtils.isNoneEmpty(title)) { builder.setTitle(title); } if (StringUtils.isNoneEmpty(message)) { builder.setMessage(message); } if (hasPositive) { if (StringUtils.isEmpty(positiveText)) { positiveText = getResources().getString(R.string.yes); } builder.setPositiveButton( positiveText, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int whichButton) { synchronized (mOnAlertDialogEventListeners) { for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) { listener.onDialogClick(dialog, whichButton, getTag()); } } } }); } if (hasNeutral) { if (StringUtils.isEmpty(neutralText)) { neutralText = getResources().getString(R.string.no); } builder.setNeutralButton( neutralText, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int whichButton) { synchronized (mOnAlertDialogEventListeners) { for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) { listener.onDialogClick(dialog, whichButton, getTag()); } } } }); } if (hasNegative) { if (StringUtils.isEmpty(negativeText)) { negativeText = getResources().getString(hasNeutral ? R.string.cancel : R.string.no); } builder.setNegativeButton( negativeText, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int whichButton) { synchronized (mOnAlertDialogEventListeners) { for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) { listener.onDialogClick(dialog, whichButton, getTag()); } } } }); } builder.setCancelable(cancelable); if (cancelable) { builder.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { synchronized (mOnAlertDialogEventListeners) { for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) { listener.onDialogCancel(dialog, getTag()); } } } }); } // View customView = getCustomView(); if (mCustomView != null) { builder.setView(mCustomView); } Dialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(canceledOnTouchOutside); return dialog; }