LCOV - code coverage report
Current view: top level - connectivity/source/commontools - ParamterSubstitution.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 43 4.7 %
Date: 2015-06-13 12:38:46 Functions: 1 11 9.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #include "ParameterSubstitution.hxx"
      20             : #include <connectivity/sqlparse.hxx>
      21             : #include <comphelper/sequenceashashmap.hxx>
      22             : #include <cppuhelper/supportsservice.hxx>
      23             : 
      24             : namespace connectivity
      25             : {
      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;
      30             : 
      31           0 :     ParameterSubstitution::ParameterSubstitution(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ) : m_xContext(_rxContext)
      32             :     {
      33           0 :     }
      34           0 :     void SAL_CALL ParameterSubstitution::initialize( const uno::Sequence< uno::Any >& _aArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
      35             :     {
      36           0 :         ::osl::MutexGuard aGuard(m_aMutex);
      37           0 :         comphelper::SequenceAsHashMap aArgs(_aArguments);
      38           0 :         uno::Reference< sdbc::XConnection > xConnection;
      39           0 :         xConnection = aArgs.getUnpackedValueOrDefault("ActiveConnection",xConnection);
      40           0 :         m_xConnection = xConnection;
      41           0 :     }
      42             : 
      43           1 :     OUString ParameterSubstitution::getImplementationName_Static(  ) throw(RuntimeException)
      44             :     {
      45           1 :         return OUString("org.openoffice.comp.helper.ParameterSubstitution");
      46             :     }
      47             : 
      48           0 :     OUString SAL_CALL ParameterSubstitution::getImplementationName(  ) throw(RuntimeException, std::exception)
      49             :     {
      50           0 :         return getImplementationName_Static();
      51             :     }
      52             : 
      53           0 :     sal_Bool SAL_CALL ParameterSubstitution::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
      54             :     {
      55           0 :         return cppu::supportsService(this, _rServiceName);
      56             :     }
      57             : 
      58           0 :     Sequence< OUString > SAL_CALL ParameterSubstitution::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
      59             :     {
      60           0 :         return getSupportedServiceNames_Static();
      61             :     }
      62             : 
      63           0 :     Sequence< OUString > ParameterSubstitution::getSupportedServiceNames_Static(  ) throw (RuntimeException)
      64             :     {
      65           0 :         Sequence< OUString > aSNS( 1 );
      66           0 :         aSNS[0] = "com.sun.star.sdb.ParameterSubstitution";
      67           0 :         return aSNS;
      68             :     }
      69             : 
      70             : 
      71           0 :     Reference< XInterface >  ParameterSubstitution::create(const Reference< XComponentContext >& _xContext)
      72             :     {
      73           0 :         return *(new ParameterSubstitution(_xContext));
      74             :     }
      75             : 
      76           0 :     OUString SAL_CALL ParameterSubstitution::substituteVariables( const OUString& _sText, sal_Bool /*bSubstRequired*/ ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception)
      77             :     {
      78           0 :         OUString sRet = _sText;
      79           0 :         uno::Reference< sdbc::XConnection > xConnection = m_xConnection;
      80           0 :         if ( xConnection.is() )
      81             :         {
      82             :             try
      83             :             {
      84           0 :                 OSQLParser aParser( m_xContext );
      85           0 :                 OUString sErrorMessage;
      86           0 :                 OUString sNewSql;
      87           0 :                 OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,_sText);
      88           0 :                 if(pNode)
      89             :                 {   // special handling for parameters
      90           0 :                     OSQLParseNode::substituteParameterNames(pNode);
      91           0 :                     pNode->parseNodeToStr( sNewSql, xConnection );
      92           0 :                     delete pNode;
      93           0 :                     sRet = sNewSql;
      94           0 :                 }
      95             :             }
      96           0 :             catch(const Exception&)
      97             :             {
      98             :             }
      99             :         }
     100           0 :         return sRet;
     101             :     }
     102             : 
     103           0 :     OUString SAL_CALL ParameterSubstitution::reSubstituteVariables( const OUString& _sText ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     104             :     {
     105           0 :         return _sText;
     106             :     }
     107             : 
     108           0 :     OUString SAL_CALL ParameterSubstitution::getSubstituteVariableValue( const OUString& /*variable*/ ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception)
     109             :     {
     110           0 :         throw container::NoSuchElementException();
     111             :     }
     112             : 
     113             : 
     114             : 
     115             : 
     116             : } // connectivity
     117             : 
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11