summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2013-04-06 20:18:10 +0200
committerDavid A. Madore <david+git@madore.org>2013-04-06 20:18:10 +0200
commita49cff43d551b29dd726a6d5c19aba31db3bfc71 (patch)
treebc3fcaebfee6b0d457e918f878ca8852a906c85a
parent2836e8c6547a04a35e08abc14f4d97e5afaf7243 (diff)
downloaddamlengine-a49cff43d551b29dd726a6d5c19aba31db3bfc71.tar.gz
damlengine-a49cff43d551b29dd726a6d5c19aba31db3bfc71.tar.bz2
damlengine-a49cff43d551b29dd726a6d5c19aba31db3bfc71.zip
Support for d:wrefcat attribute to create links inside a category.
-rw-r--r--org/madore/damlengine/TodoWrefAttr.java13
-rw-r--r--org/madore/damlengine/WeblogSummary.java18
2 files changed, 30 insertions, 1 deletions
diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java
index 7f40959..7f69a96 100644
--- a/org/madore/damlengine/TodoWrefAttr.java
+++ b/org/madore/damlengine/TodoWrefAttr.java
@@ -33,6 +33,13 @@ public class TodoWrefAttr extends TodoAttr {
String wrefNumberStr = wrefMatcher.group(4);
int wrefNumber = Integer.parseInt(wrefNumberStr);
String wrefSupplementStr = wrefMatcher.group(5);
+ String wrefCat;
+ if ( this.owner.hasAttributeNS(DamlEngine.DAML_NS, "wrefcat") ) {
+ wrefCat = this.owner.getAttributeNS(DamlEngine.DAML_NS, "wrefcat");
+ this.owner.removeAttributeNS(DamlEngine.DAML_NS, "wrefcat");
+ } else {
+ wrefCat = null;
+ }
String targetFile;
String targetStdDir = (ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/");
WeblogSummary wsum = WeblogSummary.getSummary();
@@ -47,6 +54,10 @@ 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 ) {
+ 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("") ) {
@@ -59,6 +70,8 @@ public class TodoWrefAttr extends TodoAttr {
} else if ( ctx.wsc != null && ctx.wsc.sel != null
&& ctx.wsc.sel.contains(wrefNumber) ) {
targetFile = "";
+ } else if ( wrefCat != null ) {
+ targetFile = targetStdDir + wrefCat + ".html";
} else {
targetFile = targetStdDir + wrefYearStr + "-" + wrefMonthStr + ".html";
if ( esum != null && esum.doSinglePage != null
diff --git a/org/madore/damlengine/WeblogSummary.java b/org/madore/damlengine/WeblogSummary.java
index 997f67a..50ab143 100644
--- a/org/madore/damlengine/WeblogSummary.java
+++ b/org/madore/damlengine/WeblogSummary.java
@@ -1,6 +1,7 @@
package org.madore.damlengine;
import java.util.HashMap;
+import java.util.HashSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -14,6 +15,7 @@ public final class WeblogSummary {
String lang;
String title; String titleXml;
String doSinglePage;
+ HashSet<String> catSet;
public EntrySummary(int id, String date, String lang,
String title, String titleXml,
String doSinglePage) {
@@ -23,6 +25,7 @@ public final class WeblogSummary {
this.title = title;
this.titleXml = titleXml;
this.doSinglePage = doSinglePage;
+ this.catSet = null;
}
}
@@ -50,7 +53,20 @@ public final class WeblogSummary {
String title = selRes.getString(4);
String titleXml = selRes.getString(5);
String doSinglePage = selRes.getString(6);
- singleton.entries.put(new Integer(id), new EntrySummary(id, date, lang, title, titleXml, doSinglePage));
+ singleton.entries.put(id, new EntrySummary(id, date, lang, title, titleXml, doSinglePage));
+ }
+ final PreparedStatement catSt
+ = conn.prepareStatement("SELECT id , code FROM incat");
+ final ResultSet catRes = catSt.executeQuery();
+ while ( catRes.next() ) {
+ int id = catRes.getInt(1);
+ String code = catRes.getString(2);
+ HashSet<String> catSet = singleton.entries.get(id).catSet;
+ if ( catSet == null ) {
+ catSet = new HashSet<String>();
+ singleton.entries.get(id).catSet = catSet;
+ }
+ catSet.add(code);
}
} catch (SQLException e) {
// Well, we'll have no summary. Too bad, but better than abort.