<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="https://www.smooks.org/xsd/smooks/freemarker-2.0.xsd"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:smooks="https://www.smooks.org/xsd/smooks-2.0.xsd"
           xmlns:ftl="https://www.smooks.org/xsd/smooks/freemarker-2.0.xsd">

    <xs:import namespace="https://www.smooks.org/xsd/smooks-2.0.xsd"/>

    <xs:annotation>
        <xs:documentation xml:lang="en">FreeMarker Templating Configuration</xs:documentation>
    </xs:annotation>

    <xs:element name="freemarker" type="ftl:freemarker" substitutionGroup="smooks:abstract-resource-config">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                FreeMarker Templating Configuration.
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="freemarker">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                FreeMarker Templating Configuration Type.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="smooks:element-visitor">
                <xs:sequence>
                    <xs:element name="template" type="ftl:template" />
                    <xs:element name="use" type="ftl:use" minOccurs="0" />
                    <xs:element ref="smooks:param" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
                <xs:attribute name="applyOnElement" type="xs:string" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            The name of the element on which the template is to be applied.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="applyBefore" type="xs:boolean" use="optional" default="false">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            Apply the template before visiting the elements child content.<p/>Default is 'false'.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="template">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                The FreeMarker Template.
                <p/>
                This can be an inline template, or a reference (URI) to an externally defined template (filesystem, classpath, www).
            </xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="encoding" type="xs:string" use="optional" default="UTF-8">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            Template character encodng.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="use">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                The &lt;use&gt; element allows you to define how the templating result is to be used.
            </xs:documentation>
        </xs:annotation>
        <xs:choice minOccurs="0" maxOccurs="1">
            <xs:element name="inline" type="ftl:inline" />
            <xs:element name="bindTo" type="ftl:bindTo" />
            <xs:element name="outputTo" type="ftl:outputTo" />
        </xs:choice>
    </xs:complexType>

    <xs:complexType name="inline">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                Inline the templating result into the <b>Smooks.filter</b> Result message.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="directive" type="ftl:inlineDirective" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    How the templating result is to be used (relative to the element on which it
                    is applied).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="bindTo">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                Bind the templating result into the bean context under the specified "id".  This makes the
                templating result available for routing or other operations.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="id" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The bean context ID under which the templating result is to be bound if the "BIND_TO" action is chosen.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="outputTo">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                Output the templating result to a named OutputStreamResource.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="outputStreamResource" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The name of the "outputStreamResource" to which the templating result is to be written.  By default,
                    the templating result is written to the  Smooks.filter result if (if a StreamResult is provided).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:simpleType name="inlineDirective">
		<xs:restriction base="xs:string">
            <xs:enumeration value="ADD_TO" />
            <xs:enumeration value="REPLACE" />
            <xs:enumeration value="INSERT_BEFORE" />
            <xs:enumeration value="INSERT_AFTER" />
		</xs:restriction>
	</xs:simpleType>

</xs:schema>