xref: /AOO42X/main/officecfg/util/schema_val.xsl (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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<xsl:transform  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31        xmlns:xs="http://www.w3.org/2001/XMLSchema"
32        xmlns:oor="http://openoffice.org/2001/registry"
33        version="1.0">
34
35<!-- Get the correct format -->
36<xsl:output method="xml" indent="yes"/>
37<xsl:namespace-alias stylesheet-prefix="xs" result-prefix="xs"></xsl:namespace-alias>
38
39<!-- Parameter -->
40<xsl:param name="root">../registry/schema</xsl:param>
41<xsl:param name="componentName"/>
42
43    <xsl:template match = "/">
44        <xsl:message terminate="no">CHECKING CONSISTENCY ...</xsl:message>
45        <xsl:apply-templates/>
46    </xsl:template>
47
48<!-- activate attribute templates -->
49    <xsl:template match="group|set|prop">
50        <xsl:apply-templates select="*|@*"/>
51    </xsl:template>
52
53<!-- make sure that missing features are not invoked -->
54    <xsl:template match = "item">
55        <xsl:message terminate="yes">ERROR: multiple template types for sets are NOT supported!</xsl:message>
56    </xsl:template>
57
58    <xsl:template match = "set[@oor:extensible='true']">
59        <xsl:message terminate="yes">ERROR: extensible sets are currently NOT supported!</xsl:message>
60    </xsl:template>
61
62    <xsl:template match = "group[@oor:extensible='true']">
63        <xsl:if test="count(child::set) or count(child::group) or count(child::node-ref)">
64            <xsl:message terminate="yes">ERROR: extensible groups with children are currently NOT supported!</xsl:message>
65        </xsl:if>
66        <xsl:apply-templates select="*|@*"/>
67    </xsl:template>
68
69<!-- Localized info elements (desc/label) are not supported currently -->
70    <xsl:template match="info//*[@xml:lang]">
71        <xsl:message terminate="yes">ERROR: Info elements (desc/label) are currently not localized. Remove xml:lang attributes!</xsl:message>
72    </xsl:template>
73
74<!-- check for duplicate child names -->
75    <xsl:template match="@oor:name">
76        <xsl:variable name="item-name" select="."/>
77        <xsl:if test="../following-sibling::*[@oor:name = $item-name]">
78            <xsl:message terminate="yes">ERROR: Duplicate node name '<xsl:value-of select="$item-name"/>'!</xsl:message>
79        </xsl:if>
80    </xsl:template>
81
82<!-- check if properties of type 'any' do not have a value -->
83    <xsl:template match="prop[@oor:type='oor:any']">
84        <xsl:if test="count(value)">
85            <xsl:message terminate="yes">ERROR: Properties of type 'oor:any' MUST NOT have a value!</xsl:message>
86        </xsl:if>
87        <xsl:apply-templates select="*|@*"/>
88    </xsl:template>
89
90<!-- inhibit (explicit) NIL values -->
91    <xsl:template match="value[@xsi:nil]">
92        <xsl:message terminate="yes">ERROR: xsi:nil is not allowed in schemas !</xsl:message>
93    </xsl:template>
94
95<!-- validate for correct node references -->
96    <xsl:template match="@oor:node-type">
97        <xsl:choose>
98            <xsl:when test="../@oor:component">
99                <xsl:variable name ="file">
100                    <xsl:call-template name="locateFile"><xsl:with-param name="componentName" select="../@oor:component"/></xsl:call-template>
101                </xsl:variable>
102                <xsl:if test="not(document($file)/oor:component-schema/templates/*[@oor:name=current()])">
103                    <xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
104                </xsl:if>
105            </xsl:when>
106            <xsl:when test="not(/oor:component-schema/templates/*[@oor:name=current()])">
107                <xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
108            </xsl:when>
109        </xsl:choose>
110    </xsl:template>
111
112<!-- validate if file name matches component-name -->
113    <xsl:template match="oor:component-schema">
114        <xsl:variable name ="fullName"><xsl:value-of select="@oor:package"/>.<xsl:value-of select="@oor:name"/></xsl:variable>
115        <xsl:if test="$fullName != $componentName">
116            <xsl:message terminate="yes">ERROR: Component name '<xsl:value-of select="$fullName"/>' does not match with file name!</xsl:message>
117        </xsl:if>
118        <xsl:apply-templates select="*|@*"/>
119    </xsl:template>
120
121
122<!-- locate a component file -->
123    <xsl:template name="locateFile">
124        <xsl:param name="componentName"/>
125        <xsl:variable name ="file"><xsl:value-of select="$root"/>/<xsl:value-of select="translate($componentName,'.','/')"/>.xcs</xsl:variable>
126        <xsl:if test="not( document($file) )">
127            <xsl:message terminate ="yes">**Error: unable to locate document '<xsl:value-of select="translate($componentName,'.','/')"/>.xcd'</xsl:message>
128        </xsl:if>
129        <xsl:value-of select="$file"/>
130    </xsl:template>
131
132</xsl:transform>
133