diff options
author | Oliver Bolte <obo@openoffice.org> | 2004-03-19 13:38:22 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2004-03-19 13:38:22 +0000 |
commit | 7a156ca311eef048f67e24bd859be2720a1fbf1a (patch) | |
tree | b5ce62c58372366c79bd0ceba95b86434465dcb5 /qadevOOo/tests/java/mod/_sw/PageStyle.java | |
parent | 351f9015c8041e6a6b607faf8145fa86b4388e85 (diff) |
INTEGRATION: CWS qadev16 (1.1.2); FILE ADDED
2004/02/16 16:47:31 sg 1.1.2.3: #115512#CHG: reworked getFilteredPropertNames function
2004/02/16 14:47:53 sg 1.1.2.2: #115512#CHG: added documentation and commnts
2004/02/16 10:24:41 sg 1.1.2.1: #115512#NEW: initial version
Diffstat (limited to 'qadevOOo/tests/java/mod/_sw/PageStyle.java')
-rwxr-xr-x | qadevOOo/tests/java/mod/_sw/PageStyle.java | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/mod/_sw/PageStyle.java b/qadevOOo/tests/java/mod/_sw/PageStyle.java new file mode 100755 index 000000000000..399e3acbbcc6 --- /dev/null +++ b/qadevOOo/tests/java/mod/_sw/PageStyle.java @@ -0,0 +1,236 @@ +/************************************************************************* + * + * $RCSfile: PageStyle.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Date: 2004-03-19 14:38:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package mod._sw; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XIndexAccess; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyle; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.text.XText; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import java.io.PrintWriter; +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.DesktopTools; +import util.SOfficeFactory; +import util.utils; + +/** + * Test for object which is represented by service + * <code>com.sun.star.style.PageStyle</code>. <p> + * @see com.sun.star.style.PageStyle + */ +public class PageStyle extends TestCase { + + XTextDocument xTextDoc; + SOfficeFactory SOF = null; + + /** + * Creates text document. + */ + protected void initialize( TestParameters tParam, PrintWriter log ) { + SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); + try { + log.println( "creating a textdocument" ); + xTextDoc = SOF.createTextDoc( null ); + } catch ( com.sun.star.uno.Exception e ) { + e.printStackTrace( log ); + throw new StatusException( "Couldn't create document", e ); + } + } + + /** + * Disposes text document. + */ + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xTextDoc " ); + DesktopTools.closeDoc(xTextDoc); + } + + protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { + TestEnvironment tEnv = null; + XNameAccess oSFNA = null; + XStyle oStyle = null; + XStyle oMyStyle = null; + + log.println("creating a test environment"); + + try { + log.println("getting style"); + XStyleFamiliesSupplier oSFS = (XStyleFamiliesSupplier) + UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, + xTextDoc); + XNameAccess oSF = oSFS.getStyleFamilies(); + oSFNA = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess.class,oSF.getByName("PageStyles")); // get the page style + XIndexAccess oSFIA = (XIndexAccess) + UnoRuntime.queryInterface(XIndexAccess.class, oSFNA); + oStyle = (XStyle) UnoRuntime.queryInterface( + XStyle.class,oSFIA.getByIndex(0)); + log.println("Chosen pool style: "+oStyle.getName()); + + } catch ( com.sun.star.lang.WrappedTargetException e ) { + log.println("Error: exception occured."); + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) { + log.println("Error: exception occured."); + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.container.NoSuchElementException e ) { + log.println("Error: exception occured."); + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } + + try { + log.print("Creating a user-defined style... "); + XMultiServiceFactory oMSF = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); + XInterface oInt = (XInterface) + oMSF.createInstance("com.sun.star.style.PageStyle"); +// oMSF.createInstanceWithArguments("com.sun.star.style.PageStyle",new Object[]{oStyle}); + oMyStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class, oInt); + } catch ( com.sun.star.uno.Exception e ) { + log.println("Error: exception occured."); + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } + + + if (oMyStyle == null) + log.println("FAILED"); + else + log.println("OK"); + + XNameContainer oSFNC = (XNameContainer) + UnoRuntime.queryInterface(XNameContainer.class, oSFNA); + + + try { + if ( oSFNC.hasByName("My Style") ) + oSFNC.removeByName("My Style"); + oSFNC.insertByName("My Style", oMyStyle); + } catch ( com.sun.star.lang.WrappedTargetException e ) { + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.lang.IllegalArgumentException e ) { + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.container.NoSuchElementException e ) { + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.container.ElementExistException e ) { + e.printStackTrace(log); + throw new StatusException( "Couldn't create environment ", e ); + } + + XText oText = xTextDoc.getText(); + XTextCursor oCursor = oText.createTextCursor(); + XPropertySet xProp = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, oCursor); + Property[] props = xProp.getPropertySetInfo().getProperties(); + for (int i=0; i<props.length; i++) + System.out.println("# Property: " + props[i].Name + " val: " + props[i].Type.toString() + " attr: " + props[i].Attributes); + try { + xProp.setPropertyValue("PageDescName", oMyStyle.getName()); + } catch ( com.sun.star.lang.WrappedTargetException e ) { + e.printStackTrace( log ); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.lang.IllegalArgumentException e ) { + e.printStackTrace( log ); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.beans.PropertyVetoException e ) { + e.printStackTrace( log ); + throw new StatusException( "Couldn't create environment ", e ); + } catch ( com.sun.star.beans.UnknownPropertyException e ) { + e.printStackTrace( log ); + throw new StatusException( "Couldn't create environment ", e ); + } + +// oMyStyle = oStyle; + log.println("creating a new environment for object"); + tEnv = new TestEnvironment(oMyStyle); + tEnv.addObjRelation("PoolStyle", oStyle); + + tEnv.addObjRelation("FollowStyle", "Envelope"); + XPropertySet xStyleProp = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, oMyStyle); + + short exclude = PropertyAttribute.MAYBEVOID + PropertyAttribute.READONLY; + String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude); + tEnv.addObjRelation("PropertyNames", names); + + return tEnv; + } + +} |