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