merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / filter / xml / xmlServerDatabase.cxx
blobc130e4abd88560b05307b3a7af04e08a9856b9ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlServerDatabase.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBA_XMLSERVERDATABASE_HXX_INCLUDED
34 #include "xmlServerDatabase.hxx"
35 #endif
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
38 #endif
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
41 #endif
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
44 #endif
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
47 #endif
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
50 #endif
51 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
52 #include "xmlstrings.hrc"
53 #endif
54 #ifndef _TOOLS_DEBUG_HXX
55 #include <tools/debug.hxx>
56 #endif
57 #ifndef TOOLS_DIAGNOSE_EX_H
58 #include <tools/diagnose_ex.h>
59 #endif
61 namespace dbaxml
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::xml::sax;
65 DBG_NAME(OXMLServerDatabase)
67 OXMLServerDatabase::OXMLServerDatabase( ODBFilter& rImport,
68 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
69 const Reference< XAttributeList > & _xAttrList) :
70 SvXMLImportContext( rImport, nPrfx, _sLocalName )
72 DBG_CTOR(OXMLServerDatabase,NULL);
74 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
75 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
76 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
78 Reference<XPropertySet> xDataSource = rImport.getDataSource();
80 PropertyValue aProperty;
82 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
83 ::rtl::OUString sType,sHostName,sPortNumber,sDatabaseName;
84 for(sal_Int16 i = 0; i < nLength; ++i)
86 ::rtl::OUString sLocalName;
87 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
88 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
89 const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
91 switch( rTokenMap.Get( nPrefix, sLocalName ) )
93 case XML_TOK_DB_TYPE:
94 sType = sValue;
95 break;
96 case XML_TOK_HOSTNAME:
97 sHostName = sValue;
98 break;
99 case XML_TOK_PORT:
100 sPortNumber = sValue;
101 break;
102 case XML_TOK_LOCAL_SOCKET:
103 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LocalSocket"));
104 aProperty.Value <<= sValue;
105 rImport.addInfo(aProperty);
106 break;
107 case XML_TOK_DATABASE_NAME:
108 sDatabaseName = sValue;
109 break;
112 if ( sType.getLength() )
114 ::rtl::OUStringBuffer sURL;
115 if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysql:jdbc" ) )
116 || sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysqlc" ) )
117 || sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysql:mysqlc" ) )
120 sURL.append( sType );
121 sURL.append( sal_Unicode( ':' ) );
122 sURL.append(sHostName);
123 if ( sPortNumber.getLength() )
125 sURL.appendAscii(":");
126 sURL.append(sPortNumber);
128 if ( sDatabaseName.getLength() )
130 sURL.appendAscii("/");
131 sURL.append(sDatabaseName);
134 else if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "jdbc:oracle:thin" ) ) )
136 sURL.appendAscii("jdbc:oracle:thin:@");
137 sURL.append(sHostName);
138 if ( sPortNumber.getLength() )
140 sURL.appendAscii(":");
141 sURL.append(sPortNumber);
143 if ( sDatabaseName.getLength() )
145 sURL.appendAscii(":");
146 sURL.append(sDatabaseName);
149 else if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:address:ldap" ) ) )
151 sURL.appendAscii("sdbc:address:ldap:");
152 sURL.append(sHostName);
153 if ( sPortNumber.getLength() )
155 sURL.appendAscii(":");
156 sURL.append(sPortNumber);
159 else
161 sURL.append(sType);
162 sURL.appendAscii(":");
163 sURL.append(sHostName);
164 if ( sPortNumber.getLength() )
166 sURL.appendAscii(":");
167 sURL.append(sPortNumber);
169 if ( sDatabaseName.getLength() )
171 sURL.appendAscii(":");
172 sURL.append(sDatabaseName);
177 xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL.makeStringAndClear()));
179 catch(Exception)
181 DBG_UNHANDLED_EXCEPTION();
185 // -----------------------------------------------------------------------------
187 OXMLServerDatabase::~OXMLServerDatabase()
190 DBG_DTOR(OXMLServerDatabase,NULL);
192 // -----------------------------------------------------------------------------
194 //----------------------------------------------------------------------------
195 } // namespace dbaxml
196 // -----------------------------------------------------------------------------