tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / odk / examples / cpp / DocumentLoader / DocumentLoader.cxx
blob38b661e030cfce3e1269572ac3f0dab3e601b58e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // Simple client application using the UnoUrlResolver service.
37 #include <iostream>
38 #include <sal/main.h>
39 #include <cppuhelper/bootstrap.hxx>
41 #include <osl/file.hxx>
42 #include <osl/process.h>
43 #include <rtl/process.h>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
47 #include <com/sun/star/frame/Desktop.hpp>
48 #include <com/sun/star/frame/XComponentLoader.hpp>
49 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
50 #include <com/sun/star/registry/XSimpleRegistry.hpp>
52 using namespace com::sun::star::uno;
53 using namespace com::sun::star::lang;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::bridge;
56 using namespace com::sun::star::frame;
57 using namespace com::sun::star::registry;
59 using namespace rtl;
61 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
63 OUString sConnectionString("uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager");
65 sal_Int32 nCount = rtl_getAppCommandArgCount();
67 if (nCount < 1)
69 std::cout << "using: DocumentLoader -env:URE_MORE_TYPES=<office_types_rdb_url> <file_url> "
70 "[<uno_connection_url>]"
71 << std::endl
72 << std::endl
73 << "example: DocumentLoader -env:URE_MORE_TYPES=\"file:///.../program/offapi.rdb\" "
74 "\"file:///e:/temp/test.odt\" "
75 "\"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager\""
76 << std::endl;
77 exit(1);
79 if (nCount == 2)
81 rtl_getAppCommandArg(1, &sConnectionString.pData);
84 Reference< XComponentContext > xComponentContext(::cppu::defaultBootstrap_InitialComponentContext());
86 /* Gets the service manager instance to be used (or null). This method has
87 been added for convenience, because the service manager is an often used
88 object.
90 Reference< XMultiComponentFactory > xMultiComponentFactoryClient(
91 xComponentContext->getServiceManager() );
93 /* Creates an instance of a component which supports the services specified
94 by the factory.
96 Reference< XInterface > xInterface =
97 xMultiComponentFactoryClient->createInstanceWithContext(
98 "com.sun.star.bridge.UnoUrlResolver",
99 xComponentContext );
101 Reference< XUnoUrlResolver > resolver( xInterface, UNO_QUERY );
103 // Resolves the component context from the office, on the uno URL given by argv[1].
106 xInterface = Reference< XInterface >(
107 resolver->resolve( sConnectionString ), UNO_QUERY );
109 catch ( Exception& e )
111 std::cout << "Error: cannot establish a connection using "
112 << sConnectionString << std::endl << e.Message << std::endl;
113 exit(1);
116 // gets the server component context as property of the office component factory
117 Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY );
118 xPropSet->getPropertyValue("DefaultContext") >>= xComponentContext;
120 // gets the service manager from the office
121 Reference< XMultiComponentFactory > xMultiComponentFactoryServer(
122 xComponentContext->getServiceManager() );
124 /* Creates an instance of a component which supports the services specified
125 by the factory. Important: using the office component context.
127 Reference < XDesktop2 > xComponentLoader = Desktop::create(xComponentContext);
129 /* Loads a component specified by a URL into the specified new or existing
130 frame.
132 OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl, sArgDocUrl;
133 rtl_getAppCommandArg(0, &sArgDocUrl.pData);
135 osl_getProcessWorkingDir(&sWorkingDir.pData);
136 osl::FileBase::getFileURLFromSystemPath( sArgDocUrl, sDocPathUrl);
137 osl::FileBase::getAbsoluteFileURL( sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
139 Reference< XComponent > xComponent = xComponentLoader->loadComponentFromURL(
140 sAbsoluteDocUrl, OUString( "_blank" ), 0,
141 Sequence < ::com::sun::star::beans::PropertyValue >() );
143 // dispose the local service manager
144 Reference< XComponent >::query( xMultiComponentFactoryClient )->dispose();
146 return 0;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */