1<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 2<!--*********************************************************************** 3 * 4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 6 Copyright 2000, 2010 Oracle and/or its affiliates. 7 8 OpenOffice.org - a multi-platform office productivity suite 9 10 This file is part of OpenOffice.org. 11 12 OpenOffice.org is free software: you can redistribute it and/or modify 13 it under the terms of the GNU Lesser General Public License version 3 14 only, as published by the Free Software Foundation. 15 16 OpenOffice.org is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU Lesser General Public License version 3 for more details 20 (a copy is included in the LICENSE file that accompanied this code). 21 22 You should have received a copy of the GNU Lesser General Public License 23 version 3 along with OpenOffice.org. If not, see 24 <http://www.openoffice.org/license.html> 25 for a copy of the LGPLv3 License. 26 27 ************************************************************************ --> 28 29<!-- ************************************************************************************** --> 30<!-- * Transformation from New Format XCS & XCU to schema description *** --> 31<!-- ************************************************************************************** --> 32<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 33 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 34 xmlns:xs="http://www.w3.org/2001/XMLSchema" 35 xmlns:oor="http://openoffice.org/2001/registry" 36 xmlns:install="http://openoffice.org/2004/installation"> 37 38<!-- Get the correct format --> 39<xsl:output method="xml" indent="yes" /> 40 41<xsl:param name="xcs"/> 42<xsl:param name="schemaRoot">.</xsl:param> 43 44<xsl:variable name="schemaRootURL"> 45 <xsl:value-of select="$schemaRoot"/> 46</xsl:variable> 47<xsl:variable name="schemaURL"> 48 <xsl:value-of select="$xcs"/> 49</xsl:variable> 50 51<!-- ************************************** --> 52<!-- * oor:component-data *** --> 53<!-- ************************************** --> 54 <xsl:template match="/oor:component-data"> 55 <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/> 56 <xsl:for-each select="node|prop"> 57 <xsl:apply-templates select="."> 58 <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/> 59 <xsl:with-param name="component-schema" select="$component-schema"/> 60 </xsl:apply-templates> 61 </xsl:for-each> 62 </xsl:template> 63 64<!-- ****************************************** --> 65<!-- * handle template references *** --> 66<!-- ****************************************** --> 67 <xsl:template name="resolve-template"> 68 <xsl:param name = "node-type"/> 69 <xsl:param name = "schema-type"/> 70 <xsl:param name = "component-schema"/> 71 <xsl:variable name = "path"> 72 <xsl:call-template name="collectPath"/> 73 </xsl:variable> 74 75 <xsl:if test="not ($component-schema)"> 76 <xsl:message terminate="yes">ERROR: Template '<xsl:value-of select="$node-type"/>', 77 referenced from node '<xsl:value-of select="$path"/>' 78 does not exist in schema! 79 </xsl:message> 80 </xsl:if> 81 82 <xsl:choose> 83 <xsl:when test="$schema-type='node-ref'"> 84 <xsl:apply-templates select="."> 85 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 86 <xsl:with-param name="component-schema" select="$component-schema"/> 87 </xsl:apply-templates> 88 </xsl:when> 89 <xsl:when test="$schema-type='set'"> 90 <xsl:for-each select="node|prop"> 91 <xsl:apply-templates select="."> 92 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 93 <xsl:with-param name="component-schema" select="$component-schema"/> 94 </xsl:apply-templates> 95 </xsl:for-each> 96 </xsl:when> 97 <xsl:otherwise> 98 <xsl:message terminate="yes">ERROR: The schema element for node <xsl:value-of select="$path"/> 99 is a <xsl:value-of select="$schema-type"/> and should not have a node-type. 100 </xsl:message> 101 </xsl:otherwise> 102 </xsl:choose> 103 </xsl:template> 104 105<!-- ****************************************** --> 106<!-- * node *** --> 107<!-- ****************************************** --> 108 <xsl:template match="node"> 109 <xsl:param name = "context"/> 110 <xsl:param name = "component-schema"/> 111 <xsl:variable name = "path"> 112 <xsl:call-template name="collectPath"/> 113 </xsl:variable> 114 115 <xsl:if test="not ($context)"> 116 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message> 117 </xsl:if> 118 119 <xsl:call-template name="checkModule"/> 120 <xsl:call-template name="checkDuplicates"/> 121 122 <xsl:choose> 123 <!-- look for matching templates in other components --> 124 <xsl:when test="$context/@oor:node-type and $context/@oor:component"> 125 <xsl:variable name="fileURL"> 126 <xsl:call-template name="composeFileURL"> 127 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param> 128 </xsl:call-template> 129 </xsl:variable> 130 131 <xsl:call-template name="resolve-template"> 132 <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 133 <xsl:with-param name="schema-type" select="local-name($context)"/> 134 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/> 135 </xsl:call-template> 136 </xsl:when> 137 <!-- look for matching templates within the same component --> 138 <xsl:when test="$context/@oor:node-type"> 139 <xsl:call-template name="resolve-template"> 140 <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 141 <xsl:with-param name="schema-type" select="local-name($context)"/> 142 <xsl:with-param name="component-schema" select="$component-schema"/> 143 </xsl:call-template> 144 </xsl:when> 145 <!-- is the node extensible ? --> 146 <xsl:when test="$context/@oor:extensible='true'"> 147 <xsl:for-each select="node|prop"> 148 <xsl:apply-templates select="." mode="extensible"> 149 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/> 150 <xsl:with-param name="component-schema" select="$component-schema"/> 151 </xsl:apply-templates> 152 </xsl:for-each> 153 </xsl:when> 154 <xsl:otherwise> 155 <xsl:for-each select="node|prop"> 156 <xsl:apply-templates select="."> 157 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/> 158 <xsl:with-param name="component-schema" select="$component-schema"/> 159 </xsl:apply-templates> 160 </xsl:for-each> 161 </xsl:otherwise> 162 </xsl:choose> 163 </xsl:template> 164 165<!-- ****************************************** --> 166<!-- * prop *** --> 167<!-- ****************************************** --> 168 <xsl:template match="prop"> 169 <xsl:param name = "context"/> 170 <xsl:variable name = "path"> 171 <xsl:call-template name="collectPath"/> 172 </xsl:variable> 173 174 175 <xsl:if test="not ($context)"> 176 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema !</xsl:message> 177 </xsl:if> 178 179 <xsl:if test="@oor:op"> 180 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>' !</xsl:message> 181 </xsl:if> 182 183 <xsl:call-template name="checkModule"/> 184 <xsl:call-template name="checkDuplicates"/> 185 186 <xsl:apply-templates /> 187 </xsl:template> 188 189<!-- ****************************************** --> 190<!-- * value *** --> 191<!-- ****************************************** --> 192 <xsl:template match="value"> 193 <xsl:call-template name="checkModule"/> 194 195 <xsl:if test="@install:module"> 196 <xsl:variable name = "path"> 197 <xsl:call-template name="collectPath"/> 198 </xsl:variable> 199 <xsl:variable name = "module" select="@install:module"/> 200 <xsl:variable name = "lang" select="@xml:lang"/> 201 202 <xsl:if test="following-sibling::value[@install:module=$module and @xml:lang=$lang]"> 203 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has multiple values for module <xsl:value-of select="$module"/> and locale <xsl:value-of select="$lang"/>!</xsl:message> 204 </xsl:if> 205 <xsl:if test="not(preceding-sibling::value/@install:module)"> 206 <xsl:message>ATTENTION: Property '<xsl:value-of select="$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!</xsl:message> 207 </xsl:if> 208 </xsl:if> 209 </xsl:template> 210 211<!-- ****************************************** --> 212<!-- * node (mode:extensible) - not supported * --> 213<!-- ****************************************** --> 214 <xsl:template match="node" mode="extensible"> 215 <xsl:variable name = "path"> 216 <xsl:call-template name="collectPath"/> 217 </xsl:variable> 218 219 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message> 220 </xsl:template> 221<!-- ****************************************** --> 222<!-- * prop (mode:extensible) *** --> 223<!-- ****************************************** --> 224 <xsl:template match="prop" mode="extensible"> 225 <xsl:param name = "context"/> 226 <xsl:variable name = "path"> 227 <xsl:call-template name="collectPath"/> 228 </xsl:variable> 229 230 <xsl:choose> 231 <xsl:when test="not(@oor:op)"> 232 <xsl:if test="not ($context)"> 233 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message> 234 </xsl:if> 235 </xsl:when> 236 <xsl:when test="@oor:op='replace'"> 237 <xsl:if test="not (@oor:type)"> 238 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not have a type!</xsl:message> 239 </xsl:if> 240 </xsl:when> 241 <xsl:otherwise> 242 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message> 243 </xsl:otherwise> 244 </xsl:choose> 245 246 <xsl:call-template name="checkModule"/> 247 <xsl:call-template name="checkDuplicates"/> 248 </xsl:template> 249 250 251<!-- ************************************* --> 252<!-- * checkDuplicates *** --> 253<!-- ************************************* --> 254 <xsl:template name="checkDuplicates"> 255 <xsl:variable name="item-name" select="@oor:name"/> 256 <xsl:if test="following-sibling::*[@oor:name = $item-name]"> 257 <xsl:variable name = "path"> 258 <xsl:call-template name="collectPath"/> 259 </xsl:variable> 260 <xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message> 261 </xsl:if> 262 </xsl:template> 263 264 265<!-- ************************************* --> 266<!-- * checkModule *** --> 267<!-- ************************************* --> 268 <xsl:template name="checkModule"> 269 <xsl:if test="@install:module"> 270 <xsl:if test="ancestor::*[@install:module]"> 271 <xsl:message terminate="yes">ERROR: Nested modules are not supported. Found module '<xsl:value-of select="@install:module"/>' within module '<xsl:value-of select="ancestor::*/@install:module"/>'! 272 </xsl:message> 273 </xsl:if> 274 </xsl:if> 275 </xsl:template> 276 277<!-- ************************************* --> 278<!-- * collectPath *** --> 279<!-- ************************************* --> 280 <xsl:template name="collectPath"> 281 <xsl:for-each select="ancestor-or-self::node()[@oor:name]"> 282 <xsl:text>/</xsl:text><xsl:value-of select="@oor:name"/> 283 </xsl:for-each> 284 </xsl:template> 285 286 287<!-- ****************************** --> 288<!-- * composeFileURL *** --> 289<!-- ****************************** --> 290 <xsl:template name="composeFileURL"> 291 <xsl:param name="componentName"/> 292 <xsl:variable name="fileURL"> 293 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text> 294 </xsl:variable> 295 <xsl:value-of select="$fileURL"/> 296 </xsl:template> 297 298 299</xsl:transform> 300 301