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.InstCreator; 37 import util.ParagraphDsc; 38 import util.SOfficeFactory; 39 import util.TableDsc; 40 41 import com.sun.star.beans.XPropertySet; 42 import com.sun.star.container.XNameAccess; 43 import com.sun.star.lang.XMultiServiceFactory; 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.text.XTextDocument; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 54 /** 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::text::XTextRangeMover</code></li> 58 * <li> <code>com::sun::star::text::XSimpleText</code></li> 59 * <li> <code>com::sun::star::text::XTextRange</code></li> 60 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li> 61 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li> 62 * <li> <code>com::sun::star::container::XElementAccess</code></li> 63 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 64 * <li> <code>com::sun::star::text::XText</code></li> 65 * </ul> <p> 66 * This object test <b> is NOT </b> designed to be run in several 67 * threads concurently. 68 * @see com.sun.star.text.XTextRangeMover 69 * @see com.sun.star.text.XSimpleText 70 * @see com.sun.star.text.XTextRange 71 * @see com.sun.star.text.XRelativeTextContentInsert 72 * @see com.sun.star.text.XTextRangeCompare 73 * @see com.sun.star.container.XElementAccess 74 * @see com.sun.star.container.XEnumerationAccess 75 * @see com.sun.star.text.XText 76 * @see ifc.text._XTextRangeMover 77 * @see ifc.text._XSimpleText 78 * @see ifc.text._XTextRange 79 * @see ifc.text._XRelativeTextContentInsert 80 * @see ifc.text._XTextRangeCompare 81 * @see ifc.container._XElementAccess 82 * @see ifc.container._XEnumerationAccess 83 * @see ifc.text._XText 84 */ 85 public class SwXHeadFootText extends TestCase { 86 XTextDocument xTextDoc; 87 88 /** 89 * Creates text document. 90 */ 91 protected void initialize( TestParameters tParam, PrintWriter log ) { 92 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() ); 93 try { 94 log.println( "creating a textdocument" ); 95 xTextDoc = SOF.createTextDoc( null ); 96 } catch ( com.sun.star.uno.Exception e ) { 97 e.printStackTrace( log ); 98 throw new StatusException( "Couldn't create document", e ); 99 } 100 } 101 102 /** 103 * Disposes text document. 104 */ 105 protected void cleanup( TestParameters tParam, PrintWriter log ) { 106 log.println( " disposing xTextDoc " ); 107 util.DesktopTools.closeDoc(xTextDoc); 108 } 109 110 /** 111 * Creating a Testenvironment for the interfaces to be tested. At first 112 * style families are obtained from text document, then style 'Standard' has 113 * gotten from style family 'PageStyles'. At the end, document header and 114 * footer are switched on and document text is obtained. 115 * Object relations created : 116 * <ul> 117 * <li> <code>'XTEXTINFO'</code> for 118 * {@link ifc.text._XRelativeTextContentInsert}, 119 * {@link ifc.text._XText} : creates tables 6x4</li> 120 * <li> <code>'TEXTDOC'</code> for 121 * {@link ifc.text._XTextRangeCompare} : text document</li> 122 * <li> <code>'PARA'</code> for 123 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li> 124 * </ul> 125 */ 126 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 127 XInterface oObj = null; 128 XPropertySet PropSet; 129 XNameAccess PageStyles = null; 130 XStyle StdStyle = null; 131 132 log.println( "creating a test environment" ); 133 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 134 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc); 135 XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 136 137 // obtains style 'Standatd' from style family 'PageStyles' 138 try { 139 PageStyles = (XNameAccess) AnyConverter.toObject( 140 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 141 StdStyle = (XStyle) AnyConverter.toObject( 142 new Type(XStyle.class),PageStyles.getByName("Standard")); 143 } catch ( com.sun.star.lang.WrappedTargetException e ) { 144 e.printStackTrace(log); 145 throw new StatusException("Error getting style by name!", e); 146 } catch ( com.sun.star.container.NoSuchElementException e ) { 147 e.printStackTrace(log); 148 throw new StatusException("Error, no such style name! ", e); 149 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 150 e.printStackTrace(log); 151 throw new StatusException("Error getting style by name!", e); 152 } 153 154 PropSet = (XPropertySet) 155 UnoRuntime.queryInterface( XPropertySet.class, StdStyle); 156 157 // changing/getting some properties 158 try { 159 log.println( "Switching on header" ); 160 PropSet.setPropertyValue("HeaderIsOn", new Boolean(true)); 161 log.println( "Switching on footer" ); 162 PropSet.setPropertyValue("FooterIsOn", new Boolean(true)); 163 log.println( "Get header text" ); 164 oObj = (XText) UnoRuntime.queryInterface( 165 XText.class, PropSet.getPropertyValue("HeaderText")); 166 } catch ( com.sun.star.lang.WrappedTargetException e ) { 167 e.printStackTrace(log); 168 throw new StatusException("Couldn't set/get propertyValue...", e); 169 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 170 e.printStackTrace(log); 171 throw new StatusException("Couldn't set/get propertyValue...", e); 172 } catch ( com.sun.star.beans.PropertyVetoException e ) { 173 e.printStackTrace(log); 174 throw new StatusException("Couldn't set/get propertyValue...", e); 175 } catch ( com.sun.star.beans.UnknownPropertyException e ) { 176 e.printStackTrace(log); 177 throw new StatusException("Couldn't set/get propertyValue...", e); 178 } 179 180 log.println( "creating a new environment for bodytext object" ); 181 TestEnvironment tEnv = new TestEnvironment( oObj ); 182 183 log.println( " adding Paragraph" ); 184 ParagraphDsc pDsc = new ParagraphDsc(); 185 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) ); 186 187 log.println( "adding InstDescriptor object" ); 188 TableDsc tDsc = new TableDsc( 6, 4 ); 189 190 log.println( "adding InstCreator object" ); 191 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) ); 192 193 tEnv.addObjRelation( "TEXT", oObj); 194 195 return tEnv; 196 } // finish method getTestEnvironment 197 198 } // finish class SwXHeadFootText 199