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 // MARKER(update_precomp.py): autogen include statement, do not remove 24 #include "precompiled_scripting.hxx" 25 26 #include "DialogModelProvider.hxx" 27 #include "dlgprov.hxx" 28 #include <com/sun/star/resource/XStringResourceManager.hpp> 29 #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 30 31 32 // component helper namespace 33 namespace comp_DialogModelProvider { 34 35 namespace css = ::com::sun::star; 36 using namespace ::com::sun::star; 37 using namespace awt; 38 using namespace lang; 39 using namespace uno; 40 using namespace script; 41 using namespace beans; 42 43 44 // component and service helper functions: 45 ::rtl::OUString SAL_CALL _getImplementationName(); 46 css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames(); 47 css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context ); 48 49 } // closing component helper namespace 50 51 52 53 /// anonymous implementation namespace 54 namespace dlgprov { 55 56 namespace css = ::com::sun::star; 57 using namespace ::com::sun::star; 58 using namespace awt; 59 using namespace lang; 60 using namespace uno; 61 using namespace script; 62 using namespace beans; 63 64 65 DialogModelProvider::DialogModelProvider(Reference< XComponentContext > const & context) : 66 m_xContext(context) 67 {} 68 69 // lang::XInitialization: 70 void SAL_CALL DialogModelProvider::initialize(const css::uno::Sequence< uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception) 71 { 72 if ( aArguments.getLength() == 1 ) 73 { 74 ::rtl::OUString sURL; 75 if ( !( aArguments[ 0 ] >>= sURL )) 76 throw css::lang::IllegalArgumentException(); 77 // Try any other URL with SimpleFileAccess 78 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY_THROW ); 79 Reference< ucb::XSimpleFileAccess > xSFI = 80 Reference< ucb::XSimpleFileAccess >( xSMgr->createInstanceWithContext 81 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ), UNO_QUERY ); 82 83 try 84 { 85 Reference< io::XInputStream > xInput = xSFI->openFileRead( sURL ); 86 Reference< resource::XStringResourceManager > xStringResourceManager; 87 if ( xInput.is() ) 88 { 89 xStringResourceManager = dlgprov::lcl_getStringResourceManager(m_xContext,sURL); 90 Any aDialogSourceURLAny; 91 aDialogSourceURLAny <<= sURL; 92 93 m_xDialogModel.set( dlgprov::lcl_createDialogModel( m_xContext,xInput , xStringResourceManager, aDialogSourceURLAny ), UNO_QUERY_THROW); 94 m_xDialogModelProp.set(m_xDialogModel, UNO_QUERY_THROW); 95 } 96 } 97 catch( Exception& ) 98 {} 99 //m_sURL = sURL; 100 } 101 } 102 103 // container::XElementAccess: 104 uno::Type SAL_CALL DialogModelProvider::getElementType() throw (css::uno::RuntimeException) 105 { 106 return m_xDialogModel->getElementType(); 107 } 108 109 ::sal_Bool SAL_CALL DialogModelProvider::hasElements() throw (css::uno::RuntimeException) 110 { 111 return m_xDialogModel->hasElements(); 112 } 113 114 // container::XNameAccess: 115 uno::Any SAL_CALL DialogModelProvider::getByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException, css::container::NoSuchElementException, css::lang::WrappedTargetException) 116 { 117 return m_xDialogModel->getByName(aName); 118 } 119 120 css::uno::Sequence< ::rtl::OUString > SAL_CALL DialogModelProvider::getElementNames() throw (css::uno::RuntimeException) 121 { 122 return m_xDialogModel->getElementNames(); 123 } 124 125 ::sal_Bool SAL_CALL DialogModelProvider::hasByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException) 126 { 127 return m_xDialogModel->hasByName(aName); 128 } 129 130 // container::XNameReplace: 131 void SAL_CALL DialogModelProvider::replaceByName(const ::rtl::OUString & aName, const uno::Any & aElement) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException) 132 { 133 m_xDialogModel->replaceByName(aName,aElement); 134 } 135 136 // container::XNameContainer: 137 void SAL_CALL DialogModelProvider::insertByName(const ::rtl::OUString & aName, const uno::Any & aElement) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException) 138 { 139 m_xDialogModel->insertByName(aName,aElement); 140 } 141 142 void SAL_CALL DialogModelProvider::removeByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException, css::container::NoSuchElementException, css::lang::WrappedTargetException) 143 { 144 m_xDialogModel->removeByName(aName); 145 } 146 uno::Reference< beans::XPropertySetInfo > SAL_CALL DialogModelProvider::getPropertySetInfo( ) throw (uno::RuntimeException) 147 { 148 return m_xDialogModelProp->getPropertySetInfo(); 149 } 150 void SAL_CALL DialogModelProvider::setPropertyValue( const ::rtl::OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 151 { 152 } 153 uno::Any SAL_CALL DialogModelProvider::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 154 { 155 return m_xDialogModelProp->getPropertyValue(PropertyName); 156 } 157 void SAL_CALL DialogModelProvider::addPropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 158 { 159 } 160 void SAL_CALL DialogModelProvider::removePropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 161 { 162 } 163 void SAL_CALL DialogModelProvider::addVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 164 { 165 } 166 void SAL_CALL DialogModelProvider::removeVetoableChangeListener( const ::rtl::OUString& ,const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 167 { 168 } 169 170 // com.sun.star.uno.XServiceInfo: 171 ::rtl::OUString SAL_CALL DialogModelProvider::getImplementationName() throw (css::uno::RuntimeException) 172 { 173 return comp_DialogModelProvider::_getImplementationName(); 174 } 175 176 ::sal_Bool SAL_CALL DialogModelProvider::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException) 177 { 178 css::uno::Sequence< ::rtl::OUString > serviceNames = comp_DialogModelProvider::_getSupportedServiceNames(); 179 for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) { 180 if (serviceNames[i] == serviceName) 181 return sal_True; 182 } 183 return sal_False; 184 } 185 186 css::uno::Sequence< ::rtl::OUString > SAL_CALL DialogModelProvider::getSupportedServiceNames() throw (css::uno::RuntimeException) 187 { 188 return comp_DialogModelProvider::_getSupportedServiceNames(); 189 } 190 191 } // closing anonymous implementation namespace 192 193