Java 5 code style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.mail;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,7 +32,7 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public class MailSendException extends MailException {
|
||||
|
||||
private transient Map failedMessages;
|
||||
private transient final Map<Object, Exception> failedMessages;
|
||||
|
||||
private Exception[] messageExceptions;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class MailSendException extends MailException {
|
||||
* @param msg the detail message
|
||||
*/
|
||||
public MailSendException(String msg) {
|
||||
super(msg);
|
||||
this(msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +52,7 @@ public class MailSendException extends MailException {
|
||||
*/
|
||||
public MailSendException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.failedMessages = new LinkedHashMap<Object, Exception>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,10 +63,10 @@ public class MailSendException extends MailException {
|
||||
* @param failedMessages Map of failed messages as keys and thrown
|
||||
* exceptions as values
|
||||
*/
|
||||
public MailSendException(Map failedMessages) {
|
||||
public MailSendException(Map<Object, Exception> failedMessages) {
|
||||
super(null);
|
||||
this.failedMessages = new LinkedHashMap(failedMessages);
|
||||
this.messageExceptions = (Exception[]) failedMessages.values().toArray(new Exception[failedMessages.size()]);
|
||||
this.failedMessages = new LinkedHashMap<Object, Exception>(failedMessages);
|
||||
this.messageExceptions = failedMessages.values().toArray(new Exception[failedMessages.size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,13 +84,12 @@ public class MailSendException extends MailException {
|
||||
* <p><b>NOTE:</b> This Map will not be available after serialization.
|
||||
* Use {@link #getMessageExceptions()} in such a scenario, which will
|
||||
* be available after serialization as well.
|
||||
* @return the Map of failed messages as keys and thrown exceptions as
|
||||
* values, or an empty Map if no failed messages
|
||||
* @return the Map of failed messages as keys and thrown exceptions as values
|
||||
* @see SimpleMailMessage
|
||||
* @see javax.mail.internet.MimeMessage
|
||||
*/
|
||||
public final Map getFailedMessages() {
|
||||
return (this.failedMessages != null ? this.failedMessages : Collections.EMPTY_MAP);
|
||||
public final Map<Object, Exception> getFailedMessages() {
|
||||
return this.failedMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +111,7 @@ public class MailSendException extends MailException {
|
||||
return super.getMessage();
|
||||
}
|
||||
else {
|
||||
StringBuffer sb = new StringBuffer("Failed messages: ");
|
||||
StringBuilder sb = new StringBuilder("Failed messages: ");
|
||||
for (int i = 0; i < this.messageExceptions.length; i++) {
|
||||
Exception subEx = this.messageExceptions[i];
|
||||
sb.append(subEx.toString());
|
||||
@@ -130,7 +129,7 @@ public class MailSendException extends MailException {
|
||||
return super.toString();
|
||||
}
|
||||
else {
|
||||
StringBuffer sb = new StringBuffer(getClass().getName());
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
sb.append("; nested exceptions (").append(this.messageExceptions.length).append(") are:");
|
||||
for (int i = 0; i < this.messageExceptions.length; i++) {
|
||||
Exception subEx = this.messageExceptions[i];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -201,7 +201,7 @@ public class SimpleMailMessage implements MailMessage, Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("SimpleMailMessage: ");
|
||||
StringBuilder sb = new StringBuilder("SimpleMailMessage: ");
|
||||
sb.append("from=").append(this.from).append("; ");
|
||||
sb.append("replyTo=").append(this.replyTo).append("; ");
|
||||
sb.append("to=").append(StringUtils.arrayToCommaDelimitedString(this.to)).append("; ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -298,14 +298,13 @@ public class JavaMailSenderImpl implements JavaMailSender {
|
||||
}
|
||||
|
||||
public void send(SimpleMailMessage[] simpleMessages) throws MailException {
|
||||
List mimeMessages = new ArrayList(simpleMessages.length);
|
||||
for (int i = 0; i < simpleMessages.length; i++) {
|
||||
SimpleMailMessage simpleMessage = simpleMessages[i];
|
||||
List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(simpleMessages.length);
|
||||
for (SimpleMailMessage simpleMessage : simpleMessages) {
|
||||
MimeMailMessage message = new MimeMailMessage(createMimeMessage());
|
||||
simpleMessage.copyTo(message);
|
||||
mimeMessages.add(message.getMimeMessage());
|
||||
}
|
||||
doSend((MimeMessage[]) mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages);
|
||||
doSend(mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages);
|
||||
}
|
||||
|
||||
|
||||
@@ -348,13 +347,13 @@ public class JavaMailSenderImpl implements JavaMailSender {
|
||||
|
||||
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException {
|
||||
try {
|
||||
List mimeMessages = new ArrayList(mimeMessagePreparators.length);
|
||||
for (int i = 0; i < mimeMessagePreparators.length; i++) {
|
||||
List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(mimeMessagePreparators.length);
|
||||
for (MimeMessagePreparator preparator : mimeMessagePreparators) {
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
mimeMessagePreparators[i].prepare(mimeMessage);
|
||||
preparator.prepare(mimeMessage);
|
||||
mimeMessages.add(mimeMessage);
|
||||
}
|
||||
send((MimeMessage[]) mimeMessages.toArray(new MimeMessage[mimeMessages.size()]));
|
||||
send(mimeMessages.toArray(new MimeMessage[mimeMessages.size()]));
|
||||
}
|
||||
catch (MailException ex) {
|
||||
throw ex;
|
||||
@@ -383,7 +382,7 @@ public class JavaMailSenderImpl implements JavaMailSender {
|
||||
* in case of failure when sending a message
|
||||
*/
|
||||
protected void doSend(MimeMessage[] mimeMessages, Object[] originalMessages) throws MailException {
|
||||
Map failedMessages = new LinkedHashMap();
|
||||
Map<Object, Exception> failedMessages = new LinkedHashMap<Object, Exception>();
|
||||
try {
|
||||
Transport transport = getTransport(getSession());
|
||||
transport.connect(getHost(), getPort(), getUsername(), getPassword());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.ui.velocity;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -33,6 +32,7 @@ import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class VelocityEngineFactory {
|
||||
|
||||
private Resource configLocation;
|
||||
|
||||
private final Map velocityProperties = new HashMap();
|
||||
private final Map<String, Object> velocityProperties = new HashMap<String, Object>();
|
||||
|
||||
private String resourceLoaderPath;
|
||||
|
||||
@@ -110,7 +110,7 @@ public class VelocityEngineFactory {
|
||||
* @see #setResourceLoaderPath
|
||||
*/
|
||||
public void setVelocityProperties(Properties velocityProperties) {
|
||||
setVelocityPropertiesMap(velocityProperties);
|
||||
CollectionUtils.mergePropertiesIntoMap(velocityProperties, this.velocityProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ public class VelocityEngineFactory {
|
||||
* like "ds.resource.loader.instance".
|
||||
* @see #setVelocityProperties
|
||||
*/
|
||||
public void setVelocityPropertiesMap(Map velocityPropertiesMap) {
|
||||
public void setVelocityPropertiesMap(Map<String, Object> velocityPropertiesMap) {
|
||||
if (velocityPropertiesMap != null) {
|
||||
this.velocityProperties.putAll(velocityPropertiesMap);
|
||||
}
|
||||
@@ -214,14 +214,14 @@ public class VelocityEngineFactory {
|
||||
*/
|
||||
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
|
||||
VelocityEngine velocityEngine = newVelocityEngine();
|
||||
Properties props = new Properties();
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
|
||||
// Load config file if set.
|
||||
if (this.configLocation != null) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading Velocity config from [" + this.configLocation + "]");
|
||||
}
|
||||
PropertiesLoaderUtils.fillProperties(props, this.configLocation);
|
||||
CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
|
||||
}
|
||||
|
||||
// Merge local properties if set.
|
||||
@@ -240,13 +240,8 @@ public class VelocityEngineFactory {
|
||||
}
|
||||
|
||||
// Apply properties to VelocityEngine.
|
||||
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
if (!(entry.getKey() instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal property key [" + entry.getKey() + "]: only Strings allowed");
|
||||
}
|
||||
velocityEngine.setProperty((String) entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, Object> entry : props.entrySet()) {
|
||||
velocityEngine.setProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
postProcessVelocityEngine(velocityEngine);
|
||||
@@ -301,7 +296,7 @@ public class VelocityEngineFactory {
|
||||
// Try to load via the file system, fall back to SpringResourceLoader
|
||||
// (for hot detection of template changes, if possible).
|
||||
try {
|
||||
StringBuffer resolvedPath = new StringBuffer();
|
||||
StringBuilder resolvedPath = new StringBuilder();
|
||||
String[] paths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath);
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
String path = paths[i];
|
||||
|
||||
Reference in New Issue
Block a user