nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / commontools / ParameterSubstitution.cxx
blobca96cf33140648dd0ff19eab39ac516b121d83dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 css::uno::Reference< css::uno::XComponentContext >& _rxContext ) : m_xContext(_rxContext)
34 void SAL_CALL ParameterSubstitution::initialize( const uno::Sequence< uno::Any >& _aArguments )
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 SAL_CALL ParameterSubstitution::getImplementationName( )
45 return "org.openoffice.comp.helper.ParameterSubstitution";
48 sal_Bool SAL_CALL ParameterSubstitution::supportsService( const OUString& _rServiceName )
50 return cppu::supportsService(this, _rServiceName);
53 Sequence< OUString > SAL_CALL ParameterSubstitution::getSupportedServiceNames( )
55 return { "com.sun.star.sdb.ParameterSubstitution" };
59 OUString SAL_CALL ParameterSubstitution::substituteVariables( const OUString& _sText, sal_Bool /*bSubstRequired*/ )
61 OUString sRet = _sText;
62 uno::Reference< sdbc::XConnection > xConnection = m_xConnection;
63 if ( xConnection.is() )
65 try
67 OSQLParser aParser( m_xContext );
68 OUString sErrorMessage;
69 std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,_sText);
70 if(pNode)
71 { // special handling for parameters
72 OSQLParseNode::substituteParameterNames(pNode.get());
73 OUString sNewSql;
74 pNode->parseNodeToStr( sNewSql, xConnection );
75 sRet = sNewSql;
78 catch(const Exception&)
82 return sRet;
85 OUString SAL_CALL ParameterSubstitution::reSubstituteVariables( const OUString& _sText )
87 return _sText;
90 OUString SAL_CALL ParameterSubstitution::getSubstituteVariableValue( const OUString& /*variable*/ )
92 throw container::NoSuchElementException();
96 } // connectivity
98 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
99 connectivity_dbtools_ParameterSubstitution_get_implementation(
100 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
102 return cppu::acquire(new connectivity::ParameterSubstitution(context));
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */