1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastHelper.hxx,v $
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
34 #include <resourcemodel/QNameToString.hxx>
35 #include "OOXMLFastContextHandler.hxx"
36 #include "ooxmlLoggers.hxx"
37 namespace writerfilter
{
41 using namespace ::std
;
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::xml::sax
;
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
,
58 const ::rtl::OUString
& rValue
);
60 static void newProperty(OOXMLFastContextHandler
* pHandler
,
61 Id nId
, sal_Int32 nValue
);
63 static void mark(OOXMLFastContextHandler
* pHandler
,
65 const ::rtl::OUString
& rValue
);
67 static void attributes
68 (OOXMLFastContextHandler
* pContext
,
69 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
);
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
);
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");
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
;
114 pResult
= dynamic_cast<OOXMLFastContextHandler
*>(xChild
.get());
115 pResult
->setToken(nToken
);
116 pResult
->setParent(pHandler
);
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");
138 void OOXMLFastHelper
<T
>::newProperty(OOXMLFastContextHandler
* pHandler
,
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
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");
160 pHandler
->newProperty(nId
, pVal
);
164 void OOXMLFastHelper
<T
>::newProperty(OOXMLFastContextHandler
* pHandler
,
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");
183 pHandler
->newProperty(nId
, pVal
);
187 void OOXMLFastHelper
<T
>::mark(OOXMLFastContextHandler
* pHandler
,
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
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");
209 pHandler
->mark(nId
, pVal
);
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