2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.beans
.PropertyValue
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XNamed
;
23 import com
.sun
.star
.drawing
.XDrawPage
;
24 import com
.sun
.star
.drawing
.XDrawPageSupplier
;
25 import com
.sun
.star
.lang
.XComponent
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.text
.XText
;
28 import com
.sun
.star
.text
.XTextContent
;
29 import com
.sun
.star
.text
.XTextCursor
;
30 import com
.sun
.star
.text
.XTextDocument
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
33 import util
.DesktopTools
;
36 public class WriterTools
{
37 public static XTextDocument
createTextDoc(XMultiServiceFactory xMSF
) {
38 PropertyValue
[] Args
= new PropertyValue
[0];
39 XComponent comp
= DesktopTools
.openNewDoc(xMSF
, "swriter", Args
);
40 XTextDocument WriterDoc
= UnoRuntime
.queryInterface(
41 XTextDocument
.class, comp
);
44 } // finish createTextDoc
46 public static XTextDocument
loadTextDoc(XMultiServiceFactory xMSF
,
48 PropertyValue
[] Args
= new PropertyValue
[0];
49 XTextDocument WriterDoc
= loadTextDoc(xMSF
, url
, Args
);
52 } // finish createTextDoc
54 public static XTextDocument
loadTextDoc(XMultiServiceFactory xMSF
,
55 String url
, PropertyValue
[] Args
) {
56 XComponent comp
= DesktopTools
.loadDoc(xMSF
, url
, Args
);
57 XTextDocument WriterDoc
= UnoRuntime
.queryInterface(
58 XTextDocument
.class, comp
);
61 } // finish createTextDoc
63 public static XDrawPage
getDrawPage(XTextDocument aDoc
) {
67 XDrawPageSupplier oDPS
= UnoRuntime
.queryInterface(
68 XDrawPageSupplier
.class, aDoc
);
69 oDP
= oDPS
.getDrawPage();
70 } catch (Exception e
) {
71 throw new IllegalArgumentException("Couldn't get drawpage");
77 public static void insertTextGraphic(XTextDocument aDoc
,
78 XMultiServiceFactory xMSF
, int hpos
,
79 int vpos
, int width
, int height
,
80 String pic
, String name
) {
82 Object oGObject
= xMSF
.createInstance(
83 "com.sun.star.text.GraphicObject");
85 XText the_text
= aDoc
.getText();
86 XTextCursor the_cursor
= the_text
.createTextCursor();
87 XTextContent the_content
= UnoRuntime
.queryInterface(
88 XTextContent
.class, oGObject
);
89 the_text
.insertTextContent(the_cursor
, the_content
, true);
91 XPropertySet oProps
= UnoRuntime
.queryInterface(
92 XPropertySet
.class, oGObject
);
94 String fullURL
= util
.utils
.getFullTestURL(pic
);
95 oProps
.setPropertyValue("GraphicURL", fullURL
);
96 oProps
.setPropertyValue("HoriOrientPosition", new Integer(hpos
));
97 oProps
.setPropertyValue("VertOrientPosition", new Integer(vpos
));
98 oProps
.setPropertyValue("Width", new Integer(width
));
99 oProps
.setPropertyValue("Height", new Integer(height
));
101 XNamed the_name
= UnoRuntime
.queryInterface(XNamed
.class,
103 the_name
.setName(name
);
104 } catch (Exception ex
) {
105 System
.out
.println("Exception while insertin TextGraphic");
106 ex
.printStackTrace();