merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / util / WriterTools.java
blob0e260c7df358ff5a6eeb619724e96230a0e92706
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WriterTools.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package util;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.container.XNamed;
35 import com.sun.star.drawing.XDrawPage;
36 import com.sun.star.drawing.XDrawPageSupplier;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XText;
40 import com.sun.star.text.XTextContent;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
45 // access the implementations via names
46 import com.sun.star.uno.XInterface;
48 import util.DesktopTools;
51 public class WriterTools {
52 public static XTextDocument createTextDoc(XMultiServiceFactory xMSF) {
53 PropertyValue[] Args = new PropertyValue[0];
54 XComponent comp = DesktopTools.openNewDoc(xMSF, "swriter", Args);
55 XTextDocument WriterDoc = (XTextDocument) UnoRuntime.queryInterface(
56 XTextDocument.class, comp);
58 return WriterDoc;
59 } // finish createTextDoc
61 public static XTextDocument loadTextDoc(XMultiServiceFactory xMSF,
62 String url) {
63 PropertyValue[] Args = new PropertyValue[0];
64 XTextDocument WriterDoc = loadTextDoc(xMSF, url, Args);
66 return WriterDoc;
67 } // finish createTextDoc
69 public static XTextDocument loadTextDoc(XMultiServiceFactory xMSF,
70 String url, PropertyValue[] Args) {
71 XComponent comp = DesktopTools.loadDoc(xMSF, url, Args);
72 XTextDocument WriterDoc = (XTextDocument) UnoRuntime.queryInterface(
73 XTextDocument.class, comp);
75 return WriterDoc;
76 } // finish createTextDoc
78 public static XDrawPage getDrawPage(XTextDocument aDoc) {
79 XDrawPage oDP = null;
81 try {
82 XDrawPageSupplier oDPS = (XDrawPageSupplier) UnoRuntime.queryInterface(
83 XDrawPageSupplier.class, aDoc);
84 oDP = (XDrawPage) oDPS.getDrawPage();
85 } catch (Exception e) {
86 throw new IllegalArgumentException("Couldn't get drawpage");
89 return oDP;
92 public static void insertTextGraphic(XTextDocument aDoc,
93 XMultiServiceFactory xMSF, int hpos,
94 int vpos, int width, int height,
95 String pic, String name) {
96 try {
97 Object oGObject = (XInterface) xMSF.createInstance(
98 "com.sun.star.text.GraphicObject");
100 XText the_text = aDoc.getText();
101 XTextCursor the_cursor = the_text.createTextCursor();
102 XTextContent the_content = (XTextContent) UnoRuntime.queryInterface(
103 XTextContent.class, oGObject);
104 the_text.insertTextContent(the_cursor, the_content, true);
106 XPropertySet oProps = (XPropertySet) UnoRuntime.queryInterface(
107 XPropertySet.class, oGObject);
109 String fullURL = util.utils.getFullTestURL(pic);
110 oProps.setPropertyValue("GraphicURL", fullURL);
111 oProps.setPropertyValue("HoriOrientPosition", new Integer(hpos));
112 oProps.setPropertyValue("VertOrientPosition", new Integer(vpos));
113 oProps.setPropertyValue("Width", new Integer(width));
114 oProps.setPropertyValue("Height", new Integer(height));
116 XNamed the_name = (XNamed) UnoRuntime.queryInterface(XNamed.class,
117 oGObject);
118 the_name.setName(name);
119 } catch (Exception ex) {
120 System.out.println("Exception while insertin TextGraphic");
121 ex.printStackTrace();