134dd1e25SAndrew Rist /**************************************************************
234dd1e25SAndrew Rist *
334dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file
534dd1e25SAndrew Rist * distributed with this work for additional information
634dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file
734dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at
1034dd1e25SAndrew Rist *
1134dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1234dd1e25SAndrew Rist *
1334dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist * KIND, either express or implied. See the License for the
1734dd1e25SAndrew Rist * specific language governing permissions and limitations
1834dd1e25SAndrew Rist * under the License.
1934dd1e25SAndrew Rist *
2034dd1e25SAndrew Rist *************************************************************/
2134dd1e25SAndrew Rist
2234dd1e25SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <sal/main.h>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
29cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace com::sun::star::uno;
34cdf0e10cSrcweir using namespace com::sun::star::lang;
35cdf0e10cSrcweir using namespace com::sun::star::bridge;
36cdf0e10cSrcweir using namespace rtl;
37cdf0e10cSrcweir using namespace cppu;
38cdf0e10cSrcweir
SAL_IMPLEMENT_MAIN()39cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir // create the initial component context
42cdf0e10cSrcweir Reference< XComponentContext > rComponentContext =
43cdf0e10cSrcweir defaultBootstrap_InitialComponentContext();
44cdf0e10cSrcweir
45cdf0e10cSrcweir // retrieve the servicemanager from the context
46cdf0e10cSrcweir Reference< XMultiComponentFactory > rServiceManager =
47cdf0e10cSrcweir rComponentContext->getServiceManager();
48cdf0e10cSrcweir
49cdf0e10cSrcweir // instantiate a sample service with the servicemanager.
50cdf0e10cSrcweir Reference< XInterface > rInstance =
51cdf0e10cSrcweir rServiceManager->createInstanceWithContext(
52cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ),
53cdf0e10cSrcweir rComponentContext );
54cdf0e10cSrcweir
55cdf0e10cSrcweir // Query for the XUnoUrlResolver interface
56cdf0e10cSrcweir Reference< XUnoUrlResolver > rResolver( rInstance, UNO_QUERY );
57cdf0e10cSrcweir
58cdf0e10cSrcweir if( ! rResolver.is() )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir printf( "Error: Couldn't instantiate com.sun.star.bridge.UnoUrlResolver service\n" );
61cdf0e10cSrcweir return 1;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir try
64cdf0e10cSrcweir {
65cdf0e10cSrcweir // resolve the uno-url
66cdf0e10cSrcweir rInstance = rResolver->resolve( OUString::createFromAscii(
67cdf0e10cSrcweir "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" ) );
68cdf0e10cSrcweir
69cdf0e10cSrcweir if( ! rInstance.is() )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir printf( "StarOffice.ServiceManager is not exported from remote counterpart\n" );
72cdf0e10cSrcweir return 1;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir // query for the simpler XMultiServiceFactory interface, sufficient for scripting
76cdf0e10cSrcweir Reference< XMultiServiceFactory > rOfficeServiceManager (rInstance, UNO_QUERY);
77cdf0e10cSrcweir
78cdf0e10cSrcweir if( ! rInstance.is() )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir printf( "XMultiServiceFactory interface is not exported for StarOffice.ServiceManager\n" );
81cdf0e10cSrcweir return 1;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84*a893be29SPedro Giffuni printf( "Connected successfully to the office\n" );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir catch( Exception &e )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
89cdf0e10cSrcweir printf( "Error: %s\n", o.pData->buffer );
90cdf0e10cSrcweir return 1;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir return 0;
93cdf0e10cSrcweir }
94