NodeIterator pPrNodeIt,
String pStyleVal, NodeIterator childResults,
String htmlElementName ) {
StyleTree styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
// Note that this is invoked for every paragraph with a pPr node.
// incoming objects are org.apache.xml.dtm.ref.DTMNodeIterator
// which implements org.w3c.dom.traversal.NodeIterator
Style defaultParagraphStyle =
(context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle() :
null);
String defaultParagraphStyleId;
if (defaultParagraphStyle==null) // possible, for non MS source docx
defaultParagraphStyleId = "Normal";
else defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
if ( pStyleVal ==null || pStyleVal.equals("") ) {
// pStyleVal = "Normal";
pStyleVal = defaultParagraphStyleId;
}
context.getLog().debug("style '" + pStyleVal );
// log.info("pPrNode:" + pPrNodeIt.getClass().getName() ); // org.apache.xml.dtm.ref.DTMNodeIterator
// log.info("childResults:" + childResults.getClass().getName() );
try {
// Get the pPr node as a JAXB object,
// so we can read it using our standard
// methods. Its a bit sad that we
// can't just adorn our DOM tree with the
// original JAXB objects?
PPr pPr = null;
if (pPrNodeIt!=null) { //It is never null
Node n = pPrNodeIt.nextNode();
if (n!=null) {
Unmarshaller u = Context.jc.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Object jaxb = u.unmarshal(n);
try {
pPr = (PPr)jaxb;
} catch (ClassCastException e) {
context.getLog().error("Couldn't cast " + jaxb.getClass().getName() + " to PPr!");
}
}
}
// Create a DOM document to take the results
Document document = XmlUtils.getNewDocumentBuilder().newDocument();
//log.info("Document: " + document.getClass().getName() );
Element xhtmlBlock = document.createElement(htmlElementName);
document.appendChild(xhtmlBlock);
if (context.getLog().isDebugEnabled() && pPr!=null) {
context.getLog().debug(XmlUtils.marshaltoString(pPr, true, true));
}
// Set @class
context.getLog().debug(pStyleVal);
Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();
org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal);
String classVal = StyleTree.getHtmlClassAttributeValue(pTree, asn);
xhtmlBlock.setAttribute("class", classVal);