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 package complex.embedding; 23 24 import com.sun.star.uno.XInterface; 25 import com.sun.star.lang.XMultiServiceFactory; 26 import com.sun.star.lang.XSingleServiceFactory; 27 28 import com.sun.star.bridge.XUnoUrlResolver; 29 import com.sun.star.uno.UnoRuntime; 30 import com.sun.star.uno.XInterface; 31 import com.sun.star.beans.XPropertySet; 32 import com.sun.star.frame.XLoadable; 33 import com.sun.star.drawing.XDrawPagesSupplier; 34 import com.sun.star.drawing.XDrawPages; 35 import com.sun.star.drawing.XDrawPage; 36 import com.sun.star.drawing.XShape; 37 import com.sun.star.graphic.XGraphic; 38 39 import com.sun.star.embed.*; 40 41 import complex.embedding.TestHelper; 42 43 public class Test01 { 44 45 XMultiServiceFactory m_xMSF; 46 TestHelper m_aTestHelper; 47 Test01( XMultiServiceFactory xMSF )48 public Test01( XMultiServiceFactory xMSF ) 49 { 50 m_xMSF = xMSF; 51 m_aTestHelper = new TestHelper( "Test01: " ); 52 } 53 test()54 public boolean test() 55 { 56 try 57 { 58 Object oDoc = m_xMSF.createInstance( "com.sun.star.comp.Draw.DrawingDocument" ); 59 XLoadable xLoad = (XLoadable) UnoRuntime.queryInterface( XLoadable.class, oDoc ); 60 if ( xLoad == null ) 61 { 62 m_aTestHelper.Error( "Can not get XLoadable!" ); 63 return false; 64 } 65 66 xLoad.initNew(); 67 68 XDrawPagesSupplier xDPSupply = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, oDoc ); 69 if ( xDPSupply == null ) 70 { 71 m_aTestHelper.Error( "Can not get XDrawPagesSupplier!" ); 72 return false; 73 } 74 75 XDrawPages xDrawPages = xDPSupply.getDrawPages(); 76 if ( xDrawPages == null ) 77 { 78 m_aTestHelper.Error( "Can not get XDrawPages object!" ); 79 return false; 80 } 81 82 if ( xDrawPages.getCount() == 0 ) 83 { 84 m_aTestHelper.Error( "There must be at least one page in the document!" ); 85 return false; 86 } 87 88 Object oPage = xDrawPages.getByIndex( 0 ); 89 XDrawPage xPage = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, oPage ); 90 if ( xPage == null ) 91 { 92 m_aTestHelper.Error( "Can not get access to drawing page!" ); 93 return false; 94 } 95 96 XMultiServiceFactory xDrFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class, oDoc ); 97 if ( xDrFactory == null ) 98 { 99 m_aTestHelper.Error( "Can not get drawing factory!" ); 100 return false; 101 } 102 103 Object oShape = xDrFactory.createInstance( "com.sun.star.drawing.OLE2Shape" ); 104 XShape xShape = ( XShape ) UnoRuntime.queryInterface( XShape.class, oShape ); 105 if ( xShape == null ) 106 { 107 m_aTestHelper.Error( "Can not create new shape!" ); 108 return false; 109 } 110 111 XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oShape ); 112 if ( xShapeProps == null ) 113 { 114 m_aTestHelper.Error( "Can not get access to shapes properties!" ); 115 return false; 116 } 117 118 xPage.add( xShape ); 119 xShapeProps.setPropertyValue( "CLSID", "078B7ABA-54FC-457F-8551-6147e776a997" ); 120 121 Object oEmbObj = xShapeProps.getPropertyValue( "EmbeddedObject" ); 122 XEmbeddedObject xEmbObj = ( XEmbeddedObject ) UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 123 if ( xEmbObj == null ) 124 { 125 m_aTestHelper.Error( "Embedded object can not be accessed!" ); 126 return false; 127 } 128 129 XEmbeddedClient xClient = xEmbObj.getClientSite(); 130 if ( xClient == null ) 131 { 132 m_aTestHelper.Error( "The client for the object must be set!" ); 133 return false; 134 } 135 136 Object oReplacement = xShapeProps.getPropertyValue( "Graphic" ); 137 XGraphic xReplGraph = ( XGraphic ) UnoRuntime.queryInterface( XGraphic.class, oReplacement ); 138 if ( xReplGraph == null ) 139 { 140 m_aTestHelper.Error( "The replacement graphic should be available!" ); 141 return false; 142 } 143 144 return true; 145 } 146 catch( Exception e ) 147 { 148 m_aTestHelper.Error( "Exception: " + e ); 149 return false; 150 } 151 } 152 } 153 154