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.IOException;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.abdera.model.Feed;
26 import org.springframework.extensions.surf.util.Content;
27 import org.springframework.extensions.surf.util.URLEncoder;
28 import org.springframework.extensions.webscripts.Format;
29 import org.springframework.extensions.webscripts.FormatReader;
30 import org.springframework.extensions.webscripts.WebScriptException;
31 import org.springframework.extensions.webscripts.WebScriptRequest;
32 import org.springframework.extensions.webscripts.WebScriptResponse;
33
34
35
36
37
38
39
40 public class AtomFeedReader implements FormatReader<Feed>
41 {
42
43 protected AbderaService abderaService;
44
45
46
47
48
49
50 public void setAbderaService(AbderaService abderaService)
51 {
52 this.abderaService = abderaService;
53 }
54
55
56
57
58 public Class<Feed> getDestinationClass()
59 {
60 return Feed.class;
61 }
62
63
64
65
66 public String getSourceMimetype()
67 {
68 return Format.ATOMFEED.mimetype();
69 }
70
71
72
73
74 public Feed read(WebScriptRequest req)
75 {
76 Content content = req.getContent();
77 if (content == null)
78 {
79 throw new WebScriptException("Failed to convert request to Atom Feed");
80 }
81 try
82 {
83 return abderaService.parseFeed(content.getReader(), req.getServerPath() + URLEncoder.encodeUri(req.getServicePath()));
84 }
85 catch (IOException e)
86 {
87 throw new WebScriptException("Failed to convert request to Atom Feed", e);
88 }
89 }
90
91
92
93
94 public Map<String, Object> createScriptParameters(WebScriptRequest req, WebScriptResponse res)
95 {
96 Map<String, Object> params = new HashMap<String, Object>();
97 params.put("feed", read(req));
98 return params;
99 }
100 }