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 // __________ Imports __________ 25 26 import com.sun.star.uno.UnoRuntime; 27 import com.sun.star.lang.XComponent; 28 29 import com.sun.star.beans.Property; 30 import com.sun.star.beans.PropertyValue; 31 import com.sun.star.beans.XPropertySet; 32 import com.sun.star.beans.XPropertySetInfo; 33 34 import com.sun.star.container.XIndexAccess; 35 36 import com.sun.star.document.XViewDataSupplier; 37 38 import com.sun.star.frame.XModel; 39 import com.sun.star.frame.XController; 40 41 42 43 // __________ Implementation __________ 44 45 /** text demo 46 @author Sven Jacobi 47 */ 48 49 public class DrawViewDemo 50 { main( String args[] )51 public static void main( String args[] ) 52 { 53 if ( args.length < 1 ) 54 { 55 System.out.println( "usage: DrawViewDemo SourceURL" ); 56 System.exit(1); 57 } 58 59 XComponent xComponent = null; 60 try 61 { 62 // get the remote office context of a running office (a new office 63 // instance is started if necessary) 64 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 65 66 // suppress Presentation Autopilot when opening the document 67 // properties are the same as described for 68 // com.sun.star.document.MediaDescriptor 69 PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 70 pPropValues[ 0 ] = new PropertyValue(); 71 pPropValues[ 0 ].Name = "Silent"; 72 pPropValues[ 0 ].Value = new Boolean( true ); 73 74 java.io.File sourceFile = new java.io.File(args[0]); 75 StringBuffer sUrl = new StringBuffer("file:///"); 76 sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); 77 78 xComponent = Helper.createDocument( xOfficeContext, 79 sUrl.toString(), "_blank", 0, 80 pPropValues ); 81 XModel xModel = 82 (XModel)UnoRuntime.queryInterface( 83 XModel.class, xComponent ); 84 85 86 // print all available properties of first view 87 System.out.println("*** print all available properties of first view"); 88 XViewDataSupplier xViewDataSupplier = 89 (XViewDataSupplier)UnoRuntime.queryInterface( 90 XViewDataSupplier.class, xModel ); 91 XIndexAccess xIndexAccess = xViewDataSupplier.getViewData(); 92 if ( xIndexAccess.getCount() != 0 ) 93 { 94 PropertyValue[] aPropSeq = (PropertyValue[]) 95 xIndexAccess.getByIndex( 0 ); 96 97 for( int i = 0; i < aPropSeq.length; i++ ) 98 { 99 System.out.println( aPropSeq[ i ].Name + " = " + 100 aPropSeq[ i ].Value ); 101 } 102 } 103 104 105 // print all properties that are supported by the controller 106 // and change into masterpage mode 107 System.out.println("*** print all properties that are supported by the controller"); 108 XController xController = xModel.getCurrentController(); 109 XPropertySet xPropSet = 110 (XPropertySet)UnoRuntime.queryInterface( 111 XPropertySet.class, xController ); 112 XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); 113 Property[] aPropSeq = xPropSetInfo.getProperties(); 114 for( int i = 0; i < aPropSeq.length; i++ ) 115 { 116 System.out.println( aPropSeq[ i ].Name ); 117 } 118 System.out.println("*** change into masterpage mode"); 119 xPropSet.setPropertyValue( "IsMasterPageMode", new Boolean( true ) ); 120 121 } 122 catch( Exception ex ) 123 { 124 System.out.println( ex.getMessage() ); 125 ex.printStackTrace(System.out); 126 } 127 128 System.exit( 0 ); 129 } 130 } 131