[opencms-dev] Information about content tool "Convert XML content" ?

Kunicke, Holger holger.kunicke at av-studio.de
Thu Sep 8 14:25:20 CEST 2011


Hi Mario,

thanks for the tips. At reading the step 3 I'd become big eyes for some seconds 
... 8-/

If just other like me need to change the resource type of some more resources, 
I've create a JSP scriptlet with an simple loop over these:

<%@ page import="org.opencms.jsp.*,org.opencms.file.*,java.util.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><%

CmsJspActionElement jsp = new CmsJspActionElement(pageContext, request, response);
CmsObject cms = jsp.getCmsObject();

int oldTypeId = 407;
int newTypeId = 508;
String resPath = "/test";

List<CmsResource> resList = cms.readResources(resPath, 
CmsResourceFilter.requireType(oldTypeId) );

for ( CmsResource res : resList ) {
     res.setType(newTypeId);
     cms.lockResource(cms.getSitePath(res));
     cms.writeResource(res);
     cms.unlockResource(cms.getSitePath(res));
}

%>

Kind Regards,
Holger

Am 27.06.2011 11:03, schrieb Mario Jäger:
> Hi Hein,
>
> ...
>
> (3) You select in the content menu from the file to convert
> /sites/default/xmlpageconv/xmlpage.html "Advanced" ->  "Change type" and
> select "Alkacon newsletter" and "Ok". Then, you have changed the
> resource type from that file from "xmlpage" to "alkacon-newsletter".
>
> ...
>
> Because, changing the resource type from "xmlpage" to
> "alkacon-newsletter" only works directly on the file, you can not do
> step 3 for all xml pages at once. If you do not want to do step 3 for
> each file separate, you could something implement to change the resource
> type from "xmlpage" to the other xml content resource type for all xml
> pages at once.
>
> Kind Regards,
> Mario.
>
>
>
> Am 22.06.2011 21:15, schrieb Hein van der Kallen:
>> Mario,
>> You gave a  very helpful explanation.
>>
>> additional question :
>> Is it possible to use the same "Convert XML content"  to convert xml-pages
>> to xml-content ?
>> Is there also an example of such a conversion ?
>>
>> We use xml-pages heavily since opencms 5.0.
>> But it seems to become a forgotten corner in opencms.
>>
>> opencms 8 seems to be no improvement for mainly xml-page sites.
>>
>> Would a conversion to xml-content be useful ? why ?
>> or even necessary ?
>>
>> Greetings
>> Hein van der Kallen
>>
>> ----- Original Message -----
>> From: "Mario Jäger"<m.jaeger at alkacon.com>
>> To:<opencms-dev at opencms.org>
>> Sent: Wednesday, June 22, 2011 10:33 AM
>> Subject: Re: [opencms-dev] Information about content tool "Convert XML
>> contents" ?
>>
>>
>>> Hi Holger,
>>>
>>> Yes, the output "Error while transformation." is not very meaningful.
>>> But, this is improved in the current OpenCms head already. In case of an
>>> error you get more information then.
>>>
>>> Here is a little example how to use that tool.
>>>
>>> (1) You have a test folder /sites/default/xmlkonv/ with the resource
>>> photoalbum.html from resource type "photoalbum" with that xml content:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>>
>>> <PhotoAlbumConfigurations
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd">
>>>     <PhotoAlbumConfiguration language="en">
>>>       <Title><![CDATA[Test]]></Title>
>>>       <VfsFolder/>
>>>       <AlignNavigation><![CDATA[left]]></AlignNavigation>
>>>       <NavigationPosition><![CDATA[b_b]]></NavigationPosition>
>>>       <ShowResourceNameAsTitle>false</ShowResourceNameAsTitle>
>>>       <Thumbs>
>>>         <ShowTitle>false</ShowTitle>
>>>         <AlignTitle><![CDATA[left]]></AlignTitle>
>>>         <Cols><![CDATA[3]]></Cols>
>>>         <Rows><![CDATA[3]]></Rows>
>>>         <HighQuality>false</HighQuality>
>>>         <Size><![CDATA[150x113]]></Size>
>>>         <Filter><![CDATA[none]]></Filter>
>>>         <Background>#000000</Background>
>>>       </Thumbs>
>>>       <Details>
>>>         <ShowTitle>false</ShowTitle>
>>>         <ShowDescription>false</ShowDescription>
>>>         <AlignTitle><![CDATA[left]]></AlignTitle>
>>>         <ShowLinkOriginal>false</ShowLinkOriginal>
>>>         <Size><![CDATA[600x450]]></Size>
>>>         <Filter><![CDATA[none]]></Filter>
>>>         <Background>#000000</Background>
>>>       </Details>
>>>     </PhotoAlbumConfiguration>
>>> </PhotoAlbumConfigurations>
>>>
>>> (2) Create a copy from file
>>> /system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd
>>> as photoalbum_new.xsd.
>>>
>>> (3) In folder /sites/default/ you have the xsl file
>>> convert_photoalbum.xsl. That file contains the convert rules. In that
>>> example, that file only makes that the file to convert will be written
>>> again. But, in the new written file the path to the main schema file
>>> goes to the new xsd main file "photoalbum_new.xsd" created in (2) then.
>>> The content from the xsl file is that:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <xsl:stylesheet version="2.0"
>>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>>
>>>       <xsl:template match="/">
>>>           <PhotoAlbumConfigurations
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
>>>               <xsl:apply-templates/>
>>>           </PhotoAlbumConfigurations>
>>>       </xsl:template>
>>>
>>>       <xsl:template match="PhotoAlbumConfigurations">
>>>               <xsl:apply-templates/>
>>>           </xsl:template>
>>>
>>>       <xsl:template name="" match="* | @*">
>>>           <xsl:copy>
>>>               <xsl:apply-templates select="* |  @* | text()"/>
>>>           </xsl:copy>
>>>       </xsl:template>
>>>
>>>       <xsl:template match="//PhotoAlbumConfiguration">
>>>           <xsl:variable name="lang" select="@language" />
>>>
>>>               <xsl:element name="PhotoAlbumConfiguration"
>>> use-attribute-sets="PhotoAlbumConfigurationAttributes">
>>>                   <xsl:apply-templates/>
>>>               </xsl:element>
>>>          </xsl:template>
>>>
>>>        <xsl:attribute-set name="PhotoAlbumConfigurationAttributes">
>>>           <xsl:attribute name="language"><xsl:value-of
>>> select="@language"/></xsl:attribute>
>>>       </xsl:attribute-set>
>>>
>>> </xsl:stylesheet>
>>>
>>> (4) You go in the root site. In the content tool "Convert XML contents"
>>> you configure the following settings:
>>>
>>> - "Resource type": "photoalbum"
>>>
>>> - "VFS folder": /sites/default/xmlkonv/
>>>
>>> - "Include subfolders": not selected
>>>
>>> - "Transformation file (xsl)": /sites/default/convert_photoalbum.xsl
>>>
>>> - "Only count files": not selected
>>>
>>> Start the convert tool with "Ok" then.
>>>
>>> That is the report output then:
>>>
>>> Start Thread transforming XML contents.
>>> Start transforming xml contents.
>>> Parameters:
>>> Resource path: /sites/default/xmlkonv/
>>> Inclusive sub folders: false
>>> Xslt file: /sites/default/convert_photoalbum.xsl
>>> Only count files to transform: false
>>> New xsd main file:
>>> opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd
>>> Start searching for files to transform...
>>> Number of files found to transform: 1
>>> Transform (published) file (encoding type):
>>> /sites/default/xmlkonv/photoalbum.html (UTF-8)
>>> Publishing files...
>>> Result:
>>> Number of files found to transform: 1
>>> Number of files already transformed: 0
>>> Number of errors while transforming: 0
>>> Number of locked files (could not become transformed): 0
>>> All files could become transformed successful.
>>> Finished transforming xml contents.
>>> Statistics:duration: 00:00:02
>>> End Thread transforming XML contents.
>>>
>>> (5) The converted file photoalbum.html has that content then:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>>
>>> <PhotoAlbumConfigurations
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
>>>     <PhotoAlbumConfiguration language="en">
>>>       <Title><![CDATA[Test]]></Title>
>>>       <VfsFolder/>
>>>       <AlignNavigation><![CDATA[left]]></AlignNavigation>
>>>       <NavigationPosition><![CDATA[b_b]]></NavigationPosition>
>>>       <ShowResourceNameAsTitle>false</ShowResourceNameAsTitle>
>>>       <Thumbs>
>>>         <ShowTitle>false</ShowTitle>
>>>         <AlignTitle><![CDATA[left]]></AlignTitle>
>>>         <Cols><![CDATA[3]]></Cols>
>>>         <Rows><![CDATA[3]]></Rows>
>>>         <HighQuality>false</HighQuality>
>>>         <Size><![CDATA[150x113]]></Size>
>>>         <Filter><![CDATA[none]]></Filter>
>>>         <Background>#000000</Background>
>>>       </Thumbs>
>>>       <Details>
>>>         <ShowTitle>false</ShowTitle>
>>>         <ShowDescription>false</ShowDescription>
>>>         <AlignTitle><![CDATA[left]]></AlignTitle>
>>>         <ShowLinkOriginal>false</ShowLinkOriginal>
>>>         <Size><![CDATA[600x450]]></Size>
>>>         <Filter><![CDATA[none]]></Filter>
>>>         <Background>#000000</Background>
>>>       </Details>
>>>     </PhotoAlbumConfiguration>
>>> </PhotoAlbumConfigurations>
>>>
>>> The only difference to (1) is that snippet in the third line:
>>>
>>> ...
>>> xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
>>>
>>> In (1) that line was that:
>>>
>>> ...
>>> xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd">
>>>
>>> The converted file is not published.
>>>
>>>
>>> The most important thing is, that you create a new main schema file (in
>>> that example photoalbum_new.xsd). That file you have to use in the xsl
>>> file. With that new xsd file is proved in OpenCms if a file was
>>> converted already.
>>>
>>> If you want to have the original xsd file name in your converted file,
>>> you have to do the convert twice. In the first convert you have to do
>>> the necessary convert. And in the second convert you can go back to the
>>> original xsd file name like done in the example in that mail.
>>>
>>> Kind Regards,
>>> Mario.
>>>
>>>
>>>
>>> Am 21.06.2011 11:38, schrieb Kunicke, Holger:
>>>> Hello All,
>>>>
>>>> does someone has information or docs about transforming xmlcontent
>>>> resources
>>>> with the content tool "Convert XML contents".
>>>> I need more information than the output "Error while transformation." :-(
>>>>
>>>> Which XSL transformation method can I use to simulate the content
>>>> transformation
>>>> (at local client) ?
>>>> Are there other constraints?
>>>>
>>>> Greetings
>>>> Holger


-- 
_________________________________________
Holger Kunicke
Webentwickler

AV-Studio Kommunikationsmedien GmbH Halle
Stephanusstraße 2
D-06114 Halle (Saale)

Tel.: +49 (0) 345 20 999 -0
Fax:  +49 (0) 345 20 999 -20

Mail: holger.kunicke at av-studio.de
Web:  www.av-studio.de

Amtsgericht Stendal: HRB 211368
Ust-Id-Nr.: DE 191537712
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯




More information about the opencms-dev mailing list