1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "translate.hxx"
37 #include "tools/getprocessworkingdir.hxx"
40 #include <unotools/bootstrap.hxx>
41 #include <unotools/localfilehelper.hxx>
42 #include <unotools/ucbhelper.hxx>
43 #include <vcl/svapp.hxx>
45 #include "proplist.hxx"
49 namespace css
= ::com::sun::star
;
51 using ::rtl::OUString
;
52 using ::utl::LocalFileHelper
;
53 using ::utl::UCBContentHelper
;
54 using ::utl::Bootstrap
;
56 static std::list
<OUString
>
57 getLocaleSubdirList( lang::Locale
const& rLocale
)
59 std::list
<OUString
> aSubdirs
;
60 aSubdirs
.push_front( OUString::createFromAscii( "." ) );
61 aSubdirs
.push_front( OUString::createFromAscii( "en-US" ) );
62 if ( rLocale
.Language
.getLength() )
63 aSubdirs
.push_front( rLocale
.Language
);
64 if ( rLocale
.Country
.getLength() )
66 OUString aLocaleCountry
= rLocale
.Language
67 + OUString::createFromAscii( "-" )
69 aSubdirs
.push_front( aLocaleCountry
);
70 if ( rLocale
.Variant
.getLength() )
71 aSubdirs
.push_front( aLocaleCountry
72 + OUString::createFromAscii( "." )
79 fileExists( String
const& aFile
)
82 LocalFileHelper::ConvertPhysicalNameToURL( aFile
, aUrl
);
83 return UCBContentHelper::Exists( aUrl
);
87 getFirstExisting( OUString
const& aDir
, std::list
<OUString
> const& aSubDirs
,
88 OUString
const& aXMLName
)
90 static OUString
const aSlash
= OUString::createFromAscii( "/" );
92 for ( std::list
<OUString
>::const_iterator i
= aSubDirs
.begin();
93 i
!= aSubDirs
.end(); i
++ )
95 String aFile
= aDir
+ aSlash
+ *i
+ aSlash
+ aXMLName
;
96 OSL_TRACE( "testing: %s", OUSTRING_CSTR( aFile
) );
97 if ( fileExists( aFile
) )
103 /* FIXME: IWBN to share code with impimagetree.cxx, also for reading
106 readRightTranslation( OUString
const& aXMLName
)
109 std::list
<OUString
> aSubdirs
110 = getLocaleSubdirList( Application::GetSettings().GetUILocale() );
111 #if TEST_LAYOUT // read from cwd first
112 OUString aCurrentWorkingUrl
;
113 tools::getProcessWorkingDir( &aCurrentWorkingUrl
);
114 String aCurrentWorkingDir
;
115 LocalFileHelper::ConvertURLToPhysicalName( aCurrentWorkingUrl
, aCurrentWorkingDir
);
116 aXMLFile
= getFirstExisting( aCurrentWorkingDir
, aSubdirs
, aXMLName
);
117 if ( aXMLFile
.Len() )
120 #endif /* TEST_LAYOUT */
123 Bootstrap::locateSharedData( aShareUrl
);
124 OUString aXMLUrl
= aShareUrl
+ OUString::createFromAscii( "/layout" );
126 LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl
, aXMLDir
);
127 aXMLFile
= getFirstExisting( aXMLDir
, aSubdirs
, aXMLName
);
130 OSL_TRACE( "FOUND:%s", OUSTRING_CSTR ( OUString (aXMLFile
) ) );
134 } // namespace layoutimpl