1 package yarfraw.mapping.backward.impl;
2 import static yarfraw.mapping.backward.impl.Atom03MappingUtils.getElements;
3 import static yarfraw.mapping.backward.impl.Atom03MappingUtils.toGenerator;
4 import static yarfraw.mapping.backward.impl.Atom03MappingUtils.toItemEntry;
5 import static yarfraw.mapping.backward.impl.Atom03MappingUtils.toLink;
6 import static yarfraw.mapping.backward.impl.Atom03MappingUtils.toPerson;
7 import yarfraw.core.datamodel.ChannelFeed;
8 import yarfraw.generated.atom03.elements.EntryType;
9 import yarfraw.generated.atom03.elements.FeedType;
10 import yarfraw.generated.atom03.elements.LinkType;
11 import yarfraw.generated.atom03.elements.PersonType;
12 import yarfraw.mapping.backward.ToChannelAtom03;
13
14
15 /***
16 * TODO: document me
17 * @author jliang
18 *
19 */
20 public class ToChannelAtom03Impl implements ToChannelAtom03{
21
22 private static final ToChannelAtom03 _instance = new ToChannelAtom03Impl();
23
24 private ToChannelAtom03Impl() {}
25 public static ToChannelAtom03 getInstance(){
26 return _instance;
27 }
28
29 public ChannelFeed execute(FeedType feed){
30 if(feed == null){
31 return null;
32 }
33 ChannelFeed c = new ChannelFeed();
34 if(feed.getAuthor() != null){
35 c.addManagingEditorOrAuthorOrPublisher(toPerson(feed.getAuthor()));
36 }
37 if(feed.getContributor() != null){
38 for(PersonType p : feed.getContributor()){
39 c.addContributor(toPerson(p));
40 }
41 }
42
43 c.setRights(feed.getCopyright());
44
45 if(feed.getEntry() != null){
46 for(EntryType e : feed.getEntry()){
47 c.addItem(toItemEntry(e));
48 }
49 }
50
51
52 c.setGenerator(toGenerator(feed.getGenerator()));
53 if(feed.getId() != null){
54 c.setUid(feed.getId());
55 }
56
57
58 c.setLang(feed.getLang());
59
60 if(feed.getLink() != null){
61 for(LinkType l : feed.getLink()){
62 c.addLink(toLink(l));
63 }
64 }
65
66 c.setLastBuildOrUpdatedDate(feed.getModified());
67
68
69 if(feed.getOtherAttributes() != null){
70 c.getOtherAttributes().putAll(feed.getOtherAttributes());
71 }
72 c.getOtherElements().addAll(getElements(feed.getAny()));
73 return c;
74 }
75
76
77 }