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

(-)src/java/org/apache/poi/hpsf/ClassID.java (+6 lines)
Lines 34-39 Link Here
34
    public static final ClassID PPT_SHOW = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
34
    public static final ClassID PPT_SHOW = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
35
    public static final ClassID XLS_WORKBOOK = new ClassID("{00020841-0000-0000-C000-000000000046}");
35
    public static final ClassID XLS_WORKBOOK = new ClassID("{00020841-0000-0000-C000-000000000046}");
36
    public static final ClassID TXT_ONLY = new ClassID("{5e941d80-bf96-11cd-b579-08002b30bfeb}"); // ???
36
    public static final ClassID TXT_ONLY = new ClassID("{5e941d80-bf96-11cd-b579-08002b30bfeb}"); // ???
37
    public static final ClassID EXCEL97      = new ClassID("{00020820-0000-0000-C000-000000000046}");
38
    public static final ClassID EXCEL95      = new ClassID("{00020810-0000-0000-C000-000000000046}");
39
    public static final ClassID WORD97       = new ClassID("{00020906-0000-0000-C000-000000000046}");
40
    public static final ClassID WORD95       = new ClassID("{00020900-0000-0000-C000-000000000046}");
41
    public static final ClassID POWERPOINT97 = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
42
    public static final ClassID POWERPOINT95 = new ClassID("{EA7BAE70-FB3B-11CD-A903-00AA00510EA3}");
37
	
43
	
38
	
44
	
39
    /**
45
    /**
(-)src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java (+38 lines)
Lines 23-28 Link Here
23
import org.apache.poi.hslf.record.ExObjList;
23
import org.apache.poi.hslf.record.ExObjList;
24
import org.apache.poi.hslf.record.Record;
24
import org.apache.poi.hslf.record.Record;
25
import org.apache.poi.hslf.record.ExEmbed;
25
import org.apache.poi.hslf.record.ExEmbed;
26
import org.apache.poi.hslf.record.RecordTypes;
27
import org.apache.poi.util.LittleEndian;
26
import org.apache.poi.util.POILogger;
28
import org.apache.poi.util.POILogger;
27
29
28
30
Lines 74-79 Link Here
74
    }
76
    }
75
77
76
    /**
78
    /**
79
     * Set the unique identifier for the OLE object and
80
     * register it in the necessary structures
81
     * 
82
     * @param objectId the unique identifier for the OLE object
83
     */
84
    public void setObjectID(int objectId){
85
    	setEscherProperty(EscherProperties.BLIP__PICTUREID, objectId);
86
    	
87
    	EscherContainerRecord ecr = getSpContainer();
88
    	EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
89
        spRecord.setFlags(spRecord.getFlags()|EscherSpRecord.FLAG_OLESHAPE);
90
91
        EscherContainerRecord uerCont = ecr.getChildById((short)RecordTypes.EscherClientData);
92
        if (uerCont == null) {
93
        	uerCont = new EscherContainerRecord();
94
        	ecr.addChildRecord(uerCont);
95
        }
96
        uerCont.setRecordId((short)RecordTypes.EscherClientData);
97
        uerCont.setVersion((short)0x000F); // yes, we are still a container ...
98
99
        UnknownEscherRecord uer = uerCont.getChildById((short)RecordTypes.ExObjRefAtom.typeID);
100
        if (uer == null) {
101
        	uer = new UnknownEscherRecord();
102
        	uerCont.addChildRecord(uer);
103
        }
104
        
105
        byte uerData[] = new byte[12];
106
        LittleEndian.putShort( uerData, 0, (short)0 ); // options = 0
107
        LittleEndian.putShort( uerData, 2, (short)RecordTypes.ExObjRefAtom.typeID); // recordId
108
        LittleEndian.putInt( uerData, 4, 4 ); // remaining bytes
109
        LittleEndian.putInt( uerData, 8, objectId ); // the data
110
        uer.fillFields(uerData, 0, null);        
111
    }
112
    
113
    
