]> source.dussan.org Git - poi.git/commitdiff
sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 30 Sep 2015 23:06:39 +0000 (23:06 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 30 Sep 2015 23:06:39 +0000 (23:06 +0000)
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

28 files changed:
src/examples/src/org/apache/poi/hssf/view/SVSheetTable.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java
src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
src/java/org/apache/poi/ddf/EscherTextboxRecord.java
src/java/org/apache/poi/hpsf/Section.java
src/java/org/apache/poi/hssf/model/InternalSheet.java
src/java/org/apache/poi/hssf/record/CFHeaderBase.java
src/java/org/apache/poi/hssf/record/FilePassRecord.java
src/java/org/apache/poi/hssf/record/IndexRecord.java
src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
src/java/org/apache/poi/poifs/filesystem/BlockStore.java
src/java/org/apache/poi/poifs/property/NPropertyTable.java
src/java/org/apache/poi/sl/usermodel/Insets2D.java
src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java [deleted file]
src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/TestEmbeded.java
src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java
src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java
src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java

index ed2fd8fb6d0084d4979dd7652068c8e3bb646c1a..1739eb61603479a1eda2426e0421f10fa70caf43 100644 (file)
@@ -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);
       }
index 69b570f7d3ea94b0c3e88b92d46c0f6f220aebb3..3f044c839e29c25c0d5313e3485eac74255e0d5b 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.poi.xssf.usermodel.examples;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
 import org.apache.poi.openxml4j.opc.OPCPackage;\r
 import org.apache.poi.openxml4j.opc.PackagePart;\r
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;\r
 import org.apache.poi.xwpf.usermodel.XWPFDocument;\r
 import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;\r
 import org.apache.poi.hwpf.HWPFDocument;\r
-import org.apache.poi.xslf.XSLFSlideShow;\r
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
 \r
 import java.io.InputStream;\r
index 9278f32f3ef33371e3180dca898b41e5135cb7c0..bbfdc661c7620af621ef9c7eb5909720f8a3e855 100644 (file)
@@ -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 {
index 75d5b2528ada924b740cb3d0c85f09a528b8ff18..f694ecf18ba90a86695bebef45218b6a9731c60f 100644 (file)
@@ -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";
 
index eeed53e4c31988cbfc175d174e30601029ca9103..787462c6358024d009c3cac2a5ab89aaf6d90804 100644 (file)
@@ -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();
index c6d0ae51c933c62e67a64e78a1bc86c7ad24375e..cbb921b2f7c15a8b2d75aa1d54f2da692c2cd676 100644 (file)
@@ -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));
index 0b8182d5568a40a0ea22795aa302d89fd9642e08..aa9f2daf03aa88444cd94a71ea4fb36dacdd7fc5 100644 (file)
@@ -152,5 +152,5 @@ public abstract class CFHeaderBase extends StandardRecord implements Cloneable {
     }
 
     @Override
-    public abstract CFHeaderBase clone();
+    public abstract CFHeaderBase clone(); // NOSONAR
 }
index 4793f13055bcdef253b320b2f6f15f0e99e8fb15..ca5b3e29f65a07e883211c0ce5303e83469f217f 100644 (file)
@@ -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
index 6e9558db2dac22ed4f1e6a61de31f558fef8245d..ca1ad35e4665be1d0bbf0af49f65f875526a6a51 100644 (file)
@@ -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
index c43e4f5aee61f947d234a30f7935e4dde759f428..3e1eab8a4d619f7fbc8b9c01a4c33ebe0ecd6358 100644 (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.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<CFRuleBase>(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);
     }
 
     /**
index 1da9b6a965e6e10c2388fdd7d71b544f3338cf7f..0ef8082270350d0fab2d39a97e89e5cd614bd3fd 100644 (file)
@@ -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) {
index eb2e51458a3f74412e74f6ea6205da6567a77a0f..ec38ddecb22b0af108d96c979026a679eb3f9a46 100644 (file)
@@ -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());
     }
  
     /**
index fedfbff7ee18ba77fe91100acce963f36b6e62e3..c7e59c27f5c5eb162fc81a674db8ba2da16be0d8 100644 (file)
@@ -21,7 +21,7 @@ package org.apache.poi.sl.usermodel;
  * This is a replacement for {@link java.awt.Insets} which works on doubles\r
  * instead of ints\r
  */\r
