View | Details | Raw Unified | Return to bug 48593
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (-52 / +94 lines)
Lines 29-34 Link Here
29
import java.util.HashMap;
29
import java.util.HashMap;
30
import java.util.Hashtable;
30
import java.util.Hashtable;
31
import java.util.List;
31
import java.util.List;
32
import java.util.Map;
32
33
33
import org.apache.poi.POIDocument;
34
import org.apache.poi.POIDocument;
34
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
35
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
Lines 40-51 Link Here
40
import org.apache.poi.hslf.record.PersistRecord;
41
import org.apache.poi.hslf.record.PersistRecord;
41
import org.apache.poi.hslf.record.PositionDependentRecord;
42
import org.apache.poi.hslf.record.PositionDependentRecord;
42
import org.apache.poi.hslf.record.Record;
43
import org.apache.poi.hslf.record.Record;
44
import org.apache.poi.hslf.record.RecordTypes;
43
import org.apache.poi.hslf.record.UserEditAtom;
45
import org.apache.poi.hslf.record.UserEditAtom;
44
import org.apache.poi.hslf.usermodel.ObjectData;
46
import org.apache.poi.hslf.usermodel.ObjectData;
45
import org.apache.poi.hslf.usermodel.PictureData;
47
import org.apache.poi.hslf.usermodel.PictureData;
46
import org.apache.poi.poifs.filesystem.DirectoryNode;
48
import org.apache.poi.poifs.filesystem.DirectoryNode;
47
import org.apache.poi.poifs.filesystem.DocumentEntry;
49
import org.apache.poi.poifs.filesystem.DocumentEntry;
48
import org.apache.poi.poifs.filesystem.DocumentInputStream;
50
import org.apache.poi.poifs.filesystem.DocumentInputStream;
51
import org.apache.poi.poifs.filesystem.EntryUtils;
49
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
52
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
50
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
53
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
51
import org.apache.poi.util.LittleEndian;
54
import org.apache.poi.util.LittleEndian;
Lines 59-64 Link Here
59
 * @author Nick Burch
62
 * @author Nick Burch
60
 */
63
 */
61
public final class HSLFSlideShow extends POIDocument {
64
public final class HSLFSlideShow extends POIDocument {
65
    public static final int UNSET_OFFSET = -1;
66
    
62
    // For logging
67
    // For logging
63
    private POILogger logger = POILogFactory.getLogger(this.getClass());
68
    private POILogger logger = POILogFactory.getLogger(this.getClass());
64
69
Lines 346-351 Link Here
346
            int offset = pos;
351
            int offset = pos;
347
352
348
            // Image signature
353
            // Image signature
354
            @SuppressWarnings("unused")
349
            int signature = LittleEndian.getUShort(pictstream, pos);
355
            int signature = LittleEndian.getUShort(pictstream, pos);
350
            pos += LittleEndian.SHORT_SIZE;
356
            pos += LittleEndian.SHORT_SIZE;
351
            // Image type + 0xF018
357
            // Image type + 0xF018
Lines 392-398 Link Here
392
        }
398
        }
393
	}
399
	}
394
400
401
	/**
402
     * This is a helper functions, which is needed for adding new position dependent records
403
     * or finally write the slideshow to a file.
404
	 *
405
	 * @param os the stream to write to, if null only the references are updated
406
	 * @param interestingRecords a map of interesting records (PersistPtrHolder and UserEditAtom)
407
	 *        referenced by their RecordType. Only the very last of each type will be saved to the map.
408
	 *        May be null, if not needed. 
409
	 * @throws IOException
410
	 */
411
	public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes.Type,PositionDependentRecord> interestingRecords)
412
	throws IOException {
413
        // For position dependent records, hold where they were and now are
414
        // As we go along, update, and hand over, to any Position Dependent
415
        //  records we happen across
416
        Map<Integer,Integer> oldToNewPositions = new HashMap<Integer,Integer>();
395
417
418
        // First pass - figure out where all the position dependent
419
        //   records are going to end up, in the new scheme
420
        // (Annoyingly, some powerpoint files have PersistPtrHolders
421
        //  that reference slides after the PersistPtrHolder)
422
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
423
        for (Record record : _records) {
424
            if(record instanceof PositionDependentRecord) {
425
                PositionDependentRecord pdr = (PositionDependentRecord)record;
426
                int oldPos = pdr.getLastOnDiskOffset();
427
                int newPos = baos.size();
428
                pdr.setLastOnDiskOffset(newPos);
429
                if (oldPos != UNSET_OFFSET) {
430
                    // new records don't need a mapping, as they aren't in a relation yet
431
                    oldToNewPositions.put(Integer.valueOf(oldPos),Integer.valueOf(newPos));
432
                }
433
            }
434
            
435
            // Dummy write out, so the position winds on properly
436
            record.writeOut(baos);
437
        }
438
        baos = null;
439
        
440
        // For now, we're only handling PositionDependentRecord's that
441
        // happen at the top level.
442
        // In future, we'll need the handle them everywhere, but that's
443
        // a bit trickier
444
	    UserEditAtom usr = null;
445
        for (Record record : _records) {
446
            if (record instanceof PositionDependentRecord) {
447
                // We've already figured out their new location, and
448
                // told them that
449
                // Tell them of the positions of the other records though
450
                PositionDependentRecord pdr = (PositionDependentRecord)record;
451
                pdr.updateOtherRecordReferences(oldToNewPositions);
452
    
453
                // Grab interesting records as they come past
454
                // this will only save the very last record of each type
455
                RecordTypes.Type saveme = null;
456
                int recordType = (int)record.getRecordType();
457
                if (recordType == RecordTypes.PersistPtrIncrementalBlock.typeID) {
458
                    saveme = RecordTypes.PersistPtrIncrementalBlock;
459
                } else if (recordType == RecordTypes.UserEditAtom.typeID) {
460
                    saveme = RecordTypes.UserEditAtom;
461
                    usr = (UserEditAtom)pdr;
462
                }
463
                if (interestingRecords != null && saveme != null) {
464
                    interestingRecords.put(saveme,pdr);
465
                }
466
            }
467
            
468
            // Whatever happens, write out that record tree
469
            if (os != null) {
470
                record.writeOut(os);
471
            }
472
        }
473
474
        // Update and write out the Current User atom
475
        int oldLastUserEditAtomPos = (int)currentUser.getCurrentEditOffset();
476
        Integer newLastUserEditAtomPos = oldToNewPositions.get(oldLastUserEditAtomPos);
477
        if(usr == null || newLastUserEditAtomPos == null || usr.getLastOnDiskOffset() != newLastUserEditAtomPos) {
478
            throw new HSLFException("Couldn't find the new location of the last UserEditAtom that used to be at " + oldLastUserEditAtomPos);
479
        }
480
        currentUser.setCurrentEditOffset(usr.getLastOnDiskOffset());
481
	}
482
	
396
    /**
483
    /**
397
     * Writes out the slideshow file the is represented by an instance
484
     * Writes out the slideshow file the is represented by an instance
398
     *  of this class.
485
     *  of this class.
Lines 426-474 Link Here
426
        // Write out the Property Streams
513
        // Write out the Property Streams
427
        writeProperties(outFS, writtenEntries);
514
        writeProperties(outFS, writtenEntries);
428
515
516
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
429
517
430
        // For position dependent records, hold where they were and now are
518
        // For position dependent records, hold where they were and now are
431
        // As we go along, update, and hand over, to any Position Dependent
519
        // As we go along, update, and hand over, to any Position Dependent
432
        //  records we happen across
520
        // records we happen across
433
        Hashtable<Integer,Integer> oldToNewPositions = new Hashtable<Integer,Integer>();
521
        updateAndWriteDependantRecords(baos, null);
434
522
435
        // First pass - figure out where all the position dependent
436
        //   records are going to end up, in the new scheme
437
        // (Annoyingly, some powerpoing files have PersistPtrHolders
438
        //  that reference slides after the PersistPtrHolder)
439
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
440
        for(int i=0; i<_records.length; i++) {
441
            if(_records[i] instanceof PositionDependentRecord) {
442
                PositionDependentRecord pdr = (PositionDependentRecord)_records[i];
443
                int oldPos = pdr.getLastOnDiskOffset();
444
                int newPos = baos.size();
445
                pdr.setLastOnDiskOffset(newPos);
446
                oldToNewPositions.put(Integer.valueOf(oldPos),Integer.valueOf(newPos));
447
                //System.out.println(oldPos + " -> " + newPos);
448
            }
449
450
            // Dummy write out, so the position winds on properly
451
            _records[i].writeOut(baos);
452
        }
453
454
        // No go back through, actually writing ourselves out
455
        baos.reset();
456
        for(int i=0; i<_records.length; i++) {
457
            // For now, we're only handling PositionDependentRecord's that
458
            //  happen at the top level.
459
            // In future, we'll need the handle them everywhere, but that's
460
            //  a bit trickier
461
            if(_records[i] instanceof PositionDependentRecord) {
462
                // We've already figured out their new location, and
463
                //  told them that
464
                // Tell them of the positions of the other records though
465
                PositionDependentRecord pdr = (PositionDependentRecord)_records[i];
466
                pdr.updateOtherRecordReferences(oldToNewPositions);
467
            }
468
469
            // Whatever happens, write out that record tree
470
            _records[i].writeOut(baos);
471
        }
472
        // Update our cached copy of the bytes that make up the PPT stream
523
        // Update our cached copy of the bytes that make up the PPT stream
473
        _docstream = baos.toByteArray();
524
        _docstream = baos.toByteArray();
474
525
Lines 476-490 Link Here
476
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
527
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
477
        outFS.createDocument(bais,"PowerPoint Document");
528
        outFS.createDocument(bais,"PowerPoint Document");
478
        writtenEntries.add("PowerPoint Document");
529
        writtenEntries.add("PowerPoint Document");
479
480
481
        // Update and write out the Current User atom
482
        int oldLastUserEditAtomPos = (int)currentUser.getCurrentEditOffset();
483
        Integer newLastUserEditAtomPos = (Integer)oldToNewPositions.get(Integer.valueOf(oldLastUserEditAtomPos));
484
        if(newLastUserEditAtomPos == null) {
485
            throw new HSLFException("Couldn't find the new location of the UserEditAtom that used to be at " + oldLastUserEditAtomPos);
486
        }
487
        currentUser.setCurrentEditOffset(newLastUserEditAtomPos.intValue());
488
        currentUser.writeToFS(outFS);
530
        currentUser.writeToFS(outFS);
489
        writtenEntries.add("Current User");
531
        writtenEntries.add("Current User");
490
532
Lines 506-512 Link Here
506
548
507
        // If requested, write out any other streams we spot
549
        // If requested, write out any other streams we spot
508
        if(preserveNodes) {
550
        if(preserveNodes) {
509
            copyNodes(directory.getFileSystem(), outFS, writtenEntries);
551
            EntryUtils.copyNodes(directory.getFileSystem(), outFS, writtenEntries);
510
        }
552
        }
511
553
512
        // Send the POIFSFileSystem object out to the underlying stream
554
        // Send the POIFSFileSystem object out to the underlying stream
Lines 612-620 Link Here
612
    public ObjectData[] getEmbeddedObjects() {
654
    public ObjectData[] getEmbeddedObjects() {
613
        if (_objects == null) {
655
        if (_objects == null) {
614
            List<ObjectData> objects = new ArrayList<ObjectData>();
656
            List<ObjectData> objects = new ArrayList<ObjectData>();
615
            for (int i = 0; i < _records.length; i++) {
657
            for (Record r : _records) {
616
                if (_records[i] instanceof ExOleObjStg) {
658
                if (r instanceof ExOleObjStg) {
617
                    objects.add(new ObjectData((ExOleObjStg) _records[i]));
659
                    objects.add(new ObjectData((ExOleObjStg)r));
618
                }
660
                }
619
            }
661
            }
620
            _objects = objects.toArray(new ObjectData[objects.size()]);
662
            _objects = objects.toArray(new ObjectData[objects.size()]);
(-)src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java (-4 / +8 lines)
Lines 17-26 Link Here
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
19
20
import java.io.*;
20
import java.io.ByteArrayInputStream;
21
import java.util.zip.InflaterInputStream;
21
import java.io.ByteArrayOutputStream;
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.io.OutputStream;
25
import java.util.Map;
22
import java.util.zip.DeflaterOutputStream;
26
import java.util.zip.DeflaterOutputStream;
23
import java.util.Hashtable;
27
import java.util.zip.InflaterInputStream;
24
28
25
import org.apache.poi.util.BoundedInputStream;
29
import org.apache.poi.util.BoundedInputStream;
26
import org.apache.poi.util.LittleEndian;
30
import org.apache.poi.util.LittleEndian;
Lines 180-186 Link Here
180
        myLastOnDiskOffset = offset;
184
        myLastOnDiskOffset = offset;
181
    }
185
    }
182
186
183
    public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
187
    public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
184
        return;
188
        return;
185
    }
189
    }
186
190
(-)src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java (-4 / +5 lines)
Lines 17-29 Link Here
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
19
20
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.util.POILogger;
22
23
import java.io.IOException;
20
import java.io.IOException;
24
import java.io.OutputStream;
21
import java.io.OutputStream;
25
import java.util.Enumeration;
22
import java.util.Enumeration;
26
import java.util.Hashtable;
23
import java.util.Hashtable;
24
import java.util.Map;
25
26
import org.apache.poi.util.LittleEndian;
27
import org.apache.poi.util.POILogger;
27
28
28
/**
29
/**
29
 * General holder for PersistPtrFullBlock and PersistPtrIncrementalBlock
30
 * General holder for PersistPtrFullBlock and PersistPtrIncrementalBlock
Lines 181-187 Link Here
181
	 * At write-out time, update the references to the sheets to their
182
	 * At write-out time, update the references to the sheets to their
182
	 *  new positions
183
	 *  new positions
183
	 */
