/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* 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 .
*/
package ifc.style;
import ifc.text._NumberingLevel;
import java.util.HashMap;
import lib.MultiPropertyTest;
import lib.Status;
import share.LogWriter;
import util.utils;
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;
/**
* 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 123' and 'Numbering ABC' styles.
*/
protected PropertyTester NumberingStyleTester = new PropertyTester() {
@Override
protected Object getNewValue(String propName, Object oldValue)
throws java.lang.IllegalArgumentException {
if ((oldValue != null) && (oldValue.equals("Numbering 123"))) {
return "Numbering ABC";
} else {
return "Numbering 123";
}
}
};
/**
* Custom tester for paragraph style properties. Switches between
* 'Salutation' and 'Heading' styles.
*/
protected PropertyTester charStyleTester = new PropertyTester() {
@Override
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() {
@Override
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() {
@Override
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() {
@Override
protected Object getNewValue(String propName, Object oldValue) {
if ((oldValue != null) &&
(oldValue.equals(Short.valueOf((short) 0)))) {
return Short.valueOf((short) 2);
} else {
return Short.valueOf((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() {
@Override
protected Object getNewValue(String propName, Object oldValue) {
if ((oldValue != null) &&
(oldValue.equals(Boolean.FALSE))) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
};
/**
* Custom tester for properties which contains image URLs.
* Switches between two JPG images' URLs.
*/
protected PropertyTester URLTester = new PropertyTester() {
@Override
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");
}
}
};
/**
* 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 occurred setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("Exception occurred setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.beans.UnknownPropertyException e) {
log.println("Exception occurred setting property 'ParagraphAdjust'" + e);
} catch (com.sun.star.beans.PropertyVetoException e) {
log.println("Exception occurred 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 represented 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