001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.portals.applications.rss;
018:
019: import java.io.IOException;
020: import java.net.URL;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletConfig;
025: import javax.portlet.PortletException;
026: import javax.portlet.PortletPreferences;
027: import javax.portlet.RenderRequest;
028: import javax.portlet.RenderResponse;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
033:
034: import org.apache.velocity.context.Context;
035:
036: import com.sun.syndication.feed.synd.SyndFeed;
037: import com.sun.syndication.io.SyndFeedInput;
038: import com.sun.syndication.io.XmlReader;
039:
040: /**
041: * Rome RSS Portlet
042: *
043: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
044: * @version $Id: RomeRSSPortlet.java 516448 2007-03-09 16:25:47Z ate $
045: */
046: public class RomeRSSPortlet extends GenericVelocityPortlet {
047:
048: protected Log log = LogFactory.getLog(RomeRSSPortlet.class);
049:
050: /**
051: * @see javax.portlet.Portlet#init(javax.portlet.PortletConfig)
052: */
053: public void init(PortletConfig config) throws PortletException {
054: super .init(config);
055:
056: }
057:
058: /**
059: * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
060: */
061: public void doView(RenderRequest request, RenderResponse response)
062: throws PortletException, IOException {
063:
064: response.setContentType("text/html");
065: Context velocityContext = this .getContext(request);
066: PortletPreferences prefs = request.getPreferences();
067: String url = prefs.getValue("url",
068: "http://www.npr.org/rss/rss.php?topicId=4");
069: try {
070: URL feedUrl = new URL(url);
071: SyndFeedInput input = new SyndFeedInput();
072:
073: SyndFeed feed = input.build(new XmlReader(feedUrl));
074:
075: RssInfo rssInfo = new RssInfo(feed, new Integer(prefs
076: .getValue("itemdisplayed", "15")).intValue(),
077: new Boolean(prefs.getValue("openinpopup", "true"))
078: .booleanValue(), new Boolean(prefs
079: .getValue("showdescription", "true"))
080: .booleanValue(), new Boolean(prefs
081: .getValue("showtitle", "true"))
082: .booleanValue(), new Boolean(prefs
083: .getValue("showtextinput", "true"))
084: .booleanValue());
085: if (feed.getTitle() != null)
086: response.setTitle(feed.getTitle());
087: velocityContext.put("rssInfo", rssInfo);
088:
089: super .doView(request, response);
090:
091: } catch (Exception e) {
092: throw new PortletException(new String(
093: "Failed to process RSS Feed: " + url + ", " + e));
094: }
095:
096: }
097:
098: /**
099: *
100: * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
101: */
102: public void doEdit(RenderRequest request, RenderResponse response)
103: throws PortletException, IOException {
104: response.setContentType("text/html");
105: doPreferencesEdit(request, response);
106: }
107:
108: /**
109: *
110: * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
111: */
112: public void processAction(ActionRequest request,
113: ActionResponse actionResponse) throws PortletException,
114: java.io.IOException {
115: String add = request.getParameter("Save");
116: if (add != null) {
117: processPreferencesAction(request, actionResponse);
118: }
119: }
120:
121: }
|