mirror of https://github.com/apache/poi.git
#61941 - Move Ole marker generation to Ole10Native
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
be3e6f34c7
commit
8eaecc49a4
|
@ -53,6 +53,7 @@ import org.apache.poi.ddf.EscherBlipRecord;
|
||||||
import org.apache.poi.ddf.EscherMetafileBlip;
|
import org.apache.poi.ddf.EscherMetafileBlip;
|
||||||
import org.apache.poi.ddf.EscherRecord;
|
import org.apache.poi.ddf.EscherRecord;
|
||||||
import org.apache.poi.hpsf.ClassID;
|
import org.apache.poi.hpsf.ClassID;
|
||||||
|
import org.apache.poi.hpsf.ClassIDPredefined;
|
||||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
import org.apache.poi.hpsf.SummaryInformation;
|
||||||
import org.apache.poi.hssf.OldExcelFormatException;
|
import org.apache.poi.hssf.OldExcelFormatException;
|
||||||
|
@ -2007,9 +2008,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
|
|
||||||
protected static Map<String,ClassID> getOleMap() {
|
protected static Map<String,ClassID> getOleMap() {
|
||||||
Map<String,ClassID> olemap = new HashMap<>();
|
Map<String,ClassID> olemap = new HashMap<>();
|
||||||
olemap.put("PowerPoint Document", ClassID.PPT_SHOW);
|
olemap.put("PowerPoint Document", ClassIDPredefined.POWERPOINT_V8.getClassID());
|
||||||
for (String str : WORKBOOK_DIR_ENTRY_NAMES) {
|
for (String str : WORKBOOK_DIR_ENTRY_NAMES) {
|
||||||
olemap.put(str, ClassID.XLS_WORKBOOK);
|
olemap.put(str, ClassIDPredefined.EXCEL_V7_WORKBOOK.getClassID());
|
||||||
}
|
}
|
||||||
// ... to be continued
|
// ... to be continued
|
||||||
return olemap;
|
return olemap;
|
||||||
|
@ -2056,16 +2057,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
String storageStr = "MBD"+ HexDump.toHex(++storageId);
|
String storageStr = "MBD"+ HexDump.toHex(++storageId);
|
||||||
if (!getDirectory().hasEntry(storageStr)) {
|
if (!getDirectory().hasEntry(storageStr)) {
|
||||||
oleDir = getDirectory().createDirectory(storageStr);
|
oleDir = getDirectory().createDirectory(storageStr);
|
||||||
oleDir.setStorageClsid(ClassID.OLE10_PACKAGE);
|
oleDir.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID());
|
||||||
}
|
}
|
||||||
} while (oleDir == null);
|
} while (oleDir == null);
|
||||||
|
|
||||||
// the following data was taken from an example libre office document
|
Ole10Native.createOleMarkerEntry(oleDir);
|
||||||
// beside this "\u0001Ole" record there were several other records, e.g. CompObj,
|
|
||||||
// OlePresXXX, but it seems, that they aren't neccessary
|
|
||||||
byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
||||||
oleDir.createDocument("\u0001Ole", new ByteArrayInputStream(oleBytes));
|
|
||||||
|
|
||||||
Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
|
Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
oleNative.writeOut(bos);
|
oleNative.writeOut(bos);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
package org.apache.poi.poifs.filesystem;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -30,8 +31,6 @@ import org.apache.poi.util.StringUtil;
|
||||||
/**
|
/**
|
||||||
* Represents an Ole10Native record which is wrapped around certain binary
|
* Represents an Ole10Native record which is wrapped around certain binary
|
||||||
* files being embedded in OLE2 documents.
|
* files being embedded in OLE2 documents.
|
||||||
*
|
|
||||||
* @author Rainer Schwarze
|
|
||||||
*/
|
*/
|
||||||
public class Ole10Native {
|
public class Ole10Native {
|
||||||
|
|
||||||
|
@ -41,6 +40,15 @@ public class Ole10Native {
|
||||||
//arbitrarily selected; may need to increase
|
//arbitrarily selected; may need to increase
|
||||||
private static final int MAX_RECORD_LENGTH = 100_000_000;
|
private static final int MAX_RECORD_LENGTH = 100_000_000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default content of the \u0001Ole entry
|
||||||
|
*/
|
||||||
|
private static final byte[] OLE_MARKER_BYTES =
|
||||||
|
{ 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
private static final String OLE_MARKER_NAME = "\u0001Ole";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// (the fields as they appear in the raw record:)
|
// (the fields as they appear in the raw record:)
|
||||||
private int totalSize; // 4 bytes, total size of record not including this field
|
private int totalSize; // 4 bytes, total size of record not including this field
|
||||||
private short flags1 = 2; // 2 bytes, unknown, mostly [02 00]
|
private short flags1 = 2; // 2 bytes, unknown, mostly [02 00]
|
||||||
|
@ -205,6 +213,27 @@ public class Ole10Native {
|
||||||
ofs += dataSize;
|
ofs += dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the \1OLE marker entry, which is not the Ole10Native entry.
|
||||||
|
* Beside this "\u0001Ole" record there were several other records, e.g. CompObj,
|
||||||
|
* OlePresXXX, but it seems, that they aren't necessary
|
||||||
|
*/
|
||||||
|
public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException {
|
||||||
|
if (!parent.hasEntry(OLE_MARKER_NAME)) {
|
||||||
|
parent.createDocument(OLE_MARKER_NAME, new ByteArrayInputStream(OLE_MARKER_BYTES));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the \1OLE marker entry, which is not the Ole10Native entry.
|
||||||
|
* Beside this "\u0001Ole" record there were several other records, e.g. CompObj,
|
||||||
|
* OlePresXXX, but it seems, that they aren't necessary
|
||||||
|
*/
|
||||||
|
public static void createOleMarkerEntry(final POIFSFileSystem poifs) throws IOException {
|
||||||
|
createOleMarkerEntry(poifs.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper - determine length of zero terminated string (ASCIIZ).
|
* Helper - determine length of zero terminated string (ASCIIZ).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
package org.apache.poi.hslf.usermodel;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -38,40 +37,16 @@ import org.apache.poi.ddf.EscherBSERecord;
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.ddf.EscherOptRecord;
|
import org.apache.poi.ddf.EscherOptRecord;
|
||||||
import org.apache.poi.hpsf.ClassID;
|
import org.apache.poi.hpsf.ClassID;
|
||||||
|
import org.apache.poi.hpsf.ClassIDPredefined;
|
||||||
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
|
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
import org.apache.poi.hslf.model.HeadersFooters;
|
import org.apache.poi.hslf.model.HeadersFooters;
|
||||||
import org.apache.poi.hslf.model.MovieShape;
|
import org.apache.poi.hslf.model.MovieShape;
|
||||||
import org.apache.poi.hslf.record.Document;
|
import org.apache.poi.hslf.record.*;
|
||||||
import org.apache.poi.hslf.record.DocumentAtom;
|
|
||||||
import org.apache.poi.hslf.record.ExAviMovie;
|
|
||||||
import org.apache.poi.hslf.record.ExControl;
|
|
||||||
import org.apache.poi.hslf.record.ExEmbed;
|
|
||||||
import org.apache.poi.hslf.record.ExEmbedAtom;
|
|
||||||
import org.apache.poi.hslf.record.ExMCIMovie;
|
|
||||||
import org.apache.poi.hslf.record.ExObjList;
|
|
||||||
import org.apache.poi.hslf.record.ExObjListAtom;
|
|
||||||
import org.apache.poi.hslf.record.ExOleObjAtom;
|
|
||||||
import org.apache.poi.hslf.record.ExOleObjStg;
|
|
||||||
import org.apache.poi.hslf.record.ExVideoContainer;
|
|
||||||
import org.apache.poi.hslf.record.FontCollection;
|
|
||||||
import org.apache.poi.hslf.record.HeadersFootersContainer;
|
|
||||||
import org.apache.poi.hslf.record.MainMaster;
|
|
||||||
import org.apache.poi.hslf.record.Notes;
|
|
||||||
import org.apache.poi.hslf.record.PersistPtrHolder;
|
|
||||||
import org.apache.poi.hslf.record.PositionDependentRecord;
|
|
||||||
import org.apache.poi.hslf.record.PositionDependentRecordContainer;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
|
||||||
import org.apache.poi.hslf.record.RecordContainer;
|
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
|
||||||
import org.apache.poi.hslf.record.Slide;
|
|
||||||
import org.apache.poi.hslf.record.SlideListWithText;
|
|
||||||
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
|
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
|
||||||
import org.apache.poi.hslf.record.SlidePersistAtom;
|
|
||||||
import org.apache.poi.hslf.record.TxMasterStyleAtom;
|
|
||||||
import org.apache.poi.hslf.record.UserEditAtom;
|
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
|
import org.apache.poi.poifs.filesystem.Ole10Native;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.sl.usermodel.MasterSheet;
|
import org.apache.poi.sl.usermodel.MasterSheet;
|
||||||
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
||||||
|
@ -96,12 +71,12 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
|
|
||||||
/** Powerpoint document entry/stream name */
|
/** Powerpoint document entry/stream name */
|
||||||
public static final String POWERPOINT_DOCUMENT = "PowerPoint Document";
|
public static final String POWERPOINT_DOCUMENT = "PowerPoint Document";
|
||||||
|
|
||||||
enum LoadSavePhase {
|
enum LoadSavePhase {
|
||||||
INIT, LOADED
|
INIT, LOADED
|
||||||
}
|
}
|
||||||
private static final ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<>();
|
private static final ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<>();
|
||||||
|
|
||||||
// What we're based on
|
// What we're based on
|
||||||
private final HSLFSlideShowImpl _hslfSlideShow;
|
private final HSLFSlideShowImpl _hslfSlideShow;
|
||||||
|
|
||||||
|
@ -134,7 +109,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
*/
|
*/
|
||||||
public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) {
|
public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) {
|
||||||
loadSavePhase.set(LoadSavePhase.INIT);
|
loadSavePhase.set(LoadSavePhase.INIT);
|
||||||
|
|
||||||
// Get useful things from our base slideshow
|
// Get useful things from our base slideshow
|
||||||
_hslfSlideShow = hslfSlideShow;
|
_hslfSlideShow = hslfSlideShow;
|
||||||
|
|
||||||
|
@ -150,7 +125,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
|
|
||||||
// Build up the model level Slides and Notes
|
// Build up the model level Slides and Notes
|
||||||
buildSlidesAndNotes();
|
buildSlidesAndNotes();
|
||||||
|
|
||||||
loadSavePhase.set(LoadSavePhase.LOADED);
|
loadSavePhase.set(LoadSavePhase.LOADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +166,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
protected static LoadSavePhase getLoadSavePhase() {
|
protected static LoadSavePhase getLoadSavePhase() {
|
||||||
return loadSavePhase.get();
|
return loadSavePhase.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the PersistPtrHolder entries to figure out what is the "most recent"
|
* 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
|
* version of all the core records (Document, Notes, Slide etc), and save a
|
||||||
|
@ -229,7 +204,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
// We'll also want to be able to turn the slide IDs into a position
|
// We'll also want to be able to turn the slide IDs into a position
|
||||||
// in this array
|
// in this array
|
||||||
_sheetIdToCoreRecordsLookup = new HashMap<>();
|
_sheetIdToCoreRecordsLookup = new HashMap<>();
|
||||||
Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]);
|
Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]);
|
||||||
Arrays.sort(allIDs);
|
Arrays.sort(allIDs);
|
||||||
for (int i = 0; i < allIDs.length; i++) {
|
for (int i = 0; i < allIDs.length; i++) {
|
||||||
_sheetIdToCoreRecordsLookup.put(allIDs[i], i);
|
_sheetIdToCoreRecordsLookup.put(allIDs[i], i);
|
||||||
|
@ -239,22 +214,22 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
for (Map.Entry<Integer,Integer> me : mostRecentByBytes.entrySet()) {
|
for (Map.Entry<Integer,Integer> me : mostRecentByBytes.entrySet()) {
|
||||||
mostRecentByBytesRev.put(me.getValue(), me.getKey());
|
mostRecentByBytesRev.put(me.getValue(), me.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now convert the byte offsets back into record offsets
|
// Now convert the byte offsets back into record offsets
|
||||||
for (Record record : _hslfSlideShow.getRecords()) {
|
for (Record record : _hslfSlideShow.getRecords()) {
|
||||||
if (!(record instanceof PositionDependentRecord)) {
|
if (!(record instanceof PositionDependentRecord)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PositionDependentRecord pdr = (PositionDependentRecord) record;
|
PositionDependentRecord pdr = (PositionDependentRecord) record;
|
||||||
int recordAt = pdr.getLastOnDiskOffset();
|
int recordAt = pdr.getLastOnDiskOffset();
|
||||||
|
|
||||||
Integer thisID = mostRecentByBytesRev.get(recordAt);
|
Integer thisID = mostRecentByBytesRev.get(recordAt);
|
||||||
|
|
||||||
if (thisID == null) {
|
if (thisID == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bingo. Now, where do we store it?
|
// Bingo. Now, where do we store it?
|
||||||
int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
|
int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
|
||||||
|
|
||||||
|
@ -342,7 +317,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
// SlideAtom/NotesAtom to match them with the StyleAtomSet
|
// SlideAtom/NotesAtom to match them with the StyleAtomSet
|
||||||
|
|
||||||
findMasterSlides();
|
findMasterSlides();
|
||||||
|
|
||||||
// Having sorted out the masters, that leaves the notes and slides
|
// Having sorted out the masters, that leaves the notes and slides
|
||||||
Map<Integer,Integer> slideIdToNotes = new HashMap<>();
|
Map<Integer,Integer> slideIdToNotes = new HashMap<>();
|
||||||
|
|
||||||
|
@ -364,7 +339,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
if (masterSLWT == null) {
|
if (masterSLWT == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) {
|
for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) {
|
||||||
Record r = getCoreRecordForSAS(sas);
|
Record r = getCoreRecordForSAS(sas);
|
||||||
int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
|
int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
|
||||||
|
@ -379,14 +354,14 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findNotesSlides(Map<Integer,Integer> slideIdToNotes) {
|
private void findNotesSlides(Map<Integer,Integer> slideIdToNotes) {
|
||||||
SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
|
SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
|
||||||
|
|
||||||
if (notesSLWT == null) {
|
if (notesSLWT == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match up the records and the SlideAtomSets
|
// Match up the records and the SlideAtomSets
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) {
|
for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) {
|
||||||
|
@ -408,13 +383,13 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
logger.log(POILogger.ERROR, loggerLoc+", but that was actually a " + r);
|
logger.log(POILogger.ERROR, loggerLoc+", but that was actually a " + r);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Notes notesRecord = (Notes) r;
|
Notes notesRecord = (Notes) r;
|
||||||
|
|
||||||
// Record the match between slide id and these notes
|
// Record the match between slide id and these notes
|
||||||
int slideId = spa.getSlideIdentifier();
|
int slideId = spa.getSlideIdentifier();
|
||||||
slideIdToNotes.put(slideId, idx);
|
slideIdToNotes.put(slideId, idx);
|
||||||
|
|
||||||
HSLFNotes hn = new HSLFNotes(notesRecord);
|
HSLFNotes hn = new HSLFNotes(notesRecord);
|
||||||
hn.setSlideShow(this);
|
hn.setSlideShow(this);
|
||||||
_notes.add(hn);
|
_notes.add(hn);
|
||||||
|
@ -443,7 +418,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
+ ", but that was actually a " + r);
|
+ ", but that was actually a " + r);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Slide slide = (Slide)r;
|
Slide slide = (Slide)r;
|
||||||
|
|
||||||
// Do we have a notes for this?
|
// Do we have a notes for this?
|
||||||
|
@ -467,7 +442,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
_slides.add(hs);
|
_slides.add(hs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
// check for text paragraph modifications
|
// check for text paragraph modifications
|
||||||
|
@ -491,10 +466,10 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_hslfSlideShow.write(out);
|
_hslfSlideShow.write(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDirtyParagraphs(HSLFShapeContainer container) {
|
private void writeDirtyParagraphs(HSLFShapeContainer container) {
|
||||||
for (HSLFShape sh : container.getShapes()) {
|
for (HSLFShape sh : container.getShapes()) {
|
||||||
if (sh instanceof HSLFShapeContainer) {
|
if (sh instanceof HSLFShapeContainer) {
|
||||||
|
@ -542,7 +517,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
public List<HSLFSlideMaster> getSlideMasters() {
|
public List<HSLFSlideMaster> getSlideMasters() {
|
||||||
return _masters;
|
return _masters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all the normal Title Masters found in the slideshow
|
* Returns an array of all the normal Title Masters found in the slideshow
|
||||||
*/
|
*/
|
||||||
|
@ -629,13 +604,13 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
|
Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
|
||||||
_slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
|
_slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
|
||||||
_slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
|
_slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
|
||||||
|
|
||||||
ArrayList<Record> lst = new ArrayList<>();
|
ArrayList<Record> lst = new ArrayList<>();
|
||||||
for (SlideAtomsSet s : sas) {
|
for (SlideAtomsSet s : sas) {
|
||||||
lst.add(s.getSlidePersistAtom());
|
lst.add(s.getSlidePersistAtom());
|
||||||
lst.addAll(Arrays.asList(s.getSlideRecords()));
|
lst.addAll(Arrays.asList(s.getSlideRecords()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Record[] r = lst.toArray(new Record[lst.size()]);
|
Record[] r = lst.toArray(new Record[lst.size()]);
|
||||||
slwt.setChildRecord(r);
|
slwt.setChildRecord(r);
|
||||||
}
|
}
|
||||||
|
@ -667,12 +642,12 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
HSLFSlide removedSlide = _slides.remove(index);
|
HSLFSlide removedSlide = _slides.remove(index);
|
||||||
_notes.remove(removedSlide.getNotes());
|
_notes.remove(removedSlide.getNotes());
|
||||||
sa.remove(index);
|
sa.remove(index);
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
for (HSLFSlide s : _slides) {
|
for (HSLFSlide s : _slides) {
|
||||||
s.setSlideNumber(i++);
|
s.setSlideNumber(i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SlideAtomsSet s : sa) {
|
for (SlideAtomsSet s : sa) {
|
||||||
records.add(s.getSlidePersistAtom());
|
records.add(s.getSlidePersistAtom());
|
||||||
records.addAll(Arrays.asList(s.getSlideRecords()));
|
records.addAll(Arrays.asList(s.getSlideRecords()));
|
||||||
|
@ -774,7 +749,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
int psrId = addPersistentObject(slideRecord);
|
int psrId = addPersistentObject(slideRecord);
|
||||||
sp.setRefID(psrId);
|
sp.setRefID(psrId);
|
||||||
slideRecord.setSheetId(psrId);
|
slideRecord.setSheetId(psrId);
|
||||||
|
|
||||||
slide.setMasterSheet(_masters.get(0));
|
slide.setMasterSheet(_masters.get(0));
|
||||||
// All done and added
|
// All done and added
|
||||||
return slide;
|
return slide;
|
||||||
|
@ -783,15 +758,15 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
@Override
|
@Override
|
||||||
public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
|
public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
|
||||||
if (format == null || format.nativeId == -1) {
|
if (format == null || format.nativeId == -1) {
|
||||||
throw new IllegalArgumentException("Unsupported picture format: " + format);
|
throw new IllegalArgumentException("Unsupported picture format: " + format);
|
||||||
}
|
}
|
||||||
|
|
||||||
HSLFPictureData pd = findPictureData(data);
|
HSLFPictureData pd = findPictureData(data);
|
||||||
if (pd != null) {
|
if (pd != null) {
|
||||||
// identical picture was already added to the SlideShow
|
// identical picture was already added to the SlideShow
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
EscherContainerRecord bstore;
|
EscherContainerRecord bstore;
|
||||||
|
|
||||||
EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
|
EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
|
||||||
|
@ -880,10 +855,10 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
}
|
}
|
||||||
return addPicture(data, format);
|
return addPicture(data, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if a picture with this picture data already exists in this presentation
|
* check if a picture with this picture data already exists in this presentation
|
||||||
*
|
*
|
||||||
* @param pictureData The picture data to find in the SlideShow
|
* @param pictureData The picture data to find in the SlideShow
|
||||||
* @return {@code null} if picture data is not found in this slideshow
|
* @return {@code null} if picture data is not found in this slideshow
|
||||||
* @since 3.15 beta 3
|
* @since 3.15 beta 3
|
||||||
|
@ -979,7 +954,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
|
|
||||||
int objectId = addToObjListAtom(mci);
|
int objectId = addToObjListAtom(mci);
|
||||||
exVideo.getExMediaAtom().setObjectId(objectId);
|
exVideo.getExMediaAtom().setObjectId(objectId);
|
||||||
|
|
||||||
return objectId;
|
return objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -998,12 +973,12 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
ctrl.setProgId(progId);
|
ctrl.setProgId(progId);
|
||||||
ctrl.setMenuName(name);
|
ctrl.setMenuName(name);
|
||||||
ctrl.setClipboardName(name);
|
ctrl.setClipboardName(name);
|
||||||
|
|
||||||
ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
|
ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
|
||||||
oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
|
oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
|
||||||
oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
|
oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
|
||||||
oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
|
oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
|
||||||
|
|
||||||
int objectId = addToObjListAtom(ctrl);
|
int objectId = addToObjListAtom(ctrl);
|
||||||
oleObj.setObjID(objectId);
|
oleObj.setObjID(objectId);
|
||||||
return objectId;
|
return objectId;
|
||||||
|
@ -1016,7 +991,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
*/
|
*/
|
||||||
public int addEmbed(POIFSFileSystem poiData) {
|
public int addEmbed(POIFSFileSystem poiData) {
|
||||||
DirectoryNode root = poiData.getRoot();
|
DirectoryNode root = poiData.getRoot();
|
||||||
|
|
||||||
// prepare embedded data
|
// prepare embedded data
|
||||||
if (new ClassID().equals(root.getStorageClsid())) {
|
if (new ClassID().equals(root.getStorageClsid())) {
|
||||||
// need to set class id
|
// need to set class id
|
||||||
|
@ -1029,12 +1004,12 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (classID == null) {
|
if (classID == null) {
|
||||||
throw new IllegalArgumentException("Unsupported embedded document");
|
throw new IllegalArgumentException("Unsupported embedded document");
|
||||||
}
|
}
|
||||||
|
|
||||||
root.setStorageClsid(classID);
|
root.setStorageClsid(classID);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExEmbed exEmbed = new ExEmbed();
|
ExEmbed exEmbed = new ExEmbed();
|
||||||
// remove unneccessary infos, so we don't need to specify the type
|
// remove unneccessary infos, so we don't need to specify the type
|
||||||
// of the ole object multiple times
|
// of the ole object multiple times
|
||||||
|
@ -1055,26 +1030,18 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
|
|
||||||
ExOleObjStg exOleObjStg = new ExOleObjStg();
|
ExOleObjStg exOleObjStg = new ExOleObjStg();
|
||||||
try {
|
try {
|
||||||
final String OLESTREAM_NAME = "\u0001Ole";
|
Ole10Native.createOleMarkerEntry(poiData);
|
||||||
if (!root.hasEntry(OLESTREAM_NAME)) {
|
|
||||||
// the following data was taken from an example libre office document
|
|
||||||
// beside this "\u0001Ole" record there were several other records, e.g. CompObj,
|
|
||||||
// OlePresXXX, but it seems, that they aren't neccessary
|
|
||||||
byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
||||||
poiData.createDocument(new ByteArrayInputStream(oleBytes), OLESTREAM_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
poiData.writeFilesystem(bos);
|
poiData.writeFilesystem(bos);
|
||||||
exOleObjStg.setData(bos.toByteArray());
|
exOleObjStg.setData(bos.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HSLFException(e);
|
throw new HSLFException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int psrId = addPersistentObject(exOleObjStg);
|
int psrId = addPersistentObject(exOleObjStg);
|
||||||
exOleObjStg.setPersistId(psrId);
|
exOleObjStg.setPersistId(psrId);
|
||||||
eeAtom.setObjStgDataRef(psrId);
|
eeAtom.setObjStgDataRef(psrId);
|
||||||
|
|
||||||
int objectId = addToObjListAtom(exEmbed);
|
int objectId = addToObjListAtom(exEmbed);
|
||||||
eeAtom.setObjID(objectId);
|
eeAtom.setObjID(objectId);
|
||||||
return objectId;
|
return objectId;
|
||||||
|
@ -1088,16 +1055,19 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
objAtom.setObjectIDSeed(objectId);
|
objAtom.setObjectIDSeed(objectId);
|
||||||
|
|
||||||
lst.addChildAfter(exObj, objAtom);
|
lst.addChildAfter(exObj, objAtom);
|
||||||
|
|
||||||
return objectId;
|
return objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String,ClassID> getOleMap() {
|
protected static Map<String,ClassID> getOleMap() {
|
||||||
Map<String,ClassID> olemap = new HashMap<>();
|
Map<String,ClassID> olemap = new HashMap<>();
|
||||||
olemap.put(POWERPOINT_DOCUMENT, ClassID.PPT_SHOW);
|
olemap.put(POWERPOINT_DOCUMENT, ClassIDPredefined.POWERPOINT_V8.getClassID());
|
||||||
olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
|
// as per BIFF8 spec
|
||||||
olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
|
olemap.put("Workbook", ClassIDPredefined.EXCEL_V8.getClassID());
|
||||||
olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
|
// Typically from third party programs
|
||||||
|
olemap.put("WORKBOOK", ClassIDPredefined.EXCEL_V8.getClassID());
|
||||||
|
// Typically odd Crystal Reports exports
|
||||||
|
olemap.put("BOOK", ClassIDPredefined.EXCEL_V8.getClassID());
|
||||||
// ... to be continued
|
// ... to be continued
|
||||||
return olemap;
|
return olemap;
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1087,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HSLFException(e);
|
throw new HSLFException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
|
PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
|
||||||
UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
|
UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
|
||||||
|
|
||||||
|
@ -1158,7 +1128,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||||
public HSLFSlideShowImpl getSlideShowImpl() {
|
public HSLFSlideShowImpl getSlideShowImpl() {
|
||||||
return _hslfSlideShow;
|
return _hslfSlideShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
_hslfSlideShow.close();
|
_hslfSlideShow.close();
|
||||||
|
|
|
@ -104,7 +104,7 @@ public final class TestFileSystemBugs extends TestCase {
|
||||||
Iterator<Entry> it = dir.getEntries();
|
Iterator<Entry> it = dir.getEntries();
|
||||||
entry = it.next();
|
entry = it.next();
|
||||||
assertEquals(true, entry.isDocumentEntry());
|
assertEquals(true, entry.isDocumentEntry());
|
||||||
assertEquals("\u0001Ole10Native", entry.getName());
|
assertEquals(Ole10Native.OLE10_NATIVE, entry.getName());
|
||||||
|
|
||||||
entry = it.next();
|
entry = it.next();
|
||||||
assertEquals(true, entry.isDocumentEntry());
|
assertEquals(true, entry.isDocumentEntry());
|
||||||
|
|
Loading…
Reference in New Issue