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._sc; 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.XNameAccess; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.sheet.XHeaderFooterContent; 43 import com.sun.star.sheet.XSpreadsheetDocument; 44 import com.sun.star.style.XStyle; 45 import com.sun.star.style.XStyleFamiliesSupplier; 46 import com.sun.star.text.XText; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.text.TextCursor</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::text::XTextCursor</code></li> 58 * <li> <code>com::sun::star::text::XWordCursor</code></li> 59 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li> 60 * <li> <code>com::sun::star::text::XTextRange</code></li> 61 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 62 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li> 63 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 64 * <li> <code>com::sun::star::style::CharacterProperties</code></li> 65 * <li> <code>com::sun::star::text::XSentenceCursor</code></li> 66 * <li> <code>com::sun::star::style::ParagraphProperties</code></li> 67 * <li> <code>com::sun::star::text::XParagraphCursor</code></li> 68 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li> 69 * <li> <code>com::sun::star::util::XSortable</code></li> 70 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li> 71 * </ul> 72 * @see com.sun.star.text.TextCursor 73 * @see com.sun.star.text.XTextCursor 74 * @see com.sun.star.text.XWordCursor 75 * @see com.sun.star.style.CharacterPropertiesComplex 76 * @see com.sun.star.text.XTextRange 77 * @see com.sun.star.beans.XPropertySet 78 * @see com.sun.star.container.XContentEnumerationAccess 79 * @see com.sun.star.beans.XPropertyState 80 * @see com.sun.star.style.CharacterProperties 81 * @see com.sun.star.text.XSentenceCursor 82 * @see com.sun.star.style.ParagraphProperties 83 * @see com.sun.star.text.XParagraphCursor 84 * @see com.sun.star.document.XDocumentInsertable 85 * @see com.sun.star.util.XSortable 86 * @see com.sun.star.style.CharacterPropertiesAsian 87 * @see ifc.text._XTextCursor 88 * @see ifc.text._XWordCursor 89 * @see ifc.style._CharacterPropertiesComplex 90 * @see ifc.text._XTextRange 91 * @see ifc.beans._XPropertySet 92 * @see ifc.container._XContentEnumerationAccess 93 * @see ifc.beans._XPropertyState 94 * @see ifc.style._CharacterProperties 95 * @see ifc.text._XSentenceCursor 96 * @see ifc.style._ParagraphProperties 97 * @see ifc.text._XParagraphCursor 98 * @see ifc.document._XDocumentInsertable 99 * @see ifc.util._XSortable 100 * @see ifc.style._CharacterPropertiesAsian 101 */ 102 public class ScHeaderFooterTextCursor extends TestCase { 103 static XSpreadsheetDocument xSpreadsheetDoc; 104 105 /** 106 * Creates Spreadsheet document. 107 */ 108 protected void initialize( TestParameters tParam, PrintWriter log ) { 109 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 110 111 try { 112 log.println( "creating a Spreadsheet document" ); 113 xSpreadsheetDoc = SOF.createCalcDoc(null); 114 } catch ( com.sun.star.uno.Exception e ) { 115 // Some exception occures.FAILED 116 e.printStackTrace( log ); 117 throw new StatusException( "Couldn't create document", e ); 118 } 119 } 120 121 /** 122 * Disposes Spreadsheet document. 123 */ 124 protected void cleanup( TestParameters tParam, PrintWriter log ) { 125 log.println( " disposing xSheetDoc " ); 126 XComponent oComp = (XComponent) 127 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 128 util.DesktopTools.closeDoc(oComp); 129 } 130 131 /** 132 * Creating a Testenvironment for the interfaces to be tested. 133 * Retrieves the collection of style families available in the document 134 * using the interface <code>XStyleFamiliesSupplier</code>. 135 * Obtains default style from the style family <code>'PageStyles'</code>. 136 * Retrieves value of the property <code>'RightPageHeaderContent'</code>. 137 * Sets some string for the text which is printed in the center part of the 138 * header or footer using the interface <code>XHeaderFooterContent</code> 139 * and sets new value of the property <code>'RightPageHeaderContent'</code>. 140 * Creates text cursor for the text which is printed in the center part of 141 * the header or footer. This text cursor is the instance of the service 142 * <code>com.sun.star.text.TextCursor</code>. 143 * </ul> 144 */ 145 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 146 147 XInterface oObj = null; 148 XPropertySet PropSet; 149 XNameAccess PageStyles = null; 150 XStyle StdStyle = null; 151 152 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 153 UnoRuntime.queryInterface( 154 XStyleFamiliesSupplier.class, 155 xSpreadsheetDoc ); 156 157 XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 158 try{ 159 PageStyles = (XNameAccess) AnyConverter.toObject( 160 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 161 StdStyle = (XStyle) AnyConverter.toObject( 162 new Type(XStyle.class),PageStyles.getByName("Default")); 163 } catch(com.sun.star.lang.WrappedTargetException e){ 164 e.printStackTrace(log); 165 throw new StatusException("Couldn't get by name", e); 166 } catch(com.sun.star.container.NoSuchElementException e){ 167 e.printStackTrace(log); 168 throw new StatusException("Couldn't get by name", e); 169 } catch(com.sun.star.lang.IllegalArgumentException e){ 170 e.printStackTrace(log); 171 throw new StatusException("Couldn't get by name", e); 172 } 173 174 //get the property-set 175 PropSet = (XPropertySet) 176 UnoRuntime.queryInterface(XPropertySet.class, StdStyle); 177 178 XHeaderFooterContent RPHC = null; 179 // creation of testobject here 180 // first we write what we are intend to do to log file 181 log.println( "creating a test environment" ); 182 try { 183 RPHC = (XHeaderFooterContent) AnyConverter.toObject( 184 new Type(XHeaderFooterContent.class), 185 PropSet.getPropertyValue("RightPageHeaderContent")); 186 } catch(com.sun.star.lang.WrappedTargetException e){ 187 e.printStackTrace(log); 188 throw new StatusException("Couldn't get HeaderContent", e); 189 } catch(com.sun.star.beans.UnknownPropertyException e){ 190 e.printStackTrace(log); 191 throw new StatusException("Couldn't get HeaderContent", e); 192 } catch(com.sun.star.lang.IllegalArgumentException e){ 193 e.printStackTrace(log); 194 throw new StatusException("Couldn't get HeaderContent", e); 195 } 196 197 XText center = RPHC.getCenterText(); 198 center.setString("CENTER"); 199 200 try { 201 PropSet.setPropertyValue("RightPageHeaderContent",RPHC); 202 } catch (com.sun.star.lang.WrappedTargetException e) { 203 e.printStackTrace(log); 204 throw new StatusException("Couldn't set HeaderContent", e); 205 } catch (com.sun.star.lang.IllegalArgumentException e) { 206 e.printStackTrace(log); 207 throw new StatusException("Couldn't set HeaderContent", e); 208 } catch (com.sun.star.beans.PropertyVetoException e) { 209 e.printStackTrace(log); 210 throw new StatusException("Couldn't set HeaderContent", e); 211 } catch (com.sun.star.beans.UnknownPropertyException e) { 212 e.printStackTrace(log); 213 throw new StatusException("Couldn't set HeaderContent", e); 214 } 215 216 // create testobject here 217 oObj = center.createTextCursor(); 218 TestEnvironment tEnv = new TestEnvironment(oObj); 219 220 // add relation for XTextRange 221 tEnv.addObjRelation("XTEXT", 222 UnoRuntime.queryInterface(XText.class,center)); 223 224 return tEnv; 225 226 } // finish method getTestEnvironment 227 228 } // finish class ScHeaderFooterTextCursor 229