nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / filter / xml / xmlComponent.cxx
blob144eb4ec92342f37a59f4fb4339f8aa56ad79332
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/xmlnamespace.hxx>
24 #include <strings.hxx>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <tools/diagnose_ex.h>
28 #include <comphelper/propertysequence.hxx>
30 namespace dbaxml
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::xml::sax;
37 OXMLComponent::OXMLComponent( ODBFilter& rImport
38 ,const Reference< XFastAttributeList > & _xAttrList
39 ,const Reference< XNameAccess >& _xParentContainer
40 ,const OUString& _sComponentServiceName
41 ) :
42 SvXMLImportContext( rImport )
44 OUString sName;
45 OUString sHREF;
46 bool bAsTemplate(false);
47 static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
48 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
50 OUString sValue = aIter.toString();
52 switch( aIter.getToken() )
54 case XML_ELEMENT(XLINK, XML_HREF):
55 sHREF = sValue;
56 break;
57 case XML_ELEMENT(DB, XML_NAME):
58 case XML_ELEMENT(DB_OASIS, XML_NAME):
59 sName = sValue;
60 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
61 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
62 // in older files, we replace the slash with something less offending.
63 sName = sName.replace( '/', '_' );
64 break;
65 case XML_ELEMENT(DB, XML_AS_TEMPLATE):
66 case XML_ELEMENT(DB_OASIS, XML_AS_TEMPLATE):
67 bAsTemplate = sValue == s_sTRUE;
68 break;
69 default:
70 XMLOFF_WARN_UNKNOWN_ATTR("dbaccess", aIter.getToken(), aIter.toString());
73 if ( !(!sHREF.isEmpty() && !sName.isEmpty() && _xParentContainer.is()) )
74 return;
76 Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
78 {PROPERTY_NAME, Any(sName)}, // set as folder
79 {PROPERTY_PERSISTENT_NAME, Any(sHREF.copy(sHREF.lastIndexOf('/')+1))},
80 {PROPERTY_AS_TEMPLATE, Any(bAsTemplate)},
81 }));
82 try
84 Reference< XMultiServiceFactory > xORB( _xParentContainer, UNO_QUERY_THROW );
85 Reference< XInterface > xComponent( xORB->createInstanceWithArguments( _sComponentServiceName, aArguments ) );
86 Reference< XNameContainer > xNameContainer( _xParentContainer, UNO_QUERY_THROW );
87 xNameContainer->insertByName( sName, makeAny( xComponent ) );
89 catch(Exception&)
91 DBG_UNHANDLED_EXCEPTION("dbaccess");
95 OXMLComponent::~OXMLComponent()
100 } // namespace dbaxml
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */