android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFactory.cxx
blobb11cf07c29000de43f5db6fffaa879685713cd97
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 OOXMLValue::Pointer_t xValue;
59 switch (pAttr->m_nResource)
61 case ResourceType::Boolean:
62 xValue = OOXMLBooleanValue::Create(rAttribs.getAsViewByIndex(nAttrIndex));
63 break;
64 case ResourceType::String:
65 xValue = new OOXMLStringValue(rAttribs.getValueByIndex(nAttrIndex));
66 break;
67 case ResourceType::Integer:
68 xValue = OOXMLIntegerValue::Create(rAttribs.getAsIntegerByIndex(nAttrIndex));
69 break;
70 case ResourceType::Hex:
71 xValue = new OOXMLHexValue(rAttribs.getAsViewByIndex(nAttrIndex));
72 break;
73 case ResourceType::HexColor:
74 xValue = new OOXMLHexColorValue(rAttribs.getAsViewByIndex(nAttrIndex));
75 break;
76 case ResourceType::TwipsMeasure_asSigned:
77 case ResourceType::TwipsMeasure_asZero:
78 xValue = new OOXMLTwipsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex));
79 if (xValue->getInt() < 0)
81 if (pAttr->m_nResource == ResourceType::TwipsMeasure_asZero)
82 xValue = OOXMLIntegerValue::Create(0);
84 break;
85 case ResourceType::HpsMeasure:
86 xValue = new OOXMLHpsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex));
87 break;
88 case ResourceType::MeasurementOrPercent:
89 xValue = new OOXMLMeasurementOrPercentValue(rAttribs.getAsViewByIndex(nAttrIndex));
90 break;
91 case ResourceType::List:
92 if (sal_uInt32 nValue;
93 pFactory->getListValue(pAttr->m_nRef, rAttribs.getAsViewByIndex(nAttrIndex), nValue))
95 xValue = OOXMLIntegerValue::Create(nValue);
97 break;
98 default:
99 break;
102 if (xValue)
104 pHandler->newProperty(nId, xValue);
105 pFactory->attributeAction(pHandler, nToken, xValue);
110 uno::Reference< xml::sax::XFastContextHandler>
111 OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
112 Token_t Element)
114 Id nDefine = pHandler->getDefine();
116 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
118 uno::Reference< xml::sax::XFastContextHandler> ret;
120 //Avoid handling unknown tokens and recursing to death
121 if ((Element & 0xffff) < oox::XML_TOKEN_COUNT)
122 ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
124 return ret;
127 void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
128 const OUString & rString)
130 Id nDefine = pHandler->getDefine();
131 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
133 if (pFactory)
135 pFactory->charactersAction(pHandler, rString);
139 void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler)
141 Id nDefine = pHandler->getDefine();
142 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
144 if (pFactory)
146 pFactory->startAction(pHandler);
150 void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler)
152 Id nDefine = pHandler->getDefine();
153 OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
155 if (pFactory)
157 pFactory->endAction(pHandler);
161 void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
165 void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
169 void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
173 void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue::Pointer_t&)
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */