Java Code Examples for org.springframework.util.StringUtils.arrayToCommaDelimitedString()

The following are Jave code examples for showing how to use arrayToCommaDelimitedString() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lams   File: DefaultBindingErrorProcessor.java   Source Code and License Vote up 5 votes
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (rejectedValue != null && rejectedValue.getClass().isArray()) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	bindingResult.addError(new FieldError(
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
Example 2
Project: siga   File: UserDaoImpl.java   Source Code and License Vote up 5 votes
private String convertListToDelimitedString(List<String> list) {

		String result = "";
		if (list != null) {
			result = StringUtils.arrayToCommaDelimitedString(list.toArray());
		}
		return result;

	}
 
Example 3
Project: Webstore   File: ProductController.java   Source Code and License Vote up 5 votes
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product newProduct, BindingResult result, @ModelAttribute("productImage") ProductImage image, HttpServletRequest request) throws IOException {
    if(result.hasErrors()) {
        return "addProduct";
    }
    String[] suppressedFields = result.getSuppressedFields();
    if (suppressedFields.length > 0) {
        throw new RuntimeException("Próba wiązania niedozwolonych pól: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
    }
    ProductThumbnail productThumbnail = new ProductThumbnail(newProduct);
    ProductPicture productPicture = new ProductPicture(newProduct);
    MultipartFile productImage = image.getProductImage();
    if (productImage!=null && !productImage.isEmpty()) {
        try {
            InputStream is = image.getProductImage().getInputStream();
            BufferedImage img = Thumbnails.of(is)
                    .crop(Positions.CENTER)
                    .size(400, 300)
                    .asBufferedImage();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(img, "jpg", baos);
            byte[] imageBytess = Base64.getEncoder().encode(baos.toByteArray());
            productThumbnail.setBase64Image(new String(imageBytess));

            byte[] encoded = Base64.getEncoder().encode(image.getProductImage().getBytes());
            productPicture.setBase64Image(new String(encoded));

        } catch(Exception e) {
            throw new RuntimeException("Niepowodzenie podczas próby zapisu obrazka produktu", e);
        }
    }
    productService.create(newProduct);
    productThumbnailService.create(productThumbnail);
    productPictureService.create(productPicture);
    return "redirect:/products";
}
 
Example 4
Project: lams   File: ReloadableResourceBundleMessageSource.java   Source Code and License Vote up 4 votes
@Override
public String toString() {
	return getClass().getName() + ": basenames=[" + StringUtils.arrayToCommaDelimitedString(this.basenames) + "]";
}
 
Example 5
Project: lams   File: ResourceBundleMessageSource.java   Source Code and License Vote up 4 votes
/**
 * Show the configuration of this MessageSource.
 */
@Override
public String toString() {
	return getClass().getName() + ": basenames=[" +
			StringUtils.arrayToCommaDelimitedString(this.basenames) + "]";
}
 
Example 6
Project: lams   File: TypeConverterDelegate.java   Source Code and License Vote up 4 votes
/**
 * Convert the value to the required type (if necessary from a String),
 * using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newValue the proposed new value
 * @param requiredType the type we must convert to
 * (or {@code null} if not known, for example in case of a collection element)
 * @param editor the PropertyEditor to use
 * @return the new value, possibly the result of type conversion
 * @throws IllegalArgumentException if type conversion failed
 */
private Object doConvertValue(Object oldValue, Object newValue, Class<?> requiredType, PropertyEditor editor) {
	Object convertedValue = newValue;

	if (editor != null && !(convertedValue instanceof String)) {
		// Not a String -> use PropertyEditor's setValue.
		// With standard PropertyEditors, this will return the very same object;
		// we just want to allow special PropertyEditors to override setValue
		// for type conversion from non-String values to the required type.
		try {
			editor.setValue(convertedValue);
			Object newConvertedValue = editor.getValue();
			if (newConvertedValue != convertedValue) {
				convertedValue = newConvertedValue;
				// Reset PropertyEditor: It already did a proper conversion.
				// Don't use it again for a setAsText call.
				editor = null;
			}
		}
		catch (Exception ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
			}
			// Swallow and proceed.
		}
	}

	Object returnValue = convertedValue;

	if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) {
		// Convert String array to a comma-separated String.
		// Only applies if no PropertyEditor converted the String array before.
		// The CSV String will be passed into a PropertyEditor's setAsText method, if any.
		if (logger.isTraceEnabled()) {
			logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");
		}
		convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue);
	}

	if (convertedValue instanceof String) {
		if (editor != null) {
			// Use PropertyEditor's setAsText in case of a String value.
			if (logger.isTraceEnabled()) {
				logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");
			}
			String newTextValue = (String) convertedValue;
			return doConvertTextValue(oldValue, newTextValue, editor);
		}
		else if (String.class.equals(requiredType)) {
			returnValue = convertedValue;
		}
	}

	return returnValue;
}
 
Example 7
Project: lams   File: SimpleKey.java   Source Code and License Vote up 4 votes
@Override
public String toString() {
	return "SimpleKey [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}