Line data Source code
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 <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>
29 :
30 : namespace dbaxml
31 : {
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::xml::sax;
34 : DBG_NAME(OXMLServerDatabase)
35 :
36 0 : OXMLServerDatabase::OXMLServerDatabase( ODBFilter& rImport,
37 : sal_uInt16 nPrfx, const OUString& _sLocalName,
38 : const Reference< XAttributeList > & _xAttrList) :
39 0 : SvXMLImportContext( rImport, nPrfx, _sLocalName )
40 : {
41 : DBG_CTOR(OXMLServerDatabase,NULL);
42 :
43 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
44 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
45 0 : const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
46 :
47 0 : Reference<XPropertySet> xDataSource = rImport.getDataSource();
48 :
49 0 : PropertyValue aProperty;
50 :
51 0 : const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
52 0 : OUString sType,sHostName,sPortNumber,sDatabaseName;
53 0 : for(sal_Int16 i = 0; i < nLength; ++i)
54 : {
55 0 : OUString sLocalName;
56 0 : const OUString sAttrName = _xAttrList->getNameByIndex( i );
57 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
58 0 : const OUString sValue = _xAttrList->getValueByIndex( i );
59 :
60 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
61 : {
62 : case XML_TOK_DB_TYPE:
63 0 : sType = sValue;
64 0 : break;
65 : case XML_TOK_HOSTNAME:
66 0 : sHostName = sValue;
67 0 : break;
68 : case XML_TOK_PORT:
69 0 : sPortNumber = sValue;
70 0 : break;
71 : case XML_TOK_LOCAL_SOCKET:
72 0 : aProperty.Name = OUString("LocalSocket");
73 0 : aProperty.Value <<= sValue;
74 0 : rImport.addInfo(aProperty);
75 0 : break;
76 : case XML_TOK_DATABASE_NAME:
77 0 : sDatabaseName = sValue;
78 0 : break;
79 : }
80 0 : }
81 0 : if ( !sType.isEmpty() )
82 : {
83 0 : OUStringBuffer sURL;
84 0 : if ( sType == "sdbc:mysql:jdbc" || sType == "sdbc:mysqlc" || sType == "sdbc:mysql:mysqlc" )
85 : {
86 0 : sURL.append( sType + ":" + sHostName);
87 0 : if ( !sPortNumber.isEmpty() )
88 : {
89 0 : sURL.append(":" + sPortNumber);
90 : }
91 0 : if ( !sDatabaseName.isEmpty() )
92 : {
93 0 : sURL.append("/" + sDatabaseName);
94 : }
95 : }
96 0 : else if ( sType == "jdbc:oracle:thin" )
97 : {
98 0 : sURL.append("jdbc:oracle:thin:@" + sHostName);
99 0 : if ( !sPortNumber.isEmpty() )
100 : {
101 0 : sURL.append(":" + sPortNumber);
102 : }
103 0 : if ( !sDatabaseName.isEmpty() )
104 : {
105 0 : sURL.append(":" + sDatabaseName);
106 : }
107 : }
108 0 : else if ( sType == "sdbc:address:ldap" )
109 : {
110 0 : sURL.append("sdbc:address:ldap:" + sHostName);
111 0 : if ( !sPortNumber.isEmpty() )
112 : {
113 0 : sURL.append(":" + sPortNumber);
114 : }
115 : }
116 : else
117 : {
118 0 : sURL.append(sType + ":" + sHostName);
119 0 : if ( !sPortNumber.isEmpty() )
120 : {
121 0 : sURL.append(":" + sPortNumber);
122 : }
123 0 : if ( !sDatabaseName.isEmpty() )
124 : {
125 0 : sURL.append(":" + sDatabaseName);
126 : }
127 : }
128 : try
129 : {
130 0 : xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL.makeStringAndClear()));
131 : }
132 0 : catch(const Exception&)
133 : {
134 : DBG_UNHANDLED_EXCEPTION();
135 0 : }
136 0 : }
137 0 : }
138 : // -----------------------------------------------------------------------------
139 :
140 0 : OXMLServerDatabase::~OXMLServerDatabase()
141 : {
142 :
143 : DBG_DTOR(OXMLServerDatabase,NULL);
144 0 : }
145 : // -----------------------------------------------------------------------------
146 :
147 : //----------------------------------------------------------------------------
148 : } // namespace dbaxml
149 : // -----------------------------------------------------------------------------
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|