LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/services - substitutepathvars.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 12 41.7 %
Date: 2012-12-27 Functions: 7 16 43.8 %
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             : 
      20             : #ifndef __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_
      21             : #define __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_
      22             : 
      23             : /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
      24             :                with solaris headers ...
      25             : */
      26             : #include <vector>
      27             : #include <list>
      28             : #include <boost/unordered_map.hpp>
      29             : 
      30             : #include <threadhelp/threadhelpbase.hxx>
      31             : #include <macros/generic.hxx>
      32             : #include <macros/xinterface.hxx>
      33             : #include <macros/xtypeprovider.hxx>
      34             : #include <macros/xserviceinfo.hxx>
      35             : #include <stdtypes.h>
      36             : 
      37             : #include <com/sun/star/lang/XServiceInfo.hpp>
      38             : #include <com/sun/star/lang/XTypeProvider.hpp>
      39             : #include <com/sun/star/container/NoSuchElementException.hpp>
      40             : #include <com/sun/star/util/XStringSubstitution.hpp>
      41             : 
      42             : #include <cppuhelper/implbase2.hxx>
      43             : #include <rtl/ustring.hxx>
      44             : #include <unotools/configitem.hxx>
      45             : #include <tools/link.hxx>
      46             : #include <i18npool/lang.h>
      47             : 
      48             : namespace framework
      49             : {
      50             : 
      51             : // Must be zero value based
      52             : enum EnvironmentType
      53             : {
      54             :         ET_HOST = 0             ,
      55             :         ET_YPDOMAIN             ,
      56             :         ET_DNSDOMAIN    ,
      57             :         ET_NTDOMAIN             ,
      58             :         ET_OS                   ,
      59             :         ET_UNKNOWN              ,
      60             :         ET_COUNT
      61             : };
      62             : 
      63             : // Must be zero value based
      64             : enum OperatingSystem
      65             : {
      66             :         OS_WINDOWS = 0,
      67             :         OS_UNIX         ,
      68             :         OS_SOLARIS      ,
      69             :         OS_LINUX        ,
      70             :         OS_UNKNOWN      ,
      71             :         OS_COUNT
      72             : };
      73             : 
      74           0 : struct SubstituteRule
      75             : {
      76           0 :     SubstituteRule() {}
      77           0 :     SubstituteRule( const rtl::OUString& aVarName,
      78             :                     const rtl::OUString& aValue,
      79             :                     const com::sun::star::uno::Any& aVal,
      80             :                     EnvironmentType aType ) :
      81           0 :         aSubstVariable( aVarName ), aSubstValue( aValue ), aEnvValue( aVal ), aEnvType( aType ) {}
      82             : 
      83             :     rtl::OUString            aSubstVariable;
      84             :     rtl::OUString            aSubstValue;
      85             :     com::sun::star::uno::Any aEnvValue;
      86             :     EnvironmentType          aEnvType;
      87             : };
      88             : 
      89             : struct SubstitutePathNotify
      90             : {
      91             :     SubstitutePathNotify() {};
      92             : 
      93             :     const com::sun::star::uno::Sequence<rtl::OUString> aPropertyNames;
      94             : };
      95             : 
      96          26 : class SubstituteVariables : public ::boost::unordered_map< ::rtl::OUString,
      97             :                                                     SubstituteRule,
      98             :                                                     OUStringHashCode,
      99             :                                                     ::std::equal_to< ::rtl::OUString > >
     100             : {
     101             :     public:
     102             :         inline void free()
     103             :         {
     104             :             SubstituteVariables().swap( *this );
     105             :         }
     106             : };
     107             : 
     108             : typedef std::vector< SubstituteRule > SubstituteRuleVector;
     109             : class SubstitutePathVariables_Impl : public utl::ConfigItem
     110             : {
     111             :     public:
     112             :         SubstitutePathVariables_Impl( const Link& aNotifyLink );
     113             :         virtual ~SubstitutePathVariables_Impl();
     114             : 
     115             :         static OperatingSystem GetOperatingSystemFromString( const rtl::OUString& );
     116             :         static EnvironmentType GetEnvTypeFromString( const rtl::OUString& );
     117             : 
     118             :         void                   GetSharePointsRules( SubstituteVariables& aSubstVarMap );
     119             : 
     120             :         /** is called from the ConfigManager before application ends or from the
     121             :             PropertyChangeListener if the sub tree broadcasts changes. */
     122             :         virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
     123             :         virtual void Commit();
     124             : 
     125             :         private:
     126             :             // Wrapper methods for low-level functions
     127             :             OperatingSystem         GetOperatingSystem();
     128             :             const rtl::OUString&    GetYPDomainName();
     129             :             const rtl::OUString&    GetDNSDomainName();
     130             :             const rtl::OUString&    GetNTDomainName();
     131             :             const rtl::OUString&    GetHostName();
     132             : 
     133             :             bool                    FilterRuleSet( const SubstituteRuleVector& aRuleSet, SubstituteRule& aActiveRule );
     134             : 
     135             :             void                    ReadSharePointsFromConfiguration( com::sun::star::uno::Sequence< rtl::OUString >& aSharePointsSeq );
     136             :             void                    ReadSharePointRuleSetFromConfiguration( const rtl::OUString& aSharePointName,
     137             :                                                                                                                                 const rtl::OUString& aSharePointNodeName,
     138             :                                                                                                                                 SubstituteRuleVector& aRuleSet );
     139             : 
     140             :             // Stored values for domains and host
     141             :             bool                    m_bYPDomainRetrieved;
     142             :             rtl::OUString           m_aYPDomain;
     143             :             bool                    m_bDNSDomainRetrieved;
     144             :             rtl::OUString           m_aDNSDomain;
     145             :             bool                    m_bNTDomainRetrieved;
     146             :             rtl::OUString           m_aNTDomain;
     147             :             bool                    m_bHostRetrieved;
     148             :             rtl::OUString           m_aHost;
     149             :             bool                    m_bOSRetrieved;
     150             :             OperatingSystem         m_eOSType;
     151             : 
     152             :             Link                    m_aListenerNotify;
     153             :             const rtl::OUString     m_aSharePointsNodeName;
     154             :             const rtl::OUString     m_aDirPropertyName;
     155             :             const rtl::OUString     m_aEnvPropertyName;
     156             :             const rtl::OUString     m_aLevelSep;
     157             : };
     158             : 
     159             : enum PreDefVariable
     160             : {
     161             :     PREDEFVAR_INST,
     162             :     PREDEFVAR_PROG,
     163             :     PREDEFVAR_USER,
     164             :     PREDEFVAR_WORK,
     165             :     PREDEFVAR_HOME,
     166             :     PREDEFVAR_TEMP,
     167             :     PREDEFVAR_PATH,
     168             :     PREDEFVAR_LANG,
     169             :     PREDEFVAR_LANGID,
     170             :     PREDEFVAR_VLANG,
     171             :     PREDEFVAR_INSTPATH,
     172             :     PREDEFVAR_PROGPATH,
     173             :     PREDEFVAR_USERPATH,
     174             :     PREDEFVAR_INSTURL,
     175             :     PREDEFVAR_PROGURL,
     176             :     PREDEFVAR_USERURL,
     177             :     PREDEFVAR_WORKDIRURL,
     178             :     // New variable of hierachy service (#i32656#)
     179             :     PREDEFVAR_BASEINSTURL,
     180             :     PREDEFVAR_USERDATAURL,
     181             :     PREDEFVAR_BRANDBASEURL,
     182             :     PREDEFVAR_COUNT
     183             : };
     184             : 
     185          26 : struct PredefinedPathVariables
     186             : {
     187             :     // Predefined variables supported by substitute variables
     188             :     LanguageType    m_eLanguageType;                    // Lanuage type of Office
     189             :     rtl::OUString   m_FixedVar[ PREDEFVAR_COUNT ];      // Variable value access by PreDefVariable
     190             :     rtl::OUString   m_FixedVarNames[ PREDEFVAR_COUNT ]; // Variable name access by PreDefVariable
     191             : };
     192             : 
     193             : struct ReSubstFixedVarOrder
     194             : {
     195             :     sal_Int32       nVarValueLength;
     196             :     PreDefVariable  eVariable;
     197             : 
     198        1070 :     bool operator< ( const ReSubstFixedVarOrder& aFixedVarOrder ) const
     199             :     {
     200             :         // Reverse operator< to have high to low ordering
     201        1070 :         return ( nVarValueLength > aFixedVarOrder.nVarValueLength );
     202             :     }
     203             : };
     204             : 
     205           0 : struct ReSubstUserVarOrder
     206             : {
     207             :     sal_Int32       nVarValueLength;
     208             :     rtl::OUString   aVarName;
     209             : 
     210           0 :     bool operator< ( const ReSubstUserVarOrder& aUserVarOrder ) const
     211             :     {
     212             :         // Reverse operator< to have high to low ordering
     213           0 :         return ( nVarValueLength > aUserVarOrder.nVarValueLength );
     214             :     }
     215             : };
     216             : 
     217             : typedef std::list< ReSubstFixedVarOrder > ReSubstFixedVarOrderVector;
     218             : typedef std::list< ReSubstUserVarOrder > ReSubstUserVarOrderVector;
     219             : 
     220             : class SubstitutePathVariables : private ThreadHelpBase, // Struct for right initalization of mutex member! Must be first of baseclasses.
     221             :                                 public ::cppu::WeakImplHelper2< ::com::sun::star::util::XStringSubstitution, css::lang::XServiceInfo >
     222             : {
     223             :     friend class SubstitutePathVariables_Impl;
     224             : 
     225             :     public:
     226             :         SubstitutePathVariables( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
     227             :         virtual ~SubstitutePathVariables();
     228             : 
     229             :         //  XInterface, XTypeProvider, XServiceInfo
     230             :         DECLARE_XSERVICEINFO
     231             : 
     232             :         // XStringSubstitution
     233             :         virtual rtl::OUString SAL_CALL substituteVariables( const ::rtl::OUString& aText, sal_Bool bSubstRequired )
     234             :             throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
     235             :         virtual rtl::OUString SAL_CALL reSubstituteVariables( const ::rtl::OUString& aText )
     236             :             throw (::com::sun::star::uno::RuntimeException);
     237             :         virtual ::rtl::OUString SAL_CALL getSubstituteVariableValue( const ::rtl::OUString& variable )
     238             :             throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
     239             : 
     240             :         protected:
     241             :             DECL_LINK(implts_ConfigurationNotify, void *);
     242             : 
     243             :             void            SetPredefinedPathVariables( PredefinedPathVariables& );
     244             :             rtl::OUString   ConvertOSLtoUCBURL( const rtl::OUString& aOSLCompliantURL ) const;
     245             : 
     246             :             // Special case (transient) values can change during runtime!
     247             :             // Don't store them in the pre defined struct
     248             :             rtl::OUString   GetWorkPath() const;
     249             :             rtl::OUString   GetWorkVariableValue() const;
     250             :             rtl::OUString   GetPathVariableValue() const;
     251             : 
     252             :             rtl::OUString   GetHomeVariableValue() const;
     253             : 
     254             :             // XStringSubstitution implementation methods
     255             :             rtl::OUString impl_substituteVariable( const ::rtl::OUString& aText, bool bSustRequired )
     256             :                 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
     257             :             rtl::OUString impl_reSubstituteVariables( const ::rtl::OUString& aText )
     258             :                 throw (::com::sun::star::uno::RuntimeException);
     259             :             ::rtl::OUString impl_getSubstituteVariableValue( const ::rtl::OUString& variable )
     260             :                 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
     261             : 
     262             :         private:
     263          26 :             class VarNameToIndexMap : public boost::unordered_map< ::rtl::OUString,
     264             :                                                             PreDefVariable,
     265             :                                                             OUStringHashCode,
     266             :                                                             ::std::equal_to< ::rtl::OUString > >
     267             :             {
     268             :                 inline void free()
     269             :                 {
     270             :                     VarNameToIndexMap().swap( *this );
     271             :                 }
     272             :             };
     273             : 
     274             :             // heavy used string
     275             :             const rtl::OUString          m_aVarStart;
     276             :             const rtl::OUString          m_aVarEnd;
     277             : 
     278             :             VarNameToIndexMap            m_aPreDefVarMap;         // Mapping from pre-def variable names to enum for array access
     279             :             SubstituteVariables          m_aSubstVarMap;          // Active rule set map indexed by variable name!
     280             :             PredefinedPathVariables      m_aPreDefVars;           // All predefined variables
     281             :             SubstitutePathVariables_Impl m_aImpl;                 // Implementation class that access the configuration
     282             :             ReSubstFixedVarOrderVector   m_aReSubstFixedVarOrder; // To speed up resubstitution fixed variables (order for lookup)
     283             :             ReSubstUserVarOrderVector    m_aReSubstUserVarOrder;  // To speed up resubstitution user variables
     284             :             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
     285             : };
     286             : 
     287             : }
     288             : 
     289             : #endif // __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_
     290             : 
     291             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10