merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / core / translate.cxx
blobb0599842252fd1224f04d0cde95b0bf8e7fc9b06
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$
11 * $Revision$
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"
34 #include <list>
35 #if TEST_LAYOUT
36 #include <cstdio>
37 #include "tools/getprocessworkingdir.hxx"
38 #endif
40 #include <unotools/bootstrap.hxx>
41 #include <unotools/localfilehelper.hxx>
42 #include <unotools/ucbhelper.hxx>
43 #include <vcl/svapp.hxx>
45 #include "proplist.hxx"
47 namespace layoutimpl
49 namespace css = ::com::sun::star;
50 using namespace css;
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( "-" )
68 + rLocale.Country;
69 aSubdirs.push_front( aLocaleCountry );
70 if ( rLocale.Variant.getLength() )
71 aSubdirs.push_front( aLocaleCountry
72 + OUString::createFromAscii( "." )
73 + rLocale.Variant );
75 return aSubdirs;
78 static bool
79 fileExists( String const& aFile )
81 String aUrl;
82 LocalFileHelper::ConvertPhysicalNameToURL( aFile, aUrl );
83 return UCBContentHelper::Exists( aUrl );
86 static OUString
87 getFirstExisting( OUString const& aDir, std::list<OUString> const& aSubDirs,
88 OUString const& aXMLName )
90 static OUString const aSlash = OUString::createFromAscii( "/" );
91 String aResult;
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 ) )
98 return aFile;
100 return OUString();
103 /* FIXME: IWBN to share code with impimagetree.cxx, also for reading
104 from zip files. */
105 OUString
106 readRightTranslation( OUString const& aXMLName )
108 String aXMLFile;
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() )
119 else
120 #endif /* TEST_LAYOUT */
122 OUString aShareUrl;
123 Bootstrap::locateSharedData( aShareUrl );
124 OUString aXMLUrl = aShareUrl + OUString::createFromAscii( "/layout" );
125 String aXMLDir;
126 LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl, aXMLDir );
127 aXMLFile = getFirstExisting( aXMLDir, aSubdirs, aXMLName );
130 OSL_TRACE( "FOUND:%s", OUSTRING_CSTR ( OUString (aXMLFile) ) );
131 return aXMLFile;
134 } // namespace layoutimpl