1 package org.apache.maven.archiva.common.rss;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
23 import java.io.FileWriter;
24 import java.io.IOException;
25 import java.io.Writer;
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.List;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.sun.syndication.feed.synd.SyndContent;
34 import com.sun.syndication.feed.synd.SyndContentImpl;
35 import com.sun.syndication.feed.synd.SyndEntry;
36 import com.sun.syndication.feed.synd.SyndEntryImpl;
37 import com.sun.syndication.feed.synd.SyndFeed;
38 import com.sun.syndication.feed.synd.SyndFeedImpl;
39 import com.sun.syndication.io.FeedException;
40 import com.sun.syndication.io.SyndFeedOutput;
43 * Generates RSS feeds.
45 * @plexus.component role="org.apache.maven.archiva.common.rss.RssFeedGenerator"
47 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
50 public class RssFeedGenerator
52 private Logger log = LoggerFactory.getLogger( RssFeedGenerator.class );
54 // TODO: make configurable
55 public static String DEFAULT_FEEDTYPE = "rss_2.0";
57 public static String DEFAULT_LANGUAGE = "en-us";
59 public void generateFeed( String title, String link, String description, List<RssFeedEntry> dataEntries,
62 SyndFeed feed = new SyndFeedImpl();
63 feed.setFeedType( DEFAULT_FEEDTYPE );
65 feed.setTitle( title );
67 feed.setDescription( description );
68 feed.setLanguage( DEFAULT_LANGUAGE );
69 feed.setPublishedDate( Calendar.getInstance().getTime() );
71 feed.setEntries( getEntries( dataEntries ) );
75 Writer writer = new FileWriter( outputFile );
76 SyndFeedOutput output = new SyndFeedOutput();
77 output.output( feed, writer );
80 catch ( IOException ie )
82 log.error( "Error occurred while generating the feed : " + ie.getMessage() );
84 catch ( FeedException fe )
86 log.error( "Error occurred while generating the feed : " + fe.getMessage() );
90 private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries )
92 List<SyndEntry> entries = new ArrayList<SyndEntry>();
94 SyndContent description;
96 for ( RssFeedEntry dataEntry : dataEntries )
98 entry = new SyndEntryImpl();
99 entry.setTitle( dataEntry.getTitle() );
100 entry.setLink( dataEntry.getLink() );
101 entry.setPublishedDate( Calendar.getInstance().getTime() );
103 description = new SyndContentImpl();
104 description.setType( "text/plain" );
105 description.setValue( dataEntry.getDescription() );
106 entry.setDescription( description );
108 entries.add( entry );