1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26
27 #include "sal/config.h"
28
29 #include "com/sun/star/uno/Reference.hxx"
30 #include "com/sun/star/uno/Sequence.hxx"
31 #include "com/sun/star/xml/dom/XElement.hpp"
32 #include "com/sun/star/xml/dom/XNode.hpp"
33 #include "com/sun/star/xml/dom/XNodeList.hpp"
34 #include "rtl/bootstrap.hxx"
35 #include "rtl/string.h"
36 #include "rtl/ustring.h"
37 #include "rtl/ustring.hxx"
38 #include "sal/types.h"
39 #include "tools/string.hxx"
40
41 #include "deployment.hrc"
42 #include "dp_resource.h"
43
44 #include "dp_dependencies.hxx"
45 #include "dp_descriptioninfoset.hxx"
46 #include "dp_version.hxx"
47
48 namespace {
49
50 namespace css = ::com::sun::star;
51
52 static char const xmlNamespace[] =
53 "http://openoffice.org/extensions/description/2006";
54
satisfiesMinimalVersion(::rtl::OUString const & version)55 bool satisfiesMinimalVersion(::rtl::OUString const & version) {
56 ::rtl::OUString v(
57 RTL_CONSTASCII_USTRINGPARAM(
58 "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version")
59 ":Version:OOOPackageVersion}"));
60 ::rtl::Bootstrap::expandMacros(v);
61 return ::dp_misc::compareVersions(v, version) != ::dp_misc::LESS;
62 }
63
64 }
65
66 namespace dp_misc {
67
68 namespace Dependencies {
69
70 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
check(::dp_misc::DescriptionInfoset const & infoset)71 check(::dp_misc::DescriptionInfoset const & infoset) {
72 css::uno::Reference< css::xml::dom::XNodeList > deps(
73 infoset.getDependencies());
74 ::sal_Int32 n = deps->getLength();
75 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
76 unsatisfied(n);
77 ::sal_Int32 unsat = 0;
78 for (::sal_Int32 i = 0; i < n; ++i) {
79 static char const minimalVersion[] = "OpenOffice.org-minimal-version";
80 css::uno::Reference< css::xml::dom::XElement > e(
81 deps->item(i), css::uno::UNO_QUERY_THROW);
82 bool sat = false;
83 if (e->getNamespaceURI().equalsAsciiL(
84 RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
85 && e->getTagName().equalsAsciiL(
86 RTL_CONSTASCII_STRINGPARAM(minimalVersion)))
87 {
88 sat = satisfiesMinimalVersion(
89 e->getAttribute(
90 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
91 } else if (e->getNamespaceURI().equalsAsciiL(
92 RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
93 && e->getTagName().equalsAsciiL(
94 RTL_CONSTASCII_STRINGPARAM(
95 "OpenOffice.org-maximal-version")))
96 {
97 ::rtl::OUString v(
98 RTL_CONSTASCII_USTRINGPARAM(
99 "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version")
100 ":Version:OOOBaseVersion}"));
101 ::rtl::Bootstrap::expandMacros(v);
102 sat =
103 ::dp_misc::compareVersions(
104 v,
105 e->getAttribute(
106 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))))
107 != ::dp_misc::GREATER;
108 } else if (e->hasAttributeNS(
109 ::rtl::OUString(
110 RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
111 ::rtl::OUString(
112 RTL_CONSTASCII_USTRINGPARAM(minimalVersion))))
113 {
114 sat = satisfiesMinimalVersion(
115 e->getAttributeNS(
116 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
117 ::rtl::OUString(
118 RTL_CONSTASCII_USTRINGPARAM(minimalVersion))));
119 }
120 if (!sat) {
121 unsatisfied[unsat++] = e;
122 }
123 }
124 unsatisfied.realloc(unsat);
125 return unsatisfied;
126 }
127
getErrorText(css::uno::Reference<css::xml::dom::XElement> const & dependency)128 ::rtl::OUString getErrorText( css::uno::Reference< css::xml::dom::XElement > const & dependency )
129 {
130 ::rtl::OUString sReason;
131 ::rtl::OUString sValue;
132 ::rtl::OUString sVersion(RTL_CONSTASCII_USTRINGPARAM("%VERSION"));
133
134 if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
135 && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-minimal-version" ) ) )
136 {
137 sValue = dependency->getAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "value" ) ) );
138 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
139 }
140 else if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
141 && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-maximal-version" ) ) )
142 {
143 sValue = dependency->getAttribute( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value") ) );
144 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MAX)) );
145 }
146 else if ( dependency->hasAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
147 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ))))
148 {
149 sValue = dependency->getAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
150 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ) ) );
151 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
152 }
153 else
154 return ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
155
156 if ( sValue.getLength() == 0 )
157 sValue = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
158
159 sal_Int32 nPos = sReason.indexOf( sVersion );
160 if ( nPos >= 0 )
161 sReason = sReason.replaceAt( nPos, sVersion.getLength(), sValue );
162 return sReason;
163 }
164
165 }
166
167 }
168