String r = BindingHandler.xpathGetString(pkg, customXmlDataStorageParts, storeItemId, xpathExp, prefixMappings);
try {
RPr rPrSDT = null;
Node rPrNode = rPrNodeIt.nextNode();
if (rPrNode!=null) {
rPrSDT = (RPr)XmlUtils.unmarshal(rPrNode);
}
if (r==null || r.trim().equals("")) {
return createPlaceholder(rPrSDT, sdtParent);
}
r = r.trim();
// log.debug(r);
//String unescaped = StringEscapeUtils.unescapeHtml(r);
//log.info("Unescaped: " + unescaped);
// It comes to us unescaped, so the above is unnecessary.
if (r.startsWith("<span")) {
// Wrap the XHTML in a span element with @class, @style as appropriate
// so FS uses suitable CSS
// Code copied from XsltHTMLFunctions.createBlockForRPr
Style defaultRunStyle =
(pkg.getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
pkg.getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultCharacterStyle() :
null);
String defaultCharacterStyleId;
if (defaultRunStyle.getStyleId()==null) // possible, for non MS source docx
defaultCharacterStyleId = "DefaultParagraphFont";
else defaultCharacterStyleId = defaultRunStyle.getStyleId();
StyleTree styleTree = pkg.getMainDocumentPart().getStyleTree();
// Set @class
String classVal =null;
String rStyleVal = defaultCharacterStyleId;
if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
rStyleVal = rPrSDT.getRStyle().getVal();
}
Tree<AugmentedStyle> cTree = styleTree.getCharacterStylesTree();
org.docx4j.model.styles.Node<AugmentedStyle> asn = cTree.get(rStyleVal);
if (asn==null) {
log.warn("No style node for: " + rStyleVal);
} else {
classVal = StyleTree.getHtmlClassAttributeValue(cTree, asn);
}
String css = null;
if ( rPrSDT!=null) {
StringBuilder result = new StringBuilder();
HtmlCssHelper.createCss(pkg, rPrSDT, result);
css = result.toString();
if (css.equals("")) {
css =null;
}
}
if (css==null && classVal==null) {
// Do nothing
} else if (classVal==null) {
// just @style
r = "<span style=\"" + css + "\">" + r + "</span>";
} else if (css==null) {
// just @class
r = "<span class=\"" + classVal + "\">" + r + "</span>";
} else {
r = "<span style=\"" + css + "\" class=\"" + classVal + "\">" + r + "</span>";
}
log.debug("\nenhanced with css: \n" + r);
} else if (Docx4jProperties.getProperty("docx4j.model.datastorage.BindingTraverser.XHTML.Block.rStyle.Adopt", false)) {
log.debug("Block.rStyle.Adopt..");
// its block level, and we're instructed to apply the paragraph style
// linked to w:sdtPr/w:rPr/w:rStyle (if any)
String rStyleVal=null;
if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
rStyleVal = rPrSDT.getRStyle().getVal();
log.debug(".." + rStyleVal);
}
if (rStyleVal==null) {