bump product version to 4.1.6.2
[LibreOffice.git] / desktop / source / deployment / misc / dp_dependencies.cxx
blob4b50f844f7c26a4747ed02ec73502ade99816bea
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 "sal/config.h"
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"
34 #include "deployment.hrc"
35 #include "dp_resource.h"
37 #include "dp_dependencies.hxx"
38 #include "dp_descriptioninfoset.hxx"
39 #include "dp_version.hxx"
41 namespace {
43 static char const namespaceLibreOffice[] =
44 "http://libreoffice.org/extensions/description/2011";
46 static char const namespaceOpenOfficeOrg[] =
47 "http://openoffice.org/extensions/description/2006";
49 static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
51 static char const minimalVersionOpenOfficeOrg[] =
52 "OpenOffice.org-minimal-version";
54 static char const maximalVersionOpenOfficeOrg[] =
55 "OpenOffice.org-maximal-version";
57 OUString getLibreOfficeMajorMinorMicro() {
58 return utl::ConfigManager::getAboutBoxProductVersion();
61 OUString getReferenceOpenOfficeOrgMajorMinor() {
62 OUString v(
63 "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
64 ":Version:ReferenceOOoMajorMinor}");
65 rtl::Bootstrap::expandMacros(v); //TODO: check for failure
66 return v;
69 bool satisfiesMinimalVersion(
70 OUString const & actual, OUString const & specified)
72 return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
75 bool satisfiesMaximalVersion(
76 OUString const & actual, OUString const & specified)
78 return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
81 OUString produceErrorText(
82 OUString const & reason, OUString const & version)
84 return reason.replaceFirst("%VERSION",
85 (version.isEmpty()
86 ? dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
87 : version));
92 namespace dp_misc {
94 namespace Dependencies {
96 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
97 check(dp_misc::DescriptionInfoset const & infoset) {
98 css::uno::Reference< css::xml::dom::XNodeList > deps(
99 infoset.getDependencies());
100 sal_Int32 n = deps->getLength();
101 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
102 unsatisfied(n);
103 sal_Int32 unsat = 0;
104 for (sal_Int32 i = 0; i < n; ++i) {
105 css::uno::Reference< css::xml::dom::XElement > e(
106 deps->item(i), css::uno::UNO_QUERY_THROW);
107 bool sat = false;
108 if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
110 sat = satisfiesMinimalVersion(
111 getReferenceOpenOfficeOrgMajorMinor(),
112 e->getAttribute("value"));
113 } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
115 sat = satisfiesMaximalVersion(
116 getReferenceOpenOfficeOrgMajorMinor(),
117 e->getAttribute("value"));
118 } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
120 sat = satisfiesMinimalVersion(
121 getLibreOfficeMajorMinorMicro(),
122 e->getAttribute("value"));
123 } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
124 minimalVersionOpenOfficeOrg))
126 sat = satisfiesMinimalVersion(
127 getReferenceOpenOfficeOrgMajorMinor(),
128 e->getAttributeNS(namespaceOpenOfficeOrg,
129 minimalVersionOpenOfficeOrg));
131 if (!sat) {
132 unsatisfied[unsat++] = e;
135 unsatisfied.realloc(unsat);
136 return unsatisfied;
139 OUString getErrorText(
140 css::uno::Reference< css::xml::dom::XElement > const & dependency)
142 OSL_ASSERT(dependency.is());
143 if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
145 return produceErrorText(
146 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
147 dependency->getAttribute("value"));
148 } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
150 return produceErrorText(
151 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
152 dependency->getAttribute("value"));
153 } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
155 return produceErrorText(
156 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
157 dependency->getAttribute("value"));
158 } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
159 minimalVersionOpenOfficeOrg))
161 return produceErrorText(
162 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
163 dependency->getAttributeNS(namespaceOpenOfficeOrg,
164 minimalVersionOpenOfficeOrg));
165 } else {
166 return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */