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