LibreOffice Module dbaccess (master) 1
xmlLogin.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 "xmlLogin.hxx"
21#include "xmlfilter.hxx"
22#include <xmloff/xmltoken.hxx>
23#include <strings.hxx>
25#include <com/sun/star/sdbc/XDataSource.hpp>
26
27namespace dbaxml
28{
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::sdbc;
31 using namespace ::com::sun::star::xml::sax;
32
34 const Reference< XFastAttributeList > & _xAttrList ) :
35 SvXMLImportContext( rImport )
36{
37 Reference<XPropertySet> xDataSource(rImport.getDataSource());
38
39 bool bUserFound = false;
40 if (!xDataSource.is())
41 return;
42
43 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
44 {
45 try
46 {
47 switch( aIter.getToken() & TOKEN_MASK )
48 {
49 case XML_USER_NAME:
50 if ( !bUserFound )
51 {
52 bUserFound = true;
53 try
54 {
55 xDataSource->setPropertyValue(PROPERTY_USER,Any(aIter.toString()));
56 }
57 catch(const Exception&)
58 {
59 DBG_UNHANDLED_EXCEPTION("dbaccess");
60 }
61 }
62 break;
64 try
65 {
66 xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,Any(IsXMLToken(aIter, XML_TRUE)));
67 }
68 catch(const Exception&)
69 {
70 DBG_UNHANDLED_EXCEPTION("dbaccess");
71 }
72 break;
74 if ( !bUserFound )
75 {
76 bUserFound = true;
77 PropertyValue aProperty;
78 aProperty.Name = "UseSystemUser";
79 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
80 rImport.addInfo(aProperty);
81 }
82 break;
84 try
85 {
86 Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(aIter.toInt32());
87 }
88 catch(const Exception&)
89 {
90 DBG_UNHANDLED_EXCEPTION("dbaccess");
91 }
92 break;
93 default:
94 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
95 }
96 }
97 catch(const Exception&)
98 {
99 DBG_UNHANDLED_EXCEPTION("dbaccess");
100 }
101 }
102}
103
105{
106
107}
108
109} // namespace dbaxml
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addInfo(const css::beans::PropertyValue &_rInfo)
add an Info to the sequence which will be appended to the data source
Definition: xmlfilter.hxx:108
const Reference< XPropertySet > & getDataSource() const
Definition: xmlfilter.hxx:97
OXMLLogin(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList)
Definition: xmlLogin.cxx:33
virtual ~OXMLLogin() override
Definition: xmlLogin.cxx:104
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_IS_PASSWORD_REQUIRED
XML_TRUE
XML_USE_SYSTEM_USER
XML_USER_NAME
XML_LOGIN_TIMEOUT
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
constexpr OUStringLiteral PROPERTY_USER(u"User")
constexpr OUStringLiteral PROPERTY_ISPASSWORDREQUIRED(u"IsPasswordRequired")
#define XMLOFF_WARN_UNKNOWN(area, rIter)
constexpr sal_Int32 TOKEN_MASK