nss: upgrade to release 3.73
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFactory.cxx
blob51d6ada11dab97d06e0981ca58c3d44c2a3c486d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sax/fastattribs.hxx>
21 #include "OOXMLFactory.hxx"
23 namespace writerfilter::ooxml {
25 using namespace com::sun::star;
28 OOXMLFactory_ns::~OOXMLFactory_ns()
33 void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
34 const uno::Reference< xml::sax::XFastAttributeList > & xAttribs)
36 Id nDefine = pHandler->getDefine();
37 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
39 if (!pFactory)
40 return;
42 sax_fastparser::FastAttributeList& rAttribs =
43 sax_fastparser::castToFastAttributeList( xAttribs );
45 const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
46 if (!pAttr)
47 return;
49 for (; pAttr->m_nToken != -1; ++pAttr)
51 sal_Int32 nToken = pAttr->m_nToken;
52 sal_Int32 nAttrIndex = rAttribs.getAttributeIndex(nToken);
53 if (nAttrIndex == -1)
54 continue;
56 Id nId = pFactory->getResourceId(nDefine, nToken);
58 switch (pAttr->m_nResource)
60 case ResourceType::Boolean:
62 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
63 OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue));
64 pHandler->newProperty(nId, xValue);
65 pFactory->attributeAction(pHandler, nToken, xValue);
67 break;
68 case ResourceType::String:
70 OUString aValue(rAttribs.getValueByIndex(nAttrIndex));
71 OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue));
72 pHandler->newProperty(nId, xValue);
73 pFactory->attributeAction(pHandler, nToken, xValue);
75 break;
76 case ResourceType::Integer:
78 sal_Int32 nValue = rAttribs.getAsIntegerByIndex(nAttrIndex);
79 OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
80 pHandler->newProperty(nId, xValue);
81 pFactory->attributeAction(pHandler, nToken, xValue);
83 break;
84 case ResourceType::Hex:
86 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
87 OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue));
88 pHandler->newProperty(nId, xValue);
89 pFactory->attributeAction(pHandler, nToken, xValue);
91 break;
92 case ResourceType::HexColor:
94 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
95 OOXMLValue::Pointer_t xValue(new OOXMLHexColorValue(pValue));
96 pHandler->newProperty(nId, xValue);
97 pFactory->attributeAction(pHandler, nToken, xValue);
99 break;
100 case ResourceType::TwipsMeasure_asSigned:
101 case ResourceType::TwipsMeasure_asZero:
103 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
104 OOXMLValue::Pointer_t xValue(new OOXMLTwipsMeasureValue(pValue));
105 if ( xValue->getInt() < 0 )
107 if ( pAttr->m_nResource == ResourceType::TwipsMeasure_asZero )
108 xValue = OOXMLIntegerValue::Create(0);
110 pHandler->newProperty(nId, xValue);
111 pFactory->attributeAction(pHandler, nToken, xValue);
113 break;
114 case ResourceType::HpsMeasure:
116 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
117 OOXMLValue::Pointer_t xValue(new OOXMLHpsMeasureValue(pValue));
118 pHandler->newProperty(nId, xValue);
119 pFactory->attributeAction(pHandler, nToken, xValue);
121 break;
122 case ResourceType::MeasurementOrPercent:
124 const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex);
125 OOXMLValue::Pointer_t xValue(new OOXMLMeasurementOrPercentValue(pValue));
126 pHandler->newProperty(nId, xValue);
127 pFactory->attributeAction(pHandler, nToken, xValue);
129 break;
130 case ResourceType::List:
132 sal_uInt32 nValue;
133 if (pFactory->getListValue(pAttr->m_nRef, rAttribs.getValueByIndex(nAttrIndex), nValue))
135 OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
136 pHandler->newProperty(nId, xValue);
137 pFactory->attributeAction(pHandler, nToken, xValue);
140 break;
141 default:
142 break;
147 uno::Reference< xml::sax::XFastContextHandler>
148 OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
149 Token_t Element)
151 Id nDefine = pHandler->getDefine();
153 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
155 uno::Reference< xml::sax::XFastContextHandler> ret;
157 //Avoid handling unknown tokens and recursing to death
158 if ((Element & 0xffff) < oox::XML_TOKEN_COUNT)
159 ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
161 return ret;
164 void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
165 const OUString & rString)
167 Id nDefine = pHandler->getDefine();
168 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
170 if (pFactory)
172 pFactory->charactersAction(pHandler, rString);
176 void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler)
178 Id nDefine = pHandler->getDefine();
179 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
181 if (pFactory)
183 pFactory->startAction(pHandler);
187 void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler)
189 Id nDefine = pHandler->getDefine();
190 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
192 if (pFactory)
194 pFactory->endAction(pHandler);
198 void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
202 void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
206 void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
210 void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue::Pointer_t&)
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */