/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void SAL_CALL MasterScriptProvider::initialize( const Sequence < Any >& args )
{ if ( m_bInitialised ) return;
m_bIsValid = false;
sal_Int32 len = args.getLength(); if ( len > 1 )
{ throw RuntimeException(
u"MasterScriptProvider::initialize: invalid number of arguments"_ustr );
}
Sequence< Any > invokeArgs( len );
if ( len != 0 )
{ auto pinvokeArgs = invokeArgs.getArray(); // check if first parameter is a string // if it is, this implies that this is a MSP created // with a user or share ctx ( used for browse functionality )
if ( m_xModel.is() )
{ // from the arguments, we were able to deduce a model. That alone doesn't // suffice, we also need an XEmbeddedScripts which actually indicates support // for embedding scripts
Reference< XEmbeddedScripts > xScripts( m_xModel, UNO_QUERY ); if ( !xScripts.is() )
{ throw lang::IllegalArgumentException(
u"The given document does not support embedding scripts into it, and cannot be associated with such a document."_ustr,
*this,
1
);
}
// if script us located in uno pkg
sal_Int32 index = -1;
OUString pkgTag(u":uno_packages"_ustr); // for languages other than basic, scripts located in uno packages // are merged into the user/share location context. // For other languages the location attribute in script url has the form // location = [user|share]:uno_packages or location :uno_packages/xxxx.uno.pkg // we need to extract the value of location part from the // location attribute of the script, if the script is located in an // uno package then that is the location part up to and including // ":uno_packages", if the script is not in a uno package then the // normal value is used e.g. user or share. // The value extracted will be used to determine if the script is // located in the same location context as this MSP. // For Basic, the language script provider can handle the execution of a // script in any location context if ( ( index = location.indexOf( pkgTag ) ) > -1 )
{
location = location.copy( 0, index + pkgTag.getLength() );
}
Reference< provider::XScript > xScript;
// If the script location is in the same location context as this // MSP then delete to the language provider controlled by this MSP // ** Special case is BASIC, all calls to getScript will be handled // by the language script provider in the current location context // even if it's different if ( ( location == "document"
&& m_xModel.is()
)
|| ( endsWith( m_sCtxString, location ) )
|| ( language == "Basic" )
)
{
Reference< provider::XScriptProvider > xScriptProvider;
OUString serviceName = "com.sun.star.script.provider.ScriptProviderFor" + language; if ( !providerCache() )
{ throw provider::ScriptFrameworkErrorException(
u"No LanguageProviders detected"_ustr,
Reference< XInterface >(),
sfUri->getName(), language,
provider::ScriptFrameworkErrorType::NOTSUPPORTED );
}
Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY_THROW );
xCont->insertByName( aName, aElement );
} else
{
Reference< deployment::XPackage > xPkg( aElement, UNO_QUERY ); if ( !xPkg.is() )
{ throw lang::IllegalArgumentException( u"Couldn't convert to XPackage"_ustr,
Reference < XInterface > (), 2 );
} if ( aName.isEmpty() )
{ throw lang::IllegalArgumentException( u"Name not set!!"_ustr,
Reference < XInterface > (), 1 );
} // TODO for library package parse the language, for the moment will try // to get each provider to process the new Package, the first one the succeeds // will terminate processing constbool bSuccess = FindProviderAndApply(
*providerCache(), [&aName, &aElement](Reference<container::XNameContainer>& xCont) {
xCont->insertByName(aName, aElement); returntrue;
}); if (!bSuccess)
{ // No script providers could process the package throw lang::IllegalArgumentException( "Failed to register package for " + aName,
Reference < XInterface > (), 2 );
}
}
}
// Revoke Package void SAL_CALL
MasterScriptProvider::removeByName( const OUString& Name )
{ if ( !m_bIsPkgMSP )
{ if ( !m_xMSPPkg.is() )
{ throw RuntimeException( u"PackageMasterScriptProvider is uninitialised"_ustr );
}
Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY_THROW );
xCont->removeByName( Name );
} else
{ if ( Name.isEmpty() )
{ throw lang::IllegalArgumentException( u"Name not set!!"_ustr,
Reference < XInterface > (), 1 );
} // TODO for Script library package url parse the language, // for the moment will just try to get each provider to process remove/revoke // request, the first one the succeeds will terminate processing constbool bSuccess = FindProviderAndApply(
*providerCache(), [&Name](Reference<container::XNameContainer>& xCont) {
xCont->removeByName(Name); returntrue;
}); if (!bSuccess)
{ // No script providers could process the package throw lang::IllegalArgumentException( "Failed to revoke package for " + Name,
Reference < XInterface > (), 1 );
}
Any SAL_CALL
MasterScriptProvider::getByName( const OUString& /*aName*/ )
{ // TODO needs to be implemented throw RuntimeException( u"getByName not implemented!!!!"_ustr );
}
sal_Bool SAL_CALL
MasterScriptProvider::hasByName( const OUString& aName )
{ bool result = false; if ( !m_bIsPkgMSP )
{ if ( m_xMSPPkg.is() )
{
Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY_THROW );
result = xCont->hasByName( aName );
} // If this is a document provider then we shouldn't // have a PackageProvider elseif (!m_xModel.is())
{ throw RuntimeException( u"PackageMasterScriptProvider is uninitialised"_ustr );
}
} else
{ if ( aName.isEmpty() )
{ throw lang::IllegalArgumentException( u"Name not set!!"_ustr,
Reference < XInterface > (), 1 );
} // TODO for Script library package url parse the language, // for the moment will just try to get each provider to see if the // package exists in any provider, first one that succeed will // terminate the loop
result = FindProviderAndApply(
*providerCache(), [&aName](Reference<container::XNameContainer>& xCont) { return xCont->hasByName(aName);
});
} return result;
}
Sequence< OUString > SAL_CALL
MasterScriptProvider::getElementNames( )
{ // TODO needs implementing throw RuntimeException( u"getElementNames not implemented!!!!"_ustr );
}
Type SAL_CALL
MasterScriptProvider::getElementType( )
{ // TODO needs implementing
Type t; return t;
}
sal_Bool SAL_CALL MasterScriptProvider::hasElements( )
{ // TODO needs implementing throw RuntimeException( u"hasElements not implemented!!!!"_ustr );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.