1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: substitutepathvars.hxx,v $
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 ...
41 //_________________________________________________________________________________________________________________
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>
51 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
62 #include <cppuhelper/implbase2.hxx>
63 #include <rtl/ustring.hxx>
64 #include <unotools/configitem.hxx>
65 #include <tools/link.hxx>
66 #include <i18npool/lang.h>
71 // Must be zero value based
83 // Must be zero value based
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
,
118 ::std::equal_to
< ::rtl::OUString
> >
123 SubstituteVariables().swap( *this );
127 typedef std::vector
< SubstituteRule
> SubstituteRuleVector
;
128 class SubstitutePathVariables_Impl
: public utl::ConfigItem
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
);
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
;
195 PREDEFVAR_WORKDIRURL
,
196 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
197 PREDEFVAR_BASEINSTURL
,
198 PREDEFVAR_USERDATAURL
,
200 PREDEFVAR_BRANDBASEURL
,
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
: private ThreadHelpBase
, // Struct for right initalization of mutex member! Must be first of baseclasses.
240 public ::cppu::WeakImplHelper2
< ::com::sun::star::util::XStringSubstitution
, css::lang::XServiceInfo
>
242 friend class SubstitutePathVariables_Impl
;
245 SubstitutePathVariables( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceManager
);
246 virtual ~SubstitutePathVariables();
248 // XInterface, XTypeProvider, XServiceInfo
251 // XStringSubstitution
252 virtual rtl::OUString SAL_CALL
substituteVariables( const ::rtl::OUString
& aText
, sal_Bool bSubstRequired
)
253 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
254 virtual rtl::OUString SAL_CALL
reSubstituteVariables( const ::rtl::OUString
& aText
)
255 throw (::com::sun::star::uno::RuntimeException
);
256 virtual ::rtl::OUString SAL_CALL
getSubstituteVariableValue( const ::rtl::OUString
& variable
)
257 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
260 DECL_LINK( implts_ConfigurationNotify
, SubstitutePathNotify
* );
262 void SetPredefinedPathVariables( PredefinedPathVariables
& );
263 rtl::OUString
ConvertOSLtoUCBURL( const rtl::OUString
& aOSLCompliantURL
) const;
265 // Special case (transient) values can change during runtime!
266 // Don't store them in the pre defined struct
267 rtl::OUString
GetWorkPath() const;
268 rtl::OUString
GetWorkVariableValue() const;
269 rtl::OUString
GetPathVariableValue() const;
271 rtl::OUString
GetHomeVariableValue() const;
273 // XStringSubstitution implementation methods
274 rtl::OUString
impl_substituteVariable( const ::rtl::OUString
& aText
, sal_Bool bSustRequired
)
275 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
276 rtl::OUString
impl_reSubstituteVariables( const ::rtl::OUString
& aText
)
277 throw (::com::sun::star::uno::RuntimeException
);
278 ::rtl::OUString
impl_getSubstituteVariableValue( const ::rtl::OUString
& variable
)
279 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
282 class VarNameToIndexMap
: public std::hash_map
< ::rtl::OUString
,
285 ::std::equal_to
< ::rtl::OUString
> >
289 VarNameToIndexMap().swap( *this );
294 const rtl::OUString m_aVarStart
;
295 const rtl::OUString m_aVarEnd
;
297 VarNameToIndexMap m_aPreDefVarMap
; // Mapping from pre-def variable names to enum for array access
298 SubstituteVariables m_aSubstVarMap
; // Active rule set map indexed by variable name!
299 PredefinedPathVariables m_aPreDefVars
; // All predefined variables
300 SubstitutePathVariables_Impl m_aImpl
; // Implementation class that access the configuration
301 ReSubstFixedVarOrderVector m_aReSubstFixedVarOrder
; // To speed up resubstitution fixed variables (order for lookup)
302 ReSubstUserVarOrderVector m_aReSubstUserVarOrder
; // To speed up resubstitution user variables
303 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> m_xServiceManager
;
308 #endif // __FRAMEWORK_SERVICES_SUBSTPATHVARS_HXX_