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

The following examples show how to use org.springframework.util.StringUtils#arrayToCommaDelimitedString() . 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
Source File: ProductController.java    From maven-framework-project with MIT License 6 votes vote down vote up
@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
Source File: DefaultBindingErrorProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: ControlBindingErrorProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/** 
 * 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 4
Source File: HierarchicalUriComponents.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 5
Source File: DefaultBindingErrorProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 6
Source File: LoggingListener.java    From spring-cloud-cluster with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: StartEventListener.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 8
Source File: ProductController.java    From maven-framework-project with MIT License 5 votes vote down vote up
@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 9
Source File: HierarchicalUriComponents.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 10
Source File: ProductController.java    From maven-framework-project with MIT License 5 votes vote down vote up
@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 11
Source File: SimpleKey.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 12
Source File: ResourceBundleMessageSource.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Show the configuration of this MessageSource.
 */
@Override
public String toString() {
	return getClass().getName() + ": basenames=[" +
			StringUtils.arrayToCommaDelimitedString(this.basenames) + "]";
}
 
Example 13
Source File: SimpleKey.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 14
Source File: PortletRequestMethodNotSupportedException.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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 15
Source File: PackagesAnnotationFilter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return "Packages annotation filter: " +
			StringUtils.arrayToCommaDelimitedString(this.prefixes);
}
 
Example 16
Source File: MBeanClientInterceptor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return this.name + "(" + StringUtils.arrayToCommaDelimitedString(this.parameterTypes) + ")";
}
 
Example 17
Source File: TypeConverterDelegate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 18
Source File: SimpleKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
Example 19
Source File: PrefixedSimpleKey.java    From jhipster with 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) + "]";
}
 
Example 20
Source File: MethodSimpleKey.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}