bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / filter / xml / xmlLogin.cxx
blobeb0503ffbf7900f1e80695a6f6efe777b8ee124e
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 "xmlstrings.hrc"
27 #include <tools/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <com/sun/star/sdbc/XDataSource.hpp>
30 #include <vector>
32 namespace dbaxml
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::xml::sax;
37 DBG_NAME(OXMLLogin)
39 OXMLLogin::OXMLLogin( ODBFilter& rImport,
40 sal_uInt16 nPrfx, const OUString& _sLocalName,
41 const Reference< XAttributeList > & _xAttrList ) :
42 SvXMLImportContext( rImport, nPrfx, _sLocalName )
44 DBG_CTOR(OXMLLogin,NULL);
46 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
47 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
48 const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap();
50 Reference<XPropertySet> xDataSource(rImport.getDataSource());
52 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
53 static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
54 bool bUserFound = false;
55 for(sal_Int16 i = 0; i < nLength; ++i)
57 OUString sLocalName;
58 OUString sAttrName = _xAttrList->getNameByIndex( i );
59 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
60 OUString sValue = _xAttrList->getValueByIndex( i );
62 try
64 switch( rTokenMap.Get( nPrefix, sLocalName ) )
66 case XML_TOK_USER_NAME:
67 if ( !bUserFound )
69 bUserFound = true;
70 try
72 xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue));
74 catch(const Exception&)
76 DBG_UNHANDLED_EXCEPTION();
79 break;
80 case XML_TOK_IS_PASSWORD_REQUIRED:
81 try
83 xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny((sValue == s_sTRUE ? sal_True : sal_False)));
85 catch(const Exception&)
87 DBG_UNHANDLED_EXCEPTION();
89 break;
90 case XML_TOK_USE_SYSTEM_USER:
91 if ( !bUserFound )
93 bUserFound = true;
94 PropertyValue aProperty;
95 aProperty.Name = OUString("UseSystemUser");
96 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
97 rImport.addInfo(aProperty);
99 break;
100 case XML_TOK_LOGIN_TIMEOUT:
103 Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32());
105 catch(const Exception&)
107 DBG_UNHANDLED_EXCEPTION();
109 break;
112 catch(const Exception&)
114 DBG_UNHANDLED_EXCEPTION();
118 // -----------------------------------------------------------------------------
120 OXMLLogin::~OXMLLogin()
123 DBG_DTOR(OXMLLogin,NULL);
125 // -----------------------------------------------------------------------------
127 //----------------------------------------------------------------------------
128 } // namespace dbaxml
129 // -----------------------------------------------------------------------------
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */