1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
23 #include <resourcemodel/QNameToString.hxx>
24 #include "OOXMLFastContextHandler.hxx"
25 #include "ooxmlLoggers.hxx"
26 namespace writerfilter
{
30 using namespace ::std
;
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::xml::sax
;
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
,
50 const OUString
& rValue
);
52 static void newProperty(OOXMLFastContextHandler
* pHandler
,
53 Id nId
, sal_Int32 nValue
);
55 static void mark(OOXMLFastContextHandler
* pHandler
,
57 const OUString
& rValue
);
59 static void attributes
60 (OOXMLFastContextHandler
* pContext
,
61 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
);
65 uno::Reference
<XFastContextHandler
>
66 OOXMLFastHelper
<T
>::createAndSetParent
67 (OOXMLFastContextHandler
* pHandler
, sal_uInt32 nToken
, Id nId
)
70 debug_logger
->startElement("helper.createAndSetParent");
71 debug_logger
->attribute("context", pHandler
->getType());
72 debug_logger
->attribute("id", (*QNameToString::Instance())(nId
));
75 OOXMLFastContextHandler
* pTmp
= new T(pHandler
);
77 pTmp
->setToken(nToken
);
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");
92 uno::Reference
<XFastContextHandler
> aResult(pTmp
);
98 uno::Reference
<XFastContextHandler
>
99 OOXMLFastHelper
<T
>::createAndSetParentAndDefine
100 (OOXMLFastContextHandler
* pHandler
, sal_uInt32 nToken
, Id nId
, Id nDefine
)
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
);
113 OOXMLFastContextHandler
* pTmp
= new T(pHandler
);
115 pTmp
->setToken(nToken
);
117 pTmp
->setDefine(nDefine
);
121 debug_logger
->startElement("created");
122 debug_logger
->addTag(pTmp
->toTag());
123 debug_logger
->endElement("created");
124 debug_logger
->endElement("helper.createAndSetParentAndDefine");
127 uno::Reference
<XFastContextHandler
> aResult(pTmp
);
133 uno::Reference
<XFastContextHandler
>
134 OOXMLFastHelper
<T
>::createAndSetParentRef
135 (OOXMLFastContextHandler
* pHandler
, sal_uInt32 nToken
,
136 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
139 debug_logger
->startElement("helper.createAndSetParentRef");
140 debug_logger
->attribute("context", pHandler
->getType());
141 debug_logger
->attribute("type", fastTokenToId(nToken
));
144 boost::shared_ptr
<OOXMLFastContextHandler
> pTmp(new T(pHandler
));
146 uno::Reference
<XFastContextHandler
> xChild
=
147 pTmp
->createFastChildContext(nToken
, Attribs
);
149 OOXMLFastContextHandler
* pResult
= NULL
;
152 pResult
= dynamic_cast<OOXMLFastContextHandler
*>(xChild
.get());
153 pResult
->setToken(nToken
);
154 pResult
->setParent(pHandler
);
159 debug_logger
->startElement("created");
160 debug_logger
->addTag(pTmp
->toTag());
161 debug_logger
->endElement("created");
162 debug_logger
->endElement("helper.createAndSetParentRef");
169 void OOXMLFastHelper
<T
>::newProperty(OOXMLFastContextHandler
* pHandler
,
171 const OUString
& rValue
)
173 OOXMLValue::Pointer_t
pVal(new T(rValue
));
176 string aStr
= (*QNameToString::Instance())(nId
);
178 debug_logger
->startElement("newProperty-from-string");
179 debug_logger
->attribute("name", aStr
);
180 debug_logger
->attribute
183 (rValue
, RTL_TEXTENCODING_ASCII_US
).getStr());
186 debug_logger
->element( "unknown-qname" );
189 pHandler
->newProperty(nId
, pVal
);
192 debug_logger
->endElement();
198 void OOXMLFastHelper
<T
>::newProperty(OOXMLFastContextHandler
* pHandler
,
202 OOXMLValue::Pointer_t
pVal(new T(nVal
));
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());
212 debug_logger
->element("unknown-qname");
214 debug_logger
->endElement();
217 pHandler
->newProperty(nId
, pVal
);
221 void OOXMLFastHelper
<T
>::mark(OOXMLFastContextHandler
* pHandler
,
223 const OUString
& rValue
)
225 OOXMLValue::Pointer_t
pVal(new T(rValue
));
228 string aStr
= (*QNameToString::Instance())(nId
);
230 debug_logger
->startElement("helper.mark");
231 debug_logger
->attribute("name", aStr
);
232 debug_logger
->attribute("value",
234 (rValue
, RTL_TEXTENCODING_ASCII_US
).getStr());
237 debug_logger
->element("unknown-qname");
239 debug_logger
->endElement();
242 pHandler
->mark(nId
, pVal
);
245 #endif // INCLUDED_FAST_HELPER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */