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