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
];
89 string
OOXMLFactory_ns::getDefineName(Id
/*nId*/) const
97 typedef rtl::Static
< osl::Mutex
, OOXMLFactory
> OOXMLFactory_Mutex
;
99 OOXMLFactory::Pointer_t
OOXMLFactory::m_Instance
;
101 OOXMLFactory::OOXMLFactory()
103 // multi-thread-safe mutex for all platforms
105 osl::MutexGuard
aGuard(OOXMLFactory_Mutex::get());
108 OOXMLFactory::~OOXMLFactory()
112 OOXMLFactory::Pointer_t
OOXMLFactory::getInstance()
114 if (m_Instance
.get() == NULL
)
115 m_Instance
.reset(new OOXMLFactory());
120 void OOXMLFactory::attributes(OOXMLFastContextHandler
* pHandler
,
121 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
123 Id nDefine
= pHandler
->getDefine();
124 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
126 if (pFactory
.get() != NULL
)
129 debug_logger
->startElement("factory.attributes");
130 debug_logger
->attribute("define", pFactory
->getDefineName(nDefine
));
132 snprintf(sBuffer
, sizeof(sBuffer
), "%08" SAL_PRIxUINT32
, nDefine
);
133 debug_logger
->attribute("define-num", sBuffer
);
136 TokenToIdMapPointer pTokenToIdMap
= pFactory
->getTokenToIdMap(nDefine
);
137 AttributeToResourceMapPointer pMap
= pFactory
->getAttributeToResourceMap(nDefine
);
139 AttributeToResourceMap::const_iterator aIt
;
140 AttributeToResourceMap::const_iterator aEndIt
= pMap
->end();
142 for (aIt
= pMap
->begin(); aIt
!= aEndIt
; ++aIt
)
144 Id nId
= (*pTokenToIdMap
)[aIt
->first
];
146 debug_logger
->startElement("factory.attribute");
147 debug_logger
->attribute("name", fastTokenToId(aIt
->first
));
148 debug_logger
->attribute("tokenid", (*QNameToString::Instance())(nId
));
149 snprintf(sBuffer
, sizeof(sBuffer
), "%08" SAL_PRIxUINT32
, nId
);
150 debug_logger
->attribute("tokenid-num", sBuffer
);
152 if (Attribs
->hasAttribute(aIt
->first
))
154 switch (aIt
->second
.m_nResource
)
159 debug_logger
->element("boolean");
161 OUString
aValue(Attribs
->getValue(aIt
->first
));
162 OOXMLFastHelper
<OOXMLBooleanValue
>::newProperty(pHandler
, nId
, aValue
);
164 OOXMLValue::Pointer_t
pValue(new OOXMLBooleanValue(aValue
));
165 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
171 debug_logger
->element("string");
173 OUString
aValue(Attribs
->getValue(aIt
->first
));
174 OOXMLFastHelper
<OOXMLStringValue
>::newProperty
175 (pHandler
, nId
, aValue
);
177 OOXMLValue::Pointer_t
pValue(new OOXMLStringValue(aValue
));
178 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
184 debug_logger
->element("integer");
186 OUString
aValue(Attribs
->getValue(aIt
->first
));
187 OOXMLFastHelper
<OOXMLIntegerValue
>::newProperty
188 (pHandler
, nId
, aValue
);
190 OOXMLValue::Pointer_t
pValue(new OOXMLIntegerValue(aValue
));
191 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
197 debug_logger
->element("hex");
199 OUString
aValue(Attribs
->getValue(aIt
->first
));
200 OOXMLFastHelper
<OOXMLHexValue
>::newProperty
201 (pHandler
, nId
, aValue
);
203 OOXMLValue::Pointer_t
pValue(new OOXMLHexValue(aValue
));
204 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
207 case RT_UniversalMeasure
:
210 debug_logger
->element("universalMeasure");
212 OUString
aValue(Attribs
->getValue(aIt
->first
));
213 OOXMLFastHelper
<OOXMLUniversalMeasureValue
>::newProperty(pHandler
, nId
, aValue
);
215 OOXMLValue::Pointer_t
pValue(new OOXMLUniversalMeasureValue(aValue
));
216 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
222 debug_logger
->startElement("list");
224 ListValueMapPointer pListValueMap
=
225 pFactory
->getListValueMap(aIt
->second
.m_nRef
);
227 if (pListValueMap
.get() != NULL
)
229 OUString
aValue(Attribs
->getValue(aIt
->first
));
230 sal_uInt32 nValue
= (*pListValueMap
)[aValue
];
233 debug_logger
->attribute("value", aValue
);
234 debug_logger
->attribute("value-num", nValue
);
237 OOXMLFastHelper
<OOXMLIntegerValue
>::newProperty
238 (pHandler
, nId
, nValue
);
240 OOXMLValue::Pointer_t
pValue(new OOXMLIntegerValue(nValue
));
241 pFactory
->attributeAction(pHandler
, aIt
->first
, pValue
);
244 debug_logger
->endElement();
250 debug_logger
->element("unknown-attribute-type");
256 debug_logger
->endElement();
261 debug_logger
->endElement();
266 uno::Reference
< xml::sax::XFastContextHandler
>
267 OOXMLFactory::createFastChildContext(OOXMLFastContextHandler
* pHandler
,
271 debug_logger
->startElement("factory.createFastChildContext");
272 debug_logger
->attribute("token", fastTokenToId(Element
));
275 Id nDefine
= pHandler
->getDefine();
277 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
279 uno::Reference
< xml::sax::XFastContextHandler
> ret
;
281 //Avoid handling unknown tokens and recursing to death
282 if ((Element
& 0xffff) < OOXML_FAST_TOKENS_END
)
283 ret
= createFastChildContextFromFactory(pHandler
, pFactory
, Element
);
286 debug_logger
->endElement();
292 void OOXMLFactory::characters(OOXMLFastContextHandler
* pHandler
,
293 const OUString
& rString
)
296 debug_logger
->startElement("factory.characters");
297 debug_logger
->chars(rString
);
300 Id nDefine
= pHandler
->getDefine();
301 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
303 if (pFactory
.get() != NULL
)
305 pFactory
->charactersAction(pHandler
, rString
);
309 debug_logger
->endElement();
313 void OOXMLFactory::startAction(OOXMLFastContextHandler
* pHandler
, Token_t
/*nToken*/)
315 Id nDefine
= pHandler
->getDefine();
316 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
318 if (pFactory
.get() != NULL
)
321 debug_logger
->startElement("factory.startAction");
323 pFactory
->startAction(pHandler
);
325 debug_logger
->endElement();
330 void OOXMLFactory::endAction(OOXMLFastContextHandler
* pHandler
, Token_t
/*nToken*/)
332 Id nDefine
= pHandler
->getDefine();
333 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
335 if (pFactory
.get() != NULL
)
338 debug_logger
->startElement("factory.endAction");
340 pFactory
->endAction(pHandler
);
342 debug_logger
->endElement();
347 void OOXMLFactory_ns::startAction(OOXMLFastContextHandler
*)
351 void OOXMLFactory_ns::endAction(OOXMLFastContextHandler
*)
355 void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler
*, const OUString
&)
359 void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler
*, Token_t
, OOXMLValue::Pointer_t
)
364 string
OOXMLFactory_ns::getName() const
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */