下面列出了org.springframework.util.StringUtils#arrayToDelimitedString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Validate the given type-level mapping metadata against the current request,
* checking HTTP request method and parameter conditions.
* @param mapping the mapping metadata to validate
* @param request current HTTP request
* @throws Exception if validation failed
*/
protected void validateMapping(RequestMapping mapping, HttpServletRequest request) throws Exception {
RequestMethod[] mappedMethods = mapping.method();
if (!ServletAnnotationMappingUtils.checkRequestMethod(mappedMethods, request)) {
String[] supportedMethods = new String[mappedMethods.length];
for (int i = 0; i < mappedMethods.length; i++) {
supportedMethods[i] = mappedMethods[i].name();
}
throw new HttpRequestMethodNotSupportedException(request.getMethod(), supportedMethods);
}
String[] mappedParams = mapping.params();
if (!ServletAnnotationMappingUtils.checkParameters(mappedParams, request)) {
throw new UnsatisfiedServletRequestParameterException(mappedParams, request.getParameterMap());
}
String[] mappedHeaders = mapping.headers();
if (!ServletAnnotationMappingUtils.checkHeaders(mappedHeaders, request)) {
throw new ServletRequestBindingException("Header conditions \"" +
StringUtils.arrayToDelimitedString(mappedHeaders, ", ") +
"\" not met for actual request");
}
}
@Override
public void validate(PortletRequest request) throws PortletException {
if (!PortletAnnotationMappingUtils.checkHeaders(this.headers, request)) {
throw new PortletRequestBindingException("Header conditions \"" +
StringUtils.arrayToDelimitedString(this.headers, ", ") +
"\" not met for actual request");
}
if (!this.methods.isEmpty()) {
if (!(request instanceof ClientDataRequest)) {
throw new PortletRequestMethodNotSupportedException(StringUtils.toStringArray(this.methods));
}
String method = ((ClientDataRequest) request).getMethod();
if (!this.methods.contains(method)) {
throw new PortletRequestMethodNotSupportedException(method, StringUtils.toStringArray(this.methods));
}
}
}
public void run() {
logger.info("Listing images in image database, scheduled by Timer");
List images = this.imageDatabase.getImages();
String[] imageNames = new String[images.size()];
for (int i = 0; i < images.size(); i++) {
ImageDescriptor image = (ImageDescriptor) images.get(i);
imageNames[i] = image.getName();
}
String text = "Images in image database: " + StringUtils.arrayToDelimitedString(imageNames, ", ");
logger.info(text);
if (!"".equals(this.mailTo)) {
logger.info("Sending image list mail to: " + this.mailTo);
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(this.mailFrom);
message.setTo(this.mailTo);
message.setSubject("Image list");
message.setText(text);
this.mailSender.send(message);
}
else {
logger.info("Not sending image list mail - specify mail settings in 'WEB-INF/mail.properties'");
}
}
/**
* Method to CreateName value labels.
*
* @param label
* as string
* @param values
* as string
* @return HorizontalLayout
*/
public static HorizontalLayout createNameValueLayout(final String label, final String... values) {
final String valueStr = StringUtils.arrayToDelimitedString(values, " ");
final Label nameValueLabel = new Label( label );
nameValueLabel.setContentMode(ContentMode.TEXT);
nameValueLabel.addStyleName(SPUIDefinitions.TEXT_STYLE);
nameValueLabel.addStyleName("text-bold");
nameValueLabel.setSizeUndefined();
final Label valueStrLabel = new Label(valueStr);
valueStrLabel.setWidth("100%");
valueStrLabel.addStyleName("text-cut");
valueStrLabel.addStyleName(SPUIDefinitions.TEXT_STYLE);
valueStrLabel.addStyleName(LABEL_STYLE);
final HorizontalLayout nameValueLayout = new HorizontalLayout();
nameValueLayout.setMargin(false);
nameValueLayout.setSpacing(true);
nameValueLayout.setSizeFull();
nameValueLayout.addComponent(nameValueLabel);
nameValueLayout.setComponentAlignment(nameValueLabel, Alignment.TOP_LEFT);
nameValueLayout.setExpandRatio(nameValueLabel, 0.0F);
nameValueLayout.addComponent(valueStrLabel);
nameValueLayout.setComponentAlignment(valueStrLabel, Alignment.TOP_LEFT);
nameValueLayout.setExpandRatio(valueStrLabel, 1.0F);
return nameValueLayout;
}
/**
* @return a colon separated representation of the stub configuration (e.g.
* groupid:artifactid:version:classifier)
*/
public String toColonSeparatedDependencyNotation() {
if (!isDefined()) {
return "";
}
return StringUtils.arrayToDelimitedString(
new String[] { nullCheck(this.groupId), nullCheck(this.artifactId),
nullCheck(this.version), nullCheck(this.classifier) },
STUB_COLON_DELIMITER);
}
private String valueToString(Object value) {
if (value == this) {
return "(this Map)";
}
if (value instanceof Object[]) {
return "[" + StringUtils.arrayToDelimitedString((Object[]) value, ", ") + "]";
}
return String.valueOf(value);
}
@Scheduled(cron = "0 1 0 * * ?")
public void notifyDueTodo() throws MessageSendingException {
List<Todo> todos = this.getDueTodosOfToday();
logger.info("todos of day {} counts : {}", new DateTime(), todos.size());
for (Todo todo : todos) {
if (todo.getAssigneeId() == null) {
continue;
}
Project project = projectService.getById(todo.getProjectId());
User user = userService.getById(todo.getAssigneeId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("content", todo.getContent());
model.put("host", protocol + this.host);
model.put("date", new SimpleDateFormat("yyyy年MM月dd日").format(todo.getDueDate()));
//TODO: get url
// String url = identifiableManager.getIdentifiableURL(todo);
String url = String.format("https://onboard.cn/teams/%s/projects/%s/todolists/open?id=%s1&type=todo",
todo.getCompanyId(), todo.getProjectId(), todo.getId());
model.put("url", url);
String content = templateEngineService.process(getClass(), VM_PATH, model);
String replyTo = StringUtils.arrayToDelimitedString(
new String[] { todo.getType(), String.valueOf(todo.getId()), DataCipher.encode(user.getEmail()) },
"-");
emailService.sendEmail("OnBoard", user.getEmail(), null, null,
String.format("[%s]%s 快要到期了!", project.getName(), todo.getContent()), content, replyTo);
}
}
private void invokeMavenLauncher(String[] args) throws Exception {
ClassLoader origCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(mavenClassLoader);
try {
int exitCode = (Integer) MAVEN_EXECUTE_METHOD.invoke(null, new Object[]{args});
if (exitCode != 0) {
throw new RuntimeException("mvn " + StringUtils.arrayToDelimitedString(args, " ") + " returned " +
exitCode + ", see log for details");
}
} finally {
Thread.currentThread().setContextClassLoader(origCL);
}
}
/**
* 自定义生成key的策略
*
* @return
*/
@Bean
@Override
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
return target.getClass().getSimpleName() + "_"
+ method.getName() + "_"
+ StringUtils.arrayToDelimitedString(params, "_");
}
};
}
@Override
public String resolvePlaceholder(String placeholderName) {
Object replacement = this.constraint.getConfiguration().get(placeholderName);
if (replacement == null) {
return null;
}
if (replacement.getClass().isArray()) {
return StringUtils.arrayToDelimitedString((Object[]) replacement, ", ");
}
return replacement.toString();
}
private String getResourceString(String[] gav, boolean transitive) {
//if not transitive, use type "pom"
String[] newGav = new String[Math.max(4, gav.length)];
System.arraycopy(gav, 0, newGav, 0, gav.length);
if (!transitive) {
newGav[3] = "pom";
} else {
if (newGav[3] == null) {
newGav[3] = "jar";
}
}
return StringUtils.arrayToDelimitedString(newGav, GAV_DELIMITER);
}
@Override
public String getAsText() {
return StringUtils.arrayToDelimitedString(ObjectUtils.toObjectArray(getValue()), this.separator);
}
public Object generate(Object target, Method method, Object... params) {
return target.getClass().getSimpleName() + "_" + method.getName() + "_"
+ StringUtils.arrayToDelimitedString(params, "_");
}
public String getCommandString() {
return StringUtils.arrayToDelimitedString(getCommand().toArray(), " ");
}
private String sse(String... values) {
return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
}
private String sse(String... values) {
return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
}
/**
* Set multiple JAXB context paths. The given array of context paths gets
* converted to a colon-delimited string, as supported by JAXB.
*/
public void setContextPaths(String... contextPaths) {
Assert.notEmpty(contextPaths, "'contextPaths' must not be empty");
this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":");
}
private String sse(String... values) {
return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
}
/**
* Return an error message string, concatenating all messages
* separated by the given delimiter.
* @param delimiter separator string, e.g. ", " or "<br>"
* @return the error message string
*/
public String getErrorMessagesAsString(String delimiter) {
return StringUtils.arrayToDelimitedString(initErrorMessages(), delimiter);
}
/**
* Return an error message string, concatenating all messages
* separated by the given delimiter.
* @param delimiter separator string, e.g. ", " or "<br>"
* @return the error message string
*/
public String getErrorMessagesAsString(String delimiter) {
initErrorMessages();
return StringUtils.arrayToDelimitedString(this.errorMessages, delimiter);
}