1<!--***********************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 ***********************************************************-->
21<xsl:stylesheet
22    version="1.0"
23    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
25    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
26    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
27    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
28    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
29    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
30    xmlns:xlink="http://www.w3.org/1999/xlink"
31    xmlns:dc="http://purl.org/dc/elements/1.1/"
32    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
33    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
34    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
35    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
36    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
37    xmlns:math="http://www.w3.org/1998/Math/MathML"
38    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
39    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
40    xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
41    xmlns:ooo="http://openoffice.org/2004/office"
42    xmlns:ooow="http://openoffice.org/2004/writer"
43    xmlns:oooc="http://openoffice.org/2004/calc"
44    xmlns:dom="http://www.w3.org/2001/xml-events"
45    xmlns:xforms="http://www.w3.org/2002/xforms"
46    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
47    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
49    xmlns:rng="http://relaxng.org/ns/structure/1.0"
50    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
51    xmlns:UML = 'org.omg.xmi.namespace.UML' xml:space="default">
52  <xsl:output method="text" />
53  <xsl:param name="prefix"/>
54
55  <xsl:include href="factorytools.xsl"/>
56
57  <xsl:key name="resources-with-kind" match="//resource[kind]" use="kind/@name"/>
58  <xsl:key name="sprms-with-code" match="//resource/element[@tokenid]" use="@tokenid"/>
59
60<xsl:template name="factorycreatecontextfromfactory">
61    <xsl:text>
62uno::Reference&lt; xml::sax::XFastContextHandler &gt; OOXMLFactory::createFastChildContextFromFactory
63(OOXMLFastContextHandler * pHandler, OOXMLFactory_ns::Pointer_t pFactory, Token_t Element)
64{
65    uno::Reference &lt; xml::sax::XFastContextHandler &gt; aResult;
66    Id nDefine = pHandler->getDefine();
67
68#ifdef DEBUG_FACTORY
69    debug_logger->startElement("factory.createFastChildContextFromFactory");
70#endif
71
72    if (pFactory.get() != NULL)
73    {
74        CreateElementMapPointer pMap = pFactory-&gt;getCreateElementMap(nDefine);
75        TokenToIdMapPointer pTokenMap = pFactory-&gt;getTokenToIdMap(nDefine);
76
77        if (pMap.get() != NULL)
78        {
79            Id nId = (*pTokenMap)[Element];
80#ifdef DEBUG_FACTORY
81            string sFactoryName(pFactory->getName());
82            string sDefine(pFactory->getDefineName(nDefine));
83            string sElement(fastTokenToId(Element));
84            string sQName((*QNameToString::Instance())(nId));
85
86            debug_logger->attribute("factory-name", sFactoryName);
87            debug_logger->attribute("define", sDefine);
88            debug_logger->attribute("element", sElement);
89            debug_logger->attribute("qname", sQName);
90
91            static char buffer[16];
92            snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIuUINT32, nId);
93            debug_logger->attribute("idnum", buffer);
94
95            snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIuUINT32, nDefine);
96            debug_logger->attribute("definenum", buffer);
97#endif
98
99            CreateElement aCreateElement = (*pMap)[Element];
100
101            switch (aCreateElement.m_nResource)
102            {</xsl:text>
103            <xsl:for-each select="/model/namespace/resource">
104                <xsl:if test="generate-id(key('resources', @resource)) = generate-id(.)">
105                    <xsl:if test="not(@resource = 'Hex' or
106                                      @resource = 'Integer' or
107                                      @resource = 'Boolean' or
108                                      @resource = 'List' or
109                                      @resource = 'String')">
110                        <xsl:text>
111            case RT_</xsl:text>
112                        <xsl:value-of select="@resource"/>
113                        <xsl:text>:
114                aResult.set(OOXMLFastHelper&lt;OOXMLFastContextHandler</xsl:text>
115                        <xsl:value-of select="@resource"/>
116                        <xsl:text>&gt;::createAndSetParentAndDefine(pHandler, Element, nId, aCreateElement.m_nId));
117                break;</xsl:text>
118                    </xsl:if>
119                </xsl:if>
120            </xsl:for-each>
121            <xsl:text>
122	    case RT_Any:
123	        aResult.set(createFastChildContextFromStart(pHandler, Element));
124		break;
125            default:
126                break;
127            }
128
129        }
130    }
131
132#ifdef DEBUG_FACTORY
133    debug_logger->endElement("factory.createFastChildContextFromFactory");
134#endif
135
136    return aResult;
137}
138</xsl:text>
139</xsl:template>
140
141<xsl:template name="factoryfornamespace">
142    <xsl:text>
143OOXMLFactory_ns::Pointer_t OOXMLFactory::getFactoryForNamespace(Id nId)
144{
145    OOXMLFactory_ns::Pointer_t pResult;
146
147    switch (nId &amp; 0xffff0000)
148    {</xsl:text>
149    <xsl:for-each select="/model/namespace">
150        <xsl:text>
151    case </xsl:text>
152        <xsl:call-template name="idfornamespace"/>
153        <xsl:text>:
154        pResult = </xsl:text>
155        <xsl:call-template name="factoryclassname"/>
156        <xsl:text>::getInstance();
157        break;</xsl:text>
158    </xsl:for-each>
159    <xsl:text>
160        default:
161            break;
162    }
163
164    return pResult;
165}
166</xsl:text>
167</xsl:template>
168
169<xsl:template name="factorycreatefromstart">
170    <xsl:text>
171uno::Reference&lt; xml::sax::XFastContextHandler &gt; OOXMLFactory::createFastChildContextFromStart
172(OOXMLFastContextHandler * pHandler, Token_t Element)
173{
174#ifdef DEBUG_FACTORY
175    debug_logger->startElement("factory.createFastChildContextFromStart");
176#endif
177
178    uno::Reference &lt; xml::sax::XFastContextHandler &gt; aResult;
179    OOXMLFactory_ns::Pointer_t pFactory;
180
181</xsl:text>
182    <xsl:for-each select="/model/namespace">
183        <xsl:text>
184    if (! aResult.is())
185    {
186        pFactory = getFactoryForNamespace(</xsl:text>
187        <xsl:call-template name="idfornamespace"/>
188        <xsl:text>);
189        aResult.set(createFastChildContextFromFactory(pHandler, pFactory, Element));
190    }</xsl:text>
191    </xsl:for-each>
192    <xsl:text>
193
194#ifdef DEBUG_FACTORY
195    debug_logger->endElement("factory.createFastChildContextFromStart");
196#endif
197    return aResult;
198}
199</xsl:text>
200</xsl:template>
201
202<xsl:template name="fasttokentoid">
203  <xsl:text>
204namespace tokenmap {
205struct token { const char * name; Token_t nToken; };
206class Perfect_Hash
207{
208private:
209  static inline unsigned int hash (const char *str, unsigned int len);
210public:
211  static struct token *in_word_set (const char *str, unsigned int len);
212};
213}
214
215string fastTokenToId(sal_uInt32 nToken)
216{
217  </xsl:text>
218  <xsl:text>
219    string sResult;
220
221    switch (nToken &amp; 0xffff0000)
222    {</xsl:text>
223    <xsl:for-each select="//namespace-alias">
224      <xsl:text>
225    case NS_</xsl:text>
226    <xsl:value-of select="@alias"/>
227    <xsl:text>:
228        sResult += "</xsl:text>
229        <xsl:value-of select="@alias"/>
230        <xsl:text>:";
231        break;</xsl:text>
232    </xsl:for-each>
233    <xsl:text>
234    }
235
236    switch (nToken &amp; 0xffff)
237    {</xsl:text>
238  <xsl:for-each select=".//rng:element[@localname]|.//rng:attribute[@localname]">
239    <xsl:variable name="localname" select="@localname"/>
240    <xsl:if test="generate-id(.) = generate-id(key('same-token-name', $localname)[1])">
241      <xsl:text>
242    case </xsl:text>
243    <xsl:call-template name="fastlocalname"/>
244    <xsl:text>:
245        sResult +=  "</xsl:text>
246        <xsl:value-of select="$localname"/>
247        <xsl:text>";
248        break;</xsl:text>
249    </xsl:if>
250  </xsl:for-each>
251<xsl:text>
252    }
253
254    return sResult;
255}
256  </xsl:text>
257</xsl:template>
258
259  <!--
260      Generates case labels for mapping from token ids to a single kind
261      of sprm.
262
263      @param kind     the sprm kind for which to generate the case labels
264  -->
265
266  <xsl:template name="sprmkindcase">
267    <xsl:param name="kind"/>
268    <xsl:for-each select="key('resources-with-kind', $kind)/element">
269      <xsl:if test="generate-id(.) = generate-id(key('sprms-with-code', @tokenid))">
270      <xsl:text>
271     case </xsl:text>
272     <xsl:call-template name="idtoqname">
273       <xsl:with-param name="id" select="@tokenid"/>
274     </xsl:call-template>
275     <xsl:text>: //</xsl:text>
276     <xsl:value-of select="ancestor::resource/@name"/>
277     <xsl:text>, </xsl:text>
278     <xsl:value-of select="@name"/>
279      </xsl:if>
280    </xsl:for-each>
281  </xsl:template>
282
283  <!--
284      Generates SprmKind.
285  -->
286  <xsl:template name="sprmkind">
287    <xsl:text>
288Sprm::Kind SprmKind(sal_uInt32 nSprmCode)
289{
290    Sprm::Kind nResult = Sprm::UNKNOWN;
291
292    switch (nSprmCode)
293    {</xsl:text>
294    <xsl:call-template name="sprmkindcase">
295      <xsl:with-param name="kind">paragraph</xsl:with-param>
296    </xsl:call-template>
297    <xsl:text>
298      nResult = Sprm::PARAGRAPH;
299      break;</xsl:text>
300    <xsl:call-template name="sprmkindcase">
301      <xsl:with-param name="kind">character</xsl:with-param>
302    </xsl:call-template>
303    <xsl:text>
304      nResult = Sprm::CHARACTER;
305      break;</xsl:text>
306    <xsl:call-template name="sprmkindcase">
307      <xsl:with-param name="kind">table</xsl:with-param>
308    </xsl:call-template>
309    <xsl:text>
310      nResult = Sprm::TABLE;
311      break;</xsl:text>
312    <xsl:text>
313    default:
314      break;
315    }
316
317    return nResult;
318}</xsl:text>
319  </xsl:template>
320
321<xsl:template name="getfastparser">
322<xsl:text>
323uno::Reference &lt; xml::sax::XFastParser &gt; OOXMLStreamImpl::getFastParser()
324{
325    if (! mxFastParser.is())
326    {
327        uno::Reference &lt; lang::XMultiComponentFactory &gt; xFactory =
328            uno::Reference &lt; lang::XMultiComponentFactory &gt;
329            (mxContext->getServiceManager());
330
331        mxFastParser.set(xFactory->createInstanceWithContext
332            ( ::rtl::OUString::createFromAscii
333                ( "com.sun.star.xml.sax.FastParser" ),
334                    mxContext ), uno::UNO_QUERY_THROW);
335</xsl:text>
336<xsl:for-each select="//namespace-alias">
337  <xsl:text>
338        mxFastParser->registerNamespace(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("</xsl:text>
339    <xsl:value-of select="@name"/>
340    <xsl:text>")), </xsl:text>
341    <xsl:call-template name="namespaceid"/>
342    <xsl:text>);</xsl:text>
343</xsl:for-each>
344<xsl:text>
345    }
346
347    return mxFastParser;
348}
349</xsl:text>
350</xsl:template>
351
352  <xsl:template match="/">
353    <xsl:text>
354#include "OOXMLFactory.hxx"
355#include "OOXMLFastHelper.hxx"
356#include "OOXMLStreamImpl.hxx"
357#include "doctok/sprmids.hxx"
358#include "doctok/resourceids.hxx"
359</xsl:text>
360    <xsl:call-template name="factoryincludes"/>
361    <xsl:text>
362namespace writerfilter {
363namespace ooxml {
364
365/// @cond GENERATED
366    </xsl:text>
367    <xsl:call-template name="factorycreatecontextfromfactory"/>
368    <xsl:call-template name="factoryfornamespace"/>
369    <xsl:call-template name="factorycreatefromstart"/>
370    <xsl:call-template name="fasttokentoid"/>
371    <xsl:call-template name="sprmkind"/>
372    <xsl:call-template name="getfastparser"/>
373    <xsl:text>
374/// @endcond
375}}
376</xsl:text>
377</xsl:template>
378
379</xsl:stylesheet>
380