package org.madore.damlengine; import java.util.ArrayList; import java.util.regex.Pattern; import org.w3c.dom.*; public final class TodoSubtitleElement extends TodoDefaultElement { public static class Factory extends TodoElement.Factory { @Override public TodoSubtitleElement newItem(Element node, Context ctx, TodoItem caller) { return new TodoSubtitleElement(node, ctx, caller); } } public TodoSubtitleElement(Element node, Context ctx, TodoItem caller) { super(node, ctx, caller); } @Override public void handleNodeOnly() { if ( ctx.gc.subtitle != null ) throw new IllegalArgumentException("attempting to redefine subtitle"); ctx.gc.subtitle = ctx.doc.createDocumentFragment(); ctx.gc.subtitleStr = node.getTextContent(); ctx.gc.subtitleLang = LangHelper.getLangRec(node); ArrayList childList = getChildList(node); for ( Node child : childList ) { ctx.gc.subtitle.appendChild(child); } Node ws = node.getNextSibling(); if ( ws != null && ( ws.getNodeType() == Node.TEXT_NODE || ws.getNodeType() == Node.CDATA_SECTION_NODE ) && Pattern.matches("^\\s*$",((CharacterData)ws).getData()) ) node.getParentNode().removeChild(ws); node.getParentNode().removeChild(node); } }