1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "ParameterSubstitution.hxx"
20 #include "connectivity/sqlparse.hxx"
21 #include <comphelper/sequenceashashmap.hxx>
22 #include <cppuhelper/supportsservice.hxx>
24 namespace connectivity
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::sdbc
;
28 using namespace ::com::sun::star::lang
;
29 using namespace ::com::sun::star
;
31 ParameterSubstitution::ParameterSubstitution(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
) : m_xContext(_rxContext
)
34 void SAL_CALL
ParameterSubstitution::initialize( const uno::Sequence
< uno::Any
>& _aArguments
) throw (uno::Exception
, uno::RuntimeException
, std::exception
)
36 ::osl::MutexGuard
aGuard(m_aMutex
);
37 comphelper::SequenceAsHashMap
aArgs(_aArguments
);
38 uno::Reference
< sdbc::XConnection
> xConnection
;
39 xConnection
= aArgs
.getUnpackedValueOrDefault("ActiveConnection",xConnection
);
40 m_xConnection
= xConnection
;
43 OUString
ParameterSubstitution::getImplementationName_Static( ) throw(RuntimeException
)
45 return OUString("org.openoffice.comp.helper.ParameterSubstitution");
48 OUString SAL_CALL
ParameterSubstitution::getImplementationName( ) throw(RuntimeException
, std::exception
)
50 return getImplementationName_Static();
53 sal_Bool SAL_CALL
ParameterSubstitution::supportsService( const OUString
& _rServiceName
) throw(RuntimeException
, std::exception
)
55 return cppu::supportsService(this, _rServiceName
);
58 Sequence
< OUString
> SAL_CALL
ParameterSubstitution::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
60 return getSupportedServiceNames_Static();
63 Sequence
< OUString
> ParameterSubstitution::getSupportedServiceNames_Static( ) throw (RuntimeException
)
65 Sequence
< OUString
> aSNS( 1 );
66 aSNS
[0] = "com.sun.star.sdb.ParameterSubstitution";
71 Reference
< XInterface
> ParameterSubstitution::create(const Reference
< XComponentContext
>& _xContext
)
73 return *(new ParameterSubstitution(_xContext
));
76 OUString SAL_CALL
ParameterSubstitution::substituteVariables( const OUString
& _sText
, sal_Bool
/*bSubstRequired*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
78 OUString sRet
= _sText
;
79 uno::Reference
< sdbc::XConnection
> xConnection
= m_xConnection
;
80 if ( xConnection
.is() )
84 OSQLParser
aParser( m_xContext
);
85 OUString sErrorMessage
;
87 OSQLParseNode
* pNode
= aParser
.parseTree(sErrorMessage
,_sText
);
89 { // special handling for parameters
90 OSQLParseNode::substituteParameterNames(pNode
);
91 pNode
->parseNodeToStr( sNewSql
, xConnection
);
96 catch(const Exception
&)
103 OUString SAL_CALL
ParameterSubstitution::reSubstituteVariables( const OUString
& _sText
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
108 OUString SAL_CALL
ParameterSubstitution::getSubstituteVariableValue( const OUString
& /*variable*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
110 throw container::NoSuchElementException();
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */