1 package org.apache.maven.archiva.web.tags;
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.io.IOException;
23 import java.util.List;
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.TagSupport;
28 import org.apache.archiva.metadata.model.Dependency;
29 import org.apache.archiva.metadata.model.License;
30 import org.apache.archiva.metadata.model.MailingList;
31 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
32 import org.apache.commons.lang.StringUtils;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
39 * Outputs the project metadata attributes, used in the Metadata tab in artifact browse.
41 @SuppressWarnings( "serial" )
42 public class ProjectMetadataTag
45 private Logger log = LoggerFactory.getLogger( ProjectMetadataTag.class );
47 private Object object;
57 public int doStartTag()
60 StringBuffer buf = new StringBuffer();
64 buf.append( "Error generating project metadata." );
65 log.error( "Unable to generate project metadata for null object." );
67 else if ( object instanceof ProjectVersionMetadata )
69 ProjectVersionMetadata metadata = (ProjectVersionMetadata) object;
71 buildProjectMetadata( buf, metadata );
75 buf.append( "Unable to generate project metadata for object " ).append( object.getClass().getName() );
78 out( buf.toString() );
80 return EVAL_BODY_INCLUDE;
83 private void out( String msg )
88 pageContext.getOut().print( msg );
90 catch ( IOException e )
92 throw new JspException( "Unable to output to jsp page context." );
96 private void buildProjectMetadata( StringBuffer metadataEntries, ProjectVersionMetadata projectMetadata )
98 startList( metadataEntries );
100 addListItem( "project.metadata.id=", projectMetadata.getId(), metadataEntries );
101 addListItem( "project.url=", projectMetadata.getUrl(), metadataEntries );
102 addListItem( "project.name=", projectMetadata.getName(), metadataEntries );
103 addListItem( "project.description=", projectMetadata.getDescription(), metadataEntries );
105 if ( projectMetadata.getOrganization() != null )
107 startListItem( "organization", metadataEntries );
108 startList( metadataEntries );
109 addListItem( "organization.name=", projectMetadata.getOrganization().getName(), metadataEntries );
110 addListItem( "organization.url=", projectMetadata.getOrganization().getUrl(), metadataEntries );
111 endList( metadataEntries );
112 endListItem( metadataEntries );
115 if ( projectMetadata.getIssueManagement() != null )
117 startListItem( "issueManagement", metadataEntries );
118 startList( metadataEntries );
119 addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem(), metadataEntries );
120 addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl(), metadataEntries );
121 endList( metadataEntries );
122 endListItem( metadataEntries );
125 if ( projectMetadata.getScm() != null )
127 startListItem( "scm", metadataEntries );
128 startList( metadataEntries );
129 addListItem( "scm.url=", projectMetadata.getScm().getUrl(), metadataEntries );
130 addListItem( "scm.connection=", projectMetadata.getScm().getConnection(), metadataEntries );
131 addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection(),
133 endList( metadataEntries );
134 endListItem( metadataEntries );
137 if ( projectMetadata.getCiManagement() != null )
139 startListItem( "ciManagement", metadataEntries );
140 startList( metadataEntries );
141 addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem(), metadataEntries );
142 addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl(), metadataEntries );
143 endList( metadataEntries );
144 endListItem( metadataEntries );
147 if ( projectMetadata.getLicenses() != null && !projectMetadata.getLicenses().isEmpty() )
149 startListItem( "licenses", metadataEntries );
150 List<License> licenses = projectMetadata.getLicenses();
152 startList( metadataEntries );
153 for ( License license : licenses )
155 addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries );
156 addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries );
159 endList( metadataEntries );
160 endListItem( metadataEntries );
163 if ( projectMetadata.getMailingLists() != null && !projectMetadata.getMailingLists().isEmpty() )
165 startListItem( "mailingLists", metadataEntries );
166 List<MailingList> lists = projectMetadata.getMailingLists();
167 List<String> otherArchives;
171 startList( metadataEntries );
172 for ( MailingList list : lists )
174 addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries );
175 addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries );
176 addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries );
177 addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress(), metadataEntries );
178 addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress(), metadataEntries );
179 startListItem( "mailingLists." + ctr + ".otherArchives", metadataEntries );
181 if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 )
184 otherArchives = list.getOtherArchives();
186 startList( metadataEntries );
187 for ( String archive : otherArchives )
189 addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive,
191 metadataEntries.append( archive );
194 endList( metadataEntries );
196 endListItem( metadataEntries );
199 endList( metadataEntries );
200 endListItem( metadataEntries );
203 if ( projectMetadata.getDependencies() != null && !projectMetadata.getDependencies().isEmpty() )
205 startListItem( "dependencies", metadataEntries );
206 List<Dependency> dependencies = projectMetadata.getDependencies();
209 startList( metadataEntries );
210 for ( Dependency dependency : dependencies )
212 addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries );
213 addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries );
214 addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries );
215 addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier(), metadataEntries );
216 addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries );
217 addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries );
218 addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries );
221 endList( metadataEntries );
222 endListItem( metadataEntries );
225 endList( metadataEntries );
228 private void startList( StringBuffer metadataEntries )
230 metadataEntries.append( "\n<ul>" );
233 private void endList( StringBuffer metadataEntries )
235 metadataEntries.append( "\n</ul>" );
238 private void addListItem( String label, String value, StringBuffer metadataEntries )
240 String newValue = StringUtils.isEmpty( value ) ? "" : value;
241 metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
244 private void startListItem( String value, StringBuffer metadataEntries )
246 metadataEntries.append( "\n<li>" ).append( value );
249 private void endListItem( StringBuffer metadataEntries )
251 metadataEntries.append( "\n</li>" );
254 public void setObject( Object object )
256 this.object = object;