package org.madore.damlengine; import org.w3c.dom.*; public final class TodoCutHere extends TodoDefaultElement { public static class Factory extends TodoElement.Factory { @Override public TodoCutHere newItem(Element node, Context ctx, TodoItem caller) { return new TodoCutHere(node, ctx, caller); } } public TodoCutHere(Element node, Context ctx, TodoItem caller) { super(node, ctx, caller); } @Override public void handleNodeOnly() { if ( ctx.ent == null ) throw new IllegalStateException("entry context not defined in cut-here element"); if ( ctx.ent.doSinglePage == null ) throw new IllegalStateException("cut-here element found in non single-page entry"); String lang = LangHelper.getLangRec(node); String explicitLang = LangHelper.getLangNorec(node); final WeblogLink lk = new WeblogLink(ctx.ent.year, ctx.ent.month, ctx.ent.day, ctx.ent.number, ".CUT", ctx.ent.doSinglePage); lk.setTypeSingle(); if ( ctx.wsc == null || ctx.wsc instanceof Context.WeblogSingleSelectionContext ) { Element div = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "div"); div.setAttributeNS(null, "id", lk.getFragment()); div.setAttributeNS(null, "class", "cut-anchor"); div.appendChild(ctx.doc.createComment(" EMPTY ")); node.getParentNode().replaceChild(div, node); } else { Element p = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p"); Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a"); p.appendChild(a); final String baseDir = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")); a.setAttributeNS(null, "href", lk.getTarget(baseDir)); if ( explicitLang != null ) LangHelper.setLangNorec(p, explicitLang); p.setAttributeNS(null, "class", "cut-link"); if ( lang.equals("en") ) a.appendChild(ctx.doc.createTextNode("[Continue reading\u2026]")); else if ( lang.equals("fr") ) a.appendChild(ctx.doc.createTextNode("[Lire la suite\u2026]")); else if ( lang.equals("de") ) a.appendChild(ctx.doc.createTextNode("[Weiter lesen\u2026]")); else if ( lang.equals("ia") ) a.appendChild(ctx.doc.createTextNode("[Leger ultra\u2026]")); else a.appendChild(ctx.doc.createTextNode("[\u2026]")); node.getParentNode().replaceChild(p, node); Node killPoint = p; while ( ! killPoint.isSameNode(ctx.ent.mainDivNode) ) { Node parent = killPoint.getParentNode(); while ( killPoint.getNextSibling() != null ) parent.removeChild(killPoint.getNextSibling()); // FIXME: deleted node may already have found its way // in the todo deque, which means it could cause a // null pointer exception by trying to access its // parent node. Do something about this! killPoint = parent; } } } }