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 
23 
24 package mod._sd;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DrawTools;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.document.XLinkTargetSupplier;
37 import com.sun.star.drawing.XDrawPage;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.drawing.XShapes;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.document.LinkTargets</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
51 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * </ul>
53 * @see com.sun.star.document.LinkTargets
54 * @see com.sun.star.container.XNameAccess
55 * @see com.sun.star.container.XElementAccess
56 * @see ifc.container._XNameAccess
57 * @see ifc.container._XElementAccess
58 */
59 public class SdPageLinkTargets extends TestCase {
60     XComponent xDrawDoc;
61 
62     /**
63     * Creates Drawing document.
64     */
65     protected void initialize(TestParameters Param, PrintWriter log) {
66        // get a soffice factory object
67         SOfficeFactory SOF = SOfficeFactory.getFactory(
68                                     (XMultiServiceFactory)Param.getMSF());
69 
70         try {
71             log.println( "creating a draw document" );
72             xDrawDoc = SOF.createDrawDoc(null);
73         } catch (com.sun.star.uno.Exception e) {
74             // Some exception occures.FAILED
75             e.printStackTrace( log );
76             throw new StatusException( "Couldn't create document", e );
77         }
78     }
79 
80     /**
81     * Disposes Drawing document.
82     */
83     protected void cleanup( TestParameters Param, PrintWriter log) {
84         log.println("disposing xDrawDoc");
85         util.DesktopTools.closeDoc(xDrawDoc);;
86     }
87 
88     /**
89     * Creating a Testenvironment for the interfaces to be tested.
90     * Retrieves the collection of draw pages and take one of them.
91     * Obtains the collection of possible links using the interface
92     * <code>XLinkTargetSupplier</code>. The obtained collection is
93     * the instance of the service <code>com.sun.star.document.LinkTargets</code>.
94     * Inserts some shapes into the document.
95     * @see com.sun.star.document.XLinkTargetSupplier
96     * @see com.sun.star.document.LinkTargets
97     */
98     public synchronized TestEnvironment createTestEnvironment(
99         TestParameters Param, PrintWriter log) throws StatusException {
100 
101         // creation of testobject here
102         // first we write what we are intend to do to log file
103         log.println( "creating a test environment" );
104 
105         // create testobject here
106         XDrawPage the_page = DrawTools.getDrawPage(xDrawDoc, 0);
107         XLinkTargetSupplier oLTS = (XLinkTargetSupplier)
108             UnoRuntime.queryInterface(XLinkTargetSupplier.class, the_page);
109         XInterface oObj = oLTS.getLinks();
110 
111         SOfficeFactory SOF = SOfficeFactory.getFactory(
112                                     (XMultiServiceFactory)Param.getMSF());
113         log.println( "inserting some Shapes" );
114         XShapes oShapes = (XShapes)
115             UnoRuntime.queryInterface(XShapes.class,the_page);
116         XShape oShape =
117             SOF.createShape(xDrawDoc, 15000, 13500, 5000, 5000, "OLE2");
118         oShapes.add(oShape);
119 
120         XPropertySet shape_props = (XPropertySet)
121                         UnoRuntime.queryInterface(XPropertySet.class,oShape);
122 
123         log.println("Inserting a Chart");
124 
125         try {
126             shape_props.
127                 setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e");
128         } catch (com.sun.star.lang.WrappedTargetException e) {
129             e.printStackTrace(log);
130             throw new StatusException("Couldn't change property", e);
131         } catch (com.sun.star.lang.IllegalArgumentException e) {
132             e.printStackTrace(log);
133             throw new StatusException("Couldn't change property", e);
134         } catch (com.sun.star.beans.PropertyVetoException e) {
135             e.printStackTrace(log);
136             throw new StatusException("Couldn't change property", e);
137         } catch (com.sun.star.beans.UnknownPropertyException e) {
138             e.printStackTrace(log);
139             throw new StatusException("Couldn't change property", e);
140         }
141 
142         log.println( "creating a new environment for LinkTargets object" );
143         TestEnvironment tEnv = new TestEnvironment( oObj );
144 
145         return tEnv;
146     } // finish method createTestEnvironment
147 
148 } // finish class SdPageLinkTargets
149 
150