xref: /AOO41X/main/desktop/source/deployment/manager/dp_properties.cxx (revision 2722ceddc26af33ca9ed6a22fc3c4dfb805171c3)
1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2722ceddSAndrew Rist  * distributed with this work for additional information
6*2722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist  * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2722ceddSAndrew Rist  * specific language governing permissions and limitations
18*2722ceddSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2722ceddSAndrew Rist  *************************************************************/
21*2722ceddSAndrew Rist 
22*2722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
28cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
29cdf0e10cSrcweir #include "xmlscript/xml_helper.hxx"
30cdf0e10cSrcweir #include "ucbhelper/content.hxx"
31cdf0e10cSrcweir #include <list>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "dp_ucb.h"
34cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
35cdf0e10cSrcweir #include "dp_properties.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace lang  = com::sun::star::lang;
38cdf0e10cSrcweir namespace task = com::sun::star::task;
39cdf0e10cSrcweir namespace ucb = com::sun::star::ucb;
40cdf0e10cSrcweir namespace uno = com::sun::star::uno;
41cdf0e10cSrcweir namespace css = com::sun::star;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
46cdf0e10cSrcweir using ::rtl::OUString;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
49cdf0e10cSrcweir #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace dp_manager {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //Reading the file
ExtensionProperties(OUString const & urlExtension,Reference<ucb::XCommandEnvironment> const & xCmdEnv)54cdf0e10cSrcweir ExtensionProperties::ExtensionProperties(
55cdf0e10cSrcweir     OUString const & urlExtension,
56cdf0e10cSrcweir     Reference<ucb::XCommandEnvironment> const & xCmdEnv) :
57cdf0e10cSrcweir     m_xCmdEnv(xCmdEnv)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     m_propFileUrl = urlExtension + OUSTR("properties");
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     ::std::list< ::std::pair< OUString, OUString> > props;
62cdf0e10cSrcweir     if (! dp_misc::create_ucb_content(NULL, m_propFileUrl, 0, false))
63cdf0e10cSrcweir         return;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv);
66cdf0e10cSrcweir     dp_misc::readProperties(props, contentProps);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     typedef ::std::list< ::std::pair< OUString, OUString> >::const_iterator CI;
69cdf0e10cSrcweir     for (CI i = props.begin(); i != props.end(); i++)
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         if (i->first.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
72cdf0e10cSrcweir             m_prop_suppress_license = i->second;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //Writing the file
ExtensionProperties(OUString const & urlExtension,uno::Sequence<css::beans::NamedValue> const & properties,Reference<ucb::XCommandEnvironment> const & xCmdEnv)77cdf0e10cSrcweir ExtensionProperties::ExtensionProperties(
78cdf0e10cSrcweir     OUString const & urlExtension,
79cdf0e10cSrcweir     uno::Sequence<css::beans::NamedValue> const & properties,
80cdf0e10cSrcweir     Reference<ucb::XCommandEnvironment> const & xCmdEnv) :
81cdf0e10cSrcweir     m_xCmdEnv(xCmdEnv)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     m_propFileUrl = urlExtension + OUSTR("properties");
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     for (sal_Int32 i = 0; i < properties.getLength(); i++)
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         css::beans::NamedValue const & v = properties[i];
88cdf0e10cSrcweir         if (v.Name.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
89cdf0e10cSrcweir         {
90cdf0e10cSrcweir             m_prop_suppress_license = getPropertyValue(v);
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir         else if (v.Name.equals(OUSTR(PROP_EXTENSION_UPDATE)))
93cdf0e10cSrcweir         {
94cdf0e10cSrcweir             m_prop_extension_update = getPropertyValue(v);
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir         else
97cdf0e10cSrcweir         {
98cdf0e10cSrcweir             throw lang::IllegalArgumentException(
99cdf0e10cSrcweir                 OUSTR("Extension Manager: unknown property"), 0, -1);
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
getPropertyValue(css::beans::NamedValue const & v)104cdf0e10cSrcweir OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     OUString value(OUSTR("0"));
107cdf0e10cSrcweir     if (v.Value >>= value)
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         if (value.equals(OUSTR("1")))
110cdf0e10cSrcweir             value = OUSTR("1");
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir     else
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         throw lang::IllegalArgumentException(
115cdf0e10cSrcweir             OUSTR("Extension Manager: wrong property value"), 0, -1);
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     return value;
118cdf0e10cSrcweir }
write()119cdf0e10cSrcweir void ExtensionProperties::write()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv);
122cdf0e10cSrcweir     ::rtl::OUStringBuffer buf;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     if (m_prop_suppress_license)
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         buf.append(OUSTR(PROP_SUPPRESS_LICENSE));
127cdf0e10cSrcweir         buf.append(OUSTR("="));
128cdf0e10cSrcweir         buf.append(*m_prop_suppress_license);
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     ::rtl::OString stamp = ::rtl::OUStringToOString(
132cdf0e10cSrcweir         buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
133cdf0e10cSrcweir     Reference<css::io::XInputStream> xData(
134cdf0e10cSrcweir         ::xmlscript::createInputStream(
135cdf0e10cSrcweir             ::rtl::ByteSequence(
136cdf0e10cSrcweir                 reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
137cdf0e10cSrcweir                 stamp.getLength() ) ) );
138cdf0e10cSrcweir     contentProps.writeStream( xData, true /* replace existing */ );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
isSuppressedLicense()141cdf0e10cSrcweir bool ExtensionProperties::isSuppressedLicense()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     bool ret = false;
144cdf0e10cSrcweir     if (m_prop_suppress_license)
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         if (m_prop_suppress_license->equals(OUSTR("1")))
147cdf0e10cSrcweir             ret = true;
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     return ret;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
isExtensionUpdate()152cdf0e10cSrcweir bool ExtensionProperties::isExtensionUpdate()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     bool ret = false;
155cdf0e10cSrcweir     if (m_prop_extension_update)
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         if (m_prop_extension_update->equals(OUSTR("1")))
158cdf0e10cSrcweir             ret = true;
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir     return ret;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir } // namespace dp_manager
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
166