From 2836e8c6547a04a35e08abc14f4d97e5afaf7243 Mon Sep 17 00:00:00 2001
From: "David A. Madore" <david+git@madore.org>
Date: Sat, 6 Apr 2013 19:28:03 +0200
Subject: Make local d:wref links inside single entry pages actually local.

---
 org/madore/damlengine/TodoWrefAttr.java | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

(limited to 'org')

diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java
index 0a94e0d..7f40959 100644
--- a/org/madore/damlengine/TodoWrefAttr.java
+++ b/org/madore/damlengine/TodoWrefAttr.java
@@ -31,6 +31,7 @@ public class TodoWrefAttr extends TodoAttr {
 	String wrefMonthStr = wrefMatcher.group(2);
 	String wrefDayStr = wrefMatcher.group(3);
 	String wrefNumberStr = wrefMatcher.group(4);
+	int wrefNumber = Integer.parseInt(wrefNumberStr);
 	String wrefSupplementStr = wrefMatcher.group(5);
 	String targetFile;
 	String targetStdDir = (ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/");
@@ -38,7 +39,7 @@ public class TodoWrefAttr extends TodoAttr {
 	WeblogSummary.EntrySummary esum;
 	// Get entry for target link from weblog summary
 	if ( wsum != null && wsum.entries != null )
-	    esum = wsum.entries.get(new Integer(wrefNumberStr));
+	    esum = wsum.entries.get(wrefNumber);
 	else
 	    esum = null;
 	// Check consistency if summary was available
@@ -49,9 +50,14 @@ public class TodoWrefAttr extends TodoAttr {
 	}
 	// Choose file portion of link target
 	if ( esum != null && esum.doSinglePage != null && ! wrefSupplementStr.equals("") ) {
-	    targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html";
+	    if ( ctx.wsc != null && ctx.wsc.sel != null
+		 && ctx.wsc instanceof Context.WeblogSingleSelectionContext
+		 && ((Context.WeblogSingleSelectionContext)ctx.wsc).number == wrefNumber )
+		targetFile = "";
+	    else
+		targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html";
 	} else if ( ctx.wsc != null && ctx.wsc.sel != null
-	     && ctx.wsc.sel.contains(new Integer(wrefNumberStr)) ) {
+	     && ctx.wsc.sel.contains(wrefNumber) ) {
 	    targetFile = "";
 	} else {
 	    targetFile = targetStdDir + wrefYearStr + "-" + wrefMonthStr + ".html";
-- 
cgit v1.2.3