[opencms-dev] cms.getFilesInFolder()
David Tildesley (DSLWN)
DavidTi at datacom.co.nz
Tue Dec 10 12:09:44 CET 2002
Hi,
I am trying to get a listing of files in a download gallery (or any list of
any folder for that matter). The content template, element templace and java
code follows. The problem is that no files are listed (the vector is empty)
each time. Any help would be much appreciated.
contenttemplate:
<?xml version="1.0" encoding="utf-8"?>
<XMLTEMPLATE>
<TEMPLATE>
<ELEMENT name="body"/>
<ELEMENT name="filelist"/>
</TEMPLATE>
<ELEMENTDEF name="filelist">
<CLASS>ListDownloadFiles</CLASS>
<PARAMETER
name="folder">/opencms/system/galleries/download/bot-minutes2002/</PARAMETER
>
<TEMPLATE>/system/modules/default/elements/minutes</TEMPLATE>
</ELEMENTDEF>
</XMLTEMPLATE>
element template:
<?xml version= "1.0"?>
<XMLTEMPLATE>
<TEMPLATE>
<![CDATA[
<h1>Download List</h1>
<ul>]]>
<PROCESS>row</PROCESS>
<![CDATA[</ul>]]>
</TEMPLATE>
<row>
<![CDATA[<li><a
href="]]><PROCESS>uri</PROCESS><![CDATA[">]]><PROCESS>item</PROCESS><![CDATA
[</a>]]>
</row>
</XMLTEMPLATE>
java code for ListDownloadFiles:
import com.opencms.template.*;
import com.opencms.file.*;
import com.opencms.core.*;
import java.util.*;
public class ListDownloadFiles extends CmsXmlTemplate {
public byte[] getContent(CmsObject cms, String templateFile, String
elementName, Hashtable parameters, String templateSelector) throws
CmsException
{
CmsXmlTemplateFile
template=getOwnTemplateFile(cms,templateFile,elementName,parameters,template
Selector);
String folder=(String)parameters.get("filelist.folder");
Vector files=cms.getFilesInFolder(folder);
String list="";
if (!files.isEmpty()) {
for (int i=files.size()-1; i >= 0; i--) {
CmsFile file=(CmsFile)files.elementAt(i);
String fileName=file.getAbsolutePath();
template.setData("uri", fileName);
String
fileTitle=cms.readProperty(fileName,"Title");
if (fileTitle != null)
template.setData("item", fileName);
else
template.setData("item", fileTitle);
String
row=template.getProcessedDataValue("row");
list+= row;
}
}
else
{
//the below is for debug purpose
template.setData("uri",folder);
template.setData("item",folder);
String row=template.getProcessedDataValue("row");
list+= row;
}
template.setData("row",list);
return startProcessing(cms, template, elementName,
parameters, templateSelector);
}
}
More information about the opencms-dev
mailing list