[opencms-dev] Problem with CmsXmlPageFactory.unmarshal creating only empty pages
Paul-Inge Flakstad
flakstad at npolar.no
Thu Feb 11 14:40:59 CET 2010
Hi Eska
I just tested some equivalent code on my system (OpenCms v7.5.1), with the same result.
I think maybe the class CmsXmlPage is intended for the resource type "xmlpage" and not "xmlcontents" (AKA structured content).
Maybe you can use somehting like this instead, it's what I normally do (although this is a very simplified example, you'll need to look at the docs):
CmsResource res = cmsObj.readResource("/your/file/name");
I_CmsXmlDocument xmlDoc = CmsXmlContentFactory.unmarshal(cmso, cmso.readFile(res));
I_CmsXmlContentValue val = xmlDoc.getValue(("Headline[1]"), locale); // Index starts at 1 not 0
out.println("Headline[1] = " + val.getStringValue(cmsObj));
HTH.
Cheers,
Paul
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Eska
> Sent: 11. februar 2010 12:11
> To: opencms-dev at opencms.org
> Subject: [opencms-dev] Problem with
> CmsXmlPageFactory.unmarshal creating only empty pages
>
>
> Hi List,
>
> I am trying to program me a little jsp tool that does the same as
> CmsMergePages.mergePages(),
> but somehow the call to CmsXmlPageFactory.unmarshal() only
> creates empty
> CmsXmlPage
> objects for me.
>
>
> String resPathDe = "/sites/abc/de/test.html";
> String resPathEn = "/sites/abc/en/testa.html";
>
> CmsFile resFileDe = cmsObj.readFile(resDe);
> CmsFile resFileEn = cmsObj.readFile(resEn);
>
> Locale de = new Locale("de");
> Locale en = new Locale("en");
>
>
> CmsXmlPage xmlPageDe = CmsXmlPageFactory.unmarshal(cmsObj, resFileDe);
> CmsXmlPage xmlPageEn = CmsXmlPageFactory.unmarshal(cmsObj, resFileEn);
>
> Locale locDe = new Locale("de");
> Locale locEn = new Locale("en");
>
> List textElements2 = xmlPageEn.getNames(locEn );
> Iterator j = textElements2.iterator();
> while (j.hasNext()) {
> String textElementName = (String)j.next();
> String textElement = xmlPageEn.getValue(textElementName,
> locEn).getStringValue(cmsObj);
>
> if (!xmlPageDe.hasValue(textElementName, locEn)) {
> xmlPageDe.addValue(textElementName, locEn);
> }
> xmlPageDe.setStringValue(cmsObj, textElementName, locEn,
> textElement);
> }
> ...
>
> When now trying to combine both page contents like in the
> CmsMergePages.mergePages() method,
> an empy content is created only containing only the following:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://www.opencms.org/dtd/6.0/
> xmlpage.xsd"></pages>
>
>
> I gathered the following data:
>
> resFileDe.getContents().length: 889
> resFileEn.getContents().length: 1024
> xmlPageDe.getNames(de).size(): 0
> xmlPageEn.getNames(en).size(): 0
> xmlPageDe.getValues(de).size(): 0
> xmlPageEn.getValues(en).size(): 0
> xmlPageDe.getLocales().size(): 0
> xmlPageEn.getLocales().size(): 0
> textElements2.size()=0
>
> My two files have normal content like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ArticlePages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="opencms://system/modules/my.tes
> t.module/schemas/articlepage.xsd">
> <ArticlePage language="de">
> <Status><![CDATA[7]]></Status>
> <TopProject>false</TopProject>
> <Headline><![CDATA[This is a Headline!]]></Headline>
> <Text name="Text0">
> ...
>
> </ArticlePage>
> </ArticlePages>
>
> Is it the wrong way to try to merge to contents?
>
> Thanks,
>
> Eska.
> --
> View this message in context:
> http://old.nabble.com/Problem-with-CmsXmlPageFactory.unmarshal
-creating-only-empty-pages-tp27544324p27544324.html
> Sent from the OpenCMS - Dev mailing list archive at Nabble.com.
>
>
> _______________________________________________
> 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
>
More information about the opencms-dev
mailing list