From d6b9db7926af4dc6d7df5af55d261731bd623c23 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 10 Oct 2014 21:21:14 +0200 Subject: Introduce a WeblogLink class to refactor a lot of code on how links are written. --- org/madore/damlengine/TodoCutHere.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'org/madore/damlengine/TodoCutHere.java') diff --git a/org/madore/damlengine/TodoCutHere.java b/org/madore/damlengine/TodoCutHere.java index e935c4e..898c784 100644 --- a/org/madore/damlengine/TodoCutHere.java +++ b/org/madore/damlengine/TodoCutHere.java @@ -27,12 +27,15 @@ public final class TodoCutHere extends TodoDefaultElement { 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", - "d." + ctx.ent.date + "." + ctx.ent.number - + ".CUT"); + div.setAttributeNS(null, "id", lk.getFragment()); div.setAttributeNS(null, "class", "cut-anchor"); div.appendChild(ctx.doc.createComment(" EMPTY ")); node.getParentNode().replaceChild(div, node); @@ -40,11 +43,8 @@ public final class TodoCutHere extends TodoDefaultElement { Element p = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p"); Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a"); p.appendChild(a); - a.setAttributeNS(null, "href", - ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")) - + ctx.ent.date + "-" + ctx.ent.doSinglePage + ".html" - + "#d." + ctx.ent.date + "." + ctx.ent.number - + ".CUT"); + 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"); -- cgit v1.2.3