<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fox="http://www.og.dti.gov/fox" xmlns:fm="http://www.og.dti.gov/fox_module" xmlns:upload="http://www.og.dti.gov/fox"  xmlns:widget="http://www.og.dti.gov/fox" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified" attributeFormDefault="unqualified" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema
C:\pvcswork\Fox\source\altova_xmlspy\schema\fox_schema.xsd">
	<xs:import schemaLocation="C:\pvcswork\Fox\source\altova_xmlspy\schema\fox_import.xsd"/>
	<xs:annotation>
		<xs:appinfo>
			<fm:module>
				<fm:header>
					<fm:name>DEMO_FILE_UPLOAD</fm:name>
					<fm:title>FOX Demo File Upload</fm:title>
					<fm:application-title>FOX Demo File Upload</fm:application-title>
					<fm:version-no>$Revision:   1.0  $</fm:version-no>
					<fm:version-desc/>
					<fm:history/>
					<fm:description/>
					<fm:build-notes/>
					<fm:help-text/>
				</fm:header>
				<fm:control>
					<fm:transaction-mode>read-committed</fm:transaction-mode>
					<fm:authentication>not-required</fm:authentication>
				</fm:control>
				<fm:security-list/>
				<fm:library-list>
					<fm:library>LAYOUT1</fm:library>
				</fm:library-list>
				<fm:storage-location-list>
					<fm:storage-location name="main">
						<fm:cache-key string="DEMO_FILE_UPLOAD:1">
							<fm:using using-type="UNIQUE"/>
						</fm:cache-key>
						<fm:new-document>
							<fm:root-element>ROOT</fm:root-element>
						</fm:new-document>
					</fm:storage-location>
					<!-- Storage location does not need an insert because a stub record is always created and the ID passed to the called module 
               A stub record is created because it is necessary to know the ID for performing a file upload -->
					<fm:storage-location name="edit-main">
						<fm:cache-key string="DEMO_FILE_UPLOAD:1">
							<fm:using>:{params}/FILE_UPLOAD_ID</fm:using>
						</fm:cache-key>
						<fm:new-document>
							<fm:root-element>ROOT</fm:root-element>
						</fm:new-document>
						<fm:database>
							<fm:query>
								<fm:sql>
SELECT xml_data
FROM envmgr.fox_tester_results
WHERE id = :1
FOR UPDATE OF xml_data NOWAIT
                </fm:sql>
								<fm:using>:{params}/FILE_UPLOAD_ID</fm:using>
							</fm:query>
							<fm:update>
								<fm:sql>
UPDATE envmgr.fox_tester_results
SET xml_data = :1
WHERE id = :2
                </fm:sql>
								<fm:using using-type="DATA-XMLTYPE"/>
								<fm:using>:{params}/FILE_UPLOAD_ID</fm:using>
							</fm:update>
						</fm:database>
					</fm:storage-location>-->
					<fm:file-storage-location name="file-typeStorageLocation">
						<fm:cache-key string="FILE_UPLOAD-file-typeStorageLocation"/>
						<fm:database>
							<fm:query>
								<fm:sql>
SELECT ftr.UPLOADED_FILE
FROM envmgr.FOX_TESTER_RESULTS ftr
WHERE id = :1
FOR UPDATE OF ftr.UPLOADED_FILE NOWAIT
                </fm:sql>
								<fm:using>:{params}/FILE_UPLOAD_ID</fm:using>
							</fm:query>
						</fm:database>
					</fm:file-storage-location>
				</fm:storage-location-list>
				<fm:entry-theme-list>
					<fm:entry-theme name="new">
						<fm:storage-location>main</fm:storage-location>
						<fm:state>state-new</fm:state>
						<fm:attach>/*</fm:attach>
						<fm:do>
							<fm:call action="action-initialise-new-demo"/>
						</fm:do>
					</fm:entry-theme>
					<fm:entry-theme name="edit">
						<fm:storage-location>edit-main</fm:storage-location>
						<fm:state>state-new</fm:state>
						<fm:attach>/*</fm:attach>
						<fm:do>
							<fm:call action="action-demo-edit-theme"/>
						</fm:do>
					</fm:entry-theme>
				</fm:entry-theme-list>
				<fm:action-list>
					<fm:action name="action-initialise-new-demo">
						<fm:do>
							<fm:init target="/*/FILE_UPLOAD/UPLOAD_FILE"/>
							<fm:run-api interface="dbint-demo-file-upload" api="api-create-stub"/>
							<fm:transaction operation="COMMIT"/>
							<!-- fm:eval used to call-module with new ID after creating stub record
                   It is an eval because if this module has been libraried in then it would not be correct to call itself -->
							<fm:eval expr="string(concat('&lt;call-module module=&quot;', :{sys}/module/name, '&quot; theme=&quot;edit&quot; type=&quot;modal&quot; params=&quot;:{theme}/FILE_UPLOAD_ID&quot; callback-action=&quot;action-exit-on-callback&quot;/>'))"/>
						</fm:do>
					</fm:action>
					<fm:action name="action-demo-edit-theme">
						<fm:do>
							<fm:assign initTarget=":{theme}/HAS_ERRORS" textValue="false"/>
							<fm:if test=":{sys}/module/name='SPIRE_TESTER_EXT'">
								<fm:then>
									<!-- remove the html widget from the dom so it is not validated -->
									<fm:remove match="/*/WIDGET_LIST/HTML_EDITOR | /*/SORTABLE_COLS/DOWNLOAD_COLS_WORKING"/>
								</fm:then>
							</fm:if>
						</fm:do>
					</fm:action>
				</fm:action-list>
				<fm:db-interface-list>
					<fm:db-interface name="dbint-demo-file-upload">
						<fm:api name="api-create-stub">
							<fm:statement>
