1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 29 import java.io.IOException; 30 31 import com.sun.star.beans.PropertyValue; 32 import com.sun.star.beans.PropertyState; 33 34 import com.sun.star.bridge.XBridge; 35 36 // import com.sun.star.comp.bootstrap.Bootstrap; 37 38 import com.sun.star.connection.XConnector; 39 import com.sun.star.connection.XConnection; 40 41 import com.sun.star.io.BufferSizeExceededException; 42 import com.sun.star.io.NotConnectedException; 43 import com.sun.star.io.XInputStream; 44 import com.sun.star.io.XOutputStream; 45 46 import com.sun.star.frame.XComponentLoader; 47 48 import com.sun.star.lang.XComponent; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.lang.XServiceInfo; 51 52 import com.sun.star.text.XSimpleText; 53 import com.sun.star.text.XText; 54 import com.sun.star.text.XTextCursor; 55 import com.sun.star.text.XTextDocument; 56 import com.sun.star.text.XTextRange; 57 58 import com.sun.star.uno.IBridge; 59 import com.sun.star.uno.UnoRuntime; 60 import com.sun.star.uno.XInterface; 61 import com.sun.star.uno.XNamingService; 62 import com.sun.star.container.*; 63 import com.sun.star.lang.*; 64 65 import com.sun.star.pgp.*; 66 67 68 69 public class TestPGP { 70 71 72 static void doSomething(Object r) throws com.sun.star.uno.Exception, IOException, Exception { 73 XNamingService rName = (XNamingService)UnoRuntime.queryInterface(XNamingService.class, r); 74 75 if(rName != null) { 76 System.err.println("got the remote naming service !"); 77 Object rXsmgr = rName.getRegisteredObject("StarOffice.ServiceManager"); 78 79 XMultiServiceFactory rSmgr = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, rXsmgr); 80 if(rSmgr != null) { 81 System.err.println("got the remote service manager !"); 82 } 83 84 XSet set= (XSet)UnoRuntime.queryInterface(XSet.class, rSmgr); 85 if( set == null) { 86 System.err.println(" couldn't get XSet from ServiceFactory"); 87 return; 88 } 89 // try{ 90 SimplePGPMailerFactoryReg mailerReg= new SimplePGPMailerFactoryReg(); 91 XSingleServiceFactory factory= mailerReg.getServiceFactory( 92 "com.sun.star.pgp.SimplePGPMailerImpl", rSmgr, null, null); 93 94 if( factory == null) { 95 System.err.println("couldn't create PGP factory !"); 96 return; 97 } 98 set.insert(factory ); 99 System.err.println("PGP factory inserted into service manager"); 100 101 // }catch(Exception e ){ 102 // System.err.println( "exception caught in TestPGP"); 103 // } 104 105 } 106 } 107 108 109 110 static String neededServices[] = new String[] { 111 "com.sun.star.comp.servicemanager.ServiceManager", 112 "com.sun.star.comp.loader.JavaLoader", 113 "com.sun.star.comp.connections.Connector", 114 "com.sun.star.comp.connections.Acceptor" 115 }; 116 117 public static void main(String argv[]) throws Exception { 118 if(argv.length != 1) { 119 System.err.println("usage : testoffice protocol:host:port"); 120 System.exit(-1); 121 } 122 123 // try { 124 com.sun.star.comp.servicemanager.ServiceManager smgr = new com.sun.star.comp.servicemanager.ServiceManager(); 125 smgr.addFactories(neededServices, null); 126 127 XConnector xConnector = (XConnector)smgr.createInstance("com.sun.star.connection.Connector"); 128 XConnection xConnection = xConnector.connect(argv[0]); 129 130 String rootOid = "classic_uno"; 131 IBridge iBridge = UnoRuntime.getBridgeByName("java", null, "remote", null, new Object[]{"iiop", xConnection, null}); 132 133 Object rInitialObject = iBridge.mapInterfaceFrom(rootOid, XInterface.class); 134 // Object rInitialObject = xBridge.getInstance("NamingService"); 135 136 if(rInitialObject != null) { 137 System.err.println("got the remote object"); 138 doSomething(rInitialObject); 139 } 140 // } 141 // catch (Exception exception) { 142 // System.err.println("Exception thrown:" + exception); 143 // } 144 } 145 } 146 147