KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > render > filter > CalendarFilter


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
38 import java.text.FieldPosition JavaDoc;
39 import java.util.ResourceBundle JavaDoc;
40
41 /*
42  * Class that VCAL content
43  *
44  * @author stephan
45  * @team sonicteam
46  * @version $Id: CalendarFilter.java 1606 2004-05-17 10:56:18Z leo $
47  */

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 JavaDoc 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 JavaDoc linkBuffer = new StringBuffer JavaDoc();
64     linkBuffer.append("<a HREF=\"");
65
66     String JavaDoc file = null;
67     StringBuffer JavaDoc url = new StringBuffer JavaDoc("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 JavaDoc 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 JavaDoc formatString = ResourceManager.getString("i18n.messages", "filter.calendar.subscribe.to");
83     MessageFormat JavaDoc mf = new MessageFormat JavaDoc(formatString);
84     buffer.append(mf.format(new Object JavaDoc[] { linkBuffer.toString() }));
85   }
86 }
87
Popular Tags