continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
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 GMT
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( "+&nbsp;<a href=\"" + baseUrl + urlParamSeparator + "userDirectory=/\">/</a><br
/>" );
+        buf.append( "<div class=\"eXtremeTable\" >" );
+        buf.append( "<table class=\"tableRegion\" width=\"100%\">\n" );
+
+        buf.append( "<tr class=\"odd\"><td><img src=\"" + imagesBaseUrl +
+            "icon_arrowfolder1_sml.gif\">&nbsp;<a href=\"" + baseUrl + urlParamSeparator
+
+            "userDirectory=/\">/</a><br /></td><td>&nbsp;</td><td>&nbsp;</td>"
);
+
+        print( directoryEntries, "&nbsp;&nbsp;", baseUrl, imagesBaseUrl, buf );
 
-        print( directoryEntries, "&nbsp;&nbsp;", baseUrl, buf );
+        buf.append( "</table>\n" );
+        buf.append( "</div>\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 + "&nbsp;&nbsp;&nbsp;<a href=\"" +
baseUrl + urlParamSeparator +
-                        "userDirectory=" + userDirectory + "&file=" + fileName + "\">"
+ fileName + "</a><br />" );
+                    buf.append( "<tr class=\"" + cssClass + "\">" );
+
+                    buf.append( "<td width=\"98%\">" + indent + "&nbsp;&nbsp;<img
src=\"" + imagesBaseUrl +
+                        "file.gif\">&nbsp;<a href=\"" + baseUrl + urlParamSeparator
+ "userDirectory=" + userDirectory +
+                        "&file=" + fileName + "\">" + fileName + "</a></td><td
width=\"1%\">" +
+                        getReadableFileSize( f.length() ) + "</td><td width=\"1%\">"
+
+                        getFormattedDate( f.lastModified() ) + "</td>\n" );
+                    buf.append( "</tr>\n" );
+
+                    odd = !odd;
                 }
             }
             else
@@ -113,14 +144,52 @@
 
                     userDirectory = StringUtils.replace( userDirectory, "\\", "/" );
 
-                    buf.append( indent + "+&nbsp;<a href=\"" + baseUrl + urlParamSeparator
+ "userDirectory=" +
-                        userDirectory + "\">" + directoryName + "</a><br />"
);
+                    buf.append( "<tr class=\"" + cssClass + "\">" );
+
+                    buf.append( "<td width=\"98%\">" + indent + " <img src=\"" +
imagesBaseUrl +
+                        "icon_arrowfolder1_sml.gif\"> &nbsp;<a href =\"" + baseUrl
+ urlParamSeparator +
+                        "userDirectory=" + userDirectory + "\">" + directoryName + "</a></td><td
width=\"1%\">" +
+                        "&nbsp;" + "</td><td width=\"1%\">" + getFormattedDate(
f.lastModified() ) + "</td>" );
+                    buf.append( "</tr>\n" );
+
+                    odd = !odd;
                 }
             }
         }
         else
         {
-            print( (List) obj, indent + "&nbsp;&nbsp;", baseUrl, buf );
+            print( (List) obj, indent + "&nbsp;&nbsp;", 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, " ", "&nbsp;" );
+    }
+
+    private static String getReadableFileSize( long fileSizeInBytes )
+    {
+        if ( fileSizeInBytes >= GIGA )
+        {
+            return decFormatter.format( fileSizeInBytes / GIGA ) + "&nbsp;Gb";
+        }
+        else if ( fileSizeInBytes >= MEGA )
+        {
+            return decFormatter.format( fileSizeInBytes / MEGA ) + "&nbsp;Mb";
+        }
+        else if ( fileSizeInBytes >= KILO )
+        {
+            return decFormatter.format( fileSizeInBytes / KILO ) + "&nbsp;Kb";
+        }
+        else if ( fileSizeInBytes > 0 && fileSizeInBytes < KILO )
+        {
+            return decFormatter.format( fileSizeInBytes ) + " b";
+        }
+
+        return "0 B";
     }
 }



Mime
View raw message