[opencms-dev] Put date into a CmsXmlContent

Christoph Fröhlich cfauto at folge2.de
Tue Sep 6 20:33:13 CEST 2011


Hi Franck,

did you try to create a XmlContentDocSimpleType in workplace, edit it manually and have a look at it's xml-content via right-click-on-content -> advanced/edit controlcode

When doing this on one of the demo events that come with opencms 8 (/.content/event/e_00001.html), i can see that  dates are stored in the following way:

    <EventDates>
      <EventStartDate>1314266400000</EventStartDate>
      <EventEndDate>1314637200000</EventEndDate>
    </EventDates>

Does this help?
Regards 
c

Am 01.09.2011 um 10:09 schrieb Franck Lazzarini:

> Hi there,
> 
> I have the following problem, I have defined a xsd file for structured Xml Content, and I want to use a jsp to fill this XML File. Filling in strings already works, but I wanted to add a Date Field which I can't seem to fill in. Here is how my stuff works already... I copy a "template" html xml structured content to a new resource and open up that resource and fill in the values of the xml elements. The only thing I don't know how to add is the DateField.
> 
> Thanks for helping me out.
> 
> -- newstemplate.xsd --
> 
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
> <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd" />
> <xsd:element name="XmlContentDocSimpleTypes" type="OpenCmsXmlContentDocSimpleTypes" />
> <xsd:complexType name="OpenCmsXmlContentDocSimpleTypes">
>     <xsd:sequence>
>         <xsd:element name="XmlContentDocSimpleType" type="OpenCmsXmlContentDocSimpleType" minOccurs="0"       maxOccurs="unbounded" />
>     </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name="OpenCmsXmlContentDocSimpleType">
>     <xsd:sequence>
>         <xsd:element name="Title" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
>         <xsd:element name="Teaser" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
>         <xsd:element name="Text" type="OpenCmsHtml" minOccurs="1" maxOccurs="1" />
>         <xsd:element name="ReleaseDate" type="OpenCmsDateTime" minOccurs="1" maxOccurs="1" />
>         <xsd:element name="Author" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
>     </xsd:sequence>
>     <xsd:attribute name="language" type="OpenCmsLocale" use="required" />
> </xsd:complexType>
> <xsd:annotation>
>     <xsd:appinfo>
>         <resourcebundle name="com.alkacon.documentation.xmlcontentdemo.workplace"/>
>         <mappings>
>             <mapping element="Title" mapto="property:Title" />
>             <mapping element="ReleaseDate" mapto="attribute:datereleased" />
>         </mappings>
>         <defaults>
>             <default element="Title" value="" />
>             <default element="Teaser" value="" />
>             <default element="ReleaseDate" value="${currenttime}"/>        
>             <default element="Author" value="${currentuser.fullname}"/>    
>         </defaults>
>         <layouts>
>             <layout element="Text" widget="HtmlWidget" configuration="source,link,anchor,formatselect,image,table,imagegallery,downloadgallery,linkgallery,htmlgallery,tablegallery,height:400px" />
>         </layouts>
>     </xsd:appinfo>
> </xsd:annotation>  
> </xsd:schema>
> 
> 
> -- newstemplate.html --
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <XmlContentDocSimpleTypes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="opencms://sites/test/newstemplate.xsd">
>   <XmlContentDocSimpleType language="en">
>     <Title/>
>     <Teaser/>
>     <Text name="Text0">
>       <links/>
>       <content/>
>     </Text>
>     <ReleaseDate />
>     <Author/>
>   </XmlContentDocSimpleType>
> </XmlContentDocSimpleTypes>
> 
> 
> -- my.jsp --
> ...all imports and stuff...
> output is a string
> pubdate is a long
> ............................
> 
> 
>     CmsObject cms = OpenCms.initCmsObject("Guest");
>     cms.loginUser("foo", "bar");
>     CmsProject project = cms.readProject("Offline");
>     cms.getRequestContext().setCurrentProject(project);
>     cms.getRequestContext().setSiteRoot(siteroot);
> 
>     String filename = "/news001.html";
>     String filenameResname = cms.getRequestContext().getFileTranslator().translateResource(filename);
>     int filenameResTypeId  = OpenCms.getResourceManager().getDefaultTypeForName(filename).getTypeId();
> 
>     # Make a copy of the template html
>     cms.copyResource("/newstemplate.html", filename, CmsResource.COPY_AS_NEW);
> 
>     CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(cms, cms.readFile(filename));
>     I_CmsXmlContentValue xmlContentValue = null;
>             
>     xmlContentValue = xmlContent.getValue("Title", new Locale("en"));
>     xmlContentValue.setStringValue(cms, title);
>     xmlContentValue = xmlContent.getValue("Teaser", new Locale("en"));
>     xmlContentValue.setStringValue(cms, output);
>     xmlContentValue = xmlContent.getValue("Text", new Locale("en"));
>     xmlContentValue.setStringValue(cms, output);
>     xmlContentValue = xmlContent.getValue("Author", new Locale("en"));
>     xmlContentValue.setStringValue(cms, author);
>     xmlContentValue = xmlContent.getValue("ReleaseDate", new Locale("en"));
>     xmlContentValue.setStringValue(cms, String.valueOf(pubdateDate.getTime()));
>             
> 
>     String xmlContentNews = cms.getRequestContext().getFileTranslator().translateResource(filename);
>     cms.lockResource(xmlContentNews);
>     CmsFile xmlFile = xmlContent.getFile();
>     xmlFile.setContents(xmlContent.marshal());
>     cms.writeFile(xmlFile);
> 
> 
> 
> 
> -- 
> Mat frendlechen Gréiss
> 
> <Logo_Sita.jpg>             	Frank Lazzarini
> Programmeur	 Sita Software S.A.
> 220, avenue de la Liberté
> L-4602 Niederkorn
> Grand Duché de Luxembourg
> Tel: (+352) 58 00 93-32
> Fax: (+352) 58 00 94
> 
> _______________________________________________
> 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