184
	 */
184
	public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
185
	public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
185
		int[] slideIDs = getKnownSlideIDs();
186
		int[] slideIDs = getKnownSlideIDs();
186
187
187
		// Loop over all the slides we know about
188
		// Loop over all the slides we know about
(-)src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecord.java (-2 / +2 lines)
Lines 16-22 Link Here
16
==================================================================== */
16
==================================================================== */
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
import java.util.Hashtable;
19
import java.util.Map;
20
20
21
/**
21
/**
22
 * Records which either care about where they are on disk, or have other
22
 * Records which either care about where they are on disk, or have other
Lines 47-51 Link Here
47
	 * Offer the record the list of records that have changed their
47
	 * Offer the record the list of records that have changed their
48
	 *  location as part of the writeout.
48
	 *  location as part of the writeout.
49
	 */
49
	 */
50
	public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup);
50
	public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup);
51
}
51
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordAtom.java (-2 / +2 lines)
Lines 16-22 Link Here
16
==================================================================== */
16
==================================================================== */
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
import java.util.Hashtable;
19
import java.util.Map;
20
20
21
/**
21
/**
22
 * A special (and dangerous) kind of Record Atom that cares about where
22
 * A special (and dangerous) kind of Record Atom that cares about where
Lines 48-52 Link Here
48
	 * Allows records to update their internal pointers to other records
48
	 * Allows records to update their internal pointers to other records
49
	 *  locations
49
	 *  locations
50
	 */
50
	 */
51
	public abstract void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup);
51
	public abstract void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup);
52
}
52
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java (-2 / +2 lines)
Lines 16-22 Link Here
16
==================================================================== */
16
==================================================================== */
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
import java.util.Hashtable;
19
import java.util.Map;
20
20
21
/**
21
/**
22
 * A special (and dangerous) kind of Record Container, for which other
22
 * A special (and dangerous) kind of Record Container, for which other
Lines 60-66 Link Here
60
	 * Since we're a container, we don't mind if other records move about.
60
	 * Since we're a container, we don't mind if other records move about.
61
	 * If we're told they have, just return straight off.
61
	 * If we're told they have, just return straight off.
62
	 */
62
	 */
63
	public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
63
	public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
64
		return;
64
		return;
65
	}
65
	}
