Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlComponent.cxx
blob7db3101b679d48d4e2ca5bab516c9412b33328f8
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 "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>
34 namespace dbaxml
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
42 ,sal_uInt16 nPrfx
43 ,const OUString& _sLocalName
44 ,const Reference< XAttributeList > & _xAttrList
45 ,const Reference< XNameAccess >& _xParentContainer
46 ,const OUString& _sComponentServiceName
47 ) :
48 SvXMLImportContext( rImport, nPrfx, _sLocalName )
49 ,m_bAsTemplate(false)
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)
60 OUString sLocalName;
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 ) )
67 case XML_TOK_HREF:
68 m_sHREF = sValue;
69 break;
70 case XML_TOK_COMPONENT_NAME:
71 m_sName = sValue;
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( '/', '_' );
76 break;
77 case XML_TOK_AS_TEMPLATE:
78 m_bAsTemplate = sValue == s_sTRUE;
79 break;
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)},
89 }));
90 try
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 ) );
97 catch(Exception&)
99 DBG_UNHANDLED_EXCEPTION("dbaccess");
104 OXMLComponent::~OXMLComponent()
109 } // namespace dbaxml
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */