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: xmlbasici.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "xmlbasici.hxx"
34 #include <xmloff/attrlist.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include <xmloff/xmlimp.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
42 // =============================================================================
43 // XMLBasicImportContext
44 // =============================================================================
46 XMLBasicImportContext::XMLBasicImportContext( SvXMLImport
& rImport
, USHORT nPrfx
, const ::rtl::OUString
& rLName
,
47 const Reference
< frame::XModel
>& rxModel
)
48 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
51 Reference
< lang::XMultiServiceFactory
> xMSF
= GetImport().getServiceFactory();
54 m_xHandler
.set( xMSF
->createInstance(
55 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) ) ),
59 if ( m_xHandler
.is() )
61 Reference
< document::XImporter
> xImporter( m_xHandler
, UNO_QUERY
);
64 Reference
< lang::XComponent
> xComp( m_xModel
, UNO_QUERY
);
65 xImporter
->setTargetDocument( xComp
);
70 // -----------------------------------------------------------------------------
72 XMLBasicImportContext::~XMLBasicImportContext()
76 // -----------------------------------------------------------------------------
78 SvXMLImportContext
* XMLBasicImportContext::CreateChildContext(
79 USHORT nPrefix
, const ::rtl::OUString
& rLocalName
,
80 const Reference
< xml::sax::XAttributeList
>& )
82 SvXMLImportContext
* pContext
= 0;
84 if ( m_xHandler
.is() )
85 pContext
= new XMLBasicImportChildContext( GetImport(), nPrefix
, rLocalName
, m_xHandler
);
88 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
93 // -----------------------------------------------------------------------------
95 void XMLBasicImportContext::StartElement(
96 const Reference
< xml::sax::XAttributeList
>& rxAttrList
)
98 if ( m_xHandler
.is() )
100 m_xHandler
->startDocument();
102 // copy namespace declarations
103 SvXMLAttributeList
* pAttrList
= new SvXMLAttributeList( rxAttrList
);
104 Reference
< xml::sax::XAttributeList
> xAttrList( pAttrList
);
105 const SvXMLNamespaceMap
& rNamespaceMap
= GetImport().GetNamespaceMap();
106 sal_uInt16 nPos
= rNamespaceMap
.GetFirstKey();
107 while ( nPos
!= USHRT_MAX
)
109 ::rtl::OUString
aAttrName( rNamespaceMap
.GetAttrNameByKey( nPos
) );
110 if ( xAttrList
->getValueByName( aAttrName
).getLength() == 0 )
111 pAttrList
->AddAttribute( aAttrName
, rNamespaceMap
.GetNameByKey( nPos
) );
112 nPos
= rNamespaceMap
.GetNextKey( nPos
);
115 m_xHandler
->startElement(
116 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
121 // -----------------------------------------------------------------------------
123 void XMLBasicImportContext::EndElement()
125 if ( m_xHandler
.is() )
127 m_xHandler
->endElement(
128 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
129 m_xHandler
->endDocument();
133 // -----------------------------------------------------------------------------
135 void XMLBasicImportContext::Characters( const ::rtl::OUString
& rChars
)
137 if ( m_xHandler
.is() )
138 m_xHandler
->characters( rChars
);
142 // =============================================================================
143 // XMLBasicImportChildContext
144 // =============================================================================
146 XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport
& rImport
, USHORT nPrfx
, const ::rtl::OUString
& rLName
,
147 const Reference
< xml::sax::XDocumentHandler
>& rxHandler
)
148 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
149 ,m_xHandler( rxHandler
)
153 // -----------------------------------------------------------------------------
155 XMLBasicImportChildContext::~XMLBasicImportChildContext()
159 // -----------------------------------------------------------------------------
161 SvXMLImportContext
* XMLBasicImportChildContext::CreateChildContext(
162 USHORT nPrefix
, const ::rtl::OUString
& rLocalName
,
163 const Reference
< xml::sax::XAttributeList
>& )
165 return new XMLBasicImportChildContext( GetImport(), nPrefix
, rLocalName
, m_xHandler
);
168 // -----------------------------------------------------------------------------
170 void XMLBasicImportChildContext::StartElement(
171 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
173 if ( m_xHandler
.is() )
175 m_xHandler
->startElement(
176 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
181 // -----------------------------------------------------------------------------
183 void XMLBasicImportChildContext::EndElement()
185 if ( m_xHandler
.is() )
187 m_xHandler
->endElement(
188 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
192 // -----------------------------------------------------------------------------
194 void XMLBasicImportChildContext::Characters( const ::rtl::OUString
& rChars
)
196 if ( m_xHandler
.is() )
197 m_xHandler
->characters( rChars
);
200 // -----------------------------------------------------------------------------