01: package com.technoetic.xplanner.wiki;
02:
03: import com.technoetic.xplanner.XPlannerProperties;
04:
05: public class ExternalTwikiAdapter extends GenericWikiAdapter {
06: private String defaultSubwiki;
07:
08: protected void initialize(XPlannerProperties properties) {
09: super .initialize(properties);
10: defaultSubwiki = properties
11: .getProperty("twiki.wikiadapter.subwiki.default");
12: if (defaultSubwiki == null) {
13: defaultSubwiki = "Main";
14: }
15: }
16:
17: protected String formatLinkToCreateTopic(String wikiWord) {
18: String subwiki = getSubWiki(wikiWord);
19: String word = getWord(wikiWord);
20: String url = substitute(subwiki, word, getNewTopicUrlPattern());
21: return word + "<a href='" + url + "'>?</a>";
22: }
23:
24: protected String formatUrl(String wikiWord, String urlPattern) {
25: String subwiki = getSubWiki(wikiWord);
26: String word = getWord(wikiWord);
27: return substitute(subwiki, word, urlPattern);
28: }
29:
30: private String substitute(String subwiki, String word,
31: String urlPattern) {
32: String url = urlPattern;
33: url = url.replaceAll("\\$\\{subwiki\\}", subwiki + "/");
34: url = url.replaceAll("\\$\\{word\\}", word);
35: return url;
36: }
37:
38: private String getSubWiki(String wikiWord) {
39: int periodOffset = wikiWord.lastIndexOf(".");
40: String subwiki;
41: if (periodOffset != -1) {
42: subwiki = wikiWord.substring(0, periodOffset);
43: } else {
44: subwiki = defaultSubwiki;
45: }
46: return subwiki;
47: }
48:
49: private String getWord(String wikiWord) {
50: int periodOffset = wikiWord.lastIndexOf(".");
51: return periodOffset != -1 ? wikiWord.substring(
52: periodOffset + 1, wikiWord.length()) : wikiWord;
53: }
54:
55: protected String formatLinkToExistingTopic(String wikiWord) {
56: String subwiki = getSubWiki(wikiWord);
57: String word = getWord(wikiWord);
58: String url = substitute(subwiki, word,
59: getExistingTopicUrlPattern());
60: return "<a href='" + url + "'>" + word + "</a>";
61: }
62: }
|