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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.text
.XDocumentIndexesSupplier
;
30 import com
.sun
.star
.text
.XText
;
31 import com
.sun
.star
.text
.XTextContent
;
32 import com
.sun
.star
.text
.XTextCursor
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
39 * Test for the object, which is represented by collection of document indexes.
40 * Object implements the following interfaces:
42 * <li> <code>com::sun::star::container::XNameAccess</code></li>
43 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
44 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurently.
48 * @see com.sun.star.container.XNameAccess
49 * @see com.sun.star.container.XIndexAccess
50 * @see com.sun.star.container.XElementAccess
51 * @see ifc.container._XNameAccess
52 * @see ifc.container._XIndexAccess
53 * @see ifc.container._XElementAccess
55 public class SwXDocumentIndexes
extends TestCase
{
56 XTextDocument xTextDoc
;
59 * Creates text document.
62 protected void initialize( TestParameters tParam
, PrintWriter log
) {
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
65 log
.println( "creating a textdocument" );
66 xTextDoc
= SOF
.createTextDoc( null );
67 } catch ( com
.sun
.star
.uno
.Exception e
) {
68 e
.printStackTrace( log
);
69 throw new StatusException( "Couldn't create document", e
);
74 * Disposes text document.
77 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
78 log
.println( " disposing xTextDoc " );
79 util
.DesktopTools
.closeDoc(xTextDoc
);
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Creates an instance of the service
86 * <code>com.sun.star.text.ContentIndex</code>, then created content index is
87 * inserted to the text document, and finally all document indexes are gotten
88 * from a text document using <code>XDocumentIndexesSupplier</code> interface.
91 public TestEnvironment
createTestEnvironment(
92 TestParameters tParam
, PrintWriter log
) throws StatusException
{
93 XInterface oObj
= null;
94 SOfficeFactory
.getFactory( tParam
.getMSF() );
96 log
.println( "creating a test environment" );
97 XTextContent xTC
= null;
100 xTC
= SOfficeFactory
.createIndex(xTextDoc
,"com.sun.star.text.ContentIndex");
102 catch ( com
.sun
.star
.uno
.Exception e
) {
103 e
.printStackTrace(log
);
104 throw new StatusException("Couldn't create the Index", e
);
107 XText oText
= xTextDoc
.getText();
108 XTextCursor oCursor
= oText
.createTextCursor();
110 log
.println("inserting the Index into text document");
112 oText
.insertTextContent(oCursor
, xTC
, false);
113 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
114 e
.printStackTrace(log
);
115 throw new StatusException("Couldn't insert the Index", e
);
118 XDocumentIndexesSupplier xDocInd
= UnoRuntime
.queryInterface(XDocumentIndexesSupplier
.class,xTextDoc
);
120 oObj
= xDocInd
.getDocumentIndexes();
121 TestEnvironment tEnv
= new TestEnvironment(oObj
);
124 } // finish method getTestEnvironment
126 } // finish class SwXDocumentIndexes