jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r682139 [3/6] - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki: ./ action/
Date Sun, 03 Aug 2008 12:12:49 GMT
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/VariableManager.java Sun Aug  3 05:12:47 2008
@@ -1,24 +1,26 @@
-/* 
+/*
     JSPWiki - a JSP-based WikiWiki clone.
 
-    Copyright (C) 2001 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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.   
  */
 package com.ecyrd.jspwiki;
 
+import java.lang.reflect.Method;
 import java.security.Principal;
 import java.util.Date;
 import java.util.Iterator;
@@ -28,6 +30,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import org.apache.log4j.Logger;
+
 import com.ecyrd.jspwiki.action.WikiActionBean;
 import com.ecyrd.jspwiki.filters.PageFilter;
 import com.ecyrd.jspwiki.modules.InternalModule;
@@ -36,12 +40,11 @@
  *  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 );
+    private static Logger log = Logger.getLogger( VariableManager.class );
    
     // FIXME: These are probably obsolete.
     public static final String VAR_ERROR = "error";
@@ -180,11 +183,11 @@
      *  @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 )
+    public String getValue( WikiContext context, String varName, String defValue )
     {
         try
         {
-            return getValue( actionBean, varName );
+            return getValue( context, varName );
         }
         catch( NoSuchVariableException e )
         {
@@ -216,9 +219,7 @@
      *  @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,
+    public String getValue( WikiActionBean context,
                             String      varName )
         throws IllegalArgumentException,
                NoSuchVariableException
@@ -238,212 +239,286 @@
                 return ""; // FIXME: Should this be something different?
         }
         
-        if( name.equals("pagename") && actionBean instanceof WikiContext )
+        try
+        {
+            //
+            //  Using reflection to get system variables adding a new system variable
+            //  now only invloves creating a new method in the SystemVariables class
+            //  with a name starting with get and the first character of the name of
+            //  the variable capitalized. Example:
+            //    public String getMysysvar(){
+            //      return "Hello World";
+            //    }
+            //
+            SystemVariables sysvars = new SystemVariables(context);
+            String methodName = "get"+Character.toUpperCase(name.charAt(0))+name.substring(1);
+            Method method = sysvars.getClass().getMethod(methodName);
+            return (String)method.invoke(sysvars);
+        }
+        catch( NoSuchMethodException e1 )
+        {
+            // 
+            //  It is not a system var. Time to handle the other cases.
+            //
+            //  Check if such a context variable exists,
+            //  returning its string representation.
+            //
+            if( (context.getVariable( varName )) != null )
+            {
+                return context.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 = context.getHttpRequest();
+            if( req != null && req.getSession() != null )
+            {
+                HttpSession session = req.getSession();
+
+                try
+                {
+                    String s;
+                    
+                    if( (s = (String)session.getAttribute( varName )) != null )
+                        return s;
+
+                    if( (s = context.getHttpParameter( varName )) != null )
+                        return s;
+                }
+                catch( ClassCastException e ) {}
+            }
+
+            //
+            // And the final straw: see if the current page has named metadata.
+            //
+            
+            if ( context instanceof WikiContext )
+            {
+                WikiPage pg = ((WikiContext)context).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)context).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 = context.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." );
+        }
+        catch( Exception e )
+        {
+            log.info("Interesting exception: cannot fetch variable value",e);
+        }
+        return "";
+    }
+
+    /**
+     *  This class provides the implementation for the different system variables.
+     *  It is called via Reflection - any access to a variable called $xxx is mapped
+     *  to getXxx() on this class.
+     *  <p>
+     *  This is a lot neater than using a huge if-else if branching structure
+     *  that we used to have before.
+     *  <p>
+     *  Note that since we are case insensitive for variables, and VariableManager
+     *  calls var.toLowerCase(), the getters for the variables do not have
+     *  capitalization anywhere.  This may look a bit odd, but then again, this
+     *  is not meant to be a public class.
+     *  
+     *  @since 2.7.0
+     *
+     */
+    private static class SystemVariables
+    {
+        private WikiActionBean m_context;
+
+        public SystemVariables(WikiActionBean context)
         {
-            WikiPage page = ((WikiContext)actionBean).getPage();
-            return ( page == null ? null : ((WikiContext)actionBean).getPage().getName() );
+            m_context=context;
         }
-        else if( name.equals("applicationname") )
+
+        public String getPagename()
+        {
+            return (m_context instanceof WikiContext ? ((WikiContext)m_context).getPage().getName() : null);
+        }
+
+        public String getApplicationname()
         {
-            return actionBean.getEngine().getApplicationName();
+            return m_context.getEngine().getApplicationName();
         }
-        else if( name.equals("jspwikiversion") )
+
+        public String getJspwikiversion()
         {
             return Release.getVersionString();
         }
-        else if( name.equals("encoding") )
+
+        public String getEncoding()
         {
-            return actionBean.getEngine().getContentEncoding();
+            return m_context.getEngine().getContentEncoding();
         }
-        else if( name.equals("totalpages") )
+
+        public String getTotalpages()
         {
-            return Integer.toString(actionBean.getEngine().getPageCount());
+            return Integer.toString(m_context.getEngine().getPageCount());
         }
-        else if( name.equals("pageprovider") )
+
+        public String getPageprovider()
         {
-            return actionBean.getEngine().getCurrentProvider();
+            return m_context.getEngine().getCurrentProvider();
         }
-        else if( name.equals("pageproviderdescription") )
+
+        public String getPageproviderdescription()
         {
-            return actionBean.getEngine().getCurrentProviderInfo();
+            return m_context.getEngine().getCurrentProviderInfo();
         }
-        else if( name.equals("attachmentprovider") )
+
+        public String getAttachmentprovider()
         {
-            WikiProvider p = actionBean.getEngine().getAttachmentManager().getCurrentProvider();
+            WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();
             return (p != null) ? p.getClass().getName() : "-";
         }
-        else if( name.equals("attachmentproviderdescription") )
+
+        public String getAttachmentproviderdescription()
         {
-            WikiProvider p = actionBean.getEngine().getAttachmentManager().getCurrentProvider();
+            WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();
 
             return (p != null) ? p.getProviderInfo() : "-";
         }
-        else if( name.equals("interwikilinks") )
+
+        public String getInterwikilinks()
         {
             StringBuffer res = new StringBuffer();
 
-            for( Iterator i = actionBean.getEngine().getAllInterWikiLinks().iterator(); i.hasNext(); )
+            for( Iterator i = m_context.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) );
+                res.append( m_context.getEngine().getInterWikiURL(link) );    
             }
             return res.toString();
         }
