Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-6) was last changed on 23-May-2011 01:46 by 67.180.48.96  

This page was created on 31-Jul-2002 14:32 by ThorbjoernRavnAndersen

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 5 added 124 lines
----
Quick hack for sorted list of a Wiki repository. Add "?c=100" to get the 100 latest. Path to repository is hardcoded.
{{{
<%@page
import="java.io.*, java.util.*"
contentType="text/html"
%><%!
String[] fileurlmappings = {
"/export/spare/home/ravn/wiki/tra", "/wiki/Wiki.jsp?page="
};
String dir = ".";
%><%
class Single_Entry {
File f;
String url;
Single_Entry( File f, String url) {
this.f = f;
this.url = url;
}
}
int requested_number_of_items;
List<Single_Entry> entries = new ArrayList<Single_Entry>();
try {
requested_number_of_items = Integer.parseInt(request.getParameter("c"));
} catch (NumberFormatException e) {
requested_number_of_items = 10;
}
// Gather file info
for( int i = 0; i < fileurlmappings.length; i += 2) {
File dir = new File( fileurlmappings[i]);
if (dir.isDirectory()) {
File[] files = dir.listFiles();
for( int j = 0; j < files.length; j++) {
// System.out.println( j + " " + files[j].getName());
// TODO: URL is not protected
if (! files[j].isDirectory()) {
entries.add( new Single_Entry( files[j], fileurlmappings[ i+1] + files[j].getName()));
}
}
} else {
System.out.println( "error: " + dir.getName() + " is not a directory");
}
}
// Sort. Put newest first
java.util.Collections.sort( entries, new Comparator<Single_Entry>() {
public int compare( Single_Entry a, Single_Entry b) {
if (a.f.lastModified() < b.f.lastModified())
return 1;
if (a.f.lastModified() > b.f.lastModified())
return -1;
return 0;
}
});
int number_to_show = Math.min(entries.size(), requested_number_of_items);
%>
<dl>
<%
for( int i = 0; i < number_to_show; i++) {
Single_Entry se = entries.get(i);
String entryName = se.f.getName();
if (entryName.endsWith(".txt")) {
entryName = entryName.substring( 0, entryName.length() - ".txt".length());
se.url = se.url.substring( 0, se.url.length() - ".txt".length());
}
if (entryName.length() > 23) {
entryName = entryName.substring( 0, 20) + "...";
}
%>
<dt>
<a href="<%= se.url %>"><%= entryName %></a>
</dt>
<dt>
<font size="-2" color="#999999"><%
// Voodoo to get short times for today and yesterday
Calendar midnight_today = Calendar.getInstance();
midnight_today.set( Calendar.HOUR_OF_DAY, 0);
midnight_today.set( Calendar.MINUTE, 0);
Calendar midnight_yesteday = Calendar.getInstance();
midnight_yesteday.set( Calendar.HOUR_OF_DAY, 0);
midnight_yesteday.set( Calendar.MINUTE, 0);
midnight_yesteday.add( Calendar.DAY_OF_MONTH, -1);
Calendar c = Calendar.getInstance();
c.setTimeInMillis( se.f.lastModified());
if ( c.before( midnight_yesteday)) {
%><%= new java.util.Date( se.f.lastModified()) %><% } else if (c.before(midnight_today)) {
%>Yesteday <%= c.get(Calendar.HOUR_OF_DAY) %>:<%= c.get(Calendar.MINUTE) %><% } else {
%><%= c.get(Calendar.HOUR_OF_DAY) %>:<%= c.get(Calendar.MINUTE) %><% } %>
</font>
</dt>
<% } %>
</dl>
}}}
I am not claiming this is pretty or complete, but it is an alternative which might be interesting for some.
----
CategoryHomepage
Version Date Modified Size Author Changes ... Change note
6 23-May-2011 01:46 3.509 kB 67.180.48.96 to previous
5 28-Jan-2010 11:06 3.546 kB 164.67.235.200 to previous | to last
4 02-May-2004 04:44 3.633 kB SkakMorten to previous | to last
3 31-Jul-2002 15:00 3.609 kB ThorbjoernRavnAndersen to previous | to last
2 31-Jul-2002 14:52 3.608 kB ThorbjoernRavnAndersen to previous | to last
1 31-Jul-2002 14:32 0.126 kB ThorbjoernRavnAndersen to last
« This page (revision-6) was last changed on 23-May-2011 01:46 by 67.180.48.96