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