1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <rtl/instance.hxx>
23 #include <osl/mutex.hxx>
24 #include "OOXMLFactory.hxx"
25 #include "OOXMLFastHelper.hxx"
27 namespace writerfilter
{
30 AttributeInfo::AttributeInfo()
31 :m_nResource(RT_NoResource
), m_nRef(0)
35 AttributeInfo::AttributeInfo(ResourceType_t nResource
, Id nRef
)
36 :m_nResource(nResource
), m_nRef(nRef
)
40 CreateElement::CreateElement()
41 :m_nResource(RT_NoResource
), m_nId(0)
45 CreateElement::CreateElement(ResourceType_t nResource
, Id nId
)
46 : m_nResource(nResource
), m_nId(nId
)
50 // class OOXMLFactory_ns
52 OOXMLFactory_ns::~OOXMLFactory_ns()
56 AttributeToResourceMapPointer
OOXMLFactory_ns::getAttributeToResourceMap(Id nId
)
58 if (m_AttributesMap
.find(nId
) == m_AttributesMap
.end())
59 m_AttributesMap
[nId
] = createAttributeToResourceMap(nId
);
61 return m_AttributesMap
[nId
];
64 ListValueMapPointer
OOXMLFactory_ns::getListValueMap(Id nId
)
66 if (m_ListValuesMap
.find(nId
) == m_ListValuesMap
.end())
67 m_ListValuesMap
[nId
] = createListValueMap(nId
);
69 return m_ListValuesMap
[nId
];
72 CreateElementMapPointer
OOXMLFactory_ns::getCreateElementMap(Id nId
)
74 if (m_CreateElementsMap
.find(nId
) == m_CreateElementsMap
.end())
75 m_CreateElementsMap
[nId
] = createCreateElementMap(nId
);
77 return m_CreateElementsMap
[nId
];
80 TokenToIdMapPointer
OOXMLFactory_ns::getTokenToIdMap(Id nId
)
82 if (m_TokenToIdsMap
.find(nId
) == m_TokenToIdsMap
.end())
83 m_TokenToIdsMap
[nId
] = createTokenToIdMap(nId
);
85 return m_TokenToIdsMap
[nId
];
88 string
OOXMLFactory_ns::getDefineName(Id
/*nId*/) const
95 typedef rtl::Static
< osl::Mutex
, OOXMLFactory
> OOXMLFactory_Mutex
;
97 OOXMLFactory::Pointer_t
OOXMLFactory::m_Instance
;
99 OOXMLFactory::OOXMLFactory()
101 // multi-thread-safe mutex for all platforms
103 osl::MutexGuard
aGuard(OOXMLFactory_Mutex::get());
106 OOXMLFactory::~OOXMLFactory()
110 OOXMLFactory::Pointer_t
OOXMLFactory::getInstance()
112 if (m_Instance
.get() == NULL
)
113 m_Instance
.reset(new OOXMLFactory());
118 void OOXMLFactory::attributes(OOXMLFastContextHandler
* pHandler
,
119 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
121 Id nDefine
= pHandler
->getDefine();
122 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
124 if (pFactory
.get() != NULL
)
127 debug_logger
->startElement("factory.attributes");
128 debug_logger
->attribute("define", pFactory
->getDefineName(nDefine
));
130 snprintf(sBuffer
, sizeof(sBuffer
), "%08" SAL_PRIxUINT32
, nDefine
);
131 debug_logger
->attribute("define-num", sBuffer
);
134 TokenToIdMapPointer pTokenToIdMap
= pFactory
->getTokenToIdMap(nDefine
);
135 AttributeToResourceMapPointer pMap
= pFactory
->getAttributeToResourceMap(nDefine
);
137 AttributeToResourceMap::const_iterator aIt
;
138 AttributeToResourceMap::const_iterator aEndIt
= pMap
->end();
140 for (aIt
= pMap
->begin(); aIt
!= aEndIt
; ++aIt
)
142 Id nId
= (*pTokenToIdMap
)[aIt
->first
];
144 debug_logger
->startElement("factory.attribute");
145 debug_logger
->attribute("name", fastTokenToId(aIt
->first
));
146 debug_logger
->attribute("tokenid", (*QNameToString::Instance())(nId
));
147 snprintf(sBuffer
, sizeof(sBuffer
), "%08" SAL_PRIxUINT32
, nId
);
148 debug_logger
->attribute("tokenid-num", sBuffer
);
150 if (Attribs
->hasAttribute(aIt
->first
))
152 switch (aIt
->second
.m_nResource
)
157 debug_logger
->element("boolean");
159 OUString
aValue(Attribs
->getValue(aIt
->first
));
160 OOXMLFastHelper
<OOXMLBooleanValue
>::newProperty(pHandler
, nId
, aValue
);
162 OOXMLValue::Pointer_t
pValue(new OOXMLBooleanValue(aValue
));
163 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
169 debug_logger
->element("string");
171 OUString
aValue(Attribs
->getValue(aIt
->first
));
172 OOXMLFastHelper
<OOXMLStringValue
>::newProperty
173 (pHandler
, nId
, aValue
);
175 OOXMLValue::Pointer_t
pValue(new OOXMLStringValue(aValue
));
176 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
182 debug_logger
->element("integer");
184 OUString
aValue(Attribs
->getValue(aIt
->first
));
185 OOXMLFastHelper
<OOXMLIntegerValue
>::newProperty
186 (pHandler
, nId
, aValue
);
188 OOXMLValue::Pointer_t
pValue(new OOXMLIntegerValue(aValue
));
189 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
195 debug_logger
->element("hex");
197 OUString
aValue(Attribs
->getValue(aIt
->first
));
198 OOXMLFastHelper
<OOXMLHexValue
>::newProperty
199 (pHandler
, nId
, aValue
);
201 OOXMLValue::Pointer_t
pValue(new OOXMLHexValue(aValue
));
202 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
208 debug_logger
->startElement("list");
210 ListValueMapPointer pListValueMap
=
211 pFactory
->getListValueMap(aIt
->second
.m_nRef
);
213 if (pListValueMap
.get() != NULL
)
215 OUString
aValue(Attribs
->getValue(aIt
->first
));
216 sal_uInt32 nValue
= (*pListValueMap
)[aValue
];
219 debug_logger
->attribute("value", aValue
);
220 debug_logger
->attribute("value-num", nValue
);
223 OOXMLFastHelper
<OOXMLIntegerValue
>::newProperty
224 (pHandler
, nId
, nValue
);
226 OOXMLValue::Pointer_t
pValue(new OOXMLIntegerValue(nValue
));
227 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
230 debug_logger
->endElement();
236 debug_logger
->element("unknown-attribute-type");
242 debug_logger
->endElement();
247 debug_logger
->endElement();
252 uno::Reference
< xml::sax::XFastContextHandler
>
253 OOXMLFactory::createFastChildContext(OOXMLFastContextHandler
* pHandler
,
257 debug_logger
->startElement("factory.createFastChildContext");
258 debug_logger
->attribute("token", fastTokenToId(Element
));
261 Id nDefine
= pHandler
->getDefine();
263 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
265 uno::Reference
< xml::sax::XFastContextHandler
> ret
;
267 //Avoid handling unknown tokens and recursing to death
268 if ((Element
& 0xffff) < OOXML_FAST_TOKENS_END
)
269 ret
= createFastChildContextFromFactory(pHandler
, pFactory
, Element
);
272 debug_logger
->endElement("factory.createFastChildContext");
278 void OOXMLFactory::characters(OOXMLFastContextHandler
* pHandler
,
279 const OUString
& rString
)
282 debug_logger
->startElement("factory.characters");
283 debug_logger
->chars(rString
);
286 Id nDefine
= pHandler
->getDefine();
287 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
289 if (pFactory
.get() != NULL
)
291 pFactory
->charactersAction(pHandler
, rString
);
295 debug_logger
->endElement("factory.characters");
299 void OOXMLFactory::startAction(OOXMLFastContextHandler
* pHandler
, Token_t
/*nToken*/)
301 Id nDefine
= pHandler
->getDefine();
302 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
304 if (pFactory
.get() != NULL
)
307 debug_logger
->startElement("factory.startAction");
309 pFactory
->startAction(pHandler
);
311 debug_logger
->endElement();
316 void OOXMLFactory::endAction(OOXMLFastContextHandler
* pHandler
, Token_t
/*nToken*/)
318 Id nDefine
= pHandler
->getDefine();
319 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
321 if (pFactory
.get() != NULL
)
324 debug_logger
->startElement("factory.endAction");
326 pFactory
->endAction(pHandler
);
328 debug_logger
->endElement();
333 void OOXMLFactory_ns::startAction(OOXMLFastContextHandler
*)
337 void OOXMLFactory_ns::endAction(OOXMLFastContextHandler
*)
341 void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler
*, const OUString
&)
345 void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler
*, Token_t
, OOXMLValue::Pointer_t
)
350 string
OOXMLFactory_ns::getName() const
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */