}
return;
}
// get the style
Style style = liveStyles.get(styleId);
// add it to the stack
if (style==null) {
// No such style!
// For now, just log it..
if (styleId!=null
&& styleId.equals("DocDefaults")) {
// Don't worry about this.
// SDP.createVirtualStylesForDocDefaults()
// creates a DocDefaults style, and makes Normal based on it
// (and so if a different approach to handling
// DocDefaults ... we really should do it one
// way consistently).
// The problem here is, that is typically done
// after the PropertyResolver is created,
// so as far as this PropertyResolver is
// concerned, the style doesn't exist.
// And we don't really want to always
// do createVirtualStylesForDocDefaults() before
// or during init of PropertyResolver, since that
// mean any docx saved would contain those
// virtual styles.
// Anyway, we don't need to worry about it
// here, because the doc defaults are still handled...
} else {
log.error("Style definition not found: " + styleId);
}
return;
}
// For heading styles, check the outline level is as expected
if (styleId.startsWith(HEADING_STYLE)) {
int level = getLvlFromHeadingStyle(styleId);
if (level>0
&& style.getPPr()!=null
&& style.getPPr().getOutlineLvl()!=null
&& style.getPPr().getOutlineLvl().getVal()!=null
&& style.getPPr().getOutlineLvl().getVal().intValue()!=(level-1)) {
// must use the outline level appropriate to this heading!
// No need to clone, since Microsoft Word automatically overwrites like this!
log.info(styleId + " - reset actual outline level with " + (level-1));
style.getPPr().getOutlineLvl().setVal(BigInteger.valueOf(level-1));
}
pPrStack.push(style.getPPr());
} else {
pPrStack.push(style.getPPr());
}
log.debug("Added " + styleId + " to pPr stack");
// Some styles contain numPr, without specifying
// their numId! In this case you have to get it
// from the numPr in their basedOn style.
// To save numbering emulator from having to do
// that work, we make the numId explicit here.
boolean ascertainNumId = false;
if (style.getPPr()!=null
&& style.getPPr().getNumPr()!=null
&& style.getPPr().getNumPr().getNumId()==null) {
ascertainNumId = true;
log.debug(styleId +" ascertainNumId: " + ascertainNumId);
} else {
log.debug(styleId +" ascertainNumId: " + ascertainNumId);
}
// if it is based on, recurse
if (style.getBasedOn()==null) {
log.debug("Style " + styleId + " is a root style.");
} else if (style.getBasedOn().getVal()!=null) {
String basedOnStyleName = style.getBasedOn().getVal();
log.debug("Style " + styleId + " is based on " + basedOnStyleName);
fillPPrStack( basedOnStyleName, pPrStack);
Style basedOnStyle = liveStyles.get(basedOnStyleName);
if (ascertainNumId && basedOnStyle!=null) {
// This works via recursion
//log.debug( XmlUtils.marshaltoString(basedOnStyle, true, true));
if (basedOnStyle.getPPr()!=null
&& basedOnStyle.getPPr().getNumPr()!=null
&& basedOnStyle.getPPr().getNumPr().getNumId()!=null) {
NumId numId = basedOnStyle.getPPr().getNumPr().getNumId();
// Attach it at this level - for this to work,
// you can't have a style in the basedOn hierarchy
// which doesn't have a numPr element, because
// in that case there is nowhere to hang the style
style.getPPr().getNumPr().setNumId(numId);