Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / resourcetools.xsl
blob7218b5dd1344d708b63f9cd5eea2f672d9d4b13e
1 <!--
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 -->
18 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
19 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:UML = 'org.omg.xmi.namespace.UML' xml:space="default">
20 <xsl:output method="text" />
22 <xsl:template name='idtoqname'>
23 <xsl:param name='id'/>
24 <xsl:text>NS_</xsl:text>
25 <xsl:value-of select='substring-before($id, ":")'/>
26 <xsl:text>::LN_</xsl:text>
27 <xsl:value-of select='substring-after($id, ":")'/>
28 </xsl:template>
30 <xsl:template name="parenttype">
31 <xsl:param name='type'/>
32 <xsl:for-each select='/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Generalization[UML:Generalization.child/UML:Class/@xmi.idref=$type]'>
33 <xsl:value-of select='./UML:Generalization.parent/UML:Class/@xmi.idref'/>
34 </xsl:for-each>
35 </xsl:template>
37 <xsl:template name='saltype'>
38 <xsl:param name='type'/>
39 <xsl:param name='parenttype'/>
40 <xsl:choose>
41 <xsl:when test="$type='U8'">sal_uInt8</xsl:when>
42 <xsl:when test="$type='S8'">sal_Int8</xsl:when>
43 <xsl:when test="$type='U16'">sal_uInt16</xsl:when>
44 <xsl:when test="$type='S16'">sal_Int16</xsl:when>
45 <xsl:when test="$type='U32'">sal_uInt32</xsl:when>
46 <xsl:when test="$type='S32'">sal_Int32</xsl:when>
47 <xsl:when test="$type='String'">OUString</xsl:when>
48 <xsl:otherwise>
49 <xsl:text>writerfilter::Reference &lt; </xsl:text>
50 <xsl:value-of select='$parenttype'/>
51 <xsl:text> &gt;::Pointer_t</xsl:text>
52 </xsl:otherwise>
53 </xsl:choose>
54 </xsl:template>
56 <xsl:template name='typetype'>
57 <xsl:param name='type'/><xsl:choose>
58 <xsl:when test="$type='U8'">simple</xsl:when>
59 <xsl:when test="$type='S8'">simple</xsl:when>
60 <xsl:when test="$type='U16'">simple</xsl:when>
61 <xsl:when test="$type='S16'">simple</xsl:when>
62 <xsl:when test="$type='U32'">simple</xsl:when>
63 <xsl:when test="$type='S32'">simple</xsl:when>
64 <xsl:when test="$type='String'">string</xsl:when>
65 <xsl:when test="$type='Binary'">binary</xsl:when>
66 <xsl:otherwise>complex</xsl:otherwise>
67 </xsl:choose>
68 </xsl:template>
70 <xsl:template name="valuetype">
71 <xsl:param name="type"/>
72 <xsl:choose>
73 <xsl:when test='$type="U8"'>WW8IntValue</xsl:when>
74 <xsl:when test='$type="S8"'>WW8IntValue</xsl:when>
75 <xsl:when test='$type="U16"'>WW8IntValue</xsl:when>
76 <xsl:when test='$type="S16"'>WW8IntValue</xsl:when>
77 <xsl:when test='$type="U32"'>WW8IntValue</xsl:when>
78 <xsl:when test='$type="S32"'>WW8IntValue</xsl:when>
79 <xsl:otherwise>WW8PropertiesValue</xsl:otherwise>
80 </xsl:choose>
81 </xsl:template>
83 <xsl:template match="UML:Attribute" mode="valuetype">
84 <xsl:call-template name="valuetype">
85 <xsl:with-param name="type" select='.//UML:DataType/@xmi.idref'/>
86 </xsl:call-template>
87 </xsl:template>
89 <xsl:template name="qnametostrattrs">
90 <xsl:text>
91 /* Attributes */</xsl:text>
92 <xsl:for-each select='.//UML:Attribute[@name!="reserved"]'>
93 <xsl:for-each select='.//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="attrid"]'>
94 <xsl:choose>
95 <xsl:when test='.//UML:Stereotype[@xmi.idref="noresolve"]'>
96 </xsl:when>
97 <xsl:otherwise>
98 <xsl:text>
99 mMap[</xsl:text>
100 <xsl:call-template name='idtoqname'>
101 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
102 </xsl:call-template>
103 <xsl:text>] = "</xsl:text>
104 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
105 <xsl:text>";</xsl:text>
106 </xsl:otherwise>
107 </xsl:choose>
108 </xsl:for-each>
109 </xsl:for-each>
110 </xsl:template>
112 <xsl:template name="qnametostrops">
113 <xsl:text>
114 /* Operations */</xsl:text>
115 <xsl:for-each select='.//UML:Operation[@name!="reserved"]'>
116 <xsl:for-each select='.//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="opid"]'>
117 <xsl:choose>
118 <xsl:when test='.//UML:Stereotype[@xmi.idref="noresolve"]'>
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:text>
122 mMap[</xsl:text>
123 <xsl:call-template name='idtoqname'>
124 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
125 </xsl:call-template>
126 <xsl:text>] = "</xsl:text>
127 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
128 <xsl:text>";</xsl:text>
129 </xsl:otherwise>
130 </xsl:choose>
131 </xsl:for-each>
132 </xsl:for-each>
133 </xsl:template>
135 <xsl:template name="qnametostrclasses">
136 <xsl:text>
137 /* Classes */</xsl:text>
138 <xsl:for-each select='.//UML:Class[@name!="reserved"]'>
139 <xsl:for-each select='.//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="classid"]'>
140 <xsl:text>
141 mMap[</xsl:text>
142 <xsl:call-template name='idtoqname'>
143 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
144 </xsl:call-template>
145 <xsl:text>] = "</xsl:text>
146 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
147 <xsl:text>";</xsl:text>
148 </xsl:for-each>
149 </xsl:for-each>
150 </xsl:template>
152 <xsl:template match='UML:Model' mode='qnametostr'>
153 <xsl:text>
154 void QNameToString::init_doctok()
155 {</xsl:text>
156 <xsl:call-template name="qnametostrattrs"/>
157 <xsl:call-template name="qnametostrops"/>
158 <xsl:call-template name="qnametostrclasses"/>
159 <xsl:text>
161 </xsl:text>
162 </xsl:template>
164 <xsl:key name="ids" match='UML:Attribute[@name!="reserved"]//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="attrid"]|UML:Operation[@name!="reserved"]//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="opid"]' use=".//UML:TaggedValue.dataValue"/>
166 <xsl:template match="UML:Model" mode="qnametostrfunc">
167 <xsl:text>
168 string qnameToString(sal_uInt32 nToken)
170 string sResult;
172 switch (nToken)
174 // Attributes</xsl:text>
175 <xsl:for-each select='.//UML:Attribute[@name!="reserved"]//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="attrid"]'>
176 <xsl:choose>
177 <xsl:when test='.//UML:Stereotype[@xmi.idref="noresolve"]'>
178 </xsl:when>
179 <xsl:otherwise>
180 <xsl:if test="generate-id(key('ids', .//UML:TaggedValue.dataValue)[1])=generate-id(.)">
181 <xsl:text>
182 case </xsl:text>
183 <xsl:call-template name='idtoqname'>
184 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
185 </xsl:call-template>
186 <xsl:text>:
187 sResult = "</xsl:text>
188 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
189 <xsl:text>";
190 break;</xsl:text>
191 </xsl:if>
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:for-each>
195 <xsl:text>
196 // Operations</xsl:text>
197 <xsl:for-each select='.//UML:Operation[@name!="reserved"]//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="opid"]'>
198 <xsl:choose>
199 <xsl:when test='.//UML:Stereotype[@xmi.idref="noresolve"]'>
200 </xsl:when>
201 <xsl:otherwise>
202 <xsl:if test="generate-id(key('ids', .//UML:TaggedValue.dataValue)[1])=generate-id(.)">
203 <xsl:text>
204 case </xsl:text>
205 <xsl:call-template name='idtoqname'>
206 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
207 </xsl:call-template>
208 <xsl:text>:
209 sResult = "</xsl:text>
210 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
211 <xsl:text>";
212 break;</xsl:text>
213 </xsl:if>
214 </xsl:otherwise>
215 </xsl:choose>
216 </xsl:for-each>
217 <xsl:text>
218 // Classes:</xsl:text>
219 <xsl:for-each select='.//UML:Class[@name!="reserved"]//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="classid"]'>
220 <xsl:text>
221 case </xsl:text>
222 <xsl:call-template name='idtoqname'>
223 <xsl:with-param name='id'><xsl:value-of select='.//UML:TaggedValue.dataValue'/></xsl:with-param>
224 </xsl:call-template>
225 <xsl:text>:
226 sResult = "</xsl:text>
227 <xsl:value-of select='.//UML:TaggedValue.dataValue'/>
228 <xsl:text>";
229 break;</xsl:text>
230 </xsl:for-each>
231 <xsl:text>
232 default:
236 return sResult;
237 }</xsl:text>
238 </xsl:template>
240 <xsl:template match='UML:Model' mode='sprmcodetostr'>
241 <xsl:text>
242 SprmIdToString::SprmIdToString()
243 {</xsl:text>
244 <xsl:variable name='tmp'>map &lt; sal_uInt32, string &gt; </xsl:variable>
245 <xsl:for-each select='.//UML:Class[.//UML:Stereotype/@xmi.idref="ww8sprm"]'>
246 <xsl:variable name="sprmconst">
247 <xsl:call-template name="sprmCodeOfClass"/>
248 </xsl:variable>
249 <xsl:text>
250 mMap[</xsl:text>
251 <xsl:value-of select="$sprmconst"/>
252 <xsl:text>] = "</xsl:text>
253 <xsl:value-of select='.//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref="sprmid"]//UML:TaggedValue.dataValue'/>
254 <xsl:text>";</xsl:text>
255 </xsl:for-each>
256 <xsl:text>
258 </xsl:text>
259 </xsl:template>
261 <xsl:key name="classes-with-kind" match="UML:TagDefinition[@xmi.idref='kind']"
262 use="ancestor::UML:TaggedValue/UML:TaggedValue.dataValue"/>
264 <xsl:template name="sprmCodeOfClass">
265 <xsl:variable name="tmp">
266 <xsl:text>sprm:</xsl:text>
267 <xsl:value-of select="substring-after(@name, 'sprm')"/>
268 </xsl:variable>
269 <xsl:call-template name="idtoqname">
270 <xsl:with-param name="id" select="$tmp"/>
271 </xsl:call-template>
272 </xsl:template>
274 <xsl:template name="sprmkindcase">
275 <xsl:param name="kind"/>
276 <xsl:for-each select="key('classes-with-kind', $kind)/ancestor::UML:Class">
277 <xsl:text>
278 case </xsl:text>
279 <xsl:call-template name="sprmCodeOfClass"/>
280 <xsl:text>:</xsl:text>
281 </xsl:for-each>
282 </xsl:template>
284 <xsl:template match="UML:Model" mode='sprmkind'>
285 <xsl:text>
286 Sprm::Kind SprmKind(sal_uInt32 sprmCode)
288 Sprm::Kind nResult = Sprm::UNKNOWN;
290 switch(sprmCode)
291 {</xsl:text>
292 <xsl:call-template name="sprmkindcase">
293 <xsl:with-param name="kind">paragraph</xsl:with-param>
294 </xsl:call-template>
295 <xsl:text>
296 nResult = Sprm::PARAGRAPH;
297 break;</xsl:text>
298 <xsl:call-template name="sprmkindcase">
299 <xsl:with-param name="kind">character</xsl:with-param>
300 </xsl:call-template>
301 <xsl:text>
302 nResult = Sprm::CHARACTER;
303 break;</xsl:text>
304 <xsl:call-template name="sprmkindcase">
305 <xsl:with-param name="kind">table</xsl:with-param>
306 </xsl:call-template>
307 <xsl:text>
308 nResult = Sprm::TABLE;
309 break;</xsl:text>
310 <xsl:text>
311 default:
312 break;
315 return nResult;
317 </xsl:text>
318 </xsl:template>
320 <xsl:template match="UML:Model" mode='sprmids'>
321 <xsl:text>
322 namespace NS_sprm { </xsl:text>
323 <xsl:for-each select=".//UML:Class[.//UML:Stereotype/@xmi.idref='ww8sprm']">
324 <xsl:variable name="sprmcode">
325 <xsl:value-of select=".//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref = 'sprmcode']/UML:TaggedValue.dataValue"/>
326 </xsl:variable>
327 <xsl:variable name="sprmcodelower">
328 <xsl:value-of select="translate($sprmcode, 'ABCDEF', 'abcdef')"/>
329 </xsl:variable>
330 <xsl:variable name="sprmidname">
331 <xsl:text>LN_</xsl:text>
332 <xsl:value-of select="substring-after(@name, 'sprm')"/>
333 </xsl:variable>
334 <xsl:text>
335 const sal_uInt16 </xsl:text>
336 <xsl:value-of select="$sprmidname"/>
337 <xsl:text> = </xsl:text>
338 <xsl:value-of select="$sprmcodelower"/>
339 <xsl:text>;</xsl:text>
340 </xsl:for-each>
341 <xsl:text>
343 </xsl:text>
344 </xsl:template>
346 <xsl:template match="UML:Model" mode='sprmidsed'>
347 <xsl:text>#!/bin/sh
348 cat $1 \&#xa;</xsl:text>
349 <xsl:for-each select=".//UML:Class[.//UML:Stereotype/@xmi.idref='ww8sprm']">
350 <xsl:variable name="sprmcode">
351 <xsl:value-of select=".//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref = 'sprmcode']/UML:TaggedValue.dataValue"/>
352 </xsl:variable>
353 <xsl:variable name="sprmcodelower">
354 <xsl:value-of select="translate($sprmcode, 'ABCDEF', 'abcdef')"/>
355 </xsl:variable>
356 <xsl:variable name="sprmidname">
357 <xsl:text>NS_sprm::LN_</xsl:text>
358 <xsl:value-of select="substring-after(@name, 'sprm')"/>
359 </xsl:variable>
360 <xsl:text>| sed "s/</xsl:text>
361 <xsl:value-of select="$sprmcode"/>
362 <xsl:text>/</xsl:text>
363 <xsl:value-of select="$sprmidname"/>
364 <xsl:text>/g" \&#xa;</xsl:text>
365 <xsl:text>| sed "s/</xsl:text>
366 <xsl:value-of select="$sprmcodelower"/>
367 <xsl:text>/</xsl:text>
368 <xsl:value-of select="$sprmidname"/>
369 <xsl:text>/g" \&#xa;</xsl:text>
370 </xsl:for-each>
371 <xsl:text> | cat&#xa;</xsl:text>
372 </xsl:template>
374 <xsl:template match="UML:Model" mode='sprmreplace'>
375 <xsl:for-each select=".//UML:Class[.//UML:Stereotype/@xmi.idref='ww8sprm']">
376 <xsl:variable name="pattern">
377 <xsl:value-of select=".//UML:TaggedValue[.//UML:TagDefinition/@xmi.idref = 'sprmcode']/UML:TaggedValue.dataValue"/>
378 </xsl:variable>
379 <xsl:variable name="lowerpattern">
380 <xsl:value-of select="translate($pattern, 'ABCDEF', 'abcdef')"/>
381 </xsl:variable>
382 <xsl:variable name="upperpattern">
383 <xsl:value-of select="translate($pattern, 'abcdef', 'ABCDEF')"/>
384 </xsl:variable>
385 <xsl:variable name="tmp">
386 <xsl:text>sprm:</xsl:text>
387 <xsl:value-of select="substring-after(@name, 'sprm')"/>
388 </xsl:variable>
389 <xsl:variable name="constname">
390 <xsl:call-template name="idtoqname">
391 <xsl:with-param name="id" select="$tmp"/>
392 </xsl:call-template>
393 </xsl:variable>
394 <xsl:text>
395 sed "s/</xsl:text>
396 <xsl:value-of select="$lowerpattern"/>
397 <xsl:text>/</xsl:text>
398 <xsl:value-of select="$constname"/>
399 <xsl:text>/g" &lt; $1 > $1.out &amp;&amp; mv $1.out $1 </xsl:text>
400 <xsl:text>
401 sed "s/</xsl:text>
402 <xsl:value-of select="$upperpattern"/>
403 <xsl:text>/</xsl:text>
404 <xsl:value-of select="$constname"/>
405 <xsl:text>/g" &lt; $1 > $1.out &amp;&amp; mv $1.out $1 </xsl:text>
406 </xsl:for-each>
407 <xsl:text>&#xa;</xsl:text>
408 </xsl:template>
410 <!-- Key all attributes with the same name and same value -->
411 <xsl:key name="same-valued-tagged-data"
412 match="UML:TaggedValue.dataValue" use="." />
414 <xsl:template name="licenseheader">
415 <xsl:text>
417 * This file is part of the LibreOffice project.
419 * This Source Code Form is subject to the terms of the Mozilla Public
420 * License, v. 2.0. If a copy of the MPL was not distributed with this
421 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
423 * This file incorporates work covered by the following license notice:
425 * Licensed to the Apache Software Foundation (ASF) under one or more
426 * contributor license agreements. See the NOTICE file distributed
427 * with this work for additional information regarding copyright
428 * ownership. The ASF licenses this file to you under the Apache
429 * License, Version 2.0 (the "License"); you may not use this file
430 * except in compliance with the License. You may obtain a copy of
431 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
434 THIS FILE IS GENERATED AUTOMATICALLY! DO NOT EDIT!
436 &#xa;</xsl:text>
437 </xsl:template>
438 </xsl:stylesheet>