001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.filters; 020 021import org.apache.log4j.Logger; 022import org.apache.wiki.WikiContext; 023import org.apache.wiki.WikiEngine; 024import org.apache.wiki.api.exceptions.FilterException; 025import org.apache.wiki.api.filters.BasicPageFilter; 026import org.apache.wiki.parser.CreoleToJSPWikiTranslator; 027 028import java.util.Properties; 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 installing 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 * 048 * @see <a href="http://www.wikicreole.org/wiki/MixedMode">[[WikiCreole:MixedMode]]</a> 049 */ 050 051public class CreoleFilter extends BasicPageFilter { 052 053 private static final Logger log = Logger.getLogger(CreoleFilter.class); 054 055 /** 056 * {@inheritDoc} 057 */ 058 public void initialize(WikiEngine engine, Properties props) throws FilterException { 059 } 060 061 /** 062 * {@inheritDoc} 063 */ 064 public String preSave( WikiContext wikiContext, String content ) { 065 try { 066 String username=wikiContext.getCurrentUser().getName(); 067 Properties prop = wikiContext.getEngine().getWikiProperties(); 068 return new CreoleToJSPWikiTranslator().translateSignature(prop, content,username); 069 } catch(Exception e ) { 070 log.error( e.getMessage(), e ); 071 return e.getMessage(); 072 } 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 public String preTranslate(WikiContext wikiContext, String content) { 079 try { 080 Properties prop = wikiContext.getEngine().getWikiProperties(); 081 return new CreoleToJSPWikiTranslator().translate(prop ,content); 082 } catch (Exception e) { 083 log.error( e.getMessage(), e ); 084 return content 085 + "\n \n %%error \n" 086 + "[CreoleFilterError]: This page was not translated by the CreoleFilter due to " 087 + "the following error: " + e.getMessage() + "\n \n" 088 + "%%\n \n"; 089 } 090 } 091 092}