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