[opencms-dev] cms.getFilesInFolder()
Alexander Kandzior
alex at opencms.org
Tue Dec 10 12:15:46 CET 2002
David,
in OpenCms, Files and Folders are different things, but both are
"Resources".
So get all files and folders in a folder you need:
CmsObject.getFilesInFolder(folder)
CmsObject.getSubFolders(folder)
and there is also a
CmsObject.getResourcesInFolder(folder)
Best Regards,
Alex.
Alexander Kandzior
OpenCms Group / Alkacon Software
> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org
> [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of David
> Tildesley (DSLWN)
> Sent: Tuesday, December 10, 2002 12:10 PM
> To: 'opencms-dev at www.opencms.org'
> Subject: [opencms-dev] cms.getFilesInFolder()
>
>
> 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-minutes20
> 02/</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</PR
> OCESS><![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,param
> eters,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