23#include <rtl/ustring.hxx>
24#include <rtl/bootstrap.hxx>
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>
41#include <osl/diagnose.h>
44#define IMPL_NAME "com.sun.star.comp.desktop.migration.Java"
47#define USER_CLASS_PATH 2
52using namespace com::sun::star::configuration::backend;
59class JavaMigration :
public ::cppu::WeakImplHelper<
60 css::lang::XServiceInfo,
61 css::lang::XInitialization,
63 css::configuration::backend::XLayerHandler>
72 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >&
aArguments )
override;
75 virtual css::uno::Any SAL_CALL execute(
76 const css::uno::Sequence<css::beans::NamedValue >& Arguments )
override;
79 virtual void SAL_CALL startLayer()
override;
81 virtual void SAL_CALL endLayer()
override;
83 virtual void SAL_CALL overrideNode(
84 const OUString&
aName,
85 sal_Int16 aAttributes,
88 virtual void SAL_CALL addOrReplaceNode(
89 const OUString&
aName,
90 sal_Int16 aAttributes)
override;
92 virtual void SAL_CALL addOrReplaceNodeFromTemplate(
93 const OUString&
aName,
94 const css::configuration::backend::TemplateIdentifier& aTemplate,
95 sal_Int16 aAttributes )
override;
97 virtual void SAL_CALL endNode()
override;
99 virtual void SAL_CALL dropNode(
100 const OUString&
aName )
override;
102 virtual void SAL_CALL overrideProperty(
103 const OUString&
aName,
104 sal_Int16 aAttributes,
105 const css::uno::Type& aType,
109 const css::uno::Any& aValue )
override;
111 virtual void SAL_CALL setPropertyValueForLocale(
112 const css::uno::Any& aValue,
113 const OUString& aLocale )
override;
115 virtual void SAL_CALL endProperty()
override;
117 virtual void SAL_CALL addProperty(
118 const OUString&
aName,
119 sal_Int16 aAttributes,
120 const css::uno::Type& aType )
override;
122 virtual void SAL_CALL addPropertyWithValue(
123 const OUString&
aName,
124 sal_Int16 aAttributes,
125 const css::uno::Any& aValue )
override;
128 virtual ~JavaMigration()
override;
132 css::uno::Reference< css::configuration::backend::XLayer>
m_xLayer;
134 void migrateJavarc();
135 typedef std::pair< OUString, sal_Int16> TElementType;
136 typedef std::stack< TElementType > TElementStack;
143JavaMigration::~JavaMigration()
159OUString SAL_CALL JavaMigration::getImplementationName()
164sal_Bool JavaMigration::supportsService(OUString
const & ServiceName)
169css::uno::Sequence< OUString > SAL_CALL JavaMigration::getSupportedServiceNames()
175void SAL_CALL JavaMigration::initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
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)
184 if ( aValue.Name ==
"OldConfiguration" )
186 bool bSuccess = aValue.Value >>= aOldConfigValues;
187 OSL_ENSURE(bSuccess,
"[Service implementation " IMPL_NAME
188 "] XInitialization::initialize: Argument OldConfiguration has wrong type.");
191 const css::beans::NamedValue* pIter2 = aOldConfigValues.getConstArray();
192 const css::beans::NamedValue* pEnd2 = pIter2 + aOldConfigValues.getLength();
193 for(;pIter2 != pEnd2;++pIter2)
195 if ( pIter2->Name ==
"org.openoffice.Office.Java" )
203 else if ( aValue.Name ==
"UserData" )
209 "] XInitialization::initialize: Argument UserData has wrong type.");
217css::uno::Any SAL_CALL JavaMigration::execute(
218 const css::uno::Sequence<css::beans::NamedValue >& )
224 return css::uno::Any();
227void JavaMigration::migrateJavarc()
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())
241 std::unique_ptr<JavaInfo> aInfo;
244 if (err == JFW_E_NONE)
248 OSL_FAIL(
"[Service implementation " IMPL_NAME
249 "] XJob::execute: jfw_setSelectedJRE failed.");
250 fprintf(stderr,
"\nCannot migrate Java. An error occurred.\n");
253 else if (err == JFW_E_FAILED_VERSION)
255 fprintf(stderr,
"\nCannot migrate Java settings because the version of the Java "
256 "is not supported anymore.\n");
262void SAL_CALL JavaMigration::startLayer()
267void SAL_CALL JavaMigration::endLayer()
272void SAL_CALL JavaMigration::overrideNode(
282void SAL_CALL JavaMigration::addOrReplaceNode(
288void SAL_CALL JavaMigration::endNode()
293void SAL_CALL JavaMigration::dropNode(
299void SAL_CALL JavaMigration::overrideProperty(
300 const OUString& aName,
305 if ( aName ==
"Enable" )
307 else if ( aName ==
"UserClassPath" )
312void SAL_CALL JavaMigration::setPropertyValue(
323 if (!(aValue >>= val))
324 throw MalformedDataException(
326 "] XLayerHandler::setPropertyValue received wrong type for Enable property",
nullptr,
Any());
328 throw WrappedTargetException(
330 "] XLayerHandler::setPropertyValue: jfw_setEnabled failed.",
nullptr,
Any());
337 if (!(aValue >>= cp))
338 throw MalformedDataException(
340 "] XLayerHandler::setPropertyValue received wrong type for UserClassPath property",
nullptr,
Any());
343 throw WrappedTargetException(
345 "] XLayerHandler::setPropertyValue: jfw_setUserClassPath failed.",
nullptr,
Any());
354void SAL_CALL JavaMigration::setPropertyValueForLocale(
361void SAL_CALL JavaMigration::endProperty()
368void SAL_CALL JavaMigration::addProperty(
376void SAL_CALL JavaMigration::addPropertyWithValue(
383void SAL_CALL JavaMigration::addOrReplaceNodeFromTemplate(
385 const TemplateIdentifier&,
#define SAL_CONFIGFILE(name)
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)
Sequence< PropertyValue > aArguments
constexpr OUStringLiteral SERVICE_NAME
css::uno::Reference< css::configuration::backend::XLayer > m_xLayer
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString jvmfwk_getImplementationName()
css::uno::Sequence< OUString > jvmfwk_getSupportedServiceNames()
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)