AW: [opencms-dev] Code: File Exists?
Thomas Weckert
t.weckert at alkacon.com
Fri Jul 25 18:01:00 CEST 2003
Hii,
testing for the existence of the title property on a resource is not
sufficient. Instead, you would try to read the file header of a
resource. If the resource doesnt exist you will catch a CmsException.
The costs of reading the file header are not too high, since the file
header excludes the file content.
private boolean exists(CmsObject cms, String resourcename) {
boolean result = false;
try {
cms.readFileHeader(resourcename);
result = true;
} catch (CmsException e) {
result = false;
}
return result;
}
Regards,
Thomas Weckert
Alkacon Software - The OpenCms Experts
http://www.alkacon.com
-----Ursprüngliche Nachricht-----
Von: opencms-dev-admin at opencms.org
[mailto:opencms-dev-admin at opencms.org] Im Auftrag von Jens Rickhoff
Gesendet: Freitag, 25. Juli 2003 15:50
An: opencms-dev at opencms.org; Tim.Mundy at babelfish.com
Betreff: Re: [opencms-dev] Code: File Exists?
Hi Tim,
I solved it by trying to access a property of the resource (i.e.
file/folder). If that method throws a CmsException, I know the file does
not exist (or that any other serious exception occured). It works fine
for me, here's the JSP snippet:
private boolean exist(CmsJspActionElement cms, String resource) {
boolean result = true;
try {
String test = cms.getCmsObject().readProperty(resource, "title",
false, "title");
} catch (com.opencms.core.CmsException e) {
result = false;
}
return result;
}
However, I'd prefer a "real" CmsObject.resourceExists() method...
Hope that helps,
Jens
----- Original Message -----
From: Tim Mundy
To: opencms-dev at opencms.org
Sent: Wednesday, July 16, 2003 11:46 PM
Subject: [opencms-dev] Code: File Exists?
Hello List,
In a module that I'm developing, I'm trying to confirm that a path
(string) points to an existing file. I can't seem to find a method that
will return a boolean if a file exists or not. Does anyone know of a
method in OpenCms that would do the job? I'm sure someone else has had
this issue come up before.
Thanks,
Tim Mundy
Software Developer
E-mail: Tim.Mundy at babelfish.com
Phone: 780.944-9964
Fax: 780.432.5700
The Babel Fish Corporation
Where the World comes to Communicate!!
This e-mail message (including attachments, if any) is intended for the
use of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt
from disclosure. If you are not the intended recipient, you are notified
that any dissemination, distribution or copying of this communication is
strictly prohibited. If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
------------------------------------------------------------------------
---
Le présent message électronique (y compris les pièces qui y sont
annexées, le cas échéant) s'adresse au destinataire indiqué et peut
contenir des renseignements de caractère privé ou confidentiel. Si vous
n'êtes pas le destinataire de ce document, nous vous signalons qu'il est
strictement interdit de le diffuser, de le distribuer ou de le
reproduire. Si ce message vous a été transmis par erreur, veuillez en
informer l'expéditeur et le supprimer immédiatement. www.babelfish.com
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please
visit http://mail.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list