LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/jvmfwk/plugins/sunmajor/pluginlib - vendorbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 99 71.7 %
Date: 2013-07-09 Functions: 9 18 50.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 "osl/file.hxx"
      22             : #include "osl/diagnose.h"
      23             : #include "osl/module.hxx"
      24             : #include "osl/thread.hxx"
      25             : 
      26             : #include "vendorbase.hxx"
      27             : #include "util.hxx"
      28             : #include "sunjre.hxx"
      29             : 
      30             : using namespace std;
      31             : using namespace osl;
      32             : 
      33             : 
      34             : namespace jfw_plugin
      35             : {
      36             : rtl::Reference<VendorBase> createInstance(createInstance_func pFunc,
      37             :                                           vector<pair<OUString, OUString> > properties);
      38             : 
      39             : 
      40             : 
      41             : 
      42             : 
      43             : 
      44             : 
      45             : //##############################################################################
      46             : 
      47           0 : MalformedVersionException::MalformedVersionException()
      48           0 : {}
      49           0 : MalformedVersionException::MalformedVersionException(
      50           0 :     const MalformedVersionException & )
      51           0 : {}
      52           0 : MalformedVersionException::~MalformedVersionException()
      53           0 : {}
      54             : MalformedVersionException &
      55           0 : MalformedVersionException::operator =(
      56             :     const MalformedVersionException &)
      57             : {
      58           0 :     return *this;
      59             : }
      60             : //##############################################################################
      61             : 
      62             : 
      63         207 : VendorBase::VendorBase(): m_bAccessibility(false)
      64             : {
      65         207 : }
      66             : 
      67           0 : rtl::Reference<VendorBase> VendorBase::createInstance()
      68             : {
      69           0 :     VendorBase *pBase = new VendorBase();
      70           0 :     return rtl::Reference<VendorBase>(pBase);
      71             : }
      72             : 
      73         207 : bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
      74             : {
      75             :     //get java.vendor, java.version, java.home,
      76             :     //javax.accessibility.assistive_technologies from system properties
      77             : 
      78             :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      79         207 :     OUString sVendorProperty("java.vendor");
      80         414 :     OUString sVersionProperty("java.version");
      81         414 :     OUString sHomeProperty("java.home");
      82         414 :     OUString sAccessProperty("javax.accessibility.assistive_technologies");
      83             : 
      84         207 :     bool bVersion = false;
      85         207 :     bool bVendor = false;
      86         207 :     bool bHome = false;
      87         207 :     bool bAccess = false;
      88             : 
      89             :     typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
      90       10971 :     for (it_prop i = props.begin(); i != props.end(); ++i)
      91             :     {
      92       10764 :         if(! bVendor && sVendorProperty.equals(i->first))
      93             :         {
      94         207 :             m_sVendor = i->second;
      95         207 :             bVendor = true;
      96             :         }
      97       10557 :         else if (!bVersion && sVersionProperty.equals(i->first))
      98             :         {
      99         207 :             m_sVersion = i->second;
     100         207 :             bVersion = true;
     101             :         }
     102       10350 :         else if (!bHome && sHomeProperty.equals(i->first))
     103             :         {
     104             : #ifndef JVM_ONE_PATH_CHECK
     105         207 :            OUString fileURL;
     106         207 :            if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
     107             :                osl_File_E_None)
     108             :            {
     109             :                //make sure that the drive letter have all the same case
     110             :                //otherwise file:///c:/jre and file:///C:/jre produce two
     111             :                //different objects!!!
     112         207 :                if (makeDriveLetterSame( & fileURL))
     113             :                {
     114         207 :                    m_sHome = fileURL;
     115         207 :                    bHome = true;
     116             :                }
     117         207 :            }
     118             : #else
     119             :            m_sHome = i->second;
     120             :            bHome = true;
     121             : #endif
     122             :         }
     123       10143 :         else if (!bAccess && sAccessProperty.equals(i->first))
     124             :         {
     125           0 :             if (!i->second.isEmpty())
     126             :             {
     127           0 :                 m_bAccessibility = true;
     128           0 :                 bAccess = true;
     129             :             }
     130             :         }
     131             :         // the javax.accessibility.xxx property may not be set. Therefore we
     132             :         //must search through all properties.
     133             : 
     134             :     }
     135         207 :     if (!bVersion || !bVendor || !bHome)
     136           0 :         return false;
     137             : 
     138             :     // init m_sRuntimeLibrary
     139             :     OSL_ASSERT(!m_sHome.isEmpty());
     140             :     //call virtual function to get the possible paths to the runtime library.
     141             : 
     142         207 :     int size = 0;
     143         207 :     char const* const* arRtPaths = getRuntimePaths( & size);
     144         414 :     vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
     145             : 
     146         207 :     bool bRt = false;
     147             :     typedef vector<OUString>::const_iterator i_path;
     148         207 :     for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
     149             :     {
     150             :         //Construct an absolute path to the possible runtime
     151         207 :         OUString usRt= m_sHome + *ip;
     152         207 :         DirectoryItem item;
     153         207 :         if(DirectoryItem::get(usRt, item) == File::E_None)
     154             :         {
     155             :             //found runtime lib
     156         207 :             m_sRuntimeLibrary = usRt;
     157         207 :             bRt = true;
     158         207 :             break;
     159             :         }
     160           0 :     }
     161         207 :     if (!bRt)
     162           0 :         return false;
     163             : 
     164             : #if defined(WNT)
     165             :     oslModule moduleRt = 0;
     166             :     rtl::OUString sRuntimeLib;
     167             :     if( File::getSystemPathFromFileURL( m_sRuntimeLibrary, sRuntimeLib ) == File::E_None )
     168             :     {
     169             :         if ( ( moduleRt = osl_loadModule( sRuntimeLib.pData, SAL_LOADMODULE_DEFAULT ) ) == 0 )
     170             :         {
     171             :             OSL_TRACE( "jfw_plugin::VendorBase::initialize - cannot load library %s",
     172             :                        rtl::OUStringToOString( sRuntimeLib, osl_getThreadTextEncoding() ).getStr() );
     173             :             return false;
     174             :         }
     175             :         else
     176             :         {
     177             :             // do not leave the module loaded!
     178             :             osl_unloadModule( moduleRt );
     179             :         }
     180             :     }
     181             : #endif
     182             : 
     183             :     // init m_sLD_LIBRARY_PATH
     184             :     OSL_ASSERT(!m_sHome.isEmpty());
     185         207 :     size = 0;
     186         207 :     char const * const * arLDPaths = getLibraryPaths( & size);
     187         414 :     vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
     188             : 
     189         207 :     char arSep[]= {SAL_PATHSEPARATOR, 0};
     190         414 :     OUString sPathSep= OUString::createFromAscii(arSep);
     191         207 :     bool bLdPath = true;
     192         207 :     int c = 0;
     193        1035 :     for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
     194             :     {
     195         828 :         OUString usAbsUrl= m_sHome + *il;
     196             :         // convert to system path
     197        1656 :         OUString usSysPath;
     198         828 :         if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
     199             :         {
     200             : 
     201         828 :             if(c > 0)
     202         621 :                 m_sLD_LIBRARY_PATH+= sPathSep;
     203         828 :             m_sLD_LIBRARY_PATH+= usSysPath;
     204             :         }
     205             :         else
     206             :         {
     207           0 :             bLdPath = false;
     208           0 :             break;
     209             :         }
     210         828 :     }
     211         207 :     if (bLdPath == false)
     212           0 :         return false;
     213             : 
     214         414 :     return true;
     215             : }
     216             : 
     217           0 : char const* const* VendorBase::getRuntimePaths(int* /*size*/)
     218             : {
     219           0 :     return NULL;
     220             : }
     221             : 
     222           0 : char const* const* VendorBase::getLibraryPaths(int* /*size*/)
     223             : {
     224           0 :     return NULL;
     225             : }
     226             : 
     227         315 : const OUString & VendorBase::getVendor() const
     228             : {
     229         315 :     return m_sVendor;
     230             : }
     231         210 : const OUString & VendorBase::getVersion() const
     232             : {
     233         210 :     return m_sVersion;
     234             : }
     235             : 
     236        3063 : const OUString & VendorBase::getHome() const
     237             : {
     238        3063 :     return m_sHome;
     239             : }
     240             : 
     241         315 : const OUString & VendorBase::getLibraryPaths() const
     242             : {
     243         315 :     return m_sLD_LIBRARY_PATH;
     244             : }
     245             : 
     246         105 : const OUString & VendorBase::getRuntimeLibrary() const
     247             : {
     248         105 :     return m_sRuntimeLibrary;
     249             : }
     250         105 : bool VendorBase::supportsAccessibility() const
     251             : {
     252         105 :     return m_bAccessibility;
     253             : }
     254             : 
     255         105 : bool VendorBase::needsRestart() const
     256             : {
     257         105 :     if (!getLibraryPaths().isEmpty())
     258         105 :         return true;
     259           0 :     return false;
     260             : }
     261             : 
     262           0 : int VendorBase::compareVersions(const OUString& /*sSecond*/) const
     263             : {
     264             :     OSL_FAIL("[Java framework] VendorBase::compareVersions must be "
     265             :                "overridden in derived class.");
     266           0 :     return 0;
     267             : }
     268             : 
     269             : 
     270             : 
     271             : 
     272             : }
     273             : 
     274             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10