Lines 24-30
import java.io.OutputStream;
Link Here
|
24 |
|
24 |
|
25 |
import org.apache.poi.POIXMLDocumentPart; |
25 |
import org.apache.poi.POIXMLDocumentPart; |
26 |
import org.apache.poi.POIXMLException; |
26 |
import org.apache.poi.POIXMLException; |
27 |
import org.apache.poi.POIXMLRelation; |
|
|
28 |
import org.apache.poi.openxml4j.opc.PackagePart; |
27 |
import org.apache.poi.openxml4j.opc.PackagePart; |
29 |
import org.apache.poi.openxml4j.opc.PackageRelationship; |
28 |
import org.apache.poi.openxml4j.opc.PackageRelationship; |
30 |
import org.apache.poi.sl.usermodel.PictureData; |
29 |
import org.apache.poi.sl.usermodel.PictureData; |
Lines 38-124
import org.apache.poi.util.IOUtils;
Link Here
|
38 |
*/ |
37 |
*/ |
39 |
@Beta |
38 |
@Beta |
40 |
public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData { |
39 |
public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData { |
41 |
/** |
|
|
42 |
* Extended windows meta file |
43 |
*/ |
44 |
public static final int PICTURE_TYPE_EMF = 2; |
45 |
|
40 |
|
46 |
/** |
41 |
/** Extended windows meta file */ |
47 |
* Windows Meta File |
42 |
@Deprecated public static final int PICTURE_TYPE_EMF = 2; |
48 |
*/ |
|
|
49 |
public static final int PICTURE_TYPE_WMF = 3; |
50 |
|
43 |
|
51 |
/** |
44 |
/** Windows Meta File */ |
52 |
* Mac PICT format |
45 |
@Deprecated public static final int PICTURE_TYPE_WMF = 3; |
53 |
*/ |
|
|
54 |
public static final int PICTURE_TYPE_PICT = 4; |
55 |
|
46 |
|
56 |
/** |
47 |
/** Mac PICT format */ |
57 |
* JPEG format |
48 |
@Deprecated public static final int PICTURE_TYPE_PICT = 4; |
58 |
*/ |
|
|
59 |
public static final int PICTURE_TYPE_JPEG = 5; |
60 |
|
49 |
|
61 |
/** |
50 |
/** JPEG format */ |
62 |
* PNG format |
51 |
@Deprecated public static final int PICTURE_TYPE_JPEG = 5; |
63 |
*/ |
|
|
64 |
public static final int PICTURE_TYPE_PNG = 6; |
65 |
|
52 |
|
66 |
/** |
53 |
/** PNG format */ |
67 |
* Device independent bitmap |
54 |
@Deprecated public static final int PICTURE_TYPE_PNG = 6; |
68 |
*/ |
|
|
69 |
public static final int PICTURE_TYPE_DIB = 7; |
70 |
|
55 |
|
71 |
/** |
56 |
/** Device independent bitmap */ |
72 |
* GIF image format |
57 |
@Deprecated public static final int PICTURE_TYPE_DIB = 7; |
73 |
*/ |
|
|
74 |
public static final int PICTURE_TYPE_GIF = 8; |
75 |
|
58 |
|
76 |
/** |
59 |
/** GIF image format */ |
77 |
* Tag Image File (.tiff) |
60 |
@Deprecated public static final int PICTURE_TYPE_GIF = 8; |
78 |
*/ |
|
|
79 |
public static final int PICTURE_TYPE_TIFF = 9; |
80 |
|
61 |
|
81 |
/** |
62 |
/** Tag Image File (.tiff) */ |
82 |
* Encapsulated Postscript (.eps) |
63 |
@Deprecated public static final int PICTURE_TYPE_TIFF = 9; |
83 |
*/ |
|
|
84 |
public static final int PICTURE_TYPE_EPS = 10; |
85 |
|
64 |
|
|
|
65 |
/** Encapsulated Postscript (.eps) */ |
66 |
@Deprecated public static final int PICTURE_TYPE_EPS = 10; |
86 |
|
67 |
|
87 |
/** |
68 |
/** Windows Bitmap (.bmp) */ |
88 |
* Windows Bitmap (.bmp) |
69 |
@Deprecated public static final int PICTURE_TYPE_BMP = 11; |
89 |
*/ |
|
|
90 |
public static final int PICTURE_TYPE_BMP = 11; |
91 |
|
70 |
|
92 |
/** |
71 |
/** WordPerfect graphics (.wpg) */ |
93 |
* WordPerfect graphics (.wpg) |
72 |
@Deprecated public static final int PICTURE_TYPE_WPG = 12; |
94 |
*/ |
|
|
95 |
public static final int PICTURE_TYPE_WPG = 12; |
96 |
|
73 |
|
97 |
/** |
74 |
/** Microsoft Windows Media Photo image (.wdp) */ |
98 |
* Microsoft Windows Media Photo image (.wdp) |
75 |
@Deprecated public static final int PICTURE_TYPE_WDP = 13; |
99 |
*/ |
|
|
100 |
public static final int PICTURE_TYPE_WDP = 13; |
101 |
|
76 |
|
102 |
/** |
|
|
103 |
* Relationships for each known picture type |
104 |
*/ |
105 |
protected static final POIXMLRelation[] RELATIONS; |
106 |
|
107 |
static { |
108 |
RELATIONS = new POIXMLRelation[14]; |
109 |
RELATIONS[PICTURE_TYPE_EMF] = XSLFRelation.IMAGE_EMF; |
110 |
RELATIONS[PICTURE_TYPE_WMF] = XSLFRelation.IMAGE_WMF; |
111 |
RELATIONS[PICTURE_TYPE_PICT] = XSLFRelation.IMAGE_PICT; |
112 |
RELATIONS[PICTURE_TYPE_JPEG] = XSLFRelation.IMAGE_JPEG; |
113 |
RELATIONS[PICTURE_TYPE_PNG] = XSLFRelation.IMAGE_PNG; |
114 |
RELATIONS[PICTURE_TYPE_DIB] = XSLFRelation.IMAGE_DIB; |
115 |
RELATIONS[PICTURE_TYPE_GIF] = XSLFRelation.IMAGE_GIF; |
116 |
RELATIONS[PICTURE_TYPE_TIFF] = XSLFRelation.IMAGE_TIFF; |
117 |
RELATIONS[PICTURE_TYPE_EPS] = XSLFRelation.IMAGE_EPS; |
118 |
RELATIONS[PICTURE_TYPE_BMP] = XSLFRelation.IMAGE_BMP; |
119 |
RELATIONS[PICTURE_TYPE_WPG] = XSLFRelation.IMAGE_WPG; |
120 |
RELATIONS[PICTURE_TYPE_WDP] = XSLFRelation.IMAGE_WDP; |
121 |
} |
122 |
|
77 |
|
123 |
private Long checksum = null; |
78 |
private Long checksum = null; |
124 |
|
79 |
|
Lines 187-204
public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
Link Here
|
187 |
* |
142 |
* |
188 |
* @return an integer constant that specifies type of this picture |
143 |
* @return an integer constant that specifies type of this picture |
189 |
*/ |
144 |
*/ |
|
|
145 |
@Deprecated |
190 |
public int getPictureType() { |
146 |
public int getPictureType() { |
191 |
String contentType = getPackagePart().getContentType(); |
147 |
// OLD // String contentType = getPackagePart().getContentType(); |
192 |
for (int i = 0; i < RELATIONS.length; i++) { |
148 |
// OLD // for (int i = 0; i < RELATIONS.length; i++) { |
193 |
if (RELATIONS[i] == null) { |
149 |
// OLD // if (RELATIONS[i] == null) { |
194 |
continue; |
150 |
// OLD // continue; |
195 |
} |
151 |
// OLD // } |
196 |
|
152 |
// OLD // |
197 |
if (RELATIONS[i].getContentType().equals(contentType)) { |
153 |
// OLD // if (RELATIONS[i].getContentType().equals(contentType)) { |
198 |
return i; |
154 |
// OLD // return i; |
199 |
} |
155 |
// OLD // } |
200 |
} |
156 |
// OLD // } |
201 |
return 0; |
157 |
// OLD // return 0; |
|
|
158 |
|
159 |
XSLFPicture.Type type = getType(); |
160 |
return type == null ? 0 : type.getDeprecatedPictureTypeIndex(); |
202 |
} |
161 |
} |
203 |
|
162 |
|
204 |
long getChecksum(){ |
163 |
long getChecksum(){ |
Lines 217-232
public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
Link Here
|
217 |
protected void prepareForCommit() { |
176 |
protected void prepareForCommit() { |
218 |
// do not clear the part here |
177 |
// do not clear the part here |
219 |
} |
178 |
} |
220 |
|
179 |
|
221 |
public String getContentType() { |
180 |
|
222 |
POIXMLRelation rel = RELATIONS[getPictureType()]; |
181 |
/** |
223 |
return (rel == null) ? null : rel.getContentType(); |
182 |
* Return the enum corresponding to the type of this picture content, |
|
|
183 |
* null on failure |
184 |
*/ |
185 |
public XSLFPicture.Type getType() |
186 |
{ |
187 |
return XSLFPicture.Type.findByContentType(getPackagePart().getContentType()); |
224 |
} |
188 |
} |
225 |
|
189 |
|
|
|
190 |
|
191 |
public String getContentType() |
192 |
{ |
193 |
// OLD // POIXMLRelation rel = RELATIONS[getPictureType()]; |
194 |
// OLD // return (rel == null) ? null : rel.getContentType(); |
195 |
|
196 |
XSLFPicture.Type type = getType(); |
197 |
return (type == null) ? null : type.getContentType(); |
198 |
} |
199 |
|
200 |
@Override |
226 |
public void setData(byte[] data) throws IOException { |
201 |
public void setData(byte[] data) throws IOException { |
227 |
OutputStream os = getPackagePart().getOutputStream(); |
202 |
OutputStream os = getPackagePart().getOutputStream(); |
228 |
os.write(data); |
203 |
os.write(data); |
229 |
os.close(); |
204 |
os.close(); |
|
|
205 |
|
206 |
// checksum is invalid |
207 |
checksum = null; |
230 |
} |
208 |
} |
231 |
|
209 |
|
232 |
|
210 |
|