summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogLink.java
blob: 9762e4970915c4e2362548662ebcfee59e5bfaf1 (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 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() {
	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
		+ (singlePage==null ? "" : "." + singlePage) + ".html";
	default:
	    throw new AssertionError("unknown type");
	}
    }

    public String getTarget(String baseDir) {
	return this.getFile(baseDir) + "#" + this.getFragment();
    }

}