<?xml version="1.0" encoding="UTF-8" ?>

<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:a="http://relaxng.org/ns/annotation/0.9">
<!--
RelaxNG schema for CLAM XML
    by Maarten van Gompel
	Centre for Language Studies
	Radboud University

    http://ilk.uvt.nl/clam
    http://github.com/proycon/clam

    Validation examples:
     $ xmllint ‒‒relaxng clam.rng clamresponse.xml
     $ jing clam.rng clamresponse.xml

    Licensed under the GNU General Public License v3
-->

<start>
	<element name="clam" xmlns="http://relaxng.org/ns/structure/1.0" xmlns:a="http://relaxng.org/ns/annotation/0.9">
		<attribute name="id">
		    <a:documentation>The ID of the webservice</a:documentation>
		</attribute>
		<attribute name="version">
		    <a:documentation>Defines the version of CLAM used</a:documentation>
		</attribute>
		<attribute name="baseurl">
		    <a:documentation>Defines the root URL of the CLAM service</a:documentation>
		</attribute>
		<attribute name="name">
		    <a:documentation>Defines a human readable name of the CLAM service</a:documentation>
		</attribute>
		<optional>
		    <attribute name="user">
		        <a:documentation>The username of the logged-in user. Defaults to 'anonymous' if no authentication is enabled.</a:documentation>
		    </attribute>
		</optional>
		<optional>
		    <attribute name="project">
		        <a:documentation>The ID of the project this CLAM document is representing. If not present, then the CLAM XML file represents a more general state of the system and provides a listing of projects</a:documentation>
		    </attribute>
		</optional>
		<optional>
		    <attribute name="interfaceoptions">
		        <a:documentation>A set of options for rendering the user interface</a:documentation>
		    </attribute>
		</optional>
		<optional>
		    <attribute name="authentication">
		        <a:documentation>The authentication method used (basic, digest, oauth, preauth or none)</a:documentation>
		    </attribute>
		</optional>
		<element name="description">
		    <a:documentation>A human readable description of the service.</a:documentation>
		    <text />
		</element>
        <optional>
            <element name="version">
                <a:documentation>Defines the version of the system (the underlying tool or the webservice itself)</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="author">
                <a:documentation>Defines the author(s) of the system (the underlying tool or the webservice itself)</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="email">
                <a:documentation>Defines the e-mail address of the contact person for this system</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="license">
                <a:documentation>Defines license of the software</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="url">
                <a:documentation>Defines a website associated with this system, like its homepage or a source code repository.</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="parenturl">
                <a:documentation>Defines a website that this webservice is part of, like an institution website or portal</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="loginurl">
                <a:documentation>Defines an external URL that handles logins</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="logouturl">
                <a:documentation>Defines an external URL that handles logouts</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="registerurl">
                <a:documentation>Defines an external URL that handles account registrations</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
            <element name="coverurl">
                <a:documentation>Defines an external URL to a cover image for the interface</a:documentation>
                <text />
            </element>
        </optional>
        <optional>
		<element name="customhtml">
		    <a:documentation>Custom HTML for the interface</a:documentation>
		    <text />
		</element>
        </optional>
        <optional>
		<element name="customcss">
		    <a:documentation>Custom CSS for the interface</a:documentation>
		    <text />
		</element>
        </optional>
		<optional>
		    <element name="actions">
                <a:documentation>Defines the actions that this webservice provides.</a:documentation>
		        <zeroOrMore>
                    <ref name="action"/>
		        </zeroOrMore>
            </element>
        </optional>
		<optional>
		    <element name="projects">
		        <a:documentation>Contains a list of all available projects. The list may differ based on the logged in user.</a:documentation>
		        <zeroOrMore>
		            <element name="project">
		                <a:documentation>Link to one of the available projects.</a:documentation>
		                <attribute name="type" ns="http://www.w3.org/1999/xlink">
		                    <a:documentation>XLink type, always "simple"</a:documentation>
		                </attribute>
		                <attribute name="href" ns="http://www.w3.org/1999/xlink">
		                    <a:documentation>XLink reference to the URL of the project. URL holds the CLAM XML document for the project</a:documentation>
		                </attribute>
		                <attribute name="time">
		                    <a:documentation>Time the project was last modified. In "YYYY-MM-DD hh:mm:ss" format</a:documentation>
		                </attribute>
		                <attribute name="status">
		                    <a:documentation>The status code of the project: 0 = staging, accepting input, 1 = running, 2 = completed, presenting output</a:documentation>
		                </attribute>
		                <attribute name="size">
		                    <a:documentation>The size of the project on disk, in MB</a:documentation>
		                </attribute>
		                <text />
		            </element>
		        </zeroOrMore>
		    </element>
		</optional>
		<optional>
		    <element name="status">
		        <a:documentation>Provides the status of a project</a:documentation>
		        <attribute name="code">
		            <a:documentation>The status code represents the state the project is in: 0 = staging, accepting input, 1 = running, 2 = completed, presenting output</a:documentation>
		        </attribute>
		        <attribute name="message">
		            <a:documentation>A human-readable description of the global status (depending on the status code)</a:documentation>
		        </attribute>
		        <attribute name="completion">
		            <a:documentation>An integer value between 0 and 100 representing the level of completion of the run. Differs only when the project is in state 1. In state 0, value is always 0. In state 2, value is always 100.</a:documentation>
		        </attribute>
		        <attribute name="errors">
		            <a:documentation>Indicates whether an error occured. Value is "yes" or "no". Your system should always check if "no" was returned when expected! Otherwise there may be parameter errors, the exact errors can then be found in the parameters block.</a:documentation>
		        </attribute>
		        <attribute name="errormsg">
		            <a:documentation>A human readable error message. Empty if no errors occurred.</a:documentation>
		        </attribute>
		        <zeroOrMore>
		            <element name="log">
		                <a:documentation>Contains a log message from the actual underlying system. The element body contains the log message text.</a:documentation>
		                <attribute name="completion">
		                    <a:documentation>An integer value between 0 and 100 representing the level of completion at the time of loggin. Differs only when the project is in state 1. In state 0, value is always 0. In state 2, value is always 100.</a:documentation>
		                </attribute>
		                <attribute name="time">
		                    <a:documentation>Time of the log message. Free format.</a:documentation>
		                </attribute>
		                <text />
		            </element>
		        </zeroOrMore>
		    </element>
		</optional>
        <optional>
            <element name="formats">
                <a:documentation>Globally specifies the formats used by this webservice, either as input or output. Extracted from the profiles.</a:documentation>
                <oneOrMore>
                    <element name="format">
                        <attribute name="id">
                            <a:documentation>An ID for the format, corresponds to the Python class that represents it.</a:documentation>
                        </attribute>
                        <attribute name="name">
                            <a:documentation>A human readable name for the parameter group.</a:documentation>
                        </attribute>
                        <attribute name="mimetype">
                            <a:documentation>The mimetype of the format</a:documentation>
                        </attribute>
                    </element>
                </oneOrMore>
            </element>
        </optional>
		<optional>
		    <element name="profiles">
		        <a:documentation>Specifies the profiles accepted by this webservice. Profiles describe the input that the system can take and the output it will produce given that input and the configured parameters.</a:documentation>
		        <oneOrMore>
		            <element name="profile">
		                <element name="input">
		                    <a:documentation>The input portion of a profile. Contains Input Templates. </a:documentation>
		                    <zeroOrMore>
		                        <element name="InputTemplate">
		                            <a:documentation>An Input Template can be seen like an input 'slot' for a file of a particular type and with specific metadata.</a:documentation>
		                            <attribute name="id">
		                                <a:documentation>A unique identifier (string) for this input template</a:documentation>
		                            </attribute>
		                            <attribute name="format">
		                                <a:documentation>The format associated with this input slot (for example PlainTextFormat). Name should be equal to one of the format python classes available to CLAM. Can be extended in formats.py</a:documentation>
		                            </attribute>
		                            <attribute name="label">
		                                <a:documentation>The human readable label associated with this input template. Users use this information to select their desired input template in the interface, so it should be a clear label.</a:documentation>
		                            </attribute>
		                            <optional>
		                                <attribute name="mimetype">
		                                    <a:documentation>If there is a mime-type associated with the chosen format for this input template, it will be represented here.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="schema">
		                                    <a:documentation>If there is a validation schema associated with the chosen format for this input template, it will be represented here.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="filename">
		                                    <a:documentation>If set, any uploaded file for this input template will obtain this exact filename</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="extension">
		                                    <a:documentation>If set, this is the extension that is required and automatically added for files uploaded using this input template</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="optional">
		                                    <a:documentation>Boolean value set to "true" or "false", determining whether this input template must be used (false) for this profile to work or is optional (true)</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="unique">
		                                    <a:documentation>Boolean value set to "true" or "false", determining whether this input template is unique and can only be used for uploading one file, or whether multiple files can be uploaded through this input template</a:documentation>
		                                </attribute>
		                            </optional>
		                            <ref name="parameters" />
		                            <!-- TODO: PARAMETERS WITH PARAMETERCONDITION -->
		                            <zeroOrMore>
		                                <element name="converter">
		                                    <a:documentation>Makes a converter available for this specific input template. The text content of this element is the label users see when choosing a converter.</a:documentation>
		                                    <attribute name="id">
		                                        <a:documentation>The ID of the converter.</a:documentation>
		                                    </attribute>
		                                    <text />
		                                </element>
		                            </zeroOrMore>
		                            <zeroOrMore>
		                                <element name="inputsource">
		                                    <a:documentation>Predefined input data that can go in this input template. The element text contains the label users will see when selecting a pre-defined input source</a:documentation>
		                                    <attribute name="id">
		                                        <a:documentation>The ID of the input source.</a:documentation>
		                                    </attribute>
		                                    <text />
		                                </element>
		                            </zeroOrMore>
		                            <zeroOrMore>
                                        <ref name="constraint" />
                                    </zeroOrMore>
		                        </element>
		                    </zeroOrMore>
		                </element>
		                <element name="output">
		                    <a:documentation>The output portion of a profile. Contains Output Templates. </a:documentation>
		                    <oneOrMore>
		                        <element name="OutputTemplate">
		                            <a:documentation>An Output Template can be seen like an output 'slot'. If all input conditions have been met, a file corresponding to each output template will be outputted.</a:documentation>
		                            <attribute name="id">
		                                <a:documentation>A unique identifier (string) for this output template</a:documentation>
		                            </attribute>
		                            <attribute name="format">
		                                <a:documentation>The format associated with this output slot (for example PlainTextFormat). Name should be equal to one of the format python classes available to CLAM. Can be extended in formats.py</a:documentation>
		                            </attribute>
		                            <attribute name="label">
		                                <a:documentation>The human readable label associated with this output template.</a:documentation>
		                            </attribute>
		                            <optional>
		                                <attribute name="mimetype">
		                                    <a:documentation>If there is a mime-type associated with the chosen format for this output template, it will be represented here.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="schema">
		                                    <a:documentation>If there is a validation schema associated with the chosen format for this output template, it will be represented here.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="filename">
		                                    <a:documentation>The exact filename of the output file produced by this template.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="extension">
		                                    <a:documentation>The extension that this output file will obtain, the other filename will be inherited from its input.</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="unique">
		                                    <a:documentation>Boolean value set to "true" or "false", determining whether this output template is unique and produces only one file, or whether multiple files can be produces using this input template</a:documentation>
		                                </attribute>
		                            </optional>
		                            <optional>
		                                <attribute name="parent">
		                                    <a:documentation>The ID of the inputtemplate that acts as the parent for this output template</a:documentation>
		                                </attribute>
		                            </optional>
									<zeroOrMore>
										<choice>
											<ref name="parametercondition" />
											<ref name="meta" />
                                            <ref name="constraint" />
                                            <ref name="viewer" />
										</choice>
									</zeroOrMore>
		                            <!-- Note: Converters and viewers are expressed with each individual output file in the output block rather than here -->
		                        </element>
		                    </oneOrMore>
		                </element>
		            </element>
		        </oneOrMore>
		    </element>
		    <element name="parameters">
		        <a:documentation>Specification of parameters to the system</a:documentation>
		        <zeroOrMore>
		            <element name="parametergroup">
		                <a:documentation>Parameters must be grouped, allowing a nice division of different kinds of parameters</a:documentation>
		                <attribute name="name">
		                    <a:documentation>A human readable name for the parameter group</a:documentation>
		                </attribute>
		                <zeroOrMore>
		                    <ref name="parameters" />
		                </zeroOrMore>
		            </element>
		        </zeroOrMore>
		    </element>
            <optional>
                <element name="program">
                    <a:documentation>A Program is the concretisation of Profile. It describes the exact output files that will be created on the basis of what input files.</a:documentation>
                    <oneOrMore>
                        <element name="outputfile">
                            <a:documentation>An output file</a:documentation>
                            <attribute name="name">
                                <a:documentation>The filename of the output file</a:documentation>
                            </attribute>
                            <attribute name="template">
                                <a:documentation>The ID of the outputtemplate that produces this output file</a:documentation>
                            </attribute>
                            <attribute name="type" ns="http://www.w3.org/1999/xlink">
                                <a:documentation>XLink type, always "simple"</a:documentation>
                            </attribute>
                            <attribute name="href" ns="http://www.w3.org/1999/xlink">
                                <a:documentation>XLink reference to the URL of the outputi file.</a:documentation>
                            </attribute>
                            <zeroOrMore>
                                <element name="inputfile">
                                    <a:documentation>An input file that is used to produce the outputfile</a:documentation>
                                    <attribute name="name">
                                        <a:documentation>The filename of the input file</a:documentation>
                                    </attribute>
                                    <attribute name="template">
                                        <a:documentation>The ID of the input template that produces this input file</a:documentation>
                                    </attribute>
                                    <attribute name="type" ns="http://www.w3.org/1999/xlink">
                                        <a:documentation>XLink type, always "simple"</a:documentation>
                                    </attribute>
                                    <attribute name="href" ns="http://www.w3.org/1999/xlink">
                                        <a:documentation>XLink reference to the URL of the input file.</a:documentation>
                                    </attribute>
                                </element>
                            </zeroOrMore>
                        </element>
                    </oneOrMore>
                </element>
            </optional>
		    <optional>
		    	<element name="inputsources">
		    		<text />
		    		<!-- TODO -->
		    	</element>
		    </optional>
		</optional>
	</element>
