[opencms-dev] Re cursive property search

Roman Uhlig roman.uhlig at knve.de
Wed Aug 27 15:15:31 CEST 2008


Hi Robert,

I'd recommend a manual processing and changing of these resources. Using the
OpenCms API that's actually quite easy. 
The most common (though slowest) approach is to recursively iterate through
the OpenCms VFS and check resources for properties. You could try something
like that:

public function recurseVFS(CmsObject cmso, String path) {
	Iterator<CmsFile> iter_files =
((ArrayList)cmso.getFilesInFolder(path)).iterator();
	while (iter_files.hasNext()) {
		CmsFile file = iter_files.next();
		CmsProperty p = cmso.readPropertyObject(file, "MyProperty", true);

		// do something with the file and/or property here

		Iterator iter_folders = ((ArrayList)cmso.getSubFolders(path)).iterator();
		while (iter_folders.hasNext()) {
			CmsFolder folder = iter_folders.next();
			recurseVFS(cmso, cmso.getSitePath(folder));
		}
	}
}

You would initially call recurseVFS() with the VFS path you would
recursively like to start with.

HTH,
Roman



Robert Spielmann-3 wrote:
> 
> Hi all,
> 
> I have a situation in which I need to migrate property values
> automatically in order to preserve existing content and in order to reduce
> or completely avoid manual work on several thousand resources.
> 
> Let's say the property is called "MyProperty" and it currently contains
> values like "a,b,c", "b,c,a" etc. I want to convert them to "x,y,z",
> "y,z,x" etc.
> 
> As there can potentially be a deliberate number of freely chosen
> combinations, I can obviously not use the workplace tools to replace the
> property values.
> 
> Hence, I would like to recursively iterate over all VFS resources in a
> given site, read the property "MyProperty", save the current property
> value and the resource name if a resource has that property set, and then
> go to step 2 and replace the properties on the collected resources.
> 
> If this is programatically possible, can anyone give me a hint on where to
> start?
> 
> I work with OpenCms 6.5.6 which contains custom patches directly from
> Alkacon.
> 
> Have a nice day,
> Robert
> 
> Mit freundlichen Grüßen / Best regards
> 
> Robert Spielmann
> IT Consultant
> 
> -- 
> 
> codecentric GmbH
> Grünewalder Str. 29-31
> 42657 Solingen
> 
> Telefon +49 (212) 2494-322
> Fax +49 (212) 2494-334
> Mobil +49 (151) 14705709
> 
> E-Mail spielmann at codecentric.de
> 
> Internet www.codecentric.de <http://www.codecentric.de/> 
> 
> Geschäftsführer: Peter Gierse, Mirko Novakovic und Rainer Vehns
> Sitz der Gesellschaft: Solingen
> 
> Registergericht: Amtsgericht Wuppertal, HRB 19214
> 
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
> 
> 

-- 
View this message in context: http://www.nabble.com/Recursive-property-search-tp19161767p19180703.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list