1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include "dp_properties.hxx"
29 namespace lang
= com::sun::star::lang
;
30 namespace ucb
= com::sun::star::ucb
;
31 namespace uno
= com::sun::star::uno
;
34 using ::com::sun::star::uno::Reference
;
36 constexpr OUStringLiteral PROP_SUPPRESS_LICENSE
= u
"SUPPRESS_LICENSE";
37 constexpr OUStringLiteral PROP_EXTENSION_UPDATE
= u
"EXTENSION_UPDATE";
39 namespace dp_manager
{
42 ExtensionProperties::ExtensionProperties(
43 std::u16string_view urlExtension
,
44 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
45 Reference
<uno::XComponentContext
> const & xContext
) :
46 m_xCmdEnv(xCmdEnv
), m_xContext(xContext
)
48 m_propFileUrl
= OUString::Concat(urlExtension
) + "properties";
50 std::vector
< std::pair
< OUString
, OUString
> > props
;
51 if (! dp_misc::create_ucb_content(nullptr, m_propFileUrl
, nullptr, false))
54 ::ucbhelper::Content
contentProps(m_propFileUrl
, m_xCmdEnv
, m_xContext
);
55 dp_misc::readProperties(props
, contentProps
);
57 for (auto const& prop
: props
)
59 if (prop
.first
== PROP_SUPPRESS_LICENSE
)
60 m_prop_suppress_license
= prop
.second
;
65 ExtensionProperties::ExtensionProperties(
66 std::u16string_view urlExtension
,
67 uno::Sequence
<css::beans::NamedValue
> const & properties
,
68 Reference
<ucb::XCommandEnvironment
> const & xCmdEnv
,
69 Reference
<uno::XComponentContext
> const & xContext
) :
70 m_xCmdEnv(xCmdEnv
), m_xContext(xContext
)
72 m_propFileUrl
= OUString::Concat(urlExtension
) + "properties";
74 for (css::beans::NamedValue
const & v
: properties
)
76 if (v
.Name
== PROP_SUPPRESS_LICENSE
)
78 m_prop_suppress_license
= getPropertyValue(v
);
80 else if (v
.Name
== PROP_EXTENSION_UPDATE
)
82 m_prop_extension_update
= getPropertyValue(v
);
86 throw lang::IllegalArgumentException(
87 "Extension Manager: unknown property", nullptr, -1);
92 OUString
ExtensionProperties::getPropertyValue(css::beans::NamedValue
const & v
)
95 if (! (v
.Value
>>= value
) )
97 throw lang::IllegalArgumentException(
98 "Extension Manager: wrong property value", nullptr, -1);
102 void ExtensionProperties::write()
104 ::ucbhelper::Content
contentProps(m_propFileUrl
, m_xCmdEnv
, m_xContext
);
107 if (m_prop_suppress_license
)
109 buf
= OUString::Concat(PROP_SUPPRESS_LICENSE
) + "=" + *m_prop_suppress_license
;
112 OString stamp
= OUStringToOString(buf
, RTL_TEXTENCODING_UTF8
);
113 Reference
<css::io::XInputStream
> xData(
114 ::xmlscript::createInputStream(
115 reinterpret_cast<sal_Int8
const *>(stamp
.getStr()),
116 stamp
.getLength() ) );
117 contentProps
.writeStream( xData
, true /* replace existing */ );
120 bool ExtensionProperties::isSuppressedLicense() const
123 if (m_prop_suppress_license
)
125 if (*m_prop_suppress_license
== "1")
131 bool ExtensionProperties::isExtensionUpdate() const
134 if (m_prop_extension_update
)
136 if (*m_prop_extension_update
== "1")
142 } // namespace dp_manager
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */