Changeset 6907 for metadata


Ignore:
Timestamp:
01/14/16 12:05:44 (8 years ago)
Author:
Menzo Windhouwer
Message:

M toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

  • unescaped escaped CMDI 1.2 attributes
  • warn when a @ref contains multiple resource proxy references, and use only the first one

M toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl

  • escape attributes that would clash with CMDI 1.1 reserved attributes

M toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd
A toolkit/src/main/resources/toolkit/sch/cmd-component-best-practices.sch

  • moved Schematron rules which are validate best practices

M toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

  • removed obsolete commented out code
Location:
metadata/trunk/toolkit/src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl

    r6904 r6907  
    88
    99    <xsl:param name="cmd-component-xsd" select="'http://infra.clarin.eu/cmd/general-component-schema.xsd'"/>
     10   
     11    <xsl:param name="escape" select="'ccmmddii_'"/>
    1012   
    1113    <!-- identity copy -->
     
    8082    <!-- turn Attribute child elements into attributes -->
    8183    <xsl:template match="Attribute" priority="1">
    82         <xsl:choose>
    83             <xsl:when test="exists(parent::AttributeList/parent::Component) and Name=('ref','ComponentId')">
    84                 <xsl:message>WRN: user-defined ref and ComponentId attributes for a Component are not supported by CMDI 1.1!</xsl:message>
    85             </xsl:when>
    86             <xsl:otherwise>
    87                 <Attribute>
    88                     <Name>
    89                         <xsl:value-of select="@name"/>
    90                     </Name>
    91                     <xsl:if test="normalize-space(@ConceptLink)!=''">
    92                         <ConceptLink>
    93                             <xsl:value-of select="@ConceptLink"/>
    94                         </ConceptLink>
    95                     </xsl:if>
    96                     <xsl:if test="normalize-space(@ValueScheme)!=''">
    97                         <Type>
    98                             <xsl:value-of select="@ValueScheme"/>
    99                         </Type>
    100                     </xsl:if>
    101                     <!-- @Required is skipped -->
    102                     <xsl:apply-templates select="node()"/>
    103                 </Attribute>
    104             </xsl:otherwise>
    105         </xsl:choose>
     84        <xsl:variable name="name">
     85            <xsl:choose>
     86                <xsl:when test="exists(parent::AttributeList/parent::Component) and Name=('ref','ComponentId')">
     87                    <xsl:message>WRN: user-defined ref and ComponentId attributes for a Component are not supported by CMDI 1.1! Adding the <xsl:value-of select="$escape"/> prefix</xsl:message>
     88                    <xsl:value-of select="concat($escape,@name)"/>
     89                </xsl:when>
     90                <xsl:otherwise>
     91                    <xsl:value-of select="@name"/>
     92                </xsl:otherwise>
     93            </xsl:choose>
     94        </xsl:variable>
     95        <Attribute>
     96            <Name>
     97                <xsl:value-of select="$name"/>
     98            </Name>
     99            <xsl:if test="normalize-space(@ConceptLink)!=''">
     100                <ConceptLink>
     101                    <xsl:value-of select="@ConceptLink"/>
     102                </ConceptLink>
     103            </xsl:if>
     104            <xsl:if test="normalize-space(@ValueScheme)!=''">
     105                <Type>
     106                    <xsl:value-of select="@ValueScheme"/>
     107                </Type>
     108            </xsl:if>
     109            <!-- @Required is skipped -->
     110            <xsl:apply-templates select="node()"/>
     111        </Attribute>
    106112    </xsl:template>
    107113   
  • metadata/trunk/toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

    r6751 r6907  
    1212    <xsl:param name="cmd-uri" select="'http://www.clarin.eu/cmd/1'"/>
    1313    <xsl:param name="cr-uri" select="'..'"/>
     14    <xsl:param name="cr-extension-xsd" select="'-1_2.xsd'"/>
     15    <xsl:param name="cr-extension-xml" select="'.xml'"/>
     16   
     17    <xsl:param name="escape" select="'ccmmddii_'"/>
    1418   
    1519    <xsl:variable name="cmd-components" select="concat($cmd-uri,'/components')"/>
    1620    <xsl:variable name="cmd-profiles" select="concat($cmd-uri,'/profiles')"/>
    1721    <xsl:variable name="cr-profiles" select="concat($cr-uri,'/profiles')"/>
    18     <xsl:variable name="cr-extension-xsd" select="'-1_2.xsd'"/>
    19     <xsl:variable name="cr-extension-xml" select="'.xml'"/>
    2022   
    2123    <!-- identity copy -->
     
    147149    </xsl:template>
    148150   
     151    <!-- unescape downgraded CMDI 1.2 attributes -->
     152    <xsl:template match="cmd0:Components//@*[name()=local-name()][starts-with(name(),$escape)]">
     153        <xsl:attribute name="{substring-after(name(),$escape)}" select="."/>
     154    </xsl:template>
     155   
    149156    <!-- move CMD attributes to the CMD namespace -->
    150     <xsl:template match="cmd0:Components//@ref">
     157    <xsl:template match="cmd0:Components//@ref" priority="2">
    151158        <xsl:choose>
    152159            <xsl:when test="exists(parent::*/text()[normalize-space()!=''])">
     
    158165                <!-- the parent is a component add the namespace to @ref -->
    159166                <!--<xsl:message>INF: this is an component add the namespace to ref</xsl:message>-->
    160                 <xsl:attribute name="cmd:ref" select="."/>
     167                <xsl:attribute name="cmd:ref">
     168                    <xsl:variable name="refs" select="tokenize(.,'\s+')"/>
     169                    <xsl:if test="count($refs) gt 1">
     170                        <xsl:message>WRN: CMDI 1.2 doesn't support references to multiple ResourceProxies! Only the first reference is kept.</xsl:message>
     171                    </xsl:if>
     172                    <xsl:value-of select="$refs[1]"/>
     173                </xsl:attribute>
    161174            </xsl:when>
    162175            <xsl:otherwise>
     
    175188                        <!-- this is an undeclared @ref, so add the namespace -->
    176189                        <!--<xsl:message>INF: according to the profile this @ref is not user defined, so add the namespace</xsl:message>-->
    177                         <xsl:attribute name="cmd:ref" select="."/>
     190                        <xsl:attribute name="cmd:ref">
     191                            <xsl:variable name="refs" select="tokenize(.,'\s+')"/>
     192                            <xsl:if test="count($refs) gt 1">
     193                                <xsl:message>WRN: CMDI 1.2 doesn't support references to multiple ResourceProxies! Only the first reference is kept.</xsl:message>
     194                            </xsl:if>
     195                            <xsl:value-of select="$refs[1]"/>
     196                        </xsl:attribute>
    178197                    </xsl:otherwise>
    179198                </xsl:choose>
     
    182201    </xsl:template>
    183202   
    184     <xsl:template match="cmd0:Components//@ComponentId">
     203    <xsl:template match="cmd0:Components//@ComponentId" priority="2">
    185204        <xsl:attribute name="cmd:ComponentId" select="."/>
    186205    </xsl:template>
  • metadata/trunk/toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd

    r6904 r6907  
    8080                </sch:pattern>
    8181                <!-- TODO: check: the names of referenced external components are not known, so we can't currently check if two or more of them use the same name -->
    82                 <sch:pattern id="c_nest">
    83                     <sch:title>Check nesting</sch:title>
    84                     <sch:rule context="Component[exists(Component|Element)]" role="warning">
    85                         <sch:assert test="empty((Component|Element)[@name=current()/@name])">A nested component or element has the same name ('<sch:value-of select="@name"/>') as this component! Please, consider to rename one of them.</sch:assert>
    86                     </sch:rule>
    87                 </sch:pattern>
    8882            </xs:appinfo>
    8983        </xs:annotation>
  • metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

    r6904 r6907  
    6262            validateCMDSpec = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-component.xsd").toURI().toURL());           
    6363            validateCMDoldSpec = new SchemAnon(new URL("http://infra.clarin.eu/cmd/general-component-schema.xsd"));
    64 //            validateCMDoldSpec = new SchemAnon(new URL("file:///Users/menzowi/Documents/Projects/CLARIN/CMDI/CMDI-1.1/src/toolkit/general-component-schema.xsd"));
    6564            validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL());
    6665        } catch(Exception e) {
Note: See TracChangeset for help on using the changeset viewer.