forked from amazingfate/loongoffice
2009-05-04 13:51:10 +0200 cmc r271450 : #i101533# latest sw warnings 2009-05-04 00:02:46 +0200 cmc r271436 : #i101517# silence new warnings 2009-05-03 23:13:53 +0200 cmc r271435 : #i101305# add that one back in 2009-05-02 16:30:42 +0200 cmc r271431 : #i101493# get it to build, and remove some warnings 2009-05-02 16:12:37 +0200 cmc r271430 : CWS-TOOLING: rebase CWS cmcfixes58 to trunk@271427 (milestone: DEV300:m47) 2009-04-23 13:19:33 +0200 cmc r271163 : #i101305# remove annoying import foo is unused warnings 2009-04-21 17:10:34 +0200 cmc r271048 : #i101246# remove AVMEDIA_MANAGER_SERVICE_NAME defines again 2009-04-21 17:07:41 +0200 cmc r271047 : #i86323# remove xml2cmp unused methods
205 lines
8.1 KiB
Java
Executable File
205 lines
8.1 KiB
Java
Executable File
/*************************************************************************
|
|
*
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: ConditionalParagraphStyle.java,v $
|
|
* $Revision: 1.4 $
|
|
*
|
|
* This file is part of OpenOffice.org.
|
|
*
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
* only, as published by the Free Software Foundation.
|
|
*
|
|
* OpenOffice.org 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 version 3 for more details
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
* <http://www.openoffice.org/license.html>
|
|
* for a copy of the LGPLv3 License.
|
|
*
|
|
************************************************************************/
|
|
package mod._sw;
|
|
|
|
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.UnoRuntime;
|
|
import com.sun.star.uno.XInterface;
|
|
import java.io.PrintWriter;
|
|
import lib.Status;
|
|
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.ConditionalParagraphStyle</code>. <p>
|
|
* @see com.sun.star.style.ConditionalParagraphStyle
|
|
*/
|
|
public class ConditionalParagraphStyle 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);
|
|
}
|
|
|
|
/**
|
|
* Create a new instance of the conditional
|
|
* paragraph style, and insert it into the document.
|
|
* @see com.sun.star.style.ConditionalParagraphStyle
|
|
* @param tParam The test paramters
|
|
* @param log The log writer.
|
|
*/
|
|
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("ParagraphStyles"));
|
|
XIndexAccess oSFIA = (XIndexAccess)
|
|
UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
|
|
oStyle = (XStyle) UnoRuntime.queryInterface(
|
|
XStyle.class,oSFIA.getByIndex(1));
|
|
} 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.ConditionalParagraphStyle");
|
|
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");
|
|
throw new StatusException(Status.failed("Couldn't create an own style "));
|
|
}
|
|
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);
|
|
try {
|
|
xProp.setPropertyValue("ParaStyleName", 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 );
|
|
}
|
|
|
|
log.println("creating a new environment for object");
|
|
tEnv = new TestEnvironment(oMyStyle);
|
|
tEnv.addObjRelation("PoolStyle", oStyle);
|
|
|
|
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;
|
|
}
|
|
|
|
}
|