]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic...
authorMaria Odea B. Ching <oching@apache.org>
Mon, 24 May 2010 10:29:58 +0000 (10:29 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 24 May 2010 10:29:58 +0000 (10:29 +0000)
o move out util for formatting project metadata to a custom tag
o do not show metadata section name (organization, issueManagement, ciManagement, scm, dependencies, mailing lists, licenses) when they are empty

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@947591 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld

index 2d3182d8c7ea239991b752cb694a6a3412d8c462..d148be496da3ae0fe4a8e7cfeccba743ec476c6d 100644 (file)
@@ -29,7 +29,6 @@ import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataResolutionException;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
-import org.apache.maven.archiva.web.util.ProjectMetadataDisplayUtil;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
@@ -290,13 +289,6 @@ public class ShowArtifactAction
         return SUCCESS;
     }
     
-    public String getMetadataOutput()
-    {
-        ProjectMetadataDisplayUtil metadataDisplayUtil = new ProjectMetadataDisplayUtil();
-        
-        return metadataDisplayUtil.formatProjectMetadata( projectMetadata );
-    }
-
     public String updateProjectMetadata()
     {
         metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata );
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java
new file mode 100644 (file)
index 0000000..f358127
--- /dev/null
@@ -0,0 +1,258 @@
+package org.apache.maven.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.archiva.metadata.model.Dependency;
+import org.apache.archiva.metadata.model.License;
+import org.apache.archiva.metadata.model.MailingList;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ProjectMetadataTag 
+ * 
+ * Outputs the project metadata attributes, used in the Metadata tab in artifact browse.
+ */
+@SuppressWarnings( "serial" )
+public class ProjectMetadataTag
+    extends TagSupport
+{
+    private Logger log = LoggerFactory.getLogger( ProjectMetadataTag.class );
+
+    private Object object;
+
+    @Override
+    public void release()
+    {
+        object = null;
+        super.release();
+    }
+
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        StringBuffer buf = new StringBuffer();
+
+        if ( object == null )
+        {
+            buf.append( "Error generating project metadata." );
+            log.error( "Unable to generate project metadata for null object." );
+        }
+        else if ( object instanceof ProjectVersionMetadata )
+        {
+            ProjectVersionMetadata metadata = (ProjectVersionMetadata) object;
+
+            buildProjectMetadata( buf, metadata );
+        }
+        else
+        {
+            buf.append( "Unable to generate project metadata for object " ).append( object.getClass().getName() );
+        }
+
+        out( buf.toString() );
+
+        return EVAL_BODY_INCLUDE;
+    }
+
+    private void out( String msg )
+        throws JspException
+    {
+        try
+        {
+            pageContext.getOut().print( msg );
+        }
+        catch ( IOException e )
+        {
+            throw new JspException( "Unable to output to jsp page context." );
+        }
+    }
+
+    private void buildProjectMetadata( StringBuffer metadataEntries, ProjectVersionMetadata projectMetadata )
+    {
+        startList( metadataEntries );
+
+        addListItem( "project.metadata.id=", projectMetadata.getId(), metadataEntries );
+        addListItem( "project.url=", projectMetadata.getUrl(), metadataEntries );
+        addListItem( "project.name=", projectMetadata.getName(), metadataEntries );
+        addListItem( "project.description=", projectMetadata.getDescription(), metadataEntries );
+        
+        if ( projectMetadata.getOrganization() != null )
+        {
+            startListItem( "organization", metadataEntries );
+            startList( metadataEntries );
+            addListItem( "organization.name=", projectMetadata.getOrganization().getName(), metadataEntries );
+            addListItem( "organization.url=", projectMetadata.getOrganization().getUrl(), metadataEntries );
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getIssueManagement() != null )
+        {
+            startListItem( "issueManagement", metadataEntries );
+            startList( metadataEntries );
+            addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem(), metadataEntries );
+            addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl(), metadataEntries );
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getScm() != null )
+        {
+            startListItem( "scm", metadataEntries );
+            startList( metadataEntries );
+            addListItem( "scm.url=", projectMetadata.getScm().getUrl(), metadataEntries );
+            addListItem( "scm.connection=", projectMetadata.getScm().getConnection(), metadataEntries );
+            addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection(),
+                         metadataEntries );
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getCiManagement() != null )
+        {
+            startListItem( "ciManagement", metadataEntries );
+            startList( metadataEntries );
+            addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem(), metadataEntries );
+            addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl(), metadataEntries );
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getLicenses() != null && !projectMetadata.getLicenses().isEmpty() )
+        {
+            startListItem( "licenses", metadataEntries );
+            List<License> licenses = projectMetadata.getLicenses();
+            int ctr = 0;
+            startList( metadataEntries );
+            for ( License license : licenses )
+            {
+                addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries );
+                addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries );
+                ctr++;
+            }
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getMailingLists() != null && !projectMetadata.getMailingLists().isEmpty() )
+        {
+            startListItem( "mailingLists", metadataEntries );
+            List<MailingList> lists = projectMetadata.getMailingLists();
+            List<String> otherArchives;
+            int ctr = 0;
+            int archiveCtr = 0;
+
+            startList( metadataEntries );
+            for ( MailingList list : lists )
+            {
+                addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries );
+                addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries );
+                addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries );
+                addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress(), metadataEntries );
+                addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress(), metadataEntries );
+                startListItem( "mailingLists." + ctr + ".otherArchives", metadataEntries );
+
+                if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 )
+                {
+                    archiveCtr = 0;
+                    otherArchives = list.getOtherArchives();
+
+                    startList( metadataEntries );
+                    for ( String archive : otherArchives )
+                    {
+                        addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive,
+                                     metadataEntries );
+                        metadataEntries.append( archive );
+                        archiveCtr++;
+                    }
+                    endList( metadataEntries );
+                }
+                endListItem( metadataEntries );
+                ctr++;
+            }
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+        
+        if ( projectMetadata.getDependencies() != null && !projectMetadata.getDependencies().isEmpty() )
+        {
+            startListItem( "dependencies", metadataEntries );
+            List<Dependency> dependencies = projectMetadata.getDependencies();
+            int ctr = 0;
+
+            startList( metadataEntries );
+            for ( Dependency dependency : dependencies )
+            {
+                addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries );
+                addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries );
+                addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries );
+                addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier(), metadataEntries );
+                addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries );
+                addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries );
+                addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries );
+                ctr++;
+            }
+            endList( metadataEntries );
+        }
+        endListItem( metadataEntries );
+
+        endList( metadataEntries );
+    }
+
+    private void startList( StringBuffer metadataEntries )
+    {
+        metadataEntries.append( "\n<ul>" );
+    }
+
+    private void endList( StringBuffer metadataEntries )
+    {
+        metadataEntries.append( "\n</ul>" );
+    }
+
+    private void addListItem( String label, String value, StringBuffer metadataEntries )
+    {
+        String newValue = StringUtils.isEmpty( value ) ? "" : value;
+        metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
+    }
+
+    private void startListItem( String value, StringBuffer metadataEntries )
+    {
+        metadataEntries.append( "\n<li>" ).append( value );
+    }
+
+    private void endListItem( StringBuffer metadataEntries )
+    {
+        metadataEntries.append( "\n</li>" );
+    }
+
+    public void setObject( Object object )
+    {
+        this.object = object;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java
deleted file mode 100644 (file)
index af3ba7e..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-package org.apache.maven.archiva.web.util;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.metadata.model.Dependency;
-import org.apache.archiva.metadata.model.License;
-import org.apache.archiva.metadata.model.MailingList;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.List;
-
-/**
- * ProjectMetadataDisplayUtil
- *
- */
-
-public class ProjectMetadataDisplayUtil
-{
-    private StringBuilder metadataEntries;
-    
-    public String formatProjectMetadata( ProjectVersionMetadata projectMetadata )
-    {
-        metadataEntries = new StringBuilder();
-        
-        startList();
-        
-        addListItem( "project.metadata.id=", projectMetadata.getId() );
-        addListItem( "project.url=", projectMetadata.getUrl() );
-        addListItem( "project.name=", projectMetadata.getName() );
-        addListItem( "project.description=", projectMetadata.getDescription() );
-        
-        startListItem( "organization" );
-        if ( projectMetadata.getOrganization() != null )
-        {
-            startList();
-            addListItem( "organization.name=", projectMetadata.getOrganization().getName() );
-            addListItem( "organization.url=", projectMetadata.getOrganization().getUrl() );
-            endList();
-        }
-        endListItem();
-         
-        startListItem( "issueManagement" );
-        if ( projectMetadata.getIssueManagement() != null )
-        {
-            startList();
-            addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem() );
-            addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl() );
-            endList();
-        }
-        endListItem();
-        
-        startListItem( "scm" );
-        if ( projectMetadata.getScm() != null )
-        {
-            startList();
-            addListItem( "scm.url=", projectMetadata.getScm().getUrl() );
-            addListItem( "scm.connection=", projectMetadata.getScm().getConnection() );
-            addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection() );
-            endList();
-        }
-        endListItem();
-        
-        startListItem( "ciManagement" );
-        if ( projectMetadata.getCiManagement() != null )
-        {
-            startList();
-            addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem() );
-            addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl() );
-            endList();
-        }
-        endListItem();
-        
-        startListItem( "licenses" );
-        if ( projectMetadata.getLicenses() != null )
-        {
-            List<License> licenses = projectMetadata.getLicenses();
-            int ctr = 0;
-            startList();
-            for ( License license : licenses )
-            {
-                addListItem( "licenses." + ctr + ".name=", license.getName() );
-                addListItem( "licenses." + ctr + ".url=", license.getUrl() );
-                ctr++;
-            }
-            endList();
-        }
-        endListItem();
-         
-        startListItem( "mailingLists" );
-        if ( projectMetadata.getMailingLists() != null )
-        {
-            List<MailingList> lists = projectMetadata.getMailingLists();
-            List<String> otherArchives;
-            int ctr = 0;
-            int archiveCtr = 0;
-            
-            startList();
-            for ( MailingList list : lists )
-            {
-                addListItem( "mailingLists." + ctr + ".name=", list.getName() );
-                addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl() );
-                addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress() );
-                addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress() );
-                addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress() );
-                startListItem( "mailingLists." + ctr + ".otherArchives" );
-                
-                if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 )
-                {
-                    archiveCtr = 0;
-                    otherArchives = list.getOtherArchives();
-                    
-                    startList();
-                    for ( String archive : otherArchives )
-                    {
-                        addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive );
-                        metadataEntries.append( archive );
-                        archiveCtr++;
-                    }
-                    endList();
-                }
-                endListItem();
-                ctr++;
-            }
-            endList();
-        }
-        endListItem();
-        
-        startListItem( "dependencies" );
-        if ( projectMetadata.getDependencies() != null )
-        {
-            List<Dependency> dependencies = projectMetadata.getDependencies();
-            int ctr = 0;
-            
-            startList();
-            for ( Dependency dependency : dependencies )
-            {
-                addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId() );
-                addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId() );
-                addListItem( "dependency." + ctr + ".version=", dependency.getVersion() );
-                addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier() );
-                addListItem( "dependency." + ctr + ".type=", dependency.getType() );
-                addListItem( "dependency." + ctr + ".scope=", dependency.getScope() );
-                addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath() );
-                ctr++;
-            }
-            endList();
-        }
-        endListItem();
-        
-        endList();
-        
-        return metadataEntries.toString();
-    }
-    
-    private void startList()
-    {
-        metadataEntries.append( "\n<ul>" );
-    }
-     
-    private void endList()
-    {
-        metadataEntries.append( "\n</ul>" );
-    }
-    
-    private void addListItem( String label, String value )
-    {
-        String newValue = StringUtils.isEmpty( value ) ? "" : value;
-        metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
-    }
-    
-    private void startListItem( String value )
-    {
-        metadataEntries.append( "\n<li>" ).append( value );
-    }
-    
-    private void endListItem()
-    {
-        metadataEntries.append( "\n</li>" );
-    }
-}
-
index 5f0a5ed1c4c5db830cfceed2ffe8e45f28eba95a..fc83554e0939f810ea3c9fcc8d5c12f9a32051e4 100644 (file)
 
    </tag>
    
+   <tag>
+
+      <name>project-metadata</name>
+      <tag-class>org.apache.maven.archiva.web.tags.ProjectMetadataTag</tag-class>
+      <body-content>empty</body-content>
+      <description><![CDATA[Render the project metadata tree from the provided ProjectMetadataVersion object]]></description>
+
+      <attribute>
+        <name>object</name>
+        <required>true</required>
+        <rtexprvalue>true</rtexprvalue>
+        
+        <description><![CDATA[The Object to Render]]></description>
+      </attribute>
+   
+   </tag>
+   
 </taglib>
\ No newline at end of file