You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2020/07/25 15:28:04 UTC

[openoffice] branch trunk updated (053307f -> 15daf39)

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

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


    from 053307f  Updated link in SDK
     new 02463ba  Update com.sun.star.comp.ScriptProtocolHandler to use XComponentContext.
     new 15daf39  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 da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 15daf3925bdc140e28ef7cd246a147feaed4ea47
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
---
 .../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 da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 02463baf75258a73e9b3f81ff773a0a77b4fb7a4
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
---
 .../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


Re: [openoffice] branch trunk updated (053307f -> 15daf39)

Posted by Damjan Jovanovic <da...@apache.org>.
Hi

Thank you.

I've been testing them, they work.

Regards
Damjan


On Sun, Jul 26, 2020 at 5:54 PM Matthias Seidel <ma...@hamburg.de>
wrote:

> Hi Damjan,
>
> The Windows buildbot for trunk did succeed and I don't see any problems.
> But is there any way to test your changes?
>
> I would like to cherry-pick these commits for AOO42X.
>
> Regards,
>
>    Matthias
>
> Am 25.07.20 um 17:28 schrieb damjan@apache.org:
> > This is an automated email from the ASF dual-hosted git repository.
> >
> > damjan pushed a change to branch trunk
> > in repository https://gitbox.apache.org/repos/asf/openoffice.git.
> >
> >
> >     from 053307f  Updated link in SDK
> >      new 02463ba  Update com.sun.star.comp.ScriptProtocolHandler to use
> XComponentContext.
> >      new 15daf39  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(-)
> >
>
>

Re: [openoffice] branch trunk updated (053307f -> 15daf39)

Posted by Matthias Seidel <ma...@hamburg.de>.
Hi Damjan,

The Windows buildbot for trunk did succeed and I don't see any problems.
But is there any way to test your changes?

I would like to cherry-pick these commits for AOO42X.

Regards,

   Matthias

Am 25.07.20 um 17:28 schrieb damjan@apache.org:
> This is an automated email from the ASF dual-hosted git repository.
>
> damjan pushed a change to branch trunk
> in repository https://gitbox.apache.org/repos/asf/openoffice.git.
>
>
>     from 053307f  Updated link in SDK
>      new 02463ba  Update com.sun.star.comp.ScriptProtocolHandler to use XComponentContext.
>      new 15daf39  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(-)
>