1*113d1ee9SAndrew Rist /**************************************************************
2*113d1ee9SAndrew Rist  *
3*113d1ee9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*113d1ee9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*113d1ee9SAndrew Rist  * distributed with this work for additional information
6*113d1ee9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*113d1ee9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*113d1ee9SAndrew Rist  * "License"); you may not use this file except in compliance
9*113d1ee9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*113d1ee9SAndrew Rist  *
11*113d1ee9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*113d1ee9SAndrew Rist  *
13*113d1ee9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*113d1ee9SAndrew Rist  * software distributed under the License is distributed on an
15*113d1ee9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*113d1ee9SAndrew Rist  * KIND, either express or implied.  See the License for the
17*113d1ee9SAndrew Rist  * specific language governing permissions and limitations
18*113d1ee9SAndrew Rist  * under the License.
19*113d1ee9SAndrew Rist  *
20*113d1ee9SAndrew Rist  *************************************************************/
21*113d1ee9SAndrew Rist 
22cdf0e10cSrcweir package complex.embedding;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.uno.XInterface;
25cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
26cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.XInterface;
31cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
32cdf0e10cSrcweir import com.sun.star.frame.XLoadable;
33cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier;
34cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages;
35cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
36cdf0e10cSrcweir import com.sun.star.drawing.XShape;
37cdf0e10cSrcweir import com.sun.star.graphic.XGraphic;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir import com.sun.star.embed.*;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir import share.LogWriter;
42cdf0e10cSrcweir import complex.embedding.TestHelper;
43cdf0e10cSrcweir import complex.embedding.EmbeddingTest;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public class Test01 implements EmbeddingTest {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	XMultiServiceFactory m_xMSF;
48cdf0e10cSrcweir 	TestHelper m_aTestHelper;
49cdf0e10cSrcweir 
Test01( XMultiServiceFactory xMSF, LogWriter aLogWriter )50cdf0e10cSrcweir 	public Test01( XMultiServiceFactory xMSF, LogWriter aLogWriter )
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		m_xMSF = xMSF;
53cdf0e10cSrcweir 		m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
test()56cdf0e10cSrcweir     public boolean test()
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		try
59cdf0e10cSrcweir 		{
60cdf0e10cSrcweir 			Object oDoc = m_xMSF.createInstance( "com.sun.star.comp.Draw.DrawingDocument" );
61cdf0e10cSrcweir 			XLoadable xLoad = (XLoadable) UnoRuntime.queryInterface( XLoadable.class, oDoc );
62cdf0e10cSrcweir 			if ( xLoad == null )
63cdf0e10cSrcweir 			{
64cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XLoadable!" );
65cdf0e10cSrcweir 				return false;
66cdf0e10cSrcweir 			}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			xLoad.initNew();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 			XDrawPagesSupplier xDPSupply = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, oDoc );
71cdf0e10cSrcweir 			if ( xDPSupply == null )
72cdf0e10cSrcweir 			{
73cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XDrawPagesSupplier!" );
74cdf0e10cSrcweir 				return false;
75cdf0e10cSrcweir 			}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 			XDrawPages xDrawPages = xDPSupply.getDrawPages();
78cdf0e10cSrcweir 			if ( xDrawPages == null )
79cdf0e10cSrcweir 			{
80cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XDrawPages object!" );
81cdf0e10cSrcweir 				return false;
82cdf0e10cSrcweir 			}
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			if ( xDrawPages.getCount() == 0 )
85cdf0e10cSrcweir 			{
86cdf0e10cSrcweir 				m_aTestHelper.Error( "There must be at least one page in the document!" );
87cdf0e10cSrcweir 				return false;
88cdf0e10cSrcweir 			}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			Object oPage = xDrawPages.getByIndex( 0 );
91cdf0e10cSrcweir 			XDrawPage xPage = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, oPage );
92cdf0e10cSrcweir 			if ( xPage == null )
93cdf0e10cSrcweir 			{
94cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get access to drawing page!" );
95cdf0e10cSrcweir 				return false;
96cdf0e10cSrcweir 			}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 			XMultiServiceFactory xDrFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class,
99cdf0e10cSrcweir 																								  oDoc );
100cdf0e10cSrcweir 			if ( xDrFactory == null )
101cdf0e10cSrcweir 			{
102cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get drawing factory!" );
103cdf0e10cSrcweir 				return false;
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 			Object oShape = xDrFactory.createInstance( "com.sun.star.drawing.OLE2Shape" );
107cdf0e10cSrcweir 			XShape xShape = ( XShape ) UnoRuntime.queryInterface( XShape.class, oShape );
108cdf0e10cSrcweir 			if ( xShape == null )
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not create new shape!" );
111cdf0e10cSrcweir 				return false;
112cdf0e10cSrcweir 			}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oShape );
115cdf0e10cSrcweir 			if ( xShapeProps == null )
116cdf0e10cSrcweir 			{
117cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get access to shapes properties!" );
118cdf0e10cSrcweir 				return false;
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			xPage.add( xShape );
122cdf0e10cSrcweir 			xShapeProps.setPropertyValue( "CLSID", "078B7ABA-54FC-457F-8551-6147e776a997" );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 			Object oEmbObj = xShapeProps.getPropertyValue( "EmbeddedObject" );
125cdf0e10cSrcweir 			XEmbeddedObject xEmbObj = ( XEmbeddedObject ) UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
126cdf0e10cSrcweir 			if ( xEmbObj == null )
127cdf0e10cSrcweir 			{
128cdf0e10cSrcweir 				m_aTestHelper.Error( "Embedded object can not be accessed!" );
129cdf0e10cSrcweir 				return false;
130cdf0e10cSrcweir 			}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 			XEmbeddedClient xClient = xEmbObj.getClientSite();
133cdf0e10cSrcweir 			if ( xClient == null )
134cdf0e10cSrcweir 			{
135cdf0e10cSrcweir 				m_aTestHelper.Error( "The client for the object must be set!" );
136cdf0e10cSrcweir 				return false;
137cdf0e10cSrcweir 			}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 			Object oReplacement = xShapeProps.getPropertyValue( "Graphic" );
140cdf0e10cSrcweir 			XGraphic xReplGraph = ( XGraphic ) UnoRuntime.queryInterface( XGraphic.class, oReplacement );
141cdf0e10cSrcweir 			if ( xReplGraph == null )
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				m_aTestHelper.Error( "The replacement graphic should be available!" );
144cdf0e10cSrcweir 				return false;
145cdf0e10cSrcweir 			}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			return true;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 		catch( Exception e )
150cdf0e10cSrcweir 		{
151cdf0e10cSrcweir 			m_aTestHelper.Error( "Exception: " + e );
152cdf0e10cSrcweir 			return false;
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157