[opencms-dev] How to read a file size
Cyrill Brunschwiler
cbrunsch at hsr.ch
Fri Apr 2 00:35:02 CEST 2004
Hi Oli
have a look at the jsp below. it gets all files from the current folder
and builds a little download list. If you would have an idea how it
could look like, go for: http://mobilestreaming.csnc.ch/
SNIPPET----------------------------------------------------------------------------------------
<%@ page session="false" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.opencms.file.*" %>
<%@ page import="com.opencms.flex.jsp.*" %>
<%
// get cms related stuff
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
CmsObject obj = cms.getCmsObject();
// create formatter for dates
DateFormat df = new SimpleDateFormat("dd. MMMM yyyy", Locale.GERMAN);
DateFormat cwf = new SimpleDateFormat("ww", Locale.GERMAN);
// get img link
String img = cms.link("../resources/floppy.gif");
// get all files from current folder
ArrayList list = cms.getNavigation().getNavigationForFolder();
Iterator i = list.iterator();
%>
<table width="100%" border="0" cellspacing="1" cellpading="0" class="border">
<tr>
<td class="title">Date</td>
<td class="title">Week</td>
<td class="title">Desc</td>
<td class="title">Version</td>
<td class="title">Download</td>
<td class="title" align="right">Size</td>
</tr>
<%
while (i.hasNext()) {
try {
// get first file from vector
CmsJspNavElement ne = (CmsJspNavElement)i.next();
CmsFile file = obj.readFile(ne.getResourceName());
// get the last modified date, calendar week and title
String lastModified = df.format(new Date(file.getDateLastModified()));
String lastModifiedCW = cwf.format(new Date(file.getDateLastModified()));
String title = ne.getTitle();
// get the version stored in a property
String version = ne.getProperty("version");
if (version == null) version = "none";
String link = cms.link(ne.getResourceName());
String size = file.getContents().length / 1024 + "kb";
// get the files extension eg. pdf | doc | xls
String ext = file.getExtension().substring(1).toUpperCase();
out.println("<tr>");
out.println("<td>" + lastModified + "</td>");
out.println("<td>" + lastModifiedCW + "</td>");
out.println("<td>" + title + "</td>");
out.println("<td>" + version + "</td>");
out.println("<td><a href=\"" + link + "\"> " + ext + "</a></td>");
out.println("<td>" + size + "</td>");
out.println("</tr>");
}
catch (Exception e) {
// don't worry
}
}
}
%>
</table>
SNIPPET----------------------------------------------------------------------------------------
On Thursday 01 April 2004 19:24, Joachim Arrasz wrote:
> Hi Olli,
>
> i think this should go with the getProperty Method ... shouldn`t it?
>
>
> i think i did this some month ago ..
>
> hope this helps a bit
>
> Bye Achim
More information about the opencms-dev
mailing list