1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "xmlbasici.hxx"
27cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
28cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
29cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir // =============================================================================
36cdf0e10cSrcweir // XMLBasicImportContext
37cdf0e10cSrcweir // =============================================================================
38cdf0e10cSrcweir
XMLBasicImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const Reference<frame::XModel> & rxModel)39cdf0e10cSrcweir XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
40cdf0e10cSrcweir const Reference< frame::XModel >& rxModel )
41cdf0e10cSrcweir :SvXMLImportContext( rImport, nPrfx, rLName )
42cdf0e10cSrcweir ,m_xModel( rxModel )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMSF = GetImport().getServiceFactory();
45cdf0e10cSrcweir if ( xMSF.is() )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir m_xHandler.set( xMSF->createInstance(
48cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) ) ),
49cdf0e10cSrcweir UNO_QUERY );
50cdf0e10cSrcweir }
51cdf0e10cSrcweir
52cdf0e10cSrcweir if ( m_xHandler.is() )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir Reference< document::XImporter > xImporter( m_xHandler, UNO_QUERY );
55cdf0e10cSrcweir if ( xImporter.is() )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
58cdf0e10cSrcweir xImporter->setTargetDocument( xComp );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir }
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
64cdf0e10cSrcweir
~XMLBasicImportContext()65cdf0e10cSrcweir XMLBasicImportContext::~XMLBasicImportContext()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir // -----------------------------------------------------------------------------
70cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<xml::sax::XAttributeList> &)71cdf0e10cSrcweir SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
72cdf0e10cSrcweir sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
73cdf0e10cSrcweir const Reference< xml::sax::XAttributeList >& )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir SvXMLImportContext* pContext = 0;
76cdf0e10cSrcweir
77cdf0e10cSrcweir if ( m_xHandler.is() )
78cdf0e10cSrcweir pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
79cdf0e10cSrcweir
80cdf0e10cSrcweir if ( !pContext )
81cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
82cdf0e10cSrcweir
83cdf0e10cSrcweir return pContext;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir // -----------------------------------------------------------------------------
87cdf0e10cSrcweir
StartElement(const Reference<xml::sax::XAttributeList> & rxAttrList)88cdf0e10cSrcweir void XMLBasicImportContext::StartElement(
89cdf0e10cSrcweir const Reference< xml::sax::XAttributeList >& rxAttrList )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if ( m_xHandler.is() )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir m_xHandler->startDocument();
94cdf0e10cSrcweir
95cdf0e10cSrcweir // copy namespace declarations
96cdf0e10cSrcweir SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
97cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
98cdf0e10cSrcweir const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
99cdf0e10cSrcweir sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
100cdf0e10cSrcweir while ( nPos != USHRT_MAX )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir ::rtl::OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
103cdf0e10cSrcweir if ( xAttrList->getValueByName( aAttrName ).getLength() == 0 )
104cdf0e10cSrcweir pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
105cdf0e10cSrcweir nPos = rNamespaceMap.GetNextKey( nPos );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir m_xHandler->startElement(
109cdf0e10cSrcweir GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
110cdf0e10cSrcweir xAttrList );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir // -----------------------------------------------------------------------------
115cdf0e10cSrcweir
EndElement()116cdf0e10cSrcweir void XMLBasicImportContext::EndElement()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir if ( m_xHandler.is() )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir m_xHandler->endElement(
121cdf0e10cSrcweir GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
122cdf0e10cSrcweir m_xHandler->endDocument();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
126cdf0e10cSrcweir // -----------------------------------------------------------------------------
127cdf0e10cSrcweir
Characters(const::rtl::OUString & rChars)128cdf0e10cSrcweir void XMLBasicImportContext::Characters( const ::rtl::OUString& rChars )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir if ( m_xHandler.is() )
131cdf0e10cSrcweir m_xHandler->characters( rChars );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir // =============================================================================
136cdf0e10cSrcweir // XMLBasicImportChildContext
137cdf0e10cSrcweir // =============================================================================
138cdf0e10cSrcweir
XMLBasicImportChildContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const Reference<xml::sax::XDocumentHandler> & rxHandler)139cdf0e10cSrcweir XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
140cdf0e10cSrcweir const Reference< xml::sax::XDocumentHandler >& rxHandler )
141cdf0e10cSrcweir :SvXMLImportContext( rImport, nPrfx, rLName )
142cdf0e10cSrcweir ,m_xHandler( rxHandler )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir // -----------------------------------------------------------------------------
147cdf0e10cSrcweir
~XMLBasicImportChildContext()148cdf0e10cSrcweir XMLBasicImportChildContext::~XMLBasicImportChildContext()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir // -----------------------------------------------------------------------------
153cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<xml::sax::XAttributeList> &)154cdf0e10cSrcweir SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
155cdf0e10cSrcweir sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
156cdf0e10cSrcweir const Reference< xml::sax::XAttributeList >& )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir // -----------------------------------------------------------------------------
162cdf0e10cSrcweir
StartElement(const Reference<xml::sax::XAttributeList> & xAttrList)163cdf0e10cSrcweir void XMLBasicImportChildContext::StartElement(
164cdf0e10cSrcweir const Reference< xml::sax::XAttributeList >& xAttrList )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir if ( m_xHandler.is() )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir m_xHandler->startElement(
169cdf0e10cSrcweir GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
170cdf0e10cSrcweir xAttrList );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir // -----------------------------------------------------------------------------
175cdf0e10cSrcweir
EndElement()176cdf0e10cSrcweir void XMLBasicImportChildContext::EndElement()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir if ( m_xHandler.is() )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir m_xHandler->endElement(
181cdf0e10cSrcweir GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
185cdf0e10cSrcweir // -----------------------------------------------------------------------------
186cdf0e10cSrcweir
Characters(const::rtl::OUString & rChars)187cdf0e10cSrcweir void XMLBasicImportChildContext::Characters( const ::rtl::OUString& rChars )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir if ( m_xHandler.is() )
190cdf0e10cSrcweir m_xHandler->characters( rChars );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir // -----------------------------------------------------------------------------
194