/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.style;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.container.XIndexReplace;
import com.sun.star.container.XNameContainer;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.xml.AttributeData;
import ifc.text._NumberingLevel;
import java.util.Enumeration;
import java.util.Hashtable;
import lib.MultiPropertyTest;
import lib.Status;
import share.LogWriter;
import util.utils;
/**
* Testing com.sun.star.style.ParagraphProperties
* service properties :
*
ParaAdjust
ParaLineSpacing
ParaBackColor
ParaBackTransparent
ParaBackGraphicURL
ParaBackGraphicFilter
ParaBackGraphicLocation
ParaLastLineAdjust
ParaExpandSingleWord
ParaLeftMargin
ParaRightMargin
ParaTopMargin
ParaBottomMargin
ParaLineNumberCount
ParaLineNumberStartValue
ParaIsHyphenation
PageDescName
PageNumberOffset
ParaRegisterModeActive
ParaTabStops
ParaStyleName
DropCapFormat
DropCapWholeWord
ParaKeepTogether
ParaSplit
NumberingLevel
NumberingRules
NumberingStartValue
ParaIsNumberingRestart
NumberingStyleName
ParaOrphans
ParaWidows
ParaShadowFormat
IsHangingPunctuation
IsCharacterDistance
IsForbiddenRules
LeftBorder
RightBorder
TopBorder
BottomBorder
BorderDistance
LeftBorderDistance
RightBorderDistance
TopBorderDistance
BottomBorderDistance
* This test needs the following object relations : *
'NRULES'
: optional
* (service com.sun.star.text.NumberingRules
):
* instance of the service which can be set as 'NumberingRules'
* property new value. If the relation doesn't then two
* different NumberingRules
objects are tried
* to be obtained by setting different 'NumberingStyleName'
* property styles and getting 'NumberingRules' property values.
* Properties testing is automated by lib.MultiPropertyTest
.
* @see com.sun.star.style.ParagraphProperties
*/
public class _ParagraphProperties extends MultiPropertyTest {
/**
* Custom tester for numbering style properties. Switches between
* 'Numbering 1' and 'Numbering 2' styles.
*/
protected PropertyTester NumberingStyleTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue)
throws java.lang.IllegalArgumentException {
if ((oldValue != null) && (oldValue.equals("Numbering 1"))) {
return "Numbering 2";
} else {
return "Numbering 1";
}
}
};
/**
* Custom tester for paragraph style properties. Switches between
* 'Salutation' and 'Heading' styles.
*/
protected PropertyTester charStyleTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if (!utils.isVoid(oldValue) && (oldValue.equals("Example"))) {
return "Emphasis";
} else {
return "Example";
}
}
};
/**
* Custom tester for paragraph style properties. Switches between
* 'Salutation' and 'Heading' styles.
*/
protected PropertyTester ParaStyleTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if (!utils.isVoid(oldValue) && (oldValue.equals("Heading"))) {
return "Salutation";
} else {
return "Heading";
}
}
};
/**
* Custom tester for PageDescName properties. Switches between
* 'HTML' and 'Standard' descriptor names.
*/
protected PropertyTester PageDescTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if (!util.utils.isVoid(oldValue) &&
(oldValue.equals("Default"))) {
return "HTML";
} else {
return "Default";
}
}
};
/**
* Custom tester for properties which have short
type
* and can be void, so if they have void value, the new value must
* be specified. Switches between two different values.
*/
protected PropertyTester ShortTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if ((oldValue != null) &&
(oldValue.equals(new Short((short) 0)))) {
return new Short((short) 2);
} else {
return new Short((short) 0);
}
}
};
/**
* Custom tester for properties which have boolean
type
* and can be void, so if they have void value, the new value must
* be specified. Switches between true and false.
*/
protected PropertyTester BooleanTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if ((oldValue != null) &&
(oldValue.equals(new Boolean((boolean) false)))) {
return new Boolean((boolean) true);
} else {
return new Boolean((boolean) false);
}
}
};
/**
* Custom tester for properties which contains image URLs.
* Switches between two JPG images' URLs.
*/
protected PropertyTester URLTester = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) {
return util.utils.getFullTestURL("crazy-blue.jpg");
} else {
return util.utils.getFullTestURL("space-metal.jpg");
}
}
};
protected PropertyTester rules = null;
/**
* Creates tester for 'NumberingRules' depending on relation.
*/
public void before() {
final Object nRules = tEnv.getObjRelation("NRULES");
if (nRules != null) {
rules = new PropertyTester() {
protected Object getNewValue(String propName, Object oldValue) {
return nRules;
}
};
} else {
Object rules1 = null;
Object rules2 = null;
try {
oObj.setPropertyValue("NumberingStyleName", "Numbering 1");
rules1 = oObj.getPropertyValue("NumberingRules");
oObj.setPropertyValue("NumberingStyleName", "Numbering 2");
rules2 = oObj.getPropertyValue("NumberingRules");
} catch (com.sun.star.lang.WrappedTargetException e) {
log.println("WARNING !!! Exception getting numbering rules :");
e.printStackTrace(log);
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("WARNING !!! Exception getting numbering rules :");
e.printStackTrace(log);
} catch (com.sun.star.beans.PropertyVetoException e) {
log.println("WARNING !!! Exception getting numbering rules :");
e.printStackTrace(log);
} catch (com.sun.star.beans.UnknownPropertyException e) {
log.println("Property 'NumberingStyleName' is not supported.");
}
rules = new PropertyValueSwitcher(rules1, rules2);
}
}
/**
* Tested with custom property tester.
*/
public void _NumberingStyleName() {
log.println("Testing with custom Property tester");
testProperty("NumberingStyleName", NumberingStyleTester);
}
/**
* Tested with custom property tester.
*/
public void _DropCapCharStyleName() {
log.println("Testing with custom Property tester");
testProperty("DropCapCharStyleName", charStyleTester);
}
/**
* Tested with custom property tester.
*/
public void _ParaStyleName() {
log.println("Testing with custom Property tester");
testProperty("ParaStyleName", ParaStyleTester);
}
/**
* Tested with custom property tester.
*/
public void _PageDescName() {
log.println("Testing with custom Property tester");
testProperty("PageDescName", PageDescTester);
}
/**
* Tested with custom property tester. Before testing property
* ParaAdjust
is setting to value BLOCK
* because setting the property ParaLastLineAdjust
* makes sense only in this case.
*/
public void _ParaLastLineAdjust() {
log.println("Testing with custom Property tester");
try {
oObj.setPropertyValue("ParaAdjust",
com.sun.star.style.ParagraphAdjust.BLOCK);
} catch (com.sun.star.lang.WrappedTargetException e) {
log.println("Exception occured setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("Exception occured setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.beans.UnknownPropertyException e) {
log.println("Exception occured setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.beans.PropertyVetoException e) {
log.println("Exception occured setting property 'ParagraphAdjust'" + e);
}
testProperty("ParaLastLineAdjust", ShortTester);
}
/**
* Tested with custom property tester.
*/
public void _ParaBackGraphicURL() {
log.println("Testing with custom Property tester");
testProperty("ParaBackGraphicURL", URLTester);
}
/**
* Tested with custom property tester.
* The following property tests are to be completed successfully before : *
NumberingStyleName
: a numbering style must
* be set before testing this property */ public void _ParaIsConnectBorder() { log.println("Testing with custom Property tester"); testProperty("ParaIsConnectBorder", BooleanTester); } /** * Tested with custom property tester. */ public void _ParaVertAlignment() { log.println("Testing with custom Property tester"); testProperty("ParaVertAlignment", ShortTester); } /** * Tested with com.sun.star.text.NumberingLevel
* The value of this property is a com.sun.star.container.XIndexReplace which is represneted by * com.sun.star.text.NumberingLevel. * The following property tests are to be completed successfully before : *
NumberingStyleName
: a numbering style must
* be set before testing this property