update credits
[LibreOffice.git] / writerfilter / source / ooxml / factoryimpl.xsl
blob07571b0d03cc8934773705a2ae12e768616613c1
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
19 version="1.0"
20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
22 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
23 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
24 xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
25 xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
26 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
27 xmlns:xlink="http://www.w3.org/1999/xlink"
28 xmlns:dc="http://purl.org/dc/elements/1.1/"
29 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
30 xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
31 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
32 xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
33 xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
34 xmlns:math="http://www.w3.org/1998/Math/MathML"
35 xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
36 xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
37 xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
38 xmlns:ooo="http://openoffice.org/2004/office"
39 xmlns:ooow="http://openoffice.org/2004/writer"
40 xmlns:oooc="http://openoffice.org/2004/calc"
41 xmlns:dom="http://www.w3.org/2001/xml-events"
42 xmlns:xforms="http://www.w3.org/2002/xforms"
43 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
44 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
46 xmlns:rng="http://relaxng.org/ns/structure/1.0"
47 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
48 xmlns:UML = 'org.omg.xmi.namespace.UML' xml:space="default">
49 <xsl:output method="text" />
50 <xsl:param name="prefix"/>
52 <xsl:include href="factorytools.xsl"/>
54 <xsl:key name="resources-with-kind" match="//resource[kind]" use="kind/@name"/>
55 <xsl:key name="sprms-with-code" match="//resource/element[@tokenid]" use="@tokenid"/>
57 <xsl:template name="factorycreatecontextfromfactory">
58 <xsl:text>
59 uno::Reference&lt; xml::sax::XFastContextHandler &gt; OOXMLFactory::createFastChildContextFromFactory
60 (OOXMLFastContextHandler * pHandler, OOXMLFactory_ns::Pointer_t pFactory, Token_t Element)
62 uno::Reference &lt; xml::sax::XFastContextHandler &gt; aResult;
63 Id nDefine = pHandler->getDefine();
65 #ifdef DEBUG_FACTORY
66 debug_logger->startElement("factory.createFastChildContextFromFactory");
67 #endif
69 if (pFactory.get() != NULL)
71 CreateElementMapPointer pMap = pFactory-&gt;getCreateElementMap(nDefine);
72 TokenToIdMapPointer pTokenMap = pFactory-&gt;getTokenToIdMap(nDefine);
74 if (pMap.get() != NULL)
76 Id nId = (*pTokenMap)[Element];
77 #ifdef DEBUG_FACTORY
78 string sFactoryName(pFactory->getName());
79 string sDefine(pFactory->getDefineName(nDefine));
80 string sElement(fastTokenToId(Element));
81 string sQName((*QNameToString::Instance())(nId));
83 debug_logger->attribute("factory-name", sFactoryName);
84 debug_logger->attribute("define", sDefine);
85 debug_logger->attribute("element", sElement);
86 debug_logger->attribute("qname", sQName);
88 static char buffer[16];
89 snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIuUINT32, nId);
90 debug_logger->attribute("idnum", buffer);
92 snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIuUINT32, nDefine);
93 debug_logger->attribute("definenum", buffer);
94 #endif
96 CreateElement aCreateElement = (*pMap)[Element];
98 switch (aCreateElement.m_nResource)
99 {</xsl:text>
100 <xsl:for-each select="/model/namespace/resource">
101 <xsl:if test="generate-id(key('resources', @resource)) = generate-id(.)">
102 <xsl:if test="not(@resource = 'Hex' or
103 @resource = 'Integer' or
104 @resource = 'Boolean' or
105 @resource = 'List' or
106 @resource = 'String')">
107 <xsl:text>
108 case RT_</xsl:text>
109 <xsl:value-of select="@resource"/>
110 <xsl:text>:
111 aResult.set(OOXMLFastHelper&lt;OOXMLFastContextHandler</xsl:text>
112 <xsl:value-of select="@resource"/>
113 <xsl:text>&gt;::createAndSetParentAndDefine(pHandler, Element, nId, aCreateElement.m_nId));
114 break;</xsl:text>
115 </xsl:if>
116 </xsl:if>
117 </xsl:for-each>
118 <xsl:text>
119 case RT_Any:
120 aResult.set(createFastChildContextFromStart(pHandler, Element));
121 break;
122 default:
123 break;
129 #ifdef DEBUG_FACTORY
130 debug_logger->endElement("factory.createFastChildContextFromFactory");
131 #endif
133 return aResult;
135 </xsl:text>
136 </xsl:template>
138 <xsl:template name="factoryfornamespace">
139 <xsl:text>
140 OOXMLFactory_ns::Pointer_t OOXMLFactory::getFactoryForNamespace(Id nId)
142 OOXMLFactory_ns::Pointer_t pResult;
144 switch (nId &amp; 0xffff0000)
145 {</xsl:text>
146 <xsl:for-each select="/model/namespace">
147 <xsl:text>
148 case </xsl:text>
149 <xsl:call-template name="idfornamespace"/>
150 <xsl:text>:
151 pResult = </xsl:text>
152 <xsl:call-template name="factoryclassname"/>
153 <xsl:text>::getInstance();
154 break;</xsl:text>
155 </xsl:for-each>
156 <xsl:text>
157 default:
158 break;
161 return pResult;
163 </xsl:text>
164 </xsl:template>
166 <xsl:template name="factorycreatefromstart">
167 <xsl:text>
168 uno::Reference&lt; xml::sax::XFastContextHandler &gt; OOXMLFactory::createFastChildContextFromStart
169 (OOXMLFastContextHandler * pHandler, Token_t Element)
171 #ifdef DEBUG_FACTORY
172 debug_logger->startElement("factory.createFastChildContextFromStart");
173 #endif
175 uno::Reference &lt; xml::sax::XFastContextHandler &gt; aResult;
176 OOXMLFactory_ns::Pointer_t pFactory;
178 </xsl:text>
179 <xsl:for-each select="/model/namespace">
180 <xsl:text>
181 if (! aResult.is())
183 pFactory = getFactoryForNamespace(</xsl:text>
184 <xsl:call-template name="idfornamespace"/>
185 <xsl:text>);
186 aResult.set(createFastChildContextFromFactory(pHandler, pFactory, Element));
187 }</xsl:text>
188 </xsl:for-each>
189 <xsl:text>
191 #ifdef DEBUG_FACTORY
192 debug_logger->endElement("factory.createFastChildContextFromStart");
193 #endif
194 return aResult;
196 </xsl:text>
197 </xsl:template>
199 <xsl:template name="fasttokentoid">
200 <xsl:text>
201 namespace tokenmap {
202 struct token { const char * name; Token_t nToken; };
203 class Perfect_Hash
205 private:
206 static inline unsigned int hash (const char *str, unsigned int len);
207 public:
208 static struct token *in_word_set (const char *str, unsigned int len);
212 string fastTokenToId(sal_uInt32 nToken)
214 </xsl:text>
215 <xsl:text>
216 string sResult;
218 switch (nToken &amp; 0xffff0000)
219 {</xsl:text>
220 <xsl:for-each select="//namespace-alias">
221 <xsl:text>
222 case NS_</xsl:text>
223 <xsl:value-of select="@alias"/>
224 <xsl:text>:
225 sResult += "</xsl:text>
226 <xsl:value-of select="@alias"/>
227 <xsl:text>:";
228 break;</xsl:text>
229 </xsl:for-each>
230 <xsl:text>
233 switch (nToken &amp; 0xffff)
234 {</xsl:text>
235 <xsl:for-each select=".//rng:element[@localname]|.//rng:attribute[@localname]">
236 <xsl:variable name="localname" select="@localname"/>
237 <xsl:if test="generate-id(.) = generate-id(key('same-token-name', $localname)[1])">
238 <xsl:text>
239 case </xsl:text>
240 <xsl:call-template name="fastlocalname"/>
241 <xsl:text>:
242 sResult += "</xsl:text>
243 <xsl:value-of select="$localname"/>
244 <xsl:text>";
245 break;</xsl:text>
246 </xsl:if>
247 </xsl:for-each>
248 <xsl:text>
251 return sResult;
253 </xsl:text>
254 </xsl:template>
256 <!--
257 Generates case labels for mapping from token ids to a single kind
258 of sprm.
260 @param kind the sprm kind for which to generate the case labels
263 <xsl:template name="sprmkindcase">
264 <xsl:param name="kind"/>
265 <xsl:for-each select="key('resources-with-kind', $kind)/element">
266 <xsl:if test="generate-id(.) = generate-id(key('sprms-with-code', @tokenid))">
267 <xsl:text>
268 case </xsl:text>
269 <xsl:call-template name="idtoqname">
270 <xsl:with-param name="id" select="@tokenid"/>
271 </xsl:call-template>
272 <xsl:text>: //</xsl:text>
273 <xsl:value-of select="ancestor::resource/@name"/>
274 <xsl:text>, </xsl:text>
275 <xsl:value-of select="@name"/>
276 </xsl:if>
277 </xsl:for-each>
278 </xsl:template>
280 <!--
281 Generates SprmKind.
283 <xsl:template name="sprmkind">
284 <xsl:text>
285 Sprm::Kind SprmKind(sal_uInt32 nSprmCode)
287 Sprm::Kind nResult = Sprm::UNKNOWN;
289 switch (nSprmCode)
290 {</xsl:text>
291 <xsl:call-template name="sprmkindcase">
292 <xsl:with-param name="kind">paragraph</xsl:with-param>
293 </xsl:call-template>
294 <xsl:text>
295 nResult = Sprm::PARAGRAPH;
296 break;</xsl:text>
297 <xsl:call-template name="sprmkindcase">
298 <xsl:with-param name="kind">character</xsl:with-param>
299 </xsl:call-template>
300 <xsl:text>
301 nResult = Sprm::CHARACTER;
302 break;</xsl:text>
303 <xsl:call-template name="sprmkindcase">
304 <xsl:with-param name="kind">table</xsl:with-param>
305 </xsl:call-template>
306 <xsl:text>
307 nResult = Sprm::TABLE;
308 break;</xsl:text>
309 <xsl:text>
310 default:
311 break;
314 return nResult;
315 }</xsl:text>
316 </xsl:template>
318 <xsl:template name="getfastparser">
319 <xsl:text>
320 uno::Reference &lt; xml::sax::XFastParser &gt; OOXMLStreamImpl::getFastParser()
322 if (! mxFastParser.is())
324 uno::Reference &lt; lang::XMultiComponentFactory &gt; xFactory =
325 uno::Reference &lt; lang::XMultiComponentFactory &gt;
326 (mxContext->getServiceManager());
328 mxFastParser.set(xFactory->createInstanceWithContext
329 ( "com.sun.star.xml.sax.FastParser",
330 mxContext ), uno::UNO_QUERY_THROW);
331 </xsl:text>
332 <xsl:for-each select="//namespace-alias">
333 <xsl:text>
334 mxFastParser->registerNamespace("</xsl:text>
335 <xsl:value-of select="@name"/>
336 <xsl:text>", </xsl:text>
337 <xsl:call-template name="namespaceid"/>
338 <xsl:text>);</xsl:text>
339 </xsl:for-each>
340 <xsl:text>
343 return mxFastParser;
345 </xsl:text>
346 </xsl:template>
348 <xsl:template match="/">
349 <xsl:text>
350 #include "ooxml/OOXMLFactory.hxx"
351 #include "ooxml/OOXMLFastHelper.hxx"
352 #include "ooxml/OOXMLStreamImpl.hxx"
353 #include "doctok/sprmids.hxx"
354 #include "doctok/resourceids.hxx"
355 </xsl:text>
356 <xsl:call-template name="factoryincludes"/>
357 <xsl:text>
358 namespace writerfilter {
359 namespace ooxml {
361 /// @cond GENERATED
362 </xsl:text>
363 <xsl:call-template name="factorycreatecontextfromfactory"/>
364 <xsl:call-template name="factoryfornamespace"/>
365 <xsl:call-template name="factorycreatefromstart"/>
366 <xsl:call-template name="fasttokentoid"/>
367 <xsl:call-template name="sprmkind"/>
368 <xsl:call-template name="getfastparser"/>
369 <xsl:text>
370 /// @endcond
372 </xsl:text>
373 </xsl:template>
375 </xsl:stylesheet>