1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sd;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.document.XLinkTargetSupplier;
41 import com.sun.star.drawing.XDrawPage;
42 import com.sun.star.drawing.XShape;
43 import com.sun.star.drawing.XShapes;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.document.LinkTargets</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
55 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
56 * </ul>
57 * @see com.sun.star.document.LinkTargets
58 * @see com.sun.star.container.XNameAccess
59 * @see com.sun.star.container.XElementAccess
60 * @see ifc.container._XNameAccess
61 * @see ifc.container._XElementAccess
62 */
63 public class SdPageLinkTargets extends TestCase {
64     XComponent xDrawDoc;
65 
66     /**
67     * Creates Drawing document.
68     */
69     protected void initialize(TestParameters Param, PrintWriter log) {
70        // get a soffice factory object
71         SOfficeFactory SOF = SOfficeFactory.getFactory(
72                                     (XMultiServiceFactory)Param.getMSF());
73 
74         try {
75             log.println( "creating a draw document" );
76             xDrawDoc = SOF.createDrawDoc(null);
77         } catch (com.sun.star.uno.Exception e) {
78             // Some exception occures.FAILED
79             e.printStackTrace( log );
80             throw new StatusException( "Couldn't create document", e );
81         }
82     }
83 
84     /**
85     * Disposes Drawing document.
86     */
87     protected void cleanup( TestParameters Param, PrintWriter log) {
88         log.println("disposing xDrawDoc");
89         util.DesktopTools.closeDoc(xDrawDoc);;
90     }
91 
92     /**
93     * Creating a Testenvironment for the interfaces to be tested.
94     * Retrieves the collection of draw pages and take one of them.
95     * Obtains the collection of possible links using the interface
96     * <code>XLinkTargetSupplier</code>. The obtained collection is
97     * the instance of the service <code>com.sun.star.document.LinkTargets</code>.
98     * Inserts some shapes into the document.
99     * @see com.sun.star.document.XLinkTargetSupplier
100     * @see com.sun.star.document.LinkTargets
101     */
102     public synchronized TestEnvironment createTestEnvironment(
103         TestParameters Param, PrintWriter log) throws StatusException {
104 
105         // creation of testobject here
106         // first we write what we are intend to do to log file
107         log.println( "creating a test environment" );
108 
109         // create testobject here
110         XDrawPage the_page = DrawTools.getDrawPage(xDrawDoc, 0);
111         XLinkTargetSupplier oLTS = (XLinkTargetSupplier)
112             UnoRuntime.queryInterface(XLinkTargetSupplier.class, the_page);
113         XInterface oObj = oLTS.getLinks();
114 
115         SOfficeFactory SOF = SOfficeFactory.getFactory(
116                                     (XMultiServiceFactory)Param.getMSF());
117         log.println( "inserting some Shapes" );
118         XShapes oShapes = (XShapes)
119             UnoRuntime.queryInterface(XShapes.class,the_page);
120         XShape oShape =
121             SOF.createShape(xDrawDoc, 15000, 13500, 5000, 5000, "OLE2");
122         oShapes.add(oShape);
123 
124         XPropertySet shape_props = (XPropertySet)
125                         UnoRuntime.queryInterface(XPropertySet.class,oShape);
126 
127         log.println("Inserting a Chart");
128 
129         try {
130             shape_props.
131                 setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e");
132         } catch (com.sun.star.lang.WrappedTargetException e) {
133             e.printStackTrace(log);
134             throw new StatusException("Couldn't change property", e);
135         } catch (com.sun.star.lang.IllegalArgumentException e) {
136             e.printStackTrace(log);
137             throw new StatusException("Couldn't change property", e);
138         } catch (com.sun.star.beans.PropertyVetoException e) {
139             e.printStackTrace(log);
140             throw new StatusException("Couldn't change property", e);
141         } catch (com.sun.star.beans.UnknownPropertyException e) {
142             e.printStackTrace(log);
143             throw new StatusException("Couldn't change property", e);
144         }
145 
146         log.println( "creating a new environment for LinkTargets object" );
147         TestEnvironment tEnv = new TestEnvironment( oObj );
148 
149         return tEnv;
150     } // finish method createTestEnvironment
151 
152 } // finish class SdPageLinkTargets
153 
154