Package org.apache.wiki

Examples of org.apache.wiki.WikiEngine


     */
    @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


                                              String title,
                                              String baseName )
    {
        String basicPageName = ((baseName != null)?baseName:"Bug")+MarkupParser.cleanLink(title);

        WikiEngine engine = context.getEngine();

        String pageName = basicPageName;
        long   lastbug  = 2;

        while( engine.pageExists( pageName ) )
        {
            pageName = basicPageName + lastbug++;
        }

        return pageName;
View Full Code Here

               commentText + "\" title=\"" + commentText + "\"/>";
    }

    private String imageUrl( WikiContext ctx )
    {
        WikiEngine engine = ctx.getEngine();
        String commentImage = engine.getWikiProperties().getProperty(PROP_NOTE_IMAGE,
                                                                     DEFAULT_NOTE_IMAGE);

        commentImage = "images/"+commentImage;
       
        String resource = engine.getTemplateManager().findResource( ctx,
                                                                    engine.getTemplateDir(),
                                                                    commentImage );

        return ctx.getURL( WikiContext.NONE, resource );
    }
View Full Code Here

     {@inheritDoc}
     */
    public String execute( WikiContext context, Map<String, String> params )
        throws PluginException
    {
        WikiEngine engine = context.getEngine();
        String prop = params.get( PARAM_PROP );
       
        if ( "users".equals( prop ) )
        {
            Principal[] principals = WikiSession.userPrincipals( engine );
View Full Code Here

    private List getItems()
    {
        ArrayList<Element> list = new ArrayList<Element>();
        SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");

        WikiEngine engine = m_wikiContext.getEngine();
        ServletContext servletContext = null;

        if( m_wikiContext.getHttpRequest() != null )
            servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();

        for( Iterator i = m_entries.iterator(); i.hasNext(); )
        {
            Entry e = (Entry)i.next();
            WikiPage p = e.getPage();

            String url = e.getURL();

            Element item = new Element("item");

            item.addContent( new Element("link").setText(url) );

            item.addContent( new Element("title").setText( e.getTitle()) );

            item.addContent( new Element("description").setText( e.getContent()) );

            //
            //  Attachments for enclosures
            //

            if( engine.getAttachmentManager().hasAttachments(p) && servletContext != null )
            {
                try
                {
                    Collection c = engine.getAttachmentManager().listAttachments(p);

                    for( Iterator a = c.iterator(); a.hasNext(); )
                    {
                        Attachment att = (Attachment) a.next();

                        Element attEl = new Element("enclosure");
                        attEl.setAttribute( "url", engine.getURL(WikiContext.ATTACH, att.getName(), null, true ) );
                        attEl.setAttribute( "length", Long.toString(att.getSize()) );
                        attEl.setAttribute( "type", getMimeType( servletContext, att.getFileName() ) );

                        item.addContent( attEl );
                    }
View Full Code Here

     {@inheritDoc}
     */
    @Override
    public String getString()
    {
        WikiEngine engine = m_wikiContext.getEngine();
        Element root = new Element("rss");
        root.setAttribute("version","2.0");

        Element channel = new Element("channel");
        root.addContent( channel );

        //
        //  Mandatory parts
        //
        channel.addContent( new Element("title").setText( getChannelTitle() ) );
        channel.addContent( new Element("link").setText(engine.getBaseURL()));
        channel.addContent( new Element("description").setText( getChannelDescription() ));

        //
        //  Optional
        //
        channel.addContent( new Element("language").setText(getChannelLanguage()));
        channel.addContent( new Element("generator").setText("JSPWiki "+Release.VERSTR));

        String mail = engine.getVariable(m_wikiContext,RSSGenerator.PROP_RSS_AUTHOREMAIL);
        if( mail != null )
        {
            String editor = engine.getVariable( m_wikiContext,RSSGenerator.PROP_RSS_AUTHOR );

            if( editor != null )
                mail = mail + " ("+editor+")";

            channel.addContent( new Element("managingEditor").setText(mail) );
View Full Code Here

  protected void setUp() throws Exception
  {
      super.setUp();
      Properties props = new Properties();
      props.load( TestEngine.findTestProperties() );
      WikiEngine engine  = new TestEngine( props );
      m_db = new XMLGroupDatabase();
      m_db.initialize( engine, props );
      m_wiki = engine.getApplicationName();
  }
View Full Code Here

   
    private void addItemList( XML root )
    {
        SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
       
        WikiEngine engine = m_wikiContext.getEngine();
       
        for( Iterator i = m_entries.iterator(); i.hasNext(); )
        {
            Entry e = (Entry)i.next();
           
            String url = e.getURL();
           
            XML item = new XML( "item" );
            item.addAttribute( "rdf:about", url );
           
            item.addElement( new XML("title").addElement( format(e.getTitle()) ) );

            item.addElement( new XML("link").addElement( url ) );

            XML content = new XML("description");
           
            // TODO: Add a size limiter here
            content.addElement( format(e.getContent()) );

            item.addElement( content );

            WikiPage p = e.getPage();
           
            if( p.getVersion() != -1 )
            {
                item.addElement( new XML("wiki:version").addElement( Integer.toString(p.getVersion()) ) );
            }

            if( p.getVersion() > 1 )
            {
                item.addElement( new XML("wiki:diff").addElement( engine.getURL( WikiContext.DIFF,
                                                                                 p.getName(),
                                                                                 "r1=-1",
                                                                                 true) ) );
            }

          
            //
            //  Modification date.
            //
            Calendar cal = Calendar.getInstance();
            cal.setTime( p.getLastModified() );
            cal.add( Calendar.MILLISECOND,
                     - (cal.get( Calendar.ZONE_OFFSET ) +
                        (cal.getTimeZone().inDaylightTime( p.getLastModified() ) ? cal.get( Calendar.DST_OFFSET ) : 0 )) );

            item.addElement( new XML("dc:date").addElement( iso8601fmt.format( cal.getTime() )));
          
            //
            //  Author
            String author = e.getAuthor();
            if( author == null ) author = "unknown";

            XML contributor = new XML("dc:creator");
           
            item.addElement( contributor );

            /*
            XML description = new XML("rdf:Description");
            if( m_wikiContext.getEngine().pageExists(author) )
            {
                description.addAttribute( "link", engine.getURL( WikiContext.VIEW,
                                                                 author,
                                                                 null,
                                                                 true ) );
            }
           
            description.addElement( new XML("value").addElement( format(author) ) );
            contributor.addElement( description );
           */
           
            // Not too many aggregators seem to like this.  Therefore we're
            // just adding the name here.
           
            contributor.addElement( format(author) );
           
            //  PageHistory

            item.addElement( new XML("wiki:history").addElement( engine.getURL( WikiContext.INFO,
                                                                                p.getName(),
                                                                                null,
                                                                                true ) ) );
           
            //
View Full Code Here

        props.setProperty( PageManager.PROP_USECACHE, "false" );
        props.setProperty( "log4j.appender.outlog", "org.apache.log4j.ConsoleAppender" );
        props.setProperty( "log4j.appender.outlog.layout", "org.apache.log4j.PatternLayout" );
        props.setProperty( "jspwiki.useLucene", "false" );
        props.setProperty( "log4j.rootCategory", "INFO,outlog" );
        WikiEngine engine = new WikiEngine( props );

        WikiPageProvider sourceProvider = engine.getPageManager().getProvider();
       
        File tmpDir = new File( SystemUtils.JAVA_IO_TMPDIR, "converter-tmp" );
       
        props.setProperty( AbstractFileProvider.PROP_PAGEDIR, tmpDir.getAbsolutePath() );
        WikiPageProvider destProvider = new VersioningFileProvider();
       
        destProvider.initialize( engine, props );
       
        Collection allPages = sourceProvider.getAllPages();
       
        int idx = 1;
       
        for( Iterator i = allPages.iterator(); i.hasNext(); )
        {
            WikiPage p = (WikiPage)i.next();
           
            System.out.println("Converting page: "+p.getName()+" ("+idx+"/"+allPages.size()+")");
            List pageHistory = engine.getVersionHistory( p.getName() );
           
           
            for( ListIterator v = pageHistory.listIterator(pageHistory.size()); v.hasPrevious(); )
            {
                WikiPage pv = (WikiPage)v.previous();
               
                String text = engine.getPureText( pv.getName(), pv.getVersion() );
               
                destProvider.putPageText( pv, text );
            }
           
            //
View Full Code Here

     {@inheritDoc}
     */
    public String execute( WikiContext context, Map<String, String> params )
        throws PluginException
    {
        WikiEngine engine = context.getEngine();
        WikiPage   page   = context.getPage();
        ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );

        if( context.getVariable( VAR_ALREADY_PROCESSING ) != null )
        {
            //return rb.getString("tableofcontents.title");
            return "<a href=\"#section-TOC\" class=\"toc\">"+rb.getString("tableofcontents.title")+"</a>";
        }

        StringBuffer sb = new StringBuffer();

        sb.append("<div class=\"toc\">\n");
        sb.append("<div class=\"collapsebox\">\n");

        String title = params.get(PARAM_TITLE);
        sb.append("<h4 id=\"section-TOC\">");
        if( title != null )
        {
            //sb.append("<h4>"+TextUtil.replaceEntities(title)+"</h4>\n");
            sb.append(TextUtil.replaceEntities(title));
        }
        else
        {
            //sb.append("<h4>"+rb.getString("tableofcontents.title")+"</h4>\n");
            sb.append(rb.getString("tableofcontents.title"));
        }
        sb.append("</h4>\n");

        // should we use an ordered list?
        m_usingNumberedList = false;
        if (params.containsKey(PARAM_NUMBERED))
        {
            String numbered = params.get(PARAM_NUMBERED);
            if (numbered.equalsIgnoreCase("true"))
            {
                m_usingNumberedList = true;
            }
            else if (numbered.equalsIgnoreCase("yes"))
            {
                m_usingNumberedList = true;
            }
        }

        // if we are using a numbered list, get the rest of the parameters (if any) ...
        if (m_usingNumberedList)
        {
            int start = 0;
            String startStr = params.get(PARAM_START);
            if ((startStr != null) && (startStr.matches("^\\d+$")))
            {
                start = Integer.parseInt(startStr);
            }
            if (start < 0) start = 0;

            m_starting = start;
            m_level1Index = start - 1;
            if (m_level1Index < 0) m_level1Index = 0;
            m_level2Index = 0;
            m_level3Index = 0;
            m_prefix = params.get(PARAM_PREFIX);
            if (m_prefix == null) m_prefix = "";
            m_lastLevel = Heading.HEADING_LARGE;
        }

        try
        {
            String wikiText = engine.getPureText( page );
            boolean runFilters =
                "true".equals(engine.getVariableManager().getValue(context,WikiEngine.PROP_RUNFILTERS,"true"));
           
            try
            {
                if( runFilters )
                {
                    FilterManager fm = engine.getFilterManager();
                    wikiText = fm.doPreTranslateFiltering( context, wikiText );
                }
            }
            catch(Exception e)
            {
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.