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 import com.sun.star.lang.XSingleComponentFactory; 25 import com.sun.star.uno.UnoRuntime; 26 27 import java.io.DataInputStream; 28 29 public class TestInspector { 30 main(String args[])31 public static void main(String args[]) { 32 com.sun.star.uno.XComponentContext xContext = null; 33 try { 34 // get the remote office component context 35 xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 36 if( xContext != null ) 37 System.out.println("Connected to a running office ..."); 38 } 39 catch( Exception e) { 40 e.printStackTrace(System.out); 41 System.exit(1); 42 } 43 44 try { 45 com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager(); 46 // Creating an instance of the instance inspector with arguments 47 48 XSingleComponentFactory xFactory = Inspector.__getComponentFactory(Inspector._Inspector.class.getName()); 49 Object obj= null; 50 if (xFactory != null) { 51 obj = xFactory.createInstanceWithContext(xContext); 52 } 53 org.openoffice.XInstanceInspector xInstInspector = null; 54 if (obj != null) { 55 xInstInspector = (org.openoffice.XInstanceInspector)UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj); 56 } 57 58 /* A desktop environment contains tasks with one or more 59 frames in which components can be loaded. Desktop is the 60 environment for components which can instanciate within 61 frames. */ 62 com.sun.star.frame.XComponentLoader xCmpLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class, 63 xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext)); 64 65 // Load a new spreadsheet document, which will be automatically 66 // displayed and is used for inspection 67 com.sun.star.lang.XComponent xComp = xCmpLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] ); 68 xInstInspector.inspect(xCmpLoader, ""); 69 System.out.println("You can now inspect the new spreadsheet " + "document ...\n"); 70 } 71 catch( Exception e ) { 72 System.err.println( e + e.getMessage()); 73 e.printStackTrace(); 74 } 75 // System.exit( 0 ); 76 } 77 } 78