1 /*
2 * Copyright (C) 2004 William Lachance (william.lachance@sympatico.ca)
3 * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * For further information visit http://libwpd.sourceforge.net
20 *
21 */
22 #include "DocumentHandler.hxx"
23 #include "FilterInternal.hxx"
24
25 #include <string.h>
26 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28
29 #ifndef _ATTRLIST_HPP_
30 #include <xmloff/attrlist.hxx>
31 #endif
32
33 using namespace ::rtl;
34 using rtl::OUString;
35
36 using com::sun::star::xml::sax::XAttributeList;
37
DocumentHandler(Reference<XDocumentHandler> & xHandler)38 DocumentHandler::DocumentHandler(Reference < XDocumentHandler > &xHandler) :
39 mxHandler(xHandler)
40 {
41 }
42
startDocument()43 void DocumentHandler::startDocument()
44 {
45 WRITER_DEBUG_MSG(("DocumentHandler::startDocument"));
46 mxHandler->startDocument();
47 }
48
endDocument()49 void DocumentHandler::endDocument()
50 {
51 WRITER_DEBUG_MSG(("DocumentHandler::endDocument"));
52 mxHandler->endDocument();
53 }
54
startElement(const char * psName,const WPXPropertyList & xPropList)55 void DocumentHandler::startElement(const char *psName, const WPXPropertyList &xPropList)
56 {
57 WRITER_DEBUG_MSG(("DocumentHandler::startElement"));
58 SvXMLAttributeList *pAttrList = new SvXMLAttributeList();
59 Reference < XAttributeList > xAttrList(pAttrList);
60 WPXPropertyList::Iter i(xPropList);
61 for (i.rewind(); i.next(); )
62 {
63 // filter out libwpd elements
64 if (strlen(i.key()) > 6 && strncmp(i.key(), "libwpd", 6) != 0)
65 pAttrList->AddAttribute(OUString::createFromAscii(i.key()),
66 OUString::createFromAscii(i()->getStr().cstr()));
67 }
68
69 mxHandler->startElement(OUString::createFromAscii(psName), xAttrList);
70 }
71
endElement(const char * psName)72 void DocumentHandler::endElement(const char *psName)
73 {
74 WRITER_DEBUG_MSG(("DocumentHandler::endElement"));
75 mxHandler->endElement(OUString::createFromAscii(psName));
76 }
77
characters(const WPXString & sCharacters)78 void DocumentHandler::characters(const WPXString &sCharacters)
79 {
80 WRITER_DEBUG_MSG(("DocumentHandler::characters"));
81 OUString sCharU16(sCharacters.cstr(), strlen(sCharacters.cstr()), RTL_TEXTENCODING_UTF8);
82 mxHandler->characters(sCharU16);
83 }
84