bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / filter / xml / xmlServerDatabase.cxx
blobdec5d0e1ad8fc538cdb51c2a5e76bf9c28872954
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 "xmlServerDatabase.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>
30 namespace dbaxml
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 DBG_NAME(OXMLServerDatabase)
36 OXMLServerDatabase::OXMLServerDatabase( ODBFilter& rImport,
37 sal_uInt16 nPrfx, const OUString& _sLocalName,
38 const Reference< XAttributeList > & _xAttrList) :
39 SvXMLImportContext( rImport, nPrfx, _sLocalName )
41 DBG_CTOR(OXMLServerDatabase,NULL);
43 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
44 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
45 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
47 Reference<XPropertySet> xDataSource = rImport.getDataSource();
49 PropertyValue aProperty;
51 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
52 OUString sType,sHostName,sPortNumber,sDatabaseName;
53 for(sal_Int16 i = 0; i < nLength; ++i)
55 OUString sLocalName;
56 const OUString sAttrName = _xAttrList->getNameByIndex( i );
57 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
58 const OUString sValue = _xAttrList->getValueByIndex( i );
60 switch( rTokenMap.Get( nPrefix, sLocalName ) )
62 case XML_TOK_DB_TYPE:
63 sType = sValue;
64 break;
65 case XML_TOK_HOSTNAME:
66 sHostName = sValue;
67 break;
68 case XML_TOK_PORT:
69 sPortNumber = sValue;
70 break;
71 case XML_TOK_LOCAL_SOCKET:
72 aProperty.Name = OUString("LocalSocket");
73 aProperty.Value <<= sValue;
74 rImport.addInfo(aProperty);
75 break;
76 case XML_TOK_DATABASE_NAME:
77 sDatabaseName = sValue;
78 break;
81 if ( !sType.isEmpty() )
83 OUStringBuffer sURL;
84 if ( sType == "sdbc:mysql:jdbc" || sType == "sdbc:mysqlc" || sType == "sdbc:mysql:mysqlc" )
86 sURL.append( sType + ":" + sHostName);
87 if ( !sPortNumber.isEmpty() )
89 sURL.append(":" + sPortNumber);
91 if ( !sDatabaseName.isEmpty() )
93 sURL.append("/" + sDatabaseName);
96 else if ( sType == "jdbc:oracle:thin" )
98 sURL.append("jdbc:oracle:thin:@" + sHostName);
99 if ( !sPortNumber.isEmpty() )
101 sURL.append(":" + sPortNumber);
103 if ( !sDatabaseName.isEmpty() )
105 sURL.append(":" + sDatabaseName);
108 else if ( sType == "sdbc:address:ldap" )
110 sURL.append("sdbc:address:ldap:" + sHostName);
111 if ( !sPortNumber.isEmpty() )
113 sURL.append(":" + sPortNumber);
116 else
118 sURL.append(sType + ":" + sHostName);
119 if ( !sPortNumber.isEmpty() )
121 sURL.append(":" + sPortNumber);
123 if ( !sDatabaseName.isEmpty() )
125 sURL.append(":" + sDatabaseName);
130 xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL.makeStringAndClear()));
132 catch(const Exception&)
134 DBG_UNHANDLED_EXCEPTION();
138 // -----------------------------------------------------------------------------
140 OXMLServerDatabase::~OXMLServerDatabase()
143 DBG_DTOR(OXMLServerDatabase,NULL);
145 // -----------------------------------------------------------------------------
147 //----------------------------------------------------------------------------
148 } // namespace dbaxml
149 // -----------------------------------------------------------------------------
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */