package org.madore.damlengine; public final class WeblogLink { private enum Type { RELATIVE, MONTH, CAT, SINGLE } public String yearStr; public String monthStr; public String dayStr; public String numberStr; public String supplementStr; public String specialName; // May be null private Type t = Type.MONTH; private String cat; // Only defined for type CAT public WeblogLink(String yearStr, String monthStr, String dayStr, String numberStr, String supplementStr, String specialName) { this.yearStr = yearStr; this.monthStr = monthStr; this.dayStr = dayStr; this.numberStr = numberStr; this.supplementStr = supplementStr; this.specialName = specialName; } public WeblogLink(String yearStr, String monthStr, String dayStr, String numberStr, String supplementStr) { this(yearStr, monthStr, dayStr, numberStr, supplementStr, null); } public void setTypeRelative() { this.t = Type.RELATIVE; } public void setTypeMonth() { this.t = Type.MONTH; } public void setTypeCat(String cat) { this.t = Type.CAT; this.cat = cat; } public void setTypeSingle() { this.t = Type.SINGLE; } public void setTypeStandard() { this.t = Type.SINGLE; } public String getFragment() { return "d." + yearStr + "-" + monthStr + "-" + dayStr + "." + numberStr + supplementStr; } public String getFile(String baseDir) { switch ( t ) { case RELATIVE: return ""; case MONTH: return baseDir + yearStr + "-" + monthStr + ".html"; case CAT: return baseDir + cat + ".html"; case SINGLE: return baseDir + "d." + yearStr + "-" + monthStr + "-" + dayStr + "." + numberStr + (specialName==null ? "" : "." + specialName) + ".html"; default: throw new AssertionError("unknown type"); } } public String getTarget(String baseDir) { return this.getFile(baseDir) + "#" + this.getFragment(); } }