1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_scripting.hxx" 26 #include <cppuhelper/implementationentry.hxx> 27 28 #include <hash_map> 29 30 #include <osl/file.hxx> 31 #include <cppuhelper/implbase1.hxx> 32 33 #include <com/sun/star/beans/XPropertyContainer.hpp> 34 #include <com/sun/star/beans/PropertyAttribute.hpp> 35 36 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> 37 38 #include <util/util.hxx> 39 #include "ScriptInfo.hxx" 40 41 using namespace ::rtl; 42 using namespace com::sun::star; 43 using namespace ::com::sun::star::uno; 44 using namespace ::drafts::com::sun::star::script::framework; 45 using namespace ::drafts::com::sun::star::script::framework::storage; 46 47 namespace scripting_impl 48 { 49 50 typedef ::std::hash_map < ::rtl::OUString, css::uno::Any, ::rtl::OUStringHash, 51 ::std::equal_to< ::rtl::OUString > > PropertySet_hash; 52 53 class PropertySetImpl : public ::cppu::WeakImplHelper1< css::beans::XPropertySet > 54 { 55 56 public: 57 58 PropertySetImpl(); 59 ~PropertySetImpl(); 60 61 // XPropertySet implementation 62 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL 63 getPropertySetInfo(); 64 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, 65 const css::uno::Any& aValue ); 66 virtual css::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ); 67 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, 68 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ); 69 virtual void SAL_CALL removePropertyChangeListener( 70 const ::rtl::OUString& aPropertyName, 71 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ); 72 virtual void SAL_CALL addVetoableChangeListener( 73 const ::rtl::OUString& PropertyName, 74 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ); 75 virtual void SAL_CALL removeVetoableChangeListener( 76 const ::rtl::OUString& PropertyName, 77 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ); 78 79 private: 80 friend class ScriptInfo; 81 82 css::uno::Reference< css::uno::XComponentContext > m_xContext; 83 void PropertySetImpl::privateSetPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ); 84 85 osl::Mutex m_mutex; 86 PropertySet_hash m_propertyMap; 87 }; 88 89 PropertySetImpl::PropertySetImpl() 90 { 91 OSL_TRACE( "<PropertySetImpl ctor called\n" ); 92 } 93 94 PropertySetImpl::~PropertySetImpl() 95 { 96 OSL_TRACE( "<PropertySetImpl dtor called\n>" ); 97 } 98 99 Reference< beans::XPropertySetInfo > SAL_CALL PropertySetImpl::getPropertySetInfo( ) 100 { 101 return Reference< beans::XPropertySetInfo > (); // Not supported 102 } 103 104 void SAL_CALL PropertySetImpl::setPropertyValue( const ::rtl::OUString& aPropertyName, 105 const Any& aValue ) 106 { 107 throw RuntimeException( 108 OUSTR( "PropertySetImpl::setPropertyValue: method not supported. Read-only PropertySet" ), 109 Reference< XInterface >() ); 110 } 111 112 void PropertySetImpl::privateSetPropertyValue( const ::rtl::OUString& aPropertyName, 113 const Any& aValue ) 114 { 115 ::osl::Guard< osl::Mutex > aGuard( m_mutex ); 116 m_propertyMap[ aPropertyName ] = aValue; 117 } 118 119 //************************************************************************* 120 Any SAL_CALL PropertySetImpl::getPropertyValue( const ::rtl::OUString& PropertyName ) 121 { 122 if ( m_propertyMap.find( PropertyName ) == m_propertyMap.end() ) 123 { 124 throw RuntimeException( 125 126 OUSTR( "PropertySetImpl::getPropertyValue: invalid PropertyName ").concat( 127 PropertyName), 128 Reference< XInterface >() ); 129 } 130 131 ::osl::Guard< osl::Mutex > aGuard( m_mutex ); 132 Any returnValue = m_propertyMap[ PropertyName ]; 133 134 return returnValue; 135 } 136 137 //************************************************************************* 138 void SAL_CALL PropertySetImpl::addPropertyChangeListener( 139 const ::rtl::OUString& aPropertyName, 140 const Reference< beans::XPropertyChangeListener >& xListener ) 141 { 142 throw RuntimeException( 143 OUSTR( "PropertySetImpl::addPropertyChangeListener: method not supported" ), 144 Reference< XInterface >() ); 145 } 146 147 //************************************************************************* 148 void SAL_CALL PropertySetImpl::removePropertyChangeListener( 149 const ::rtl::OUString& aPropertyName, 150 const Reference< beans::XPropertyChangeListener >& aListener ) 151 { 152 throw RuntimeException( 153 OUSTR( "PropertySetImpl::removePropertyChangeListener: method not supported" ), 154 Reference< XInterface >() ); 155 } 156 157 //************************************************************************* 158 void SAL_CALL PropertySetImpl::addVetoableChangeListener( 159 const ::rtl::OUString& PropertyName, 160 const Reference< beans::XVetoableChangeListener >& aListener ) 161 { 162 throw RuntimeException( 163 OUSTR( "PropertySetImpl::addVetoableChangeListener: method not supported" ), 164 Reference< XInterface >() ); 165 } 166 167 //************************************************************************* 168 void SAL_CALL PropertySetImpl::removeVetoableChangeListener( 169 const ::rtl::OUString& PropertyName, 170 const Reference< beans::XVetoableChangeListener >& aListener ) 171 { 172 throw RuntimeException( 173 OUSTR( "PropertySetImpl::removeVetoableChangeListener: method not supported" ), 174 Reference< XInterface >() ); 175 } 176 177 178 //************************************************************************* 179 ScriptInfo::ScriptInfo( const ScriptData & scriptData, sal_Int32 storageID ) 180 : m_scriptData( scriptData ), m_storageID( storageID ) 181 { 182 OSL_TRACE( "< ++++++ ScriptInfo ctor called >\n" ); 183 OSL_TRACE( "< ++++++ parcelURI=%s>\n",::rtl::OUStringToOString(m_scriptData.parcelURI , RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 184 } 185 //************************************************************************* 186 ScriptInfo::~ScriptInfo() 187 { 188 OSL_TRACE( "< ScriptInfo dtor called >\n" ); 189 } 190 //************************************************************************* 191 OUString SAL_CALL ScriptInfo::getLogicalName( ) 192 { 193 OSL_TRACE( "ScriptInfo::getLogicalName() " ); 194 return m_scriptData.logicalname; 195 } 196 197 //************************************************************************* 198 OUString SAL_CALL ScriptInfo::getDescription( ) 199 { 200 OUString rs_desc; 201 // TDB need to determine locale here, hardcoded at the moment 202 // to english 203 204 OUString localeLang = OUString::createFromAscii( "en" ); 205 strpair_map::const_iterator str_it = 206 m_scriptData.locales.find( localeLang ); 207 208 if( str_it == m_scriptData.locales.end() ) 209 { 210 OSL_TRACE( "No description set in meta-data" ); 211 return rs_desc; 212 } 213 rs_desc = str_it->second.second; 214 return rs_desc; 215 } 216 217 //************************************************************************* 218 OUString SAL_CALL ScriptInfo::getLanguage( ) 219 { 220 OSL_TRACE( "ScriptInfo::getLanguage() " ); 221 return m_scriptData.language; 222 } 223 224 //************************************************************************* 225 OUString SAL_CALL ScriptInfo::getFunctionName( ) 226 { 227 OSL_TRACE( "ScriptInfo::getFunctionName() " ); 228 return m_scriptData.functionname; 229 } 230 231 //************************************************************************* 232 OUString SAL_CALL ScriptInfo::getParcelURI( ) 233 { 234 return m_scriptData.parcelURI; 235 } 236 237 //************************************************************************* 238 Reference< beans::XPropertySet > SAL_CALL ScriptInfo::getLanguageProperties( ) 239 { 240 PropertySetImpl* propSetImpl = new PropertySetImpl(); 241 Reference< beans::XPropertySet > xPropSet = propSetImpl; 242 243 props_vec::const_iterator pv_it = m_scriptData.languagedepprops.begin(); 244 props_vec::const_iterator pv_itend = m_scriptData.languagedepprops.end(); 245 246 for( ; pv_it != pv_itend; ++pv_it ) 247 { 248 try 249 { 250 propSetImpl->privateSetPropertyValue( pv_it->first, makeAny( pv_it->second ) ); 251 } 252 catch( Exception& e ) 253 { 254 OUString msg = OUSTR( 255 "ScriptInfo::getLanguage caught exception while setting property," ); 256 msg = msg.concat( OUSTR( " PropertryName: " ) ).concat( pv_it->first ); 257 msg = msg.concat( OUSTR( " \nException message is: " ) ); 258 msg = msg.concat( e.Message ); 259 throw RuntimeException( msg , Reference< XInterface >() ); 260 } 261 } 262 263 return xPropSet; 264 } 265 //************************************************************************* 266 css::uno::Sequence< ::rtl::OUString > SAL_CALL ScriptInfo::getFileSetNames() 267 { 268 OSL_TRACE("ScriptInfo::getFileSetNames"); 269 Sequence< OUString > results; 270 filesets_map::iterator fsm_it = m_scriptData.filesets.begin(); 271 filesets_map::iterator fsm_itend = m_scriptData.filesets.end(); 272 if( fsm_it == fsm_itend ) 273 { 274 OSL_TRACE( "ScriptInfo::getFileSetNames: no filesets" ); 275 return results; 276 } 277 results.realloc( m_scriptData.filesets.size() ); 278 for ( sal_Int32 count = 0; fsm_it != fsm_itend; ++fsm_it ) 279 { 280 OUString fileSetName = fsm_it->first; 281 OSL_TRACE( "ScriptInfo::getFileSetNames: adding name %s", 282 ::rtl::OUStringToOString( fileSetName, 283 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 284 results[ count++ ] = fileSetName; 285 } 286 return results; 287 } 288 //************************************************************************* 289 css::uno::Sequence< ::rtl::OUString > SAL_CALL 290 ScriptInfo::getFilesInFileSet( const ::rtl::OUString & fileSetName ) 291 { 292 Sequence< OUString > results; 293 filesets_map::iterator fsm_it = m_scriptData.filesets.find( fileSetName ); 294 filesets_map::iterator fsm_itend = m_scriptData.filesets.end(); 295 if( fsm_it == fsm_itend ) 296 { 297 OSL_TRACE( "ScriptInfo::getFilesInFileSet: no fileset named %s", 298 ::rtl::OUStringToOString( fileSetName, 299 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 300 return results; 301 } 302 303 strpairvec_map files = fsm_it->second.second; 304 strpairvec_map::iterator spvm_it = files.begin(); 305 strpairvec_map::iterator spvm_itend = files.end(); 306 if( spvm_it == spvm_itend ) 307 { 308 OSL_TRACE( "ScriptInfo::getFilesInFileSet: no files in fileset %s", 309 ::rtl::OUStringToOString( fileSetName, 310 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 311 return results; 312 } 313 results.realloc( files.size() ); 314 for( sal_Int32 count = 0; spvm_it != spvm_itend ; ++spvm_it ) 315 { 316 OUString fileName = spvm_it->first; 317 OSL_TRACE( "ScriptInfo::getFilesInFileSet: adding file %s", 318 ::rtl::OUStringToOString( fileName, 319 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 320 results[ count++ ] = fileName; 321 } 322 return results; 323 } 324 //************************************************************************* 325 } 326