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 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); if ( ! this.owner.hasAttributeNS(null, "class") ) this.owner.setAttributeNS(null, "class", "weblog-internal-link"); } }