</start>


<define name="parameters">
    <interleave>
     <zeroOrMore>
      <element name="StaticParameter">
         <a:documentation>A dummy parameter taking a fixed value</a:documentation>
         <ref name="commonparameterattribs" />
      </element>
      <element name="BooleanParameter">
         <a:documentation>A parameter taking a boolean value</a:documentation>
         <ref name="commonparameterattribs" />
         <optional><attribute name="reverse" /></optional>
      </element>
     </zeroOrMore>
     <zeroOrMore>
      <element name="StringParameter">
         <a:documentation>A parameter taking a (short) string value</a:documentation>
         <ref name="commonparameterattribs" />
         <optional><attribute name="maxlength" /></optional>
      </element>
     </zeroOrMore>
     <zeroOrMore>
      <element name="TextParameter">
         <a:documentation>A parameter taking a longer textual value</a:documentation>
         <ref name="commonparameterattribs" />
         <optional><attribute name="maxlength" /></optional>
      </element>
     </zeroOrMore>
     <zeroOrMore>
      <element name="IntegerParameter">
         <a:documentation>A parameter taking an integer number as value</a:documentation>
         <ref name="commonparameterattribs" />
         <optional><attribute name="minvalue" /></optional>
         <optional><attribute name="maxvalue" /></optional>
      </element>
     </zeroOrMore>
     <zeroOrMore>
      <element name="FloatParameter">
         <a:documentation>A parameter taking a floating point number as value</a:documentation>
         <ref name="commonparameterattribs" />
         <optional><attribute name="minvalue" /></optional>
         <optional><attribute name="maxvalue" /></optional>
      </element>
     </zeroOrMore>
     <zeroOrMore>
     	<element name="ChoiceParameter">
     		<a:documentation>A parameter taking selecting one or more predefined options as value</a:documentation>
     		<ref name="commonparameterattribs" />
     		<optional>
     			<attribute name="multi">
     				<a:documentation>Attribute expressing whether multiple choices are allowed similtaneously. Value can be 'true' or 'false'</a:documentation>
     			</attribute>
     		</optional>
     		<optional>
     			<attribute name="showall">
     				<a:documentation>Attribute affecting presentation, if set to 'true' options are presented as checkboxes or radiobuttons instead of a pull-down list.</a:documentation>
     			</attribute>
     		</optional>
			<optional>
     			<attribute name="delimiter">
     				<a:documentation>The delimiter between multiple values, as propagated to the command line. Only applicable if multi=true</a:documentation>
     			</attribute>
     		</optional>
     		<oneOrMore>
     			<element name="choice">
     				    <attribute name="id">
        					<a:documentation>The ID of a choice attribute. This is the value that will be used to identify the choice.</a:documentation>
    					</attribute>
    					<optional>
    						<attribute name="selected">
    							<a:documentation>Determines whether the choice is selected or not. Value is 1 or 0. Multiple selections are only allowed if multi=true</a:documentation>
    						</attribute>
    					</optional>
						<text />
     			</element>
     		</oneOrMore>
     	</element>
     </zeroOrMore>
    </interleave>
