1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts.atom;
20
21 import java.io.StringReader;
22 import java.util.Map;
23
24 import javax.xml.namespace.QName;
25
26 import org.apache.abdera.model.Content;
27 import org.apache.abdera.model.Element;
28 import org.apache.abdera.model.Entry;
29 import org.apache.abdera.model.Feed;
30 import org.apache.abdera.model.Service;
31 import org.apache.abdera.model.Content.Type;
32 import org.springframework.extensions.webscripts.Format;
33
34
35
36
37
38
39 public class AtomService
40 {
41 private AbderaService abderaService;
42
43
44
45
46
47
48 public void setAbderaService(AbderaService abderaService)
49 {
50 this.abderaService = abderaService;
51 }
52
53
54
55
56
57
58 public Feed createFeed()
59 {
60 return abderaService.createFeed();
61 }
62
63
64
65
66
67
68 public Entry createEntry()
69 {
70 return abderaService.createEntry();
71 }
72
73
74
75
76
77
78 public Map<String, QName> getNames()
79 {
80 return abderaService.getNames();
81 }
82
83
84
85
86
87
88
89
90 public QName createQName(String uri, String localName)
91 {
92 return new QName(uri, localName);
93 }
94
95
96
97
98
99
100
101 public String toMimeType(Entry entry)
102 {
103 if (entry == null || entry.getContentElement() == null)
104 {
105 return null;
106 }
107
108 Content content = entry.getContentElement();
109 String mimetype = (content.getMimeType() == null ? null : content.getMimeType().toString());
110 if (mimetype == null)
111 {
112 Content.Type type = content.getContentType();
113 if (type != null)
114 {
115 if (type == Type.HTML)
116 {
117 mimetype = Format.HTML.mimetype();
118 }
119 else if (type == Type.XHTML)
120 {
121 mimetype = Format.XHTML.mimetype();
122 }
123 else if (type == Type.TEXT)
124 {
125 mimetype = Format.TEXT.mimetype();
126 }
127 }
128 }
129 return mimetype;
130 }
131
132
133
134
135
136
137
138 public Element toAtom(org.springframework.extensions.surf.util.Content atom)
139 {
140 return abderaService.parse(atom.getInputStream(), null);
141 }
142
143
144
145
146
147
148
149 public Element toAtom(String atom)
150 {
151 return abderaService.parse(new StringReader(atom), null);
152 }
153
154
155
156
157
158
159
160 public Service toService(org.springframework.extensions.surf.util.Content entry)
161 {
162 return abderaService.parseService(entry.getInputStream(), null);
163 }
164
165
166
167
168
169
170
171 public Service toService(String entry)
172 {
173 return abderaService.parseService(new StringReader(entry), null);
174 }
175
176
177
178
179
180
181
182 public Entry toEntry(org.springframework.extensions.surf.util.Content entry)
183 {
184 return abderaService.parseEntry(entry.getInputStream(), null);
185 }
186
187
188
189
190
191
192
193 public Entry toEntry(String entry)
194 {
195 return abderaService.parseEntry(new StringReader(entry), null);
196 }
197
198
199
200
201
202
203
204 public Feed toFeed(org.springframework.extensions.surf.util.Content feed)
205 {
206 return abderaService.parseFeed(feed.getInputStream(), null);
207 }
208
209
210
211
212
213
214
215 public Feed toFeed(String feed)
216 {
217 return abderaService.parseFeed(new StringReader(feed), null);
218 }
219
220 }