114
    /**
77
     * Returns unique identifier for the OLE object.
115
     * Returns unique identifier for the OLE object.
78
     *
116
     *
79
     * @return the unique identifier for the OLE object
117
     * @return the unique identifier for the OLE object
(-)src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java (-2 / +6 lines)
Lines 70-76 Link Here
70
     */
70
     */
71
    protected ExEmbedAtom() {
71
    protected ExEmbedAtom() {
72
        _header = new byte[8];
72
        _header = new byte[8];
73
        _data = new byte[7];
73
        _data = new byte[8];
74
74
75
        LittleEndian.putShort(_header, 2, (short)getRecordType());
75
        LittleEndian.putShort(_header, 2, (short)getRecordType());
76
        LittleEndian.putInt(_header, 4, _data.length);
76
        LittleEndian.putInt(_header, 4, _data.length);
Lines 95-101 Link Here
95
        System.arraycopy(source,start+8,_data,0,len-8);
95
        System.arraycopy(source,start+8,_data,0,len-8);
96
96
97
        // Must be at least 4 bytes long
97
        // Must be at least 4 bytes long
98
        if(_data.length < 7) {
98
        if(_data.length < 8) {
99
        	throw new IllegalArgumentException("The length of the data for a ExEmbedAtom must be at least 4 bytes, but was only " + _data.length);
99
        	throw new IllegalArgumentException("The length of the data for a ExEmbedAtom must be at least 4 bytes, but was only " + _data.length);
100
        }
100
        }
101
    }
101
    }
Lines 120-125 Link Here
120
        return _data[4] != 0;
120
        return _data[4] != 0;
121
    }
121
    }
122
122
123
    public void setCantLockServerB(boolean cantBeLocked) {
124
    	_data[4] = (byte)(cantBeLocked ? 1 : 0);
125
    }
126
    
123
    /**
127
    /**
124
     * Gets whether it is not required to send the dimensions to the embedded object.
128
     * Gets whether it is not required to send the dimensions to the embedded object.
125
     *
129
     *
(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (-85 / +167 lines)
Lines 18-23 Link Here
18
package org.apache.poi.hslf.usermodel;
18
package org.apache.poi.hslf.usermodel;
19
19
20
import java.awt.Dimension;
20
import java.awt.Dimension;
21
import java.io.ByteArrayInputStream;
21
import java.io.ByteArrayOutputStream;
22
import java.io.ByteArrayOutputStream;
22
import java.io.File;
23
import java.io.File;
23
import java.io.FileInputStream;
24
import java.io.FileInputStream;
Lines 30-35 Link Here
30
import org.apache.poi.ddf.EscherContainerRecord;
31
import org.apache.poi.ddf.EscherContainerRecord;
31
import org.apache.poi.ddf.EscherOptRecord;
32
import org.apache.poi.ddf.EscherOptRecord;
32
import org.apache.poi.ddf.EscherRecord;
33
import org.apache.poi.ddf.EscherRecord;
34
import org.apache.poi.hpsf.ClassID;
33
import org.apache.poi.hslf.HSLFSlideShow;
35
import org.apache.poi.hslf.HSLFSlideShow;
34
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
36
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
35
import org.apache.poi.hslf.exceptions.HSLFException;
37
import org.apache.poi.hslf.exceptions.HSLFException;
Lines 38-43 Link Here
38
import org.apache.poi.hslf.model.Slide;
40
import org.apache.poi.hslf.model.Slide;
39
import org.apache.poi.hslf.record.*;
41
import org.apache.poi.hslf.record.*;
40
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
42
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
43
import org.apache.poi.poifs.filesystem.DirectoryNode;
44
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
41
import org.apache.poi.util.POILogFactory;
45
import org.apache.poi.util.POILogFactory;
42
import org.apache.poi.util.POILogger;
46
import org.apache.poi.util.POILogger;
43
47
Lines 723-775 Link Here
723
727
724
		// Add the core records for this new Slide to the record tree
728
		// Add the core records for this new Slide to the record tree
725
		org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord();
729
		org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord();
726
		int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(slideRecord);
730
		int psrId = addPersistentObject(slideRecord);
727
		_records = _hslfSlideShow.getRecords();
728
729
		// Add the new Slide into the PersistPtr stuff
730
		int offset = 0;
731
		int slideOffset = 0;
732
		PersistPtrHolder ptr = null;
733
		UserEditAtom usr = null;
734
		for (int i = 0; i < _records.length; i++) {
735
			Record record = _records[i];
736
			ByteArrayOutputStream out = new ByteArrayOutputStream();
737
			try {
738
				record.writeOut(out);
739
			} catch (IOException e) {
740
				throw new HSLFException(e);
741
			}
742
743
			// Grab interesting records as they come past
744
			if (_records[i].getRecordType() == RecordTypes.PersistPtrIncrementalBlock.typeID) {
745
				ptr = (PersistPtrHolder) _records[i];
746
			}
747
			if (_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) {
748
				usr = (UserEditAtom) _records[i];
749
			}
750
751
			if (i == slideRecordPos) {
752
				slideOffset = offset;
753
			}
754
			offset += out.size();
755
		}
756
757
		// persist ID is UserEditAtom.maxPersistWritten + 1
758
		int psrId = usr.getMaxPersistWritten() + 1;
759
		sp.setRefID(psrId);
731
		sp.setRefID(psrId);
760
		slideRecord.setSheetId(psrId);
732
		slideRecord.setSheetId(psrId);
761
733
		
762
		// Last view is now of the slide
763
		usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
764
		usr.setMaxPersistWritten(psrId); // increment the number of persit
765
										 // objects
766
767
		// Add the new slide into the last PersistPtr
768
		// (Also need to tell it where it is)
769
		slideRecord.setLastOnDiskOffset(slideOffset);
770
		ptr.addSlideLookup(sp.getRefID(), slideOffset);
771
		logger.log(POILogger.INFO, "New slide ended up at " + slideOffset);
772
773
		slide.setMasterSheet(_masters[0]);
734
		slide.setMasterSheet(_masters[0]);
774
		// All done and added
735
		// All done and added
775
		return slide;
736
		return slide;
Lines 978-993 Link Here
978
	 * @return 0-based index of the movie
939
	 * @return 0-based index of the movie
979
	 */
