Commit edacc080 authored by Anne Goloubkoff-Duponchel's avatar Anne Goloubkoff-Duponchel
Browse files

renommage du dossier plugin en ead_metadata

parent cb74d7d7
Loading
Loading
Loading
Loading

plugins/metadata/README.md

deleted100644 → 0
+0 −11
Original line number Diff line number Diff line
# Plugin metadata

Route permettant d'afficher les métadonnées des fichiers xml, comme eadheader et archdesc.

La route associée est de type `projet/info/tag.html``tag` est l'élément que l'on veut afficher.

Pour l'instant, cette route a été testée avec `eadheader` et `archdesc`. 

La balise `archdesc` est gérée de façon particulière pour que la xquery ne récupère pas l'ensemble des balises `c` qu'elle contient. Car trop compliqué à gérer en xsl.

Les `xsl` utilisées, nommées `[tag].xsl`, sont celles trouvées dans le dossier du projet s'il y en a, sinon on applique celles qui se trouvent dans le dossier du plugin.

plugins/metadata/archdesc.xsl

deleted100644 → 0
+0 −129
Original line number Diff line number Diff line
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ead="urn:isbn:1-931666-22-9"
    xmlns:max="https://max.unicaen.fr" exclude-result-prefixes="ead xsl max">

   <!-- Pour une xsl dans le dossier édition, modifier le chemin
    <xsl:import href="../../../../../ui/xsl/core/i18n.xsl"/>-->
    <xsl:import href="../../ui/xsl/core/i18n.xsl"/>
    <xsl:param name="project"/>
    <xsl:param name="locale"/>

    <xsl:template match="/">
        <div>
            <xsl:apply-templates />
        </div>
    </xsl:template>

    <xsl:template match="div/ead:*">
        <table class="ead_details {local-name(.)}">
             <tr>
                     <th class="titreTabHeader">
                        <xsl:variable name="i18nKey">
                            <xsl:value-of select="local-name(.)" />
                            <xsl:if test="@role">
                                <xsl:text>@</xsl:text>
                                <xsl:value-of select="@role" />
                            </xsl:if>
                        </xsl:variable>
                        <xsl:value-of select="max:i18n($project,$i18nKey,$locale)"/>
                    </th>
                    <td>
                        <xsl:apply-templates />
                    </td>
                </tr>
        </table>
    </xsl:template>

       <xsl:template match="div/ead:*//ead:*">
                    <xsl:choose>
            <!-- on masque par défaut certaines balises, comme p-->
            <xsl:when test="(local-name(.)='p')">
                <xsl:apply-templates />
            </xsl:when>
            <xsl:otherwise>
                <tr>
                    <th>
                        <xsl:variable name="i18nKey">
                            <xsl:value-of select="local-name(.)" />
                            <xsl:if test="@role">
                                <xsl:text>@</xsl:text>
                                <xsl:value-of select="@role" />
                            </xsl:if>
                        </xsl:variable>
                        <xsl:value-of select="max:i18n($project,$i18nKey,$locale)"/>
                    </th>
                    <td>
                        <xsl:apply-templates />
                    </td>
                </tr>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


     <xsl:template match="div/ead:controlaccess/ead:subject | div/ead:controlaccess/ead:geogname">
        <li class="{local-name(.)}">
            <xsl:apply-templates />
        </li>
    </xsl:template>

    <!-- on gère les éléments inline, comme emph, extref, et les lb -->
    <xsl:template match="//ead:emph">
        <xsl:choose>
            <xsl:when test="./@render='bold'">
                <span class="bold">
                    <xsl:apply-templates />
                </span>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="//ead:extref | //ead:archref">
        <a href="{@href}" target="_blank">
            <xsl:apply-templates />
        </a>
    </xsl:template>

    <xsl:template match="//ead:lb">
        <br/>
    </xsl:template>

     <!-- certains éléments sont à conserver dans le fil du texte 
        comme les éléments date, addressline, language (peut dépendre du contexte) -->

    <xsl:template match="//ead:language | //ead:corpname">
        <span class="{local-name(.)}">
            <xsl:apply-templates />
        </span>
    </xsl:template>

        <xsl:template match="//ead:address/ead:addressline">
              <span class="addressline"><xsl:apply-templates /><br/></span>
    </xsl:template>

    <xsl:template match="//ead:head">
        <h2>
            <xsl:apply-templates />
        </h2>
    </xsl:template>

    <xsl:template match="//ead:list">
        <ul>
            <xsl:apply-templates />
        </ul>
    </xsl:template>

    <xsl:template match="//ead:item">
        <li>
            <xsl:apply-templates />
        </li>
    </xsl:template>

 


</xsl:stylesheet>
 No newline at end of file

plugins/metadata/eadheader.xsl

deleted100644 → 0
+0 −148
Original line number Diff line number Diff line
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ead="urn:isbn:1-931666-22-9"
    xmlns:max="https://max.unicaen.fr" 
    exclude-result-prefixes="ead xsl max">

    <xsl:import href="../../ui/xsl/core/i18n.xsl"/>
    <xsl:param name="project"/>
    <xsl:param name="locale"/>

    <xsl:template match="ead:eadheader">
        <div>
            <xsl:apply-templates />
        </div>
    </xsl:template>

    <!-- 
        Si les balises sont présentes dans le fichier xml, 
        4 tableaux sont créés pour les éléments eadid, filedesc, 
        profiledesc et revisiondesc
        Un template spécifique est fait pour eadid 
        qui n'a pas tout à fait la même construction
     -->
    <xsl:template match="ead:eadheader/ead:*">
        <table class="ead_details {local-name(.)}">
            <tr>
                <th class="titreTabHeader">
                <!-- 
                pour l'affichage des révisions : 
                on compte le nombre de balises pour ajouter un rowspan
                -->
                    <xsl:if test="local-name(.)='revisiondesc'">
                        <xsl:attribute name="rowspan">
                            <xsl:value-of select="count(//ead:date) + count(//ead:item) + count(//ead:change) + 1" />
                        </xsl:attribute>
                    </xsl:if>
                    <xsl:variable name="i18nKey">
                        <xsl:value-of select="local-name(.)" />
                    </xsl:variable>
                    <xsl:value-of select="max:i18n($project,$i18nKey,$locale)"/>
                </th>
                <xsl:apply-templates />
            </tr>
        </table>
    </xsl:template>
    <!--
        Template spécifique pour le tableau du eadid 
        qui n'a pas tout à fait la même construction
     -->
    <xsl:template match="ead:eadheader/ead:eadid">
        <table class="ead_details {local-name(.)}">
            <tr>
                <th class="titreTabHeader">
                    <xsl:variable name="i18nKey">
                        <xsl:value-of select="local-name(.)" />
                    </xsl:variable>
                    <xsl:value-of select="max:i18n($project,$i18nKey,$locale)"/>
                </th>
                <td>
                    <xsl:apply-templates />
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="ead:eadheader/ead:*//ead:*">
        <xsl:choose>
            <!-- on masque par défaut les titres, comme titleStmt et publicationStmt-->
            <xsl:when test="(local-name(.)='titlestmt') or (local-name(.)='publicationstmt')">
                <xsl:apply-templates />
            </xsl:when>
            <xsl:otherwise>
                <tr>
                    <th>
                        <xsl:variable name="i18nKey">
                            <xsl:value-of select="local-name(.)" />
                        </xsl:variable>
                        <xsl:value-of select="max:i18n($project,$i18nKey,$locale)"/>
                    </th>
                    <td>
                        <xsl:apply-templates />
                    </td>
                </tr>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

   <!-- pour les révisions on masque les balises change, item et date -->
    <xsl:template match="ead:eadheader/ead:revisiondesc//ead:*">
        <tr>
            <td>
                <xsl:apply-templates />
            </td>
        </tr>
    </xsl:template>


    <!-- on gère les éléments inline, comme emph, extref, et les lb -->
    <xsl:template match="//ead:emph">
        <xsl:choose>
            <xsl:when test="./@render='bold'">
                <span class="bold">
                    <xsl:apply-templates />
                </span>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="//ead:extref">
        <a href="{href}">
            <xsl:apply-templates />
        </a>
    </xsl:template>

    <xsl:template match="//ead:lb">
        <br/>
    </xsl:template>

    <!-- certains éléments sont à conserver dans le fil du texte 
        comme les éléments date, addressline, language (peut dépendre du contexte) -->

    <xsl:template match="//ead:language">
        <span class="language">
            <xsl:apply-templates />
        </span>
    </xsl:template>

    <xsl:template match="//ead:creation/ead:date">
              <span class="date"><xsl:apply-templates /></span>
    </xsl:template>

    <xsl:template match="//ead:address/ead:addressline">
              <span class="addressline"><xsl:apply-templates /></span>
    </xsl:template>

    <xsl:template match="//ead:editionstmt/ead:edition">
              <span class="edition"><xsl:apply-templates /></span>
    </xsl:template>






</xsl:stylesheet>
 No newline at end of file

plugins/metadata/metadata.xq

deleted100644 → 0
+0 −80
Original line number Diff line number Diff line
xquery version "3.0";

module namespace max.plugin.metadata = 'pddn/max/plugin/metadata';
import module namespace max.config = 'pddn/max/config' at '../../rxq/config.xqm';
import module namespace max.util = 'pddn/max/util' at '../../rxq/util.xqm';
import module namespace max.html = 'pddn/max/html' at '../../rxq/html.xqm';
import module namespace max.max = 'pddn/max' at '../../max.xq';
import module namespace max.i18n = 'pddn/max/i18n' at '../../rxq/i18n.xqm';

declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace ead="urn:isbn:1-931666-22-9";
declare variable $max.plugin.metadata:PLUGIN_ID := "metadata";


declare
%rest:GET
%output:method("html")
%output:html-version("5.0")
%output:indent("no")
%output:encoding("UTF-8")
%rest:query-param("search", "{$search}")
%rest:query-param("focus", "{$focus}")
%rest:path("/{$project}/{$doc=.*}/info/{$tag}.html")
function max.plugin.metadata:getMetadataDocument($project, $doc, $tag, $search as xs:string ?, $focus as xs:string ?){
    let $dbPath := max.config:getProjectDBPath($project)
    let $xml := max.plugin.metadata:getXMLByTag($project, $dbPath, $doc, $tag) 
    let $projectXSL := file:parent(file:parent(file:parent(static-base-uri())))||"editions/"||$project||"/ui/xsl/ead/" || $tag || ".xsl"
    let $maxXSL :=  max.util:maxHome() ||  "/" || "/plugins/metadata/" || $tag || ".xsl"
    let $xsl := if (file:exists($projectXSL))
                then $projectXSL
                else $maxXSL
    let $html := max.html:render(
            $project, $doc,
            <div>
                <div class="plugins-wrapper">{max.html:invokePluginXQueries($project, $doc, ())}</div>
                <div id='text'>
                  {xslt:transform(
                    $xml, 
                    $xsl,
                    map {
                        'project' : $project,
                        'locale': max.i18n:getLang($project)
                        })}  
                </div>
            </div>)
            return $html 
};

declare function max.plugin.metadata:getXMLByTag($project, $dbPath, $doc, $tag){
    
        switch ($tag)
        case "archdesc" return
            try{
                
                    let $queryArchdesc := '<div>{doc("'||$dbPath || '/' || $doc ||'")/*:ead/*:archdesc/* except doc("'|| $dbPath || '/' || $doc ||'")/*:ead/*:archdesc/*:dsc}</div>'
                    return 
                    xquery:eval($queryArchdesc,map
                        {
                        'project':$project,
                        'locale': max.i18n:getLang($project)
                        })
                }
                catch *{
                <div class='error'>{'Error [' || $err:code || '/' || $err:module || '/' || $err:line-number ||']: ' || $err:description}</div>
                }
        default return
            try{
                    let $queryHeader := 'doc("'||$dbPath || '/' || $doc ||'")//*:ead/*:'|| $tag
                    return 
                    xquery:eval($queryHeader,map
                        {
                        'project':$project,
                        'locale': max.i18n:getLang($project)
                        })
                }
            catch *{
                <div class='error'>"{'Error [' || $err:code || '/' || $err:module || '/' || $err:line-number ||']: ' || $err:description}""MaX - Erreur = Vérifier l'URL"</div>
                }

};
 No newline at end of file