try
{
final OfficeStyles automaticStyles = predefCollection.getAutomaticStyles();
final DataStyle autoDataStyle = automaticStyles.getDataStyle(styleName);
if (autoDataStyle != null)
{
final DataStyle derivedStyle = (DataStyle) autoDataStyle.clone();
Node[] nodes = autoDataStyle.getNodeArray();
for (int i = 0; i < nodes.length; i++) {
Node node = nodes[i];
if (node instanceof DataStyle) {
DataStyle element = (DataStyle) node;
final Object apply = element.getAttribute(OfficeNamespaces.STYLE_NS, "apply-style-name");
if (apply != null) {
final String applyStyleName = String.valueOf(apply);
if (!stylesCollection.getAutomaticStyles().containsDataStyle(applyStyleName)) {
final DataStyle autoApplyDataStyle = automaticStyles.getDataStyle(applyStyleName);
if (autoApplyDataStyle != null) {
stylesCollection.getAutomaticStyles().addDataStyle((DataStyle) autoApplyDataStyle.clone());
}
}
break;
}
}
}
stylesCollection.getAutomaticStyles().addDataStyle(derivedStyle);
return;
}
final OfficeStyles commonStyles = predefCollection.getCommonStyles();
final DataStyle commonDataStyle = commonStyles.getDataStyle(styleName);
if (commonDataStyle != null)
{
final DataStyle derivedStyle = (DataStyle) commonDataStyle.clone();
stylesCollection.getCommonStyles().addDataStyle(derivedStyle);
return;
}
Log.warn("Dangling data style: " + styleName);