You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2020/07/26 16:57:44 UTC

[openoffice] branch AOO42X updated (6728657 -> 4277327)

This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a change to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git.


    from 6728657  Updated graphic for helpagent
     new 7110543  Update com.sun.star.comp.ScriptProtocolHandler to use XComponentContext.
     new 4277327  Improve parsing of script URLs and detection of in-document macros therein, as per the excellent sample code in main/dbaccess/source/ext/macromigration/migrationengine.cxx method MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow().

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../source/protocolhandler/scripthandler.cxx       | 93 +++++++---------------
 .../source/protocolhandler/scripthandler.hxx       |  9 +--
 main/sfx2/source/doc/objmisc.cxx                   | 19 +++--
 3 files changed, 45 insertions(+), 76 deletions(-)


[openoffice] 02/02: Improve parsing of script URLs and detection of in-document macros therein, as per the excellent sample code in main/dbaccess/source/ext/macromigration/migrationengine.cxx method MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow().

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 427732704c1ee941d594b77f2cdee11f8a179eb1
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sat Jul 25 17:23:57 2020 +0200

    Improve parsing of script URLs and detection of in-document
    macros therein, as per the excellent sample code in
    main/dbaccess/source/ext/macromigration/migrationengine.cxx
    method MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow().
    
    Patch by: me
    
    (cherry picked from commit 15daf3925bdc140e28ef7cd246a147feaed4ea47)
---
 .../source/protocolhandler/scripthandler.cxx          |  9 +++++----
 main/sfx2/source/doc/objmisc.cxx                      | 19 +++++++++++++------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/main/scripting/source/protocolhandler/scripthandler.cxx b/main/scripting/source/protocolhandler/scripthandler.cxx
index 0a1b7b0..d064fde 100644
--- a/main/scripting/source/protocolhandler/scripthandler.cxx
+++ b/main/scripting/source/protocolhandler/scripthandler.cxx
@@ -41,7 +41,6 @@
 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
 #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
 
-#include <rtl/uri.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/frame.hxx>
 #include <sfx2/sfxdlg.hxx>
@@ -59,6 +58,7 @@
 #include "com/sun/star/uri/UriReferenceFactory.hpp"
 #include "com/sun/star/uri/XUriReferenceFactory.hpp"
 #include "com/sun/star/uri/XVndSunStarScriptUrl.hpp"
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
 #include "com/sun/star/beans/XPropertySet.hpp"
 
 using namespace ::com::sun::star;
@@ -161,9 +161,10 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
     {
         try
         {
-            ::rtl::OUString xStringUri = ::rtl::Uri::decode( aURL.Complete,
-                rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
-            bool bIsDocumentScript = ( xStringUri.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "document" ) ) !=-1 );
+            Reference< uri::XUriReferenceFactory > xFac( uri::UriReferenceFactory::create( m_xCtx ) );
+            Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( aURL.Complete ), UNO_QUERY_THROW );
+            ::rtl::OUString sLocation = xScriptUri->getParameter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) );
+            bool bIsDocumentScript = ( sLocation == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ) );
 
             if ( bIsDocumentScript )
             {
diff --git a/main/sfx2/source/doc/objmisc.cxx b/main/sfx2/source/doc/objmisc.cxx
index 7f66da7..90c7c67 100644
--- a/main/sfx2/source/doc/objmisc.cxx
+++ b/main/sfx2/source/doc/objmisc.cxx
@@ -75,6 +75,9 @@
 #include <com/sun/star/task/ErrorCodeRequest.hpp>
 #include <unotools/securityoptions.hxx>
 
+#include "com/sun/star/uri/XUriReferenceFactory.hpp"
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
+
 #include <comphelper/processfactory.hxx>
 #include <comphelper/componentcontext.hxx>
 #include <comphelper/configurationhelper.hxx>
@@ -1695,16 +1698,20 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon
     OSL_TRACE( "in CallXScript" );
 	ErrCode nErr = ERRCODE_NONE;
 
-    bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
-        // TODO: we should parse the URL, and check whether there is a parameter with this name.
-        // Otherwise, we might find too much.
-    if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
-        return ERRCODE_IO_ACCESSDENIED;
-
 	bool bCaughtException = false;
     Any aException;
     try
     {
+        uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+        Reference< uri::XUriReferenceFactory > xFac (
+            xServiceManager->createInstance( rtl::OUString::createFromAscii(
+                "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY_THROW );
+        Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( _rScriptURL ), UNO_QUERY_THROW );
+        ::rtl::OUString sLocation = xScriptUri->getParameter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) );
+        bool bIsDocumentScript = ( sLocation == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ) );
+        if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
+            return ERRCODE_IO_ACCESSDENIED;
+
         // obtain/create a script provider
         Reference< provider::XScriptProvider > xScriptProvider;
         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );


[openoffice] 01/02: Update com.sun.star.comp.ScriptProtocolHandler to use XComponentContext.

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 7110543d1c471f991649a4ad41f7ee4272218010
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sat Jul 25 16:05:38 2020 +0200

    Update com.sun.star.comp.ScriptProtocolHandler to use XComponentContext.
    
    As per https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Component_Context
    XMultiServiceFactory is deprecated, we use XComponentContext now. Also
    use the cppuhelper factory wrappers instead of custom code.
    
    Patch by: me
    
    (cherry picked from commit 02463baf75258a73e9b3f81ff773a0a77b4fb7a4)
---
 .../source/protocolhandler/scripthandler.cxx       | 84 ++++++----------------
 .../source/protocolhandler/scripthandler.hxx       |  9 ++-
 2 files changed, 27 insertions(+), 66 deletions(-)

diff --git a/main/scripting/source/protocolhandler/scripthandler.cxx b/main/scripting/source/protocolhandler/scripthandler.cxx
index f7cf661..0a1b7b0 100644
--- a/main/scripting/source/protocolhandler/scripthandler.cxx
+++ b/main/scripting/source/protocolhandler/scripthandler.cxx
@@ -50,11 +50,13 @@
 
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/exc_hlp.hxx>
+#include <cppuhelper/implementationentry.hxx>
 #include <util/util.hxx>
 #include <framework/documentundoguard.hxx>
 
 #include "com/sun/star/uno/XComponentContext.hpp"
 #include "com/sun/star/uri/XUriReference.hpp"
+#include "com/sun/star/uri/UriReferenceFactory.hpp"
 #include "com/sun/star/uri/XUriReferenceFactory.hpp"
 #include "com/sun/star/uri/XVndSunStarScriptUrl.hpp"
 #include "com/sun/star/beans/XPropertySet.hpp"
@@ -77,6 +79,8 @@ const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler";
 const sal_Char * MYSCHEME = "vnd.sun.star.script";
 const sal_Int32 MYSCHEME_LEN = 20;
 
+rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
+
 void SAL_CALL ScriptProtocolHandler::initialize( 
     const css::uno::Sequence < css::uno::Any >& aArguments )
     throw ( css::uno::Exception )
@@ -95,7 +99,7 @@ void SAL_CALL ScriptProtocolHandler::initialize(
         throw RuntimeException( temp, Reference< XInterface >() );
     }
 
-    ENSURE_OR_THROW( m_xFactory.is(), "ScriptProtocolHandler::initialize: No Service Manager available" );
+    ENSURE_OR_THROW( m_xCtx.is(), "ScriptProtocolHandler::initialize: No Component Context available" );
     m_bInitialised = true;
 }
 
@@ -109,9 +113,7 @@ Reference< XDispatch > SAL_CALL ScriptProtocolHandler::queryDispatch(
     Reference< XDispatch > xDispatcher;
     // get scheme of url
 
-    Reference< uri::XUriReferenceFactory > xFac ( 
-         m_xFactory->createInstance( rtl::OUString::createFromAscii( 
-            "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY );
+    Reference< uri::XUriReferenceFactory > xFac ( uri::UriReferenceFactory::create( m_xCtx ) );
     if ( xFac.is() )
     {
         Reference<  uri::XUriReference > uriRef(
@@ -431,19 +433,11 @@ void ScriptProtocolHandler::createScriptProvider()
         // if nothing of this is successful, use the master script provider
         if ( !m_xScriptProvider.is() )
         {
-            Reference< XPropertySet > xProps( m_xFactory, UNO_QUERY_THROW );
-
-            ::rtl::OUString dc(
-                RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) );
-
-            Reference< XComponentContext > xCtx(
-                xProps->getPropertyValue( dc ), UNO_QUERY_THROW );
-
             ::rtl::OUString tmspf = ::rtl::OUString::createFromAscii(
                 "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory");
 
             Reference< provider::XScriptProviderFactory > xFac(
-                xCtx->getValueByName( tmspf ), UNO_QUERY_THROW );
+                m_xCtx->getValueByName( tmspf ), UNO_QUERY_THROW );
                                                                                 
             Any aContext;
             if ( getScriptInvocation() )
@@ -465,8 +459,8 @@ void ScriptProtocolHandler::createScriptProvider()
 }
 
 ScriptProtocolHandler::ScriptProtocolHandler(
-Reference< css::lang::XMultiServiceFactory > const& rFact ) :
-m_bInitialised( false ), m_xFactory( rFact )
+Reference< css::uno::XComponentContext > const& xCtx ) :
+m_bInitialised( false ), m_xCtx( xCtx )
 {
 }
 
@@ -524,24 +518,24 @@ Sequence< ::rtl::OUString > ScriptProtocolHandler::impl_getStaticSupportedServic
 
 /* Helper for registry */
 Reference< XInterface > SAL_CALL ScriptProtocolHandler::impl_createInstance(
-const Reference< css::lang::XMultiServiceFactory >& xServiceManager )
+const Reference< css::uno::XComponentContext > & xCtx)
 throw( RuntimeException )
 {
-    return Reference< XInterface > ( *new ScriptProtocolHandler( xServiceManager ) );
+    return Reference < XInterface >( *new ScriptProtocolHandler( xCtx ) );
 }
 
-/* Factory for registration */
-Reference< XSingleServiceFactory > ScriptProtocolHandler::impl_createFactory(
-const Reference< XMultiServiceFactory >& xServiceManager )
+static struct ::cppu::ImplementationEntry g_entries[] =
 {
-    Reference< XSingleServiceFactory > xReturn (
-        cppu::createSingleFactory( xServiceManager,
-            ScriptProtocolHandler::impl_getStaticImplementationName(),
-            ScriptProtocolHandler::impl_createInstance,
-            ScriptProtocolHandler::impl_getStaticSupportedServiceNames() )
-    );
-    return xReturn;
-}
+    {
+        ScriptProtocolHandler::impl_createInstance,
+        ScriptProtocolHandler::impl_getStaticImplementationName,
+        ScriptProtocolHandler::impl_getStaticSupportedServiceNames,
+        ::cppu::createSingleComponentFactory,
+        &g_moduleCount.modCnt,
+        0
+    },
+    { 0, 0, 0, 0, 0, 0 }
+};
 
 } // namespace scripting_protocolhandler
 
@@ -564,39 +558,7 @@ extern "C"
                                          void * pServiceManager ,
                                          void * pRegistryKey )
     {
-		(void)pRegistryKey;
-
-        // Set default return value for this operation - if it failed.
-        void * pReturn = NULL ;
-
-        if (
-            ( pImplementationName != NULL ) &&
-            ( pServiceManager != NULL )
-        )
-        {
-            // Define variables which are used in following macros.
-            ::com::sun::star::uno::Reference<
-            ::com::sun::star::lang::XSingleServiceFactory > xFactory ;
-            ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 
-            xServiceManager( reinterpret_cast<
-            ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ;
-
-            if ( ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName().equals(
-                ::rtl::OUString::createFromAscii( pImplementationName ) ) )
-            {
-                xFactory = ::scripting_protocolhandler::ScriptProtocolHandler::impl_createFactory( xServiceManager );
-            }
-
-            // Factory is valid - service was found.
-            if ( xFactory.is() )
-            {
-                xFactory->acquire();
-                pReturn = xFactory.get();
-            }
-        }
-
-        // Return with result of this operation.
-        return pReturn ;
+        return component_getFactoryHelper( pImplementationName, pServiceManager, pRegistryKey, scripting_protocolhandler::g_entries );
     }
 } // extern "C"
 
diff --git a/main/scripting/source/protocolhandler/scripthandler.hxx b/main/scripting/source/protocolhandler/scripthandler.hxx
index dee3d1c..afa30ff 100644
--- a/main/scripting/source/protocolhandler/scripthandler.hxx
+++ b/main/scripting/source/protocolhandler/scripthandler.hxx
@@ -44,6 +44,7 @@ namespace com { namespace sun { namespace star {
     }
     namespace uno {
         class Any;
+        class XComponentContext;
     }
     namespace lang {
         class XMultiServiceFactory;
@@ -76,7 +77,7 @@ public ::cppu::WeakImplHelper4< css::frame::XDispatchProvider,
 {
 private:
     bool m_bInitialised;
-    css::uno::Reference < css::lang::XMultiServiceFactory >         m_xFactory;
+    css::uno::Reference < css::uno::XComponentContext >             m_xCtx;
     css::uno::Reference < css::frame::XFrame >                      m_xFrame;
     css::uno::Reference < css::script::provider::XScriptProvider >  m_xScriptProvider;
     css::uno::Reference< css::document::XScriptInvocationContext >  m_xScriptInvocation;
@@ -86,7 +87,7 @@ private:
 
 public:
     ScriptProtocolHandler( const css::uno::Reference < 
-        css::lang::XMultiServiceFactory >& xFactory );
+        css::uno::XComponentContext >& xCtx );
     virtual ~ScriptProtocolHandler();
 
     /* XServiceInfo */
@@ -104,10 +105,8 @@ public:
     /* Helper for registry */
     static css::uno::Reference < css::uno::XInterface > SAL_CALL
     impl_createInstance( 
-        const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager )
+        const css::uno::Reference< css::uno::XComponentContext >& xCtx )
     throw( css::uno::RuntimeException );
-    static css::uno::Reference < css::lang::XSingleServiceFactory > impl_createFactory(
-        const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
 
     /* Implementation for XDispatchProvider */
     virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL