summaryrefslogtreecommitdiff
path: root/scripting/source/storage/ScriptStorageManager.hxx
blob: 4cabe11772bb989f706bfe3e686a0ca16eb757fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_

#include <hash_map>
#include <map>

#include <osl/mutex.hxx>
#include <cppuhelper/implbase4.hxx>

#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/security/AccessControlException.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>

#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
#include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp>
#include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp>
#include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
#include "ScriptSecurityManager.hxx"


namespace scripting_impl
{
// for simplification
#define css ::com::sun::star
#define dcsssf ::drafts::com::sun::star::script::framework

// Define a map used to store the ScriptingStorages key;d by ID
typedef ::std::map < sal_Int32, css::uno::Reference < css::uno::XInterface > >
    ScriptStorage_map;

typedef ::std::hash_map < ::rtl::OUString, sal_Int32, ::rtl::OUStringHash>
    StorageId_hash;

class ScriptStorageManager : public 
    ::cppu::WeakImplHelper4 < dcsssf::storage::XScriptStorageManager,
    dcsssf::security::XScriptSecurity, css::lang::XServiceInfo, 
    css::lang::XEventListener >
{
public:
    explicit ScriptStorageManager( 
        const css::uno::Reference< css::uno::XComponentContext > & xContext )
        SAL_THROW ( ( css::uno::RuntimeException ) );

    
    ~ScriptStorageManager() SAL_THROW ( () );
    
    // XServiceInfo implementation
    //======================================================================
    virtual ::rtl::OUString SAL_CALL getImplementationName()
        throw( css::uno::RuntimeException );
    //----------------------------------------------------------------------
    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
        throw( css::uno::RuntimeException );
    //----------------------------------------------------------------------
    virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 
        throw( css::uno::RuntimeException );
    //======================================================================

    //XScriptStorageManager
    //======================================================================
    /**
        create a ScriptStorage using the XSimpleFileAccess passed as an
        argument, and return a ID for getting the associated ScriptStorage

        @params xSFA
        an implementation of XSimpleFileAccess that knows its own base URL
        and can thus take URLs relative to that base.

        @returns an unsigned short ScriptStorage ID, which can be used in the
        getScriptStorage method
    */
    virtual sal_Int32 SAL_CALL createScriptStorage( 
            const css::uno::Reference< css::ucb::XSimpleFileAccess > & xSFA ) 
            throw ( css::uno::RuntimeException );
    //----------------------------------------------------------------------
    /**
        create a ScriptStorage using the XSimpleFileAccess, and a string URL
        and return a ID for getting the associated ScriptStorage

        @params xSFA
        a standard implementation of XSimpleFileAccess

        @params stringURI
        a string URI to the head of the script storage

        @returns an unsigned short ScriptStorage ID, which can be used in the
        getScriptStorage method
    */
    virtual sal_Int32 SAL_CALL 
        createScriptStorageWithURI( 
            const css::uno::Reference< css::ucb::XSimpleFileAccess >& xSFA, 
            const ::rtl::OUString& stringURI ) 
            throw ( css::uno::RuntimeException );
    //----------------------------------------------------------------------
    /**
        get a ScriptStorage component using its scriptStorageID

        @params scriptStorageID
        the usigned short returned by one of the methods above. ID=0 is 
        reserved for the application/share scripts, and ID=1 is reserved 
        for the application/user scripts

        @returns an XInterface to a component that implements the ScriptStorage
        service
    */
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getScriptStorage(
        sal_Int32 scriptStorageID ) 
        throw ( css::uno::RuntimeException );

    /**
        get a ScriptStorage ID using storage URI

        @param scriptStorageURI
        the file URL for the document will retrieve storage id for the document,        special treatment is reserved for the strings "USER"and "SHARE" which
        retrieve storage id for application/user application/share areas respectively.


        @returns as long ScriptStorage ID (-1 if no storage exists), which can be used in getScriptStorage method.

    */

    virtual sal_Int32 SAL_CALL getScriptStorageID( const ::rtl::OUString& scriptStorageURI ) 
        throw (::com::sun::star::uno::RuntimeException);

    /**
        refresh a storage component using its URI

        @param StringURI
        URI of storage area, for documents, url to document eg, file:///home/user/ADocument.sxw To refresh the storage for user or share area, use USER or SHARE respectively instead or a url.

    */

    virtual void SAL_CALL refreshScriptStorage(const ::rtl::OUString & stringURI)
    throw ( css::uno::RuntimeException );
    //======================================================================

    //XScriptSecurity
    //======================================================================
    //----------------------------------------------------------------------
    /**
        the language independent interface for invocation

        @param scriptURI
            a string containing the script URI

        @returns
            the value returned from the function being invoked

        @throws IllegalArgumentException
            if there is no matching script name

    */
    virtual void SAL_CALL ScriptStorageManager::checkPermission( 
        const rtl::OUString & scriptStorageURI, 
        const rtl::OUString & permissionRequest )
        throw ( css::uno::RuntimeException, css::lang::IllegalArgumentException,
            css::security::AccessControlException );
    //======================================================================
    
    //XEventListener
    //======================================================================

    virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) 
        throw ( css::uno::RuntimeException );

private:
    ScriptStorageManager( const ScriptStorageManager & );
    ScriptStorageManager& operator= ( const ScriptStorageManager & );

    void removeScriptDocURIHashEntry( const ::rtl::OUString & origURI );
    
    // to obtain other services if needed
    css::uno::Reference< css::uno::XComponentContext > m_xContext;
    css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
    ::osl::Mutex m_mutex;
    ScriptStorage_map m_ScriptStorageMap;
    StorageId_hash m_StorageIdOrigURIHash;
    sal_Int32 m_count;
    scripting_securitymgr::ScriptSecurityManager m_securityMgr;

    void setupAppStorage( const css::uno::Reference< css::util::XMacroExpander > & xME,
        const ::rtl::OUString & storageStr,
        const ::rtl::OUString & appStr)
        SAL_THROW ( ( css::uno::RuntimeException ) );

    sal_Int32 setupAnyStorage( 
        const css::uno::Reference< css::ucb::XSimpleFileAccess> & xSFA,
        const ::rtl::OUString & storageStr,
        const ::rtl::OUString & origStringURI )
        SAL_THROW ( ( css::uno::RuntimeException ) );

};
} // scripting_impl

#endif //_COM_SUN_STAR_SCRIPTING_STORAGE_SCRIPTSTORAGEMANAGER_HXX_