1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <stdio.h>
25 
26 #include <sal/main.h>
27 #include <cppuhelper/bootstrap.hxx>
28 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
29 #include <com/sun/star/frame/XComponentLoader.hpp>
30 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
31 
32 using namespace rtl;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::frame;
36 
37 
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc,argv)38 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
39 {
40     try
41     {
42         // get the remote office component context
43         Reference< XComponentContext > xContext( ::cppu::bootstrap() );
44         if ( !xContext.is() )
45         {
46             fprintf(stderr, "no component context!\n");
47             return 1;
48         }
49 
50         // get the remote office service manager
51         Reference< XMultiComponentFactory > xServiceManager(
52             xContext->getServiceManager() );
53         if ( !xServiceManager.is() )
54         {
55             fprintf(stderr, "no service manager!\n");
56             return 1;
57         }
58 
59         // get an instance of the remote office desktop UNO service
60         // and query the XComponentLoader interface
61         Reference < XComponentLoader > xComponentLoader(
62             xServiceManager->createInstanceWithContext(
63             OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ),
64             xContext ), UNO_QUERY_THROW );
65 
66         // open a spreadsheet document
67         Reference< XComponent > xComponent( xComponentLoader->loadComponentFromURL(
68             OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ),
69             OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0,
70             Sequence < ::com::sun::star::beans::PropertyValue >() ) );
71         if ( !xComponent.is() )
72         {
73             fprintf(stderr, "opening spreadsheet document failed!\n");
74             return 1;
75         }
76     }
77     catch ( ::cppu::BootstrapException & e )
78     {
79         fprintf(stderr, "caught BootstrapException: %s\n",
80                 OUStringToOString( e.getMessage(), RTL_TEXTENCODING_ASCII_US ).getStr());
81         return 1;
82     }
83     catch ( Exception & e )
84     {
85         fprintf(stderr, "caught UNO exception: %s\n",
86                 OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
87         return 1;
88     }
89 
90     return 0;
91 }
92