From e0232eca0ae22d5c8784acdc95972a0c5b59124a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 26 Jun 2005 18:09:15 +0000 Subject: [PATCH] Make use of the PersistPtr records to come up with a list of the most recent versions of all the "key" records (Document, Slide, Notes, Master etc) Doesn't yet make use of this internally though, that's still to do git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353729 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hslf/usermodel/SlideShow.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java index c3a789ffe7..33e353c0fc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -30,6 +30,8 @@ import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.SlideAtom; import org.apache.poi.hslf.record.SlideListWithText; import org.apache.poi.hslf.record.SlideListWithText.*; +import org.apache.poi.hslf.record.PersistPtrHolder; +import org.apache.poi.hslf.record.PositionDependentRecord; /** * This class is a friendly wrapper on top of the more scary HSLFSlideShow. @@ -50,6 +52,10 @@ public class SlideShow // Low level contents, as taken from HSLFSlideShow private Record[] _records; + // Pointers to the most recent versions of the core records + // (Document, Notes, Slide etc) + private Record[] _mostRecentCoreRecords; + // Friendly objects for people to deal with private Slide[] _slides; private Notes[] _notes; @@ -90,7 +96,93 @@ public class SlideShow _records = _hslfSlideShow.getRecords(); byte[] _docstream = _hslfSlideShow.getUnderlyingBytes(); + // Find the versions of the core records we'll want to use + findMostRecentCoreRecords(); + + // Build up the model level Slides and Notes + buildSlidesAndNotes(); + } + + /** + * Use the PersistPtrHolder entries to figure out what is + * the "most recent" version of all the core records + * (Document, Notes, Slide etc), and save a record of them. + * Do this by walking from the oldest PersistPtr to the newest, + * overwriting any references found along the way with newer ones + */ + private void findMostRecentCoreRecords() { + // To start with, find the most recent in the byte offset domain + Hashtable mostRecentByBytes = new Hashtable(); + for(int i=0; i<_records.length; i++) { + if(_records[i] instanceof PersistPtrHolder) { + PersistPtrHolder pph = (PersistPtrHolder)_records[i]; + + // If we've already seen any of the "slide" IDs for this + // PersistPtr, remove their old positions + int[] ids = pph.getKnownSlideIDs(); + for(int j=0; j