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