You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/13 06:54:24 UTC

svn commit: r627255 [33/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...

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CommentLinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CommentLinkTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CommentLinkTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CommentLinkTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,93 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001-2006 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.WikiContext;
+import com.ecyrd.jspwiki.action.CommentActionBean;
+
+/**
+ *  Writes a comment link.  Body of the link becomes the link text.
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *    <LI>format - Format, either "anchor" or "url".
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class CommentLinkTag
+    extends WikiLinkTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        String pageName = null;
+        
+        //
+        //  Determine the page and the link.
+        //
+        if( m_pageName == null )
+        {
+            if( m_page == null )
+            {
+                // You can't call this on the page itself anyways.
+                return SKIP_BODY;
+            }
+
+            pageName = m_page.getName();
+        }
+        else
+        {
+            pageName = m_pageName;
+        }
+
+        //
+        //  Finally, print out the correct link, according to what
+        //  user commanded.
+        //
+        JspWriter out = pageContext.getOut();
+
+        switch( m_format )
+        {
+          case ANCHOR:
+            out.print("<a href=\""+getCommentURL(pageName)+"\">");
+            break;
+
+          case URL:
+            out.print( getCommentURL(pageName) );
+            break;
+        }
+
+        return EVAL_BODY_INCLUDE;
+    }
+
+    private String getCommentURL( String pageName )
+    {
+        return ((WikiContext)m_actionBean).getContext().getURL(CommentActionBean.class, pageName);
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentEncodingTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentEncodingTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentEncodingTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentEncodingTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,46 @@
+/* 
+    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.WikiEngine;
+
+/**
+ *  Returns the app name.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class ContentEncodingTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine = m_actionBean.getEngine();
+
+        pageContext.getOut().print( engine.getContentEncoding() );
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/ContentTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,149 @@
+/* 
+    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 java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.jsp.JspException;
+
+import com.ecyrd.jspwiki.action.*;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ *  Is used as a "super include" tag, which can include the proper context
+ *  based on the wikicontext.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.2
+ */
+public class ContentTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    private Map<Class <? extends WikiActionBean>,String> m_mappings = new HashMap<Class <? extends WikiActionBean>,String>();
+
+    public void setView( String s )
+    {
+        m_mappings.put( ViewActionBean.class, s );
+    }
+
+    public void setDiff( String s )
+    {
+        m_mappings.put( DiffActionBean.class, s );
+    }
+
+    public void setInfo( String s )
+    {
+        m_mappings.put( PageInfoActionBean.class, s );
+    }
+
+    public void setPreview( String s )
+    {
+        m_mappings.put( PreviewActionBean.class, s );
+    }
+
+    public void setConflict( String s )
+    {
+        m_mappings.put( DiffActionBean.class, s );
+    }
+
+    public void setFind( String s )
+    {
+        m_mappings.put( SearchActionBean.class, s );
+    }
+
+    public void setPrefs( String s )
+    {
+        m_mappings.put( UserPreferencesActionBean.class, s );
+    }
+
+    public void setError( String s )
+    {
+        m_mappings.put( ErrorActionBean.class, s );
+    }
+
+    public void setEdit( String s )
+    {
+        m_mappings.put( EditActionBean.class, s );
+    }
+
+    public void setComment( String s )
+    {
+        m_mappings.put( CommentActionBean.class, s );
+    }
+
+    public final int doWikiStartTag()
+        throws IOException,
+               ProviderException
+    {
+        return SKIP_BODY;
+    }
+
+    public final int doEndTag()
+        throws JspException
+    {
+        try
+        {
+            // Check the overridden templates first
+            String contentTemplate = m_mappings.get( m_actionBean.getClass() );
+
+            // If not found, use the default name (trim "ActionBean" from name, and append "Content"
+            // e.g., EditActionBean yields "EditContent.jsp"
+            if ( contentTemplate == null )
+            {
+                String beanName = m_actionBean.getClass().getName();
+                if ( beanName.endsWith( "ActionBean" ) )
+                {
+                    beanName = beanName.substring( 0, beanName.lastIndexOf( "ActionBean") );
+                }
+                contentTemplate = beanName + "Content.jsp";
+            }
+            
+            // If still no, something fishy is going on
+            if( contentTemplate == null )
+            {
+                throw new JspException("This template uses <wiki:Content/> in an unsupported context: " + m_actionBean.getClass().getName() );
+            }
+
+            String page = m_actionBean.getEngine().getTemplateManager().findJSP( pageContext,
+                                                                                  m_actionBean.getTemplate(),
+                                                                                  contentTemplate );
+            pageContext.include( page );
+        }
+        catch( ServletException e )
+        {
+            log.warn( "Including failed, got a servlet exception from sub-page. "+
+                      "Rethrowing the exception to the JSP engine.", e );
+            throw new JspException( e.getMessage() );
+        }
+        catch( IOException e )
+        {
+            log.warn( "I/O exception - probably the connection was broken. "+
+                      "Rethrowing the exception to the JSP engine.", e );
+            throw new JspException( e.getMessage() );
+        }
+
+        return EVAL_PAGE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CookieTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CookieTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CookieTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/CookieTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,410 @@
+/*
+    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.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * Sets or gets Cookie values. This implementation makes the following
+ * assumptions:
+ * <ul>
+ * <li>The cookie contains any number of name-value pairs
+ * <li>Name-value pairs are separated by "&" in the encoded cookie value string
+ * <li>An encoded name-value pair is compatible with JavaScript's
+ * encodeURIComponent(). Notably, spaces are encoded as "%20".
+ * <li>A decoded name-value pair separates the name and value with a "="
+ * </ul>
+ *
+ * <p>The value of a cookie carrying values n1="v1" and n2="v2 with space"
+ * would thus be
+ * <pre>
+ *   n1%3Dv1&n2%3Dv2%20with%20space
+ * </pre>
+ *
+ * <p>Usage:
+ *
+ * <pre>
+ * &lt;wiki:cookie name="cookiename" var="contextvariable" scope="page" /&gt;
+ * </pre>
+ * - Returns the value of the named cookie, or an empty string if not set.
+ * If 'var' is specified, the value is set into a context variable of this name.
+ * The 'scope' parameter may be added to specify the context: "session",
+ * "page", "request". If var is omitted, the output is placed directly into
+ * the JSP page.
+ *
+ * <pre>
+ * &lt;wiki:cookie name="cookiename" value="encoded_value" /&gt;
+ * </pre>
+ * - Sets the named cookie to the given value. If the value string is empty,
+ * the cookie value is set to empty; otherwise the cookie encoding rules of
+ * this class must be followed for the value.
+ *
+ * <pre>
+ * &lt;wiki:cookie name="cookiename" item="parameter_name" /&gt;
+ * </pre>
+ * - Assumes that the cookie contains URLEncoded name-value pairs,
+ * with name and value separated by an equals sign, and returns the value
+ * of the specified item.
+ *
+ * &lt;wiki:cookie name="cookiename" item="parameter_name" value="value" /&gt;
+ * </pre>
+ * - Sets the value of 'parameter_name' in the named cookie to 'value'.
+ *
+ * <pre>
+ * &lt;wiki:cookie name="cookiename" clear="parameter_name" /&gt;
+ * </pre>
+ * - Removes the named parameter from the cookie.
+ *
+ * <pre>
+ * &lt;wiki:cookie clear="cookiename" /&gt;
+ * </pre>
+ * - Removes the named cookie. Clear may be used at the same time as a value
+ * is retrieved (or set, despite the dubious usefulness of that operation).
+ */
+public class CookieTag
+    extends TagSupport
+{
+    private static final long serialVersionUID = 0L;
+
+    private static Logger log = Logger.getLogger( CookieTag.class );
+
+    /** Name of the cookie value. Required. */
+    private String m_name;
+    /** Name of the cookie nvp item. Optional. */
+    private String m_item;
+    /** A value to echo or set. Optional. */
+    private String m_value;
+    /** Name of a context variable to set result in. Optional, defaults to out.*/
+    private String m_var;
+    /** Scope of m_var: request, session, page. */
+    private String m_scope;
+    /** Name of a cookie or a cookie nvp to clear. */
+    private String m_clear;
+
+    public void setName( String s )
+    {
+        m_name = s;
+    }
+
+    public void setItem( String s )
+    {
+        m_item = s;
+    }
+
+    public void setValue( String s )
+    {
+        m_value = s;
+    }
+
+    public void setVar( String s )
+    {
+        m_scope = s;
+    }
+
+    public void setClear( String s )
+    {
+        m_clear = s;
+    }
+
+    public void setScope( String s )
+    {
+        m_scope = s;
+    }
+
+
+    public void release()
+    {
+        m_name = m_item = m_var = m_value = m_clear = m_scope = null;
+        super.release();
+    }
+
+    /**
+     * Examines the parameter and returns the corresponding scope identifier:
+     * "request" maps to PageContext.REQUEST_SCOPE, and so on.
+     * Possible values are "page", "session", "application", and "request",
+     * which is the default return value.
+     */
+    private int getScope( String s )
+    {
+        if( s == null )
+        {
+            return PageContext.REQUEST_SCOPE;
+        }
+        if( "page".equals( m_scope ) )
+        {
+            return PageContext.PAGE_SCOPE;
+        }
+        if( "session".equals( m_scope ) )
+        {
+            return PageContext.SESSION_SCOPE;
+        }
+        if( "application".equals( m_scope ) )
+        {
+            return PageContext.APPLICATION_SCOPE;
+        }
+
+        return PageContext.REQUEST_SCOPE;
+    }
+
+
+    public int doEndTag()
+    {
+        String out = null;
+        Cookie cookie = findCookie( m_name );
+        boolean changed = false;
+
+        if( m_value != null )
+        {
+            if( m_item != null )
+            {
+                setItemValue( cookie, m_item, m_value );
+            }
+            else
+            {
+                cookie.setValue( m_value );
+            }
+            changed = true;
+        }
+        else
+        {
+            if( m_item != null )
+            {
+                out = getItemValue( cookie, m_item );
+            }
+            else
+            {
+                out = cookie.getValue();
+            }
+        }
+
+        if( out != null )
+        {
+            if( m_var != null )
+            {
+                int scope = getScope( m_scope );
+                pageContext.setAttribute( m_var, out,  scope );
+            }
+            else
+            {
+                try
+                {
+                    pageContext.getOut().print( out );
+                }
+                catch( IOException ioe )
+                {
+                    log.warn( "Failed to write to JSP page: " + ioe.getMessage(), ioe );
+                }
+            }
+        }
+
+        Cookie cleared = null;
+        if( m_clear != null )
+        {
+            cleared = findCookie( m_clear );
+            if( m_item != null )
+            {
+                setItemValue( cookie, m_item, null );
+            }
+            else
+            {
+                cleared.setValue( null );
+            }
+        }
+
+        HttpServletResponse res = (HttpServletResponse)pageContext.getResponse();
+        if( changed )
+        {
+            res.addCookie( cookie );
+        }
+        if( cleared != null )
+        {
+            res.addCookie( cleared );
+        }
+
+        return EVAL_PAGE;
+    }
+
+    /**
+     * Sets a single name-value pair in the given cookie.
+     */
+    private void setItemValue( Cookie c, String item, String value )
+    {
+        if( c == null )
+        {
+            return;
+        }
+        String in = c.getValue();
+        Map<String, String> values = parseCookieValues( in );
+        values.put( item, value );
+        String cv = encodeValues( values );
+        c.setValue( cv );
+    }
+
+    /**
+     * Returns the value of the given item in the cookie.
+     */
+    private String getItemValue( Cookie c, String item )
+    {
+        if( c == null || item == null )
+        {
+            return null;
+        }
+        String in = c.getValue();
+        Map values = parseCookieValues( in );
+        return (String)values.get( item );
+    }
+
+
+    /**
+     * Parses a cookie value, of format name1%3Fvalue1&name2%3Fvalue2...,
+     * into a Map<String,String>.
+     */
+    private Map<String, String> parseCookieValues( String s )
+    {
+        Map<String,String> rval = new HashMap<String,String>();
+        if( s == null )
+        {
+            return rval;
+        }
+        String[] nvps = s.split( "&" );
+        if( nvps == null )
+        {
+            return rval;
+        }
+        for( int i = 0; i < nvps.length; i++ )
+        {
+            String nvp = decode( nvps[i] );
+            String[] nv = nvp.split( "=" );
+            if( nv[0] != null && nv[0].trim().length() > 0 )
+            {
+                rval.put( nv[0], nv[1] );
+            }
+        }
+
+        return rval;
+    }
+
+    /**
+     * Encodes name-value pairs in the map into a single string, in a format
+     * understood by this class and JavaScript decodeURIComponent().
+     */
+    private String encodeValues( Map values )
+    {
+        StringBuffer rval = new StringBuffer();
+        if( values == null || values.size() == 0 )
+        {
+            return rval.toString();
+        }
+
+        Iterator it = values.entrySet().iterator();
+        while( it.hasNext() )
+        {
+            Map.Entry e = (Map.Entry) it.next();
+            String n = (String)e.getKey();
+            String v = (String)e.getValue();
+            if( v != null )
+            {
+                String nv = n + "=" + v;
+                rval.append( encode( nv ) );
+            }
+        }
+
+        return rval.toString();
+    }
+
+    /**
+     * Converts a String to an encoding understood by JavaScript
+     * decodeURIComponent.
+     */
+    private String encode( String nvp )
+    {
+        String coded = "";
+        try
+        {
+            coded = URLEncoder.encode( nvp, "UTF-8" );
+        }
+        catch( UnsupportedEncodingException e )
+        {
+            /* never happens */
+            log.info( "Failed to encode UTF-8", e );
+        }
+        return coded.replaceAll( "\\+", "%20" );
+    }
+
+    /**
+     * Converts a cookie value (set by this class, or by a JavaScript
+     * encodeURIComponent call) into a plain string.
+     */
+    private String decode( String envp )
+    {
+        String rval;
+        try
+        {
+            rval = URLDecoder.decode( envp , "UTF-8" );
+            return rval;
+        }
+        catch( UnsupportedEncodingException e )
+        {
+            log.error( "Failed to decode cookie", e );
+            return envp;
+        }
+    }
+
+    /**
+     * Locates the named cookie in the request, or creates a new one if it
+     * doesn't exist.
+     */
+    private Cookie findCookie( String cname )
+    {
+        HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
+        if( req != null )
+        {
+            Cookie[] cookies = req.getCookies();
+            if( cookies != null )
+            {
+                for( int i = 0; i < cookies.length; i++ )
+                {
+                    if( cookies[i].getName().equals( cname ) )
+                    {
+                        return cookies[i];
+                    }
+                }
+            }
+        }
+
+        return new Cookie( cname, null );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/DiffLinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/DiffLinkTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/DiffLinkTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/DiffLinkTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,185 @@
+/* 
+    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.HashMap;
+import java.util.Map;
+
+import javax.servlet.jsp.JspWriter;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.action.DiffActionBean;
+
+/**
+ *  Writes a diff link.  Body of the link becomes the link text.
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.</LI>
+ *    <LI>version - The older of these versions.  May be an integer to
+ *        signify a version number, or the text "latest" to signify the latest version.
+ *        If not specified, will default to "latest".  May also be "previous" to signify
+ *        a version prior to this particular version.</LI>
+ *    <LI>newVersion - The newer of these versions.  Can also be "latest", or "previous".  Defaults to "latest".</LI>
+ *  </UL>
+ *
+ *  If the page does not exist, this tag will fail silently, and not evaluate
+ *  its body contents.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class DiffLinkTag
+    extends WikiLinkTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    public static final String VER_LATEST   = "latest";
+    public static final String VER_PREVIOUS = "previous";
+    public static final String VER_CURRENT  = "current";
+
+    private String m_version    = VER_LATEST;
+    private String m_newVersion = VER_LATEST;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_version = m_newVersion = VER_LATEST;
+    }
+
+    public final String getVersion()
+    {
+        return m_version;
+    }
+
+    public void setVersion( String arg )
+    {
+        m_version = arg;
+    }
+
+    public final String getNewVersion()
+    {
+        return m_newVersion;
+    }
+
+    public void setNewVersion( String arg )
+    {
+        m_newVersion = arg;
+    }
+
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine   = m_actionBean.getEngine();
+        String     pageName = m_pageName;
+
+        if( pageName == null )
+        {
+            if( m_page != null )
+            {
+                pageName = m_page.getName();
+            }
+            else
+            {
+                return SKIP_BODY;
+            }
+        }
+
+        JspWriter out = pageContext.getOut();
+
+        int r1 = 0;
+        int r2 = 0;
+
+        //
+        //  In case the page does not exist, we fail silently.
+        //
+        if(!engine.pageExists(pageName))
+        {
+            return SKIP_BODY;
+        }
+
+        if( VER_LATEST.equals(getVersion()) )
+        {
+            WikiPage latest = engine.getPage( pageName, 
+                                              WikiProvider.LATEST_VERSION );
+
+            if( latest == null )
+            {
+                // This may occur if matchEnglishPlurals is on, and we access the wrong page name
+                return SKIP_BODY;
+            }
+            r1 = latest.getVersion();
+        }
+        else if( VER_PREVIOUS.equals(getVersion()) )
+        {
+            r1 = m_page.getVersion() - 1;
+            r1 = (r1 < 1 ) ? 1 : r1;
+        }
+        else if( VER_CURRENT.equals(getVersion()) )
+        {
+            r1 = m_page.getVersion();
+        }
+        else
+        {
+            r1 = Integer.parseInt( getVersion() );
+        }
+
+        if( VER_LATEST.equals(getNewVersion()) )
+        {
+            WikiPage latest = engine.getPage( pageName,
+                                              WikiProvider.LATEST_VERSION );
+
+            r2 = latest.getVersion();
+        }
+        else if( VER_PREVIOUS.equals(getNewVersion()) )
+        {
+            r2 = m_page.getVersion() - 1;
+            r2 = (r2 < 1 ) ? 1 : r2;
+        }
+        else if( VER_CURRENT.equals(getNewVersion()) )
+        {
+            r2 = m_page.getVersion();
+        }
+        else
+        {
+            r2 = Integer.parseInt( getNewVersion() );
+        }
+
+        Map<String,String> urlParams = new HashMap<String,String>();
+        urlParams.put("r1", String.valueOf( r1 ));
+        urlParams.put("r2", String.valueOf( r2 ));
+        String url = m_actionBean.getContext().getURL( DiffActionBean.class,
+                                           pageName,
+                                           urlParams );
+        switch( m_format )
+        {
+          case ANCHOR:
+            out.print("<a 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/EditLinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditLinkTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditLinkTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditLinkTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,151 @@
+/* 
+    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.HashMap;
+import java.util.Map;
+
+import javax.servlet.jsp.JspWriter;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.action.EditActionBean;
+
+/**
+ *  Writes an edit link.  Body of the link becomes the link text.
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *    <LI>format - Format, either "anchor" or "url".
+ *    <LI>version - Version number of the page to refer to.  Possible values
+ *        are "this", meaning the version of the current page; or a version
+ *        number.  Default is always to point at the latest version of the page.
+ *    <LI>title - Is used in page actions to display hover text (tooltip)
+ *    <LI>accesskey - Set an accesskey (ALT+[Char])
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class EditLinkTag
+    extends WikiLinkTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    public String m_version = null;
+    public String m_title = "";
+    public String m_accesskey = "";
+    
+    public void initTag()
+    {
+        super.initTag();
+        m_version = null;
+    }
+
+    public void setVersion( String vers )
+    {
+        m_version = vers;
+    }
+    
+    public void setTitle( String title )
+    {
+        m_title = title;
+    }
+
+    public void setAccesskey( String access )
+    {
+        m_accesskey = access;
+    }
+
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine   = m_actionBean.getEngine();
+        WikiPage   page     = null;
+        String     pageName = null;
+        
+        //
+        //  Determine the page and the link.
+        //
+        if( m_pageName == null )
+        {
+            if( m_page == null )
+            {
+                // You can't call this on the page itself anyways.
+                return SKIP_BODY;
+            }
+
+            pageName = m_page.getName();
+        }
+        else
+        {
+            pageName = m_pageName;
+        }
+
+        //
+        //  Determine the latest version, if the version attribute is "this".
+        //
+        Map<String,String> urlParams = new HashMap<String,String>();
+        if( m_version != null )
+        {
+            if( "this".equalsIgnoreCase(m_version) )
+            {
+                if( m_page == null )
+                {
+                    // No page, so go fetch according to page name.
+                    page = engine.getPage( m_pageName );
+                }
+                
+                if( page != null )
+                {
+                    urlParams.put("version", String.valueOf(page.getVersion()));
+                }
+            }
+            else
+            {
+                urlParams.put("version", String.valueOf(m_version));
+            }
+        }
+
+        //
+        //  Finally, print out the correct link, according to what
+        //  user commanded.
+        //
+        JspWriter out = pageContext.getOut();
+        WikiContext context = (WikiContext)m_actionBean;
+
+        switch( m_format )
+        {
+          case ANCHOR:
+              urlParams.put("accesskey", m_accesskey);
+              urlParams.put("title", m_title);
+              out.print("<a href=\""+context.getContext().getURL(EditActionBean.class,pageName, urlParams) + "\">");
+              break;
+
+          case URL:
+              out.print( context.getContext().getURL(EditActionBean.class,pageName,urlParams) );
+              break;
+        }
+
+        return EVAL_BODY_INCLUDE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorInfo.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorInfo.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorInfo.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorInfo.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,45 @@
+/* 
+    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.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.VariableInfo;
+
+/**
+ *  Just provides the TEI data for EditorIteratorTag.
+ *
+ *  @author Chuck Smith
+ *  @since 2.4.12
+ */
+public class EditorIteratorInfo extends TagExtraInfo
+{
+    public VariableInfo[] getVariableInfo(TagData data)
+    {
+        VariableInfo[] var = { new VariableInfo( data.getAttributeString("id"),
+                                                 "com.ecyrd.jspwiki.ui.Editor",
+                                                 true,
+                                                 VariableInfo.NESTED )
+        };
+
+        return var;
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorIteratorTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,66 @@
+/*
+    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.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+import com.ecyrd.jspwiki.ui.Editor;
+import com.ecyrd.jspwiki.ui.EditorManager;
+
+/**
+ *  Iterates through editors.
+ *
+ *  @author Chuck Smith
+ *  @since 2.4.12
+ */
+
+public class EditorIteratorTag
+    extends IteratorTag
+{
+    private static final long serialVersionUID = 0L;
+
+    static    Logger    log = Logger.getLogger( EditorIteratorTag.class );
+
+    public final int doStartTag()
+    {
+        m_wikiContext = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+
+        WikiEngine engine = m_wikiContext.getEngine();
+        EditorManager mgr    = engine.getEditorManager();
+
+        String[] editorList = mgr.getEditorList();
+
+        Collection<Editor>editors = new ArrayList<Editor>();
+
+        for ( int i = 0; i < editorList.length; i++ )
+        {
+            editors.add(new Editor(m_wikiContext, editorList[i]));
+        }
+        setList( editors );
+
+        return super.doStartTag();
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/EditorTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,86 @@
+/* 
+    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.ServletException;
+import javax.servlet.jsp.JspException;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.ui.EditorManager;
+
+/**
+ *  Creates an editor component with all the necessary parts
+ *  to get it working.
+ *  <p>
+ *  In the future, this component should be expanded to provide
+ *  a customized version of the editor according to user preferences.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.2
+ */
+public class EditorTag
+    extends WikiBodyTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        return SKIP_BODY;
+    }
+       
+    public int doEndTag() throws JspException
+    {
+        WikiEngine engine = m_wikiContext.getEngine();
+        EditorManager mgr = engine.getEditorManager();
+        
+        String editorPath = mgr.getEditorPath( m_wikiContext );
+        
+        try
+        {
+            String page = engine.getTemplateManager().findJSP( pageContext,
+                                                               m_wikiContext.getTemplate(),
+                                                               editorPath );
+            
+            if( page == null )
+            {
+                //FIXME: should be I18N ...
+                pageContext.getOut().println("Unable to find editor '"+editorPath+"'");
+            }
+            else
+            {
+                pageContext.include( page );
+            }
+        }
+        catch( ServletException e )
+        {
+            log.error("Failed to include editor",e);
+            throw new JspException("Failed to include editor: "+e.getMessage() );
+        }
+        catch( IOException e )
+        {
+            throw new JspException("Could not print Editor tag: "+e.getMessage() );
+        }
+        
+        return EVAL_PAGE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/FeedDiscoveryTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/FeedDiscoveryTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/FeedDiscoveryTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/FeedDiscoveryTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,104 @@
+/* 
+    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.http.HttpServletResponse;
+
+import net.sourceforge.stripes.action.UrlBinding;
+import net.sourceforge.stripes.util.UrlBuilder;
+
+import com.ecyrd.jspwiki.TextUtil;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.action.RSSActionBean;
+import com.ecyrd.jspwiki.plugin.WeblogPlugin;
+import com.ecyrd.jspwiki.util.BlogUtil;
+
+/**
+ *  Outputs links to all the site feeds and APIs this Wiki/blog supports.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.2
+ */
+public class FeedDiscoveryTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine = m_actionBean.getEngine();
+
+        String rssSiteURL      = engine.getGlobalRSSURL();
+        
+        if( rssSiteURL != null )
+        {
+            // Write the feed URL for the site
+            String siteName = BlogUtil.getSiteName(m_actionBean);
+            siteName = TextUtil.replaceEntities( siteName );
+            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for the entire site.\" href=\""+rssSiteURL+"\" />\n");
+
+            // Write the feed URL for this page
+            if ( m_page != null )
+            {
+                HttpServletResponse httpResponse = (HttpServletResponse)pageContext.getResponse();
+                String encodedPageName = engine.encodeName( m_page.getName() );
+                String url = RSSActionBean.class.getAnnotation(UrlBinding.class).value();
+                
+                // Create the feed
+                UrlBuilder urlBuilder = new UrlBuilder( url, true );
+                urlBuilder.addParameter("page", encodedPageName);
+                urlBuilder.addParameter("mode", "wiki");
+                String rssPageURL  =  httpResponse.encodeURL( urlBuilder.toString() );
+                if( rssPageURL != null )
+                {
+                    pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for page "+siteName+".\" href=\""+rssPageURL+"\" />\n");
+
+                    // TODO: Enable this
+                    /*
+                    pageContext.getOut().print("<link rel=\"service.post\" type=\"application/atom+xml\" title=\""+
+                                               siteName+"\" href=\""+atomPostURL+"\" />\n");
+                    */
+                    // FIXME: This does not work always, as plugins are not initialized until the first fetch
+                    if( "true".equals(m_page.getAttribute(WeblogPlugin.ATTR_ISWEBLOG)) )
+                    {
+                        // Create blog feed URL
+                        urlBuilder = new UrlBuilder( url, true );
+                        urlBuilder.addParameter("page", encodedPageName);
+                        String blogPageFeedURL = httpResponse.encodeURL( urlBuilder.toString() );
+                        pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS feed for weblog "+
+                                                   siteName+".\" href=\""+blogPageFeedURL+"\" />\n");
+                        
+                        // Create atom feed URL
+                        urlBuilder.addParameter("type", "atom");
+                        String atomPageFeedURL = httpResponse.encodeURL( urlBuilder.toString() );
+
+                        pageContext.getOut().print("<link rel=\"service.feed\" type=\"application/atom+xml\" title=\"Atom 1.0 weblog feed for "+
+                                                   siteName+"\" href=\""+atomPageFeedURL+"\" />\n");
+                    }
+                }
+            }
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HasAttachmentsTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HasAttachmentsTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HasAttachmentsTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HasAttachmentsTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,63 @@
+/* 
+    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.WikiEngine;
+import com.ecyrd.jspwiki.attachment.AttachmentManager;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ *  Includes body if page has attachments.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class HasAttachmentsTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine = m_actionBean.getEngine();
+        AttachmentManager mgr = engine.getAttachmentManager();
+
+        try
+        {
+            if( m_page != null && engine.pageExists(m_page) && mgr.attachmentsEnabled() )
+            {
+                if( mgr.hasAttachments(m_page) )
+                {
+                    return EVAL_BODY_INCLUDE;
+                }
+            }
+        }
+        catch( ProviderException e )
+        {
+            log.fatal("Provider failed while trying to check for attachements",e);
+            // FIXME: THrow something.
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorInfo.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorInfo.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorInfo.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorInfo.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,44 @@
+/* 
+    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.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.VariableInfo;
+
+/**
+ *  Just provides the TEI data for HistoryIteratorTag.
+ *
+ *  @since 2.0
+ */
+public class HistoryIteratorInfo extends TagExtraInfo
+{
+    public VariableInfo[] getVariableInfo(TagData data)
+    {
+        VariableInfo[] var = { new VariableInfo( data.getAttributeString("id"),
+                                                 "com.ecyrd.jspwiki.WikiPage",
+                                                 true,
+                                                 VariableInfo.NESTED )
+        };
+
+        return var;
+
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/HistoryIteratorTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,131 @@
+/* 
+    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 org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ *  Iterates through tags.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+
+// FIXME: Too much in common with IteratorTag - REFACTOR
+public class HistoryIteratorTag
+    extends IteratorTag
+{
+    private static final long serialVersionUID = 0L;
+    
+    static    Logger    log = Logger.getLogger( HistoryIteratorTag.class );
+
+    public final int doStartTag()
+    {
+        m_wikiContext = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+
+        WikiEngine engine = m_wikiContext.getEngine();
+        WikiPage   page;
+
+        page = m_wikiContext.getPage();
+
+        try
+        {
+            if( page != null && engine.pageExists(page) )
+            {
+                Collection versions = engine.getVersionHistory( page.getName() );
+
+                if( versions == null )
+                {
+                    // There is no history
+                    return SKIP_BODY;
+                }
+
+                m_iterator = versions.iterator();
+
+                if( m_iterator.hasNext() )
+                {
+                    WikiContext context = (WikiContext)m_wikiContext.clone();
+                    context.setPage( (WikiPage)m_iterator.next() );
+                    WikiActionBeanFactory.saveActionBean( pageContext, context );
+                    pageContext.setAttribute( getId(),
+                                              context.getPage() );
+                }
+                else
+                {
+                    return SKIP_BODY;
+                }
+            }
+
+            return EVAL_BODY_BUFFERED;
+        }
+        catch( ProviderException e )
+        {
+            log.fatal("Provider failed while trying to iterator through history",e);
+            // FIXME: THrow something.
+        }
+
+        return SKIP_BODY;
+    }
+
+    public final 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?
+            }
+        }
+
+        if( m_iterator != null && m_iterator.hasNext() )
+        {
+            WikiContext context = (WikiContext)m_wikiContext.clone();
+            context.setPage( (WikiPage)m_iterator.next() );
+            WikiActionBeanFactory.saveActionBean( pageContext, context );
+            pageContext.setAttribute( getId(),
+                                      context.getPage() );
+            return EVAL_BODY_BUFFERED;
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IfNoSearchResultsTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IfNoSearchResultsTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IfNoSearchResultsTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IfNoSearchResultsTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,49 @@
+/* 
+    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;
+
+/**
+ *  If there have been no search results, then outputs the body text.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class IfNoSearchResultsTag
+    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 || list.size() == 0 )
+        {   
+            return EVAL_BODY_INCLUDE;
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeResourcesTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeResourcesTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeResourcesTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeResourcesTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,60 @@
+/* 
+    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 com.ecyrd.jspwiki.ui.TemplateManager;
+
+/**
+ *  This tag is used to include any programmatic includes into the
+ *  output stream.  Actually, what it does is that it simply emits a
+ *  tiny marker into the stream, and then a ServletFilter will take
+ *  care of the actual inclusion.
+ *  
+ *  @author jalkanen
+ *
+ */
+public class IncludeResourcesTag extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+        
+    private String m_type;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_type = null;
+    }
+    
+    public void setType( String type )
+    {
+        m_type = type;
+    }
+    
+    public int doWikiStartTag() throws Exception
+    {
+        //String marker = m_wikiContext.getEngine().getTemplateManager().getMarker(m_wikiContext, m_type);
+        String marker = TemplateManager.getMarker(m_actionBean, m_type);
+
+        pageContext.getOut().println( marker );
+        
+        return SKIP_BODY;
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IncludeTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,104 @@
+/* 
+    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.JspException;
+import javax.servlet.ServletException;
+
+import com.ecyrd.jspwiki.TextUtil;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ *  Includes an another JSP page, making sure that we actually pass
+ *  the WikiContext correctly.
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+// FIXME: Perhaps unnecessary?
+public class IncludeTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    protected String m_pageName;
+    protected boolean m_searchTemplates;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_pageName = null;
+        m_searchTemplates = false;
+    }
+
+    public void setPage( String page )
+    {
+        m_pageName = page;
+    }
+
+    public String getPage()
+    {
+        return m_pageName;
+    }
+
+    public final int doWikiStartTag()
+        throws IOException,
+               ProviderException
+    {
+        // WikiEngine engine = m_wikiContext.getEngine();
+
+        return SKIP_BODY;
+    }
+
+    public final int doEndTag()
+        throws JspException
+    {
+        try
+        {
+            String page = m_actionBean.getEngine().getTemplateManager().findJSP( pageContext,
+                                                                                  m_actionBean.getTemplate(),
+                                                                                  m_pageName );
+            
+            if( page == null )
+            {
+                pageContext.getOut().println("No template file called '"+TextUtil.replaceEntities(m_pageName)+"'");
+            }
+            else
+            {
+                pageContext.include( page );
+            }
+        }
+        catch( ServletException e )
+        {
+            log.warn( "Including failed, got a servlet exception from sub-page. "+
+                      "Rethrowing the exception to the JSP engine.", e );
+            throw new JspException( e.getMessage() );
+        }
+        catch( IOException e )
+        {
+            log.warn( "I/O exception - probably the connection was broken. "+
+                      "Rethrowing the exception to the JSP engine.", e );
+            throw new JspException( e.getMessage() );
+        }
+
+        return EVAL_PAGE;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertDiffTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertDiffTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertDiffTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertDiffTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,122 @@
+/* 
+    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.PageContext;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+
+/**
+ *  Writes difference between two pages using a HTML table.  If there is
+ *  no difference, includes the body.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class InsertDiffTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    /** Attribute which is used to store the old page content to the Page Context */
+    public static final String ATTR_OLDVERSION = "olddiff";
+
+    /** Attribute which is used to store the new page content to the Page Context */
+    public static final String ATTR_NEWVERSION = "newdiff";
+
+    protected String m_pageName;
+
+    /** {@inheritDoc} */
+    public void initTag()
+    {
+        super.initTag();
+        m_pageName = null;
+    }
+
+    /**
+     *  Sets the page name.
+     *  @param page Page to get diff from.
+     */
+    public void setPage( String page )
+    {
+        m_pageName = page;
+    }
+
+    /**
+     *  Gets the page name.
+     * @return The page name.
+     */
+    public String getPage()
+    {
+        return m_pageName;
+    }
+
+    /** {@inheritDoc} */
+    public final int doWikiStartTag()
+        throws IOException
+    {
+        WikiEngine engine = m_actionBean.getEngine();
+        WikiPage   page;
+
+        if( m_pageName == null )
+        {
+            page = m_page;
+        }
+        else
+        {
+            page = engine.getPage( m_pageName );
+        }
+
+        Integer vernew = (Integer) pageContext.getAttribute( ATTR_NEWVERSION,
+                                                             PageContext.REQUEST_SCOPE );
+        Integer verold = (Integer) pageContext.getAttribute( ATTR_OLDVERSION,
+                                                             PageContext.REQUEST_SCOPE );
+
+        log.info("Request diff between version "+verold+" and "+vernew);
+
+        if( page != null )
+        {
+            JspWriter out = pageContext.getOut();
+
+            String diff = engine.getDiff( engine.getWikiActionBeanFactory().newViewActionBean( page ), 
+                                          vernew.intValue(), 
+                                          verold.intValue() );
+
+            if( diff.length() == 0 )
+            {
+                return EVAL_BODY_INCLUDE;
+            }
+
+            out.write( diff );
+        }
+
+        return SKIP_BODY;
+    }
+}
+

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertPageTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertPageTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertPageTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/InsertPageTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,142 @@
+/* 
+    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.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ *  Renders WikiPage content.  For InsertPage tag and the InsertPage plugin
+ *  the difference is that the tag will always render in the context of the page
+ *  which is referenced (i.e. a LeftMenu inserted on a JSP page with the InsertPage tag
+ *  will always render in the context of the actual URL, e.g. Main.), whereas
+ *  the InsertPage plugin always renders in local context.  This allows this like
+ *  ReferringPagesPlugin to really refer to the Main page instead of having to
+ *  resort to any trickery.
+ *  <p>
+ *  This tag sets the "realPage" field of the WikiContext to point at the inserted
+ *  page, while the "page" will contain the actual page in which the rendering
+ *  is being made.
+ *   
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>page - Page name to refer to.  Default is the current page.
+ *    <li>mode - In which format to insert the page.  Can be either "plain" or "html".
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public class InsertPageTag
+    extends WikiTagBase
+{
+    private static final long serialVersionUID = 0L;
+    
+    public static final int HTML  = 0;
+    public static final int PLAIN = 1;
+
+    protected String m_pageName = null;
+    private   int    m_mode = HTML;
+
+    public void initTag()
+    {
+        super.initTag();
+        m_pageName = null;
+        m_mode = HTML;
+    }
+
+    public void setPage( String page )
+    {
+        m_pageName = page;
+    }
+
+    public String getPage()
+    {
+        return m_pageName;
+    }
+
+    public void setMode( String arg )
+    {
+        if( "plain".equals(arg) )
+        {
+            m_mode = PLAIN;
+        }
+        else
+        {
+            m_mode = HTML;
+        }
+    }
+
+    public final int doWikiStartTag()
+        throws IOException,
+               ProviderException
+    {
+        WikiEngine engine = m_actionBean.getEngine();
+        WikiPage   page;
+
+        //
+        //  NB: The page might not really exist if the user is currently
+        //      creating it (i.e. it is not yet in the cache or providers), 
+        //      AND we got the page from the wikiContext.
+        //
+
+        if( m_pageName == null )
+        {
+            page = m_page;
+            if( !engine.pageExists( page ) ) return SKIP_BODY;
+        }
+        else
+        {
+            page = engine.getPage( m_pageName );
+        }
+
+        if( page != null )
+        {
+            // FIXME: Do version setting later.
+            // page.setVersion( WikiProvider.LATEST_VERSION );
+
+            log.debug("Inserting page "+page);
+
+            JspWriter out = pageContext.getOut();
+
+            WikiContext context = (WikiContext)m_actionBean;
+            WikiPage oldPage = context.setRealPage( page );
+            
+            switch( m_mode )
+            {
+              case HTML:
+                out.print( engine.getHTML(context, page) );
+                break;
+              case PLAIN:
+                out.print( engine.getText(context, page) );
+                break;
+            }
+            
+            context.setRealPage( oldPage );
+        }
+
+        return SKIP_BODY;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IteratorTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IteratorTag.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IteratorTag.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/tags/IteratorTag.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,218 @@
+/*
+    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.Arrays;
+import java.util.Iterator;
+import java.util.Collection;
+import javax.servlet.jsp.JspWriter;
+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.WikiPage;
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+
+/**
+ *  Iterates through tags.
+ *
+ *  <P><B>Attributes</B></P>
+ *  <UL>
+ *    <LI>list - a collection.
+ *  </UL>
+ *
+ *  @author Janne Jalkanen
+ *  @since 2.0
+ */
+public abstract class IteratorTag
+    extends BodyTagSupport
+    implements TryCatchFinally
+{
+
+    protected String      m_pageName;
+    protected Iterator    m_iterator;
+    protected WikiContext m_wikiContext;
+
+    private static Logger log = Logger.getLogger( IteratorTag.class );
+
+    /**
+     *  Sets the collection that is used to form the iteration.
+     *  
+     *  @param arg A Collection which will be iterated.
+     */
+    public void setList( Collection arg )
+    {
+        if( arg != null )
+            m_iterator = arg.iterator();
+    }
+
+    /**
+     *  Sets the collection list, but using an array.
+     *  @param arg An array of objects which will be iterated.
+     */
+    public void setList( Object[] arg )
+    {
+        if( arg != null )
+        {
+            m_iterator = Arrays.asList(arg).iterator();
+        }
+    }
+    
+    /**
+     *  Sets the iterator directly that is used to form the iteration.
+     */
+    /*
+    public void setList( Iterator arg )
+    {
+        m_iterator = arg;
+    }
+    */
+
+    /**
+     *  Clears the iterator away.  After calling this method doStartTag()
+     *  will always return SKIP_BODY
+     */
+    public void clearList()
+    {
+        m_iterator = null;
+    }
+    
+    /**
+     *  Override this method to reset your own iterator.
+     */
+    public void resetIterator()
+    {
+        // No operation here
+    }
+    
+    /**
+     *  {@inheritDoc}
+     */
+    public int doStartTag()
+    {
+        m_wikiContext = (WikiContext) WikiActionBeanFactory.findActionBean( pageContext );
+        
+        resetIterator();
+        
+        if( m_iterator == null ) return SKIP_BODY;
+
+        if( m_iterator.hasNext() )
+        {
+            buildContext();
+        }
+
+        return EVAL_BODY_BUFFERED;
+    }
+
+    /**
+     *  Arg, I hate globals.
+     */
+    private void buildContext()
+    {
+        //
+        //  Build a clone of the current context
+        //
+        WikiContext context = (WikiContext)m_wikiContext.clone();
+        
+        Object o = m_iterator.next();
+        
+        if( o instanceof WikiPage )
+            context.setPage( (WikiPage)o );
+
+        //
+        //  Push it to the iterator stack, and set the id.
+        //
+        WikiActionBeanFactory.saveActionBean( pageContext, context );
+        pageContext.setAttribute( getId(),
+                                  o );
+    }
+
+    /**
+     *  {@inheritDoc}
+     */
+    public int doEndTag()
+    {
+        // Return back to the original.
+        WikiActionBeanFactory.saveActionBean( pageContext, m_wikiContext );
+
+        return EVAL_PAGE;
+    }
+
+    /**
+     *  {@inheritDoc}
+     */
+    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?
+            }
+        }
+
+        if( m_iterator != null && m_iterator.hasNext() )
+        {
+            buildContext();
+            return EVAL_BODY_BUFFERED;
+        }
+
+        return SKIP_BODY;
+    }
+    
+    /**
+     *  In case your tag throws an exception at any point, you can
+     *  override this method and implement a custom exception handler.
+     *  <p>
+     *  By default, this handler does nothing.
+     *  
+     *  @param arg0 The Throwable that the tag threw
+     *  
+     *  @throws Throwable I have no idea why this would throw anything
+     */
+    public void doCatch(Throwable arg0) throws Throwable
+    {
+    }
+
+    /**
+     *  Executed after the tag has been finished.  This is a great place
+     *  to put any cleanup code.  However you <b>must</b> call super.doFinally()
+     *  if you override this method, or else some of the things may not
+     *  work as expected.
+     */
+    public void doFinally()
+    {
+        resetIterator();
+        m_iterator = null;
+        m_pageName = null;
+        m_wikiContext = null;        
+    }
+
+}