1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 // __________ Imports __________
36 
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.lang.XComponent;
39 
40 import com.sun.star.beans.Property;
41 import com.sun.star.beans.PropertyValue;
42 import com.sun.star.beans.XPropertySet;
43 import com.sun.star.beans.XPropertySetInfo;
44 
45 import com.sun.star.container.XIndexAccess;
46 
47 import com.sun.star.document.XViewDataSupplier;
48 
49 import com.sun.star.frame.XModel;
50 import com.sun.star.frame.XController;
51 
52 
53 
54 // __________ Implementation __________
55 
56 /** text demo
57     @author Sven Jacobi
58  */
59 
60 public class DrawViewDemo
61 {
62     public static void main( String args[] )
63     {
64 		if ( args.length < 1 )
65 		{
66 			System.out.println( "usage: DrawViewDemo SourceURL" );
67             System.exit(1);
68 		}
69 
70         XComponent xComponent = null;
71         try
72         {
73             // get the remote office context of a running office (a new office
74             // instance is started if necessary)
75 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
76 
77             // suppress Presentation Autopilot when opening the document
78             // properties are the same as described for
79             // com.sun.star.document.MediaDescriptor
80             PropertyValue[] pPropValues = new PropertyValue[ 1 ];
81             pPropValues[ 0 ] = new PropertyValue();
82             pPropValues[ 0 ].Name = "Silent";
83             pPropValues[ 0 ].Value = new Boolean( true );
84 
85             java.io.File sourceFile = new java.io.File(args[0]);
86             StringBuffer sUrl = new StringBuffer("file:///");
87             sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
88 
89             xComponent = Helper.createDocument( xOfficeContext,
90                                                 sUrl.toString(), "_blank", 0,
91                                                 pPropValues );
92             XModel xModel =
93                 (XModel)UnoRuntime.queryInterface(
94                     XModel.class, xComponent );
95 
96 
97             // print all available properties of first view
98             System.out.println("*** print all available properties of first view");
99             XViewDataSupplier xViewDataSupplier =
100                 (XViewDataSupplier)UnoRuntime.queryInterface(
101                     XViewDataSupplier.class, xModel );
102             XIndexAccess xIndexAccess = xViewDataSupplier.getViewData();
103             if ( xIndexAccess.getCount() != 0 )
104             {
105                 PropertyValue[] aPropSeq = (PropertyValue[])
106                     xIndexAccess.getByIndex( 0 );
107 
108                 for( int i = 0; i < aPropSeq.length; i++ )
109                 {
110                     System.out.println( aPropSeq[ i ].Name + " = " +
111                                         aPropSeq[ i ].Value );
112                 }
113             }
114 
115 
116             // print all properties that are supported by the controller
117             // and change into masterpage mode
118             System.out.println("*** print all properties that are supported by the controller");
119             XController xController = xModel.getCurrentController();
120             XPropertySet xPropSet =
121                 (XPropertySet)UnoRuntime.queryInterface(
122                     XPropertySet.class, xController );
123             XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo();
124             Property[] aPropSeq = xPropSetInfo.getProperties();
125             for( int i = 0; i < aPropSeq.length; i++ )
126             {
127                 System.out.println( aPropSeq[ i ].Name );
128             }
129             System.out.println("*** change into masterpage mode");
130             xPropSet.setPropertyValue( "IsMasterPageMode", new Boolean( true ) );
131 
132         }
133         catch( Exception ex )
134         {
135             System.out.println( ex.getMessage() );
136             ex.printStackTrace(System.out);
137         }
138 
139         System.exit( 0 );
140     }
141 }
142