LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/deployment/misc - dp_dependencies.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 54 0.0 %
Date: 2012-12-17 Functions: 0 7 0.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             : 
      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 : rtl::OUString getLibreOfficeMajorMinorMicro() {
      58           0 :     return utl::ConfigManager::getAboutBoxProductVersion();
      59             : }
      60             : 
      61           0 : rtl::OUString getReferenceOpenOfficeOrgMajorMinor() {
      62             :     rtl::OUString v(
      63             :         RTL_CONSTASCII_USTRINGPARAM(
      64             :             "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
      65           0 :             ":Version:ReferenceOOoMajorMinor}"));
      66           0 :     rtl::Bootstrap::expandMacros(v); //TODO: check for failure
      67           0 :     return v;
      68             : }
      69             : 
      70           0 : bool satisfiesMinimalVersion(
      71             :     rtl::OUString const & actual, rtl::OUString const & specified)
      72             : {
      73           0 :     return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
      74             : }
      75             : 
      76           0 : bool satisfiesMaximalVersion(
      77             :     rtl::OUString const & actual, rtl::OUString const & specified)
      78             : {
      79           0 :     return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
      80             : }
      81             : 
      82           0 : rtl::OUString produceErrorText(
      83             :     rtl::OUString const & reason, rtl::OUString const & version)
      84             : {
      85             :     return reason.replaceFirst("%VERSION",
      86           0 :         (version.isEmpty()
      87             :          ?  dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
      88           0 :          : version));
      89             : }
      90             : 
      91             : }
      92             : 
      93             : namespace dp_misc {
      94             : 
      95             : namespace Dependencies {
      96             : 
      97             : css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
      98           0 : check(dp_misc::DescriptionInfoset const & infoset) {
      99             :     css::uno::Reference< css::xml::dom::XNodeList > deps(
     100           0 :         infoset.getDependencies());
     101           0 :     sal_Int32 n = deps->getLength();
     102             :     css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
     103           0 :         unsatisfied(n);
     104           0 :     sal_Int32 unsat = 0;
     105           0 :     for (sal_Int32 i = 0; i < n; ++i) {
     106             :         css::uno::Reference< css::xml::dom::XElement > e(
     107           0 :             deps->item(i), css::uno::UNO_QUERY_THROW);
     108           0 :         bool sat = false;
     109           0 :         if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
     110             :         {
     111             :             sat = satisfiesMinimalVersion(
     112             :                 getReferenceOpenOfficeOrgMajorMinor(),
     113           0 :                 e->getAttribute(
     114           0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     115           0 :         } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
     116             :         {
     117             :             sat = satisfiesMaximalVersion(
     118             :                 getReferenceOpenOfficeOrgMajorMinor(),
     119           0 :                 e->getAttribute(
     120           0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     121           0 :         } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
     122             :         {
     123             :             sat = satisfiesMinimalVersion(
     124             :                 getLibreOfficeMajorMinorMicro(),
     125           0 :                 e->getAttribute(
     126           0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     127           0 :         } else if (e->hasAttributeNS(
     128             :                        rtl::OUString(
     129             :                            RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     130             :                        rtl::OUString(
     131             :                            RTL_CONSTASCII_USTRINGPARAM(
     132           0 :                                minimalVersionOpenOfficeOrg))))
     133             :         {
     134             :             sat = satisfiesMinimalVersion(
     135             :                 getReferenceOpenOfficeOrgMajorMinor(),
     136           0 :                 e->getAttributeNS(
     137             :                     rtl::OUString(
     138             :                         RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     139             :                     rtl::OUString(
     140             :                         RTL_CONSTASCII_USTRINGPARAM(
     141           0 :                             minimalVersionOpenOfficeOrg))));
     142             :         }
     143           0 :         if (!sat) {
     144           0 :             unsatisfied[unsat++] = e;
     145             :         }
     146           0 :     }
     147           0 :     unsatisfied.realloc(unsat);
     148           0 :     return unsatisfied;
     149             : }
     150             : 
     151           0 : rtl::OUString getErrorText(
     152             :     css::uno::Reference< css::xml::dom::XElement > const & dependency)
     153             : {
     154             :     OSL_ASSERT(dependency.is());
     155           0 :     if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
     156             :     {
     157             :         return produceErrorText(
     158             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     159           0 :             dependency->getAttribute(
     160           0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     161           0 :     } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
     162             :     {
     163             :         return produceErrorText(
     164             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
     165           0 :             dependency->getAttribute(
     166           0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     167           0 :     } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
     168             :     {
     169             :         return produceErrorText(
     170             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
     171           0 :             dependency->getAttribute(
     172           0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
     173           0 :     } else if (dependency->hasAttributeNS(
     174             :                    rtl::OUString(
     175             :                        RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     176             :                    rtl::OUString(
     177             :                        RTL_CONSTASCII_USTRINGPARAM(
     178           0 :                            minimalVersionOpenOfficeOrg))))
     179             :     {
     180             :         return produceErrorText(
     181             :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     182           0 :             dependency->getAttributeNS(
     183             :                 rtl::OUString(
     184             :                     RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     185             :                 rtl::OUString(
     186           0 :                     RTL_CONSTASCII_USTRINGPARAM(minimalVersionOpenOfficeOrg))));
     187             :     } else {
     188           0 :         return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
     189             :     }
     190             : }
     191             : 
     192             : }
     193             : 
     194             : }
     195             : 
     196             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10