Skip to content

Commit

Permalink
fixed some file upload problems, using xforms:upload, not fr:, remove…
Browse files Browse the repository at this point in the history
…d space from filename, encoding filename for URI
  • Loading branch information
ewg118 committed Dec 16, 2016
1 parent 135e85c commit f9eceae
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 56 deletions.
4 changes: 3 additions & 1 deletion solr-home/4.10/conf/schema.xml
Expand Up @@ -101,7 +101,9 @@
<field name="title" type="ignored"/>
<field name="author" type="ignored"/>
<field name="date" type="ignored"/>
<field name="content" type="text_general" indexed="false" stored="true" multiValued="false"/>

<!-- fulltext -->
<field name="content" type="text_general" indexed="false" stored="true" multiValued="false"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

<copyField source="content" dest="text"/>
Expand Down
121 changes: 70 additions & 51 deletions ui/xslt/serializations/ead/solr.xsl
@@ -1,46 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ead="urn:isbn:1-931666-22-9"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:datetime="http://exslt.org/dates-and-times"
xmlns:eaditor="https://github.com/ewg118/eaditor" exclude-result-prefixes="#all" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ead="urn:isbn:1-931666-22-9" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:datetime="http://exslt.org/dates-and-times" xmlns:eaditor="https://github.com/ewg118/eaditor" exclude-result-prefixes="#all" version="2.0">

<xsl:variable name="upload" select="boolean(descendant::ead:archdesc/ead:otherfindaid[@type = 'eaditor_upload']/ead:bibref/ead:extptr/@xlink:href)"/>

<xsl:variable name="upload" select="boolean(descendant::ead:archdesc/ead:otherfindaid[@type='eaditor_upload']/ead:bibref/ead:extptr/@xlink:href)"/>

<!-- config variables -->
<xsl:variable name="url" select="/content/config/url"/>
<xsl:variable name="geonames_api_key" select="/content/config/geonames_api_key"/>
<xsl:variable name="flickr-api-key" select="/content/config/flickr_api_key"/>
<xsl:variable name="collection-name" select="substring-before(substring-after(doc('input:request')/request/request-url, 'eaditor/'), '/')"/>

<xsl:variable name="geonames-url">
<xsl:text>http://api.geonames.org</xsl:text>
</xsl:variable>

<xsl:variable name="places" as="node()*">
<places>
<xsl:for-each select="descendant::ead:geogname[@source='geonames' and string(@authfilenumber)]">
<xsl:for-each select="descendant::ead:geogname[@source = 'geonames' and string(@authfilenumber)]">
<xsl:variable name="geonames_data" as="node()*">
<xsl:copy-of select="document(concat($geonames-url, '/get?geonameId=', @authfilenumber, '&amp;username=', $geonames_api_key, '&amp;style=full'))"/>
<xsl:copy-of
select="document(concat($geonames-url, '/get?geonameId=', @authfilenumber, '&amp;username=', $geonames_api_key, '&amp;style=full'))"/>
</xsl:variable>

<place authfilenumber="{@authfilenumber}">
<xsl:value-of select="concat($geonames_data//lng, ',', $geonames_data//lat)"/>
</place>
</xsl:for-each>
</places>
</xsl:variable>

<xsl:template match="/">
<xsl:apply-templates select="/content/ead:ead"/>
</xsl:template>

<xsl:template match="ead:ead">
<xsl:variable name="title" select="ead:archdesc/ead:did/ead:unittitle"/>
<xsl:variable name="recordId" select="ead:eadheader/ead:eadid"/>
<xsl:variable name="archdesc-level" select="ead:archdesc/@level"/>

<add>
<!--<xsl:copy-of select="/content/pleiades"/>-->

<xsl:if test="/content/config/levels/archdesc/@enabled = true()">
<xsl:call-template name="ead-doc">
<xsl:with-param name="title" select="$title"/>
Expand Down Expand Up @@ -75,12 +76,16 @@
<xsl:param name="title"/>
<xsl:param name="recordId"/>
<xsl:param name="archdesc-level"/>
<xsl:variable name="id" select="if (string(ead:eadheader/ead:eadid)) then ead:eadheader/ead:eadid else @id"/>
<xsl:variable name="id" select="
if (string(ead:eadheader/ead:eadid)) then
ead:eadheader/ead:eadid
else
@id"/>

<doc>
<field name="id">
<xsl:value-of select="$id"/>
</field>
</field>
<field name="recordId">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand All @@ -93,21 +98,33 @@
</xsl:if>
<xsl:value-of select="$collection-name"/>
</field>
<xsl:if test="local-name()='c'">
<xsl:if test="local-name() = 'c'">
<field name="cid">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:value-of select="$id"/>
</field>
</xsl:if>

<field name="level_facet">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:value-of select="if (local-name()='c') then @level else ead:archdesc/@level"/>
<xsl:value-of select="
if (local-name() = 'c') then
@level
else
ead:archdesc/@level"/>
</field>

<field name="oai_set">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:text>ead</xsl:text>
</field>
<field name="oai_set">ead</field>

<field name="oai_id">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand Down Expand Up @@ -135,7 +152,7 @@
</field>
</xsl:for-each>
<!-- if the doc is a component, added dsc_hier field for the archdesc -->
<xsl:if test="local-name()='c'">
<xsl:if test="local-name() = 'c'">
<field name="dsc_hier">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand Down Expand Up @@ -210,15 +227,11 @@
<field name="text">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">add</xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:for-each select="descendant-or-self::node()">
<xsl:for-each select="//ead:archdesc/descendant-or-self::node()">
<xsl:value-of select="text()"/>
<xsl:text> </xsl:text>
<xsl:if test="@normal">
<xsl:value-of select="@normal"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</field>
</doc>
Expand All @@ -229,19 +242,19 @@
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:value-of select="ead:daoloc[@xlink:label='Thumbnail']/@xlink:href"/>
<xsl:value-of select="ead:daoloc[@xlink:label = 'Thumbnail']/@xlink:href"/>
</field>
<field name="collection_reference">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:choose>
<!-- display Medium primarily, Small secondarily -->
<xsl:when test="string(ead:daoloc[@xlink:label='Medium']/@xlink:href)">
<xsl:value-of select="ead:daoloc[@xlink:label='Medium']/@xlink:href"/>
<xsl:when test="string(ead:daoloc[@xlink:label = 'Medium']/@xlink:href)">
<xsl:value-of select="ead:daoloc[@xlink:label = 'Medium']/@xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ead:daoloc[@xlink:label='Small']/@xlink:href"/>
<xsl:value-of select="ead:daoloc[@xlink:label = 'Small']/@xlink:href"/>
</xsl:otherwise>
</xsl:choose>
</field>
Expand Down Expand Up @@ -271,7 +284,7 @@
<xsl:if test="local-name() = 'geogname' and string(@authfilenumber)">
<xsl:variable name="authfilenumber" select="@authfilenumber"/>
<xsl:choose>
<xsl:when test="@source='geonames'">
<xsl:when test="@source = 'geonames'">
<field name="georef">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand All @@ -280,10 +293,10 @@
<xsl:text>|</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="$places//place[@authfilenumber=$authfilenumber]"/>
<xsl:value-of select="$places//place[@authfilenumber = $authfilenumber]"/>
</field>
</xsl:when>
<xsl:when test="@source='pleiades'">
<xsl:when test="@source = 'pleiades'">
<field name="georef">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand All @@ -292,7 +305,8 @@
<xsl:text>|</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="concat(/content/pleiades/place[@id=$authfilenumber]/long, ',', /content/pleiades/place[@id=$authfilenumber]/lat)"/>
<xsl:value-of
select="concat(/content/pleiades/place[@id = $authfilenumber]/long, ',', /content/pleiades/place[@id = $authfilenumber]/lat)"/>
</field>
</xsl:when>
</xsl:choose>
Expand All @@ -302,22 +316,22 @@
<xsl:if test="string(@authfilenumber)">
<xsl:variable name="resource">
<xsl:choose>
<xsl:when test="@source='aat'">
<xsl:when test="@source = 'aat'">
<xsl:value-of select="concat('http://vocab.getty.edu/aat/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="@source='tgn'">
<xsl:when test="@source = 'tgn'">
<xsl:value-of select="concat('http://vocab.getty.edu/tgn/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="@source='geonames'">
<xsl:when test="@source = 'geonames'">
<xsl:value-of select="concat('http://www.geonames.org/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="@source='pleiades'">
<xsl:when test="@source = 'pleiades'">
<xsl:value-of select="concat('http://pleiades.stoa.org/places/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="@source='lcsh' or @source='lcgft'">
<xsl:when test="@source = 'lcsh' or @source = 'lcgft'">
<xsl:value-of select="concat('http://id.loc.gov/authorities/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="@source='viaf'">
<xsl:when test="@source = 'viaf'">
<xsl:value-of select="concat('http://viaf.org/viaf/', @authfilenumber)"/>
</xsl:when>
<xsl:when test="contains(@authfilenumber, 'http://')">
Expand All @@ -333,7 +347,7 @@
</xsl:if>
<xsl:value-of select="$resource"/>
</field>
<xsl:if test="@source='pleiades'">
<xsl:if test="@source = 'pleiades'">
<field name="pleiades_uri">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
Expand Down Expand Up @@ -373,7 +387,7 @@
</xsl:if>
<xsl:for-each select="ead:unitdate">
<xsl:value-of select="."/>
<xsl:if test="not(position()=last())">
<xsl:if test="not(position() = last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
Expand All @@ -384,7 +398,7 @@
<xsl:call-template name="eaditor:get_date_hierarchy">
<xsl:with-param name="date" select="."/>
</xsl:call-template>

</xsl:for-each>
</xsl:for-each>
</xsl:if>
Expand All @@ -405,16 +419,21 @@
</field>
</xsl:if>
</xsl:template>

<!-- functions -->
<xsl:template name="eaditor:get_date_hierarchy">
<xsl:param name="date"/>

<xsl:if test="$date castable as xs:gYear">
<xsl:variable name="year_string" select="string(abs(number($date)))"/>
<xsl:variable name="century" select="if(number($date) &gt; 0) then ceiling(number($date) div 100) else floor(number($date) div 100)"/>
<xsl:variable name="decade" select="floor(abs(number($date)) div 10) * 10"/>

<xsl:variable name="century"
select="
if (number($date) &gt; 0) then
ceiling(number($date) div 100)
else
floor(number($date) div 100)"/>
<xsl:variable name="decade" select="floor(abs(number($date)) div 10) * 10"/>

<xsl:if test="number($century)">
<field name="century_num">
<xsl:if test="$upload = true()">
Expand All @@ -432,12 +451,12 @@
<xsl:if test="number($date)">
<field name="year_num">
<xsl:if test="$upload = true()">
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:attribute name="update">set</xsl:attribute>
</xsl:if>
<xsl:value-of select="number($date)"/>
</field>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
21 changes: 17 additions & 4 deletions xforms/xbl/otherfindaid/otherfindaid.xbl
Expand Up @@ -51,19 +51,19 @@
<div>
<h4>Upload</h4>
</div>
<fr:upload ref="instance('file')">
<xforms:upload ref="instance('file')">
<xforms:filename ref="@filename"/>
<xforms:mediatype ref="@mediatype"/>
<xxforms:size ref="@size"/>
</fr:upload>
</xforms:upload>
<br/>
<xforms:trigger>
<xforms:label>Upload</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:send submission="upload-file"/>
<!--get the temp file written to disk, and move it into the docs folder in the etdpub app directory -->
<xforms:action ev:event="xforms-submit-done">
<xforms:var name="filename" select="concat(substring(string(digest( string( random( true ) ), 'MD5', 'hex' )), 1, 6), '_', instance('file')/@filename)"/>
<xforms:var name="filename" select="concat(substring(string(digest( string( random( true ) ), 'MD5', 'hex' )), 1, 6), '_', encode-for-uri(replace(instance('file')/@filename, ' ', '_')))"/>

<xforms:setvalue ref="instance('generator-config')/url" value="instance('file')"/>
<xforms:setvalue ref="instance('generator-config')/content-type" value="instance('file')/@mediatype"/>
Expand All @@ -79,7 +79,14 @@
</xforms:trigger>
<xforms:trigger>
<xforms:label>Cancel</xforms:label>
<xforms:delete ev:event="DOMActivate" nodeset="$binding"/>
<xforms:action ev:event="DOMActivate">
<!-- clear file parameters and delete the node -->
<xforms:setvalue ref="instance('file')"/>
<xforms:setvalue ref="instance('file')/@filename"/>
<xforms:setvalue ref="instance('file')/@mediatype"/>
<xforms:setvalue ref="instance('file')/@size"/>
<xforms:delete nodeset="$binding"/>
</xforms:action>
</xforms:trigger>
</div>
</xforms:group>
Expand Down Expand Up @@ -188,6 +195,12 @@
<fr:positive-choice>
<fr:label>Yes</fr:label>
<xforms:action ev:event="DOMActivate">
<!-- clear file parameters and delete the node -->
<xforms:setvalue ref="instance('file')"/>
<xforms:setvalue ref="instance('file')/@filename"/>
<xforms:setvalue ref="instance('file')/@mediatype"/>
<xforms:setvalue ref="instance('file')/@size"/>

<!-- delete the file -->
<xforms:setvalue ref="instance('delete-config')/delete/url" value="concat('oxf:/apps/eaditor/uploads/', xxforms:get-session-attribute('collection-name'), '/',
$binding/ead:bibref/ead:extptr/@xlink:href)"/>
Expand Down

0 comments on commit f9eceae

Please sign in to comment.