1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScriptInfo.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
33 #include <cppuhelper/implementationentry.hxx>
37 #include <osl/file.hxx>
38 #include <cppuhelper/implbase1.hxx>
40 #include <com/sun/star/beans/XPropertyContainer.hpp>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
45 #include <util/util.hxx>
46 #include "ScriptInfo.hxx"
48 using namespace ::rtl
;
49 using namespace com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::drafts::com::sun::star::script::framework
;
52 using namespace ::drafts::com::sun::star::script::framework::storage
;
54 namespace scripting_impl
57 typedef ::std::hash_map
< ::rtl::OUString
, css::uno::Any
, ::rtl::OUStringHash
,
58 ::std::equal_to
< ::rtl::OUString
> > PropertySet_hash
;
60 class PropertySetImpl
: public ::cppu::WeakImplHelper1
< css::beans::XPropertySet
>
68 // XPropertySet implementation
69 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
71 throw ( css::uno::RuntimeException
);
72 virtual void SAL_CALL
setPropertyValue( const ::rtl::OUString
& aPropertyName
,
73 const css::uno::Any
& aValue
)
74 throw ( css::beans::UnknownPropertyException
,
75 css::beans::PropertyVetoException
,
76 css::lang::IllegalArgumentException
,
77 css::lang::WrappedTargetException
,
78 css::uno::RuntimeException
);
79 virtual css::uno::Any SAL_CALL
getPropertyValue( const ::rtl::OUString
& PropertyName
)
80 throw ( css::beans::UnknownPropertyException
,
81 css::lang::WrappedTargetException
,
82 css::uno::RuntimeException
);
83 virtual void SAL_CALL
addPropertyChangeListener( const ::rtl::OUString
& aPropertyName
,
84 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
)
85 throw ( css::beans::UnknownPropertyException
,
86 css::lang::WrappedTargetException
,
87 css::uno::RuntimeException
);
88 virtual void SAL_CALL
removePropertyChangeListener(
89 const ::rtl::OUString
& aPropertyName
,
90 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
)
91 throw ( css::beans::UnknownPropertyException
,
92 css::lang::WrappedTargetException
,
93 css::uno::RuntimeException
);
94 virtual void SAL_CALL
addVetoableChangeListener(
95 const ::rtl::OUString
& PropertyName
,
96 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
)
97 throw ( css::beans::UnknownPropertyException
,
98 css::lang::WrappedTargetException
,
99 css::uno::RuntimeException
);
100 virtual void SAL_CALL
removeVetoableChangeListener(
101 const ::rtl::OUString
& PropertyName
,
102 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
)
103 throw ( css::beans::UnknownPropertyException
,
104 css::lang::WrappedTargetException
,
105 css::uno::RuntimeException
);
108 friend class ScriptInfo
;
110 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
111 void PropertySetImpl::privateSetPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
)
112 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
,
113 lang::IllegalArgumentException
, lang::WrappedTargetException
,
117 PropertySet_hash m_propertyMap
;
120 PropertySetImpl::PropertySetImpl()
122 OSL_TRACE( "<PropertySetImpl ctor called\n" );
125 PropertySetImpl::~PropertySetImpl()
127 OSL_TRACE( "<PropertySetImpl dtor called\n>" );
130 Reference
< beans::XPropertySetInfo
> SAL_CALL
PropertySetImpl::getPropertySetInfo( )
131 throw ( RuntimeException
)
133 return Reference
< beans::XPropertySetInfo
> (); // Not supported
136 void SAL_CALL
PropertySetImpl::setPropertyValue( const ::rtl::OUString
& aPropertyName
,
138 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
,
139 lang::IllegalArgumentException
, lang::WrappedTargetException
,
142 throw RuntimeException(
143 OUSTR( "PropertySetImpl::setPropertyValue: method not supported. Read-only PropertySet" ),
144 Reference
< XInterface
>() );
147 void PropertySetImpl::privateSetPropertyValue( const ::rtl::OUString
& aPropertyName
,
149 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
,
150 lang::IllegalArgumentException
, lang::WrappedTargetException
,
153 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
154 m_propertyMap
[ aPropertyName
] = aValue
;
157 //*************************************************************************
158 Any SAL_CALL
PropertySetImpl::getPropertyValue( const ::rtl::OUString
& PropertyName
)
159 throw ( beans::UnknownPropertyException
,
160 lang::WrappedTargetException
, RuntimeException
)
162 if ( m_propertyMap
.find( PropertyName
) == m_propertyMap
.end() )
164 throw RuntimeException(
166 OUSTR( "PropertySetImpl::getPropertyValue: invalid PropertyName ").concat(
168 Reference
< XInterface
>() );
171 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
172 Any returnValue
= m_propertyMap
[ PropertyName
];
177 //*************************************************************************
178 void SAL_CALL
PropertySetImpl::addPropertyChangeListener(
179 const ::rtl::OUString
& aPropertyName
,
180 const Reference
< beans::XPropertyChangeListener
>& xListener
)
181 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
,
184 throw RuntimeException(
185 OUSTR( "PropertySetImpl::addPropertyChangeListener: method not supported" ),
186 Reference
< XInterface
>() );
189 //*************************************************************************
190 void SAL_CALL
PropertySetImpl::removePropertyChangeListener(
191 const ::rtl::OUString
& aPropertyName
,
192 const Reference
< beans::XPropertyChangeListener
>& aListener
)
193 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
,
196 throw RuntimeException(
197 OUSTR( "PropertySetImpl::removePropertyChangeListener: method not supported" ),
198 Reference
< XInterface
>() );
201 //*************************************************************************
202 void SAL_CALL
PropertySetImpl::addVetoableChangeListener(
203 const ::rtl::OUString
& PropertyName
,
204 const Reference
< beans::XVetoableChangeListener
>& aListener
)
205 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
,
208 throw RuntimeException(
209 OUSTR( "PropertySetImpl::addVetoableChangeListener: method not supported" ),
210 Reference
< XInterface
>() );
213 //*************************************************************************
214 void SAL_CALL
PropertySetImpl::removeVetoableChangeListener(
215 const ::rtl::OUString
& PropertyName
,
216 const Reference
< beans::XVetoableChangeListener
>& aListener
)
217 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
,
220 throw RuntimeException(
221 OUSTR( "PropertySetImpl::removeVetoableChangeListener: method not supported" ),
222 Reference
< XInterface
>() );
226 //*************************************************************************
227 ScriptInfo::ScriptInfo( const ScriptData
& scriptData
, sal_Int32 storageID
)
228 : m_scriptData( scriptData
), m_storageID( storageID
)
230 OSL_TRACE( "< ++++++ ScriptInfo ctor called >\n" );
231 OSL_TRACE( "< ++++++ parcelURI=%s>\n",::rtl::OUStringToOString(m_scriptData
.parcelURI
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
233 //*************************************************************************
234 ScriptInfo::~ScriptInfo()
236 OSL_TRACE( "< ScriptInfo dtor called >\n" );
238 //*************************************************************************
239 OUString SAL_CALL
ScriptInfo::getLogicalName( ) throw ( RuntimeException
)
241 OSL_TRACE( "ScriptInfo::getLogicalName() " );
242 return m_scriptData
.logicalname
;
245 //*************************************************************************
246 OUString SAL_CALL
ScriptInfo::getDescription( ) throw ( RuntimeException
)
249 // TDB need to determine locale here, hardcoded at the moment
252 OUString localeLang
= OUString::createFromAscii( "en" );
253 strpair_map::const_iterator str_it
=
254 m_scriptData
.locales
.find( localeLang
);
256 if( str_it
== m_scriptData
.locales
.end() )
258 OSL_TRACE( "No description set in meta-data" );
261 rs_desc
= str_it
->second
.second
;
265 //*************************************************************************
266 OUString SAL_CALL
ScriptInfo::getLanguage( ) throw ( RuntimeException
)
268 OSL_TRACE( "ScriptInfo::getLanguage() " );
269 return m_scriptData
.language
;
272 //*************************************************************************
273 OUString SAL_CALL
ScriptInfo::getFunctionName( ) throw ( RuntimeException
)
275 OSL_TRACE( "ScriptInfo::getFunctionName() " );
276 return m_scriptData
.functionname
;
279 //*************************************************************************
280 OUString SAL_CALL
ScriptInfo::getParcelURI( ) throw ( RuntimeException
)
282 return m_scriptData
.parcelURI
;
285 //*************************************************************************
286 Reference
< beans::XPropertySet
> SAL_CALL
ScriptInfo::getLanguageProperties( )
287 throw ( RuntimeException
)
289 PropertySetImpl
* propSetImpl
= new PropertySetImpl();
290 Reference
< beans::XPropertySet
> xPropSet
= propSetImpl
;
292 props_vec::const_iterator pv_it
= m_scriptData
.languagedepprops
.begin();
293 props_vec::const_iterator pv_itend
= m_scriptData
.languagedepprops
.end();
295 for( ; pv_it
!= pv_itend
; ++pv_it
)
299 propSetImpl
->privateSetPropertyValue( pv_it
->first
, makeAny( pv_it
->second
) );
301 catch( Exception
& e
)
303 OUString msg
= OUSTR(
304 "ScriptInfo::getLanguage caught exception while setting property," );
305 msg
= msg
.concat( OUSTR( " PropertryName: " ) ).concat( pv_it
->first
);
306 msg
= msg
.concat( OUSTR( " \nException message is: " ) );
307 msg
= msg
.concat( e
.Message
);
308 throw RuntimeException( msg
, Reference
< XInterface
>() );
314 //*************************************************************************
315 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
ScriptInfo::getFileSetNames()
316 throw ( css::uno::RuntimeException
)
318 OSL_TRACE("ScriptInfo::getFileSetNames");
319 Sequence
< OUString
> results
;
320 filesets_map::iterator fsm_it
= m_scriptData
.filesets
.begin();
321 filesets_map::iterator fsm_itend
= m_scriptData
.filesets
.end();
322 if( fsm_it
== fsm_itend
)
324 OSL_TRACE( "ScriptInfo::getFileSetNames: no filesets" );
327 results
.realloc( m_scriptData
.filesets
.size() );
328 for ( sal_Int32 count
= 0; fsm_it
!= fsm_itend
; ++fsm_it
)
330 OUString fileSetName
= fsm_it
->first
;
331 OSL_TRACE( "ScriptInfo::getFileSetNames: adding name %s",
332 ::rtl::OUStringToOString( fileSetName
,
333 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
334 results
[ count
++ ] = fileSetName
;
338 //*************************************************************************
339 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
340 ScriptInfo::getFilesInFileSet( const ::rtl::OUString
& fileSetName
)
341 throw ( css::uno::RuntimeException
)
343 Sequence
< OUString
> results
;
344 filesets_map::iterator fsm_it
= m_scriptData
.filesets
.find( fileSetName
);
345 filesets_map::iterator fsm_itend
= m_scriptData
.filesets
.end();
346 if( fsm_it
== fsm_itend
)
348 OSL_TRACE( "ScriptInfo::getFilesInFileSet: no fileset named %s",
349 ::rtl::OUStringToOString( fileSetName
,
350 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
354 strpairvec_map files
= fsm_it
->second
.second
;
355 strpairvec_map::iterator spvm_it
= files
.begin();
356 strpairvec_map::iterator spvm_itend
= files
.end();
357 if( spvm_it
== spvm_itend
)
359 OSL_TRACE( "ScriptInfo::getFilesInFileSet: no files in fileset %s",
360 ::rtl::OUStringToOString( fileSetName
,
361 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
364 results
.realloc( files
.size() );
365 for( sal_Int32 count
= 0; spvm_it
!= spvm_itend
; ++spvm_it
)
367 OUString fileName
= spvm_it
->first
;
368 OSL_TRACE( "ScriptInfo::getFilesInFileSet: adding file %s",
369 ::rtl::OUStringToOString( fileName
,
370 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
371 results
[ count
++ ] = fileName
;
375 //*************************************************************************