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