1 package org.apache.maven.archiva.web.util;
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 org.apache.archiva.metadata.model.Dependency;
23 import org.apache.archiva.metadata.model.License;
24 import org.apache.archiva.metadata.model.MailingList;
25 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
26 import org.apache.commons.lang.StringUtils;
28 import java.util.List;
31 * ProjectMetadataDisplayUtil
35 public class ProjectMetadataDisplayUtil
37 private StringBuilder metadataEntries;
39 public String formatProjectMetadata( ProjectVersionMetadata projectMetadata )
41 metadataEntries = new StringBuilder();
45 addListItem( "project.metadata.id=", projectMetadata.getId() );
46 addListItem( "project.url=", projectMetadata.getUrl() );
47 addListItem( "project.name=", projectMetadata.getName() );
48 addListItem( "project.description=", projectMetadata.getDescription() );
50 startListItem( "organization" );
51 if ( projectMetadata.getOrganization() != null )
54 addListItem( "organization.name=", projectMetadata.getOrganization().getName() );
55 addListItem( "organization.url=", projectMetadata.getOrganization().getUrl() );
60 startListItem( "issueManagement" );
61 if ( projectMetadata.getIssueManagement() != null )
64 addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem() );
65 addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl() );
70 startListItem( "scm" );
71 if ( projectMetadata.getScm() != null )
74 addListItem( "scm.url=", projectMetadata.getScm().getUrl() );
75 addListItem( "scm.connection=", projectMetadata.getScm().getConnection() );
76 addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection() );
81 startListItem( "ciManagement" );
82 if ( projectMetadata.getCiManagement() != null )
85 addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem() );
86 addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl() );
91 startListItem( "licenses" );
92 if ( projectMetadata.getLicenses() != null )
94 List<License> licenses = projectMetadata.getLicenses();
97 for ( License license : licenses )
99 addListItem( "licenses." + ctr + ".name=", license.getName() );
100 addListItem( "licenses." + ctr + ".url=", license.getUrl() );
107 startListItem( "mailingLists" );
108 if ( projectMetadata.getMailingLists() != null )
110 List<MailingList> lists = projectMetadata.getMailingLists();
111 List<String> otherArchives;
116 for ( MailingList list : lists )
118 addListItem( "mailingLists." + ctr + ".name=", list.getName() );
119 addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl() );
120 addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress() );
121 addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress() );
122 addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress() );
123 startListItem( "mailingLists." + ctr + ".otherArchives" );
125 if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 )
128 otherArchives = list.getOtherArchives();
131 for ( String archive : otherArchives )
133 addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive );
134 metadataEntries.append( archive );
146 startListItem( "dependencies" );
147 if ( projectMetadata.getDependencies() != null )
149 List<Dependency> dependencies = projectMetadata.getDependencies();
153 for ( Dependency dependency : dependencies )
155 addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId() );
156 addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId() );
157 addListItem( "dependency." + ctr + ".version=", dependency.getVersion() );
158 addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier() );
159 addListItem( "dependency." + ctr + ".type=", dependency.getType() );
160 addListItem( "dependency." + ctr + ".scope=", dependency.getScope() );
161 addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath() );
170 return metadataEntries.toString();
173 private void startList()
175 metadataEntries.append( "\n<ul>" );
178 private void endList()
180 metadataEntries.append( "\n</ul>" );
183 private void addListItem( String label, String value )
185 String newValue = StringUtils.isEmpty( value ) ? "" : value;
186 metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
189 private void startListItem( String value )
191 metadataEntries.append( "\n<li>" ).append( value );
194 private void endListItem()
196 metadataEntries.append( "\n</li>" );