12c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32c696243SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42c696243SAndrew Rist * or more contributor license agreements. See the NOTICE file
52c696243SAndrew Rist * distributed with this work for additional information
62c696243SAndrew Rist * regarding copyright ownership. The ASF licenses this file
72c696243SAndrew Rist * to you under the Apache License, Version 2.0 (the
82c696243SAndrew Rist * "License"); you may not use this file except in compliance
92c696243SAndrew Rist * with the License. You may obtain a copy of the License at
102c696243SAndrew Rist *
112c696243SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122c696243SAndrew Rist *
132c696243SAndrew Rist * Unless required by applicable law or agreed to in writing,
142c696243SAndrew Rist * software distributed under the License is distributed on an
152c696243SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162c696243SAndrew Rist * KIND, either express or implied. See the License for the
172c696243SAndrew Rist * specific language governing permissions and limitations
182c696243SAndrew Rist * under the License.
192c696243SAndrew Rist *
202c696243SAndrew Rist *************************************************************/
212c696243SAndrew Rist
222c696243SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_scripting.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
30cdf0e10cSrcweir #include <sal/config.h>
31cdf0e10cSrcweir #include <rtl/uri.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
34cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
39cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include "ScriptStorageManager.hxx"
42cdf0e10cSrcweir #include <util/util.hxx>
43cdf0e10cSrcweir #include <util/scriptingconstants.hxx>
44cdf0e10cSrcweir #include <tools/diagnose_ex.h>
45cdf0e10cSrcweir
46cdf0e10cSrcweir using namespace ::rtl;
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using namespace ::drafts::com::sun::star::script::framework;
50cdf0e10cSrcweir
51cdf0e10cSrcweir namespace scripting_impl
52cdf0e10cSrcweir {
53cdf0e10cSrcweir
54cdf0e10cSrcweir static OUString s_implName =
55cdf0e10cSrcweir ::rtl::OUString::createFromAscii(
56cdf0e10cSrcweir "drafts.com.sun.star.script.framework.storage.ScriptStorageManager" );
57cdf0e10cSrcweir static OUString s_serviceName =
58cdf0e10cSrcweir ::rtl::OUString::createFromAscii(
59cdf0e10cSrcweir "drafts.com.sun.star.script.framework.storage.ScriptStorageManager" );
60cdf0e10cSrcweir static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceName, 1 );
61cdf0e10cSrcweir
62cdf0e10cSrcweir //extern ::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT;
63cdf0e10cSrcweir //extern ::rtl_StandardModuleCount s_moduleCount;
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir //*************************************************************************
67cdf0e10cSrcweir // ScriptStorageManager Constructor
ScriptStorageManager(const Reference<XComponentContext> & xContext)68cdf0e10cSrcweir ScriptStorageManager::ScriptStorageManager( const Reference<
69cdf0e10cSrcweir XComponentContext > & xContext ) SAL_THROW ( ( RuntimeException ) )
70cdf0e10cSrcweir : m_xContext( xContext, UNO_SET_THROW ), m_count( 0 ), m_securityMgr( xContext )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir OSL_TRACE( "< ScriptStorageManager ctor called >\n" );
73cdf0e10cSrcweir //s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
74cdf0e10cSrcweir
75cdf0e10cSrcweir m_xMgr.set( m_xContext->getServiceManager(), UNO_SET_THROW );
76cdf0e10cSrcweir
77cdf0e10cSrcweir try
78cdf0e10cSrcweir {
79cdf0e10cSrcweir // obtain the macro expander singleton to use in determining the
80cdf0e10cSrcweir // location of the application script storage
81cdf0e10cSrcweir Reference< util::XMacroExpander > xME( m_xContext->getValueByName( OUString::createFromAscii(
82cdf0e10cSrcweir "/singletons/com.sun.star.util.theMacroExpander" ) ), UNO_QUERY_THROW );
83cdf0e10cSrcweir
84cdf0e10cSrcweir OUString base = OUString::createFromAscii(
85*910823aeSJürgen Schmidt SAL_CONFIGFILE( "${$OOO_BASE_DIR/program/bootstrap" ) );
86cdf0e10cSrcweir
87cdf0e10cSrcweir setupAppStorage( xME,
88cdf0e10cSrcweir base.concat( OUString::createFromAscii( "::BaseInstallation}/share" ) ),
89cdf0e10cSrcweir OUSTR( "SHARE" ) );
90cdf0e10cSrcweir setupAppStorage( xME,
91cdf0e10cSrcweir base.concat( OUString::createFromAscii( "::UserInstallation}/user" ) ),
92cdf0e10cSrcweir OUSTR( "USER" ) );
93cdf0e10cSrcweir
94cdf0e10cSrcweir }
95cdf0e10cSrcweir catch ( Exception & e )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir throw RuntimeException( OUSTR( "ScriptStorageManager::ScriptStorageManager: " ).concat( e.Message ), Reference< XInterface >() );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir OSL_ASSERT( m_count == 2 );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir //*************************************************************************
103cdf0e10cSrcweir // ScriptStorageManager setupAppStorage
104cdf0e10cSrcweir void
setupAppStorage(const Reference<util::XMacroExpander> & xME,const OUString & storageStr,const OUString & appStr)105cdf0e10cSrcweir ScriptStorageManager::setupAppStorage(
106cdf0e10cSrcweir const Reference< util::XMacroExpander > & xME,
107cdf0e10cSrcweir const OUString & storageStr,
108cdf0e10cSrcweir const OUString & appStr)
109cdf0e10cSrcweir SAL_THROW ( ( RuntimeException ) )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir try
112cdf0e10cSrcweir {
113cdf0e10cSrcweir Reference< ucb::XSimpleFileAccess > xSFA(
114cdf0e10cSrcweir m_xMgr->createInstanceWithContext(
115cdf0e10cSrcweir OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ),
116cdf0e10cSrcweir m_xContext
117cdf0e10cSrcweir ),
118cdf0e10cSrcweir UNO_QUERY_THROW
119cdf0e10cSrcweir );
120cdf0e10cSrcweir
121cdf0e10cSrcweir setupAnyStorage( xSFA, xME->expandMacros( storageStr ), appStr );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir catch ( Exception & e )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir throw RuntimeException(
126cdf0e10cSrcweir OUSTR( "ScriptStorageManager::setupAppStorage: " ).concat( e.Message ),
127cdf0e10cSrcweir Reference< XInterface >() );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //*************************************************************************
132cdf0e10cSrcweir // ScriptStorageManager setupAnyStorage
133cdf0e10cSrcweir sal_Int32
setupAnyStorage(const Reference<ucb::XSimpleFileAccess> & xSFA,const OUString & storageStr,const OUString & origStringURI)134cdf0e10cSrcweir ScriptStorageManager::setupAnyStorage(
135cdf0e10cSrcweir const Reference< ucb::XSimpleFileAccess > & xSFA,
136cdf0e10cSrcweir const OUString & storageStr,
137cdf0e10cSrcweir const OUString & origStringURI )
138cdf0e10cSrcweir SAL_THROW ( ( RuntimeException ) )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir // Required for scope of fnc to protect all access read and writes to m_count
141cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
142cdf0e10cSrcweir try
143cdf0e10cSrcweir {
144cdf0e10cSrcweir
145cdf0e10cSrcweir // create a ScriptingStorage using the SimpleFileAccess, the storageID
146cdf0e10cSrcweir // (from the count), and the URL to the application's shared area
147cdf0e10cSrcweir Sequence < Any > aArgs( 3 );
148cdf0e10cSrcweir aArgs[ 0 ] <<= xSFA;
149cdf0e10cSrcweir aArgs[ 1 ] <<= m_count;
150cdf0e10cSrcweir aArgs[ 2 ] <<= storageStr;
151cdf0e10cSrcweir
152cdf0e10cSrcweir OSL_TRACE( "creating storage for: %s\n",
153cdf0e10cSrcweir ::rtl::OUStringToOString( storageStr,
154cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
155cdf0e10cSrcweir
156cdf0e10cSrcweir Reference< XInterface > xInterface(
157cdf0e10cSrcweir m_xMgr->createInstanceWithArgumentsAndContext(
158cdf0e10cSrcweir OUString::createFromAscii( "drafts.com.sun.star.script.framework.storage.ScriptStorage" ),
159cdf0e10cSrcweir aArgs,
160cdf0e10cSrcweir m_xContext
161cdf0e10cSrcweir ),
162cdf0e10cSrcweir UNO_QUERY_THROW
163cdf0e10cSrcweir );
164cdf0e10cSrcweir
165cdf0e10cSrcweir // and place it in the hash_map. Increment the counter
166cdf0e10cSrcweir m_ScriptStorageMap[ m_count++ ] = xInterface;
167cdf0e10cSrcweir sal_Int32 sid = m_count - 1;
168cdf0e10cSrcweir
169cdf0e10cSrcweir // create hash of original uri i.e. file:///home/users/docs/mydoc.sxw
170cdf0e10cSrcweir // and storage id (sid) this will allow us to retrieve
171cdf0e10cSrcweir // the sid based on the url of the document.
172cdf0e10cSrcweir m_StorageIdOrigURIHash [ origStringURI ] = sid;
173cdf0e10cSrcweir OSL_TRACE( "\tcreated with ID=%d\n", m_count - 1 );
174cdf0e10cSrcweir
175cdf0e10cSrcweir }
176cdf0e10cSrcweir catch ( Exception & e )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir throw RuntimeException(
179cdf0e10cSrcweir OUSTR( "ScriptStorageManager::setupAnyStorage: " ).concat(
180cdf0e10cSrcweir e.Message ), Reference< XInterface >() );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
183cdf0e10cSrcweir return m_count -1;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
186cdf0e10cSrcweir //*************************************************************************
187cdf0e10cSrcweir // ScriptStorageManager Destructor
~ScriptStorageManager()188cdf0e10cSrcweir ScriptStorageManager::~ScriptStorageManager()
189cdf0e10cSrcweir SAL_THROW ( () )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir OSL_TRACE( "< ScriptStorageManager dtor called >\n" );
192cdf0e10cSrcweir // s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
195cdf0e10cSrcweir //*************************************************************************
196cdf0e10cSrcweir // This method assumes that the XSimpleFileAccess knows it's on root URL
197cdf0e10cSrcweir // and can be used with relative URLs
198cdf0e10cSrcweir sal_Int32 SAL_CALL
createScriptStorage(const Reference<ucb::XSimpleFileAccess> & xSFA)199cdf0e10cSrcweir ScriptStorageManager::createScriptStorage(
200cdf0e10cSrcweir const Reference< ucb::XSimpleFileAccess >& xSFA )
201cdf0e10cSrcweir throw ( RuntimeException )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorage\n" );
204cdf0e10cSrcweir ENSURE_OR_THROW( xSFA.is(), "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" );
205cdf0e10cSrcweir
206cdf0e10cSrcweir return setupAnyStorage( xSFA, ::rtl::OUString::createFromAscii( "" ),
207cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "" ) );
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir //*************************************************************************
211cdf0e10cSrcweir sal_Int32 SAL_CALL
createScriptStorageWithURI(const Reference<ucb::XSimpleFileAccess> & xSFA,const OUString & cStringURI)212cdf0e10cSrcweir ScriptStorageManager::createScriptStorageWithURI(
213cdf0e10cSrcweir const Reference< ucb::XSimpleFileAccess >& xSFA, const OUString & cStringURI )
214cdf0e10cSrcweir throw ( RuntimeException )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorageWithURI\n" );
217cdf0e10cSrcweir ENSURE_OR_THROW( xSFA.is(), "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" );
218cdf0e10cSrcweir
219cdf0e10cSrcweir // related to issue 11866
220cdf0e10cSrcweir // warning dialog gets launched when adding binding to script in doc
221cdf0e10cSrcweir // workaround issue: no functionProvider created on doc open
222cdf0e10cSrcweir // if NODIALOG tag, strip from stringURI, set boolean=true
223cdf0e10cSrcweir bool displayDialog = true;
224cdf0e10cSrcweir ::rtl::OUString dialogTag = ::rtl::OUString::createFromAscii( "NoDialog::" );
225cdf0e10cSrcweir ::rtl::OUString stringURI = cStringURI;
226cdf0e10cSrcweir if( stringURI.indexOf( dialogTag ) == 0 )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir OSL_TRACE( "ScriptStorageManager::createScriptStorage: will not display security dialogs" );
229cdf0e10cSrcweir stringURI = stringURI.copy( dialogTag.getLength() );
230cdf0e10cSrcweir displayDialog = false;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir sal_Int32 returnedID = getScriptStorageID(stringURI);
233cdf0e10cSrcweir
234cdf0e10cSrcweir
235cdf0e10cSrcweir // convert file:///... url to vnd... syntax
236cdf0e10cSrcweir ::rtl::OUString canonicalURI(
237cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "vnd.sun.star.pkg://" ) );
238cdf0e10cSrcweir canonicalURI = canonicalURI.concat( ::rtl::Uri::encode( stringURI,
239cdf0e10cSrcweir rtl_UriCharClassUricNoSlash, rtl_UriEncodeCheckEscapes,
240cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) );
241cdf0e10cSrcweir
242cdf0e10cSrcweir if (returnedID == -1)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir OSL_TRACE("Creating new storage for %s",
245cdf0e10cSrcweir ::rtl::OUStringToOString( stringURI,
246cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
247cdf0e10cSrcweir returnedID = setupAnyStorage( xSFA, canonicalURI, stringURI );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir else
250cdf0e10cSrcweir {
251cdf0e10cSrcweir OSL_TRACE("Using existing storage for %s",
252cdf0e10cSrcweir ::rtl::OUStringToOString( stringURI,
253cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir // np - removed previous scripting framework security handling
257cdf0e10cSrcweir // now handled by modification to existing calls in sfx for basic
258cdf0e10cSrcweir //
259cdf0e10cSrcweir /* if( displayDialog )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir try
262cdf0e10cSrcweir {
263cdf0e10cSrcweir OSL_TRACE("Adding to security mgr for %s",
264cdf0e10cSrcweir ::rtl::OUStringToOString( stringURI,
265cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
266cdf0e10cSrcweir m_securityMgr.addScriptStorage( stringURI, returnedID );
267cdf0e10cSrcweir }
268cdf0e10cSrcweir catch ( RuntimeException & rte )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir throw RuntimeException(
271cdf0e10cSrcweir OUSTR( "ScriptStorageManager::createScriptStorageWithURI: " ).concat(
272cdf0e10cSrcweir rte.Message ), Reference< XInterface >() );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir else
276cdf0e10cSrcweir {
277cdf0e10cSrcweir OSL_TRACE("No need to security mgr for %s",
278cdf0e10cSrcweir ::rtl::OUStringToOString( stringURI,
279cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
280cdf0e10cSrcweir }*/
281cdf0e10cSrcweir return returnedID;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir //*************************************************************************
285cdf0e10cSrcweir Reference < XInterface > SAL_CALL
getScriptStorage(sal_Int32 scriptStorageID)286cdf0e10cSrcweir ScriptStorageManager::getScriptStorage( sal_Int32 scriptStorageID )
287cdf0e10cSrcweir throw( RuntimeException )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir OSL_TRACE( "** ==> ScriptStorageManager in getStorageInstance\n" );
290cdf0e10cSrcweir OSL_TRACE( "** ==> request for id=%d",scriptStorageID );
291cdf0e10cSrcweir
292cdf0e10cSrcweir ScriptStorage_map::const_iterator itr =
293cdf0e10cSrcweir m_ScriptStorageMap.find( scriptStorageID );
294cdf0e10cSrcweir
295cdf0e10cSrcweir if ( itr == m_ScriptStorageMap.end() )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir throw RuntimeException(
298cdf0e10cSrcweir OUSTR( "ScriptStorageManager::getScriptStorage: invalid storage ID" ),
299cdf0e10cSrcweir Reference< XInterface >() );
300cdf0e10cSrcweir }
301cdf0e10cSrcweir ENSURE_OR_THROW( itr->second.is(),
302cdf0e10cSrcweir "ScriptStorageManager::getScriptStorage: Cannot get ScriptStorage from ScriptStorageHash" );
303cdf0e10cSrcweir return itr->second;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir //*******************************************************************
307cdf0e10cSrcweir sal_Int32 SAL_CALL
getScriptStorageID(const::rtl::OUString & origURI)308cdf0e10cSrcweir ScriptStorageManager::getScriptStorageID( const ::rtl::OUString& origURI )
309cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir StorageId_hash::const_iterator it = m_StorageIdOrigURIHash.find( origURI );
312cdf0e10cSrcweir
313cdf0e10cSrcweir if ( it == m_StorageIdOrigURIHash.end() )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir OUString message = OUSTR( "ScriptStorageManager::getScriptStorageID(): Cannot find storage for " );
316cdf0e10cSrcweir if ( origURI.getLength() == 0 )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir message = message.concat( OUSTR("Empty URI") );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir else
321cdf0e10cSrcweir {
322cdf0e10cSrcweir message = message.concat( origURI );
323cdf0e10cSrcweir }
324cdf0e10cSrcweir OSL_TRACE( ::rtl::OUStringToOString( message,
325cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
326cdf0e10cSrcweir return -1;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
329cdf0e10cSrcweir return it->second;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
332cdf0e10cSrcweir //*******************************************************************
333cdf0e10cSrcweir void
removeScriptDocURIHashEntry(const OUString & origURI)334cdf0e10cSrcweir ScriptStorageManager::removeScriptDocURIHashEntry( const OUString & origURI )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir StorageId_hash::iterator it = m_StorageIdOrigURIHash.find( origURI );
337cdf0e10cSrcweir if ( it == m_StorageIdOrigURIHash.end() )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir OSL_TRACE( "ScriptStorageManager::removeScriptDocURIHashEntry: no entry to remove" );
340cdf0e10cSrcweir return;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir
343cdf0e10cSrcweir // remove entry for this doc url from orig uri map.
344cdf0e10cSrcweir m_StorageIdOrigURIHash.erase( it );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
347cdf0e10cSrcweir //*******************************************************************
348cdf0e10cSrcweir void SAL_CALL
refreshScriptStorage(const OUString & stringURI)349cdf0e10cSrcweir ScriptStorageManager::refreshScriptStorage( const OUString & stringURI )
350cdf0e10cSrcweir throw( RuntimeException )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir OSL_TRACE( "** => ScriptStorageManager in refreshScriptStorage\n" );
353cdf0e10cSrcweir OSL_TRACE( "** => refreshing URI: %s\n",
354cdf0e10cSrcweir ::rtl::OUStringToOString(
355cdf0e10cSrcweir stringURI, RTL_TEXTENCODING_ASCII_US ).pData->buffer);
356cdf0e10cSrcweir
357cdf0e10cSrcweir sal_Int32 storageID = getScriptStorageID( stringURI );
358cdf0e10cSrcweir
359cdf0e10cSrcweir if ( storageID == -1 )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir OSL_TRACE( "** id was -1, no storage");
362cdf0e10cSrcweir // Refreshing noexistent storage - just return
363cdf0e10cSrcweir return;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir
366cdf0e10cSrcweir try
367cdf0e10cSrcweir {
368cdf0e10cSrcweir Reference < storage::XScriptStorageRefresh > xSSR(
369cdf0e10cSrcweir getScriptStorage( storageID ), UNO_QUERY );
370cdf0e10cSrcweir
371cdf0e10cSrcweir xSSR->refresh();
372cdf0e10cSrcweir }
373cdf0e10cSrcweir catch ( RuntimeException & e )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir throw RuntimeException(
376cdf0e10cSrcweir OUSTR( "ScriptStorageManager::refreshScriptStorage: " ).concat(
377cdf0e10cSrcweir e.Message ), Reference< XInterface >() );
378cdf0e10cSrcweir }
379cdf0e10cSrcweir catch ( Exception & e )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir throw RuntimeException(
382cdf0e10cSrcweir OUSTR( "ScriptStorageManager::refreshScriptStorage: " ).concat(
383cdf0e10cSrcweir e.Message ), Reference< XInterface >() );
384cdf0e10cSrcweir }
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir //*************************************************************************
388cdf0e10cSrcweir void SAL_CALL
checkPermission(const OUString & scriptStorageURI,const OUString & permissionRequest)389cdf0e10cSrcweir ScriptStorageManager::checkPermission( const OUString &
390cdf0e10cSrcweir scriptStorageURI, const OUString & permissionRequest )
391cdf0e10cSrcweir throw ( RuntimeException, lang::IllegalArgumentException, css::security::AccessControlException )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir try
394cdf0e10cSrcweir {
395cdf0e10cSrcweir m_securityMgr.checkPermission( scriptStorageURI, permissionRequest );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir catch ( css::security::AccessControlException & e )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir throw css::security::AccessControlException(
400cdf0e10cSrcweir OUSTR( "ScriptStorageManager::checkPermission: AccessControlException: " ).concat(
401cdf0e10cSrcweir e.Message ), Reference< XInterface >(), e.LackingPermission );
402cdf0e10cSrcweir }
403cdf0e10cSrcweir catch ( lang::IllegalArgumentException & e )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir throw lang::IllegalArgumentException(
406cdf0e10cSrcweir OUSTR( "ScriptStorageManager::checkPermission: IllegalArgumentException: " ).concat(
407cdf0e10cSrcweir e.Message ), Reference< XInterface >(), e.ArgumentPosition );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir catch ( RuntimeException & e )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir throw RuntimeException(
412cdf0e10cSrcweir OUSTR( "ScriptStorageManager::checkPermission: RuntimeException: " ).concat(
413cdf0e10cSrcweir e.Message ), Reference< XInterface >() );
414cdf0e10cSrcweir }
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
417cdf0e10cSrcweir //*************************************************************************
418cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()419cdf0e10cSrcweir ScriptStorageManager::getImplementationName( )
420cdf0e10cSrcweir throw( RuntimeException )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir return s_implName;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir //*************************************************************************
426cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const OUString & serviceName)427cdf0e10cSrcweir ScriptStorageManager::supportsService( const OUString& serviceName )
428cdf0e10cSrcweir throw( RuntimeException )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir OUString const * pNames = s_serviceNames.getConstArray();
431cdf0e10cSrcweir for ( sal_Int32 nPos = s_serviceNames.getLength(); nPos--; )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir if ( serviceName.equals( pNames[ nPos ] ) )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir return sal_True;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir }
438cdf0e10cSrcweir return sal_False;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir //*************************************************************************
442cdf0e10cSrcweir Sequence< OUString > SAL_CALL
getSupportedServiceNames()443cdf0e10cSrcweir ScriptStorageManager::getSupportedServiceNames( )
444cdf0e10cSrcweir throw( RuntimeException )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir return s_serviceNames;
447cdf0e10cSrcweir }
448cdf0e10cSrcweir
449cdf0e10cSrcweir //*************************************************************************
450cdf0e10cSrcweir void SAL_CALL
disposing(const::com::sun::star::lang::EventObject & Source)451cdf0e10cSrcweir ScriptStorageManager::disposing( const ::com::sun::star::lang::EventObject& Source )
452cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir OSL_TRACE( "ScriptStorageManager::disposing started" );
455cdf0e10cSrcweir OSL_TRACE( "event object type=%s",
456cdf0e10cSrcweir ::rtl::OUStringToOString( getCppuType( &Source ).getTypeName(),
457cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
458cdf0e10cSrcweir OUString storageURI;
459cdf0e10cSrcweir bool removeSecurityPermission = true;
460cdf0e10cSrcweir try
461cdf0e10cSrcweir {
462cdf0e10cSrcweir Reference< XInterface > xInterface = Source.Source;
463cdf0e10cSrcweir // no UNO_QUERY_THROW since we want a 2nd change to query if it's
464cdf0e10cSrcweir // not a document being disposed
465cdf0e10cSrcweir Reference< frame::XModel > xModel = Reference< frame::XModel > ( xInterface, UNO_QUERY );
466cdf0e10cSrcweir if( xModel.is() )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir storageURI = xModel->getURL();
469cdf0e10cSrcweir }
470cdf0e10cSrcweir else
471cdf0e10cSrcweir {
472cdf0e10cSrcweir // UNO_QURY_THROW here since it's supposed to be either a doc
473cdf0e10cSrcweir // or a XScriptInfo (in the case of a filesys script)
474cdf0e10cSrcweir Reference< storage::XScriptInfo > xScriptInfo = Reference< storage::XScriptInfo > ( xInterface, UNO_QUERY_THROW );
475cdf0e10cSrcweir storageURI = xScriptInfo->getParcelURI().concat( xScriptInfo->getFunctionName() );
476cdf0e10cSrcweir // to save the user seeing the security dialogs every time they
477cdf0e10cSrcweir // run the script we hang on to the permission for a given script
478cdf0e10cSrcweir // for the lifetime of the Office
479cdf0e10cSrcweir removeSecurityPermission = false;
480cdf0e10cSrcweir // possibly need to encode it??
481cdf0e10cSrcweir }
482cdf0e10cSrcweir if ( storageURI.getLength() > 0 )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir OSL_TRACE( "URI disposing is ... %s",
485cdf0e10cSrcweir ::rtl::OUStringToOString( storageURI,
486cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir }
489cdf0e10cSrcweir catch ( RuntimeException& e )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir OUString message =
492cdf0e10cSrcweir OUSTR(
493cdf0e10cSrcweir "ScriptStorageManager::disposing: can't get script context, reason = " );
494cdf0e10cSrcweir message = message.concat( e.Message );
495cdf0e10cSrcweir OSL_TRACE( ::rtl::OUStringToOString( message,
496cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
497cdf0e10cSrcweir return;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir
500cdf0e10cSrcweir
501cdf0e10cSrcweir // grab storage id.
502cdf0e10cSrcweir sal_Int32 scriptStorageID = getScriptStorageID( storageURI );
503cdf0e10cSrcweir
504cdf0e10cSrcweir // no need to do anything if there's no doc storage
505cdf0e10cSrcweir if( scriptStorageID == -1 )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir return;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir
510cdf0e10cSrcweir OSL_TRACE( "disposing storageID = %d", scriptStorageID );
511cdf0e10cSrcweir
512cdf0e10cSrcweir // attempt to get the storage from the hash to ensure that we have a
513cdf0e10cSrcweir // valid storageID
514cdf0e10cSrcweir ScriptStorage_map::const_iterator itr =
515cdf0e10cSrcweir m_ScriptStorageMap.find( scriptStorageID );
516cdf0e10cSrcweir
517cdf0e10cSrcweir if ( itr == m_ScriptStorageMap.end() )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir OSL_TRACE( "Entry for storage id %d doesn't exist in map", scriptStorageID );
520cdf0e10cSrcweir return;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir // erase the entry from the hash
524cdf0e10cSrcweir m_ScriptStorageMap.erase( scriptStorageID );
525cdf0e10cSrcweir removeScriptDocURIHashEntry( storageURI );
526cdf0e10cSrcweir if ( removeSecurityPermission )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir m_securityMgr.removePermissionSettings ( storageURI );
529cdf0e10cSrcweir }
530cdf0e10cSrcweir }
531cdf0e10cSrcweir } // Namespace
532cdf0e10cSrcweir
533cdf0e10cSrcweir namespace scripting_runtimemgr
534cdf0e10cSrcweir {
535cdf0e10cSrcweir //*************************************************************************
536cdf0e10cSrcweir Reference< XInterface > SAL_CALL
ssm_create(const Reference<XComponentContext> & xCompC)537cdf0e10cSrcweir ssm_create(
538cdf0e10cSrcweir const Reference< XComponentContext > & xCompC )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir return ( cppu::OWeakObject * ) new ::scripting_impl::ScriptStorageManager( xCompC );
541cdf0e10cSrcweir }
542cdf0e10cSrcweir
543cdf0e10cSrcweir //*************************************************************************
544cdf0e10cSrcweir Sequence< OUString >
ssm_getSupportedServiceNames()545cdf0e10cSrcweir ssm_getSupportedServiceNames( )
546cdf0e10cSrcweir SAL_THROW( () )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir return ::scripting_impl::s_serviceNames;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
551cdf0e10cSrcweir //*************************************************************************
552cdf0e10cSrcweir OUString
ssm_getImplementationName()553cdf0e10cSrcweir ssm_getImplementationName( )
554cdf0e10cSrcweir SAL_THROW( () )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir return ::scripting_impl::s_implName;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir }
559