bump product version to 4.1.6.2
[LibreOffice.git] / desktop / source / deployment / manager / dp_properties.cxx
blobf45f42f7011f1c476c56f8fb1d4e340003b6ae5f
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 .
21 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
22 #include "com/sun/star/lang/IllegalArgumentException.hpp"
23 #include "xmlscript/xml_helper.hxx"
24 #include "ucbhelper/content.hxx"
25 #include <list>
27 #include "dp_ucb.h"
28 #include "rtl/ustrbuf.hxx"
29 #include "dp_properties.hxx"
31 namespace lang = com::sun::star::lang;
32 namespace ucb = com::sun::star::ucb;
33 namespace uno = com::sun::star::uno;
36 using ::com::sun::star::uno::Reference;
38 #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
39 #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
41 namespace dp_manager {
43 //Reading the file
44 ExtensionProperties::ExtensionProperties(
45 OUString const & urlExtension,
46 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
47 Reference<uno::XComponentContext> const & xContext) :
48 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
50 m_propFileUrl = urlExtension + "properties";
52 ::std::list< ::std::pair< OUString, OUString> > props;
53 if (! dp_misc::create_ucb_content(NULL, m_propFileUrl, 0, false))
54 return;
56 ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
57 dp_misc::readProperties(props, contentProps);
59 typedef ::std::list< ::std::pair< OUString, OUString> >::const_iterator CI;
60 for (CI i = props.begin(); i != props.end(); ++i)
62 if (i->first == PROP_SUPPRESS_LICENSE)
63 m_prop_suppress_license = i->second;
67 //Writing the file
68 ExtensionProperties::ExtensionProperties(
69 OUString const & urlExtension,
70 uno::Sequence<css::beans::NamedValue> const & properties,
71 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
72 Reference<uno::XComponentContext> const & xContext) :
73 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
75 m_propFileUrl = urlExtension + "properties";
77 for (sal_Int32 i = 0; i < properties.getLength(); i++)
79 css::beans::NamedValue const & v = properties[i];
80 if (v.Name == PROP_SUPPRESS_LICENSE)
82 m_prop_suppress_license = getPropertyValue(v);
84 else if (v.Name == PROP_EXTENSION_UPDATE)
86 m_prop_extension_update = getPropertyValue(v);
88 else
90 throw lang::IllegalArgumentException(
91 "Extension Manager: unknown property", 0, -1);
96 OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
98 OUString value("0");
99 if (! (v.Value >>= value) )
101 throw lang::IllegalArgumentException(
102 "Extension Manager: wrong property value", 0, -1);
104 return value;
106 void ExtensionProperties::write()
108 ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
109 OUStringBuffer buf;
111 if (m_prop_suppress_license)
113 buf.append(PROP_SUPPRESS_LICENSE);
114 buf.append("=");
115 buf.append(*m_prop_suppress_license);
118 OString stamp = OUStringToOString(
119 buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
120 Reference<css::io::XInputStream> xData(
121 ::xmlscript::createInputStream(
122 ::rtl::ByteSequence(
123 reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
124 stamp.getLength() ) ) );
125 contentProps.writeStream( xData, true /* replace existing */ );
128 bool ExtensionProperties::isSuppressedLicense()
130 bool ret = false;
131 if (m_prop_suppress_license)
133 if (*m_prop_suppress_license == "1")
134 ret = true;
136 return ret;
139 bool ExtensionProperties::isExtensionUpdate()
141 bool ret = false;
142 if (m_prop_extension_update)
144 if (*m_prop_extension_update == "1")
145 ret = true;
147 return ret;
150 } // namespace dp_manager
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */