1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sw_SwXDocumentIndex" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31' Be sure that all variables are dimensioned: 32option explicit 33 34 35' REQUIRED VARIABLES for interface/service tests: 36Global oCollection As Object 37Global oComponentInstance As Object ' it will be disposed 38Global oXTextContent as Object 39Global oXTextContentRange as Object 40 41 42 43Sub CreateObj() 44 45'************************************************************************* 46' COMPONENT: 47' sw.SwXDocumentIndex 48'************************************************************************* 49On Error Goto ErrHndl 50 Dim i As Integer 51 Dim n As Integer 52 Dim oCursor As Object 53 Dim oSearch As Object 54 Dim oFound As Object 55 Dim oIndexEntry As Object 56 Dim oFoundPos As Object 57 Dim oIndex As Object 58 59 oDoc = utils.createDocument("swriter", cObjectName) 60 oCursor = oDoc.Text.createTextCursor() 61 62 ' write some strings to document 63 for i = 1 to 10 64 oCursor.gotoEnd(false) 65 oDoc.Text.insertString(oCursor, cObjectName, false) 66 oDoc.Text.insertControlCharacter(oCursor, 0, false) 67 next i 68 69 ' insert some IndexMakrs 70 oSearch = oDoc.createSearchDescriptor() 71 oSearch.SearchString = cObjectName 72 oFound = oDoc.findAll(oSearch) 73 74 for n = 0 to oFound.Count - 5 75 oFoundPos = oFound(n) 76 oIndexEntry = oDoc.createInstance("com.sun.star.text.DocumentIndexMark") 77 oDoc.text.insertTextContent(oFoundPos, oIndexEntry, true) 78 next n 79 80 'create an index 81 oIndex = oDoc.createInstance("com.sun.star.text.DocumentIndex") 82 oDoc.Text.insertTextContent(oCursor, oIndex, false) 83 oObj = oIndex 84 85 oXTextContent = oDoc.createInstance("com.sun.star.text.DocumentIndex") 86 oXTextContentRange = oDoc.Text.createTextCursor() 87 88 oIndex = oDoc.createInstance("com.sun.star.text.ContentIndex") 89 oDoc.Text.insertTextContent(oCursor, oIndex, false) 90 oIndex = oDoc.createInstance("com.sun.star.text.ContentIndex") 91 oDoc.Text.insertTextContent(oCursor, oIndex, false) 92 oIndex = oDoc.createInstance("com.sun.star.text.ContentIndex") 93 oDoc.Text.insertTextContent(oCursor, oIndex, false) 94 oComponentInstance = oIndex 95 96 oCollection = oDoc.getDocumentIndexes() 97 98Exit Sub 99ErrHndl: 100 Test.Exception() 101End Sub 102</script:module> 103