Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 : *
7 : * For further information visit http://libwpd.sourceforge.net
8 : */
9 : #include "DocumentHandler.hxx"
10 : #include "FilterInternal.hxx"
11 :
12 : #include <string.h>
13 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
14 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
15 :
16 : #include <xmloff/attrlist.hxx>
17 :
18 : // #define DEBUG_XML 1
19 :
20 : using namespace ::rtl;
21 : using rtl::OUString;
22 :
23 : using com::sun::star::xml::sax::XAttributeList;
24 :
25 0 : DocumentHandler::DocumentHandler(Reference < XDocumentHandler > &xHandler) :
26 0 : mxHandler(xHandler)
27 : {
28 0 : }
29 :
30 0 : void DocumentHandler::startDocument()
31 : {
32 0 : mxHandler->startDocument();
33 0 : }
34 :
35 0 : void DocumentHandler::endDocument()
36 : {
37 0 : mxHandler->endDocument();
38 0 : }
39 :
40 0 : void DocumentHandler::startElement(const char *psName, const WPXPropertyList &xPropList)
41 : {
42 : #ifdef DEBUG_XML
43 : printf("<%s", psName);
44 : #endif
45 0 : SvXMLAttributeList *pAttrList = new SvXMLAttributeList();
46 0 : Reference < XAttributeList > xAttrList(pAttrList);
47 0 : WPXPropertyList::Iter i(xPropList);
48 0 : for (i.rewind(); i.next(); )
49 : {
50 : // filter out libwpd elements
51 0 : if (strncmp(i.key(), "libwpd", 6) != 0)
52 : {
53 : pAttrList->AddAttribute(OUString::createFromAscii(i.key()),
54 0 : OUString::createFromAscii(i()->getStr().cstr()));
55 : #ifdef DEBUG_XML
56 : printf(" %s=\"%s\"", i.key(), i()->getStr().cstr());
57 : #endif
58 : }
59 : }
60 : #ifdef DEBUG_XML
61 : printf(">");
62 : #endif
63 :
64 0 : mxHandler->startElement(OUString::createFromAscii(psName), xAttrList);
65 0 : }
66 :
67 0 : void DocumentHandler::endElement(const char *psName)
68 : {
69 : #ifdef DEBUG_XML
70 : printf("</%s>", psName);
71 : #endif
72 0 : mxHandler->endElement(OUString::createFromAscii(psName));
73 0 : }
74 :
75 0 : void DocumentHandler::characters(const WPXString &sCharacters)
76 : {
77 0 : OUString sCharU16(sCharacters.cstr(), strlen(sCharacters.cstr()), RTL_TEXTENCODING_UTF8);
78 : #ifdef DEBUG_XML
79 : WPXString sEscapedCharacters(sCharacters, true);
80 : printf("%s", sEscapedCharacters.cstr());
81 : #endif
82 0 : mxHandler->characters(sCharU16);
83 0 : }
84 :
85 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|