Branch data 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 ::rtl::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 : ::rtl::OUString sType,sHostName,sPortNumber,sDatabaseName;
53 [ # # ]: 0 : for(sal_Int16 i = 0; i < nLength; ++i)
54 : : {
55 : 0 : ::rtl::OUString sLocalName;
56 [ # # ][ # # ]: 0 : const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
57 [ # # ]: 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
58 [ # # ][ # # ]: 0 : const rtl::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 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("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 : ::rtl::OUStringBuffer sURL;
84 [ # # ][ # # ]: 0 : if ( sType == "sdbc:mysql:jdbc" || sType == "sdbc:mysqlc" || sType == "sdbc:mysql:mysqlc" )
[ # # ][ # # ]
85 : : {
86 [ # # ]: 0 : sURL.append( sType );
87 [ # # ]: 0 : sURL.append( sal_Unicode( ':' ) );
88 [ # # ]: 0 : sURL.append(sHostName);
89 [ # # ]: 0 : if ( !sPortNumber.isEmpty() )
90 : : {
91 [ # # ]: 0 : sURL.appendAscii(":");
92 [ # # ]: 0 : sURL.append(sPortNumber);
93 : : }
94 [ # # ]: 0 : if ( !sDatabaseName.isEmpty() )
95 : : {
96 [ # # ]: 0 : sURL.appendAscii("/");
97 [ # # ]: 0 : sURL.append(sDatabaseName);
98 : : }
99 : : }
100 [ # # ]: 0 : else if ( sType == "jdbc:oracle:thin" )
101 : : {
102 [ # # ]: 0 : sURL.appendAscii("jdbc:oracle:thin:@");
103 [ # # ]: 0 : sURL.append(sHostName);
104 [ # # ]: 0 : if ( !sPortNumber.isEmpty() )
105 : : {
106 [ # # ]: 0 : sURL.appendAscii(":");
107 [ # # ]: 0 : sURL.append(sPortNumber);
108 : : }
109 [ # # ]: 0 : if ( !sDatabaseName.isEmpty() )
110 : : {
111 [ # # ]: 0 : sURL.appendAscii(":");
112 [ # # ]: 0 : sURL.append(sDatabaseName);
113 : : }
114 : : }
115 [ # # ]: 0 : else if ( sType == "sdbc:address:ldap" )
116 : : {
117 [ # # ]: 0 : sURL.appendAscii("sdbc:address:ldap:");
118 [ # # ]: 0 : sURL.append(sHostName);
119 [ # # ]: 0 : if ( !sPortNumber.isEmpty() )
120 : : {
121 [ # # ]: 0 : sURL.appendAscii(":");
122 [ # # ]: 0 : sURL.append(sPortNumber);
123 : : }
124 : : }
125 : : else
126 : : {
127 [ # # ]: 0 : sURL.append(sType);
128 [ # # ]: 0 : sURL.appendAscii(":");
129 [ # # ]: 0 : sURL.append(sHostName);
130 [ # # ]: 0 : if ( !sPortNumber.isEmpty() )
131 : : {
132 [ # # ]: 0 : sURL.appendAscii(":");
133 [ # # ]: 0 : sURL.append(sPortNumber);
134 : : }
135 [ # # ]: 0 : if ( !sDatabaseName.isEmpty() )
136 : : {
137 [ # # ]: 0 : sURL.appendAscii(":");
138 [ # # ]: 0 : sURL.append(sDatabaseName);
139 : : }
140 : : }
141 : : try
142 : : {
143 [ # # ][ # # ]: 0 : xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL.makeStringAndClear()));
[ # # ][ # # ]
[ # # ][ # # ]
144 : : }
145 [ # # ]: 0 : catch(const Exception&)
146 : : {
147 : : DBG_UNHANDLED_EXCEPTION();
148 : 0 : }
149 : 0 : }
150 : 0 : }
151 : : // -----------------------------------------------------------------------------
152 : :
153 : 0 : OXMLServerDatabase::~OXMLServerDatabase()
154 : : {
155 : :
156 : : DBG_DTOR(OXMLServerDatabase,NULL);
157 [ # # ]: 0 : }
158 : : // -----------------------------------------------------------------------------
159 : :
160 : : //----------------------------------------------------------------------------
161 : : } // namespace dbaxml
162 : : // -----------------------------------------------------------------------------
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|