1 /* Copyright (2007) Schibsted Søk AS
2 * This file is part of SESAT.
3 *
4 * SESAT is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * SESAT is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /*
18 * SearchResultModuleParser.java
19 *
20 */
21
22 package no.sesat.search.view.output.syndication.modules;
23
24 import com.sun.syndication.feed.module.Module;
25 import com.sun.syndication.io.ModuleParser;
26 import org.jdom.Element;
27
28 /**
29 * A parser for the rome module defining the sesam syndication feed format.
30 */
31 public class SearchResultModuleParser implements ModuleParser {
32
33 /**
34 * Creates a new instance of this class.
35 */
36 public SearchResultModuleParser() {
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public String getNamespaceUri() {
43 return SearchResultModule.URI;
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public Module parse(final Element root) {
50
51 final SearchResultModule m = new SearchResultModuleImpl();
52
53 boolean touched = false;
54
55 final Element e = root.getChild(SearchResultModule.ELEM_NUMBER_OF_HITS, SearchResultModuleImpl.NS);
56
57 if (e != null) {
58 touched = true;
59 m.setNumberOfHits(e.getText());
60 }
61
62 final Element ageElem = root.getChild(SearchResultModule.ELEM_ARTICLE_AGE, SearchResultModuleImpl.NS);
63
64 if (ageElem != null) {
65 touched = true;
66 m.setArticleAge(e.getText());
67 }
68
69 final Element sourceElem = root.getChild(SearchResultModule.ELEM_NEWS_SOURCE, SearchResultModuleImpl.NS);
70
71 if (sourceElem != null) {
72 touched = true;
73 m.setNewsSource(e.getText());
74 }
75
76 return touched == true ? m : null;
77 }
78 }