[opencms-dev] Put date into a CmsXmlContent
Franck Lazzarini
f.lazzarini at sitasoftware.lu
Thu Sep 1 10:09:52 CEST 2011
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
------------------------------------------------------------------------
<http://www.sita.lu> 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
------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110901/65c43c68/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Logo_Sita.jpg
Type: image/jpeg
Size: 3052 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110901/65c43c68/attachment.jpg>
More information about the opencms-dev
mailing list