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 .
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">
59 uno::Reference
< xml::sax::XFastContextHandler
> OOXMLFactory::createFastChildContextFromFactory
60 (OOXMLFastContextHandler * pHandler, OOXMLFactory_ns::Pointer_t pFactory, Token_t Element)
62 uno::Reference
< xml::sax::XFastContextHandler
> aResult;
63 Id nDefine = pHandler-
>getDefine();
66 debug_logger-
>startElement(
"factory.createFastChildContextFromFactory");
69 if (pFactory.get() != NULL)
71 CreateElementMapPointer pMap = pFactory-
>getCreateElementMap(nDefine);
72 TokenToIdMapPointer pTokenMap = pFactory-
>getTokenToIdMap(nDefine);
74 if (pMap.get() != NULL)
76 Id nId = (*pTokenMap)[Element];
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);
96 CreateElement aCreateElement = (*pMap)[Element];
98 switch (aCreateElement.m_nResource)
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')">
109 <xsl:value-of select=
"@resource"/>
111 aResult.set(OOXMLFastHelper
<OOXMLFastContextHandler
</xsl:text>
112 <xsl:value-of select=
"@resource"/>
113 <xsl:text>>::createAndSetParentAndDefine(pHandler, Element, nId, aCreateElement.m_nId));
120 aResult.set(createFastChildContextFromStart(pHandler, Element));
130 debug_logger-
>endElement(
"factory.createFastChildContextFromFactory");
138 <xsl:template name=
"factoryfornamespace">
140 OOXMLFactory_ns::Pointer_t OOXMLFactory::getFactoryForNamespace(Id nId)
142 OOXMLFactory_ns::Pointer_t pResult;
144 switch (nId
& 0xffff0000)
146 <xsl:for-each select=
"/model/namespace">
149 <xsl:call-template name=
"idfornamespace"/>
151 pResult =
</xsl:text>
152 <xsl:call-template name=
"factoryclassname"/>
153 <xsl:text>::getInstance();
166 <xsl:template name=
"factorycreatefromstart">
168 uno::Reference
< xml::sax::XFastContextHandler
> OOXMLFactory::createFastChildContextFromStart
169 (OOXMLFastContextHandler * pHandler, Token_t Element)
172 debug_logger-
>startElement(
"factory.createFastChildContextFromStart");
175 uno::Reference
< xml::sax::XFastContextHandler
> aResult;
176 OOXMLFactory_ns::Pointer_t pFactory;
179 <xsl:for-each select=
"/model/namespace">
183 pFactory = getFactoryForNamespace(
</xsl:text>
184 <xsl:call-template name=
"idfornamespace"/>
186 aResult.set(createFastChildContextFromFactory(pHandler, pFactory, Element));
192 debug_logger-
>endElement(
"factory.createFastChildContextFromStart");
199 <xsl:template name=
"fasttokentoid">
202 struct token { const char * name; Token_t nToken; };
206 static inline unsigned int hash (const char *str, unsigned int len);
208 static struct token *in_word_set (const char *str, unsigned int len);
212 string fastTokenToId(sal_uInt32 nToken)
218 switch (nToken
& 0xffff0000)
220 <xsl:for-each select=
"//namespace-alias">
223 <xsl:value-of select=
"@alias"/>
225 sResult +=
"</xsl:text>
226 <xsl:value-of select="@alias
"/>
233 switch (nToken
& 0xffff)
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])">
240 <xsl:call-template name=
"fastlocalname"/>
242 sResult +=
"</xsl:text>
243 <xsl:value-of select="$localname
"/>
257 Generates case labels for mapping from token ids to a single kind
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))">
269 <xsl:call-template name=
"idtoqname">
270 <xsl:with-param name=
"id" select=
"@tokenid"/>
272 <xsl:text>: //
</xsl:text>
273 <xsl:value-of select=
"ancestor::resource/@name"/>
274 <xsl:text>,
</xsl:text>
275 <xsl:value-of select=
"@name"/>
283 <xsl:template name=
"sprmkind">
285 Sprm::Kind SprmKind(sal_uInt32 nSprmCode)
287 Sprm::Kind nResult = Sprm::UNKNOWN;
291 <xsl:call-template name=
"sprmkindcase">
292 <xsl:with-param name=
"kind">paragraph
</xsl:with-param>
295 nResult = Sprm::PARAGRAPH;
297 <xsl:call-template name=
"sprmkindcase">
298 <xsl:with-param name=
"kind">character
</xsl:with-param>
301 nResult = Sprm::CHARACTER;
303 <xsl:call-template name=
"sprmkindcase">
304 <xsl:with-param name=
"kind">table
</xsl:with-param>
307 nResult = Sprm::TABLE;
318 <xsl:template name=
"getfastparser">
320 uno::Reference
< xml::sax::XFastParser
> OOXMLStreamImpl::getFastParser()
322 if (! mxFastParser.is())
324 uno::Reference
< lang::XMultiComponentFactory
> xFactory =
325 uno::Reference
< lang::XMultiComponentFactory
>
326 (mxContext-
>getServiceManager());
328 mxFastParser.set(xFactory-
>createInstanceWithContext
329 (
"com.sun.star.xml.sax.FastParser",
330 mxContext ), uno::UNO_QUERY_THROW);
332 <xsl:for-each select=
"//namespace-alias">
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>
348 <xsl:template match=
"/">
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"
356 <xsl:call-template name=
"factoryincludes"/>
358 namespace writerfilter {
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"/>