LibreOffice Module dbaccess (master) 1
xmlComponent.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "xmlComponent.hxx"
21#include "xmlfilter.hxx"
22#include <xmloff/xmltoken.hxx>
24#include <strings.hxx>
25#include <com/sun/star/container/XNameContainer.hpp>
26#include <com/sun/star/lang/XMultiServiceFactory.hpp>
29
30namespace dbaxml
31{
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;
36
37OXMLComponent::OXMLComponent( ODBFilter& rImport
38 ,const Reference< XFastAttributeList > & _xAttrList
39 ,const Reference< XNameAccess >& _xParentContainer
40 ,const OUString& _sComponentServiceName
41 ) :
42 SvXMLImportContext( rImport )
43{
44 OUString sName;
45 OUString sHREF;
46 bool bAsTemplate(false);
47 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
48 {
49 switch( aIter.getToken() )
50 {
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);
68 }
69 }
70 if ( !(!sHREF.isEmpty() && !sName.isEmpty() && _xParentContainer.is()) )
71 return;
72
74 {
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
80 {
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 ) );
85 }
86 catch(Exception&)
87 {
88 DBG_UNHANDLED_EXCEPTION("dbaccess");
89 }
90}
91
92OXMLComponent::~OXMLComponent()
93{
94
95}
96
97} // namespace dbaxml
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sName
OXMLComponent(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList, const css::uno::Reference< css::container::XNameAccess > &_xParentContainer, const OUString &_sComponentServiceName)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
XML_TRUE
XML_NAME
XML_AS_TEMPLATE
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
constexpr OUStringLiteral PROPERTY_PERSISTENT_NAME(u"PersistentName")
constexpr OUStringLiteral PROPERTY_AS_TEMPLATE(u"AsTemplate")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)