bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / test / pgp / TestPGP.java
blobce719a530c9ebb77ecc66761deedc4ccd16e12a1
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com.sun.star.bridge.UnoUrlResolver;
21 import com.sun.star.bridge.XUnoUrlResolver;
22 import com.sun.star.comp.helper.Bootstrap;
23 import com.sun.star.connection.XConnection;
24 import com.sun.star.connection.XConnector;
25 import com.sun.star.container.XSet;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.lang.XSingleServiceFactory;
28 import com.sun.star.pgp.SimplePGPMailerFactoryReg;
29 import com.sun.star.uno.IBridge;
30 import com.sun.star.uno.Type;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.uno.XNamingService;
37 public class TestPGP {
40 static void doSomething(Object r) throws com.sun.star.uno.Exception, Exception {
41 XNamingService rName = UnoRuntime.queryInterface(XNamingService.class, r);
43 if(rName != null) {
44 System.err.println("got the remote naming service !");
45 Object rXsmgr = rName.getRegisteredObject("StarOffice.ServiceManager");
47 XMultiServiceFactory rSmgr = UnoRuntime.queryInterface(XMultiServiceFactory.class, rXsmgr);
48 if(rSmgr != null) {
49 System.err.println("got the remote service manager !");
52 XSet set= UnoRuntime.queryInterface(XSet.class, rSmgr);
53 if( set == null) {
54 System.err.println(" couldn't get XSet from ServiceFactory");
55 return;
57 SimplePGPMailerFactoryReg mailerReg= new SimplePGPMailerFactoryReg();
58 XSingleServiceFactory factory= mailerReg.getServiceFactory(
59 "com.sun.star.pgp.SimplePGPMailerImpl", rSmgr, null, null);
61 if( factory == null) {
62 System.err.println("couldn't create PGP factory !");
63 return;
65 set.insert(factory );
66 System.err.println("PGP factory inserted into service manager");
73 public static void main(String argv[]) throws Exception {
74 if(argv.length != 1) {
75 System.err.println("usage : testoffice protocol:host:port");
76 System.exit(-1);
79 XUnoUrlResolver resolver = UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null));
81 XConnector xConnector = UnoRuntime.queryInterface(XConnector.class, resolver.resolve("com.sun.star.connection.Connector"));
82 XConnection xConnection = xConnector.connect(argv[0]);
84 String rootOid = "classic_uno";
85 IBridge iBridge = UnoRuntime.getBridgeByName("java", null, "remote", null, new Object[]{"iiop", xConnection, null});
87 Object rInitialObject = iBridge.mapInterfaceFrom(rootOid, new Type(XInterface.class));
89 if(rInitialObject != null) {
90 System.err.println("got the remote object");
91 doSomething(rInitialObject);