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 <stdio.h>
21 :
22 : #include <rtl/instance.hxx>
23 : #include <osl/mutex.hxx>
24 : #include <sax/fastattribs.hxx>
25 : #include "OOXMLFactory.hxx"
26 : #include "OOXMLFastHelper.hxx"
27 :
28 : namespace writerfilter {
29 : namespace ooxml {
30 :
31 : using namespace com::sun::star;
32 :
33 : // class OOXMLFactory_ns
34 :
35 810 : OOXMLFactory_ns::~OOXMLFactory_ns()
36 : {
37 810 : }
38 :
39 : // class OOXMLFactory
40 :
41 : typedef rtl::Static< osl::Mutex, OOXMLFactory > OOXMLFactory_Mutex;
42 :
43 38 : OOXMLFactory::Pointer_t OOXMLFactory::m_Instance;
44 :
45 30 : OOXMLFactory::OOXMLFactory()
46 : {
47 : // multi-thread-safe mutex for all platforms
48 30 : osl::MutexGuard aGuard(OOXMLFactory_Mutex::get());
49 30 : mnRefCnt = 0;
50 30 : }
51 :
52 60 : OOXMLFactory::~OOXMLFactory()
53 : {
54 60 : }
55 :
56 14985888 : OOXMLFactory::Pointer_t OOXMLFactory::getInstance()
57 : {
58 14985888 : if (m_Instance.get() == nullptr)
59 30 : m_Instance.reset(new OOXMLFactory());
60 :
61 14985888 : return m_Instance;
62 : }
63 :
64 3680782 : void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
65 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
66 : {
67 3680782 : Id nDefine = pHandler->getDefine();
68 3680782 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
69 :
70 3680782 : if (pFactory.get() == nullptr)
71 0 : return;
72 :
73 : assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != nullptr );
74 : sax_fastparser::FastAttributeList *pAttribs;
75 3680782 : pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
76 :
77 3680782 : const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
78 3680782 : if (!pAttr)
79 655324 : return;
80 :
81 12291160 : for (; pAttr->m_nToken != -1; ++pAttr)
82 : {
83 9265702 : sal_Int32 nToken = pAttr->m_nToken;
84 9265702 : if (!pAttribs->hasAttribute(nToken))
85 4241260 : continue;
86 :
87 5024442 : Id nId = pFactory->getResourceId(nDefine, nToken);
88 :
89 5024442 : switch (pAttr->m_nResource)
90 : {
91 : case RT_Boolean:
92 : {
93 146294 : const char *pValue = "";
94 146294 : pAttribs->getAsChar(nToken, pValue);
95 146294 : OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue));
96 146294 : pHandler->newProperty(nId, xValue);
97 146294 : pFactory->attributeAction(pHandler, nToken, xValue);
98 : }
99 146294 : break;
100 : case RT_String:
101 : {
102 2929454 : OUString aValue(pAttribs->getValue(nToken));
103 5858908 : OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue));
104 2929454 : pHandler->newProperty(nId, xValue);
105 5858908 : pFactory->attributeAction(pHandler, nToken, xValue);
106 : }
107 2929454 : break;
108 : case RT_Integer:
109 : {
110 : sal_Int32 nValue;
111 502816 : pAttribs->getAsInteger(nToken,nValue);
112 502816 : OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
113 502816 : pHandler->newProperty(nId, xValue);
114 502816 : pFactory->attributeAction(pHandler, nToken, xValue);
115 : }
116 502816 : break;
117 : case RT_Hex:
118 : {
119 510908 : const char *pValue = "";
120 510908 : pAttribs->getAsChar(nToken, pValue);
121 510908 : OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue));
122 510908 : pHandler->newProperty(nId, xValue);
123 510908 : pFactory->attributeAction(pHandler, nToken, xValue);
124 : }
125 510908 : break;
126 : case RT_UniversalMeasure:
127 : {
128 291106 : const char *pValue = "";
129 291106 : pAttribs->getAsChar(nToken, pValue);
130 291106 : OOXMLValue::Pointer_t xValue(new OOXMLUniversalMeasureValue(pValue));
131 291106 : pHandler->newProperty(nId, xValue);
132 291106 : pFactory->attributeAction(pHandler, nToken, xValue);
133 : }
134 291106 : break;
135 : case RT_List:
136 : {
137 : sal_uInt32 nValue;
138 643846 : if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue))
139 : {
140 643846 : OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
141 643846 : pHandler->newProperty(nId, xValue);
142 643846 : pFactory->attributeAction(pHandler, nToken, xValue);
143 : }
144 : }
145 643846 : break;
146 : default:
147 18 : break;
148 : }
149 3025458 : }
150 : }
151 :
152 : uno::Reference< xml::sax::XFastContextHandler>
153 3685218 : OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
154 : Token_t Element)
155 : {
156 3685218 : Id nDefine = pHandler->getDefine();
157 :
158 3685218 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
159 :
160 3685218 : uno::Reference< xml::sax::XFastContextHandler> ret;
161 :
162 : //Avoid handling unknown tokens and recursing to death
163 3685218 : if ((Element & 0xffff) < oox::XML_TOKEN_COUNT)
164 3685218 : ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
165 :
166 3685218 : return ret;
167 : }
168 :
169 266002 : void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
170 : const OUString & rString)
171 : {
172 266002 : Id nDefine = pHandler->getDefine();
173 266002 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
174 :
175 266002 : if (pFactory.get() != nullptr)
176 : {
177 266002 : pFactory->charactersAction(pHandler, rString);
178 266002 : }
179 266002 : }
180 :
181 3670118 : void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
182 : {
183 3670118 : Id nDefine = pHandler->getDefine();
184 3670118 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
185 :
186 3670118 : if (pFactory.get() != nullptr)
187 : {
188 3670118 : pFactory->startAction(pHandler);
189 3670118 : }
190 3670118 : }
191 :
192 3662640 : void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
193 : {
194 3662640 : Id nDefine = pHandler->getDefine();
195 3662640 : OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
196 :
197 3662640 : if (pFactory.get() != nullptr)
198 : {
199 3662640 : pFactory->endAction(pHandler);
200 3662640 : }
201 3662626 : }
202 :
203 312376 : void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
204 : {
205 312376 : }
206 :
207 492864 : void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
208 : {
209 492864 : }
210 :
211 0 : void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
212 : {
213 0 : }
214 :
215 0 : void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, OOXMLValue::Pointer_t)
216 : {
217 0 : }
218 :
219 : }
220 114 : }
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|