LCOV - code coverage report
Current view: top level - desktop/source/migration/services - jvmfwk.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 105 0.0 %
Date: 2014-11-03 Functions: 0 26 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      21             : #include <cppuhelper/implbase4.hxx>
      22             : #include <cppuhelper/implementationentry.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <rtl/ustring.h>
      26             : #include <rtl/ustring.hxx>
      27             : #include <rtl/bootstrap.hxx>
      28             : #include <sal/types.h>
      29             : #include <sal/config.h>
      30             : #include <boost/noncopyable.hpp>
      31             : #include <boost/scoped_array.hpp>
      32             : #include <com/sun/star/lang/XServiceInfo.hpp>
      33             : #include <com/sun/star/lang/XInitialization.hpp>
      34             : #include <com/sun/star/lang/WrappedTargetException.hpp>
      35             : #include <com/sun/star/task/XJob.hpp>
      36             : #include <com/sun/star/configuration/backend/XLayer.hpp>
      37             : #include <com/sun/star/configuration/backend/XLayerHandler.hpp>
      38             : #include <com/sun/star/configuration/backend/MalformedDataException.hpp>
      39             : #include <com/sun/star/configuration/backend/TemplateIdentifier.hpp>
      40             : #include <jvmfwk/framework.h>
      41             : #include "jvmfwk.hxx"
      42             : #include <stack>
      43             : #include <stdio.h>
      44             : 
      45             : #include <osl/thread.hxx>
      46             : 
      47             : #define SERVICE_NAME "com.sun.star.migration.Java"
      48             : #define IMPL_NAME "com.sun.star.comp.desktop.migration.Java"
      49             : 
      50             : #define ENABLE_JAVA     1
      51             : #define USER_CLASS_PATH 2
      52             : 
      53             : using namespace com::sun::star::uno;
      54             : using namespace com::sun::star::beans;
      55             : using namespace com::sun::star::lang;
      56             : using namespace com::sun::star::configuration::backend;
      57             : 
      58             : namespace migration
      59             : {
      60             : 
      61             : class CJavaInfo: private boost::noncopyable
      62             : {
      63             : public:
      64             :     JavaInfo* pData;
      65             :     CJavaInfo();
      66             :     ~CJavaInfo();
      67           0 :     operator JavaInfo* () const { return pData;}
      68             : };
      69             : 
      70           0 : CJavaInfo::CJavaInfo(): pData(NULL)
      71             : {
      72           0 : }
      73             : 
      74           0 : CJavaInfo::~CJavaInfo()
      75             : {
      76           0 :     jfw_freeJavaInfo(pData);
      77           0 : }
      78             : 
      79             : 
      80             : 
      81             : class JavaMigration : public ::cppu::WeakImplHelper4<
      82             :     css::lang::XServiceInfo,
      83             :     css::lang::XInitialization,
      84             :     css::task::XJob,
      85             :     css::configuration::backend::XLayerHandler>
      86             : {
      87             : public:
      88             :     // XServiceInfo
      89             :     virtual OUString SAL_CALL getImplementationName()
      90             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      91             :     virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName )
      92             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      93             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
      94             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             : 
      96             :     //XInitialization
      97             :     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
      98             :         throw(css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      99             : 
     100             :     //XJob
     101             :     virtual css::uno::Any SAL_CALL execute(
     102             :         const css::uno::Sequence<css::beans::NamedValue >& Arguments )
     103             :         throw (css::lang::IllegalArgumentException, css::uno::Exception,
     104             :                css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     105             : 
     106             :         // XLayerHandler
     107             :     virtual void SAL_CALL startLayer()
     108             :         throw(::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
     109             : 
     110             :     virtual void SAL_CALL endLayer()
     111             :         throw(
     112             :             ::com::sun::star::configuration::backend::MalformedDataException,
     113             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     114             : 
     115             :     virtual void SAL_CALL overrideNode(
     116             :             const OUString& aName,
     117             :             sal_Int16 aAttributes,
     118             :             sal_Bool bClear)
     119             :         throw(
     120             :             ::com::sun::star::configuration::backend::MalformedDataException,
     121             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     122             : 
     123             :     virtual void SAL_CALL addOrReplaceNode(
     124             :             const OUString& aName,
     125             :             sal_Int16 aAttributes)
     126             :         throw(
     127             :             ::com::sun::star::configuration::backend::MalformedDataException,
     128             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     129             : 
     130             :     virtual void SAL_CALL  addOrReplaceNodeFromTemplate(
     131             :             const OUString& aName,
     132             :             const ::com::sun::star::configuration::backend::TemplateIdentifier& aTemplate,
     133             :             sal_Int16 aAttributes )
     134             :         throw(
     135             :             ::com::sun::star::configuration::backend::MalformedDataException,
     136             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     137             : 
     138             :     virtual void SAL_CALL  endNode()
     139             :         throw(
     140             :             ::com::sun::star::configuration::backend::MalformedDataException,
     141             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     142             : 
     143             :     virtual void SAL_CALL  dropNode(
     144             :             const OUString& aName )
     145             :         throw(
     146             :             ::com::sun::star::configuration::backend::MalformedDataException,
     147             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     148             : 
     149             :     virtual void SAL_CALL  overrideProperty(
     150             :             const OUString& aName,
     151             :             sal_Int16 aAttributes,
     152             :             const css::uno::Type& aType,
     153             :             sal_Bool bClear )
     154             :         throw(
     155             :             ::com::sun::star::configuration::backend::MalformedDataException,
     156             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     157             : 
     158             :     virtual void SAL_CALL  setPropertyValue(
     159             :             const css::uno::Any& aValue )
     160             :         throw(
     161             :             ::com::sun::star::configuration::backend::MalformedDataException,
     162             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     163             : 
     164             :     virtual void SAL_CALL setPropertyValueForLocale(
     165             :             const css::uno::Any& aValue,
     166             :             const OUString& aLocale )
     167             :         throw(
     168             :             ::com::sun::star::configuration::backend::MalformedDataException,
     169             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     170             : 
     171             :     virtual void SAL_CALL  endProperty()
     172             :         throw(
     173             :             ::com::sun::star::configuration::backend::MalformedDataException,
     174             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     175             : 
     176             :     virtual void SAL_CALL  addProperty(
     177             :             const OUString& aName,
     178             :             sal_Int16 aAttributes,
     179             :             const css::uno::Type& aType )
     180             :         throw(
     181             :             ::com::sun::star::configuration::backend::MalformedDataException,
     182             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     183             : 
     184             :     virtual void SAL_CALL  addPropertyWithValue(
     185             :             const OUString& aName,
     186             :             sal_Int16 aAttributes,
     187             :             const css::uno::Any& aValue )
     188             :         throw(
     189             :             ::com::sun::star::configuration::backend::MalformedDataException,
     190             :             ::com::sun::star::lang::WrappedTargetException, std::exception ) SAL_OVERRIDE;
     191             : 
     192             : 
     193             : 
     194             : 
     195             :     virtual ~JavaMigration();
     196             : 
     197             : private:
     198             :     OUString m_sUserDir;
     199             :     css::uno::Reference< css::configuration::backend::XLayer> m_xLayer;
     200             : 
     201             :     void migrateJavarc();
     202             :     typedef ::std::pair< OUString,   sal_Int16>  TElementType;
     203             :     typedef ::std::stack< TElementType > TElementStack;
     204             :     TElementStack m_aStack;
     205             : 
     206             : };
     207             : 
     208           0 : JavaMigration::~JavaMigration()
     209             : {
     210             :     OSL_ASSERT(m_aStack.empty());
     211           0 : }
     212             : 
     213           0 : OUString jvmfwk_getImplementationName()
     214             : {
     215           0 :     return OUString(IMPL_NAME);
     216             : }
     217             : 
     218           0 : css::uno::Sequence< OUString > jvmfwk_getSupportedServiceNames()
     219             : {
     220           0 :     OUString str_name = SERVICE_NAME;
     221           0 :     return css::uno::Sequence< OUString >( &str_name, 1 );
     222             : }
     223             : 
     224             : // XServiceInfo
     225           0 : OUString SAL_CALL JavaMigration::getImplementationName()
     226             :     throw (css::uno::RuntimeException, std::exception)
     227             : {
     228           0 :     return jvmfwk_getImplementationName();
     229             : }
     230             : 
     231           0 : sal_Bool JavaMigration::supportsService(OUString const & ServiceName)
     232             :         throw (css::uno::RuntimeException, std::exception)
     233             : {
     234           0 :     return cppu::supportsService(this, ServiceName);
     235             : }
     236             : 
     237           0 : css::uno::Sequence< OUString > SAL_CALL JavaMigration::getSupportedServiceNames()
     238             :         throw (css::uno::RuntimeException, std::exception)
     239             : {
     240           0 :     return jvmfwk_getSupportedServiceNames();
     241             : }
     242             : 
     243             : //XInitialization ----------------------------------------------------------------------
     244           0 : void SAL_CALL JavaMigration::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
     245             :         throw(css::uno::Exception, css::uno::RuntimeException, std::exception)
     246             : {
     247           0 :     const css::uno::Any* pIter = aArguments.getConstArray();
     248           0 :     const css::uno::Any* pEnd = pIter + aArguments.getLength();
     249           0 :     css::uno::Sequence<css::beans::NamedValue> aOldConfigValues;
     250           0 :     css::beans::NamedValue aValue;
     251           0 :     for(;pIter != pEnd;++pIter)
     252             :     {
     253           0 :         *pIter >>= aValue;
     254           0 :         if ( aValue.Name == "OldConfiguration" )
     255             :         {
     256           0 :             bool bSuccess = aValue.Value >>= aOldConfigValues;
     257             :             OSL_ENSURE(bSuccess, "[Service implementation " IMPL_NAME
     258             :                        "] XInitialization::initialize: Argument OldConfiguration has wrong type.");
     259           0 :             if (bSuccess)
     260             :             {
     261           0 :                 const css::beans::NamedValue* pIter2 = aOldConfigValues.getConstArray();
     262           0 :                 const css::beans::NamedValue* pEnd2 = pIter2 + aOldConfigValues.getLength();
     263           0 :                 for(;pIter2 != pEnd2;++pIter2)
     264             :                 {
     265           0 :                     if ( pIter2->Name == "org.openoffice.Office.Java" )
     266             :                     {
     267           0 :                         pIter2->Value >>= m_xLayer;
     268           0 :                         break;
     269             :                     }
     270             :                 }
     271             :             }
     272             :         }
     273           0 :         else if ( aValue.Name == "UserData" )
     274             :         {
     275           0 :             if ( !(aValue.Value >>= m_sUserDir) )
     276             :             {
     277             :                 OSL_FAIL(
     278             :                     "[Service implementation " IMPL_NAME
     279             :                     "] XInitialization::initialize: Argument UserData has wrong type.");
     280             :             }
     281             :         }
     282           0 :     }
     283             : 
     284           0 : }
     285             : 
     286             : //XJob
     287           0 : css::uno::Any SAL_CALL JavaMigration::execute(
     288             :         const css::uno::Sequence<css::beans::NamedValue >& )
     289             :         throw (css::lang::IllegalArgumentException, css::uno::Exception,
     290             :                css::uno::RuntimeException, std::exception)
     291             : {
     292           0 :     migrateJavarc();
     293           0 :     if (m_xLayer.is())
     294           0 :         m_xLayer->readData(this);
     295             : 
     296           0 :     return css::uno::Any();
     297             : }
     298             : 
     299           0 : void JavaMigration::migrateJavarc()
     300             : {
     301           0 :     if (m_sUserDir.isEmpty())
     302           0 :         return;
     303             : 
     304           0 :     OUString sValue;
     305           0 :     rtl::Bootstrap javaini(m_sUserDir + "/user/config/" SAL_CONFIGFILE("java"));
     306           0 :     bool bSuccess = javaini.getFrom("Home", sValue);
     307             :     OSL_ENSURE(bSuccess, "[Service implementation " IMPL_NAME
     308             :                        "] XJob::execute: Could not get Home entry from java.ini/javarc.");
     309           0 :     if (bSuccess && !sValue.isEmpty())
     310             :     {
     311             :         //get the directory
     312           0 :         CJavaInfo aInfo;
     313           0 :         javaFrameworkError err = jfw_getJavaInfoByPath(sValue.pData, &aInfo.pData);
     314             : 
     315           0 :         if (err == JFW_E_NONE)
     316             :         {
     317           0 :             if (jfw_setSelectedJRE(aInfo) != JFW_E_NONE)
     318             :             {
     319             :                 OSL_FAIL("[Service implementation " IMPL_NAME
     320             :                            "] XJob::execute: jfw_setSelectedJRE failed.");
     321           0 :                 fprintf(stderr, "\nCannot migrate Java. An error occurred.\n");
     322             :             }
     323             :         }
     324           0 :         else if (err == JFW_E_FAILED_VERSION)
     325             :         {
     326             :             fprintf(stderr, "\nCannot migrate Java settings because the version of the Java  "
     327           0 :                     "is not supported anymore.\n");
     328           0 :         }
     329           0 :     }
     330             : }
     331             : 
     332             : 
     333             : // XLayerHandler
     334           0 : void SAL_CALL JavaMigration::startLayer()
     335             :     throw(css::lang::WrappedTargetException, std::exception)
     336             : {
     337           0 : }
     338             : 
     339             : 
     340           0 : void SAL_CALL JavaMigration::endLayer()
     341             :     throw(
     342             :         MalformedDataException,
     343             :         WrappedTargetException, std::exception )
     344             : {
     345           0 : }
     346             : 
     347             : 
     348           0 : void SAL_CALL JavaMigration::overrideNode(
     349             :         const OUString&,
     350             :         sal_Int16,
     351             :         sal_Bool)
     352             :     throw(
     353             :         MalformedDataException,
     354             :         WrappedTargetException, std::exception )
     355             : 
     356             : {
     357             : 
     358           0 : }
     359             : 
     360             : 
     361           0 : void SAL_CALL JavaMigration::addOrReplaceNode(
     362             :         const OUString&,
     363             :         sal_Int16)
     364             :     throw(
     365             :         MalformedDataException,
     366             :         WrappedTargetException, std::exception )
     367             : {
     368             : 
     369           0 : }
     370           0 : void SAL_CALL  JavaMigration::endNode()
     371             :     throw(
     372             :         MalformedDataException,
     373             :         WrappedTargetException, std::exception )
     374             : {
     375           0 : }
     376             : 
     377             : 
     378           0 : void SAL_CALL  JavaMigration::dropNode(
     379             :         const OUString& )
     380             :     throw(
     381             :         MalformedDataException,
     382             :         WrappedTargetException, std::exception )
     383             : {
     384           0 : }
     385             : 
     386             : 
     387           0 : void SAL_CALL  JavaMigration::overrideProperty(
     388             :         const OUString& aName,
     389             :         sal_Int16,
     390             :         const Type&,
     391             :         sal_Bool )
     392             :     throw(
     393             :         MalformedDataException,
     394             :         WrappedTargetException, std::exception )
     395             : {
     396           0 :     if ( aName == "Enable" )
     397           0 :         m_aStack.push(TElementStack::value_type(aName,ENABLE_JAVA));
     398           0 :     else if ( aName == "UserClassPath" )
     399           0 :         m_aStack.push(TElementStack::value_type(aName, USER_CLASS_PATH));
     400           0 : }
     401             : 
     402             : 
     403           0 : void SAL_CALL  JavaMigration::setPropertyValue(
     404             :         const Any& aValue )
     405             :     throw(
     406             :         MalformedDataException,
     407             :         WrappedTargetException, std::exception )
     408             : {
     409           0 :     if ( !m_aStack.empty())
     410             :     {
     411           0 :         switch (m_aStack.top().second)
     412             :         {
     413             :         case ENABLE_JAVA:
     414             :         {
     415             :             bool val;
     416           0 :             if (!(aValue >>= val))
     417             :                 throw MalformedDataException(
     418             :                        "[Service implementation " IMPL_NAME
     419           0 :                        "] XLayerHandler::setPropertyValue received wrong type for Enable property", 0, Any());
     420           0 :             if (jfw_setEnabled(val) != JFW_E_NONE)
     421             :                 throw WrappedTargetException(
     422             :                        "[Service implementation " IMPL_NAME
     423           0 :                        "] XLayerHandler::setPropertyValue: jfw_setEnabled failed.", 0, Any());
     424             : 
     425           0 :             break;
     426             :         }
     427             :         case USER_CLASS_PATH:
     428             :          {
     429           0 :              OUString cp;
     430           0 :              if (!(aValue >>= cp))
     431             :                  throw MalformedDataException(
     432             :                            "[Service implementation " IMPL_NAME
     433           0 :                            "] XLayerHandler::setPropertyValue received wrong type for UserClassPath property", 0, Any());
     434             : 
     435           0 :              if (jfw_setUserClassPath(cp.pData) != JFW_E_NONE)
     436             :                  throw WrappedTargetException(
     437             :                        "[Service implementation " IMPL_NAME
     438           0 :                        "] XLayerHandler::setPropertyValue: jfw_setUserClassPath failed.", 0, Any());
     439           0 :              break;
     440             :          }
     441             :         default:
     442             :             OSL_ASSERT(false);
     443             :         }
     444             :     }
     445           0 : }
     446             : 
     447             : 
     448           0 : void SAL_CALL JavaMigration::setPropertyValueForLocale(
     449             :         const Any&,
     450             :         const OUString& )
     451             :     throw(
     452             :         MalformedDataException,
     453             :         WrappedTargetException, std::exception )
     454             : {
     455           0 : }
     456             : 
     457             : 
     458           0 : void SAL_CALL  JavaMigration::endProperty()
     459             :     throw(
     460             :         MalformedDataException,
     461             :         WrappedTargetException, std::exception )
     462             : {
     463           0 :             if (!m_aStack.empty())
     464           0 :                 m_aStack.pop();
     465           0 : }
     466             : 
     467             : 
     468           0 : void SAL_CALL  JavaMigration::addProperty(
     469             :         const OUString&,
     470             :         sal_Int16,
     471             :         const Type& )
     472             :     throw(
     473             :         MalformedDataException,
     474             :         WrappedTargetException, std::exception )
     475             : {
     476           0 : }
     477             : 
     478             : 
     479           0 : void SAL_CALL  JavaMigration::addPropertyWithValue(
     480             :         const OUString&,
     481             :         sal_Int16,
     482             :         const Any& )
     483             :     throw(
     484             :         MalformedDataException,
     485             :         WrappedTargetException, std::exception )
     486             : {
     487           0 : }
     488             : 
     489           0 : void SAL_CALL JavaMigration::addOrReplaceNodeFromTemplate(
     490             :         const OUString&,
     491             :         const TemplateIdentifier&,
     492             :         sal_Int16 )
     493             :     throw(
     494             :         MalformedDataException,
     495             :         WrappedTargetException, std::exception )
     496             : {
     497           0 : }
     498             : 
     499             : 
     500             : //ToDo enable java, user class path
     501             : 
     502             : } //end namespace jfw
     503             : 
     504             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10