66
}
66
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java (-7 / +8 lines)
Lines 17-26 Link Here
17
17
18
package org.apache.poi.hslf.record;
18
package org.apache.poi.hslf.record;
19
19
20
import org.apache.poi.util.LittleEndian;
21
import java.io.IOException;
20
import java.io.IOException;
22
import java.io.OutputStream;
21
import java.io.OutputStream;
23
import java.util.Hashtable;
22
import java.util.Map;
23
24
import org.apache.poi.util.LittleEndian;
24
25
25
/**
26
/**
26
 * A UserEdit Atom (type 4085). Holds information which bits of the file
27
 * A UserEdit Atom (type 4085). Holds information which bits of the file
Lines 90-111 Link Here
90
		// Get the offset to the previous incremental save's UserEditAtom
91
		// Get the offset to the previous incremental save's UserEditAtom
91
		// This will be the byte offset on disk where the previous one
92
		// This will be the byte offset on disk where the previous one
92
		//  starts, or 0 if this is the first one
93
		//  starts, or 0 if this is the first one
93
		lastUserEditAtomOffset = LittleEndian.getInt(source,start+8+8);
94
		setLastUserEditAtomOffset(LittleEndian.getInt(source,start+8+8));
94
95
95
		// Get the offset to the persist pointers
96
		// Get the offset to the persist pointers
96
		// This will be the byte offset on disk where the preceding
97
		// This will be the byte offset on disk where the preceding
97
		//  PersistPtrFullBlock or PersistPtrIncrementalBlock starts
98
		//  PersistPtrFullBlock or PersistPtrIncrementalBlock starts
98
		persistPointersOffset = LittleEndian.getInt(source,start+12+8);
99
		setPersistPointersOffset(LittleEndian.getInt(source,start+12+8));
99
100
100
		// Get the persist reference for the document persist object
101
		// Get the persist reference for the document persist object
101
		// Normally seems to be 1
102
		// Normally seems to be 1
102
		docPersistRef = LittleEndian.getInt(source,start+16+8);
103
		docPersistRef = LittleEndian.getInt(source,start+16+8);
103
104
104
		// Maximum number of persist objects written
105
		// Maximum number of persist objects written
105
		maxPersistWritten = LittleEndian.getInt(source,start+20+8);
106
		setMaxPersistWritten(LittleEndian.getInt(source,start+20+8));
106
107
107
		// Last view type
108
		// Last view type
108
		lastViewType = LittleEndian.getShort(source,start+24+8);
109
		setLastViewType(LittleEndian.getShort(source,start+24+8));
109
110
110
		// There might be a few more bytes, which are a reserved field
111
		// There might be a few more bytes, which are a reserved field
111
		reserved = new byte[len-26-8];
112
		reserved = new byte[len-26-8];
Lines 121-127 Link Here
121
	 * At write-out time, update the references to PersistPtrs and
122
	 * At write-out time, update the references to PersistPtrs and
122
	 *  other UserEditAtoms to point to their new positions
123
	 *  other UserEditAtoms to point to their new positions
123
	 */
124
	 */
124
	public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
125
	public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
125
		// Look up the new positions of our preceding UserEditAtomOffset
126
		// Look up the new positions of our preceding UserEditAtomOffset