940
	 */
980
	public int addMovie(String path, int type) {
941
	public int addMovie(String path, int type) {
981
		ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
982
		if (lst == null) {
983
			lst = new ExObjList();
984
			_documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
985
		}
986
987
		ExObjListAtom objAtom = lst.getExObjListAtom();
988
		// increment the object ID seed
989
		int objectId = (int) objAtom.getObjectIDSeed() + 1;
990
		objAtom.setObjectIDSeed(objectId);
991
		ExMCIMovie mci;
942
		ExMCIMovie mci;
992
		switch (type) {
943
		switch (type) {
993
			case MovieShape.MOVIE_MPEG:
944
			case MovieShape.MOVIE_MPEG:
Lines 1000-1010 Link Here
1000
				throw new IllegalArgumentException("Unsupported Movie: " + type);
951
				throw new IllegalArgumentException("Unsupported Movie: " + type);
1001
		}
952
		}
1002
953
1003
		lst.appendChildRecord(mci);
1004
		ExVideoContainer exVideo = mci.getExVideo();
954
		ExVideoContainer exVideo = mci.getExVideo();
1005
		exVideo.getExMediaAtom().setObjectId(objectId);
1006
		exVideo.getExMediaAtom().setMask(0xE80000);
955
		exVideo.getExMediaAtom().setMask(0xE80000);
1007
		exVideo.getPathAtom().setText(path);
956
		exVideo.getPathAtom().setText(path);
957
958
		int objectId = addToObjListAtom(mci);
959
		exVideo.getExMediaAtom().setObjectId(objectId);
960
		
1008
		return objectId;
961
		return objectId;
1009
	}
962
	}
1010
963
Lines 1019-1045 Link Here
1019
	 * @return 0-based index of the control
972
	 * @return 0-based index of the control
1020
	 */
973
	 */
1021
	public int addControl(String name, String progId) {
974
	public int addControl(String name, String progId) {
1022
		ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
1023
		if (lst == null) {
1024
			lst = new ExObjList();
1025
			_documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
1026
		}
1027
		ExObjListAtom objAtom = lst.getExObjListAtom();
1028
		// increment the object ID seed
1029
		int objectId = (int) objAtom.getObjectIDSeed() + 1;
1030
		objAtom.setObjectIDSeed(objectId);
1031
		ExControl ctrl = new ExControl();
975
		ExControl ctrl = new ExControl();
976
		ctrl.setProgId(progId);
977
		ctrl.setMenuName(name);
978
		ctrl.setClipboardName(name);
979
		
1032
		ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
980
		ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
1033
		oleObj.setObjID(objectId);
1034
		oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
981
		oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
1035
		oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
982
		oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
1036
		oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
983
		oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
1037
984
		
1038
		ctrl.setProgId(progId);
985
		int objectId = addToObjListAtom(ctrl);
1039
		ctrl.setMenuName(name);
986
		oleObj.setObjID(objectId);
1040
		ctrl.setClipboardName(name);
1041
		lst.addChildAfter(ctrl, objAtom);
1042
1043
		return objectId;
987
		return objectId;
1044
	}
988
	}
1045
989
Lines 1049-1076 Link Here
1049
	 * @return 0-based index of the hyperlink
993
	 * @return 0-based index of the hyperlink
1050
	 */
994
	 */
1051
	public int addHyperlink(Hyperlink link) {
995
	public int addHyperlink(Hyperlink link) {
1052
		ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
1053
		if (lst == null) {
1054
			lst = new ExObjList();
1055
			_documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
1056
		}
1057
		ExObjListAtom objAtom = lst.getExObjListAtom();
1058
		// increment the object ID seed
1059
		int objectId = (int) objAtom.getObjectIDSeed() + 1;
1060
		objAtom.setObjectIDSeed(objectId);
1061
1062
		ExHyperlink ctrl = new ExHyperlink();
996
		ExHyperlink ctrl = new ExHyperlink();
1063
		ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
997
		ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
1064
		obj.setNumber(objectId);
1065
        if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
998
        if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
1066
            ctrl.setLinkURL(link.getAddress(), 0x30);
999
            ctrl.setLinkURL(link.getAddress(), 0x30);
1067
        } else {
1000
        } else {
1068
            ctrl.setLinkURL(link.getAddress());
1001
            ctrl.setLinkURL(link.getAddress());
1069
        }
1002
        }
1070
		ctrl.setLinkTitle(link.getTitle());
1003
		ctrl.setLinkTitle(link.getTitle());
1071
		lst.addChildAfter(ctrl, objAtom);
1004
1005
		int objectId = addToObjListAtom(ctrl);
1072
		link.setId(objectId);
1006
		link.setId(objectId);
1007
		obj.setNumber(objectId);
1008
1009
		return objectId;
1010
	}
1011
1012
	/**
1013
	 * Add a embedded object to this presentation
1014
	 *
1015
	 * @return 0-based index of the embedded object
1016
	 */
1017
	public int addEmbed(POIFSFileSystem poiData) {
1018
        DirectoryNode root = poiData.getRoot();
1019
        
1020
        // prepare embedded data
1021
        if (new ClassID().equals(root.getStorageClsid())) {
1022
        	// need to set class id
1023
	        Map<String,ClassID> olemap = getOleMap();
1024
	        ClassID classID = null;
1025
	    	for (Map.Entry<String,ClassID> entry : olemap.entrySet()) {
1026
	    		if (root.hasEntry(entry.getKey())) {
1027
	    			classID = entry.getValue();
1028
	    			break;
1029
	    		}
1030
	    	}
1031
	    	if (classID == null) {
1032
	    		throw new IllegalArgumentException("Unsupported embedded document");    		
1033
	    	}
1034
	    	
1035
	    	root.setStorageClsid(classID);
1036
        }
1037
        
1038
		ExEmbed exEmbed = new ExEmbed();
1039
        // remove unneccessary infos, so we don't need to specify the type
1040
        // of the ole object multiple times
1041
        Record children[] = exEmbed.getChildRecords();
1042
        exEmbed.removeChild(children[2]);
1043
        exEmbed.removeChild(children[3]);
1044
        exEmbed.removeChild(children[4]);
1045
1046
        ExEmbedAtom eeEmbed = exEmbed.getExEmbedAtom();
1047
        eeEmbed.setCantLockServerB(true);
1073
1048
1049
        ExOleObjAtom eeAtom = exEmbed.getExOleObjAtom();
1050
        eeAtom.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
1051
        eeAtom.setType(ExOleObjAtom.TYPE_EMBEDDED);
1052
        // eeAtom.setSubType(ExOleObjAtom.SUBTYPE_EXCEL);
1053
        // should be ignored?!?, see MS-PPT ExOleObjAtom, but Libre Office sets it ...
1054
        eeAtom.setOptions(1226240);
1055
1056
        ExOleObjStg exOleObjStg = new ExOleObjStg();
1057
        try {
1058
	        final String OLESTREAM_NAME = "\u0001Ole";
1059
	        if (!root.hasEntry(OLESTREAM_NAME)) {
1060
	            // the following data was taken from an example libre office document
1061
	            // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
1062
	            // OlePresXXX, but it seems, that they aren't neccessary
1063
	            byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1064
	            poiData.createDocument(new ByteArrayInputStream(oleBytes), OLESTREAM_NAME);
1065
	        }        
1066
1067
	        ByteArrayOutputStream bos = new ByteArrayOutputStream();
1068
	        poiData.writeFilesystem(bos);
1069
	        exOleObjStg.setData(bos.toByteArray());
1070
        } catch (IOException e) {
1071
        	throw new HSLFException(e);
1072
        }
1073
        
1074
        int psrId = addPersistentObject(exOleObjStg);
1075
        exOleObjStg.setPersistId(psrId);
1076
        eeAtom.setObjStgDataRef(psrId);
1077
        
1078
		int objectId = addToObjListAtom(exEmbed);
1079
		eeAtom.setObjID(objectId);
1074
		return objectId;
1080
		return objectId;
1075
	}
1081
	}
1082
1083
	protected int addToObjListAtom(RecordContainer exObj) {
1084
		ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
1085
		if (lst == null) {
1086
			lst = new ExObjList();
1087
			_documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
1088
		}
1089
		ExObjListAtom objAtom = lst.getExObjListAtom();
1090
		// increment the object ID seed
1091
		int objectId = (int) objAtom.getObjectIDSeed() + 1;
1092
		objAtom.setObjectIDSeed(objectId);
1093
1094
		lst.addChildAfter(exObj, objAtom);
1095
		
1096
		return objectId;
1097
	}
1098
1099
    protected static Map<String,ClassID> getOleMap() {
1100
    	Map<String,ClassID> olemap = new HashMap<String,ClassID>();
1101
    	olemap.put("PowerPoint Document", ClassID.PPT_SHOW);
1102
    	olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
1103
    	olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
1104
    	olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
1105
    	// ... to be continued
1106
    	return olemap;
1107
    }
1108
1109
    protected int addPersistentObject(PositionDependentRecord slideRecord) {
1110
		int slideRecordPos = _hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
1111
		_records = _hslfSlideShow.getRecords();
1112
1113
		// Add the new Slide into the PersistPtr stuff
1114
		int offset = 0;
1115
		int slideOffset = 0;
1116
		PersistPtrHolder ptr = null;
1117
		UserEditAtom usr = null;
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
1129
			if (i++ == slideRecordPos) {
1130
				slideOffset = offset;
1131
			}
1132
			
1133
			try {
1134
				ByteArrayOutputStream out = new ByteArrayOutputStream();
1135
				record.writeOut(out);
1136
				offset += out.size();
1137
			} catch (IOException e) {
1138
				throw new HSLFException(e);
1139
			}
1140
		}
1141
1142
		// persist ID is UserEditAtom.maxPersistWritten + 1
1143
		int psrId = usr.getMaxPersistWritten() + 1;
1144
1145
		// Last view is now of the slide
1146
		usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
1147
		// increment the number of persistent objects
1148
		usr.setMaxPersistWritten(psrId);
1149
1150
		// Add the new slide into the last PersistPtr
1151
		// (Also need to tell it where it is)
1152
		slideRecord.setLastOnDiskOffset(slideOffset);
1153
		ptr.addSlideLookup(psrId, slideOffset);
1154
		logger.log(POILogger.INFO, "New slide/object ended up at " + slideOffset);
1155
1156
		return psrId;
1157
    }
1076
}
1158
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java (+50 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.hslf.model;
18
package org.apache.poi.hslf.model;
19
19
20
import java.awt.geom.Rectangle2D;
21
import java.io.ByteArrayInputStream;
22
import java.io.ByteArrayOutputStream;
23
import java.io.File;
24
import java.io.FileOutputStream;
25
import java.io.InputStream;
26
import java.util.Arrays;
27
20
import junit.framework.TestCase;
28
import junit.framework.TestCase;
21
29
22
import org.apache.poi.hslf.HSLFSlideShow;
30
import org.apache.poi.hslf.HSLFSlideShow;
Lines 26-31 Link Here
26
import org.apache.poi.hssf.usermodel.HSSFSheet;
34
import org.apache.poi.hssf.usermodel.HSSFSheet;
27
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
35
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
28
import org.apache.poi.hwpf.HWPFDocument;
36
import org.apache.poi.hwpf.HWPFDocument;
37
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
38
import org.apache.poi.util.IOUtils;
29
import org.apache.poi.POIDataSamples;
39
import org.apache.poi.POIDataSamples;
30
40
31
public final class TestOleEmbedding extends TestCase {
41
public final class TestOleEmbedding extends TestCase {
Lines 82-85 Link Here
82
        }
92
        }
83
        assertEquals("Expected 2 OLE shapes", 2, cnt);
93
        assertEquals("Expected 2 OLE shapes", 2, cnt);
84
    }
94
    }
95
    
96
    public void testEmbedding() throws Exception {
97
    	HSLFSlideShow _hslfSlideShow = HSLFSlideShow.create();
98
    	SlideShow ppt = new SlideShow(_hslfSlideShow);
99
    	
100
    	File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
101
    	int pictId = ppt.addPicture(pict, Picture.JPEG);
102
    	
103
    	InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("Employee.xls");
104
    	POIFSFileSystem poiData = new POIFSFileSystem(is);
105
    	is.close();
106
    	
107
    	int oleObjectId = ppt.addEmbed(poiData);
108
    	
109
    	Slide slide = ppt.createSlide();
110
    	OLEShape oleShape1 = new OLEShape(pictId);
111
    	oleShape1.setObjectID(oleObjectId);
112
    	slide.addShape(oleShape1);
113
    	oleShape1.setAnchor(new Rectangle2D.Double(100,100,100,100));
114
    	
115
    	if (false) {
116
	    	FileOutputStream fos = new FileOutputStream("embed.ppt");
117
	    	ppt.write(fos);
118
	    	fos.close();
119
    	}
120
    	
121
    	ByteArrayOutputStream bos = new ByteArrayOutputStream();
122
    	ppt.write(bos);
123
    	
124
    	ppt = new SlideShow(new ByteArrayInputStream(bos.toByteArray()));
125
    	OLEShape comp = (OLEShape)ppt.getSlides()[0].getShapes()[0];
126
    	byte compData[] = IOUtils.toByteArray(comp.getObjectData().getData());
127
    	
128
    	bos.reset();
129
    	poiData.writeFilesystem(bos);
130
    	byte expData[] = bos.toByteArray();
131
    	
132
    	assertTrue(Arrays.equals(expData, compData));
133
    	
134
    }
85
}
135
}

Return to bug 55579