[opencms-dev] getting the file resource from a link
Christian Fleron Guldner
cfg at pbs.dk
Tue Oct 21 13:25:02 CEST 2003
Thanks for your answer. I'm sure your example will come in handy later on.
But it wasn't the answer to my problem. I have found the answer though.
Instead of:
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String filename = com.opencms.file.CmsFile.getPath(cms.getRequestContext().getUri());
CmsJspNavElement element = cms.getNavigation().getNavigationForResource(foldername);
I do this:
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String filename = cms.getRequestContext().getUri();
String linkFile = cms.getContent(filename);
CmsJspNavElement element = cms.getNavigation().getNavigationForResource(linkFile);
Many of you probably knew that the content of a link resource is the uri of the page it links to. I just should have explained my problem a little better.
Christian Güldner
20. oktober 2003 17:03
To: <opencms-dev at opencms.org>
cc:
From: "Matthew Evans" <matte at solidstategroup.com>
Subject: RE: [opencms-dev] getting the file resource from a link
I'm not sure exactly what you are after, but I use this code to access files in the VFS, maybe it will help you.
M at .
--------------------
<%@ page session="false" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ page import="java.util.*,
com.opencms.flex.jsp.*,
com.opencms.file.*,
com.opencms.file.CmsUser" %>
<cms:include property="template" element="head" />
<%
//Get command line parameters
String download_dir = request.getParameter("download_dir");
// Create a JSP action element
com.opencms.flex.jsp.CmsJspActionElement cms = new com.opencms.flex.jsp.CmsJspActionElement(pageContext, request, response);
String DEF_FILE_TYPE = "Downloadable File";
//out.println(download_dir);
boolean hasFiles = false;
boolean hasFolders = false;
CmsObject cmso = cms.getCmsObject();
CmsFolder currentFolder = cmso.readFolder(download_dir);
if (download_dir != null && !"".equals(download_dir)) {
try {
// Print out the breadcrumb trail
String endFolder = "";
Vector dirTree = new Vector();
int count = 0;
while (!currentFolder.getAbsolutePath().equals("/system/galleries/download/Contents/")){
dirTree.add(count,"<a href=\"RGLFiles.jsp?download_dir=" + currentFolder.getAbsolutePath() + "&menunode=title3\">" + cmso.readProperty(currentFolder.getAbsolutePath(),"Title") + "</a>");
currentFolder = cmso.readFolder(currentFolder.getParent());
}
out.println("<p class=\"user\">");
for (count = 0; count <= dirTree.size()-1; count++){
out.println(" > " + dirTree.elementAt(count));
}
out.println("</p>");
// Use the Cms* object to get all folders under the download_dir
java.util.Vector allSubFolders = cmso.getSubFolders(download_dir);
Iterator ii = allSubFolders.iterator();
if(ii.hasNext()){
hasFolders=true;
%>
<!-- Downloads table -->
<p class="title">Folders</p>
<table border="0" width="100%">
<%
}
while (ii.hasNext()) {
CmsFolder thisFolder = (CmsFolder)ii.next();
out.println("<tr><td class=\"normal\"><a href=\"RGLFiles.jsp?download_dir=" + thisFolder.getAbsolutePath() + "&menunode=title3\">" + cmso.readProperty(thisFolder.getAbsolutePath(),"Title") + "</a></td></tr>");
}
if (hasFolders==true){
out.println("</table>");
}
// We have to use Cms* objects to get files that are not Pages.
Iterator i = cmso.getFilesInFolder(download_dir).iterator();
if (i.hasNext()) {
hasFiles = true;
%>
<!-- Downloads table -->
<p class="title">Files</p>
<table border="0" width="100%">
<%
}
int lines = 0;
while (i.hasNext()) {
CmsFile f = (CmsFile)i.next();
if(lines % 2 == 0) out.println("<tr>");
else out.println("<tr>");
// There is probably a built-in source for this....
HashMap fTypes = new HashMap(35);
fTypes.put(".txt","Text File");
fTypes.put(".doc","MS Word Doc");
fTypes.put(".htm","Web (HTML) Document");
fTypes.put(".html","Web (HTML) Document");
fTypes.put(".jpg","JPEG Image File");
fTypes.put(".jpeg","JPEG Image File");
fTypes.put(".gif","GIF Image File");
fTypes.put(".pdf","Adobe PDF (Acrobat™) Document");
fTypes.put(".zip","ZIP Compressed File");
fTypes.put(".tar","UNIX Archive File");
fTypes.put(".tgz","GZip Compressed Archive File");
fTypes.put(".gz","GZip Compressed File");
fTypes.put(".gzip","GZip Compressed File");
fTypes.put(".xls","MS Excel Spreadsheet");
fTypes.put(".ppt","MS PowerPoint Slideshow");
fTypes.put(".exe","Windows/DOS Executable");
fTypes.put(".wmf","Windows Media File");
fTypes.put(".ram","Real Media File");
fTypes.put(".rpm","Real Media File");
fTypes.put(".mp3","MP3 Audio File");
fTypes.put(".mpg","MPEG Video File");
fTypes.put(".mpeg","MPEG Video File");
fTypes.put(".avi","AVI Video File");
String fName = f.getName();
String ext = f.getExtension();
int fLength = f.getLength();
String unit = "Kb";
if(fLength < 1024) unit = "bytes";
else fLength /= 1024;
//out.println("Extension from CMS: "+ext+"<br>");//DEBUG
String fTitle = cmso.readProperty(f.getAbsolutePath(),"Title");
String fileType;
if("".equals(ext)) fileType = DEF_FILE_TYPE;
else fileType = (fTypes.get(ext) != null)?fTypes.get(ext).toString():DEF_FILE_TYPE;
out.println("<td class=\"normal\"><a href=\"" + cms.link(f.getAbsolutePath()));
out.print("\">");
if(fTitle !="" && fTitle != null) out.print(fTitle);
else out.print(fName);
out.println("</a></td>");
out.println("<td class=\"normal\">" + fileType + "</td>");
out.print("<td class=\"normal\" width=\"50\">");
out.print(fLength);
out.println(" "+unit+"</td>");
++lines;
}
} catch (Exception e) {
out.println(e.toString());
}
}
if (hasFiles==true){
out.println("</table>");
}
%>
<cms:include property="template" element="foot" />
Matthew Evans
SolidStateGroup
tel. +44 (0) 20 77402133
Mob. +44(0)7958 379562
http://www.solidstategroup.com
From: opencms-dev-admin at opencms.org [mailto:opencms-dev-admin at opencms.org] On Behalf Of Christian Fleron Guldner
Sent: 20 October 2003 15:04
To: opencms-dev at opencms.org
Hi,
Hope you can help me. I have not been able to find the answer to my problem by searching the list.
I have a folder full of links, wich I use to generate a menu. When I need another item in the menu, I create a new link to the page in this "menu-folder".
My problem:
I need to get at the navigation information of the page I've linked to, not the navigation info of the link.
Obviously this:
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String foldername = com.opencms.file.CmsFile.getPath(cms.getRequestContext().getUri());
CmsJspNavElement element = cms.getNavigation().getNavigationForResource(foldername);
does not work. element points to the link resource.
Any ideas?
Thanks,
Christian Güldner
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 06/10/2003
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20031021/e25eba34/attachment.htm>
More information about the opencms-dev
mailing list