taylor 2005/01/18 09:43:49 Modified: applications/rss/src/webapp/WEB-INF/view edit-prefs.vm applications/rss/src/webapp/WEB-INF portlet.xml applications/rss project.xml applications/rss/src/java/org/apache/portals/applications/rss RomeRSSPortlet.java Added: applications/rss/src/webapp/WEB-INF/view view.vm applications/rss/src/java/org/apache/portals/applications/rss RssInfo.java Log: http://issues.apache.org/jira/browse/JS2-191 completed implementation of Rome RSS portlet contributed by Christophe Lombart Revision Changes Path 1.3 +24 -1 jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/view/edit-prefs.vm Index: edit-prefs.vm =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/view/edit-prefs.vm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- edit-prefs.vm 15 Nov 2004 18:40:44 -0000 1.2 +++ edit-prefs.vm 18 Jan 2005 17:43:49 -0000 1.3 @@ -1,10 +1,33 @@ +#* +Copyright 2004 The Apache Software Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*# + +#** + [EMAIL PROTECTED] <a href="mailto:[EMAIL PROTECTED]">Christophe Lombart</a> [EMAIL PROTECTED] $Id$ + +*# <h2 class="portlet-section-header">Edit Preferences</h2> + <form action="$renderResponse.createActionURL()" method="post"> <table> #foreach ($pref in $prefs) -#prefField($pref.Key $pref.Value "40") + #prefField($pref.Key $pref.Value "40") #end </table> <input type="submit" name="Save" value="Save" /> 1.1 jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/view/view.vm Index: view.vm =================================================================== #* Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *# #** @author <a href="mailto:[EMAIL PROTECTED]">Christophe Lombart</a> @version $Id: view.vm,v 1.1 2005/01/18 17:43:49 taylor Exp $ *# #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale)) #set ($syncFeed = $rssInfo.getFeed()) #if ($rssInfo.isShowtitle()) $syncFeed.getTitle() #set ($feedImage = $syncFeed.getImage()) #if($feedImage) <a href="$feedImage.getLink()" #if($rssInfo.isOpeninpopup()) target="_blank" #end /> <img align="right" border ="0" #if($feedImage.getTitle()) != null) alt="$feedImage.getTitle()" #end #if($feedImage.getUrl()) != null) src="$feedImage.getUrl()" #end /> </a> #end #set ($syncEntries = $syncFeed.getEntries()) <ul> #foreach($syncEntry in $syncEntries) <li> <a href="$syncEntry.getLink()" #if($rssInfo.isOpeninpopup()) target="_blank" #end /> $syncEntry.getTitle() </a> #if($rssInfo.isShowdescription() && $syncEntry.getDescription().getValue()) <br> $syncEntry.getDescription().getValue() #end </li> #end </ul> #if($rssInfo.isShowtextinput()) <form action="$syncFeed.getLink()"> $syncFeed.getDescription() <br/> <input type="text" name="" value=""/> <input type="submit" name="submit" value="$syncFeed.getTitle()"/> </form> #end #end 1.2 +10 -6 jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/portlet.xml Index: portlet.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/portlet.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- portlet.xml 15 Nov 2004 06:06:41 -0000 1.1 +++ portlet.xml 18 Jan 2005 17:43:49 -0000 1.2 @@ -92,6 +92,14 @@ </portlet> <portlet id="RomeRSS"> + <init-param> + <name>AllowPreferences</name> + <value>true</value> + </init-param> + <init-param> + <name>ViewPage</name> + <value>/WEB-INF/view/view.vm</value> + </init-param> <init-param> <name>HelpPage</name> <value>/WEB-INF/view/rss-help.html</value> @@ -100,11 +108,7 @@ <name>EditPage</name> <value>/WEB-INF/view/edit-prefs.vm</value> </init-param> - <init-param> - <name>stylesheet</name> - <value>/WEB-INF/xsl/rss.xsl</value> - <description>Default RSS Transform XSLT</description> - </init-param> + <portlet-name>RomeRSS</portlet-name> <display-name>Rome RSS Portlet</display-name> <description>Rome RSS Portlet</description> @@ -151,7 +155,7 @@ </preference> <preference> <name>showtextinput</name> - <value>true</value> + <value>false</value> </preference> </portlet-preferences> </portlet> 1.3 +137 -146 jakarta-jetspeed-2/applications/rss/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/rss/project.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- project.xml 2 Dec 2004 05:22:12 -0000 1.2 +++ project.xml 18 Jan 2005 17:43:49 -0000 1.3 @@ -3,150 +3,141 @@ $Id$ --> <project> - <extend>${basedir}/./../project.xml</extend> - <id>rss</id> - <name>Jetspeed-2 Language Selector Portlet</name> - <description>Jetspeed-2 Language Selector Portlet</description> - <shortDescription>Language Selector Portlet</shortDescription> - - <repository> - <connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-jetspeed-2/applications/rss</connection> - <url>http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/applications/rss/</url> - </repository> - - <dependencies> - <dependency> - <id>portlet-api</id> - <groupId>portlet-api</groupId> - <version>1.0</version> - <properties> - <war.bundle>false</war.bundle> - </properties> - </dependency> - <dependency> - <id>servletapi</id> - <version>2.3</version> - <properties> - <war.bundle>false</war.bundle> - </properties> - </dependency> - - <dependency> - <id>springframework:spring-core</id> - <version>1.1.1</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <groupId>jdom</groupId> - <artifactId>jdom</artifactId> - <version>1.0</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <groupId>commons-digester</groupId> - <artifactId>commons-digester</artifactId> - <version>1.5</version> - <type>jar</type> - <url>http://jakarta.apache.org/commons/digester.html</url> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.6.1</version> - <type>jar</type> - <url>http://jakarta.apache.org/commons/beanutils.html</url> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - - <dependency> - <groupId>rome</groupId> - <artifactId>rome</artifactId> - <version>0.4</version> - <type>jar</type> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - - <dependency> - <groupId>portals-bridges</groupId> - <artifactId>portals-bridges-common</artifactId> - <version>0.1</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - - <dependency> - <id>velocity</id> - <version>1.4</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <id>velocity-tools</id> - <version>1.1</version> - <url>http://jakarta.apache.org/velocity</url> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <groupId>portals-bridges</groupId> - <artifactId>portals-bridges-velocity</artifactId> - <version>0.1</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - <dependency> - <id>xml-apis</id> - <version>2.0.2</version> - <properties> - <war.bundle.jar>true</war.bundle.jar> - </properties> - </dependency> - - - </dependencies> - - - <build> - <sourceDirectory>src/java</sourceDirectory> - <resources> - <resource> - <directory>${basedir}/src/java/</directory> - <includes> - <include>**/*.properties</include> - </includes> - </resource> - </resources> - </build> - - <reports> - <report>maven-jdepend-plugin</report> -<!-- + <extend>${basedir}/./../project.xml</extend> + <id>rss</id> + <name>Jetspeed-2 Language Selector Portlet</name> + <description>Jetspeed-2 Language Selector Portlet</description> + <shortDescription>Language Selector Portlet</shortDescription> + <repository> + <connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-jetspeed-2/applications/rss</connection> + <url>http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/applications/rss/</url> + </repository> + <dependencies> + <dependency> + <id>portlet-api</id> + <groupId>portlet-api</groupId> + <version>1.0</version> + <properties> + <war.bundle>false</war.bundle> + </properties> + </dependency> + <dependency> + <id>servletapi</id> + <version>2.3</version> + <properties> + <war.bundle>false</war.bundle> + </properties> + </dependency> + <dependency> + <id>springframework:spring-core</id> + <version>1.1.1</version> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <groupId>jdom</groupId> + <artifactId>jdom</artifactId> + <version>1.0</version> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <groupId>commons-digester</groupId> + <artifactId>commons-digester</artifactId> + <version>1.5</version> + <type>jar</type> + <url>http://jakarta.apache.org/commons/digester.html</url> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.6.1</version> + <type>jar</type> + <url>http://jakarta.apache.org/commons/beanutils.html</url> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <groupId>rome</groupId> + <artifactId>rome</artifactId> + <version>0.4</version> + <type>jar</type> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <id>xml-apis</id> + <version>2.0.2</version> + <properties> + <war.bundle.jar>true</war.bundle.jar> + </properties> + </dependency> + <dependency> + <groupId>portals-bridges</groupId> + <artifactId>portals-bridges-common</artifactId> + <version>0.1</version> + <type>jar</type> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <groupId>portals-bridges</groupId> + <artifactId>portals-bridges-velocity</artifactId> + <version>0.1</version> + <type>jar</type> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <id>velocity</id> + <version>1.4</version> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + <dependency> + <id>velocity-tools</id> + <version>1.1</version> + <url>http://jakarta.apache.org/velocity</url> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + </dependencies> + <build> + <sourceDirectory>src/java</sourceDirectory> + <resources> + <resource> + <directory>${basedir}/src/java/</directory> + <includes> + <include>**/*.properties</include> + </includes> + </resource> + </resources> + </build> + <reports> + <report>maven-jdepend-plugin</report> + <!-- <report>maven-checkstyle-plugin</report> --> - <report>maven-pmd-plugin</report> - <report>maven-changelog-plugin</report> - <report>maven-file-activity-plugin</report> - <report>maven-developer-activity-plugin</report> - <report>maven-license-plugin</report> - <report>maven-javadoc-plugin</report> - <report>maven-jxr-plugin</report> - <report>maven-junit-report-plugin</report> - <report>maven-linkcheck-plugin</report> - <report>maven-tasklist-plugin</report> - </reports> -</project> + <report>maven-pmd-plugin</report> + <report>maven-changelog-plugin</report> + <report>maven-file-activity-plugin</report> + <report>maven-developer-activity-plugin</report> + <report>maven-license-plugin</report> + <report>maven-javadoc-plugin</report> + <report>maven-jxr-plugin</report> + <report>maven-junit-report-plugin</report> + <report>maven-linkcheck-plugin</report> + <report>maven-tasklist-plugin</report> + </reports> +</project> \ No newline at end of file 1.3 +64 -62 jakarta-jetspeed-2/applications/rss/src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java Index: RomeRSSPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/rss/src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RomeRSSPortlet.java 19 Nov 2004 21:59:09 -0000 1.2 +++ RomeRSSPortlet.java 18 Jan 2005 17:43:49 -0000 1.3 @@ -15,26 +15,25 @@ */ package org.apache.portals.applications.rss; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; -import java.util.HashMap; -import java.util.Map; +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.PortletPreferences; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import org.apache.portals.applications.transform.TransformCacheEntry; -import org.apache.portals.applications.util.Streams; -import org.w3c.dom.Document; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.portals.bridges.velocity.GenericVelocityPortlet; + +import org.apache.velocity.context.Context; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.io.XmlReader; /** @@ -43,72 +42,75 @@ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a> * @version $Id$ */ -public class RomeRSSPortlet extends AbstractRssPortlet +public class RomeRSSPortlet extends GenericVelocityPortlet { + + protected Log log = LogFactory.getLog(RomeRSSPortlet.class); + + /** + * @see javax.portlet.Portlet#init(javax.portlet.PortletConfig) + */ public void init(PortletConfig config) throws PortletException { super.init(config); + } - - /* - * (non-Javadoc) - * - * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, - * javax.portlet.RenderResponse) + + /** + * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse) */ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); - - PortletPreferences prefs = request.getPreferences(); + Context velocityContext = this.getContext(request); + PortletPreferences prefs = request.getPreferences(); String url = prefs.getValue("url", "http://www.npr.org/rss/rss.php?topicId=4"); - String stylesheet = getPortletConfig().getInitParameter("stylesheet"); - String realStylesheet = getPortletConfig().getPortletContext().getRealPath(stylesheet); + try + { + URL feedUrl = new URL(url); + SyndFeedInput input = new SyndFeedInput(); + + SyndFeed feed = input.build(new XmlReader(feedUrl)); + + RssInfo rssInfo = new RssInfo(feed, new Integer(prefs.getValue("itemdisplayed", "15")).intValue(), new Boolean(prefs + .getValue("openinpopup", "true")).booleanValue(), new Boolean(prefs.getValue("showdescription", "true")) + .booleanValue(), new Boolean(prefs.getValue("showtitle", "true")).booleanValue(), new Boolean(prefs.getValue( + "showtextinput", "true")).booleanValue()); - URL xslt = getPortletConfig().getPortletContext().getResource(stylesheet); - - String key = cache.constructKey(url, stylesheet); // TODO: use the entire parameter list - TransformCacheEntry entry = cache.get(key); - if (entry != null) + velocityContext.put("rssInfo", rssInfo); + + super.doView(request, response); + + } + catch (Exception e) { - byte[] bytes = (byte[])entry.getDocument(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - Streams.drain(bais, response.getPortletOutputStream()); - bais.close(); + throw new PortletException(new String("Failed to process RSS Feed: " + url + ", " + e)); } - else - { - try - { - URL feedUrl = new URL(url); - SyndFeedInput input = new SyndFeedInput(); - SyndFeed feed = input.build(new XmlReader(feedUrl)); - SyndFeedOutput output = new SyndFeedOutput(); - //output.output(feed, response.getWriter()); - Document document = output.outputW3CDom(feed); - - Map parameters = new HashMap(); - - parameters.put("itemdisplayed", prefs.getValue("itemdisplayed", "15")); - parameters.put("openinpopup", prefs.getValue("openinpopup", "true")); - parameters.put("showdescription", prefs.getValue("showdescription", "true")); - parameters.put("showtitle", prefs.getValue("showtitle", "true")); - parameters.put("showtextinput", prefs.getValue("showtextinput", "true")); - - - // TODO: don't use a transform, instead use Velocity template and populate via Rome model - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - transform.transform(realStylesheet, document, baos, parameters); - byte[] bytes = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - Streams.drain(bais, response.getPortletOutputStream()); - cache.put(key, bytes, 15); - } - catch (Exception e) - { - response.getPortletOutputStream().write(new String("Failed to process RSS Feed: " + url + ", " + e).getBytes()); - } + + } + + /** + * + * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse) + */ + public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + response.setContentType("text/html"); + doPreferencesEdit(request, response); + } + + /** + * + * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse) + */ + public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, java.io.IOException + { + String add = request.getParameter("Save"); + if (add != null) + { + processPreferencesAction(request, actionResponse); } } + } 1.1 jakarta-jetspeed-2/applications/rss/src/java/org/apache/portals/applications/rss/RssInfo.java Index: RssInfo.java =================================================================== /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.portals.applications.rss; import com.sun.syndication.feed.synd.SyndFeed; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Lombart Christophe </a> * @version $Id: RssInfo.java,v 1.1 2005/01/18 17:43:49 taylor Exp $ */ public class RssInfo { private SyndFeed feed; private int itemdisplayed; private boolean openinpopup; private boolean showdescription; private boolean showtitle; private boolean showtextinput; /** * @param feed * @param itemdisplayed * @param openinpopup * @param showdescription * @param showtitle * @param showtextinput */ public RssInfo(SyndFeed feed, int itemdisplayed, boolean openinpopup, boolean showdescription, boolean showtitle, boolean showtextinput) { this.feed = feed; this.itemdisplayed = itemdisplayed; this.openinpopup = openinpopup; this.showdescription = showdescription; this.showtitle = showtitle; this.showtextinput = showtextinput; } public SyndFeed getFeed() { return feed; } public void setFeed(SyndFeed feed) { this.feed = feed; } public int getItemdisplayed() { return itemdisplayed; } public void setItemdisplayed(int itemdisplayed) { this.itemdisplayed = itemdisplayed; } public boolean isOpeninpopup() { return openinpopup; } public void setOpeninpopup(boolean openinpopup) { this.openinpopup = openinpopup; } public boolean isShowdescription() { return showdescription; } public void setShowdescription(boolean showdescription) { this.showdescription = showdescription; } public boolean isShowtextinput() { return showtextinput; } public void setShowtextinput(boolean showtextinput) { this.showtextinput = showtextinput; } public boolean isShowtitle() { return showtitle; } public void setShowtitle(boolean showtitle) { this.showtitle = showtitle; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]