-        else if( name.equals("inlinedimages") )
+
+        public String getInlinedimages()
         {
             StringBuffer res = new StringBuffer();
 
-            for( Iterator i = actionBean.getEngine().getAllInlinedImagePatterns().iterator(); i.hasNext(); )
+            for( Iterator i = m_context.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") )
+
+        @SuppressWarnings("deprecation")
+        public String getPluginpath()
         {
-            String s = actionBean.getEngine().getPluginSearchPath();
+            String s = m_context.getEngine().getPluginSearchPath();
 
             return (s == null) ? "-" : s;
         }
-        else if( name.equals("baseurl") )
+
+        public String getBaseurl()
         {
-            return actionBean.getEngine().getBaseURL();
+            return m_context.getEngine().getBaseURL();
         }
-        else if( name.equals("uptime") )
+
+        public String getUptime()
         {
             Date now = new Date();
-            long secondsRunning = (now.getTime() - actionBean.getEngine().getStartTime().getTime())/1000L;
+            long secondsRunning = (now.getTime() - m_context.getEngine().getStartTime().getTime()) / 1000L;
 
             long seconds = secondsRunning % 60;
             long minutes = (secondsRunning /= 60) % 60;
-            long hours   = (secondsRunning /= 60) % 24;
-            long days    = secondsRunning /= 24;
+            long hours = (secondsRunning /= 60) % 24;
+            long days = secondsRunning /= 24;
 
-            return days+"d, "+hours+"h "+minutes+"m "+seconds+"s";
+            return days + "d, " + hours + "h " + minutes + "m " + seconds + "s";
         }
-        else if( name.equals("loginstatus") )
+
+        public String getLoginstatus()
         {
-            WikiSession session = actionBean.getWikiSession();
+            WikiSession session = m_context.getWikiSession();
             return session.getStatus();
         }
-        else if( name.equals("username") )
+
+        public String getUsername()
         {
-            Principal wup = actionBean.getCurrentUser();
+            Principal wup = m_context.getCurrentUser();
 
             return wup != null ? wup.getName() : "not logged in";
         }
-        else if( name.equals("requestcontext") )
+
+        public String getRequestcontext()
         {
-            return actionBean.getRequestContext();
+            return m_context.getRequestContext();
         }
-        else if( name.equals("pagefilters") )
+
+        public String getPagefilters()
         {
-            List filters = actionBean.getEngine().getFilterManager().getFilterList();
+            List filters = m_context.getEngine().getFilterManager().getFilterList();
             StringBuffer sb = new StringBuffer();
 
-            for( Iterator i = filters.iterator(); i.hasNext(); )
+            for (Iterator i = filters.iterator(); i.hasNext();)
             {
-                PageFilter pf = (PageFilter)i.next();
+                PageFilter pf = (PageFilter) i.next();
                 String f = pf.getClass().getName();
 
                 if( pf instanceof InternalModule )
                     continue;
 
-                if( sb.length() > 0 ) sb.append(", ");
-                sb.append( f );
+                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." );
-        }
     }
+
 }

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiContext.java Sun Aug  3 05:12:47 2008
@@ -1,36 +1,46 @@
 /*
     JSPWiki - a JSP-based WikiWiki clone.
 
-    Copyright (C) 2001 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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
  */
 package com.ecyrd.jspwiki;
 
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
+import java.io.IOException;
+import java.security.Permission;
+import java.security.Principal;
+import java.text.MessageFormat;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.el.ELException;
 
 import net.sourceforge.stripes.validation.Validate;
 
 import org.apache.log4j.Logger;
 
 import com.ecyrd.jspwiki.action.*;
+import com.ecyrd.jspwiki.auth.*;
 import com.ecyrd.jspwiki.auth.permissions.AllPermission;
+import com.ecyrd.jspwiki.i18n.InternationalizationManager;
+import com.ecyrd.jspwiki.tags.WikiTagBase;
+import com.ecyrd.jspwiki.preferences.Preferences;
 
 /**
  *  <p>Provides state information throughout the processing of a page.  A
@@ -54,102 +64,104 @@
  *
  *  @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;
+    private    WikiPage   m_page;
+    private    WikiPage   m_realPage;
+
+    /** User is administering JSPWiki (Install, SecurityConfig). */
+    public static final String    INSTALL  = HandlerInfo.getHandlerInfo( InstallActionBean.class, "install" ).getRequestContext();
 
-    /** 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();
+    public static final String    VIEW     = HandlerInfo.getHandlerInfo( ViewActionBean.class, "view" ).getRequestContext();
 
     /** User wants to view or administer workflows. */
-    public static final String    WORKFLOW = WorkflowActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    WORKFLOW = HandlerInfo.getHandlerInfo( WorkflowActionBean.class, "view" ).getRequestContext();
 
     /** The EDIT context - the user is editing the page. */
-    public static final String    EDIT     = EditActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    EDIT     = HandlerInfo.getHandlerInfo( EditActionBean.class, "edit" ).getRequestContext();
 
     /** User is preparing for a login/authentication. */
-    public static final String    LOGIN    = LoginActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    LOGIN    = HandlerInfo.getHandlerInfo( LoginActionBean.class, "login" ).getRequestContext();
 
     /** User is preparing to log out. */
-    public static final String    LOGOUT   = "logout";
+    public static final String    LOGOUT   = HandlerInfo.getHandlerInfo( LoginActionBean.class, "logout" ).getRequestContext();
 
     /** JSPWiki wants to display a message. */
-    public static final String    MESSAGE  = MessageActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    MESSAGE  = HandlerInfo.getHandlerInfo( MessageActionBean.class, "message" ).getRequestContext();
 
     /** User is viewing a DIFF between the two versions of the page. */
-    public static final String    DIFF     = DiffActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    DIFF     = HandlerInfo.getHandlerInfo( EditActionBean.class, "diff" ).getRequestContext();
 
     /** User is viewing page history. */
-    public static final String    INFO     = PageInfoActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    INFO     = HandlerInfo.getHandlerInfo( PageInfoActionBean.class, "info" ).getRequestContext();
 
     /** User is previewing the changes he just made. */
-    public static final String    PREVIEW  = PreviewActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    PREVIEW  = HandlerInfo.getHandlerInfo( EditActionBean.class, "preview" ).getRequestContext();
 
     /** 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();
+    public static final String    CONFLICT = HandlerInfo.getHandlerInfo( PageModifiedActionBean.class, "conflict" ).getRequestContext();
 
     /** An error has been encountered and the user needs to be informed. */
-    public static final String    ERROR    = ErrorActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    ERROR    = HandlerInfo.getHandlerInfo( ErrorActionBean.class, "error" ).getRequestContext();
 
     /** User is uploading something. */
-    public static final String    UPLOAD   = UploadActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    UPLOAD   = HandlerInfo.getHandlerInfo( UploadActionBean.class, "upload" ).getRequestContext();
 
     /** User is commenting something. */
-    public static final String    COMMENT  = CommentActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    COMMENT  = HandlerInfo.getHandlerInfo( CommentActionBean.class, "comment" ).getRequestContext();
 
     /** User is searching for content. */
-    public static final String    FIND     = SearchActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    FIND     = HandlerInfo.getHandlerInfo( SearchActionBean.class, "find" ).getRequestContext();
 
     /** User wishes to create a new group */
-    public static final String    CREATE_GROUP = "createGroup";
-    
+    public static final String    CREATE_GROUP = HandlerInfo.getHandlerInfo( GroupActionBean.class, "create" ).getRequestContext();
+
     /** User is deleting an existing group. */
-    public static final String    DELETE_GROUP = "deleteGroup";
-    
+    public static final String    DELETE_GROUP = HandlerInfo.getHandlerInfo( GroupActionBean.class, "delete" ).getRequestContext();
+
     /** User is editing an existing group. */
-    public static final String    EDIT_GROUP = GroupActionBean.class.getAnnotation(WikiRequestContext.class).value();
-    
+    public static final String    EDIT_GROUP = HandlerInfo.getHandlerInfo( GroupActionBean.class, "save" ).getRequestContext();
+
     /** User is viewing an existing group */
-    public static final String    VIEW_GROUP = GroupActionBean.class.getAnnotation(WikiRequestContext.class).value();
-    
+    public static final String    VIEW_GROUP = HandlerInfo.getHandlerInfo( GroupActionBean.class, "view" ).getRequestContext();
+
     /** User is editing preferences */
-    public static final String    PREFS    = UserPreferencesActionBean.class.getAnnotation(WikiRequestContext.class).value();
-    
+    public static final String    PREFS    = HandlerInfo.getHandlerInfo( UserPreferencesActionBean.class, "editFavorites" ).getRequestContext();
+
     /** User is renaming a page. */
-    public static final String    RENAME   = RenameActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    RENAME   = HandlerInfo.getHandlerInfo( RenameActionBean.class, "rename" ).getRequestContext();
 
     /** User is deleting a page or an attachment. */
-    public static final String    DELETE   = DeleteActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    DELETE   = HandlerInfo.getHandlerInfo( DeleteActionBean.class, "delete" ).getRequestContext();
 
     /** User is downloading an attachment. */
-    public static final String    ATTACH   = AttachActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    ATTACH   = HandlerInfo.getHandlerInfo( AttachActionBean.class, "upload" ).getRequestContext();
 
     /** RSS feed is being generated. */
-    public static final String    RSS      = RSSActionBean.class.getAnnotation(WikiRequestContext.class).value();
+    public static final String    RSS      = HandlerInfo.getHandlerInfo( RSSActionBean.class, "rss" ).getRequestContext();
 
     /** 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();
+    public static final String    ADMIN    = "admin";
 
     private static final Logger   log      = Logger.getLogger( WikiContext.class );
 
     /**
-     * Creates a new WikiContext, without a WikiEngine, Request or WikiPage.
+     * Creates a new WikiContext, without a WikiEngine, Request or WikiPage. This constructor should
+     * <em>never be called;</em> factory methods such as {@link WikiEngine#createContext(HttpServletRequest, String)}
+     * and {@link WikiActionBeanFactory#newActionBean(HttpServletRequest, HttpServletResponse, Class)} should
+     * be used instead.
      */
     public WikiContext()
     {
@@ -157,6 +169,27 @@
     }
 
     /**
+     * {@inheritDoc}
+     * @see com.ecyrd.jspwiki.action.WikiActionBean#getContentTemplate()
+     */
+    public String getContentTemplate()
+    {
+        return super.getContentTemplate();
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.ecyrd.jspwiki.action.WikiActionBean#getJSP()
+     */
+    public String getJSP()
+    {
+        return super.getJSP();
+    }
+
+    /**
+     *  Sets a reference to the real page whose content is currently being
+     *  rendered.
+     *  <p>
      *  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
@@ -202,11 +235,19 @@
     }
 
     /**
-     *  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.
+     *  Returns the handling engine.
+     *
+     *  @return The wikiengine owning this context.
+     */
+    public WikiEngine getEngine()
+    {
+        return super.getEngine();
+    }
+
+    /**
+     *  Returns the page that is being handled.
+     *
+     *  @return the page which was fetched.
      */
     public WikiPage getPage()
     {
@@ -214,8 +255,7 @@
     }
 
     /**
-     *  Sets the page that is being handled. Calling this
-     *  method also re-sets the "real page" to the same value.
+     *  Sets the page that is being handled.
      *
      *  @param page The wikipage
      *  @since 2.1.37.
@@ -228,26 +268,62 @@
     }
 
     /**
-     * If the WikiPage contains a template attribute ({@link WikiEngine#PROP_TEMPLATEDIR}),
-     * this method returns its value; otherwise, it returns superclass value via
-     * {@link AbstractActionBean#getTemplate()}.
+     *  Returns the request context.
+     *  @return The name of the request context (e.g. VIEW).
      */
-    @Override
-    public String getTemplate()
+    public String getRequestContext()
     {
-        if ( m_page != null )
-        {
-            String template = (String) m_page.getAttribute(WikiEngine.PROP_TEMPLATEDIR);
-            if ( template != null )
-            {
-                return template;
-            }
-        }
-        return super.getTemplate();
+        return super.getRequestContext();
+    }
+
+    /**
+     * Sets the request context. See above for the different request contexts
+     * (VIEW, EDIT, etc.) This argument must correspond exactly to the value of
+     * a Stripes event handler method's
+     * {@link com.ecyrd.jspwiki.action.WikiRequestContext} annotation for the
+     * bean class. For event handlers that do not have an
+     * {@linkplain com.ecyrd.jspwiki.action.WikiRequestContext} annotation,
+     * callers can supply a request context value based on the bean class and
+     * the event name; see the
+     * {@link com.ecyrd.jspwiki.action.HandlerInfo#getRequestContext()}
+     * documentation for more details.
+     * 
+     * @param arg The request context (one of the predefined contexts.)
+     * @throws if the supplied request context does not correspond
+     * to a {@linkplain com.ecyrd.jspwiki.action.WikiRequestContext}
+     * annotation, or the automatically request context name
+     */
+    public void setRequestContext( String arg )
+    {
+        super.setRequestContext( arg );
+    }
+
+    /**
+     *  Gets a previously set variable.
+     *
+     *  @param key The variable name.
+     *  @return The variable contents.
+     */
+    public Object getVariable( String key )
+    {
+        return super.getVariable( key );
     }
 
     /**
-     *  This method will safely return any HTTP parameters that 
+     *  Sets a variable.  The variable is valid while the WikiContext is valid,
+     *  i.e. while page processing continues.  The variable data is discarded
+     *  once the page processing is finished.
+     *
+     *  @param key The variable name.
+     *  @param data The variable value.
+     */
+    public void setVariable( String key, Object data )
+    {
+        super.setVariable( key, data );
+    }
+
+    /**
+     *  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,
@@ -259,14 +335,7 @@
      */
     public String getHttpParameter( String paramName )
     {
-        String result = null;
-
-        if( getContext() != null )
-        {
-            result = getContext().getRequest().getParameter( paramName );
-        }
-
-        return result;
+        return super.getHttpParameter( paramName );
     }
 
     /**
@@ -276,13 +345,22 @@
      *  return null, and YOU SHOULD CHECK FOR IT!
      *
      *  @return Null, if no HTTP request was done.
-     *  @deprecated use the method {@link #getContext()} to obtain the ActionBeanContext,
-     *  and call {@link com.ecyrd.jspwiki.action.WikiActionBeanContext#getRequest()} method.
      *  @since 2.0.13.
      */
     public HttpServletRequest getHttpRequest()
     {
-        return getContext().getRequest();
+        return super.getHttpRequest();
+    }
+
+    /**
+     *  Sets the template to be used for this request.
+     *
+     *  @param dir The template name
+     *  @since 2.1.15.
+     */
+    public void setTemplate( String dir )
+    {
+        super.setTemplate( dir );
     }
 
     /**
@@ -295,26 +373,83 @@
     }
 
     /**
-     * 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
+     *  Gets the template that is to be used throughout this request.
+     *  @since 2.1.15.
+     *  @return template name
+     */
+    public String getTemplate()
+    {
+        return super.getTemplate();
+    }
+
+    /**
+     *  Convenience method that gets the current user. Delegates the
+     *  lookup to the WikiSession associated with this WikiContect.
+     *  May return null, in case the current
+     *  user has not yet been determined; or this is an internal system.
+     *  If the WikiSession has not been set, <em>always</em> returns null.
+     *
+     *  @return The current user; or maybe null in case of internal calls.
+     */
+    public Principal getCurrentUser()
+    {
+        return super.getCurrentUser();
+    }
+
+    /**
+     *  A shortcut to generate a VIEW url.
+     *
+     *  @param page The page to which to link.
+     *  @return An URL to the page.  This honours the current absolute/relative setting.
      */
     public String getViewURL( String page )
     {
-        boolean absolute = "absolute".equals(getEngine().getVariable( this, WikiEngine.PROP_REFSTYLE ));
-        return getContext().getURL( ViewActionBean.class, page, null, absolute );
+        return getURL( VIEW, page, null );
+    }
+
+    /**
+     *  Creates an URL for the given request context.
+     *
+     *  @param context e.g. WikiContext.EDIT
+     *  @param page The page to which to link
+     *  @return An URL to the page, honours the absolute/relative setting in jspwiki.properties
+     */
+    public String getURL( String context,
+                          String page )
+    {
+        return getURL( context, page, null );
+    }
+
+    /**
+     *  Returns an URL from a page. It this WikiContext instance was constructed
+     *  with an actual HttpServletRequest, we will attempt to construct the
+     *  URL using HttpUtil, which preserves the HTTPS portion if it was used.
+     *
+     *  @param context The request context (e.g. WikiContext.UPLOAD)
+     *  @param page    The page to which to link
+     *  @param params  A list of parameters, separated with "&amp;"
+     *
+     *  @return An URL to the given context and page.
+     */
+    public String getURL( String context,
+                          String page,
+                          String params )
+    {
+        boolean absolute = "absolute".equals( getEngine().getVariable( this, WikiEngine.PROP_REFSTYLE ) );
+
+        // FIXME: is rather slow
+        return getEngine().getURL( context,
+                                page,
+                                params,
+                                absolute );
+
     }
 
     /**
      *  Returns a shallow clone of the WikiContext.
      *
      *  @since 2.1.37.
-     *  //TODO: this could be a problem...
+     *  @return A shallow clone of the WikiContext
      */
     public Object clone()
     {
@@ -339,6 +474,140 @@
     }
 
     /**
+     *  Returns the WikiSession associated with the context.
+     *  This method is guaranteed to always return a valid WikiSession.
+     *  If this context was constructed without an associated
+     *  HttpServletRequest, it will return {@link WikiSession#guestSession(WikiEngine)}.
+     *
+     *  @return The WikiSession associate with this context.
+     */
+    public WikiSession getWikiSession()
+    {
+        return super.getWikiSession();
+    }
+
+    /**
+     *  This method can be used to find the WikiContext programmatically
+     *  from a JSP PageContext. We check the request context. 
+     *  The wiki context, if it exists,
+     *  is looked up using the key
+     *  {@link com.ecyrd.jspwiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     *
+     *  @since 2.4
+     *  @param pageContext the JSP page context
+     *  @return Current WikiContext, or null, of no context exists.
+     */
+    public static WikiContext findContext( PageContext pageContext )
+    {
+        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
+        WikiContext context = (WikiContext)request.getAttribute( WikiTagBase.ATTR_CONTEXT );
+        return context;
+    }
+
+    /**
+     * Checks whether the current user has access to this wiki context,
+     * by obtaining the required Permission ({@link #requiredPermission()})
+     * and delegating the access check to
+     * {@link com.ecyrd.jspwiki.auth.AuthorizationManager#checkPermission(WikiSession, Permission)}.
+     * If the user is allowed, this method returns <code>true</code>;
+     * <code>false</code> otherwise. If access is allowed,
+     * the wiki context will be added to the request as an attribute
+     * with the key name {@link com.ecyrd.jspwiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     * Note that this method will automatically redirect the user to
+     * a login or error page, as appropriate, if access fails. This is
+     * NOT guaranteed to be default behavior in the future.
+     * @param response the http response
+     * @return the result of the access check
+     * @throws IOException In case something goes wrong
+     * @deprecated callers should not need to call this method, and should rely on {@link WikiInterceptor} instead to control access
+     */
+    public boolean hasAccess( HttpServletResponse response ) throws IOException
+    {
+        return hasAccess( response, true );
+    }
+
+    /**
+     * Checks whether the current user has access to this wiki context (and
+     * optionally redirects if not), by obtaining the required Permission ({@link #requiredPermission()})
+     * and delegating the access check to
+     * {@link com.ecyrd.jspwiki.auth.AuthorizationManager#checkPermission(WikiSession, Permission)}.
+     * If the user is allowed, this method returns <code>true</code>;
+     * <code>false</code> otherwise. If access is allowed,
+     * the wiki context will be added to the request as attribute
+     * with the key name {@link com.ecyrd.jspwiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     * Note: for 3.0, this method obtains the required permission by looking up its permission information
+     * by calling {@link com.ecyrd.jspwiki.action.HandlerInfo#getDefaultHandlerInfo(Class)}.
+     * The method that contains the {@link net.sourceforge.stripes.action.DefaultHandler} annotation
+     * is the one that will be used to determine the correct permission. If no method containing a
+     * DefaultHandler is found, this method returns <code>true</code>.
+     * @return the result of the access check
+     * @param response The servlet response object
+     * @param redirect If true, makes an automatic redirect to the response
+     * @throws IOException If something goes wrong
+     * @deprecated callers should not need to call this method, and should rely on {@link WikiInterceptor} instead to control access
+     */
+    public boolean hasAccess( HttpServletResponse response, boolean redirect ) throws IOException
+    {
+        // Look up the HandlerInfo for the current Stripes event handler
+        String eventMethod = getContext().getEventName();
+        HandlerInfo handlerInfo;
+        if ( eventMethod == null )
+        {
+            handlerInfo = HandlerInfo.getDefaultHandlerInfo( this.getClass() );
+        }
+        else
+        {
+            handlerInfo = HandlerInfo.getHandlerInfo( this.getClass(), eventMethod );
+        }
+        
+        // Get the required permission
+        Permission requiredPermission = null;
+        try
+        {
+            requiredPermission = handlerInfo.getPermission( this );
+        }
+        catch ( ELException e ) {
+            log.error( "Could not evaluate event handler permission for  " + this.getClass() + ", method=" + handlerInfo.getHandlerMethod().getName() );
+        }
+        
+        WikiSession wikiSession = getWikiSession();
+        AuthorizationManager mgr = getEngine().getAuthorizationManager();
+        boolean allowed = requiredPermission == null ? true : mgr.checkPermission( getWikiSession(), requiredPermission );
+        ResourceBundle rb = getBundle( InternationalizationManager.CORE_BUNDLE );
+
+        // Stash the wiki context
+        if( allowed )
+        {
+            if ( getContext().getRequest().getAttribute( WikiTagBase.ATTR_CONTEXT ) == null )
+            {
+                getContext().getRequest().setAttribute( WikiTagBase.ATTR_CONTEXT, this );
+            }
+        }
+
+        // If access not allowed, redirect
+        if( !allowed && redirect )
+        {
+            Principal currentUser  = wikiSession.getUserPrincipal();
+            Object[] arguments = { getName() };
+            if( wikiSession.isAuthenticated() )
+            {
+                log.info("User "+currentUser.getName()+" has no access - forbidden (permission=" + requiredPermission + ")" );
+                String pageurl = m_page.getName();
+                wikiSession.addMessage( MessageFormat.format( rb.getString("security.error.noaccess.logged"), arguments) );
+                response.sendRedirect( getEngine().getURL(WikiContext.LOGIN, pageurl, null, false ) );
+            }
+            else
+            {
+                log.info("User "+currentUser.getName()+" has no access - redirecting (permission=" + requiredPermission + ")");
+                String pageurl = m_page.getName();
+                wikiSession.addMessage( MessageFormat.format( rb.getString("security.error.noaccess"), arguments) );
+                response.sendRedirect( getEngine().getURL(WikiContext.LOGIN, pageurl, null, false ) );
+            }
+        }
+        return allowed;
+    }
+
+    /**
      *  Returns true, if the current user has administrative permissions (i.e. the omnipotent
      *  AllPermission).
      *
@@ -348,10 +617,45 @@
     public boolean hasAdminPermissions()
     {
         boolean admin = false;
-        WikiEngine engine = getEngine();
-        admin = engine.getAuthorizationManager().checkPermission( getWikiSession(), 
-                                                                    new AllPermission(engine.getApplicationName()) );
+
+        WikiEngine m_engine = getEngine();
+        admin = m_engine.getAuthorizationManager().checkPermission( getWikiSession(),
+                                                                    new AllPermission(m_engine.getApplicationName()) );
+
         return admin;
     }
 
+    /**
+     *  Locates the i18n ResourceBundle given.  This method interprets
+     *  the request locale, and uses that to figure out which language the
+     *  user wants.
+     *  @see com.ecyrd.jspwiki.i18n.InternationalizationManager
+     *  @param bundle The name of the bundle you are looking for.
+     *  @return A resource bundle object
+     *  @throws MissingResourceException If the bundle cannot be found
+     */
+    // FIXME: This method should really cache the ResourceBundles or something...
+    public ResourceBundle getBundle( String bundle ) throws MissingResourceException
+    {
+        return super.getBundle( bundle );
+    }
+
+    /**
+     *  Returns the locale of the HTTP request if available,
+     *  otherwise returns the default Locale of the server.
+     *
+     *  @return A valid locale object
+     *  @param context The WikiContext
+     *  @deprecated use {@link com.ecyrd.jspwiki.action.WikiActionBeanContext#getLocale()} instead
+     */
+    public static Locale getLocale( WikiContext context )
+    {
+        return Preferences.getLocale( context );
+/*
+        HttpServletRequest request = context.getHttpRequest();
+        return ( request != null )
+                ? request.getLocale() : Locale.getDefault();
+*/
+    }
+
 }

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiEngine.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiEngine.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiEngine.java Sun Aug  3 05:12:47 2008
@@ -1,21 +1,22 @@
-/*
+/* 
     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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.  
  */
 package com.ecyrd.jspwiki;
 
@@ -31,11 +32,13 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
+import com.ecyrd.jspwiki.action.HandlerInfo;
 import com.ecyrd.jspwiki.action.WikiActionBean;
 import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
 import com.ecyrd.jspwiki.attachment.Attachment;
@@ -46,6 +49,7 @@
 import com.ecyrd.jspwiki.auth.acl.AclManager;
 import com.ecyrd.jspwiki.auth.acl.DefaultAclManager;
 import com.ecyrd.jspwiki.auth.authorize.GroupManager;
+import com.ecyrd.jspwiki.content.PageRenamer;
 import com.ecyrd.jspwiki.diff.DifferenceManager;
 import com.ecyrd.jspwiki.event.WikiEngineEvent;
 import com.ecyrd.jspwiki.event.WikiEventListener;
@@ -67,6 +71,7 @@
 import com.ecyrd.jspwiki.ui.TemplateManager;
 import com.ecyrd.jspwiki.ui.admin.AdminBeanManager;
 import com.ecyrd.jspwiki.ui.progress.ProgressManager;
+import com.ecyrd.jspwiki.url.URLConstructor;
 import com.ecyrd.jspwiki.util.ClassUtil;
 import com.ecyrd.jspwiki.util.WatchDog;
 import com.ecyrd.jspwiki.workflow.*;
@@ -84,8 +89,6 @@
  *  <p>
  *  There's basically only a single WikiEngine for each web application, and
  *  you should always get it using the WikiEngine.getInstance() method.
- *
- *  @author Janne Jalkanen
  */
 public class WikiEngine
 {
@@ -140,6 +143,10 @@
     /** Property name for the default front page. */
     public static final String PROP_FRONTPAGE    = "jspwiki.frontPage";
 
+    /** Property name for setting the url generator instance */
+
+    public static final String PROP_URLCONSTRUCTOR = "jspwiki.urlConstructor";
+
     /** If this property is set to false, all filters are disabled when translating. */
     public static final String PROP_RUNFILTERS   = "jspwiki.runFilters";
 
@@ -149,6 +156,9 @@
     /** The name of the property containing the ACLManager implementing class.
      *  The value is {@value}. */
     public static final String PROP_ACL_MANAGER_IMPL = "jspwiki.aclManager";
+    
+    /** If this property is set to false, we don't allow the creation of empty pages */
+    public static final String PROP_ALLOW_CREATION_OF_EMPTY_PAGES = "jspwiki.allowCreationOfEmptyPages";
 
     /** Should the user info be saved with the page data as well? */
     private boolean          m_saveUserInfo = true;
@@ -156,9 +166,6 @@
     /** If true, uses UTF8 encoding for all data */
     private boolean          m_useUTF8      = true;
 
-    /** If true, always generate absolute URLs. */
-    private boolean         m_absoluteUrls = false;
-
     /** Stores the base URL. */
     private String           m_baseURL;
 
@@ -218,6 +225,9 @@
 
     private ProgressManager  m_progressManager;
 
+    /** Constructs URLs */
+    private URLConstructor   m_urlConstructor;
+
     /** Generates RSS feed when requested. */
     private RSSGenerator     m_rssGenerator;
 
@@ -254,6 +264,9 @@
 
     private AdminBeanManager m_adminBeanManager;
 
+    /** Stores wikiengine attributes. */
+    private Map<String,Object> m_attributes = Collections.synchronizedMap(new HashMap<String,Object>());
+
     /**
      *  Gets a WikiEngine related to this servlet.  Since this method
      *  is only called from JSP pages (and JspInit()) to be specific,
@@ -327,6 +340,7 @@
                 }
 
                 engine = new WikiEngine( context, appid, props );
+                context.setAttribute( ATTR_WIKIENGINE, engine );
             }
             catch( Exception e )
             {
@@ -376,14 +390,14 @@
         if ( context != null )
         {
             context.setAttribute( ATTR_WIKIENGINE,  this );
-            //
-            //  Note: May be null, if JSPWiki has been deployed in a WAR file.
-            //
             m_rootPath = context.getRealPath("/");
         }
         
         try
         {
+            //
+            //  Note: May be null, if JSPWiki has been deployed in a WAR file.
+            //
             initialize( props );
             log.info("Root path for this Wiki is: '"+m_rootPath+"'");
         }
@@ -484,7 +498,7 @@
 
         m_useUTF8        = "UTF-8".equals( TextUtil.getStringProperty( props, PROP_ENCODING, "ISO-8859-1" ) );
         m_baseURL        = TextUtil.getStringProperty( props, PROP_BASEURL, "" );
-        m_absoluteUrls = "absolute".equals( m_properties.getProperty( PROP_REFSTYLE ) );
+
 
         m_beautifyTitle  = TextUtil.getBooleanProperty( props,
                                                         PROP_BEAUTIFYTITLE,
@@ -493,9 +507,6 @@
         m_templateDir    = TextUtil.getStringProperty( props, PROP_TEMPLATEDIR, "default" );
         m_frontPage      = TextUtil.getStringProperty( props, PROP_FRONTPAGE,   "Main" );
 
-        //  Initializes the WikiActionBeanResolver -- this MUST be done after setting the baseURL
-        m_beanFactory  = new WikiActionBeanFactory( this, props );
-
         //
         //  Initialize the important modules.  Any exception thrown by the
         //  managers means that we will not start up.
@@ -505,6 +516,14 @@
         //        of a better way to do the startup-sequence.
         try
         {
+            //  Initialize the WikiActionBeanResolver -- this MUST be done after setting the baseURL
+            m_beanFactory  = new WikiActionBeanFactory( this, props );
+            
+            Class urlclass = ClassUtil.findClass( "com.ecyrd.jspwiki.url",
+                    TextUtil.getStringProperty( props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor" ) );
+            m_urlConstructor = (URLConstructor) urlclass.newInstance();
+            m_urlConstructor.initialize( this, props );
+
             m_pageManager       = (PageManager)ClassUtil.getMappedObject(PageManager.class.getName(), this, props );
             m_pluginManager     = (PluginManager)ClassUtil.getMappedObject(PluginManager.class.getName(), this, props );
             m_differenceManager = (DifferenceManager)ClassUtil.getMappedObject(DifferenceManager.class.getName(), this, props );
@@ -580,7 +599,29 @@
             log.fatal( "Failed to start managers.", e );
             throw new WikiException( "Failed to start managers: "+e.getMessage() );
         }
-
+        catch (ClassNotFoundException e)
+        {
+            log.fatal( "JSPWiki could not start, URLConstructor was not found: ",e );
+            throw new WikiException(e.getMessage());
+        }
+        catch (InstantiationException e)
+        {
+            log.fatal( "JSPWiki could not start, URLConstructor could not be instantiated: ",e );
+            throw new WikiException(e.getMessage());
+        }
+        catch (IllegalAccessException e)
+        {
+            log.fatal( "JSPWiki could not start, URLConstructor cannot be accessed: ",e );
+            throw new WikiException(e.getMessage());
+        }
+        catch( Exception e )
+        {
+            // Final catch-all for everything
+            
+            log.fatal( "JSPWiki could not start, due to an unknown exception when starting.",e );
+            throw new WikiException("Failed to start; please check log files for better information.");
+        }
+        
         //
         //  Initialize the good-to-have-but-not-fatal modules.
         //
@@ -635,6 +676,7 @@
      *
      *  @throws WikiException If the reference manager initialization fails.
      */
+    @SuppressWarnings("unchecked")
     public void initReferenceManager() throws WikiException
     {
         try
@@ -686,16 +728,17 @@
     }
 
     /**
-     *  Returns a copy of the properties that the WikiEngine was initialized
-     *  with.
+     *  Returns the set of properties that the WikiEngine was initialized
+     *  with.  Note that this method returns a direct reference, so it's possible
+     *  to manipulate the properties.  However, this is not advised unless you
+     *  really know what you're doing.
+     *
      *  @return The wiki properties
      */
 
     public Properties getWikiProperties()
     {
-        Properties propsCopy = new Properties();
-        propsCopy.putAll( m_properties );
-        return propsCopy;
+        return m_properties;
     }
 
     /**
@@ -713,6 +756,7 @@
      *  Don't use.
      *  @since 1.8.0
      *  @deprecated
+     *  @return Something magical.
      */
     public String getPluginSearchPath()
     {
@@ -766,6 +810,78 @@
     }
 
     /**
+     * <p>
+     * Returns the basic absolute URL to a page, without any modifications. You
+     * may add any parameters to this.
+     * </p>
+     * <p>
+     * Since 2.3.90 it is safe to call this method with <code>null</code>
+     * pageName, in which case it will default to the front page.
+     * </p>
+     * @since 2.0.3
+     * @param pageName The name of the page.  May be null, in which case defaults to the front page.
+     * @return An absolute URL to the page.
+     * @deprecated
+     */
+    public String getViewURL( String pageName )
+    {
+        if( pageName == null )
+        {
+            pageName = getFrontPage();
+        }
+        return getURLConstructor().makeURL( WikiContext.VIEW, pageName, true, null );
+    }
+
+    /**
+     *  Returns the basic URL to an editor.  Please use WikiContext.getURL() or
+     *  WikiEngine.getURL() instead.
+     *
+     *  @see #getURL(String, String, String, boolean)
+     *  @see WikiContext#getURL(String, String)
+     *  @deprecated
+     *  
+     *  @param pageName The name of the page.
+     *  @return An URI.
+     *
+     *  @since 2.0.3
+     */
+    public String getEditURL( String pageName )
+    {
+        return m_urlConstructor.makeURL( WikiContext.EDIT, pageName, false, null );
+    }
+
+    /**
+     *  Returns the basic attachment URL.Please use WikiContext.getURL() or
+     *  WikiEngine.getURL() instead.
+     *
+     *  @see #getURL(String, String, String, boolean)
+     *  @see WikiContext#getURL(String, String)
+     *  @since 2.0.42.
+     *  @param attName Attachment name
+     *  @deprecated
+     *  @return An URI.
+     */
+    public String getAttachmentURL( String attName )
+    {
+        return m_urlConstructor.makeURL( WikiContext.ATTACH, attName, false, null );
+    }
+
+    /**
+     *  Returns an URL if a WikiContext is not available.
+     *
+     *  @param context The WikiContext (VIEW, EDIT, etc...)
+     *  @param pageName Name of the page, as usual
+     *  @param params List of parameters. May be null, if no parameters.
+     *  @param absolute If true, will generate an absolute URL regardless of properties setting.
+     *  @return An URL (absolute or relative).
+     */
+    public String getURL( String context, String pageName, String params, boolean absolute )
+    {
+        if( pageName == null ) pageName = getFrontPage();
+        return m_urlConstructor.makeURL( context, pageName, absolute, params );
+    }
+
+    /**
      *  Returns the default front page, if no page is used.
      *
      *  @return The front page name.
@@ -803,6 +919,9 @@
      *  Incidentally, this is almost the same as encodeName(), below.
      *  I am not yet entirely sure if it's safe to merge the code.
      *
+     *  @param request The servlet request
+     *  @param name    The parameter name to get.
+     *  @return The parameter value or null
      *  @since 1.5.3
      *  @deprecated JSPWiki now requires servlet API 2.3, which has a better
      *              way of dealing with this stuff.  This will be removed in
@@ -926,6 +1045,26 @@
     }
 
     /**
+     *  <p>If the page is a special page, then returns a direct URL
+     *  to that page.  Otherwise returns <code>null</code>.
+     *  This method delegates requests to
+     *  {@link com.ecyrd.jspwiki.ui.CommandResolver#getSpecialPageReference(String)}.
+     *  </p>
+     *  <p>
+     *  Special pages are defined in jspwiki.properties using the jspwiki.specialPage
+     *  setting.  They're typically used to give Wiki page names to e.g. custom JSP
+     *  pages.
+     *  </p>
+     *
+     *  @param original The page to check
+     *  @return A reference to the page, or null, if there's no special page.
+     */
+    public String getSpecialPageReference( String original )
+    {
+        return m_beanFactory.getSpecialPageReference( original );
+    }
+
+    /**
      *  Returns the name of the application.
      *
      *  @return A string describing the name of this application.
@@ -936,7 +1075,7 @@
     {
         String appName = TextUtil.getStringProperty(m_properties,PROP_APPNAME,Release.APPNAME);
 
-        return appName;
+        return MarkupParser.cleanLink( appName );
     }
 
     /**
@@ -1333,7 +1472,7 @@
     {
         WikiPage page = getPage( pagename, version );
 
-        WikiContext context = m_beanFactory.newViewActionBean( page );
+        WikiContext context = m_beanFactory.newViewActionBean( null, null, page );
 
         String res = getHTML( context, page );
 
@@ -1397,11 +1536,11 @@
      *  @param pagedata The page contents
      *  @return a Collection of Strings
      */
-    protected Collection<String> scanWikiLinks( WikiPage page, String pagedata )
+    public Collection scanWikiLinks( WikiPage page, String pagedata )
     {
         LinkCollector localCollector = new LinkCollector();
 
-        textToHTML( m_beanFactory.newViewActionBean( page ),
+        textToHTML( m_beanFactory.newViewActionBean( null, null, page ),
                     pagedata,
                     localCollector,
                     null,
@@ -1573,6 +1712,15 @@
             return;
         }
 
+        // Check if creation of empty pages is allowed; bail if not
+        boolean allowEmpty = TextUtil.getBooleanProperty( m_properties, 
+                                                          PROP_ALLOW_CREATION_OF_EMPTY_PAGES, 
+                                                          false );
+        if ( !allowEmpty && !pageExists( page ) && text.trim().equals( "" ) )  
+        {
+            return;
+        }
+        
         // Create approval workflow for page save; add the diffed, proposed
         // and old text versions as Facts for the approver (if approval is required)
         // If submitter is authenticated, any reject messages will appear in his/her workflow inbox.
@@ -1649,11 +1797,12 @@
 
     // FIXME: Should really get a Date object and do proper comparisons.
     //        This is terribly wasteful.
-    public Collection<WikiPage> getRecentChanges()
+    @SuppressWarnings("unchecked")
+    public Collection getRecentChanges()
     {
         try
         {
-            Collection<WikiPage> pages = m_pageManager.getAllPages();
+            Collection<WikiPage>   pages = m_pageManager.getAllPages();
             Collection<Attachment>  atts = m_attachmentManager.getAllAttachments();
 
             TreeSet<WikiPage> sortedPages = new TreeSet<WikiPage>( new PageTimeComparator() );
@@ -1851,16 +2000,16 @@
      *  throw a NoSuchVariableException, but returns null in case the variable does
      *  not exist.
      *
-     *  @param actionBean WikiActionBean to look up the variable in
+     *  @param context WikiActionBean to look up the variable in
      *  @param name Name of the variable to look for
      *  @return Variable value, or null, if there is no such variable.
      *  @since 2.2
      */
-    public String getVariable( WikiActionBean actionBean, String name )
+    public String getVariable( WikiActionBean context, String name )
     {
         try
         {
-            return m_variableManager.getValue( actionBean, name );
+            return m_variableManager.getValue( context, name );
         }
         catch( NoSuchVariableException e )
         {
@@ -1880,8 +2029,8 @@
     }
 
     /**
-     * Returns the CommandResolver for this wiki engine.
-     * @return the resolver
+     * Returns the WikiActionBeanFactory for this wiki engine.
+     * @return the factory
      */
     public WikiActionBeanFactory getWikiActionBeanFactory()
     {
@@ -1951,6 +2100,53 @@
     }
 
     /**
+     *  Shortcut to create a WikiContext from a supplied HTTP request,
+     *  using a default wiki context.
+     *  @param request the HTTP request
+     *  @param requestContext the default context to use
+     *  @return a new WikiContext object.
+     *  @deprecated use WikiActionBeanFactory instead, especially for WikiActionBeans that are not page-related.
+     *  This method returns <em>only</em> WikiContexts, not other WikiActionBean types
+     *  @since 2.1.15.
+     */
+    // FIXME: We need to have a version which takes a fixed page
+    //        name as well, or check it elsewhere.
+    public WikiContext createContext( HttpServletRequest request,
+                                      String requestContext )
+    {
+        if( !m_isConfigured )
+        {
+            throw new InternalWikiException("WikiEngine has not been properly started.  It is likely that the configuration is faulty.  Please check all logs for the possible reason.");
+        }
+        
+        // Find the WikiActionBean and event handler for this request context
+        HandlerInfo handler = m_beanFactory.findEventHandler( requestContext );
+        if( handler == null )
+        {
+            log.error( "No HandlerInfo found for request context '" + requestContext + "'! Check your annotations." );
+            return null;
+        }
+        Class<? extends WikiActionBean> beanClass = handler.getActionBeanClass();
+        
+        // Build the wiki context... dummy reply and response objects will be added by WikiActionBeanFactory
+        try
+        {
+            WikiActionBean actionBean = m_beanFactory.newActionBean( request, (HttpServletResponse)null, beanClass );
+            actionBean.getContext().setEventName( handler.getEventName() );
+            if ( actionBean instanceof WikiContext )
+            {
+                return (WikiContext)actionBean;
+            }
+            throw new IllegalArgumentException( "Context '" + requestContext + "' resolved to non-WikiContext action bean class!" );
+        }
+        catch ( WikiException e )
+        {
+            log.error( "Could not create context: " + e.getMessage() );
+            return null;
+        }
+    }
+
+    /**
      *  Deletes a page or an attachment completely, including all versions.  If the page
      *  does not exist, does nothing.
      *
@@ -2031,6 +2227,16 @@
     }
 
     /**
+     * @since 2.2.6
+     * @return the URL constructor
+     * @deprecated
+     */
+    public URLConstructor getURLConstructor()
+    {
+        return m_urlConstructor;
+    }
+
+    /**
      * @since 2.1.165
      * @return the RSS generator
      */
@@ -2194,31 +2400,6 @@
             WikiEventManager.fireEvent(this,new WikiEngineEvent(this,type));
         }
     }
-    
-    /**
-     * Returns <code>true</code> if this WikiEngine has been successfully
-     * initialized; <code>false</code> otherwise.
-     * @return the initialization status
-     */
-    public boolean isConfigured()
-    {
-        return m_isConfigured;
-    }
-    
-    /**
-     * Returns <code>true</code> if this WikiEngine is configured to use
-     * absolute references when generating URLs. The absolute reference will
-     * begin with the "base URL" configured by the property <code>jspwiki.baseURL</code>
-     * in <code>jspwiki.properties</code>. This value can also be obtained by
-     * calling {@link #getBaseURL()}.
-     * @return <code>true</code> if the wiki generates absolute URLs
-     */
-    public boolean useAbsoluteUrls()
-    {
-        return m_absoluteUrls;
-    }
-
-    private Map<String,Object> m_attributes = Collections.synchronizedMap(new HashMap<String,Object>());
 
     /**
      * Adds an attribute to the engine for the duration of this engine.  The

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiException.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiException.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiException.java Sun Aug  3 05:12:47 2008
@@ -1,28 +1,28 @@
-/* 
+/*
     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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.     
  */
 package com.ecyrd.jspwiki;
 
 /**
  *  A generic Wiki exception.
  *
- *  @author Janne Jalkanen
  *  @since 2.0
  */
 public class WikiException

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java Sun Aug  3 05:12:47 2008
@@ -1,32 +1,30 @@
-/* 
+/*
     JSPWiki - a JSP-based WikiWiki clone.
 
-    Copyright (C) 2001 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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
  */
 package com.ecyrd.jspwiki;
 
-import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.ecyrd.jspwiki.attachment.Attachment;
 import com.ecyrd.jspwiki.auth.acl.Acl;
-import com.ecyrd.jspwiki.providers.ProviderException;
 import com.ecyrd.jspwiki.providers.WikiPageProvider;
 
 /**
@@ -51,8 +49,7 @@
     private long             m_fileSize = -1;
     private int              m_version = WikiPageProvider.LATEST_VERSION;
     private String           m_author = null;
-    private final HashMap    m_attributes = new HashMap();
-    private String           m_qualifiedName;
+    private final HashMap<String,Object> m_attributes = new HashMap<String,Object>();
 
     /**
      *  "Summary" is a short summary of the page.  It is a String.
@@ -81,7 +78,6 @@
         m_engine = engine;
         m_name = name;
         m_wiki = engine.getApplicationName();
-        m_qualifiedName =m_wiki + ":" + m_name;
     }
 
     /**
@@ -93,25 +89,8 @@
     {
         return m_name;
     }
-    
-    public String getQualifiedName()
-    {
-        return m_qualifiedName;
-    }
 
     /**
-     * Convenience method that returns the collection of 
-     * Attachment objects associated with this WikiPage.
-     * It simply delegates to
-     * {@link com.ecyrd.jspwiki.attachment.AttachmentManager#listAttachments(WikiPage)}.
-     * @return the collection
-     */
-    public Collection<Attachment> getAttachments() throws ProviderException
-    {
-        return m_engine.getAttachmentManager().listAttachments( this );
-    }
-    
-    /**
      *  A WikiPage may have a number of attributes, which might or might not be 
      *  available.  Typically attributes are things that do not need to be stored
      *  with the wiki page to the page repository, but are generated
@@ -129,7 +108,7 @@
     /**
      *  Sets an metadata attribute.
      *  
-     *  @see #getAttribute()
+     *  @see #getAttribute(String)
      *  @param key The key for the attribute used to fetch the attribute later on.
      *  @param attribute The attribute value
      */
@@ -386,6 +365,9 @@
      *  
      *  {@inheritDoc}
      */
+    // TODO: I have a suspicion that defining this method causes some problems
+    //       with page attributes and caching.  So as of 2.7.32, it's disabled.
+    /*
     public boolean equals( Object o )
     {
         if( o != null && o instanceof WikiPage )
@@ -403,7 +385,7 @@
         
         return false;
     }
-    
+    */
     /**
      *  {@inheritDoc}
      */

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiProvider.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiProvider.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiProvider.java Sun Aug  3 05:12:47 2008
@@ -1,21 +1,22 @@
-/* 
+/*
     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
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.     
  */
 package com.ecyrd.jspwiki;
 
@@ -26,7 +27,6 @@
  *  A generic Wiki provider for all sorts of things that the Wiki can
  *  store.
  *
- *  @author Janne Jalkanen
  *  @since 2.0
  */
 public interface WikiProvider

Added: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiServlet.java?rev=682139&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiServlet.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiServlet.java Sun Aug  3 05:12:47 2008
@@ -0,0 +1,104 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.     
+ */
+package com.ecyrd.jspwiki;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.io.*;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.url.DefaultURLConstructor;
+
+/**
+ *  This provides a master servlet for dealing with short urls.  It mostly does
+ *  redirects to the proper JSP pages. It also intercepts the servlet
+ *  shutdown events and uses it to signal wiki shutdown.
+ *  
+ *  @author Andrew Jaquith
+ *  @since 2.2
+ */
+public class WikiServlet
+    extends HttpServlet
+{
+    private static final long serialVersionUID = 3258410651167633973L;
+    private WikiEngine m_engine;
+    static final Logger log = Logger.getLogger(WikiServlet.class.getName());
+
+    /**
+     *  {@inheritDoc}
+     */
+    public void init( ServletConfig config )
+        throws ServletException 
+    {
+        super.init( config );
+
+        m_engine         = WikiEngine.getInstance( config );
+
+        log.info("WikiServlet initialized.");
+    }
+
+    /**
+     * Destroys the WikiServlet; called by the servlet container
+     * when shutting down the webapp. This method calls the
+     * protected method {@link WikiEngine#shutdown()}, which
+     * sends {@link com.ecyrd.jspwiki.event.WikiEngineEvent#SHUTDOWN}
+     * events to registered listeners.
+     * @see javax.servlet.GenericServlet#destroy()
+     */
+    public void destroy()
+    {
+        log.info("WikiServlet shutdown.");
+        m_engine.shutdown();
+        super.destroy();
+    }
+
+    /**
+     *  {@inheritDoc}
+     */
+    public void doPost( HttpServletRequest req, HttpServletResponse res )
+        throws IOException, ServletException
+    {
+        doGet( req, res );
+    }
+    
+    /**
+     *  {@inheritDoc}
+     */
+    public void doGet( HttpServletRequest req, HttpServletResponse res ) 
+        throws IOException, ServletException 
+    {
+        String pageName = DefaultURLConstructor.parsePageFromURL( req,
+                                                                  m_engine.getContentEncoding() );
+
+        log.info("Request for page: "+pageName);
+
+        if( pageName == null ) pageName = m_engine.getFrontPage(); // FIXME: Add special pages as well
+        
+        String jspPage = m_engine.getURLConstructor().getForwardPage( req );
+        
+        RequestDispatcher dispatcher = req.getRequestDispatcher("/"+jspPage+"?page="+m_engine.encodeName(pageName)+"&"+req.getQueryString() );
+
+        dispatcher.forward( req, res );
+    }
+}
+
+

Propchange: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/WikiServlet.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message