1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/diagnose.h>
29 #include <rtl/bootstrap.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 #include <unotools/configmgr.hxx>
34 #include <strings.hrc>
35 #include <dp_shared.hxx>
37 #include <dp_dependencies.hxx>
38 #include <dp_descriptioninfoset.hxx>
39 #include <dp_version.hxx>
43 char const namespaceLibreOffice
[] =
44 "http://libreoffice.org/extensions/description/2011";
46 constexpr OUStringLiteral namespaceOpenOfficeOrg
=
47 u
"http://openoffice.org/extensions/description/2006";
49 char const minimalVersionLibreOffice
[] = "LibreOffice-minimal-version";
50 char const maximalVersionLibreOffice
[] = "LibreOffice-maximal-version";
52 constexpr OUStringLiteral minimalVersionOpenOfficeOrg
=
53 u
"OpenOffice.org-minimal-version";
55 char const maximalVersionOpenOfficeOrg
[] =
56 "OpenOffice.org-maximal-version";
58 OUString
getLibreOfficeMajorMinorMicro() {
59 return utl::ConfigManager::getAboutBoxProductVersion();
62 OUString
getReferenceOpenOfficeOrgMajorMinor() {
64 // just hardcode the version
68 "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE("version")
69 ":Version:ReferenceOOoMajorMinor}");
70 rtl::Bootstrap::expandMacros(v
); //TODO: check for failure
75 bool satisfiesMinimalVersion(
76 std::u16string_view actual
, std::u16string_view specified
)
78 return dp_misc::compareVersions(actual
, specified
) != dp_misc::LESS
;
81 bool satisfiesMaximalVersion(
82 std::u16string_view actual
, std::u16string_view specified
)
84 return dp_misc::compareVersions(actual
, specified
) != dp_misc::GREATER
;
87 OUString
produceErrorText(
88 OUString
const & reason
, OUString
const & version
)
90 return reason
.replaceFirst("%VERSION",
92 ? DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN
)
98 namespace dp_misc::Dependencies
{
100 css::uno::Sequence
< css::uno::Reference
< css::xml::dom::XElement
> >
101 check(dp_misc::DescriptionInfoset
const & infoset
) {
102 css::uno::Reference
< css::xml::dom::XNodeList
> deps(
103 infoset
.getDependencies());
104 sal_Int32 n
= deps
->getLength();
105 css::uno::Sequence
< css::uno::Reference
< css::xml::dom::XElement
> >
107 auto unsatisfiedRange
= asNonConstRange(unsatisfied
);
109 // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
110 bool bIgnoreOoo
= false;
111 for (sal_Int32 i
= 0; i
< n
; ++i
) {
112 css::uno::Reference
< css::xml::dom::XElement
> e(
113 deps
->item(i
), css::uno::UNO_QUERY_THROW
);
114 if ( e
->getNamespaceURI() == namespaceLibreOffice
&& e
->getTagName() == minimalVersionLibreOffice
)
120 for (sal_Int32 i
= 0; i
< n
; ++i
) {
121 css::uno::Reference
< css::xml::dom::XElement
> e(
122 deps
->item(i
), css::uno::UNO_QUERY_THROW
);
124 if ( e
->getNamespaceURI() == namespaceOpenOfficeOrg
&& e
->getTagName() == minimalVersionOpenOfficeOrg
)
126 sat
= bIgnoreOoo
|| satisfiesMinimalVersion(
127 getReferenceOpenOfficeOrgMajorMinor(),
128 e
->getAttribute("value"));
129 } else if ( e
->getNamespaceURI() == namespaceOpenOfficeOrg
&& e
->getTagName() == maximalVersionOpenOfficeOrg
)
131 sat
= bIgnoreOoo
|| satisfiesMaximalVersion(
132 getReferenceOpenOfficeOrgMajorMinor(),
133 e
->getAttribute("value"));
134 } else if (e
->getNamespaceURI() == namespaceLibreOffice
&& e
->getTagName() == minimalVersionLibreOffice
)
136 sat
= satisfiesMinimalVersion(
137 getLibreOfficeMajorMinorMicro(),
138 e
->getAttribute("value"));
139 } else if (e
->getNamespaceURI() == namespaceLibreOffice
&& e
->getTagName() == maximalVersionLibreOffice
)
141 sat
= satisfiesMaximalVersion(getLibreOfficeMajorMinorMicro(), e
->getAttribute("value"));
142 } else if (e
->hasAttributeNS(namespaceOpenOfficeOrg
,
143 minimalVersionOpenOfficeOrg
))
145 sat
= satisfiesMinimalVersion(
146 getReferenceOpenOfficeOrgMajorMinor(),
147 e
->getAttributeNS(namespaceOpenOfficeOrg
,
148 minimalVersionOpenOfficeOrg
));
151 unsatisfiedRange
[unsat
++] = e
;
154 unsatisfied
.realloc(unsat
);
158 OUString
getErrorText(
159 css::uno::Reference
< css::xml::dom::XElement
> const & dependency
)
161 OSL_ASSERT(dependency
.is());
162 if ( dependency
->getNamespaceURI() == namespaceOpenOfficeOrg
&& dependency
->getTagName() == minimalVersionOpenOfficeOrg
)
164 return produceErrorText(
165 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN
),
166 dependency
->getAttribute("value"));
167 } else if (dependency
->getNamespaceURI() == namespaceOpenOfficeOrg
&& dependency
->getTagName() == maximalVersionOpenOfficeOrg
)
169 return produceErrorText(
170 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX
),
171 dependency
->getAttribute("value"));
172 } else if (dependency
->getNamespaceURI() == namespaceLibreOffice
&& dependency
->getTagName() == minimalVersionLibreOffice
)
174 return produceErrorText(
175 DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN
),
176 dependency
->getAttribute("value"));
177 } else if (dependency
->getNamespaceURI() == namespaceLibreOffice
&& dependency
->getTagName() == maximalVersionLibreOffice
)
179 return produceErrorText(
180 DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MAX
),
181 dependency
->getAttribute("value"));
182 } else if (dependency
->hasAttributeNS(namespaceOpenOfficeOrg
,
183 minimalVersionOpenOfficeOrg
))
185 return produceErrorText(
186 DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN
),
187 dependency
->getAttributeNS(namespaceOpenOfficeOrg
,
188 minimalVersionOpenOfficeOrg
));
190 return DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */