Line 0
Link Here
|
|
|
1 |
package org.apache.poi.hslf.record; |
2 |
|
3 |
import java.io.IOException; |
4 |
import java.io.OutputStream; |
5 |
|
6 |
import org.apache.poi.util.LittleEndian; |
7 |
|
8 |
/** |
9 |
* Atom storing information for an OLE object. |
10 |
* |
11 |
* <!-- |
12 |
* offset type name description |
13 |
* |
14 |
* 0 uint4 drawAspect Stores whether the object can be completely seen |
15 |
* (value of 1), or if only the icon is visible (value of 4). |
16 |
* |
17 |
* 4 sint4 type Specifies whether the object is embedded or linked. |
18 |
* 0 - embedded |
19 |
* 1 - linked |
20 |
* |
21 |
* 8 sint4 objID Unique identifier for the OLE object |
22 |
* |
23 |
* 2 sint4 subType This specifies the type of ole object. |
24 |
* 0 - Default object |
25 |
* 1 - Microsoft Clipart Gallery |
26 |
* 2 - Microsoft Word table |
27 |
* 3 - Microsoft Excel |
28 |
* 4 - Microsoft Graph |
29 |
* 5 - Microsoft Organization Chart |
30 |
* 6 - Microsoft Equation Editor |
31 |
* 7 - Microsoft Wordart object |
32 |
* 8 - Sound |
33 |
* 9 - Image |
34 |
* 10 - PowerPoint presentation |
35 |
* 11 - PowerPoint slide |
36 |
* 12 - Microsoft Project |
37 |
* 13 - Microsoft Note-It Ole |
38 |
* 14 - Microsoft Excel chart |
39 |
* 15 - Media Player object |
40 |
* |
41 |
* 16 sint4 objStgDataRef Reference to persist object |
42 |
* |
43 |
* 17 bool1 isBlank Set if the object's image is blank |
44 |
* --> |
45 |
*/ |
46 |
public class ExOleObjAtom extends RecordAtom { |
47 |
|
48 |
public static final int DRAW_ASPECT_VISIBLE = 1; |
49 |
public static final int DRAW_ASPECT_ICON = 4; |
50 |
|
51 |
public static final int TYPE_EMBEDDED = 0; |
52 |
public static final int TYPE_LINKED = 1; |
53 |
|
54 |
public static final int SUBTYPE_DEFAULT = 0; |
55 |
public static final int SUBTYPE_CLIPART_GALLERY = 1; |
56 |
public static final int SUBTYPE_WORD_TABLE = 2; |
57 |
public static final int SUBTYPE_EXCEL = 3; |
58 |
public static final int SUBTYPE_GRAPH = 4; |
59 |
public static final int SUBTYPE_ORGANIZATION_CHART = 5; |
60 |
public static final int SUBTYPE_EQUATION = 6; |
61 |
public static final int SUBTYPE_WORDART = 7; |
62 |
public static final int SUBTYPE_SOUND = 8; |
63 |
public static final int SUBTYPE_IMAGE = 9; |
64 |
public static final int SUBTYPE_POWERPOINT_PRESENTATION = 10; |
65 |
public static final int SUBTYPE_POWERPOINT_SLIDE = 11; |
66 |
public static final int SUBTYPE_PROJECT = 12; |
67 |
public static final int SUBTYPE_NOTEIT = 13; |
68 |
public static final int SUBTYPE_EXCEL_CHART = 14; |
69 |
public static final int SUBTYPE_MEDIA_PLAYER = 15; |
70 |
|
71 |
/** |
72 |
* Record header. |
73 |
*/ |
74 |
private byte[] _header; |
75 |
|
76 |
/** |
77 |
* Record data. |
78 |
*/ |
79 |
private byte[] _data; |
80 |
|
81 |
/** |
82 |
* Constructs a brand new link related atom record. |
83 |
*/ |
84 |
protected ExOleObjAtom() { |
85 |
_header = new byte[8]; |
86 |
_data = new byte[18]; |
87 |
|
88 |
LittleEndian.putShort(_header, 2, (short)getRecordType()); |
89 |
LittleEndian.putInt(_header, 4, _data.length); |
90 |
|
91 |
// I hope it is fine for the other values to be zero. |
92 |
} |
93 |
|
94 |
/** |
95 |
* Constructs the link related atom record from its |
96 |
* source data. |
97 |
* |
98 |
* @param source the source data as a byte array. |
99 |
* @param start the start offset into the byte array. |
100 |
* @param len the length of the slice in the byte array. |
101 |
*/ |
102 |
protected ExOleObjAtom(byte[] source, int start, int len) { |
103 |
// Get the header. |
104 |
_header = new byte[8]; |
105 |
System.arraycopy(source,start,_header,0,8); |
106 |
|
107 |
// Get the record data. |
108 |
_data = new byte[len-8]; |
109 |
System.arraycopy(source,start+8,_data,0,len-8); |
110 |
|
111 |
// Must be at least 4 bytes long |
112 |
if(_data.length < 24) { |
113 |
throw new IllegalArgumentException("The length of the data for a ExOleObjAtom must be at least 24 bytes, but was only " + _data.length); |
114 |
} |
115 |
} |
116 |
|
117 |
/** |
118 |
* Gets whether the object can be completely seen, or if only the |
119 |
* icon is visible. |
120 |
* |
121 |
* @return the draw aspect, one of the {@code DRAW_ASPECT_*} constants. |
122 |
*/ |
123 |
public int getDrawAspect() { |
124 |
return LittleEndian.getInt(_data, 0); |
125 |
} |
126 |
|
127 |
/** |
128 |
* Gets whether the object is embedded or linked. |
129 |
* |
130 |
* @return the type, one of the {@code TYPE_EMBEDDED_*} constants. |
131 |
*/ |
132 |
public int getType() { |
133 |
return LittleEndian.getInt(_data, 4); |
134 |
} |
135 |
|
136 |
/** |
137 |
* Gets the unique identifier for the OLE object. |
138 |
* |
139 |
* @return the object ID. |
140 |
*/ |
141 |
public int getObjID() { |
142 |
return LittleEndian.getInt(_data, 8); |
143 |
} |
144 |
|
145 |
/** |
146 |
* Gets the type of OLE object. |
147 |
* |
148 |
* @return the sub-type, one of the {@code SUBTYPE_*} constants. |
149 |
*/ |
150 |
public int getSubType() { |
151 |
return LittleEndian.getInt(_data, 12); |
152 |
} |
153 |
|
154 |
/** |
155 |
* Gets the reference to the persistent object |
156 |
* |
157 |
* @return the sub-type, one of the {@code SUBTYPE_*} constants. |
158 |
*/ |
159 |
public int getObjStgDataRef() { |
160 |
return LittleEndian.getInt(_data, 16); |
161 |
} |
162 |
|
163 |
/** |
164 |
* Gets whether the object's image is blank. |
165 |
* |
166 |
* @return {@code true} if the object's image is blank. |
167 |
*/ |
168 |
public boolean getIsBlank() { |
169 |
// Even though this is a mere boolean, KOffice's code says it's an int. |
170 |
return LittleEndian.getInt(_data, 20) != 0; |
171 |
} |
172 |
|
173 |
|
174 |
// 16 |
175 |
// |
176 |
// |
177 |
//sint4 |
178 |
// |
179 |
// |
180 |
//objStgDataRef |
181 |
// |
182 |
// |
183 |
//Reference to persist object |
184 |
// |
185 |
//17 |
186 |
// |
187 |
// |
188 |
//bool1 |
189 |
// |
190 |
// |
191 |
//isBlank |
192 |
// |
193 |
// |
194 |
//Set if the object's image is blank |
195 |
|
196 |
|
197 |
// TODO: Convenience methods. |
198 |
|
199 |
/** |
200 |
* Returns the type (held as a little endian in bytes 3 and 4) |
201 |
* that this class handles. |
202 |
*/ |
203 |
public long getRecordType() { |
204 |
return RecordTypes.ExOleObjAtom.typeID; |
205 |
} |
206 |
|
207 |
/** |
208 |
* Have the contents printer out into an OutputStream, used when |
209 |
* writing a file back out to disk |
210 |
* (Normally, atom classes will keep their bytes around, but |
211 |
* non atom classes will just request the bytes from their |
212 |
* children, then chuck on their header and return) |
213 |
*/ |
214 |
public void writeOut(OutputStream out) throws IOException |
215 |
{ |
216 |
out.write(_header); |
217 |
out.write(_data); |
218 |
} |
219 |
} |