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

📄 pluginmanager.java

📁 我想下载一个东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*     JSPWiki - a JSP-based WikiWiki clone.    Copyright (C) 2001 Janne Jalkanen (Janne.Jalkanen@iki.fi)    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation; either version 2.1 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package com.ecyrd.jspwiki.plugin;import org.apache.oro.text.*;import org.apache.oro.text.regex.*;import org.apache.log4j.Category;import java.io.StreamTokenizer;import java.io.StringReader;import java.io.StringWriter;import java.io.IOException;import java.util.NoSuchElementException;import java.util.Map;import java.util.Vector;import java.util.Iterator;import java.util.Properties;import java.util.StringTokenizer;import java.util.HashMap;import com.ecyrd.jspwiki.WikiContext;import com.ecyrd.jspwiki.FileUtil;import com.ecyrd.jspwiki.InternalWikiException;/** *  Manages plugin classes.  There exists a single instance of PluginManager *  per each instance of WikiEngine, that is, each JSPWiki instance. *  <P> *  A plugin is defined to have three parts: *  <OL> *    <li>The plugin class *    <li>The plugin parameters *    <li>The plugin body *  </ol> * *  For example, in the following line of code: *  <pre> *  [{INSERT com.ecyrd.jspwiki.plugin.FunnyPlugin  foo='bar' *  blob='goo' * *  abcdefghijklmnopqrstuvw *  01234567890}] *  </pre> * *  The plugin class is "com.ecyrd.jspwiki.plugin.FunnyPlugin", the *  parameters are "foo" and "blob" (having values "bar" and "goo", *  respectively), and the plugin body is then *  "abcdefghijklmnopqrstuvw\n01234567890".  *  <P> *  The class name can be shortened, and marked without the package. *  For example, "FunnyPlugin" would be expanded to *  "com.ecyrd.jspwiki.plugin.FunnyPlugin" automatically.  It is also *  possible to defined other packages, by setting the *  "jspwiki.plugin.searchPath" property.  See the included *  jspwiki.properties file for examples. *  <P> *  Even though the nominal way of writing the plugin is *  <pre> *  [{INSERT pluginclass WHERE param1=value1...}], *  </pre> *  it is possible to shorten this quite a lot, by skipping the *  INSERT, and WHERE words, and dropping the package name.  For *  example: * *  <pre> *  [{INSERT com.ecyrd.jspwiki.plugin.Counter WHERE name='foo'}] *  </pre> * *  is the same as *  <pre> *  [{Counter name='foo'}] *  </pre> * *  @author Janne Jalkanen *  @since 1.6.1 */public class PluginManager{    private static Category log = Category.getInstance( PluginManager.class );    /**     *  This is the default package to try in case the instantiation     *  fails.     */    public static final String DEFAULT_PACKAGE = "com.ecyrd.jspwiki.plugin";    /**     *  The property name defining which packages will be searched for properties.     */    public static final String PROP_SEARCHPATH = "jspwiki.plugin.searchPath";    /**     *  The name of the body content.  Current value is "_body".     */    public static final String PARAM_BODY      = "_body";    Vector  m_searchPath = new Vector();    Pattern m_pluginPattern;    private boolean m_pluginsEnabled = true;    /**     *  Create a new PluginManager.     *     *  @param props Contents of a "jspwiki.properties" file.     */    public PluginManager( Properties props )    {        String packageNames = props.getProperty( PROP_SEARCHPATH );        if( packageNames != null )        {            StringTokenizer tok = new StringTokenizer( packageNames, "," );            while( tok.hasMoreTokens() )            {                m_searchPath.add( tok.nextToken() );            }        }        //        //  The default package is always added.        //        m_searchPath.add( DEFAULT_PACKAGE );        PatternCompiler compiler = new Perl5Compiler();        try        {            m_pluginPattern = compiler.compile( "\\{?(INSERT)?\\s*([\\w\\._]+)[ \\t]*(WHERE)?[ \\t]*" );        }        catch( MalformedPatternException e )        {            log.fatal("Internal error: someone messed with pluginmanager patterns.", e );            throw new InternalWikiException( "PluginManager patterns are broken" );        }    }    /**     * Enables or disables plugin execution.     */    public void enablePlugins( boolean enabled )    {        m_pluginsEnabled = enabled;    }    /**     * Returns plugin execution status. If false, plugins are not      * executed when they are encountered on a WikiPage, and an     * empty string is returned in their place.     */    public boolean pluginsEnabled()    {        return( m_pluginsEnabled );    }    /**     *  Returns true if the link is really command to insert     *  a plugin.     *  <P>     *  Currently we just check if the link starts with "{INSERT",     *  or just plain "{" but not "{$".     *     *  @param link Link text, i.e. the contents of text between [].     *  @return True, if this link seems to be a command to insert a plugin here.     */    public static boolean isPluginLink( String link )    {        return link.startsWith("{INSERT") ||                (link.startsWith("{") && !link.startsWith("{$"));    }    /**     *  Attempts to locate a plugin class from the class path     *  set in the property file.     *     *  @param classname Either a fully fledged class name, or just     *  the name of the file (that is,     *  "com.ecyrd.jspwiki.plugin.Counter" or just plain "Counter").     *     *  @return A found class.     *     *  @throws ClassNotFoundException if no such class exists.     */    private Class findPluginClass( String classname )        throws ClassNotFoundException    {        ClassLoader loader = getClass().getClassLoader();        try        {            return loader.loadClass( classname );        }        catch( ClassNotFoundException e )        {            for( Iterator i = m_searchPath.iterator(); i.hasNext(); )            {                String packageName = (String)i.next();                try                {                    return loader.loadClass( packageName + "." + classname );                }                catch( ClassNotFoundException ex )                {                    // This is okay, we go to the next package.                }            }            //            //  Nope, it wasn't on the normal plugin path.  Let's try tags.            //  We'll only accept tags that implement the WikiPluginTag            //            /*              FIXME: Not functioning, need to create a PageContext            try            {                Class c = loader.loadClass( "com.ecyrd.jspwiki.tags."+classname );                if( c instanceof WikiPluginTag )                {                    return new TagPlugin( c );                }            }            catch( ClassNotFoundException exx )            {                // Just fall through, and let the execution end with stuff.            }            */        }        throw new ClassNotFoundException("Plugin not in "+PROP_SEARCHPATH);    }    /**     *  Executes a plugin class in the given context.     *  <P>Used to be private, but is public since 1.9.21.     *     *  @param context The current WikiContext.     *  @param classname The name of the class.  Can also be a     *  shortened version without the package name, since the class name is searched from the     *  package search path.     *     *  @param params A parsed map of key-value pairs.

⌨️ 快捷键说明

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