1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBA_XMLLOGIN_HXX
27 #include "xmlLogin.hxx"
28 #endif
29 #ifndef DBA_XMLFILTER_HXX
30 #include "xmlfilter.hxx"
31 #endif
32 #ifndef _XMLOFF_XMLTOKEN_HXX
33 #include <xmloff/xmltoken.hxx>
34 #endif
35 #ifndef _XMLOFF_XMLNMSPE_HXX
36 #include <xmloff/xmlnmspe.hxx>
37 #endif
38 #ifndef _XMLOFF_NMSPMAP_HXX
39 #include <xmloff/nmspmap.hxx>
40 #endif
41 #ifndef DBA_XMLENUMS_HXX
42 #include "xmlEnums.hxx"
43 #endif
44 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
45 #include "xmlstrings.hrc"
46 #endif
47 #ifndef _TOOLS_DEBUG_HXX
48 #include <tools/debug.hxx>
49 #endif
50 #ifndef TOOLS_DIAGNOSE_EX_H
51 #include <tools/diagnose_ex.h>
52 #endif
53 #include <com/sun/star/sdbc/XDataSource.hpp>
54 #include <vector>
55
56 namespace dbaxml
57 {
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::sdbc;
60 using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLLogin)61 DBG_NAME(OXMLLogin)
62
63 OXMLLogin::OXMLLogin( ODBFilter& rImport,
64 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
65 const Reference< XAttributeList > & _xAttrList ) :
66 SvXMLImportContext( rImport, nPrfx, _sLocalName )
67 {
68 DBG_CTOR(OXMLLogin,NULL);
69
70 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
71 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
72 const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap();
73
74 Reference<XPropertySet> xDataSource(rImport.getDataSource());
75
76 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
77 static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
78 bool bUserFound = false;
79 for(sal_Int16 i = 0; i < nLength; ++i)
80 {
81 ::rtl::OUString sLocalName;
82 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
83 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
84 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
85
86 try
87 {
88 switch( rTokenMap.Get( nPrefix, sLocalName ) )
89 {
90 case XML_TOK_USER_NAME:
91 if ( !bUserFound )
92 {
93 bUserFound = true;
94 try
95 {
96 xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue));
97 }
98 catch(Exception)
99 {
100 DBG_UNHANDLED_EXCEPTION();
101 }
102 }
103 break;
104 case XML_TOK_IS_PASSWORD_REQUIRED:
105 try
106 {
107 xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny((sValue == s_sTRUE ? sal_True : sal_False)));
108 }
109 catch(Exception)
110 {
111 DBG_UNHANDLED_EXCEPTION();
112 }
113 break;
114 case XML_TOK_USE_SYSTEM_USER:
115 if ( !bUserFound )
116 {
117 bUserFound = true;
118 PropertyValue aProperty;
119 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSystemUser"));
120 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
121 rImport.addInfo(aProperty);
122 }
123 break;
124 case XML_TOK_LOGIN_TIMEOUT:
125 try
126 {
127 Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32());
128 }
129 catch(Exception)
130 {
131 DBG_UNHANDLED_EXCEPTION();
132 }
133 break;
134 }
135 }
136 catch(Exception)
137 {
138 DBG_UNHANDLED_EXCEPTION();
139 }
140 }
141 }
142 // -----------------------------------------------------------------------------
143
~OXMLLogin()144 OXMLLogin::~OXMLLogin()
145 {
146
147 DBG_DTOR(OXMLLogin,NULL);
148 }
149 // -----------------------------------------------------------------------------
150
151 //----------------------------------------------------------------------------
152 } // namespace dbaxml
153 // -----------------------------------------------------------------------------
154