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 java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Date;
25 import java.util.List;
28 import com.sun.syndication.feed.synd.SyndFeed;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
30 import org.apache.archiva.metadata.repository.MetadataResolverException;
31 import org.apache.archiva.rss.RssFeedEntry;
32 import org.apache.archiva.rss.RssFeedGenerator;
35 * Retrieve and process new versions of an artifact from the database and
36 * generate a rss feed. The versions will be grouped by the date when the artifact
37 * was gathered. Each group will appear as one entry in the feed.
39 * @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-versions"
41 public class NewVersionsOfArtifactRssFeedProcessor
42 extends AbstractArtifactsRssFeedProcessor
44 private static final String title = "New Versions of Artifact ";
46 private static final String desc = "These are the new versions of artifact ";
51 private RssFeedGenerator generator;
54 * Process all versions of the artifact which had a rss feed request.
56 public SyndFeed process( Map<String, String> reqParams )
57 throws MetadataResolverException
59 String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
60 String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
62 if ( groupId != null && artifactId != null )
64 return processNewVersionsOfArtifact( groupId, artifactId );
70 private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId )
71 throws MetadataResolverException
73 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
74 for ( String repoId : metadataRepository.getRepositories() )
76 Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
77 for ( String version : versions )
79 artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
84 RssFeedEntry entry = null;
85 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
86 String description = "";
88 for ( ArtifactMetadata artifact : artifacts )
90 long whenGathered = artifact.getWhenGathered().getTime();
92 if ( tmp != whenGathered )
96 entry.setDescription( description );
101 entry = new RssFeedEntry(
102 this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
103 entry.setPublishedDate( artifact.getWhenGathered() );
105 this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
110 description = description + artifact.getId() + " | ";
113 if ( idx == ( artifacts.size() - 1 ) )
115 entry.setDescription( description );
116 entries.add( entry );
123 String key = groupId + ":" + artifactId;
125 return generator.generateFeed( getTitle() + "\'" + key + "\'",
126 "New versions of artifact " + "\'" + key + "\' found during repository scan.",
130 public String getTitle()
135 public String getDescription()
140 public RssFeedGenerator getGenerator()
145 public void setGenerator( RssFeedGenerator generator )
147 this.generator = generator;