1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sal/config.h"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
34*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
35*cdf0e10cSrcweir #include "com/sun/star/xml/dom/XElement.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/xml/dom/XNode.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/xml/dom/XNodeList.hpp"
38*cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
39*cdf0e10cSrcweir #include "rtl/string.h"
40*cdf0e10cSrcweir #include "rtl/ustring.h"
41*cdf0e10cSrcweir #include "rtl/ustring.hxx"
42*cdf0e10cSrcweir #include "sal/types.h"
43*cdf0e10cSrcweir #include "tools/string.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "deployment.hrc"
46*cdf0e10cSrcweir #include "dp_resource.h"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include "dp_dependencies.hxx"
49*cdf0e10cSrcweir #include "dp_descriptioninfoset.hxx"
50*cdf0e10cSrcweir #include "dp_version.hxx"
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir namespace {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace css = ::com::sun::star;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir static char const xmlNamespace[] =
57*cdf0e10cSrcweir     "http://openoffice.org/extensions/description/2006";
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir bool satisfiesMinimalVersion(::rtl::OUString const & version) {
60*cdf0e10cSrcweir     ::rtl::OUString v(
61*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
62*cdf0e10cSrcweir             "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version")
63*cdf0e10cSrcweir             ":Version:OOOPackageVersion}"));
64*cdf0e10cSrcweir     ::rtl::Bootstrap::expandMacros(v);
65*cdf0e10cSrcweir     return ::dp_misc::compareVersions(v, version) != ::dp_misc::LESS;
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir namespace dp_misc {
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir namespace Dependencies {
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
75*cdf0e10cSrcweir check(::dp_misc::DescriptionInfoset const & infoset) {
76*cdf0e10cSrcweir     css::uno::Reference< css::xml::dom::XNodeList > deps(
77*cdf0e10cSrcweir         infoset.getDependencies());
78*cdf0e10cSrcweir     ::sal_Int32 n = deps->getLength();
79*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
80*cdf0e10cSrcweir         unsatisfied(n);
81*cdf0e10cSrcweir     ::sal_Int32 unsat = 0;
82*cdf0e10cSrcweir     for (::sal_Int32 i = 0; i < n; ++i) {
83*cdf0e10cSrcweir         static char const minimalVersion[] = "OpenOffice.org-minimal-version";
84*cdf0e10cSrcweir         css::uno::Reference< css::xml::dom::XElement > e(
85*cdf0e10cSrcweir             deps->item(i), css::uno::UNO_QUERY_THROW);
86*cdf0e10cSrcweir         bool sat = false;
87*cdf0e10cSrcweir         if (e->getNamespaceURI().equalsAsciiL(
88*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
89*cdf0e10cSrcweir             && e->getTagName().equalsAsciiL(
90*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM(minimalVersion)))
91*cdf0e10cSrcweir         {
92*cdf0e10cSrcweir             sat = satisfiesMinimalVersion(
93*cdf0e10cSrcweir                 e->getAttribute(
94*cdf0e10cSrcweir                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
95*cdf0e10cSrcweir         } else if (e->getNamespaceURI().equalsAsciiL(
96*cdf0e10cSrcweir                        RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
97*cdf0e10cSrcweir                    && e->getTagName().equalsAsciiL(
98*cdf0e10cSrcweir                        RTL_CONSTASCII_STRINGPARAM(
99*cdf0e10cSrcweir                            "OpenOffice.org-maximal-version")))
100*cdf0e10cSrcweir         {
101*cdf0e10cSrcweir             ::rtl::OUString v(
102*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
103*cdf0e10cSrcweir                     "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version")
104*cdf0e10cSrcweir                     ":Version:OOOBaseVersion}"));
105*cdf0e10cSrcweir             ::rtl::Bootstrap::expandMacros(v);
106*cdf0e10cSrcweir             sat =
107*cdf0e10cSrcweir                 ::dp_misc::compareVersions(
108*cdf0e10cSrcweir                     v,
109*cdf0e10cSrcweir                     e->getAttribute(
110*cdf0e10cSrcweir                         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))))
111*cdf0e10cSrcweir                 != ::dp_misc::GREATER;
112*cdf0e10cSrcweir         } else if (e->hasAttributeNS(
113*cdf0e10cSrcweir                        ::rtl::OUString(
114*cdf0e10cSrcweir                            RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
115*cdf0e10cSrcweir                        ::rtl::OUString(
116*cdf0e10cSrcweir                            RTL_CONSTASCII_USTRINGPARAM(minimalVersion))))
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             sat = satisfiesMinimalVersion(
119*cdf0e10cSrcweir                 e->getAttributeNS(
120*cdf0e10cSrcweir                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
121*cdf0e10cSrcweir                     ::rtl::OUString(
122*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(minimalVersion))));
123*cdf0e10cSrcweir         }
124*cdf0e10cSrcweir         if (!sat) {
125*cdf0e10cSrcweir             unsatisfied[unsat++] = e;
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     unsatisfied.realloc(unsat);
129*cdf0e10cSrcweir     return unsatisfied;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir ::rtl::OUString getErrorText( css::uno::Reference< css::xml::dom::XElement > const & dependency )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     ::rtl::OUString sReason;
135*cdf0e10cSrcweir     ::rtl::OUString sValue;
136*cdf0e10cSrcweir     ::rtl::OUString sVersion(RTL_CONSTASCII_USTRINGPARAM("%VERSION"));
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
139*cdf0e10cSrcweir          && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-minimal-version" ) ) )
140*cdf0e10cSrcweir     {
141*cdf0e10cSrcweir         sValue = dependency->getAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "value" ) ) );
142*cdf0e10cSrcweir         sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
143*cdf0e10cSrcweir     }
144*cdf0e10cSrcweir     else if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
145*cdf0e10cSrcweir               && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-maximal-version" ) ) )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         sValue = dependency->getAttribute( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value") ) );
148*cdf0e10cSrcweir         sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MAX)) );
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir     else if ( dependency->hasAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
151*cdf0e10cSrcweir                                           ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ))))
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         sValue = dependency->getAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
154*cdf0e10cSrcweir                                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ) ) );
155*cdf0e10cSrcweir         sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir     else
158*cdf0e10cSrcweir         return ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     if ( sValue.getLength() == 0 )
161*cdf0e10cSrcweir         sValue = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     sal_Int32 nPos = sReason.indexOf( sVersion );
164*cdf0e10cSrcweir     if ( nPos >= 0 )
165*cdf0e10cSrcweir         sReason = sReason.replaceAt( nPos, sVersion.getLength(), sValue );
166*cdf0e10cSrcweir     return sReason;
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir }
172