incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robw...@apache.org
Subject svn commit: r1396272 - in /incubator/odf/trunk/odfdom/src: main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java test/java/org/odftoolkit/odfdom/pkg/PackageTest.java
Date Tue, 09 Oct 2012 20:06:37 GMT
Author: robweir
Date: Tue Oct  9 20:06:36 2012
New Revision: 1396272

URL: http://svn.apache.org/viewvc?rev=1396272&view=rev
Log:
Integrated patches for ODFTOOLKIT-327 to degrade more gracefully cases
where ODF document is lacking a manifest.
Patch by: Florian Hopf

Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java?rev=1396272&r1=1396271&r2=1396272&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java (original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java Tue
Oct  9 20:06:36 2012
@@ -2051,7 +2051,10 @@ public class OdfPackage implements Close
 
 	void logValidationWarning(ValidationConstraint constraint, String baseURI, Object... o)
 			throws SAXException {
-		int varCount = 0;
+		if (mErrorHandler == null) {
+                    return;
+                }
+                int varCount = 0;
 		if (o != null) {
 			varCount = o.length;
 		}
@@ -2070,7 +2073,10 @@ public class OdfPackage implements Close
 
 	void logValidationError(ValidationConstraint constraint, String baseURI, Object... o)
 				throws SAXException {
-		int varCount = 0;
+		if (mErrorHandler == null) {
+                    return;
+                }
+                int varCount = 0;
 		if (o != null) {
 			varCount = o.length;
 		}

Modified: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java?rev=1396272&r1=1396271&r2=1396272&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java (original)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java Tue
Oct  9 20:06:36 2012
@@ -22,6 +22,7 @@
 package org.odftoolkit.odfdom.pkg;
 
 import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -33,6 +34,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
 
 import javax.xml.transform.Templates;
 import javax.xml.transform.TransformerFactory;
@@ -258,13 +260,30 @@ public class PackageTest {
 		try {
 			OdfPackage.loadPackage(ResourceUtilities.getAbsolutePath("testA.jpg"));
 			Assert.fail();
-		} catch (Exception e) {
+                } catch (Exception e) {
 			String errorMsg = OdfPackageConstraint.PACKAGE_IS_NO_ZIP.getMessage();
 			if (!e.getMessage().endsWith(errorMsg.substring(errorMsg.indexOf("%1$s") + 4))) {
 				Assert.fail();
 			}
 		}
 	}
+        
+        @Test
+        public void loadPackageWithoutManifest() throws Exception {
+            // regression for ODFTOOLKIT-327: invalid package without errorhandler
+            // doesn't throw NPE
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            ZipOutputStream zipped = new ZipOutputStream(out);
+            ZipEntry entry = new ZipEntry("someentry");
+            zipped.putNextEntry(entry);
+            zipped.close();
+            
+            byte [] data = out.toByteArray();
+            ByteArrayInputStream in = new ByteArrayInputStream(data);
+            OdfPackage pkg = OdfPackage.loadPackage(in);
+            
+            Assert.assertNotNull(pkg);
+        }
 
 	@Test
 	public void validationTest() {
@@ -337,4 +356,4 @@ public class PackageTest {
 		handler3.validate();
 		handler4.validate();
 	}
-}
+}    



Mime
View raw message