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;
49 private String groupId;
51 private String artifactId;
53 private String version;
63 public int doStartTag()
66 StringBuffer buf = new StringBuffer();
70 buf.append( "Error generating project metadata." );
71 log.error( "Unable to generate project metadata for null object." );
73 else if ( object instanceof ProjectVersionMetadata )
75 ProjectVersionMetadata metadata = (ProjectVersionMetadata) object;
77 buildProjectMetadata( buf, metadata );
81 buf.append( "Unable to generate project metadata for object " ).append( object.getClass().getName() );
84 out( buf.toString() );
86 return EVAL_BODY_INCLUDE;
89 private void out( String msg )
94 pageContext.getOut().print( msg );
96 catch ( IOException e )
98 throw new JspException( "Unable to output to jsp page context." );
102 private void buildProjectMetadata( StringBuffer metadataEntries, ProjectVersionMetadata projectMetadata )
104 startList( metadataEntries );
106 addListItem( "project.metadata.id=", projectMetadata.getId(), metadataEntries );
107 addListItem( "project.url=", projectMetadata.getUrl(), metadataEntries );
108 addListItem( "project.name=", projectMetadata.getName(), metadataEntries );
109 addListItem( "project.description=", projectMetadata.getDescription(), metadataEntries );
111 if ( projectMetadata.getOrganization() != null )
113 startListItem( "organization", metadataEntries );
114 startList( metadataEntries );
115 addListItem( "organization.name=", projectMetadata.getOrganization().getName(), metadataEntries );
116 addListItem( "organization.url=", projectMetadata.getOrganization().getUrl(), metadataEntries );
117 endList( metadataEntries );
118 endListItem( metadataEntries );
121 if ( projectMetadata.getIssueManagement() != null )
123 startListItem( "issueManagement", metadataEntries );
124 startList( metadataEntries );
125 addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem(), metadataEntries );
126 addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl(), metadataEntries );
127 endList( metadataEntries );
128 endListItem( metadataEntries );
131 if ( projectMetadata.getScm() != null )
133 startListItem( "scm", metadataEntries );
134 startList( metadataEntries );
135 addListItem( "scm.url=", projectMetadata.getScm().getUrl(), metadataEntries );
136 addListItem( "scm.connection=", projectMetadata.getScm().getConnection(), metadataEntries );
137 addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection(),
139 endList( metadataEntries );
140 endListItem( metadataEntries );
143 if ( projectMetadata.getCiManagement() != null )
145 startListItem( "ciManagement", metadataEntries );
146 startList( metadataEntries );
147 addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem(), metadataEntries );
148 addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl(), metadataEntries );
149 endList( metadataEntries );
150 endListItem( metadataEntries );
153 if ( projectMetadata.getLicenses() != null && !projectMetadata.getLicenses().isEmpty() )
155 startListItem( "licenses", metadataEntries );
156 List<License> licenses = projectMetadata.getLicenses();
158 startList( metadataEntries );
159 for ( License license : licenses )
161 createDeleteLink( "license", license.getName(), metadataEntries );
162 startList( metadataEntries );
163 addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries );
164 addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries );
165 endList( metadataEntries );
166 endListItem( metadataEntries );
169 endList( metadataEntries );
170 endListItem( metadataEntries );
173 if ( projectMetadata.getMailingLists() != null && !projectMetadata.getMailingLists().isEmpty() )
175 startListItem( "mailingLists", metadataEntries );
176 List<MailingList> lists = projectMetadata.getMailingLists();
177 List<String> otherArchives;
181 startList( metadataEntries );
182 for ( MailingList list : lists )
184 createDeleteLink( "mailingList", list.getName(), metadataEntries );
185 startList( metadataEntries );
186 addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries );
187 addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries );
188 addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries );
189 addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress(), metadataEntries );
190 addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress(), metadataEntries );
191 startListItem( "mailingLists." + ctr + ".otherArchives", metadataEntries );
193 if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 )
196 otherArchives = list.getOtherArchives();
198 startList( metadataEntries );
199 for ( String archive : otherArchives )
201 addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive,
203 metadataEntries.append( archive );
206 endList( metadataEntries );
208 endListItem( metadataEntries );
209 endList( metadataEntries );
210 endListItem( metadataEntries );
213 endList( metadataEntries );
214 endListItem( metadataEntries );
217 if ( projectMetadata.getDependencies() != null && !projectMetadata.getDependencies().isEmpty() )
219 startListItem( "dependencies", metadataEntries );
220 List<Dependency> dependencies = projectMetadata.getDependencies();
223 startList( metadataEntries );
225 for ( Dependency dependency : dependencies )
227 createDeleteLink( "dependency", dependency.getArtifactId(), metadataEntries );
228 startList( metadataEntries );
229 addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries );
230 addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries );
231 addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries );
232 addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier(), metadataEntries );
233 addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries );
234 addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries );
235 addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries );
236 endList( metadataEntries );
237 endListItem( metadataEntries );
240 endList( metadataEntries );
242 endListItem( metadataEntries );
245 endList( metadataEntries );
248 private void startList( StringBuffer metadataEntries )
250 metadataEntries.append( "\n<ul>" );
253 private void endList( StringBuffer metadataEntries )
255 metadataEntries.append( "\n</ul>" );
258 private void addListItem( String label, String value, StringBuffer metadataEntries )
260 String newValue = StringUtils.isEmpty( value ) ? "" : value;
261 metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
264 private void startListItem( String value, StringBuffer metadataEntries )
266 metadataEntries.append( "\n<li>" ).append( value );
269 private void endListItem( StringBuffer metadataEntries )
271 metadataEntries.append( "\n</li>" );
274 private void createDeleteLink( String name, String value, StringBuffer metadataEntries )
276 metadataEntries.append( "\n<li>" ).append( value )
277 .append( "\n<a href=\"showProjectMetadata!deleteMetadataEntry.action?" )
278 .append( "groupId=" ).append( groupId )
279 .append( "&artifactId=" ).append( artifactId )
280 .append( "&version=" ).append( version )
281 .append( "&deleteItem=" ).append( name )
282 .append( "&itemValue=").append( value ).append( "\" >" )
283 .append( "<img src=\"images/icons/delete.gif\"/>" ).append( "</a>" );
286 public void setObject( Object object )
288 this.object = object;
291 public void setGroupId( String groupId )
293 this.groupId = groupId;
296 public void setArtifactId( String artifactId )
298 this.artifactId = artifactId;
301 public void setVersion( String version )
303 this.version = version;