Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit 5fd055b

Browse files
author
vbarathan
committed
Add image media support in Document List Feed
1 parent 4e5b82d commit 5fd055b

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

java/src/com/google/gdata/data/docs/DocumentListEntry.java

+45-11
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,26 @@ public class DocumentListEntry extends MediaEntry<DocumentListEntry> {
5050
* Represents the MIME types supported by the doclist GData feed
5151
*/
5252
public enum MediaType {
53-
CSV("text/comma-separated-values"),
54-
DOC("application/msword"),
55-
ODS("application/vnd.oasis.opendocument.spreadsheet"),
53+
JPG("image/jpeg"),
54+
JPEG("image/jpeg"),
55+
PNG("image/png"),
56+
BMP("image/bmp"),
57+
GIF("image/gif"),
58+
TXT("text/plain"),
59+
HTML("text/html"),
60+
HTM("text/html"),
5661
ODT("application/vnd.oasis.opendocument.text"),
62+
SXW("application/vnd.sun.xml.writer"),
63+
DOC("application/msword"),
64+
RTF("application/rtf"),
5765
PPS("application/vnd.ms-powerpoint"),
5866
PPT("application/vnd.ms-powerpoint"),
59-
RTF("application/rtf"),
60-
SXW("application/vnd.sun.xml.writer"),
61-
TXT("text/plain"),
62-
XLS("application/vnd.ms-excel");
67+
XLS("application/vnd.ms-excel"),
68+
ODS("application/x-vnd.oasis.opendocument.spreadsheet"),
69+
CSV("text/csv"),
70+
TAB("text/tab-separated-value"),
71+
TSV("text/tab-separated-value"),
72+
;
6373

6474
private String mimeType;
6575

@@ -81,6 +91,18 @@ public static MediaType fromFileName(String fileName) {
8191
}
8292
}
8393

94+
/**
95+
* Returns the mime type given a file name. Not intended for extenal
96+
* use, see setFile(File, String) instead. protected access for
97+
* testing.
98+
*
99+
* @throws IllegalArgumentException if the mime type is not known
100+
* given the file name
101+
*/
102+
protected static String getMimeTypeFromFileName(String fileName) {
103+
return MediaType.fromFileName(fileName).getMimeType();
104+
}
105+
84106
public static final String DOCUMENT_NAMESPACE
85107
= "http://schemas.google.com/docs/2007";
86108

@@ -157,13 +179,25 @@ public String getId() {
157179
return result;
158180
}
159181

182+
/**
183+
* Associate a File with this entry, implicitly determining the mime type
184+
* from the file's extension.
185+
*
186+
* @deprecated Prefer setFile(File, String)
187+
*/
188+
@Deprecated
160189
public void setFile(File file) throws IOException {
161-
MediaType mediaType = MediaType.fromFileName(file.getName());
162-
MediaFileSource fileSource = new MediaFileSource(file,
163-
mediaType.getMimeType());
190+
setFile(file, getMimeTypeFromFileName(file.getName()));
191+
}
192+
193+
/**
194+
* Associate a File with this entry with the specified mime type
195+
*/
196+
public void setFile(File file, String mimeType) throws IOException {
197+
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
164198
MediaContent content = new MediaContent();
165199
content.setMediaSource(fileSource);
166-
content.setMimeType(new ContentType(mediaType.getMimeType()));
200+
content.setMimeType(new ContentType(mimeType));
167201
setContent(content);
168202
}
169203

0 commit comments

Comments
 (0)