From 0f041a8ad9595584c9e048ec026ff87cbf481c6f Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 6 Apr 2013 19:17:18 +0200 Subject: Rewrite selection of d:wref target in a hopefully less messy way. --- org/madore/damlengine/TodoWrefAttr.java | 68 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'org/madore/damlengine') diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java index 95583e4..0a94e0d 100644 --- a/org/madore/damlengine/TodoWrefAttr.java +++ b/org/madore/damlengine/TodoWrefAttr.java @@ -32,45 +32,49 @@ public class TodoWrefAttr extends TodoAttr { String wrefDayStr = wrefMatcher.group(3); String wrefNumberStr = wrefMatcher.group(4); String wrefSupplementStr = wrefMatcher.group(5); - String targetFile = ""; - boolean isLocal = false; - if ( ctx.wsc != null && ctx.wsc.sel != null + String targetFile; + String targetStdDir = (ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"); + WeblogSummary wsum = WeblogSummary.getSummary(); + WeblogSummary.EntrySummary esum; + // Get entry for target link from weblog summary + if ( wsum != null && wsum.entries != null ) + esum = wsum.entries.get(new Integer(wrefNumberStr)); + else + esum = null; + // Check consistency if summary was available + if ( esum != null ) { + if ( ! ((wrefYearStr+"-"+wrefMonthStr+"-"+wrefDayStr) + .equals(esum.date)) ) + throw new IllegalArgumentException("date mismatch for reference to entry "+wrefNumberStr); + } + // Choose file portion of link target + if ( esum != null && esum.doSinglePage != null && ! wrefSupplementStr.equals("") ) { + targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html"; + } else if ( ctx.wsc != null && ctx.wsc.sel != null && ctx.wsc.sel.contains(new Integer(wrefNumberStr)) ) { - isLocal = true; targetFile = ""; - } else - targetFile = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")) - + wrefYearStr + "-" + wrefMonthStr + ".html"; + } else { + targetFile = targetStdDir + wrefYearStr + "-" + wrefMonthStr + ".html"; + if ( esum != null && esum.doSinglePage != null + // Note to self: remember we could be called from d:wxref + // because of link on "older entries": we don't want + // to link to single entry page in this case. :-\ + && ! ( caller instanceof TodoWXrefAttr ) ) { + targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html"; + } + } + // Construct full link target String targetFragment = "d." + wrefYearStr + "-" + wrefMonthStr + "-" + wrefDayStr + "." + wrefNumberStr + wrefSupplementStr; String target = targetFile + "#" + targetFragment; + // Class and title attributes if ( ! this.owner.hasAttributeNS(null, "class") ) this.owner.setAttributeNS(null, "class", "weblog-internal-link"); - WeblogSummary wsum = WeblogSummary.getSummary(); - if ( wsum != null && wsum.entries != null ) { - WeblogSummary.EntrySummary esum - = wsum.entries.get(new Integer(wrefNumberStr)); - if ( esum != null ) { - if ( ! ((wrefYearStr+"-"+wrefMonthStr+"-"+wrefDayStr) - .equals(esum.date)) ) - throw new IllegalArgumentException("date mismatch for reference to entry "+wrefNumberStr); - if ( esum.doSinglePage != null - && ! ( wrefSupplementStr.equals("") - && isLocal ) - // Note to self: remember we could be called from d:wxref - // because of link on "older entries": we don't want - // to link to single entry page in this case. :-\ - && ! ( caller instanceof TodoWXrefAttr ) ) { - targetFile = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/")) - + esum.date + "-" + esum.doSinglePage + ".html"; - target = targetFile + "#" + targetFragment; - } - if ( wrefSupplementStr.equals("") - && ! this.owner.hasAttributeNS(null, "title") - && esum.title != null ) - this.owner.setAttributeNS(null, "title", esum.title); - } - } + if ( wrefSupplementStr.equals("") + && ! this.owner.hasAttributeNS(null, "title") + && esum != null && esum.title != null ) + this.owner.setAttributeNS(null, "title", esum.title); + // Replace this attribute by computed target this.owner.removeAttributeNode(this.attr); this.owner.setAttributeNS(null, "href", target); } -- cgit v1.2.3