SyncFileLinks Advanced Example

This example uses the syncfilelinks macro to generate an Import xml file with changes to be made to exactly mirror the specified folder on disc.

By (built-in) default, the syncfilelinks macro uses contenttype FileLink (FLK) for generating page nodes within this import xml (see example below).

XML CopyCode image Copy Code
<?xml version="1.0"?>
<page update="false">
  <contenttype code="CWP" storage="SixCT.SimpleLookupStorage" />
  <nr>1476</nr>
  <code><![CDATA[FS_INDEXEDCONTENT]]></code>
  <children>
    <page update="false">
      <title><![CDATA[Images]]></title>
      <contenttype code="WP" storage="SixCT.SimpleLookupStorage" />
      <folder type="xsd:boolean">1</folder>
      <defaultcontenttype code="FLK" storage="SixCT.DefaultContentTypeStorage" />
      <nr>2736</nr>
      <code><![CDATA[GUID-242FB159559745488F0F4498B371A359]]></code>
      <children>
        <page update="false">
          <title><![CDATA[IIS 7.0 config]]></title>
          <contenttype code="WP" storage="SixCT.SimpleLookupStorage" />
          <folder type="xsd:boolean">1</folder>
          <defaultcontenttype code="FLK" storage="SixCT.DefaultContentTypeStorage" />
          <nr>2737</nr>
          <code><![CDATA[GUID-7A173C241FA34299B94A0F40D4D1C5B0]]></code>
          <children>
            <page>
              <title><![CDATA[Application Pool - Idle timeout]]></title>
              <contenttype code="FLK" storage="SixCT.SimpleLookupStorage" />
              <filetype code="PNG" storage="SixCT.SimpleLookupStorage" />
              <url><![CDATA[/indexcontent/Images/IIS 7.0 config/Application Pool - Idle timeout.png]]></url>
              <file_lastwritetime type="xsd:dateTime">2010-10-08T13:42:20.000</file_lastwritetime>
              <file_creationtime type="xsd:dateTime">2011-02-10T16:06:17.742</file_creationtime>
              <file_size>38313</file_size>
              <file_extension>.png</file_extension>
            </page>
          </children>
        </page>
      </children>
    </page>
  </children>
</page>

This Import xml contains one page node (the page node with title Application Pool - Idle timeout) which will be added when the xml is imported. The page nodes higher in the hierarchy just reflect the cms hierarchy, so the Importer knows where to insert/update the item (the update=false attribute instructs the Importer not to update the corresponding items).

If you want to use a different contenttype for items referencing files on disc, you need to adjust the generated Import xml. Notice however, the contenttype used must belong to the Reference contenttype group. 
The example below shows you how this can be achieved.

It uses the writefileproperties (introduced in 1.4 build 2) parameter, to have the syncfilelinks macro also output generic file properties for each file (the four nodes in the example above starting with "file_"). Then the xml file is transformed using the transform macro, changing the contenttype used and mapping the file_lastwritetime node to the adddate field.

Smartsite SXML CopyCode image Copy Code
<se:syncfilelinks
    filename="{buffer.get(filename)}"
    item="{buffer.get(parent)}"
    location="{buffer.get(location)}"
    contenttypecodefolders="{buffer.get(ctcode)}"
    writefileproperties="true"
    save="result">
    <se:parameters>
        <se:parameter name="fileexclusionexpressions">
            <se:collection>
                <se:member>^.*\.(db|zip|dll|exe|config)$</se:member>
            </se:collection>
        </se:parameter>
    </se:parameters>
</se:syncfilelinks>

<se:if expression="$result==true">
    <se:transform xml="{filesystem.readtext(buffer.get(filename))}" save="transformedresult">
        <se:parameters>
            <se:parameter name="xslt">
                <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                    <xsl:output method="xml" encoding="UTF-8" cdata-section-elements="title code url" />
                    <xsl:template match="@*|node()">
                        <xsl:copy>
                            <xsl:apply-templates select="@*|node()"/>
                        </xsl:copy>
                    </xsl:template>
                    <xsl:template match="contenttype[@code='FLK']">
                        <contenttype code="REF" storage="SixCT.SimpleLookupStorage" />
                    </xsl:template>
                    <xsl:template match="defaultcontenttype[@code='FLK']">
                        <defaultcontenttype code="REF" storage="SixCT.DefaultContentTypeStorage" />
                    </xsl:template>
                    <xsl:template match="file_lastwritetime">
                        <adddate type="xsd:dateTime">
                            <xsl:value-of select="." />
                        </adddate>
                    </xsl:template>
                    <!-- skip the following nodes -->
                    <xsl:template match="file_creationtime" />
                    <xsl:template match="file_size" />
                    <xsl:template match="file_extension" />
                </xsl:stylesheet>
            </se:parameter>
        </se:parameters>
    </se:transform>
    {filesystem.writetext(buffer.get(filename), string.replace(buffer.get(transformedresult), 'encoding="utf-16"', 'encoding="UTF-8"'))}
</se:if>