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/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>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::xml::sax
;
36 OXMLComponent::OXMLComponent( ODBFilter
& rImport
37 ,const Reference
< XFastAttributeList
> & _xAttrList
38 ,const Reference
< XNameAccess
>& _xParentContainer
39 ,const OUString
& _sComponentServiceName
41 SvXMLImportContext( rImport
)
45 bool bAsTemplate(false);
46 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
48 switch( aIter
.getToken() )
50 case XML_ELEMENT(XLINK
, XML_HREF
):
51 sHREF
= aIter
.toString();
53 case XML_ELEMENT(DB
, XML_NAME
):
54 case XML_ELEMENT(DB_OASIS
, XML_NAME
):
55 sName
= aIter
.toString();
56 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
57 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
58 // in older files, we replace the slash with something less offending.
59 sName
= sName
.replace( '/', '_' );
61 case XML_ELEMENT(DB
, XML_AS_TEMPLATE
):
62 case XML_ELEMENT(DB_OASIS
, XML_AS_TEMPLATE
):
63 bAsTemplate
= IsXMLToken(aIter
, XML_TRUE
);
66 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
69 if ( !(!sHREF
.isEmpty() && !sName
.isEmpty() && _xParentContainer
.is()) )
72 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
74 {PROPERTY_NAME
, Any(sName
)}, // set as folder
75 {PROPERTY_PERSISTENT_NAME
, Any(sHREF
.copy(sHREF
.lastIndexOf('/')+1))},
76 {PROPERTY_AS_TEMPLATE
, Any(bAsTemplate
)},
80 Reference
< XMultiServiceFactory
> xORB( _xParentContainer
, UNO_QUERY_THROW
);
81 Reference
< XInterface
> xComponent( xORB
->createInstanceWithArguments( _sComponentServiceName
, aArguments
) );
82 Reference
< XNameContainer
> xNameContainer( _xParentContainer
, UNO_QUERY_THROW
);
83 xNameContainer
->insertByName( sName
, Any( xComponent
) );
87 DBG_UNHANDLED_EXCEPTION("dbaccess");
91 OXMLComponent::~OXMLComponent()
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */