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