android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / filter / xml / xmlComponent.cxx
blob019842259109f1397ba2a40e017e8a48b1db3f25
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 <comphelper/diagnose_ex.hxx>
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 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
49 switch( aIter.getToken() )
51 case XML_ELEMENT(XLINK, XML_HREF):
52 sHREF = aIter.toString();
53 break;
54 case XML_ELEMENT(DB, XML_NAME):
55 case XML_ELEMENT(DB_OASIS, XML_NAME):
56 sName = aIter.toString();
57 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
58 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
59 // in older files, we replace the slash with something less offending.
60 sName = sName.replace( '/', '_' );
61 break;
62 case XML_ELEMENT(DB, XML_AS_TEMPLATE):
63 case XML_ELEMENT(DB_OASIS, XML_AS_TEMPLATE):
64 bAsTemplate = IsXMLToken(aIter, XML_TRUE);
65 break;
66 default:
67 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
70 if ( !(!sHREF.isEmpty() && !sName.isEmpty() && _xParentContainer.is()) )
71 return;
73 Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
75 {PROPERTY_NAME, Any(sName)}, // set as folder
76 {PROPERTY_PERSISTENT_NAME, Any(sHREF.copy(sHREF.lastIndexOf('/')+1))},
77 {PROPERTY_AS_TEMPLATE, Any(bAsTemplate)},
78 }));
79 try
81 Reference< XMultiServiceFactory > xORB( _xParentContainer, UNO_QUERY_THROW );
82 Reference< XInterface > xComponent( xORB->createInstanceWithArguments( _sComponentServiceName, aArguments ) );
83 Reference< XNameContainer > xNameContainer( _xParentContainer, UNO_QUERY_THROW );
84 xNameContainer->insertByName( sName, Any( xComponent ) );
86 catch(Exception&)
88 DBG_UNHANDLED_EXCEPTION("dbaccess");
92 OXMLComponent::~OXMLComponent()
97 } // namespace dbaxml
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */