summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogLink.java
blob: ac0b507a79b71f96987d94364f686b3937cfd095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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();
    }

}