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
.container
.XIndexAccess
;
21 import com
.sun
.star
.container
.XNameAccess
;
22 import com
.sun
.star
.container
.XNamed
;
23 import com
.sun
.star
.frame
.XController
;
24 import com
.sun
.star
.frame
.XModel
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.text
.ControlCharacter
;
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
.text
.XTextFrame
;
32 import com
.sun
.star
.text
.XTextSection
;
33 import com
.sun
.star
.text
.XTextSectionsSupplier
;
34 import com
.sun
.star
.text
.XTextTable
;
35 import com
.sun
.star
.text
.XWordCursor
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.view
.XSelectionSupplier
;
40 import java
.io
.PrintWriter
;
42 import lib
.StatusException
;
44 import lib
.TestEnvironment
;
45 import lib
.TestParameters
;
46 import util
.DesktopTools
;
48 import util
.SOfficeFactory
;
49 import util
.WriterTools
;
52 public class SwXTextDocument
extends TestCase
{
53 XTextDocument xTextDoc
;
54 XTextDocument xSecondTextDoc
;
57 protected void initialize(TestParameters tParam
, PrintWriter log
) {
61 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
62 log
.println(" disposing xTextDoc ");
63 DesktopTools
.closeDoc(xSecondTextDoc
);
64 DesktopTools
.closeDoc(xTextDoc
);
68 * creating a Testenvironment for the interfaces to be tested
71 public synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
73 throws StatusException
{
74 TestEnvironment tEnv
= null;
75 XTextTable the_table
= null;
78 log
.println("creating a textdocument");
79 xTextDoc
= WriterTools
.createTextDoc(
82 XText oText
= xTextDoc
.getText();
83 XTextCursor oCursor
= oText
.createTextCursor();
85 log
.println("inserting some lines");
88 for (int i
= 0; i
< 5; i
++) {
89 oText
.insertString(oCursor
, "Paragraph Number: " + i
,
91 oText
.insertString(oCursor
,
92 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
94 oText
.insertControlCharacter(oCursor
,
95 ControlCharacter
.PARAGRAPH_BREAK
,
97 oText
.insertString(oCursor
,
98 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
100 oText
.insertControlCharacter(oCursor
,
101 ControlCharacter
.PARAGRAPH_BREAK
,
103 oText
.insertControlCharacter(oCursor
,
104 ControlCharacter
.LINE_BREAK
,
107 for (int i
= 0; i
< 11; i
++) {
108 oText
.insertString(oCursor
, "xTextDoc ", false);
111 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
112 e
.printStackTrace(log
);
113 throw new StatusException("Couldn't insert lines", e
);
116 //insert two sections parent and child
117 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
118 XMultiServiceFactory
.class,
124 XTextSectionsSupplier oTSSupp
= UnoRuntime
.queryInterface(
125 XTextSectionsSupplier
.class,
127 XNameAccess oTSSuppName
= oTSSupp
.getTextSections();
129 oTS
= (XInterface
) oDocMSF
.createInstance(
130 "com.sun.star.text.TextSection");
132 XTextContent oTSC
= UnoRuntime
.queryInterface(
133 XTextContent
.class, oTS
);
134 oText
.insertTextContent(oCursor
, oTSC
, false);
136 XWordCursor oWordC
= UnoRuntime
.queryInterface(
137 XWordCursor
.class, oCursor
);
138 oCursor
.setString("End of TextSection");
139 oCursor
.gotoStart(false);
140 oCursor
.setString("Start of TextSection ");
141 oWordC
.gotoEndOfWord(false);
143 XInterface oTS2
= (XInterface
) oDocMSF
.createInstance(
144 "com.sun.star.text.TextSection");
145 oTSC
= UnoRuntime
.queryInterface(XTextContent
.class,
147 oText
.insertTextContent(oCursor
, oTSC
, false);
149 XIndexAccess oTSSuppIndex
= UnoRuntime
.queryInterface(
153 "getting a TextSection with the XTextSectionSupplier()");
154 xTS
= UnoRuntime
.queryInterface(XTextSection
.class,
155 oTSSuppIndex
.getByIndex(0));
157 XNamed xTSName
= UnoRuntime
.queryInterface(XNamed
.class,
159 xTSName
.setName("SwXTextSection");
161 log
.println(" adding TextTable");
162 the_table
= SOfficeFactory
.createTextTable(xTextDoc
, 6, 4);
164 XNamed the_name
= UnoRuntime
.queryInterface(XNamed
.class,
166 the_name
.setName("SwXTextDocument");
167 SOfficeFactory
.insertTextContent(xTextDoc
,
170 log
.println(" adding ReferenceMark");
172 XInterface aMark
= (XInterface
) oDocMSF
.createInstance(
173 "com.sun.star.text.ReferenceMark");
174 the_name
= UnoRuntime
.queryInterface(XNamed
.class, aMark
);
175 the_name
.setName("SwXTextDocument");
177 XTextContent oTC
= UnoRuntime
.queryInterface(
178 XTextContent
.class, aMark
);
179 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
181 log
.println(" adding TextGraphic");
182 WriterTools
.insertTextGraphic(xTextDoc
, oDocMSF
, 5200, 4200, 4400,
183 4000, "space-metal.jpg",
186 log
.println(" adding EndNote");
188 XInterface aEndNote
= (XInterface
) oDocMSF
.createInstance(
189 "com.sun.star.text.Endnote");
190 oTC
= UnoRuntime
.queryInterface(XTextContent
.class,
192 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
194 log
.println(" adding Bookmark");
195 SOfficeFactory
.insertTextContent(xTextDoc
,
196 SOfficeFactory
.createBookmark(
199 log
.println(" adding DocumentIndex");
200 oTC
= SOfficeFactory
.createIndex(xTextDoc
,
201 "com.sun.star.text.DocumentIndex");
202 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
204 log
.println(" adding TextFrame");
206 XTextFrame frame
= SOfficeFactory
.createTextFrame(xTextDoc
, 500,
208 oTC
= UnoRuntime
.queryInterface(XTextContent
.class,
210 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
212 log
.println("creating a second textdocument");
213 xSecondTextDoc
= WriterTools
.createTextDoc(
215 } catch (com
.sun
.star
.uno
.Exception e
) {
216 // Some exception occurs.FAILED
217 e
.printStackTrace(log
);
218 throw new StatusException("Couldn't create document", e
);
221 if (xTextDoc
!= null) {
222 log
.println("Creating instance...");
224 XText oText
= xTextDoc
.getText();
225 XTextCursor oTextCursor
= oText
.createTextCursor();
227 for (int i
= 0; i
< 11; i
++) {
228 oText
.insertString(oTextCursor
, "xTextDoc ", false);
231 tEnv
= new TestEnvironment(xTextDoc
);
233 log
.println("Failed to create instance.");
238 XModel model1
= UnoRuntime
.queryInterface(XModel
.class,
240 XModel model2
= UnoRuntime
.queryInterface(XModel
.class,
243 XController cont1
= model1
.getCurrentController();
244 XController cont2
= model2
.getCurrentController();
246 cont1
.getFrame().setName("cont1");
247 cont2
.getFrame().setName("cont2");
249 XSelectionSupplier sel
= UnoRuntime
.queryInterface(
250 XSelectionSupplier
.class, cont1
);
252 log
.println("Adding SelectionSupplier and Shape to select for XModel");
253 tEnv
.addObjRelation("SELSUPP", sel
);
254 tEnv
.addObjRelation("TOSELECT", the_table
);
256 log
.println("adding Controller as ObjRelation for XModel");
257 tEnv
.addObjRelation("CONT1", cont1
);
258 tEnv
.addObjRelation("CONT2", cont2
);
262 } // finish class SwXTextDocument