poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1858117 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hslf/extractor/PowerPointExtractor.java testcases/org/apache/poi/hslf/usermodel/TestBugs.java
Date Thu, 25 Apr 2019 12:27:04 GMT
Author: centic
Date: Thu Apr 25 12:27:04 2019
New Revision: 1858117

URL: http://svn.apache.org/viewvc?rev=1858117&view=rev
Log:
Make compilation work in Eclipse 2019.03 again by working around a 
limitation of the Eclipse Java Compiler regarding casting/generics

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java?rev=1858117&r1=1858116&r2=1858117&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java Thu
Apr 25 12:27:04 2019
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.extractor.POIOLE2TextExtractor;
 import org.apache.poi.hslf.usermodel.HSLFObjectShape;
 import org.apache.poi.hslf.usermodel.HSLFShape;
@@ -32,6 +33,7 @@ import org.apache.poi.hssf.record.crypto
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.sl.extractor.SlideShowExtractor;
+import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.util.Removal;
 
@@ -94,7 +96,7 @@ public final class PowerPointExtractor e
 	 * @param fileName The name of the file to extract from
 	 */
 	public PowerPointExtractor(String fileName) throws IOException {
-		this((HSLFSlideShow)SlideShowFactory.create(new File(fileName), Biff8EncryptionKey.getCurrentUserPassword(),
true));
+		this(createHSLF(new File(fileName), Biff8EncryptionKey.getCurrentUserPassword(), true));
 	}
 
 	/**
@@ -103,7 +105,7 @@ public final class PowerPointExtractor e
 	 * @param iStream The input stream containing the PowerPoint document
 	 */
 	public PowerPointExtractor(InputStream iStream) throws IOException {
-		this((HSLFSlideShow)SlideShowFactory.create(iStream, Biff8EncryptionKey.getCurrentUserPassword()));
+		this(createHSLF(iStream, Biff8EncryptionKey.getCurrentUserPassword()));
 	}
 
 	/**
@@ -112,7 +114,7 @@ public final class PowerPointExtractor e
 	 * @param fs the POIFSFileSystem containing the PowerPoint document
 	 */
 	public PowerPointExtractor(POIFSFileSystem fs) throws IOException {
-		this((HSLFSlideShow)SlideShowFactory.create(fs, Biff8EncryptionKey.getCurrentUserPassword()));
+		this(createHSLF(fs, Biff8EncryptionKey.getCurrentUserPassword()));
 	}
 
    /**
@@ -213,4 +215,65 @@ public final class PowerPointExtractor e
 	public List<HSLFObjectShape> getOLEShapes() {
 		return (List<HSLFObjectShape>)delegate.getOLEShapes();
 	}
+
+	/**
+	 * Helper method to avoid problems with compiling code in Eclipse
+	 *
+	 * Eclipse javac has some bugs with complex casts, this method tries
+	 * to work around this.
+	 *
+	 * @param fs The {@link POIFSFileSystem} to read the document from
+	 * @param password The password that should be used or null if no password is necessary.
+	 *
+	 * @return The created SlideShow
+	 *
+	 * @throws IOException if an error occurs while reading the data
+	 */
+	private static HSLFSlideShow createHSLF(POIFSFileSystem fs, String password) throws IOException,
EncryptedDocumentException {
+		// Note: don't change the code here, it is required for Eclipse to compile the code
+		SlideShow slideShowOrig = SlideShowFactory.create(fs, password);
+		return (HSLFSlideShow)slideShowOrig;
+	}
+
+	/**
+	 * Helper method to avoid problems with compiling code in Eclipse
+	 *
+	 * Eclipse javac has some bugs with complex casts, this method tries
+	 * to work around this.
+	 *
+	 *  @param inp The {@link InputStream} to read data from.
+	 *  @param password The password that should be used or null if no password is necessary.
+	 *
+	 *  @return The created SlideShow
+	 *
+	 *  @throws IOException if an error occurs while reading the data
+	 *  @throws EncryptedDocumentException If the wrong password is given for a protected file
+	 */
+	private static HSLFSlideShow createHSLF(InputStream inp, String password) throws IOException,
EncryptedDocumentException {
+		// Note: don't change the code here, it is required for Eclipse to compile the code
+		SlideShow slideShowOrig = SlideShowFactory.create(inp, password);
+		return (HSLFSlideShow)slideShowOrig;
+	}
+
+	/**
+	 * Helper method to avoid problems with compiling code in Eclipse
+	 *
+	 * Eclipse javac has some bugs with complex casts, this method tries
+	 * to work around this.
+	 *
+	 *  @param file The file to read data from.
+	 *  @param password The password that should be used or null if no password is necessary.
+	 *  @param readOnly If the SlideShow should be opened in read-only mode to avoid writing
back
+	 *      changes when the document is closed.
+	 *
+	 *  @return The created SlideShow
+	 *
+	 *  @throws IOException if an error occurs while reading the data
+	 *  @throws EncryptedDocumentException If the wrong password is given for a protected file
+	 */
+	private static HSLFSlideShow createHSLF(File file, String password, boolean readOnly) throws
IOException, EncryptedDocumentException {
+		// Note: don't change the code here, it is required for Eclipse to compile the code
+		SlideShow slideShowOrig = SlideShowFactory.create(file, password, readOnly);
+		return (HSLFSlideShow)slideShowOrig;
+	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=1858117&r1=1858116&r2=1858117&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java Thu Apr
25 12:27:04 2019
@@ -934,7 +934,9 @@ public final class TestBugs {
     
     private static HSLFSlideShow open(String fileName) throws IOException {
         File sample = HSLFTestDataSamples.getSampleFile(fileName);
-        return (HSLFSlideShow)SlideShowFactory.create(sample);
+        // Note: don't change the code here, it is required for Eclipse to compile the code
+        SlideShow slideShowOrig = SlideShowFactory.create(sample, null, false);
+        return (HSLFSlideShow)slideShowOrig;
     }
 
     @Test



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message