diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2017-06-08 14:25:50 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-06-09 13:17:14 +0200 |
commit | 0f1d081a3c3ad44b07e02d98b75e6c41696ead22 (patch) | |
tree | 715f0e2d5d792a686085c0ea8c7b62b87b70ac9e /desktop | |
parent | 320179612c6dc8be39eaf27de0fc7c8575e160ff (diff) |
Add --script-cat parameter to dump scripts content.
Also factor out over-long print method into its own helper.
Change-Id: Ica98dc9c999d5655e78662774e0140d70369d0b7
Reviewed-on: https://gerrit.libreoffice.org/38579
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/38602
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/app/app.cxx | 1 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.cxx | 7 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.hxx | 2 | ||||
-rw-r--r-- | desktop/source/app/cmdlinehelp.cxx | 3 | ||||
-rw-r--r-- | desktop/source/app/dispatchwatcher.cxx | 229 | ||||
-rw-r--r-- | desktop/source/app/dispatchwatcher.hxx | 14 | ||||
-rw-r--r-- | desktop/source/app/officeipcthread.cxx | 20 | ||||
-rw-r--r-- | desktop/source/app/officeipcthread.hxx | 5 |
8 files changed, 191 insertions, 90 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index 1f9307d0c26f..796cc71df6b8 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -2187,6 +2187,7 @@ void Desktop::OpenClients() aRequest.aConversionOut = rArgs.GetConversionOut(); aRequest.aInFilter = rArgs.GetInFilter(); aRequest.bTextCat = rArgs.IsTextCat(); + aRequest.bScriptCat = rArgs.IsScriptCat(); if ( !aRequest.aOpenList.empty() || !aRequest.aViewList.empty() || diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index 07dee1b60aa8..cefcaa55a625 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -339,6 +339,12 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) eCurrentEvent = CommandLineEvent::Conversion; setHeadless(); } + else if ( oArg == "script-cat" ) + { + m_scriptcat = true; + eCurrentEvent = CommandLineEvent::Conversion; + setHeadless(); + } else if ( oArg == "quickstart" ) { #if defined(ENABLE_QUICKSTART_APPLET) @@ -706,6 +712,7 @@ void CommandLineArgs::InitParamValues() m_bEmpty = true; m_bDocumentArgs = false; m_textcat = false; + m_scriptcat = false; m_safemode = false; } diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx index 7a52e042016d..78c5057a3d54 100644 --- a/desktop/source/app/cmdlineargs.hxx +++ b/desktop/source/app/cmdlineargs.hxx @@ -93,6 +93,7 @@ class CommandLineArgs bool HasModuleParam() const; bool WantsToLoadDocument() const { return m_bDocumentArgs;} bool IsTextCat() const { return m_textcat;} + bool IsScriptCat() const { return m_scriptcat;} bool IsSafeMode() const { return m_safemode; } const OUString& GetUnknown() const { return m_unknown;} @@ -157,6 +158,7 @@ class CommandLineArgs bool m_version; bool m_splashpipe; bool m_textcat; + bool m_scriptcat; bool m_safemode; OUString m_unknown; diff --git a/desktop/source/app/cmdlinehelp.cxx b/desktop/source/app/cmdlinehelp.cxx index aaa6af9830b9..e3e4539e9ab0 100644 --- a/desktop/source/app/cmdlinehelp.cxx +++ b/desktop/source/app/cmdlinehelp.cxx @@ -133,6 +133,9 @@ namespace desktop "--cat files\n"\ " Dump text content of the files to console\n"\ " Eg. --cat *.odt\n"\ + "--script-cat\n"\ + " Dump text content of any scripts embedded in the files to console\n" + " Eg. --script-cat *.xls\n" "--pidfile=file\n"\ " Store soffice.bin pid to file.\n"\ "-env:<VAR>[=<VALUE>]\n"\ diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 3bbb191da359..da9a31930b17 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -50,6 +50,10 @@ #include <com/sun/star/document/XTypeDetection.hpp> #include <com/sun/star/document/UpdateDocMode.hpp> #include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/script/ModuleInfo.hpp> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/script/XLibraryContainer2.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> #include <tools/urlobj.hxx> #include <unotools/mediadescriptor.hxx> @@ -69,6 +73,7 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::view; using namespace ::com::sun::star::task; +using namespace ::com::sun::star::document; namespace document = ::com::sun::star::document; @@ -129,32 +134,31 @@ std::shared_ptr<const SfxFilter> impl_lookupExportFilterForUrl( const rtl::OUStr std::shared_ptr<const SfxFilter> impl_getExportFilterFromUrl( const rtl::OUString& rUrl, const rtl::OUString& rFactory) { -try -{ - const Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); - const Reference< document::XTypeDetection > xTypeDetector( + try + { + const Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); + const Reference< document::XTypeDetection > xTypeDetector( xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.TypeDetection", xContext ), UNO_QUERY_THROW ); - const rtl::OUString aTypeName( xTypeDetector->queryTypeByURL( rUrl ) ); + const rtl::OUString aTypeName( xTypeDetector->queryTypeByURL( rUrl ) ); - std::shared_ptr<const SfxFilter> pFilter( SfxFilterMatcher( rFactory ).GetFilter4EA( aTypeName, SfxFilterFlags::EXPORT ) ); - if ( !pFilter ) - pFilter = impl_lookupExportFilterForUrl( rUrl, rFactory ); - if ( !pFilter ) - { - OUString aTempName; - FileBase::getSystemPathFromFileURL( rUrl, aTempName ); - OString aSource = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); - std::cerr << "Error: no export filter for " << aSource << " found, aborting." << std::endl; + std::shared_ptr<const SfxFilter> pFilter( SfxFilterMatcher( rFactory ).GetFilter4EA( aTypeName, SfxFilterFlags::EXPORT ) ); + if ( !pFilter ) + pFilter = impl_lookupExportFilterForUrl( rUrl, rFactory ); + if ( !pFilter ) + { + OUString aTempName; + FileBase::getSystemPathFromFileURL( rUrl, aTempName ); + OString aSource = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); + std::cerr << "Error: no export filter for " << aSource << " found, aborting." << std::endl; + } + return pFilter; + } + catch ( const Exception& ) + { + return nullptr; } - - return pFilter; -} -catch ( const Exception& ) -{ - return nullptr; -} } OUString impl_GuessFilter( const OUString& rUrlOut, const OUString& rDocService ) @@ -167,8 +171,108 @@ OUString impl_GuessFilter( const OUString& rUrlOut, const OUString& rDocService return aOutFilter; } +/// dump scripts in a document to the console. +void scriptCat(const Reference< XModel >& xDoc ) +{ + Reference< XEmbeddedScripts > xScriptAccess( xDoc, UNO_QUERY ); + if (!xScriptAccess.is()) + { + std::cout << "No script access\n"; + return; + } + + // ignore xScriptAccess->getDialogLibraries() for now + Reference< css::script::XLibraryContainer2 > xLibraries( + xScriptAccess->getBasicLibraries() ); + + if ( !xLibraries.is() ) + { + std::cout << "No script libraries\n"; + return; + } + + Sequence< OUString > aLibNames = xLibraries->getElementNames(); + std::cout << "Libraries: " << aLibNames.getLength() << "\n"; + for ( sal_Int32 i = 0 ; i < aLibNames.getLength() ; ++i ) + { + std::cout << "Library: '" << aLibNames[i] << "' children: "; + Reference< XNameContainer > xContainer( + xLibraries->getByName( aLibNames[i] ), UNO_QUERY ); + if( !xContainer.is() ) + std::cout << "0\n"; + else + { + Sequence< OUString > aObjectNames = xContainer->getElementNames(); + + std::cout << aObjectNames.getLength() << "\n\n"; + for ( sal_Int32 j = 0 ; j < aObjectNames.getLength() ; ++j ) + { + rtl::OUString &rObjectName = aObjectNames[j]; + + rtl::OUString aCodeString; + Any aCode = xContainer->getByName( rObjectName ); + + if (! (aCode >>= aCodeString ) ) + std::cout << "[" << rObjectName << "] - error fetching code\n"; + else + std::cout << "[" << rObjectName << "]\n" + << aCodeString.trim() + << "\n[/" << rObjectName << "]\n"; + if (j < aObjectNames.getLength() - 1) + std::cout << "\n----------------------------------------------------------\n"; + std::cout << "\n"; + } + } + } +} + +// Perform batch print +void batchPrint( const OUString &rPrinterName, const Reference< XPrintable > &xDoc, + const INetURLObject &aObj, const OUString &aName ) +{ + OUString aFilterOut; + OUString aPrinterName; + sal_Int32 nPathIndex = rPrinterName.lastIndexOf( ';' ); + if( nPathIndex != -1 ) + aFilterOut=rPrinterName.copy( nPathIndex+1 ); + if( nPathIndex != 0 ) + aPrinterName=rPrinterName.copy( 0, nPathIndex ); + + INetURLObject aOutFilename( aObj ); + aOutFilename.SetExtension( "ps" ); + FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut ); + OUString aOutFile = aFilterOut + "/" + aOutFilename.getName(); + + OUString aTempName; + FileBase::getSystemPathFromFileURL( aName, aTempName ); + OString aSource8 = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); + FileBase::getSystemPathFromFileURL( aOutFile, aTempName ); + OString aTargetURL8 = OUStringToOString(aTempName, osl_getThreadTextEncoding() ); + + std::cout << "print " << aSource8 << " -> " << aTargetURL8; + std::cout << " using " << (aPrinterName.isEmpty() ? "<default_printer>" : OUStringToOString( aPrinterName, osl_getThreadTextEncoding() )); + std::cout << std::endl; + + // create the custom printer, if given + Sequence < PropertyValue > aPrinterArgs( 1 ); + if( !aPrinterName.isEmpty() ) + { + aPrinterArgs[0].Name = "Name"; + aPrinterArgs[0].Value <<= aPrinterName; + xDoc->setPrinter( aPrinterArgs ); + } + + // print ( also without user interaction ) + aPrinterArgs.realloc(2); + aPrinterArgs[0].Name = "FileName"; + aPrinterArgs[0].Value <<= aOutFile; + aPrinterArgs[1].Name = "Wait"; + aPrinterArgs[1].Value <<= true; + xDoc->print( aPrinterArgs ); } +} // anonymous namespace + DispatchWatcher::DispatchWatcher() : m_nRequestCount(0) { @@ -210,7 +314,8 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest aDispatchRequest.aRequestType == REQUEST_PRINTTO || aDispatchRequest.aRequestType == REQUEST_BATCHPRINT || aDispatchRequest.aRequestType == REQUEST_CONVERSION || - aDispatchRequest.aRequestType == REQUEST_CAT) + aDispatchRequest.aRequestType == REQUEST_CAT || + aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT) nCount++; Sequence < PropertyValue > aArgs( nCount ); @@ -223,7 +328,8 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest aDispatchRequest.aRequestType == REQUEST_PRINTTO || aDispatchRequest.aRequestType == REQUEST_BATCHPRINT || aDispatchRequest.aRequestType == REQUEST_CONVERSION || - aDispatchRequest.aRequestType == REQUEST_CAT) + aDispatchRequest.aRequestType == REQUEST_CAT || + aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT) { aArgs[1].Name = "ReadOnly"; aArgs[2].Name = "OpenNewView"; @@ -260,7 +366,8 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest aDispatchRequest.aRequestType == REQUEST_PRINTTO || aDispatchRequest.aRequestType == REQUEST_BATCHPRINT || aDispatchRequest.aRequestType == REQUEST_CONVERSION || - aDispatchRequest.aRequestType == REQUEST_CAT) + aDispatchRequest.aRequestType == REQUEST_CAT || + aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT ) { // documents opened for printing are opened readonly because they must be opened as a new document and this // document could be open already @@ -447,11 +554,16 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest aDispatchRequest.aRequestType == REQUEST_PRINTTO || aDispatchRequest.aRequestType == REQUEST_BATCHPRINT || aDispatchRequest.aRequestType == REQUEST_CONVERSION || - aDispatchRequest.aRequestType == REQUEST_CAT ) + aDispatchRequest.aRequestType == REQUEST_CAT || + aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT ) { if ( xDoc.is() ) { - if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION || aDispatchRequest.aRequestType == REQUEST_CAT ) { + // Do we need to save the document in a different format? + if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION || + aDispatchRequest.aRequestType == REQUEST_CAT ) + { +// FIXME: factor out into a method ... Reference< XStorable > xStorable( xDoc, UNO_QUERY ); if ( xStorable.is() ) { OUString aParam = aDispatchRequest.aPrinterName; @@ -478,9 +590,7 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest INetURLObject aOutFilename( aObj ); aOutFilename.SetExtension( aFilterExt ); FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut ); - OUString aOutFile = aFilterOut+ - "/" + - aOutFilename.getName(); + OUString aOutFile = aFilterOut + "/" + aOutFilename.getName(); OUString fileForCat; if( aDispatchRequest.aRequestType == REQUEST_CAT ) @@ -581,51 +691,19 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest } } } - } else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) { - OUString aParam = aDispatchRequest.aPrinterName; - sal_Int32 nPathIndex = aParam.lastIndexOf( ';' ); - - OUString aFilterOut; - OUString aPrinterName; - if( nPathIndex != -1 ) - aFilterOut=aParam.copy( nPathIndex+1 ); - if( nPathIndex != 0 ) - aPrinterName=aParam.copy( 0, nPathIndex ); - - INetURLObject aOutFilename( aObj ); - aOutFilename.SetExtension( "ps" ); - FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut ); - OUString aOutFile = aFilterOut+ - "/" + - aOutFilename.getName(); - - OUString aTempName; - FileBase::getSystemPathFromFileURL( aName, aTempName ); - OString aSource8 = OUStringToOString ( aTempName, osl_getThreadTextEncoding() ); - FileBase::getSystemPathFromFileURL( aOutFile, aTempName ); - OString aTargetURL8 = OUStringToOString(aTempName, osl_getThreadTextEncoding() ); - - std::cout << "print " << aSource8 << " -> " << aTargetURL8; - std::cout << " using " << (aPrinterName.isEmpty() ? "<default_printer>" : OUStringToOString( aPrinterName, osl_getThreadTextEncoding() )); - std::cout << std::endl; - - // create the custom printer, if given - Sequence < PropertyValue > aPrinterArgs( 1 ); - if( !aPrinterName.isEmpty() ) - { - aPrinterArgs[0].Name = "Name"; - aPrinterArgs[0].Value <<= aPrinterName; - xDoc->setPrinter( aPrinterArgs ); - } - - // print ( also without user interaction ) - aPrinterArgs.realloc(2); - aPrinterArgs[0].Name = "FileName"; - aPrinterArgs[0].Value <<= aOutFile; - aPrinterArgs[1].Name = "Wait"; - aPrinterArgs[1].Value <<= true; - xDoc->print( aPrinterArgs ); - } else { + } + else if ( aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT ) + { + Reference< XModel > xModel( xDoc, UNO_QUERY ); + if( xModel.is() ) + scriptCat( xModel ); + } + else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) + { + batchPrint( aDispatchRequest.aPrinterName, xDoc, aObj, aName ); + } + else + { if ( aDispatchRequest.aRequestType == REQUEST_PRINTTO ) { // create the printer @@ -745,7 +823,6 @@ void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) th } } -} - +} // namespace desktop /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx index 79f0858ee145..54427e4e6a5a 100644 --- a/desktop/source/app/dispatchwatcher.hxx +++ b/desktop/source/app/dispatchwatcher.hxx @@ -53,16 +53,17 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu REQUEST_CONVERSION, REQUEST_INFILTER, REQUEST_BATCHPRINT, - REQUEST_CAT + REQUEST_CAT, + REQUEST_SCRIPT_CAT }; struct DispatchRequest { - RequestType aRequestType; - OUString aURL; + RequestType aRequestType; + OUString aURL; boost::optional< OUString > aCwdUrl; - OUString aPrinterName; // also conversion params - OUString aPreselectedFactory; + OUString aPrinterName; // also conversion params + OUString aPreselectedFactory; }; DispatchWatcher(); @@ -82,8 +83,7 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu private: osl::Mutex m_mutex; - std::unordered_map<OUString, sal_Int32, OUStringHash> - m_aRequestContainer; + std::unordered_map<OUString, sal_Int32, OUStringHash> m_aRequestContainer; sal_Int16 m_nRequestCount; }; diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx index 7a2fd4624a58..1df2e06c722e 100644 --- a/desktop/source/app/officeipcthread.cxx +++ b/desktop/source/app/officeipcthread.cxx @@ -1053,6 +1053,7 @@ bool IpcThread::process(OString const & arguments, bool * waitProcessed) { pRequest->aConversionOut = aCmdLineArgs->GetConversionOut(); pRequest->aInFilter = aCmdLineArgs->GetInFilter(); pRequest->bTextCat = aCmdLineArgs->IsTextCat(); + pRequest->bScriptCat = aCmdLineArgs->IsScriptCat(); bDocRequestSent |= !pRequest->aConversionList.empty(); if ( !rCurrentCmdLineArgs.IsInvisible() ) @@ -1291,20 +1292,29 @@ static void AddConversionsToDispatchList( const OUString& rPrinterName, const OUString& rFactory, const OUString& rParamOut, - const bool isTextCat ) + const bool isTextCat, + const bool isScriptCat ) { DispatchWatcher::RequestType nType; OUString aParam( rParam ); if( !rParam.isEmpty() ) { - nType = ( isTextCat ) ? DispatchWatcher::REQUEST_CAT : DispatchWatcher::REQUEST_CONVERSION; + if ( isTextCat ) + nType = DispatchWatcher::REQUEST_CAT; + else + nType = DispatchWatcher::REQUEST_CONVERSION; aParam = rParam; } else { - nType = DispatchWatcher::REQUEST_BATCHPRINT; - aParam = rPrinterName; + if ( isScriptCat ) + nType = DispatchWatcher::REQUEST_SCRIPT_CAT; + else + { + nType = DispatchWatcher::REQUEST_BATCHPRINT; + aParam = rPrinterName; + } } OUString aOutDir( rParamOut.trim() ); @@ -1357,7 +1367,7 @@ bool RequestHandler::ExecuteCmdLineRequests( AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aPrintToList, DispatchWatcher::REQUEST_PRINTTO, aRequest.aPrinterName, aRequest.aModule ); AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceOpenList, DispatchWatcher::REQUEST_FORCEOPEN, "", aRequest.aModule ); AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceNewList, DispatchWatcher::REQUEST_FORCENEW, "", aRequest.aModule ); - AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat ); + AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat, aRequest.bScriptCat ); bool bShutdown( false ); if ( pGlobal.is() ) diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx index 2826aba9c32d..533312a477cd 100644 --- a/desktop/source/app/officeipcthread.hxx +++ b/desktop/source/app/officeipcthread.hxx @@ -46,7 +46,7 @@ oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSign struct ProcessDocumentsRequest { explicit ProcessDocumentsRequest(boost::optional< OUString > const & cwdUrl): - aCwdUrl(cwdUrl), pcProcessed( nullptr ), bTextCat( false ) {} + aCwdUrl(cwdUrl), pcProcessed( nullptr ), bTextCat( false ), bScriptCat( false ) {} boost::optional< OUString > aCwdUrl; OUString aModule; @@ -63,7 +63,8 @@ struct ProcessDocumentsRequest OUString aConversionOut; std::vector< OUString > aInFilter; ::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed - bool bTextCat; // boolean flag indicating whether to dump text content to screen + bool bTextCat; // boolean flag indicating whether to dump text content to console + bool bScriptCat; // boolean flag indicating whether to dump script content to console }; class DispatchWatcher; |