* deal with the style, the inserted span will also have the style of
* <code>parentNode</code>.
*/
private void adjustStyle(Node parentNode, OdfTextSpan textSpan, Map<OdfStyleProperty, String> styleMap) {
if (parentNode instanceof OdfStylableElement) {
OdfStylableElement pStyleNode = (OdfStylableElement) parentNode;
if (styleMap == null) {
styleMap = getTextStylePropertiesDeep(pStyleNode);
}
Node node = parentNode.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.TEXT_NODE) {
if (node.getTextContent().length() > 0) {
Node nextNode = node.getNextSibling();
OdfTextSpan span = new OdfTextSpan((OdfFileDom) node.getOwnerDocument());
span.appendChild(node);
if (nextNode != null) {
parentNode.insertBefore(span, nextNode);
} else {
parentNode.appendChild(span);
}
node = span;
applyTextStyleProperties(styleMap, (OdfStylableElement) node);
}
} else if ((node instanceof OdfStylableElement)) {
if (!node.equals(textSpan)) {
Map<OdfStyleProperty, String> styles = getTextStylePropertiesDeep(pStyleNode);
Map<OdfStyleProperty, String> styles1 = getTextStylePropertiesDeep((OdfStylableElement) node);
if (styles == null) {
styles = styles1;
} else if (styles1 != null) {
styles.putAll(styles1);
}
int comp = node.compareDocumentPosition(textSpan);
// if node contains textSpan, then recurse the node
if ((comp & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0) {
adjustStyle(node, textSpan, styles);
} else {
applyTextStyleProperties(styles, (OdfStylableElement) node);
}
}
}
node = node.getNextSibling();
}
// change the parentNode to default style
// here we don't know the default style name, so here just
// remove the text:style-name attribute
pStyleNode.removeAttributeNS(OdfDocumentNamespace.TEXT.getUri(), "style-name");
}
}