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