Skip to content
Browse files

Continued improvement of the MAIL module: better readable null.empty …

…string checks, probably better to use the isBlank() method.
  • Loading branch information...
1 parent 93e9e8f commit 656272e361a57996be9458ac0c7a054ff6672fc8 @dizzzz dizzzz committed Jul 9, 2014
View
17 extensions/modules/src/org/exist/xquery/modules/mail/MessageListFunctions.java
@@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
-
import javax.mail.Address;
import javax.mail.FetchProfile;
import javax.mail.Flags;
@@ -49,7 +48,7 @@
import javax.mail.search.SearchTerm;
import javax.mail.search.SentDateTerm;
import javax.mail.search.SubjectTerm;
-
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.exist.dom.QName;
import org.exist.memtree.MemTreeBuilder;
@@ -637,7 +636,7 @@ private SearchTerm parseRecipientTerm( Node terms ) throws XPathException
String pattern = ((Element)terms).getAttribute( "pattern" );
String type = ((Element)terms).getAttribute( "recipientType" );
- if( type == null || type.length() == 0 ) {
+ if( StringUtils.isEmpty(type) ) {
throw( new XPathException(this, "recipientType not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
@@ -670,7 +669,7 @@ private SearchTerm parseHeaderTerm( Node terms ) throws XPathException
String pattern = ((Element)terms).getAttribute( "pattern" );
String name = ((Element)terms).getAttribute( "name" );
- if( name == null || name.length() == 0 ) {
+ if( StringUtils.isEmpty(name) ) {
throw( new XPathException(this, "name not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
@@ -691,7 +690,7 @@ private SearchTerm parseFlagTerm( Node terms ) throws XPathException
String flag = ((Element)terms).getAttribute( "flag" );
String value = ((Element)terms).getAttribute( "value" );
- if( value == null || value.length() == 0 ) {
+ if( StringUtils.isEmpty(value) ) {
throw( new XPathException(this, "value not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
@@ -728,11 +727,11 @@ private SearchTerm parseSentDateTerm( Node terms ) throws XPathException
String value = ((Element)terms).getAttribute( "date" );
String format = ((Element)terms).getAttribute( "format" );
- if( value == null || value.length() == 0 ) {
+ if( StringUtils.isEmpty(value) ) {
throw( new XPathException(this, "value not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
- if( format == null || format.length() == 0 ) {
+ if( StringUtils.isEmpty(format) ) {
throw( new XPathException(this, "format not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
@@ -760,11 +759,11 @@ private SearchTerm parseReceivedDateTerm( Node terms ) throws XPathException
String value = ((Element)terms).getAttribute( "date" );
String format = ((Element)terms).getAttribute( "format" );
- if( value == null || value.length() == 0 ) {
+ if( StringUtils.isEmpty(value) ) {
throw( new XPathException(this, "value not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
- if( format == null || format.length() == 0 ) {
+ if( StringUtils.isEmpty(format) ) {
throw( new XPathException(this, "format not specified for term with type: " + ((Element)terms).getAttribute( "type" ) ) );
}
View
32 extensions/modules/src/org/exist/xquery/modules/mail/SendEmailFunction.java
@@ -22,16 +22,10 @@
package org.exist.xquery.modules.mail;
-import org.apache.log4j.Logger;
-import org.exist.dom.QName;
-import org.exist.util.Base64Encoder;
-import org.exist.util.MimeTable;
-import org.exist.xquery.*;
-import org.exist.xquery.functions.system.GetVersion;
-import org.exist.xquery.value.*;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
+import java.io.*;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.*;
import javax.activation.DataHandler;
import javax.mail.*;
import javax.mail.internet.*;
@@ -41,10 +35,16 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import java.io.*;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.util.*;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+import org.exist.dom.QName;
+import org.exist.util.Base64Encoder;
+import org.exist.util.MimeTable;
+import org.exist.xquery.*;
+import org.exist.xquery.functions.system.GetVersion;
+import org.exist.xquery.value.*;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
//send-email specific imports
@@ -936,11 +936,11 @@ else if(bodyPart.getLocalName().equals("xhtml"))
multibody.addBodyPart(body);
}
- if (charset == null || charset.length() == 0) {
+ if (StringUtils.isEmpty(charset)) {
charset = "UTF-8";
}
- if (encoding == null || encoding.length() == 0) {
+ if (StringUtils.isEmpty(encoding)) {
encoding = "quoted-printable";
}

0 comments on commit 656272e

Please sign in to comment.
Something went wrong with that request. Please try again.