Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlLogin.cxx
blobd747ef801f552b45faa26224cb9674054b8aedfd
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 "xmlLogin.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "xmlEnums.hxx"
26 #include <stringconstants.hxx>
27 #include <strings.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <com/sun/star/sdbc/XDataSource.hpp>
31 #include <vector>
33 namespace dbaxml
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::xml::sax;
39 OXMLLogin::OXMLLogin( ODBFilter& rImport,
40 sal_uInt16 nPrfx, const OUString& _sLocalName,
41 const Reference< XAttributeList > & _xAttrList ) :
42 SvXMLImportContext( rImport, nPrfx, _sLocalName )
45 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
46 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
47 const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap();
49 Reference<XPropertySet> xDataSource(rImport.getDataSource());
51 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
52 static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
53 bool bUserFound = false;
54 for(sal_Int16 i = 0; i < nLength; ++i)
56 OUString sLocalName;
57 OUString sAttrName = _xAttrList->getNameByIndex( i );
58 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
59 OUString sValue = _xAttrList->getValueByIndex( i );
61 try
63 switch( rTokenMap.Get( nPrefix, sLocalName ) )
65 case XML_TOK_USER_NAME:
66 if ( !bUserFound )
68 bUserFound = true;
69 try
71 xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue));
73 catch(const Exception&)
75 DBG_UNHANDLED_EXCEPTION("dbaccess");
78 break;
79 case XML_TOK_IS_PASSWORD_REQUIRED:
80 try
82 xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny(sValue == s_sTRUE));
84 catch(const Exception&)
86 DBG_UNHANDLED_EXCEPTION("dbaccess");
88 break;
89 case XML_TOK_USE_SYSTEM_USER:
90 if ( !bUserFound )
92 bUserFound = true;
93 PropertyValue aProperty;
94 aProperty.Name = "UseSystemUser";
95 aProperty.Value <<= (sValue == s_sTRUE);
96 rImport.addInfo(aProperty);
98 break;
99 case XML_TOK_LOGIN_TIMEOUT:
102 Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32());
104 catch(const Exception&)
106 DBG_UNHANDLED_EXCEPTION("dbaccess");
108 break;
111 catch(const Exception&)
113 DBG_UNHANDLED_EXCEPTION("dbaccess");
118 OXMLLogin::~OXMLLogin()
123 } // namespace dbaxml
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */