1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.samples.module;
18
19 import com.sun.syndication.feed.module.Module;
20 import com.sun.syndication.io.ModuleParser;
21 import com.sun.syndication.io.WireFeedParser;
22 import com.sun.syndication.io.impl.DateParser;
23 import org.jdom.Element;
24 import org.jdom.Namespace;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 /***
30 * Parser for the Sample ModuleImpl.
31 * <p>
32 * @author Alejandro Abdelnur
33 */
34 public class SampleModuleParser implements ModuleParser {
35 private static final Namespace SAMPLE_NS = Namespace.getNamespace("sample", SampleModule.URI);
36
37 public String getNamespaceUri() {
38 return SampleModule.URI;
39 }
40
41 public Module parse(Element dcRoot) {
42 boolean foundSomething = false;
43 SampleModule fm = new SampleModuleImpl();
44
45 Element e = dcRoot.getChild("bar", SAMPLE_NS);
46 if (e != null) {
47 foundSomething = true;
48 fm.setBar(e.getText());
49 }
50
51 List eList = dcRoot.getChildren("foo", SAMPLE_NS);
52 if (eList.size() > 0) {
53 foundSomething = true;
54 fm.setFoos(parseFoos(eList));
55 }
56 e = dcRoot.getChild("date", SAMPLE_NS);
57 if (e != null) {
58 foundSomething = true;
59 fm.setDate(DateParser.parseDate(e.getText()));
60 }
61 return (foundSomething) ? fm : null;
62 }
63
64 private List parseFoos(List eList) {
65 List foos = new ArrayList();
66 for (int i = 0; i < eList.size(); i++) {
67 Element e = (Element) eList.get(i);
68 foos.add(e.getText());
69 }
70 return foos;
71 }
72
73 }
74