</define>


<define name="commonparameterattribs">
    <attribute name="id">
        <a:documentation>A unique identifier for this parameter</a:documentation>
    </attribute>
    <attribute name="name">
        <a:documentation>The human readable name of the parameter</a:documentation>
    </attribute>
    <attribute name="description">
        <a:documentation>A description clarifying the use of this parameter</a:documentation>
    </attribute>
    <optional><attribute name="flag" /></optional>
    <optional>
        <attribute name="value">
            <a:documentation>The selected value for this parameter</a:documentation>
        </attribute>
    </optional>
    <optional>
        <attribute name="error">
            <a:documentation>If an error occurred validating this parameter, this will hold the error message</a:documentation>
        </attribute>
    </optional>
</define>

<define name="meta">
	<element name="meta">
		<a:documentation>A metadata field for the output template</a:documentation>
	  	<attribute name="id">
			<a:documentation>The ID of the metadata field</a:documentation>
		</attribute>
		<optional>
			<attribute name="operator">
				<a:documentation>The operator for this metadata field. Can be 'set' in which case the value of the metadata field is simply set to the value specified in textbody of this element. If set to 'unset', the body should be empty and it will unset this metadata field if present. If set to 'copy', the body contains the ID of a parameter from the inputtemplate in the form templateid.parameterid , whose value will be copied. If set to 'parameter', the body contains the ID of a global parameter, whose value will be copied. The default operator is 'set', in which case the operator attribute can be simply omitted.</a:documentation>
			</attribute>
		</optional>
		<text />
	</element>
