#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug(args...){dbg,args; cerr< typedef long long int ll; typedef long double ld; typedef unsigned int ui; typedef unsigned long long int ull; using namespace std; typedef vector VI; typedef set SI; typedef map MII; typedef pair PII; struct debugger { template debugger& operator , (const T& v) { cerr< []\n\n" "example: DocumentLoader -env:URE_MORE_TYPES=\"file:///.../program/offapi.rdb\" \"file:///e:/temp/test.odt\" \"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager\"\n"); exit(1); } if (nCount == 2) { rtl_getAppCommandArg(1, &sConnectionString.pData); } Reference< XComponentContext > xComponentContext(::cppu::defaultBootstrap_InitialComponentContext()); /* Gets the service manager instance to be used (or null).*/ Reference< XMultiComponentFactory > xMultiComponentFactoryClient( xComponentContext->getServiceManager() ); /* Creates an instance of a component which supports the services specified by the factory. */ Reference< XInterface > xInterface = xMultiComponentFactoryClient->createInstanceWithContext( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.UnoUrlResolver")), xComponentContext ); Reference< XUnoUrlResolver > resolver( xInterface, UNO_QUERY ); // Resolves the component context from the office, on the uno URL given by argv[1]. try { xInterface = Reference< XInterface >( resolver->resolve( sConnectionString ), UNO_QUERY ); } catch ( Exception& e ) { printf("Exception caught !!!!\n"); exit(1); } // gets the server component context as property of the office component factory Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY ); xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xComponentContext; // gets the service manager from the office Reference< XMultiComponentFactory > xMultiComponentFactoryServer( xComponentContext->getServiceManager() ); /* Creates an instance of a component which supports the services specified by the factory. Important: using the office component context. */ Reference < XComponentLoader > xComponentLoader( xMultiComponentFactoryServer->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop" ) ), xComponentContext ), UNO_QUERY ); /* Loading a component specified by an URL into the specified new or existing frame. */ OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl, sArgDocUrl; rtl_getAppCommandArg(0, &sArgDocUrl.pData); osl_getProcessWorkingDir(&sWorkingDir.pData); osl::FileBase::getFileURLFromSystemPath( sArgDocUrl, sDocPathUrl); // get URL osl::FileBase::getAbsoluteFileURL( sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); Reference< XComponent > xComponent = xComponentLoader->loadComponentFromURL( sAbsoluteDocUrl, OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") ), 0, Sequence < ::com::sun::star::beans::PropertyValue >() ); // disposing the local service manager Reference< XComponent >::query( xMultiComponentFactoryClient )->dispose(); cout << "Ending" << endl; return 0; }