git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902789 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_3
@@ -25,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; | |||
import org.apache.poi.openxml4j.opc.OPCPackage; | |||
import org.apache.poi.openxml4j.opc.PackageAccess; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.util.XMLHelper; | |||
import org.apache.poi.xssf.eventusermodel.XSSFReader; | |||
import org.apache.poi.xssf.model.SharedStrings; | |||
@@ -132,7 +133,7 @@ public class FromHowTo { | |||
throws SAXException { | |||
// Process the last contents as required. | |||
// Do now, as characters() may be called more than once | |||
if(nextIsString && !lastContents.trim().isEmpty()) { | |||
if(nextIsString && StringUtil.isNotBlank(lastContents)) { | |||
Integer idx = Integer.valueOf(lastContents); | |||
lastContents = lruCache.get(idx); | |||
if (lastContents == null && !lruCache.containsKey(idx)) { |
@@ -61,6 +61,7 @@ import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; | |||
import org.apache.poi.openxml4j.util.ZipEntrySource; | |||
import org.apache.poi.util.IOUtils; | |||
import org.apache.poi.util.NotImplemented; | |||
import org.apache.poi.util.StringUtil; | |||
/** | |||
* Represents a container that can store multiple data objects. | |||
@@ -234,7 +235,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { | |||
*/ | |||
public static OPCPackage open(String path, PackageAccess access) | |||
throws InvalidFormatException, InvalidOperationException { | |||
if (path == null || path.trim().isEmpty()) { | |||
if (StringUtil.isBlank(path)) { | |||
throw new IllegalArgumentException("'path' must be given"); | |||
} | |||
@@ -458,8 +459,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { | |||
return; | |||
} | |||
if (this.originalPackagePath != null | |||
&& !this.originalPackagePath.trim().isEmpty()) { | |||
if (StringUtil.isNotBlank(this.originalPackagePath)) { | |||
File targetFile = new File(this.originalPackagePath); | |||
if (!targetFile.exists() | |||
|| !(this.originalPackagePath |
@@ -27,6 +27,7 @@ import org.apache.poi.ss.usermodel.RichTextString; | |||
import org.apache.poi.ss.util.CellAddress; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.LittleEndian; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; | |||
import org.apache.poi.xssf.model.SharedStrings; | |||
import org.apache.poi.xssf.usermodel.XSSFComment; | |||
@@ -226,7 +227,7 @@ public class XSSFBSheetHandler extends XSSFBParser { | |||
private void outputHeaderFooter(XSSFBHeaderFooter headerFooter) { | |||
String text = headerFooter.getString(); | |||
if (text != null && !text.trim().isEmpty()) { | |||
if (StringUtil.isNotBlank(text)) { | |||
handler.headerFooter(text, headerFooter.isHeader(), headerFooter.getHeaderFooterTypeLabel()); | |||
} | |||
} |
@@ -40,6 +40,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; | |||
import org.apache.poi.openxml4j.opc.PackagingURIHelper; | |||
import org.apache.poi.util.LittleEndian; | |||
import org.apache.poi.util.LittleEndianConsts; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.xssf.binary.XSSFBCommentsTable; | |||
import org.apache.poi.xssf.binary.XSSFBParseException; | |||
import org.apache.poi.xssf.binary.XSSFBParser; | |||
@@ -254,7 +255,7 @@ public class XSSFBReader extends XSSFReader { | |||
String relId = sb.toString(); sb.setLength(0); | |||
/*offset +=*/ XSSFBUtils.readXLWideString(data, offset, sb); | |||
String name = sb.toString(); | |||
if (relId.trim().length() > 0) { | |||
if (StringUtil.isNotBlank(relId)) { | |||
sheets.add(new XSSFSheetRef(relId, name)); | |||
} | |||
} | |||
@@ -273,7 +274,7 @@ public class XSSFBReader extends XSSFReader { | |||
sb.setLength(0); | |||
offset += XSSFBUtils.readXLWideString(data, offset, sb); | |||
String name = sb.toString(); | |||
if (relId.trim().length() > 0) { | |||
if (StringUtil.isNotBlank(relId)) { | |||
sheets.add(new XSSFSheetRef(relId, name)); | |||
} | |||
if (offset == data.length) { |
@@ -20,6 +20,7 @@ import java.util.Arrays; | |||
import java.util.regex.Pattern; | |||
import org.apache.poi.ss.usermodel.DataValidationConstraint; | |||
import org.apache.poi.util.StringUtil; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationType; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOperator.Enum; | |||
@@ -180,7 +181,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { | |||
return s; | |||
} | |||
protected static boolean isFormulaEmpty(String formula1) { | |||
return formula1 == null || formula1.trim().length()==0; | |||
return StringUtil.isBlank(formula1); | |||
} | |||
/* (non-Javadoc) |
@@ -27,6 +27,7 @@ import org.apache.poi.ss.util.AreaReference; | |||
import org.apache.poi.ss.util.CellReference; | |||
import org.apache.poi.util.Beta; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.xmlbeans.XmlException; | |||
import org.apache.xmlbeans.XmlOptions; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; | |||
@@ -293,7 +294,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart { | |||
pivotField.setAxis(STAxis.AXIS_COL); | |||
pivotField.setShowAll(false); | |||
if (valueFormat != null && !valueFormat.trim().isEmpty()) { | |||
if (StringUtil.isNotBlank(valueFormat)) { | |||
DataFormat df = parentSheet.getWorkbook().createDataFormat(); | |||
pivotField.setNumFmtId(df.getFormat(valueFormat)); | |||
} | |||
@@ -416,7 +417,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart { | |||
dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue())); | |||
dataField.setName(valueFieldName); | |||
dataField.setFld(columnIndex); | |||
if (valueFormat != null && !valueFormat.trim().isEmpty()) { | |||
if (StringUtil.isNotBlank(valueFormat)) { | |||
DataFormat df = parentSheet.getWorkbook().createDataFormat(); | |||
dataField.setNumFmtId(df.getFormat(valueFormat)); | |||
} |
@@ -90,6 +90,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory; | |||
import org.apache.poi.util.ConditionalExecution.DisabledOnJreEx; | |||
import org.apache.poi.util.IOUtils; | |||
import org.apache.poi.util.LocaleUtil; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.util.TempFile; | |||
import org.apache.poi.xssf.streaming.SXSSFWorkbook; | |||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | |||
@@ -146,7 +147,7 @@ class TestSignatureInfo { | |||
// in the xmlsec jar file | |||
String additionalJar = System.getProperty("additionaljar"); | |||
//System.out.println("Having: " + additionalJar); | |||
assumeTrue(additionalJar == null || additionalJar.trim().length() == 0, | |||
assumeTrue(StringUtil.isBlank(additionalJar), | |||
"Not running TestSignatureInfo because we are testing with additionaljar set to " + additionalJar); | |||
System.setProperty("org.apache.xml.security.ignoreLineBreaks", "true"); | |||
@@ -475,7 +476,7 @@ class TestSignatureInfo { | |||
//set proxy info if any | |||
String proxy = System.getProperty("http_proxy"); | |||
if (proxy != null && proxy.trim().length() > 0) { | |||
if (StringUtil.isNotBlank(proxy)) { | |||
signatureConfig.setProxyUrl(proxy); | |||
} | |||
@@ -779,7 +779,7 @@ public final class TestXWPFParagraph { | |||
str.append(par.getText()).append("\n"); | |||
} | |||
String s = str.toString(); | |||
assertTrue(s.trim().length() > 0, "Having text: \n" + s + "\nTrimmed length: " + s.trim().length()); | |||
assertTrue(StringUtil.isNotBlank(s), "Having text: \n" + s + "\nTrimmed length: " + s.trim().length()); | |||
} | |||
} | |||
@@ -53,6 +53,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import org.apache.poi.util.CodePageUtil; | |||
import org.apache.poi.util.LocaleUtil; | |||
import org.apache.poi.util.StringUtil; | |||
import static org.apache.logging.log4j.util.Unbox.box; | |||
@@ -630,7 +631,7 @@ public class MAPIMessage extends POIReadOnlyDocument { | |||
*/ | |||
public MESSAGE_CLASS getMessageClassEnum() throws ChunkNotFoundException { | |||
String mc = getStringFromChunk(mainChunks.getMessageClass()); | |||
if (mc == null || mc.trim().length() == 0) { | |||
if (StringUtil.isBlank(mc)) { | |||
return MESSAGE_CLASS.UNSPECIFIED; | |||
} else if (mc.equalsIgnoreCase("IPM.Note")) { | |||
return MESSAGE_CLASS.NOTE; |
@@ -52,6 +52,7 @@ import org.apache.poi.hwpf.usermodel.TableRow; | |||
import org.apache.poi.poifs.filesystem.Entry; | |||
import org.apache.poi.util.Beta; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.StringUtil; | |||
import org.w3c.dom.Document; | |||
import org.w3c.dom.Element; | |||
@@ -553,7 +554,7 @@ public abstract class AbstractWordConverter { | |||
} | |||
} | |||
haveAnyText |= text.trim().length() != 0; | |||
haveAnyText |= StringUtil.isNotBlank(text); | |||
} | |||
return haveAnyText; |
@@ -48,6 +48,7 @@ import org.apache.poi.hwpf.usermodel.Table; | |||
import org.apache.poi.hwpf.usermodel.TableCell; | |||
import org.apache.poi.hwpf.usermodel.TableRow; | |||
import org.apache.poi.util.Beta; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.util.XMLHelper; | |||
import org.w3c.dom.Document; | |||
import org.w3c.dom.Element; | |||
@@ -438,7 +439,7 @@ public class WordToFoConverter extends AbstractWordConverter | |||
Text textNode = foDocumentFacade.createText( bulletText ); | |||
inline.appendChild( textNode ); | |||
haveAnyText |= bulletText.trim().length() != 0; | |||
haveAnyText |= StringUtil.isNotBlank(bulletText); | |||
} | |||
haveAnyText = processCharacters( hwpfDocument, currentTableLevel, |
@@ -658,7 +658,7 @@ public class VBAMacroReader implements Closeable { | |||
} catch (EOFException e) { | |||
return; | |||
} | |||
if (mbcs.trim().length() > 0 && unicode.trim().length() > 0) { | |||
if (StringUtil.isNotBlank(mbcs) && StringUtil.isNotBlank(unicode)) { | |||
moduleNames.put(mbcs, unicode); | |||
} | |||
@@ -63,6 +63,7 @@ import org.apache.poi.sl.usermodel.TextShape; | |||
import org.apache.poi.sl.usermodel.TextShape.TextDirection; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.LocaleUtil; | |||
import org.apache.poi.util.StringUtil; | |||
import org.apache.poi.util.Units; | |||
public class DrawTextParagraph implements Drawable { | |||
@@ -242,7 +243,7 @@ public class DrawTextParagraph implements Drawable { | |||
} | |||
public boolean isEmptyParagraph() { | |||
return (lines.isEmpty() || rawText.trim().isEmpty()); | |||
return (lines.isEmpty() || StringUtil.isBlank(rawText)); | |||
} | |||
@Override |
@@ -42,6 +42,7 @@ import org.apache.poi.ss.util.CellRangeAddressBase; | |||
import org.apache.poi.ss.util.CellRangeAddressList; | |||
import org.apache.poi.ss.util.CellReference; | |||
import org.apache.poi.ss.util.SheetUtil; | |||
import org.apache.poi.util.StringUtil; | |||
/** | |||
* Evaluates Data Validation constraints.<p> | |||
@@ -418,7 +419,7 @@ public class DataValidationEvaluator { | |||
* @throws NumberFormatException if the formula is non-numeric when it should be | |||
*/ | |||
private Double evalOrConstant(String formula, DataValidationContext context) throws NumberFormatException { | |||
if (formula == null || formula.trim().isEmpty()) return null; // shouldn't happen, but just in case | |||
if (StringUtil.isBlank(formula)) return null; // shouldn't happen, but just in case | |||
try { | |||
return Double.valueOf(formula); | |||
} catch (NumberFormatException e) { | |||
@@ -433,7 +434,7 @@ public class DataValidationEvaluator { | |||
if (eval instanceof NumberEval) return Double.valueOf(((NumberEval) eval).getNumberValue()); | |||
if (eval instanceof StringEval) { | |||
final String value = ((StringEval) eval).getStringValue(); | |||
if (value == null || value.trim().isEmpty()) return null; | |||
if (StringUtil.isBlank(value)) return null; | |||
// try to parse the cell value as a double and return it | |||
return Double.valueOf(value); | |||
} |
@@ -52,6 +52,7 @@ import org.apache.poi.ss.usermodel.Sheet; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
import org.apache.poi.ss.util.CellReference; | |||
import org.apache.poi.util.LocaleUtil; | |||
import org.apache.poi.util.StringUtil; | |||
/** | |||
* Abstracted and cached version of a Conditional Format rule for use with a | |||
@@ -506,7 +507,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon | |||
try { | |||
String v = cv.getString(); | |||
// see TextFunction.TRIM for implementation | |||
return v == null || v.trim().length() == 0; | |||
return StringUtil.isBlank(v); | |||
} catch (Exception e) { | |||
// not a valid string value, and not a blank cell (that's checked earlier) | |||
return false; | |||
@@ -515,7 +516,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon | |||
try { | |||
String v = cv.getString(); | |||
// see TextFunction.TRIM for implementation | |||
return v != null && v.trim().length() > 0; | |||
return StringUtil.isNotBlank(v); | |||
} catch (Exception e) { | |||
// not a valid string value, but not blank | |||
return true; |
@@ -80,6 +80,7 @@ import org.apache.poi.ss.util.AreaReference; | |||
import org.apache.poi.ss.util.CellReference; | |||
import org.apache.poi.ss.util.CellReference.NameType; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.StringUtil; | |||
/** | |||
* This class parses a formula string into a List of tokens in RPN order. | |||
@@ -255,7 +256,7 @@ public final class FormulaParser { | |||
private RuntimeException expected(String s) { | |||
String msg; | |||
if (look == '=' && _formulaString.substring(0, _pointer-1).trim().length() < 1) { | |||
if (look == '=' && StringUtil.isBlank(_formulaString.substring(0, _pointer-1))) { | |||
msg = "The specified formula '" + _formulaString | |||
+ "' starts with an equals sign which is not allowed."; | |||
} else { |
@@ -29,7 +29,7 @@ import java.util.List; | |||
* Implementation of Excel function TEXTJOIN() | |||
* | |||
* <b>Syntax</b><br> | |||
* <b>TEXTJOIN</b>(<b>delimiter</b>, <b>ignore_empty</b>, <b>text1</b>, <b>[text2]<b>, …)<p> | |||
* <b>TEXTJOIN</b>(<b>delimiter</b>, <b>ignore_empty</b>, <b>text1</b>, <b>[text2]<b>, ...)<p> | |||
* | |||
* <b>delimiter</b> A text string, either empty, or one or more characters enclosed by double quotes, or a reference to a valid text string. | |||
* If a number is supplied, it will be treated as text.<br> |
@@ -48,6 +48,7 @@ import org.apache.poi.ss.formula.ConditionalFormattingEvaluator; | |||
import org.apache.poi.ss.util.DateFormatConverter; | |||
import org.apache.poi.ss.util.NumberToTextConverter; | |||
import org.apache.poi.util.LocaleUtil; | |||
import org.apache.poi.util.StringUtil; | |||
/** | |||
@@ -355,7 +356,7 @@ public class DataFormatter { | |||
int formatIndex = numFmt.getIdx(); | |||
String formatStr = numFmt.getFormat(); | |||
if(formatStr == null || formatStr.trim().length() == 0) { | |||
if(StringUtil.isBlank(formatStr)) { | |||
return null; | |||
} | |||
return getFormat(cell.getNumericCellValue(), formatIndex, formatStr, isDate1904(cell)); | |||
@@ -483,7 +484,7 @@ public class DataFormatter { | |||
} | |||
// Check for special cases | |||
if(formatStr == null || formatStr.trim().isEmpty()) { | |||
if(StringUtil.isBlank(formatStr)) { | |||
return getDefaultFormat(cellValue); | |||
} | |||
@@ -1361,10 +1362,10 @@ public class DataFormatter { | |||
seg2 = result.substring(Math.max(0, len - 7), len - 4); | |||
seg1 = result.substring(Math.max(0, len - 10), Math.max(0, len - 7)); | |||
if(seg1.trim().length() > 0) { | |||
if(StringUtil.isNotBlank(seg1)) { | |||
sb.append('(').append(seg1).append(") "); | |||
} | |||
if(seg2.trim().length() > 0) { | |||
if(StringUtil.isNotBlank(seg2)) { | |||
sb.append(seg2).append('-'); | |||
} | |||
sb.append(seg3); |
@@ -689,4 +689,74 @@ public final class StringUtil { | |||
return prefix + ((newLen == 0) ? "" : new String(string, newOffset, newLen * 2, UTF16LE)); | |||
} | |||
/** | |||
* Gets a CharSequence length or {@code 0} if the CharSequence is | |||
* {@code null}. | |||
* | |||
* copied from commons-lang3 | |||
* | |||
* @param cs | |||
* a CharSequence or {@code null} | |||
* @return CharSequence length or {@code 0} if the CharSequence is | |||
* {@code null}. | |||
*/ | |||
public static int length(final CharSequence cs) { | |||
return cs == null ? 0 : cs.length(); | |||
} | |||
/** | |||
* <p>Checks if a CharSequence is empty (""), null or whitespace only.</p> | |||
* | |||
* <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |||
* | |||
* <pre> | |||
* StringUtil.isBlank(null) = true | |||
* StringUtil.isBlank("") = true | |||
* StringUtil.isBlank(" ") = true | |||
* StringUtil.isBlank("bob") = false | |||
* StringUtil.isBlank(" bob ") = false | |||
* </pre> | |||
* | |||
* copied from commons-lang3 | |||
* | |||
* @param cs the CharSequence to check, may be null | |||
* @return {@code true} if the CharSequence is null, empty or whitespace only | |||
*/ | |||
public static boolean isBlank(final CharSequence cs) { | |||
final int strLen = length(cs); | |||
if (strLen == 0) { | |||
return true; | |||
} | |||
for (int i = 0; i < strLen; i++) { | |||
if (!Character.isWhitespace(cs.charAt(i))) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
/** | |||
* <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p> | |||
* | |||
* <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |||
* | |||
* <pre> | |||
* StringUtil.isNotBlank(null) = false | |||
* StringUtil.isNotBlank("") = false | |||
* StringUtil.isNotBlank(" ") = false | |||
* StringUtil.isNotBlank("bob") = true | |||
* StringUtil.isNotBlank(" bob ") = true | |||
* </pre> | |||
* | |||
* copied from commons-lang3 | |||
* | |||
* @param cs the CharSequence to check, may be null | |||
* @return {@code true} if the CharSequence is | |||
* not empty and not null and not whitespace only | |||
*/ | |||
public static boolean isNotBlank(final CharSequence cs) { | |||
return !isBlank(cs); | |||
} | |||
} |