diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2017-06-08 14:25:50 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2017-06-09 11:00:14 +0200 |
commit | 6c6992f80082aabd665ab7545f5b6b9ca3644ed4 (patch) | |
tree | 55a07ec871b0f7719b2f487e52949ab531d2c0d3 /desktop | |
parent | 15957e14408e7b525c71914739faa63bd827117d (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>
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 | 2 | ||||
-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, 190 insertions, 90 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index df5346195a7f..023c06af6e7e 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -2204,6 +2204,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 b86fe45d3b80..b15706046f50 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -337,6 +337,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) @@ -704,6 +710,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 83baa1df21ab..043f7b2a2f5e 100644 --- a/desktop/source/app/cmdlinehelp.cxx +++ b/desktop/source/app/cmdlinehelp.cxx @@ -160,6 +160,8 @@ namespace desktop " --pt switch interferes with --printer-name.\n" " --cat Dump text content of the following files to console\n" " (implies --headless). Cannot be used with --convert-to.\n" + " --script-cat Dump text content of any scripts embedded in the files to console\n" + " (implies --headless). Cannot be used with --convert-to.\n" " -env:<VAR>[=<VALUE>] Set a bootstrap variable. For example: to set\n" " a non-default user profile path:\n" " -env:UserInstallation=file:///tmp/test\n\n" diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index b23627748edf..a1b65114b43f 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -51,6 +51,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> @@ -70,6 +74,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; @@ -130,32 +135,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 ) @@ -168,8 +172,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) + { + 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) { @@ -211,7 +315,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 ); @@ -224,7 +329,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"; @@ -261,7 +367,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 @@ -448,11 +555,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; @@ -479,9 +591,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 ) @@ -582,51 +692,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& ) } } -} - +} // namespace desktop /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx index b8a70c08e33b..4755690a7686 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(); @@ -81,8 +82,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 24252716bd73..57546f8ea66d 100644 --- a/desktop/source/app/officeipcthread.cxx +++ b/desktop/source/app/officeipcthread.cxx @@ -1051,6 +1051,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() ) @@ -1289,20 +1290,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() ); @@ -1355,7 +1365,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 7c24f78fcb65..fd25195a6e8a 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; |