Return-Path: Delivered-To: apmail-maven-continuum-commits-archive@www.apache.org Received: (qmail 29261 invoked from network); 18 Sep 2007 09:52:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Sep 2007 09:52:47 -0000 Received: (qmail 55181 invoked by uid 500); 18 Sep 2007 09:52:39 -0000 Delivered-To: apmail-maven-continuum-commits-archive@maven.apache.org Received: (qmail 55128 invoked by uid 500); 18 Sep 2007 09:52:39 -0000 Mailing-List: contact continuum-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: continuum-dev@maven.apache.org Delivered-To: mailing list continuum-commits@maven.apache.org Received: (qmail 55073 invoked by uid 99); 18 Sep 2007 09:52:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2007 02:52:39 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2007 09:52:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7D52E1A9832; Tue, 18 Sep 2007 02:52:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r576806 - in /maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web: action/WorkingCopyAction.java util/WorkingCopyContentGenerator.java Date: Tue, 18 Sep 2007 09:52:26 -0000 To: continuum-commits@maven.apache.org From: evenisse@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070918095226.7D52E1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: evenisse Date: Tue Sep 18 02:52:25 2007 New Revision: 576806 URL: http://svn.apache.org/viewvc?rev=576806&view=rev Log: [CONTINUUM-1455] Add date and file length in the working copy page Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/WorkingCopyContentGenerator.java Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java?rev=576806&r1=576805&r2=576806&view=diff ============================================================================== --- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java (original) +++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java Tue Sep 18 02:52:25 2007 @@ -99,7 +99,12 @@ String baseUrl = UrlHelper.buildUrl( "/workingCopy.action", ServletActionContext.getRequest(), ServletActionContext.getResponse(), params ); - output = generator.generate( files, baseUrl, getContinuum().getWorkingDirectory( projectId ) ); + String imagesBaseUrl = UrlHelper.buildUrl( "/images/", ServletActionContext.getRequest(), + ServletActionContext.getResponse(), params ); + + imagesBaseUrl = imagesBaseUrl.substring( 0, imagesBaseUrl.indexOf( "/images/" ) + "/images/".length() ); + + output = generator.generate( files, baseUrl, imagesBaseUrl, getContinuum().getWorkingDirectory( projectId ) ); if ( currentFile != null && currentFile != "" ) { Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/WorkingCopyContentGenerator.java URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/WorkingCopyContentGenerator.java?rev=576806&r1=576805&r2=576806&view=diff ============================================================================== --- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/WorkingCopyContentGenerator.java (original) +++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/WorkingCopyContentGenerator.java Tue Sep 18 02:52:25 2007 @@ -23,6 +23,10 @@ import org.codehaus.plexus.util.StringUtils; import java.io.File; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.Iterator; import java.util.List; @@ -37,7 +41,17 @@ private String urlParamSeparator; - public String generate( Object item, String baseUrl, File basedir ) + private static DecimalFormat decFormatter = new DecimalFormat( "###.##" ); + + private static final long KILO = 1024; + + private static final long MEGA = 1024 * KILO; + + private static final long GIGA = 1024 * MEGA; + + private boolean odd = false; + + public String generate( Object item, String baseUrl, String imagesBaseUrl, File basedir ) { this.basedir = basedir; if ( baseUrl.indexOf( "?" ) > 0 ) @@ -53,29 +67,38 @@ StringBuffer buf = new StringBuffer(); - buf.append( "+ /
" ); + buf.append( "
" ); + buf.append( "\n" ); + + buf.append( "" ); + + print( directoryEntries, "  ", baseUrl, imagesBaseUrl, buf ); - print( directoryEntries, "  ", baseUrl, buf ); + buf.append( "
 /
  
\n" ); + buf.append( "
\n" ); return buf.toString(); } - private void print( List dirs, String indent, String baseUrl, StringBuffer buf ) + private void print( List dirs, String indent, String baseUrl, String imagesBaseUrl, StringBuffer buf ) { for ( Iterator i = dirs.iterator(); i.hasNext(); ) { Object obj = i.next(); - print( obj, indent, baseUrl, buf ); + print( obj, indent, baseUrl, imagesBaseUrl, buf ); } } - private void print( Object obj, String indent, String baseUrl, StringBuffer buf ) + private void print( Object obj, String indent, String baseUrl, String imagesBaseUrl, StringBuffer buf ) { if ( obj instanceof File ) { + String cssClass = odd ? "odd" : "even"; + File f = (File) obj; - ; if ( !f.isDirectory() ) { @@ -98,8 +121,16 @@ userDirectory = StringUtils.replace( userDirectory, "\\", "/" ); - buf.append( indent + "   " + fileName + "
" ); + buf.append( "" ); + + buf.append( "" + indent + "   " + fileName + "" + + getReadableFileSize( f.length() ) + "" + + getFormattedDate( f.lastModified() ) + "\n" ); + buf.append( "\n" ); + + odd = !odd; } } else @@ -113,14 +144,52 @@ userDirectory = StringUtils.replace( userDirectory, "\\", "/" ); - buf.append( indent + "+ " + directoryName + "
" ); + buf.append( "" ); + + buf.append( "" + indent + "  " + directoryName + "" + + " " + "" + getFormattedDate( f.lastModified() ) + "" ); + buf.append( "\n" ); + + odd = !odd; } } } else { - print( (List) obj, indent + "  ", baseUrl, buf ); + print( (List) obj, indent + "  ", baseUrl, imagesBaseUrl, buf ); } + } + + private String getFormattedDate( long timestamp ) + { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis( timestamp ); + Date date = cal.getTime(); + String res = new SimpleDateFormat( "dd-MMM-yyyy, K:mm a, z" ).format( date ); + return StringUtils.replace( res, " ", " " ); + } + + private static String getReadableFileSize( long fileSizeInBytes ) + { + if ( fileSizeInBytes >= GIGA ) + { + return decFormatter.format( fileSizeInBytes / GIGA ) + " Gb"; + } + else if ( fileSizeInBytes >= MEGA ) + { + return decFormatter.format( fileSizeInBytes / MEGA ) + " Mb"; + } + else if ( fileSizeInBytes >= KILO ) + { + return decFormatter.format( fileSizeInBytes / KILO ) + " Kb"; + } + else if ( fileSizeInBytes > 0 && fileSizeInBytes < KILO ) + { + return decFormatter.format( fileSizeInBytes ) + " b"; + } + + return "0 B"; } }