cancel
Showing results for 
Search instead for 
Did you mean: 

Store article content in XML

mikhailponomare
Champ in-the-making
Champ in-the-making
Hi,

Sorry for my English and I is newbie in Alfresco Smiley Happy

I use wcmqs and I've already added some custom attributes (e.g. "writer" ) for article. These attributes are visible when metadata for article is edited.
The next step what I need: store all attributes and content in xml file when user select "create content/xml"  in the Document Library.
e.g.:

<Article xmlns:alf="http://www.alfresco.org" xmlns:chiba="http://chiba.sourceforge.net/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:pr="http://www.alfresco.org/alfresco/pr" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>
some name
</name>
<title>
some title
</title>
<writer>
Mister X
</writer>
<content>
some content of the article
</content>
</Article>

Who knows what should I do in general?  Should I create some web scripts or add/modify java classes or something else ?

WBR, Mikhail Ponomarev.
5 REPLIES 5

bremmington
Champ on-the-rise
Champ on-the-rise
I'm not entirely sure what you plan on doing with the XML once you have it, but here is an idea that may be useful.

Alfresco has a Rendition Service that is useful for generating alternative renditions of a node. Typical examples of this are generating different-sized versions of an image, rendering Word documents as PDFs, creating JPG files from GIFS, and so on. However, there are a couple of rendering engines that are useful for producing alternative representations of text: the FreemarkerRenderingEngine and the XSLTRenderingEngine.

Web Quick Start makes much use of the Rendition Service, and provides a way for rendition definitions to be specified and associated with different sections of the website. You can read about this in the WQS Developer Guide. What I suggest is that you have your editors enter content using the normal forms (so that name, title, writer, and so on have their own entry fields), and setup a rendition definition that uses the FreemarkerRenderingEngine to create an XML rendition of the content.

You can see an example of using Freemarker to render node properties in the Freemarker Template Cookbook on the Alfresco wiki. Note that in this example "document" is used to refer to the node being accessed, but when using the FreemarkerRenderingEngine the name "node" should be used instead. The example is also rendering into HTML instead of XML, but should give the idea.

Hope that helps.

mikhailponomare
Champ in-the-making
Champ in-the-making
What I did:
1. Add the next changes to rendition-context.xml

<bean class="org.alfresco.module.org_alfresco_module_wcmquickstart.rendition.BootstrapRenditionDefinition">
                    <property name="name" value="xmlArticle"/>
                    <property name="renderingEngineName" value="freemarkerRenderingEngine"/>
                    <property name="parameters">
                        <map>
                            <entry key="runAs" value="System"/>
                            <entry key="template_path" value="/Company Home/Data Dictionary/Presentation Templates/xmlArticle.ftl"/>
                        </map>
                    </property>
                </bean>
2. create xmlArticle.ftl (as example above, but I replaced "document" to "node") and load it to /Company Home/Data Dictionary/Presentation Templates/xmlArticle.ftl"
3. Edit metadata for "blog" in Document Library:

V  Inherit Rendition Config (this param is cheked)
Rendition Config:
ws:article=xmlArticle
4. Add create content
5. When I open http://localhost:8080/wcmqs/blog/ My content is available, but xmlArticle.ftl is not used.

What it's wrong ?

bremmington
Champ on-the-rise
Champ on-the-rise
WQS always places rendition definition names into the "ws" namespace, so in your rendition config the setting should be:

ws:article=ws:xmlArticle

However, I'm not really clear about what you're trying to achieve. When you hit your new article on the website what are you expecting to see?

mikhailponomare
Champ in-the-making
Champ in-the-making
I try to explain:
Other external application is needed in "xml-style" article. If we would generate xml per request we got problem with performance. Finally we decided to store article in xml immediately.
What i want to see:
1. somebody is creating xml-content in "Document Library" in alfresco share (e.g. in "blog")
2. She/he fills "Name", "Title", "Description", "Content"
3. As result xml file is created:

<name>
some name
</name>
<title>
some title
</title>
<Description>
Some Description
</Description>
<content>
the content of the article
</content>
</Article>
I don't sure that  Rendition Service is what I need, but i newbie in Alfresco.

bremmington
Champ on-the-rise
Champ on-the-rise
I see. Honestly, I'd be surprised if generating the XML on-the-fly would cause any discernible performance issues at all - especially if your example is illustrative of the complexity. However, it's worth describing how to do it using the static approach you're describing. These are the steps needed:
  1. Create a new content type for our XML renditions so we can configure a special template for them

  2. Make the XML rendition visible in the URL namespace and force it to be of the new content type

  3. Create a template for the new content type that simply pushes out the XML content

  4. Make a template mapping between the new content type and the new template
There are actually a few ways to ensure your XML assets are rendered using a special "pass-through" template. One is to give them a particular content type and then provide a template mapping on a section for that content type. Another approach is to ensure that each request that wants the XML specifies the appropriate template name on the request. For example, if your pass-through template was called "raw" then pass this as the required view on the request:
http://my.example.com/products/my-product.xml?view=raw
The final option (that springs to mind) is to specify the template to be used on the asset itself by setting a value for the ws:templateName property. The value would be "raw" in our example. For the sake of this description, I'll assume the first approach - a custom content type.

  1. The quick and dirty way to define a new content type is to open up the file "webSiteModel.xml" (you'll find it in the exploded alfresco.war if you have WebQS installed) and add the following immediately above the line that contains "</types>":

  2.         <type name="ws:xmlarticle">
                <title>XML Article</title>
                <parent>cm:content</parent>
            </type>

    The more correct way is to define your own content model definition and bootstrap it. I won't go into that here, but you can read about it on the wiki.

  3. Next we need to adjust your rendition definition. Change it to read:

  4.                  <bean class="org.alfresco.module.org_alfresco_module_wcmquickstart.rendition.BootstrapRenditionDefinition">
                        <property name="name" value="xmlArticle"/>
                        <property name="renderingEngineName" value="freemarkerRenderingEngine"/>
                        <property name="parameters">
                            <map>
                                <entry key="runAs" value="System"/>
                                <entry key="template_path" value="/app:company_home/app:dictionary/app:content_templates/cm:xmlArticle.ftl"/>
                                <entry key="destination-path-template" value="${cwd}/${name}.xml" />
                                <entry key="rendition-nodetype" value="{http://www.alfresco.org/model/website/1.0}xmlarticle" />
                            </map>
                        </property>
                    </bean>

  5. We now need to write a template for the WebQS sample site that simply pushes out the content of the requested asset. In the wcmqs webapp, navigate to the WEB-INF/templates folder. We'll create two new files in this folder:
  6. "raw.ftl":

    <@region id="main" scope="template"/>   

    "raw.xml":

    <?xml version="1.0" encoding="UTF-8"?>
    <template-instance>
      <title>Raw</title> 
      <description>Template that just sends the asset content raw</description>
      <template-type>raw</template-type>
      <components>
        <component>
          <region-id>main</region-id>
          <url>/content/current</url>  
        </component>
      </components>      
    </template-instance>

    Then, navigating into the folder WEB-INF/pages, we create one new file, also named "raw.xml":

    <?xml version="1.0" encoding="UTF-8"?>
    <page>
       <id>raw</id>
       <template-instance>raw</template-instance>
       <authentication>none</authentication>
    </page>

    Restart Tomcat now so that all your changes so far are loaded up. Watch out for errors in the log.

  7. Finally, we need to configure WebQS to use the new template for any assets of the new content type. In Share, edit the metadata of the "root" section on the website. In the "Template Mapping" property add a new mapping "ws:xmlarticle=raw". In the sample website as shipped this means that the template mapping on the root section becomes:

  8. cmis:document=baseTemplate,ws:indexPage=sectionpage1,ws:article=articlepage1,ws:xmlarticle=raw
That's it. You should now find that when you create an article in the blog section named "my-blog-post.html", an XML rendition will be created next to it named "my-blog-post.xml". If you point your browser at http://localhost:8080/wcmqs/blog/my-blog-post.xml then the XML rendition should be downloaded.

Note that, while testing out this example, I noticed a fault in the FreemarkerRenderingEngine. You should be able to specify a "mime-type" parameter in your rendition definition to ensure the generated rendition has the correct MIME type ("text/xml" in this case). However, this parameter isn't being exposed, and this means that the MIME type of the rendition is not being set correctly. I've raised this as an issue in Jira (ALF-7039) and will fix it on HEAD when I can. If you want to patch the code yourself, then you just need to add this line to the getParameterDefinitions method in the BaseTemplateRenderingEngine class:

        paramList.add(new ParameterDefinitionImpl(PARAM_MIME_TYPE, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_MIME_TYPE)));

If you do that, then you can add this parameter setting to your xmlArticle rendition definition:

                            <entry key="mime-type" value="text/xml" />

and your XML renditions will then have the correct MIME type.