1*2c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2c696243SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2c696243SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2c696243SAndrew Rist  * distributed with this work for additional information
6*2c696243SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2c696243SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2c696243SAndrew Rist  * "License"); you may not use this file except in compliance
9*2c696243SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2c696243SAndrew Rist  *
11*2c696243SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2c696243SAndrew Rist  *
13*2c696243SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2c696243SAndrew Rist  * software distributed under the License is distributed on an
15*2c696243SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2c696243SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2c696243SAndrew Rist  * specific language governing permissions and limitations
18*2c696243SAndrew Rist  * under the License.
19*2c696243SAndrew Rist  *
20*2c696243SAndrew Rist  *************************************************************/
21*2c696243SAndrew Rist 
22*2c696243SAndrew Rist 
23cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
24cdf0e10cSrcweir #include "precompiled_scripting.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "DialogModelProvider.hxx"
27cdf0e10cSrcweir #include "dlgprov.hxx"
28cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceManager.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // component helper namespace
33cdf0e10cSrcweir namespace comp_DialogModelProvider {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace css = ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace awt;
38cdf0e10cSrcweir using namespace lang;
39cdf0e10cSrcweir using namespace uno;
40cdf0e10cSrcweir using namespace script;
41cdf0e10cSrcweir using namespace beans;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // component and service helper functions:
45cdf0e10cSrcweir ::rtl::OUString SAL_CALL _getImplementationName();
46cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
47cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir } // closing component helper namespace
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /// anonymous implementation namespace
54cdf0e10cSrcweir namespace dlgprov {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace css = ::com::sun::star;
57cdf0e10cSrcweir using namespace ::com::sun::star;
58cdf0e10cSrcweir using namespace awt;
59cdf0e10cSrcweir using namespace lang;
60cdf0e10cSrcweir using namespace uno;
61cdf0e10cSrcweir using namespace script;
62cdf0e10cSrcweir using namespace beans;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
DialogModelProvider(Reference<XComponentContext> const & context)65cdf0e10cSrcweir DialogModelProvider::DialogModelProvider(Reference< XComponentContext > const & context) :
66cdf0e10cSrcweir     m_xContext(context)
67cdf0e10cSrcweir {}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir // lang::XInitialization:
initialize(const css::uno::Sequence<uno::Any> & aArguments)70cdf0e10cSrcweir void SAL_CALL DialogModelProvider::initialize(const css::uno::Sequence< uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	if ( aArguments.getLength() == 1 )
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         ::rtl::OUString sURL;
75cdf0e10cSrcweir         if ( !( aArguments[ 0 ] >>= sURL ))
76cdf0e10cSrcweir             throw css::lang::IllegalArgumentException();
77cdf0e10cSrcweir          // Try any other URL with SimpleFileAccess
78cdf0e10cSrcweir         Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY_THROW );
79cdf0e10cSrcweir 		Reference< ucb::XSimpleFileAccess > xSFI =
80cdf0e10cSrcweir 			Reference< ucb::XSimpleFileAccess >( xSMgr->createInstanceWithContext
81cdf0e10cSrcweir 			( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ), UNO_QUERY );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 		try
84cdf0e10cSrcweir 		{
85cdf0e10cSrcweir 			Reference< io::XInputStream > xInput = xSFI->openFileRead( sURL );
86cdf0e10cSrcweir             Reference< resource::XStringResourceManager > xStringResourceManager;
87cdf0e10cSrcweir 			if ( xInput.is() )
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir                 xStringResourceManager = dlgprov::lcl_getStringResourceManager(m_xContext,sURL);
90cdf0e10cSrcweir                 Any aDialogSourceURLAny;
91cdf0e10cSrcweir 			    aDialogSourceURLAny <<= sURL;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 			    m_xDialogModel.set( dlgprov::lcl_createDialogModel( m_xContext,xInput , xStringResourceManager, aDialogSourceURLAny  ), UNO_QUERY_THROW);
94cdf0e10cSrcweir                 m_xDialogModelProp.set(m_xDialogModel, UNO_QUERY_THROW);
95cdf0e10cSrcweir 			}
96cdf0e10cSrcweir 		}
97cdf0e10cSrcweir 		catch( Exception& )
98cdf0e10cSrcweir 		{}
99cdf0e10cSrcweir         //m_sURL = sURL;
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // container::XElementAccess:
getElementType()104cdf0e10cSrcweir uno::Type SAL_CALL DialogModelProvider::getElementType() throw (css::uno::RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     return m_xDialogModel->getElementType();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
hasElements()109cdf0e10cSrcweir ::sal_Bool SAL_CALL DialogModelProvider::hasElements() throw (css::uno::RuntimeException)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     return m_xDialogModel->hasElements();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // container::XNameAccess:
getByName(const::rtl::OUString & aName)115cdf0e10cSrcweir uno::Any SAL_CALL DialogModelProvider::getByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException, css::container::NoSuchElementException, css::lang::WrappedTargetException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     return m_xDialogModel->getByName(aName);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
getElementNames()120cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL DialogModelProvider::getElementNames() throw (css::uno::RuntimeException)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     return m_xDialogModel->getElementNames();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
hasByName(const::rtl::OUString & aName)125cdf0e10cSrcweir ::sal_Bool SAL_CALL DialogModelProvider::hasByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     return m_xDialogModel->hasByName(aName);
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // container::XNameReplace:
replaceByName(const::rtl::OUString & aName,const uno::Any & aElement)131cdf0e10cSrcweir 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)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     m_xDialogModel->replaceByName(aName,aElement);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // container::XNameContainer:
insertByName(const::rtl::OUString & aName,const uno::Any & aElement)137cdf0e10cSrcweir 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)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     m_xDialogModel->insertByName(aName,aElement);
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
removeByName(const::rtl::OUString & aName)142cdf0e10cSrcweir void SAL_CALL DialogModelProvider::removeByName(const ::rtl::OUString & aName) throw (css::uno::RuntimeException, css::container::NoSuchElementException, css::lang::WrappedTargetException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     m_xDialogModel->removeByName(aName);
145cdf0e10cSrcweir }
getPropertySetInfo()146cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL DialogModelProvider::getPropertySetInfo(  ) throw (uno::RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     return m_xDialogModelProp->getPropertySetInfo();
149cdf0e10cSrcweir }
setPropertyValue(const::rtl::OUString &,const uno::Any &)150cdf0e10cSrcweir void SAL_CALL DialogModelProvider::setPropertyValue( const ::rtl::OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir }
getPropertyValue(const::rtl::OUString & PropertyName)153cdf0e10cSrcweir uno::Any SAL_CALL DialogModelProvider::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     return m_xDialogModelProp->getPropertyValue(PropertyName);
156cdf0e10cSrcweir }
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)157cdf0e10cSrcweir void SAL_CALL DialogModelProvider::addPropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir }
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)160cdf0e10cSrcweir void SAL_CALL DialogModelProvider::removePropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir }
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)163cdf0e10cSrcweir void SAL_CALL DialogModelProvider::addVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir }
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)166cdf0e10cSrcweir void SAL_CALL DialogModelProvider::removeVetoableChangeListener( const ::rtl::OUString& ,const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir // com.sun.star.uno.XServiceInfo:
getImplementationName()171cdf0e10cSrcweir ::rtl::OUString SAL_CALL DialogModelProvider::getImplementationName() throw (css::uno::RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     return comp_DialogModelProvider::_getImplementationName();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
supportsService(::rtl::OUString const & serviceName)176cdf0e10cSrcweir ::sal_Bool SAL_CALL DialogModelProvider::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > serviceNames = comp_DialogModelProvider::_getSupportedServiceNames();
179cdf0e10cSrcweir     for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
180cdf0e10cSrcweir         if (serviceNames[i] == serviceName)
181cdf0e10cSrcweir             return sal_True;
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir     return sal_False;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
getSupportedServiceNames()186cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL DialogModelProvider::getSupportedServiceNames() throw (css::uno::RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     return comp_DialogModelProvider::_getSupportedServiceNames();
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir } // closing anonymous implementation namespace
192cdf0e10cSrcweir 
193