diff options
author | David A. Madore <david+git@madore.org> | 2014-10-10 21:54:23 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2014-10-10 21:54:23 +0200 |
commit | eaa29f26c5aa1ff9cfc306dc23c6bcfae0c0c68d (patch) | |
tree | b4acc2289987a57685eac4db0fb51e2b1d550f92 /org/madore/damlengine/TodoWrefAttr.java | |
parent | 01ad55efbfb3b0056efaa0f9a7d7c48765d7db81 (diff) | |
parent | d6b9db7926af4dc6d7df5af55d261731bd623c23 (diff) | |
download | damlengine-eaa29f26c5aa1ff9cfc306dc23c6bcfae0c0c68d.tar.gz damlengine-eaa29f26c5aa1ff9cfc306dc23c6bcfae0c0c68d.tar.bz2 damlengine-eaa29f26c5aa1ff9cfc306dc23c6bcfae0c0c68d.zip |
Merge branch 'master' into servlet
Conflicts:
org/madore/damlengine/TodoWrefAttr.java
Diffstat (limited to 'org/madore/damlengine/TodoWrefAttr.java')
-rw-r--r-- | org/madore/damlengine/TodoWrefAttr.java | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java index b707a95..650297c 100644 --- a/org/madore/damlengine/TodoWrefAttr.java +++ b/org/madore/damlengine/TodoWrefAttr.java @@ -23,16 +23,16 @@ public class TodoWrefAttr extends TodoAttr { @Override public void handle() { - String wrefStr = attr.getValue(); - Matcher wrefMatcher = Pattern.compile("^\\#d\\.(\\d{4})-(\\d{2})-(\\d{2})\\.(\\d{4})(|\\..*)$").matcher(wrefStr); + final String wrefStr = attr.getValue(); + final Matcher wrefMatcher = Pattern.compile("^\\#d\\.(\\d{4})-(\\d{2})-(\\d{2})\\.(\\d{4})(|\\..*)$").matcher(wrefStr); if ( ! wrefMatcher.matches() ) throw new IllegalArgumentException("wref attribute must be of the form #d.YYYY-MM-DD.NNNN[.xxx]"); - String wrefYearStr = wrefMatcher.group(1); - 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); + final String wrefYearStr = wrefMatcher.group(1); + final String wrefMonthStr = wrefMatcher.group(2); + final String wrefDayStr = wrefMatcher.group(3); + final String wrefNumberStr = wrefMatcher.group(4); + final int wrefNumber = Integer.parseInt(wrefNumberStr); + final String wrefSupplementStr = wrefMatcher.group(5); String wrefCat; if ( this.owner.hasAttributeNS(DamlEngine.DAML_NS, "wrefcat") ) { wrefCat = this.owner.getAttributeNS(DamlEngine.DAML_NS, "wrefcat"); @@ -40,10 +40,9 @@ public class TodoWrefAttr extends TodoAttr { } else { wrefCat = null; } - String targetFile; - String targetStdDir = (ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"); - WeblogSummary wsum = WeblogSummary.getSummary(ctx.dc); - WeblogSummary.EntrySummary esum; + final String baseDir = (ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"); + final WeblogSummary wsum = WeblogSummary.getSummary(ctx.dc); + final WeblogSummary.EntrySummary esum; // Get entry for target link from weblog summary if ( wsum != null && wsum.entries != null ) esum = wsum.entries.get(wrefNumber); @@ -54,43 +53,51 @@ public class TodoWrefAttr extends TodoAttr { if ( ! ((wrefYearStr+"-"+wrefMonthStr+"-"+wrefDayStr) .equals(esum.date)) ) throw new IllegalArgumentException("date mismatch for reference to entry "+wrefNumberStr); - if ( wrefCat != null && ! wrefCat.equals("@month") ) { + if ( wrefCat != null && ! wrefCat.equals("@month") + && ! wrefCat.equals("@single") ) { if ( esum.catSet == null || ! esum.catSet.contains(wrefCat) ) throw new IllegalArgumentException("reference to entry "+wrefNumberStr+" in wrong category "+wrefCat); } } - // Choose file portion of link target - if ( esum != null && esum.doSinglePage != null && ! wrefSupplementStr.equals("") ) { + // Prepare link object + final WeblogLink lk; + if ( esum != null && esum.doSinglePage != null ) + lk = new WeblogLink(wrefYearStr, wrefMonthStr, wrefDayStr, + wrefNumberStr, wrefSupplementStr, + esum.doSinglePage); + else + lk = new WeblogLink(wrefYearStr, wrefMonthStr, wrefDayStr, + wrefNumberStr, wrefSupplementStr); + // Decide whether link target is on this page + final boolean onThisPage; + if ( lk.singlePage != null && ! lk.supplementStr.equals("") ) { // Linking to a _fragment_ of an entry that has a single page. - if ( wrefCat != null ) - System.err.println("warning: ignoring d:wrefcat attribute!"); if ( ctx.wsc != null && ctx.wsc.sel != null && ctx.wsc instanceof Context.WeblogSingleSelectionContext && ((Context.WeblogSingleSelectionContext)ctx.wsc).number == wrefNumber ) - targetFile = ""; + onThisPage = true; else - targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html"; - } else if ( ctx.wsc != null && ctx.wsc.sel != null - && ctx.wsc.sel.contains(wrefNumber) ) { - // Linking to an entry already present on this page. - targetFile = ""; - } else if ( wrefCat != null && ! wrefCat.equals("@month") ) { - // Linking to an entry in a designated category. - targetFile = targetStdDir + wrefCat + ".html"; + onThisPage = false; } else { - // Linking to an entry in its month, or single page. - 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". - && ( wrefCat == null || ! wrefCat.equals("@month") ) ) { - targetFile = targetStdDir + esum.date + "-" + esum.doSinglePage + ".html"; - } + if ( ctx.wsc != null && ctx.wsc.sel != null + && ctx.wsc.sel.contains(wrefNumber) ) + onThisPage = true; + else + onThisPage = false; } + // Choose file portion of link target + if ( onThisPage ) + lk.setTypeRelative(); + else if ( wrefCat == null ) + lk.setTypeStandard(); + else if ( wrefCat.equals("@month") ) + lk.setTypeMonth(); + else if ( wrefCat.equals("@single") ) + lk.setTypeSingle(); + else + lk.setTypeCat(wrefCat); // Construct full link target - String targetFragment = "d." + wrefYearStr + "-" + wrefMonthStr - + "-" + wrefDayStr + "." + wrefNumberStr + wrefSupplementStr; - String target = targetFile + "#" + targetFragment; + String target = lk.getTarget(baseDir); // Class and title attributes if ( ! this.owner.hasAttributeNS(null, "class") ) this.owner.setAttributeNS(null, "class", "weblog-internal-link"); |