1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "xmlComponent.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlstrings.hrc"
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::container
;
37 using namespace ::com::sun::star::xml::sax
;
39 OXMLComponent::OXMLComponent( ODBFilter
& rImport
41 ,const OUString
& _sLocalName
42 ,const Reference
< XAttributeList
> & _xAttrList
43 ,const Reference
< XNameAccess
>& _xParentContainer
44 ,const OUString
& _sComponentServiceName
46 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
50 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
51 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
52 const SvXMLTokenMap
& rTokenMap
= rImport
.GetComponentElemTokenMap();
54 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
55 static const OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
56 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
59 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
60 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
61 OUString sValue
= _xAttrList
->getValueByIndex( i
);
63 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
68 case XML_TOK_COMPONENT_NAME
:
70 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
71 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
72 // in older files, we replace the slash with something less offending.
73 m_sName
= m_sName
.replace( '/', '_' );
75 case XML_TOK_AS_TEMPLATE
:
76 m_bAsTemplate
= sValue
== s_sTRUE
;
80 if ( !m_sHREF
.isEmpty() && !m_sName
.isEmpty() && _xParentContainer
.is() )
82 Sequence
< Any
> aArguments(3);
85 aValue
.Name
= PROPERTY_NAME
;
86 aValue
.Value
<<= m_sName
;
87 aArguments
[0] <<= aValue
;
89 aValue
.Name
= PROPERTY_PERSISTENT_NAME
;
90 sal_Int32 nIndex
= m_sHREF
.lastIndexOf('/')+1;
91 aValue
.Value
<<= m_sHREF
.getToken(0,'/',nIndex
);
92 aArguments
[1] <<= aValue
;
94 aValue
.Name
= PROPERTY_AS_TEMPLATE
;
95 aValue
.Value
<<= m_bAsTemplate
;
96 aArguments
[2] <<= aValue
;
100 Reference
< XMultiServiceFactory
> xORB( _xParentContainer
, UNO_QUERY_THROW
);
101 Reference
< XInterface
> xComponent( xORB
->createInstanceWithArguments( _sComponentServiceName
, aArguments
) );
102 Reference
< XNameContainer
> xNameContainer( _xParentContainer
, UNO_QUERY_THROW
);
103 xNameContainer
->insertByName( m_sName
, makeAny( xComponent
) );
107 DBG_UNHANDLED_EXCEPTION();
112 OXMLComponent::~OXMLComponent()
117 } // namespace dbaxml
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */