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 <stringconstants.hxx>
27 #include <strings.hxx>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <comphelper/propertysequence.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::container
;
39 using namespace ::com::sun::star::xml::sax
;
41 OXMLComponent::OXMLComponent( ODBFilter
& rImport
43 ,const OUString
& _sLocalName
44 ,const Reference
< XAttributeList
> & _xAttrList
45 ,const Reference
< XNameAccess
>& _xParentContainer
46 ,const OUString
& _sComponentServiceName
48 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
52 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
53 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
54 const SvXMLTokenMap
& rTokenMap
= rImport
.GetComponentElemTokenMap();
56 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
57 static const OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
58 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
61 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
62 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
63 OUString sValue
= _xAttrList
->getValueByIndex( i
);
65 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
70 case XML_TOK_COMPONENT_NAME
:
72 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
73 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
74 // in older files, we replace the slash with something less offending.
75 m_sName
= m_sName
.replace( '/', '_' );
77 case XML_TOK_AS_TEMPLATE
:
78 m_bAsTemplate
= sValue
== s_sTRUE
;
82 if ( !m_sHREF
.isEmpty() && !m_sName
.isEmpty() && _xParentContainer
.is() )
84 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
86 {PROPERTY_NAME
, Any(m_sName
)}, // set as folder
87 {PROPERTY_PERSISTENT_NAME
, Any(m_sHREF
.copy(m_sHREF
.lastIndexOf('/')+1))},
88 {PROPERTY_AS_TEMPLATE
, Any(m_bAsTemplate
)},
92 Reference
< XMultiServiceFactory
> xORB( _xParentContainer
, UNO_QUERY_THROW
);
93 Reference
< XInterface
> xComponent( xORB
->createInstanceWithArguments( _sComponentServiceName
, aArguments
) );
94 Reference
< XNameContainer
> xNameContainer( _xParentContainer
, UNO_QUERY_THROW
);
95 xNameContainer
->insertByName( m_sName
, makeAny( xComponent
) );
99 DBG_UNHANDLED_EXCEPTION("dbaccess");
104 OXMLComponent::~OXMLComponent()
109 } // namespace dbaxml
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */