001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.filters;
021:
022: import java.util.Properties;
023:
024: import com.ecyrd.jspwiki.WikiContext;
025: import com.ecyrd.jspwiki.WikiEngine;
026: import com.ecyrd.jspwiki.filters.BasicPageFilter;
027: import com.ecyrd.jspwiki.filters.FilterException;
028: import com.ecyrd.jspwiki.parser.CreoleToJSPWikiTranslator;
029:
030: /**
031: * <p>Provides the Implementation for mixed mode creole: If you activate
032: * this filter, it will translate all markup that was saved as creole
033: * markup to JSPWiki markup. Therefore the files will be saved
034: * with mixed markup.
035: * <p>
036: * <b>WARNING</b>: There's no turning back after insalling this
037: * filter. Since your wiki pages are saved in Creole markup you can
038: * not deactivate it afterwards.
039: * <p>
040: * <b>WARNING</b>: This feature is completely experimental, and is known to be
041: * broken. Use at your own risk.
042: * <p>
043: * <b>WARNING</b>: The CreoleFilter feature is deprecated. JSPWiki is likely
044: * to implement a non-mixed mode Creole at some point, since turning on
045: * Creole will make new pages obsolete.
046: *
047: * @author Steffen Schramm
048: * @author Hanno Eichelberger
049: * @author Christoph Sauer
050: *
051: * @see <a href="http://www.wikicreole.org/wiki/MixedMode">[[WikiCreole:MixedMode]]</a>
052: */
053:
054: public class CreoleFilter extends BasicPageFilter {
055: /**
056: * {@inheritDoc}
057: */
058: public void initialize(WikiEngine engine, Properties props)
059: throws FilterException {
060: }
061:
062: /**
063: * {@inheritDoc}
064: */
065: public String preSave(WikiContext wikiContext, String content)
066: throws FilterException {
067: try {
068: String username = wikiContext.getCurrentUser().getName();
069: Properties prop = wikiContext.getEngine()
070: .getWikiProperties();
071: return new CreoleToJSPWikiTranslator().translateSignature(
072: prop, content, username);
073: } catch (Exception e) {
074: e.printStackTrace();
075: return e.getMessage();
076: }
077: }
078:
079: /**
080: * {@inheritDoc}
081: */
082:
083: public String preTranslate(WikiContext wikiContext, String content)
084: throws FilterException {
085: try {
086: Properties prop = wikiContext.getEngine()
087: .getWikiProperties();
088: return new CreoleToJSPWikiTranslator().translate(prop,
089: content);
090:
091: } catch (Exception e) {
092: e.printStackTrace();
093: return content
094: + "\n \n %%error \n"
095: + "[CreoleFilterError]: This page was not translated by the CreoleFilter due to "
096: + "the following error: " + e.getMessage()
097: + "\n \n" + "%%\n \n";
098: }
099: }
100:
101: }
|