sonar fixes

Very interesting was the exception swallowing in PackagePropertiesPart. When it was properly thrown, it already led to various errors in the junits test - I've fixed the handling for at least the ones which are in our test set

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1706169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-09-30 23:06:39 +00:00
parent d81547befd
commit 2de9d527b4
27 changed files with 154 additions and 105 deletions

View File

@ -163,7 +163,7 @@ public class SVSheetTable extends JTable {
Row row = sheet.getRow(i - sheet.getFirstRowNum()); Row row = sheet.getRow(i - sheet.getFirstRowNum());
if (row != null) { if (row != null) {
short h = row.getHeight(); short h = row.getHeight();
int height = Math.round(Math.max(1, h / (res / 70 * 20) + 3)); int height = (int)Math.round(Math.max(1., ((double)h) / (((double)res) / 70. * 20.) + 3.));
System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res); System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res);
setRowHeight(i, height); setRowHeight(i, height);
} }

View File

@ -19,10 +19,10 @@ package org.apache.poi.xssf.usermodel.examples;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.InputStream; import java.io.InputStream;

View File

@ -24,9 +24,9 @@ import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.junit.Test; import org.junit.Test;
public class XSLFFileHandler extends SlideShowHandler { public class XSLFFileHandler extends SlideShowHandler {

View File

@ -27,7 +27,7 @@ import org.apache.poi.util.RecordFormatException;
* Escher format. We don't attempt to understand the contents, since * Escher format. We don't attempt to understand the contents, since
* they will be in the parent's format, not Escher format. * they will be in the parent's format, not Escher format.
*/ */
public class EscherTextboxRecord extends EscherRecord implements Cloneable { public final class EscherTextboxRecord extends EscherRecord implements Cloneable {
public static final short RECORD_ID = (short)0xF00D; public static final short RECORD_ID = (short)0xF00D;
public static final String RECORD_DESCRIPTION = "msofbtClientTextbox"; public static final String RECORD_DESCRIPTION = "msofbtClientTextbox";

View File

@ -318,6 +318,38 @@ public class Section
return 1; return 1;
} }
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + length;
result = prime * result + offset;
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PropertyListEntry other = (PropertyListEntry) obj;
if (id != other.id)
return false;
if (length != other.length)
return false;
if (offset != other.offset)
return false;
return true;
}
public String toString() public String toString()
{ {
final StringBuffer b = new StringBuffer(); final StringBuffer b = new StringBuffer();

View File

@ -164,7 +164,7 @@ public final class InternalSheet {
int dimsloc = -1; int dimsloc = -1;
if (rs.peekNextSid() != BOFRecord.sid) { if (rs.peekNextSid() != BOFRecord.sid) {
throw new RuntimeException("BOF record expected"); throw new RecordFormatException("BOF record expected");
} }
BOFRecord bof = (BOFRecord) rs.getNext(); BOFRecord bof = (BOFRecord) rs.getNext();
@ -210,7 +210,7 @@ public final class InternalSheet {
if (RecordOrderer.isRowBlockRecord(recSid)) { if (RecordOrderer.isRowBlockRecord(recSid)) {
//only add the aggregate once //only add the aggregate once
if (rra != null) { if (rra != null) {
throw new RuntimeException("row/cell records found in the wrong place"); throw new RecordFormatException("row/cell records found in the wrong place");
} }
RowBlocksReader rbr = new RowBlocksReader(rs); RowBlocksReader rbr = new RowBlocksReader(rs);
_mergedCellsTable.addRecords(rbr.getLooseMergedCells()); _mergedCellsTable.addRecords(rbr.getLooseMergedCells());
@ -332,7 +332,7 @@ public final class InternalSheet {
records.add(rec); records.add(rec);
} }
if (windowTwo == null) { if (windowTwo == null) {
throw new RuntimeException("WINDOW2 was not found"); throw new RecordFormatException("WINDOW2 was not found");
} }
if (_dimensions == null) { if (_dimensions == null) {
// Excel seems to always write the DIMENSION record, but tolerates when it is not present // Excel seems to always write the DIMENSION record, but tolerates when it is not present
@ -393,7 +393,7 @@ public final class InternalSheet {
try { try {
_destList.add((Record)r.clone()); _destList.add((Record)r.clone());
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new RuntimeException(e); throw new RecordFormatException(e);
} }
} }
} }
@ -423,7 +423,7 @@ public final class InternalSheet {
Record rec = (Record) ((Record) rb).clone(); Record rec = (Record) ((Record) rb).clone();
clonedRecords.add(rec); clonedRecords.add(rec);
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new RuntimeException(e); throw new RecordFormatException(e);
} }
} }
return createSheet(new RecordStream(clonedRecords, 0)); return createSheet(new RecordStream(clonedRecords, 0));

View File

@ -152,5 +152,5 @@ public abstract class CFHeaderBase extends StandardRecord implements Cloneable {
} }
@Override @Override
public abstract CFHeaderBase clone(); public abstract CFHeaderBase clone(); // NOSONAR
} }

View File

@ -41,10 +41,10 @@ public final class FilePassRecord extends StandardRecord implements Cloneable {
void serialize(LittleEndianOutput out); void serialize(LittleEndianOutput out);
int getDataSize(); int getDataSize();
void appendToString(StringBuffer buffer); void appendToString(StringBuffer buffer);
KeyData clone(); KeyData clone(); // NOSONAR
} }
public static class Rc4KeyData implements KeyData { public static final class Rc4KeyData implements KeyData, Cloneable {
private static final int ENCRYPTION_OTHER_RC4 = 1; private static final int ENCRYPTION_OTHER_RC4 = 1;
private static final int ENCRYPTION_OTHER_CAPI_2 = 2; private static final int ENCRYPTION_OTHER_CAPI_2 = 2;
private static final int ENCRYPTION_OTHER_CAPI_3 = 3; private static final int ENCRYPTION_OTHER_CAPI_3 = 3;
@ -135,7 +135,7 @@ public final class FilePassRecord extends StandardRecord implements Cloneable {
} }
} }
public static class XorKeyData implements KeyData { public static final class XorKeyData implements KeyData, Cloneable {
/** /**
* key (2 bytes): An unsigned integer that specifies the obfuscation key. * key (2 bytes): An unsigned integer that specifies the obfuscation key.
* See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR * See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndianOutput;
* @author Andrew C. Oliver (acoliver at apache dot org) * @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public class IndexRecord extends StandardRecord implements Cloneable { public final class IndexRecord extends StandardRecord implements Cloneable {
public final static short sid = 0x020B; public final static short sid = 0x020B;
private int field_2_first_row; // first row on the sheet private int field_2_first_row; // first row on the sheet
private int field_3_last_row_add1; // last row private int field_3_last_row_add1; // last row

View File

@ -28,6 +28,7 @@ import org.apache.poi.hssf.record.CFRule12Record;
import org.apache.poi.hssf.record.CFRuleBase; import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.ptg.AreaErrPtg; import org.apache.poi.ss.formula.ptg.AreaErrPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.ptg.AreaPtg;
@ -68,7 +69,7 @@ public final class CFRecordsAggregate extends RecordAggregate {
+ " this file will cause problems with old Excel versions"); + " this file will cause problems with old Excel versions");
} }
if (pRules.length != pHeader.getNumberOfConditionalFormats()) { if (pRules.length != pHeader.getNumberOfConditionalFormats()) {
throw new RuntimeException("Mismatch number of rules"); throw new RecordFormatException("Mismatch number of rules");
} }
header = pHeader; header = pHeader;
rules = new ArrayList<CFRuleBase>(pRules.length); rules = new ArrayList<CFRuleBase>(pRules.length);
@ -119,9 +120,9 @@ public final class CFRecordsAggregate extends RecordAggregate {
public CFRecordsAggregate cloneCFAggregate() { public CFRecordsAggregate cloneCFAggregate() {
CFRuleBase[] newRecs = new CFRuleBase[rules.size()]; CFRuleBase[] newRecs = new CFRuleBase[rules.size()];
for (int i = 0; i < newRecs.length; i++) { for (int i = 0; i < newRecs.length; i++) {
newRecs[i] = (CFRuleRecord) getRule(i).clone(); newRecs[i] = getRule(i).clone();
} }
return new CFRecordsAggregate((CFHeaderBase)header.clone(), newRecs); return new CFRecordsAggregate(header.clone(), newRecs);
} }
/** /**

View File

@ -80,7 +80,7 @@ public abstract class BlockStore {
protected class ChainLoopDetector { protected class ChainLoopDetector {
private boolean[] used_blocks; private boolean[] used_blocks;
protected ChainLoopDetector(long rawSize) { protected ChainLoopDetector(long rawSize) {
int numBlocks = (int)Math.ceil( rawSize / getBlockStoreBlockSize() ); int numBlocks = (int)Math.ceil( ((double)rawSize) / getBlockStoreBlockSize() );
used_blocks = new boolean[numBlocks]; used_blocks = new boolean[numBlocks];
} }
protected void claim(int offset) { protected void claim(int offset) {

View File

@ -120,7 +120,7 @@ public final class NPropertyTable extends PropertyTableBase {
public int countBlocks() public int countBlocks()
{ {
int size = _properties.size() * POIFSConstants.PROPERTY_SIZE; int size = _properties.size() * POIFSConstants.PROPERTY_SIZE;
return (int)Math.ceil(size / _bigBigBlockSize.getBigBlockSize()); return (int)Math.ceil( ((double)size) / _bigBigBlockSize.getBigBlockSize());
} }
/** /**

View File

@ -21,7 +21,7 @@ package org.apache.poi.sl.usermodel;
* This is a replacement for {@link java.awt.Insets} which works on doubles * This is a replacement for {@link java.awt.Insets} which works on doubles
* instead of ints * instead of ints
*/ */
public class Insets2D implements Cloneable { public final class Insets2D implements Cloneable {
/** /**
* The inset from the top. * The inset from the top.

View File

@ -55,9 +55,9 @@ import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XSLFRelation; import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xssf.usermodel.XSSFRelation;

View File

@ -48,6 +48,10 @@ public final class PackagePropertiesPart extends PackagePart implements
public final static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/"; public final static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/";
private final static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private final static String ALTERNATIVE_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SS'Z'";
/** /**
* Constructor. * Constructor.
* *
@ -386,8 +390,8 @@ public final class PackagePropertiesPart extends PackagePart implements
try { try {
this.created = setDateValue(created); this.created = setDateValue(created);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
new IllegalArgumentException("created : " throw new IllegalArgumentException("created : "
+ e.getLocalizedMessage()); + e.getLocalizedMessage(), e);
} }
} }
@ -464,8 +468,8 @@ public final class PackagePropertiesPart extends PackagePart implements
try { try {
this.lastPrinted = setDateValue(lastPrinted); this.lastPrinted = setDateValue(lastPrinted);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
new IllegalArgumentException("lastPrinted : " throw new IllegalArgumentException("lastPrinted : "
+ e.getLocalizedMessage()); + e.getLocalizedMessage(), e);
} }
} }
@ -488,8 +492,8 @@ public final class PackagePropertiesPart extends PackagePart implements
try { try {
this.modified = setDateValue(modified); this.modified = setDateValue(modified);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
new IllegalArgumentException("modified : " throw new IllegalArgumentException("modified : "
+ e.getLocalizedMessage()); + e.getLocalizedMessage(), e);
} }
} }
@ -559,9 +563,17 @@ public final class PackagePropertiesPart extends PackagePart implements
if (s == null || s.equals("")) { if (s == null || s.equals("")) {
return new Nullable<Date>(); return new Nullable<Date>();
} }
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT); if (!s.endsWith("Z")) {
s += "Z";
}
SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC); df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
Date d = df.parse(s, new ParsePosition(0)); Date d = df.parse(s, new ParsePosition(0));
if (d == null) {
df = new SimpleDateFormat(ALTERNATIVE_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
d = df.parse(s, new ParsePosition(0));
}
if (d == null) { if (d == null) {
throw new InvalidFormatException("Date not well formated"); throw new InvalidFormatException("Date not well formated");
} }
@ -585,7 +597,7 @@ public final class PackagePropertiesPart extends PackagePart implements
return ""; return "";
} }
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT); SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC); df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
return df.format(date); return df.format(date);
} }

View File

@ -28,6 +28,7 @@ import static org.apache.poi.poifs.crypt.dsig.facets.XAdESSignatureFacet.insertX
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.cert.CRLException; import java.security.cert.CRLException;
import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateEncodingException;
@ -324,21 +325,25 @@ public class XAdESXLSignatureFacet extends SignatureFacet {
} }
private BigInteger getCrlNumber(X509CRL crl) { private BigInteger getCrlNumber(X509CRL crl) {
try { byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());
byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId()); if (null == crlNumberExtensionValue) {
if (null == crlNumberExtensionValue) { return null;
return null; }
}
@SuppressWarnings("resource") try {
ASN1InputStream asn1InputStream = new ASN1InputStream(crlNumberExtensionValue); ASN1InputStream asn1IS1 = null, asn1IS2 = null;
ASN1OctetString octetString = (ASN1OctetString)asn1InputStream.readObject(); try {
byte[] octets = octetString.getOctets(); asn1IS1 = new ASN1InputStream(crlNumberExtensionValue);
asn1InputStream = new ASN1InputStream(octets); ASN1OctetString octetString = (ASN1OctetString)asn1IS1.readObject();
ASN1Integer integer = (ASN1Integer)asn1InputStream.readObject(); byte[] octets = octetString.getOctets();
BigInteger crlNumber = integer.getPositiveValue(); asn1IS2 = new ASN1InputStream(octets);
return crlNumber; ASN1Integer integer = (ASN1Integer)asn1IS2.readObject();
} catch (Exception e) { return integer.getPositiveValue();
} finally {
asn1IS2.close();
asn1IS1.close();
}
} catch (IOException e) {
throw new RuntimeException("I/O error: " + e.getMessage(), e); throw new RuntimeException("I/O error: " + e.getMessage(), e);
} }
} }

View File

@ -22,7 +22,6 @@ import java.util.List;
import org.apache.poi.POIXMLTextExtractor; import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.DrawingTextBody; import org.apache.poi.xslf.usermodel.DrawingTextBody;
import org.apache.poi.xslf.usermodel.DrawingTextPlaceholder; import org.apache.poi.xslf.usermodel.DrawingTextPlaceholder;
@ -35,6 +34,7 @@ import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout; import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster; import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTComment; import org.openxmlformats.schemas.presentationml.x2006.main.CTComment;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor;

View File

@ -49,7 +49,6 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.PackageHelper; import org.apache.poi.util.PackageHelper;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlOptions;
@ -124,12 +123,6 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
} }
} }
// TODO get rid of this method
@Deprecated
public XSLFSlideShow _getXSLFSlideShow() throws OpenXML4JException, IOException, XmlException{
return new XSLFSlideShow(getPackage());
}
@Override @Override
protected void onDocumentRead() throws IOException { protected void onDocumentRead() throws IOException {
try { try {

View File

@ -14,7 +14,7 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xslf; package org.apache.poi.xslf.usermodel;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
@ -28,8 +28,6 @@ import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;

View File

@ -20,7 +20,7 @@
package org.apache.poi; package org.apache.poi;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;

View File

@ -20,7 +20,7 @@ import junit.framework.TestCase;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.PackageHelper; import org.apache.poi.util.PackageHelper;
import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;

View File

@ -16,12 +16,17 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.extractor; package org.apache.poi.extractor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor; import org.apache.poi.POITextExtractor;
@ -43,40 +48,42 @@ import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.junit.BeforeClass;
import org.junit.Test;
/** /**
* Test that the extractor factory plays nicely * Test that the extractor factory plays nicely
*/ */
public class TestExtractorFactory extends TestCase { public class TestExtractorFactory {
private File txt; private static File txt;
private File xls; private static File xls;
private File xlsx; private static File xlsx;
private File xlsxStrict; private static File xlsxStrict;
private File xltx; private static File xltx;
private File xlsEmb; private static File xlsEmb;
private File doc; private static File doc;
private File doc6; private static File doc6;
private File doc95; private static File doc95;
private File docx; private static File docx;
private File dotx; private static File dotx;
private File docEmb; private static File docEmb;
private File docEmbOOXML; private static File docEmbOOXML;
private File ppt; private static File ppt;
private File pptx; private static File pptx;
private File msg; private static File msg;
private File msgEmb; private static File msgEmb;
private File msgEmbMsg; private static File msgEmbMsg;
private File vsd; private static File vsd;
private File vsdx; private static File vsdx;
private File pub; private static File pub;
private File getFileAndCheck(POIDataSamples samples, String name) { private static File getFileAndCheck(POIDataSamples samples, String name) {
File file = samples.getFile(name); File file = samples.getFile(name);
assertNotNull("Did not get a file for " + name, file); assertNotNull("Did not get a file for " + name, file);
@ -85,9 +92,9 @@ public class TestExtractorFactory extends TestCase {
return file; return file;
} }
@Override
protected void setUp() throws Exception { @BeforeClass
super.setUp(); public static void setUp() throws Exception {
POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance(); POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
xls = getFileAndCheck(ssTests, "SampleSS.xls"); xls = getFileAndCheck(ssTests, "SampleSS.xls");
@ -123,6 +130,7 @@ public class TestExtractorFactory extends TestCase {
msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg"); msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg");
} }
@Test
public void testFile() throws Exception { public void testFile() throws Exception {
// Excel // Excel
POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls); POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls);
@ -297,6 +305,7 @@ public class TestExtractorFactory extends TestCase {
} }
} }
@Test
public void testInputStream() throws Exception { public void testInputStream() throws Exception {
// Excel // Excel
assertTrue( assertTrue(
@ -421,6 +430,7 @@ public class TestExtractorFactory extends TestCase {
} }
} }
@Test
public void testPOIFS() throws Exception { public void testPOIFS() throws Exception {
// Excel // Excel
assertTrue( assertTrue(
@ -501,6 +511,7 @@ public class TestExtractorFactory extends TestCase {
} }
} }
@Test
public void testPackage() throws Exception { public void testPackage() throws Exception {
// Excel // Excel
POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ)); POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
@ -550,6 +561,7 @@ public class TestExtractorFactory extends TestCase {
} }
} }
@Test
public void testPreferEventBased() throws Exception { public void testPreferEventBased() throws Exception {
assertFalse(ExtractorFactory.getPreferEventExtractor()); assertFalse(ExtractorFactory.getPreferEventExtractor());
assertFalse(ExtractorFactory.getThreadPrefersEventExtractors()); assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
@ -635,6 +647,7 @@ public class TestExtractorFactory extends TestCase {
* does poifs embeded, but will do ooxml ones * does poifs embeded, but will do ooxml ones
* at some point. * at some point.
*/ */
@Test
public void testEmbeded() throws Exception { public void testEmbeded() throws Exception {
POIOLE2TextExtractor ext; POIOLE2TextExtractor ext;
POITextExtractor[] embeds; POITextExtractor[] embeds;

View File

@ -37,7 +37,6 @@ import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.DrawingTextBody; import org.apache.poi.xslf.usermodel.DrawingTextBody;
@ -56,7 +55,6 @@ import org.junit.Test;
public class TestXSLFBugs { public class TestXSLFBugs {
@Test @Test
@SuppressWarnings("deprecation")
public void bug51187() throws Exception { public void bug51187() throws Exception {
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx"); XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
@ -64,29 +62,26 @@ public class TestXSLFBugs {
// Check the relations on it // Check the relations on it
// Note - rId3 is a self reference // Note - rId3 is a self reference
PackagePart slidePart = ss1._getXSLFSlideShow().getSlidePart( XSLFSlide slide0 = ss1.getSlides().get(0);
ss1._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
); assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString());
assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString()); assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString()); assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString()); assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString()); assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
// Save and re-load // Save and re-load
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1); XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
ss1.close(); ss1.close();
assertEquals(1, ss2.getSlides().size()); assertEquals(1, ss2.getSlides().size());
slidePart = ss2._getXSLFSlideShow().getSlidePart( slide0 = ss2.getSlides().get(0);
ss2._getXSLFSlideShow().getSlideReferences().getSldIdArray(0) assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString());
); assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString()); assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
// TODO Fix this // TODO Fix this
assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString()); assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString());
assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString()); assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString());
ss2.close(); ss2.close();
} }

View File

@ -22,6 +22,7 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xslf.usermodel.XSLFRelation; import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;

View File

@ -20,7 +20,7 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.POITextExtractor; import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import junit.framework.TestCase; import junit.framework.TestCase;

View File

@ -111,7 +111,7 @@ public class MAPIAttribute {
boolean isMV = false; boolean isMV = false;
boolean isVL = false; boolean isVL = false;
int typeId = typeAndMV; int typeId = typeAndMV;
if( (typeAndMV & Types.MULTIVALUED_FLAG) > 0 ) { if( (typeAndMV & Types.MULTIVALUED_FLAG) != 0 ) {
isMV = true; isMV = true;
typeId -= Types.MULTIVALUED_FLAG; typeId -= Types.MULTIVALUED_FLAG;
} }

View File

@ -17,7 +17,6 @@
package org.apache.poi.hslf.model.textproperties; package org.apache.poi.hslf.model.textproperties;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;