1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // __________ Imports __________ 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.lang.XComponent; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.beans.Property; 30cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 31cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 32cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import com.sun.star.document.XViewDataSupplier; 37cdf0e10cSrcweir 38cdf0e10cSrcweir import com.sun.star.frame.XModel; 39cdf0e10cSrcweir import com.sun.star.frame.XController; 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir // __________ Implementation __________ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** text demo 46cdf0e10cSrcweir @author Sven Jacobi 47cdf0e10cSrcweir */ 48cdf0e10cSrcweir 49cdf0e10cSrcweir public class DrawViewDemo 50cdf0e10cSrcweir { main( String args[] )51cdf0e10cSrcweir public static void main( String args[] ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir if ( args.length < 1 ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir System.out.println( "usage: DrawViewDemo SourceURL" ); 56cdf0e10cSrcweir System.exit(1); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir XComponent xComponent = null; 60cdf0e10cSrcweir try 61cdf0e10cSrcweir { 62cdf0e10cSrcweir // get the remote office context of a running office (a new office 63cdf0e10cSrcweir // instance is started if necessary) 64cdf0e10cSrcweir com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 65cdf0e10cSrcweir 66cdf0e10cSrcweir // suppress Presentation Autopilot when opening the document 67cdf0e10cSrcweir // properties are the same as described for 68cdf0e10cSrcweir // com.sun.star.document.MediaDescriptor 69cdf0e10cSrcweir PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 70cdf0e10cSrcweir pPropValues[ 0 ] = new PropertyValue(); 71cdf0e10cSrcweir pPropValues[ 0 ].Name = "Silent"; 72cdf0e10cSrcweir pPropValues[ 0 ].Value = new Boolean( true ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir java.io.File sourceFile = new java.io.File(args[0]); 75cdf0e10cSrcweir StringBuffer sUrl = new StringBuffer("file:///"); 76cdf0e10cSrcweir sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); 77cdf0e10cSrcweir 78cdf0e10cSrcweir xComponent = Helper.createDocument( xOfficeContext, 79cdf0e10cSrcweir sUrl.toString(), "_blank", 0, 80cdf0e10cSrcweir pPropValues ); 81cdf0e10cSrcweir XModel xModel = 82cdf0e10cSrcweir (XModel)UnoRuntime.queryInterface( 83cdf0e10cSrcweir XModel.class, xComponent ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir // print all available properties of first view 87cdf0e10cSrcweir System.out.println("*** print all available properties of first view"); 88cdf0e10cSrcweir XViewDataSupplier xViewDataSupplier = 89cdf0e10cSrcweir (XViewDataSupplier)UnoRuntime.queryInterface( 90cdf0e10cSrcweir XViewDataSupplier.class, xModel ); 91cdf0e10cSrcweir XIndexAccess xIndexAccess = xViewDataSupplier.getViewData(); 92cdf0e10cSrcweir if ( xIndexAccess.getCount() != 0 ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir PropertyValue[] aPropSeq = (PropertyValue[]) 95cdf0e10cSrcweir xIndexAccess.getByIndex( 0 ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir for( int i = 0; i < aPropSeq.length; i++ ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir System.out.println( aPropSeq[ i ].Name + " = " + 100cdf0e10cSrcweir aPropSeq[ i ].Value ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir // print all properties that are supported by the controller 106cdf0e10cSrcweir // and change into masterpage mode 107cdf0e10cSrcweir System.out.println("*** print all properties that are supported by the controller"); 108cdf0e10cSrcweir XController xController = xModel.getCurrentController(); 109cdf0e10cSrcweir XPropertySet xPropSet = 110cdf0e10cSrcweir (XPropertySet)UnoRuntime.queryInterface( 111cdf0e10cSrcweir XPropertySet.class, xController ); 112cdf0e10cSrcweir XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); 113cdf0e10cSrcweir Property[] aPropSeq = xPropSetInfo.getProperties(); 114cdf0e10cSrcweir for( int i = 0; i < aPropSeq.length; i++ ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir System.out.println( aPropSeq[ i ].Name ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir System.out.println("*** change into masterpage mode"); 119cdf0e10cSrcweir xPropSet.setPropertyValue( "IsMasterPageMode", new Boolean( true ) ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir } 122cdf0e10cSrcweir catch( Exception ex ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir System.out.println( ex.getMessage() ); 125cdf0e10cSrcweir ex.printStackTrace(System.out); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir System.exit( 0 ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131