diff options
author | skygo <skygo@unknown> | 2012-08-27 22:41:57 +0000 |
---|---|---|
committer | skygo <skygo@unknown> | 2012-08-27 22:41:57 +0000 |
commit | d897c8bcfa2f3b55fca72e556d30d7e9ceac8fe7 (patch) | |
tree | 9638cab0edd6ddc86f372f01d2b5f793e44982e9 | |
parent | 6f6609413d7f8ea240dc4dfa38d9f1e365a3a3ae (diff) | |
download | archiva-d897c8bcfa2f3b55fca72e556d30d7e9ceac8fe7.tar.gz archiva-d897c8bcfa2f3b55fca72e556d30d7e9ceac8fe7.zip |
change to repository browsing webdav side
date filesize color.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1377897 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java index 5fa185335..bf5d92d9c 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java @@ -25,12 +25,15 @@ import org.apache.jackrabbit.webdav.io.OutputContext; import java.io.File; import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -62,7 +65,7 @@ public class IndexWriter { outputContext.setModificationTime( new Date().getTime() ); outputContext.setContentType( "text/html" ); - outputContext.setETag( "" ); + outputContext.setETag( "" ); // skygo ETag MRM-1127 seems to be fixed if ( outputContext.hasStream() ) { PrintWriter writer = new PrintWriter( outputContext.getOutputStream() ); @@ -76,9 +79,28 @@ public class IndexWriter private void writeDocumentStart( PrintWriter writer ) { + writer.println("<!DOCTYPE html>"); writer.println( "<html>" ); writer.println( "<head>" ); writer.println( "<title>Collection: /" + logicalResource + "</title>" ); + writer.println( "<style type=\"text/css\">" ); + writer.println( "ul{list-style:none;}" ); //list-style-image: url("../images/folder.png"); + StringBuilder relative = new StringBuilder("../../"); + if ( logicalResource.length() > 0 ) + { + String tmpRelative = StringUtils.replace( logicalResource, "\\", "/" ); + for (int i=0;i<tmpRelative.split("/").length;i++) + { + relative.append("../"); + } + } + writer.println( ".file{list-style-image:url(" + relative.toString() + "images/trash.png);}" ); + writer.println( ".folder{list-style-image:url(" + relative.toString() + "images/folder.png);}" ); + writer.println( "a{color: #0088CC;text-decoration: none;}" ); + writer.println( ".collection li:nth-child(odd){background-color:#fafafa;}" ); + writer.println( ".size{position:absolute;left:500px;color:#cc8800;}" ); + writer.println( ".date{position:absolute;left:600px;color:#0000cc;}" ); + writer.println( "</style>" ); writer.println( "</head>" ); writer.println( "<body>" ); writer.println( "<h3>Collection: /" + logicalResource + "</h3>" ); @@ -93,11 +115,11 @@ public class IndexWriter parentName = StringUtils.replace( parentName, "\\", "/" ); writer.println( "<ul>" ); - writer.println( "<li><a href=\"../\">" + parentName + "</a> <i><small>(Parent)</small></i></li>" ); + writer.println( "<li class=\"folder\"><a href=\"../\">" + parentName + "</a> <i><small>(Parent)</small></i></li>" ); writer.println( "</ul>" ); } - writer.println( "<ul>" ); + writer.println( "<ul class=\"collection\">" ); } private void writeDocumentEnd( PrintWriter writer ) @@ -118,7 +140,7 @@ public class IndexWriter for ( File file : files ) { - writeHyperlink( writer, file.getName(), file.isDirectory() ); + writeHyperlink( writer, file.getName(), file.lastModified(), file.length(), file.isDirectory() ); } } } @@ -161,22 +183,35 @@ public class IndexWriter if ( !written.contains( childFile.getName() ) ) { written.add( childFile.getName() ); - writeHyperlink( writer, fileName, childFile.isDirectory() ); + writeHyperlink( writer, fileName, childFile.lastModified(), childFile.length(), childFile.isDirectory() ); } } } } } - private void writeHyperlink( PrintWriter writer, String resourceName, boolean directory ) + private static String fileDateFormat( long date ) + { + DateFormat dateFormatter = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault() ); + Date aDate = new Date( date ); + return dateFormatter.format( aDate ); + } + + private static String fileSizeFormat( long fileSize ) + { + DecimalFormat format =new DecimalFormat( "###,##0.000" ); + return format.format( (double) fileSize / 1024 ) + " KB"; + } + + private void writeHyperlink( PrintWriter writer, String resourceName, long lastModified, long fileSize, boolean directory ) { if ( directory ) { - writer.println( "<li><a href=\"" + resourceName + "/\">" + resourceName + "</a></li>" ); + writer.println( "<li class=\"folder\"><a href=\"" + resourceName + "/\">" + resourceName + "</a></li>" ); } else { - writer.println( "<li><a href=\"" + resourceName + "\">" + resourceName + "</a></li>" ); + writer.println( "<li class=\"file\"><a href=\"" + resourceName + "\">" + resourceName + "<span class=\"size\">" + fileSizeFormat( fileSize ) + "</span><span class=\"date\">" + fileDateFormat( lastModified ) + "</span></a></li>" ); } } } |