LCOV - code coverage report
Current view: top level - jvmfwk/source - elements.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 9 12 75.0 %
Date: 2015-06-13 12:38:46 Functions: 10 13 76.9 %
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_SOURCE_ELEMENTS_HXX
      20             : #define INCLUDED_JVMFWK_SOURCE_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          11 : 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 attribute 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          60 : 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 position 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             :     static jfw::FileStatus checkSettingsFileStatus(OUString const & sURL);
     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             :     /** adds a location to the already existing locations.
     211             :         Note: call load() before, then add the location and then call write().
     212             :     */
     213             :     void addJRELocation(rtl_uString * sLocation);
     214             : 
     215             :     /** writes the data to user settings.
     216             :      */
     217             :     void write() const;
     218             : 
     219             :     /** load the values of the settings file.
     220             :      */
     221             :     void load();
     222             : 
     223             :     /** returns the value of the element /java/enabled
     224             :      */
     225          56 :     const boost::optional<sal_Bool> & getEnabled() const { return m_enabled;}
     226             :     /** returns the value of the element /java/userClassPath.
     227             :      */
     228          56 :     const boost::optional< OUString> & getUserClassPath() const { return m_userClassPath;}
     229             : 
     230             :     /** returns the value of the element /java/javaInfo.
     231             :      */
     232          56 :     const boost::optional<CNodeJavaInfo> & getJavaInfo() const { return m_javaInfo;}
     233             : 
     234             :     /** returns the parameters from the element /java/vmParameters/param.
     235             :      */
     236          56 :     const boost::optional< ::std::vector< OUString> > & getVmParameters() const { return m_vmParameters;}
     237             : 
     238             :     /** returns the parameters from the element /java/jreLocations/location.
     239             :      */
     240          56 :     const boost::optional< ::std::vector< OUString> > & getJRELocations() const { return m_JRELocations;}
     241             : };
     242             : 
     243             : /** merges the settings for shared, user and installation during construction.
     244             :     The class uses a simple merge mechanism for the javasettings.xml files in share and
     245             :     user. The following elements completely overwrite the corresponding elements
     246             :     from share:
     247             :     /java/enabled
     248             :     /java/userClassPath
     249             :     /java/vmParameters
     250             :     /java/jreLocations
     251             :     /java/javaInfo
     252             : 
     253             :     In case of an installation, the shared and user settings are completely
     254             :     disregarded.
     255             : 
     256             :     The locations of the different settings files is obtained through the
     257             :     bootstrap variables:
     258             :     UNO_JAVA_JFW_USER_DATA
     259             :     UNO_JAVA_JFW_SHARED_DATA
     260             : 
     261             :     The class also determines useful default values for settings which have not been made.
     262             : */
     263             : class MergedSettings
     264             : {
     265             : private:
     266             :     const MergedSettings& operator = (MergedSettings&) SAL_DELETED_FUNCTION;
     267             :     MergedSettings(MergedSettings&) SAL_DELETED_FUNCTION;
     268             : 
     269             :     void merge(const NodeJava & share, const NodeJava & user);
     270             : 
     271             :     bool m_bEnabled;
     272             : 
     273             :     OUString m_sClassPath;
     274             : 
     275             :     ::std::vector< OUString> m_vmParams;
     276             : 
     277             :     ::std::vector< OUString> m_JRELocations;
     278             : 
     279             :     CNodeJavaInfo m_javaInfo;
     280             : 
     281             : public:
     282             :     MergedSettings();
     283             :     virtual ~MergedSettings();
     284             : 
     285             :     /** the default is true.
     286             :      */
     287          28 :     bool getEnabled() const { return m_bEnabled;}
     288             : 
     289           0 :     const OUString & getUserClassPath() const { return m_sClassPath;}
     290             : 
     291             :     ::std::vector< OString> getVmParametersUtf8() const;
     292             :     /** returns a JavaInfo structure representing the node
     293             :         /java/javaInfo. Every time a new JavaInfo structure is created
     294             :         which needs to be freed by the caller.
     295             :         If both, user and share settings are nil, then NULL is returned.
     296             :     */
     297             :     JavaInfo * createJavaInfo() const;
     298             : 
     299             :     /** returns the value of the attribute /java/javaInfo[@vendorUpdate].
     300             :      */
     301           0 :     OString const & getJavaInfoAttrVendorUpdate() const { return m_javaInfo.sAttrVendorUpdate;}
     302             : 
     303             : #ifdef WNT
     304             :     /** returns the javaInfo@autoSelect attribute.
     305             :         Before calling this function loadFromSettings must be called.
     306             :         It uses the javaInfo@autoSelect attribute  to determine
     307             :         the return value;
     308             :      */
     309             :     bool getJavaInfoAttrAutoSelect() const;
     310             : #endif
     311             : 
     312             :     /** returns an array.
     313             :         Caller must free the strings and the array.
     314             :      */
     315             :     void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size) const;
     316             : 
     317             :     /** returns an array.
     318             :         Caller must free the strings and the array.
     319             :      */
     320             :     void getJRELocations(rtl_uString *** parLocations, sal_Int32 * size) const;
     321             : 
     322           0 :     const ::std::vector< OUString> & getJRELocations() const { return m_JRELocations;}
     323             : };
     324             : 
     325             : 
     326          92 : class VersionInfo
     327             : {
     328             :     ::std::vector< OUString> vecExcludeVersions;
     329             :     rtl_uString ** arVersions;
     330             : 
     331             : public:
     332             :     VersionInfo();
     333             :     ~VersionInfo();
     334             : 
     335             :     void addExcludeVersion(const OUString& sVersion);
     336             : 
     337             :     OUString sMinVersion;
     338             :     OUString sMaxVersion;
     339             : 
     340             :     /** The caller DOES NOT get ownership of the strings. That is he
     341             :         does not need to release the strings.
     342             :         The array exists as long as this object exists.
     343             :     */
     344             : 
     345             :     rtl_uString** getExcludeVersions();
     346             :     sal_Int32 getExcludeVersionSize();
     347             : };
     348             : 
     349             : } //end namespace
     350             : #endif
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11