LibreOffice Module desktop (master) 1
jvmfwk.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
23#include <rtl/ustring.hxx>
24#include <rtl/bootstrap.hxx>
25#include <sal/types.h>
26#include <sal/config.h>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/lang/XInitialization.hpp>
29#include <com/sun/star/lang/WrappedTargetException.hpp>
30#include <com/sun/star/task/XJob.hpp>
31#include <com/sun/star/configuration/backend/XLayer.hpp>
32#include <com/sun/star/configuration/backend/XLayerHandler.hpp>
33#include <com/sun/star/configuration/backend/MalformedDataException.hpp>
34#include <com/sun/star/configuration/backend/TemplateIdentifier.hpp>
35#include <jvmfwk/framework.hxx>
36#include "jvmfwk.hxx"
37#include <memory>
38#include <stack>
39#include <stdio.h>
40
41#include <osl/diagnose.h>
42
43constexpr OUStringLiteral SERVICE_NAME = u"com.sun.star.migration.Java";
44#define IMPL_NAME "com.sun.star.comp.desktop.migration.Java"
45
46#define ENABLE_JAVA 1
47#define USER_CLASS_PATH 2
48
49using namespace com::sun::star::uno;
50using namespace com::sun::star::beans;
51using namespace com::sun::star::lang;
52using namespace com::sun::star::configuration::backend;
53
54namespace migration
55{
56
57namespace {
58
59class JavaMigration : public ::cppu::WeakImplHelper<
60 css::lang::XServiceInfo,
61 css::lang::XInitialization,
62 css::task::XJob,
63 css::configuration::backend::XLayerHandler>
64{
65public:
66 // XServiceInfo
67 virtual OUString SAL_CALL getImplementationName() override;
68 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) override;
69 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
70
71 //XInitialization
72 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
73
74 //XJob
75 virtual css::uno::Any SAL_CALL execute(
76 const css::uno::Sequence<css::beans::NamedValue >& Arguments ) override;
77
78 // XLayerHandler
79 virtual void SAL_CALL startLayer() override;
80
81 virtual void SAL_CALL endLayer() override;
82
83 virtual void SAL_CALL overrideNode(
84 const OUString& aName,
85 sal_Int16 aAttributes,
86 sal_Bool bClear) override;
87
88 virtual void SAL_CALL addOrReplaceNode(
89 const OUString& aName,
90 sal_Int16 aAttributes) override;
91
92 virtual void SAL_CALL addOrReplaceNodeFromTemplate(
93 const OUString& aName,
94 const css::configuration::backend::TemplateIdentifier& aTemplate,
95 sal_Int16 aAttributes ) override;
96
97 virtual void SAL_CALL endNode() override;
98
99 virtual void SAL_CALL dropNode(
100 const OUString& aName ) override;
101
102 virtual void SAL_CALL overrideProperty(
103 const OUString& aName,
104 sal_Int16 aAttributes,
105 const css::uno::Type& aType,
106 sal_Bool bClear ) override;
107
108 virtual void SAL_CALL setPropertyValue(
109 const css::uno::Any& aValue ) override;
110
111 virtual void SAL_CALL setPropertyValueForLocale(
112 const css::uno::Any& aValue,
113 const OUString& aLocale ) override;
114
115 virtual void SAL_CALL endProperty() override;
116
117 virtual void SAL_CALL addProperty(
118 const OUString& aName,
119 sal_Int16 aAttributes,
120 const css::uno::Type& aType ) override;
121
122 virtual void SAL_CALL addPropertyWithValue(
123 const OUString& aName,
124 sal_Int16 aAttributes,
125 const css::uno::Any& aValue ) override;
126
127
128 virtual ~JavaMigration() override;
129
130private:
131 OUString m_sUserDir;
132 css::uno::Reference< css::configuration::backend::XLayer> m_xLayer;
133
134 void migrateJavarc();
135 typedef std::pair< OUString, sal_Int16> TElementType;
136 typedef std::stack< TElementType > TElementStack;
137 TElementStack m_aStack;
138
139};
140
141}
142
143JavaMigration::~JavaMigration()
144{
145 OSL_ASSERT(m_aStack.empty());
146}
147
149{
150 return IMPL_NAME;
151}
152
153css::uno::Sequence< OUString > jvmfwk_getSupportedServiceNames()
154{
155 return { SERVICE_NAME };
156}
157
158// XServiceInfo
159OUString SAL_CALL JavaMigration::getImplementationName()
160{
162}
163
164sal_Bool JavaMigration::supportsService(OUString const & ServiceName)
165{
166 return cppu::supportsService(this, ServiceName);
167}
168
169css::uno::Sequence< OUString > SAL_CALL JavaMigration::getSupportedServiceNames()
170{
172}
173
174//XInitialization ----------------------------------------------------------------------
175void SAL_CALL JavaMigration::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
176{
177 const css::uno::Any* pIter = aArguments.getConstArray();
178 const css::uno::Any* pEnd = pIter + aArguments.getLength();
179 css::uno::Sequence<css::beans::NamedValue> aOldConfigValues;
180 css::beans::NamedValue aValue;
181 for(;pIter != pEnd;++pIter)
182 {
183 *pIter >>= aValue;
184 if ( aValue.Name == "OldConfiguration" )
185 {
186 bool bSuccess = aValue.Value >>= aOldConfigValues;
187 OSL_ENSURE(bSuccess, "[Service implementation " IMPL_NAME
188 "] XInitialization::initialize: Argument OldConfiguration has wrong type.");
189 if (bSuccess)
190 {
191 const css::beans::NamedValue* pIter2 = aOldConfigValues.getConstArray();
192 const css::beans::NamedValue* pEnd2 = pIter2 + aOldConfigValues.getLength();
193 for(;pIter2 != pEnd2;++pIter2)
194 {
195 if ( pIter2->Name == "org.openoffice.Office.Java" )
196 {
197 pIter2->Value >>= m_xLayer;
198 break;
199 }
200 }
201 }
202 }
203 else if ( aValue.Name == "UserData" )
204 {
205 if ( !(aValue.Value >>= m_sUserDir) )
206 {
207 OSL_FAIL(
208 "[Service implementation " IMPL_NAME
209 "] XInitialization::initialize: Argument UserData has wrong type.");
210 }
211 }
212 }
213
214}
215
216//XJob
217css::uno::Any SAL_CALL JavaMigration::execute(
218 const css::uno::Sequence<css::beans::NamedValue >& )
219{
220 migrateJavarc();
221 if (m_xLayer.is())
222 m_xLayer->readData(this);
223
224 return css::uno::Any();
225}
226
227void JavaMigration::migrateJavarc()
228{
229 if (m_sUserDir.isEmpty())
230 return;
231
232 OUString sValue;
233 rtl::Bootstrap javaini(m_sUserDir + "/user/config/" SAL_CONFIGFILE("java"));
234 bool bSuccess = javaini.getFrom("Home", sValue);
235 OSL_ENSURE(bSuccess, "[Service implementation " IMPL_NAME
236 "] XJob::execute: Could not get Home entry from java.ini/javarc.");
237 if (!bSuccess || sValue.isEmpty())
238 return;
239
240 //get the directory
241 std::unique_ptr<JavaInfo> aInfo;
243
244 if (err == JFW_E_NONE)
245 {
246 if (jfw_setSelectedJRE(aInfo.get()) != JFW_E_NONE)
247 {
248 OSL_FAIL("[Service implementation " IMPL_NAME
249 "] XJob::execute: jfw_setSelectedJRE failed.");
250 fprintf(stderr, "\nCannot migrate Java. An error occurred.\n");
251 }
252 }
253 else if (err == JFW_E_FAILED_VERSION)
254 {
255 fprintf(stderr, "\nCannot migrate Java settings because the version of the Java "
256 "is not supported anymore.\n");
257 }
258}
259
260
261// XLayerHandler
262void SAL_CALL JavaMigration::startLayer()
263{
264}
265
266
267void SAL_CALL JavaMigration::endLayer()
268{
269}
270
271
272void SAL_CALL JavaMigration::overrideNode(
273 const OUString&,
274 sal_Int16,
275 sal_Bool)
276
277{
278
279}
280
281
282void SAL_CALL JavaMigration::addOrReplaceNode(
283 const OUString&,
284 sal_Int16)
285{
286
287}
288void SAL_CALL JavaMigration::endNode()
289{
290}
291
292
293void SAL_CALL JavaMigration::dropNode(
294 const OUString& )
295{
296}
297
298
299void SAL_CALL JavaMigration::overrideProperty(
300 const OUString& aName,
301 sal_Int16,
302 const Type&,
303 sal_Bool )
304{
305 if ( aName == "Enable" )
306 m_aStack.push(TElementStack::value_type(aName,ENABLE_JAVA));
307 else if ( aName == "UserClassPath" )
308 m_aStack.push(TElementStack::value_type(aName, USER_CLASS_PATH));
309}
310
311
312void SAL_CALL JavaMigration::setPropertyValue(
313 const Any& aValue )
314{
315 if ( m_aStack.empty())
316 return;
317
318 switch (m_aStack.top().second)
319 {
320 case ENABLE_JAVA:
321 {
322 bool val;
323 if (!(aValue >>= val))
324 throw MalformedDataException(
325 "[Service implementation " IMPL_NAME
326 "] XLayerHandler::setPropertyValue received wrong type for Enable property", nullptr, Any());
327 if (jfw_setEnabled(val) != JFW_E_NONE)
328 throw WrappedTargetException(
329 "[Service implementation " IMPL_NAME
330 "] XLayerHandler::setPropertyValue: jfw_setEnabled failed.", nullptr, Any());
331
332 break;
333 }
334 case USER_CLASS_PATH:
335 {
336 OUString cp;
337 if (!(aValue >>= cp))
338 throw MalformedDataException(
339 "[Service implementation " IMPL_NAME
340 "] XLayerHandler::setPropertyValue received wrong type for UserClassPath property", nullptr, Any());
341
342 if (jfw_setUserClassPath(cp) != JFW_E_NONE)
343 throw WrappedTargetException(
344 "[Service implementation " IMPL_NAME
345 "] XLayerHandler::setPropertyValue: jfw_setUserClassPath failed.", nullptr, Any());
346 break;
347 }
348 default:
349 OSL_ASSERT(false);
350 }
351}
352
353
354void SAL_CALL JavaMigration::setPropertyValueForLocale(
355 const Any&,
356 const OUString& )
357{
358}
359
360
361void SAL_CALL JavaMigration::endProperty()
362{
363 if (!m_aStack.empty())
364 m_aStack.pop();
365}
366
367
368void SAL_CALL JavaMigration::addProperty(
369 const OUString&,
370 sal_Int16,
371 const Type& )
372{
373}
374
375
376void SAL_CALL JavaMigration::addPropertyWithValue(
377 const OUString&,
378 sal_Int16,
379 const Any& )
380{
381}
382
383void SAL_CALL JavaMigration::addOrReplaceNodeFromTemplate(
384 const OUString&,
385 const TemplateIdentifier&,
386 sal_Int16 )
387{
388}
389
390
391//ToDo enable java, user class path
392
393} //end namespace jfw
394
395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_CONFIGFILE(name)
float u
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
javaFrameworkError jfw_getJavaInfoByPath(OUString const &pPath, std::unique_ptr< JavaInfo > *ppInfo)
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
javaFrameworkError jfw_setEnabled(bool bEnabled)
javaFrameworkError
Sequence< PropertyValue > aArguments
OUString aName
#define ENABLE_JAVA
Definition: jvmfwk.cxx:46
constexpr OUStringLiteral SERVICE_NAME
Definition: jvmfwk.cxx:43
OUString m_sUserDir
Definition: jvmfwk.cxx:131
#define IMPL_NAME
Definition: jvmfwk.cxx:44
#define USER_CLASS_PATH
Definition: jvmfwk.cxx:47
css::uno::Reference< css::configuration::backend::XLayer > m_xLayer
Definition: jvmfwk.cxx:132
TElementStack m_aStack
Definition: jvmfwk.cxx:137
err
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Type
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString jvmfwk_getImplementationName()
Definition: jvmfwk.cxx:148
css::uno::Sequence< OUString > jvmfwk_getSupportedServiceNames()
Definition: jvmfwk.cxx:153
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
unsigned char sal_Bool