1
14
15 package com.liferay.portlet.wiki.engines.mediawiki.matchers;
16
17 import com.liferay.portal.kernel.util.CallbackMatcher;
18 import com.liferay.portal.kernel.util.HttpUtil;
19 import com.liferay.portal.kernel.util.StringBundler;
20
21 import java.util.regex.MatchResult;
22
23
29 public class ImageURLMatcher extends CallbackMatcher {
30
31 public ImageURLMatcher(String attachmentURLPrefix) {
32 _attachmentURLPrefix = attachmentURLPrefix;
33
34 setRegex(_REGEX);
35 }
36
37 public String replaceMatches(CharSequence charSequence) {
38 return replaceMatches(charSequence, _callBack);
39 }
40
41 private static final String _REGEX =
42 "<a href=\"[^\"]*?Special:Upload[^\"]*?topic=Image:([^\"]*?)\".*?</a>";
43
44 private Callback _callBack = new Callback() {
45
46 public String foundMatch(MatchResult matchResult) {
47 String title = matchResult.group(1);
48
49 String url = _attachmentURLPrefix + HttpUtil.encodeURL(title);
50
51 StringBundler sb = new StringBundler(5);
52
53 sb.append("<img alt=\"");
54 sb.append(title);
55 sb.append("\" class=\"wikiimg\" src=\"");
56 sb.append(url);
57 sb.append("\" />");
58
59 return sb.toString();
60 }
61
62 };
63
64 private String _attachmentURLPrefix;
65
66 }