1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
33 //_________________________________________________________________________________________________________________
34 #include "services/substitutepathvars.hxx"
35 #include <threadhelp/resetableguard.hxx>
36 #include <helper/networkdomain.hxx>
39 //_________________________________________________________________________________________________________________
41 //_________________________________________________________________________________________________________________
42 #include <com/sun/star/beans/XPropertySet.hpp>
44 //_________________________________________________________________________________________________________________
45 // includes of other projects
46 //_________________________________________________________________________________________________________________
47 #include <unotools/configitem.hxx>
48 #include <unotools/localfilehelper.hxx>
49 #include <unotools/configmgr.hxx>
51 #ifndef _UTL_BOOTSTRAP_HXX_
52 #include <unotools/bootstrap.hxx>
54 #include <osl/mutex.hxx>
55 #include <osl/file.hxx>
56 #include <osl/security.hxx>
57 #include <osl/socket.hxx>
58 #include <vos/process.hxx>
59 #include <i18npool/mslangid.hxx>
60 #include <tools/urlobj.hxx>
61 #include <tools/resmgr.hxx>
62 #include <tools/debug.hxx>
63 #include <tools/wldcrd.hxx>
64 #include <rtl/ustrbuf.hxx>
65 #include <rtl/bootstrap.hxx>
67 #include <comphelper/configurationhelper.hxx>
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
76 #define STRPOS_NOTFOUND (sal_Int32)-1
78 #define ASCII_STR( val ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( val ))
80 #define SEARCHPATH_DELIMITER ';'
82 // Variable start/end characters
83 #define SIGN_STARTVARIABLE ASCII_STR("$(")
84 #define SIGN_ENDVARIABLE ASCII_STR(")")
86 // Length of SUBSTITUTE_... to replace it with real values.
87 #define REPLACELENGTH_INST 7
88 #define REPLACELENGTH_PROG 7
89 #define REPLACELENGTH_USER 7
90 #define REPLACELENGTH_WORK 7
91 #define REPLACELENGTH_HOME 7
92 #define REPLACELENGTH_TEMP 7
93 #define REPLACELENGTH_PATH 7
94 #define REPLACELENGTH_INSTPATH 11
95 #define REPLACELENGTH_PROGPATH 11
96 #define REPLACELENGTH_USERPATH 11
97 #define REPLACELENGTH_INSTURL 10
98 #define REPLACELENGTH_PROGURL 10
99 #define REPLACELENGTH_USERURL 10
100 #define REPLACELENGTH_PATH 7
101 #define REPLACELENGTH_LANG 7
102 #define REPLACELENGTH_LANGID 9
103 #define REPLACELENGTH_VLANG 8
104 #define REPLACELENGTH_WORKDIRURL 13
105 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
106 #define REPLACELENGTH_BASEINSTURL 14
107 #define REPLACELENGTH_USERDATAURL 14
110 // Name of the pre defined path variables
111 #define VARIABLE_INST "$(inst)"
112 #define VARIABLE_PROG "$(prog)"
113 #define VARIABLE_USER "$(user)"
114 #define VARIABLE_WORK "$(work)"
115 #define VARIABLE_HOME "$(home)"
116 #define VARIABLE_TEMP "$(temp)"
117 #define VARIABLE_PATH "$(path)"
118 #define VARIABLE_LANG "$(lang)"
119 #define VARIABLE_LANGID "$(langid)"
120 #define VARIABLE_VLANG "$(vlang)"
121 #define VARIABLE_INSTPATH "$(instpath)"
122 #define VARIABLE_PROGPATH "$(progpath)"
123 #define VARIABLE_USERPATH "$(userpath)"
124 #define VARIABLE_INSTURL "$(insturl)"
125 #define VARIABLE_PROGURL "$(progurl)"
126 #define VARIABLE_USERURL "$(userurl)"
127 #define VARIABLE_WORKDIRURL "$(workdirurl)"
128 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
129 #define VARIABLE_BASEINSTURL "$(baseinsturl)"
130 #define VARIABLE_USERDATAURL "$(userdataurl)"
133 using namespace com::sun::star::uno
;
134 using namespace com::sun::star::beans
;
135 using namespace com::sun::star::util
;
136 using namespace com::sun::star::lang
;
137 using namespace com::sun::star::container
;
139 //_________________________________________________________________________________________________________________
141 //_________________________________________________________________________________________________________________
149 const char* pVarName
;
150 PreDefVariable nEnumValue
;
156 const char* pOSString
;
160 // Table with valid operating system strings
161 // Name of the os as char* and the length
163 static TableEntry aOSTable
[OS_COUNT
] =
169 { "" , 0 } // unknown
172 // Table with valid environment variables
173 // Name of the environment type as a char* and
174 // the length of the string.
175 static TableEntry aEnvTable
[ET_COUNT
] =
182 { "" , 0 } // unknown
185 // Priority table for the environment types. Lower numbers define
186 // a higher priority. Equal numbers has the same priority that means
187 // that the first match wins!!
188 static sal_Int16 aEnvPrioTable
[ET_COUNT
] =
198 // Table with all fixed/predefined variables supported.
199 static FixedVariable aFixedVarTable
[] =
201 { VARIABLE_INST
, PREDEFVAR_INST
, REPLACELENGTH_INST
},
202 { VARIABLE_PROG
, PREDEFVAR_PROG
, REPLACELENGTH_PROG
},
203 { VARIABLE_USER
, PREDEFVAR_USER
, REPLACELENGTH_USER
},
204 { VARIABLE_WORK
, PREDEFVAR_WORK
, REPLACELENGTH_WORK
}, // Special variable (transient)!
205 { VARIABLE_HOME
, PREDEFVAR_HOME
, REPLACELENGTH_HOME
},
206 { VARIABLE_TEMP
, PREDEFVAR_TEMP
, REPLACELENGTH_TEMP
},
207 { VARIABLE_PATH
, PREDEFVAR_PATH
, REPLACELENGTH_PATH
},
208 { VARIABLE_LANG
, PREDEFVAR_LANG
, REPLACELENGTH_LANG
},
209 { VARIABLE_LANGID
, PREDEFVAR_LANGID
, REPLACELENGTH_LANGID
},
210 { VARIABLE_VLANG
, PREDEFVAR_VLANG
, REPLACELENGTH_VLANG
},
211 { VARIABLE_INSTPATH
, PREDEFVAR_INSTPATH
, REPLACELENGTH_INSTPATH
},
212 { VARIABLE_PROGPATH
, PREDEFVAR_PROGPATH
, REPLACELENGTH_PROGPATH
},
213 { VARIABLE_USERPATH
, PREDEFVAR_USERPATH
, REPLACELENGTH_USERPATH
},
214 { VARIABLE_INSTURL
, PREDEFVAR_INSTURL
, REPLACELENGTH_INSTURL
},
215 { VARIABLE_PROGURL
, PREDEFVAR_PROGURL
, REPLACELENGTH_PROGURL
},
216 { VARIABLE_USERURL
, PREDEFVAR_USERURL
, REPLACELENGTH_USERURL
},
217 { VARIABLE_WORKDIRURL
, PREDEFVAR_WORKDIRURL
, REPLACELENGTH_WORKDIRURL
}, // Special variable (transient) and don't use for resubstitution!
218 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
219 { VARIABLE_BASEINSTURL
, PREDEFVAR_BASEINSTURL
, REPLACELENGTH_BASEINSTURL
},
220 { VARIABLE_USERDATAURL
, PREDEFVAR_USERDATAURL
, REPLACELENGTH_USERDATAURL
},
222 { "$(brandbaseurl)", PREDEFVAR_BRANDBASEURL
,
223 RTL_CONSTASCII_LENGTH("$(brandbaseurl)") }
226 //_________________________________________________________________________________________________________________
227 // Implementation helper classes
228 //_________________________________________________________________________________________________________________
231 OperatingSystem
SubstitutePathVariables_Impl::GetOperatingSystemFromString( const rtl::OUString
& aOSString
)
233 for ( int i
= 0; i
< OS_COUNT
; i
++ )
235 if ( aOSString
.equalsIgnoreAsciiCaseAsciiL( aOSTable
[i
].pOSString
, aOSTable
[i
].nStrLen
))
236 return (OperatingSystem
)i
;
242 EnvironmentType
SubstitutePathVariables_Impl::GetEnvTypeFromString( const rtl::OUString
& aEnvTypeString
)
244 for ( int i
= 0; i
< ET_COUNT
; i
++ )
246 if ( aEnvTypeString
.equalsIgnoreAsciiCaseAsciiL( aEnvTable
[i
].pOSString
, aEnvTable
[i
].nStrLen
))
247 return (EnvironmentType
)i
;
253 SubstitutePathVariables_Impl::SubstitutePathVariables_Impl( const Link
& aNotifyLink
) :
254 utl::ConfigItem( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.Substitution" ))),
255 m_bYPDomainRetrieved( sal_False
),
256 m_bDNSDomainRetrieved( sal_False
),
257 m_bNTDomainRetrieved( sal_False
),
258 m_bHostRetrieved( sal_False
),
259 m_bOSRetrieved( sal_False
),
260 m_aListenerNotify( aNotifyLink
),
261 m_aSharePointsNodeName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SharePoints" ))),
262 m_aDirPropertyName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Directory" ))),
263 m_aEnvPropertyName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Environment" ))),
264 m_aLevelSep( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" )))
266 // Enable notification mechanism
267 // We need it to get information about changes outside these class on our configuration branch
268 Sequence
< rtl::OUString
> aNotifySeq( 1 );
269 aNotifySeq
[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SharePoints" ));
270 EnableNotification( aNotifySeq
, sal_True
);
273 SubstitutePathVariables_Impl::~SubstitutePathVariables_Impl()
277 void SubstitutePathVariables_Impl::GetSharePointsRules( SubstituteVariables
& aSubstVarMap
)
279 Sequence
< rtl::OUString
> aSharePointNames
;
280 ReadSharePointsFromConfiguration( aSharePointNames
);
282 if ( aSharePointNames
.getLength() > 0 )
284 sal_Int32 nSharePoints
= 0;
286 // Read SharePoints container from configuration
287 while ( nSharePoints
< aSharePointNames
.getLength() )
289 rtl::OUString
aSharePointNodeName( m_aSharePointsNodeName
);
290 aSharePointNodeName
+= rtl::OUString::createFromAscii( "/" );
291 aSharePointNodeName
+= aSharePointNames
[ nSharePoints
];
293 SubstituteRuleVector aRuleSet
;
294 ReadSharePointRuleSetFromConfiguration( aSharePointNames
[ nSharePoints
], aSharePointNodeName
, aRuleSet
);
295 if ( !aRuleSet
.empty() )
297 // We have at minimum one rule. Filter the correct rule out of the rule set
298 // and put into our SubstituteVariable map
299 SubstituteRule aActiveRule
;
300 if ( FilterRuleSet( aRuleSet
, aActiveRule
))
302 // We have found an active rule
303 aActiveRule
.aSubstVariable
= aSharePointNames
[ nSharePoints
];
304 aSubstVarMap
.insert( SubstituteVariables::value_type(
305 aActiveRule
.aSubstVariable
, aActiveRule
));
314 void SubstitutePathVariables_Impl::Notify( const com::sun::star::uno::Sequence
< rtl::OUString
>& /*aPropertyNames*/ )
316 // NOT implemented yet!
319 void SubstitutePathVariables_Impl::Commit()
324 //_________________________________________________________________________________________________________________
326 //_________________________________________________________________________________________________________________
329 OperatingSystem
SubstitutePathVariables_Impl::GetOperatingSystem()
331 if ( !m_bOSRetrieved
)
334 m_eOSType
= OS_SOLARIS
;
336 m_eOSType
= OS_LINUX
;
338 m_eOSType
= OS_WINDOWS
;
342 m_eOSType
= OS_UNKNOWN
;
344 m_bOSRetrieved
= sal_True
;
350 const rtl::OUString
& SubstitutePathVariables_Impl::GetYPDomainName()
352 if ( !m_bYPDomainRetrieved
)
354 m_aYPDomain
= NetworkDomain::GetYPDomainName().toAsciiLowerCase();
355 m_bYPDomainRetrieved
= sal_True
;
361 const rtl::OUString
& SubstitutePathVariables_Impl::GetDNSDomainName()
363 if ( !m_bDNSDomainRetrieved
)
366 osl::SocketAddr aSockAddr
;
367 oslSocketResult aResult
;
369 rtl::OUString aHostName
= GetHostName();
370 osl::SocketAddr::resolveHostname( aHostName
, aSockAddr
);
371 aTemp
= aSockAddr
.getHostname( &aResult
);
373 // DNS domain name begins after the first "."
374 sal_Int32 nIndex
= aTemp
.indexOf( '.' );
375 if ( nIndex
>= 0 && aTemp
.getLength() > nIndex
+1 )
376 m_aDNSDomain
= aTemp
.copy( nIndex
+1 ).toAsciiLowerCase();
378 m_aDNSDomain
= rtl::OUString();
380 m_bDNSDomainRetrieved
= sal_True
;
386 const rtl::OUString
& SubstitutePathVariables_Impl::GetNTDomainName()
388 if ( !m_bNTDomainRetrieved
)
390 m_aNTDomain
= NetworkDomain::GetNTDomainName().toAsciiLowerCase();
391 m_bNTDomainRetrieved
= sal_True
;
397 const rtl::OUString
& SubstitutePathVariables_Impl::GetHostName()
399 if ( !m_bHostRetrieved
)
401 rtl::OUString aHostName
;
402 oslSocketResult aSocketResult
;
404 m_aHost
= osl::SocketAddr::getLocalHostname( &aSocketResult
).toAsciiLowerCase();
410 sal_Bool
SubstitutePathVariables_Impl::FilterRuleSet( const SubstituteRuleVector
& aRuleSet
, SubstituteRule
& aActiveRule
)
412 sal_Bool bResult
= sal_False
;
414 if ( !aRuleSet
.empty() )
416 sal_Int16 nPrioCurrentRule
= aEnvPrioTable
[ ET_UNKNOWN
];
417 const sal_uInt32 nCount
= aRuleSet
.size();
418 for ( sal_uInt32 nIndex
= 0; nIndex
< nCount
; nIndex
++ )
420 const SubstituteRule
& aRule
= aRuleSet
[nIndex
];
421 EnvironmentType eEnvType
= aRule
.aEnvType
;
423 // Check if environment type has a higher priority than current one!
424 if ( nPrioCurrentRule
> aEnvPrioTable
[eEnvType
] )
430 rtl::OUString aHost
= GetHostName();
431 rtl::OUString aHostStr
;
432 aRule
.aEnvValue
>>= aHostStr
;
433 aHostStr
= aHostStr
.toAsciiLowerCase();
435 // Pattern match if domain environment match
436 WildCard
aPattern(aHostStr
);
437 sal_Bool bMatch
= aPattern
.Matches(aHost
);
442 nPrioCurrentRule
= aEnvPrioTable
[eEnvType
];
451 rtl::OUString aDomain
;
452 rtl::OUString aDomainStr
;
453 aRule
.aEnvValue
>>= aDomainStr
;
454 aDomainStr
= aDomainStr
.toAsciiLowerCase();
456 // Retrieve the correct domain value
457 if ( eEnvType
== ET_YPDOMAIN
)
458 aDomain
= GetYPDomainName();
459 else if ( eEnvType
== ET_DNSDOMAIN
)
460 aDomain
= GetDNSDomainName();
462 aDomain
= GetNTDomainName();
464 // Pattern match if domain environment match
465 WildCard
aPattern(aDomainStr
);
466 sal_Bool bMatch
= aPattern
.Matches(aDomain
);
471 nPrioCurrentRule
= aEnvPrioTable
[eEnvType
];
478 // No pattern matching for OS type
479 OperatingSystem eOSType
= GetOperatingSystem();
481 sal_Int16 nValue
= 0;
482 aRule
.aEnvValue
>>= nValue
;
484 sal_Bool bUnix
= ( eOSType
== OS_LINUX
) || ( eOSType
== OS_SOLARIS
);
485 OperatingSystem eRuleOSType
= (OperatingSystem
)nValue
;
487 // Match if OS identical or rule is set to UNIX and OS is LINUX/SOLARIS!
488 if (( eRuleOSType
== eOSType
) || ( eRuleOSType
== OS_UNIX
&& bUnix
))
492 nPrioCurrentRule
= aEnvPrioTable
[eEnvType
];
497 case ET_UNKNOWN
: // nothing to do
510 void SubstitutePathVariables_Impl::ReadSharePointsFromConfiguration( Sequence
< rtl::OUString
>& aSharePointsSeq
)
512 //returns all the names of all share point nodes
513 aSharePointsSeq
= GetNodeNames( m_aSharePointsNodeName
);
516 void SubstitutePathVariables_Impl::ReadSharePointRuleSetFromConfiguration(
517 const rtl::OUString
& aSharePointName
,
518 const rtl::OUString
& aSharePointNodeName
,
519 SubstituteRuleVector
& rRuleSet
)
521 Sequence
< rtl::OUString
> aSharePointMappingsNodeNames
= GetNodeNames( aSharePointNodeName
, utl::CONFIG_NAME_LOCAL_PATH
);
523 sal_Int32 nSharePointMapping
= 0;
524 while ( nSharePointMapping
< aSharePointMappingsNodeNames
.getLength() )
526 rtl::OUString
aSharePointMapping( aSharePointNodeName
);
527 aSharePointMapping
+= m_aLevelSep
;
528 aSharePointMapping
+= aSharePointMappingsNodeNames
[ nSharePointMapping
];
530 // Read SharePointMapping
531 rtl::OUString aDirValue
;
532 rtl::OUString
aDirProperty( aSharePointMapping
);
533 aDirProperty
+= m_aDirPropertyName
;
535 // Read only the directory property
536 Sequence
< rtl::OUString
> aDirPropertySeq( 1 );
537 aDirPropertySeq
[0] = aDirProperty
;
539 Sequence
< Any
> aValueSeq
= GetProperties( aDirPropertySeq
);
540 if ( aValueSeq
.getLength() == 1 )
541 aValueSeq
[0] >>= aDirValue
;
543 // Read the environment setting
544 rtl::OUString aEnvUsed
;
545 rtl::OUString
aEnvProperty( aSharePointMapping
);
546 aEnvProperty
+= m_aEnvPropertyName
;
547 Sequence
< rtl::OUString
> aEnvironmentVariable
= GetNodeNames( aEnvProperty
);
549 // Filter the property which has a value set
550 Sequence
< rtl::OUString
> aEnvUsedPropertySeq( aEnvironmentVariable
.getLength() );
552 rtl::OUString
aEnvUsePropNameTemplate( aEnvProperty
);
553 aEnvUsePropNameTemplate
+= m_aLevelSep
;
555 for ( sal_Int32 nProperty
= 0; nProperty
< aEnvironmentVariable
.getLength(); nProperty
++ )
556 aEnvUsedPropertySeq
[nProperty
] = rtl::OUString( aEnvUsePropNameTemplate
+ aEnvironmentVariable
[nProperty
] );
558 Sequence
< Any
> aEnvUsedValueSeq
;
559 aEnvUsedValueSeq
= GetProperties( aEnvUsedPropertySeq
);
561 rtl::OUString aEnvUsedValue
;
562 for ( sal_Int32 nIndex
= 0; nIndex
< aEnvironmentVariable
.getLength(); nIndex
++ )
564 if ( aEnvUsedValueSeq
[nIndex
] >>= aEnvUsedValue
)
566 aEnvUsed
= aEnvironmentVariable
[nIndex
];
571 // Decode the environment and optional the operatng system settings
573 EnvironmentType eEnvType
= GetEnvTypeFromString( aEnvUsed
);
574 if ( eEnvType
== ET_OS
)
576 OperatingSystem eOSType
= GetOperatingSystemFromString( aEnvUsedValue
);
577 aEnvValue
<<= (sal_Int16
)eOSType
;
580 aEnvValue
<<= aEnvUsedValue
;
582 // Create rule struct and push it into the rule set
583 SubstituteRule
aRule( aSharePointName
, aDirValue
, aEnvValue
, eEnvType
);
584 rRuleSet
.push_back( aRule
);
586 ++nSharePointMapping
;
590 //*****************************************************************************************************************
591 // XInterface, XTypeProvider, XServiceInfo
592 //*****************************************************************************************************************
593 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( SubstitutePathVariables
,
594 ::cppu::OWeakObject
,
595 SERVICENAME_SUBSTITUTEPATHVARIABLES
,
596 IMPLEMENTATIONNAME_SUBSTITUTEPATHVARIABLES
599 DEFINE_INIT_SERVICE ( SubstitutePathVariables
, {} )
602 SubstitutePathVariables::SubstitutePathVariables( const Reference
< XMultiServiceFactory
>& xServiceManager
) :
604 m_aVarStart( SIGN_STARTVARIABLE
),
605 m_aVarEnd( SIGN_ENDVARIABLE
),
606 m_aImpl( LINK( this, SubstitutePathVariables
, implts_ConfigurationNotify
)),
607 m_xServiceManager( xServiceManager
)
609 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::SubstitutePathVariables" );
612 SetPredefinedPathVariables( m_aPreDefVars
);
613 m_aImpl
.GetSharePointsRules( m_aSubstVarMap
);
615 // Init the predefined/fixed variable to index hash map
616 for ( i
= 0; i
< PREDEFVAR_COUNT
; i
++ )
618 // Store variable name into struct of predefined/fixed variables
619 m_aPreDefVars
.m_FixedVarNames
[i
] = rtl::OUString::createFromAscii( aFixedVarTable
[i
].pVarName
);
621 // Create hash map entry
622 m_aPreDefVarMap
.insert( VarNameToIndexMap::value_type(
623 m_aPreDefVars
.m_FixedVarNames
[i
], aFixedVarTable
[i
].nEnumValue
) );
626 // Sort predefined/fixed variable to path length
627 for ( i
= 0; i
< PREDEFVAR_COUNT
; i
++ )
629 if (( i
!= PREDEFVAR_WORKDIRURL
) &&
630 ( i
!= PREDEFVAR_PATH
))
632 // Special path variables, don't include into automatic resubstituion search!
633 // $(workdirurl) is not allowed to resubstitute! This variable is the value of path settings entry
634 // and it could be possible that it will be resubstituted by itself!!
635 // Example: WORK_PATH=c:\test, $(workdirurl)=WORK_PATH => WORK_PATH=$(workdirurl) and this cannot be substituted!
636 ReSubstFixedVarOrder aFixedVar
;
637 aFixedVar
.eVariable
= aFixedVarTable
[i
].nEnumValue
;
638 aFixedVar
.nVarValueLength
= m_aPreDefVars
.m_FixedVar
[(sal_Int32
)aFixedVar
.eVariable
].getLength();
639 m_aReSubstFixedVarOrder
.push_back( aFixedVar
);
642 m_aReSubstFixedVarOrder
.sort();
644 // Sort user variables to path length
645 SubstituteVariables::const_iterator pIter
;
646 for ( pIter
= m_aSubstVarMap
.begin(); pIter
!= m_aSubstVarMap
.end(); pIter
++ )
648 ReSubstUserVarOrder aUserOrderVar
;
649 rtl::OUStringBuffer
aStrBuffer( pIter
->second
.aSubstVariable
.getLength() );
650 aStrBuffer
.append( m_aVarStart
);
651 aStrBuffer
.append( pIter
->second
.aSubstVariable
);
652 aStrBuffer
.append( m_aVarEnd
);
653 aUserOrderVar
.aVarName
= aStrBuffer
.makeStringAndClear();
654 aUserOrderVar
.nVarValueLength
= pIter
->second
.aSubstVariable
.getLength();
655 m_aReSubstUserVarOrder
.push_back( aUserOrderVar
);
657 m_aReSubstUserVarOrder
.sort();
660 SubstitutePathVariables::~SubstitutePathVariables()
664 // XStringSubstitution
665 rtl::OUString SAL_CALL
SubstitutePathVariables::substituteVariables( const ::rtl::OUString
& aText
, sal_Bool bSubstRequired
)
666 throw ( NoSuchElementException
, RuntimeException
)
668 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::substituteVariables" );
669 ResetableGuard
aLock( m_aLock
);
670 return impl_substituteVariable( aText
, bSubstRequired
);
673 rtl::OUString SAL_CALL
SubstitutePathVariables::reSubstituteVariables( const ::rtl::OUString
& aText
)
674 throw ( RuntimeException
)
676 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::reSubstituteVariables" );
677 ResetableGuard
aLock( m_aLock
);
678 return impl_reSubstituteVariables( aText
);
681 rtl::OUString SAL_CALL
SubstitutePathVariables::getSubstituteVariableValue( const ::rtl::OUString
& aVariable
)
682 throw ( NoSuchElementException
, RuntimeException
)
684 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::getSubstituteVariableValue" );
685 ResetableGuard
aLock( m_aLock
);
686 return impl_getSubstituteVariableValue( aVariable
);
689 //_________________________________________________________________________________________________________________
691 //_________________________________________________________________________________________________________________
694 IMPL_LINK( SubstitutePathVariables
, implts_ConfigurationNotify
, SubstitutePathNotify
*, EMPTYARG
)
696 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
697 ResetableGuard
aLock( m_aLock
);
702 rtl::OUString
SubstitutePathVariables::ConvertOSLtoUCBURL( const rtl::OUString
& aOSLCompliantURL
) const
704 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::ConvertOSLtoUCBURL" );
708 osl::FileBase::getSystemPathFromFileURL( aOSLCompliantURL
, aTemp
);
709 utl::LocalFileHelper::ConvertPhysicalNameToURL( aTemp
, aResult
);
711 // Not all OSL URL's can be mapped to UCB URL's!
712 if ( aResult
.Len() == 0 )
713 return aOSLCompliantURL
;
715 return rtl::OUString( aResult
);
718 rtl::OUString
SubstitutePathVariables::GetWorkPath() const
720 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetWorkPath" );
721 rtl::OUString aWorkPath
;
722 ::comphelper::ConfigurationHelper::readDirectKey(
724 ::rtl::OUString::createFromAscii("org.openoffice.Office.Paths"),
725 ::rtl::OUString::createFromAscii("Paths/Work"),
726 ::rtl::OUString::createFromAscii("WritePath"),
727 ::comphelper::ConfigurationHelper::E_READONLY
) >>= aWorkPath
;
731 rtl::OUString
SubstitutePathVariables::GetWorkVariableValue() const
733 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetWorkVariableValue" );
734 ::rtl::OUString aWorkPath
;
735 ::comphelper::ConfigurationHelper::readDirectKey(
737 ::rtl::OUString::createFromAscii("org.openoffice.Office.Paths"),
738 ::rtl::OUString::createFromAscii("Variables"),
739 ::rtl::OUString::createFromAscii("Work"),
740 ::comphelper::ConfigurationHelper::E_READONLY
) >>= aWorkPath
;
742 // fallback to $HOME in case platform dependend config layer does not return
743 // an usuable work dir value.
744 if (aWorkPath
.getLength() < 1)
746 osl::Security aSecurity
;
747 aSecurity
.getHomeDir( aWorkPath
);
749 return ConvertOSLtoUCBURL( aWorkPath
);
752 rtl::OUString
SubstitutePathVariables::GetHomeVariableValue() const
754 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetHomeVariableValue" );
755 osl::Security aSecurity
;
756 rtl::OUString aHomePath
;
758 aSecurity
.getHomeDir( aHomePath
);
759 return ConvertOSLtoUCBURL( aHomePath
);
762 rtl::OUString
SubstitutePathVariables::GetPathVariableValue() const
764 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetPathVariableValue" );
765 const int PATH_EXTEND_FACTOR
= 120;
767 rtl::OUString aRetStr
;
768 const char* pEnv
= getenv( "PATH" );
773 rtl::OUString
aPathList( pEnv
, strlen( pEnv
), gsl_getSystemTextEncoding() );
774 rtl::OUStringBuffer
aPathStrBuffer( aPathList
.getLength() * PATH_EXTEND_FACTOR
/ 100 );
776 sal_Bool bAppendSep
= sal_False
;
777 sal_Int32 nToken
= 0;
780 ::rtl::OUString sToken
= aPathList
.getToken(0, SAL_PATHSEPARATOR
, nToken
);
781 if (sToken
.getLength())
783 osl::FileBase::getFileURLFromSystemPath( sToken
, aTmp
);
785 aPathStrBuffer
.appendAscii( ";" ); // Office uses ';' as path separator
786 aPathStrBuffer
.append( aTmp
);
787 bAppendSep
= sal_True
;
792 aRetStr
= aPathStrBuffer
.makeStringAndClear();
798 rtl::OUString
SubstitutePathVariables::impl_substituteVariable( const ::rtl::OUString
& rText
, sal_Bool bSubstRequired
)
799 throw ( NoSuchElementException
, RuntimeException
)
801 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_substituteVariable" );
802 // This is maximal recursive depth supported!
803 const sal_Int32 nMaxRecursiveDepth
= 8;
805 rtl::OUString aWorkText
= rText
;
806 rtl::OUString aResult
;
808 // Use vector with strings to detect endless recursions!
809 std::vector
< rtl::OUString
> aEndlessRecursiveDetector
;
811 // Search for first occure of "$(...".
812 sal_Int32 nDepth
= 0;
813 sal_Int32 bSubstitutionCompleted
= sal_False
;
814 sal_Int32 nPosition
= aWorkText
.indexOf( m_aVarStart
); // = first position of "$(" in string
815 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
816 sal_Bool bVarNotSubstituted
= sal_False
;
818 // Have we found any variable like "$(...)"?
819 if ( nPosition
!= STRPOS_NOTFOUND
)
821 // Yes; Get length of found variable.
822 // If no ")" was found - nLength is set to 0 by default! see before.
823 sal_Int32 nEndPosition
= aWorkText
.indexOf( m_aVarEnd
, nPosition
);
824 if ( nEndPosition
!= STRPOS_NOTFOUND
)
825 nLength
= nEndPosition
- nPosition
+ 1;
828 // Is there something to replace ?
829 sal_Bool bWorkRetrieved
= sal_False
;
830 sal_Bool bWorkDirURLRetrieved
= sal_False
;
831 while ( !bSubstitutionCompleted
&& nDepth
< nMaxRecursiveDepth
)
833 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 3 ) ) // "$(" ")"
835 // YES; Get the next variable for replace.
836 sal_Int32 nReplaceLength
= 0;
837 rtl::OUString aReplacement
;
838 rtl::OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
839 rtl::OUString aSubVarString
;
841 // Path variables are not case sensitive!
842 aSubVarString
= aSubString
.toAsciiLowerCase();
843 VarNameToIndexMap::const_iterator pNTOIIter
= m_aPreDefVarMap
.find( aSubVarString
);
844 if ( pNTOIIter
!= m_aPreDefVarMap
.end() )
846 // Fixed/Predefined variable found
847 PreDefVariable nIndex
= (PreDefVariable
)pNTOIIter
->second
;
849 // Determine variable value and length from array/table
850 if ( nIndex
== PREDEFVAR_WORK
&& !bWorkRetrieved
)
852 // Transient value, retrieve it again
853 m_aPreDefVars
.m_FixedVar
[ (PreDefVariable
)nIndex
] = GetWorkVariableValue();
854 bWorkRetrieved
= sal_True
;
856 else if ( nIndex
== PREDEFVAR_WORKDIRURL
&& !bWorkDirURLRetrieved
)
858 // Transient value, retrieve it again
859 m_aPreDefVars
.m_FixedVar
[ (PreDefVariable
)nIndex
] = GetWorkPath();
860 bWorkDirURLRetrieved
= sal_True
;
863 aReplacement
= m_aPreDefVars
.m_FixedVar
[ (PreDefVariable
)nIndex
];
864 nReplaceLength
= nLength
;
868 // Extract the variable name and try to find in the user defined variable set
869 rtl::OUString aVarName
= aSubString
.copy( 2, nLength
-3 );
870 SubstituteVariables::const_iterator pIter
= m_aSubstVarMap
.find( aVarName
);
871 if ( pIter
!= m_aSubstVarMap
.end() )
874 aReplacement
= pIter
->second
.aSubstValue
;
875 nReplaceLength
= nLength
;
879 // Have we found something to replace?
880 if ( nReplaceLength
> 0 )
882 // Yes ... then do it.
883 aWorkText
= aWorkText
.replaceAt( nPosition
, nReplaceLength
, aReplacement
);
887 // Variable not known
888 bVarNotSubstituted
= sal_False
;
889 nPosition
+= nLength
;
892 // Step after replaced text! If no text was replaced (unknown variable!),
893 // length of aReplacement is 0 ... and we don't step then.
894 nPosition
+= aReplacement
.getLength();
896 // We must control index in string before call something at OUString!
897 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
898 if ( nPosition
+ 1 > aWorkText
.getLength() )
900 // Position is out of range. Break loop!
901 nPosition
= STRPOS_NOTFOUND
;
906 // Else; Position is valid. Search for next variable to replace.
907 nPosition
= aWorkText
.indexOf( m_aVarStart
, nPosition
);
908 // Have we found any variable like "$(...)"?
909 if ( nPosition
!= STRPOS_NOTFOUND
)
911 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
913 sal_Int32 nEndPosition
= aWorkText
.indexOf( m_aVarEnd
, nPosition
);
914 if ( nEndPosition
!= STRPOS_NOTFOUND
)
915 nLength
= nEndPosition
- nPosition
+ 1;
920 nPosition
= aWorkText
.indexOf( m_aVarStart
);
921 if ( nPosition
== -1 )
923 bSubstitutionCompleted
= sal_True
;
924 break; // All variables are substituted
928 // Check for recursion
929 const sal_uInt32 nCount
= aEndlessRecursiveDetector
.size();
930 for ( sal_uInt32 i
=0; i
< nCount
; i
++ )
932 if ( aEndlessRecursiveDetector
[i
] == aWorkText
)
934 if ( bVarNotSubstituted
)
935 break; // Not all variables could be substituted!
938 nDepth
= nMaxRecursiveDepth
;
939 break; // Recursion detected!
944 aEndlessRecursiveDetector
.push_back( aWorkText
);
946 // Initialize values for next
947 sal_Int32 nEndPosition
= aWorkText
.indexOf( m_aVarEnd
, nPosition
);
948 if ( nEndPosition
!= STRPOS_NOTFOUND
)
949 nLength
= nEndPosition
- nPosition
+ 1;
950 bVarNotSubstituted
= sal_False
;
955 // Fill return value with result
956 if ( bSubstitutionCompleted
)
958 // Substitution successfull!
963 // Substitution not successfull!
964 if ( nDepth
== nMaxRecursiveDepth
)
966 // recursion depth reached!
967 if ( bSubstRequired
)
969 rtl::OUString
aMsg( RTL_CONSTASCII_USTRINGPARAM( "Endless recursion detected. Cannot substitute variables!" ));
970 throw NoSuchElementException( aMsg
, (cppu::OWeakObject
*)this );
977 // variable in text but unknwon!
978 if ( bSubstRequired
)
980 rtl::OUString
aMsg( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable found!" ));
981 throw NoSuchElementException( aMsg
, (cppu::OWeakObject
*)this );
991 rtl::OUString
SubstitutePathVariables::impl_reSubstituteVariables( const ::rtl::OUString
& rURL
)
992 throw ( RuntimeException
)
994 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_reSubstituteVariables" );
997 INetURLObject
aUrl( rURL
);
998 if ( !aUrl
.HasError() )
999 aURL
= aUrl
.GetMainURL( INetURLObject::NO_DECODE
);
1002 // Convert a system path to a UCB compliant URL before resubstitution
1003 rtl::OUString aTemp
;
1004 if ( osl::FileBase::getFileURLFromSystemPath( rURL
, aTemp
) == osl::FileBase::E_None
)
1006 aTemp
= ConvertOSLtoUCBURL( aTemp
);
1007 if ( aTemp
.getLength() )
1008 aURL
= INetURLObject( aTemp
).GetMainURL( INetURLObject::NO_DECODE
);
1014 // rURL is not a valid URL nor a osl system path. Give up and return error!
1019 // Due to a recursive definition this code must exchange variables with variables!
1020 sal_Bool bResubstitutionCompleted
= sal_False
;
1021 sal_Bool bVariableFound
= sal_False
;
1023 // Get transient predefined path variable $(work) value before starting resubstitution
1024 m_aPreDefVars
.m_FixedVar
[ PREDEFVAR_WORK
] = GetWorkVariableValue();
1026 while ( !bResubstitutionCompleted
)
1028 ReSubstFixedVarOrderVector::const_iterator pIterFixed
;
1029 for ( pIterFixed
= m_aReSubstFixedVarOrder
.begin(); pIterFixed
!= m_aReSubstFixedVarOrder
.end(); pIterFixed
++ )
1031 rtl::OUString aValue
= m_aPreDefVars
.m_FixedVar
[ (sal_Int32
)pIterFixed
->eVariable
];
1032 sal_Int32 nPos
= aURL
.indexOf( aValue
);
1035 sal_Bool bMatch
= sal_True
;
1036 if ( pIterFixed
->eVariable
== PREDEFVAR_LANG
||
1037 pIterFixed
->eVariable
== PREDEFVAR_LANGID
||
1038 pIterFixed
->eVariable
== PREDEFVAR_VLANG
)
1040 // Special path variables as they can occur in the middle of a path. Only match if they
1041 // describe a whole directory and not only a substring of a directory!
1042 const sal_Unicode
* pStr
= aURL
.getStr();
1045 bMatch
= ( aURL
[ nPos
-1 ] == '/' );
1049 if ( nPos
+ aValue
.getLength() < aURL
.getLength() )
1050 bMatch
= ( pStr
[ nPos
+ aValue
.getLength() ] == '/' );
1056 rtl::OUStringBuffer
aStrBuffer( aURL
.getLength() );
1057 aStrBuffer
.append( aURL
.copy( 0, nPos
) );
1058 aStrBuffer
.append( m_aPreDefVars
.m_FixedVarNames
[ (sal_Int32
)pIterFixed
->eVariable
] ); // Get the variable name for struct var name array!
1059 aStrBuffer
.append( aURL
.copy( nPos
+ aValue
.getLength(), ( aURL
.getLength() - ( nPos
+ aValue
.getLength() )) ));
1060 aURL
= aStrBuffer
.makeStringAndClear();
1061 bVariableFound
= sal_True
; // Resubstitution not finished yet!
1067 // This part can be iteratered more than one time as variables can contain variables again!
1068 ReSubstUserVarOrderVector::const_iterator pIterUser
;
1069 for ( pIterUser
= m_aReSubstUserVarOrder
.begin(); pIterUser
!= m_aReSubstUserVarOrder
.end(); pIterUser
++ )
1071 rtl::OUString aVarValue
= pIterUser
->aVarName
;
1072 sal_Int32 nPos
= aURL
.indexOf( aVarValue
);
1075 rtl::OUStringBuffer
aStrBuffer( aURL
.getLength() );
1076 aStrBuffer
.append( aURL
.copy( 0, nPos
) );
1077 aStrBuffer
.append( m_aVarStart
);
1078 aStrBuffer
.append( aVarValue
);
1079 aStrBuffer
.append( m_aVarEnd
);
1080 aStrBuffer
.append( aURL
.copy( nPos
+ aVarValue
.getLength(), ( aURL
.getLength() - ( nPos
+ aVarValue
.getLength() )) ));
1081 aURL
= aStrBuffer
.makeStringAndClear();
1082 bVariableFound
= sal_True
; // Resubstitution not finished yet!
1086 if ( !bVariableFound
)
1087 bResubstitutionCompleted
= sal_True
;
1089 bVariableFound
= sal_False
; // Next resubstitution
1095 // This method support both request schemes "$("<varname>")" or "<varname>".
1096 ::rtl::OUString
SubstitutePathVariables::impl_getSubstituteVariableValue( const ::rtl::OUString
& rVariable
)
1097 throw ( NoSuchElementException
, RuntimeException
)
1099 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_getSubstituteVariableValue" );
1100 rtl::OUString aVariable
;
1102 sal_Int32 nPos
= rVariable
.indexOf( m_aVarStart
);
1105 // Prepare variable name before hash map access
1106 rtl::OUStringBuffer
aStrBuffer( rVariable
.getLength() + m_aVarStart
.getLength() + m_aVarEnd
.getLength() );
1107 aStrBuffer
.append( m_aVarStart
);
1108 aStrBuffer
.append( rVariable
);
1109 aStrBuffer
.append( m_aVarEnd
);
1110 aVariable
= aStrBuffer
.makeStringAndClear();
1113 VarNameToIndexMap::const_iterator pNTOIIter
= m_aPreDefVarMap
.find( ( nPos
== -1 ) ? aVariable
: rVariable
);
1115 // Fixed/Predefined variable
1116 if ( pNTOIIter
!= m_aPreDefVarMap
.end() )
1118 PreDefVariable nIndex
= (PreDefVariable
)pNTOIIter
->second
;
1119 return m_aPreDefVars
.m_FixedVar
[(sal_Int32
)nIndex
];
1123 // Prepare variable name before hash map access
1126 if ( rVariable
.getLength() > 3 )
1127 aVariable
= rVariable
.copy( 2, rVariable
.getLength() - 3 );
1130 rtl::OUString
aExceptionText( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable!" ));
1131 throw NoSuchElementException();
1135 aVariable
= rVariable
;
1137 // User defined variable
1138 SubstituteVariables::const_iterator pIter
= m_aSubstVarMap
.find( aVariable
);
1139 if ( pIter
!= m_aSubstVarMap
.end() )
1142 return pIter
->second
.aSubstValue
;
1145 rtl::OUString
aExceptionText( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable!" ));
1146 throw NoSuchElementException( aExceptionText
, (cppu::OWeakObject
*)this );
1150 void SubstitutePathVariables::SetPredefinedPathVariables( PredefinedPathVariables
& aPreDefPathVariables
)
1152 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::SetPredefinedPathVariables" );
1154 ::rtl::OUString aOfficePath
;
1155 ::rtl::OUString aUserPath
;
1156 ::rtl::OUString aTmp
;
1157 ::rtl::OUString aTmp2
;
1160 // Get inspath and userpath from bootstrap mechanism in every case as file URL
1161 ::utl::Bootstrap::PathStatus aState
;
1162 ::rtl::OUString sVal
;
1164 aState
= utl::Bootstrap::locateBaseInstallation( sVal
);
1165 if( aState
==::utl::Bootstrap::PATH_EXISTS
) {
1166 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTPATH
] = ConvertOSLtoUCBURL( sVal
);
1169 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Bootstrap code has no value for instpath!");
1172 aState
= utl::Bootstrap::locateUserData( sVal
);
1173 if( aState
== ::utl::Bootstrap::PATH_EXISTS
) {
1174 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERPATH
] = ConvertOSLtoUCBURL( sVal
);
1177 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Bootstrap code has no value for userpath");
1180 // Set $(inst), $(instpath), $(insturl)
1181 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTURL
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTPATH
];
1182 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INST
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTPATH
];
1183 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
1184 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_BASEINSTURL
]= aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTPATH
];
1187 // Set $(user), $(userpath), $(userurl)
1188 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERURL
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERPATH
];
1189 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USER
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERPATH
];
1190 // --> PB 2004-11-11 #i32656# - new variable of hierachy service
1191 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERDATAURL
]= aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_USERPATH
];
1194 // Detect the program directory
1195 // Set $(prog), $(progpath), $(progurl)
1196 INetURLObject
aProgObj(
1197 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_INSTPATH
] );
1198 if ( !aProgObj
.HasError() &&
1199 aProgObj
.insertName(
1200 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("program")) ) )
1202 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PROGPATH
] = aProgObj
.GetMainURL(INetURLObject::NO_DECODE
);
1203 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PROGURL
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PROGPATH
];
1204 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PROG
] = aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PROGPATH
];
1207 // Detect the language type of the current office
1208 aPreDefPathVariables
.m_eLanguageType
= LANGUAGE_ENGLISH_US
;
1209 rtl::OUString aLocaleStr
;
1210 if ( utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty( utl::ConfigManager::LOCALE
) >>= aLocaleStr
)
1211 aPreDefPathVariables
.m_eLanguageType
= MsLangId::convertIsoStringToLanguage( aLocaleStr
);
1214 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Wrong Any type for language!" );
1218 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_LANG
] = ConvertOSLtoUCBURL(
1219 rtl::OUString::createFromAscii( ResMgr::GetLang( aPreDefPathVariables
.m_eLanguageType
, 0 ) ));
1221 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_VLANG
] = aLocaleStr
;
1224 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_LANGID
] = rtl::OUString::valueOf( (sal_Int32
)aPreDefPathVariables
.m_eLanguageType
);
1226 // Set the other pre defined path variables
1228 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_WORK
] = GetWorkVariableValue();
1229 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_HOME
] = GetHomeVariableValue();
1231 // Set $(workdirurl) this is the value of the path PATH_WORK which doesn't make sense
1232 // anymore because the path settings service has this value! It can deliver this value more
1233 // quickly than the substitution service!
1234 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_WORKDIRURL
] = GetWorkPath();
1236 // Set $(path) variable
1237 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_PATH
] = GetPathVariableValue();
1240 osl::FileBase::getTempDirURL( aTmp
);
1241 aPreDefPathVariables
.m_FixedVar
[ PREDEFVAR_TEMP
] = ConvertOSLtoUCBURL( aTmp
);
1243 aPreDefPathVariables
.m_FixedVar
[PREDEFVAR_BRANDBASEURL
] = rtl::OUString(
1244 RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR"));
1245 rtl::Bootstrap::expandMacros(
1246 aPreDefPathVariables
.m_FixedVar
[PREDEFVAR_BRANDBASEURL
]);
1249 } // namespace framework