LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/deployment/misc - dp_dependencies.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 48 41.7 %
Date: 2013-07-09 Functions: 3 7 42.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             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include "com/sun/star/uno/Reference.hxx"
      23             : #include "com/sun/star/uno/Sequence.hxx"
      24             : #include "com/sun/star/xml/dom/XElement.hpp"
      25             : #include "com/sun/star/xml/dom/XNodeList.hpp"
      26             : #include "rtl/bootstrap.hxx"
      27             : #include "rtl/string.h"
      28             : #include "rtl/ustring.h"
      29             : #include "rtl/ustring.hxx"
      30             : #include "sal/types.h"
      31             : #include "tools/resid.hxx"
      32             : #include "unotools/configmgr.hxx"
      33             : 
      34             : #include "deployment.hrc"
      35             : #include "dp_resource.h"
      36             : 
      37             : #include "dp_dependencies.hxx"
      38             : #include "dp_descriptioninfoset.hxx"
      39             : #include "dp_version.hxx"
      40             : 
      41             : namespace {
      42             : 
      43             : static char const namespaceLibreOffice[] =
      44             :     "http://libreoffice.org/extensions/description/2011";
      45             : 
      46             : static char const namespaceOpenOfficeOrg[] =
      47             :     "http://openoffice.org/extensions/description/2006";
      48             : 
      49             : static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
      50             : 
      51             : static char const minimalVersionOpenOfficeOrg[] =
      52             :     "OpenOffice.org-minimal-version";
      53             : 
      54             : static char const maximalVersionOpenOfficeOrg[] =
      55             :     "OpenOffice.org-maximal-version";
      56             : 
      57           0 : OUString getLibreOfficeMajorMinorMicro() {
      58           0 :     return utl::ConfigManager::getAboutBoxProductVersion();
      59             : }
      60             : 
      61          34 : OUString getReferenceOpenOfficeOrgMajorMinor() {
      62             :     OUString v(
      63             :             "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
      64          34 :             ":Version:ReferenceOOoMajorMinor}");
      65          34 :     rtl::Bootstrap::expandMacros(v); //TODO: check for failure
      66          34 :     return v;
      67             : }
      68             : 
      69          34 : bool satisfiesMinimalVersion(
      70             :     OUString const & actual, OUString const & specified)
      71             : {
      72          34 :     return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
      73             : }
      74             : 
      75           0 : bool satisfiesMaximalVersion(
      76             :     OUString const & actual, OUString const & specified)
      77             : {
      78           0 :     return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
      79             : }
      80             : 
      81           0 : OUString produceErrorText(
      82             :     OUString const & reason, OUString const & version)
      83             : {
      84             :     return reason.replaceFirst("%VERSION",
      85           0 :         (version.isEmpty()
      86             :          ?  dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
      87           0 :          : version));
      88             : }
      89             : 
      90             : }
      91             : 
      92             : namespace dp_misc {
      93             : 
      94             : namespace Dependencies {
      95             : 
      96             : css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
      97          34 : check(dp_misc::DescriptionInfoset const & infoset) {
      98             :     css::uno::Reference< css::xml::dom::XNodeList > deps(
      99          34 :         infoset.getDependencies());
     100          34 :     sal_Int32 n = deps->getLength();
     101             :     css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
     102          34 :         unsatisfied(n);
     103          34 :     sal_Int32 unsat = 0;
     104          68 :     for (sal_Int32 i = 0; i < n; ++i) {
     105             :         css::uno::Reference< css::xml::dom::XElement > e(
     106          34 :             deps->item(i), css::uno::UNO_QUERY_THROW);
     107          34 :         bool sat = false;
     108          34 :         if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
     109             :         {
     110             :             sat = satisfiesMinimalVersion(
     111             :                 getReferenceOpenOfficeOrgMajorMinor(),
     112          34 :                 e->getAttribute("value"));
     113           0 :         } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
     114             :         {
     115             :             sat = satisfiesMaximalVersion(
     116             :                 getReferenceOpenOfficeOrgMajorMinor(),
     117           0 :                 e->getAttribute("value"));
     118           0 :         } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
     119             :         {
     120             :             sat = satisfiesMinimalVersion(
     121             :                 getLibreOfficeMajorMinorMicro(),
     122           0 :                 e->getAttribute("value"));
     123           0 :         } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
     124           0 :                        minimalVersionOpenOfficeOrg))
     125             :         {
     126             :             sat = satisfiesMinimalVersion(
     127             :                 getReferenceOpenOfficeOrgMajorMinor(),
     128           0 :                 e->getAttributeNS(namespaceOpenOfficeOrg,
     129           0 :                     minimalVersionOpenOfficeOrg));
     130             :         }
     131          34 :         if (!sat) {
     132           0 :             unsatisfied[unsat++] = e;
     133             :         }
     134          34 :     }
     135          34 :     unsatisfied.realloc(unsat);
     136          34 :     return unsatisfied;
     137             : }
     138             : 
     139           0 : OUString getErrorText(
     140             :     css::uno::Reference< css::xml::dom::XElement > const & dependency)
     141             : {
     142             :     OSL_ASSERT(dependency.is());
     143           0 :     if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
     144             :     {
     145             :         return produceErrorText(
     146             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     147           0 :             dependency->getAttribute("value"));
     148           0 :     } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
     149             :     {
     150             :         return produceErrorText(
     151             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
     152           0 :             dependency->getAttribute("value"));
     153           0 :     } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
     154             :     {
     155             :         return produceErrorText(
     156             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
     157           0 :             dependency->getAttribute("value"));
     158           0 :     } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
     159           0 :                    minimalVersionOpenOfficeOrg))
     160             :     {
     161             :         return produceErrorText(
     162             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     163           0 :             dependency->getAttributeNS(namespaceOpenOfficeOrg,
     164           0 :                 minimalVersionOpenOfficeOrg));
     165             :     } else {
     166           0 :         return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
     167             :     }
     168             : }
     169             : 
     170             : }
     171             : 
     172             : }
     173             : 
     174             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10