1 25 26 package org.snipsnap.render.filter; 27 28 import org.radeox.filter.regex.RegexTokenFilter; 29 import org.radeox.regex.MatchResult; 30 import org.radeox.filter.context.FilterContext; 31 import org.radeox.util.i18n.ResourceManager; 32 import org.snipsnap.app.Application; 33 import org.snipsnap.config.Configuration; 34 import org.snipsnap.render.filter.context.SnipFilterContext; 35 import org.snipsnap.snip.Snip; 36 37 import java.text.MessageFormat ; 38 import java.text.FieldPosition ; 39 import java.util.ResourceBundle ; 40 41 48 49 public class CalendarFilter extends RegexTokenFilter { 50 51 public CalendarFilter() { 52 super("^BEGIN:VCALENDAR(.*?)END:VCALENDAR", SINGLELINE); 53 } 54 55 private final static int CALENDAR_PREFIX_LENGTH = "calendar-".length(); 56 57 public void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) { 58 Snip snip = ((SnipFilterContext) context).getSnip(); 59 Application app = Application.get(); 60 Configuration config = app.getConfiguration(); 61 Snip parent = snip.getParent(); 62 63 StringBuffer linkBuffer = new StringBuffer (); 64 linkBuffer.append("<a HREF=\""); 65 66 String file = null; 67 StringBuffer url = new StringBuffer ("exec/ical/"); 68 if (parent != null) { 69 file = snip.getName().substring(CALENDAR_PREFIX_LENGTH + parent.getName().length() + 1); 70 url.append(parent.getName()).append("/"); 71 url.append(file); 72 } else { 73 file = snip.getName().substring(CALENDAR_PREFIX_LENGTH); 74 url.append(file); 75 } 76 77 String webcalUrl = config.getUrl(url.toString()); 78 webcalUrl = webcalUrl.substring(webcalUrl.indexOf("//") + 2); 79 linkBuffer.append("webcal://").append(webcalUrl); 80 linkBuffer.append("\">").append("calendar ").append(file).append("</a>"); 81 82 String formatString = ResourceManager.getString("i18n.messages", "filter.calendar.subscribe.to"); 83 MessageFormat mf = new MessageFormat (formatString); 84 buffer.append(mf.format(new Object [] { linkBuffer.toString() })); 85 } 86 } 87 | Popular Tags |