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
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
45 import util
.DesktopTools
;
47 import util
.SOfficeFactory
;
48 import util
.WriterTools
;
50 public class SwXTextDocument
extends TestCase
{
51 XTextDocument xTextDoc
;
52 XTextDocument xSecondTextDoc
;
55 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
56 log
.println(" disposing xTextDoc ");
57 DesktopTools
.closeDoc(xSecondTextDoc
);
58 DesktopTools
.closeDoc(xTextDoc
);
62 * creating a TestEnvironment for the interfaces to be tested
65 public TestEnvironment
createTestEnvironment(
66 TestParameters Param
, PrintWriter log
) throws Exception
{
67 TestEnvironment tEnv
= null;
68 XTextTable the_table
= null;
70 log
.println("creating a textdocument");
71 xTextDoc
= WriterTools
.createTextDoc(Param
.getMSF());
73 XText oText
= xTextDoc
.getText();
74 XTextCursor oCursor
= oText
.createTextCursor();
76 log
.println("inserting some lines");
78 for (int i
= 0; i
< 5; i
++) {
79 oText
.insertString(oCursor
, "Paragraph Number: " + i
, false);
82 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
84 oText
.insertControlCharacter(oCursor
,
85 ControlCharacter
.PARAGRAPH_BREAK
, false);
88 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
90 oText
.insertControlCharacter(oCursor
,
91 ControlCharacter
.PARAGRAPH_BREAK
, false);
92 oText
.insertControlCharacter(oCursor
, ControlCharacter
.LINE_BREAK
,
95 for (int i
= 0; i
< 11; i
++) {
96 oText
.insertString(oCursor
, "xTextDoc ", false);
100 // insert two sections parent and child
101 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
102 XMultiServiceFactory
.class, xTextDoc
);
107 XTextSectionsSupplier oTSSupp
= UnoRuntime
.queryInterface(
108 XTextSectionsSupplier
.class, xTextDoc
);
109 XNameAccess oTSSuppName
= oTSSupp
.getTextSections();
111 oTS
= (XInterface
) oDocMSF
112 .createInstance("com.sun.star.text.TextSection");
114 XTextContent oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS
);
115 oText
.insertTextContent(oCursor
, oTSC
, false);
117 XWordCursor oWordC
= UnoRuntime
.queryInterface(XWordCursor
.class,
119 oCursor
.setString("End of TextSection");
120 oCursor
.gotoStart(false);
121 oCursor
.setString("Start of TextSection ");
122 oWordC
.gotoEndOfWord(false);
124 XInterface oTS2
= (XInterface
) oDocMSF
125 .createInstance("com.sun.star.text.TextSection");
126 oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS2
);
127 oText
.insertTextContent(oCursor
, oTSC
, false);
129 XIndexAccess oTSSuppIndex
= UnoRuntime
.queryInterface(
130 XIndexAccess
.class, oTSSuppName
);
131 log
.println("getting a TextSection with the XTextSectionSupplier()");
132 xTS
= UnoRuntime
.queryInterface(XTextSection
.class,
133 oTSSuppIndex
.getByIndex(0));
135 XNamed xTSName
= UnoRuntime
.queryInterface(XNamed
.class, xTS
);
136 xTSName
.setName("SwXTextSection");
138 log
.println(" adding TextTable");
139 the_table
= SOfficeFactory
.createTextTable(xTextDoc
, 6, 4);
141 XNamed the_name
= UnoRuntime
.queryInterface(XNamed
.class, the_table
);
142 the_name
.setName("SwXTextDocument");
143 SOfficeFactory
.insertTextContent(xTextDoc
, the_table
);
145 log
.println(" adding ReferenceMark");
147 XInterface aMark
= (XInterface
) oDocMSF
148 .createInstance("com.sun.star.text.ReferenceMark");
149 the_name
= UnoRuntime
.queryInterface(XNamed
.class, aMark
);
150 the_name
.setName("SwXTextDocument");
152 XTextContent oTC
= UnoRuntime
.queryInterface(XTextContent
.class, aMark
);
153 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
155 log
.println(" adding TextGraphic");
156 WriterTools
.insertTextGraphic(xTextDoc
, oDocMSF
, Param
.getComponentContext(),
157 5200, 4200, 4400, 4000, "space-metal.jpg", "SwXTextDocument");
159 log
.println(" adding EndNote");
161 XInterface aEndNote
= (XInterface
) oDocMSF
162 .createInstance("com.sun.star.text.Endnote");
163 oTC
= UnoRuntime
.queryInterface(XTextContent
.class, aEndNote
);
164 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
166 log
.println(" adding Bookmark");
167 SOfficeFactory
.insertTextContent(xTextDoc
,
168 SOfficeFactory
.createBookmark(xTextDoc
));
170 log
.println(" adding DocumentIndex");
171 oTC
= SOfficeFactory
.createIndex(xTextDoc
,
172 "com.sun.star.text.DocumentIndex");
173 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
175 log
.println(" adding TextFrame");
177 XTextFrame frame
= SOfficeFactory
.createTextFrame(xTextDoc
, 500, 500);
178 oTC
= UnoRuntime
.queryInterface(XTextContent
.class, frame
);
179 SOfficeFactory
.insertTextContent(xTextDoc
, oTC
);
181 log
.println("creating a second textdocument");
182 xSecondTextDoc
= WriterTools
.createTextDoc(Param
.getMSF());
184 XText oText2
= xTextDoc
.getText();
185 XTextCursor oTextCursor
= oText2
.createTextCursor();
187 for (int i
= 0; i
< 11; i
++) {
188 oText2
.insertString(oTextCursor
, "xTextDoc ", false);
191 tEnv
= new TestEnvironment(xTextDoc
);
193 XModel model1
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
194 XModel model2
= UnoRuntime
.queryInterface(XModel
.class, xSecondTextDoc
);
196 XController cont1
= model1
.getCurrentController();
197 XController cont2
= model2
.getCurrentController();
199 cont1
.getFrame().setName("cont1");
200 cont2
.getFrame().setName("cont2");
202 XSelectionSupplier sel
= UnoRuntime
.queryInterface(
203 XSelectionSupplier
.class, cont1
);
205 log
.println("Adding SelectionSupplier and Shape to select for XModel");
206 tEnv
.addObjRelation("SELSUPP", sel
);
207 tEnv
.addObjRelation("TOSELECT", the_table
);
209 log
.println("adding Controller as ObjRelation for XModel");
210 tEnv
.addObjRelation("CONT1", cont1
);
211 tEnv
.addObjRelation("CONT2", cont2
);
215 } // finish class SwXTextDocument