[opencms-dev] Default-file for folder tree
Lynn Chapman
chapmanlynnmarie at gmail.com
Fri Feb 25 15:44:07 CET 2011
I'm not sure if this helps you but we had a similar problem. We have many
microsite editors that post minutes, agendas, etc. but they are not very
skilled. They were uploading files, creating links, etc. etc. Too many
steps.
So I build this little "table of contents" tool. I put the index.jsp into a
folder and all the editors have to do is put the minutes, agendas, etc. into
the folder and give each one a title. It automatically creates a list of
the folders contents. I've included the code below. (We're still at openCms
6 )
What I don't know how to do is to make this a structured content type so the
editors can set the folders up themselves. I'm working on that now.
Lynn
----------------------------
<!--
Name: index.jsp
Author: Lynn Chapman
Description: Table of Contents tool. This code generates a list of links
to folders and files.
It lists files that are within it's own folder and any subfolders.
Calls: none
Modification History
Written: December 2010
-->
<%@ page session="false" buffer="none" import="java.sql.*, com.onr.*,
java.util.*,org.opencms.search.*, org.opencms.flex.*, org.opencms.util.*,
org.opencms.jsp.*, org.opencms.frontend.templateone.modules.*,
org.opencms.main.*, org.opencms.file.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<jsp:useBean id="cmsUser" class="org.opencms.jsp.CmsJspActionElement">
<% cmsUser.init(pageContext, request, response); %>
</jsp:useBean>
<cms:include property="template" element="head" />
<head>
<link rel="stylesheet" type = "text/css" href="site-event.css" >
</head>
<div class="element">
<%
CmsJspActionElement action = new
CmsJspActionElement(pageContext,request,response);
CmsObject cms = action.getCmsObject();
// Plan to allow user to put a heading on the Table of Contents page would
not work. Normal user
// cannot change properties of jsp files. Left code in hopes that another
way can eventually be found.
// String heading = action.property("Title", "index.jsp");
// out.println ("<h1>heading</h1>");
try {
out.println ("<table>");
// List the Folders
List listFolders = cms.getSubFolders(action.info
("opencms.request.folder"));
CmsFolder cmsfolder= null;
for(int i=0;i<listFolders.size();i++){
cmsfolder=(CmsFolder) listFolders.get(i);
String folderName = cmsfolder.getName();
String folderNameWithSlash = folderName + "/";
String folderPath = cmsfolder.getFolderPath(folderNameWithSlash);
String folderTitle = action.property("Title",folderName);
if (folderTitle == null){folderTitle = folderName;}
String topFolder = action.info("opencms.request.folder");
String longFolderPath = topFolder + folderPath;
String folderDescription = action.property("Description", folderName);
if (folderDescription == null) { folderDescription = ""; }
out.println ("<tr><td>" +folderTitle +"</td><td>" +folderDescription
+"</td></tr>");
// LIST THE FILES IN EACH FOLDER
List listFilesInFolder = cms.getFilesInFolder(longFolderPath);
for(int j=0;j<listFilesInFolder.size();j++){
CmsFile cmsfileinside= (CmsFile) listFilesInFolder.get(j);
String filenameinside = cmsfileinside.getName();
if (!filenameinside.equals("index.jsp")){
String linkinside = "";
String longFileNameInside = longFolderPath + filenameinside;
String titleinside = action.property("Title", longFileNameInside);
titleinside = action.property("Title",longFileNameInside);
if (titleinside == null) {titleinside = filenameinside;}
String fileDescription = action.property("Description",
longFileNameInside);
if (fileDescription == null) { fileDescription = ""; }
linkinside = action.link(longFileNameInside);
out.println ("<tr><td> </td><td><a href=\"" +linkinside +"\">"
+titleinside +"</a></td><td>" +fileDescription +"</td><tr>");
}
}
}
// LIST FILE THAT ARE AT THE TOP FOLDER LEVEL
List listFiles = cms.getFilesInFolder(action.info("opencms.request.folder"));
for(int i=0;i<listFiles.size();i++){
CmsFile cmsfile= (CmsFile) listFiles.get(i);
String filename = cmsfile.getName();
if (!filename.equals("index.jsp")){
String title = action.property("Title", filename);
String link = "";
String description = action.property("Description", filename);
if (description == null) { description = ""; }
title = action.property("Title",filename);
if (title == null) {title = filename;}
link = action.link(filename);
out.println ("<tr><td><a href=\"" +link +"\">" +title +"</a></td><td>"
+description +"</td></tr>");
}
}
} catch (CmsException e) {
out.println(e);
}
%>
</div>
<cms:include property="template" element="foot" />
On Fri, Feb 25, 2011 at 8:24 AM, Paul-Inge Flakstad <flakstad at npolar.no>wrote:
> Hi Tylla,
>
> Instead of dabbling with the "default-file" property, how about just
> setting the "restypes.indexpage" property to a resource type especially
> created to serve the required purpose? (For example an xmlcontent type with
> its "template-elements" property set to a JSP that does what you want it
> to.)
>
> As far as I can see, this could be a simple solution in your case.
>
> Cheers,
> Paul
>
> > -----Original Message-----
> > From: opencms-dev-bounces at opencms.org
> > [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Nagy Attila
> > Sent: 25. februar 2011 13:45
> > To: opencms-dev at opencms.org
> > Subject: [opencms-dev] Default-file for folder tree
> >
> > Hi!
> >
> > I am having a frequently changing directory tree which is
> > populated with
> > some custom XML objects. What I want to do is automatically list the
> > elements of a folder when the folder is accessed.
> > I managed to solve this, but it is too tedious (it involves
> > creating an
> > index.html in every folder and adding a property which gets
> > read by the
> > template). I can't put this in the hand of the user, it would forget
> > one-two steps and I have to clean up the mess. :(
> >
> > I thought this could be done simply with the "default-file"
> > property, by
> > setting it to some self-made jsp file that lists the
> > directory contents,
> > but it doesn't seem to work.
> >
> > I did search the mail list and the forums, but except for an almost
> > similar question that wasn't answered anyway, I couldn't find
> > any usable
> > info.
> > Am I missing something?
> > How does the "default-file" property work?
> >
> > Thanks in advance, and sorry if this was already answered somewhere
> > (than some pointer would be welcome too).
> > Tylla.
> >
> > _______________________________________________
> > This mail is sent to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the list,
> > please visit
> > http://lists.opencms.org/mailman/listinfo/opencms-dev
> >
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110225/56bb1d48/attachment.htm>
More information about the opencms-dev
mailing list