1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b0724fc6SAndrew Rist * distributed with this work for additional information
6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at
10*b0724fc6SAndrew Rist *
11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist *
13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the
17*b0724fc6SAndrew Rist * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist * under the License.
19*b0724fc6SAndrew Rist *
20*b0724fc6SAndrew Rist *************************************************************/
21*b0724fc6SAndrew Rist
22*b0724fc6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "translate.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <list>
27cdf0e10cSrcweir #if TEST_LAYOUT
28cdf0e10cSrcweir #include <cstdio>
29cdf0e10cSrcweir #include "tools/getprocessworkingdir.hxx"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
33cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
34cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "proplist.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace layoutimpl
40cdf0e10cSrcweir {
41cdf0e10cSrcweir namespace css = ::com::sun::star;
42cdf0e10cSrcweir using namespace css;
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::utl::LocalFileHelper;
45cdf0e10cSrcweir using ::utl::UCBContentHelper;
46cdf0e10cSrcweir using ::utl::Bootstrap;
47cdf0e10cSrcweir
48cdf0e10cSrcweir static std::list<OUString>
getLocaleSubdirList(lang::Locale const & rLocale)49cdf0e10cSrcweir getLocaleSubdirList( lang::Locale const& rLocale )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir std::list<OUString> aSubdirs;
52cdf0e10cSrcweir aSubdirs.push_front( OUString::createFromAscii( "." ) );
53cdf0e10cSrcweir aSubdirs.push_front( OUString::createFromAscii( "en-US" ) );
54cdf0e10cSrcweir if ( rLocale.Language.getLength() )
55cdf0e10cSrcweir aSubdirs.push_front( rLocale.Language );
56cdf0e10cSrcweir if ( rLocale.Country.getLength() )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir OUString aLocaleCountry = rLocale.Language
59cdf0e10cSrcweir + OUString::createFromAscii( "-" )
60cdf0e10cSrcweir + rLocale.Country;
61cdf0e10cSrcweir aSubdirs.push_front( aLocaleCountry );
62cdf0e10cSrcweir if ( rLocale.Variant.getLength() )
63cdf0e10cSrcweir aSubdirs.push_front( aLocaleCountry
64cdf0e10cSrcweir + OUString::createFromAscii( "." )
65cdf0e10cSrcweir + rLocale.Variant );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir return aSubdirs;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
70cdf0e10cSrcweir static bool
fileExists(String const & aFile)71cdf0e10cSrcweir fileExists( String const& aFile )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir String aUrl;
74cdf0e10cSrcweir LocalFileHelper::ConvertPhysicalNameToURL( aFile, aUrl );
75cdf0e10cSrcweir return UCBContentHelper::Exists( aUrl );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir static OUString
getFirstExisting(OUString const & aDir,std::list<OUString> const & aSubDirs,OUString const & aXMLName)79cdf0e10cSrcweir getFirstExisting( OUString const& aDir, std::list<OUString> const& aSubDirs,
80cdf0e10cSrcweir OUString const& aXMLName )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir static OUString const aSlash = OUString::createFromAscii( "/" );
83cdf0e10cSrcweir String aResult;
84cdf0e10cSrcweir for ( std::list<OUString>::const_iterator i = aSubDirs.begin();
85cdf0e10cSrcweir i != aSubDirs.end(); i++ )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir String aFile = aDir + aSlash + *i + aSlash + aXMLName;
88cdf0e10cSrcweir OSL_TRACE( "testing: %s", OUSTRING_CSTR( aFile ) );
89cdf0e10cSrcweir if ( fileExists( aFile ) )
90cdf0e10cSrcweir return aFile;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir return OUString();
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir /* FIXME: IWBN to share code with impimagetree.cxx, also for reading
96cdf0e10cSrcweir from zip files. */
97cdf0e10cSrcweir OUString
readRightTranslation(OUString const & aXMLName)98cdf0e10cSrcweir readRightTranslation( OUString const& aXMLName )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir String aXMLFile;
101cdf0e10cSrcweir std::list<OUString> aSubdirs
102cdf0e10cSrcweir = getLocaleSubdirList( Application::GetSettings().GetUILocale() );
103cdf0e10cSrcweir #if TEST_LAYOUT // read from cwd first
104cdf0e10cSrcweir OUString aCurrentWorkingUrl;
105cdf0e10cSrcweir tools::getProcessWorkingDir( &aCurrentWorkingUrl );
106cdf0e10cSrcweir String aCurrentWorkingDir;
107cdf0e10cSrcweir LocalFileHelper::ConvertURLToPhysicalName( aCurrentWorkingUrl, aCurrentWorkingDir );
108cdf0e10cSrcweir aXMLFile = getFirstExisting( aCurrentWorkingDir, aSubdirs, aXMLName );
109cdf0e10cSrcweir if ( aXMLFile.Len() )
110cdf0e10cSrcweir ;
111cdf0e10cSrcweir else
112cdf0e10cSrcweir #endif /* TEST_LAYOUT */
113cdf0e10cSrcweir {
114cdf0e10cSrcweir OUString aShareUrl;
115cdf0e10cSrcweir Bootstrap::locateSharedData( aShareUrl );
116cdf0e10cSrcweir OUString aXMLUrl = aShareUrl + OUString::createFromAscii( "/layout" );
117cdf0e10cSrcweir String aXMLDir;
118cdf0e10cSrcweir LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl, aXMLDir );
119cdf0e10cSrcweir aXMLFile = getFirstExisting( aXMLDir, aSubdirs, aXMLName );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir OSL_TRACE( "FOUND:%s", OUSTRING_CSTR ( OUString (aXMLFile) ) );
123cdf0e10cSrcweir return aXMLFile;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
126cdf0e10cSrcweir } // namespace layoutimpl
127