bump product version to 4.1.6.2
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFastHelper.hxx
blob8863bde8a326242278796d759e542b6963bcc6f0
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_FAST_HELPER_HXX
20 #define INCLUDED_FAST_HELPER_HXX
22 #include <iostream>
23 #include <resourcemodel/QNameToString.hxx>
24 #include "OOXMLFastContextHandler.hxx"
25 #include "ooxmlLoggers.hxx"
26 namespace writerfilter {
28 namespace ooxml
30 using namespace ::std;
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::xml::sax;
34 template <class T>
35 class OOXMLFastHelper
37 public:
38 static uno::Reference<XFastContextHandler> createAndSetParent
39 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId);
41 static uno::Reference<XFastContextHandler> createAndSetParentAndDefine
42 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine);
44 static uno::Reference<XFastContextHandler> createAndSetParentRef
45 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
46 const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
48 static void newProperty(OOXMLFastContextHandler * pHandler,
49 Id nId,
50 const OUString & rValue);
52 static void newProperty(OOXMLFastContextHandler * pHandler,
53 Id nId, sal_Int32 nValue);
55 static void mark(OOXMLFastContextHandler * pHandler,
56 Id nId,
57 const OUString & rValue);
59 static void attributes
60 (OOXMLFastContextHandler * pContext,
61 const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
64 template <class T>
65 uno::Reference<XFastContextHandler>
66 OOXMLFastHelper<T>::createAndSetParent
67 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId)
69 #ifdef DEBUG_HELPER
70 debug_logger->startElement("helper.createAndSetParent");
71 debug_logger->attribute("context", pHandler->getType());
72 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
73 #endif
75 OOXMLFastContextHandler * pTmp = new T(pHandler);
77 pTmp->setToken(nToken);
78 pTmp->setId(nId);
80 #ifdef DEBUG_CREATE
81 debug_logger->startElement("createAndSetParent");
82 debug_logger->attribute("context", pHandler->getType());
83 debug_logger->attribute("token", fastTokenToId(pTmp->getToken()));
84 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
86 debug_logger->startElement("created");
87 debug_logger->addTag(pTmp->toTag());
88 debug_logger->endElement("created");
89 debug_logger->endElement("helper.createAndSetParent");
90 #endif
92 uno::Reference<XFastContextHandler> aResult(pTmp);
94 return aResult;
97 template <class T>
98 uno::Reference<XFastContextHandler>
99 OOXMLFastHelper<T>::createAndSetParentAndDefine
100 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine)
102 #ifdef DEBUG_HELPER
103 debug_logger->startElement("helper.createAndSetParentAndDefine");
104 debug_logger->attribute("context", pHandler->getType());
105 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
107 static char buffer[16];
108 snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIxUINT32, nId);
110 debug_logger->attribute("idnum", buffer);
111 #endif
113 OOXMLFastContextHandler * pTmp = new T(pHandler);
115 pTmp->setToken(nToken);
116 pTmp->setId(nId);
117 pTmp->setDefine(nDefine);
120 #ifdef DEBUG_HELPER
121 debug_logger->startElement("created");
122 debug_logger->addTag(pTmp->toTag());
123 debug_logger->endElement("created");
124 debug_logger->endElement("helper.createAndSetParentAndDefine");
125 #endif
127 uno::Reference<XFastContextHandler> aResult(pTmp);
129 return aResult;
132 template <class T>
133 uno::Reference<XFastContextHandler>
134 OOXMLFastHelper<T>::createAndSetParentRef
135 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
136 const uno::Reference < xml::sax::XFastAttributeList > & Attribs)
138 #ifdef DEBUG_HELPER
139 debug_logger->startElement("helper.createAndSetParentRef");
140 debug_logger->attribute("context", pHandler->getType());
141 debug_logger->attribute("type", fastTokenToId(nToken));
142 #endif
144 boost::shared_ptr<OOXMLFastContextHandler> pTmp(new T(pHandler));
146 uno::Reference<XFastContextHandler> xChild =
147 pTmp->createFastChildContext(nToken, Attribs);
149 OOXMLFastContextHandler * pResult = NULL;
150 if (xChild.is())
152 pResult = dynamic_cast<OOXMLFastContextHandler *>(xChild.get());
153 pResult->setToken(nToken);
154 pResult->setParent(pHandler);
158 #ifdef DEBUG_HELPER
159 debug_logger->startElement("created");
160 debug_logger->addTag(pTmp->toTag());
161 debug_logger->endElement("created");
162 debug_logger->endElement("helper.createAndSetParentRef");
163 #endif
165 return xChild;
168 template <class T>
169 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
170 Id nId,
171 const OUString & rValue)
173 OOXMLValue::Pointer_t pVal(new T(rValue));
175 #ifdef DEBUG_HELPER
176 string aStr = (*QNameToString::Instance())(nId);
178 debug_logger->startElement("newProperty-from-string");
179 debug_logger->attribute("name", aStr);
180 debug_logger->attribute
181 ("value",
182 OUStringToOString
183 (rValue, RTL_TEXTENCODING_ASCII_US).getStr());
185 if (aStr.empty())
186 debug_logger->element( "unknown-qname" );
187 #endif
189 pHandler->newProperty(nId, pVal);
191 #ifdef DEBUG_HELPER
192 debug_logger->endElement();
193 #endif
197 template <class T>
198 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
199 Id nId,
200 sal_Int32 nVal)
202 OOXMLValue::Pointer_t pVal(new T(nVal));
204 #ifdef DEBUG_HELPER
205 string aStr = (*QNameToString::Instance())(nId);
207 debug_logger->startElement("helper.newProperty-from-int");
208 debug_logger->attribute("name", aStr);
209 debug_logger->attribute("value", pVal->toString());
211 if (aStr.empty())
212 debug_logger->element("unknown-qname");
214 debug_logger->endElement();
215 #endif
217 pHandler->newProperty(nId, pVal);
220 template <class T>
221 void OOXMLFastHelper<T>::mark(OOXMLFastContextHandler * pHandler,
222 Id nId,
223 const OUString & rValue)
225 OOXMLValue::Pointer_t pVal(new T(rValue));
227 #ifdef DEBUG_HELPER
228 string aStr = (*QNameToString::Instance())(nId);
230 debug_logger->startElement("helper.mark");
231 debug_logger->attribute("name", aStr);
232 debug_logger->attribute("value",
233 OUStringToOString
234 (rValue, RTL_TEXTENCODING_ASCII_US).getStr());
236 if (aStr.empty())
237 debug_logger->element("unknown-qname");
239 debug_logger->endElement();
240 #endif
242 pHandler->mark(nId, pVal);
245 #endif // INCLUDED_FAST_HELPER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */