Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "xmlbasici.hxx"
30 : : #include <xmloff/attrlist.hxx>
31 : : #include <xmloff/nmspmap.hxx>
32 : : #include <xmloff/xmlimp.hxx>
33 : :
34 : : using namespace ::com::sun::star;
35 : : using namespace ::com::sun::star::uno;
36 : :
37 : :
38 : : // =============================================================================
39 : : // XMLBasicImportContext
40 : : // =============================================================================
41 : :
42 : 0 : XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
43 : : const Reference< frame::XModel >& rxModel )
44 : : :SvXMLImportContext( rImport, nPrfx, rLName )
45 : 0 : ,m_xModel( rxModel )
46 : : {
47 [ # # ]: 0 : Reference< lang::XMultiServiceFactory > xMSF = GetImport().getServiceFactory();
48 [ # # ]: 0 : if ( xMSF.is() )
49 : : {
50 [ # # ]: 0 : m_xHandler.set( xMSF->createInstance(
51 : 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) ) ),
52 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
53 : : }
54 : :
55 [ # # ]: 0 : if ( m_xHandler.is() )
56 : : {
57 [ # # ]: 0 : Reference< document::XImporter > xImporter( m_xHandler, UNO_QUERY );
58 [ # # ]: 0 : if ( xImporter.is() )
59 : : {
60 [ # # ]: 0 : Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
61 [ # # ][ # # ]: 0 : xImporter->setTargetDocument( xComp );
62 : 0 : }
63 : 0 : }
64 : 0 : }
65 : :
66 : : // -----------------------------------------------------------------------------
67 : :
68 : 0 : XMLBasicImportContext::~XMLBasicImportContext()
69 : : {
70 [ # # ]: 0 : }
71 : :
72 : : // -----------------------------------------------------------------------------
73 : :
74 : 0 : SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
75 : : sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
76 : : const Reference< xml::sax::XAttributeList >& )
77 : : {
78 : 0 : SvXMLImportContext* pContext = 0;
79 : :
80 [ # # ]: 0 : if ( m_xHandler.is() )
81 [ # # ]: 0 : pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
82 : :
83 [ # # ]: 0 : if ( !pContext )
84 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
85 : :
86 : 0 : return pContext;
87 : : }
88 : :
89 : : // -----------------------------------------------------------------------------
90 : :
91 : 0 : void XMLBasicImportContext::StartElement(
92 : : const Reference< xml::sax::XAttributeList >& rxAttrList )
93 : : {
94 [ # # ]: 0 : if ( m_xHandler.is() )
95 : : {
96 [ # # ][ # # ]: 0 : m_xHandler->startDocument();
97 : :
98 : : // copy namespace declarations
99 [ # # ]: 0 : SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
100 [ # # ][ # # ]: 0 : Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
101 : 0 : const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
102 [ # # ]: 0 : sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
103 [ # # ]: 0 : while ( nPos != USHRT_MAX )
104 : : {
105 [ # # ]: 0 : ::rtl::OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
106 [ # # ][ # # ]: 0 : if ( xAttrList->getValueByName( aAttrName ).isEmpty() )
[ # # ]
107 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
108 [ # # ]: 0 : nPos = rNamespaceMap.GetNextKey( nPos );
109 : 0 : }
110 : :
111 [ # # ]: 0 : m_xHandler->startElement(
112 : 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
113 [ # # ][ # # ]: 0 : xAttrList );
114 : : }
115 : 0 : }
116 : :
117 : : // -----------------------------------------------------------------------------
118 : :
119 : 0 : void XMLBasicImportContext::EndElement()
120 : : {
121 [ # # ]: 0 : if ( m_xHandler.is() )
122 : : {
123 : 0 : m_xHandler->endElement(
124 [ # # ]: 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
125 : 0 : m_xHandler->endDocument();
126 : : }
127 : 0 : }
128 : :
129 : : // -----------------------------------------------------------------------------
130 : :
131 : 0 : void XMLBasicImportContext::Characters( const ::rtl::OUString& rChars )
132 : : {
133 [ # # ]: 0 : if ( m_xHandler.is() )
134 : 0 : m_xHandler->characters( rChars );
135 : 0 : }
136 : :
137 : :
138 : : // =============================================================================
139 : : // XMLBasicImportChildContext
140 : : // =============================================================================
141 : :
142 : 0 : XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
143 : : const Reference< xml::sax::XDocumentHandler >& rxHandler )
144 : : :SvXMLImportContext( rImport, nPrfx, rLName )
145 : 0 : ,m_xHandler( rxHandler )
146 : : {
147 : 0 : }
148 : :
149 : : // -----------------------------------------------------------------------------
150 : :
151 : 0 : XMLBasicImportChildContext::~XMLBasicImportChildContext()
152 : : {
153 [ # # ]: 0 : }
154 : :
155 : : // -----------------------------------------------------------------------------
156 : :
157 : 0 : SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
158 : : sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
159 : : const Reference< xml::sax::XAttributeList >& )
160 : : {
161 [ # # ]: 0 : return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
162 : : }
163 : :
164 : : // -----------------------------------------------------------------------------
165 : :
166 : 0 : void XMLBasicImportChildContext::StartElement(
167 : : const Reference< xml::sax::XAttributeList >& xAttrList )
168 : : {
169 [ # # ]: 0 : if ( m_xHandler.is() )
170 : : {
171 : 0 : m_xHandler->startElement(
172 : 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
173 [ # # ]: 0 : xAttrList );
174 : : }
175 : 0 : }
176 : :
177 : : // -----------------------------------------------------------------------------
178 : :
179 : 0 : void XMLBasicImportChildContext::EndElement()
180 : : {
181 [ # # ]: 0 : if ( m_xHandler.is() )
182 : : {
183 : 0 : m_xHandler->endElement(
184 [ # # ]: 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
185 : : }
186 : 0 : }
187 : :
188 : : // -----------------------------------------------------------------------------
189 : :
190 : 0 : void XMLBasicImportChildContext::Characters( const ::rtl::OUString& rChars )
191 : : {
192 [ # # ]: 0 : if ( m_xHandler.is() )
193 : 0 : m_xHandler->characters( rChars );
194 : 0 : }
195 : :
196 : : // -----------------------------------------------------------------------------
197 : :
198 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|