- If the controller cannot be found, MR searches for a special rescue "rescues/404...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / WizardUtils.cs
blobf29c32fd8192a502e62c64318c0baf20f12ec4f2
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Internal
17 using System;
18 using System.Collections;
20 public abstract class WizardUtils
22 public static String ConstructWizardNamespace(Controller controller)
24 if (controller is WizardStepPage)
26 return ConstructWizardNamespace( (controller as WizardStepPage).WizardController );
29 return String.Format("wizard.{0}", controller.Name);
32 public static bool HasPreviousStep(Controller controller)
34 IRailsEngineContext context = controller.Context;
36 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
38 int currentIndex = (int) context.Session[wizardName + "currentstepindex"];
40 return currentIndex > 0;
43 public static bool HasNextStep(Controller controller)
45 IRailsEngineContext context = controller.Context;
47 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
49 IList stepList = (IList) context.Items["wizard.step.list"];
51 int currentIndex = (int) context.Session[wizardName + "currentstepindex"];
53 return (currentIndex + 1) < stepList.Count;
56 public static String GetPreviousStepName(Controller controller)
58 IRailsEngineContext context = controller.Context;
60 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
62 int curIndex = (int) context.Session[wizardName + "currentstepindex"];
64 IList stepList = (IList) context.Items["wizard.step.list"];
66 if ((curIndex - 1) >= 0)
68 return (String) stepList[curIndex - 1];
71 return null;
74 public static String GetNextStepName(Controller controller)
76 IRailsEngineContext context = controller.Context;
78 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
80 int curIndex = (int) context.Session[wizardName + "currentstepindex"];
82 IList stepList = (IList) context.Items["wizard.step.list"];
84 if ((curIndex + 1) < stepList.Count)
86 return (String) stepList[curIndex + 1];
89 return null;
92 public static void RegisterCurrentStepInfo(Controller controller, String actionName)
94 IRailsEngineContext context = controller.Context;
96 IList stepList = (IList) context.Items["wizard.step.list"];
98 for(int i=0; i < stepList.Count; i++)
100 String stepName = (String) stepList[i];
102 if (actionName == stepName)
104 RegisterCurrentStepInfo(controller, i, stepName);
106 break;
111 public static void RegisterCurrentStepInfo(Controller controller, int stepIndex, String stepName)
113 IRailsEngineContext context = controller.Context;
114 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
116 context.Session[wizardName + "currentstepindex"] = stepIndex;
117 context.Session[wizardName + "currentstep"] = stepName;