1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #if !defined INCLUDED_JFW_PLUGIN_UTIL_HXX 28 #define INCLUDED_JFW_PLUGIN_UTIL_HXX 29 30 #include "rtl/ustring.hxx" 31 #include "rtl/bootstrap.hxx" 32 #include <vector> 33 #include "vendorbase.hxx" 34 35 namespace jfw_plugin 36 { 37 38 class VendorBase; 39 std::vector<rtl::OUString> getVectorFromCharArray(char const * const * ar, int size); 40 41 /* The function uses the relative paths, such as "bin/java.exe" as provided by 42 VendorBase::getJavaExePaths and the provided path to derive the the home directory. 43 The home directory is then used as argument to getJREInfoByPath. For example 44 usBinDir is file:///c:/j2sdk/jre/bin then file:///c:/j2sdk/jre would be derived. 45 */ 46 bool getJREInfoFromBinPath( 47 const rtl::OUString& path, std::vector<rtl::Reference<VendorBase> > & vecInfos); 48 inline rtl::OUString getDirFromFile(const rtl::OUString& usFilePath); 49 void createJavaInfoFromPath(std::vector<rtl::Reference<VendorBase> >& vecInfos); 50 void createJavaInfoFromJavaHome(std::vector<rtl::Reference<VendorBase> > &vecInfos); 51 void createJavaInfoDirScan(std::vector<rtl::Reference<VendorBase> >& vecInfos); 52 #ifdef WNT 53 void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> >& vecInfos); 54 #endif 55 56 bool makeDriveLetterSame(rtl::OUString * fileURL); 57 58 59 /* for std::find_if 60 Used to find a JavaInfo::Impl object in a std::vector<Impl*> which has a member usJavaHome 61 as the specified string in the constructor. 62 */ 63 struct InfoFindSame 64 { 65 rtl::OUString sJava; 66 InfoFindSame(const rtl::OUString& sJavaHome):sJava(sJavaHome){} 67 68 bool operator () (const rtl::Reference<VendorBase> & aVendorInfo) 69 { 70 return aVendorInfo->getHome().equals(sJava) == sal_True ? true : false; 71 } 72 }; 73 74 struct SameOrSubDirJREMap 75 { 76 rtl::OUString s1; 77 SameOrSubDirJREMap(const rtl::OUString& s):s1(s){ 78 } 79 80 bool operator () (const std::pair<const rtl::OUString, rtl::Reference<VendorBase> > & s2) 81 { 82 if (s1 == s2.first) 83 return true; 84 rtl::OUString sSub; 85 sSub = s2.first + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); 86 if (s1.match(sSub) == sal_True) 87 return true; 88 return false; 89 } 90 }; 91 92 93 /* Creates a VendorBase object if a JRE could be found at the specified path. 94 95 This depends if there is a JRE at all and if it is from a vendor that 96 is supported by this plugin. 97 */ 98 rtl::Reference<VendorBase> getJREInfoByPath(const rtl::OUString& path); 99 100 /* Creates a VendorBase object if a JRE could be found at the specified path. 101 102 The difference to the other getJREInfoByPath is that this function checks 103 first if the path corresponds to one of the VendorBase::getHome path already 104 contained in vecInfo. Only if there is no such entry, then the other 105 getJREInfoByPath is called. Again the created VendorBase is compared to 106 those contained in vecInfos. If it it not in there then it's added. 107 108 @return 109 true a VendorBase was created and added to the end of vecInfos. 110 false - no VendorBase has been created. Either the path did not represent a 111 supported JRE installation or there was already a VendorBase in vecInfos. 112 */ 113 bool getJREInfoByPath(const rtl::OUString& path, 114 std::vector<rtl::Reference<VendorBase> > & vecInfos); 115 116 std::vector<rtl::Reference<VendorBase> > getAllJREInfos(); 117 118 bool getJavaProps( 119 const rtl::OUString & exePath, 120 std::vector<std::pair<rtl::OUString, rtl::OUString> >& props, 121 bool * bProcessRun); 122 123 void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos); 124 125 void bubbleSortVersion(std::vector<rtl::Reference<VendorBase> >& vec); 126 127 rtl::Bootstrap* getBootstrap(); 128 } 129 130 #endif 131