1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sw; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.InstCreator; 33cdf0e10cSrcweir import util.ParagraphDsc; 34cdf0e10cSrcweir import util.SOfficeFactory; 35cdf0e10cSrcweir import util.TableDsc; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 38cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 39cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 40cdf0e10cSrcweir import com.sun.star.style.XStyle; 41cdf0e10cSrcweir import com.sun.star.style.XStyleFamiliesSupplier; 42cdf0e10cSrcweir import com.sun.star.text.XText; 43cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 44cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 45cdf0e10cSrcweir import com.sun.star.uno.Type; 46cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 47cdf0e10cSrcweir import com.sun.star.uno.XInterface; 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** 51cdf0e10cSrcweir * Object implements the following interfaces : 52cdf0e10cSrcweir * <ul> 53cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRangeMover</code></li> 54cdf0e10cSrcweir * <li> <code>com::sun::star::text::XSimpleText</code></li> 55cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRange</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRangeCompare</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::container::XElementAccess</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::text::XText</code></li> 61cdf0e10cSrcweir * </ul> <p> 62cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 63cdf0e10cSrcweir * threads concurently. 64cdf0e10cSrcweir * @see com.sun.star.text.XTextRangeMover 65cdf0e10cSrcweir * @see com.sun.star.text.XSimpleText 66cdf0e10cSrcweir * @see com.sun.star.text.XTextRange 67cdf0e10cSrcweir * @see com.sun.star.text.XRelativeTextContentInsert 68cdf0e10cSrcweir * @see com.sun.star.text.XTextRangeCompare 69cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess 70cdf0e10cSrcweir * @see com.sun.star.container.XEnumerationAccess 71cdf0e10cSrcweir * @see com.sun.star.text.XText 72cdf0e10cSrcweir * @see ifc.text._XTextRangeMover 73cdf0e10cSrcweir * @see ifc.text._XSimpleText 74cdf0e10cSrcweir * @see ifc.text._XTextRange 75cdf0e10cSrcweir * @see ifc.text._XRelativeTextContentInsert 76cdf0e10cSrcweir * @see ifc.text._XTextRangeCompare 77cdf0e10cSrcweir * @see ifc.container._XElementAccess 78cdf0e10cSrcweir * @see ifc.container._XEnumerationAccess 79cdf0e10cSrcweir * @see ifc.text._XText 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir public class SwXHeadFootText extends TestCase { 82cdf0e10cSrcweir XTextDocument xTextDoc; 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** 85cdf0e10cSrcweir * Creates text document. 86cdf0e10cSrcweir */ initialize( TestParameters tParam, PrintWriter log )87cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 88cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() ); 89cdf0e10cSrcweir try { 90cdf0e10cSrcweir log.println( "creating a textdocument" ); 91cdf0e10cSrcweir xTextDoc = SOF.createTextDoc( null ); 92cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 93cdf0e10cSrcweir e.printStackTrace( log ); 94cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** 99cdf0e10cSrcweir * Disposes text document. 100cdf0e10cSrcweir */ cleanup( TestParameters tParam, PrintWriter log )101cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 102cdf0e10cSrcweir log.println( " disposing xTextDoc " ); 103cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** 107cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. At first 108cdf0e10cSrcweir * style families are obtained from text document, then style 'Standard' has 109cdf0e10cSrcweir * gotten from style family 'PageStyles'. At the end, document header and 110cdf0e10cSrcweir * footer are switched on and document text is obtained. 111cdf0e10cSrcweir * Object relations created : 112cdf0e10cSrcweir * <ul> 113cdf0e10cSrcweir * <li> <code>'XTEXTINFO'</code> for 114cdf0e10cSrcweir * {@link ifc.text._XRelativeTextContentInsert}, 115cdf0e10cSrcweir * {@link ifc.text._XText} : creates tables 6x4</li> 116cdf0e10cSrcweir * <li> <code>'TEXTDOC'</code> for 117cdf0e10cSrcweir * {@link ifc.text._XTextRangeCompare} : text document</li> 118cdf0e10cSrcweir * <li> <code>'PARA'</code> for 119cdf0e10cSrcweir * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li> 120cdf0e10cSrcweir * </ul> 121cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)122cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 123cdf0e10cSrcweir XInterface oObj = null; 124cdf0e10cSrcweir XPropertySet PropSet; 125cdf0e10cSrcweir XNameAccess PageStyles = null; 126cdf0e10cSrcweir XStyle StdStyle = null; 127cdf0e10cSrcweir 128cdf0e10cSrcweir log.println( "creating a test environment" ); 129cdf0e10cSrcweir XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 130cdf0e10cSrcweir UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc); 131cdf0e10cSrcweir XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // obtains style 'Standatd' from style family 'PageStyles' 134cdf0e10cSrcweir try { 135cdf0e10cSrcweir PageStyles = (XNameAccess) AnyConverter.toObject( 136cdf0e10cSrcweir new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 137cdf0e10cSrcweir StdStyle = (XStyle) AnyConverter.toObject( 138cdf0e10cSrcweir new Type(XStyle.class),PageStyles.getByName("Standard")); 139cdf0e10cSrcweir } catch ( com.sun.star.lang.WrappedTargetException e ) { 140cdf0e10cSrcweir e.printStackTrace(log); 141cdf0e10cSrcweir throw new StatusException("Error getting style by name!", e); 142cdf0e10cSrcweir } catch ( com.sun.star.container.NoSuchElementException e ) { 143cdf0e10cSrcweir e.printStackTrace(log); 144cdf0e10cSrcweir throw new StatusException("Error, no such style name! ", e); 145cdf0e10cSrcweir } catch ( com.sun.star.lang.IllegalArgumentException e ) { 146cdf0e10cSrcweir e.printStackTrace(log); 147cdf0e10cSrcweir throw new StatusException("Error getting style by name!", e); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir PropSet = (XPropertySet) 151cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, StdStyle); 152cdf0e10cSrcweir 153cdf0e10cSrcweir // changing/getting some properties 154cdf0e10cSrcweir try { 155cdf0e10cSrcweir log.println( "Switching on header" ); 156cdf0e10cSrcweir PropSet.setPropertyValue("HeaderIsOn", new Boolean(true)); 157cdf0e10cSrcweir log.println( "Switching on footer" ); 158cdf0e10cSrcweir PropSet.setPropertyValue("FooterIsOn", new Boolean(true)); 159cdf0e10cSrcweir log.println( "Get header text" ); 160cdf0e10cSrcweir oObj = (XText) UnoRuntime.queryInterface( 161cdf0e10cSrcweir XText.class, PropSet.getPropertyValue("HeaderText")); 162cdf0e10cSrcweir } catch ( com.sun.star.lang.WrappedTargetException e ) { 163cdf0e10cSrcweir e.printStackTrace(log); 164cdf0e10cSrcweir throw new StatusException("Couldn't set/get propertyValue...", e); 165cdf0e10cSrcweir } catch ( com.sun.star.lang.IllegalArgumentException e ) { 166cdf0e10cSrcweir e.printStackTrace(log); 167cdf0e10cSrcweir throw new StatusException("Couldn't set/get propertyValue...", e); 168cdf0e10cSrcweir } catch ( com.sun.star.beans.PropertyVetoException e ) { 169cdf0e10cSrcweir e.printStackTrace(log); 170cdf0e10cSrcweir throw new StatusException("Couldn't set/get propertyValue...", e); 171cdf0e10cSrcweir } catch ( com.sun.star.beans.UnknownPropertyException e ) { 172cdf0e10cSrcweir e.printStackTrace(log); 173cdf0e10cSrcweir throw new StatusException("Couldn't set/get propertyValue...", e); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir log.println( "creating a new environment for bodytext object" ); 177cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir log.println( " adding Paragraph" ); 180cdf0e10cSrcweir ParagraphDsc pDsc = new ParagraphDsc(); 181cdf0e10cSrcweir tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir log.println( "adding InstDescriptor object" ); 184cdf0e10cSrcweir TableDsc tDsc = new TableDsc( 6, 4 ); 185cdf0e10cSrcweir 186cdf0e10cSrcweir log.println( "adding InstCreator object" ); 187cdf0e10cSrcweir tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir tEnv.addObjRelation( "TEXT", oObj); 190cdf0e10cSrcweir 191cdf0e10cSrcweir return tEnv; 192cdf0e10cSrcweir } // finish method getTestEnvironment 193cdf0e10cSrcweir 194cdf0e10cSrcweir } // finish class SwXHeadFootText 195