[opencms-dev] (no subject) - retrieve xml content manually

Peter Birchmeier peterbirchmeier at hotmail.com
Tue Sep 27 00:12:52 CEST 2005


Thanx, i didn't know that method. But after looking through its source code, 
i think its rather a slow way to retrieve xml content since the xml file 
must be unmarshalled for eaxh element...

I tried to find a way with as less code as possible, which is still fast 
enough.


something like that might do the job:

import org.opencms.jsp.*, org.opencms.main.*, import org.opencms.file.*, 
org.opencms.file.collectors.*, import org.opencms.xml.*, 
org.opencms.xml.content.*;

CmsJspActionElement cms = ..

I_CmsResourceCollector collector = 
OpenCms.getResourceManager().getContentCollector(m_collectorName);
List collectorResult = collector.getResults(cms.getObject(), 
m_collectorName, m_collectorParam);

CmsResource resource = (CmsResource) collectorResult.get( 0..n );

public String getContent( CmsResource resource, String element, Locale 
locale) {
	CmsFile file = CmsFile.upgrade( resource, cms.getCmsObject() );
	I_CmsXmlDocument content = CmsXmlContentFactory.unmarshal( 
cms.getCmsObject(), file );

	Locale loc = OpenCms.getLocaleManager().getBestMatchingLocale( locale,
		OpenCms.getLocaleManager().getDefaultLocales(cms, 
cms.getSitePath(resource)),
		content.getLocales(element));

	return content.getStringValue( element, loc );
}

hmmm.. i'm not sure if it is a good idea to use too much code..
maybe anybody has a better idea? The most practical way would be if 
xmlcontentload-tags could be used together with scriptlets that request a 
specific xml content element from the loaded xml file...



>From: Bernd Wolfsegger <bw at code-create.com>
>Reply-To: Bernd Wolfsegger <bw at code-create.com>,The OpenCms mailing list 
><opencms-dev at opencms.org>
>To: The OpenCms mailing list <opencms-dev at opencms.org>
>Subject: Re: [opencms-dev] (no subject)
>Date: Mon, 26 Sep 2005 16:19:58 +0300
>
>Hi Peter,
>
>simply use "cms.getContent(String resourcePath, String elementName, Locale
>locale)"
>
>Kind Regards, Bernd Wolfsegger
>
>On Monday, 26. September 2005 16:02, Peter Birchmeier wrote:
> > Hi,
> >
> > I do a xml files load and query single xml elements by 
><cms:contentshow..
> > I'ld like to be able to have more options with the output, e.g. check a
> > certain element whether it is empty or not (empty String "", not null).
> >
> > I couldn't find any way with the given standard xml tags. Have I 
>overseen
> > anything?
> >
> > So my idea was to manually query the elements by jsp scriptlets. But as 
>far
> > as I have seen in the CmsJspContentShowTag source code I would have to
> > implement several steps to achieve the data. Therefore it might be 
>easier
> > to do the whole xml content load manually, by calling the responsible
> > Collector class....
> >
> > Is there a better way?
> > thanks for your hints,
> > kind regards, Peter
> >
> > _________________________________________________________________
> > Behalten Sie Ihre Hotmails, den Messenger und die Suchfunktionen stets 
>im
> > Auge! http://toolbar.msn.ch?&DI=165&XAPID=2170 Jetzt downloaden!
> >
> >
> >
> > _______________________________________________
> > 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
>
>--
>
>[  Code Create
>[  Web Content Management and Presentation
>
>
>[  Bernd Wolfsegger
>[  Sun Certified Programmer for Java(TM) 2 Platform
>
>
>[  Lohmeyerstrasse 13
>[  10587 Berlin
>[  Germany
>[  Fon +49 (0)30 26555788
>[  Fax +49 (0)30 2651835
>[  Mobile +49 (0)163 6505622
>
>[  bw at code-create.com
>[  http://www.code-create.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

_________________________________________________________________
Essenzielle Infos von A-Z! Starten Sie eine Online-Recherche mit MSN Search! 
http://search.msn.ch/ Jetzt neu! Jetzt gratis downloaden!




More information about the opencms-dev mailing list