Bump version to 4.3-4
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFastHelper.hxx
blob2f10ff7760aeb8abd2d6f043efe8d653fa59580c
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 .
19 #ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX
20 #define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX
22 #include <iostream>
23 #include <resourcemodel/QNameToString.hxx>
24 #include "OOXMLFastContextHandler.hxx"
25 #include "ooxmlLoggers.hxx"
26 namespace writerfilter {
28 namespace ooxml
31 template <class T>
32 class OOXMLFastHelper
34 public:
35 static css::uno::Reference<css::xml::sax::XFastContextHandler> createAndSetParent
36 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId);
38 static css::uno::Reference<css::xml::sax::XFastContextHandler> createAndSetParentAndDefine
39 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine);
41 static css::uno::Reference<css::xml::sax::XFastContextHandler> createAndSetParentRef
42 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
43 const css::uno::Reference < css::xml::sax::XFastAttributeList > & Attribs);
45 static void newProperty(OOXMLFastContextHandler * pHandler,
46 Id nId,
47 const OUString & rValue);
49 static void newProperty(OOXMLFastContextHandler * pHandler,
50 Id nId, sal_Int32 nValue);
52 static void attributes
53 (OOXMLFastContextHandler * pContext,
54 const css::uno::Reference < css::xml::sax::XFastAttributeList > & Attribs);
57 template <class T>
58 uno::Reference<css::xml::sax::XFastContextHandler>
59 OOXMLFastHelper<T>::createAndSetParent
60 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId)
62 #ifdef DEBUG_HELPER
63 debug_logger->startElement("helper.createAndSetParent");
64 debug_logger->attribute("context", pHandler->getType());
65 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
66 #endif
68 OOXMLFastContextHandler * pTmp = new T(pHandler);
70 pTmp->setToken(nToken);
71 pTmp->setId(nId);
73 #ifdef DEBUG_CREATE
74 debug_logger->startElement("createAndSetParent");
75 debug_logger->attribute("context", pHandler->getType());
76 debug_logger->attribute("token", fastTokenToId(pTmp->getToken()));
77 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
79 debug_logger->startElement("created");
80 debug_logger->addTag(pTmp->toTag());
81 debug_logger->endElement("created");
82 debug_logger->endElement("helper.createAndSetParent");
83 #endif
85 css::uno::Reference<css::xml::sax::XFastContextHandler> aResult(pTmp);
87 return aResult;
90 template <class T>
91 uno::Reference<css::xml::sax::XFastContextHandler>
92 OOXMLFastHelper<T>::createAndSetParentAndDefine
93 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine)
95 #ifdef DEBUG_HELPER
96 debug_logger->startElement("helper.createAndSetParentAndDefine");
97 debug_logger->attribute("context", pHandler->getType());
98 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
100 static char buffer[16];
101 snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIxUINT32, nId);
103 debug_logger->attribute("idnum", buffer);
104 #endif
106 OOXMLFastContextHandler * pTmp = new T(pHandler);
108 pTmp->setToken(nToken);
109 pTmp->setId(nId);
110 pTmp->setDefine(nDefine);
113 #ifdef DEBUG_HELPER
114 debug_logger->startElement("created");
115 debug_logger->addTag(pTmp->toTag());
116 debug_logger->endElement("created");
117 debug_logger->endElement("helper.createAndSetParentAndDefine");
118 #endif
120 css::uno::Reference<css::xml::sax::XFastContextHandler> aResult(pTmp);
122 return aResult;
125 template <class T>
126 uno::Reference<css::xml::sax::XFastContextHandler>
127 OOXMLFastHelper<T>::createAndSetParentRef
128 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
129 const css::uno::Reference < css::xml::sax::XFastAttributeList > & Attribs)
131 #ifdef DEBUG_HELPER
132 debug_logger->startElement("helper.createAndSetParentRef");
133 debug_logger->attribute("context", pHandler->getType());
134 debug_logger->attribute("type", fastTokenToId(nToken));
135 #endif
137 boost::shared_ptr<OOXMLFastContextHandler> pTmp(new T(pHandler));
139 css::uno::Reference<css::xml::sax::XFastContextHandler> xChild =
140 pTmp->createFastChildContext(nToken, Attribs);
142 if (xChild.is())
144 OOXMLFastContextHandler* pResult = dynamic_cast<OOXMLFastContextHandler *>(xChild.get());
145 pResult->setToken(nToken);
146 pResult->setParent(pHandler);
150 #ifdef DEBUG_HELPER
151 debug_logger->startElement("created");
152 debug_logger->addTag(pTmp->toTag());
153 debug_logger->endElement("created");
154 debug_logger->endElement("helper.createAndSetParentRef");
155 #endif
157 return xChild;
160 template <class T>
161 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
162 Id nId,
163 const OUString & rValue)
165 OOXMLValue::Pointer_t pVal(new T(rValue));
167 #ifdef DEBUG_HELPER
168 string aStr = (*QNameToString::Instance())(nId);
170 debug_logger->startElement("newProperty-from-string");
171 debug_logger->attribute("name", aStr);
172 debug_logger->attribute
173 ("value",
174 OUStringToOString
175 (rValue, RTL_TEXTENCODING_ASCII_US).getStr());
177 if (aStr.empty())
178 debug_logger->element( "unknown-qname" );
179 #endif
181 pHandler->newProperty(nId, pVal);
183 #ifdef DEBUG_HELPER
184 debug_logger->endElement();
185 #endif
189 template <class T>
190 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
191 Id nId,
192 sal_Int32 nVal)
194 OOXMLValue::Pointer_t pVal(new T(nVal));
196 #ifdef DEBUG_HELPER
197 string aStr = (*QNameToString::Instance())(nId);
199 debug_logger->startElement("helper.newProperty-from-int");
200 debug_logger->attribute("name", aStr);
201 debug_logger->attribute("value", pVal->toString());
203 if (aStr.empty())
204 debug_logger->element("unknown-qname");
206 debug_logger->endElement();
207 #endif
209 pHandler->newProperty(nId, pVal);
213 #endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */