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