</define>


<define name="conditions">
	<oneOrMore>
		<choice>
			<element name="equals">
				<a:documentation>A condition that matches if the parameter's value equals the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For parameters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="notequals">
				<a:documentation>A condition that matches if the parameter's value does not equal the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For parameters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="lessthan">
				<a:documentation>A condition that matches if the parameter's value is less than the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For parameters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="lessequalthan">
				<a:documentation>A condition that matches if the parameter's value is less or equal than the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For paramters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="greaterthan">
				<a:documentation>A condition that matches if the parameter's value is greater than the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For paramters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="greaterequalthan">
				<a:documentation>A condition that matches if the parameter's value is greater or equal than the value of this element.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For paramters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="contains">
				<a:documentation>A condition that matches if the parameter's value contains the value of this element. Useful for applying to choice parameters.</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For parameters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="set">
				<a:documentation>YET TO BE DOCUMENTED</a:documentation>
			  	<attribute name="parameter"><a:documentation>The ID of the parameter the condition is on. For parameters pertaining to input templates use 'templateid.parameterid'</a:documentation></attribute>
			  	<text />
			</element>
			<element name="disjunction">
				<a:documentation>Create a disjunction of conditions</a:documentation>
				<ref name="conditions" />
			</element>
		</choice>
	</oneOrMore>
</define>

<define name="parametercondition">
	<element name="parametercondition">
		<a:documentation>A parametercondition conditions metadata for outputtemplate on global parameters or parameters from input templates</a:documentation>
		<element name="if">
			<a:documentation>One or more conditions, applied conjunctively</a:documentation>
			<ref name="conditions" />
		</element>
		<element name="then">
		<a:documentation>Meta fields or further parameter conditions to apply when the conditions match</a:documentation>
			<zeroOrMore>
				<choice>
					<ref name="parametercondition" />
					<ref name="meta" />
				</choice>
			</zeroOrMore>
		</element>
		<optional>
			<element name="else">
				<a:documentation>Meta fields or further parameter conditions to apply when the conditions do not match</a:documentation>
				<zeroOrMore>
					<choice>
						<ref name="parametercondition" />
						<ref name="meta" />
					</choice>
				</zeroOrMore>
			</element>
		</optional>
	</element>
</define>

<define name="viewer">
    <element name="viewer">
        <a:documentation>Registers a viewer for this output format</a:documentation>
        <attribute name="id">
            <a:documentation>An ID for the format</a:documentation>
        </attribute>
        <attribute name="name">
            <a:documentation>A human readable name for the parameter group.</a:documentation>
        </attribute>
        <attribute name="type">
            <a:documentation>The type of the format, refers to the python class that implements is.</a:documentation>
        </attribute>
        <attribute name="mimetype">
            <a:documentation>The mimetype of the format</a:documentation>
        </attribute>
        <attribute name="more">
            <a:documentation>Set to either true or false: should this viewer be visualised in an extra menu or as part of the main group?</a:documentation>
        </attribute>
        <attribute name="allowdefault">
            <a:documentation>Set to either true or false: may this viewer act as the default viewer if it is the first
            defined viewer?</a:documentation>
    </element>
