From 4aa6c9bab02fbdc90f23cbf7b8b324546f8213b4 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 25 Jul 2008 10:47:53 +0000 Subject: [PATCH] [MRM-883] -do not generate feed if there are no information available -return 204 if no information/update available git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@679754 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/archiva/rss/RssFeedGenerator.java | 12 +++++++----- .../org/apache/archiva/rss/RssFeedGeneratorTest.java | 10 ++++++++++ .../apache/maven/archiva/web/rss/RssFeedServlet.java | 10 ++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java index 2bff45def..4b05a36fc 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java @@ -50,14 +50,16 @@ public class RssFeedGenerator public static String DEFAULT_LANGUAGE = "en-us"; - //private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/"; - public SyndFeed generateFeed( String title, String description, List dataEntries ) { + if( dataEntries.size() == 0 ) + { + log.debug( "No updates found, feed not generated." ); + return null; + } + SyndFeed feed = new SyndFeedImpl(); - - feed.setTitle( title ); - //feed.setLink( DEFAULT_LINK + queryString ); + feed.setTitle( title ); feed.setDescription( description ); feed.setLanguage( DEFAULT_LANGUAGE ); feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java index 0c8287be0..356177ef8 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java @@ -81,6 +81,16 @@ public class RssFeedGeneratorTest assertEquals( "Item 2", syndEntries.get( 1 ).getTitle() ); assertEquals( "Item 3", syndEntries.get( 2 ).getTitle() ); } + + public void testNoDataEntries() + throws Exception + { + List entries = new ArrayList(); + SyndFeed feed = + generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries ); + + assertNull( feed ); + } /* * this test might need to be removed since diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java index 267c8137e..caedf31bf 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java @@ -149,9 +149,15 @@ public class RssFeedServlet return; } - feed = processor.process( map ); + feed = processor.process( map ); + if( feed == null ) + { + res.sendError( HttpServletResponse.SC_NO_CONTENT, "No information available." ); + return; + } + res.setContentType( MIME_TYPE ); - + if ( repoId != null ) { feed.setLink( req.getRequestURL() + "?repoId=" + repoId ); -- 2.39.5