⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filtermanager.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*     JSPWiki - a JSP-based WikiWiki clone.    Licensed to the Apache Software Foundation (ASF) under one    or more contributor license agreements.  See the NOTICE file    distributed with this work for additional information    regarding copyright ownership.  The ASF licenses this file    to you under the Apache License, Version 2.0 (the    "License"); you may not use this file except in compliance    with the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0    Unless required by applicable law or agreed to in writing,    software distributed under the License is distributed on an    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY    KIND, either express or implied.  See the License for the    specific language governing permissions and limitations    under the License.   */package com.ecyrd.jspwiki.filters;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.util.*;import org.apache.log4j.Logger;import org.jdom.Document;import org.jdom.Element;import org.jdom.JDOMException;import org.jdom.input.SAXBuilder;import org.jdom.xpath.XPath;import com.ecyrd.jspwiki.WikiContext;import com.ecyrd.jspwiki.WikiEngine;import com.ecyrd.jspwiki.WikiException;import com.ecyrd.jspwiki.event.WikiEventManager;import com.ecyrd.jspwiki.event.WikiPageEvent;import com.ecyrd.jspwiki.modules.ModuleManager;import com.ecyrd.jspwiki.modules.WikiModuleInfo;import com.ecyrd.jspwiki.util.ClassUtil;import com.ecyrd.jspwiki.util.PriorityList;/** *  Manages the page filters.  Page filters are components that can be executed *  at certain places: *  <ul> *    <li>Before the page is translated into HTML. *    <li>After the page has been translated into HTML. *    <li>Before the page is saved. *    <li>After the page has been saved. *  </ul> *  *  Using page filters allows you to modify the page data on-the-fly, and do things like *  adding your own custom WikiMarkup. *  *  <p> *  The initial page filter configuration is kept in a file called "filters.xml".  The *  format is really very simple: *  <pre> *  <?xml version="1.0"?> *  *  <pagefilters> * *    <filter> *      <class>com.ecyrd.jspwiki.filters.ProfanityFilter</class> *    </filter> *   *    <filter> *      <class>com.ecyrd.jspwiki.filters.TestFilter</class> * *      <param> *        <name>foobar</name> *        <value>Zippadippadai</value> *      </param> * *      <param> *        <name>blatblaa</name> *        <value>5</value> *      </param> * *    </filter> *  </pagefilters> *  </pre> * *  The &lt;filter> -sections define the filters.  For more information, please see *  the PageFilterConfiguration page in the JSPWiki distribution. * */public final class FilterManager extends ModuleManager{    private PriorityList    m_pageFilters = new PriorityList();    private HashMap<String, PageFilterInfo>          m_filterClassMap = new HashMap<String,PageFilterInfo>();    private static final Logger log = Logger.getLogger(WikiEngine.class);    /** Property name for setting the filter XML property file.  Value is <tt>{@value}</tt>. */    public static final String PROP_FILTERXML = "jspwiki.filterConfig";        /** Default location for the filter XML property file.  Value is <tt>{@value}</tt>. */    public static final String DEFAULT_XMLFILE = "/WEB-INF/filters.xml";    /** JSPWiki system filters are all below this value. */    public static final int SYSTEM_FILTER_PRIORITY = -1000;        /** The standard user level filtering. */    public static final int USER_FILTER_PRIORITY   = 0;        /**     *  Constructs a new FilterManager object.     *       *  @param engine The WikiEngine which owns the FilterManager     *  @param props Properties to initialize the FilterManager with     *  @throws WikiException If something goes wrong.     */    public FilterManager( WikiEngine engine, Properties props )        throws WikiException    {        super( engine );        initialize( props );    }    /**     *  Adds a page filter to the queue.  The priority defines in which     *  order the page filters are run, the highest priority filters go     *  in the queue first.     *  <p>     *  In case two filters have the same priority, their execution order     *  is the insertion order.     *     *  @since 2.1.44.     *  @param f PageFilter to add     *  @param priority The priority in which position to add it in.     *  @throws IllegalArgumentException If the PageFilter is null or invalid.     */    public void addPageFilter( PageFilter f, int priority ) throws IllegalArgumentException    {        if( f == null )        {            throw new IllegalArgumentException("Attempt to provide a null filter - this should never happen.  Please check your configuration (or if you're a developer, check your own code.)");        }        m_pageFilters.add( f, priority );    }    private void initPageFilter( String className, Properties props )    {        try        {            PageFilterInfo info = m_filterClassMap.get( className );                        if( info != null && !checkCompatibility(info) )            {                String msg = "Filter '"+info.getName()+"' not compatible with this version of JSPWiki";                log.warn(msg);                return;            }                        int priority = 0; // FIXME: Currently fixed.            Class cl = ClassUtil.findClass( "com.ecyrd.jspwiki.filters",                                            className );            PageFilter filter = (PageFilter)cl.newInstance();            filter.initialize( m_engine, props );            addPageFilter( filter, priority );            log.info("Added page filter "+cl.getName()+" with priority "+priority);        }        catch( ClassNotFoundException e )        {            log.error("Unable to find the filter class: "+className);        }        catch( InstantiationException e )        {            log.error("Cannot create filter class: "+className);        }        catch( IllegalAccessException e )        {            log.error("You are not allowed to access class: "+className);        }        catch( ClassCastException e )        {            log.error("Suggested class is not a PageFilter: "+className);        }        catch( FilterException e )        {            log.error("Filter "+className+" failed to initialize itself.", e);        }    }    /**     *  Initializes the filters from an XML file.     *       *  @param props The list of properties.  Typically jspwiki.properties     *  @throws WikiException If something goes wrong.     */    protected void initialize( Properties props )        throws WikiException    {        InputStream xmlStream = null;        String      xmlFile   = props.getProperty( PROP_FILTERXML );        try        {            registerFilters();                        if( m_engine.getServletContext() != null )            {                log.debug( "Attempting to locate " + DEFAULT_XMLFILE + " from servlet context." );                if( xmlFile == null )                {                    xmlStream = m_engine.getServletContext().getResourceAsStream( DEFAULT_XMLFILE );                }                else                {                    xmlStream = m_engine.getServletContext().getResourceAsStream( xmlFile );                }            }            if( xmlStream == null )            {                // just a fallback element to the old behaviour prior to 2.5.8                log.debug( "Attempting to locate filters.xml from class path." );                if( xmlFile == null )                {                    xmlStream = getClass().getResourceAsStream( "/filters.xml" );                }                else                {                    xmlStream = getClass().getResourceAsStream( xmlFile );                }            }            if( (xmlStream == null) && (xmlFile != null) )            {                log.debug("Attempting to load property file "+xmlFile);                xmlStream = new FileInputStream( new File(xmlFile) );            }            if( xmlStream == null )            {                log.info("Cannot find property file for filters (this is okay, expected to find it as: '"+ (xmlFile == null ? DEFAULT_XMLFILE : xmlFile ) +"')");                return;            }                        parseConfigFile( xmlStream );        }        catch( IOException e )        {            log.error("Unable to read property file", e);        }        catch( JDOMException e )        {            log.error("Problem in the XML file",e);        }    }    /**     *  Parses the XML filters configuration file.     *       * @param xmlStream     * @throws JDOMException     * @throws IOException     */    private void parseConfigFile( InputStream xmlStream )        throws JDOMException,               IOException    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -