From: Andreas Beeker Date: Wed, 30 Sep 2015 23:06:39 +0000 (+0000) Subject: sonar fixes X-Git-Tag: REL_3_14_BETA1~279 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fad6546d8a8172aaf197a95a4af086a387390fbb;p=poi.git 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 --- diff --git a/src/examples/src/org/apache/poi/hssf/view/SVSheetTable.java b/src/examples/src/org/apache/poi/hssf/view/SVSheetTable.java index ed2fd8fb6d..1739eb6160 100644 --- a/src/examples/src/org/apache/poi/hssf/view/SVSheetTable.java +++ b/src/examples/src/org/apache/poi/hssf/view/SVSheetTable.java @@ -163,7 +163,7 @@ public class SVSheetTable extends JTable { Row row = sheet.getRow(i - sheet.getFirstRowNum()); if (row != null) { 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); setRowHeight(i, height); } diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java index 69b570f7d3..3f044c839e 100644 --- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java +++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java @@ -19,10 +19,10 @@ package org.apache.poi.xssf.usermodel.examples; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.openxml4j.opc.OPCPackage; 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.hslf.usermodel.HSLFSlideShowImpl; import org.apache.poi.hwpf.HWPFDocument; -import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import java.io.InputStream; diff --git a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java index 9278f32f3e..bbfdc661c7 100644 --- a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java @@ -24,9 +24,9 @@ import java.io.FileInputStream; import java.io.InputStream; import org.apache.poi.extractor.ExtractorFactory; -import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.junit.Test; public class XSLFFileHandler extends SlideShowHandler { diff --git a/src/java/org/apache/poi/ddf/EscherTextboxRecord.java b/src/java/org/apache/poi/ddf/EscherTextboxRecord.java index 75d5b2528a..f694ecf18b 100644 --- a/src/java/org/apache/poi/ddf/EscherTextboxRecord.java +++ b/src/java/org/apache/poi/ddf/EscherTextboxRecord.java @@ -27,7 +27,7 @@ import org.apache.poi.util.RecordFormatException; * Escher format. We don't attempt to understand the contents, since * 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 String RECORD_DESCRIPTION = "msofbtClientTextbox"; diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index eeed53e4c3..787462c635 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -318,6 +318,38 @@ public class Section 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() { final StringBuffer b = new StringBuffer(); diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index c6d0ae51c9..cbb921b2f7 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -164,7 +164,7 @@ public final class InternalSheet { int dimsloc = -1; if (rs.peekNextSid() != BOFRecord.sid) { - throw new RuntimeException("BOF record expected"); + throw new RecordFormatException("BOF record expected"); } BOFRecord bof = (BOFRecord) rs.getNext(); @@ -210,7 +210,7 @@ public final class InternalSheet { if (RecordOrderer.isRowBlockRecord(recSid)) { //only add the aggregate once 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); _mergedCellsTable.addRecords(rbr.getLooseMergedCells()); @@ -332,7 +332,7 @@ public final class InternalSheet { records.add(rec); } if (windowTwo == null) { - throw new RuntimeException("WINDOW2 was not found"); + throw new RecordFormatException("WINDOW2 was not found"); } if (_dimensions == null) { // Excel seems to always write the DIMENSION record, but tolerates when it is not present @@ -393,7 +393,7 @@ public final class InternalSheet { try { _destList.add((Record)r.clone()); } 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(); clonedRecords.add(rec); } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); + throw new RecordFormatException(e); } } return createSheet(new RecordStream(clonedRecords, 0)); diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderBase.java b/src/java/org/apache/poi/hssf/record/CFHeaderBase.java index 0b8182d556..aa9f2daf03 100644 --- a/src/java/org/apache/poi/hssf/record/CFHeaderBase.java +++ b/src/java/org/apache/poi/hssf/record/CFHeaderBase.java @@ -152,5 +152,5 @@ public abstract class CFHeaderBase extends StandardRecord implements Cloneable { } @Override - public abstract CFHeaderBase clone(); + public abstract CFHeaderBase clone(); // NOSONAR } diff --git a/src/java/org/apache/poi/hssf/record/FilePassRecord.java b/src/java/org/apache/poi/hssf/record/FilePassRecord.java index 4793f13055..ca5b3e29f6 100644 --- a/src/java/org/apache/poi/hssf/record/FilePassRecord.java +++ b/src/java/org/apache/poi/hssf/record/FilePassRecord.java @@ -41,10 +41,10 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { void serialize(LittleEndianOutput out); int getDataSize(); 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_CAPI_2 = 2; 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. * See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR diff --git a/src/java/org/apache/poi/hssf/record/IndexRecord.java b/src/java/org/apache/poi/hssf/record/IndexRecord.java index 6e9558db2d..ca1ad35e46 100644 --- a/src/java/org/apache/poi/hssf/record/IndexRecord.java +++ b/src/java/org/apache/poi/hssf/record/IndexRecord.java @@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndianOutput; * @author Andrew C. Oliver (acoliver at apache dot org) * @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; private int field_2_first_row; // first row on the sheet private int field_3_last_row_add1; // last row diff --git a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java index c43e4f5aee..3e1eab8a4d 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java @@ -28,6 +28,7 @@ import org.apache.poi.hssf.record.CFRule12Record; import org.apache.poi.hssf.record.CFRuleBase; import org.apache.poi.hssf.record.CFRuleRecord; 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.ptg.AreaErrPtg; 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"); } if (pRules.length != pHeader.getNumberOfConditionalFormats()) { - throw new RuntimeException("Mismatch number of rules"); + throw new RecordFormatException("Mismatch number of rules"); } header = pHeader; rules = new ArrayList(pRules.length); @@ -119,9 +120,9 @@ public final class CFRecordsAggregate extends RecordAggregate { public CFRecordsAggregate cloneCFAggregate() { CFRuleBase[] newRecs = new CFRuleBase[rules.size()]; 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); } /** diff --git a/src/java/org/apache/poi/poifs/filesystem/BlockStore.java b/src/java/org/apache/poi/poifs/filesystem/BlockStore.java index 1da9b6a965..0ef8082270 100644 --- a/src/java/org/apache/poi/poifs/filesystem/BlockStore.java +++ b/src/java/org/apache/poi/poifs/filesystem/BlockStore.java @@ -80,7 +80,7 @@ public abstract class BlockStore { protected class ChainLoopDetector { private boolean[] used_blocks; protected ChainLoopDetector(long rawSize) { - int numBlocks = (int)Math.ceil( rawSize / getBlockStoreBlockSize() ); + int numBlocks = (int)Math.ceil( ((double)rawSize) / getBlockStoreBlockSize() ); used_blocks = new boolean[numBlocks]; } protected void claim(int offset) { diff --git a/src/java/org/apache/poi/poifs/property/NPropertyTable.java b/src/java/org/apache/poi/poifs/property/NPropertyTable.java index eb2e51458a..ec38ddecb2 100644 --- a/src/java/org/apache/poi/poifs/property/NPropertyTable.java +++ b/src/java/org/apache/poi/poifs/property/NPropertyTable.java @@ -120,7 +120,7 @@ public final class NPropertyTable extends PropertyTableBase { public int countBlocks() { int size = _properties.size() * POIFSConstants.PROPERTY_SIZE; - return (int)Math.ceil(size / _bigBigBlockSize.getBigBlockSize()); + return (int)Math.ceil( ((double)size) / _bigBigBlockSize.getBigBlockSize()); } /** diff --git a/src/java/org/apache/poi/sl/usermodel/Insets2D.java b/src/java/org/apache/poi/sl/usermodel/Insets2D.java index fedfbff7ee..c7e59c27f5 100644 --- a/src/java/org/apache/poi/sl/usermodel/Insets2D.java +++ b/src/java/org/apache/poi/sl/usermodel/Insets2D.java @@ -21,7 +21,7 @@ package org.apache.poi.sl.usermodel; * This is a replacement for {@link java.awt.Insets} which works on doubles * instead of ints */ -public class Insets2D implements Cloneable { +public final class Insets2D implements Cloneable { /** * The inset from the top. diff --git a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java index 2ef23d2da1..59ebeb10d0 100644 --- a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java @@ -55,9 +55,9 @@ import org.apache.poi.poifs.filesystem.NotOLE2FileException; import org.apache.poi.poifs.filesystem.OPOIFSFileSystem; import org.apache.poi.poifs.filesystem.OfficeXmlFileException; 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.usermodel.XSLFRelation; +import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFRelation; diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index 3b917a6fbe..26331fbccf 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -48,6 +48,10 @@ public final class PackagePropertiesPart extends PackagePart implements 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. * @@ -386,8 +390,8 @@ public final class PackagePropertiesPart extends PackagePart implements try { this.created = setDateValue(created); } catch (InvalidFormatException e) { - new IllegalArgumentException("created : " - + e.getLocalizedMessage()); + throw new IllegalArgumentException("created : " + + e.getLocalizedMessage(), e); } } @@ -464,8 +468,8 @@ public final class PackagePropertiesPart extends PackagePart implements try { this.lastPrinted = setDateValue(lastPrinted); } catch (InvalidFormatException e) { - new IllegalArgumentException("lastPrinted : " - + e.getLocalizedMessage()); + throw new IllegalArgumentException("lastPrinted : " + + e.getLocalizedMessage(), e); } } @@ -488,8 +492,8 @@ public final class PackagePropertiesPart extends PackagePart implements try { this.modified = setDateValue(modified); } catch (InvalidFormatException e) { - new IllegalArgumentException("modified : " - + e.getLocalizedMessage()); + throw new IllegalArgumentException("modified : " + + e.getLocalizedMessage(), e); } } @@ -559,9 +563,17 @@ public final class PackagePropertiesPart extends PackagePart implements if (s == null || s.equals("")) { return new Nullable(); } - 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); 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) { throw new InvalidFormatException("Date not well formated"); } @@ -585,7 +597,7 @@ public final class PackagePropertiesPart extends PackagePart implements 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); return df.format(date); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java index 136f3e0eb5..493afb843b 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java @@ -28,6 +28,7 @@ import static org.apache.poi.poifs.crypt.dsig.facets.XAdESSignatureFacet.insertX import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.math.BigInteger; import java.security.cert.CRLException; import java.security.cert.CertificateEncodingException; @@ -324,21 +325,25 @@ public class XAdESXLSignatureFacet extends SignatureFacet { } private BigInteger getCrlNumber(X509CRL crl) { + byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId()); + if (null == crlNumberExtensionValue) { + return null; + } + try { - byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId()); - if (null == crlNumberExtensionValue) { - return null; + ASN1InputStream asn1IS1 = null, asn1IS2 = null; + try { + asn1IS1 = new ASN1InputStream(crlNumberExtensionValue); + ASN1OctetString octetString = (ASN1OctetString)asn1IS1.readObject(); + byte[] octets = octetString.getOctets(); + asn1IS2 = new ASN1InputStream(octets); + ASN1Integer integer = (ASN1Integer)asn1IS2.readObject(); + return integer.getPositiveValue(); + } finally { + asn1IS2.close(); + asn1IS1.close(); } - - @SuppressWarnings("resource") - ASN1InputStream asn1InputStream = new ASN1InputStream(crlNumberExtensionValue); - ASN1OctetString octetString = (ASN1OctetString)asn1InputStream.readObject(); - byte[] octets = octetString.getOctets(); - asn1InputStream = new ASN1InputStream(octets); - ASN1Integer integer = (ASN1Integer)asn1InputStream.readObject(); - BigInteger crlNumber = integer.getPositiveValue(); - return crlNumber; - } catch (Exception e) { + } catch (IOException e) { throw new RuntimeException("I/O error: " + e.getMessage(), e); } } diff --git a/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java deleted file mode 100644 index 7f0f1b773c..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java +++ /dev/null @@ -1,262 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xslf; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import org.apache.poi.POIXMLDocument; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; -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.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; -import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; -import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList; -import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; -import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument; -import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument; -import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument; -import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; -import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; - -/** - * Experimental class to do low level processing of pptx files. - * - * Most users should use the higher level {@link XMLSlideShow} instead. - * - * If you are using these low level classes, then you - * will almost certainly need to refer to the OOXML - * specifications from - * http://www.ecma-international.org/publications/standards/Ecma-376.htm - * - * WARNING - APIs expected to change rapidly - */ -public class XSLFSlideShow extends POIXMLDocument { - - private PresentationDocument presentationDoc; - /** - * The embedded OLE2 files in the OPC package - */ - private List embedds; - - @SuppressWarnings("deprecation") - public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { - super(container); - - if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) { - rebase(getPackage()); - } - - presentationDoc = - PresentationDocument.Factory.parse(getCorePart().getInputStream()); - - embedds = new LinkedList(); - for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) { - PackagePart corePart = getCorePart(); - PackagePart slidePart = corePart.getRelatedPart( - corePart.getRelationship(ctSlide.getId2())); - - for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well - - for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); - } - } - public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException { - this(openPackage(file)); - } - - /** - * Returns the low level presentation base object - */ - @Internal - public CTPresentation getPresentation() { - return presentationDoc.getPresentation(); - } - - /** - * Returns the references from the presentation to its - * slides. - * You'll need these to figure out the slide ordering, - * and to get at the actual slides themselves - */ - @Internal - public CTSlideIdList getSlideReferences() { - if(! getPresentation().isSetSldIdLst()) { - getPresentation().setSldIdLst( - CTSlideIdList.Factory.newInstance() - ); - } - return getPresentation().getSldIdLst(); - } - - /** - * Returns the references from the presentation to its - * slide masters. - * You'll need these to get at the actual slide - * masters themselves - */ - @Internal - public CTSlideMasterIdList getSlideMasterReferences() { - return getPresentation().getSldMasterIdLst(); - } - - public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException { - try { - PackagePart corePart = getCorePart(); - return corePart.getRelatedPart( - corePart.getRelationship(master.getId2()) - ); - } catch(InvalidFormatException e) { - throw new XmlException(e); - } - } - /** - * Returns the low level slide master object from - * the supplied slide master reference - */ - @Internal - public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException { - PackagePart masterPart = getSlideMasterPart(master); - SldMasterDocument masterDoc = - SldMasterDocument.Factory.parse(masterPart.getInputStream()); - return masterDoc.getSldMaster(); - } - - public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException { - try { - PackagePart corePart = getCorePart(); - return corePart.getRelatedPart( - corePart.getRelationship(slide.getId2()) - ); - } catch(InvalidFormatException e) { - throw new XmlException(e); - } - } - /** - * Returns the low level slide object from - * the supplied slide reference - */ - @Internal - public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException { - PackagePart slidePart = getSlidePart(slide); - SldDocument slideDoc = - SldDocument.Factory.parse(slidePart.getInputStream()); - return slideDoc.getSld(); - } - - /** - * Gets the PackagePart of the notes for the - * given slide, or null if there isn't one. - */ - public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException { - PackageRelationshipCollection notes; - PackagePart slidePart = getSlidePart(parentSlide); - - try { - notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation()); - } catch(InvalidFormatException e) { - throw new IllegalStateException(e); - } - - if(notes.size() == 0) { - // No notes for this slide - return null; - } - if(notes.size() > 1) { - throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size()); - } - - try { - return slidePart.getRelatedPart(notes.getRelationship(0)); - } catch(InvalidFormatException e) { - throw new IllegalStateException(e); - } - } - /** - * Returns the low level notes object for the given - * slide, as found from the supplied slide reference - */ - @Internal - public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException { - PackagePart notesPart = getNodesPart(slide); - if(notesPart == null) - return null; - - NotesDocument notesDoc = - NotesDocument.Factory.parse(notesPart.getInputStream()); - - return notesDoc.getNotes(); - } - - /** - * Returns all the comments for the given slide - */ - @Internal - public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException { - PackageRelationshipCollection commentRels; - PackagePart slidePart = getSlidePart(slide); - - try { - commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation()); - } catch(InvalidFormatException e) { - throw new IllegalStateException(e); - } - - if(commentRels.size() == 0) { - // No comments for this slide - return null; - } - if(commentRels.size() > 1) { - throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size()); - } - - try { - PackagePart cPart = slidePart.getRelatedPart( - commentRels.getRelationship(0) - ); - CmLstDocument commDoc = - CmLstDocument.Factory.parse(cPart.getInputStream()); - return commDoc.getCmLst(); - } catch(InvalidFormatException e) { - throw new IllegalStateException(e); - } - } - - /** - * Get the document's embedded files. - */ - @Override - public List getAllEmbedds() throws OpenXML4JException { - return embedds; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java b/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java index 266ebb395d..cad527032f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java +++ b/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.poi.POIXMLTextExtractor; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; 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.DrawingTextBody; 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.XSLFSlideLayout; import org.apache.poi.xslf.usermodel.XSLFSlideMaster; +import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTComment; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index a327630ba8..f61d743a19 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -49,7 +49,6 @@ import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.PackageHelper; import org.apache.poi.util.Units; -import org.apache.poi.xslf.XSLFSlideShow; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; @@ -124,12 +123,6 @@ implements SlideShow { } } - // TODO get rid of this method - @Deprecated - public XSLFSlideShow _getXSLFSlideShow() throws OpenXML4JException, IOException, XmlException{ - return new XSLFSlideShow(getPackage()); - } - @Override protected void onDocumentRead() throws IOException { try { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java new file mode 100644 index 0000000000..6d17cbb4c7 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java @@ -0,0 +1,260 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xslf.usermodel; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import org.apache.poi.POIXMLDocument; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.exceptions.OpenXML4JException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackagePart; +import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; +import org.apache.poi.util.Internal; +import org.apache.xmlbeans.XmlException; +import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; +import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; +import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; + +/** + * Experimental class to do low level processing of pptx files. + * + * Most users should use the higher level {@link XMLSlideShow} instead. + * + * If you are using these low level classes, then you + * will almost certainly need to refer to the OOXML + * specifications from + * http://www.ecma-international.org/publications/standards/Ecma-376.htm + * + * WARNING - APIs expected to change rapidly + */ +public class XSLFSlideShow extends POIXMLDocument { + + private PresentationDocument presentationDoc; + /** + * The embedded OLE2 files in the OPC package + */ + private List embedds; + + @SuppressWarnings("deprecation") + public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { + super(container); + + if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) { + rebase(getPackage()); + } + + presentationDoc = + PresentationDocument.Factory.parse(getCorePart().getInputStream()); + + embedds = new LinkedList(); + for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) { + PackagePart corePart = getCorePart(); + PackagePart slidePart = corePart.getRelatedPart( + corePart.getRelationship(ctSlide.getId2())); + + for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) + embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well + + for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) + embedds.add(slidePart.getRelatedPart(rel)); + } + } + public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException { + this(openPackage(file)); + } + + /** + * Returns the low level presentation base object + */ + @Internal + public CTPresentation getPresentation() { + return presentationDoc.getPresentation(); + } + + /** + * Returns the references from the presentation to its + * slides. + * You'll need these to figure out the slide ordering, + * and to get at the actual slides themselves + */ + @Internal + public CTSlideIdList getSlideReferences() { + if(! getPresentation().isSetSldIdLst()) { + getPresentation().setSldIdLst( + CTSlideIdList.Factory.newInstance() + ); + } + return getPresentation().getSldIdLst(); + } + + /** + * Returns the references from the presentation to its + * slide masters. + * You'll need these to get at the actual slide + * masters themselves + */ + @Internal + public CTSlideMasterIdList getSlideMasterReferences() { + return getPresentation().getSldMasterIdLst(); + } + + public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException { + try { + PackagePart corePart = getCorePart(); + return corePart.getRelatedPart( + corePart.getRelationship(master.getId2()) + ); + } catch(InvalidFormatException e) { + throw new XmlException(e); + } + } + /** + * Returns the low level slide master object from + * the supplied slide master reference + */ + @Internal + public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException { + PackagePart masterPart = getSlideMasterPart(master); + SldMasterDocument masterDoc = + SldMasterDocument.Factory.parse(masterPart.getInputStream()); + return masterDoc.getSldMaster(); + } + + public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException { + try { + PackagePart corePart = getCorePart(); + return corePart.getRelatedPart( + corePart.getRelationship(slide.getId2()) + ); + } catch(InvalidFormatException e) { + throw new XmlException(e); + } + } + /** + * Returns the low level slide object from + * the supplied slide reference + */ + @Internal + public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException { + PackagePart slidePart = getSlidePart(slide); + SldDocument slideDoc = + SldDocument.Factory.parse(slidePart.getInputStream()); + return slideDoc.getSld(); + } + + /** + * Gets the PackagePart of the notes for the + * given slide, or null if there isn't one. + */ + public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException { + PackageRelationshipCollection notes; + PackagePart slidePart = getSlidePart(parentSlide); + + try { + notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation()); + } catch(InvalidFormatException e) { + throw new IllegalStateException(e); + } + + if(notes.size() == 0) { + // No notes for this slide + return null; + } + if(notes.size() > 1) { + throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size()); + } + + try { + return slidePart.getRelatedPart(notes.getRelationship(0)); + } catch(InvalidFormatException e) { + throw new IllegalStateException(e); + } + } + /** + * Returns the low level notes object for the given + * slide, as found from the supplied slide reference + */ + @Internal + public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException { + PackagePart notesPart = getNodesPart(slide); + if(notesPart == null) + return null; + + NotesDocument notesDoc = + NotesDocument.Factory.parse(notesPart.getInputStream()); + + return notesDoc.getNotes(); + } + + /** + * Returns all the comments for the given slide + */ + @Internal + public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException { + PackageRelationshipCollection commentRels; + PackagePart slidePart = getSlidePart(slide); + + try { + commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation()); + } catch(InvalidFormatException e) { + throw new IllegalStateException(e); + } + + if(commentRels.size() == 0) { + // No comments for this slide + return null; + } + if(commentRels.size() > 1) { + throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size()); + } + + try { + PackagePart cPart = slidePart.getRelatedPart( + commentRels.getRelationship(0) + ); + CmLstDocument commDoc = + CmLstDocument.Factory.parse(cPart.getInputStream()); + return commDoc.getCmLst(); + } catch(InvalidFormatException e) { + throw new IllegalStateException(e); + } + } + + /** + * Get the document's embedded files. + */ + @Override + public List getAllEmbedds() throws OpenXML4JException { + return embedds; + } + +} diff --git a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java index fee804a9ae..fb16b8a0e6 100644 --- a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java +++ b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java @@ -20,7 +20,7 @@ package org.apache.poi; 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.xwpf.usermodel.XWPFDocument; import org.apache.poi.openxml4j.opc.OPCPackage; diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java index 0df6ccf816..9ba1333c3d 100644 --- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java @@ -20,7 +20,7 @@ import junit.framework.TestCase; import org.apache.poi.openxml4j.opc.OPCPackage; 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.usermodel.XSSFWorkbook; diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index a8644f4202..3d2d2a5b15 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -16,12 +16,17 @@ ==================================================================== */ 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.FileInputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.apache.poi.POIDataSamples; import org.apache.poi.POIOLE2TextExtractor; 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.XSSFExcelExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; +import org.junit.BeforeClass; +import org.junit.Test; /** * Test that the extractor factory plays nicely */ -public class TestExtractorFactory extends TestCase { - private File txt; +public class TestExtractorFactory { + private static File txt; - private File xls; - private File xlsx; - private File xlsxStrict; - private File xltx; - private File xlsEmb; + private static File xls; + private static File xlsx; + private static File xlsxStrict; + private static File xltx; + private static File xlsEmb; - private File doc; - private File doc6; - private File doc95; - private File docx; - private File dotx; - private File docEmb; - private File docEmbOOXML; + private static File doc; + private static File doc6; + private static File doc95; + private static File docx; + private static File dotx; + private static File docEmb; + private static File docEmbOOXML; - private File ppt; - private File pptx; + private static File ppt; + private static File pptx; - private File msg; - private File msgEmb; - private File msgEmbMsg; + private static File msg; + private static File msgEmb; + private static File msgEmbMsg; - private File vsd; - private File vsdx; + private static File vsd; + 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); assertNotNull("Did not get a file for " + name, file); @@ -85,9 +92,9 @@ public class TestExtractorFactory extends TestCase { return file; } - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeClass + public static void setUp() throws Exception { POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance(); xls = getFileAndCheck(ssTests, "SampleSS.xls"); @@ -123,6 +130,7 @@ public class TestExtractorFactory extends TestCase { msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg"); } + @Test public void testFile() throws Exception { // Excel POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls); @@ -297,6 +305,7 @@ public class TestExtractorFactory extends TestCase { } } + @Test public void testInputStream() throws Exception { // Excel assertTrue( @@ -421,6 +430,7 @@ public class TestExtractorFactory extends TestCase { } } + @Test public void testPOIFS() throws Exception { // Excel assertTrue( @@ -501,6 +511,7 @@ public class TestExtractorFactory extends TestCase { } } + @Test public void testPackage() throws Exception { // Excel 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 { assertFalse(ExtractorFactory.getPreferEventExtractor()); assertFalse(ExtractorFactory.getThreadPrefersEventExtractors()); @@ -635,6 +647,7 @@ public class TestExtractorFactory extends TestCase { * does poifs embeded, but will do ooxml ones * at some point. */ + @Test public void testEmbeded() throws Exception { POIOLE2TextExtractor ext; POITextExtractor[] embeds; diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java index 0f1d14f4cb..1c6656bef5 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java @@ -37,7 +37,6 @@ import java.util.List; import javax.imageio.ImageIO; import org.apache.poi.POIXMLDocumentPart; -import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingTextBody; @@ -56,7 +55,6 @@ import org.junit.Test; public class TestXSLFBugs { @Test - @SuppressWarnings("deprecation") public void bug51187() throws Exception { XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx"); @@ -64,29 +62,26 @@ public class TestXSLFBugs { // Check the relations on it // Note - rId3 is a self reference - PackagePart slidePart = ss1._getXSLFSlideShow().getSlidePart( - ss1._getXSLFSlideShow().getSlideReferences().getSldIdArray(0) - ); - assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString()); - assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString()); - assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString()); - assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString()); - assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString()); + XSLFSlide slide0 = ss1.getSlides().get(0); + + assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString()); + assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString()); + assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString()); + assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString()); + assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString()); // Save and re-load XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1); ss1.close(); assertEquals(1, ss2.getSlides().size()); - slidePart = ss2._getXSLFSlideShow().getSlidePart( - ss2._getXSLFSlideShow().getSlideReferences().getSldIdArray(0) - ); - assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString()); - assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString()); - assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString()); + slide0 = ss2.getSlides().get(0); + assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString()); + assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString()); + assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString()); // TODO Fix this - assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString()); - assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString()); + assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString()); + assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString()); ss2.close(); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java index b34a0d1c4e..2a21972f13 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java @@ -22,6 +22,7 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; 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.CTSlideMasterIdListEntry; diff --git a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java index 5b61979570..346aeab898 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java @@ -20,7 +20,7 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.POITextExtractor; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.xslf.XSLFSlideShow; +import org.apache.poi.xslf.usermodel.XSLFSlideShow; import junit.framework.TestCase; diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java index 7f27de3e3b..84161f8482 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java @@ -111,7 +111,7 @@ public class MAPIAttribute { boolean isMV = false; boolean isVL = false; int typeId = typeAndMV; - if( (typeAndMV & Types.MULTIVALUED_FLAG) > 0 ) { + if( (typeAndMV & Types.MULTIVALUED_FLAG) != 0 ) { isMV = true; typeId -= Types.MULTIVALUED_FLAG; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java index c76b05cd25..2b626e643d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java @@ -17,7 +17,6 @@ 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.POILogger;