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.api.filters;
020
021import org.apache.logging.log4j.LogManager;
022import org.apache.wiki.WikiContext;
023import org.apache.wiki.WikiEngine;
024import org.apache.wiki.api.core.Context;
025import org.apache.wiki.api.core.Engine;
026import org.apache.wiki.api.exceptions.FilterException;
027
028import java.lang.reflect.Method;
029import java.util.Properties;
030
031import static org.apache.wiki.api.filters.FilterSupportOperations.executePageFilterPhase;
032import static org.apache.wiki.api.filters.FilterSupportOperations.methodOfNonPublicAPI;
033
034
035/**
036 * Hooks all filters not using the public api into it.
037 *
038 * @deprecated use {@link BasePageFilter} instead
039 * @see BasePageFilter
040 */
041@Deprecated
042public class BasicPageFilter extends BasePageFilter {
043
044    public void initialize( final WikiEngine engine, final Properties properties ) throws FilterException {
045        this.m_engine = engine;
046        LogManager.getLogger( BasicPageFilter.class ).warn( this.getClass().getName() + " implements deprecated org.apache.wiki.api.filters.BasicPageFilter" );
047        LogManager.getLogger( BasicPageFilter.class ).warn( "Please contact the filter's author so there can be a new release of the filter " +
048                                                            "extending the new org.apache.wiki.api.filters.BasePageFilter class" );
049    }
050
051    public String preTranslate( final WikiContext wikiContext, final String content ) throws FilterException {
052        return content;
053    }
054
055    public String preTranslate( final Context wikiContext, final String content ) throws FilterException {
056        final Method m = methodOfNonPublicAPI( this, "preTranslate", "org.apache.wiki.WikiContext", "java.lang.String" );
057        return executePageFilterPhase( () -> content, m, this, wikiContext, content );
058        // return content;
059    }
060
061    public String postTranslate( final WikiContext wikiContext, final String htmlContent ) throws FilterException {
062        return htmlContent;
063    }
064
065    public String postTranslate( final Context wikiContext, final String htmlContent ) throws FilterException {
066        final Method m = methodOfNonPublicAPI( this, "postTranslate", "org.apache.wiki.WikiContext", "java.lang.String" );
067        return executePageFilterPhase( () -> htmlContent, m, this, wikiContext, htmlContent );
068        // return htmlContent;
069    }
070
071    public String preSave( final WikiContext wikiContext, final String content ) throws FilterException {
072        return content;
073    }
074
075    public String preSave( final Context wikiContext, final String content ) throws FilterException {
076        final Method m = methodOfNonPublicAPI( this, "preSave", "org.apache.wiki.WikiContext", "java.lang.String" );
077        return executePageFilterPhase( () -> content, m, this, wikiContext, content );
078        // return content;
079    }
080
081    public void postSave( final WikiContext wikiContext, final String content ) throws FilterException {
082    }
083
084    public void postSave( final Context wikiContext, final String content ) throws FilterException {
085        final Method m = methodOfNonPublicAPI( this, "postSave", "org.apache.wiki.WikiContext", "java.lang.String" );
086        executePageFilterPhase( () -> null, m, this, wikiContext, content );
087        // empty method
088    }
089
090    public void destroy( final WikiEngine engine ) {
091    }
092
093    public void destroy( final Engine engine ) {
094        final Method m = methodOfNonPublicAPI( this, "destroy", "org.apache.wiki.WikiEngine" );
095        executePageFilterPhase( () -> null, m, this, engine );
096        // empty method
097    }
098
099}