Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_FAST_HELPER_HXX
20 : #define INCLUDED_FAST_HELPER_HXX
21 :
22 : #include <iostream>
23 : #include <resourcemodel/QNameToString.hxx>
24 : #include "OOXMLFastContextHandler.hxx"
25 : #include "ooxmlLoggers.hxx"
26 : namespace writerfilter {
27 :
28 : namespace ooxml
29 : {
30 : using namespace ::std;
31 : using namespace ::com::sun::star;
32 : using namespace ::com::sun::star::xml::sax;
33 :
34 : template <class T>
35 : class OOXMLFastHelper
36 : {
37 : public:
38 : static uno::Reference<XFastContextHandler> createAndSetParent
39 : (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId);
40 :
41 : static uno::Reference<XFastContextHandler> createAndSetParentAndDefine
42 : (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine);
43 :
44 : static uno::Reference<XFastContextHandler> createAndSetParentRef
45 : (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
46 : const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
47 :
48 : static void newProperty(OOXMLFastContextHandler * pHandler,
49 : Id nId,
50 : const OUString & rValue);
51 :
52 : static void newProperty(OOXMLFastContextHandler * pHandler,
53 : Id nId, sal_Int32 nValue);
54 :
55 : static void mark(OOXMLFastContextHandler * pHandler,
56 : Id nId,
57 : const OUString & rValue);
58 :
59 : static void attributes
60 : (OOXMLFastContextHandler * pContext,
61 : const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
62 : };
63 :
64 : template <class T>
65 : uno::Reference<XFastContextHandler>
66 : OOXMLFastHelper<T>::createAndSetParent
67 : (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId)
68 : {
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
74 :
75 : OOXMLFastContextHandler * pTmp = new T(pHandler);
76 :
77 : pTmp->setToken(nToken);
78 : pTmp->setId(nId);
79 :
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));
85 :
86 : debug_logger->startElement("created");
87 : debug_logger->addTag(pTmp->toTag());
88 : debug_logger->endElement("created");
89 : debug_logger->endElement("helper.createAndSetParent");
90 : #endif
91 :
92 : uno::Reference<XFastContextHandler> aResult(pTmp);
93 :
94 : return aResult;
95 : }
96 :
97 : template <class T>
98 : uno::Reference<XFastContextHandler>
99 26005 : OOXMLFastHelper<T>::createAndSetParentAndDefine
100 : (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine)
101 : {
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));
106 :
107 : static char buffer[16];
108 : snprintf(buffer, sizeof(buffer), "0x%08" SAL_PRIxUINT32, nId);
109 :
110 : debug_logger->attribute("idnum", buffer);
111 : #endif
112 :
113 26005 : OOXMLFastContextHandler * pTmp = new T(pHandler);
114 :
115 26005 : pTmp->setToken(nToken);
116 26005 : pTmp->setId(nId);
117 26005 : pTmp->setDefine(nDefine);
118 :
119 :
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
126 :
127 26005 : uno::Reference<XFastContextHandler> aResult(pTmp);
128 :
129 26005 : return aResult;
130 : }
131 :
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)
137 : {
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
143 :
144 : boost::shared_ptr<OOXMLFastContextHandler> pTmp(new T(pHandler));
145 :
146 : uno::Reference<XFastContextHandler> xChild =
147 : pTmp->createFastChildContext(nToken, Attribs);
148 :
149 : OOXMLFastContextHandler * pResult = NULL;
150 : if (xChild.is())
151 : {
152 : pResult = dynamic_cast<OOXMLFastContextHandler *>(xChild.get());
153 : pResult->setToken(nToken);
154 : pResult->setParent(pHandler);
155 : }
156 :
157 :
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
164 :
165 : return xChild;
166 : }
167 :
168 : template <class T>
169 21259 : void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
170 : Id nId,
171 : const OUString & rValue)
172 : {
173 21259 : OOXMLValue::Pointer_t pVal(new T(rValue));
174 :
175 : #ifdef DEBUG_HELPER
176 : string aStr = (*QNameToString::Instance())(nId);
177 :
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());
184 :
185 : if (aStr.empty())
186 : debug_logger->element( "unknown-qname" );
187 : #endif
188 :
189 21259 : pHandler->newProperty(nId, pVal);
190 :
191 : #ifdef DEBUG_HELPER
192 : debug_logger->endElement();
193 : #endif
194 :
195 21259 : }
196 :
197 : template <class T>
198 5455 : void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
199 : Id nId,
200 : sal_Int32 nVal)
201 : {
202 5455 : OOXMLValue::Pointer_t pVal(new T(nVal));
203 :
204 : #ifdef DEBUG_HELPER
205 : string aStr = (*QNameToString::Instance())(nId);
206 :
207 : debug_logger->startElement("helper.newProperty-from-int");
208 : debug_logger->attribute("name", aStr);
209 : debug_logger->attribute("value", pVal->toString());
210 :
211 : if (aStr.empty())
212 : debug_logger->element("unknown-qname");
213 :
214 : debug_logger->endElement();
215 : #endif
216 :
217 5455 : pHandler->newProperty(nId, pVal);
218 5455 : }
219 :
220 : template <class T>
221 2 : void OOXMLFastHelper<T>::mark(OOXMLFastContextHandler * pHandler,
222 : Id nId,
223 : const OUString & rValue)
224 : {
225 2 : OOXMLValue::Pointer_t pVal(new T(rValue));
226 :
227 : #ifdef DEBUG_HELPER
228 : string aStr = (*QNameToString::Instance())(nId);
229 :
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());
235 :
236 : if (aStr.empty())
237 : debug_logger->element("unknown-qname");
238 :
239 : debug_logger->endElement();
240 : #endif
241 :
242 2 : pHandler->mark(nId, pVal);
243 2 : }
244 : }}
245 : #endif // INCLUDED_FAST_HELPER_HXX
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|