Added: 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java?rev=627255&view=auto
==============================================================================
--- 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java
 (added)
+++ 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java
 Tue Feb 12 21:53:55 2008
@@ -0,0 +1,448 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001 Janne Jalkanen ([EMAIL PROTECTED])
+
+    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;
+
+import java.security.Principal;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import com.ecyrd.jspwiki.action.WikiActionBean;
+import com.ecyrd.jspwiki.filters.PageFilter;
+import com.ecyrd.jspwiki.modules.InternalModule;
+
+/**
+ *  Manages variables.  Variables are case-insensitive.  A list of all
+ *  available variables is on a Wiki page called "WikiVariables".
+ *
+ *  @author Janne Jalkanen
+ *  @since 1.9.20.
+ */
+public class VariableManager
+{
+    //private static Logger log = Logger.getLogger( VariableManager.class );
+   
+    // FIXME: These are probably obsolete.
+    public static final String VAR_ERROR = "error";
+    public static final String VAR_MSG   = "msg";
+    
+    /**
+     *  Contains a list of those properties that shall never be shown.
+     *  Put names here in lower case.
+     */
+    
+    static final String[] THE_BIG_NO_NO_LIST = {
+        "jspwiki.auth.masterpassword"
+    };
+    
+    /**
+     *  Creates a VariableManager object using the property list given.
+     *  @param props The properties.
+     */
+    public VariableManager( Properties props )
+    {
+    }
+
+    /**
+     *  Returns true if the link is really command to insert
+     *  a variable.
+     *  <P>
+     *  Currently we just check if the link starts with "{$".
+     *  
+     *  @param link The link text
+     *  @return true, if this represents a variable link.
+     */
+    public static boolean isVariableLink( String link )
+    {
+        return link.startsWith("{$");
+    }
+
+    /**
+     *  Parses the link and finds a value.  This is essentially used
+     *  once [EMAIL PROTECTED] #isVariableLink(String)} has found that the 
link text
+     *  actually contains a variable.  For example, you could pass in
+     *  "{$username}" and get back "JanneJalkanen".
+     *
+     *  @param  context The WikiContext
+     *  @param  link    The link text containing the variable name.
+     *  @return The variable value.
+     *  @throws IllegalArgumentException If the format is not valid (does not 
+     *          start with "{$", is zero length, etc.)
+     *  @throws NoSuchVariableException If a variable is not known.
+     */
+    public String parseAndGetValue( WikiContext context,
+                                    String link )
+        throws IllegalArgumentException,
+               NoSuchVariableException
+    {
+        if( !link.startsWith("{$") )
+            throw new IllegalArgumentException( "Link does not start with {$" 
);
+
+        if( !link.endsWith("}") )
+            throw new IllegalArgumentException( "Link does not end with }" );
+
+        String varName = link.substring(2,link.length()-1);
+
+        return getValue( context, varName.trim() );
+    }
+
+    /**
+     *  This method does in-place expansion of any variables.  However,
+     *  the expansion is not done twice, that is, a variable containing text 
$variable
+     *  will not be expanded.
+     *  <P>
+     *  The variables should be in the same format ({$variablename} as in the 
web 
+     *  pages.
+     *
+     *  @param context The WikiContext of the current page.
+     *  @param source  The source string.
+     *  @return The source string with variables expanded.
+     */
+    // FIXME: somewhat slow.
+    public String expandVariables( WikiContext context,
+                                   String      source )
+    {
+        StringBuffer result = new StringBuffer();
+
+        for( int i = 0; i < source.length(); i++ )
+        {
+            if( source.charAt(i) == '{' )
+            {
+                if( i < source.length()-2 && source.charAt(i+1) == '$' )
+                {
+                    int end = source.indexOf( '}', i );
+
+                    if( end != -1 )
+                    {
+                        String varname = source.substring( i+2, end );
+                        String value;
+
+                        try
+                        {
+                            value = getValue( context, varname );
+                        }
+                        catch( NoSuchVariableException e )
+                        {
+                            value = e.getMessage();
+                        }
+                        catch( IllegalArgumentException e )
+                        {
+                            value = e.getMessage();
+                        }
+
+                        result.append( value );
+                        i = end;
+                        continue;
+                    }
+                }
+                else
+                {
+                    result.append( '{' );
+                }
+            }
+            else
+            {
+                result.append( source.charAt(i) );
+            }
+        }
+
+        return result.toString();
+    }
+
+    /**
+     *  Returns the value of a named variable.  See [EMAIL PROTECTED] 
#getValue(WikiContext, String)}.
+     *  The only difference is that this method does not throw an exception, 
but it
+     *  returns the given default value instead.
+     *  
+     *  @param context WikiContext
+     *  @param varName The name of the variable
+     *  @param defValue A default value.
+     *  @return The variable value, or if not found, the default value.
+     */
+    public String getValue( WikiActionBean actionBean, String varName, String 
defValue )
+    {
+        try
+        {
+            return getValue( actionBean, varName );
+        }
+        catch( NoSuchVariableException e )
+        {
+            return defValue;
+        }
+    }
+    
+    /**
+     *  Returns a value of the named variable.  The resolving order is
+     *  <ol>
+     *    <li>Known "constant" name, such as "pagename", etc.  This is so
+     *        that pages could not override certain constants.
+     *    <li>WikiContext local variable.  This allows a programmer to
+     *        set a parameter which cannot be overridden by user.
+     *    <li>HTTP Session
+     *    <li>HTTP Request parameters
+     *    <li>WikiPage variable.  As set by the user with the SET directive.
+     *    <li>jspwiki.properties
+     *  </ol>
+     *
+     *  Use this method only whenever you really need to have a parameter that
+     *  can be overridden by anyone using the wiki.
+     *  
+     *  @param context The WikiContext
+     *  @param varName Name of the variable.
+     *
+     *  @return The variable value.
+     *  
+     *  @throws IllegalArgumentException If the name is somehow broken.
+     *  @throws NoSuchVariableException If a variable is not known.
+     */
+    // FIXME: Currently a bit complicated.  Perhaps should use reflection
+    //        or something to make an easy way of doing stuff.
+    public String getValue( WikiActionBean actionBean,
+                            String      varName )
+        throws IllegalArgumentException,
+               NoSuchVariableException
+    {
+        if( varName == null )
+            throw new IllegalArgumentException( "Null variable name." );
+
+        if( varName.length() == 0 )
+            throw new IllegalArgumentException( "Zero length variable name." );
+
+        // Faster than doing equalsIgnoreCase()
+        String name = varName.toLowerCase();
+
+        for( int i = 0; i < THE_BIG_NO_NO_LIST.length; i++ )
+        {
+            if( name.equals(THE_BIG_NO_NO_LIST[i]) )
+                return ""; // FIXME: Should this be something different?
+        }
+        
+        if( name.equals("pagename") && actionBean instanceof WikiContext )
+        {
+            WikiPage page = ((WikiContext)actionBean).getPage();
+            return ( page == null ? null : 
((WikiContext)actionBean).getPage().getName() );
+        }
+        else if( name.equals("applicationname") )
+        {
+            return actionBean.getEngine().getApplicationName();
+        }
+        else if( name.equals("jspwikiversion") )
+        {
+            return Release.getVersionString();
+        }
+        else if( name.equals("encoding") )
+        {
+            return actionBean.getEngine().getContentEncoding();
+        }
+        else if( name.equals("totalpages") )
+        {
+            return Integer.toString(actionBean.getEngine().getPageCount());
+        }
+        else if( name.equals("pageprovider") )
+        {
+            return actionBean.getEngine().getCurrentProvider();
+        }
+        else if( name.equals("pageproviderdescription") )
+        {
+            return actionBean.getEngine().getCurrentProviderInfo();
+        }
+        else if( name.equals("attachmentprovider") )
+        {
+            WikiProvider p = 
actionBean.getEngine().getAttachmentManager().getCurrentProvider();
+            return (p != null) ? p.getClass().getName() : "-";
+        }
+        else if( name.equals("attachmentproviderdescription") )
+        {
+            WikiProvider p = 
actionBean.getEngine().getAttachmentManager().getCurrentProvider();
+
+            return (p != null) ? p.getProviderInfo() : "-";
+        }
+        else if( name.equals("interwikilinks") )
+        {
+            StringBuffer res = new StringBuffer();
+
+            for( Iterator i = 
actionBean.getEngine().getAllInterWikiLinks().iterator(); i.hasNext(); )
+            {
+                if( res.length() > 0 ) res.append(", ");
+                String link = (String) i.next();
+                res.append( link );
+                res.append( " --> " );
+                res.append( actionBean.getEngine().getInterWikiURL(link) );
+            }
+            return res.toString();
+        }
+        else if( name.equals("inlinedimages") )
+        {
+            StringBuffer res = new StringBuffer();
+
+            for( Iterator i = 
actionBean.getEngine().getAllInlinedImagePatterns().iterator(); i.hasNext(); )
+            {
+                if( res.length() > 0 ) res.append(", ");
+                
+                String ptrn = (String) i.next();
+                res.append(ptrn);
+            }
+            
+            return res.toString();
+        }
+        else if( name.equals("pluginpath") )
+        {
+            String s = actionBean.getEngine().getPluginSearchPath();
+
+            return (s == null) ? "-" : s;
+        }
+        else if( name.equals("baseurl") )
+        {
+            return actionBean.getEngine().getBaseURL();
+        }
+        else if( name.equals("uptime") )
+        {
+            Date now = new Date();
+            long secondsRunning = (now.getTime() - 
actionBean.getEngine().getStartTime().getTime())/1000L;
+
+            long seconds = secondsRunning % 60;
+            long minutes = (secondsRunning /= 60) % 60;
+            long hours   = (secondsRunning /= 60) % 24;
+            long days    = secondsRunning /= 24;
+
+            return days+"d, "+hours+"h "+minutes+"m "+seconds+"s";
+        }
+        else if( name.equals("loginstatus") )
+        {
+            WikiSession session = actionBean.getWikiSession();
+            return session.getStatus();
+        }
+        else if( name.equals("username") )
+        {
+            Principal wup = actionBean.getCurrentUser();
+
+            return wup != null ? wup.getName() : "not logged in";
+        }
+        else if( name.equals("requestcontext") )
+        {
+            return actionBean.getRequestContext();
+        }
+        else if( name.equals("pagefilters") )
+        {
+            List filters = 
actionBean.getEngine().getFilterManager().getFilterList();
+            StringBuffer sb = new StringBuffer();
+
+            for( Iterator i = filters.iterator(); i.hasNext(); )
+            {
+                PageFilter pf = (PageFilter)i.next();
+                String f = pf.getClass().getName();
+
+                if( pf instanceof InternalModule )
+                    continue;
+
+                if( sb.length() > 0 ) sb.append(", ");
+                sb.append( f );
+            }
+
+            return sb.toString();
+        }
+        else
+        {
+            // 
+            // Check if such a context variable exists,
+            // returning its string representation.
+            //
+            if( (actionBean.getVariable( varName )) != null )
+            {
+                return actionBean.getVariable( varName ).toString();
+            }
+
+            //
+            //  Well, I guess it wasn't a final straw.  We also allow 
+            //  variables from the session and the request (in this order).
+            //
+
+            HttpServletRequest req = actionBean.getContext().getRequest();
+            if( req != null && req.getSession() != null )
+            {
+                HttpSession session = req.getSession();
+
+                try
+                {
+                    String s;
+                    
+                    if( (s = (String)session.getAttribute( varName )) != null )
+                        return s;
+
+                    if( (s = 
actionBean.getContext().getRequest().getParameter( varName )) != null )
+                        return s;
+                }
+                catch( ClassCastException e ) {}
+            }
+
+            // And the final straw: see if the current page has named metadata.
+            
+            if ( actionBean instanceof WikiContext )
+            {
+                WikiPage pg = ((WikiContext)actionBean).getPage();
+                if( pg != null )
+                {
+                    Object metadata = pg.getAttribute( varName );
+                    if( metadata != null )
+                        return( metadata.toString() );
+                }
+            
+                   // And the final straw part 2: see if the "real" current 
page has
+               // named metadata. This allows a parent page to control a 
inserted
+                   // page through defining variables
+                  WikiPage rpg = ((WikiContext)actionBean).getRealPage();
+                               if( rpg != null )
+               {
+                       Object metadata = rpg.getAttribute( varName );
+                       if( metadata != null )
+                       return metadata.toString();
+               }
+            }
+            // Next-to-final straw: attempt to fetch using property name
+            // We don't allow fetching any other properties than those starting
+            // with "jspwiki.".  I know my own code, but I can't vouch for bugs
+            // in other people's code... :-)
+            
+            if( varName.startsWith("jspwiki.") )
+            {
+                Properties props = actionBean.getEngine().getWikiProperties();
+
+                String s = props.getProperty( varName );
+                if( s != null )
+                {
+                    return s;
+                }
+            }
+            
+            //
+            //  Final defaults for some known quantities.
+            //
+
+            if( varName.equals( VAR_ERROR ) || varName.equals( VAR_MSG ) )
+                return "";
+  
+            throw new NoSuchVariableException( "No variable "+varName+" 
defined." );
+        }
+    }
+}

Added: 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java?rev=627255&view=auto
==============================================================================
--- 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java
 (added)
+++ 
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java
 Tue Feb 12 21:53:55 2008
@@ -0,0 +1,357 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Copyright (C) 2001 Janne Jalkanen ([EMAIL PROTECTED])
+
+    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;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import javax.servlet.http.HttpServletRequest;
+
+import net.sourceforge.stripes.validation.Validate;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.action.*;
+import com.ecyrd.jspwiki.auth.permissions.AllPermission;
+
+/**
+ *  <p>Provides state information throughout the processing of a page.  A
+ *  WikiContext is born when the JSP pages that are the main entry
+ *  points, are invoked.  The JSPWiki engine creates the new
+ *  WikiContext, which basically holds information about the page, the
+ *  handling engine, and in which context (view, edit, etc) the
+ *  call was done.</p>
+ *  <p>A WikiContext also provides request-specific variables, which can
+ *  be used to communicate between plugins on the same page, or
+ *  between different instances of the same plugin.  A WikiContext
+ *  variable is valid until the processing of the page has ended.  For
+ *  an example, please see the Counter plugin.</p>
+ *  <p>When a WikiContext is created, it automatically associates a
+ *  [EMAIL PROTECTED] WikiSession} object with the user's HttpSession. The
+ *  WikiSession contains information about the user's authentication
+ *  status, and is consulted by [EMAIL PROTECTED] #getCurrentUser()}.
+ *  object</p>
+ *  <p>Do not cache the page object that you get from the WikiContext; always
+ *  use getPage()!</p>
+ *
+ *  @see com.ecyrd.jspwiki.plugin.Counter
+ *
+ *  @author Janne Jalkanen
+ *  @author Andrew R. Jaquith
+ */
+public abstract class WikiContext extends AbstractActionBean
+    implements Cloneable
+{
+    private    WikiPage   m_page = null;
+    private    WikiPage   m_realPage = null;
+
+    /** User is administering JSPWiki (Install, SecurityConfig). @deprecated 
use ActionBean  */
+    public static final String    INSTALL  = 
InstallActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    
+    /** The VIEW context - the user just wants to view the page
+        contents. */
+    public static final String    VIEW     = 
ViewActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User wants to view or administer workflows. */
+    public static final String    WORKFLOW = 
WorkflowActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** The EDIT context - the user is editing the page. */
+    public static final String    EDIT     = 
EditActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is preparing for a login/authentication. */
+    public static final String    LOGIN    = 
LoginActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is preparing to log out. */
+    public static final String    LOGOUT   = "logout";
+
+    /** JSPWiki wants to display a message. */
+    public static final String    MESSAGE  = 
MessageActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is viewing a DIFF between the two versions of the page. */
+    public static final String    DIFF     = 
DiffActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is viewing page history. */
+    public static final String    INFO     = 
PageInfoActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is previewing the changes he just made. */
+    public static final String    PREVIEW  = 
PreviewActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User has an internal conflict, and does quite not know what to
+        do. Please provide some counseling. */
+    public static final String    CONFLICT = 
PageModifiedActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** An error has been encountered and the user needs to be informed. */
+    public static final String    ERROR    = 
ErrorActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is uploading something. */
+    public static final String    UPLOAD   = 
UploadActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is commenting something. */
+    public static final String    COMMENT  = 
CommentActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is searching for content. */
+    public static final String    FIND     = 
SearchActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User wishes to create a new group */
+    public static final String    CREATE_GROUP = "createGroup";
+    
+    /** User is deleting an existing group. */
+    public static final String    DELETE_GROUP = "deleteGroup";
+    
+    /** User is editing an existing group. */
+    public static final String    EDIT_GROUP = 
GroupActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    
+    /** User is viewing an existing group */
+    public static final String    VIEW_GROUP = 
GroupActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    
+    /** User is editing preferences */
+    public static final String    PREFS    = 
UserPreferencesActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    
+    /** User is renaming a page. */
+    public static final String    RENAME   = 
RenameActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is deleting a page or an attachment. */
+    public static final String    DELETE   = 
DeleteActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** User is downloading an attachment. */
+    public static final String    ATTACH   = 
AttachActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** RSS feed is being generated. */
+    public static final String    RSS      = 
RSSActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    /** This is not a JSPWiki context, use it to access static files. */
+    public static final String    NONE     = "none";  
+    
+    /** Same as NONE; this is just a clarification. */
+    public static final String    OTHER    = "other";
+
+    /** User is doing administrative things. */
+    public static final String    ADMIN    = 
AdminActionBean.class.getAnnotation(WikiRequestContext.class).value();
+
+    private static final Logger   log      = Logger.getLogger( 
WikiContext.class );
+    
+    /**
+     * Creates a new WikiContext, without a WikiEngine, Request or WikiPage.
+     */
+    public WikiContext()
+    {
+        super();
+    }
+
+    /**
+     *  Sometimes you may want to render the page using some other page's 
context.
+     *  In those cases, it is highly recommended that you set the setRealPage()
+     *  to point at the real page you are rendering.  Please see InsertPageTag
+     *  for an example.
+     *  <p>
+     *  Also, if your plugin e.g. does some variable setting, be aware that if 
it
+     *  is embedded in the LeftMenu or some other page added with 
InsertPageTag,
+     *  you should consider what you want to do - do you wish to really 
reference
+     *  the "master" page or the included page.
+     *
+     *  @param page  The real page which is being rendered.
+     *  @return The previous real page
+     *  @since 2.3.14
+     *  @see com.ecyrd.jspwiki.tags.InsertPageTag
+     */
+    public WikiPage setRealPage( WikiPage page )
+    {
+        WikiPage old = m_realPage;
+        m_realPage = page;
+        return old;
+    }
+
+    /**
+     *  Gets a reference to the real page whose content is currently being 
rendered.
+     *  If your plugin e.g. does some variable setting, be aware that if it
+     *  is embedded in the LeftMenu or some other page added with 
InsertPageTag,
+     *  you should consider what you want to do - do you wish to really 
reference
+     *  the "master" page or the included page.
+     *  <p>
+     *  For example, in the default template, there is a page called 
"LeftMenu".
+     *  Whenever you access a page, e.g. "Main", the master page will be Main, 
and
+     *  that's what the getPage() will return - regardless of whether your 
plugin
+     *  resides on the LeftMenu or on the Main page.  However, getRealPage()
+     *  will return "LeftMenu".
+     *
+     *  @return A reference to the real page.
+     *  @see com.ecyrd.jspwiki.tags.InsertPageTag
+     *  @see com.ecyrd.jspwiki.parser.JSPWikiMarkupParser
+     */
+    public WikiPage getRealPage()
+    {
+        return m_realPage;
+    }
+
+    /**
+     *  Returns the page that is being handled. If the page had not
+     *  been previously set, try to set it to the WikiEngine's
+     *  front page. It is possible that this method will return
+     *  <code>null</code>, so calling classes should check the 
+     *  return value.
+     */
+    public WikiPage getPage()
+    {
+        return m_page;
+    }
+
+    /**
+     *  Sets the page that is being handled. Calling this
+     *  method also re-sets the "real page" to the same value.
+     *
+     *  @param page The wikipage
+     *  @since 2.1.37.
+     */
+    @Validate(required = true)
+    public void setPage( WikiPage page )
+    {
+        m_page = page;
+        m_realPage = m_page;
+    }
+
+    /**
+     * If the WikiPage contains a template attribute ([EMAIL PROTECTED] 
WikiEngine#PROP_TEMPLATEDIR}),
+     * this method returns its value; otherwise, it returns superclass value 
via
+     * [EMAIL PROTECTED] AbstractActionBean#getTemplate()}.
+     */
+    @Override
+    public String getTemplate()
+    {
+        if ( m_page != null )
+        {
+            String template = (String) 
m_page.getAttribute(WikiEngine.PROP_TEMPLATEDIR);
+            if ( template != null )
+            {
+                return template;
+            }
+        }
+        return super.getTemplate();
+    }
+
+    /**
+     *  This method will safely return any HTTP parameters that 
+     *  might have been defined.  You should use this method instead
+     *  of peeking directly into the result of getHttpRequest(), since
+     *  this method is smart enough to do all of the right things,
+     *  figure out UTF-8 encoded parameters, etc.
+     *
+     *  @since 2.0.13.
+     *  @param paramName Parameter name to look for.
+     *  @return HTTP parameter, or null, if no such parameter existed.
+     */
+    public String getHttpParameter( String paramName )
+    {
+        String result = null;
+
+        if( getContext() != null )
+        {
+            result = getContext().getRequest().getParameter( paramName );
+        }
+
+        return result;
+    }
+
+    /**
+     *  If the request did originate from a HTTP request,
+     *  then the HTTP request can be fetched here.  However, it the request
+     *  did NOT originate from a HTTP request, then this method will
+     *  return null, and YOU SHOULD CHECK FOR IT!
+     *
+     *  @return Null, if no HTTP request was done.
+     *  @deprecated use the method [EMAIL PROTECTED] #getContext()} to obtain 
the ActionBeanContext,
+     *  and call [EMAIL PROTECTED] 
com.ecyrd.jspwiki.action.WikiActionBeanContext#getRequest()} method.
+     *  @since 2.0.13.
+     */
+    public HttpServletRequest getHttpRequest()
+    {
+        return getContext().getRequest();
+    }
+
+    /**
+     * Returns the name of the WikiPage associated with this wiki context.
+     * @return the page name
+     */
+    public String getName()
+    {
+        return m_page != null ? m_page.getName() : "<no page>";
+    }
+
+    /**
+     * Returns the URL for viewing a named wiki page, without parameters. 
+     * The URL will be encoded via the HttpServletResponse object, 
+     * which means that any outbound filters will be able to transform 
+     * it as needed. The URL returned will be absolute if the WikiEngine
+     * was configured to return absolute URLs; otherwise, the URL will be
+     * relative to the webapp context root.
+     * @param page the wiki page; if <code>null</code>, the front page will be 
used
+     * @return the URL
+     */
+    public String getViewURL( String page )
+    {
+        boolean absolute = "absolute".equals(getEngine().getVariable( this, 
WikiEngine.PROP_REFSTYLE ));
+        return getContext().getURL( ViewActionBean.class, page, null, absolute 
);
+    }
+
+    /**
+     *  Returns a shallow clone of the WikiContext.
+     *
+     *  @since 2.1.37.
+     *  //TODO: this could be a problem...
+     */
+    public Object clone()
+    {
+        try
+        {
+            // super.clone() must always be called to make sure that inherited 
objects
+            // get the right type
+            WikiContext copy = (WikiContext)super.clone();
+        
+            copy.m_variableMap    = m_variableMap;
+            copy.m_page           = m_page;
+            copy.m_realPage       = m_realPage;
+            WikiActionBeanContext context = getContext();
+            copy.setContext( context );
+            String template = getTemplate();
+            copy.setTemplate( template );
+            return copy;
+        }
+        catch( CloneNotSupportedException e ){} // Never happens
+
+        return null;
+    }
+
+    /**
+     *  Returns true, if the current user has administrative permissions (i.e. 
the omnipotent
+     *  AllPermission).
+     *
+     *  @since 2.4.46
+     *  @return true, if the user has all permissions.
+     */
+    public boolean hasAdminPermissions()
+    {
+        boolean admin = false;
+        WikiEngine engine = getEngine();
+        admin = engine.getAuthorizationManager().checkPermission( 
getWikiSession(), 
+                                                                    new 
AllPermission(engine.getApplicationName()) );
+        return admin;
+    }
+
+}


Reply via email to