1 package org.apache.archiva.rss.processor;
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
22 import com.sun.syndication.feed.synd.SyndFeed;
23 import com.sun.syndication.io.FeedException;
24 import org.apache.archiva.metadata.model.ArtifactMetadata;
25 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
26 import org.apache.archiva.metadata.repository.MetadataResolutionException;
27 import org.apache.archiva.rss.RssFeedEntry;
28 import org.apache.archiva.rss.RssFeedGenerator;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Date;
35 import java.util.List;
39 * Retrieve and process new versions of an artifact from the database and
40 * generate a rss feed. The versions will be grouped by the date when the artifact
41 * was gathered. Each group will appear as one entry in the feed.
43 * @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-versions"
45 public class NewVersionsOfArtifactRssFeedProcessor
46 extends AbstractArtifactsRssFeedProcessor
48 private Logger log = LoggerFactory.getLogger( NewVersionsOfArtifactRssFeedProcessor.class );
50 private static final String title = "New Versions of Artifact ";
52 private static final String desc = "These are the new versions of artifact ";
57 private RssFeedGenerator generator;
60 * Process all versions of the artifact which had a rss feed request.
62 public SyndFeed process( Map<String, String> reqParams )
65 String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
66 String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
68 if ( groupId != null && artifactId != null )
70 return processNewVersionsOfArtifact( groupId, artifactId );
76 private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId )
79 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
82 for ( String repoId : metadataRepository.getRepositories() )
84 Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
85 for ( String version : versions )
87 artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
91 catch ( MetadataRepositoryException e )
93 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
96 catch ( MetadataResolutionException e )
98 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
103 RssFeedEntry entry = null;
104 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
105 String description = "";
107 for ( ArtifactMetadata artifact : artifacts )
109 long whenGathered = artifact.getWhenGathered().getTime();
111 if ( tmp != whenGathered )
115 entry.setDescription( description );
116 entries.add( entry );
120 entry = new RssFeedEntry(
121 this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
122 entry.setPublishedDate( artifact.getWhenGathered() );
124 this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
129 description = description + artifact.getId() + " | ";
132 if ( idx == ( artifacts.size() - 1 ) )
134 entry.setDescription( description );
135 entries.add( entry );
142 String key = groupId + ":" + artifactId;
144 return generator.generateFeed( getTitle() + "\'" + key + "\'",
145 "New versions of artifact " + "\'" + key + "\' found during repository scan.",
149 public String getTitle()
154 public String getDescription()
159 public RssFeedGenerator getGenerator()
164 public void setGenerator( RssFeedGenerator generator )
166 this.generator = generator;