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

Generated by: LCOV version 1.10