jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r627255 [35/41] - in /incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src: ./ com/ com/ecyrd/ com/ecyrd/jspwiki/ com/ecyrd/jspwiki/action/ com/ecyrd/jspwiki/attachment/ com/ecyrd/jspwiki/auth/ com/ecyrd/jspwiki/auth/acl/ com/ecyrd/jspwiki...
Date Wed, 13 Feb 2008 05:54:24 GMT
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultIteratorTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultIteratorTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultIteratorTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultIteratorTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,145 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.SearchResult;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+
+/**
+ *  Iterates through Search result results.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>max = how many search results should be shown.
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+
+// FIXME: Shares MUCH too much in common with IteratorTag.  Must refactor.
+public class SearchResultIteratorTag
+    extends IteratorTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    private   int         m_maxItems;
+    private   int         m_count = 0;
+    private   int         m_start = 0;
+    
+    static Logger log = Logger.getLogger(SearchResultIteratorTag.class);
+    
+    public void release()
+    {
+        super.release();
+        m_maxItems = m_count = 0;
+    }
+
+    public void setMaxItems( int arg )
+    {
+        m_maxItems = arg;
+    }
+
+    public void setStart( int arg )
+    {
+        m_start = arg;
+    }
+    
+    public final int doStartTag()
+    {
+        //
+        //  Do lazy eval if the search results have not been set.
+        //
+        if( m_iterator == null )
+        {
+            Collection searchresults = (Collection) pageContext.getAttribute( "searchresults",
+                                                                              PageContext.REQUEST_SCOPE );
+            setList( searchresults );
+            
+            int skip = 0;
+            
+            //  Skip the first few ones...
+            m_iterator = searchresults.iterator();
+            while( m_iterator.hasNext() && (skip++ < m_start) ) m_iterator.next();
+        }
+
+        m_count       = 0;
+        m_wikiContext = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+
+        return nextResult();
+    }
+
+    private int nextResult()
+    {
+        if( m_iterator != null && m_iterator.hasNext() && m_count++ < m_maxItems )
+        {
+            SearchResult r = (SearchResult) m_iterator.next();
+            
+            // Create a wiki context for the result
+            WikiEngine engine = m_wikiContext.getEngine();
+            WikiContext context = engine.getWikiActionBeanFactory().newViewActionBean( r.getPage() );
+            
+            // Stash it in the page context
+            WikiActionBeanFactory.saveActionBean( pageContext, context );
+            pageContext.setAttribute( getId(), r );
+
+            return EVAL_BODY_BUFFERED;
+        }
+
+        return SKIP_BODY;
+    }
+
+    public int doAfterBody()
+    {
+        if( bodyContent != null )
+        {
+            try
+            {
+                JspWriter out = getPreviousOut();
+                out.print(bodyContent.getString());
+                bodyContent.clearBody();
+            }
+            catch( IOException e )
+            {
+                log.error("Unable to get inner tag text", e);
+                // FIXME: throw something?
+            }
+        }
+
+        return nextResult();
+    }
+
+    public int doEndTag()
+    {
+        m_iterator = null;
+
+        return super.doEndTag();
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsSizeTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsSizeTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsSizeTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsSizeTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,50 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2004 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.tags;
+
+import java.io.IOException;
+import java.util.Collection;
+import javax.servlet.jsp.PageContext;
+
+/**
+ *  Outputs the size of the search results list, if it contains any items.
+ *  Otherwise outputs an empty string.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class SearchResultsSizeTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        Collection list = (Collection)pageContext.getAttribute( "searchresults",
+                                                                PageContext.REQUEST_SCOPE );
+        if( list != null )
+        {
+            pageContext.getOut().print( list.size() );
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SearchResultsTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,60 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2004 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.tags;
+
+import java.io.IOException;
+import java.util.Collection;
+import javax.servlet.jsp.PageContext;
+
+/**
+ *  Includes the body content, if there are any search results.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class SearchResultsTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        Collection list = (Collection)pageContext.getAttribute( "searchresults",
+                                                                PageContext.REQUEST_SCOPE );
+        
+        if( list != null )
+        {
+            return EVAL_BODY_INCLUDE;
+        }
+
+        String message = (String)pageContext.getAttribute( "err",
+                                                           PageContext.REQUEST_SCOPE );
+            
+        if( message != null )
+        {
+            pageContext.getOut().print("<div class='error'>");
+            pageContext.getOut().print( message );
+            pageContext.getOut().println("</div>");
+        }
+        
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SetPaginationTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SetPaginationTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SetPaginationTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/SetPaginationTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,266 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2004 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.tags;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.jstl.fmt.LocaleSupport;
+
+import com.ecyrd.jspwiki.TextUtil;
+
+
+/**
+ *  Calculate pagination string. Used for page-info and search results
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI> start - start item of the page to be highlighted
+ *    <LI> total - total number of items
+ *    <LI> pagesize - total number of items per page
+ *    <LI> maxlinks - number of page links to be generated
+ *    <LI> fmtkey - pagination prefix of the i18n resource key
+ *  </UL>
+ *  <P>Following optional attributes can be parameterised with '%s' (item count)</P>
+ *  <UL>
+ *    <LI> href - href of each page link. (optional)
+ *    <LI> onclick - onclick of each page link. (optional)
+ *  </UL>
+ *
+ *  @author Dirk Frederickx
+ *  @since 2.5.109
+ */
+public class SetPaginationTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    private static final int ALLITEMS = -1;
+
+        private int m_start;
+    private int m_total;
+    private int m_pagesize;
+    private int m_maxlinks;
+    private String m_fmtkey;
+    private String m_href;
+    private String m_onclick;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_start = 0;
+        m_total = 0;
+        m_pagesize = 20;
+        m_maxlinks = 9;
+        m_fmtkey = null;
+        m_href = null;
+        m_onclick = null;
+    }
+
+    public void setStart(int arg)
+    {
+        m_start = arg;
+    }
+
+    public void setTotal(int arg)
+    {
+        m_total = arg;
+    }
+
+    public void setPagesize(int arg)
+    {
+        m_pagesize = arg;
+    }
+
+    public void setMaxlinks(int arg)
+    {
+        m_maxlinks = arg;
+        if( m_maxlinks % 2 == 0 ) m_maxlinks--; /* must be odd */
+    }
+
+    public void setFmtkey(String arg)
+    {
+        m_fmtkey = arg;
+    }
+
+    public void setHref(String arg)
+    {
+        m_href = arg;
+    }
+
+    public void setOnclick(String arg)
+    {
+        m_onclick = arg;
+    }
+
+
+    // 0 20 40 60
+    // 0 20 40 60 80 next last
+    // first previous 20 40 *60* 80 100 next last
+    // fist previous 40 60 80 100 120
+    public int doWikiStartTag()
+        throws IOException
+    {
+        if( m_total < m_pagesize ) return SKIP_BODY;
+
+        StringBuffer pagination = new StringBuffer();
+
+        if( m_start > m_total ) m_start = m_total;
+        if( m_start < ALLITEMS ) m_start = 0;
+
+        int maxs = m_pagesize * m_maxlinks;
+        int mids = m_pagesize * ( m_maxlinks / 2 );
+
+        pagination.append( "<div class='pagination'>");
+
+        pagination.append( LocaleSupport.getLocalizedMessage(pageContext, m_fmtkey )+ " " );
+
+        int cursor = 0;
+        int cursormax = m_total;
+
+        if( m_total > maxs )   //need to calculate real window ends
+        {
+          if( m_start > mids ) cursor = m_start - mids;
+          if( (cursor + maxs) > m_total )
+            cursor = ( ( 1 + m_total/m_pagesize ) * m_pagesize ) - maxs ;
+
+          cursormax = cursor + maxs;
+        }
+
+
+        if( ( m_start == ALLITEMS ) || (cursor > 0) )
+        {
+            appendLink ( pagination, 0, m_fmtkey + ".first" );
+        }
+
+
+        if( (m_start != ALLITEMS ) && (m_start-m_pagesize >= 0) )
+        {
+            appendLink( pagination, m_start-m_pagesize, m_fmtkey + ".previous" );
+        }
+
+        if( m_start != ALLITEMS )
+        {
+          while( cursor < cursormax )
+          {
+            if( cursor == m_start )
+            {
+              pagination.append( "<span class='cursor'>" );
+              pagination.append( 1 + cursor/m_pagesize );
+              pagination.append( "</span> " );
+            }
+            else
+            {
+              appendLink( pagination, cursor, 1+cursor/m_pagesize );
+            }
+            cursor += m_pagesize;
+          }
+        }
+
+
+        if( (m_start != ALLITEMS ) && (m_start + m_pagesize < m_total) )
+        {
+            appendLink( pagination, m_start+m_pagesize, m_fmtkey + ".next" );
+
+        if( (m_start == ALLITEMS ) || (cursormax < m_total) )
+          appendLink ( pagination, ( (m_total/m_pagesize) * m_pagesize ), m_fmtkey + ".last" );
+        }
+
+        if( m_start == ALLITEMS )
+        {
+          pagination.append( "<span class='cursor'>" );
+          pagination.append( LocaleSupport.getLocalizedMessage(pageContext, m_fmtkey + ".all" ) );
+          pagination.append( "</span>&nbsp;&nbsp;" );
+        }
+        else
+        {
+          appendLink ( pagination, ALLITEMS, m_fmtkey + ".all" );
+        }
+
+        //(Total items: " + m_total + ")" );
+        pagination.append( LocaleSupport.getLocalizedMessage(pageContext, m_fmtkey + ".total",
+                           new Object[]{ new Integer( m_total ) } ) );
+
+        pagination.append( "</div>" );
+
+
+        /* +++ processing done +++ */
+
+		String p = pagination.toString();
+
+        pageContext.getOut().println( p );
+
+        pageContext.setAttribute( "pagination", p ); /* and cache for later use in page context */
+
+        return SKIP_BODY;
+    }
+
+
+    /**
+     * Generate pagination links <a href='' title='' onclick=''>text</a>
+     * for pagination blocks starting a page.
+     * Uses m_href and m_onclick as attribute patterns
+     * '%s' in the patterns are replaced with page offset
+     *
+     * @param sb  : stringbuffer to write output to
+     * @param page : start of page block
+     * @param onclick : link text
+     *
+     **/
+    private void appendLink( StringBuffer sb, int page, String fmttextkey )
+    {
+		appendLink2( sb, page, LocaleSupport.getLocalizedMessage( pageContext, fmttextkey ) );
+    }
+    private void appendLink( StringBuffer sb, int page, int paginationblock )
+    {
+		appendLink2( sb, page, Integer.toString( paginationblock ) );
+    }
+    private void appendLink2( StringBuffer sb, int page, String text )
+    {
+        sb.append( "<a title=\"" );
+        if( page == ALLITEMS )
+        {
+            sb.append( LocaleSupport.getLocalizedMessage( pageContext, m_fmtkey + ".showall.title" ) );
+        }
+        else
+        {
+            sb.append( LocaleSupport.getLocalizedMessage( pageContext, m_fmtkey + ".show.title",
+                       new Object[]{ new Integer( page + 1 ), new Integer( page + m_pagesize ) } ) );
+        }
+        sb.append( "\" " );
+
+        if( m_href != null )
+        {
+            sb.append( "href=\"" );
+            sb.append( TextUtil.replaceString( m_href, "%s", Integer.toString( page ) ) );
+            sb.append( "\" " );
+        }
+
+        if( m_onclick != null )
+        {
+            sb.append( "onclick=\"" );
+            sb.append( TextUtil.replaceString( m_onclick, "%s", Integer.toString( page ) ) );
+            sb.append( "\" " );
+        }
+
+        sb.append( ">" );
+        sb.append( text );
+        sb.append( "</a> " );
+    }
+
+}
\ No newline at end of file

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,210 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2007 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.tags;
+
+import javax.servlet.jsp.*;
+import com.ecyrd.jspwiki.TextUtil;
+
+/**
+ *  Generates single tabbed page layout.
+ *  Works together with the tabbedSection javascript.  Note that if you do not
+ *  specify an url, the body contents of the tag are loaded by the tag itself.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>id - ID for this tab. (mandatory)
+ *    <LI>title - Title of this tab. (mandatory)
+ *    <LI>accesskey - Single char usable as quick accesskey (alt- or ctrl-) (optional)
+ *    <li>url - If you <i>don't</i> want to create a Javascript-enabled tag, you can use this
+ *              to make the tab look just the usual tag, but instead, it will actually link
+ *              to that page.  This can be useful in certain cases where you have something
+ *              that you want to look like a part of a tag, but for example, due to it being
+ *              very big in size, don't want to include it as a part of the page content
+ *              every time.
+ *  </UL>
+ *
+ *  @author Dirk Frederickx
+ *  @since v2.3.63
+ */
+
+public class TabTag extends WikiTagBase
+{
+    private static final long serialVersionUID = -8534125226484616489L;
+    private String m_accesskey;
+    private String m_tabTitle;
+    private String m_url;
+
+    /**
+     * {@inheritDoc}
+     */
+    public void doFinally()
+    {
+        super.doFinally();
+
+        m_accesskey = null;
+        m_tabTitle  = null;
+        m_url       = null;
+    }
+
+    /**
+     * Sets the tab title.
+     * @param aTabTitle the tab title
+     */
+    public void setTitle(String aTabTitle)
+    {
+        m_tabTitle = TextUtil.replaceEntities( aTabTitle );
+    }
+
+    /**
+     * Sets the tab access key.
+     * @param anAccesskey the access key
+     */
+    public void setAccesskey(String anAccesskey)
+    {
+        m_accesskey = TextUtil.replaceEntities( anAccesskey ); //take only the first char
+    }
+
+    /**
+     * Sets the tab URL.
+     * @param url the URL
+     */
+    public void setUrl( String url )
+    {
+        m_url = TextUtil.replaceEntities( url );
+    }
+
+    // insert <u> ..accesskey.. </u> in title
+    private boolean handleAccesskey()
+    {
+        if( (m_tabTitle == null) || (m_accesskey == null) ) return false;
+
+        int pos = m_tabTitle.toLowerCase().indexOf( m_accesskey.toLowerCase() );
+        if( pos > -1 )
+        {
+            m_tabTitle = m_tabTitle.substring( 0, pos ) + "<span class='accesskey'>"
+                       + m_tabTitle.charAt( pos ) + "</span>" + m_tabTitle.substring( pos+1 );
+        }
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int doWikiStartTag() throws JspTagException
+    {
+        TabbedSectionTag parent=getParentTag(TabbedSectionTag.class );
+
+        //
+        //  Sanity checks
+        //
+        if( getId() == null )
+        {
+            throw new JspTagException("Tab Tag without \"id\" attribute");
+        }
+        if( m_tabTitle == null )
+        {
+            throw new JspTagException("Tab Tag without \"tabTitle\" attribute");
+        }
+        if( parent == null )
+        {
+            throw new JspTagException("Tab Tag without parent \"TabbedSection\" Tag");
+        }
+
+        if( !parent.isStateGenerateTabBody() ) return SKIP_BODY;
+
+        StringBuffer sb = new StringBuffer(32);
+
+        sb.append( "<div id=\""+ getId() + "\"" );
+
+        if( !parent.validateDefaultTab( getId()) )
+        {
+            sb.append( " class=\"hidetab\"" );
+        }
+        sb.append( " >\n" );
+
+        try
+        {
+            pageContext.getOut().write( sb.toString() );
+        }
+        catch( java.io.IOException e )
+        {
+            throw new JspTagException( "IO Error: " + e.getMessage() );
+        }
+
+        return EVAL_BODY_INCLUDE;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int doEndTag() throws javax.servlet.jsp.JspTagException
+    {
+        TabbedSectionTag parent=getParentTag( TabbedSectionTag.class );
+
+        StringBuffer sb = new StringBuffer();
+
+        if( parent.isStateFindDefaultTab() )
+        {
+            //inform the parent of each tab
+            parent.validateDefaultTab( getId() );
+        }
+        else if( parent.isStateGenerateTabBody() )
+        {
+            sb.append( "</div>\n" );
+        }
+        else if( parent.isStateGenerateTabMenu() )
+        {
+            sb.append( "<a" );
+
+            if( parent.validateDefaultTab( getId() ) )
+            {
+                sb.append( " class=\"activetab\"" );
+            }
+
+            sb.append( " id=\"menu-" + getId() + "\"" );
+
+            if( m_url != null )
+            {
+                sb.append( " href='"+m_url+"'" );
+            }
+
+            if( handleAccesskey() )
+            {
+                sb.append( " accesskey=\"" + m_accesskey + "\"" );
+            }
+
+            sb.append( " >" );
+            sb.append( m_tabTitle );
+            sb.append( "</a>" );
+        }
+
+        try
+        {
+            pageContext.getOut().write( sb.toString() );
+        }
+        catch( java.io.IOException e )
+        {
+            throw new JspTagException( "IO Error: " + e.getMessage() );
+        }
+
+        return EVAL_PAGE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabbedSectionTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabbedSectionTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabbedSectionTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TabbedSectionTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,164 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2007 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.tags;
+
+import javax.servlet.jsp.*;
+import javax.servlet.jsp.tagext.*;
+
+/**
+ *  Generates tabbed page section: container for the Tab tag.
+ *  Works together with the tabbedSection javacript.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>defaultTab - Page name to refer to.  Default is the current page.
+ *  </UL>
+ *
+ *  @author Dirk Frederickx
+ *  @since v2.3.63
+ */
+
+public class TabbedSectionTag extends BodyTagSupport
+{
+    private static final long serialVersionUID = 1702437933960026481L;
+    private String       m_defaultTabId;
+    private String       m_firstTabId;
+    private boolean      m_defaultTabFound = false;
+
+    private StringBuffer m_buffer = new StringBuffer(BUFFER_SIZE);
+
+    private static final int FIND_DEFAULT_TAB = 0;
+    private static final int GENERATE_TABMENU = 1;
+    private static final int GENERATE_TABBODY = 2;
+
+    private static final int BUFFER_SIZE      = 1024;
+
+    private              int m_state            = FIND_DEFAULT_TAB;
+
+    public void release()
+    {
+        super.release();
+        m_defaultTabId = m_firstTabId = null;
+        m_defaultTabFound = false;
+        m_buffer = new StringBuffer();
+        m_state = FIND_DEFAULT_TAB;
+    }
+
+    public void setDefaultTab(String anDefaultTabId)
+    {
+        m_defaultTabId = anDefaultTabId;
+    }
+
+    public boolean validateDefaultTab( String aTabId )
+    {
+        if( m_firstTabId == null ) m_firstTabId = aTabId;
+        if( aTabId.equals( m_defaultTabId ) ) m_defaultTabFound = true;
+
+        return aTabId.equals( m_defaultTabId );
+    }
+
+    public int doStartTag() throws JspTagException
+    {
+        return EVAL_BODY_BUFFERED; /* always look inside */
+    }
+
+    public boolean isStateFindDefaultTab()
+    {
+        return m_state == FIND_DEFAULT_TAB;
+    }
+
+    public boolean isStateGenerateTabMenu()
+    {
+        return m_state == GENERATE_TABMENU;
+    }
+
+    public boolean isStateGenerateTabBody()
+    {
+        return m_state == GENERATE_TABBODY;
+    }
+
+
+    /* The tabbed section iterates 3 time through the underlying Tab tags
+     * - first it identifies the default tab (displayed by default)
+     * - second it generates the tabmenu markup (displays all tab-titles)
+     * - finally it generates the content of each tab.
+     */
+    public int doAfterBody() throws JspTagException
+    {
+        if( isStateFindDefaultTab() )
+        {
+            if( !m_defaultTabFound )
+            {
+                m_defaultTabId = m_firstTabId;
+            }
+            m_state = GENERATE_TABMENU;
+            return EVAL_BODY_BUFFERED;
+        }
+        else if( isStateGenerateTabMenu() )
+        {
+            if( bodyContent != null )
+            {
+                m_buffer.append( "<div class=\"tabmenu\">" );
+                m_buffer.append( bodyContent.getString() );
+                bodyContent.clearBody();
+                m_buffer.append( "</div>\n" );
+            }
+            m_state = GENERATE_TABBODY;
+            return EVAL_BODY_BUFFERED;
+        }
+        else if( isStateGenerateTabBody() )
+        {
+            if( bodyContent != null )
+            {
+                m_buffer.append( "<div class=\"tabs\">" );
+                m_buffer.append( bodyContent.getString() );
+                bodyContent.clearBody();
+                m_buffer.append( "<div style=\"clear:both;\" ></div>\n</div>\n" );
+            }
+            return SKIP_BODY;
+        }
+        return SKIP_BODY;
+    }
+
+    public int doEndTag() throws JspTagException
+    {
+        try
+        {
+            if( m_buffer.length() > 0 )
+            {
+                getPreviousOut().write( m_buffer.toString() );
+            }
+        }
+        catch(java.io.IOException e)
+        {
+            throw new JspTagException( "IO Error: " + e.getMessage() );
+        }
+
+        //now reset some stuff for the next run -- ugh.
+        m_buffer    = new StringBuffer(BUFFER_SIZE);
+        m_state = FIND_DEFAULT_TAB;
+        m_defaultTabId    = null;
+        m_firstTabId      = null;
+        m_defaultTabFound = false;
+        return EVAL_PAGE;
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TemplateDirTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TemplateDirTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TemplateDirTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TemplateDirTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,45 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2003 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.tags;
+
+import java.io.IOException;
+
+/**
+ *  Returns the currently used template.  For example
+ *  "default"
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.1.15.
+ */
+public class TemplateDirTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        String template = m_actionBean.getTemplate();
+
+        pageContext.getOut().print( template );
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TranslateTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TranslateTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TranslateTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/TranslateTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,71 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2004 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.tags;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+
+import org.apache.log4j.Logger;
+
+/**
+ *  Converts the body text into HTML content.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class TranslateTag
+    extends BodyTagSupport
+{
+    private static final long serialVersionUID = 0L;
+    
+    static    Logger    log = Logger.getLogger( TranslateTag.class );
+
+    public final int doAfterBody()
+        throws JspException
+    {
+        try
+        {
+            WikiContext context = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+            BodyContent bc = getBodyContent();
+            String wikiText = bc.getString();
+            bc.clearBody();
+
+            if( wikiText != null )
+            {
+                wikiText = wikiText.trim();
+            
+                String result = context.getEngine().textToHTML( context, wikiText );
+
+                getPreviousOut().write( result );
+            }
+        }
+        catch( Exception e )
+        {
+            log.error( "Tag failed", e );
+            throw new JspException( "Tag failed, check logs: "+e.getMessage() );
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UploadLinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UploadLinkTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UploadLinkTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UploadLinkTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,79 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+import javax.servlet.jsp.JspWriter;
+
+import com.ecyrd.jspwiki.action.UploadActionBean;
+
+/**
+ *  Writes a link to the upload page.  Body of the link becomes the actual text.
+ *  The link is written regardless to whether the page exists or not.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *    <LI>format - either "anchor" or "url" to output either an <A>... or just the HREF part of one.
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class UploadLinkTag
+    extends WikiLinkTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        String     pageName = m_pageName;
+
+        if( m_pageName == null )
+        {
+            if( m_page != null )
+            {
+                pageName = m_page.getName();
+            }
+            else
+            {
+                return SKIP_BODY;
+            }
+        }
+
+        JspWriter out = pageContext.getOut();
+
+        String url = m_actionBean.getContext().getURL( UploadActionBean.class, pageName );
+
+        switch( m_format )
+        {
+          case ANCHOR:
+            out.print("<a target=\"_new\" class=\"uploadlink\" href=\""+url+"\">");
+            break;
+          case URL:
+            out.print( url );
+            break;
+        }
+
+        return EVAL_BODY_INCLUDE;
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserCheckTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserCheckTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserCheckTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserCheckTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,208 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+
+import com.ecyrd.jspwiki.WikiSession;
+import com.ecyrd.jspwiki.auth.AuthenticationManager;
+
+/**
+ *  Includes the content if an user check validates.  This has
+ *  been considerably enhanced for 2.2.  The possibilities for the "status"-argument are:
+ *
+ * <ul>
+ * <li>"anonymous"     - the body of the tag is included 
+ *                       if the user is completely unknown (no cookie, no password)</li>
+ * <li>"asserted"      - the body of the tag is included 
+ *                       if the user has either been named by a cookie, but
+ *                       not been authenticated.</li>
+ * <li>"authenticated" - the body of the tag is included 
+ *                       if the user is validated either through the container,
+ *                       or by our own authentication.</li>
+ * <li>"assertionsAllowed"
+ *                     - the body of the tag is included 
+ *                       if wiki allows identities to be asserted using cookies.</li>
+ * <li>"assertionsNotAllowed"
+ *                     - the body of the tag is included 
+ *                       if wiki does <i>not</i> allow identities to 
+ *                       be asserted using cookies.</li>
+ * <li>"containerAuth" - the body of the tag is included 
+ *                       if the user is validated through the container.</li>
+ * <li>"customAuth"    - the body of the tag is included 
+ *                       if the user is validated through our own authentication.</li>
+ * <li>"known"         - if the user is not anonymous</li>                      
+ * <li>"notAuthenticated"
+ *                     - the body of the tag is included 
+ *                       if the user is not yet authenticated.</li>
+ * </ul>
+ *
+ *  If the old "exists" -argument is used, it corresponds as follows:
+ *  <p>
+ *  <tt>exists="true" ==> status="known"<br>
+ *  <tt>exists="false" ==> status="unknown"<br>
+ *
+ *  It is NOT a good idea to use BOTH of the arguments.
+ *
+ *  @author Janne Jalkanen
+ *  @author Erik Bunn
+ *  @author Andrew Jaquith
+ *  @since 2.0
+ */
+public class UserCheckTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 3256438110127863858L;
+    private static final String ASSERTED = "asserted";
+    private static final String AUTHENTICATED = "authenticated";
+    private static final String ANONYMOUS = "anonymous";
+    private static final String ASSERTIONS_ALLOWED = "assertionsallowed";
+    private static final String ASSERTIONS_NOT_ALLOWED = "assertionsnotallowed";
+    private static final String CONTAINER_AUTH = "containerauth";
+    private static final String CUSTOM_AUTH = "customauth";
+    private static final String KNOWN = "known";
+    private static final String NOT_AUTHENTICATED = "notauthenticated";
+
+    private String m_status;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_status = null;
+    }
+
+    public String getStatus()
+    {
+        return( m_status );
+    }
+
+    public void setStatus( String arg )
+    {
+        m_status = arg.toLowerCase();
+    }
+
+
+    /**
+     *  Sets the "exists" attribute, which is converted on-the-fly into
+     *  an equivalent "status" -attribute.  This is only for backwards compatibility.
+     *
+     *  @deprecated
+     */
+    public void setExists( String arg )
+    {
+        if("true".equals(arg))
+        {
+            m_status = AUTHENTICATED;
+        }
+        else
+        {
+            m_status = ANONYMOUS;
+        }
+    }
+
+
+    /**
+     * @see com.ecyrd.jspwiki.tags.WikiTagBase#doWikiStartTag()
+     */
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiSession session = m_actionBean.getWikiSession();
+        String status = session.getStatus();
+        AuthenticationManager mgr = m_actionBean.getEngine().getAuthenticationManager();
+        boolean containerAuth = mgr.isContainerAuthenticated();
+        boolean cookieAssertions = AuthenticationManager.allowsCookieAssertions();
+
+        if( m_status != null )
+        {
+            if ( ANONYMOUS.equals( m_status )) 
+            {
+                if (status.equals(WikiSession.ANONYMOUS))
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+            }
+            else if( AUTHENTICATED.equals( m_status ))
+            { 
+                if (status.equals(WikiSession.AUTHENTICATED)) 
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+            }
+            else if( ASSERTED.equals( m_status )) 
+            { 
+                if (status.equals(WikiSession.ASSERTED)) 
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+            }
+            else if( ASSERTIONS_ALLOWED.equals( m_status ))
+            { 
+                if ( cookieAssertions )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+                return SKIP_BODY;
+            }
+            else if( ASSERTIONS_NOT_ALLOWED.equals( m_status ))
+            { 
+                if ( !cookieAssertions )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+                return SKIP_BODY;
+            }
+            else if( CONTAINER_AUTH.equals( m_status )) 
+            { 
+                if ( containerAuth )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+                return SKIP_BODY;
+            }
+            else if( CUSTOM_AUTH.equals( m_status )) 
+            { 
+                if ( !containerAuth )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+                return SKIP_BODY;
+            }
+            else if( KNOWN.equals( m_status )) 
+            { 
+                if ( !session.isAnonymous() )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+                return SKIP_BODY;
+            }
+            else if( NOT_AUTHENTICATED.equals( m_status ))
+            { 
+                if (!status.equals(WikiSession.AUTHENTICATED)) 
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+            }
+        }
+
+        return SKIP_BODY;
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserNameTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserNameTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserNameTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserNameTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,56 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+import java.security.Principal;
+import javax.servlet.http.HttpServletRequest;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiSession;
+import com.ecyrd.jspwiki.TextUtil;
+
+/**
+ *  Returns the current user name, or empty, if the user has not been
+ *  validated.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class UserNameTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine = this.m_actionBean.getEngine();
+        WikiSession wikiSession = WikiSession.getWikiSession( engine, (HttpServletRequest)pageContext.getRequest() );
+        Principal user = wikiSession.getUserPrincipal();
+
+        if( user != null )
+        {
+            pageContext.getOut().print( TextUtil.replaceEntities( user.getName() ) );
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserProfileTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserProfileTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserProfileTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/UserProfileTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,298 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.ecyrd.jspwiki.TextUtil;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiSession;
+import com.ecyrd.jspwiki.action.WikiActionBean;
+import com.ecyrd.jspwiki.auth.AuthenticationManager;
+import com.ecyrd.jspwiki.auth.GroupPrincipal;
+import com.ecyrd.jspwiki.auth.UserManager;
+import com.ecyrd.jspwiki.auth.WikiSecurityException;
+import com.ecyrd.jspwiki.auth.authorize.Role;
+import com.ecyrd.jspwiki.auth.user.UserProfile;
+import com.ecyrd.jspwiki.i18n.InternationalizationManager;
+
+/**
+ * <p>
+ * Returns user profile attributes, or empty strings if the user has not been
+ * validated. This tag has a single attribute, "property."
+ * The <code>property</code> attribute may contain one of the following
+ * case-insensitive values:
+ * </p>
+ * <ul>
+ * <li><code>created</code> - creation date</li>
+ * <li><code>email</code> - user's e-mail address</li>
+ * <li><code>fullname</code> - user's full name</li>
+ * <li><code>groups</code> - a sorted list of the groups a user belongs to</li>
+ * <li><code>loginname</code> - user's login name. If the current user does not have
+ * a profile, the user's login principal (such as one provided by a container
+ * login module, user cookie, or anonyous IP address), will supply the login
+ * name property</li>
+ * <li><code>roles</code> - a sorted list of the roles a user possesses</li>
+ * <li><code>wikiname</code> - user's wiki name</li>
+ * <li><code>modified</code> - last modification date</li>
+ * <li><code>exists</code> - evaluates the body of the tag if user's profile exists
+ * in the user database
+ * <li><code>new</code> - evaluates the body of the tag if user's profile does not
+ * exist in the user database
+ * <li><code>canChangeLoginName</code> - always true if custom auth used; also true for container auth
+ * and current UserDatabase.isSharedWithContainer() is true.</li>
+ * <li><code>canChangePassword</code> - always true if custom auth used; also true for container auth
+ * and current UserDatabase.isSharedWithContainer() is true.</li>
+ * </ul>
+ * <p>In addition, the values <code>exists</code>, <code>new</code>, <code>canChangeLoginName</code>
+ * and <code>canChangeLoginName</code> can also be prefixed with <code>!</code> to indicate the
+ * negative condition (for example, <code>!exists</code>).</p>
+ * @author Andrew Jaquith
+ * @since 2.3
+ */
+public class UserProfileTag extends WikiTagBase
+{
+    private static final long serialVersionUID = 3258410625431582003L;
+
+    public  static final String BLANK = "(not set)";
+
+    private static final String CREATED   = "created";
+
+    private static final String EMAIL     = "email";
+
+    private static final String EXISTS    = "exists";
+
+    private static final String NOT_EXISTS= "!exists";
+
+    private static final String FULLNAME  = "fullname";
+
+    private static final String GROUPS    = "groups";
+
+    private static final String LOGINNAME = "loginname";
+
+    private static final String MODIFIED  = "modified";
+
+    private static final String NEW       = "new";
+
+    private static final String NOT_NEW   = "!new";
+
+    private static final String ROLES     = "roles";
+
+    private static final String WIKINAME  = "wikiname";
+
+    private static final String CHANGE_LOGIN_NAME     = "canchangeloginname";
+
+    private static final String NOT_CHANGE_LOGIN_NAME = "!canchangeloginname";
+
+    private static final String CHANGE_PASSWORD       = "canchangepassword";
+
+    private static final String NOT_CHANGE_PASSWORD   = "!canchangepassword";
+
+    private String             m_prop;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_prop = null;
+    }
+
+    public final int doWikiStartTag() throws IOException, WikiSecurityException
+    {
+        UserManager manager = m_actionBean.getEngine().getUserManager();
+        UserProfile profile = manager.getUserProfile( m_actionBean.getWikiSession() );
+        String result = null;
+
+        if ( EXISTS.equals( m_prop ) || NOT_NEW.equals( m_prop ) )
+        {
+            return profile.isNew() ? SKIP_BODY : EVAL_BODY_INCLUDE;
+        }
+        else if ( NEW.equals( m_prop ) || NOT_EXISTS.equals( m_prop ) )
+        {
+            return profile.isNew() ? EVAL_BODY_INCLUDE : SKIP_BODY;
+        }
+
+        else if ( CREATED.equals( m_prop ) && profile.getCreated() != null )
+        {
+            result = profile.getCreated().toString();
+        }
+        else if ( EMAIL.equals( m_prop ) )
+        {
+            result = profile.getEmail();
+        }
+        else if ( FULLNAME.equals( m_prop ) )
+        {
+            result = profile.getFullname();
+        }
+        else if ( GROUPS.equals( m_prop ) )
+        {
+            result = printGroups( m_actionBean );
+        }
+        else if ( LOGINNAME.equals( m_prop ) )
+        {
+            result = profile.getLoginName();
+        }
+        else if ( MODIFIED.equals( m_prop ) && profile.getLastModified() != null )
+        {
+            result = profile.getLastModified().toString();
+        }
+        else if ( ROLES.equals( m_prop ) )
+        {
+            result = printRoles( m_actionBean );
+        }
+        else if ( WIKINAME.equals( m_prop ) )
+        {
+            result = profile.getWikiName();
+
+            if( result == null )
+            {
+                //
+                //  Default back to the declared user name
+                //
+                WikiEngine engine = this.m_actionBean.getEngine();
+                WikiSession wikiSession = WikiSession.getWikiSession( engine, (HttpServletRequest)pageContext.getRequest() );
+                Principal user = wikiSession.getUserPrincipal();
+
+                if( user != null )
+                {
+                    result = user.getName();
+                }
+            }
+        }
+        else if ( CHANGE_PASSWORD.equals( m_prop ) || CHANGE_LOGIN_NAME.equals( m_prop ) )
+        {
+            AuthenticationManager authMgr = m_actionBean.getEngine().getAuthenticationManager();
+            if ( !authMgr.isContainerAuthenticated() ||
+                 manager.getUserDatabase().isSharedWithContainer() )
+            {
+                return EVAL_BODY_INCLUDE;
+            }
+        }
+        else if ( NOT_CHANGE_PASSWORD.equals( m_prop ) || NOT_CHANGE_LOGIN_NAME.equals( m_prop ) )
+        {
+            AuthenticationManager authMgr = m_actionBean.getEngine().getAuthenticationManager();
+            if ( authMgr.isContainerAuthenticated() &&
+                 !manager.getUserDatabase().isSharedWithContainer() )
+            {
+                return EVAL_BODY_INCLUDE;
+            }
+        }
+
+        if ( result != null )
+        {
+            pageContext.getOut().print( TextUtil.replaceEntities(result) );
+        }
+        return SKIP_BODY;
+    }
+
+    public void setProperty( String property )
+    {
+        m_prop = property.toLowerCase().trim();
+    }
+
+    /**
+     * Returns a sorted list of the {@link com.ecyrd.jspwiki.auth.authorize.Group} objects a user possesses
+     * in his or her WikiSession. The result is computed by consulting
+     * {@link com.ecyrd.jspwiki.WikiSession#getRoles()}
+     * and extracting those that are of type Group.
+     * @return the list of groups, sorted by name
+     */
+    public static String printGroups( WikiActionBean actionBean )
+    {
+        Principal[] roles = actionBean.getWikiSession().getRoles();
+        List<String> tempRoles = new ArrayList<String>();
+        ResourceBundle rb = actionBean.getBundle(InternationalizationManager.CORE_BUNDLE);
+        
+        for ( int i = 0; i < roles.length; i++ )
+        {
+            if( roles[i] instanceof GroupPrincipal )
+            {
+                tempRoles.add( roles[i].getName() );
+            }
+        }
+        if ( tempRoles.size() == 0 )
+        {
+            return rb.getString("userprofile.nogroups");
+        }
+
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < tempRoles.size(); i++ )
+        {
+            String name = tempRoles.get( i );
+
+            sb.append( name );
+            if ( i < ( tempRoles.size() - 1 ) )
+            {
+                sb.append(',');
+                sb.append(' ');
+            }
+
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Returns a sorted list of the {@link com.ecyrd.jspwiki.auth.authorize.Role} objects a user possesses
+     * in his or her WikiSession. The result is computed by consulting
+     * {@link com.ecyrd.jspwiki.WikiSession#getRoles()}
+     * and extracting those that are of type Role.
+     * @return the list of roles, sorted by name
+     */
+    public static String printRoles( WikiActionBean actionBean )
+    {
+        Principal[] roles = actionBean.getWikiSession().getRoles();
+        List<String> tempRoles = new ArrayList<String>();
+        ResourceBundle rb = actionBean.getBundle(InternationalizationManager.CORE_BUNDLE);
+        
+        for ( int i = 0; i < roles.length; i++ )
+        {
+            if ( roles[i] instanceof Role )
+            {
+                tempRoles.add( roles[i].getName() );
+            }
+        }
+        if ( tempRoles.size() == 0 )
+        {
+            return rb.getString("userprofile.noroles");
+        }
+
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < tempRoles.size(); i++ )
+        {
+            String name = tempRoles.get( i );
+            {
+                sb.append( name );
+                if ( i < ( tempRoles.size() - 1 ) ) 
+                {
+                    sb.append(',');
+                    sb.append(' ');
+                }
+            }
+
+        }
+        return sb.toString();
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/VariableTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/VariableTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/VariableTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/VariableTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,111 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.JspException;
+
+import com.ecyrd.jspwiki.TextUtil;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.NoSuchVariableException;
+
+/**
+ *  Returns the value of an Wiki variable.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>var - Name of the variable.  Required.
+ *    <LI>default - Revert to this value, if the value of "var" is null.
+ *                  If left out, this tag will produce a concise error message
+ *                  if the named variable is not found. Set to empty (default="")
+ *                  to hide the message.
+ *  </UL>
+ *
+ *  <P>A default value implies <I>failmode='quiet'</I>.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class VariableTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+
+    private String m_var      = null;
+    private String m_default  = null;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_var = m_default = null;
+    }
+
+    public String getVar()
+    {
+        return m_var;
+    }
+
+    public void setVar( String arg )
+    {
+        m_var = arg;
+    }
+
+    public void setDefault( String arg )
+    {
+        m_default = arg;
+    }
+
+    public final int doWikiStartTag()
+        throws JspException,
+               IOException
+    {
+        WikiEngine engine   = m_actionBean.getEngine();
+        JspWriter out = pageContext.getOut();
+        String msg = null;
+        String value = null;
+
+        try
+        {
+            value = engine.getVariableManager().getValue( m_actionBean,
+                                                          getVar() );
+        }
+        catch( NoSuchVariableException e )
+        {
+            msg = "No such variable: "+e.getMessage();
+        }
+        catch( IllegalArgumentException e )
+        {
+            msg = "Incorrect variable name: "+e.getMessage();
+        }
+
+        if( value == null )
+        {
+            value = m_default;
+        }
+
+        if( value == null )
+        {
+            value = msg;
+        }
+        out.write( TextUtil.replaceEntities(value) );
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiBodyTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiBodyTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiBodyTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiBodyTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,85 @@
+/* 
+     JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2005 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.tags;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.TryCatchFinally;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+
+/**
+ *  This is a class that provides the same services as the WikiTagBase, but this time it
+ *   works for the BodyTagSupport base class.
+ * 
+ *  @author jalkanen
+ *
+ */
+public abstract class WikiBodyTag extends BodyTagSupport
+    implements TryCatchFinally
+{
+    protected WikiContext m_wikiContext;
+    static    Logger    log = Logger.getLogger( WikiBodyTag.class );
+
+    public int doStartTag() throws JspException
+    {
+        try
+        {
+            m_wikiContext = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+
+            if( m_wikiContext == null )
+            {
+                throw new JspException("WikiContext may not be NULL - serious internal problem!");
+            }
+
+            return doWikiStartTag();
+        }
+        catch( Exception e )
+        {
+            log.error( "Tag failed", e );
+            throw new JspException( "Tag failed, check logs: "+e.getMessage() );
+        }
+    }
+
+    /**
+     * A local stub for doing tags.  This is just called after the local variables
+     * have been set.
+     * @return As doStartTag()
+     * @throws JspException
+     * @throws IOException
+     */
+    public abstract int doWikiStartTag() throws JspException, IOException;
+
+    public void doCatch(Throwable arg0) throws Throwable
+    {
+    }
+
+    public void doFinally()
+    {
+        m_wikiContext = null;
+    }  
+    
+    
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiLinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiLinkTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiLinkTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiLinkTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,108 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import java.io.IOException;
+
+/**
+ *  Root class for different internal wiki links.  Cannot be used directly,
+ *  but provides basic stuff for other classes.
+ *  <P>
+ *  Extend from this class if you need the following attributes.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *    <li>format - Either "url" or "anchor".  If "url", will provide
+ *  just the URL for the link.  If "anchor", will output proper HTML
+ *  (&lt;a&gt; href="...).
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public abstract class WikiLinkTag
+    extends WikiTagBase
+{
+    public static final int   ANCHOR = 0;
+    public static final int   URL    = 1;
+
+    protected String m_pageName;
+    protected int    m_format = ANCHOR;
+    protected String m_template;
+
+    
+    public void initTag() 
+    {
+        super.initTag();
+        m_pageName = m_template = null;
+        m_format = ANCHOR;
+    }
+    
+    public void setPage( String page )
+    {
+        m_pageName = page;
+    }
+
+    public String getPage()
+    {
+        return m_pageName;
+    }
+
+
+    public String getTemplate()
+    {
+        return m_template;
+    }
+
+    public void setTemplate( String arg )
+    {
+        m_template = arg;
+    }
+
+    public void setFormat( String mode )
+    {
+        if( "url".equalsIgnoreCase(mode) )
+        {
+            m_format = URL;
+        }
+        else
+        {
+            m_format = ANCHOR;
+        }
+    }
+
+    public int doEndTag()
+    {
+        try
+        {
+            if( m_format == ANCHOR )
+            {
+                pageContext.getOut().print("</a>");
+            }
+        }
+        catch( IOException e )
+        {
+            // FIXME: Should do something?
+        }
+
+        return EVAL_PAGE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiTagBase.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiTagBase.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiTagBase.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/WikiTagBase.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,187 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.tags;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.TryCatchFinally;
+
+import net.sourceforge.stripes.tag.StripesTagSupport;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.action.WikiActionBean;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+import com.ecyrd.jspwiki.ui.WikiInterceptor;
+
+/**
+ * <p>
+ *  Base class for JSPWiki tags.  You do not necessarily have
+ *  to derive from this class, since this does some initialization.
+ * </p>
+ *  <p>
+ *  This tag is only useful if you're having an "empty" tag, with
+ *  no body content.
+ * </p>
+ *  <p>The order of init method processing for subclasses of WikiTagBase is as follows:</p>
+ *  <ul>
+ *  <li>{@link #initTag()}</li>
+ *  <li>{@link #doStartTag()}</li>
+ *  <li>{@link #doWikiStartTag()} - implemented by subclasses</li>
+ *  </ul>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public abstract class WikiTagBase
+    extends StripesTagSupport
+    implements TryCatchFinally
+{
+    /**
+     *  The name of the request attribute used to store ActionBeans (WikiContexts).
+     *  @deprecated Use {@link WikiInterceptor#ATTR_ACTIONBEAN} instead
+     */
+    public static final String ATTR_CONTEXT = WikiInterceptor.ATTR_ACTIONBEAN;
+
+    static    Logger    log = Logger.getLogger( WikiTagBase.class );
+
+    protected WikiActionBean m_actionBean;
+    
+    private String m_id;
+    
+    /**
+     * If the ActionBean is a WikiContext and the page is non-null, this value will be set automatically by {@link #doStartTag()}.
+     */
+    protected WikiPage m_page;
+    
+    /**
+     *   This method calls the parent setPageContext() but it also
+     *   provides a way for a tag to initialize itself before
+     *   any of the setXXX() methods are called.
+     */
+    public void setPageContext(PageContext arg0)
+    {
+        super.setPageContext(arg0);
+        
+        initTag();
+    }
+
+    /**
+     *  This method is called when the tag is encountered within a new request,
+     *  but before the setXXX() methods are called. 
+     *  The default implementation does nothing.
+     *  @since 2.3.92
+     */
+    public void initTag()
+    {
+        m_actionBean = null;
+        m_page = null;
+        return;
+    }
+    
+    /**
+     * Initializes the tag, and sets an internal reference to the current WikiActionBean
+     * by delegating to
+     * {@link com.ecyrd.jspwiki.action.WikiInterceptor#findActionBean( PageContext )}.
+     * (That method retrieves the WikiActionBean from page scope.).
+     * If the WikiActionBean is a WikiContext, a reference to the current wiki page will be
+     * set also. Both of these available as protected fields {@link #m_actionBean} and
+     * {@link #m_page}, respectively. It is considered an error condition if the 
+     * WikiActionBean cannot be retrieved from the PageContext.
+     * It's also an error condition if the WikiActionBean is actually a WikiContext, and it
+     * returns a <code>null</code> WikiPage.
+     */
+    public int doStartTag()
+        throws JspException
+    {
+        try
+        {
+            // Retrieve the ActionBean injected by WikiInterceptor
+            m_actionBean = WikiActionBeanFactory.findActionBean( pageContext );
+            
+            // It's really bad news if the WikiActionBean wasn't injected (or saved as a variable!)
+            if ( m_actionBean == null )
+            {
+                throw new JspException( "Can't find WikiActionBean in page or request context. Make sure JSP saves it as a variable." );
+            }
+
+            // If this is a WikiContext-style ActionBean, get the page (WikiInterceptor should have set it)
+            m_page = null;
+            if ( m_actionBean instanceof WikiContext )
+            {
+                m_page = ((WikiContext)m_actionBean).getPage();
+                if ( m_page == null )
+                {
+                    throw new JspException( "WikiContext has a null WikiPage. This should not happen, and probably indicates a bug in JSPWiki's core classes!" );
+                }
+            }
+
+            return doWikiStartTag();
+        }
+        catch( Exception e )
+        {
+            log.error( "Tag failed", e );
+            throw new JspException( "Tag failed, check logs: "+e.getMessage() );
+        }
+    }
+
+    /**
+     *  This method is allowed to do pretty much whatever he wants.
+     *  We then catch all mistakes.
+     */
+    public abstract int doWikiStartTag() throws Exception;
+
+    public int doEndTag()
+        throws JspException
+    {
+        return EVAL_PAGE;
+    }
+    
+    public int doAfterBody() throws JspException {
+        return SKIP_BODY;
+    }
+    
+    public String getId()
+    {
+        return m_id;
+    }
+
+    public void doCatch(Throwable arg0) throws Throwable
+    {
+    }
+
+    public void doFinally()
+    {
+        m_actionBean = null;
+        m_id = null;
+        m_page = null;
+    }
+
+	/**
+	 * Sets the ID for this tag. Note that the ID is sanitized using {@link com.ecyrd.jspwiki.TextUtil#replaceEntities(String)}.
+	 * @param id the id for this tag
+	 */
+    public void setId( String id )
+    {
+		m_id = ( TextUtil.replaceEntities( id ) );
+	}
+    
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/package.html
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/package.html?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/package.html (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/package.html Tue Feb 12 21:53:55 2008
@@ -0,0 +1,44 @@
+<body>
+Provides standard JSP tags for JSPWiki.
+
+<h2>Package specification</h2>
+
+<p>This package contains a diverse set of JSP tags which are used in the template pages.</p>
+
+<h3>Managing tag pooling</h3>
+
+<p>A typical problem for many tag developers is that many web containers pool tags,
+i.e. the tag is not released after doEndTag(), but put into a pool, from which it
+can be invoked again.  This is highly efficient, as you don't need to instantiate
+the tag again.</p>
+
+<p>The problem, however, is that when your tag is put back into the pool, it still
+retains all the internal references, i.e. none of the member fields are cleared.
+This means there can be dangling references to things which will take a lot of memory.
+In JSPWiki's case, the WikiContext is a good example: it can actually contain quite
+a lot of stuff accumulated during it's life time, and therefore it's important for
+memory use that all references are cleared.</p>
+
+<p>Unfortunately, the "easy" solution of implementing your custom release handler
+in <code>Tag.release()</code> does not help, since it is called only when the tag
+is truly and completely released <i>from the pool</i>.  So, as long as the tag sits
+in the pool, release() is not called, and your references keep on dangling like wet
+spaghetti off the balcony.</p>
+
+<p>Neither can you trust e.g. doEndTag() being called every time, since e.g. if there
+is an exception, doEndTag() is never called.</p>
+
+<p>The correct way to do reference cleaning is to implement the {@link javax.servlet.jsp.tagext.TryCatchFinally}
+interface, where the <code>doFinally()</code> method is called every time the tag
+has been finished with and prior to it being put back into the pool.  Most JSPWiki
+base tag classes {@link com.ecyrd.jspwiki.tags.IteratorTag} and {@link com.ecyrd.jspwiki.tags.WikiTagBase}
+implement the TryCatchFinally
+interface, which means that any class subclassed from them also allows has those methods.</p>
+
+<p>Check out the javadocs for the tags for more info!</p>
+
+<h2>Related documentation</h2>
+
+TBD.
+
+</body>
\ No newline at end of file

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/Editor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/Editor.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/Editor.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/Editor.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,94 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2002 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.ui;
+
+import com.ecyrd.jspwiki.WikiContext;
+
+/**
+ *  Describes an editor.
+ *
+ *  @author Chuck Smith
+ *  @since 2.4.12
+ */
+public class Editor
+{
+    private String m_editorName;
+    private WikiContext m_wikiContext;
+    private EditorManager m_editorManager;
+
+    public Editor( WikiContext wikiContext, String editorName )
+    {
+        m_wikiContext = wikiContext;
+        m_editorName = editorName;
+        m_editorManager = wikiContext.getEngine().getEditorManager();
+    }
+
+    public String getName()
+    {
+        return m_editorName;
+    }
+
+    // FIXME: Fails, if the editoriterator is on a non-editor page.
+    /** @deprecated */
+    public String getURL()
+    {
+        String uri = m_wikiContext.getHttpRequest().getRequestURI();
+        String para = m_wikiContext.getHttpRequest().getQueryString();
+
+        // if para already contains editor parameter, replace instead of append it
+        // FIXME: Should cut out parameter instead of simple setting strin to null, maybe
+        // in futur releases it may change and theres the danger that trailing parameters get lost
+        int idx = para.indexOf(EditorManager.PARA_EDITOR + "=");
+        if (idx >= 0)
+        {
+            para = para.substring(0, idx-1);
+        }
+
+        return uri + "?" + para + "&amp;" + EditorManager.PARA_EDITOR + "=" + m_editorName;
+    }
+
+    /**
+     *  Convinience method which returns XHTML for an option element.
+     * @return "selected='selected'", if this editor is selected.
+     */
+    public String isSelected( )
+    {
+        return isSelected( "selected='selected'", "" );
+    }
+
+    public String isSelected( String ifSelected )
+    {
+        return isSelected( ifSelected, "" );
+    }
+
+    public String isSelected( String ifSelected, String ifNotSelected )
+    {
+        if ( m_editorName.equals(m_editorManager.getEditorName(m_wikiContext) ) )
+        {
+            return ifSelected;
+        }
+        return ifNotSelected;
+    }
+
+    public String toString()
+    {
+        return m_editorName;
+    }
+}



Mime
View raw message