merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / filter / xml / xmlLogin.cxx
blob5e9b4187e6d56eb633054dc9d6e06b24214d2490
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlLogin.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBA_XMLLOGIN_HXX
34 #include "xmlLogin.hxx"
35 #endif
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
38 #endif
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
41 #endif
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
44 #endif
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
47 #endif
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
50 #endif
51 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
52 #include "xmlstrings.hrc"
53 #endif
54 #ifndef _TOOLS_DEBUG_HXX
55 #include <tools/debug.hxx>
56 #endif
57 #ifndef TOOLS_DIAGNOSE_EX_H
58 #include <tools/diagnose_ex.h>
59 #endif
60 #include <com/sun/star/sdbc/XDataSource.hpp>
61 #include <vector>
63 namespace dbaxml
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::sdbc;
67 using namespace ::com::sun::star::xml::sax;
68 DBG_NAME(OXMLLogin)
70 OXMLLogin::OXMLLogin( ODBFilter& rImport,
71 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
72 const Reference< XAttributeList > & _xAttrList ) :
73 SvXMLImportContext( rImport, nPrfx, _sLocalName )
75 DBG_CTOR(OXMLLogin,NULL);
77 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
78 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
79 const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap();
81 Reference<XPropertySet> xDataSource(rImport.getDataSource());
83 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
84 static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
85 bool bUserFound = false;
86 for(sal_Int16 i = 0; i < nLength; ++i)
88 ::rtl::OUString sLocalName;
89 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
90 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
91 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
93 try
95 switch( rTokenMap.Get( nPrefix, sLocalName ) )
97 case XML_TOK_USER_NAME:
98 if ( !bUserFound )
100 bUserFound = true;
103 xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue));
105 catch(Exception)
107 DBG_UNHANDLED_EXCEPTION();
110 break;
111 case XML_TOK_IS_PASSWORD_REQUIRED:
114 xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny((sValue == s_sTRUE ? sal_True : sal_False)));
116 catch(Exception)
118 DBG_UNHANDLED_EXCEPTION();
120 break;
121 case XML_TOK_USE_SYSTEM_USER:
122 if ( !bUserFound )
124 bUserFound = true;
125 PropertyValue aProperty;
126 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSystemUser"));
127 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
128 rImport.addInfo(aProperty);
130 break;
131 case XML_TOK_LOGIN_TIMEOUT:
134 Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32());
136 catch(Exception)
138 DBG_UNHANDLED_EXCEPTION();
140 break;
143 catch(Exception)
145 DBG_UNHANDLED_EXCEPTION();
149 // -----------------------------------------------------------------------------
151 OXMLLogin::~OXMLLogin()
154 DBG_DTOR(OXMLLogin,NULL);
156 // -----------------------------------------------------------------------------
158 //----------------------------------------------------------------------------
159 } // namespace dbaxml
160 // -----------------------------------------------------------------------------