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 .
20 #include <rtl/instance.hxx>
21 #include <sax/fastattribs.hxx>
22 #include "OOXMLFactory.hxx"
23 #include "OOXMLFastHelper.hxx"
25 namespace writerfilter
{
28 using namespace com::sun::star
;
30 // class OOXMLFactory_ns
32 OOXMLFactory_ns::~OOXMLFactory_ns()
38 void OOXMLFactory::attributes(OOXMLFastContextHandler
* pHandler
,
39 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttribs
)
41 Id nDefine
= pHandler
->getDefine();
42 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
44 if (pFactory
.get() == nullptr)
47 sax_fastparser::FastAttributeList
*pAttribs
=
48 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttribs
);
50 const AttributeInfo
*pAttr
= pFactory
->getAttributeInfoArray(nDefine
);
54 for (; pAttr
->m_nToken
!= -1; ++pAttr
)
56 sal_Int32 nToken
= pAttr
->m_nToken
;
57 sal_Int32 nAttrIndex
= pAttribs
->getAttributeIndex(nToken
);
61 Id nId
= pFactory
->getResourceId(nDefine
, nToken
);
63 switch (pAttr
->m_nResource
)
65 case ResourceType::Boolean
:
67 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
68 OOXMLValue::Pointer_t
xValue(OOXMLBooleanValue::Create(pValue
));
69 pHandler
->newProperty(nId
, xValue
);
70 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
73 case ResourceType::String
:
75 OUString
aValue(pAttribs
->getValueByIndex(nAttrIndex
));
76 OOXMLValue::Pointer_t
xValue(new OOXMLStringValue(aValue
));
77 pHandler
->newProperty(nId
, xValue
);
78 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
81 case ResourceType::Integer
:
83 sal_Int32 nValue
= pAttribs
->getAsIntegerByIndex(nAttrIndex
);
84 OOXMLValue::Pointer_t xValue
= OOXMLIntegerValue::Create(nValue
);
85 pHandler
->newProperty(nId
, xValue
);
86 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
89 case ResourceType::Hex
:
91 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
92 OOXMLValue::Pointer_t
xValue(new OOXMLHexValue(pValue
));
93 pHandler
->newProperty(nId
, xValue
);
94 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
97 case ResourceType::HexColor
:
99 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
100 OOXMLValue::Pointer_t
xValue(new OOXMLHexColorValue(pValue
));
101 pHandler
->newProperty(nId
, xValue
);
102 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
105 case ResourceType::TwipsMeasure_asSigned
:
106 case ResourceType::TwipsMeasure_asZero
:
108 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
109 OOXMLValue::Pointer_t
xValue(new OOXMLTwipsMeasureValue(pValue
));
110 if ( xValue
->getInt() < 0 )
112 if ( pAttr
->m_nResource
== ResourceType::TwipsMeasure_asZero
)
113 xValue
= OOXMLIntegerValue::Create(0);
115 pHandler
->newProperty(nId
, xValue
);
116 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
119 case ResourceType::HpsMeasure
:
121 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
122 OOXMLValue::Pointer_t
xValue(new OOXMLHpsMeasureValue(pValue
));
123 pHandler
->newProperty(nId
, xValue
);
124 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
127 case ResourceType::MeasurementOrPercent
:
129 const char *pValue
= pAttribs
->getAsCharByIndex(nAttrIndex
);
130 OOXMLValue::Pointer_t
xValue(new OOXMLMeasurementOrPercentValue(pValue
));
131 pHandler
->newProperty(nId
, xValue
);
132 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
135 case ResourceType::List
:
138 if (pFactory
->getListValue(pAttr
->m_nRef
, pAttribs
->getValueByIndex(nAttrIndex
), nValue
))
140 OOXMLValue::Pointer_t xValue
= OOXMLIntegerValue::Create(nValue
);
141 pHandler
->newProperty(nId
, xValue
);
142 pFactory
->attributeAction(pHandler
, nToken
, xValue
);
152 uno::Reference
< xml::sax::XFastContextHandler
>
153 OOXMLFactory::createFastChildContext(OOXMLFastContextHandler
* pHandler
,
156 Id nDefine
= pHandler
->getDefine();
158 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
160 uno::Reference
< xml::sax::XFastContextHandler
> ret
;
162 //Avoid handling unknown tokens and recursing to death
163 if ((Element
& 0xffff) < oox::XML_TOKEN_COUNT
)
164 ret
= createFastChildContextFromFactory(pHandler
, pFactory
, Element
);
169 void OOXMLFactory::characters(OOXMLFastContextHandler
* pHandler
,
170 const OUString
& rString
)
172 Id nDefine
= pHandler
->getDefine();
173 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
175 if (pFactory
.get() != nullptr)
177 pFactory
->charactersAction(pHandler
, rString
);
181 void OOXMLFactory::startAction(OOXMLFastContextHandler
* pHandler
)
183 Id nDefine
= pHandler
->getDefine();
184 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
186 if (pFactory
.get() != nullptr)
188 pFactory
->startAction(pHandler
);
192 void OOXMLFactory::endAction(OOXMLFastContextHandler
* pHandler
)
194 Id nDefine
= pHandler
->getDefine();
195 OOXMLFactory_ns::Pointer_t pFactory
= getFactoryForNamespace(nDefine
);
197 if (pFactory
.get() != nullptr)
199 pFactory
->endAction(pHandler
);
203 void OOXMLFactory_ns::startAction(OOXMLFastContextHandler
*)
207 void OOXMLFactory_ns::endAction(OOXMLFastContextHandler
*)
211 void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler
*, const OUString
&)
215 void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler
*, Token_t
, const OOXMLValue::Pointer_t
&)
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */