]> source.dussan.org Git - archiva.git/commitdiff
[MRM-346]: Show Artifact results in error 500.
authorJoakim Erdfelt <joakime@apache.org>
Tue, 22 May 2007 15:48:23 +0000 (15:48 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Tue, 22 May 2007 15:48:23 +0000 (15:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@540614 13f79535-47bb-0310-9956-ffa450edef68

archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/DownloadArtifact.java
archiva-web/archiva-webapp/src/main/webapp/css/site.css

index 4a3938f1dfb424a998b8673d456c712ebd393edb..b02cf1106ce3b1daac7c7faf7514f773089fa24b 100644 (file)
@@ -31,10 +31,9 @@ import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.jpox.PMFConfiguration;
 import org.jpox.SchemaTool;
 
-import sun.security.action.GetLongAction;
-
 import java.io.File;
 import java.io.PrintStream;
 import java.net.URL;
@@ -79,23 +78,37 @@ public class JdoAccess
         throws InitializationException
     {
         pmf = jdoFactory.getPersistenceManagerFactory();
-        
+
+        /* Primitive (and failed) attempt at creating the schema on startup.
+           Just to prevent the multiple stack trace warnings on auto-gen of schema.
+         
         // Create the schema (if needed)
         URL jdoFileUrls[] = new URL[] { getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
 
         File propsFile = null; // intentional
         boolean verbose = true;
-        
+
         try
         {
+            String connectionFactoryName = pmf.getConnectionFactoryName();
+            if ( StringUtils.isNotBlank( connectionFactoryName ) && connectionFactoryName.startsWith( "java:comp" ) )
+            {
+                // We have a JNDI datasource!
+                String jndiDatasource = connectionFactoryName;
+                System.setProperty( PMFConfiguration.JDO_DATASTORE_URL_PROPERTY, jndiDatasource );
+            }
+            
+            // TODO: figure out how to get the jdbc driver details from JNDI to pass into SchemaTool.
+
             SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
         }
         catch ( Exception e )
         {
             getLogger().error( "Unable to create schema: " + e.getMessage(), e );
         }
-        
+
         pmf.getPersistenceManager();
+        */
 
         // Add the lifecycle listener.
         pmf.addInstanceLifecycleListener( this, null );
@@ -352,7 +365,7 @@ public class JdoAccess
                     + "> declared parameters, yet there are <" + constraint.getParameters().length
                     + "> parameter objects to use.  This should be equal." );
             }
-            
+
             query.declareParameters( StringUtils.join( constraint.getDeclaredParameters(), ", " ) );
 
             return processParameterizedQuery( query, constraint.getParameters() );
index a637fd549e627ae47d50ea1022f3898f480ee607..691062b994ba8374d3b375ccfbb9c72489872bb1 100644 (file)
@@ -39,6 +39,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
 
 import java.io.IOException;
 import java.io.Writer;
+import java.text.DecimalFormat;
 import java.util.Iterator;
 import java.util.List;
 
@@ -80,9 +81,12 @@ public class DownloadArtifact
 
     private boolean mini = false;
 
+    private DecimalFormat decimalFormat;
+
     public DownloadArtifact( OgnlValueStack stack, PageContext pageContext )
     {
         super( stack );
+        decimalFormat = new DecimalFormat( "#,#00" );
         this.req = (HttpServletRequest) pageContext.getRequest();
         this.res = (HttpServletResponse) pageContext.getResponse();
         try
@@ -198,13 +202,29 @@ public class DownloadArtifact
         // Body
         sb.append( "<p class=\"body\">" );
 
+        sb.append( "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" );
         Iterator it = relatedArtifacts.iterator();
         while ( it.hasNext() )
         {
             ArchivaArtifact artifact = (ArchivaArtifact) it.next();
-
+            sb.append("\n<tr>");
+            
+            sb.append( "<td class=\"icon\">" );
+            appendImageLink( sb, prefix, layout, artifact );
+            sb.append( "</td>" );
+            
+            sb.append( "<td class=\"type\">" );
             appendLink( sb, prefix, layout, artifact );
+            sb.append( "</td>" );
+            
+            sb.append( "<td class=\"size\">" );
+            appendFilesize( sb, artifact );
+            sb.append( "</td>" );
+            
+            sb.append("</tr>");
         }
+        sb.append( "</table>" );
+        sb.append( "</p>" );
 
         sb.append( "</div>" ); // close "downloadbox.bd.c"
         sb.append( "</div>" ); // close "downloadbox.bd"
@@ -212,6 +232,27 @@ public class DownloadArtifact
         sb.append( "<div class=\"ft\"><div class=\"c\"></div></div>" );
         sb.append( "</div>" ); // close "download"
     }
+    
+    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( "<a href=\"" ).append( StringEscapeUtils.escapeXml( url.toString() ) ).append( "\"" );
+        sb.append( " title=\"" ).append( "Download " ).append( StringEscapeUtils.escapeXml( filename ) ).append( "\"" );
+        sb.append( ">" );
+        
+        sb.append( "<img src=\"" ).append( req.getContextPath() );
+        sb.append( "/images/download-type-" ).append( type ).append( ".png\" />" );
+        
+        sb.append( "</a>" );
+    }
 
     private void appendLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
                              ArchivaArtifact artifact )
@@ -229,13 +270,14 @@ public class DownloadArtifact
         sb.append( " title=\"" ).append( "Download " ).append( StringEscapeUtils.escapeXml( filename ) ).append( "\"" );
         sb.append( ">" );
 
-        sb.append( "<img src=\"" ).append( req.getContextPath() );
-        sb.append( "/images/download-type-" ).append( type ).append( ".png\" />" );
-
-        // TODO: Include file size / date in output ?
         sb.append( StringUtils.capitalize( type ) );
         sb.append( "</a>" );
     }
+    
+    private void appendFilesize( StringBuffer sb, ArchivaArtifact artifact )
+    {
+        sb.append( decimalFormat.format( artifact.getModel().getSize() ) );
+    }
 
     public void setArtifactId( String artifactId )
     {
index 73c65f9db69c83fdcda1531637ee61a02cd958fd..03f6a4f6fbb05af53688d6c84cbaaf4750e34877 100644 (file)
        text-decoration: none;
 }
 
+.download p.body {
+  font-weight: bold;
+}
+
+.download table {
+  margin-left: 5px;
+  width: 140px;
+}
+
+.download .icon {
+  width: 16px;
+}
+
+.download .type {
+  font-size: 0.9em;
+  text-align: right;
+}
+
+.download .size {
+  font-weight: normal;
+  font-size: 0.8em;
+  text-align: right;
+}
+
 #contentArea {
        /* margin-right: 15em; */
        padding: 1em;
@@ -342,4 +366,4 @@ div.admin table.consumers th {
 
 div.admin table.consumers td strong {
        font-size: 0.8em;
-}
\ No newline at end of file
+}