summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2013-04-06 19:17:18 +0200
committerDavid A. Madore <david+git@madore.org>2013-04-06 19:17:18 +0200
commit0f041a8ad9595584c9e048ec026ff87cbf481c6f (patch)
tree20b6167a25ce0e2675b26a7743b3c8f0806e91b1 /org/madore/damlengine
parent7050a6b7b8fbd1c3f2622d611139a5df801b9f95 (diff)
downloaddamlengine-0f041a8ad9595584c9e048ec026ff87cbf481c6f.tar.gz
damlengine-0f041a8ad9595584c9e048ec026ff87cbf481c6f.tar.bz2
damlengine-0f041a8ad9595584c9e048ec026ff87cbf481c6f.zip
Rewrite selection of d:wref target in a hopefully less messy way.
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r--org/madore/damlengine/TodoWrefAttr.java68
1 files changed, 36 insertions, 32 deletions
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);
}