[opencms-dev] Re: simple API question
Joe Desbonnet
jdesbonnet at gmail.com
Mon Aug 8 03:48:06 CEST 2005
I think I've solved that problem: sorry for posting the question. Just
to summarize:
if I have a.jpg and b.jpg in a directory and I have CmsObject for
a.jpg and I want
to get the contents of b.jpg:
// Start with imgObjectA, the CmsObject corresponding to 'a.jpg'.
// Want to get byte[] of the contents of 'b.jpg' in the same directory.
String folderUri = imgObjectA.getRequestContext().getFolderUri();
CmsResource folderResource = imgObjectA.readResource(folderUri);
// get path to folder relative to root of site
String folderSitePath = imgObjectA.getSitePath(folderResource);
CmsFile fileB = imgObjectA.readFile (folderSitePath + "b.jpg");
byte[] contentB = fileB.getContents();
imgObjectA.getRequestContext().getFolderUri(); was the vital method I
was missing.
Thanks,
Joe.
>
> I have the CmsObject ('imgObj') and CmsFile ('imgFile') objects
> representing 'a.jpg'.
>
> I need to able to access the content (ie by getting a CmsFile
> instance) of b.jpg.
>
> So far I have:
>
> String requestUri = imgObject.getRequestContext().getUri();
>
> CmsResource imgResource = imgObject.readResource(requestUri);
>
>
> // path of image relative to root of VFS
>
> String imgRootPath = imgFile.getRootPath();
>
> // path of image relative to root of site
>
> String imgSitePath = imgObject.getSitePath(imgResource);
>
> // path of parent folder relative to root of VFS
>
> String parentRootPath = CmsFile.getFolderPath(imgRootPath);
>
> // path of parent folder relative to root of site
> CmsResource parentResource = ????????????????????;
> String parentSitePath = imgObject.setSitePath(parentResource)
>
> I know I can do it by hacking the paths manually with String.spli()
> etc, but I'm sure there is a cleaner solution...
>
> Any suggestions?
>
> Thanks,
> Joe.
>
More information about the opencms-dev
mailing list