Repository navigation
Expand file tree
/
Copy pathMediaItem.java
More file actions
206 lines (175 loc) · 6.17 KB
/
Copy pathMediaItem.java
File metadata and controls
206 lines (175 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package perf;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import com.fasterxml.jackson.core.*;
public class MediaItem
{
public enum Player { JAVA, FLASH; }
public enum Size { SMALL, LARGE; }
private List<Photo> _photos;
private Content _content;
public MediaItem() { }
public MediaItem(Content c)
{
_content = c;
}
public void addPhoto(Photo p) {
if (_photos == null) {
_photos = new ArrayList<Photo>();
}
_photos.add(p);
}
public List<Photo> getImages() { return _photos; }
public void setImages(List<Photo> p) { _photos = p; }
public Content getContent() { return _content; }
public void setContent(Content c) { _content = c; }
public String asJsonString(JsonFactory f) throws IOException
{
StringWriter w = new StringWriter();
JsonGenerator gen = f.createGenerator(ObjectWriteContext.empty(), w);
write(gen);
gen.close();
w.close();
return w.toString();
}
public void write(JsonGenerator gen) throws IOException
{
gen.writeStartObject();
gen.writeFieldName("content");
if (_content == null) {
gen.writeNull();
} else {
_content.write(gen);
}
gen.writeFieldName("photos");
if (_photos == null) {
gen.writeNull();
} else {
gen.writeStartArray();
for (int i = 0, len = _photos.size(); i < len; ++i) {
_photos.get(i).write(gen);
}
gen.writeEndArray();
}
gen.writeEndObject();
}
/*
/**********************************************************
/* Helper types
/**********************************************************
*/
public static class Photo
{
private String _uri;
private String _title;
private int _width;
private int _height;
private Size _size;
public Photo() {}
public Photo(String uri, String title, int w, int h, Size s)
{
_uri = uri;
_title = title;
_width = w;
_height = h;
_size = s;
}
public String getUri() { return _uri; }
public String getTitle() { return _title; }
public int getWidth() { return _width; }
public int getHeight() { return _height; }
public Size getSize() { return _size; }
public void setUri(String u) { _uri = u; }
public void setTitle(String t) { _title = t; }
public void setWidth(int w) { _width = w; }
public void setHeight(int h) { _height = h; }
public void setSize(Size s) { _size = s; }
public void write(JsonGenerator gen) throws IOException
{
gen.writeStartObject();
gen.writeStringField("uri", _uri);
gen.writeStringField("title", _title);
gen.writeNumberField("width", _width);
gen.writeNumberField("height", _height);
if (_size == null) {
gen.writeNullField("size");
} else {
gen.writeStringField("size", _size.name());
}
gen.writeEndObject();
}
}
public static class Content
{
private String _uri;
private String _title;
private int _width;
private int _height;
private String _format;
private long _duration;
private long _size;
private int _bitrate;
private String _copyright;
private Player _player;
private List<String> _persons;
public void write(JsonGenerator gen) throws IOException
{
gen.writeStartObject();
gen.writeStringField("uri", _uri);
gen.writeStringField("title", _title);
gen.writeNumberField("width", _width);
gen.writeNumberField("height", _height);
gen.writeStringField("format", _format);
gen.writeNumberField("duration", _duration);
gen.writeNumberField("size", _size);
gen.writeNumberField("bitrate", _bitrate);
gen.writeStringField("copyright", _copyright);
if (_player == null) {
gen.writeNullField("player");
} else {
gen.writeStringField("player", _player.name());
}
gen.writeFieldName("photos");
if (_persons == null) {
gen.writeNull();
} else {
gen.writeStartArray();
for (int i = 0, len = _persons.size(); i < len; ++i) {
gen.writeString(_persons.get(i));
}
gen.writeEndArray();
}
gen.writeEndObject();
}
public Content() { }
public void addPerson(String p) {
if (_persons == null) {
_persons = new ArrayList<String>();
}
_persons.add(p);
}
public Player getPlayer() { return _player; }
public String getUri() { return _uri; }
public String getTitle() { return _title; }
public int getWidth() { return _width; }
public int getHeight() { return _height; }
public String getFormat() { return _format; }
public long getDuration() { return _duration; }
public long getSize() { return _size; }
public int getBitrate() { return _bitrate; }
public List<String> getPersons() { return _persons; }
public String getCopyright() { return _copyright; }
public void setPlayer(Player p) { _player = p; }
public void setUri(String u) { _uri = u; }
public void setTitle(String t) { _title = t; }
public void setWidth(int w) { _width = w; }
public void setHeight(int h) { _height = h; }
public void setFormat(String f) { _format = f; }
public void setDuration(long d) { _duration = d; }
public void setSize(long s) { _size = s; }
public void setBitrate(int b) { _bitrate = b; }
public void setPersons(List<String> p) { _persons = p; }
public void setCopyright(String c) { _copyright = c; }
}
}