bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / script / xmlbasici.cxx
blob2a8eacaaa47994875d522313e3e211caade35aa3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xmlbasici.hxx"
21 #include <xmloff/attrlist.hxx>
22 #include <xmloff/nmspmap.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <com/sun/star/document/XMLOasisBasicImporter.hpp>
25 #include <comphelper/processfactory.hxx>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
30 // XMLBasicImportContext
32 XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
33 const Reference< frame::XModel >& rxModel )
34 :SvXMLImportContext( rImport, nPrfx, rLName )
35 ,m_xModel( rxModel )
37 Reference< uno::XComponentContext > xContext = GetImport().GetComponentContext();
38 m_xHandler = document::XMLOasisBasicImporter::create( xContext );
40 Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
41 m_xHandler->setTargetDocument( xComp );
44 XMLBasicImportContext::~XMLBasicImportContext()
48 SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
49 sal_uInt16 nPrefix, const OUString& rLocalName,
50 const Reference< xml::sax::XAttributeList >& )
52 SvXMLImportContext* pContext = 0;
54 if ( m_xHandler.is() )
55 pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName,
56 Reference<xml::sax::XDocumentHandler>(m_xHandler, UNO_QUERY_THROW) );
58 if ( !pContext )
59 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
61 return pContext;
64 void XMLBasicImportContext::StartElement(
65 const Reference< xml::sax::XAttributeList >& rxAttrList )
67 if ( m_xHandler.is() )
69 m_xHandler->startDocument();
71 // copy namespace declarations
72 SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
73 Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
74 const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
75 sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
76 while ( nPos != USHRT_MAX )
78 OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
79 if ( xAttrList->getValueByName( aAttrName ).isEmpty() )
80 pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
81 nPos = rNamespaceMap.GetNextKey( nPos );
84 m_xHandler->startElement(
85 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
86 xAttrList );
90 void XMLBasicImportContext::EndElement()
92 if ( m_xHandler.is() )
94 m_xHandler->endElement(
95 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
96 m_xHandler->endDocument();
100 void XMLBasicImportContext::Characters( const OUString& rChars )
102 if ( m_xHandler.is() )
103 m_xHandler->characters( rChars );
106 // XMLBasicImportChildContext
108 XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
109 const Reference< xml::sax::XDocumentHandler >& rxHandler )
110 :SvXMLImportContext( rImport, nPrfx, rLName )
111 ,m_xHandler( rxHandler )
115 XMLBasicImportChildContext::~XMLBasicImportChildContext()
119 SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
120 sal_uInt16 nPrefix, const OUString& rLocalName,
121 const Reference< xml::sax::XAttributeList >& )
123 return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
126 void XMLBasicImportChildContext::StartElement(
127 const Reference< xml::sax::XAttributeList >& xAttrList )
129 if ( m_xHandler.is() )
131 m_xHandler->startElement(
132 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
133 xAttrList );
137 void XMLBasicImportChildContext::EndElement()
139 if ( m_xHandler.is() )
141 m_xHandler->endElement(
142 GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
146 void XMLBasicImportChildContext::Characters( const OUString& rChars )
148 if ( m_xHandler.is() )
149 m_xHandler->characters( rChars );
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */