LibreOffice Module desktop (master)  1
dp_properties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
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 
26 #include <dp_ucb.h>
27 #include <rtl/ustrbuf.hxx>
28 #include "dp_properties.hxx"
29 
30 namespace lang = com::sun::star::lang;
31 namespace ucb = com::sun::star::ucb;
32 namespace uno = com::sun::star::uno;
33 
34 
35 using ::com::sun::star::uno::Reference;
36 
37 #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
38 #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
39 
40 namespace dp_manager {
41 
42 //Reading the file
44  OUString const & urlExtension,
45  Reference<ucb::XCommandEnvironment> const & xCmdEnv,
47  m_xCmdEnv(xCmdEnv), m_xContext(xContext)
48 {
49  m_propFileUrl = urlExtension + "properties";
50 
51  std::vector< std::pair< OUString, OUString> > props;
52  if (! dp_misc::create_ucb_content(nullptr, m_propFileUrl, nullptr, false))
53  return;
54 
55  ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
56  dp_misc::readProperties(props, contentProps);
57 
58  for (auto const& prop : props)
59  {
60  if (prop.first == PROP_SUPPRESS_LICENSE)
61  m_prop_suppress_license = prop.second;
62  }
63 }
64 
65 //Writing the file
67  OUString const & urlExtension,
68  uno::Sequence<css::beans::NamedValue> const & properties,
69  Reference<ucb::XCommandEnvironment> const & xCmdEnv,
70  Reference<uno::XComponentContext> const & xContext) :
71  m_xCmdEnv(xCmdEnv), m_xContext(xContext)
72 {
73  m_propFileUrl = urlExtension + "properties";
74 
75  for (css::beans::NamedValue const & v : properties)
76  {
77  if (v.Name == PROP_SUPPRESS_LICENSE)
78  {
79  m_prop_suppress_license = getPropertyValue(v);
80  }
81  else if (v.Name == PROP_EXTENSION_UPDATE)
82  {
83  m_prop_extension_update = getPropertyValue(v);
84  }
85  else
86  {
87  throw lang::IllegalArgumentException(
88  "Extension Manager: unknown property", nullptr, -1);
89  }
90  }
91 }
92 
93 OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
94 {
95  OUString value("0");
96  if (! (v.Value >>= value) )
97  {
98  throw lang::IllegalArgumentException(
99  "Extension Manager: wrong property value", nullptr, -1);
100  }
101  return value;
102 }
104 {
106  OUStringBuffer buf;
107 
109  {
110  buf.append(PROP_SUPPRESS_LICENSE);
111  buf.append("=");
112  buf.append(*m_prop_suppress_license);
113  }
114 
115  OString stamp = OUStringToOString(
116  buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
117  Reference<css::io::XInputStream> xData(
119  reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
120  stamp.getLength() ) );
121  contentProps.writeStream( xData, true /* replace existing */ );
122 }
123 
125 {
126  bool ret = false;
128  {
129  if (*m_prop_suppress_license == "1")
130  ret = true;
131  }
132  return ret;
133 }
134 
136 {
137  bool ret = false;
139  {
140  if (*m_prop_extension_update == "1")
141  ret = true;
142  }
143  return ret;
144 }
145 
146 } // namespace dp_manager
147 
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool readProperties(std::vector< std::pair< OUString, OUString > > &out_result,::ucbhelper::Content &ucb_content)
Definition: dp_ucb.cxx:258
static OUString getPropertyValue(css::beans::NamedValue const &v)
const css::uno::Reference< css::uno::XComponentContext > m_xContext
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
::std::optional< OUString > m_prop_suppress_license
#define PROP_EXTENSION_UPDATE
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > const &rInData)
ExtensionProperties(OUString const &urlExtension, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, css::uno::Reference< css::uno::XComponentContext > const &xContext)
dictionary props
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_ucb_content(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
float v
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2178
const css::uno::Reference< css::ucb::XCommandEnvironment > m_xCmdEnv
Any value
#define PROP_SUPPRESS_LICENSE
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
::std::optional< OUString > m_prop_extension_update
uno::Reference< uno::XComponentContext > m_xContext