public String execute()

in jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferredPagesPlugin.java [104:206]


    public String execute( final Context context, final Map< String, String > params ) throws PluginException {
        m_engine = context.getEngine();
        final Page page = context.getPage();
        if( page == null ) {
            return "";
        }

        // parse parameters
        String rootname = params.get( PARAM_ROOT );
        if( rootname == null ) {
            rootname = page.getName() ;
        }

        String format = params.get( PARAM_FORMAT );
        if( format == null) {
            format = "";
        }
        if( format.contains( "full" ) ) {
            m_formatCompact = false ;
        }
        if( format.contains( "sort" ) ) {
            m_formatSort = true  ;
        }

        m_depth = TextUtil.parseIntParameter( params.get( PARAM_DEPTH ), MIN_DEPTH );
        if( m_depth > MAX_DEPTH ) {
            m_depth = MAX_DEPTH;
        }

        String includePattern = params.get(PARAM_INCLUDE);
        if( includePattern == null ) {
            includePattern = ".*";
        }

        String excludePattern = params.get(PARAM_EXCLUDE);
        if( excludePattern == null ) {
            excludePattern = "^$";
        }

        final String columns = params.get( PARAM_COLUMNS );
        if( columns != null ) {
            items = TextUtil.parseIntParameter( columns, 0 );
        }

        LOG.debug( "Fetching referred pages for "+ rootname +
                   " with a depth of "+ m_depth +
                   " with include pattern of "+ includePattern +
                   " with exclude pattern of "+ excludePattern +
                   " with " + columns + " items" );

        //
        // do the actual work
        //
        final String href  = context.getViewURL( rootname );
        final String title = "ReferredPagesPlugin: depth[" + m_depth +
                             "] include[" + includePattern + "] exclude[" + excludePattern +
                             "] format[" + ( m_formatCompact ? "compact" : "full" ) +
                             ( m_formatSort ? " sort" : "" ) + "]";

        if( items > 1 ) {
            m_result.append( "<div class=\"ReferredPagesPlugin\" style=\"" )
                    .append( "columns:" ).append( columns ).append( ";" )
                    .append( "moz-columns:" ).append( columns ).append( ";" )
                    .append( "webkit-columns:" ).append( columns ).append( ";" )
                    .append( "\">\n" );
        } else {
            m_result.append( "<div class=\"ReferredPagesPlugin\">\n" );
        }
        m_result.append( "<a class=\"wikipage\" href=\"" )
                .append( href ).append( "\" title=\"" )
                .append( TextUtil.replaceEntities( title ) )
                .append( "\">" )
                .append( TextUtil.replaceEntities( rootname ) )
                .append( "</a>\n" );
        m_exists.add( rootname );

        // pre compile all needed patterns
        // glob compiler :  * is 0..n instance of any char  -- more convenient as input
        // perl5 compiler : .* is 0..n instances of any char -- more powerful
        //PatternCompiler g_compiler = new GlobCompiler();
        final PatternCompiler compiler = new Perl5Compiler();

        try {
            m_includePattern = compiler.compile( includePattern );
            m_excludePattern = compiler.compile( excludePattern );
        } catch( final MalformedPatternException e ) {
            if( m_includePattern == null ) {
                throw new PluginException( "Illegal include pattern detected." );
            } else if( m_excludePattern == null ) {
                throw new PluginException( "Illegal exclude pattern detected." );
            } else {
                throw new PluginException( "Illegal internal pattern detected." );
            }
        }

        // go get all referred links
        getReferredPages(context,rootname, 0);

        // close and finish
        m_result.append ("</div>\n" ) ;

        return m_result.toString() ;
    }