bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / commontools / ParameterSubstitution.cxx
bloba8efa6c6a6942908d2647939e9f23f7c5c6c748d
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 ParameterSubstitution::getImplementationName_Static( )
45 return OUString("org.openoffice.comp.helper.ParameterSubstitution");
48 OUString SAL_CALL ParameterSubstitution::getImplementationName( )
50 return getImplementationName_Static();
53 sal_Bool SAL_CALL ParameterSubstitution::supportsService( const OUString& _rServiceName )
55 return cppu::supportsService(this, _rServiceName);
58 Sequence< OUString > SAL_CALL ParameterSubstitution::getSupportedServiceNames( )
60 return getSupportedServiceNames_Static();
63 Sequence< OUString > ParameterSubstitution::getSupportedServiceNames_Static( )
65 Sequence<OUString> aSNS { "com.sun.star.sdb.ParameterSubstitution" };
66 return aSNS;
70 Reference< XInterface > ParameterSubstitution::create(const Reference< XComponentContext >& _xContext)
72 return *(new ParameterSubstitution(_xContext));
75 OUString SAL_CALL ParameterSubstitution::substituteVariables( const OUString& _sText, sal_Bool /*bSubstRequired*/ )
77 OUString sRet = _sText;
78 uno::Reference< sdbc::XConnection > xConnection = m_xConnection;
79 if ( xConnection.is() )
81 try
83 OSQLParser aParser( m_xContext );
84 OUString sErrorMessage;
85 OUString sNewSql;
86 std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,_sText);
87 if(pNode)
88 { // special handling for parameters
89 OSQLParseNode::substituteParameterNames(pNode.get());
90 pNode->parseNodeToStr( sNewSql, xConnection );
91 sRet = sNewSql;
94 catch(const Exception&)
98 return sRet;
101 OUString SAL_CALL ParameterSubstitution::reSubstituteVariables( const OUString& _sText )
103 return _sText;
106 OUString SAL_CALL ParameterSubstitution::getSubstituteVariableValue( const OUString& /*variable*/ )
108 throw container::NoSuchElementException();
112 } // connectivity
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */