poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1156529 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/testcases/org/apache/poi/openxml4j/opc/ ooxml/testcases/org/apache/poi/xslf/
Date Thu, 11 Aug 2011 08:13:00 GMT
Author: yegor
Date: Thu Aug 11 08:13:00 2011
New Revision: 1156529

URL: http://svn.apache.org/viewvc?rev=1156529&view=rev
Log:
51187 - fixed OPCPackage to correctly handle self references

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1156529&r1=1156528&r2=1156529&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Aug 11 08:13:00 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51187 - fixed OPCPackage to correctly
handle self references</action>
            <action dev="poi-developers" type="fix">51635 - Improved performance of
XSSFSheet#write</action>
            <action dev="poi-developers" type="fix">47731 - Word Extractor considers
text copied from some website as an embedded object</action>
            <action dev="poi-developers" type="add">Add Word-to-Text converter and use
it as replacement for WordExtractor</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java?rev=1156529&r1=1156528&r2=1156529&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java Thu Aug
11 08:13:00 2011
@@ -342,7 +342,16 @@ public final class PackagingURIHelper {
 		// Special case for where the two are the same
 		if (segmentsTheSame == segmentsSource.length
 				&& segmentsTheSame == segmentsTarget.length) {
-			retVal.append("");
+            if(sourceURI.equals(targetURI)){
+                // if source and target are the same they should be resolved to the last
segment,
+                // Example: if a slide references itself, e.g. the source URI is
+                // "/ppt/slides/slide1.xml" and the targetURI is "slide1.xml" then
+                // this it should be relativized as "slide1.xml", i.e. the last segment.
+                retVal.append(segmentsSource[segmentsSource.length - 1]);
+            } else {
+                retVal.append("");
+            }
+
 		} else {
 			// Matched for so long, but no more
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java?rev=1156529&r1=1156528&r2=1156529&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
Thu Aug 11 08:13:00 2011
@@ -53,7 +53,10 @@ public class TestPackagingURIHelper exte
 
 		// Document to itself is the same place (empty URI)
 		URI retURI2 = PackagingURIHelper.relativizeURI(uri1, uri1);
-		assertEquals("", retURI2.getPath());
+		// YK: the line below used to assert empty string which is wrong
+        // if source and target are the same they should be relaitivized as the last segment,
+        // see Bugzilla 51187
+        assertEquals("document.xml", retURI2.getPath());
 
 		// relativization against root
 		URI root = new URI("/");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java?rev=1156529&r1=1156528&r2=1156529&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java Thu
Aug 11 08:13:00 2011
@@ -313,4 +313,35 @@ public class TestRelationships extends T
         assertEquals("'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A5", rel6.getFragment());
     }
 
+   public void testSelfRelations_bug51187() throws Exception {
+    	ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    	OPCPackage pkg = OPCPackage.create(baos);
+
+    	PackagePart partA =
+    		pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain");
+    	assertNotNull(partA);
+
+    	// reference itself
+    	PackageRelationship rel1 = partA.addRelationship(partA.getPartName(), TargetMode.INTERNAL,
"partA");
+
+    	
+    	// Save, and re-load
+    	pkg.close();
+    	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+    	pkg = OPCPackage.open(bais);
+
+    	partA = pkg.getPart(PackagingURIHelper.createPartName("/partA"));
+
+
+    	// Check the relations
+    	assertEquals(1, partA.getRelationships().size());
+
+       PackageRelationship rel2 = partA.getRelationships().getRelationship(0);
+
+    	assertEquals(rel1.getRelationshipType(), rel2.getRelationshipType());
+       assertEquals(rel1.getId(), rel2.getId());
+       assertEquals(rel1.getSourceURI(), rel2.getSourceURI());
+       assertEquals(rel1.getTargetURI(), rel2.getTargetURI());
+       assertEquals(rel1.getTargetMode(), rel2.getTargetMode());
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1156529&r1=1156528&r2=1156529&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Thu Aug 11 08:13:00
2011
@@ -52,7 +52,7 @@ public class TestXSLFBugs extends TestCa
        assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
        assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
        // TODO Fix this
-//       assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
+       assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
        assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
     }
 }



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


Mime
View raw message