1 /************************************************************************* 2 * 3 * The Contents of this file are made available subject to the terms of 4 * the BSD license. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 *************************************************************************/ 34 35 #include <stdio.h> 36 37 #include <sal/main.h> 38 #include <cppuhelper/bootstrap.hxx> 39 #include <com/sun/star/bridge/XUnoUrlResolver.hpp> 40 #include <com/sun/star/frame/XComponentLoader.hpp> 41 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 42 43 using namespace rtl; 44 using namespace com::sun::star::uno; 45 using namespace com::sun::star::lang; 46 using namespace com::sun::star::frame; 47 48 49 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) 50 { 51 try 52 { 53 // get the remote office component context 54 Reference< XComponentContext > xContext( ::cppu::bootstrap() ); 55 if ( !xContext.is() ) 56 { 57 fprintf(stderr, "no component context!\n"); 58 return 1; 59 } 60 61 // get the remote office service manager 62 Reference< XMultiComponentFactory > xServiceManager( 63 xContext->getServiceManager() ); 64 if ( !xServiceManager.is() ) 65 { 66 fprintf(stderr, "no service manager!\n"); 67 return 1; 68 } 69 70 // get an instance of the remote office desktop UNO service 71 // and query the XComponentLoader interface 72 Reference < XComponentLoader > xComponentLoader( 73 xServiceManager->createInstanceWithContext( 74 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), 75 xContext ), UNO_QUERY_THROW ); 76 77 // open a spreadsheet document 78 Reference< XComponent > xComponent( xComponentLoader->loadComponentFromURL( 79 OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ), 80 OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, 81 Sequence < ::com::sun::star::beans::PropertyValue >() ) ); 82 if ( !xComponent.is() ) 83 { 84 fprintf(stderr, "opening spreadsheet document failed!\n"); 85 return 1; 86 } 87 } 88 catch ( ::cppu::BootstrapException & e ) 89 { 90 fprintf(stderr, "caught BootstrapException: %s\n", 91 OUStringToOString( e.getMessage(), RTL_TEXTENCODING_ASCII_US ).getStr()); 92 return 1; 93 } 94 catch ( Exception & e ) 95 { 96 fprintf(stderr, "caught UNO exception: %s\n", 97 OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); 98 return 1; 99 } 100 101 return 0; 102 } 103