1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sw; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.container.XEnumeration; 40 import com.sun.star.container.XEnumerationAccess; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.text.ControlCharacter; 43 import com.sun.star.text.XText; 44 import com.sun.star.text.XTextCursor; 45 import com.sun.star.text.XTextDocument; 46 import com.sun.star.uno.AnyConverter; 47 import com.sun.star.uno.Type; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 51 /** 52 * 53 * initial description 54 * @see com.sun.star.text.TextPortion 55 * 56 */ 57 public class SwXTextPortion extends TestCase { 58 XTextDocument xTextDoc; 59 60 protected void initialize( TestParameters tParam, PrintWriter log ) { 61 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 62 63 try { 64 log.println( "creating a textdocument" ); 65 xTextDoc = SOF.createTextDoc( null ); 66 } catch ( com.sun.star.uno.Exception e ) { 67 // Some exception occures.FAILED 68 e.printStackTrace( log ); 69 throw new StatusException( "Couldn't create document", e ); 70 } 71 } 72 73 protected void cleanup( TestParameters tParam, PrintWriter log ) { 74 log.println( " disposing xTextDoc " ); 75 util.DesktopTools.closeDoc(xTextDoc); 76 } 77 78 /** 79 * * creating a Testenvironment for the interfaces to be tested 80 * 81 * @param tParam class which contains additional test parameters 82 * @param log class to log the test state and result 83 * 84 * @return Status class 85 * 86 * @see TestParameters 87 * * @see PrintWriter 88 */ 89 protected synchronized TestEnvironment createTestEnvironment 90 (TestParameters tParam, PrintWriter log) { 91 92 XInterface oObj = null; 93 XInterface param = null; 94 XPropertySet paraP = null; 95 XPropertySet portP = null; 96 97 // creation of testobject here 98 // first we write what we are intend to do to log file 99 log.println( "creating a test environment" ); 100 101 // create testobject here 102 103 XText oText = xTextDoc.getText(); 104 XTextCursor oCursor = oText.createTextCursor(); 105 106 log.println( "inserting Strings" ); 107 log.println( "inserting ControlCharacter" ); 108 109 try{ 110 for (int i =0; i < 5; i++){ 111 oText.insertString( oCursor,"Paragraph Number: " + i, false); 112 oText.insertControlCharacter( 113 oCursor, ControlCharacter.LINE_BREAK, false ); 114 oText.insertString( oCursor, 115 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n", 116 false); 117 oText.insertControlCharacter( 118 oCursor, ControlCharacter.LINE_BREAK, false ); 119 oText.insertString( oCursor, 120 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph", 121 false); 122 oText.insertControlCharacter( 123 oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 124 } 125 }catch(Exception e){ 126 log.println("Couldn't insert Text"); 127 e.printStackTrace(log); 128 throw new StatusException( "Couldn't insert Text", e ); 129 } 130 131 // Enumeration 132 XEnumerationAccess oEnumA = (XEnumerationAccess) 133 UnoRuntime.queryInterface( XEnumerationAccess.class, oText ); 134 XEnumeration oEnum = oEnumA.createEnumeration(); 135 136 int n = 0; 137 while ( (oEnum.hasMoreElements()) ) { 138 try { 139 param = (XInterface) AnyConverter.toObject( 140 new Type(XInterface.class),oEnum.nextElement()); 141 log.println("Element Nr.: " + n ); 142 } catch ( Exception e) { 143 log.println("Couldn't get Paragraph"); 144 e.printStackTrace(log); 145 throw new StatusException( "Couldn't get Paragraph", e ); 146 } 147 n++; 148 } 149 150 XEnumerationAccess oEnumP = (XEnumerationAccess) 151 UnoRuntime.queryInterface( XEnumerationAccess.class, param ); 152 XEnumeration oEnum2 = oEnumP.createEnumeration(); 153 try { 154 oObj = (XInterface)AnyConverter.toObject( 155 new Type(XInterface.class),oEnum2.nextElement()); 156 } catch ( Exception e) { 157 log.println("Couldn't get TextPortion"); 158 e.printStackTrace(log); 159 throw new StatusException( "Couldn't get TextPortion", e ); 160 } 161 162 portP = (XPropertySet) 163 UnoRuntime.queryInterface(XPropertySet.class, oObj); 164 paraP = (XPropertySet) 165 UnoRuntime.queryInterface(XPropertySet.class, param); 166 167 168 log.println( "creating a new environment for Paragraph object" ); 169 TestEnvironment tEnv = new TestEnvironment( oObj ); 170 171 log.println("adding ObjRelation TRO for TextContent"); 172 tEnv.addObjRelation("TRO", new Boolean(true)); 173 174 log.println("adding ObjectRelation 'PARA' for CharacterProperties"); 175 tEnv.addObjRelation("PARA", paraP); 176 177 log.println("adding ObjectRelation 'PORTION' for CharacterProperties"); 178 tEnv.addObjRelation("PORTION", portP); 179 180 tEnv.addObjRelation("XTEXT", oText); 181 182 return tEnv; 183 } // finish method getTestEnvironment 184 185 186 } // finish class SwXTextPortion 187 188