126
		if(lastUserEditAtomOffset != 0) {
127
		if(lastUserEditAtomOffset != 0) {
127
			Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
128
			Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (-103 / +105 lines)
Lines 25-31 Link Here
25
import java.io.IOException;
25
import java.io.IOException;
26
import java.io.InputStream;
26
import java.io.InputStream;
27
import java.io.OutputStream;
27
import java.io.OutputStream;
28
import java.util.*;
28
import java.util.ArrayList;
29
import java.util.Arrays;
30
import java.util.HashMap;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
29
34
30
import org.apache.poi.ddf.EscherBSERecord;
35
import org.apache.poi.ddf.EscherBSERecord;
31
import org.apache.poi.ddf.EscherContainerRecord;
36
import org.apache.poi.ddf.EscherContainerRecord;
Lines 35-45 Link Here
35
import org.apache.poi.hslf.HSLFSlideShow;
40
import org.apache.poi.hslf.HSLFSlideShow;
36
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
41
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
37
import org.apache.poi.hslf.exceptions.HSLFException;
42
import org.apache.poi.hslf.exceptions.HSLFException;
38
import org.apache.poi.hslf.model.*;
43
import org.apache.poi.hslf.model.HeadersFooters;
44
import org.apache.poi.hslf.model.Hyperlink;
45
import org.apache.poi.hslf.model.MovieShape;
39
import org.apache.poi.hslf.model.Notes;
46
import org.apache.poi.hslf.model.Notes;
47
import org.apache.poi.hslf.model.PPFont;
48
import org.apache.poi.hslf.model.Picture;
49
import org.apache.poi.hslf.model.Shape;
40
import org.apache.poi.hslf.model.Slide;
50
import org.apache.poi.hslf.model.Slide;
41
import org.apache.poi.hslf.record.*;
51
import org.apache.poi.hslf.model.SlideMaster;
52
import org.apache.poi.hslf.model.TitleMaster;
53
import org.apache.poi.hslf.record.Document;
54
import org.apache.poi.hslf.record.DocumentAtom;
55
import org.apache.poi.hslf.record.ExAviMovie;
56
import org.apache.poi.hslf.record.ExControl;
57
import org.apache.poi.hslf.record.ExEmbed;
58
import org.apache.poi.hslf.record.ExEmbedAtom;
59
import org.apache.poi.hslf.record.ExHyperlink;
60
import org.apache.poi.hslf.record.ExHyperlinkAtom;
61
import org.apache.poi.hslf.record.ExMCIMovie;
62
import org.apache.poi.hslf.record.ExObjList;
63
import org.apache.poi.hslf.record.ExObjListAtom;
64
import org.apache.poi.hslf.record.ExOleObjAtom;
65
import org.apache.poi.hslf.record.ExOleObjStg;
66
import org.apache.poi.hslf.record.ExVideoContainer;
67
import org.apache.poi.hslf.record.FontCollection;
68
import org.apache.poi.hslf.record.FontEntityAtom;
69
import org.apache.poi.hslf.record.HeadersFootersContainer;
70
import org.apache.poi.hslf.record.PersistPtrHolder;
71
import org.apache.poi.hslf.record.PositionDependentRecord;
72
import org.apache.poi.hslf.record.PositionDependentRecordContainer;
73
import org.apache.poi.hslf.record.Record;
74
import org.apache.poi.hslf.record.RecordContainer;
75
import org.apache.poi.hslf.record.RecordTypes;
76
import org.apache.poi.hslf.record.SlideListWithText;
42
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
77
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
78
import org.apache.poi.hslf.record.SlidePersistAtom;
79
import org.apache.poi.hslf.record.UserEditAtom;
43
import org.apache.poi.poifs.filesystem.DirectoryNode;
80
import org.apache.poi.poifs.filesystem.DirectoryNode;
44
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
81
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
45
import org.apache.poi.util.POILogFactory;
82
import org.apache.poi.util.POILogFactory;
Lines 58-72 Link Here
58
	// What we're based on
95
	// What we're based on
59
	private HSLFSlideShow _hslfSlideShow;
96
	private HSLFSlideShow _hslfSlideShow;
60
97
61
	// Low level contents, as taken from HSLFSlideShow
62
	private Record[] _records;
63
64
	// Pointers to the most recent versions of the core records
98
	// Pointers to the most recent versions of the core records
65
	// (Document, Notes, Slide etc)
99
	// (Document, Notes, Slide etc)
66
	private Record[] _mostRecentCoreRecords;
100
	private Record[] _mostRecentCoreRecords;
67
	// Lookup between the PersitPtr "sheet" IDs, and the position
101
	// Lookup between the PersitPtr "sheet" IDs, and the position
68
	// in the mostRecentCoreRecords array
102
	// in the mostRecentCoreRecords array
69
	private Hashtable<Integer,Integer> _sheetIdToCoreRecordsLookup;
103
	private Map<Integer,Integer> _sheetIdToCoreRecordsLookup;
70
104
71
	// Records that are interesting
105
	// Records that are interesting
72
	private Document _documentRecord;
106
	private Document _documentRecord;
Lines 97-106 Link Here
97
	public SlideShow(HSLFSlideShow hslfSlideShow) {
131
	public SlideShow(HSLFSlideShow hslfSlideShow) {
98
	    // Get useful things from our base slideshow
132
	    // Get useful things from our base slideshow
99
	    _hslfSlideShow = hslfSlideShow;
133
	    _hslfSlideShow = hslfSlideShow;
100
		_records = _hslfSlideShow.getRecords();
101
134
102
		// Handle Parent-aware Records
135
		// Handle Parent-aware Records
103
		for (Record record : _records) {
136
		for (Record record : _hslfSlideShow.getRecords()) {
104
			if(record instanceof RecordContainer){
137
			if(record instanceof RecordContainer){
105
                RecordContainer.handleParentAwareRecords((RecordContainer)record);
138
                RecordContainer.handleParentAwareRecords((RecordContainer)record);
106
            }
139
            }
Lines 135-159 Link Here
135
	 */
168
	 */
136
	private void findMostRecentCoreRecords() {
169
	private void findMostRecentCoreRecords() {
137
		// To start with, find the most recent in the byte offset domain
170
		// To start with, find the most recent in the byte offset domain
138
		Hashtable<Integer,Integer> mostRecentByBytes = new Hashtable<Integer,Integer>();
171
		Map<Integer,Integer> mostRecentByBytes = new HashMap<Integer,Integer>();
139
		for (int i = 0; i < _records.length; i++) {
172
		for (Record record : _hslfSlideShow.getRecords()) {
140
			if (_records[i] instanceof PersistPtrHolder) {
173
			if (record instanceof PersistPtrHolder) {
141
				PersistPtrHolder pph = (PersistPtrHolder) _records[i];
174
				PersistPtrHolder pph = (PersistPtrHolder) record;
142
175
143
				// If we've already seen any of the "slide" IDs for this
176
				// If we've already seen any of the "slide" IDs for this
144
				// PersistPtr, remove their old positions
177
				// PersistPtr, remove their old positions
145
				int[] ids = pph.getKnownSlideIDs();
178
				int[] ids = pph.getKnownSlideIDs();
146
				for (int j = 0; j < ids.length; j++) {
179
				for (int id : ids) {
147
					Integer id = Integer.valueOf(ids[j]);
148
					if (mostRecentByBytes.containsKey(id)) {
180
					if (mostRecentByBytes.containsKey(id)) {
149
						mostRecentByBytes.remove(id);
181
						mostRecentByBytes.remove(id);
150
					}
182
					}
151
				}
183
				}
152
184
153
				// Now, update the byte level locations with their latest values
185
				// Now, update the byte level locations with their latest values
154
				Hashtable<Integer,Integer> thisSetOfLocations = pph.getSlideLocationsLookup();
186
				Map<Integer,Integer> thisSetOfLocations = pph.getSlideLocationsLookup();
155
				for (int j = 0; j < ids.length; j++) {
187
				for (int id : ids) {
156
					Integer id = Integer.valueOf(ids[j]);
157
					mostRecentByBytes.put(id, thisSetOfLocations.get(id));
188
					mostRecentByBytes.put(id, thisSetOfLocations.get(id));
158
				}
189
				}
159
			}
190
			}
Lines 165-218 Link Here
165
196
166
		// We'll also want to be able to turn the slide IDs into a position
197
		// We'll also want to be able to turn the slide IDs into a position
167
		// in this array
198
		// in this array
168
		_sheetIdToCoreRecordsLookup = new Hashtable<Integer,Integer>();
199
		_sheetIdToCoreRecordsLookup = new HashMap<Integer,Integer>();
169
		int[] allIDs = new int[_mostRecentCoreRecords.length];
200
		Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]); 
170
		Enumeration<Integer> ids = mostRecentByBytes.keys();
171
		for (int i = 0; i < allIDs.length; i++) {
172
			Integer id = ids.nextElement();
173
			allIDs[i] = id.intValue();
174
		}
175
		Arrays.sort(allIDs);
201
		Arrays.sort(allIDs);
176
		for (int i = 0; i < allIDs.length; i++) {
202
		for (int i = 0; i < allIDs.length; i++) {
177
			_sheetIdToCoreRecordsLookup.put(Integer.valueOf(allIDs[i]), Integer.valueOf(i));
203
			_sheetIdToCoreRecordsLookup.put(allIDs[i], i);
178
		}
204
		}
179
205
180
		// Now convert the byte offsets back into record offsets
206
		// Now convert the byte offsets back into record offsets
181
		for (int i = 0; i < _records.length; i++) {
207
		for (Record record : _hslfSlideShow.getRecords()) {
182
			if (_records[i] instanceof PositionDependentRecord) {
208
			if (record instanceof PositionDependentRecord) {
183
				PositionDependentRecord pdr = (PositionDependentRecord) _records[i];
209
				PositionDependentRecord pdr = (PositionDependentRecord) record;
184
				Integer recordAt = Integer.valueOf(pdr.getLastOnDiskOffset());
210
				int recordAt = pdr.getLastOnDiskOffset();
185
211
186
				// Is it one we care about?
212
				// Is it one we care about?
187
				for (int j = 0; j < allIDs.length; j++) {
213
				for (Integer thisID : allIDs) {
188
					Integer thisID = Integer.valueOf(allIDs[j]);
214
					int thatRecordAt = mostRecentByBytes.get(thisID);
189
					Integer thatRecordAt = mostRecentByBytes.get(thisID);
190
215
191
					if (thatRecordAt.equals(recordAt)) {
216
					if (thatRecordAt == recordAt) {
192
						// Bingo. Now, where do we store it?
217
						// Bingo. Now, where do we store it?
193
						Integer storeAtI = _sheetIdToCoreRecordsLookup.get(thisID);
218
						Integer storeAtI = _sheetIdToCoreRecordsLookup.get(thisID);
194
						int storeAt = storeAtI.intValue();
219
						int storeAt = storeAtI.intValue();
195
220
196
						// Tell it its Sheet ID, if it cares
221
						// Tell it its Sheet ID, if it cares
197
						if (pdr instanceof PositionDependentRecordContainer) {
222
						if (pdr instanceof PositionDependentRecordContainer) {
198
							PositionDependentRecordContainer pdrc = (PositionDependentRecordContainer) _records[i];
223
							PositionDependentRecordContainer pdrc = (PositionDependentRecordContainer) record;
199
							pdrc.setSheetId(thisID.intValue());
224
							pdrc.setSheetId(thisID);
200
						}
225
						}
201
226
202
						// Finally, save the record
227
						// Finally, save the record
203
						_mostRecentCoreRecords[storeAt] = _records[i];
228
						_mostRecentCoreRecords[storeAt] = record;
204
					}
229
					}
205
				}
230
				}
206
			}
231
			}
207
		}
232
		}
208
233
209
		// Now look for the interesting records in there
234
		// Now look for the interesting records in there
210
		for (int i = 0; i < _mostRecentCoreRecords.length; i++) {
235
		for (Record record : _mostRecentCoreRecords) {
211
			// Check there really is a record at this number
236
			// Check there really is a record at this number
212
			if (_mostRecentCoreRecords[i] != null) {
237
			if (record != null) {
213
				// Find the Document, and interesting things in it
238
				// Find the Document, and interesting things in it
214
				if (_mostRecentCoreRecords[i].getRecordType() == RecordTypes.Document.typeID) {
239
				if (record.getRecordType() == RecordTypes.Document.typeID) {
215
					_documentRecord = (Document) _mostRecentCoreRecords[i];
240
					_documentRecord = (Document) record;
216
					_fonts = _documentRecord.getEnvironment().getFontCollection();
241
					_fonts = _documentRecord.getEnvironment().getFontCollection();
217
				}
242
				}
218
			} else {
243
			} else {
Lines 296-304 Link Here
296
			ArrayList<SlideMaster> mmr = new ArrayList<SlideMaster>();
321
			ArrayList<SlideMaster> mmr = new ArrayList<SlideMaster>();
297
			ArrayList<TitleMaster> tmr = new ArrayList<TitleMaster>();
322
			ArrayList<TitleMaster> tmr = new ArrayList<TitleMaster>();
298
323
299
			for (int i = 0; i < masterSets.length; i++) {
324
			for (SlideAtomsSet sas : masterSets) {
300
				Record r = getCoreRecordForSAS(masterSets[i]);
325
				Record r = getCoreRecordForSAS(sas);
301
				SlideAtomsSet sas = masterSets[i];
302
				int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
326
				int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
303
				if (r instanceof org.apache.poi.hslf.record.Slide) {
327
				if (r instanceof org.apache.poi.hslf.record.Slide) {
304
					TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide) r,
328
					TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide) r,
Lines 313-323 Link Here
313
				}
337
				}
314
			}
338
			}
315
339
316
			_masters = new SlideMaster[mmr.size()];
340
			_masters = mmr.toArray(new SlideMaster[mmr.size()]);
317
			mmr.toArray(_masters);
341
			_titleMasters = tmr.toArray(new TitleMaster[tmr.size()]);
318
319
			_titleMasters = new TitleMaster[tmr.size()];
320
			tmr.toArray(_titleMasters);
321
		}
342
		}
322
343
323
		// Having sorted out the masters, that leaves the notes and slides
344
		// Having sorted out the masters, that leaves the notes and slides
Lines 326-339 Link Here
326
		// notesSLWT
347
		// notesSLWT
327
		org.apache.poi.hslf.record.Notes[] notesRecords;
348
		org.apache.poi.hslf.record.Notes[] notesRecords;
328
		SlideAtomsSet[] notesSets = new SlideAtomsSet[0];
349
		SlideAtomsSet[] notesSets = new SlideAtomsSet[0];
329
		Hashtable<Integer,Integer> slideIdToNotes = new Hashtable<Integer,Integer>();
350
		Map<Integer,Integer> slideIdToNotes = new HashMap<Integer,Integer>();
330
		if (notesSLWT == null) {
351
		if (notesSLWT == null) {
331
			// None
352
			// None
332
			notesRecords = new org.apache.poi.hslf.record.Notes[0];
353
			notesRecords = new org.apache.poi.hslf.record.Notes[0];
333
		} else {
354
		} else {
334
			// Match up the records and the SlideAtomSets
355
			// Match up the records and the SlideAtomSets
335
			notesSets = notesSLWT.getSlideAtomsSets();
356
			notesSets = notesSLWT.getSlideAtomsSets();
336
			ArrayList<org.apache.poi.hslf.record.Notes> notesRecordsL = 
357
			List<org.apache.poi.hslf.record.Notes> notesRecordsL = 
337
			   new ArrayList<org.apache.poi.hslf.record.Notes>();
358
			   new ArrayList<org.apache.poi.hslf.record.Notes>();
338
			for (int i = 0; i < notesSets.length; i++) {
359
			for (int i = 0; i < notesSets.length; i++) {
339
				// Get the right core record
360
				// Get the right core record
Lines 346-353 Link Here
346
367
347
					// Record the match between slide id and these notes
368
					// Record the match between slide id and these notes
348
					SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
369
					SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
349
					Integer slideId = Integer.valueOf(spa.getSlideIdentifier());
370
					int slideId = spa.getSlideIdentifier();
350
					slideIdToNotes.put(slideId, Integer.valueOf(i));
371
					slideIdToNotes.put(slideId, i);
351
				} else {
372
				} else {
352
					logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i
373
					logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i
353
							+ " said its record was at refID "
374
							+ " said its record was at refID "
Lines 686-694 Link Here
686
		// (Will stay as null if no SlidePersistAtom exists yet in
707
		// (Will stay as null if no SlidePersistAtom exists yet in
687
		// the slide, or only master slide's ones do)
708
		// the slide, or only master slide's ones do)
688
		SlidePersistAtom prev = null;
709
		SlidePersistAtom prev = null;
689
		SlideAtomsSet[] sas = slist.getSlideAtomsSets();
710
		for (SlideAtomsSet sas : slist.getSlideAtomsSets()) {
690
		for (int j = 0; j < sas.length; j++) {
711
			SlidePersistAtom spa = sas.getSlidePersistAtom();
691
			SlidePersistAtom spa = sas[j].getSlidePersistAtom();
692
			if (spa.getSlideIdentifier() < 0) {
712
			if (spa.getSlideIdentifier() < 0) {
693
				// This is for a master slide
713
				// This is for a master slide
694
				// Odd, since we only deal with the Slide SLWT
714
				// Odd, since we only deal with the Slide SLWT
Lines 850-868 Link Here
850
	 *         found
870
	 *         found
851
	 */
871
	 */
852
	public PPFont getFont(int idx) {
872
	public PPFont getFont(int idx) {
853
		PPFont font = null;
854
		FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
873
		FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
855
		Record[] ch = fonts.getChildRecords();
874
		for (Record ch : fonts.getChildRecords()) {
856
		for (int i = 0; i < ch.length; i++) {
875
			if (ch instanceof FontEntityAtom) {
857
			if (ch[i] instanceof FontEntityAtom) {
876
				FontEntityAtom atom = (FontEntityAtom) ch;
858
				FontEntityAtom atom = (FontEntityAtom) ch[i];
859
				if (atom.getFontIndex() == idx) {
877
				if (atom.getFontIndex() == idx) {
860
					font = new PPFont(atom);
878
					return new PPFont(atom);
861
					break;
862
				}
879
				}
863
			}
880
			}
864
		}
881
		}
865
		return font;
882
		return null;
866
	}
883
	}
867
884
868
	/**
885
	/**
Lines 885-895 Link Here
885
		boolean ppt2007 = "___PPT12".equals(tag);
902
		boolean ppt2007 = "___PPT12".equals(tag);
886
903
887
		HeadersFootersContainer hdd = null;
904
		HeadersFootersContainer hdd = null;
888
		Record[] ch = _documentRecord.getChildRecords();
905
		for (Record ch : _documentRecord.getChildRecords()) {
889
		for (int i = 0; i < ch.length; i++) {
906
			if (ch instanceof HeadersFootersContainer
890
			if (ch[i] instanceof HeadersFootersContainer
907
				&& ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) {
891
					&& ((HeadersFootersContainer) ch[i]).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) {
908
				hdd = (HeadersFootersContainer) ch;
892
				hdd = (HeadersFootersContainer) ch[i];
893
				break;
909
				break;
894
			}
910
			}
895
		}
911
		}
Lines 912-922 Link Here
912
		boolean ppt2007 = "___PPT12".equals(tag);
928
		boolean ppt2007 = "___PPT12".equals(tag);
913
929
914
		HeadersFootersContainer hdd = null;
930
		HeadersFootersContainer hdd = null;
915
		Record[] ch = _documentRecord.getChildRecords();
931
		for (Record ch : _documentRecord.getChildRecords()) {
916
		for (int i = 0; i < ch.length; i++) {
932
			if (ch instanceof HeadersFootersContainer
917
			if (ch[i] instanceof HeadersFootersContainer
933
					&& ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) {
918
					&& ((HeadersFootersContainer) ch[i]).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) {
934
				hdd = (HeadersFootersContainer) ch;
919
				hdd = (HeadersFootersContainer) ch[i];
920
				break;
935
				break;
921
			}
936
			}
922
		}
937
		}
Lines 1107-1143 Link Here
1107
    }
1122
    }
1108
1123
1109
    protected int addPersistentObject(PositionDependentRecord slideRecord) {
1124
    protected int addPersistentObject(PositionDependentRecord slideRecord) {
1110
		int slideRecordPos = _hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
1125
    	slideRecord.setLastOnDiskOffset(HSLFSlideShow.UNSET_OFFSET);
1111
		_records = _hslfSlideShow.getRecords();
1126
		_hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
1112
1127
1113
		// Add the new Slide into the PersistPtr stuff
1128
        // For position dependent records, hold where they were and now are
1114
		int offset = 0;
1129
        // As we go along, update, and hand over, to any Position Dependent
1115
		int slideOffset = 0;
1130
        // records we happen across
1116
		PersistPtrHolder ptr = null;
1131
		Map<RecordTypes.Type,PositionDependentRecord> interestingRecords =
1117
		UserEditAtom usr = null;
1132
                new HashMap<RecordTypes.Type,PositionDependentRecord>();
1118
		int i = 0;
1119
		for (Record record : _records) {
1120
            // Grab interesting records as they come past
1121
			int recordType = (int)record.getRecordType();
1122
            if (recordType == RecordTypes.PersistPtrIncrementalBlock.typeID) {
1123
                ptr = (PersistPtrHolder)record;
1124
            }
1125
            if (recordType == RecordTypes.UserEditAtom.typeID) {
1126
                usr = (UserEditAtom)record;
1127
            }
1128
1133
1129
			if (i++ == slideRecordPos) {
1134
		try {
1130
				slideOffset = offset;
1135
            _hslfSlideShow.updateAndWriteDependantRecords(null,interestingRecords);
1131
			}
1136
        } catch (IOException e) {
1132
			
1137
            throw new HSLFException(e);
1133
			try {
1138
        }
1134
				ByteArrayOutputStream out = new ByteArrayOutputStream();
1139
		
1135
				record.writeOut(out);
1140
		PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
1136
				offset += out.size();
1141
		UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
1137
			} catch (IOException e) {
1138
				throw new HSLFException(e);
1139
			}
1140
		}
1141
1142
1142
		// persist ID is UserEditAtom.maxPersistWritten + 1
1143
		// persist ID is UserEditAtom.maxPersistWritten + 1
1143
		int psrId = usr.getMaxPersistWritten() + 1;
1144
		int psrId = usr.getMaxPersistWritten() + 1;
Lines 1149-1154 Link Here
1149
1150
1150
		// Add the new slide into the last PersistPtr
1151
		// Add the new slide into the last PersistPtr
1151
		// (Also need to tell it where it is)
1152
		// (Also need to tell it where it is)
1153
		int slideOffset = slideRecord.getLastOnDiskOffset();
1152
		slideRecord.setLastOnDiskOffset(slideOffset);
1154
		slideRecord.setLastOnDiskOffset(slideOffset);
1153
		ptr.addSlideLookup(psrId, slideOffset);
1155
		ptr.addSlideLookup(psrId, slideOffset);
1154
		logger.log(POILogger.INFO, "New slide/object ended up at " + slideOffset);
1156
		logger.log(POILogger.INFO, "New slide/object ended up at " + slideOffset);
(-)src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java (+74 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hslf;
19
20
import java.io.ByteArrayInputStream;
21
import java.io.ByteArrayOutputStream;
22
import java.io.File;
23
import java.io.IOException;
24
import java.io.InputStream;
25
26
import org.apache.poi.POIDataSamples;
27
import org.apache.poi.hslf.usermodel.SlideShow;
28
29
public class HSLFTestDataSamples {
30
31
	private static final POIDataSamples _inst = POIDataSamples.getSlideShowInstance();
32
33
	public static InputStream openSampleFileStream(String sampleFileName) {
34
		return _inst.openResourceAsStream(sampleFileName);
35
	}
36
	public static File getSampleFile(String sampleFileName) {
37
	   return _inst.getFile(sampleFileName);
38
	}
39
	public static byte[] getTestDataFileContent(String fileName) {
40
		return _inst.readFile(fileName);
41
	}
42
43
	/**
44
	 * Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back
45
	 * from a <tt>ByteArrayInputStream</tt>.<p/>
46
	 * Useful for verifying that the serialisation round trip
47
	 */
48
	public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
49
		try {
50
			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
51
			original.write(baos);
52
			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
53
			return new HSLFSlideShow(bais);
54
		} catch (IOException e) {
55
			throw new RuntimeException(e);
56
		}
57
	}
58
59
	/**
60
	 * Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back
61
	 * from a <tt>ByteArrayInputStream</tt>.<p/>
62
	 * Useful for verifying that the serialisation round trip
63
	 */
64
	public static SlideShow writeOutAndReadBack(SlideShow original) {
65
		try {
66
			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
67
			original.write(baos);
68
			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
69
			return new SlideShow(bais);
70
		} catch (IOException e) {
71
			throw new RuntimeException(e);
72
		}
73
	}
74
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java (-6 / +19 lines)
Lines 18-32 Link Here
18
package org.apache.poi.hslf;
18
package org.apache.poi.hslf;
19
19
20
20
21
import java.io.ByteArrayInputStream;
22
import java.io.ByteArrayOutputStream;
23
import java.io.FileNotFoundException;
24
21
import junit.framework.TestCase;
25
import junit.framework.TestCase;
22
26
23
import org.apache.poi.hslf.usermodel.SlideShow;
24
import org.apache.poi.poifs.filesystem.*;
25
import org.apache.poi.POIDataSamples;
27
import org.apache.poi.POIDataSamples;
26
28
import org.apache.poi.hslf.usermodel.SlideShow;
27
import java.io.ByteArrayOutputStream;
29
import org.apache.poi.poifs.filesystem.DocumentEntry;
28
import java.io.ByteArrayInputStream;
30
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
29
import java.io.FileNotFoundException;
30
31
31
/**
32
/**
32
 * Tests that HSLFSlideShow writes the powerpoint bit of data back out
33
 * Tests that HSLFSlideShow writes the powerpoint bit of data back out
Lines 160-163 Link Here
160
			assertEquals(_oData[i], _nData[i]);
161
			assertEquals(_oData[i], _nData[i]);
161
		}
162
		}
162
	}
163
	}
164
    
165
    public void test48593() throws Exception {
166
		SlideShow slideShow = new SlideShow();
167
		slideShow.createSlide();
168
		slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
169
		slideShow.createSlide();
170
		slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
171
		slideShow.createSlide();
172
		slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
173
		slideShow.createSlide();
174
		slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
175
    }
163
}
176
}

Return to bug 48593