-public class Insets2D implements Cloneable {\r
+public final class Insets2D implements Cloneable {\r
 \r
     /**\r
      * The inset from the top.\r
index 2ef23d2da10e1cdf4e894d1ff8c1b4a5f7b8abe2..59ebeb10d0f217883f5210c0a85df185c3dc5e91 100644 (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.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;
index 3b917a6fbec6ef9e68c30ca1d3c1990ccab2eb4a..26331fbccf9edfa99b2904f670ef4316609c3130 100644 (file)
@@ -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<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);
                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);
        }
index 136f3e0eb50e58a4cd267b21a52f6c17086942ea..493afb843b4a020e0baac8d3ae1753c9635ba3b4 100644 (file)
@@ -28,6 +28,7 @@ import static org.apache.poi.poifs.crypt.dsig.facets.XAdESSignatureFacet.insertX
 \r
 import java.io.ByteArrayInputStream;\r
 import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
 import java.math.BigInteger;\r
 import java.security.cert.CRLException;\r
 import java.security.cert.CertificateEncodingException;\r
@@ -324,21 +325,25 @@ public class XAdESXLSignatureFacet extends SignatureFacet {
     }\r
 \r
     private BigInteger getCrlNumber(X509CRL crl) {\r
+        byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());\r
+        if (null == crlNumberExtensionValue) {\r
+            return null;\r
+        }\r
+\r
         try {\r
-            byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());\r
-            if (null == crlNumberExtensionValue) {\r
-                return null;\r
+            ASN1InputStream asn1IS1 = null, asn1IS2 = null;\r
+            try {\r
+                asn1IS1 = new ASN1InputStream(crlNumberExtensionValue);\r
+                ASN1OctetString octetString = (ASN1OctetString)asn1IS1.readObject();\r
+                byte[] octets = octetString.getOctets();\r
+                asn1IS2 = new ASN1InputStream(octets);\r
+                ASN1Integer integer = (ASN1Integer)asn1IS2.readObject();\r
+                return integer.getPositiveValue();\r
+            } finally {\r
+                asn1IS2.close();\r
+                asn1IS1.close();\r
             }\r
-\r
-            @SuppressWarnings("resource")\r
-            ASN1InputStream asn1InputStream = new ASN1InputStream(crlNumberExtensionValue);\r
-            ASN1OctetString octetString = (ASN1OctetString)asn1InputStream.readObject();\r
-            byte[] octets = octetString.getOctets();\r
-            asn1InputStream = new ASN1InputStream(octets);\r
-            ASN1Integer integer = (ASN1Integer)asn1InputStream.readObject();\r
-            BigInteger crlNumber = integer.getPositiveValue();\r
-            return crlNumber;\r
-        } catch (Exception e) {\r
+        } catch (IOException e) {\r
             throw new RuntimeException("I/O error: " + e.getMessage(), e);\r
         }\r
     }\r
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 (file)
index 7f0f1b7..0000000
+++ /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<PackagePart> 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<PackagePart>();
-      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<PackagePart> getAllEmbedds() throws OpenXML4JException {
-        return embedds;
-    }
-
-}
index 266ebb395d4667908bf408520fb5852075faea5d..cad527032f5e26dbafb2940273e2e47169efd2f2 100644 (file)
@@ -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;
index a327630ba8439b3e118146f0bc6c3d47350b998f..f61d743a19babff6d63a7ead1ab5efeb5b7f62b9 100644 (file)
@@ -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<XSLFShape,XSLFTextParagraph> {
         }
     }
 
-    // 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 (file)
index 0000000..6d17cbb
--- /dev/null
@@ -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<PackagePart> 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<PackagePart>();
+      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<PackagePart> getAllEmbedds() throws OpenXML4JException {
+        return embedds;
+    }
+
+}
index fee804a9aee5c19a487e68bf33da958d583cd2e1..fb16b8a0e6de5f2026b455929947d877fb6cd126 100644 (file)
@@ -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;
index 0df6ccf8164dc60fb8748d933109e0740a5b9228..9ba1333c3d0b5a22ed3eb8ab588c9a3424f5be4e 100644 (file)
@@ -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;
 
index a8644f420295c518cd9fdc3e234f391df0236bd9..3d2d2a5b1533203a4682a72d815fe2c3623a6be2 100644 (file)
 ==================================================================== */
 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;
index 0f1d14f4cbfead145da3b1ab8d5f5a58af74a042..1c6656bef570f56b75073f56261dcadf80d1fd3d 100644 (file)
@@ -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();
     }
index b34a0d1c4e82a80eff96357d1c424250e3c9bb86..2a21972f130998a31b24af73cc1750c70386eca7 100644 (file)
@@ -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;
 
index 5b61979570c5c01ce177f0df28f913235941d1d7..346aeab898f482e422b128e015a8174bdecd8aa4 100644 (file)
@@ -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;
 
index 7f27de3e3be59a763639f5026de326ff6cf94352..84161f8482afe6b16ce70d423f743b4d23d337e5 100644 (file)
@@ -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;
          }
index c76b05cd25b4b82cdf6ebafc807e4023e7894f5b..2b626e643d3bbf998dde2fa09546a4cc575d5986 100644 (file)
@@ -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;