</define>


<define name="constraint">
    <element name="constraint">
        <a:documentation>Defines a constraint on the input or output template in the form of one or more tests, the constraint passes if any of the tests pass.</a:documentation>
        <attribute name="type">
            <a:documentation>type type of the constraint, can be "require" or "forbid".</a:documentation>
        </attribute>
        <oneOrMore>
            <element name="test">
                <a:documentation>One of the tests that make up this constraint, is checked against the metadata.</a:documentation>
                <attribute name="key">
                    <a:documentation>The metadata field to test</a:documentation>
                </attribute>
                <attribute name="operator">
                    <a:documentation>The operator for testing, can be "equals","notequals","greaterthan","greaterequalthan","lessthan","lessequalthan","contains","incommalist","inspacelist"</a:documentation>
                </attribute>
                <attribute name="value">
                    <a:documentation>The value the field needs to be checked against (using the supplied operator)</a:documentation>
                </attribute>
            </element>
        </oneOrMore>
    </element>
</define>

<define name="action">
    <element name="action">
        <a:documentation>Defines an action, an action allows you to tie a URL to a script or Python function, and may take a number of parameters you explicitly specify. Each action is strictly independent of other actions, and completely separate of the projects, and by extension also of any files within projects and any profiles.  Unlike projects, which may run over a long time period and are suited for batch processing, actions are intended for real-time communication.  Typically they should return an answer in at most a couple of seconds.</a:documentation>
        <attribute name="id">
            <a:documentation>An ID for the action</a:documentation>
        </attribute>
        <optional>
        <attribute name="name">
            <a:documentation>A human readable name for the action.</a:documentation>
        </attribute>
        </optional>
        <optional>
        <attribute name="description">
            <a:documentation>A human readable name for the parameter group.</a:documentation>
        </attribute>
        </optional>
        <optional>
        <attribute name="mimetype">
            <a:documentation>The mimetype of the output format</a:documentation>
        </attribute>
        </optional>
        <optional>
        <attribute name="allowanonymous">
            <a:documentation>Is anonymous usage of this action allowed? Value should be yes or no.</a:documentation>
        </attribute>
        </optional>
        <zeroOrMore>
            <choice>
                <ref name="parameters" />
                <ref name="viewer" />
            </choice>
        </zeroOrMore>
    </element>
</define>

</grammar>
