Package org.apache.wiki

Examples of org.apache.wiki.WikiEngine


         * @return String Wiki page snippet
         * @throws PluginException Malformed pattern parameter.
         */
        public String execute( WikiContext context, Map<String, String> params ) throws PluginException
        {
            WikiEngine engine = context.getEngine();
            WikiPage page = context.getPage();
            String result = STR_EMPTY;

            if( page != null )
            {
                // get parameters
                String pagename = page.getName();
                String count = params.get( PARAM_COUNT );
                String show = params.get( PARAM_SHOW );
                int entries = TextUtil.parseIntParameter( params.get( PARAM_MAX_ENTRIES ), Integer.MAX_VALUE );
                final int max = TextUtil.parseIntParameter( params.get( PARAM_MAX_COUNT ), Integer.MAX_VALUE );
                final int min = TextUtil.parseIntParameter( params.get( PARAM_MIN_COUNT ), Integer.MIN_VALUE );
                String sort = params.get( PARAM_SORT );
                String body = params.get( DefaultPluginManager.PARAM_BODY );
                Pattern[] exclude = compileGlobs( PARAM_EXCLUDE, params.get( PARAM_EXCLUDE ) );
                Pattern[] include = compileGlobs( PARAM_INCLUDE, params.get( PARAM_INCLUDE ) );
                Pattern[] refer = compileGlobs( PARAM_REFER, params.get( PARAM_REFER ) );
                PatternMatcher matcher = (null != exclude || null != include || null != refer) ? new Perl5Matcher() : null;
                boolean increment = false;

                // increment counter?
                if( STR_YES.equals( count ) )
                {
                    increment = true;
                }
                else
                {
                    count = null;
                }

                // default increment counter?
                if( (show == null || STR_NONE.equals( show )) && count == null )
                {
                    increment = true;
                }

                // filter on referring pages?
                Collection<String> referrers = null;

                if( refer != null )
                {
                    ReferenceManager refManager = engine.getReferenceManager();

                    Iterator iter = refManager.findCreated().iterator();

                    while ( iter != null && iter.hasNext() )
                    {

                        String name = (String) iter.next();
                        boolean use = false;

                        for( int n = 0; !use && n < refer.length; n++ )
                        {
                            use = matcher.matches( name, refer[n] );
                        }

                        if( use )
                        {
                            Collection<String> refs = engine.getReferenceManager().findReferrers( name );

                            if( refs != null && !refs.isEmpty() )
                            {
                                if( referrers == null )
                                {
                                    referrers = new HashSet<String>();
                                }
                                referrers.addAll( refs );
                            }
                        }
                    }
                }

                synchronized( this )
                {
                    Counter counter = m_counters.get( pagename );

                    // only count in view mode, keep storage values in sync
                    if( increment && WikiContext.VIEW.equalsIgnoreCase( context.getRequestContext() ) )
                    {
                        if( counter == null )
                        {
                            counter = new Counter();
                            m_counters.put( pagename, counter );
                        }
                        counter.increment();
                        m_storage.setProperty( pagename, counter.toString() );
                        m_dirty = true;
                    }

                    if( show == null || STR_NONE.equals( show ) )
                    {
                        // nothing to show

                    }
                    else if( PARAM_COUNT.equals( show ) )
                    {
                        // show page count
                        if( counter == null )
                        {
                            counter = new Counter();
                            m_counters.put( pagename, counter );
                            m_storage.setProperty( pagename, counter.toString() );
                            m_dirty = true;
                        }
                        result = counter.toString();

                    }
                    else if( body != null && 0 < body.length() && STR_LIST.equals( show ) )
                    {
                        // show list of counts
                        String header = STR_EMPTY;
                        String line = body;
                        String footer = STR_EMPTY;
                        int start = body.indexOf( STR_SEPARATOR );

                        // split body into header, line, footer on ----
                        // separator
                        if( 0 < start )
                        {
                            header = body.substring( 0, start );

                            start = skipWhitespace( start + STR_SEPARATOR.length(), body );

                            int end = body.indexOf( STR_SEPARATOR, start );

                            if( start >= end )
                            {
                                line = body.substring( start );

                            }
                            else
                            {
                                line = body.substring( start, end );

                                end = skipWhitespace( end + STR_SEPARATOR.length(), body );

                                footer = body.substring( end );
                            }
                        }

                        // sort on name or count?
                        Map<String, Counter> sorted = m_counters;

                        if( sort != null && PARAM_COUNT.equals( sort ) )
                        {
                            sorted = new TreeMap<String, Counter>( m_compareCountDescending );

                            sorted.putAll( m_counters );
                        }

                        // build a messagebuffer with the list in wiki markup
                        StringBuffer buf = new StringBuffer( header );
                        MessageFormat fmt = new MessageFormat( line );
                        Object[] args = new Object[] { pagename, STR_EMPTY, STR_EMPTY };
                        Iterator iter = sorted.entrySet().iterator();

                        while ( iter != null && 0 < entries && iter.hasNext() )
                        {

                            Entry entry = (Entry) iter.next();
                            String name = (String) entry.getKey();

                            // check minimum/maximum count
                            final int value = ((Counter) entry.getValue()).getValue();
                            boolean use = min <= value && value <= max;

                            // did we specify a refer-to page?
                            if( use && referrers != null )
                            {

                                use = referrers.contains( name );
                            }

                            // did we specify what pages to include?
                            if( use && include != null )
                            {
                                use = false;

                                for( int n = 0; !use && n < include.length; n++ )
                                {

                                    use = matcher.matches( name, include[n] );
                                }
                            }

                            // did we specify what pages to exclude?
                            if( use && null != exclude )
                            {
                                for( int n = 0; use && n < exclude.length; n++ )
                                {

                                    use &= !matcher.matches( name, exclude[n] );
                                }
                            }

                            if( use )
                            {
                                args[1] = engine.beautifyTitle( name );
                                args[2] = entry.getValue();

                                fmt.format( args, buf, null );

                                entries--;
                            }
                        }
                        buf.append( footer );

                        // let the engine render the list
                        result = engine.textToHTML( context, buf.toString() );
                    }
                }
            }
            return result;
        }
View Full Code Here


                                     String username,
                                     String password,
                                     Hashtable content )
        throws XmlRpcException
    {
        WikiEngine engine = m_context.getEngine();
        String url = "";

        log.info("metaWeblog.newMediaObject() called");

        WikiPage page = engine.getPage( blogid );
        checkPermissions( page, username, password, "upload" );

        String name = (String) content.get( "name" );
        byte[] data = (byte[]) content.get( "bits" );

        AttachmentManager attmgr = engine.getAttachmentManager();

        try
        {
            Attachment att = new Attachment( engine, blogid, name );
            att.setAuthor( username );
            attmgr.storeAttachment( att, new ByteArrayInputStream( data ) );

            url = engine.getURL( WikiContext.ATTACH, att.getName(), null, true );
        }
        catch( Exception e )
        {
            log.error( "Failed to upload attachment", e );
            throw new XmlRpcException( 0, "Failed to upload media object: "+e.getMessage() );
View Full Code Here

                      String password,
                      Hashtable content,
                      boolean publish )
        throws XmlRpcException
    {
        WikiEngine engine = m_context.getEngine();
        log.info("metaWeblog.editPost("+postid+") called");

        // FIXME: Is postid correct?  Should we determine it from the page name?
        WikiPage page = engine.getPage( postid );
        checkPermissions( page, username, password, "edit" );

        try
        {
            WikiPage entryPage = (WikiPage)page.clone();
            entryPage.setAuthor( username );

            WikiContext context = new WikiContext( engine, entryPage );

            StringBuffer text = new StringBuffer();
            text.append( "!"+content.get("title") );
            text.append( "\n\n" );
            text.append( content.get("description") );

            log.debug("Updating entry: "+text);

            engine.saveText( context, text.toString() );
        }
        catch( Exception e )
        {
            log.error("Failed to create weblog entry",e);
            throw new XmlRpcException( 0, "Failed to update weblog entry: "+e.getMessage() );
View Full Code Here

     {@inheritDoc}
     */
    public void postSave( WikiContext context, String pagecontent )
    {
        String     blogName = context.getPage().getName();
        WikiEngine engine   = context.getEngine();

        int blogentryTxt = blogName.indexOf("_blogentry_");
        if( blogentryTxt == -1 )
        {
            return; // This is not a weblog entry.
        }
       
        blogName = blogName.substring( 0, blogentryTxt );

        if( blogName.equals( engine.getFrontPage() ) )
        {
            blogName = null;
        }

        try
        {
            XmlRpcClient xmlrpc = new XmlRpcClient(m_pingURL);
            Vector<String> params = new Vector<String>();
            params.addElement( "The Butt Ugly Weblog" ); // FIXME: Must be settable
            params.addElement( engine.getURL( WikiContext.VIEW, blogName, null, true ) );

            if( log.isDebugEnabled() )
                log.debug("Pinging weblogs.com with URL: "+engine.getURL( WikiContext.VIEW, blogName, null, true ));

            xmlrpc.executeAsync("weblogUpdates.ping", params,
                                new AsyncCallback()
                                {
                                    public void handleError( Exception ex,
View Full Code Here

     *
     * @param context the wiki context
     * @return the site name
     */
    public static String getSiteName(WikiContext context) {
        WikiEngine engine = context.getEngine();

        String blogname = null;

        try {
            blogname = engine.getVariableManager().getValue(context, VAR_BLOGNAME);
        } catch (NoSuchVariableException e) {
        }

        if (blogname == null) {
            blogname = engine.getApplicationName() + ": " + context.getPage().getName();
        }

        return blogname;
    }
View Full Code Here

    /** {@inheritDoc} */
    public final int doWikiStartTag()
        throws IOException
    {
        WikiEngine engine = m_wikiContext.getEngine();
        WikiContext ctx;
       
        if( m_pageName == null )
        {
            ctx = m_wikiContext;
        }
        else
        {
            ctx = (WikiContext)m_wikiContext.clone();
            ctx.setPage( engine.getPage(m_pageName) );
        }

        Integer vernew = (Integer) pageContext.getAttribute( ATTR_NEWVERSION,
                                                             PageContext.REQUEST_SCOPE );
        Integer verold = (Integer) pageContext.getAttribute( ATTR_OLDVERSION,
                                                             PageContext.REQUEST_SCOPE );

        log.info("Request diff between version "+verold+" and "+vernew);

        if( ctx.getPage() != null )
        {
            JspWriter out = pageContext.getOut();

            String diff = engine.getDiff( ctx,
                                          vernew.intValue(),
                                          verold.intValue() );

            if( diff.length() == 0 )
            {
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public String execute( WikiContext context, Map<String, String> params )
        throws PluginException
    {
        WikiEngine engine = context.getEngine();

        StringBuffer res = new StringBuffer();

        String clazz        = params.get( PARAM_CLASS );
        String includedPage = params.get( PARAM_PAGENAME );
        String style        = params.get( PARAM_STYLE );
        String defaultstr   = params.get( PARAM_DEFAULT );
        int    section      = TextUtil.parseIntParameter(params.get( PARAM_SECTION ), -1 );
        int    maxlen       = TextUtil.parseIntParameter(params.get( PARAM_MAXLENGTH ), -1 );

        if( style == null ) style = DEFAULT_STYLE;

        if( maxlen == -1 ) maxlen = Integer.MAX_VALUE;

        if( includedPage != null )
        {
            WikiPage page = null;
            try
            {
                String pageName = engine.getFinalPageName( includedPage );
                if( pageName != null )
                {
                    page = engine.getPage( pageName );
                }
                else
                {
                    page = engine.getPage( includedPage );
                }
            }
            catch( ProviderException e )
            {
                res.append( "<span class=\"error\">Page could not be found by the page provider.</span>" );
                return res.toString();
            }
           
            if( page != null )
            {
                //
                //  Check for recursivity
                //
               
                List<String> previousIncludes = (List)context.getVariable( ATTR_RECURSE );
               
                if( previousIncludes != null )
                {
                    if( previousIncludes.contains( page.getName() ) )
                    {
                        return "<span class=\"error\">Error: Circular reference - you can't include a page in itself!</span>";
                    }
                }
                else
                {
                    previousIncludes = new ArrayList<String>();
                }
              
                previousIncludes.add( page.getName() );
                context.setVariable( ATTR_RECURSE, previousIncludes );
               
                //
                // Check for permissions
                //
                AuthorizationManager mgr = engine.getAuthorizationManager();

                if( !mgr.checkPermission( context.getWikiSession(),
                                          PermissionFactory.getPagePermission( page, "view") ) )
                {
                    res.append("<span class=\"error\">You do not have permission to view this included page.</span>");
                    return res.toString();
                }

                /**
                 *  We want inclusion to occur within the context of
                 *  its own page, because we need the links to be correct.
                 */
               
                WikiContext includedContext = (WikiContext) context.clone();
                includedContext.setPage( page );

                String pageData = engine.getPureText( page );
                String moreLink = "";

                if( section != -1 )
                {
                    try
                    {
                        pageData = TextUtil.getSection( pageData, section );
                    }
                    catch( IllegalArgumentException e )
                    {
                        throw new PluginException( e.getMessage() );
                    }
                }

                if( pageData.length() > maxlen )
                {
                    pageData = pageData.substring( 0, maxlen )+" ...";
                    moreLink = "<p><a href=\""+context.getURL(WikiContext.VIEW,includedPage)+"\">More...</a></p>";
                }

                res.append("<div style=\""+style+"\""+(clazz != null ? " class=\""+clazz+"\"" : "")+">");
                res.append( engine.textToHTML( includedContext, pageData ) );
                res.append( moreLink );
                res.append("</div>");
               
                //
                //  Remove the name from the stack; we're now done with this.
View Full Code Here

    public final int doWikiStartTag()
        throws IOException,
               ProviderException
    {
        WikiEngine engine = m_wikiContext.getEngine();
        WikiPage   insertedPage;

        //
        //  NB: The page might not really exist if the user is currently
        //      creating it (i.e. it is not yet in the cache or providers),
        //      AND we got the page from the wikiContext.
        //

        if( m_pageName == null )
        {
            insertedPage = m_wikiContext.getPage();
            if( !engine.pageExists(insertedPage) ) return SKIP_BODY;
        }
        else
        {
            insertedPage = engine.getPage( m_pageName );
        }

        if( insertedPage != null )
        {
            // FIXME: Do version setting later.
            // page.setVersion( WikiProvider.LATEST_VERSION );

            log.debug("Inserting page "+insertedPage);

            JspWriter out = pageContext.getOut();

            WikiPage oldPage = m_wikiContext.setRealPage( insertedPage );
           
            switch( m_mode )
            {
              case HTML:
                out.print( engine.getHTML( m_wikiContext, insertedPage ) );
                break;
              case PLAIN:
                out.print( engine.getText( m_wikiContext, insertedPage ) );
                break;
            }
           
            m_wikiContext.setRealPage( oldPage );
        }
View Full Code Here

    @Override
    public final int doWikiStartTag()
        throws IOException,
               ProviderException
    {
        WikiEngine engine = m_wikiContext.getEngine();
        WikiPage   page   = m_wikiContext.getPage();

        if( page != null && engine.pageExists(page.getName()) )
        {
            int version = page.getVersion();
            boolean include = false;

            WikiPage latest = engine.getPage( page.getName() );

            //log.debug("Doing version check: this="+page.getVersion()+
            //          ", latest="+latest.getVersion());

            switch( m_mode )
View Full Code Here

    private static final long serialVersionUID = 0L;
   
    public final int doWikiStartTag()
        throws IOException
    {
        WikiEngine engine = m_wikiContext.getEngine();
        WikiPage   page   = m_wikiContext.getPage();

        String encodedName = engine.encodeName( page.getName() );

        String rssURL      = engine.getGlobalRSSURL();
        String rssFeedURL  = engine.getURL(WikiContext.NONE, "rss.jsp",
                                           "page="+encodedName+"&amp;mode=wiki",
                                           true );
       
        if( rssURL != null )
        {
            String siteName = Feed.getSiteName(m_wikiContext);
            siteName = TextUtil.replaceEntities( siteName );
           
            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for the entire site.\" href=\""+rssURL+"\" />\n");
            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for page "+siteName+".\" href=\""+rssFeedURL+"\" />\n");

            // TODO: Enable this
            /*
            pageContext.getOut().print("<link rel=\"service.post\" type=\"application/atom+xml\" title=\""+
                                       siteName+"\" href=\""+atomPostURL+"\" />\n");
            */
            // FIXME: This does not work always, as plugins are not initialized until the first fetch
            if( "true".equals(page.getAttribute(WeblogPlugin.ATTR_ISWEBLOG)) )
            {
                String blogFeedURL = engine.getURL(WikiContext.NONE,"rss.jsp","page="+encodedName,true);
                String atomFeedURL = engine.getURL(WikiContext.NONE,"rss.jsp","page="+encodedName+"&amp;type=atom",true);
       
                pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS feed for weblog "+
                                           siteName+".\" href=\""+blogFeedURL+"\" />\n");

                pageContext.getOut().print("<link rel=\"service.feed\" type=\"application/atom+xml\" title=\"Atom 1.0 weblog feed for "+
View Full Code Here

TOP

Related Classes of org.apache.wiki.WikiEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.