Author: dion Date: Wed Jun 22 07:23:54 2005 New Revision: 191951 URL: http://svn.apache.org/viewcvs?rev=191951&view=rev Log: Bug 34918: Checkstyle/Javadoc issues
Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/ByteArrayDataSource.java jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/EmailException.java jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/ByteArrayDataSource.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/ByteArrayDataSource.java?rev=191951&r1=191950&r2=191951&view=diff ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/ByteArrayDataSource.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/ByteArrayDataSource.java Wed Jun 22 07:23:54 2005 @@ -40,15 +40,15 @@ */ public class ByteArrayDataSource implements DataSource { + /** define the buffer size */ + public static final int BUFFER_SIZE = 512; + /** Stream containg the Data */ - private ByteArrayOutputStream baos = null; + private ByteArrayOutputStream baos; /** Content-type. */ private String type = "application/octet-stream"; - /** define the buffer size */ - public static final int BUFFER_SIZE = 512; - /** * Create a datasource from a byte array. * @@ -91,6 +91,41 @@ } /** + * Create a datasource from a String. + * + * @param data A String. + * @param aType A String. + * @throws IOException IOException + */ + public ByteArrayDataSource(String data, String aType) throws IOException + { + this.type = aType; + + try + { + baos = new ByteArrayOutputStream(); + + // Assumption that the string contains only ASCII + // characters! Else just pass in a charset into this + // constructor and use it in getBytes(). + baos.write(data.getBytes("iso-8859-1")); + baos.flush(); + baos.close(); + } + catch (UnsupportedEncodingException uex) + { + throw new IOException("The Character Encoding is not supported."); + } + finally + { + if (baos != null) + { + baos.close(); + } + } + } + + /** * Create a datasource from an input stream. * * @param aIs An InputStream. @@ -144,40 +179,7 @@ } } - /** - * Create a datasource from a String. - * - * @param data A String. - * @param aType A String. - * @throws IOException IOException - */ - public ByteArrayDataSource(String data, String aType) throws IOException - { - this.type = aType; - try - { - baos = new ByteArrayOutputStream(); - - // Assumption that the string contains only ASCII - // characters! Else just pass in a charset into this - // constructor and use it in getBytes(). - baos.write(data.getBytes("iso-8859-1")); - baos.flush(); - baos.close(); - } - catch (UnsupportedEncodingException uex) - { - throw new IOException("The Character Encoding is not supported."); - } - finally - { - if (baos != null) - { - baos.close(); - } - } - } /** * Get the content type. @@ -186,7 +188,7 @@ */ public String getContentType() { - return (type == null ? "application/octet-stream" : type); + return type == null ? "application/octet-stream" : type; } /** @@ -225,4 +227,4 @@ baos = new ByteArrayOutputStream(); return baos; } -} \ No newline at end of file +} Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?rev=191951&r1=191950&r2=191951&view=diff ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java Wed Jun 22 07:23:54 2005 @@ -1,7 +1,7 @@ /* * Copyright 2001-2005 The Apache Software Foundation * - * Licensed under the Apache License, Version 2.0 ( the "License" ); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -127,14 +127,11 @@ protected String contentType; /** Set session debugging on or off */ - protected boolean debug = false; + protected boolean debug; /** Sent date */ protected Date sentDate; - /** The Session to mail with */ - private Session session; - /** * Instance of an <code>Authenticator</code> object that will be used * when authentication is requested from the mail server. @@ -148,7 +145,7 @@ protected String hostName; /** - * The port number of the mail server to connect to. + * The port number of the mail server to connect to. * Defaults to the standard port ( 25 ). */ protected String smtpPort = "25"; @@ -165,13 +162,13 @@ /** List of "replyTo" email adresses */ protected List replyList = new ArrayList(); - /** - * Address to which undeliverable mail should be sent. + /** + * Address to which undeliverable mail should be sent. * Because this is handled by JavaMail as a String property * in the mail session, this property is of type <code>String</code> * rather than <code>InternetAddress</code>. */ - protected String bounceAddress = null; + protected String bounceAddress; /** * Used to specify the mail headers. Example: @@ -187,13 +184,16 @@ */ /** */ - protected boolean popBeforeSmtp = false; + protected boolean popBeforeSmtp; /** */ - protected String popHost = null; + protected String popHost; /** */ - protected String popUsername = null; + protected String popUsername; /** */ - protected String popPassword = null; + protected String popPassword; + + /** The Session to mail with */ + private Session session; /** * Setting to true will enable the display of debug information. @@ -339,7 +339,7 @@ * Initialise a mailsession object * * @return A Session. - * @throws EmailException thrown when host name was not set + * @throws EmailException thrown when host name was not set. */ protected Session getMailSession() throws EmailException { @@ -373,34 +373,35 @@ properties.setProperty(MAIL_SMTP_FROM, this.bounceAddress); } - // changed this (back) to getInstance due to security exceptions + // changed this (back) to getInstance due to security exceptions // caused when testing using maven this.session = Session.getInstance(properties, this.authenticator); } return this.session; } - + /** - * Creates a InternetAddress - * @param email An Email - * @param name A Name. - * @return An internet address - * @throws EmailException thrown when the address supplied or name were invalid - */ - private InternetAddress createInternetAddress(String email, String name) + * Creates a InternetAddress. + * + * @param email An email address. + * @param name A name. + * @return An internet address. + * @throws EmailException Thrown when the address supplied or name were invalid. + */ + private InternetAddress createInternetAddress(String email, String name) throws EmailException { InternetAddress address = null; - - try + + try { // check name input if (!StringUtils.isNotEmpty(name)) { name = email; } - + if (StringUtils.isNotEmpty(this.charset)) { address = new InternetAddress(email, name, this.charset); @@ -409,7 +410,7 @@ { address = new InternetAddress(email, name); } - + address.validate(); } catch (Exception e) @@ -418,17 +419,17 @@ } return address; } - - + + /** * Set the FROM field of the email. * * @param email A String. * @return An Email. - * @throws EmailException Indicates an invalid email address + * @throws EmailException Indicates an invalid email address. */ - public Email setFrom(String email) - throws EmailException + public Email setFrom(String email) + throws EmailException { return setFrom(email, null); } @@ -438,10 +439,10 @@ * * @param email A String. * @param name A String. + * @throws EmailException Indicates an invalid email address. * @return An Email. - * @throws EmailException Indicates an invalid email address */ - public Email setFrom(String email, String name) + public Email setFrom(String email, String name) throws EmailException { this.fromAddress = createInternetAddress(email, name); @@ -453,10 +454,10 @@ * Add a recipient TO to the email. * * @param email A String. + * @throws EmailException Indicates an invalid email address. * @return An Email. - * @throws EmailException Indicates an invalid email address */ - public Email addTo(String email) + public Email addTo(String email) throws EmailException { return addTo(email, null); @@ -467,23 +468,22 @@ * * @param email A String. * @param name A String. + * @throws EmailException Indicates an invalid email address. * @return An Email. - * @throws EmailException Indicates an invalid email address */ - public Email addTo(String email, String name) + public Email addTo(String email, String name) throws EmailException { this.toList.add(createInternetAddress(email, name)); - return this; } /** - * Set a list of "TO" addresses + * Set a list of "TO" addresses. * - * @param aCollection collection of InternetAddress objects + * @param aCollection collection of InternetAddress objects. + * @throws EmailException Indicates an invalid email address. * @return An Email. - * @throws EmailException Indicates an invalid email address */ public Email setTo(Collection aCollection) throws EmailException { @@ -501,9 +501,9 @@ * * @param email A String. * @return An Email. - * @throws EmailException Indicates an invalid email address + * @throws EmailException Indicates an invalid email address. */ - public Email addCc(String email) + public Email addCc(String email) throws EmailException { return this.addCc(email, null); @@ -514,23 +514,23 @@ * * @param email A String. * @param name A String. + * @throws EmailException Indicates an invalid email address. * @return An Email. - * @throws EmailException Indicates an invalid email address + */ - public Email addCc(String email, String name) + public Email addCc(String email, String name) throws EmailException { this.ccList.add(createInternetAddress(email, name)); - return this; } /** - * Set a list of "CC" addresses + * Set a list of "CC" addresses. * - * @param aCollection collection of InternetAddress objects - * @return An EmailException. - * @throws EmailException Indicates an invalid email address + * @param aCollection collection of InternetAddress objects. + * @return An Email. + * @throws EmailException Indicates an invalid email address. */ public Email setCc(Collection aCollection) throws EmailException { @@ -550,7 +550,7 @@ * @return An Email. * @throws EmailException Indicates an invalid email address */ - public Email addBcc(String email) + public Email addBcc(String email) throws EmailException { return this.addBcc(email, null); @@ -564,12 +564,10 @@ * @return An Email. * @throws EmailException Indicates an invalid email address */ - public Email addBcc(String email, String name) + public Email addBcc(String email, String name) throws EmailException { - this.bccList.add(createInternetAddress(email, name)); - return this; } @@ -598,7 +596,7 @@ * @return An Email. * @throws EmailException Indicates an invalid email address */ - public Email addReplyTo(String email) + public Email addReplyTo(String email) throws EmailException { return this.addReplyTo(email, null); @@ -615,12 +613,11 @@ public Email addReplyTo(String email, String name) throws EmailException { - this.replyList.add(createInternetAddress(email, name)); - return this; } + /** * Used to specify the mail headers. Example: * @@ -707,7 +704,7 @@ * * @param msg A String. * @return An Email. - * @throws EmailException generic exception + * @throws EmailException generic exception. */ public abstract Email setMsg(String msg) throws EmailException; @@ -718,11 +715,11 @@ */ public void send() throws EmailException { - try + try { this.getMailSession(); this.message = new MimeMessage(this.session); - + if (StringUtils.isNotEmpty(this.subject)) { if (StringUtils.isNotEmpty(this.charset)) @@ -734,7 +731,7 @@ this.message.setSubject(this.subject); } } - + // ======================================================== // Start of replacement code if (this.content != null) @@ -751,7 +748,7 @@ { this.message.setContent("", Email.TEXT_PLAIN); } - + if (this.fromAddress != null) { this.message.setFrom(this.fromAddress); @@ -804,24 +801,24 @@ this.message.addHeader(name, value); } } - + if (this.message.getSentDate() == null) { this.message.setSentDate(getSentDate()); } - + if (this.popBeforeSmtp) { Store store = session.getStore("pop3"); store.connect(this.popHost, this.popUsername, this.popPassword); } - + Transport.send(this.message); } catch (MessagingException me) { throw new EmailException(me); - } + } } /** @@ -856,21 +853,22 @@ * Utility to copy List of known InternetAddress objects into an * array. * - * @param aList A List of InternetAddress. + * @param list A List. * @return An InternetAddress[]. */ - protected InternetAddress[] toInternetAddressArray(List aList) + protected InternetAddress[] toInternetAddressArray(List list) { InternetAddress[] ia = - (InternetAddress[]) aList.toArray(new InternetAddress[0]); + (InternetAddress[]) list.toArray(new InternetAddress[0]); return ia; } /** - * Set details regarding "pop3 before smtp" authentication - * @param newPopBeforeSmtp Wether or not to log into pop3 - * server before sending mail + * Set details regarding "pop3 before smtp" authentication. + * + * @param newPopBeforeSmtp Wether or not to log into pop3 + * server before sending mail. * @param newPopHost The pop3 host to use. * @param newPopUsername The pop3 username. * @param newPopPassword The pop3 password. @@ -886,4 +884,5 @@ this.popUsername = newPopUsername; this.popPassword = newPopPassword; } -} \ No newline at end of file +} + Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/EmailException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/EmailException.java?rev=191951&r1=191950&r2=191951&view=diff ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/EmailException.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/EmailException.java Wed Jun 22 07:23:54 2005 @@ -1,7 +1,7 @@ /* * Copyright 2001-2004 The Apache Software Foundation * - * Licensed under the Apache License, Version 2.0 ( the "License" ); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -21,25 +21,25 @@ * EmailException * @author jakarta-commons */ -public class EmailException extends NestableException +public class EmailException extends NestableException { /** */ public EmailException() { super(); } - + /** - * + * * @param msg msg */ public EmailException(String msg) { super(msg); } - + /** - * + * * @param msg msg * @param cause cause */ @@ -47,14 +47,14 @@ { super(msg, cause); } - + /** - * + * * @param cause cause */ public EmailException(Throwable cause) { super(cause); } - + } Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java?rev=191951&r1=191950&r2=191951&view=diff ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java Wed Jun 22 07:23:54 2005 @@ -57,6 +57,9 @@ */ public class HtmlEmail extends MultiPartEmail { + /** Defintion of the length of generated CID's */ + public static final int CID_LENGTH = 10; + /** * Text part of the message. This will be used as alternative text if * the email client does not support HTML messages. @@ -69,9 +72,6 @@ /** Embeded images */ protected List inlineImages = new ArrayList(); - /** Defintion of the length of generated CID's */ - public static final int CID_LENGTH = 10; - /** * Set the text content. * @@ -105,7 +105,7 @@ { throw new EmailException("Invalid message supplied"); } - + this.html = aHtml; return this; } @@ -190,13 +190,12 @@ String cid = RandomStringUtils.randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase(); mbp.addHeader("Content-ID", "<" + cid + ">"); this.inlineImages.add(mbp); - return cid; - } + return cid; + } catch (MessagingException me) { throw new EmailException(me); } - } /** @@ -208,7 +207,7 @@ { try { - // if the email has attachments then the base type is mixed, + // if the email has attachments then the base type is mixed, // otherwise it should be related if (this.isBoolHasAttachments()) { @@ -235,7 +234,7 @@ { MimeMultipart container = this.getContainer(); MimeMultipart subContainer = null; - MimeMultipart subContainerHTML = new MimeMultipart("related"); + MimeMultipart subContainerHTML = new MimeMultipart("related"); BodyPart msgHtml = null; BodyPart msgText = null; @@ -261,16 +260,16 @@ if (StringUtils.isNotEmpty(this.html)) { - if (this.inlineImages.size() > 0) - { - msgHtml = new MimeBodyPart(); - subContainerHTML.addBodyPart(msgHtml); - } - else - { - msgHtml = new MimeBodyPart(); - subContainer.addBodyPart(msgHtml); - } + if (this.inlineImages.size() > 0) + { + msgHtml = new MimeBodyPart(); + subContainerHTML.addBodyPart(msgHtml); + } + else + { + msgHtml = new MimeBodyPart(); + subContainer.addBodyPart(msgHtml); + } if (StringUtils.isNotEmpty(this.charset)) { @@ -284,20 +283,20 @@ } Iterator iter = this.inlineImages.iterator(); - while (iter.hasNext()) - { - subContainerHTML.addBodyPart((BodyPart) iter.next()); - } + while (iter.hasNext()) + { + subContainerHTML.addBodyPart((BodyPart) iter.next()); + } } // add sub containers to message this.addPart(subContainer, 0); - if (this.inlineImages.size() > 0) - { - // add sub container to message - this.addPart(subContainerHTML, 1); - } + if (this.inlineImages.size() > 0) + { + // add sub container to message + this.addPart(subContainerHTML, 1); + } } /** Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java?rev=191951&r1=191950&r2=191951&view=diff ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java Wed Jun 22 07:23:54 2005 @@ -49,22 +49,23 @@ public class MultiPartEmail extends Email { /** Body portion of the email. */ - private MimeMultipart container = null; + private MimeMultipart container; /** The message container. */ - private MimeBodyPart primaryBodyPart = null; + private MimeBodyPart primaryBodyPart; /** The MIME subtype. */ - private String subType = null; + private String subType; /** Indicates if the message has been initialized */ - private boolean initialized = false; + private boolean initialized; /** Indicates if attachments have been added to the message */ - private boolean boolHasAttachments = false; - + private boolean boolHasAttachments; + /** * Set the MIME subtype of the email. + * * @param aSubType MIME subtype of the email */ public void setSubType(String aSubType) @@ -74,6 +75,7 @@ /** * Get the MIME subtype of the email. + * * @return MIME subtype of the email */ public String getSubType() @@ -83,6 +85,7 @@ /** * Add a new part to the email. + * * @param content The content. * @param contentType The content type. * @return An Email. @@ -108,6 +111,7 @@ /** * Add a new part to the email. + * * @param multipart The MimeMultipart. * @return An Email. * @throws EmailException see javax.mail.internet.MimeBodyPart @@ -115,22 +119,34 @@ */ public Email addPart(MimeMultipart multipart) throws EmailException { - try{ + try + { return addPart(multipart, getContainer().getCount()); } - catch( MessagingException me ){ + catch (MessagingException me) + { throw new EmailException(me); } } + /** + * Add a new part to the email. + * + * @param multipart The part to add. + * @param index The index to add at. + * @return The email. + * @throws EmailException An error occured while adding the part. + */ public Email addPart(MimeMultipart multipart, int index) throws EmailException { MimeBodyPart bodyPart = new MimeBodyPart(); - try { + try + { bodyPart.setContent(multipart); getContainer().addBodyPart(bodyPart, index); } - catch (MessagingException me){ + catch (MessagingException me) + { throw new EmailException(me); } @@ -139,9 +155,6 @@ /** * Initialize the multipart email. - * - * @throws EmailException see javax.mail.internet.MimeBodyPart - * for defintions */ protected void init() { @@ -151,7 +164,7 @@ } container = new MimeMultipart(); - super.setContent(container); + super.setContent(container); initialized = true; } @@ -171,7 +184,8 @@ { throw new EmailException("Invalid message supplied"); } - try { + try + { if (StringUtils.isNotEmpty(charset)) { getPrimaryBodyPart().setText(msg, charset); @@ -181,9 +195,10 @@ getPrimaryBodyPart().setText(msg); } } - catch (MessagingException me){ + catch (MessagingException me) + { throw new EmailException(me); - } + } return this; } @@ -195,13 +210,14 @@ */ public void send() throws EmailException { - try { + try + { if (primaryBodyPart != null) { // before a multipart message can be sent, we must make sure that // the content for the main body part was actually set. If not, // an IOException will be thrown during super.send(). - + MimeBodyPart body = this.getPrimaryBodyPart(); Object content = null; try @@ -215,15 +231,16 @@ content = null; } } - + if (subType != null) { getContainer().setSubType(subType); } - + super.send(); } - catch (MessagingException me){ + catch (MessagingException me) + { throw new EmailException(me); } } @@ -247,7 +264,7 @@ } URL url = attachment.getURL(); - + if (url == null) { String fileName = null; @@ -391,7 +408,8 @@ name = ds.getName(); } MimeBodyPart mbp = new MimeBodyPart(); - try { + try + { getContainer().addBodyPart(mbp); mbp.setDisposition(disposition); @@ -399,11 +417,12 @@ mbp.setDescription(description); mbp.setDataHandler(new DataHandler(ds)); } - catch (MessagingException me){ + catch (MessagingException me) + { throw new EmailException(me); - } + } this.boolHasAttachments = true; - + return this; } @@ -411,8 +430,7 @@ * Gets first body part of the message. * * @return The primary body part. - * @throws EmailException see javax.mail.internet.MimeBodyPart - * for defintions + * @throws MessagingException An error occured while getting the primary body part. */ protected MimeBodyPart getPrimaryBodyPart() throws MessagingException { @@ -420,7 +438,7 @@ { init(); } - + // Add the first body part to the message. The fist body part must be if (this.primaryBodyPart == null) { @@ -435,8 +453,6 @@ * Gets the message container. * * @return The message container. - * @throws EmailException see javax.mail.internet.MimeBodyPart - * for defintions */ protected MimeMultipart getContainer() { @@ -446,7 +462,7 @@ } return container; } - + /** * @return boolHasAttachments @@ -463,5 +479,4 @@ { boolHasAttachments = b; } - -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]