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 package mod._sd;
24 
25 import com.sun.star.beans.PropertyVetoException;
26 import com.sun.star.beans.UnknownPropertyException;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.drawing.XShape;
29 import com.sun.star.frame.XController;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.WrappedTargetException;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.view.XSelectionSupplier;
36 import ifc.view._XPrintJobBroadcaster;
37 import java.io.File;
38 
39 import java.io.PrintWriter;
40 
41 import lib.StatusException;
42 import lib.TestCase;
43 import lib.TestEnvironment;
44 import lib.TestParameters;
45 
46 import util.DrawTools;
47 import util.SOfficeFactory;
48 import util.utils;
49 
50 
51 /**
52  * Test for object which is represented by service
53  * <code>com.sun.star.presentation.PresentationDocument</code>. <p>
54  * Object implements the following interfaces :
55  * <ul>
56  *  <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
57  *  <li> <code>com::sun::star::drawing::XMasterPagesSupplier</code></li>
58  *  <li> <code>com::sun::star::presentation::XCustomPresentationSupplier</code></li>
59  *  <li> <code>com::sun::star::document::XLinkTargetSupplier</code></li>
60  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
61  *  <li> <code>com::sun::star::drawing::XLayerSupplier</code></li>
62  *  <li> <code>com::sun::star::presentation::XPresentationSupplier</code></li>
63  *  <li> <code>com::sun::star::style::XStyleFamiliesSupplier</code></li>
64  *  <li> <code>com::sun::star::drawing::DrawingDocument</code></li>
65  *  <li> <code>com::sun::star::drawing::XDrawPageDuplicator</code></li>
66  *  <li> <code>com::sun::star::drawing::XDrawPagesSupplier</code></li>
67  * </ul>
68  * @see com.sun.star.presentation.PresentationDocument
69  * @see com.sun.star.lang.XMultiServiceFactory
70  * @see com.sun.star.drawing.XMasterPagesSupplier
71  * @see com.sun.star.presentation.XCustomPresentationSupplier
72  * @see com.sun.star.document.XLinkTargetSupplier
73  * @see com.sun.star.beans.XPropertySet
74  * @see com.sun.star.drawing.XLayerSupplier
75  * @see com.sun.star.presentation.XPresentationSupplier
76  * @see com.sun.star.style.XStyleFamiliesSupplier
77  * @see com.sun.star.drawing.DrawingDocument
78  * @see com.sun.star.drawing.XDrawPageDuplicator
79  * @see com.sun.star.drawing.XDrawPagesSupplier
80  * @see ifc.lang._XMultiServiceFactory
81  * @see ifc.drawing._XMasterPagesSupplier
82  * @see ifc.presentation._XCustomPresentationSupplier
83  * @see ifc.document._XLinkTargetSupplier
84  * @see ifc.beans._XPropertySet
85  * @see ifc.drawing._XLayerSupplier
86  * @see ifc.presentation._XPresentationSupplier
87  * @see ifc.style._XStyleFamiliesSupplier
88  * @see ifc.drawing._DrawingDocument
89  * @see ifc.drawing._XDrawPageDuplicator
90  * @see ifc.drawing._XDrawPagesSupplier
91  */
92 public class SdXImpressDocument extends TestCase {
93     XComponent xImpressDoc;
94     XComponent xImpressDoc2;
95 
96     /**
97      * Called while disposing a <code>TestEnvironment</code>.
98      * Disposes Impress document.
99      * @param tParam test parameters
100      * @param tEnv the environment to cleanup
101      * @param log writer to log information while testing
102      */
103     protected void cleanup(TestParameters Param, PrintWriter log) {
104         log.println("disposing xImpressDoc");
105         util.DesktopTools.closeDoc(xImpressDoc);
106         util.DesktopTools.closeDoc(xImpressDoc2);
107     }
108 
109     /**
110      * Creating a Testenvironment for the interfaces to be tested.
111      * Creates new impress document that is the instance of the service
112      * <code>com.sun.star.presentation.PresentationDocument</code>.
113      * @see com.sun.star.presentation.PresentationDocument
114      */
115     public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
116         PrintWriter log)
117         throws StatusException {
118         log.println("creating a test environment");
119 
120         // get a soffice factory object
121         SOfficeFactory SOF = SOfficeFactory.getFactory(
122             (XMultiServiceFactory) Param.getMSF());
123 
124         try {
125             log.println("creating two impress documents");
126             xImpressDoc2 = SOF.createImpressDoc(null);
127             xImpressDoc = SOF.createImpressDoc(null);
128         } catch (com.sun.star.uno.Exception e) {
129             e.printStackTrace(log);
130             throw new StatusException("Couldn't create documents", e);
131         }
132 
133         XModel xModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
134             xImpressDoc);
135         XModel xModel2 = (XModel) UnoRuntime.queryInterface(XModel.class,
136             xImpressDoc2);
137 
138         XController cont1 = xModel1.getCurrentController();
139         XController cont2 = xModel2.getCurrentController();
140 
141         cont1.getFrame().setName("cont1");
142         cont2.getFrame().setName("cont2");
143 
144         XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface(
145             XSelectionSupplier.class, cont1);
146 
147         XShape aShape = SOF.createShape(xImpressDoc, 5000, 3500, 7500, 5000,
148             "Rectangle");
149 
150 
151         XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aShape);
152 
153         try {
154             xShapeProps.setPropertyValue("FillStyle", com.sun.star.drawing.FillStyle.SOLID);
155             xShapeProps.setPropertyValue("FillTransparence", new Integer(50));
156         } catch (UnknownPropertyException ex) {
157             ex.printStackTrace(log);
158             throw new StatusException("Couldn't make shape transparent", ex);
159         } catch (PropertyVetoException ex) {
160             ex.printStackTrace(log);
161             throw new StatusException("Couldn't make shape transparent", ex);
162         } catch (com.sun.star.lang.IllegalArgumentException ex) {
163             ex.printStackTrace(log);
164             throw new StatusException("Couldn't make shape transparent", ex);
165         } catch (WrappedTargetException ex) {
166             ex.printStackTrace(log);
167             throw new StatusException("Couldn't make shape transparent", ex);
168         }
169 
170         DrawTools.getDrawPage(xImpressDoc, 0).add(aShape);
171 
172         log.println("creating a new environment for drawpage object");
173 
174         TestEnvironment tEnv = new TestEnvironment(xImpressDoc);
175 
176         log.println("adding Controller as ObjRelation for XModel");
177         tEnv.addObjRelation("CONT2", cont2);
178 
179         log.println("Adding SelectionSupplier and Shape to select for XModel");
180         tEnv.addObjRelation("SELSUPP", sel);
181         tEnv.addObjRelation("TOSELECT", aShape);
182 
183         // create object relation for XPrintJobBroadcaster
184         String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory) Param.getMSF())+"printfile.prt" ;
185         File f = new File(fileName);
186         if (f.exists()) {
187             f.delete();
188         }
189         _XPrintJobBroadcaster.MyPrintJobListener listener = new _XPrintJobBroadcaster.MyPrintJobListener(xImpressDoc, fileName);
190         tEnv.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener);
191 
192         return tEnv;
193     } // finish method getTestEnvironment
194 
195 } // finish class SdDrawPage
196