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 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 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. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sc; 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.DefaultDsc; 33cdf0e10cSrcweir import util.InstCreator; 34cdf0e10cSrcweir import util.ParagraphDsc; 35cdf0e10cSrcweir import util.SOfficeFactory; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 38cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 39cdf0e10cSrcweir import com.sun.star.lang.XComponent; 40cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 41cdf0e10cSrcweir import com.sun.star.sheet.XHeaderFooterContent; 42cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 43cdf0e10cSrcweir import com.sun.star.style.XStyle; 44cdf0e10cSrcweir import com.sun.star.style.XStyleFamiliesSupplier; 45cdf0e10cSrcweir import com.sun.star.text.ControlCharacter; 46cdf0e10cSrcweir import com.sun.star.text.XText; 47cdf0e10cSrcweir import com.sun.star.text.XTextCursor; 48cdf0e10cSrcweir import com.sun.star.text.XTextRange; 49cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 50cdf0e10cSrcweir import com.sun.star.uno.Type; 51cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 52cdf0e10cSrcweir import com.sun.star.uno.XInterface; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * Test for object which is represented by service 56cdf0e10cSrcweir * <code>com.sun.star.text.Text</code>. <p> 57cdf0e10cSrcweir * Object implements the following interfaces : 58cdf0e10cSrcweir * <ul> 59cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRangeMover</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::text::XSimpleText</code></li> 61cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRange</code></li> 62cdf0e10cSrcweir * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li> 63cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRangeCompare</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::container::XElementAccess</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::text::XText</code></li> 67cdf0e10cSrcweir * </ul> 68cdf0e10cSrcweir * @see com.sun.star.text.Text 69cdf0e10cSrcweir * @see com.sun.star.text.XTextRangeMover 70cdf0e10cSrcweir * @see com.sun.star.text.XSimpleText 71cdf0e10cSrcweir * @see com.sun.star.text.XTextRange 72cdf0e10cSrcweir * @see com.sun.star.text.XRelativeTextContentInsert 73cdf0e10cSrcweir * @see com.sun.star.text.XTextRangeCompare 74cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess 75cdf0e10cSrcweir * @see com.sun.star.container.XEnumerationAccess 76cdf0e10cSrcweir * @see com.sun.star.text.XText 77cdf0e10cSrcweir * @see ifc.text._XTextRangeMover 78cdf0e10cSrcweir * @see ifc.text._XSimpleText 79cdf0e10cSrcweir * @see ifc.text._XTextRange 80cdf0e10cSrcweir * @see ifc.text._XRelativeTextContentInsert 81cdf0e10cSrcweir * @see ifc.text._XTextRangeCompare 82cdf0e10cSrcweir * @see ifc.container._XElementAccess 83cdf0e10cSrcweir * @see ifc.container._XEnumerationAccess 84cdf0e10cSrcweir * @see ifc.text._XText 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir public class ScHeaderFooterTextObj extends TestCase { 87cdf0e10cSrcweir 88cdf0e10cSrcweir static XSpreadsheetDocument xSpreadsheetDoc; 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** 91cdf0e10cSrcweir * Creates Spreadsheet document. 92cdf0e10cSrcweir */ initialize( TestParameters tParam, PrintWriter log )93cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 94cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir try { 97cdf0e10cSrcweir log.println( "creating a Spreadsheet document" ); 98cdf0e10cSrcweir xSpreadsheetDoc = SOF.createCalcDoc(null); 99cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 100cdf0e10cSrcweir // Some exception occures.FAILED 101cdf0e10cSrcweir e.printStackTrace( log ); 102cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** 108cdf0e10cSrcweir * Disposes Spreadsheet document. 109cdf0e10cSrcweir */ cleanup( TestParameters tParam, PrintWriter log )110cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 111cdf0e10cSrcweir log.println( " disposing xSheetDoc " ); 112cdf0e10cSrcweir XComponent oComp = (XComponent) 113cdf0e10cSrcweir UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc); 114cdf0e10cSrcweir util.DesktopTools.closeDoc(oComp); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** 118cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 119cdf0e10cSrcweir * Retrieves the collection of style families available in the document 120cdf0e10cSrcweir * using the interface <code>XStyleFamiliesSupplier</code>. 121cdf0e10cSrcweir * Obtains default style from the style family <code>'PageStyles'</code>. 122cdf0e10cSrcweir * Retrieves value of the property <code>'RightPageHeaderContent'</code>. 123cdf0e10cSrcweir * Creates text cursor for the text which is printed in the center part of 124cdf0e10cSrcweir * the header or footer using the interface <code>XHeaderFooterContent</code>. 125cdf0e10cSrcweir * Insert some lines using the created cursor and sets new value of the 126cdf0e10cSrcweir * property <code>'RightPageHeaderContent'</code>. The value of the property 127cdf0e10cSrcweir * <code>'RightPageHeaderContent'</code> is the instance of the service 128cdf0e10cSrcweir * <code>com.sun.star.text.Text</code>. 129cdf0e10cSrcweir * Object relations created : 130cdf0e10cSrcweir * <ul> 131cdf0e10cSrcweir * <li> <code>'RangeForMove'</code> for 132cdf0e10cSrcweir * {@link ifc.text._XTextRangeMover} (the range to be moved)</li> 133cdf0e10cSrcweir * <li> <code>'XTextRange'</code> for 134cdf0e10cSrcweir * {@link ifc.text._XTextRangeMover} (the range that includes moving 135cdf0e10cSrcweir * range)</li> 136cdf0e10cSrcweir * <li> <code>'XTEXTINFO'</code> for 137cdf0e10cSrcweir * {@link ifc.text._XRelativeTextContentInsert}(the instance creator 138cdf0e10cSrcweir * which can create instances of some text content service)</li> 139cdf0e10cSrcweir * <li> <code>'PARA'</code> for 140cdf0e10cSrcweir * {@link ifc.text._XRelativeTextContentInsert}(the instance creator 141cdf0e10cSrcweir * which can create instances of <code>com.sun.star.text.Paragraph</code> 142cdf0e10cSrcweir * service)</li> 143cdf0e10cSrcweir * </ul> 144cdf0e10cSrcweir * @see com.sun.star.text.Text 145cdf0e10cSrcweir */ createTestEnvironment(TestParameters tParam, PrintWriter log)146cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 147cdf0e10cSrcweir 148cdf0e10cSrcweir XInterface oObj = null; 149cdf0e10cSrcweir XPropertySet PropSet; 150cdf0e10cSrcweir XNameAccess PageStyles = null; 151cdf0e10cSrcweir XStyle StdStyle = null; 152cdf0e10cSrcweir 153cdf0e10cSrcweir XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 154cdf0e10cSrcweir UnoRuntime.queryInterface( 155cdf0e10cSrcweir XStyleFamiliesSupplier.class, 156cdf0e10cSrcweir xSpreadsheetDoc ); 157cdf0e10cSrcweir XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 158cdf0e10cSrcweir try{ 159cdf0e10cSrcweir PageStyles = (XNameAccess) AnyConverter.toObject( 160cdf0e10cSrcweir new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 161cdf0e10cSrcweir StdStyle = (XStyle) AnyConverter.toObject( 162cdf0e10cSrcweir new Type(XStyle.class),PageStyles.getByName("Default")); 163cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e){ 164cdf0e10cSrcweir e.printStackTrace(log); 165cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 166cdf0e10cSrcweir } catch(com.sun.star.container.NoSuchElementException e){ 167cdf0e10cSrcweir e.printStackTrace(log); 168cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 169cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e){ 170cdf0e10cSrcweir e.printStackTrace(log); 171cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir //get the property-set 175cdf0e10cSrcweir PropSet = (XPropertySet) 176cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, StdStyle); 177cdf0e10cSrcweir 178cdf0e10cSrcweir XHeaderFooterContent RPHC = null; 179cdf0e10cSrcweir // creation of testobject here 180cdf0e10cSrcweir // first we write what we are intend to do to log file 181cdf0e10cSrcweir log.println( "creating a test environment" ); 182cdf0e10cSrcweir try { 183cdf0e10cSrcweir RPHC = (XHeaderFooterContent) AnyConverter.toObject( 184cdf0e10cSrcweir new Type(XHeaderFooterContent.class), 185cdf0e10cSrcweir PropSet.getPropertyValue("RightPageHeaderContent")); 186cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e){ 187cdf0e10cSrcweir e.printStackTrace(log); 188cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 189cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e){ 190cdf0e10cSrcweir e.printStackTrace(log); 191cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 192cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e){ 193cdf0e10cSrcweir e.printStackTrace(log); 194cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir XText center = RPHC.getCenterText(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir XTextRange text_to_move = null; 200cdf0e10cSrcweir 201cdf0e10cSrcweir log.println( "inserting some lines" ); 202cdf0e10cSrcweir try { 203cdf0e10cSrcweir XTextCursor oCursor = center.createTextCursor(); 204cdf0e10cSrcweir center.insertControlCharacter( 205cdf0e10cSrcweir oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 206cdf0e10cSrcweir center.insertControlCharacter( 207cdf0e10cSrcweir oCursor, ControlCharacter.LINE_BREAK, false ); 208cdf0e10cSrcweir center.insertString(oCursor,"Paragraph 1", false); 209cdf0e10cSrcweir center.insertString(oCursor,": ScHeaderFooterTextObj", false); 210cdf0e10cSrcweir center.insertControlCharacter( 211cdf0e10cSrcweir oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 212cdf0e10cSrcweir center.insertString(oCursor, "THE QUICK BROWN FOX JUMPS OVER THE" + 213cdf0e10cSrcweir " LAZY DOG: ScHeaderFooterTextObj", false ); 214cdf0e10cSrcweir center.insertControlCharacter( 215cdf0e10cSrcweir oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 216cdf0e10cSrcweir center.insertControlCharacter( 217cdf0e10cSrcweir oCursor, ControlCharacter.LINE_BREAK, false ); 218cdf0e10cSrcweir oCursor.setString("TextForMove"); 219cdf0e10cSrcweir text_to_move = oCursor; 220cdf0e10cSrcweir 221cdf0e10cSrcweir XTextCursor oCursor1 = center.createTextCursorByRange(center.getEnd()); 222cdf0e10cSrcweir center.insertString(oCursor1,"Paragraph 2", false); 223cdf0e10cSrcweir center.insertString(oCursor1,": ScHeaderFooterTextObj", false); 224cdf0e10cSrcweir center.insertControlCharacter( 225cdf0e10cSrcweir oCursor1, ControlCharacter.PARAGRAPH_BREAK, false ); 226cdf0e10cSrcweir center.insertString( oCursor1, "THE QUICK BROWN FOX JUMPS OVER THE" + 227cdf0e10cSrcweir " LAZY DOG: ScHeaderFooterTextObj", false); 228cdf0e10cSrcweir center.insertControlCharacter( 229cdf0e10cSrcweir oCursor1, ControlCharacter.PARAGRAPH_BREAK, false ); 230cdf0e10cSrcweir center.insertControlCharacter( 231cdf0e10cSrcweir oCursor1, ControlCharacter.LINE_BREAK, false ); 232cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e){ 233cdf0e10cSrcweir e.printStackTrace(log); 234cdf0e10cSrcweir throw new StatusException("Couldn't insert Text ", e); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir try { 238cdf0e10cSrcweir PropSet.setPropertyValue("RightPageHeaderContent", RPHC); 239cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 240cdf0e10cSrcweir e.printStackTrace(log); 241cdf0e10cSrcweir throw new StatusException("Couldn't set HeaderContent", e); 242cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 243cdf0e10cSrcweir e.printStackTrace(log); 244cdf0e10cSrcweir throw new StatusException("Couldn't set HeaderContent", e); 245cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e) { 246cdf0e10cSrcweir e.printStackTrace(log); 247cdf0e10cSrcweir throw new StatusException("Couldn't set HeaderContent", e); 248cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 249cdf0e10cSrcweir e.printStackTrace(log); 250cdf0e10cSrcweir throw new StatusException("Couldn't set HeaderContent", e); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir // create testobject here 254cdf0e10cSrcweir oObj = center; 255cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 256cdf0e10cSrcweir 257cdf0e10cSrcweir DefaultDsc tDsc = new DefaultDsc( 258cdf0e10cSrcweir "com.sun.star.text.XTextContent","com.sun.star.text.TextField.Time"); 259cdf0e10cSrcweir 260cdf0e10cSrcweir log.println( "adding InstCreator object" ); 261cdf0e10cSrcweir tEnv.addObjRelation( 262cdf0e10cSrcweir "XTEXTINFO", new InstCreator( xSpreadsheetDoc, tDsc ) ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir ParagraphDsc pDsc = new ParagraphDsc(); 265cdf0e10cSrcweir tEnv.addObjRelation( "PARA", new InstCreator(xSpreadsheetDoc, pDsc) ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir log.println("adding TextRange for XTextRangeMover" ); 268cdf0e10cSrcweir tEnv.addObjRelation("RangeForMove", text_to_move); 269cdf0e10cSrcweir tEnv.addObjRelation("XTextRange", RPHC.getCenterText()); 270cdf0e10cSrcweir 271cdf0e10cSrcweir return tEnv; 272cdf0e10cSrcweir 273cdf0e10cSrcweir } // finish method getTestEnvironment 274cdf0e10cSrcweir } // finish class ScHeaderFooterTextObj 275