Coverage Report - org.apache.archiva.rss.RssFeedGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
RssFeedGenerator
0%
0/27
0%
0/4
0
 
 1  
 package org.apache.archiva.rss;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.slf4j.Logger;
 26  
 import org.slf4j.LoggerFactory;
 27  
 
 28  
 import com.sun.syndication.feed.synd.SyndContent;
 29  
 import com.sun.syndication.feed.synd.SyndContentImpl;
 30  
 import com.sun.syndication.feed.synd.SyndEntry;
 31  
 import com.sun.syndication.feed.synd.SyndEntryImpl;
 32  
 import com.sun.syndication.feed.synd.SyndFeed;
 33  
 import com.sun.syndication.feed.synd.SyndFeedImpl;
 34  
 
 35  
 /**
 36  
  * Generates RSS feeds.
 37  
  * 
 38  
  * @plexus.component role="org.apache.archiva.rss.RssFeedGenerator" 
 39  
  *      instantiation-strategy="per-lookup"
 40  
  * 
 41  
  * @version
 42  
  */
 43  0
 public class RssFeedGenerator
 44  
 {
 45  0
     private Logger log = LoggerFactory.getLogger( RssFeedGenerator.class );
 46  
 
 47  
     // TODO: make configurable
 48  0
     public static String DEFAULT_FEEDTYPE = "rss_2.0";
 49  
 
 50  0
     public static String DEFAULT_LANGUAGE = "en-us";
 51  
 
 52  
     public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries )
 53  
     {
 54  0
         if( dataEntries.size() ==  0 )
 55  
         {
 56  0
             log.debug( "No updates found, feed not generated." );
 57  0
             return null;
 58  
         }
 59  
         
 60  0
         SyndFeed feed = new SyndFeedImpl();
 61  0
         feed.setTitle( title );        
 62  0
         feed.setDescription( description );
 63  0
         feed.setLanguage( DEFAULT_LANGUAGE );
 64  0
         feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() );
 65  0
         feed.setFeedType( DEFAULT_FEEDTYPE );
 66  0
         feed.setEntries( getEntries( dataEntries ) );
 67  
 
 68  0
         log.debug( "Finished generating the feed \'" + title + "\'." );
 69  
         
 70  0
         return feed;
 71  
     }
 72  
 
 73  
     private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries )
 74  
     {
 75  0
         List<SyndEntry> entries = new ArrayList<SyndEntry>();
 76  
 
 77  
         SyndEntry entry;
 78  
         SyndContent description;
 79  
 
 80  0
         for ( RssFeedEntry dataEntry : dataEntries )
 81  
         {
 82  0
             entry = new SyndEntryImpl();
 83  0
             entry.setTitle( dataEntry.getTitle() );
 84  0
             entry.setPublishedDate( dataEntry.getPublishedDate() );
 85  
 
 86  0
             description = new SyndContentImpl();
 87  0
             description.setType( "text/plain" );
 88  0
             description.setValue( dataEntry.getDescription() );
 89  0
             entry.setDescription( description );
 90  
 
 91  0
             entries.add( entry );
 92  
         }
 93  
 
 94  0
         return entries;
 95  
     }
 96  
 }