Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <rtl/instance.hxx>
21 : #include <osl/mutex.hxx>
22 : #include <sax/fastattribs.hxx>
23 : #include "OOXMLFactory.hxx"
24 : #include "OOXMLFastHelper.hxx"
25 :
26 : namespace writerfilter {
27 : namespace ooxml {
28 :
29 : using namespace com::sun::star;
30 :
31 : // class OOXMLFactory_ns
32 :
33 513 : OOXMLFactory_ns::~OOXMLFactory_ns()
34 : {
35 513 : }
36 :
37 : // class OOXMLFactory
38 :
39 1969607 : void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
40 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
41 : {
42 1969607 : Id nDefine = pHandler->getDefine();
43 1969607 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
44 :
45 1969607 : if (pFactory.get() == nullptr)
46 0 : return;
47 :
48 : assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != nullptr );
49 : sax_fastparser::FastAttributeList *pAttribs;
50 1969607 : pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
51 :
52 1969607 : const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
53 1969607 : if (!pAttr)
54 354371 : return;
55 :
56 6588826 : for (; pAttr->m_nToken != -1; ++pAttr)
57 : {
58 4973590 : sal_Int32 nToken = pAttr->m_nToken;
59 4973590 : if (!pAttribs->hasAttribute(nToken))
60 2298800 : continue;
61 :
62 2674790 : Id nId = pFactory->getResourceId(nDefine, nToken);
63 :
64 2674790 : switch (pAttr->m_nResource)
65 : {
66 : case RT_Boolean:
67 : {
68 77500 : const char *pValue = "";
69 77500 : pAttribs->getAsChar(nToken, pValue);
70 77500 : OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue));
71 77500 : pHandler->newProperty(nId, xValue);
72 77500 : pFactory->attributeAction(pHandler, nToken, xValue);
73 : }
74 77500 : break;
75 : case RT_String:
76 : {
77 1560748 : OUString aValue(pAttribs->getValue(nToken));
78 3121496 : OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue));
79 1560748 : pHandler->newProperty(nId, xValue);
80 3121496 : pFactory->attributeAction(pHandler, nToken, xValue);
81 : }
82 1560748 : break;
83 : case RT_Integer:
84 : {
85 : sal_Int32 nValue;
86 272035 : pAttribs->getAsInteger(nToken,nValue);
87 272035 : OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
88 272035 : pHandler->newProperty(nId, xValue);
89 272035 : pFactory->attributeAction(pHandler, nToken, xValue);
90 : }
91 272035 : break;
92 : case RT_Hex:
93 : {
94 266454 : const char *pValue = "";
95 266454 : pAttribs->getAsChar(nToken, pValue);
96 266454 : OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue));
97 266454 : pHandler->newProperty(nId, xValue);
98 266454 : pFactory->attributeAction(pHandler, nToken, xValue);
99 : }
100 266454 : break;
101 : case RT_UniversalMeasure:
102 : {
103 155074 : const char *pValue = "";
104 155074 : pAttribs->getAsChar(nToken, pValue);
105 155074 : OOXMLValue::Pointer_t xValue(new OOXMLUniversalMeasureValue(pValue));
106 155074 : pHandler->newProperty(nId, xValue);
107 155074 : pFactory->attributeAction(pHandler, nToken, xValue);
108 : }
109 155074 : break;
110 : case RT_List:
111 : {
112 : sal_uInt32 nValue;
113 342970 : if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue))
114 : {
115 342970 : OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
116 342970 : pHandler->newProperty(nId, xValue);
117 342970 : pFactory->attributeAction(pHandler, nToken, xValue);
118 : }
119 : }
120 342970 : break;
121 : default:
122 9 : break;
123 : }
124 1615236 : }
125 : }
126 :
127 : uno::Reference< xml::sax::XFastContextHandler>
128 1971941 : OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
129 : Token_t Element)
130 : {
131 1971941 : Id nDefine = pHandler->getDefine();
132 :
133 1971941 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
134 :
135 1971941 : uno::Reference< xml::sax::XFastContextHandler> ret;
136 :
137 : //Avoid handling unknown tokens and recursing to death
138 1971941 : if ((Element & 0xffff) < oox::XML_TOKEN_COUNT)
139 1971941 : ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
140 :
141 1971941 : return ret;
142 : }
143 :
144 90978 : void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
145 : const OUString & rString)
146 : {
147 90978 : Id nDefine = pHandler->getDefine();
148 90978 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
149 :
150 90978 : if (pFactory.get() != nullptr)
151 : {
152 90978 : pFactory->charactersAction(pHandler, rString);
153 90978 : }
154 90978 : }
155 :
156 1964280 : void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
157 : {
158 1964280 : Id nDefine = pHandler->getDefine();
159 1964280 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
160 :
161 1964280 : if (pFactory.get() != nullptr)
162 : {
163 1964280 : pFactory->startAction(pHandler);
164 1964280 : }
165 1964280 : }
166 :
167 1960355 : void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
168 : {
169 1960355 : Id nDefine = pHandler->getDefine();
170 1960355 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
171 :
172 1960355 : if (pFactory.get() != nullptr)
173 : {
174 1960355 : pFactory->endAction(pHandler);
175 1960355 : }
176 1960355 : }
177 :
178 166696 : void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
179 : {
180 166696 : }
181 :
182 262819 : void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
183 : {
184 262819 : }
185 :
186 0 : void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
187 : {
188 0 : }
189 :
190 0 : void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, OOXMLValue::Pointer_t)
191 : {
192 0 : }
193 :
194 : }
195 72 : }
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|