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

The following examples show how to use org.springframework.util.StringUtils#arrayToCommaDelimitedString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") Product productToBeAdded, ModelMap map, BindingResult result, HttpServletRequest request) {
	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
Example 2
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	Assert.state(field != null, "No field in exception");
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (ObjectUtils.isArray(rejectedValue)) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage());
	error.wrap(ex);
	bindingResult.addError(error);
}
 
Example 3
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product productToBeAdded, BindingResult result, HttpServletRequest request) {
	if(result.hasErrors()) {
		return "addProduct";
	}

	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
Example 4
@Override
public Object getValue(@Nullable String name) {
	Object value = this.delegate.getValue(name);
	if (ObjectUtils.isArray(value)) {
		value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value));
	}
	return value;
}
 
Example 5
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product productToBeAdded, BindingResult result, HttpServletRequest request) {
	if(result.hasErrors()) {
		return "addProduct";
	}

	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
Example 6
@Async
@Order
@EventListener(WebServerInitializedEvent.class)
public void afterStart(WebServerInitializedEvent event) {
	Environment environment = event.getApplicationContext().getEnvironment();
	String appName = environment.getProperty("spring.application.name").toUpperCase();
	int localPort = event.getWebServer().getPort();
	String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
	log.info("---[{}]---启动完成,当前使用的端口:[{}],环境变量:[{}]---", appName, localPort, profile);
}
 
Example 7
/**
 * Constructs Logger listener with given level.
 *
 * @param level the level string
 */
public LoggingListener(String level) {
	try {
		this.level = Level.valueOf(level.toUpperCase());
	}
	catch (IllegalArgumentException e) {
		throw new IllegalArgumentException("Invalid log level '" + level
				+ "'. The (case-insensitive) supported values are: "
				+ StringUtils.arrayToCommaDelimitedString(Level.values()));
	}
}
 
Example 8
@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 9
@Override
public Object getValue(String name) {
	Object value = this.delegate.getValue(name);
	if (ObjectUtils.isArray(value)) {
		value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value));
	}
	return value;
}
 
Example 10
/** 
 * Add a ControlError instead FieldError to hold component that has failed.
 * @param control
 * @param ex
 * @param bindingResult
 */
public void processPropertyAccessException(Object control, 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 ControlError(control,
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
Example 11
Source Project: onetwo   File: MethodSimpleKey.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 12
@Override
public String toString() {
	return "Packages annotation filter: " +
			StringUtils.arrayToCommaDelimitedString(this.prefixes);
}
 
Example 13
/**
 * Create a new PortletRequestMethodNotSupportedException.
 * @param supportedMethods the actually supported HTTP methods
 */
public PortletRequestMethodNotSupportedException(String[] supportedMethods) {
	super("Mapped handler only supports client data requests with methods " +
			StringUtils.arrayToCommaDelimitedString(supportedMethods));
	this.supportedMethods = supportedMethods;
}
 
Example 14
/**
 * Show the configuration of this MessageSource.
 */
@Override
public String toString() {
	return getClass().getName() + ": basenames=[" +
			StringUtils.arrayToCommaDelimitedString(this.basenames) + "]";
}
 
Example 15
Source Project: java-technology-stack   File: SimpleKey.java    License: MIT License 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 16
Source Project: spring4-understanding   File: SimpleKey.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 17
@Override
public String toString() {
	return this.name + "(" + StringUtils.arrayToCommaDelimitedString(this.parameterTypes) + ")";
}
 
Example 18
/**
 * 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 == requiredType) {
			returnValue = convertedValue;
		}
	}

	return returnValue;
}
 
Example 19
Source Project: lams   File: SimpleKey.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 20
Source Project: jhipster   File: PrefixedSimpleKey.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return this.prefix + " " + getClass().getSimpleName() + this.methodName + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}