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

📄 pluginmanager.java

📁 JSPWiki,100%Java开发的一套完整WIKI程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        throws PluginException    {        if( !m_pluginsEnabled )            return( "" );        try        {            Class      pluginClass;            WikiPlugin plugin;            boolean debug = TextUtil.isPositive( (String) params.get( PARAM_DEBUG ) );            pluginClass = findPluginClass( classname );            //            //   Create...            //            try            {                plugin = (WikiPlugin) pluginClass.newInstance();            }            catch( InstantiationException e )            {                throw new PluginException( "Cannot instantiate plugin "+classname, e );            }            catch( IllegalAccessException e )            {                throw new PluginException( "Not allowed to access plugin "+classname, e );            }            catch( Exception e )            {                throw new PluginException( "Instantiation of plugin "+classname+" failed.", e );            }            //            //  ...and launch.            //            try            {                return plugin.execute( context, params );            }            catch( PluginException e )            {                if( debug )                {                    return stackTrace( params, e );                }                // Just pass this exception onward.                throw (PluginException) e.fillInStackTrace();            }            catch( Throwable t )            {                // But all others get captured here.                log.info( "Plugin failed while executing:", t );                if( debug )                {                    return stackTrace( params, t );                }                throw new PluginException( "Plugin failed", t );            }                    }        catch( ClassNotFoundException e )        {            throw new PluginException( "Could not find plugin "+classname, e );        }        catch( ClassCastException e )        {            throw new PluginException( "Class "+classname+" is not a Wiki plugin.", e );        }    }    /**     *  Parses plugin arguments.  Handles quotes and all other kewl     *  stuff.     *       *  @param argstring The argument string to the plugin.  This is     *  typically a list of key-value pairs, using "'" to escape     *  spaces in strings, followed by an empty line and then the     *  plugin body.  In case the parameter is null, will return an     *  empty parameter list.     *     *  @return A parsed list of parameters.  The plugin body is put     *  into a special parameter defined by PluginManager.PARAM_BODY.     *     *  @throws IOException If the parsing fails.     */    public Map parseArgs( String argstring )        throws IOException    {        HashMap         arglist = new HashMap();        StringReader    in      = new StringReader(argstring);        StreamTokenizer tok     = new StreamTokenizer(in);        int             type;        //        //  Protection against funny users.        //        if( argstring == null ) return arglist;        String param = null, value = null;        tok.eolIsSignificant( true );        boolean potentialEmptyLine = false;        boolean quit               = false;        while( !quit )        {            String s;            type = tok.nextToken();            switch( type )            {              case StreamTokenizer.TT_EOF:                quit = true;                s = null;                break;              case StreamTokenizer.TT_WORD:                s = tok.sval;                potentialEmptyLine = false;                break;              case StreamTokenizer.TT_EOL:                quit = potentialEmptyLine;                potentialEmptyLine = true;                s = null;                break;              case StreamTokenizer.TT_NUMBER:                s = Integer.toString( new Double(tok.nval).intValue() );                potentialEmptyLine = false;                break;              case '\'':                s = tok.sval;                break;              default:                s = null;            }            //            //  Assume that alternate words on the line are            //  parameter and value, respectively.            //            if( s != null )            {                if( param == null )                 {                    param = s;                }                else                {                    value = s;                                                arglist.put( param, value );                    // log.debug("ARG: "+param+"="+value);                    param = null;                }            }        }        //        //  Now, we'll check the body.        //        if( potentialEmptyLine )        {            StringWriter out = new StringWriter();            FileUtil.copyContents( in, out );            String bodyContent = out.toString();            if( bodyContent != null )            {                arglist.put( PARAM_BODY, bodyContent );            }        }                return arglist;    }        /**     *  Parses a plugin.  Plugin commands are of the form:     *  [{INSERT myplugin WHERE param1=value1, param2=value2}]     *  myplugin may either be a class name or a plugin alias.     *  <P>     *  This is the main entry point that is used.     *     *  @param context The current WikiContext.     *  @param commandline The full command line, including plugin     *  name, parameters and body.     *     *  @return HTML as returned by the plugin, or possibly an error     *  message.     */    public String execute( WikiContext context,                           String commandline )        throws PluginException    {        if( !m_pluginsEnabled )            return( "" );        PatternMatcher  matcher  = new Perl5Matcher();        try        {            if( matcher.contains( commandline, m_pluginPattern ) )            {                MatchResult res = matcher.getMatch();                String plugin   = res.group(2);                                String args     = commandline.substring(res.endOffset(0),                                                        commandline.length() -                                                        (commandline.charAt(commandline.length()-1) == '}' ? 1 : 0 ) );                Map arglist     = parseArgs( args );                return execute( context, plugin, arglist );            }        }        catch( NoSuchElementException e )        {            String msg =  "Missing parameter in plugin definition: "+commandline;            log.warn( msg, e );            throw new PluginException( msg );        }        catch( IOException e )        {            String msg = "Zyrf.  Problems with parsing arguments: "+commandline;            log.warn( msg, e );            throw new PluginException( msg );        }        // FIXME: We could either return an empty string "", or        // the original line.  If we want unsuccessful requests        // to be invisible, then we should return an empty string.        return commandline;    }    /*      // FIXME: Not functioning, needs to create or fetch PageContext from somewhere.    public class TagPlugin implements WikiPlugin    {        private Class m_tagClass;                public TagPlugin( Class tagClass )        {            m_tagClass = tagClass;        }                public String execute( WikiContext context, Map params )            throws PluginException        {            WikiPluginTag plugin = m_tagClass.newInstance();                    }    }    */}

⌨️ 快捷键说明

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