xref: /aoo4110/main/extensions/test/pgp/TestPGP.java (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 import java.io.IOException;
26 
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.beans.PropertyState;
29 
30 import com.sun.star.bridge.XBridge;
31 
32 //  import com.sun.star.comp.bootstrap.Bootstrap;
33 
34 import com.sun.star.connection.XConnector;
35 import com.sun.star.connection.XConnection;
36 
37 import com.sun.star.io.BufferSizeExceededException;
38 import com.sun.star.io.NotConnectedException;
39 import com.sun.star.io.XInputStream;
40 import com.sun.star.io.XOutputStream;
41 
42 import com.sun.star.frame.XComponentLoader;
43 
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.lang.XServiceInfo;
47 
48 import com.sun.star.text.XSimpleText;
49 import com.sun.star.text.XText;
50 import com.sun.star.text.XTextCursor;
51 import com.sun.star.text.XTextDocument;
52 import com.sun.star.text.XTextRange;
53 
54 import com.sun.star.uno.IBridge;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
57 import com.sun.star.uno.XNamingService;
58 import com.sun.star.container.*;
59 import com.sun.star.lang.*;
60 
61 import com.sun.star.pgp.*;
62 
63 
64 
65 public class TestPGP {
66 
67 
doSomething(Object r)68 	static void doSomething(Object r) throws com.sun.star.uno.Exception, IOException, Exception {
69 		XNamingService rName = (XNamingService)UnoRuntime.queryInterface(XNamingService.class, r);
70 
71 		if(rName != null) {
72 			System.err.println("got the remote naming service !");
73 			Object rXsmgr = rName.getRegisteredObject("StarOffice.ServiceManager");
74 
75 			XMultiServiceFactory rSmgr = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, rXsmgr);
76 			if(rSmgr != null) {
77 				System.err.println("got the remote service manager !");
78 			}
79 
80 			XSet set= (XSet)UnoRuntime.queryInterface(XSet.class, rSmgr);
81 			if( set == null) {
82 				System.err.println(" couldn't get XSet from ServiceFactory");
83 				return;
84 			}
85 //  			try{
86 			SimplePGPMailerFactoryReg mailerReg= new SimplePGPMailerFactoryReg();
87 			XSingleServiceFactory factory= mailerReg.getServiceFactory(
88 				"com.sun.star.pgp.SimplePGPMailerImpl", rSmgr, null, null);
89 
90 			if( factory == null) {
91 				System.err.println("couldn't create PGP factory !");
92 				return;
93 			}
94 			set.insert(factory );
95 			System.err.println("PGP factory inserted into service manager");
96 
97 //  			}catch(Exception e ){
98 //  				System.err.println( "exception caught in TestPGP");
99 //  			}
100 
101 		}
102 	}
103 
104 
105 
106 	static String neededServices[] = new String[] {
107 		"com.sun.star.comp.servicemanager.ServiceManager",
108 		"com.sun.star.comp.loader.JavaLoader",
109 		"com.sun.star.comp.connections.Connector",
110   		"com.sun.star.comp.connections.Acceptor"
111 	};
112 
main(String argv[])113 	public static void main(String argv[]) throws Exception {
114 		if(argv.length != 1)	{
115 			System.err.println("usage : testoffice protocol:host:port");
116 			System.exit(-1);
117 		}
118 
119 //  		try {
120 			com.sun.star.comp.servicemanager.ServiceManager smgr = new com.sun.star.comp.servicemanager.ServiceManager();
121 			smgr.addFactories(neededServices, null);
122 
123   			XConnector  xConnector  = (XConnector)smgr.createInstance("com.sun.star.connection.Connector");
124   			XConnection xConnection = xConnector.connect(argv[0]);
125 
126 			String rootOid = "classic_uno";
127   			IBridge iBridge = UnoRuntime.getBridgeByName("java", null, "remote", null, new Object[]{"iiop", xConnection, null});
128 
129 			Object rInitialObject = iBridge.mapInterfaceFrom(rootOid, XInterface.class);
130 //  			Object rInitialObject = xBridge.getInstance("NamingService");
131 
132 			if(rInitialObject != null) {
133 				System.err.println("got the remote object");
134 				doSomething(rInitialObject);
135 			}
136 //  		}
137 //  		catch (Exception exception) {
138 //  			System.err.println("Exception thrown:" + exception);
139 //  		}
140 	}
141 }
142 
143