1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "flat/EDriver.hxx"
31 #include "flat/EConnection.hxx"
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "connectivity/dbexception.hxx"
34 #include <comphelper/sequence.hxx>
35 #include "resource/common_res.hrc"
36 #include "resource/sharedresources.hxx"
37 
38 
39 using namespace connectivity::flat;
40 using namespace connectivity::file;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::sdbcx;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::lang;
46 
47 
48 // static ServiceInfo
49 //------------------------------------------------------------------------------
50 rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
51 {
52 	return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.flat.ODriver");
53 }
54 
55 //------------------------------------------------------------------
56 ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
57 {
58 	return getImplementationName_Static();
59 }
60 
61 //------------------------------------------------------------------
62 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  SAL_CALL connectivity::flat::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
63 {
64 	return *(new ODriver(_rxFactory));
65 }
66 // --------------------------------------------------------------------------------
67 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
68 {
69 	::osl::MutexGuard aGuard( m_aMutex );
70 	if (ODriver_BASE::rBHelper.bDisposed)
71        throw DisposedException();
72 
73 	if ( ! acceptsURL(url) )
74 		return NULL;
75 
76 	OFlatConnection* pCon = new OFlatConnection(this);
77 	pCon->construct(url,info);
78         Reference< XConnection > xCon = pCon;
79         m_xConnections.push_back(WeakReferenceHelper(*pCon));
80 
81 	return xCon;
82 }
83 // --------------------------------------------------------------------------------
84 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
85                 throw(SQLException, RuntimeException)
86 {
87 	return url.compareTo(::rtl::OUString::createFromAscii("sdbc:flat:"),10) == 0;
88 }
89 // -----------------------------------------------------------------------------
90 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
91 {
92 	if ( acceptsURL(url) )
93 	{
94 		::std::vector< DriverPropertyInfo > aDriverInfo;
95 
96 		Sequence< ::rtl::OUString > aBoolean(2);
97 		aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
98 		aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
99 
100 		aDriverInfo.push_back(DriverPropertyInfo(
101 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter"))
102 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field separator."))
103 				,sal_False
104 				,::rtl::OUString()
105 				,Sequence< ::rtl::OUString >())
106 				);
107 		aDriverInfo.push_back(DriverPropertyInfo(
108 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine"))
109 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text contains headers."))
110 				,sal_False
111 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
112 				,aBoolean)
113 				);
114 		aDriverInfo.push_back(DriverPropertyInfo(
115 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter"))
116 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text separator."))
117 				,sal_False
118 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
119 				,aBoolean)
120 				);
121 		aDriverInfo.push_back(DriverPropertyInfo(
122 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter"))
123 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Decimal separator."))
124 				,sal_False
125 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
126 				,aBoolean)
127 				);
128 		aDriverInfo.push_back(DriverPropertyInfo(
129 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter"))
130 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thousands separator."))
131 				,sal_False
132 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
133 				,aBoolean)
134 				);
135 		return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ),
136                                              Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()));
137 	}
138 	::connectivity::SharedResources aResources;
139     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
140 	::dbtools::throwGenericSQLException(sMessage ,*this);
141 	return Sequence< DriverPropertyInfo >();
142 }
143 // -----------------------------------------------------------------------------
144 
145 
146