Project

Profile

Help

How to connect?
Download (10.7 KB) Statistics
| Branch: | Revision:

he / tools / featureKeys / FeatureKeysToJava.xsl @ 2699858e

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
4
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="3.0">
5

    
6
    <xd:doc scope="stylesheet">
7
        <xd:desc>
8
            <xd:p><xd:b>(re)Created on:</xd:b> Jan 10, 2013</xd:p>
9
            <xd:p><xd:b>Author:</xd:b> Michael Kay, Saxonica</xd:p>
10
            <xd:p>Generates FeatureKeys.java from FeatureKeys.xml</xd:p>
11
        </xd:desc>
12
    </xd:doc>
13

    
14
    <xsl:output method="text"/>
15

    
16
    <xsl:template match="features">
17
        <xsl:call-template name="validate"/>
18
        <xsl:apply-templates select="." mode="FeatureKeys.java"/>
19
        <xsl:apply-templates select="." mode="Feature.java"/>
20
        <xsl:apply-templates select="." mode="FeatureCode.java"/>
21
    </xsl:template>
22
    
23
    <xsl:template match="features" mode="FeatureCode.java">
24
        <xsl:result-document href="FeatureCode.java" method="text">
25
        <xsl:text><![CDATA[////////////////////////////////////////////////////////////////////////
26
// Copyright (c) 2018-2020 Saxonica Limited
27
// This Source Code Form is subject to the terms of the Mozilla Public
28
// License, v. 2.0.
29
// If a copy of the MPL was not distributed with this file, You can
30
// obtain one at http://mozilla.org/MPL/2.0/.
31
// This Source Code Form is "Incompatible With Secondary Licenses", 
32
// as defined by the Mozilla Public License, v. 2.0.
33
////////////////////////////////////////////////////////////////////////
34

    
35
package net.sf.saxon.lib;
36

    
37
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
38
// If you edit this file, your edits WILL BE TERMINATED with
39
// extreme prejudice by the next build.
40

    
41
/**
42
 * FeatureCode defines a set of integer constants, representing unique identifiers for the
43
 * features that can be configured. This module is generated from the master XML
44
 * file listing all the features.
45
 * 
46
 * <p>The integer codes are intended to remain stable across Saxon releases so that compiled
47
 * code using these integer codes will continue to work without recompilation.</p>
48
 */
49

    
50
public abstract class FeatureCode {
51

    
52
]]></xsl:text>
53
        <xsl:apply-templates select="//feature" mode="#current"/>
54
        <xsl:text expand-text="yes">&#xa;&#xa;    public final static int MAX = {count(//feature) + 3};&#xa;</xsl:text>
55
        <xsl:text>
56
}
57
        </xsl:text>
58
        </xsl:result-document>
59
    </xsl:template>
60
    
61
    <xsl:template match="features" mode="FeatureKeys.java">
62
        <xsl:result-document href="FeatureKeys.java" method="text">
63
            <xsl:text><![CDATA[////////////////////////////////////////////////////////////////////////
64
// Copyright (c) 2018-2020 Saxonica Limited
65
// This Source Code Form is subject to the terms of the Mozilla Public
66
// License, v. 2.0.
67
// If a copy of the MPL was not distributed with this file, You can
68
// obtain one at http://mozilla.org/MPL/2.0/.
69
// This Source Code Form is "Incompatible With Secondary Licenses", 
70
// as defined by the Mozilla Public License, v. 2.0.
71
////////////////////////////////////////////////////////////////////////
72

    
73
package net.sf.saxon.lib;
74

    
75
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
76
// If you edit this file, your edits WILL BE TERMINATED with
77
// extreme prejudice by the next build.
78

    
79
import net.sf.saxon.trans.RecoveryPolicy;
80

    
81
/**
82
 * FeatureKeys defines a set of constants, representing the names of Saxon configuration
83
 * options which can be supplied to the Saxon implementations of the JAXP
84
 * interfaces TransformerFactory, SchemaFactory, Validator, and ValidationHandler,
85
 * and to other interfaces such as the s9api {@link net.sf.saxon.s9api.Processor}
86
 *
87
 * @author Michael H. Kay
88
 */
89

    
90
public abstract class FeatureKeys {
91

    
92
]]></xsl:text>
93
            <xsl:apply-templates select="//feature" mode="#current"/>
94
            <xsl:text>
95
}
96
        </xsl:text>
97
        </xsl:result-document>
98
    </xsl:template>
99
    
100
    <xsl:template match="features" mode="Feature.java">
101
        <xsl:result-document href="Feature.java" method="text">
102
            <xsl:text><![CDATA[////////////////////////////////////////////////////////////////////////
103
// Copyright (c) 2018-2020 Saxonica Limited
104
// This Source Code Form is subject to the terms of the Mozilla Public
105
// License, v. 2.0.
106
// If a copy of the MPL was not distributed with this file, You can
107
// obtain one at http://mozilla.org/MPL/2.0/.
108
// This Source Code Form is "Incompatible With Secondary Licenses", 
109
// as defined by the Mozilla Public License, v. 2.0.
110
////////////////////////////////////////////////////////////////////////
111

    
112
package net.sf.saxon.lib;
113

    
114
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
115
// If you edit this file, your edits WILL BE TERMINATED with
116
// extreme prejudice by the next build.
117

    
118
import net.sf.saxon.trans.RecoveryPolicy;
119

    
120
import java.util.Iterator;
121
import java.util.Map;
122
import java.util.TreeMap;
123

    
124
/**
125
 * Feature defines a set of constants, representing the details of Saxon configuration
126
 * options which can be supplied to the Saxon method Configuration.setProperty(),
127
 * and to other interfaces
128
 */
129

    
130
public class Feature<T> {
131
    public String name;
132
    public final int code;
133
    public int requiredEdition;
134
    public Class<? extends T> type;
135
    public T defaultValue;
136

    
137
    private static final int HE = 0, PE = 1, EE = 2;
138

    
139
    private static final Map<String, Feature> index = new TreeMap<String, Feature>();
140

    
141
    private Feature(String name, int code, int requiredEdition, Class<? extends T> type, T defaultValue) {
142
        this.name = name;
143
        this.code = code;
144
        this.requiredEdition = requiredEdition;
145
        this.type = type;
146
        this.defaultValue = defaultValue;
147
        index.put(name, this);
148
    }
149

    
150
    public static Feature<?> byName(String name) {
151
        return index.get(name);
152
    }
153
    
154
    public static Iterator<String> getNames() {
155
        return index.keySet().iterator();
156
    }
157
]]></xsl:text>
158
            <xsl:apply-templates select="//feature" mode="#current"/>
159
            <xsl:text>            
160
}
161
        </xsl:text> 
162
        </xsl:result-document>
163
    </xsl:template>
164
    
165
    <xsl:template match="feature" mode="FeatureKeys.java">
166
        <xsl:message>Processing <xsl:value-of select="name"/></xsl:message>
167
        <xsl:apply-templates select="desc, name, uri" mode="#current"/>
168
    </xsl:template>
169
    
170
    <xsl:template match="feature" mode="FeatureCode.java" expand-text="yes">
171
        <xsl:text>    /** @see Feature#{name}  */&#xa;</xsl:text>
172
        <xsl:text>    public final static int {name} = {featureCode};&#xa;</xsl:text>
173
    </xsl:template>
174
   
175
    
176
    <xsl:template match="name" mode="FeatureKeys.java">
177
        <xsl:text>&#xa;&#xa;    public final static String </xsl:text>
178
        <xsl:value-of select="."/>
179
        <xsl:text> = </xsl:text>
180
    </xsl:template>
181
    
182
    <xsl:template match="feature/*" priority="-0.1" mode="#all"/>
183
    
184
    <xsl:template match="uri" mode="FeatureKeys.java">
185
        <xsl:text>&#xa;        "</xsl:text>
186
        <xsl:value-of select="."/>
187
        <xsl:text>";&#xa;</xsl:text>
188
        <xsl:text>&#xa;// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE&#xa;&#xa;</xsl:text>
189
    </xsl:template>
190
    
191
    <xsl:template match="desc" mode="#all">
192
        <xsl:text>&#xa;    /**</xsl:text>
193
        <xsl:apply-templates mode="#current"/>
194
        <xsl:text>&#xa;    **/</xsl:text>
195
    </xsl:template>
196
    
197
    <xsl:template match="desc//*" mode="#all">
198
        <xsl:text>&lt;</xsl:text>
199
        <xsl:value-of select="name()"/>
200
        <xsl:text>&gt;</xsl:text>
201
        <xsl:apply-templates mode="#current"/>
202
        <xsl:text>&lt;/</xsl:text>
203
        <xsl:value-of select="name()"/>
204
        <xsl:text>&gt;</xsl:text>
205
    </xsl:template>
206
    
207
    <xsl:template match="desc//link" priority="2" mode="Feature.java">
208
        <xsl:text>{@link </xsl:text>
209
        <xsl:apply-templates/>
210
        <xsl:text>}</xsl:text>
211
    </xsl:template>
212
    
213
    <xsl:template match="desc//link" priority="2" mode="FeatureKeys.java">
214
        <xsl:text>{@link </xsl:text>
215
        <xsl:value-of select="replace(., 'net.sf.saxon.lib.Feature#', 'net.sf.saxon.lib.FeatureKeys#')"/>
216
        <xsl:text>}</xsl:text>
217
    </xsl:template>
218
    
219
    <xsl:template match="desc//a" priority="2" mode="#all">
220
        <xsl:text>&lt;span class="link" data-href="</xsl:text>
221
        <xsl:value-of select="@href"/>
222
        <xsl:text>"&gt;</xsl:text>
223
        <xsl:apply-templates mode="#current"/>
224
        <xsl:text>&lt;/span&gt;</xsl:text>
225
    </xsl:template>
226
    
227
    <xsl:template match="desc//text()" mode="#all">
228
        <xsl:value-of select="replace(replace(replace(., '&#xa;', '&#xa;    *'), '&gt;', '&amp;gt;'), '&lt;', '&amp;lt;')"/>
229
    </xsl:template>
230
    
231
    <xsl:template match="feature" mode="Feature.java" expand-text="yes">
232
        <xsl:variable name="type" as="xs:string">
233
            <xsl:apply-templates select="type"/>
234
        </xsl:variable>
235
        <xsl:variable name="angledType" select="'&lt;'||$type||'&gt;'"/>
236
        <xsl:variable name="javaType" select="
237
            if ($type = 'boolean') then 'Boolean.TYPE'
238
            else if ($type = 'integer') then 'Integer.TYPE'
239
            else ($type || '.class')"/>
240
        <xsl:apply-templates select="desc" mode="#current"/>
241
        <xsl:text>&#xa;&#xa;    public final static Feature{$angledType} {name} = new Feature{$angledType}(&#xa;</xsl:text>
242
        <xsl:text>            "{uri}", {featureCode}, {(tokenize(editions), 'HE')[1]}, {$javaType}, {if (type='boolean') then 'false' else 'null'});
243
</xsl:text>
244
        <xsl:text>&#xa;// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE&#xa;&#xa;</xsl:text>
245
    </xsl:template>
246
    
247
    <xsl:template match="type[.='boolean']">
248
        <xsl:text><![CDATA[Boolean]]></xsl:text>
249
    </xsl:template>
250
    
251
    <xsl:template match="type[starts-with(., 'integer')]">
252
        <xsl:text><![CDATA[Integer]]></xsl:text>
253
    </xsl:template>
254
    
255
    <xsl:template match="type[starts-with(., 'string') or starts-with(., 'Absolute URI')]">
256
        <xsl:text><![CDATA[String]]></xsl:text>
257
    </xsl:template>
258
    
259
    <xsl:template match="type[starts-with(., 'Instance of')]" expand-text="yes">
260
        <xsl:text>{(link|code)[1]}</xsl:text>
261
    </xsl:template>
262
    
263
    <xsl:template match="type[starts-with(., 'Name of a class')]" expand-text="yes">
264
        <xsl:text><![CDATA[String]]></xsl:text>
265
    </xsl:template>
266
    
267
    <xsl:template match="type">
268
        <xsl:text><![CDATA[Object]]></xsl:text>
269
    </xsl:template>
270
 
271
    
272
<xsl:template name="validate" expand-text="yes">
273
    <xsl:if test="//feature[not(featureCode)]">
274
        <xsl:message terminate="yes">Every feature must have a numeric featureCode</xsl:message>
275
    </xsl:if>
276
    <xsl:if test="count(//featureCode) ne count(distinct-values(//featureCode))">
277
        <xsl:message terminate="yes">Every featureCode must be unique</xsl:message>
278
    </xsl:if>
279
</xsl:template>
280
    
281
    
282
</xsl:stylesheet>
(5-5/8)