LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/commontools - ParamterSubstitution.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 47 0.0 %
Date: 2012-12-17 Functions: 0 11 0.0 %
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             : 
      23             : namespace connectivity
      24             : {
      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;
      29             : 
      30           0 :     ParameterSubstitution::ParameterSubstitution(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ) : m_xContext(_rxContext)
      31             :     {
      32           0 :     }
      33           0 :     void SAL_CALL ParameterSubstitution::initialize( const uno::Sequence< uno::Any >& _aArguments ) throw (uno::Exception, uno::RuntimeException)
      34             :     {
      35           0 :         ::osl::MutexGuard aGuard(m_aMutex);
      36           0 :         comphelper::SequenceAsHashMap aArgs(_aArguments);
      37           0 :         uno::Reference< sdbc::XConnection > xConnection;
      38           0 :         xConnection = aArgs.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),xConnection);
      39           0 :         m_xConnection = xConnection;
      40           0 :     }
      41             :     //------------------------------------------------------------------------------
      42           0 :     rtl::OUString ParameterSubstitution::getImplementationName_Static(  ) throw(RuntimeException)
      43             :     {
      44           0 :         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.ParameterSubstitution"));
      45             :     }
      46             :     //------------------------------------------------------------------------------
      47           0 :     ::rtl::OUString SAL_CALL ParameterSubstitution::getImplementationName(  ) throw(RuntimeException)
      48             :     {
      49           0 :         return getImplementationName_Static();
      50             :     }
      51             :     //------------------------------------------------------------------
      52           0 :     sal_Bool SAL_CALL ParameterSubstitution::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
      53             :     {
      54           0 :         Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
      55           0 :         const ::rtl::OUString* pSupported = aSupported.getConstArray();
      56           0 :         const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
      57           0 :         for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
      58             :             ;
      59             : 
      60           0 :         return pSupported != pEnd;
      61             :     }
      62             :     //------------------------------------------------------------------
      63           0 :     Sequence< ::rtl::OUString > SAL_CALL ParameterSubstitution::getSupportedServiceNames(  ) throw(RuntimeException)
      64             :     {
      65           0 :         return getSupportedServiceNames_Static();
      66             :     }
      67             :     //------------------------------------------------------------------
      68           0 :     Sequence< ::rtl::OUString > ParameterSubstitution::getSupportedServiceNames_Static(  ) throw (RuntimeException)
      69             :     {
      70           0 :         Sequence< ::rtl::OUString > aSNS( 1 );
      71           0 :         aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ParameterSubstitution"));
      72           0 :         return aSNS;
      73             :     }
      74             : 
      75             :     //------------------------------------------------------------------
      76           0 :     Reference< XInterface >  ParameterSubstitution::create(const Reference< XComponentContext >& _xContext)
      77             :     {
      78           0 :         return *(new ParameterSubstitution(_xContext));
      79             :     }
      80             :     //------------------------------------------------------------------
      81           0 :     ::rtl::OUString SAL_CALL ParameterSubstitution::substituteVariables( const ::rtl::OUString& _sText, ::sal_Bool /*bSubstRequired*/ ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
      82             :     {
      83           0 :         ::rtl::OUString sRet = _sText;
      84           0 :         uno::Reference< sdbc::XConnection > xConnection = m_xConnection;
      85           0 :         if ( xConnection.is() )
      86             :         {
      87             :             try
      88             :             {
      89           0 :                 OSQLParser aParser( m_xContext );
      90           0 :                 ::rtl::OUString sErrorMessage;
      91           0 :                 ::rtl::OUString sNewSql;
      92           0 :                 OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,_sText);
      93           0 :                 if(pNode)
      94             :                 {   // special handling for parameters
      95           0 :                     OSQLParseNode::substituteParameterNames(pNode);
      96           0 :                     pNode->parseNodeToStr( sNewSql, xConnection );
      97           0 :                     delete pNode;
      98           0 :                     sRet = sNewSql;
      99           0 :                 }
     100             :             }
     101           0 :             catch(const Exception&)
     102             :             {
     103             :             }
     104             :         }
     105           0 :         return sRet;
     106             :     }
     107             :     //------------------------------------------------------------------
     108           0 :     ::rtl::OUString SAL_CALL ParameterSubstitution::reSubstituteVariables( const ::rtl::OUString& _sText ) throw (::com::sun::star::uno::RuntimeException)
     109             :     {
     110           0 :         return _sText;
     111             :     }
     112             :     //------------------------------------------------------------------
     113           0 :     ::rtl::OUString SAL_CALL ParameterSubstitution::getSubstituteVariableValue( const ::rtl::OUString& /*variable*/ ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
     114             :     {
     115           0 :         throw container::NoSuchElementException();
     116             :     }
     117             :     //------------------------------------------------------------------
     118             : 
     119             : 
     120             : // ==================================
     121             : } // connectivity
     122             : // ==================================
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10