diff options
author | David A. Madore <david+git@madore.org> | 2011-08-26 15:51:50 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2011-08-26 15:51:50 +0200 |
commit | e3ac578e74c3197d7e4bb03e10cd5756b9405e76 (patch) | |
tree | af6d22d74be4a2f944bd7fe086c97dad64e614c8 /org/madore/damlengine | |
parent | 7077d9d7bafdf6ce05e86bf4439cddc17553a487 (diff) | |
download | damlengine-e3ac578e74c3197d7e4bb03e10cd5756b9405e76.tar.gz damlengine-e3ac578e74c3197d7e4bb03e10cd5756b9405e76.tar.bz2 damlengine-e3ac578e74c3197d7e4bb03e10cd5756b9405e76.zip |
Handle d:wref attribute (incompletely).
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r-- | org/madore/damlengine/TodoAttr.java | 1 | ||||
-rw-r--r-- | org/madore/damlengine/TodoWrefAttr.java | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java index f510cf9..b88dc53 100644 --- a/org/madore/damlengine/TodoAttr.java +++ b/org/madore/damlengine/TodoAttr.java @@ -18,6 +18,7 @@ public abstract class TodoAttr extends TodoItem { static { damlAttrFactories = new HashMap<String,Factory>(); damlAttrFactories.put("xempty", new TodoXemptyAttr.Factory()); + damlAttrFactories.put("wref", new TodoWrefAttr.Factory()); } protected final Attr attr; diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java new file mode 100644 index 0000000..5737577 --- /dev/null +++ b/org/madore/damlengine/TodoWrefAttr.java @@ -0,0 +1,45 @@ +package org.madore.damlengine; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.w3c.dom.*; + +public class TodoWrefAttr extends TodoAttr { + + public static class Factory extends TodoAttr.Factory { + @Override + public TodoWrefAttr newItem(Attr attr, Element owner, + Context ctx, + TodoItem caller) { + return new TodoWrefAttr(attr, owner, ctx, caller); + } + } + + public TodoWrefAttr(Attr attr, Element owner, + Context ctx, + TodoItem caller) { + super(attr, owner, ctx, caller); + } + + @Override + public void handle() { + String wrefStr = attr.getValue(); + Matcher wrefMatcher = Pattern.compile("^\\#d\\.(\\d{4})-(\\d{2})-(\\d{2})\\.(\\d{4})(|\\..*)$").matcher(wrefStr); + if ( ! wrefMatcher.matches() ) + throw new IllegalArgumentException("wref attribute ("+wrefStr+") 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); + String wrefSupplementStr = wrefMatcher.group(5); + String targetFile = ""; + if ( true ) + targetFile = wrefYearStr + "-" + wrefMonthStr + ".html"; + String targetFragment = "d." + wrefYearStr + "-" + wrefMonthStr + + "-" + wrefDayStr + "." + wrefNumberStr + wrefSupplementStr; + String target = targetFile + "#" + targetFragment; + this.owner.removeAttribute(this.attr.getName()); + this.owner.setAttributeNS(null, "href", target); + } + +} |