Re: Retrieve list all files stored in the same folder

Sergiy Shyrkov <[email protected]> Sun, 22 Jun 2008 12:35:48 +0200
Newsgroups gmane.comp.cms.jahia.devel
Message-ID <[email protected]>
Hi,

I assume, you are using Jahia 5.0 SP3.

1) You can create the "WebDAV folder selector" in your page using the =

following code:

<input type=3D"text" name=3D"myFolder" id=3D"myFolder" value=3D""/>
&nbsp;<a href=3D"#select"
                onclick=3D"javascript:{var pathSelector =3D window.open('<%=
=3D =

request.getContextPath() =

%>/jsp/jahia/engines/webdav/webdavrepository.jsp?display=3Ddirectories_Only=
&htmlElementId=3DmyFolder', =

'pathSelector_<%=3D request.getSession().getId()%>', =

'resizable,height=3D800,width=3D600'); pathSelector.focus(); return false;}=
">
                Select folder
      </a>

It contains an input field (with ID) and a link to the folder selector, =

where you pass the ID of the input element to store the selected folder =

path. The only thing, your will need to remove the '/jahia/webdav' from =

the URL.

2) To get the folder path for the selected file (Jahia field of type =

'File') you can use the following code:
I am using mainContent container as an example (see our =

corporate_portal_templates_v2/common/main_content.jsp).
The field name is 'image'.

<%@ page import=3D"org.jahia.services.webdav.JahiaWebdavBaseService,
                                org.jahia.services.webdav.DAVFileAccess,
                                org.jahia.data.beans.RequestBean,
                                org.jahia.params.ProcessingContext,
                                org.jahia.data.files.JahiaFile,
                                org.apache.commons.io.FilenameUtils" %>

<content:containerList name=3D'<%=3D"mainContentList" + id%>' =

id=3D"mainContentList">
...
    <content:container id=3D"mainContent">
...
    <logic:present name=3D"mainContent" property=3D"field(image)">
        <bean:define id=3D"image" name=3D"mainContent" =

property=3D"field(image).object"/>
        <logic:present name=3D"image">
          <bean:define id=3D"filePath" name=3D"image" property=3D"realName"=
/>
            <%
                String folderPath =3D =

FilenameUtils.getFullPathNoEndSeparator((String) =

pageContext.getAttribute("filePath"));
                if (folderPath !=3D null && folderPath.length() !=3D 0) {
                    ProcessingContext jParams =3D ((RequestBean) =

request.getAttribute("currentRequest")).getParamBean();
                    DAVFileAccess folderItem =3D =

JahiaWebdavBaseService.getInstance().getDAVFileAccess(jParams, folderPath);
                    %>
                   =

                    Here is the folder path of the selected file: <%=3D =

folderItem.getPath() %>

                <%
                }
            %>
        </logic:present>
    </logic:present>
...
    </content:container>
</content:containerList>


3) You can get a list of files (and also sub folders) in your template =

JSP using the DAVFileAccess API =

(http://www.jahia.org/javadoc-dev_5/org/jahia/services/webdav/DAVFileAccess=
.html) =

in the following way:

<%@ page =

import=3D"org.jahia.services.webdav.JahiaWebdavBaseService,org.jahia.servic=
es.webdav.DAVFileAccess" =

%>
<h3>Content of the /shared/myfolder</h3>
<ul>
<%
DAVFileAccess myFolder =3D =

JahiaWebdavBaseService.getInstance().getDAVFileAccess(jParams, =

"/shared/myfolder");
List children =3D myFolder.getChildren();
for (Iterator it =3D children.iterator(); it.hasNext();) {
    DAVFileAccess item =3D (DAVFileAccess) it.next();
    boolean isFolder =3D item.isCollection();
  %><li><a href=3D"<%=3D request.getContextPath() %>/webdav<%=3D =

item.getPath() %>" target=3D"_blank"><%=3D item.getName() %>[<%=3D isFolder=
 ? =

"folder" : "file" %>]</a></li><%
}
%>
</ul>


Kind regards
Sergiy

PIRONET Beno=EEt schrieb:
> Hi, =

>
> I'd like to store lots of documents in different places in my file manage=
r and let page creators (webmasters) to choose one directory and the templa=
te will be responsible for displaying all the files stored in that director=
y.
>
> First question: =

> Is it possible to instanciate the file chooser to choose not a file but a=
 folder? =

> if I can't select a folder, I will ask page creator to select one file fr=
om the directory we want to list all files and the processing will do the j=
ob.
> By searching this way, I found that JahiaFile has a getFolderId() method =
but I can't figure what I can do with the folder id ?
>
> Second question: =

> Is there an API to exploid the folder id retrieve from a JahiaFile ?
>
>
>
> Third question: How to get the list of file from one folder ??
> I saw the jahiaWebdavBaseService but I'm not sure at all that I'm on the =
right way?
>
>
> Thank you very much for your replies, =

>
>
> Benoit Pironet
>
>
>
> I'm using Jahia 5.0.3
> _______________________________________________
> dev_list mailing list
> [email protected]
> http://lists.jahia.org/cgi-bin/mailman/listinfo/dev_list
>   =


_______________________________________________
dev_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/dev_list