Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 :
30 : // XMLBasicImportContext
31 :
32 0 : XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
33 : const Reference< frame::XModel >& rxModel )
34 : :SvXMLImportContext( rImport, nPrfx, rLName )
35 0 : ,m_xModel( rxModel )
36 : {
37 0 : Reference< uno::XComponentContext > xContext = GetImport().GetComponentContext();
38 0 : m_xHandler = document::XMLOasisBasicImporter::create( xContext );
39 :
40 0 : Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
41 0 : m_xHandler->setTargetDocument( xComp );
42 0 : }
43 :
44 0 : XMLBasicImportContext::~XMLBasicImportContext()
45 : {
46 0 : }
47 :
48 0 : SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
49 : sal_uInt16 nPrefix, const OUString& rLocalName,
50 : const Reference< xml::sax::XAttributeList >& )
51 : {
52 0 : SvXMLImportContext* pContext = 0;
53 :
54 0 : if ( m_xHandler.is() )
55 0 : pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName,
56 0 : Reference<xml::sax::XDocumentHandler>(m_xHandler, UNO_QUERY_THROW) );
57 :
58 0 : if ( !pContext )
59 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
60 :
61 0 : return pContext;
62 : }
63 :
64 0 : void XMLBasicImportContext::StartElement(
65 : const Reference< xml::sax::XAttributeList >& rxAttrList )
66 : {
67 0 : if ( m_xHandler.is() )
68 : {
69 0 : m_xHandler->startDocument();
70 :
71 : // copy namespace declarations
72 0 : SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
73 0 : Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
74 0 : const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
75 0 : sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
76 0 : while ( nPos != USHRT_MAX )
77 : {
78 0 : OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
79 0 : if ( xAttrList->getValueByName( aAttrName ).isEmpty() )
80 0 : pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
81 0 : nPos = rNamespaceMap.GetNextKey( nPos );
82 0 : }
83 :
84 0 : m_xHandler->startElement(
85 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
86 0 : xAttrList );
87 : }
88 0 : }
89 :
90 0 : void XMLBasicImportContext::EndElement()
91 : {
92 0 : if ( m_xHandler.is() )
93 : {
94 0 : m_xHandler->endElement(
95 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
96 0 : m_xHandler->endDocument();
97 : }
98 0 : }
99 :
100 0 : void XMLBasicImportContext::Characters( const OUString& rChars )
101 : {
102 0 : if ( m_xHandler.is() )
103 0 : m_xHandler->characters( rChars );
104 0 : }
105 :
106 : // XMLBasicImportChildContext
107 :
108 0 : XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
109 : const Reference< xml::sax::XDocumentHandler >& rxHandler )
110 : :SvXMLImportContext( rImport, nPrfx, rLName )
111 0 : ,m_xHandler( rxHandler )
112 : {
113 0 : }
114 :
115 0 : XMLBasicImportChildContext::~XMLBasicImportChildContext()
116 : {
117 0 : }
118 :
119 0 : SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
120 : sal_uInt16 nPrefix, const OUString& rLocalName,
121 : const Reference< xml::sax::XAttributeList >& )
122 : {
123 0 : return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
124 : }
125 :
126 0 : void XMLBasicImportChildContext::StartElement(
127 : const Reference< xml::sax::XAttributeList >& xAttrList )
128 : {
129 0 : if ( m_xHandler.is() )
130 : {
131 0 : m_xHandler->startElement(
132 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
133 0 : xAttrList );
134 : }
135 0 : }
136 :
137 0 : void XMLBasicImportChildContext::EndElement()
138 : {
139 0 : if ( m_xHandler.is() )
140 : {
141 0 : m_xHandler->endElement(
142 0 : GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
143 : }
144 0 : }
145 :
146 0 : void XMLBasicImportChildContext::Characters( const OUString& rChars )
147 : {
148 0 : if ( m_xHandler.is() )
149 0 : m_xHandler->characters( rChars );
150 0 : }
151 :
152 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|