[opencms-dev] Re: simple API question

Alexandru Popescu the.mindstorm.mailinglist at gmail.com
Mon Aug 8 10:04:18 CEST 2005


#: Joe Desbonnet changed the world a bit at a time by saying on  8/8/2005 3:48 AM :#
> 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.
> 
> 

The above code is accessing a file on a real FS, but as far as I read in OpenCMS docs everything is 
stored in the DB. What part have I understood wrongly?


thanks for your time,
:alex |.::the_mindstorm::.|

>> 
>> 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.
>>
> 
> 
> _______________________________________________
> 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