summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogLink.java
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine/WeblogLink.java')
-rw-r--r--org/madore/damlengine/WeblogLink.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/org/madore/damlengine/WeblogLink.java b/org/madore/damlengine/WeblogLink.java
new file mode 100644
index 0000000..f29c69e
--- /dev/null
+++ b/org/madore/damlengine/WeblogLink.java
@@ -0,0 +1,75 @@
+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 singlePage; // 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 singlePage) {
+ this.yearStr = yearStr;
+ this.monthStr = monthStr;
+ this.dayStr = dayStr;
+ this.numberStr = numberStr;
+ this.supplementStr = supplementStr;
+ this.singlePage = singlePage;
+ }
+
+ 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() {
+ if ( singlePage == null )
+ this.t = Type.MONTH;
+ else
+ 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:
+ if ( singlePage == null )
+ throw new IllegalArgumentException("can't have single page link to non single-page entry");
+ return baseDir + yearStr + "-" + monthStr + "-" + dayStr
+ + "-" + singlePage + ".html";
+ default:
+ throw new AssertionError("unknown type");
+ }
+ }
+
+ public String getTarget(String baseDir) {
+ return this.getFile(baseDir) + "#" + this.getFragment();
+ }
+
+}