BrightSide Workbench Full Report + Source Code
FeedMacro.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.feed;
19 
20 import com.sun.syndication.feed.synd.SyndFeed;
21 import com.sun.syndication.io.FeedException;
22 import com.sun.syndication.io.SyndFeedInput;
23 import com.sun.syndication.io.XmlReader;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.net.URL;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.context.IConstructor;
31 import org.turro.elephant.impl.util.Localizer;
32 import org.turro.marker.ElephantMarker;
33 
38 public class FeedMacro {
39 
40  public static void writeFeed(IConstructor constructor, String feeds) {
41  PrintWriter out = null;
42  try {
43  Localizer localizer = constructor.getLocalizer();
44  out = constructor.getOut();
45  String[] url = feeds.split(",");
46  SyndFeedInput input = new SyndFeedInput();
47  SyndFeed feed;
48  out.print("<div class='rssreader'>");
49  for (int i = 0; i < url.length; i++) {
50  feed = input.build(new XmlReader(new URL(url[i])));
51  renderFeed(feed, constructor);
52  }
53  out.print("</div>");
54  } catch (IllegalArgumentException ex) {
55  Logger.getLogger(FeedMacro.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
56  } catch (FeedException ex) {
57  Logger.getLogger(FeedMacro.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
58  } catch (IOException ex) {
59  Logger.getLogger(FeedMacro.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
60  }
61  }
62 
63  private static void renderFeed(SyndFeed feed, IConstructor constructor) {
64  ElephantMarker marker = new ElephantMarker(constructor);
65  marker.put("feed", feed);
66  marker.process("rss", "feed");
67  }
68 
69  private FeedMacro() {
70  }
71 }
static void writeFeed(IConstructor constructor, String feeds)
Definition: FeedMacro.java:40
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)