DECLARE

  l_xml_data XMLTYPE := :1;
  
BEGIN

  INSERT INTO envmgr.FOX_TESTER_RESULTS (id, xml_data, uploaded_file)
  VALUES (envmgr.FOX_TESTER_SEQ.nextval, l_xml_data, empty_blob())
  RETURNING id INTO :2;

END;
             						 </fm:statement>
							<fm:using datadom-type="dom" datadom-location="/ROOT" sql-type="xmltype"/>
							<fm:using direction="out" datadom-location=":{theme}/FILE_UPLOAD_ID"/>
						</fm:api>
						<fm:api name="api-save-answers">
							<fm:statement>
DECLARE

  l_xml_data XMLTYPE := :1;
  
BEGIN

  UPDATE envmgr.FOX_TESTER_RESULTS
  SET xml_data = l_xml_data
  WHERE id = :2;

END;
              					</fm:statement>
							<fm:using datadom-type="dom" datadom-location="/ROOT" sql-type="xmltype"/>
							<fm:using>:{params}/FILE_UPLOAD_ID</fm:using>
						</fm:api>
					</fm:db-interface>
				</fm:db-interface-list>
				<fm:state-list>
					<fm:state name="state-new">
						<fm:action-list/>
						<fm:presentation>
							<!-- Override buffers within LAYOUT1LIB to remove images -->
							<fm:set-buffer name="buffer-top-left-logo"/>
							<fm:set-buffer name="buffer-mid-left-logo"/>
							<!-- Override topNav and bottomNav to remove -->
							<fm:set-buffer name="buffer-topNav"/>
							<fm:set-buffer name="buffer-bottomNav"/>
							<fm:set-buffer name="buffer-fileUploadTitle">
            File Upload
          </fm:set-buffer>
							<fm:set-buffer name="buffer-content">
								<br/>
								<br/>
								<table width="30%">
									<tr>
										<th class="setoutForm" align="left">
											<fm:include name="buffer-fileUploadTitle"/>
										</th>
									</tr>
								</table>
								<br/>
	                Please upload a test file of your choice. Click 'Choose File...' and a window should appear, click 'Browse...' in this window and find a file to upload. Click 'Start Upload' to begin the process of uploading the file. The window will change to a success message with a green tick, click 'Close' to end the file upload.  You can then press View to look at the file. 
	               							 <br/>
								<br/>
								<fm:set-out match="/*/FILE_UPLOAD" upload:mode="."/>
								<br/>
							</fm:set-buffer>
						</fm:presentation>
					</fm:state>
				</fm:state-list>
				<fm:template-list/>
				<fm:map-set-list/>
			</fm:module>
		</xs:appinfo>
	</xs:annotation>
	<xs:element name="ROOT">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="FILE_UPLOAD" upload:ro=".">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="UPLOAD_FILE" type="file-type" upload:prompt="Uploaded File" upload:edit="." fox:file-storage-location="file-typeStorageLocation" fox:widget="file" fox:promptLayout="north" fox:buttonFlow="horizontal" fox:buttonPosition="south" fox:mand="."/>
							<xs:element name="phantom_upload_check" type="phantom" upload:ro="./UPLOAD_FILE/fox-error" upload:run="false" fox:prompt="Error" fox:imageUrl="img/cross" fox:widget="button+" fox:hint="You must upload a file"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
