poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r413911 - in /jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf: HSLFSlideShow.java record/PersistPtrHolder.java
Date Tue, 13 Jun 2006 14:54:52 GMT
Author: nick
Date: Tue Jun 13 07:54:52 2006
New Revision: 413911

URL: http://svn.apache.org/viewvc?rev=413911&view=rev
Log:
Some PersistPtrHolders seem to reference records stored after them. Add a second pass to cope
with these cases

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?rev=413911&r1=413910&r2=413911&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java Tue Jun 13
07:54:52 2006
@@ -248,25 +248,42 @@
 	// As we go along, update, and hand over, to any Position Dependent
 	//  records we happen across
 	Hashtable oldToNewPositions = new Hashtable();
-
-	// Write ourselves out
+	
+	// First pass - figure out where all the position dependent
+	//   records are going to end up, in the new scheme
+	// (Annoyingly, some powerpoing files have PersistPtrHolders
+	//  that reference slides after the PersistPtrHolder)
 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
 	for(int i=0; i<_records.length; i++) {
-		// For now, we're only handling PositionDependentRecord's that
-		//  happen at the top level.
-		// In future, we'll need the handle them everywhere, but that's
-		//  a bit trickier
 		if(_records[i] instanceof PositionDependentRecord) {
 			PositionDependentRecord pdr = (PositionDependentRecord)_records[i];
 			int oldPos = pdr.getLastOnDiskOffset();
 			int newPos = baos.size();
 			pdr.setLastOnDiskOffset(newPos);
-			//System.out.println(i + "  " + oldPos + " " + newPos);
 			oldToNewPositions.put(new Integer(oldPos),new Integer(newPos));
+			//System.out.println(oldPos + " -> " + newPos);
+		}
+		
+		// Dummy write out, so the position winds on properly
+		_records[i].writeOut(baos);
+	}
+
+	// No go back through, actually writing ourselves out
+	baos.reset();
+	for(int i=0; i<_records.length; i++) {
+		// For now, we're only handling PositionDependentRecord's that
+		//  happen at the top level.
+		// In future, we'll need the handle them everywhere, but that's
+		//  a bit trickier
+		if(_records[i] instanceof PositionDependentRecord) {
+			// We've already figured out their new location, and
+			//  told them that
+			// Tell them of the positions of the other records though
+			PositionDependentRecord pdr = (PositionDependentRecord)_records[i];
 			pdr.updateOtherRecordReferences(oldToNewPositions);
 		}
 
-		// Finally, write out
+		// Whatever happens, write out that record tree
 		_records[i].writeOut(baos);
 	}
 	// Update our cached copy of the bytes that make up the PPT stream

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java?rev=413911&r1=413910&r2=413911&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java
Tue Jun 13 07:54:52 2006
@@ -192,7 +192,9 @@
 			Integer newPos = (Integer)oldToNewReferencesLookup.get(oldPos);
 
 			if(newPos == null) {
-				throw new RuntimeException("Couldn't find the new location of the \"slide\" that used
to be at " + oldPos);
+				System.err.println("Couldn't find the new location of the \"slide\" with id " + id +
" that used to be at " + oldPos);
+				System.err.println("Not updating the position of it, you probably won't be able to find
it any more (if you ever could!)");
+				newPos = oldPos;
 			}
 
 			// Write out the new location



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message