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