Fix some IntelliJ and Findbugs warnings: StringBuilder, foreach, append(), ...
test-updates git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
412ae950c2
commit
da595c2343
@ -207,7 +207,7 @@ public abstract class AbstractEscherOptRecord extends EscherRecord
|
||||
|
||||
for ( EscherProperty property : properties )
|
||||
{
|
||||
stringBuilder.append( " " + property.toString() + nl );
|
||||
stringBuilder.append(" ").append(property.toString()).append(nl);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
|
@ -85,12 +85,12 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
|
||||
}
|
||||
|
||||
Constructor<? extends EscherRecord> recordConstructor = recordsMap.get(Short.valueOf(recordId));
|
||||
EscherRecord escherRecord = null;
|
||||
final EscherRecord escherRecord;
|
||||
if (recordConstructor == null) {
|
||||
return new UnknownEscherRecord();
|
||||
}
|
||||
try {
|
||||
escherRecord = recordConstructor.newInstance(new Object[] {});
|
||||
escherRecord = recordConstructor.newInstance();
|
||||
} catch (Exception e) {
|
||||
return new UnknownEscherRecord();
|
||||
}
|
||||
@ -111,9 +111,9 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
|
||||
Map<Short, Constructor<? extends EscherRecord>> result = new HashMap<Short, Constructor<? extends EscherRecord>>();
|
||||
final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
|
||||
|
||||
for (int i = 0; i < recClasses.length; i++) {
|
||||
for (Class<?> recClass : recClasses) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends EscherRecord> recCls = (Class<? extends EscherRecord>) recClasses[i];
|
||||
Class<? extends EscherRecord> recCls = (Class<? extends EscherRecord>) recClass;
|
||||
short sid;
|
||||
try {
|
||||
sid = recCls.getField("RECORD_ID").getShort(null);
|
||||
|
@ -112,9 +112,8 @@ public class EscherComplexProperty extends EscherProperty {
|
||||
|
||||
EscherComplexProperty escherComplexProperty = (EscherComplexProperty) o;
|
||||
|
||||
if ( !Arrays.equals( _complexData, escherComplexProperty._complexData ) ) return false;
|
||||
return Arrays.equals(_complexData, escherComplexProperty._complexData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,12 +147,10 @@ public class EscherComplexProperty extends EscherProperty {
|
||||
|
||||
@Override
|
||||
public String toXml(String tab){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
|
||||
.append("\" name=\"").append(getName()).append("\" blipId=\"")
|
||||
.append(isBlipId()).append("\">\n");
|
||||
return tab + "<" + getClass().getSimpleName() + " id=\"0x" + HexDump.toHex(getId()) +
|
||||
"\" name=\"" + getName() + "\" blipId=\"" +
|
||||
isBlipId() + "\">\n" +
|
||||
tab + "</" + getClass().getSimpleName() + ">\n";
|
||||
//builder.append("\t").append(tab).append(dataStr);
|
||||
builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
==================================================================== */
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.Internal;
|
||||
|
||||
/**
|
||||
@ -72,15 +71,4 @@ public class EscherOptRecord extends AbstractEscherOptRecord
|
||||
|
||||
super.setVersion( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXml(String tab) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())));
|
||||
for (EscherProperty property: getEscherProperties()){
|
||||
builder.append(property.toXml(tab+"\t"));
|
||||
}
|
||||
builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
@ -72,8 +71,7 @@ public final class EscherPropertyFactory {
|
||||
}
|
||||
|
||||
// Get complex data
|
||||
for (Iterator<EscherProperty> iterator = results.iterator(); iterator.hasNext();) {
|
||||
EscherProperty p = iterator.next();
|
||||
for (EscherProperty p : results) {
|
||||
if (p instanceof EscherComplexProperty) {
|
||||
if (p instanceof EscherArrayProperty) {
|
||||
pos += ((EscherArrayProperty)p).setArrayData(data, pos);
|
||||
|
@ -84,8 +84,7 @@ public abstract class EscherRecord implements Cloneable {
|
||||
protected int readHeader( byte[] data, int offset ) {
|
||||
_options = LittleEndian.getShort( data, offset );
|
||||
_recordId = LittleEndian.getShort( data, offset + 2 );
|
||||
int remainingBytes = LittleEndian.getInt( data, offset + 4 );
|
||||
return remainingBytes;
|
||||
return LittleEndian.getInt( data, offset + 4 );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -312,19 +311,15 @@ public abstract class EscherRecord implements Cloneable {
|
||||
* @return xml representation of this record
|
||||
*/
|
||||
public String toXml(String tab){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(tab).append("<").append(getClass().getSimpleName()).append(">\n")
|
||||
.append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(_recordId)).append("</RecordId>\n")
|
||||
.append(tab).append("\t").append("<Options>").append(_options).append("</Options>\n")
|
||||
.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
|
||||
return builder.toString();
|
||||
return tab + "<" + getClass().getSimpleName() + ">\n" +
|
||||
tab + "\t" + "<RecordId>0x" + HexDump.toHex(_recordId) + "</RecordId>\n" +
|
||||
tab + "\t" + "<Options>" + _options + "</Options>\n" +
|
||||
tab + "</" + getClass().getSimpleName() + ">\n";
|
||||
}
|
||||
|
||||
protected String formatXmlRecordHeader(String className, String recordId, String version, String instance){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<").append(className).append(" recordId=\"0x").append(recordId).append("\" version=\"0x")
|
||||
.append(version).append("\" instance=\"0x").append(instance).append("\" size=\"").append(getRecordSize()).append("\">\n");
|
||||
return builder.toString();
|
||||
return "<" + className + " recordId=\"0x" + recordId + "\" version=\"0x" +
|
||||
version + "\" instance=\"0x" + instance + "\" size=\"" + getRecordSize() + "\">\n";
|
||||
}
|
||||
|
||||
public String toXml(){
|
||||
|
@ -20,6 +20,7 @@ package org.apache.poi.dev;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -92,7 +93,9 @@ public class RecordGenerator {
|
||||
// Generate record
|
||||
String destinationPath = destSrcPathDir + "/" + packageName;
|
||||
File destinationPathFile = new File(destinationPath);
|
||||
if (destinationPathFile.mkdirs()) {
|
||||
if(!destinationPathFile.mkdirs()) {
|
||||
throw new IOException("Could not create directory " + destinationPathFile);
|
||||
} else {
|
||||
System.out.println("Created destination directory: " + destinationPath);
|
||||
}
|
||||
String destinationFilepath = destinationPath + "/" + recordName + suffix + ".java";
|
||||
@ -103,11 +106,13 @@ public class RecordGenerator {
|
||||
// Generate test (if not already generated)
|
||||
destinationPath = testSrcPathDir + "/" + packageName;
|
||||
destinationPathFile = new File(destinationPath);
|
||||
if (destinationPathFile.mkdirs()) {
|
||||
if(!destinationPathFile.mkdirs()) {
|
||||
throw new IOException("Could not create directory " + destinationPathFile);
|
||||
} else {
|
||||
System.out.println("Created destination directory: " + destinationPath);
|
||||
}
|
||||
destinationFilepath = destinationPath + "/Test" + recordName + suffix + ".java";
|
||||
if (new File(destinationFilepath).exists() == false) {
|
||||
if (!new File(destinationFilepath).exists()) {
|
||||
String temp = (recordStyleDir + "/" + extendstg.toLowerCase(Locale.ROOT) + "_test.xsl");
|
||||
transform(file, new File(destinationFilepath), new File(temp));
|
||||
System.out.println("Generated test: " + destinationFilepath);
|
||||
|
@ -97,7 +97,7 @@ public class MutablePropertySet extends PropertySet
|
||||
/**
|
||||
* <p>The length of the property set stream header.</p>
|
||||
*/
|
||||
private final int OFFSET_HEADER =
|
||||
private final static int OFFSET_HEADER =
|
||||
BYTE_ORDER_ASSERTION.length + /* Byte order */
|
||||
FORMAT_ASSERTION.length + /* Format */
|
||||
LittleEndianConsts.INT_SIZE + /* OS version */
|
||||
@ -197,14 +197,13 @@ public class MutablePropertySet extends PropertySet
|
||||
{
|
||||
/* Write the number of sections in this property set stream. */
|
||||
final int nrSections = sections.size();
|
||||
int length = 0;
|
||||
|
||||
/* Write the property set's header. */
|
||||
length += TypeWriter.writeToStream(out, (short) getByteOrder());
|
||||
length += TypeWriter.writeToStream(out, (short) getFormat());
|
||||
length += TypeWriter.writeToStream(out, getOSVersion());
|
||||
length += TypeWriter.writeToStream(out, getClassID());
|
||||
length += TypeWriter.writeToStream(out, nrSections);
|
||||
TypeWriter.writeToStream(out, (short) getByteOrder());
|
||||
TypeWriter.writeToStream(out, (short) getFormat());
|
||||
TypeWriter.writeToStream(out, getOSVersion());
|
||||
TypeWriter.writeToStream(out, getClassID());
|
||||
TypeWriter.writeToStream(out, nrSections);
|
||||
int offset = OFFSET_HEADER;
|
||||
|
||||
/* Write the section list, i.e. the references to the sections. Each
|
||||
@ -218,8 +217,8 @@ public class MutablePropertySet extends PropertySet
|
||||
final ClassID formatID = s.getFormatID();
|
||||
if (formatID == null)
|
||||
throw new NoFormatIDException();
|
||||
length += TypeWriter.writeToStream(out, s.getFormatID());
|
||||
length += TypeWriter.writeUIntToStream(out, offset);
|
||||
TypeWriter.writeToStream(out, s.getFormatID());
|
||||
TypeWriter.writeUIntToStream(out, offset);
|
||||
try
|
||||
{
|
||||
offset += s.getSize();
|
||||
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
@ -61,7 +62,7 @@ public class PropertySet
|
||||
* <p>The "byteOrder" field must equal this value.</p>
|
||||
*/
|
||||
static final byte[] BYTE_ORDER_ASSERTION =
|
||||
new byte[] {(byte) 0xFE, (byte) 0xFF};
|
||||
{(byte) 0xFE, (byte) 0xFF};
|
||||
|
||||
/**
|
||||
* <p>Specifies this {@link PropertySet}'s byte order. See the
|
||||
@ -86,7 +87,7 @@ public class PropertySet
|
||||
* <p>The "format" field must equal this value.</p>
|
||||
*/
|
||||
static final byte[] FORMAT_ASSERTION =
|
||||
new byte[]{(byte) 0x00, (byte) 0x00};
|
||||
{(byte) 0x00, (byte) 0x00};
|
||||
|
||||
/**
|
||||
* <p>Specifies this {@link PropertySet}'s format. See the HPFS
|
||||
@ -238,7 +239,7 @@ public class PropertySet
|
||||
{
|
||||
final int avail = stream.available();
|
||||
final byte[] buffer = new byte[avail];
|
||||
stream.read(buffer, 0, buffer.length);
|
||||
IOUtils.readFully(stream, buffer);
|
||||
init(buffer, 0, buffer.length);
|
||||
}
|
||||
else
|
||||
@ -627,6 +628,7 @@ public class PropertySet
|
||||
* @return <code>true</code> if the objects are equal, <code>false</code>
|
||||
* if not
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
if (o == null || !(o instanceof PropertySet))
|
||||
@ -670,7 +672,7 @@ public class PropertySet
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
final StringBuffer b = new StringBuffer();
|
||||
final StringBuilder b = new StringBuilder();
|
||||
final int sectionCount = getSectionCount();
|
||||
b.append(getClass().getName());
|
||||
b.append('[');
|
||||
|
@ -19,7 +19,6 @@ package org.apache.poi.hpsf.extractor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.POIDocument;
|
||||
import org.apache.poi.POIOLE2TextExtractor;
|
||||
@ -59,7 +58,7 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
|
||||
}
|
||||
|
||||
DocumentSummaryInformation dsi = document.getDocumentSummaryInformation();
|
||||
StringBuffer text = new StringBuffer();
|
||||
StringBuilder text = new StringBuilder();
|
||||
|
||||
// Normal properties
|
||||
text.append( getPropertiesText(dsi) );
|
||||
@ -67,11 +66,9 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
|
||||
// Now custom ones
|
||||
CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
|
||||
if (cps != null) {
|
||||
Iterator<String> keys = cps.nameSet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
for (String key : cps.nameSet()) {
|
||||
String val = HelperPropertySet.getPropertyValueText(cps.get(key));
|
||||
text.append(key + " = " + val + "\n");
|
||||
text.append(key).append(" = ").append(val).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,19 +92,19 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuffer text = new StringBuffer();
|
||||
StringBuilder text = new StringBuilder();
|
||||
|
||||
PropertyIDMap idMap = ps.getPropertySetIDMap();
|
||||
Property[] props = ps.getProperties();
|
||||
for (int i=0; i<props.length; i++) {
|
||||
String type = Long.toString( props[i].getID() );
|
||||
Object typeObj = idMap.get(props[i].getID());
|
||||
for (Property prop : props) {
|
||||
String type = Long.toString(prop.getID());
|
||||
Object typeObj = idMap.get(prop.getID());
|
||||
if (typeObj != null) {
|
||||
type = typeObj.toString();
|
||||
}
|
||||
|
||||
String val = HelperPropertySet.getPropertyValueText( props[i].getValue() );
|
||||
text.append(type + " = " + val + "\n");
|
||||
String val = HelperPropertySet.getPropertyValueText(prop.getValue());
|
||||
text.append(type).append(" = ").append(val).append("\n");
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
@ -140,6 +137,16 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
for (String file : args) {
|
||||
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(
|
||||
|
@ -77,15 +77,13 @@ final class LazyAreaEval extends AreaEvalBase {
|
||||
public String toString() {
|
||||
CellReference crA = new CellReference(getFirstRow(), getFirstColumn());
|
||||
CellReference crB = new CellReference(getLastRow(), getLastColumn());
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getClass().getName()).append("[");
|
||||
sb.append(_evaluator.getSheetNameRange());
|
||||
sb.append('!');
|
||||
sb.append(crA.formatAsString());
|
||||
sb.append(':');
|
||||
sb.append(crB.formatAsString());
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
return getClass().getName() + "[" +
|
||||
_evaluator.getSheetNameRange() +
|
||||
'!' +
|
||||
crA.formatAsString() +
|
||||
':' +
|
||||
crB.formatAsString() +
|
||||
"]";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -319,7 +318,7 @@ public class DataFormatter implements Observer {
|
||||
// handle these ourselves in a special way.
|
||||
// For now, if we detect 3+ parts, we call out to CellFormat to handle it
|
||||
// TODO Going forward, we should really merge the logic between the two classes
|
||||
if (formatStr.indexOf(";") != -1 &&
|
||||
if (formatStr.contains(";") &&
|
||||
formatStr.indexOf(';') != formatStr.lastIndexOf(';')) {
|
||||
try {
|
||||
// Ask CellFormat to get a formatter for it
|
||||
@ -402,11 +401,9 @@ public class DataFormatter implements Observer {
|
||||
String match = m.group();
|
||||
String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
|
||||
if (symbol.indexOf('$') > -1) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(symbol.substring(0, symbol.indexOf('$')));
|
||||
sb.append('\\');
|
||||
sb.append(symbol.substring(symbol.indexOf('$'), symbol.length()));
|
||||
symbol = sb.toString();
|
||||
symbol = symbol.substring(0, symbol.indexOf('$')) +
|
||||
'\\' +
|
||||
symbol.substring(symbol.indexOf('$'), symbol.length());
|
||||
}
|
||||
formatStr = m.replaceAll(symbol);
|
||||
m = localePatternGroup.matcher(formatStr);
|
||||
@ -426,10 +423,10 @@ public class DataFormatter implements Observer {
|
||||
return createDateFormat(formatStr, cellValue);
|
||||
}
|
||||
// Excel supports fractions in format strings, which Java doesn't
|
||||
if (formatStr.indexOf("#/") >= 0 || formatStr.indexOf("?/") >= 0) {
|
||||
if (formatStr.contains("#/") || formatStr.contains("?/")) {
|
||||
String[] chunks = formatStr.split(";");
|
||||
for (int i = 0; i < chunks.length; i++){
|
||||
String chunk = chunks[i].replaceAll("\\?", "#");
|
||||
for (String chunk1 : chunks) {
|
||||
String chunk = chunk1.replaceAll("\\?", "#");
|
||||
Matcher matcher = fractionStripper.matcher(chunk);
|
||||
chunk = matcher.replaceAll(" ");
|
||||
chunk = chunk.replaceAll(" +", " ");
|
||||
@ -498,7 +495,7 @@ public class DataFormatter implements Observer {
|
||||
Excel displays the month instead of minutes."
|
||||
*/
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] chars = formatStr.toCharArray();
|
||||
boolean mIsMonth = true;
|
||||
List<Integer> ms = new ArrayList<Integer>();
|
||||
@ -602,7 +599,7 @@ public class DataFormatter implements Observer {
|
||||
}
|
||||
|
||||
private String cleanFormatForNumber(String formatStr) {
|
||||
StringBuffer sb = new StringBuffer(formatStr);
|
||||
StringBuilder sb = new StringBuilder(formatStr);
|
||||
|
||||
if (emulateCSV) {
|
||||
// Requested spacers with "_" are replaced by a single space.
|
||||
@ -927,9 +924,7 @@ public class DataFormatter implements Observer {
|
||||
* @see java.text.Format#format
|
||||
*/
|
||||
public void setDefaultNumberFormat(Format format) {
|
||||
Iterator<Map.Entry<String,Format>> itr = formats.entrySet().iterator();
|
||||
while(itr.hasNext()) {
|
||||
Map.Entry<String,Format> entry = itr.next();
|
||||
for (Map.Entry<String, Format> entry : formats.entrySet()) {
|
||||
if (entry.getValue() == generalNumberFormat) {
|
||||
entry.setValue(format);
|
||||
}
|
||||
@ -1054,11 +1049,9 @@ public class DataFormatter implements Observer {
|
||||
/** Format a number as an SSN */
|
||||
public static String format(Number num) {
|
||||
String result = df.format(num);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(result.substring(0, 3)).append('-');
|
||||
sb.append(result.substring(3, 5)).append('-');
|
||||
sb.append(result.substring(5, 9));
|
||||
return sb.toString();
|
||||
return result.substring(0, 3) + '-' +
|
||||
result.substring(3, 5) + '-' +
|
||||
result.substring(5, 9);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1088,10 +1081,8 @@ public class DataFormatter implements Observer {
|
||||
/** Format a number as Zip + 4 */
|
||||
public static String format(Number num) {
|
||||
String result = df.format(num);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(result.substring(0, 5)).append('-');
|
||||
sb.append(result.substring(5, 9));
|
||||
return sb.toString();
|
||||
return result.substring(0, 5) + '-' +
|
||||
result.substring(5, 9);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1121,7 +1112,7 @@ public class DataFormatter implements Observer {
|
||||
/** Format a number as a phone number */
|
||||
public static String format(Number num) {
|
||||
String result = df.format(num);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String seg1, seg2, seg3;
|
||||
int len = result.length();
|
||||
if (len <= 4) {
|
||||
@ -1132,10 +1123,10 @@ public class DataFormatter implements Observer {
|
||||
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 != null && seg1.trim().length() > 0) {
|
||||
if(seg1.trim().length() > 0) {
|
||||
sb.append('(').append(seg1).append(") ");
|
||||
}
|
||||
if(seg2 != null && seg2.trim().length() > 0) {
|
||||
if(seg2.trim().length() > 0) {
|
||||
sb.append(seg2).append('-');
|
||||
}
|
||||
sb.append(seg3);
|
||||
|
@ -139,7 +139,7 @@ public class HexRead
|
||||
}
|
||||
}
|
||||
}
|
||||
Byte[] polished = bytes.toArray( new Byte[0] );
|
||||
Byte[] polished = bytes.toArray(new Byte[bytes.size()]);
|
||||
byte[] rval = new byte[polished.length];
|
||||
for ( int j = 0; j < polished.length; j++ )
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
|
||||
* Helper class to extract text from an OOXML Word file
|
||||
*/
|
||||
public class XWPFWordExtractor extends POIXMLTextExtractor {
|
||||
public static final XWPFRelation[] SUPPORTED_TYPES = new XWPFRelation[]{
|
||||
public static final XWPFRelation[] SUPPORTED_TYPES = {
|
||||
XWPFRelation.DOCUMENT, XWPFRelation.TEMPLATE,
|
||||
XWPFRelation.MACRO_DOCUMENT,
|
||||
XWPFRelation.MACRO_TEMPLATE_DOCUMENT
|
||||
@ -134,7 +134,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
|
||||
if (run instanceof XWPFHyperlinkRun && fetchHyperlinks) {
|
||||
XWPFHyperlink link = ((XWPFHyperlinkRun) run).getHyperlink(document);
|
||||
if (link != null)
|
||||
text.append(" <" + link.getURL() + ">");
|
||||
text.append(" <").append(link.getURL()).append(">");
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
|
||||
// Do endnotes and footnotes
|
||||
String footnameText = paragraph.getFootnoteText();
|
||||
if (footnameText != null && footnameText.length() > 0) {
|
||||
text.append(footnameText + '\n');
|
||||
text.append(footnameText).append('\n');
|
||||
}
|
||||
|
||||
if (ctSectPr != null) {
|
||||
|
@ -35,6 +35,7 @@ import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class TestProper {
|
||||
private Cell cell11;
|
||||
@ -74,6 +75,7 @@ public final class TestProper {
|
||||
|
||||
final String scharfes = "\u00df"; //German lowercase eszett, scharfes s, sharp s
|
||||
confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e");
|
||||
assertTrue(Character.isLetter(scharfes.charAt(0)));
|
||||
|
||||
// CURRENTLY FAILS: result: "SSUnd"+scharfes
|
||||
// LibreOffice 5.0.3.2 behavior: "Sund"+scharfes
|
||||
|
@ -265,37 +265,14 @@ public final class TestExcelExtractor {
|
||||
assertTrue(text.startsWith(
|
||||
"Dates, all 24th November 2006\n"
|
||||
));
|
||||
assertTrue(
|
||||
text.indexOf(
|
||||
"yyyy/mm/dd\t2006/11/24\n"
|
||||
) > -1
|
||||
);
|
||||
assertTrue(
|
||||
text.indexOf(
|
||||
"yyyy-mm-dd\t2006-11-24\n"
|
||||
) > -1
|
||||
);
|
||||
assertTrue(
|
||||
text.indexOf(
|
||||
"dd-mm-yy\t24-11-06\n"
|
||||
) > -1
|
||||
);
|
||||
assertTrue(text.contains("yyyy/mm/dd\t2006/11/24\n"));
|
||||
assertTrue(text.contains("yyyy-mm-dd\t2006-11-24\n"));
|
||||
assertTrue(text.contains("dd-mm-yy\t24-11-06\n"));
|
||||
|
||||
assertTrue("Had: " + text + ", but should contain 'nn.nn\\t10.52\\n'",
|
||||
text.indexOf(
|
||||
"nn.nn\t10.52\n"
|
||||
) > -1
|
||||
);
|
||||
assertTrue(
|
||||
text.indexOf(
|
||||
"nn.nnn\t10.520\n"
|
||||
) > -1
|
||||
);
|
||||
assertTrue(
|
||||
text.indexOf(
|
||||
"\u00a3nn.nn\t\u00a310.52\n"
|
||||
) > -1
|
||||
);
|
||||
text.contains("nn.nn\t10.52\n"));
|
||||
assertTrue(text.contains("nn.nnn\t10.520\n"));
|
||||
assertTrue(text.contains("\u00a3nn.nn\t\u00a310.52\n"));
|
||||
extractor.close();
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(userLocale);
|
||||
@ -387,11 +364,11 @@ public final class TestExcelExtractor {
|
||||
"45538_classic_Footer.xls", "45538_form_Footer.xls",
|
||||
"45538_classic_Header.xls", "45538_form_Header.xls"
|
||||
};
|
||||
for(int i=0; i<files.length; i++) {
|
||||
ExcelExtractor extractor = createExtractor(files[i]);
|
||||
for (String file : files) {
|
||||
ExcelExtractor extractor = createExtractor(file);
|
||||
String text = extractor.getText();
|
||||
assertTrue("Unable to find expected word in text\n" + text, text.indexOf("testdoc") >=0);
|
||||
assertTrue("Unable to find expected word in text\n" + text, text.indexOf("test phrase") >= 0);
|
||||
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
|
||||
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
|
||||
extractor.close();
|
||||
}
|
||||
}
|
||||
|
@ -246,18 +246,18 @@ public final class TestHSSFDataFormatter {
|
||||
String fmt = cell.getCellStyle().getDataFormatString();
|
||||
|
||||
//assert the correct month form, as in the original Excel format
|
||||
String monthPtrn = fmt.indexOf("mmmm") != -1 ? "MMMM" : "MMM";
|
||||
String monthPtrn = fmt.contains("mmmm") ? "MMMM" : "MMM";
|
||||
// this line is intended to compute how "July" would look like in the current locale
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(monthPtrn, LocaleUtil.getUserLocale());
|
||||
sdf.setTimeZone(LocaleUtil.getUserTimeZone());
|
||||
Calendar calDef = LocaleUtil.getLocaleCalendar(2010, 6, 15, 0, 0, 0);
|
||||
String jul = sdf.format(calDef.getTime());
|
||||
// special case for MMMMM = 1st letter of month name
|
||||
if(fmt.indexOf("mmmmm") > -1) {
|
||||
if(fmt.contains("mmmmm")) {
|
||||
jul = jul.substring(0,1);
|
||||
}
|
||||
// check we found july properly
|
||||
assertTrue("Format came out incorrect - " + fmt, fmtval.indexOf(jul) > -1);
|
||||
assertTrue("Format came out incorrect - " + fmt, fmtval.contains(jul));
|
||||
}
|
||||
|
||||
row = wb.getSheetAt(0).getRow(1);
|
||||
@ -275,7 +275,7 @@ public final class TestHSSFDataFormatter {
|
||||
|
||||
// check we found the time properly
|
||||
assertTrue("Format came out incorrect - " + fmt + " - found " + fmtval +
|
||||
", but expected to find '11:23'", fmtval.indexOf("11:23") > -1);
|
||||
", but expected to find '11:23'", fmtval.contains("11:23"));
|
||||
}
|
||||
|
||||
// test number formats
|
||||
@ -451,7 +451,7 @@ public final class TestHSSFDataFormatter {
|
||||
assertEquals("\u00a310.52", f.formatCellValue(sheet.getRow(12).getCell(1)));
|
||||
}
|
||||
|
||||
private static void log(String msg) {
|
||||
private static void log(@SuppressWarnings("UnusedParameters") String msg) {
|
||||
// if (false) { // successful tests should be silent
|
||||
// System.out.println(msg);
|
||||
// }
|
||||
|
@ -39,7 +39,7 @@ public class TestPOIFSDump {
|
||||
private static final String INVALID_FILE = HSSFTestDataSamples.getSampleFile("48936-strings.txt").getAbsolutePath();
|
||||
private static final String INVALID_XLSX_FILE = HSSFTestDataSamples.getSampleFile("47668.xlsx").getAbsolutePath();
|
||||
|
||||
private static final String[] DUMP_OPTIONS = new String[] {
|
||||
private static final String[] DUMP_OPTIONS = {
|
||||
"-dumprops",
|
||||
"-dump-props",
|
||||
"-dump-properties",
|
||||
|
@ -140,7 +140,7 @@ public class TestDataFormatter {
|
||||
public void testColours() {
|
||||
DataFormatter dfUS = new DataFormatter(Locale.US);
|
||||
|
||||
String[] formats = new String[] {
|
||||
String[] formats = {
|
||||
"##.##",
|
||||
"[WHITE]##.##",
|
||||
"[BLACK]##.##;[RED]-##.##",
|
||||
@ -169,7 +169,7 @@ public class TestDataFormatter {
|
||||
DataFormatter dfUS = new DataFormatter(Locale.US);
|
||||
|
||||
// Without currency symbols
|
||||
String[] formats = new String[] { "#,##0.00;[Blue](#,##0.00)" };
|
||||
String[] formats = { "#,##0.00;[Blue](#,##0.00)" };
|
||||
for (String format : formats) {
|
||||
assertEquals(
|
||||
"Wrong format for: " + format,
|
||||
@ -304,7 +304,7 @@ public class TestDataFormatter {
|
||||
assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/? ?/?"));
|
||||
assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/? #/# #/#"));
|
||||
|
||||
// Where +ve has a fraction, but -ve doesnt, we currently show both
|
||||
// Where +ve has a fraction, but -ve doesn't, we currently show both
|
||||
assertEquals("123 1/3", dfUS.formatRawCellContents( 123.321, -1, "0 ?/?;0"));
|
||||
//assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0 ?/?;0"));
|
||||
|
||||
@ -567,12 +567,12 @@ public class TestDataFormatter {
|
||||
|
||||
assertEquals(" 0.10 ", dfUS.formatRawCellContents( 0.1, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
|
||||
assertEquals("- 0.10 ", dfUS.formatRawCellContents(-0.1, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
|
||||
// TODO Fix this, we are randomly adding a 0 at the end that souldn't be there
|
||||
// TODO Fix this, we are randomly adding a 0 at the end that shouldn't be there
|
||||
//assertEquals(" - ", dfUS.formatRawCellContents(0.0, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
|
||||
|
||||
assertEquals(" $ 1.10 ", dfUS.formatRawCellContents( 1.1, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
|
||||
assertEquals("-$ 1.10 ", dfUS.formatRawCellContents(-1.1, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
|
||||
// TODO Fix this, we are randomly adding a 0 at the end that souldn't be there
|
||||
// TODO Fix this, we are randomly adding a 0 at the end that shouldn't be there
|
||||
//assertEquals(" $ - ", dfUS.formatRawCellContents( 0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user