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 <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>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::xml::sax
;
35 OXMLServerDatabase::OXMLServerDatabase( ODBFilter
& rImport
,
36 sal_uInt16 nPrfx
, const OUString
& _sLocalName
,
37 const Reference
< XAttributeList
> & _xAttrList
) :
38 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
41 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
42 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
43 const SvXMLTokenMap
& rTokenMap
= rImport
.GetDataSourceElemTokenMap();
45 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
47 PropertyValue aProperty
;
49 const sal_Int16 nLength
= (xDataSource
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
50 OUString sType
,sHostName
,sPortNumber
,sDatabaseName
;
51 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
54 const OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
55 const sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
56 const OUString sValue
= _xAttrList
->getValueByIndex( i
);
58 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
63 case XML_TOK_HOSTNAME
:
69 case XML_TOK_LOCAL_SOCKET
:
70 aProperty
.Name
= "LocalSocket";
71 aProperty
.Value
<<= sValue
;
72 rImport
.addInfo(aProperty
);
74 case XML_TOK_DATABASE_NAME
:
75 sDatabaseName
= sValue
;
79 if ( !sType
.isEmpty() )
82 if ( sType
== "sdbc:mysql:jdbc" || sType
== "sdbc:mysqlc" || sType
== "sdbc:mysql:mysqlc" )
84 sURL
.append( sType
+ ":" + sHostName
);
85 if ( !sPortNumber
.isEmpty() )
87 sURL
.append(":" + sPortNumber
);
89 if ( !sDatabaseName
.isEmpty() )
91 sURL
.append("/" + sDatabaseName
);
94 else if ( sType
== "jdbc:oracle:thin" )
96 sURL
.append("jdbc:oracle:thin:@" + sHostName
);
97 if ( !sPortNumber
.isEmpty() )
99 sURL
.append(":" + sPortNumber
);
101 if ( !sDatabaseName
.isEmpty() )
103 sURL
.append(":" + sDatabaseName
);
106 else if ( sType
== "sdbc:address:ldap" )
108 sURL
.append("sdbc:address:ldap:" + sHostName
);
109 if ( !sPortNumber
.isEmpty() )
111 sURL
.append(":" + sPortNumber
);
116 sURL
.append(sType
+ ":" + sHostName
);
117 if ( !sPortNumber
.isEmpty() )
119 sURL
.append(":" + sPortNumber
);
121 if ( !sDatabaseName
.isEmpty() )
123 sURL
.append(":" + sDatabaseName
);
128 xDataSource
->setPropertyValue(PROPERTY_URL
,makeAny(sURL
.makeStringAndClear()));
130 catch(const Exception
&)
132 DBG_UNHANDLED_EXCEPTION();
137 OXMLServerDatabase::~OXMLServerDatabase()
142 } // namespace dbaxml
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */