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
9 * $RCSfile: unopkg_shared.h,v $
10 * $Revision: 1.9.8.3 $
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 ************************************************************************/
32 #include "com/sun/star/uno/Exception.hpp"
33 #include "com/sun/star/lang/XComponent.hpp"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
36 #include "com/sun/star/deployment/XPackage.hpp"
37 #include "tools/resmgr.hxx"
38 #include "rtl/ustring.hxx"
39 #include "unotools/configmgr.hxx"
42 #define APP_NAME "unopkg"
44 namespace css
= ::com::sun::star
;
48 inline ::com::sun::star::lang::Locale
toLocale( ::rtl::OUString
const & slang
)
50 ::com::sun::star::lang::Locale locale
;
52 locale
.Language
= slang
.getToken( 0, '-', nIndex
);
53 locale
.Country
= slang
.getToken( 0, '-', nIndex
);
54 locale
.Variant
= slang
.getToken( 0, '-', nIndex
);
60 public rtl::StaticWithInit
<const css::lang::Locale
, OfficeLocale
> {
61 const css::lang::Locale
operator () () {
62 ::rtl::OUString slang
;
63 if (! (::utl::ConfigManager::GetDirectConfigProperty(
64 ::utl::ConfigManager::LOCALE
) >>= slang
))
65 throw css::uno::RuntimeException( OUSTR("Cannot determine language!"), 0 );
66 if (slang
.getLength() == 0)
67 slang
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US"));
68 return toLocale(slang
);
72 struct DeploymentResMgr
: public rtl::StaticWithInit
< ResMgr
*, DeploymentResMgr
>
74 ResMgr
* operator () () {
75 return ResMgr::CreateResMgr( "deployment", OfficeLocale::get());
82 sal_uInt32 m_name_length
;
83 sal_Unicode m_short_option
;
87 struct LockFileException
: public css::uno::Exception
89 LockFileException(::rtl::OUString
const & sMessage
) :
90 css::uno::Exception(sMessage
, css::uno::Reference
< css::uno::XInterface
> ()) {}
93 //==============================================================================
94 ::rtl::OUString
toString( OptionInfo
const * info
);
96 //==============================================================================
97 OptionInfo
const * getOptionInfo(
98 OptionInfo
const * list
,
99 ::rtl::OUString
const & opt
, sal_Unicode copt
= '\0' );
101 //==============================================================================
102 bool isOption( OptionInfo
const * option_info
, sal_uInt32
* pIndex
);
104 //==============================================================================
106 ::rtl::OUString
* pValue
, OptionInfo
const * option_info
,
107 sal_uInt32
* pIndex
);
109 //==============================================================================
110 inline bool readOption(
111 bool * flag
, OptionInfo
const * option_info
, sal_uInt32
* pIndex
)
113 if (isOption( option_info
, pIndex
)) {
114 OSL_ASSERT( flag
!= 0 );
120 //==============================================================================
122 /** checks if an argument is a bootstrap variable. These start with -env:. For example
123 -env:UNO_JAVA_JFW_USER_DATA=file:///d:/user
125 bool isBootstrapVariable(sal_uInt32
* pIndex
);
126 //==============================================================================
127 ::rtl::OUString
const & getExecutableDir();
129 //==============================================================================
130 ::rtl::OUString
const & getProcessWorkingDir();
132 //==============================================================================
133 ::rtl::OUString
makeAbsoluteFileUrl(
134 ::rtl::OUString
const & sys_path
, ::rtl::OUString
const & base_url
,
135 bool throw_exc
= true );
137 //##############################################################################
139 //==============================================================================
142 css::uno::Reference
<css::lang::XComponent
> m_xComp
;
145 inline DisposeGuard() {}
147 css::uno::Reference
<css::lang::XComponent
> const & xComp
)
148 : m_xComp( xComp
) {}
150 inline ~DisposeGuard()
157 css::uno::Reference
<css::lang::XComponent
> const & xComp
)
163 //==============================================================================
164 css::uno::Reference
<css::ucb::XCommandEnvironment
> createCmdEnv(
165 css::uno::Reference
<css::uno::XComponentContext
> const & xContext
,
166 ::rtl::OUString
const & logFile
,
167 bool option_force_overwrite
,
170 bool option_bundled
);
172 //==============================================================================
173 void printf_packages(
175 css::uno::Reference
<css::deployment::XPackage
> > const & seq
,
176 css::uno::Reference
<css::ucb::XCommandEnvironment
> const & xCmdEnv
,
177 sal_Int32 level
= 0 );
179 //##############################################################################
181 //==============================================================================
182 css::uno::Reference
<css::uno::XComponentContext
> getUNO(
183 DisposeGuard
& disposeGuard
, bool verbose
, bool shared
, bool bGui
,
184 css::uno::Reference
<css::uno::XComponentContext
> & out_LocalComponentContext
);