merge the formfield patch from ooo-build
[ooovba.git] / framework / source / services / substitutepathvars.cxx
blobee766efeee4e7bf0606c7c3eb383c13a5b8303e9
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.cxx,v $
10 * $Revision: 1.22 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include "services/substitutepathvars.hxx"
38 #include <threadhelp/resetableguard.hxx>
39 #include <helper/networkdomain.hxx>
40 #include "services.h"
42 //_________________________________________________________________________________________________________________
43 // interface includes
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/beans/XPropertySet.hpp>
47 //_________________________________________________________________________________________________________________
48 // includes of other projects
49 //_________________________________________________________________________________________________________________
50 #include <unotools/configitem.hxx>
51 #include <unotools/localfilehelper.hxx>
52 #include <unotools/configmgr.hxx>
54 #ifndef _UTL_BOOTSTRAP_HXX_
55 #include <unotools/bootstrap.hxx>
56 #endif
57 #include <osl/mutex.hxx>
58 #include <osl/file.hxx>
59 #include <osl/security.hxx>
60 #include <osl/socket.hxx>
61 #include <vos/process.hxx>
62 #include <i18npool/mslangid.hxx>
63 #include <tools/urlobj.hxx>
64 #include <tools/resmgr.hxx>
65 #include <tools/debug.hxx>
66 #include <tools/wldcrd.hxx>
67 #include <rtl/ustrbuf.hxx>
68 #include <rtl/bootstrap.hxx>
70 #include <comphelper/configurationhelper.hxx>
72 #include <string.h>
74 //_________________________________________________________________________________________________________________
75 // Defines
76 //_________________________________________________________________________________________________________________
79 #define STRPOS_NOTFOUND (sal_Int32)-1
81 #define ASCII_STR( val ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( val ))
83 #define SEARCHPATH_DELIMITER ';'
85 // Variable start/end characters
86 #define SIGN_STARTVARIABLE ASCII_STR("$(")
87 #define SIGN_ENDVARIABLE ASCII_STR(")")
89 // Length of SUBSTITUTE_... to replace it with real values.
90 #define REPLACELENGTH_INST 7
91 #define REPLACELENGTH_PROG 7
92 #define REPLACELENGTH_USER 7
93 #define REPLACELENGTH_WORK 7
94 #define REPLACELENGTH_HOME 7
95 #define REPLACELENGTH_TEMP 7
96 #define REPLACELENGTH_PATH 7
97 #define REPLACELENGTH_INSTPATH 11
98 #define REPLACELENGTH_PROGPATH 11
99 #define REPLACELENGTH_USERPATH 11
100 #define REPLACELENGTH_INSTURL 10
101 #define REPLACELENGTH_PROGURL 10
102 #define REPLACELENGTH_USERURL 10
103 #define REPLACELENGTH_PATH 7
104 #define REPLACELENGTH_LANG 7
105 #define REPLACELENGTH_LANGID 9
106 #define REPLACELENGTH_VLANG 8
107 #define REPLACELENGTH_WORKDIRURL 13
108 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
109 #define REPLACELENGTH_BASEINSTURL 14
110 #define REPLACELENGTH_USERDATAURL 14
111 // <--
113 // Name of the pre defined path variables
114 #define VARIABLE_INST "$(inst)"
115 #define VARIABLE_PROG "$(prog)"
116 #define VARIABLE_USER "$(user)"
117 #define VARIABLE_WORK "$(work)"
118 #define VARIABLE_HOME "$(home)"
119 #define VARIABLE_TEMP "$(temp)"
120 #define VARIABLE_PATH "$(path)"
121 #define VARIABLE_LANG "$(lang)"
122 #define VARIABLE_LANGID "$(langid)"
123 #define VARIABLE_VLANG "$(vlang)"
124 #define VARIABLE_INSTPATH "$(instpath)"
125 #define VARIABLE_PROGPATH "$(progpath)"
126 #define VARIABLE_USERPATH "$(userpath)"
127 #define VARIABLE_INSTURL "$(insturl)"
128 #define VARIABLE_PROGURL "$(progurl)"
129 #define VARIABLE_USERURL "$(userurl)"
130 #define VARIABLE_WORKDIRURL "$(workdirurl)"
131 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
132 #define VARIABLE_BASEINSTURL "$(baseinsturl)"
133 #define VARIABLE_USERDATAURL "$(userdataurl)"
134 // <--
136 using namespace com::sun::star::uno;
137 using namespace com::sun::star::beans;
138 using namespace com::sun::star::util;
139 using namespace com::sun::star::lang;
140 using namespace com::sun::star::container;
142 //_________________________________________________________________________________________________________________
143 // Namespace
144 //_________________________________________________________________________________________________________________
147 namespace framework
150 struct FixedVariable
152 const char* pVarName;
153 PreDefVariable nEnumValue;
154 int nStrLen;
157 struct TableEntry
159 const char* pOSString;
160 int nStrLen;
163 // Table with valid operating system strings
164 // Name of the os as char* and the length
165 // of the string
166 static TableEntry aOSTable[OS_COUNT] =
168 { "WINDOWS" , 7 },
169 { "UNIX" , 4 },
170 { "SOLARIS" , 7 },
171 { "LINUX" , 5 },
172 { "" , 0 } // unknown
175 // Table with valid environment variables
176 // Name of the environment type as a char* and
177 // the length of the string.
178 static TableEntry aEnvTable[ET_COUNT] =
180 { "HOST" , 4 },
181 { "YPDOMAIN" , 8 },
182 { "DNSDOMAIN" , 9 },
183 { "NTDOMAIN" , 8 },
184 { "OS" , 2 },
185 { "" , 0 } // unknown
188 // Priority table for the environment types. Lower numbers define
189 // a higher priority. Equal numbers has the same priority that means
190 // that the first match wins!!
191 static sal_Int16 aEnvPrioTable[ET_COUNT] =
193 1, // ET_HOST
194 2, // ET_IPDOMAIN
195 2, // ET_DNSDOMAIN
196 2, // ET_NTDOMAIN
197 3, // ET_OS
198 99, // ET_UNKNOWN
201 // Table with all fixed/predefined variables supported.
202 static FixedVariable aFixedVarTable[] =
204 { VARIABLE_INST, PREDEFVAR_INST, REPLACELENGTH_INST },
205 { VARIABLE_PROG, PREDEFVAR_PROG, REPLACELENGTH_PROG },
206 { VARIABLE_USER, PREDEFVAR_USER, REPLACELENGTH_USER },
207 { VARIABLE_WORK, PREDEFVAR_WORK, REPLACELENGTH_WORK }, // Special variable (transient)!
208 { VARIABLE_HOME, PREDEFVAR_HOME, REPLACELENGTH_HOME },
209 { VARIABLE_TEMP, PREDEFVAR_TEMP, REPLACELENGTH_TEMP },
210 { VARIABLE_PATH, PREDEFVAR_PATH, REPLACELENGTH_PATH },
211 { VARIABLE_LANG, PREDEFVAR_LANG, REPLACELENGTH_LANG },
212 { VARIABLE_LANGID, PREDEFVAR_LANGID, REPLACELENGTH_LANGID },
213 { VARIABLE_VLANG, PREDEFVAR_VLANG, REPLACELENGTH_VLANG },
214 { VARIABLE_INSTPATH, PREDEFVAR_INSTPATH, REPLACELENGTH_INSTPATH },
215 { VARIABLE_PROGPATH, PREDEFVAR_PROGPATH, REPLACELENGTH_PROGPATH },
216 { VARIABLE_USERPATH, PREDEFVAR_USERPATH, REPLACELENGTH_USERPATH },
217 { VARIABLE_INSTURL, PREDEFVAR_INSTURL, REPLACELENGTH_INSTURL },
218 { VARIABLE_PROGURL, PREDEFVAR_PROGURL, REPLACELENGTH_PROGURL },
219 { VARIABLE_USERURL, PREDEFVAR_USERURL, REPLACELENGTH_USERURL },
220 { VARIABLE_WORKDIRURL, PREDEFVAR_WORKDIRURL, REPLACELENGTH_WORKDIRURL }, // Special variable (transient) and don't use for resubstitution!
221 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
222 { VARIABLE_BASEINSTURL, PREDEFVAR_BASEINSTURL, REPLACELENGTH_BASEINSTURL },
223 { VARIABLE_USERDATAURL, PREDEFVAR_USERDATAURL, REPLACELENGTH_USERDATAURL },
224 // <--
225 { "$(brandbaseurl)", PREDEFVAR_BRANDBASEURL,
226 RTL_CONSTASCII_LENGTH("$(brandbaseurl)") }
229 //_________________________________________________________________________________________________________________
230 // Implementation helper classes
231 //_________________________________________________________________________________________________________________
234 OperatingSystem SubstitutePathVariables_Impl::GetOperatingSystemFromString( const rtl::OUString& aOSString )
236 for ( int i = 0; i < OS_COUNT; i++ )
238 if ( aOSString.equalsIgnoreAsciiCaseAsciiL( aOSTable[i].pOSString, aOSTable[i].nStrLen ))
239 return (OperatingSystem)i;
242 return OS_UNKNOWN;
245 EnvironmentType SubstitutePathVariables_Impl::GetEnvTypeFromString( const rtl::OUString& aEnvTypeString )
247 for ( int i = 0; i < ET_COUNT; i++ )
249 if ( aEnvTypeString.equalsIgnoreAsciiCaseAsciiL( aEnvTable[i].pOSString, aEnvTable[i].nStrLen ))
250 return (EnvironmentType)i;
253 return ET_UNKNOWN;
256 SubstitutePathVariables_Impl::SubstitutePathVariables_Impl( const Link& aNotifyLink ) :
257 utl::ConfigItem( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.Substitution" ))),
258 m_bYPDomainRetrieved( sal_False ),
259 m_bDNSDomainRetrieved( sal_False ),
260 m_bNTDomainRetrieved( sal_False ),
261 m_bHostRetrieved( sal_False ),
262 m_bOSRetrieved( sal_False ),
263 m_aListenerNotify( aNotifyLink ),
264 m_aSharePointsNodeName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SharePoints" ))),
265 m_aDirPropertyName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Directory" ))),
266 m_aEnvPropertyName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Environment" ))),
267 m_aLevelSep( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" )))
269 // Enable notification mechanism
270 // We need it to get information about changes outside these class on our configuration branch
271 Sequence< rtl::OUString > aNotifySeq( 1 );
272 aNotifySeq[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SharePoints" ));
273 EnableNotification( aNotifySeq, sal_True );
276 SubstitutePathVariables_Impl::~SubstitutePathVariables_Impl()
280 void SubstitutePathVariables_Impl::GetSharePointsRules( SubstituteVariables& aSubstVarMap )
282 Sequence< rtl::OUString > aSharePointNames;
283 ReadSharePointsFromConfiguration( aSharePointNames );
285 if ( aSharePointNames.getLength() > 0 )
287 sal_Int32 nSharePoints = 0;
289 // Read SharePoints container from configuration
290 while ( nSharePoints < aSharePointNames.getLength() )
292 rtl::OUString aSharePointNodeName( m_aSharePointsNodeName );
293 aSharePointNodeName += rtl::OUString::createFromAscii( "/" );
294 aSharePointNodeName += aSharePointNames[ nSharePoints ];
296 SubstituteRuleVector aRuleSet;
297 ReadSharePointRuleSetFromConfiguration( aSharePointNames[ nSharePoints ], aSharePointNodeName, aRuleSet );
298 if ( !aRuleSet.empty() )
300 // We have at minimum one rule. Filter the correct rule out of the rule set
301 // and put into our SubstituteVariable map
302 SubstituteRule aActiveRule;
303 if ( FilterRuleSet( aRuleSet, aActiveRule ))
305 // We have found an active rule
306 aActiveRule.aSubstVariable = aSharePointNames[ nSharePoints ];
307 aSubstVarMap.insert( SubstituteVariables::value_type(
308 aActiveRule.aSubstVariable, aActiveRule ));
312 ++nSharePoints;
317 void SubstitutePathVariables_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& /*aPropertyNames*/ )
319 // NOT implemented yet!
322 //_________________________________________________________________________________________________________________
323 // private methods
324 //_________________________________________________________________________________________________________________
327 OperatingSystem SubstitutePathVariables_Impl::GetOperatingSystem()
329 if ( !m_bOSRetrieved )
331 #ifdef SOLARIS
332 m_eOSType = OS_SOLARIS;
333 #elif defined LINUX
334 m_eOSType = OS_LINUX;
335 #elif defined WIN32
336 m_eOSType = OS_WINDOWS;
337 #elif defined UNIX
338 m_eOSType = OS_UNIX;
339 #else
340 m_eOSType = OS_UNKNOWN;
341 #endif
342 m_bOSRetrieved = sal_True;
345 return m_eOSType;
348 const rtl::OUString& SubstitutePathVariables_Impl::GetYPDomainName()
350 if ( !m_bYPDomainRetrieved )
352 m_aYPDomain = NetworkDomain::GetYPDomainName().toAsciiLowerCase();
353 m_bYPDomainRetrieved = sal_True;
356 return m_aYPDomain;
359 const rtl::OUString& SubstitutePathVariables_Impl::GetDNSDomainName()
361 if ( !m_bDNSDomainRetrieved )
363 rtl::OUString aTemp;
364 osl::SocketAddr aSockAddr;
365 oslSocketResult aResult;
367 rtl::OUString aHostName = GetHostName();
368 osl::SocketAddr::resolveHostname( aHostName, aSockAddr );
369 aTemp = aSockAddr.getHostname( &aResult );
371 // DNS domain name begins after the first "."
372 sal_Int32 nIndex = aTemp.indexOf( '.' );
373 if ( nIndex >= 0 && aTemp.getLength() > nIndex+1 )
374 m_aDNSDomain = aTemp.copy( nIndex+1 ).toAsciiLowerCase();
375 else
376 m_aDNSDomain = rtl::OUString();
378 m_bDNSDomainRetrieved = sal_True;
381 return m_aDNSDomain;
384 const rtl::OUString& SubstitutePathVariables_Impl::GetNTDomainName()
386 if ( !m_bNTDomainRetrieved )
388 m_aNTDomain = NetworkDomain::GetNTDomainName().toAsciiLowerCase();
389 m_bNTDomainRetrieved = sal_True;
392 return m_aNTDomain;
395 const rtl::OUString& SubstitutePathVariables_Impl::GetHostName()
397 if ( !m_bHostRetrieved )
399 rtl::OUString aHostName;
400 oslSocketResult aSocketResult;
402 m_aHost = osl::SocketAddr::getLocalHostname( &aSocketResult ).toAsciiLowerCase();
405 return m_aHost;
408 sal_Bool SubstitutePathVariables_Impl::FilterRuleSet( const SubstituteRuleVector& aRuleSet, SubstituteRule& aActiveRule )
410 sal_Bool bResult = sal_False;
412 if ( !aRuleSet.empty() )
414 sal_Int16 nPrioCurrentRule = aEnvPrioTable[ ET_UNKNOWN ];
415 const sal_uInt32 nCount = aRuleSet.size();
416 for ( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ )
418 const SubstituteRule& aRule = aRuleSet[nIndex];
419 EnvironmentType eEnvType = aRule.aEnvType;
421 // Check if environment type has a higher priority than current one!
422 if ( nPrioCurrentRule > aEnvPrioTable[eEnvType] )
424 switch ( eEnvType )
426 case ET_HOST:
428 rtl::OUString aHost = GetHostName();
429 rtl::OUString aHostStr;
430 aRule.aEnvValue >>= aHostStr;
431 aHostStr = aHostStr.toAsciiLowerCase();
433 // Pattern match if domain environment match
434 WildCard aPattern(aHostStr);
435 sal_Bool bMatch = aPattern.Matches(aHost);
436 if ( bMatch )
438 aActiveRule = aRule;
439 bResult = sal_True;
440 nPrioCurrentRule = aEnvPrioTable[eEnvType];
443 break;
445 case ET_YPDOMAIN:
446 case ET_DNSDOMAIN:
447 case ET_NTDOMAIN:
449 rtl::OUString aDomain;
450 rtl::OUString aDomainStr;
451 aRule.aEnvValue >>= aDomainStr;
452 aDomainStr = aDomainStr.toAsciiLowerCase();
454 // Retrieve the correct domain value
455 if ( eEnvType == ET_YPDOMAIN )
456 aDomain = GetYPDomainName();
457 else if ( eEnvType == ET_DNSDOMAIN )
458 aDomain = GetDNSDomainName();
459 else
460 aDomain = GetNTDomainName();
462 // Pattern match if domain environment match
463 WildCard aPattern(aDomainStr);
464 sal_Bool bMatch = aPattern.Matches(aDomain);
465 if ( bMatch )
467 aActiveRule = aRule;
468 bResult = sal_True;
469 nPrioCurrentRule = aEnvPrioTable[eEnvType];
472 break;
474 case ET_OS:
476 // No pattern matching for OS type
477 OperatingSystem eOSType = GetOperatingSystem();
479 sal_Int16 nValue = 0;
480 aRule.aEnvValue >>= nValue;
482 sal_Bool bUnix = ( eOSType == OS_LINUX ) || ( eOSType == OS_SOLARIS );
483 OperatingSystem eRuleOSType = (OperatingSystem)nValue;
485 // Match if OS identical or rule is set to UNIX and OS is LINUX/SOLARIS!
486 if (( eRuleOSType == eOSType ) || ( eRuleOSType == OS_UNIX && bUnix ))
488 aActiveRule = aRule;
489 bResult = sal_True;
490 nPrioCurrentRule = aEnvPrioTable[eEnvType];
493 break;
495 case ET_UNKNOWN: // nothing to do
496 break;
498 default:
499 break;
505 return bResult;
508 void SubstitutePathVariables_Impl::ReadSharePointsFromConfiguration( Sequence< rtl::OUString >& aSharePointsSeq )
510 //returns all the names of all share point nodes
511 aSharePointsSeq = GetNodeNames( m_aSharePointsNodeName );
514 void SubstitutePathVariables_Impl::ReadSharePointRuleSetFromConfiguration(
515 const rtl::OUString& aSharePointName,
516 const rtl::OUString& aSharePointNodeName,
517 SubstituteRuleVector& rRuleSet )
519 Sequence< rtl::OUString > aSharePointMappingsNodeNames = GetNodeNames( aSharePointNodeName, utl::CONFIG_NAME_LOCAL_PATH );
521 sal_Int32 nSharePointMapping = 0;
522 while ( nSharePointMapping < aSharePointMappingsNodeNames.getLength() )
524 rtl::OUString aSharePointMapping( aSharePointNodeName );
525 aSharePointMapping += m_aLevelSep;
526 aSharePointMapping += aSharePointMappingsNodeNames[ nSharePointMapping ];
528 // Read SharePointMapping
529 rtl::OUString aDirValue;
530 rtl::OUString aDirProperty( aSharePointMapping );
531 aDirProperty += m_aDirPropertyName;
533 // Read only the directory property
534 Sequence< rtl::OUString > aDirPropertySeq( 1 );
535 aDirPropertySeq[0] = aDirProperty;
537 Sequence< Any > aValueSeq = GetProperties( aDirPropertySeq );
538 if ( aValueSeq.getLength() == 1 )
539 aValueSeq[0] >>= aDirValue;
541 // Read the environment setting
542 rtl::OUString aEnvUsed;
543 rtl::OUString aEnvProperty( aSharePointMapping );
544 aEnvProperty += m_aEnvPropertyName;
545 Sequence< rtl::OUString > aEnvironmentVariable = GetNodeNames( aEnvProperty );
547 // Filter the property which has a value set
548 Sequence< rtl::OUString > aEnvUsedPropertySeq( aEnvironmentVariable.getLength() );
550 rtl::OUString aEnvUsePropNameTemplate( aEnvProperty );
551 aEnvUsePropNameTemplate += m_aLevelSep;
553 for ( sal_Int32 nProperty = 0; nProperty < aEnvironmentVariable.getLength(); nProperty++ )
554 aEnvUsedPropertySeq[nProperty] = rtl::OUString( aEnvUsePropNameTemplate + aEnvironmentVariable[nProperty] );
556 Sequence< Any > aEnvUsedValueSeq;
557 aEnvUsedValueSeq = GetProperties( aEnvUsedPropertySeq );
559 rtl::OUString aEnvUsedValue;
560 for ( sal_Int32 nIndex = 0; nIndex < aEnvironmentVariable.getLength(); nIndex++ )
562 if ( aEnvUsedValueSeq[nIndex] >>= aEnvUsedValue )
564 aEnvUsed = aEnvironmentVariable[nIndex];
565 break;
569 // Decode the environment and optional the operatng system settings
570 Any aEnvValue;
571 EnvironmentType eEnvType = GetEnvTypeFromString( aEnvUsed );
572 if ( eEnvType == ET_OS )
574 OperatingSystem eOSType = GetOperatingSystemFromString( aEnvUsedValue );
575 aEnvValue <<= (sal_Int16)eOSType;
577 else
578 aEnvValue <<= aEnvUsedValue;
580 // Create rule struct and push it into the rule set
581 SubstituteRule aRule( aSharePointName, aDirValue, aEnvValue, eEnvType );
582 rRuleSet.push_back( aRule );
584 ++nSharePointMapping;
588 //*****************************************************************************************************************
589 // XInterface, XTypeProvider, XServiceInfo
590 //*****************************************************************************************************************
591 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( SubstitutePathVariables ,
592 ::cppu::OWeakObject ,
593 SERVICENAME_SUBSTITUTEPATHVARIABLES ,
594 IMPLEMENTATIONNAME_SUBSTITUTEPATHVARIABLES
597 DEFINE_INIT_SERVICE ( SubstitutePathVariables, {} )
600 SubstitutePathVariables::SubstitutePathVariables( const Reference< XMultiServiceFactory >& xServiceManager ) :
601 ThreadHelpBase(),
602 m_aVarStart( SIGN_STARTVARIABLE ),
603 m_aVarEnd( SIGN_ENDVARIABLE ),
604 m_aImpl( LINK( this, SubstitutePathVariables, implts_ConfigurationNotify )),
605 m_xServiceManager( xServiceManager )
607 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::SubstitutePathVariables" );
608 int i;
610 SetPredefinedPathVariables( m_aPreDefVars );
611 m_aImpl.GetSharePointsRules( m_aSubstVarMap );
613 // Init the predefined/fixed variable to index hash map
614 for ( i = 0; i < PREDEFVAR_COUNT; i++ )
616 // Store variable name into struct of predefined/fixed variables
617 m_aPreDefVars.m_FixedVarNames[i] = rtl::OUString::createFromAscii( aFixedVarTable[i].pVarName );
619 // Create hash map entry
620 m_aPreDefVarMap.insert( VarNameToIndexMap::value_type(
621 m_aPreDefVars.m_FixedVarNames[i], aFixedVarTable[i].nEnumValue ) );
624 // Sort predefined/fixed variable to path length
625 for ( i = 0; i < PREDEFVAR_COUNT; i++ )
627 if (( i != PREDEFVAR_WORKDIRURL ) &&
628 ( i != PREDEFVAR_PATH ))
630 // Special path variables, don't include into automatic resubstituion search!
631 // $(workdirurl) is not allowed to resubstitute! This variable is the value of path settings entry
632 // and it could be possible that it will be resubstituted by itself!!
633 // Example: WORK_PATH=c:\test, $(workdirurl)=WORK_PATH => WORK_PATH=$(workdirurl) and this cannot be substituted!
634 ReSubstFixedVarOrder aFixedVar;
635 aFixedVar.eVariable = aFixedVarTable[i].nEnumValue;
636 aFixedVar.nVarValueLength = m_aPreDefVars.m_FixedVar[(sal_Int32)aFixedVar.eVariable].getLength();
637 m_aReSubstFixedVarOrder.push_back( aFixedVar );
640 m_aReSubstFixedVarOrder.sort();
642 // Sort user variables to path length
643 SubstituteVariables::const_iterator pIter;
644 for ( pIter = m_aSubstVarMap.begin(); pIter != m_aSubstVarMap.end(); pIter++ )
646 ReSubstUserVarOrder aUserOrderVar;
647 rtl::OUStringBuffer aStrBuffer( pIter->second.aSubstVariable.getLength() );
648 aStrBuffer.append( m_aVarStart );
649 aStrBuffer.append( pIter->second.aSubstVariable );
650 aStrBuffer.append( m_aVarEnd );
651 aUserOrderVar.aVarName = aStrBuffer.makeStringAndClear();
652 aUserOrderVar.nVarValueLength = pIter->second.aSubstVariable.getLength();
653 m_aReSubstUserVarOrder.push_back( aUserOrderVar );
655 m_aReSubstUserVarOrder.sort();
658 SubstitutePathVariables::~SubstitutePathVariables()
662 // XStringSubstitution
663 rtl::OUString SAL_CALL SubstitutePathVariables::substituteVariables( const ::rtl::OUString& aText, sal_Bool bSubstRequired )
664 throw ( NoSuchElementException, RuntimeException )
666 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::substituteVariables" );
667 ResetableGuard aLock( m_aLock );
668 return impl_substituteVariable( aText, bSubstRequired );
671 rtl::OUString SAL_CALL SubstitutePathVariables::reSubstituteVariables( const ::rtl::OUString& aText )
672 throw ( RuntimeException )
674 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::reSubstituteVariables" );
675 ResetableGuard aLock( m_aLock );
676 return impl_reSubstituteVariables( aText );
679 rtl::OUString SAL_CALL SubstitutePathVariables::getSubstituteVariableValue( const ::rtl::OUString& aVariable )
680 throw ( NoSuchElementException, RuntimeException )
682 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::getSubstituteVariableValue" );
683 ResetableGuard aLock( m_aLock );
684 return impl_getSubstituteVariableValue( aVariable );
687 //_________________________________________________________________________________________________________________
688 // protected methods
689 //_________________________________________________________________________________________________________________
692 IMPL_LINK( SubstitutePathVariables, implts_ConfigurationNotify, SubstitutePathNotify*, EMPTYARG )
694 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
695 ResetableGuard aLock( m_aLock );
697 return 0;
700 rtl::OUString SubstitutePathVariables::ConvertOSLtoUCBURL( const rtl::OUString& aOSLCompliantURL ) const
702 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::ConvertOSLtoUCBURL" );
703 String aResult;
704 rtl::OUString aTemp;
706 osl::FileBase::getSystemPathFromFileURL( aOSLCompliantURL, aTemp );
707 utl::LocalFileHelper::ConvertPhysicalNameToURL( aTemp, aResult );
709 // Not all OSL URL's can be mapped to UCB URL's!
710 if ( aResult.Len() == 0 )
711 return aOSLCompliantURL;
712 else
713 return rtl::OUString( aResult );
716 rtl::OUString SubstitutePathVariables::GetWorkPath() const
718 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetWorkPath" );
719 rtl::OUString aWorkPath;
720 ::comphelper::ConfigurationHelper::readDirectKey(
721 m_xServiceManager,
722 ::rtl::OUString::createFromAscii("org.openoffice.Office.Paths"),
723 ::rtl::OUString::createFromAscii("Paths/Work"),
724 ::rtl::OUString::createFromAscii("WritePath"),
725 ::comphelper::ConfigurationHelper::E_READONLY) >>= aWorkPath;
726 return aWorkPath;
729 rtl::OUString SubstitutePathVariables::GetWorkVariableValue() const
731 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetWorkVariableValue" );
732 ::rtl::OUString aWorkPath;
733 ::comphelper::ConfigurationHelper::readDirectKey(
734 m_xServiceManager,
735 ::rtl::OUString::createFromAscii("org.openoffice.Office.Paths"),
736 ::rtl::OUString::createFromAscii("Variables"),
737 ::rtl::OUString::createFromAscii("Work"),
738 ::comphelper::ConfigurationHelper::E_READONLY) >>= aWorkPath;
740 // fallback to $HOME in case platform dependend config layer does not return
741 // an usuable work dir value.
742 if (aWorkPath.getLength() < 1)
744 osl::Security aSecurity;
745 aSecurity.getHomeDir( aWorkPath );
747 return ConvertOSLtoUCBURL( aWorkPath );
750 rtl::OUString SubstitutePathVariables::GetHomeVariableValue() const
752 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetHomeVariableValue" );
753 osl::Security aSecurity;
754 rtl::OUString aHomePath;
756 aSecurity.getHomeDir( aHomePath );
757 return ConvertOSLtoUCBURL( aHomePath );
760 rtl::OUString SubstitutePathVariables::GetPathVariableValue() const
762 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::GetPathVariableValue" );
763 const int PATH_EXTEND_FACTOR = 120;
765 rtl::OUString aRetStr;
766 const char* pEnv = getenv( "PATH" );
768 if ( pEnv )
770 rtl::OUString aTmp;
771 rtl::OUString aPathList( pEnv, strlen( pEnv ), gsl_getSystemTextEncoding() );
772 rtl::OUStringBuffer aPathStrBuffer( aPathList.getLength() * PATH_EXTEND_FACTOR / 100 );
774 sal_Bool bAppendSep = sal_False;
775 sal_Int32 nToken = 0;
778 ::rtl::OUString sToken = aPathList.getToken(0, SAL_PATHSEPARATOR, nToken);
779 if (sToken.getLength())
781 osl::FileBase::getFileURLFromSystemPath( sToken, aTmp );
782 if ( bAppendSep )
783 aPathStrBuffer.appendAscii( ";" ); // Office uses ';' as path separator
784 aPathStrBuffer.append( aTmp );
785 bAppendSep = sal_True;
788 while(nToken>=0);
790 aRetStr = aPathStrBuffer.makeStringAndClear();
793 return aRetStr;
796 rtl::OUString SubstitutePathVariables::impl_substituteVariable( const ::rtl::OUString& rText, sal_Bool bSubstRequired )
797 throw ( NoSuchElementException, RuntimeException )
799 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_substituteVariable" );
800 // This is maximal recursive depth supported!
801 const sal_Int32 nMaxRecursiveDepth = 8;
803 rtl::OUString aWorkText = rText;
804 rtl::OUString aResult;
806 // Use vector with strings to detect endless recursions!
807 std::vector< rtl::OUString > aEndlessRecursiveDetector;
809 // Search for first occure of "$(...".
810 sal_Int32 nDepth = 0;
811 sal_Int32 bSubstitutionCompleted = sal_False;
812 sal_Int32 nPosition = aWorkText.indexOf( m_aVarStart ); // = first position of "$(" in string
813 sal_Int32 nLength = 0; // = count of letters from "$(" to ")" in string
814 sal_Bool bVarNotSubstituted = sal_False;
816 // Have we found any variable like "$(...)"?
817 if ( nPosition != STRPOS_NOTFOUND )
819 // Yes; Get length of found variable.
820 // If no ")" was found - nLength is set to 0 by default! see before.
821 sal_Int32 nEndPosition = aWorkText.indexOf( m_aVarEnd, nPosition );
822 if ( nEndPosition != STRPOS_NOTFOUND )
823 nLength = nEndPosition - nPosition + 1;
826 // Is there something to replace ?
827 sal_Bool bWorkRetrieved = sal_False;
828 sal_Bool bWorkDirURLRetrieved = sal_False;
829 while ( !bSubstitutionCompleted && nDepth < nMaxRecursiveDepth )
831 while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 3 ) ) // "$(" ")"
833 // YES; Get the next variable for replace.
834 sal_Int32 nReplaceLength = 0;
835 rtl::OUString aReplacement;
836 rtl::OUString aSubString = aWorkText.copy( nPosition, nLength );
837 rtl::OUString aSubVarString;
839 // Path variables are not case sensitive!
840 aSubVarString = aSubString.toAsciiLowerCase();
841 VarNameToIndexMap::const_iterator pNTOIIter = m_aPreDefVarMap.find( aSubVarString );
842 if ( pNTOIIter != m_aPreDefVarMap.end() )
844 // Fixed/Predefined variable found
845 PreDefVariable nIndex = (PreDefVariable)pNTOIIter->second;
847 // Determine variable value and length from array/table
848 if ( nIndex == PREDEFVAR_WORK && !bWorkRetrieved )
850 // Transient value, retrieve it again
851 m_aPreDefVars.m_FixedVar[ (PreDefVariable)nIndex ] = GetWorkVariableValue();
852 bWorkRetrieved = sal_True;
854 else if ( nIndex == PREDEFVAR_WORKDIRURL && !bWorkDirURLRetrieved )
856 // Transient value, retrieve it again
857 m_aPreDefVars.m_FixedVar[ (PreDefVariable)nIndex ] = GetWorkPath();
858 bWorkDirURLRetrieved = sal_True;
861 aReplacement = m_aPreDefVars.m_FixedVar[ (PreDefVariable)nIndex ];
862 nReplaceLength = nLength;
864 else
866 // Extract the variable name and try to find in the user defined variable set
867 rtl::OUString aVarName = aSubString.copy( 2, nLength-3 );
868 SubstituteVariables::const_iterator pIter = m_aSubstVarMap.find( aVarName );
869 if ( pIter != m_aSubstVarMap.end() )
871 // found!
872 aReplacement = pIter->second.aSubstValue;
873 nReplaceLength = nLength;
877 // Have we found something to replace?
878 if ( nReplaceLength > 0 )
880 // Yes ... then do it.
881 aWorkText = aWorkText.replaceAt( nPosition, nReplaceLength, aReplacement );
883 else
885 // Variable not known
886 bVarNotSubstituted = sal_False;
887 nPosition += nLength;
890 // Step after replaced text! If no text was replaced (unknown variable!),
891 // length of aReplacement is 0 ... and we don't step then.
892 nPosition += aReplacement.getLength();
894 // We must control index in string before call something at OUString!
895 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
896 if ( nPosition + 1 > aWorkText.getLength() )
898 // Position is out of range. Break loop!
899 nPosition = STRPOS_NOTFOUND;
900 nLength = 0;
902 else
904 // Else; Position is valid. Search for next variable to replace.
905 nPosition = aWorkText.indexOf( m_aVarStart, nPosition );
906 // Have we found any variable like "$(...)"?
907 if ( nPosition != STRPOS_NOTFOUND )
909 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
910 nLength = 0;
911 sal_Int32 nEndPosition = aWorkText.indexOf( m_aVarEnd, nPosition );
912 if ( nEndPosition != STRPOS_NOTFOUND )
913 nLength = nEndPosition - nPosition + 1;
918 nPosition = aWorkText.indexOf( m_aVarStart );
919 if ( nPosition == -1 )
921 bSubstitutionCompleted = sal_True;
922 break; // All variables are substituted
924 else
926 // Check for recursion
927 const sal_uInt32 nCount = aEndlessRecursiveDetector.size();
928 for ( sal_uInt32 i=0; i < nCount; i++ )
930 if ( aEndlessRecursiveDetector[i] == aWorkText )
932 if ( bVarNotSubstituted )
933 break; // Not all variables could be substituted!
934 else
936 nDepth = nMaxRecursiveDepth;
937 break; // Recursion detected!
942 aEndlessRecursiveDetector.push_back( aWorkText );
944 // Initialize values for next
945 sal_Int32 nEndPosition = aWorkText.indexOf( m_aVarEnd, nPosition );
946 if ( nEndPosition != STRPOS_NOTFOUND )
947 nLength = nEndPosition - nPosition + 1;
948 bVarNotSubstituted = sal_False;
949 ++nDepth;
953 // Fill return value with result
954 if ( bSubstitutionCompleted )
956 // Substitution successfull!
957 aResult = aWorkText;
959 else
961 // Substitution not successfull!
962 if ( nDepth == nMaxRecursiveDepth )
964 // recursion depth reached!
965 if ( bSubstRequired )
967 rtl::OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "Endless recursion detected. Cannot substitute variables!" ));
968 throw NoSuchElementException( aMsg, (cppu::OWeakObject *)this );
970 else
971 aResult = rText;
973 else
975 // variable in text but unknwon!
976 if ( bSubstRequired )
978 rtl::OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable found!" ));
979 throw NoSuchElementException( aMsg, (cppu::OWeakObject *)this );
981 else
982 aResult = aWorkText;
986 return aResult;
989 rtl::OUString SubstitutePathVariables::impl_reSubstituteVariables( const ::rtl::OUString& rURL )
990 throw ( RuntimeException )
992 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_reSubstituteVariables" );
993 rtl::OUString aURL;
995 INetURLObject aUrl( rURL );
996 if ( !aUrl.HasError() )
997 aURL = aUrl.GetMainURL( INetURLObject::NO_DECODE );
998 else
1000 // Convert a system path to a UCB compliant URL before resubstitution
1001 rtl::OUString aTemp;
1002 if ( osl::FileBase::getFileURLFromSystemPath( rURL, aTemp ) == osl::FileBase::E_None )
1004 aTemp = ConvertOSLtoUCBURL( aTemp );
1005 if ( aTemp.getLength() )
1006 aURL = INetURLObject( aTemp ).GetMainURL( INetURLObject::NO_DECODE );
1007 else
1008 return rURL;
1010 else
1012 // rURL is not a valid URL nor a osl system path. Give up and return error!
1013 return rURL;
1017 // Due to a recursive definition this code must exchange variables with variables!
1018 sal_Bool bResubstitutionCompleted = sal_False;
1019 sal_Bool bVariableFound = sal_False;
1021 // Get transient predefined path variable $(work) value before starting resubstitution
1022 m_aPreDefVars.m_FixedVar[ PREDEFVAR_WORK ] = GetWorkVariableValue();
1024 while ( !bResubstitutionCompleted )
1026 ReSubstFixedVarOrderVector::const_iterator pIterFixed;
1027 for ( pIterFixed = m_aReSubstFixedVarOrder.begin(); pIterFixed != m_aReSubstFixedVarOrder.end(); pIterFixed++ )
1029 rtl::OUString aValue = m_aPreDefVars.m_FixedVar[ (sal_Int32)pIterFixed->eVariable ];
1030 sal_Int32 nPos = aURL.indexOf( aValue );
1031 if ( nPos >= 0 )
1033 sal_Bool bMatch = sal_True;
1034 if ( pIterFixed->eVariable == PREDEFVAR_LANG ||
1035 pIterFixed->eVariable == PREDEFVAR_LANGID ||
1036 pIterFixed->eVariable == PREDEFVAR_VLANG )
1038 // Special path variables as they can occur in the middle of a path. Only match if they
1039 // describe a whole directory and not only a substring of a directory!
1040 const sal_Unicode* pStr = aURL.getStr();
1042 if ( nPos > 0 )
1043 bMatch = ( aURL[ nPos-1 ] == '/' );
1045 if ( bMatch )
1047 if ( nPos + aValue.getLength() < aURL.getLength() )
1048 bMatch = ( pStr[ nPos + aValue.getLength() ] == '/' );
1052 if ( bMatch )
1054 rtl::OUStringBuffer aStrBuffer( aURL.getLength() );
1055 aStrBuffer.append( aURL.copy( 0, nPos ) );
1056 aStrBuffer.append( m_aPreDefVars.m_FixedVarNames[ (sal_Int32)pIterFixed->eVariable ] ); // Get the variable name for struct var name array!
1057 aStrBuffer.append( aURL.copy( nPos + aValue.getLength(), ( aURL.getLength() - ( nPos + aValue.getLength() )) ));
1058 aURL = aStrBuffer.makeStringAndClear();
1059 bVariableFound = sal_True; // Resubstitution not finished yet!
1060 break;
1065 // This part can be iteratered more than one time as variables can contain variables again!
1066 ReSubstUserVarOrderVector::const_iterator pIterUser;
1067 for ( pIterUser = m_aReSubstUserVarOrder.begin(); pIterUser != m_aReSubstUserVarOrder.end(); pIterUser++ )
1069 rtl::OUString aVarValue = pIterUser->aVarName;
1070 sal_Int32 nPos = aURL.indexOf( aVarValue );
1071 if ( nPos >= 0 )
1073 rtl::OUStringBuffer aStrBuffer( aURL.getLength() );
1074 aStrBuffer.append( aURL.copy( 0, nPos ) );
1075 aStrBuffer.append( m_aVarStart );
1076 aStrBuffer.append( aVarValue );
1077 aStrBuffer.append( m_aVarEnd );
1078 aStrBuffer.append( aURL.copy( nPos + aVarValue.getLength(), ( aURL.getLength() - ( nPos + aVarValue.getLength() )) ));
1079 aURL = aStrBuffer.makeStringAndClear();
1080 bVariableFound = sal_True; // Resubstitution not finished yet!
1084 if ( !bVariableFound )
1085 bResubstitutionCompleted = sal_True;
1086 else
1087 bVariableFound = sal_False; // Next resubstitution
1090 return aURL;
1093 // This method support both request schemes "$("<varname>")" or "<varname>".
1094 ::rtl::OUString SubstitutePathVariables::impl_getSubstituteVariableValue( const ::rtl::OUString& rVariable )
1095 throw ( NoSuchElementException, RuntimeException )
1097 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::impl_getSubstituteVariableValue" );
1098 rtl::OUString aVariable;
1100 sal_Int32 nPos = rVariable.indexOf( m_aVarStart );
1101 if ( nPos == -1 )
1103 // Prepare variable name before hash map access
1104 rtl::OUStringBuffer aStrBuffer( rVariable.getLength() + m_aVarStart.getLength() + m_aVarEnd.getLength() );
1105 aStrBuffer.append( m_aVarStart );
1106 aStrBuffer.append( rVariable );
1107 aStrBuffer.append( m_aVarEnd );
1108 aVariable = aStrBuffer.makeStringAndClear();
1111 VarNameToIndexMap::const_iterator pNTOIIter = m_aPreDefVarMap.find( ( nPos == -1 ) ? aVariable : rVariable );
1113 // Fixed/Predefined variable
1114 if ( pNTOIIter != m_aPreDefVarMap.end() )
1116 PreDefVariable nIndex = (PreDefVariable)pNTOIIter->second;
1117 return m_aPreDefVars.m_FixedVar[(sal_Int32)nIndex];
1119 else
1121 // Prepare variable name before hash map access
1122 if ( nPos >= 0 )
1124 if ( rVariable.getLength() > 3 )
1125 aVariable = rVariable.copy( 2, rVariable.getLength() - 3 );
1126 else
1128 rtl::OUString aExceptionText( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable!" ));
1129 throw NoSuchElementException();
1132 else
1133 aVariable = rVariable;
1135 // User defined variable
1136 SubstituteVariables::const_iterator pIter = m_aSubstVarMap.find( aVariable );
1137 if ( pIter != m_aSubstVarMap.end() )
1139 // found!
1140 return pIter->second.aSubstValue;
1143 rtl::OUString aExceptionText( RTL_CONSTASCII_USTRINGPARAM( "Unknown variable!" ));
1144 throw NoSuchElementException( aExceptionText, (cppu::OWeakObject *)this );
1148 void SubstitutePathVariables::SetPredefinedPathVariables( PredefinedPathVariables& aPreDefPathVariables )
1150 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "SubstitutePathVariables::SetPredefinedPathVariables" );
1151 Any aAny;
1152 ::rtl::OUString aOfficePath;
1153 ::rtl::OUString aUserPath;
1154 ::rtl::OUString aTmp;
1155 ::rtl::OUString aTmp2;
1156 String aResult;
1158 // Get inspath and userpath from bootstrap mechanism in every case as file URL
1159 ::utl::Bootstrap::PathStatus aState;
1160 ::rtl::OUString sVal ;
1162 aState = utl::Bootstrap::locateBaseInstallation( sVal );
1163 if( aState==::utl::Bootstrap::PATH_EXISTS ) {
1164 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTPATH ] = ConvertOSLtoUCBURL( sVal );
1166 else {
1167 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Bootstrap code has no value for instpath!");
1170 aState = utl::Bootstrap::locateUserData( sVal );
1171 if( aState == ::utl::Bootstrap::PATH_EXISTS ) {
1172 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERPATH ] = ConvertOSLtoUCBURL( sVal );
1174 else {
1175 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Bootstrap code has no value for userpath");
1178 // Set $(inst), $(instpath), $(insturl)
1179 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTURL ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTPATH ];
1180 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INST ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTPATH ];
1181 // --> PB 2004-10-27 #i32656# - new variable of hierachy service
1182 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_BASEINSTURL ]= aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTPATH ];
1183 // <--
1185 // Set $(user), $(userpath), $(userurl)
1186 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERURL ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERPATH ];
1187 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USER ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERPATH ];
1188 // --> PB 2004-11-11 #i32656# - new variable of hierachy service
1189 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERDATAURL ]= aPreDefPathVariables.m_FixedVar[ PREDEFVAR_USERPATH ];
1190 // <--
1192 // Detect the program directory
1193 // Set $(prog), $(progpath), $(progurl)
1194 INetURLObject aProgObj(
1195 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_INSTPATH ] );
1196 if ( !aProgObj.HasError() &&
1197 aProgObj.insertName(
1198 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("program")) ) )
1200 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PROGPATH ] = aProgObj.GetMainURL(INetURLObject::NO_DECODE);
1201 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PROGURL ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PROGPATH ];
1202 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PROG ] = aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PROGPATH ];
1205 // Detect the language type of the current office
1206 aPreDefPathVariables.m_eLanguageType = LANGUAGE_ENGLISH_US;
1207 rtl::OUString aLocaleStr;
1208 if ( utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty( utl::ConfigManager::LOCALE ) >>= aLocaleStr )
1209 aPreDefPathVariables.m_eLanguageType = MsLangId::convertIsoStringToLanguage( aLocaleStr );
1210 else
1212 LOG_ERROR( "SubstitutePathVariables::SetPredefinedPathVariables", "Wrong Any type for language!" );
1215 // Set $(lang)
1216 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_LANG ] = ConvertOSLtoUCBURL(
1217 rtl::OUString::createFromAscii( ResMgr::GetLang( aPreDefPathVariables.m_eLanguageType, 0 ) ));
1218 // Set $(vlang)
1219 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_VLANG ] = aLocaleStr;
1221 // Set $(langid)
1222 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_LANGID ] = rtl::OUString::valueOf( (sal_Int32)aPreDefPathVariables.m_eLanguageType );
1224 // Set the other pre defined path variables
1225 // Set $(work)
1226 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_WORK ] = GetWorkVariableValue();
1227 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_HOME ] = GetHomeVariableValue();
1229 // Set $(workdirurl) this is the value of the path PATH_WORK which doesn't make sense
1230 // anymore because the path settings service has this value! It can deliver this value more
1231 // quickly than the substitution service!
1232 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_WORKDIRURL ] = GetWorkPath();
1234 // Set $(path) variable
1235 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_PATH ] = GetPathVariableValue();
1237 // Set $(temp)
1238 osl::FileBase::getTempDirURL( aTmp );
1239 aPreDefPathVariables.m_FixedVar[ PREDEFVAR_TEMP ] = ConvertOSLtoUCBURL( aTmp );
1241 aPreDefPathVariables.m_FixedVar[PREDEFVAR_BRANDBASEURL] = rtl::OUString(
1242 RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR"));
1243 rtl::Bootstrap::expandMacros(
1244 aPreDefPathVariables.m_FixedVar[PREDEFVAR_BRANDBASEURL]);
1247 } // namespace framework