Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / misc / dp_dependencies.cxx
blob49b64780ec04225bb089a04bc5a979ced7429710
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_folders.h>
22 #include <sal/config.h>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/xml/dom/XElement.hpp>
27 #include <com/sun/star/xml/dom/XNodeList.hpp>
28 #include <rtl/bootstrap.hxx>
29 #include <rtl/string.h>
30 #include <rtl/ustring.h>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
33 #include <unotools/configmgr.hxx>
35 #include <strings.hrc>
36 #include <dp_resource.h>
37 #include <dp_shared.hxx>
39 #include <dp_dependencies.hxx>
40 #include <dp_descriptioninfoset.hxx>
41 #include <dp_version.hxx>
43 namespace {
45 static char const namespaceLibreOffice[] =
46 "http://libreoffice.org/extensions/description/2011";
48 static char const namespaceOpenOfficeOrg[] =
49 "http://openoffice.org/extensions/description/2006";
51 static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
53 static char const minimalVersionOpenOfficeOrg[] =
54 "OpenOffice.org-minimal-version";
56 static char const maximalVersionOpenOfficeOrg[] =
57 "OpenOffice.org-maximal-version";
59 OUString getLibreOfficeMajorMinorMicro() {
60 return utl::ConfigManager::getAboutBoxProductVersion();
63 OUString getReferenceOpenOfficeOrgMajorMinor() {
64 OUString v(
65 "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
66 ":Version:ReferenceOOoMajorMinor}");
67 rtl::Bootstrap::expandMacros(v); //TODO: check for failure
68 return v;
71 bool satisfiesMinimalVersion(
72 OUString const & actual, OUString const & specified)
74 return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
77 bool satisfiesMaximalVersion(
78 OUString const & actual, OUString const & specified)
80 return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
83 OUString produceErrorText(
84 OUString const & reason, OUString const & version)
86 return reason.replaceFirst("%VERSION",
87 (version.isEmpty()
88 ? DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN)
89 : version));
94 namespace dp_misc {
96 namespace Dependencies {
98 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
99 check(dp_misc::DescriptionInfoset const & infoset) {
100 css::uno::Reference< css::xml::dom::XNodeList > deps(
101 infoset.getDependencies());
102 sal_Int32 n = deps->getLength();
103 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
104 unsatisfied(n);
105 sal_Int32 unsat = 0;
106 // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
107 bool bIgnoreOoo = false;
108 for (sal_Int32 i = 0; i < n; ++i) {
109 css::uno::Reference< css::xml::dom::XElement > e(
110 deps->item(i), css::uno::UNO_QUERY_THROW);
111 if ( e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice)
113 bIgnoreOoo = true;
114 break;
117 for (sal_Int32 i = 0; i < n; ++i) {
118 css::uno::Reference< css::xml::dom::XElement > e(
119 deps->item(i), css::uno::UNO_QUERY_THROW);
120 bool sat = false;
121 if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
123 sat = bIgnoreOoo || satisfiesMinimalVersion(
124 getReferenceOpenOfficeOrgMajorMinor(),
125 e->getAttribute("value"));
126 } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
128 sat = bIgnoreOoo || satisfiesMaximalVersion(
129 getReferenceOpenOfficeOrgMajorMinor(),
130 e->getAttribute("value"));
131 } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
133 sat = satisfiesMinimalVersion(
134 getLibreOfficeMajorMinorMicro(),
135 e->getAttribute("value"));
136 } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
137 minimalVersionOpenOfficeOrg))
139 sat = satisfiesMinimalVersion(
140 getReferenceOpenOfficeOrgMajorMinor(),
141 e->getAttributeNS(namespaceOpenOfficeOrg,
142 minimalVersionOpenOfficeOrg));
144 if (!sat) {
145 unsatisfied[unsat++] = e;
148 unsatisfied.realloc(unsat);
149 return unsatisfied;
152 OUString getErrorText(
153 css::uno::Reference< css::xml::dom::XElement > const & dependency)
155 OSL_ASSERT(dependency.is());
156 if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
158 return produceErrorText(
159 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
160 dependency->getAttribute("value"));
161 } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
163 return produceErrorText(
164 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX),
165 dependency->getAttribute("value"));
166 } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
168 return produceErrorText(
169 DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN),
170 dependency->getAttribute("value"));
171 } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
172 minimalVersionOpenOfficeOrg))
174 return produceErrorText(
175 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
176 dependency->getAttributeNS(namespaceOpenOfficeOrg,
177 minimalVersionOpenOfficeOrg));
178 } else {
179 return DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */