LCOV - code coverage report
Current view: top level - jvmfwk/source - elements.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 6 6 100.0 %
Date: 2014-04-14 Functions: 6 6 100.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             : #ifndef INCLUDED_JVMFWK_ELEMENTS_HXX
      20             : #define INCLUDED_JVMFWK_ELEMENTS_HXX
      21             : 
      22             : #include <vector>
      23             : #include "jvmfwk/framework.h"
      24             : #include "fwkutil.hxx"
      25             : #include "rtl/ustring.hxx"
      26             : #include "rtl/byteseq.hxx"
      27             : #include "libxml/parser.h"
      28             : #include "boost/optional.hpp"
      29             : 
      30             : #define NS_JAVA_FRAMEWORK "http://openoffice.org/2004/java/framework/1.0"
      31             : #define NS_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance"
      32             : 
      33             : namespace jfw
      34             : {
      35             : 
      36             : /** gets the value of the updated element from the javavendors.xml.
      37             :  */
      38             : OString getElementUpdated();
      39             : 
      40             : /** create the child elements within the root structure for each platform.
      41             : 
      42             :     @param bNeedsSave
      43             :     [out]If true then the respective structure of elements was added and the
      44             :     document needs to be saved.
      45             :  */
      46             : void createSettingsStructure(
      47             :     xmlDoc * document, bool * bNeedsSave);
      48             : 
      49             : 
      50             : /** represents the settings saved in the /java/javaInfo element.
      51             :     It is used within class NodeJava which determines the settings
      52             :     file.
      53             : */
      54      255026 : class CNodeJavaInfo
      55             : {
      56             : public:
      57             :     CNodeJavaInfo();
      58             :     ~CNodeJavaInfo();
      59             : 
      60             :     /** if true, then javaInfo is empty. When writeToNode is called
      61             :         then all child elements are deleted.
      62             :      */
      63             :     bool m_bEmptyNode;
      64             :     /** Contains the value of the <updated> element of
      65             :         the javavendors.xml after loadFromNode was called.
      66             :         It is not used, when the javaInfo node is written.
      67             :         see writeToNode
      68             :      */
      69             :     OString sAttrVendorUpdate;
      70             :     /** contains the nil value of the /java/javaInfo@xsi:nil attribute.
      71             :         Default is true;
      72             :      */
      73             :     bool bNil;
      74             :     /** contains the value of the /java/javaInfo@autoSelect attribute.
      75             :         Default is true. If it is false then the user has modified the JRE
      76             :         selection by actively choosing a JRE from the options dialog. That is,
      77             :         the function jfw_setSelectedJRE was called. Contrary, the function
      78             :         jfw_findAndSelectJRE sets the attribute to true.
      79             :      */
      80             :     bool bAutoSelect;
      81             :     OUString sVendor;
      82             :     OUString sLocation;
      83             :     OUString sVersion;
      84             :     sal_uInt64 nFeatures;
      85             :     sal_uInt64 nRequirements;
      86             :     ::rtl::ByteSequence arVendorData;
      87             : 
      88             :     /** reads the node /java/javaInfo.
      89             :         If javaInfo@xsi:nil = true then member bNil is set to true
      90             :         an no further elements are read.
      91             :      */
      92             :     void loadFromNode(xmlDoc * pDoc,xmlNode * pJavaInfo);
      93             :     /** The attribut nil will be set to false. The function gets the value
      94             :         javaSettings/updated from the javavendors.xml and writes it to
      95             :         javaInfo@vendorUpdate in javasettings.xml
      96             :      */
      97             :     void writeToNode(xmlDoc * pDoc, xmlNode * pJavaInfo) const;
      98             : 
      99             :     /** returns NULL if javaInfo is nil.
     100             :      */
     101             :     JavaInfo * makeJavaInfo() const;
     102             : };
     103             : 
     104             : /** this class represents the java settings  based on a particular
     105             :     settings file.
     106             : 
     107             :     Which settings file is used is determined by the value passed into the
     108             :     constructor and the values of the bootstrap parameters
     109             :     UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
     110             : 
     111             :     The method load reads the data from the settings file.
     112             :     The method write stores the data into the settings file.
     113             :  */
     114      170021 : class NodeJava
     115             : {
     116             : public:
     117             :     enum Layer { USER, SHARED };
     118             : private:
     119             : 
     120             :     /** creates settings file and fills it with default values.
     121             : 
     122             :         When this function is called then it creates the
     123             :         settings file at the possition determined by the bootstrap parameters
     124             :         (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA) and m_layer, unless
     125             :         the file already exists (see createSettingsDocument).
     126             : 
     127             :         @return
     128             :         JFW_E_CONFIG_READWRITE
     129             :     */
     130             :     bool prepareSettingsDocument() const;
     131             : 
     132             :     /** helper function for prepareSettingsDocument.
     133             :     */
     134             :     bool createSettingsDocument() const;
     135             : 
     136             :     /** returns the system path to the data file which is to be used. The value
     137             :         depends on the member m_layer and the bootstrap parameters
     138             :         UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
     139             :     */
     140             :     OString getSettingsPath() const;
     141             : 
     142             :     /** returns the file URL to the data file which is to be used. See getSettingsPath.
     143             :     */
     144             :     OUString getSettingsURL() const;
     145             : 
     146             :     /** Verifies if the respective settings file exist.
     147             :      */
     148             :     jfw::FileStatus checkSettingsFileStatus(OUString const & sURL) const;
     149             : 
     150             :     /** Determines the layer for which the instance the loads and writes the
     151             :         data.
     152             :     */
     153             :     Layer m_layer;
     154             : 
     155             :     /** User configurable option.  /java/enabled
     156             :         If /java/enabled@xsi:nil == true then the value will be uninitialized
     157             :         after a call to load().
     158             :     */
     159             :     boost::optional<sal_Bool> m_enabled;
     160             : 
     161             :     /** User configurable option. /java/userClassPath
     162             :         If /java/userClassPath@xsi:nil == true then the value is uninitialized
     163             :         after a call to load().
     164             :     */
     165             :     boost::optional< OUString> m_userClassPath;
     166             :     /** User configurable option.  /java/javaInfo
     167             :         If /java/javaInfo@xsi:nil == true then the value is uninitialized
     168             :         after a call to load.
     169             :      */
     170             :     boost::optional<CNodeJavaInfo> m_javaInfo;
     171             :     /** User configurable option. /java/vmParameters
     172             :         If /java/vmParameters@xsi:nil == true then the value is uninitialized
     173             :         after a call to load.
     174             :     */
     175             :     boost::optional< ::std::vector< OUString> > m_vmParameters;
     176             :     /** User configurable option. /java/jreLocations
     177             :         If /java/jreLocaltions@xsi:nil == true then the value is uninitialized
     178             :         after a call to load.
     179             :     */
     180             :     boost::optional< ::std::vector< OUString> > m_JRELocations;
     181             : 
     182             : public:
     183             : 
     184             :     explicit NodeJava(Layer theLayer);
     185             : 
     186             :     /** sets m_enabled.
     187             :         /java/enabled@xsi:nil will be set to false when write is called.
     188             :      */
     189             :     void setEnabled(bool bEnabled);
     190             : 
     191             :     /** sets m_sUserClassPath. See setEnabled.
     192             :      */
     193             :     void setUserClassPath(const OUString & sClassPath);
     194             : 
     195             :     /** sets m_aInfo. See setEnabled.
     196             :         @param bAutoSelect
     197             :         true- called by jfw_setSelectedJRE
     198             :         false called by jfw_findAndSelectJRE
     199             :      */
     200             :     void setJavaInfo(const JavaInfo * pInfo, bool bAutoSelect);
     201             : 
     202             :     /** sets the /java/vmParameters/param elements.
     203             :         When this method all previous values are removed and replaced
     204             :         by those in arParameters.
     205             :         /java/vmParameters@xsi:nil will be set to true when write() is
     206             :         called.
     207             :      */
     208             :     void setVmParameters(rtl_uString  * * arParameters, sal_Int32 size);
     209             : 
     210             :     /** sets the /java/jreLocations/location elements.
     211             :         When this method is called then all previous values are removed
     212             :         and replaced by those in arParamters.
     213             :         /java/jreLocations@xsi:nil will be set to true write() is called.
     214             :      */
     215             :     void setJRELocations(rtl_uString  * * arParameters, sal_Int32 size);
     216             : 
     217             :     /** adds a location to the already existing locations.
     218             :         Note: call load() before, then add the location and then call write().
     219             :     */
     220             :     void addJRELocation(rtl_uString * sLocation);
     221             : 
     222             :     /** writes the data to user settings.
     223             :      */
     224             :     void write() const;
     225             : 
     226             :     /** load the values of the settings file.
     227             :      */
     228             :     void load();
     229             : 
     230             :     /** returns the value of the element /java/enabled
     231             :      */
     232             :     const boost::optional<sal_Bool> & getEnabled() const;
     233             :     /** returns the value of the element /java/userClassPath.
     234             :      */
     235             :     const boost::optional< OUString> & getUserClassPath() const;
     236             : 
     237             :     /** returns the value of the element /java/javaInfo.
     238             :      */
     239             :     const boost::optional<CNodeJavaInfo> & getJavaInfo() const;
     240             : 
     241             :     /** returns the parameters from the element /java/vmParameters/param.
     242             :      */
     243             :     const boost::optional< ::std::vector< OUString> > & getVmParameters() const;
     244             : 
     245             :     /** returns the parameters from the element /java/jreLocations/location.
     246             :      */
     247             :     const boost::optional< ::std::vector< OUString> > & getJRELocations() const;
     248             : };
     249             : 
     250             : /** merges the settings for shared, user and installation during construction.
     251             :     The class uses a simple merge mechanism for the javasettings.xml files in share and
     252             :     user. The following elements completely overwrite the corresponding elements
     253             :     from share:
     254             :     /java/enabled
     255             :     /java/userClassPath
     256             :     /java/vmParameters
     257             :     /java/jreLocations
     258             :     /java/javaInfo
     259             : 
     260             :     In case of an installation, the shared and user settings are completely
     261             :     disregarded.
     262             : 
     263             :     The locations of the different settings files is obtained through the
     264             :     bootstrap variables:
     265             :     UNO_JAVA_JFW_USER_DATA
     266             :     UNO_JAVA_JFW_SHARED_DATA
     267             : 
     268             :     The class also determines useful default values for settings which have not been made.
     269             : */
     270             : class MergedSettings
     271             : {
     272             : private:
     273             :     const MergedSettings& operator = (MergedSettings&);
     274             :     MergedSettings(MergedSettings&);
     275             : 
     276             :     void merge(const NodeJava & share, const NodeJava & user);
     277             : 
     278             :     bool m_bEnabled;
     279             : 
     280             :     OUString m_sClassPath;
     281             : 
     282             :     ::std::vector< OUString> m_vmParams;
     283             : 
     284             :     ::std::vector< OUString> m_JRELocations;
     285             : 
     286             :     CNodeJavaInfo m_javaInfo;
     287             : 
     288             : public:
     289             :     MergedSettings();
     290             :     virtual ~MergedSettings();
     291             : 
     292             :     /** the default is true.
     293             :      */
     294             :     bool getEnabled() const;
     295             : 
     296             :     const OUString & getUserClassPath() const;
     297             : 
     298             :     ::std::vector< OString> getVmParametersUtf8() const;
     299             :     /** returns a JavaInfo structure representing the node
     300             :         /java/javaInfo. Every time a new JavaInfo structure is created
     301             :         which needs to be freed by the caller.
     302             :         If both, user and share settings are nil, then NULL is returned.
     303             :     */
     304             :     JavaInfo * createJavaInfo() const;
     305             : 
     306             :     /** returns the value of the attribute /java/javaInfo[@vendorUpdate].
     307             :      */
     308             :     OString const & getJavaInfoAttrVendorUpdate() const;
     309             : 
     310             : #ifdef WNT
     311             :     /** returns the javaInfo@autoSelect attribute.
     312             :         Before calling this function loadFromSettings must be called.
     313             :         It uses the javaInfo@autoSelect attribute  to determine
     314             :         the return value;
     315             :      */
     316             :     bool getJavaInfoAttrAutoSelect() const;
     317             : #endif
     318             : 
     319             :     /** returns an array.
     320             :         Caller must free the strings and the array.
     321             :      */
     322             :     void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size) const;
     323             : 
     324             :     /** returns an array.
     325             :         Caller must free the strings and the array.
     326             :      */
     327             :     void getJRELocations(rtl_uString *** parLocations, sal_Int32 * size) const;
     328             : 
     329             :     const ::std::vector< OUString> & getJRELocations() const;
     330             : };
     331             : 
     332             : 
     333             : class VersionInfo
     334             : {
     335             :     ::std::vector< OUString> vecExcludeVersions;
     336             :     rtl_uString ** arVersions;
     337             : 
     338             : public:
     339             :     VersionInfo();
     340             :     ~VersionInfo();
     341             : 
     342             :     void addExcludeVersion(const OUString& sVersion);
     343             : 
     344             :     OUString sMinVersion;
     345             :     OUString sMaxVersion;
     346             : 
     347             :     /** The caller DOES NOT get ownership of the strings. That is he
     348             :         does not need to release the strings.
     349             :         The array exists as long as this object exists.
     350             :     */
     351             : 
     352             :     rtl_uString** getExcludeVersions();
     353             :     sal_Int32 getExcludeVersionSize();
     354             : };
     355             : 
     356          32 : struct PluginLibrary
     357             : {
     358           6 :     PluginLibrary()
     359           6 :     {
     360           6 :     }
     361             :     PluginLibrary(const OUString & vendor, const OUString & path) :
     362             :         sVendor(vendor), sPath(path)
     363             :     {
     364             :     }
     365             :     /** contains the vendor string which is later userd in the xml API
     366             :      */
     367             :     OUString sVendor;
     368             :     /** File URL the plug-in library
     369             :      */
     370             :     OUString sPath;
     371             : };
     372             : 
     373             : } //end namespace
     374             : #endif
     375             : 
     376             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10