Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "com/sun/star/ucb/XCommandEnvironment.hpp"
31 : : #include "com/sun/star/lang/IllegalArgumentException.hpp"
32 : : #include "xmlscript/xml_helper.hxx"
33 : : #include "ucbhelper/content.hxx"
34 : : #include <list>
35 : :
36 : : #include "dp_ucb.h"
37 : : #include "rtl/ustrbuf.hxx"
38 : : #include "dp_properties.hxx"
39 : :
40 : : namespace lang = com::sun::star::lang;
41 : : namespace ucb = com::sun::star::ucb;
42 : : namespace uno = com::sun::star::uno;
43 : : namespace css = com::sun::star;
44 : :
45 : : #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
46 : :
47 : : using ::com::sun::star::uno::Reference;
48 : : using ::rtl::OUString;
49 : :
50 : : #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
51 : : #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
52 : :
53 : : namespace dp_manager {
54 : :
55 : : //Reading the file
56 : 496 : ExtensionProperties::ExtensionProperties(
57 : : OUString const & urlExtension,
58 : : Reference<ucb::XCommandEnvironment> const & xCmdEnv) :
59 [ + - ][ + - ]: 496 : m_xCmdEnv(xCmdEnv)
60 : : {
61 [ + - ]: 496 : m_propFileUrl = urlExtension + OUSTR("properties");
62 : :
63 [ + - ]: 496 : ::std::list< ::std::pair< OUString, OUString> > props;
64 [ + - ][ + - ]: 496 : if (! dp_misc::create_ucb_content(NULL, m_propFileUrl, 0, false))
[ + - ]
65 : 496 : return;
66 : :
67 [ # # ]: 0 : ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv);
68 [ # # ]: 0 : dp_misc::readProperties(props, contentProps);
69 : :
70 : : typedef ::std::list< ::std::pair< OUString, OUString> >::const_iterator CI;
71 [ # # ]: 0 : for (CI i = props.begin(); i != props.end(); ++i)
72 : : {
73 [ # # ][ # # ]: 0 : if (i->first.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
74 [ # # ]: 0 : m_prop_suppress_license = i->second;
75 [ # # ][ - + ]: 496 : }
76 : : }
77 : :
78 : : //Writing the file
79 : 8 : ExtensionProperties::ExtensionProperties(
80 : : OUString const & urlExtension,
81 : : uno::Sequence<css::beans::NamedValue> const & properties,
82 : : Reference<ucb::XCommandEnvironment> const & xCmdEnv) :
83 [ + - ][ + - ]: 8 : m_xCmdEnv(xCmdEnv)
84 : : {
85 [ + - ]: 8 : m_propFileUrl = urlExtension + OUSTR("properties");
86 : :
87 [ - + ]: 8 : for (sal_Int32 i = 0; i < properties.getLength(); i++)
88 : : {
89 : 0 : css::beans::NamedValue const & v = properties[i];
90 [ # # ][ # # ]: 0 : if (v.Name.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
91 : : {
92 [ # # ][ # # ]: 0 : m_prop_suppress_license = getPropertyValue(v);
93 : : }
94 [ # # ][ # # ]: 0 : else if (v.Name.equals(OUSTR(PROP_EXTENSION_UPDATE)))
95 : : {
96 [ # # ][ # # ]: 0 : m_prop_extension_update = getPropertyValue(v);
97 : : }
98 : : else
99 : : {
100 : : throw lang::IllegalArgumentException(
101 [ # # ][ # # ]: 0 : OUSTR("Extension Manager: unknown property"), 0, -1);
[ # # ]
102 : : }
103 : : }
104 : 8 : }
105 : :
106 : 0 : OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
107 : : {
108 : 0 : OUString value(OUSTR("0"));
109 [ # # ]: 0 : if (v.Value >>= value)
110 : : {
111 [ # # ][ # # ]: 0 : if (value.equals(OUSTR("1")))
112 [ # # ]: 0 : value = OUSTR("1");
113 : : }
114 : : else
115 : : {
116 : : throw lang::IllegalArgumentException(
117 [ # # ][ # # ]: 0 : OUSTR("Extension Manager: wrong property value"), 0, -1);
[ # # ]
118 : : }
119 : 0 : return value;
120 : : }
121 : 6 : void ExtensionProperties::write()
122 : : {
123 [ + - ]: 6 : ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv);
124 : 6 : ::rtl::OUStringBuffer buf;
125 : :
126 [ - + ][ + - ]: 6 : if (m_prop_suppress_license)
127 : : {
128 [ # # ][ # # ]: 0 : buf.append(OUSTR(PROP_SUPPRESS_LICENSE));
129 [ # # ][ # # ]: 0 : buf.append(OUSTR("="));
130 [ # # ][ # # ]: 0 : buf.append(*m_prop_suppress_license);
131 : : }
132 : :
133 : : ::rtl::OString stamp = ::rtl::OUStringToOString(
134 [ + - ][ + - ]: 6 : buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
135 : : Reference<css::io::XInputStream> xData(
136 : : ::xmlscript::createInputStream(
137 : : ::rtl::ByteSequence(
138 : 6 : reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
139 [ + - ][ + - ]: 12 : stamp.getLength() ) ) );
140 [ + - ][ + - ]: 6 : contentProps.writeStream( xData, true /* replace existing */ );
141 : 6 : }
142 : :
143 : 0 : bool ExtensionProperties::isSuppressedLicense()
144 : : {
145 : 0 : bool ret = false;
146 [ # # ]: 0 : if (m_prop_suppress_license)
147 : : {
148 [ # # ][ # # ]: 0 : if (m_prop_suppress_license->equals(OUSTR("1")))
149 : 0 : ret = true;
150 : : }
151 : 0 : return ret;
152 : : }
153 : :
154 : 2 : bool ExtensionProperties::isExtensionUpdate()
155 : : {
156 : 2 : bool ret = false;
157 [ - + ]: 2 : if (m_prop_extension_update)
158 : : {
159 [ # # ][ # # ]: 0 : if (m_prop_extension_update->equals(OUSTR("1")))
160 : 0 : ret = true;
161 : : }
162 : 2 : return ret;
163 : : }
164 : :
165 : : } // namespace dp_manager
166 : :
167 : :
168 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|