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