From: Brett Porter
Date: Tue, 28 Aug 2007 06:37:52 +0000 (+0000)
Subject: remove code duplication
X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=75761cb85b7635c7cce8cd001ec6c0987a78199a;p=archiva.git
remove code duplication
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@570333 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/DownloadArtifact.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/DownloadArtifact.java
index 691062b99..21092cafe 100644
--- a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/DownloadArtifact.java
+++ b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/DownloadArtifact.java
@@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.tags;
import com.opensymphony.webwork.WebWorkException;
import com.opensymphony.webwork.components.Component;
import com.opensymphony.xwork.util.OgnlValueStack;
-
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.database.ArchivaDAO;
@@ -37,24 +36,22 @@ import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutF
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
import java.io.IOException;
import java.io.Writer;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.PageContext;
-
/**
- * DownloadArtifact
+ * DownloadArtifact
*
* @author Joakim Erdfelt
* @version $Id$
- *
- * @plexus.component role="com.opensymphony.webwork.components.Component" role-hint="download-artifact"
- * instantiation-strategy="per-lookup"
+ * @plexus.component role="com.opensymphony.webwork.components.Component" role-hint="download-artifact"
+ * instantiation-strategy="per-lookup"
*/
public class DownloadArtifact
extends Component
@@ -207,21 +204,21 @@ public class DownloadArtifact
while ( it.hasNext() )
{
ArchivaArtifact artifact = (ArchivaArtifact) it.next();
- sb.append("\n");
-
+ sb.append( "\n
" );
+
sb.append( "" );
appendImageLink( sb, prefix, layout, artifact );
sb.append( " | " );
-
+
sb.append( "" );
appendLink( sb, prefix, layout, artifact );
sb.append( " | " );
-
+
sb.append( "" );
appendFilesize( sb, artifact );
sb.append( " | " );
-
- sb.append("
");
+
+ sb.append( "" );
}
sb.append( "" );
sb.append( "
" );
@@ -232,34 +229,20 @@ public class DownloadArtifact
sb.append( "" );
sb.append( "" ); // close "download"
}
-
- private void appendImageLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout, ArchivaArtifact artifact )
+
+ private void appendImageLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
+ ArchivaArtifact artifact )
{
- StringBuffer url = new StringBuffer();
- String path = layout.toPath( artifact );
String type = artifact.getType();
-
- url.append( prefix );
- url.append( "/" ).append( path );
-
- String filename = path.substring( path.lastIndexOf( "/" ) + 1 );
-
- sb.append( "" );
-
- sb.append( "" );
-
- sb.append( "" );
+ String linkText = "";
+ appendLink( sb, prefix, layout, artifact, linkText );
}
- private void appendLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
- ArchivaArtifact artifact )
+ private static void appendLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
+ ArchivaArtifact artifact, String linkText )
{
StringBuffer url = new StringBuffer();
String path = layout.toPath( artifact );
- String type = artifact.getType();
url.append( prefix );
url.append( "/" ).append( path );
@@ -270,10 +253,20 @@ public class DownloadArtifact
sb.append( " title=\"" ).append( "Download " ).append( StringEscapeUtils.escapeXml( filename ) ).append( "\"" );
sb.append( ">" );
- sb.append( StringUtils.capitalize( type ) );
+ sb.append( linkText );
+
sb.append( "" );
}
-
+
+ private void appendLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
+ ArchivaArtifact artifact )
+ {
+ String type = artifact.getType();
+ String linkText = StringUtils.capitalize( type );
+
+ appendLink( sb, prefix, layout, artifact, linkText );
+ }
+
private void appendFilesize( StringBuffer sb, ArchivaArtifact artifact )
{
sb.append( decimalFormat.format( artifact.getModel().getSize() ) );