LibreOffice Module dbaccess (master) 1
xmlServerDatabase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "xmlServerDatabase.hxx"
21#include "xmlfilter.hxx"
22#include <xmloff/xmltoken.hxx>
23#include <strings.hxx>
24#include <rtl/ustrbuf.hxx>
26
27namespace dbaxml
28{
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::xml::sax;
31
33 const Reference< XFastAttributeList > & _xAttrList) :
34 SvXMLImportContext( rImport )
35{
36 Reference<XPropertySet> xDataSource = rImport.getDataSource();
37
38 PropertyValue aProperty;
39
40 OUString sType,sHostName,sPortNumber,sDatabaseName;
41 if (xDataSource.is())
42 {
43 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
44 {
45 OUString sValue = aIter.toString();
46
47 switch( aIter.getToken() & TOKEN_MASK )
48 {
49 case XML_TYPE:
50 sType = sValue;
51 break;
52 case XML_HOSTNAME:
53 sHostName = sValue;
54 break;
55 case XML_PORT:
56 sPortNumber = sValue;
57 break;
59 aProperty.Name = "LocalSocket";
60 aProperty.Value <<= sValue;
61 rImport.addInfo(aProperty);
62 break;
64 sDatabaseName = sValue;
65 break;
66 default:
67 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
68 }
69 }
70 }
71 if ( sType.isEmpty() )
72 return;
73
74 OUStringBuffer sURL;
75 if ( sType == "sdbc:mysql:jdbc" || sType == "sdbc:mysqlc" || sType == "sdbc:mysql:mysqlc" )
76 {
77 sURL.append( sType + ":" + sHostName);
78 if ( !sPortNumber.isEmpty() )
79 {
80 sURL.append(":" + sPortNumber);
81 }
82 if ( !sDatabaseName.isEmpty() )
83 {
84 sURL.append("/" + sDatabaseName);
85 }
86 }
87 else if ( sType == "jdbc:oracle:thin" )
88 {
89 sURL.append("jdbc:oracle:thin:@" + sHostName);
90 if ( !sPortNumber.isEmpty() )
91 {
92 sURL.append(":" + sPortNumber);
93 }
94 if ( !sDatabaseName.isEmpty() )
95 {
96 sURL.append(":" + sDatabaseName);
97 }
98 }
99 else if ( sType == "sdbc:address:ldap" )
100 {
101 sURL.append("sdbc:address:ldap:" + sHostName);
102 if ( !sPortNumber.isEmpty() )
103 {
104 sURL.append(":" + sPortNumber);
105 }
106 }
107 else
108 {
109 sURL.append(sType + ":" + sHostName);
110 if ( !sPortNumber.isEmpty() )
111 {
112 sURL.append(":" + sPortNumber);
113 }
114 if ( !sDatabaseName.isEmpty() )
115 {
116 sURL.append(":" + sDatabaseName);
117 }
118 }
119 try
120 {
121 xDataSource->setPropertyValue(PROPERTY_URL,Any(sURL.makeStringAndClear()));
122 }
123 catch(const Exception&)
124 {
125 DBG_UNHANDLED_EXCEPTION("dbaccess");
126 }
127}
128
130{
131
132}
133
134} // namespace dbaxml
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
void addInfo(const css::beans::PropertyValue &_rInfo)
add an Info to the sequence which will be appended to the data source
Definition: xmlfilter.hxx:108
const Reference< XPropertySet > & getDataSource() const
Definition: xmlfilter.hxx:97
virtual ~OXMLServerDatabase() override
OXMLServerDatabase(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_DATABASE_NAME
XML_HOSTNAME
XML_PORT
XML_LOCAL_SOCKET
XML_TYPE
constexpr OUStringLiteral PROPERTY_URL(u"URL")
#define XMLOFF_WARN_UNKNOWN(area, rIter)
constexpr sal_Int32 TOKEN_MASK