[opencms-dev] Retrieve Files from Repository

Michael Emmerich m.emmerich at alkacon.com
Fri Feb 11 15:40:37 CET 2011


Sean,

Am 11.02.2011 15:27, schrieb Sean C:
> Does OpenCMS have the capability to programmaticly retrieve files from
> the repository?  For example, is there an API exposed that has a
> function such as getDocument(pathToDoc)?

Everything you need is in the org.opencms.file.CmsObject.

There you have

public CmsResource readResource(String resourcename) throws CmsException

which retunes a CmsResource object, containing everything of a resource 
in OpenCms except the content itself.

And you have

public CmsFile readFile(String resourcename) throws CmsException

which returns a CmsFile that has everything of a CmsResource plus the 
file content.

You should take a closer look to the JavaDocs of the CmsObject, what you 
can do there with files, users, etc.



Form a JSP, you can get the required CmsObject with this code:

CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, 
response);
CmsObject cmsObject = cms.getCmsObject();


-- 
Kind Regards,
Michael.

-------------------
Michael Emmerich

Visit OpenCms Days 2011 Conference and Expo
May 9 to May 10 2011 in Cologne, Germany
http://www.opencms-days.org

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org



More information about the opencms-dev mailing list