1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <strings.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <comphelper/diagnose_ex.hxx>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::xml::sax
;
32 OXMLServerDatabase::OXMLServerDatabase( ODBFilter
& rImport
,
33 const Reference
< XFastAttributeList
> & _xAttrList
) :
34 SvXMLImportContext( rImport
)
36 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
38 PropertyValue aProperty
;
40 OUString sType
,sHostName
,sPortNumber
,sDatabaseName
;
43 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
45 OUString sValue
= aIter
.toString();
47 switch( aIter
.getToken() & TOKEN_MASK
)
58 case XML_LOCAL_SOCKET
:
59 aProperty
.Name
= "LocalSocket";
60 aProperty
.Value
<<= sValue
;
61 rImport
.addInfo(aProperty
);
63 case XML_DATABASE_NAME
:
64 sDatabaseName
= sValue
;
67 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
71 if ( sType
.isEmpty() )
75 if ( sType
== "sdbc:mysql:jdbc" || sType
== "sdbc:mysqlc" || sType
== "sdbc:mysql:mysqlc" )
77 sURL
.append( sType
+ ":" + sHostName
);
78 if ( !sPortNumber
.isEmpty() )
80 sURL
.append(":" + sPortNumber
);
82 if ( !sDatabaseName
.isEmpty() )
84 sURL
.append("/" + sDatabaseName
);
87 else if ( sType
== "jdbc:oracle:thin" )
89 sURL
.append("jdbc:oracle:thin:@" + sHostName
);
90 if ( !sPortNumber
.isEmpty() )
92 sURL
.append(":" + sPortNumber
);
94 if ( !sDatabaseName
.isEmpty() )
96 sURL
.append(":" + sDatabaseName
);
99 else if ( sType
== "sdbc:address:ldap" )
101 sURL
.append("sdbc:address:ldap:" + sHostName
);
102 if ( !sPortNumber
.isEmpty() )
104 sURL
.append(":" + sPortNumber
);
109 sURL
.append(sType
+ ":" + sHostName
);
110 if ( !sPortNumber
.isEmpty() )
112 sURL
.append(":" + sPortNumber
);
114 if ( !sDatabaseName
.isEmpty() )
116 sURL
.append(":" + sDatabaseName
);
121 xDataSource
->setPropertyValue(PROPERTY_URL
,Any(sURL
.makeStringAndClear()));
123 catch(const Exception
&)
125 DBG_UNHANDLED_EXCEPTION("dbaccess");
129 OXMLServerDatabase::~OXMLServerDatabase()
134 } // namespace dbaxml
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */