    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    @Override
    056    public String preTranslate(final Context wikiContext, final String content ) throws FilterException {
    057        final Method m = methodOfNonPublicAPI( this, "preTranslate", "org.apache.wiki.WikiContext", "java.lang.String" );
    058        return executePageFilterPhase( () -> content, m, this, wikiContext, content );
    059        // return content;
    060    }
    061
    062    public String postTranslate( final WikiContext wikiContext, final String htmlContent ) throws FilterException {
    063        return htmlContent;
    064    }
    065
    066    @Override
    067    public String postTranslate(final Context wikiContext, final String htmlContent ) throws FilterException {
    068        final Method m = methodOfNonPublicAPI( this, "postTranslate", "org.apache.wiki.WikiContext", "java.lang.String" );
    069        return executePageFilterPhase( () -> htmlContent, m, this, wikiContext, htmlContent );
    070        // return htmlContent;
    071    }
    072
    073    public String preSave( final WikiContext wikiContext, final String content ) throws FilterException {
    074        return content;
    075    }
    076
    077    @Override
    078    public String preSave(final Context wikiContext, final String content ) throws FilterException {
    079        final Method m = methodOfNonPublicAPI( this, "preSave", "org.apache.wiki.WikiContext", "java.lang.String" );
    080        return executePageFilterPhase( () -> content, m, this, wikiContext, content );
    081        // return content;
    082    }
    083
    084    public void postSave( final WikiContext wikiContext, final String content ) throws FilterException {
    085    }
    086
    087    @Override
    088    public void postSave(final Context wikiContext, final String content ) throws FilterException {
    089        final Method m = methodOfNonPublicAPI( this, "postSave", "org.apache.wiki.WikiContext", "java.lang.String" );
    090        executePageFilterPhase( () -> null, m, this, wikiContext, content );
    091        // empty method
    092    }
    093
    094    public void destroy( final WikiEngine engine ) {
    095    }
    096
    097    @Override
    098    public void destroy(final Engine engine ) {
    099        final Method m = methodOfNonPublicAPI( this, "destroy", "org.apache.wiki.WikiEngine" );
    100        executePageFilterPhase( () -> null, m, this, engine );
    101        // empty method
    102    }
    103
    104}