update dev300-m57
[ooovba.git] / framework / inc / services / substitutepathvars.hxx
blob8bd7c9db42c95d1ef21b8b88291290353c9e16ed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: substitutepathvars.hxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_
32 #define __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_
34 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
35 with solaris headers ...
37 #include <vector>
38 #include <list>
39 #include <hash_map>
41 //_________________________________________________________________________________________________________________
42 // my own includes
43 //_________________________________________________________________________________________________________________
44 #include <threadhelp/threadhelpbase.hxx>
45 #include <macros/generic.hxx>
46 #include <macros/xinterface.hxx>
47 #include <macros/xtypeprovider.hxx>
48 #include <macros/xserviceinfo.hxx>
49 #include <stdtypes.h>
51 //_________________________________________________________________________________________________________________
52 // interface includes
53 //_________________________________________________________________________________________________________________
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/lang/XTypeProvider.hpp>
56 #include <com/sun/star/container/NoSuchElementException.hpp>
57 #include <com/sun/star/util/XStringSubstitution.hpp>
59 //_________________________________________________________________________________________________________________
60 // other includes
61 //_________________________________________________________________________________________________________________
62 #include <cppuhelper/weak.hxx>
63 #include <rtl/ustring.hxx>
64 #include <unotools/configitem.hxx>
65 #include <tools/link.hxx>
66 #include <i18npool/lang.h>
68 namespace framework
71 // Must be zero value based
72 enum EnvironmentType
74 ET_HOST = 0 ,
75 ET_YPDOMAIN ,
76 ET_DNSDOMAIN ,
77 ET_NTDOMAIN ,
78 ET_OS ,
79 ET_UNKNOWN ,
80 ET_COUNT
83 // Must be zero value based
84 enum OperatingSystem
86 OS_WINDOWS = 0,
87 OS_UNIX ,
88 OS_SOLARIS ,
89 OS_LINUX ,
90 OS_UNKNOWN ,
91 OS_COUNT
94 struct SubstituteRule
96 SubstituteRule() {}
97 SubstituteRule( const rtl::OUString& aVarName,
98 const rtl::OUString& aValue,
99 const com::sun::star::uno::Any& aVal,
100 EnvironmentType aType ) :
101 aSubstVariable( aVarName ), aSubstValue( aValue ), aEnvValue( aVal ), aEnvType( aType ) {}
103 rtl::OUString aSubstVariable;
104 rtl::OUString aSubstValue;
105 com::sun::star::uno::Any aEnvValue;
106 EnvironmentType aEnvType;
109 struct SubstitutePathNotify
111 SubstitutePathNotify() {};
112 const com::sun::star::uno::Sequence<rtl::OUString> aPropertyNames;
115 class SubstituteVariables : public ::std::hash_map< ::rtl::OUString,
116 SubstituteRule,
117 OUStringHashCode,
118 ::std::equal_to< ::rtl::OUString > >
120 public:
121 inline void free()
123 SubstituteVariables().swap( *this );
127 typedef std::vector< SubstituteRule > SubstituteRuleVector;
128 class SubstitutePathVariables_Impl : public utl::ConfigItem
130 public:
131 SubstitutePathVariables_Impl( const Link& aNotifyLink );
132 virtual ~SubstitutePathVariables_Impl();
134 static OperatingSystem GetOperatingSystemFromString( const rtl::OUString& );
135 static EnvironmentType GetEnvTypeFromString( const rtl::OUString& );
137 void GetSharePointsRules( SubstituteVariables& aSubstVarMap );
139 /** is called from the ConfigManager before application ends or from the
140 PropertyChangeListener if the sub tree broadcasts changes. */
141 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
143 private:
144 // Wrapper methods for low-level functions
145 OperatingSystem GetOperatingSystem();
146 const rtl::OUString& GetYPDomainName();
147 const rtl::OUString& GetDNSDomainName();
148 const rtl::OUString& GetNTDomainName();
149 const rtl::OUString& GetHostName();
151 sal_Bool FilterRuleSet( const SubstituteRuleVector& aRuleSet, SubstituteRule& aActiveRule );
153 void ReadSharePointsFromConfiguration( com::sun::star::uno::Sequence< rtl::OUString >& aSharePointsSeq );
154 void ReadSharePointRuleSetFromConfiguration( const rtl::OUString& aSharePointName,
155 const rtl::OUString& aSharePointNodeName,
156 SubstituteRuleVector& aRuleSet );
158 // Stored values for domains and host
159 sal_Bool m_bYPDomainRetrieved;
160 rtl::OUString m_aYPDomain;
161 sal_Bool m_bDNSDomainRetrieved;
162 rtl::OUString m_aDNSDomain;
163 sal_Bool m_bNTDomainRetrieved;
164 rtl::OUString m_aNTDomain;
165 sal_Bool m_bHostRetrieved;
166 rtl::OUString m_aHost;
167 sal_Bool m_bOSRetrieved;
168 OperatingSystem m_eOSType;
170 Link m_aListenerNotify;
171 const rtl::OUString m_aSharePointsNodeName;
172 const rtl::OUString m_aDirPropertyName;
173 const rtl::OUString m_aEnvPropertyName;
174 const rtl::OUString m_aLevelSep;
177 enum PreDefVariable
179 PREDEFVAR_INST,
180 PREDEFVAR_PROG,
181 PREDEFVAR_USER,
182 PREDEFVAR_WORK,
183 PREDEFVAR_HOME,
184 PREDEFVAR_TEMP,
185 PREDEFVAR_PATH,
186 PREDEFVAR_LANG,
187 PREDEFVAR_LANGID,
188 PREDEFVAR_VLANG,
189 PREDEFVAR_INSTPATH,
190 PREDEFVAR_PROGPATH,
191 PREDEFVAR_USERPATH,
192 PREDEFVAR_INSTURL,
193 PREDEFVAR_PROGURL,
194 PREDEFVAR_USERURL,
195 PREDEFVAR_WORKDIRURL,
196 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
197 PREDEFVAR_BASEINSTURL,
198 PREDEFVAR_USERDATAURL,
199 // <--
200 PREDEFVAR_BRANDBASEURL,
201 PREDEFVAR_COUNT
204 struct PredefinedPathVariables
206 // Predefined variables supported by substitute variables
207 LanguageType m_eLanguageType; // Lanuage type of Office
208 rtl::OUString m_FixedVar[ PREDEFVAR_COUNT ]; // Variable value access by PreDefVariable
209 rtl::OUString m_FixedVarNames[ PREDEFVAR_COUNT ]; // Variable name access by PreDefVariable
212 struct ReSubstFixedVarOrder
214 sal_Int32 nVarValueLength;
215 PreDefVariable eVariable;
217 bool operator< ( const ReSubstFixedVarOrder& aFixedVarOrder ) const
219 // Reverse operator< to have high to low ordering
220 return ( nVarValueLength > aFixedVarOrder.nVarValueLength );
224 struct ReSubstUserVarOrder
226 sal_Int32 nVarValueLength;
227 rtl::OUString aVarName;
229 bool operator< ( const ReSubstUserVarOrder& aUserVarOrder ) const
231 // Reverse operator< to have high to low ordering
232 return ( nVarValueLength > aUserVarOrder.nVarValueLength );
236 typedef std::list< ReSubstFixedVarOrder > ReSubstFixedVarOrderVector;
237 typedef std::list< ReSubstUserVarOrder > ReSubstUserVarOrderVector;
239 class SubstitutePathVariables : public com::sun::star::lang::XTypeProvider ,
240 public com::sun::star::lang::XServiceInfo ,
241 public com::sun::star::util::XStringSubstitution,
242 private ThreadHelpBase , // Struct for right initalization of mutex member! Must be first of baseclasses.
243 public ::cppu::OWeakObject
245 friend class SubstitutePathVariables_Impl;
247 public:
248 SubstitutePathVariables( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
249 virtual ~SubstitutePathVariables();
251 // XInterface, XTypeProvider, XServiceInfo
252 FWK_DECLARE_XINTERFACE
253 FWK_DECLARE_XTYPEPROVIDER
254 DECLARE_XSERVICEINFO
256 // XStringSubstitution
257 virtual rtl::OUString SAL_CALL substituteVariables( const ::rtl::OUString& aText, sal_Bool bSubstRequired )
258 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
259 virtual rtl::OUString SAL_CALL reSubstituteVariables( const ::rtl::OUString& aText )
260 throw (::com::sun::star::uno::RuntimeException);
261 virtual ::rtl::OUString SAL_CALL getSubstituteVariableValue( const ::rtl::OUString& variable )
262 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
264 protected:
265 DECL_LINK( implts_ConfigurationNotify, SubstitutePathNotify* );
267 void SetPredefinedPathVariables( PredefinedPathVariables& );
268 rtl::OUString ConvertOSLtoUCBURL( const rtl::OUString& aOSLCompliantURL ) const;
270 // Special case (transient) values can change during runtime!
271 // Don't store them in the pre defined struct
272 rtl::OUString GetWorkPath() const;
273 rtl::OUString GetWorkVariableValue() const;
274 rtl::OUString GetPathVariableValue() const;
276 rtl::OUString GetHomeVariableValue() const;
278 // XStringSubstitution implementation methods
279 rtl::OUString impl_substituteVariable( const ::rtl::OUString& aText, sal_Bool bSustRequired )
280 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
281 rtl::OUString impl_reSubstituteVariables( const ::rtl::OUString& aText )
282 throw (::com::sun::star::uno::RuntimeException);
283 ::rtl::OUString impl_getSubstituteVariableValue( const ::rtl::OUString& variable )
284 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
286 private:
287 class VarNameToIndexMap : public std::hash_map< ::rtl::OUString,
288 PreDefVariable,
289 OUStringHashCode,
290 ::std::equal_to< ::rtl::OUString > >
292 inline void free()
294 VarNameToIndexMap().swap( *this );
298 // heavy used string
299 const rtl::OUString m_aVarStart;
300 const rtl::OUString m_aVarEnd;
302 VarNameToIndexMap m_aPreDefVarMap; // Mapping from pre-def variable names to enum for array access
303 SubstituteVariables m_aSubstVarMap; // Active rule set map indexed by variable name!
304 PredefinedPathVariables m_aPreDefVars; // All predefined variables
305 SubstitutePathVariables_Impl m_aImpl; // Implementation class that access the configuration
306 ReSubstFixedVarOrderVector m_aReSubstFixedVarOrder; // To speed up resubstitution fixed variables (order for lookup)
307 ReSubstUserVarOrderVector m_aReSubstUserVarOrder; // To speed up resubstitution user variables
308 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
313 #endif // __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_