I’m trying to create a new numbering style of com.sun.star.style.NumberingType.TEXT_CARDINAL (i.e. One, Two, Three…) using UNO. My attempts so far have been unsuccessful, and I’ve searched high and low for an example with no joy.
I tried the following function (preceded by test calls), which works fine when called to create a paragraph style. But it fails when called to create a numbering style, throwing a com.sun.star.lang.WrappedTargetException on the line xMPS.setPropertyValues(prop_names, prop_values);. Also, part of the trace spewed by my IDE along with the exception was the line “at com.sun.proxy.$Proxy11.setPropertyValues(Unknown Source)”.
createStyle("Paragraph Centered", "ParagraphStyle", "ParagraphStyles", new String[]{"ParaAdjust"}, new Object[]{com.sun.star.style.ParagraphAdjust.CENTER});
createStyle("Numbering Cardinal", "NumberingStyle", "NumberingStyles", new String[]{"NumberingType"}, new Object[]{com.sun.star.style.NumberingType.TEXT_CARDINAL});
private void createStyle (String new_style_name, String base_style_name, String style_family_name, String[] prop_names, Object[] prop_values) throws Exception {
// External functions provide xStyle and xFamily with no problems
XStyle xStyle = getXStyle(base_style_name);
XNameContainer xFamily = getStyleFamily (style_family_name);
// Unless it already exists, customize and then add style to LO
if (xFamily.hasByName(new_style_name) == false) {
if (prop_names.length > 0) {
XMultiPropertySet xMPS = (XMultiPropertySet)UnoRuntime.queryInterface(XMultiPropertySet.class, xStyle);
xMPS.setPropertyValues(prop_names, prop_values);
}
xFamily.insertByName (new_style_name, xStyle);
}
}
I’ve also tried creating a paragraph style with numbering added to it using the following function (again, preceded by a test call). It fails with a throw of com.sun.star.beans.UnknownPropertyException on the line xPropertySet.setPropertyValue(“NumberingRules”, xNum);. Also, similar to before, the IDE’s trace along with the exception included “at com.sun.proxy.$Proxy13.setPropertyValue(Unknown Source)”.
createNumParaStyle("Numbering Cardinal", "ParagraphStyle", "ParagraphStyles");private
void createNumParaStyle (String new_style_name, String base_style_name, String style_family_name) throws Exception {
// External functions provide xStyle and xFamily with no problems
XStyle xParaStyle = getXStyle(base_style_name);
XNameContainer xFamily = getStyleFamily (style_family_name);
if (xFamily.hasByName(new_style_name) == false) {
XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, msFactory.createInstance("com.sun.star.text.NumberingRules"));
XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNum);
PropertyValue[] aProps = (PropertyValue []) xNum.getByIndex(0);
for (int j = 0 ; j < aProps.length ; ++j) {
if (aProps[j].Name.equals ("NumberingType")) {
aProps[j].Value = Short.valueOf(com.sun.star.style.NumberingType.TEXT_CARDINAL);
continue;
}
}
xReplace.replaceByIndex (0,aProps);
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xParaStyle);
xPropertySet.setPropertyValue("NumberingRules", xNum);
xPropertySet.setPropertyValue("NumberingLevel", (short)0);
xFamily.insertByName (new_style_name, xParaStyle);
}
}
It’s pretty clear I’m missing something related to setPropertyValue in each case. In the latter case, the exception seems to suggest (at least to me) that I might need to get a different interface than XPropertySet to provide access to the paragraph styles properties. But I don’t know what that interface would be or where to get it from.
Any suggestions as to what I might be missing or doing wrong?