<commit_before><?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2010 <NAME>
    EADitor: http://code.google.com/p/eaditor/
    Apache License 2.0: http://code.google.com/p/eaditor/    
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
	xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
	xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:ead="urn:isbn:1-931666-22-9" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude" xmlns:eaditor="https://github.com/ewg118/eaditor">
	<head>
		<title>EADitor: Administrative Interface</title>
		<link rel="stylesheet" href="/fr/style/bootstrap/css/bootstrap.css" type="text/css"/>
		<link rel="stylesheet" href="/fr/style/form-runner-bootstrap-override.css" type="text/css"/>
		<link rel="stylesheet" href="/config/theme/examples.css" type="text/css" media="all"/>
		<link rel="shortcut icon" href="/ops/images/orbeon-icon-16.ico"/>
		<link rel="icon" href="/ops/images/orbeon-icon-16.png" type="image/png"/>
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.8.0/build/cssgrids/grids-min.css"/>

		<!-- EADitor styling -->
		<link rel="stylesheet" href="/apps/eaditor/xforms/css/xforms.css"/>

		<!-- expand components (unnecessary to include jquery: orbeon already does -->
		<script type="text/javascript" src="/apps/eaditor/xforms/javascript/get_components.js"/>

		<xforms:model>
			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-url">
				<xi:include href="../exist-url.xml"/>
			</xforms:instance>

			<xforms:instance id="control-instance">
				<controls xmlns="">
					<id/>
					<status/>
					<error/>
					<numFound/>
					<page>1</page>
					<query_input/>
					<query_sent/>
					<solr-core/>
				</controls>
			</xforms:instance>

			<xforms:instance id="config">
				<config xmlns=""/>
			</xforms:instance>

			<xforms:instance id="config-template">
				<config xmlns:xlink="http://www.w3.org/1999/xlink">
					<firstrun/>
					<flickr_api_key/>
					<geonames_api_key/>
					<title>EADitor</title>
					<description/>
					<license>http://opendatacommons.org/licenses/odbl/</license>
					<banner_text>EADitor: XForms for EAD</banner_text>
					<banner_image xlink:href=""/>					
					<solr_published>http://localhost:8080/solr/eaditor-published/</solr_published>
					<url>http://localhost:8080/orbeon/eaditor/</url>
					<export>
						<oai-pmh>true</oai-pmh>
						<pelagios>false</pelagios>
					</export>					
					<theme>
						<facets>agency_facet,century_num,corpname_facet,famname_facet,genreform_facet,geogname_facet,language_facet,persname_facet,subject_facet</facets>
						<jquery_ui_theme>smoothness</jquery_ui_theme>
						<layouts>
							<index>
								<yui_class>yui-t5</yui_class>
							</index>
							<results>
								<yui_class>yui-t2</yui_class>
								<image_location>right</image_location>
							</results>
						</layouts>
					</theme>
					<machine_tags>
						<namespace id="geonames">
							<predicate>locality</predicate>
						</namespace>
						<namespace id="lcgft">
							<predicate>genreform</predicate>
						</namespace>
						<namespace id="lcsh">
							<predicate>subject</predicate>
						</namespace>
						<namespace id="pleiades">
							<predicate>atteststo</predicate>
							<predicate>depicts</predicate>
							<predicate>findspot</predicate>
							<predicate>origin</predicate>
							<predicate>place</predicate>
						</namespace>
						<namespace id="viaf">
							<predicate>depicts</predicate>
						</namespace>
					</machine_tags>
				</config>
			</xforms:instance>

			<xforms:instance id="instance-templates">
				<templates>
					<agencycodes>
						<agencycode value="default">Default Agency: Edit Your Template!</agencycode>
					</agencycodes>
					<containertypes>
						<container value="box">Box</container>
						<container value="box-folder">Box-Folder</container>
						<container value="folder">Folder</container>
						<container value="reel">Reel</container>
						<container value="tape">Tape</container>
					</containertypes>
				</templates>
			</xforms:instance>

			<xforms:instance id="ead-template">
				<ead id="" xmlns="urn:isbn:1-931666-22-9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"
					xsi:schemaLocation="urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd">
					<eadheader langencoding="iso639-2b">
						<eadid countrycode="US"/>
						<filedesc>
							<titlestmt>
								<titleproper/>
							</titlestmt>
						</filedesc>
					</eadheader>
					<archdesc level="collection">
						<did>
							<unittitle/>
						</did>
					</archdesc>
				</ead>
			</xforms:instance>
			<xforms:instance id="c-template">
				<c id="" level="" xmlns="urn:isbn:1-931666-22-9">
					<did>
						<unittitle/>
					</did>
				</c>
			</xforms:instance>

			<xforms:instance id="list">
				<list xmlns=""/>
			</xforms:instance>

			<xforms:instance id="item-template">
				<item xmlns="">
					<title/>
					<id/>
					<published/>
					<components/>
				</item>
			</xforms:instance>

			<xforms:instance id="guide">
				<ead xmlns=""/>
			</xforms:instance>

			<xforms:instance id="eXist-xquery">
				<exist:query xmlns="">
					<exist:text/>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="xqueries">
				<queries xmlns="">
					<query id="collection-count">&lt;report&gt;{count(collection())}&lt;/report&gt;</query>
					<query id="get-objects"> &lt;report> { for $record in subsequence(collection(), START, 20) let $type := $record/*/local-name() return if ($type='ead') then &lt;record> &lt;type>{
						$type }&lt;/type> &lt;id>{ $record//*[local-name()='eadid']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='archdesc']/*[local-name()='did']/*[local-name()='unittitle']/text() }&lt;/title> &lt;components>{ if (count($record//*[local-name()='c']) &gt; 0) then
						'true' else 'false' }&lt;/components> &lt;published/> &lt;/record> else &lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{
						$record//*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='mods']/*[local-name()='titleInfo']/*[local-name()='title']/text() }&lt;/title> &lt;published/> &lt;/record> } &lt;/report> </query>
					<query id="create-collection">xmldb:create-collection('/db/eaditor', 'guides')</query>
					<query id="publish-ead">&lt;report> { for $foo in collection() return if($foo[child::node()[local-name()='ead']]) then &lt;item> { $foo/*[local-name()='ead']/@id } &lt;/item> else
						'' } &lt;/report></query>
					<query id="publish-mods">&lt;report xmlns:mods="http://www.loc.gov/mods/v3"> { for $foo in collection() return if($foo[child::node()[local-name()='modsCollection']]) then &lt;item>
						{ $foo/*[local-name()='modsCollection']/*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier'] } &lt;/item> else '' } &lt;/report></query>
					<query id="query-objects"> &lt;report> { for $record in collection()[contains(descendant::*[local-name()='unittitle'], 'QUERY') or descendant::*[local-name()='eadid'] = 'QUERY' or
						descendant::*[local-name()='identifier'] = 'QUERY' or descendant::*[local-name()='recordIdentifier'] = 'QUERY' or contains(descendant::*[local-name()='title'], 'QUERY')] let $type := $record/*/local-name() return if ($type='ead') then
						&lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{ $record//*[local-name()='eadid']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='archdesc']/*[local-name()='did']/*[local-name()='unittitle']/text() }&lt;/title> &lt;components>{ if (count($record//*[local-name()='c']) &gt; 0) then
						'true' else 'false' }&lt;/components> &lt;published/> &lt;/record> else &lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{
						$record//*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='mods']/*[local-name()='titleInfo']/*[local-name()='title']/text() }&lt;/title> &lt;published/> &lt;/record> } &lt;/report> </query>
				</queries>
			</xforms:instance>

			<xforms:instance id="pagination-result">
				<exist:result/>
			</xforms:instance>

			<xforms:instance id="xquery-result">
				<exist:result/>
			</xforms:instance>

			<!-- solr response for id query -->
			<xforms:instance id="published-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="list-published-response">
				<response xmlns=""/>
			</xforms:instance>

			<!-- send to Solr -->
			<xforms:instance id="addIndex">
				<add xmlns=""/>
			</xforms:instance>
			<xforms:instance id="addDoc">
				<add xmlns=""/>
			</xforms:instance>
			<!-- Instance for Solr commit-->
			<xforms:instance id="sendCommit">
				<commit/>
			</xforms:instance>
			<!-- delete from Solr -->
			<xforms:instance id="deleteId">
				<delete xmlns="">
					<id/>
				</delete>
			</xforms:instance>
			<xforms:instance id="deleteAll">
				<delete xmlns="">
					<query>id:*</query>
				</delete>
			</xforms:instance>

			<xforms:instance id="optimizeIndex">
				<optimize/>
			</xforms:instance>

			<xforms:bind nodeset="instance('config-template')">
				<xforms:bind nodeset="title" required="true()"/>
				<xforms:bind nodeset="url" required="true()" type="xs:anyURI"/>
				<xforms:bind nodeset="solr_published" required="true()" type="xs:anyURI"/>
			</xforms:bind>


			<!-- submissions -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-url')}eaditor/config.xml" replace="instance" instance="config">
				<xforms:action ev:event="xforms-submit-done">
					<!-- get the number of docs in the eXist collection() -->
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='collection-count']"/>
					<xforms:send submission="xquery-collection"/>
					<xforms:setvalue ref="instance('control-instance')/numFound" value="number(instance('xquery-result'))"/>
					<!-- set value in control instance -->

					<xxforms:variable name="end" select="if(instance('control-instance')/numFound &gt; 20) then 20 else instance('control-instance')/numFound"/>
					<!-- get list of files for page 1, replacing START and END -->
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="replace(instance('xqueries')/query[@id='get-objects'], 'START', '1')"/>
					<xforms:send submission="xquery-pagination"/>
				</xforms:action>
				<xforms:action ev:event="xforms-submit-error">
					<xforms:setvalue ref="instance('config-template')/firstrun">true</xforms:setvalue>
				</xforms:action>
			</xforms:submission>

			<!-- xquery for getting and processing query results into pages of items -->
			<xforms:submission id="xquery-pagination" ref="instance('eXist-xquery')" action="{instance('exist-url')}eaditor/guides/" method="post" replace="instance" instance="pagination-result">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Error querying eXist database.</xforms:setvalue>
				<xforms:action ev:event="xforms-submit-done">
					<!--iterate through docs, check for publication -->
					<xforms:action xxforms:iterate="instance('pagination-result')//record">
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
						<xforms:setvalue ref="instance('control-instance')/id" value="context()/id"/>
						<xforms:send submission="query-solr-for-publication"/>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<!-- generic xquery -->
			<xforms:submission id="xquery-collection" ref="instance('eXist-xquery')" action="{instance('exist-url')}eaditor/guides/" method="post" replace="instance" instance="xquery-result">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Error querying eXist database.</xforms:setvalue>
			</xforms:submission>

			<!-- submission to query solr to see if the document is published -->
			<xforms:submission id="query-solr-for-publication" serialization="none" method="get" action="{instance('control-instance')/solr-core}select/?q=id:{instance('control-instance')/id}"
				replace="instance" instance="published-response">
				<!-- if the document is found in solr, get the updated solr doc -->
				<xforms:setvalue ev:event="xforms-submit-done" if="instance('published-response')/result[@name='response']/@numFound = '1'"
					ref="instance('pagination-result')//record[id=instance('control-instance')/id]/published" value="'true'"/>
			</xforms:submission>

			<!-- save templates and add guides collection to eXist on the first run of EADitor -->
			<xforms:submission id="save-config" ref="instance('config-template')" action="{instance('exist-url')}eaditor/config.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Config.</xforms:message>
				<!-- reload the config after it has been created -->
				<xforms:send submission="load-config" ev:event="xforms-submit-done"/>
			</xforms:submission>
			<xforms:submission id="save-instance-templates" ref="instance('instance-templates')" action="{instance('exist-url')}eaditor/instance-templates.xml" method="put" replace="none"
				xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Agency Codes Template.</xforms:message>
			</xforms:submission>
			<xforms:submission id="save-ead-template" ref="instance('ead-template')" action="{instance('exist-url')}eaditor/ead-template.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving EAD Template.</xforms:message>
			</xforms:submission>
			<xforms:submission id="save-c-template" ref="instance('c-template')" action="{instance('exist-url')}eaditor/c-template.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Component Template.</xforms:message>
				<xforms:toggle case="file-list" ev:event="xforms-submit-done"/>
			</xforms:submission>
			<xforms:submission id="add-collection" ref="instance('eXist-xquery')" method="post" action="{instance('exist-url')}" replace="none" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error adding guides collection.</xforms:message>
			</xforms:submission>

			<!-- load ead guide temporarily -->
			<xforms:submission id="load-guide" serialization="none" method="get" action="{instance('exist-url')}eaditor/guides/{instance('control-instance')/id}.xml" replace="instance"
				instance="guide" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Cannot load finding aid.</xforms:message>
			</xforms:submission>

			<!-- delete finding aid -->
			<xforms:submission id="delete-guide" action="{instance('exist-url')}eaditor/guides/{instance('control-instance')/id}.xml" method="delete" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Finding aid successfully deleted.</xforms:setvalue>
			</xforms:submission>

			<!-- ************************* Solr **************************8 -->
			<!-- access service to read in pre-transformed solr doc -->
			<xforms:submission id="doc-to-solr" method="get" replace="instance" instance="addIndex" serialization="none" resource="/eaditor/solr/{instance('control-instance')/id}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming EAD guide to Solr document.</xforms:message>
				<xforms:send ev:event="xforms-submit-done" submission="post-to-solr"/>
			</xforms:submission>

			<!-- query Solr for the id of all currently published documents and repost them to solr -->
			<xforms:submission id="republish" serialization="none" method="get" action="{instance('control-instance')/solr-core}select/?q=*:*&amp;rows=10000&amp;start=0&amp;fl=id" replace="instance"
				instance="list-published-response">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr is inaccessible. Please check Solr configuration. [ADM001]</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
					<xforms:action xxforms:iterate="instance('list-published-response')//doc">
						<xxforms:variable name="id" select="str[@name='id']"/>
						<xforms:setvalue ref="instance('control-instance')/id" value="$id"/>
						<xforms:send submission="doc-to-solr"/>
					</xforms:action>
				</xforms:action><commit_msg>updated admin with new solr path<commit_after><?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2010 <NAME>
    EADitor: http://code.google.com/p/eaditor/
    Apache License 2.0: http://code.google.com/p/eaditor/    
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
	xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
	xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:ead="urn:isbn:1-931666-22-9" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude" xmlns:eaditor="https://github.com/ewg118/eaditor">
	<head>
		<title>EADitor: Administrative Interface</title>
		<link rel="stylesheet" href="/fr/style/bootstrap/css/bootstrap.css" type="text/css"/>
		<link rel="stylesheet" href="/fr/style/form-runner-bootstrap-override.css" type="text/css"/>
		<link rel="stylesheet" href="/config/theme/examples.css" type="text/css" media="all"/>
		<link rel="shortcut icon" href="/ops/images/orbeon-icon-16.ico"/>
		<link rel="icon" href="/ops/images/orbeon-icon-16.png" type="image/png"/>
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.8.0/build/cssgrids/grids-min.css"/>

		<!-- EADitor styling -->
		<link rel="stylesheet" href="/apps/eaditor/xforms/css/xforms.css"/>

		<!-- expand components (unnecessary to include jquery: orbeon already does -->
		<script type="text/javascript" src="/apps/eaditor/xforms/javascript/get_components.js"/>

		<xforms:model>
			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-url">
				<xi:include href="../exist-url.xml"/>
			</xforms:instance>

			<xforms:instance id="control-instance">
				<controls xmlns="">
					<id/>
					<status/>
					<error/>
					<numFound/>
					<page>1</page>
					<query_input/>
					<query_sent/>
					<solr-core/>
				</controls>
			</xforms:instance>

			<xforms:instance id="config">
				<config xmlns=""/>
			</xforms:instance>

			<xforms:instance id="config-template">
				<config xmlns:xlink="http://www.w3.org/1999/xlink">
					<firstrun/>
					<flickr_api_key/>
					<geonames_api_key/>
					<title>EADitor</title>
					<description/>
					<license>http://opendatacommons.org/licenses/odbl/</license>
					<banner_text>EADitor: XForms for EAD</banner_text>
					<banner_image xlink:href=""/>					
					<solr_published>http://localhost:8080/solr/eaditor-published/</solr_published>
					<url>http://localhost:8080/orbeon/eaditor/</url>
					<export>
						<oai-pmh>true</oai-pmh>
						<pelagios>false</pelagios>
					</export>					
					<theme>
						<facets>agency_facet,century_num,corpname_facet,famname_facet,genreform_facet,geogname_facet,language_facet,persname_facet,subject_facet</facets>
						<jquery_ui_theme>smoothness</jquery_ui_theme>
						<layouts>
							<index>
								<yui_class>yui-t5</yui_class>
							</index>
							<results>
								<yui_class>yui-t2</yui_class>
								<image_location>right</image_location>
							</results>
						</layouts>
					</theme>
					<machine_tags>
						<namespace id="geonames">
							<predicate>locality</predicate>
						</namespace>
						<namespace id="lcgft">
							<predicate>genreform</predicate>
						</namespace>
						<namespace id="lcsh">
							<predicate>subject</predicate>
						</namespace>
						<namespace id="pleiades">
							<predicate>atteststo</predicate>
							<predicate>depicts</predicate>
							<predicate>findspot</predicate>
							<predicate>origin</predicate>
							<predicate>place</predicate>
						</namespace>
						<namespace id="viaf">
							<predicate>depicts</predicate>
						</namespace>
					</machine_tags>
				</config>
			</xforms:instance>

			<xforms:instance id="instance-templates">
				<templates>
					<agencycodes>
						<agencycode value="default">Default Agency: Edit Your Template!</agencycode>
					</agencycodes>
					<containertypes>
						<container value="box">Box</container>
						<container value="box-folder">Box-Folder</container>
						<container value="folder">Folder</container>
						<container value="reel">Reel</container>
						<container value="tape">Tape</container>
					</containertypes>
				</templates>
			</xforms:instance>

			<xforms:instance id="ead-template">
				<ead id="" xmlns="urn:isbn:1-931666-22-9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"
					xsi:schemaLocation="urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd">
					<eadheader langencoding="iso639-2b">
						<eadid countrycode="US"/>
						<filedesc>
							<titlestmt>
								<titleproper/>
							</titlestmt>
						</filedesc>
					</eadheader>
					<archdesc level="collection">
						<did>
							<unittitle/>
						</did>
					</archdesc>
				</ead>
			</xforms:instance>
			<xforms:instance id="c-template">
				<c id="" level="" xmlns="urn:isbn:1-931666-22-9">
					<did>
						<unittitle/>
					</did>
				</c>
			</xforms:instance>

			<xforms:instance id="list">
				<list xmlns=""/>
			</xforms:instance>

			<xforms:instance id="item-template">
				<item xmlns="">
					<title/>
					<id/>
					<published/>
					<components/>
				</item>
			</xforms:instance>

			<xforms:instance id="guide">
				<ead xmlns=""/>
			</xforms:instance>

			<xforms:instance id="eXist-xquery">
				<exist:query xmlns="">
					<exist:text/>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="xqueries">
				<queries xmlns="">
					<query id="collection-count">&lt;report&gt;{count(collection())}&lt;/report&gt;</query>
					<query id="get-objects"> &lt;report> { for $record in subsequence(collection(), START, 20) let $type := $record/*/local-name() return if ($type='ead') then &lt;record> &lt;type>{
						$type }&lt;/type> &lt;id>{ $record//*[local-name()='eadid']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='archdesc']/*[local-name()='did']/*[local-name()='unittitle']/text() }&lt;/title> &lt;components>{ if (count($record//*[local-name()='c']) &gt; 0) then
						'true' else 'false' }&lt;/components> &lt;published/> &lt;/record> else &lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{
						$record//*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='mods']/*[local-name()='titleInfo']/*[local-name()='title']/text() }&lt;/title> &lt;published/> &lt;/record> } &lt;/report> </query>
					<query id="create-collection">xmldb:create-collection('/db/eaditor', 'guides')</query>
					<query id="publish-ead">&lt;report> { for $foo in collection() return if($foo[child::node()[local-name()='ead']]) then &lt;item> { $foo/*[local-name()='ead']/@id } &lt;/item> else
						'' } &lt;/report></query>
					<query id="publish-mods">&lt;report xmlns:mods="http://www.loc.gov/mods/v3"> { for $foo in collection() return if($foo[child::node()[local-name()='modsCollection']]) then &lt;item>
						{ $foo/*[local-name()='modsCollection']/*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier'] } &lt;/item> else '' } &lt;/report></query>
					<query id="query-objects"> &lt;report> { for $record in collection()[contains(descendant::*[local-name()='unittitle'], 'QUERY') or descendant::*[local-name()='eadid'] = 'QUERY' or
						descendant::*[local-name()='identifier'] = 'QUERY' or descendant::*[local-name()='recordIdentifier'] = 'QUERY' or contains(descendant::*[local-name()='title'], 'QUERY')] let $type := $record/*/local-name() return if ($type='ead') then
						&lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{ $record//*[local-name()='eadid']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='archdesc']/*[local-name()='did']/*[local-name()='unittitle']/text() }&lt;/title> &lt;components>{ if (count($record//*[local-name()='c']) &gt; 0) then
						'true' else 'false' }&lt;/components> &lt;published/> &lt;/record> else &lt;record> &lt;type>{ $type }&lt;/type> &lt;id>{
						$record//*[local-name()='mods']/*[local-name()='recordInfo']/*[local-name()='recordIdentifier']/text() }&lt;/id> &lt;title>{
						$record//*[local-name()='mods']/*[local-name()='titleInfo']/*[local-name()='title']/text() }&lt;/title> &lt;published/> &lt;/record> } &lt;/report> </query>
				</queries>
			</xforms:instance>

			<xforms:instance id="pagination-result">
				<exist:result/>
			</xforms:instance>

			<xforms:instance id="xquery-result">
				<exist:result/>
			</xforms:instance>

			<!-- solr response for id query -->
			<xforms:instance id="published-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="list-published-response">
				<response xmlns=""/>
			</xforms:instance>

			<!-- send to Solr -->
			<xforms:instance id="addIndex">
				<add xmlns=""/>
			</xforms:instance>
			<xforms:instance id="addDoc">
				<add xmlns=""/>
			</xforms:instance>
			<!-- Instance for Solr commit-->
			<xforms:instance id="sendCommit">
				<commit/>
			</xforms:instance>
			<!-- delete from Solr -->
			<xforms:instance id="deleteId">
				<delete xmlns="">
					<id/>
				</delete>
			</xforms:instance>
			<xforms:instance id="deleteAll">
				<delete xmlns="">
					<query>id:*</query>
				</delete>
			</xforms:instance>

			<xforms:instance id="optimizeIndex">
				<optimize/>
			</xforms:instance>

			<xforms:bind nodeset="instance('config-template')">
				<xforms:bind nodeset="title" required="true()"/>
				<xforms:bind nodeset="url" required="true()" type="xs:anyURI"/>
				<xforms:bind nodeset="solr_published" required="true()" type="xs:anyURI"/>
			</xforms:bind>


			<!-- submissions -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-url')}eaditor/config.xml" replace="instance" instance="config">
				<xforms:action ev:event="xforms-submit-done">
					<!-- get the number of docs in the eXist collection() -->
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='collection-count']"/>
					<xforms:send submission="xquery-collection"/>
					<xforms:setvalue ref="instance('control-instance')/numFound" value="number(instance('xquery-result'))"/>
					<!-- set value in control instance -->

					<xxforms:variable name="end" select="if(instance('control-instance')/numFound &gt; 20) then 20 else instance('control-instance')/numFound"/>
					<!-- get list of files for page 1, replacing START and END -->
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="replace(instance('xqueries')/query[@id='get-objects'], 'START', '1')"/>
					<xforms:send submission="xquery-pagination"/>
				</xforms:action>
				<xforms:action ev:event="xforms-submit-error">
					<xforms:setvalue ref="instance('config-template')/firstrun">true</xforms:setvalue>
				</xforms:action>
			</xforms:submission>

			<!-- xquery for getting and processing query results into pages of items -->
			<xforms:submission id="xquery-pagination" ref="instance('eXist-xquery')" action="{instance('exist-url')}eaditor/guides/" method="post" replace="instance" instance="pagination-result">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Error querying eXist database.</xforms:setvalue>
				<xforms:action ev:event="xforms-submit-done">
					<!--iterate through docs, check for publication -->
					<xforms:action xxforms:iterate="instance('pagination-result')//record">
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
						<xforms:setvalue ref="instance('control-instance')/id" value="context()/id"/>
						<xforms:send submission="query-solr-for-publication"/>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<!-- generic xquery -->
			<xforms:submission id="xquery-collection" ref="instance('eXist-xquery')" action="{instance('exist-url')}eaditor/guides/" method="post" replace="instance" instance="xquery-result">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Error querying eXist database.</xforms:setvalue>
			</xforms:submission>

			<!-- submission to query solr to see if the document is published -->
			<xforms:submission id="query-solr-for-publication" serialization="none" method="get" action="{instance('control-instance')/solr-core}select/?q=id:{instance('control-instance')/id}"
				replace="instance" instance="published-response">
				<!-- if the document is found in solr, get the updated solr doc -->
				<xforms:setvalue ev:event="xforms-submit-done" if="instance('published-response')/result[@name='response']/@numFound = '1'"
					ref="instance('pagination-result')//record[id=instance('control-instance')/id]/published" value="'true'"/>
			</xforms:submission>

			<!-- save templates and add guides collection to eXist on the first run of EADitor -->
			<xforms:submission id="save-config" ref="instance('config-template')" action="{instance('exist-url')}eaditor/config.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Config.</xforms:message>
				<!-- reload the config after it has been created -->
				<xforms:send submission="load-config" ev:event="xforms-submit-done"/>
			</xforms:submission>
			<xforms:submission id="save-instance-templates" ref="instance('instance-templates')" action="{instance('exist-url')}eaditor/instance-templates.xml" method="put" replace="none"
				xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Agency Codes Template.</xforms:message>
			</xforms:submission>
			<xforms:submission id="save-ead-template" ref="instance('ead-template')" action="{instance('exist-url')}eaditor/ead-template.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving EAD Template.</xforms:message>
			</xforms:submission>
			<xforms:submission id="save-c-template" ref="instance('c-template')" action="{instance('exist-url')}eaditor/c-template.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Component Template.</xforms:message>
				<xforms:toggle case="file-list" ev:event="xforms-submit-done"/>
			</xforms:submission>
			<xforms:submission id="add-collection" ref="instance('eXist-xquery')" method="post" action="{instance('exist-url')}" replace="none" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error adding guides collection.</xforms:message>
			</xforms:submission>

			<!-- load ead guide temporarily -->
			<xforms:submission id="load-guide" serialization="none" method="get" action="{instance('exist-url')}eaditor/guides/{instance('control-instance')/id}.xml" replace="instance"
				instance="guide" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Cannot load finding aid.</xforms:message>
			</xforms:submission>

			<!-- delete finding aid -->
			<xforms:submission id="delete-guide" action="{instance('exist-url')}eaditor/guides/{instance('control-instance')/id}.xml" method="delete" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Finding aid successfully deleted.</xforms:setvalue>
			</xforms:submission>

			<!-- ************************* Solr **************************8 -->
			<!-- access service to read in pre-transformed solr doc -->
			<xforms:submission id="doc-to-solr" method="get" replace="instance" instance="addIndex" serialization="none" resource="/eaditor/id/{instance('control-instance')/id}.solr">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming EAD guide to Solr document.</xforms:message>
				<xforms:send ev:event="xforms-submit-done" submission="post-to-solr"/>
			</xforms:submission>

			<!-- query Solr for the id of all currently published documents and repost them to solr -->
			<xforms:submission id="republish" serialization="none" method="get" action="{instance('control-instance')/solr-core}select/?q=*:*&amp;rows=10000&amp;start=0&amp;fl=id" replace="instance"
				instance="list-published-response">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr is inaccessible. Please check Solr configuration. [ADM001]</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
					<xforms:action xxforms:iterate="instance('list-published-response')//doc">
						<xxforms:variable name="id" select="str[@name='id']"/>
						<xforms:setvalue ref="instance('control-instance')/id" value="$id"/>
						<xforms:send submission="doc-to-solr"/>
					</xforms:action>
				</xforms:action>
{'fraction_non_alphanumeric': 0.2043301365882011, 'fraction_numerical': 0.007904678872420808, 'mean_word_length': 4.4838247011952195, 'pattern_counts': {'":': 0, '<': 659, '<?xml version=': 2, '>': 763, 'https://': 2, 'lorem ipsum': 0, 'www.': 20, 'xml': 92}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7177286', 'n_tokens_mistral': 13803, 'n_tokens_neox': 11358, 'n_words': 1758}