update dev300-m58
[ooovba.git] / writerfilter / source / ooxml / OOXMLFastHelper.hxx
blobf6920a989028484aec88025e5f93cafc775fde23
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastHelper.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef INCLUDED_FAST_HELPER_HXX
31 #define INCLUDED_FAST_HELPER_HXX
33 #include <iostream>
34 #include <resourcemodel/QNameToString.hxx>
35 #include "OOXMLFastContextHandler.hxx"
36 #include "ooxmlLoggers.hxx"
37 namespace writerfilter {
39 namespace ooxml
41 using namespace ::std;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::xml::sax;
45 template <class T>
46 class OOXMLFastHelper
48 public:
49 static uno::Reference<XFastContextHandler> createAndSetParent
50 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId);
52 static uno::Reference<XFastContextHandler> createAndSetParentRef
53 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
54 const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
56 static void newProperty(OOXMLFastContextHandler * pHandler,
57 Id nId,
58 const ::rtl::OUString & rValue);
60 static void newProperty(OOXMLFastContextHandler * pHandler,
61 Id nId, sal_Int32 nValue);
63 static void mark(OOXMLFastContextHandler * pHandler,
64 Id nId,
65 const ::rtl::OUString & rValue);
67 static void attributes
68 (OOXMLFastContextHandler * pContext,
69 const uno::Reference < xml::sax::XFastAttributeList > & Attribs);
72 template <class T>
73 uno::Reference<XFastContextHandler>
74 OOXMLFastHelper<T>::createAndSetParent
75 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId)
77 OOXMLFastContextHandler * pTmp = new T(pHandler);
78 OOXMLFastContextHandler::RefAndPointer_t aResult(pTmp);
80 pTmp->setToken(nToken);
81 pTmp->setId(nId);
83 #ifdef DEBUG_CREATE
84 debug_logger->startElement("createAndSetParent");
85 debug_logger->attribute("context", pHandler->getType());
86 debug_logger->attribute("token", fastTokenToId(pTmp->getToken()));
87 debug_logger->attribute("id", (*QNameToString::Instance())(nId));
88 if (pTmp->isFallback())
89 debug_logger->attribute("fallback", "yes");
91 debug_logger->startElement("created");
92 debug_logger->addTag(pTmp->toTag());
93 debug_logger->endElement("created");
94 debug_logger->endElement("createAndSetParent");
95 #endif
97 return aResult;
100 template <class T>
101 uno::Reference<XFastContextHandler>
102 OOXMLFastHelper<T>::createAndSetParentRef
103 (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken,
104 const uno::Reference < xml::sax::XFastAttributeList > & Attribs)
106 boost::shared_ptr<OOXMLFastContextHandler> pTmp(new T(pHandler));
108 uno::Reference<XFastContextHandler> xChild =
109 pTmp->createFastChildContext(nToken, Attribs);
111 OOXMLFastContextHandler * pResult = NULL;
112 if (xChild.is())
114 pResult = dynamic_cast<OOXMLFastContextHandler *>(xChild.get());
115 pResult->setToken(nToken);
116 pResult->setParent(pHandler);
120 #ifdef DEBUG_CREATE
121 debug_logger->startElement("createAndSetParentRef");
122 debug_logger->attribute("context", pHandler->getType());
123 debug_logger->attribute("type", fastTokenToId(nToken));
125 if (pTmp->isFallback())
126 debug_logger->attribute("fallback", "yes");
128 debug_logger->startElement("created");
129 debug_logger->chars(pTmp->getType());
130 debug_logger->endElement("created");
131 debug_logger->endElement("createAndSetParentRef");
132 #endif
134 return xChild;
137 template <class T>
138 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
139 Id nId,
140 const ::rtl::OUString & rValue)
142 OOXMLValue::Pointer_t pVal(new T(rValue));
144 string aStr = (*QNameToString::Instance())(nId);
146 #ifdef DEBUG_PROPERTIES
147 debug_logger->startElement("newProperty");
148 debug_logger->attribute("name", aStr);
149 debug_logger->attribute
150 ("value",
151 ::rtl::OUStringToOString
152 (rValue, RTL_TEXTENCODING_ASCII_US).getStr());
154 if (aStr.size() == 0)
155 debug_logger->addTag(XMLTag::Pointer_t(new XMLTag("unknown-qname")));
157 debug_logger->endElement("newProperty");
158 #endif
160 pHandler->newProperty(nId, pVal);
163 template <class T>
164 void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler,
165 Id nId,
166 sal_Int32 nVal)
168 OOXMLValue::Pointer_t pVal(new T(nVal));
170 string aStr = (*QNameToString::Instance())(nId);
172 #ifdef DEBUG_PROPERTIES
173 debug_logger->startElement("newProperty");
174 debug_logger->attribute("name", aStr);
175 debug_logger->attribute("value", pVal->toString());
177 if (aStr.size() == 0)
178 debug_logger->addTag(XMLTag::Pointer_t(new XMLTag("unknown-qname")));
180 debug_logger->endElement("newProperty");
181 #endif
183 pHandler->newProperty(nId, pVal);
186 template <class T>
187 void OOXMLFastHelper<T>::mark(OOXMLFastContextHandler * pHandler,
188 Id nId,
189 const ::rtl::OUString & rValue)
191 OOXMLValue::Pointer_t pVal(new T(rValue));
193 string aStr = (*QNameToString::Instance())(nId);
195 #ifdef DEBUG_PROPERTIES
196 debug_logger->startElement("mark");
197 debug_logger->attribute("name", aStr);
198 debug_logger->attribute
199 ("value",
200 ::rtl::OUStringToOString
201 (rValue, RTL_TEXTENCODING_ASCII_US).getStr());
203 if (aStr.size() == 0)
204 debug_logger->addTag(XMLTag::Pointer_t(new XMLTag("unknown-qname")));
206 debug_logger->endElement("mark");
207 #endif
209 pHandler->mark(nId, pVal);
212 template <class T>
213 void OOXMLFastHelper<T>::attributes
214 (OOXMLFastContextHandler * pContext,
215 const uno::Reference < xml::sax::XFastAttributeList > & Attribs)
217 T aContext(pContext);
219 aContext.setPropertySet(pContext->getPropertySet());
220 aContext.attributes(Attribs);
224 #endif // INCLUDED_FAST_HELPER_HXX