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>
23 namespace connectivity
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::sdbc
;
27 using namespace ::com::sun::star::lang
;
28 using namespace ::com::sun::star
;
30 ParameterSubstitution::ParameterSubstitution(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
) : m_xContext(_rxContext
)
33 void SAL_CALL
ParameterSubstitution::initialize( const uno::Sequence
< uno::Any
>& _aArguments
) throw (uno::Exception
, uno::RuntimeException
)
35 ::osl::MutexGuard
aGuard(m_aMutex
);
36 comphelper::SequenceAsHashMap
aArgs(_aArguments
);
37 uno::Reference
< sdbc::XConnection
> xConnection
;
38 xConnection
= aArgs
.getUnpackedValueOrDefault(OUString("ActiveConnection"),xConnection
);
39 m_xConnection
= xConnection
;
41 //------------------------------------------------------------------------------
42 OUString
ParameterSubstitution::getImplementationName_Static( ) throw(RuntimeException
)
44 return OUString("org.openoffice.comp.helper.ParameterSubstitution");
46 //------------------------------------------------------------------------------
47 OUString SAL_CALL
ParameterSubstitution::getImplementationName( ) throw(RuntimeException
)
49 return getImplementationName_Static();
51 //------------------------------------------------------------------
52 sal_Bool SAL_CALL
ParameterSubstitution::supportsService( const OUString
& _rServiceName
) throw(RuntimeException
)
54 Sequence
< OUString
> aSupported(getSupportedServiceNames());
55 const OUString
* pSupported
= aSupported
.getConstArray();
56 const OUString
* pEnd
= pSupported
+ aSupported
.getLength();
57 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
60 return pSupported
!= pEnd
;
62 //------------------------------------------------------------------
63 Sequence
< OUString
> SAL_CALL
ParameterSubstitution::getSupportedServiceNames( ) throw(RuntimeException
)
65 return getSupportedServiceNames_Static();
67 //------------------------------------------------------------------
68 Sequence
< OUString
> ParameterSubstitution::getSupportedServiceNames_Static( ) throw (RuntimeException
)
70 Sequence
< OUString
> aSNS( 1 );
71 aSNS
[0] = "com.sun.star.sdb.ParameterSubstitution";
75 //------------------------------------------------------------------
76 Reference
< XInterface
> ParameterSubstitution::create(const Reference
< XComponentContext
>& _xContext
)
78 return *(new ParameterSubstitution(_xContext
));
80 //------------------------------------------------------------------
81 OUString SAL_CALL
ParameterSubstitution::substituteVariables( const OUString
& _sText
, ::sal_Bool
/*bSubstRequired*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
)
83 OUString sRet
= _sText
;
84 uno::Reference
< sdbc::XConnection
> xConnection
= m_xConnection
;
85 if ( xConnection
.is() )
89 OSQLParser
aParser( m_xContext
);
90 OUString sErrorMessage
;
92 OSQLParseNode
* pNode
= aParser
.parseTree(sErrorMessage
,_sText
);
94 { // special handling for parameters
95 OSQLParseNode::substituteParameterNames(pNode
);
96 pNode
->parseNodeToStr( sNewSql
, xConnection
);
101 catch(const Exception
&)
107 //------------------------------------------------------------------
108 OUString SAL_CALL
ParameterSubstitution::reSubstituteVariables( const OUString
& _sText
) throw (::com::sun::star::uno::RuntimeException
)
112 //------------------------------------------------------------------
113 OUString SAL_CALL
ParameterSubstitution::getSubstituteVariableValue( const OUString
& /*variable*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
)
115 throw container::NoSuchElementException();
117 //------------------------------------------------------------------
120 // ==================================
122 // ==================================
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */