01: package com.technoetic.xplanner.wiki;
02:
03: import java.util.Properties;
04:
05: import org.apache.oro.text.perl.Perl5Util;
06:
07: public class SimpleSchemeHandler implements SchemeHandler {
08: private Perl5Util perl = new Perl5Util();
09: private final String pattern;
10: private static final String TARGET_TOP = "_top";
11:
12: public SimpleSchemeHandler() {
13: this .pattern = null;
14: }
15:
16: public SimpleSchemeHandler(String pattern) {
17: this .pattern = pattern;
18: }
19:
20: public String translate(Properties properties, String scheme,
21: String location, String linkText) {
22: String pattern = getPattern(properties);
23: location = perl.substitute("s|(/)|\\\\$1|g", location);
24: String url = perl.substitute("s/\\$1/" + location + "/go",
25: pattern);
26: return "<a href=\""
27: + url
28: + "\" target=\""
29: + getTarget()
30: + "\">"
31: + (linkText != null ? linkText
32: : (scheme + ":" + location)) + "</a>";
33: }
34:
35: protected String getPattern(Properties properties) {
36: return this .pattern;
37: }
38:
39: protected String getTarget() {
40: return TARGET_TOP;
41: }
42:
43: public String toString() {
44: return "[" + getClass().getName() + " pattern=" + pattern + "]";
45: }
46: }
|