Update of /cvsroot/yafdotnet/yafsrc/URLRewriter.NET/Parsers In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25871/yafsrc/URLRewriter.NET/Parsers Added Files: Tag: v1_0_2_NETv2 AddHeaderActionParser.cs AddressConditionParser.cs ConditionActionParser.cs ExistsConditionParser.cs ForbiddenActionParser.cs GoneActionParser.cs HeaderMatchConditionParser.cs IRewriteActionParser.cs IRewriteConditionParser.cs IfRedirectActionParser.cs IfRewriteActionParser.cs MethodConditionParser.cs NotAllowedActionParser.cs NotFoundActionParser.cs NotImplementedActionParser.cs PropertyMatchConditionParser.cs RedirectActionParser.cs RewriteActionParser.cs RewriteActionParserBase.cs SetCookieActionParser.cs SetPropertyActionParser.cs SetStatusActionParser.cs UrlMatchConditionParser.cs Log Message: URL Rewriter class --- NEW FILE: IfRewriteActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parses the rewrite portion of the IF and IFNOT elements. /// </summary> public sealed class IfRewriteActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public IfRewriteActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return String.Format(Constants.AttributeAction, Constants.ElementIf, Constants.ElementRewrite); } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return true; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode rewriteAttribute = node.Attributes.GetNamedItem(Constants.AttrRewrite); if (rewriteAttribute != null) { RewriteProcessing processing = RewriteProcessing.ContinueProcessing; XmlNode processingNode = node.Attributes.GetNamedItem(Constants.AttrProcessing); if (processingNode != null) { if (processingNode.Value == Constants.AttrValueRestart) { processing = RewriteProcessing.RestartProcessing; } else if (processingNode.Value == Constants.AttrValueStop) { processing = RewriteProcessing.StopProcessing; } else if (processingNode.Value != Constants.AttrValueContinue) { throw new ConfigurationException(MessageProvider.FormatString(Message.ValueOfProcessingAttribute, processingNode.Value, Constants.AttrValueContinue, Constants.AttrValueRestart, Constants.AttrValueStop), node); } } return new RewriteAction(rewriteAttribute.Value, processing); } else { return null; } } } } --- NEW FILE: GoneActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for GoneActionParser. /// </summary> public sealed class GoneActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public GoneActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementGone; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return false; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { return new GoneAction(); } } } --- NEW FILE: UrlMatchConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for url match conditions. /// </summary> public sealed class UrlMatchConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode matchAttr = node.Attributes.GetNamedItem(Constants.AttrUrl); if (matchAttr != null) { return new UrlMatchCondition(matchAttr.Value); } return null; } } } --- NEW FILE: NotImplementedActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for ForbiddenActionParser. /// </summary> public sealed class NotImplementedActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public NotImplementedActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementNotImplemented; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return false; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { return new NotImplementedAction(); } } } --- NEW FILE: ForbiddenActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for ForbiddenActionParser. /// </summary> public sealed class ForbiddenActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public ForbiddenActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementForbidden; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return false; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { return new ForbiddenAction(); } } } --- NEW FILE: IfRedirectActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parses the redirect portion of the IF and IFNOT elements. /// </summary> public sealed class IfRedirectActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public IfRedirectActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return String.Format(Constants.AttributeAction, Constants.ElementIf, Constants.ElementRedirect); } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return true; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode redirectAttribute = node.Attributes.GetNamedItem(Constants.AttrRedirect); if (redirectAttribute != null) { bool permanent = true; XmlNode permanentNode = node.Attributes.GetNamedItem(Constants.AttrPermanent); if (permanentNode != null) { permanent = Convert.ToBoolean(permanentNode.Value); } return new RedirectAction(redirectAttribute.Value, permanent); } else { return null; } } } } --- NEW FILE: RedirectActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for RedirectActionParser. /// </summary> public sealed class RedirectActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public RedirectActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementRedirect; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode toNode = node.Attributes.GetNamedItem(Constants.AttrTo); if (toNode == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrTo), node); } bool permanent = true; XmlNode permanentNode = node.Attributes.GetNamedItem(Constants.AttrPermanent); if (permanentNode != null) { permanent = Convert.ToBoolean(permanentNode.Value); } RedirectAction action = new RedirectAction(toNode.Value, permanent); ParseConditions(node, action.Conditions, false, config); return action; } } } --- NEW FILE: IRewriteConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Conditions; namespace Intelligencia.UrlRewriter { /// <summary> /// Interface defining a parser which parses an XML node and returns the correct /// IRewriteCondition instance based on the node. /// </summary> public interface IRewriteConditionParser { /// <summary> /// Parses the node if possible. The parser may be called on a condition /// that it cannot parse, if it is registered on a common verb /// which is shared by several condition parsers (e.g., and). /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed. If the parser could not parse the node, /// it <strong>must</strong> return null.</returns> IRewriteCondition Parse(XmlNode node); } } --- NEW FILE: ConditionActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Net; using System.Xml; using System.Text.RegularExpressions; using System.Collections; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parses the IF and IFNOT nodes. /// </summary> public sealed class ConditionActionParser : RewriteActionParserBase { /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementIf; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return true; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the action. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { ConditionalAction rule = new ConditionalAction(); // Process the conditions on the element. bool negative = (node.LocalName == Constants.ElementIfNot); ParseConditions(node, rule.Conditions, negative, config); // Process attribute-based actions. ReadAttributeActions(node, false, rule.Actions, (RewriterConfiguration)config); // Next, process the nested <if> and <ifnot> and non-final actions. ReadActions(node, false, rule.Actions, (RewriterConfiguration)config); // Finish off with any final actions. ReadAttributeActions(node, true, rule.Actions, (RewriterConfiguration)config); ReadActions(node, true, rule.Actions, (RewriterConfiguration)config); return rule; } private void ReadAttributeActions(XmlNode node, bool allowFinal, IList actions, RewriterConfiguration config) { int i = 0; while (i < node.Attributes.Count) { XmlNode attrNode = node.Attributes[i++]; IList parsers = config.ActionParserFactory.GetParsers(String.Format(Constants.AttributeAction, node.LocalName, attrNode.LocalName)); if (parsers != null) { foreach (IRewriteActionParser parser in parsers) { IRewriteAction action = parser.Parse(node, config); if (action != null) { if (action.Processing == RewriteProcessing.ContinueProcessing || allowFinal) { actions.Add(action); break; } } } } } } private void ReadActions(XmlNode node, bool allowFinal, IList actions, RewriterConfiguration config) { XmlNode childNode = node.FirstChild; while (childNode != null) { if (childNode.NodeType == XmlNodeType.Element) { IList parsers = config.ActionParserFactory.GetParsers(childNode.LocalName); if (parsers != null) { bool parsed = false; foreach (IRewriteActionParser parser in parsers) { IRewriteAction action = parser.Parse(childNode, config); if (action != null) { parsed = true; if ((action.Processing == RewriteProcessing.ContinueProcessing) ^ allowFinal) { actions.Add(action); break; } } } if (!parsed) { throw new ConfigurationException(MessageProvider.FormatString(Message.ElementNotAllowed, node.FirstChild.Name), node); } } } childNode = childNode.NextSibling; } } } } --- NEW FILE: IRewriteActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter { /// <summary> /// Interface defining a parser which parses an XML node and returns the correct /// IRewriteAction instance based on the node. /// </summary> public interface IRewriteActionParser { /// <summary> /// Parses the node if possible. The parser may be called on an action node /// that it cannot parse, if it is registered on a common verb /// which is shared by several action parsers (e.g., set). /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The action parsed. If the parser could not parse the node, /// it <strong>must</strong> return null.</returns> IRewriteAction Parse(XmlNode node, object config); /// <summary> /// The name of the action. /// </summary> string Name { get; } /// <summary> /// Whether the action allows nested actions. /// </summary> bool AllowsNestedActions { get; } /// <summary> /// Whether the action allows attributes. /// </summary> bool AllowsAttributes { get; } } } --- NEW FILE: RewriteActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for RewriteActionParser. /// </summary> public sealed class RewriteActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public RewriteActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementRewrite; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode toNode = node.Attributes[Constants.AttrTo]; if (toNode.Value == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrTo), node); } XmlNode processingNode = node.Attributes[Constants.AttrProcessing]; RewriteProcessing processing = RewriteProcessing.ContinueProcessing; if (processingNode != null) { if (processingNode.Value == Constants.AttrValueRestart) { processing = RewriteProcessing.RestartProcessing; } else if (processingNode.Value == Constants.AttrValueStop) { processing = RewriteProcessing.StopProcessing; } else if (processingNode.Value != Constants.AttrValueContinue) { throw new ConfigurationException(MessageProvider.FormatString(Message.ValueOfProcessingAttribute, processingNode.Value, Constants.AttrValueContinue, Constants.AttrValueRestart, Constants.AttrValueStop), node); } } RewriteAction action = new RewriteAction(toNode.Value, processing); ParseConditions(node, action.Conditions, false, config); return action; } } } --- NEW FILE: AddHeaderActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Action parser for the add-header action. /// </summary> public sealed class AddHeaderActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public AddHeaderActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementAdd; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode headerNameNode = node.Attributes.GetNamedItem(Constants.AttrHeader); if (headerNameNode == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrHeader), node); } XmlNode headerValueNode = node.Attributes.GetNamedItem(Constants.AttrValue); if (headerValueNode == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrValue), node); } return new AddHeaderAction(headerNameNode.Value, headerValueNode.Value); } } } --- NEW FILE: MethodConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for method conditions. /// </summary> public sealed class MethodConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode methodAttr = node.Attributes.GetNamedItem(Constants.AttrMethod); if (methodAttr != null) { return new MethodCondition(methodAttr.Value); } return null; } } } --- NEW FILE: PropertyMatchConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for property match conditions. /// </summary> public sealed class PropertyMatchConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode propertyAttr = node.Attributes.GetNamedItem(Constants.AttrProperty); if (propertyAttr != null) { string propertyName = propertyAttr.Value; XmlNode matchAttr = node.Attributes.GetNamedItem(Constants.AttrMatch); if (matchAttr != null) { return new PropertyMatchCondition(propertyName, matchAttr.Value); } else { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrMatch), node); } } return null; } } } --- NEW FILE: HeaderMatchConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for header match conditions. /// </summary> public sealed class HeaderMatchConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode headerAttr = node.Attributes.GetNamedItem(Constants.AttrHeader); if (headerAttr != null) { string headerName = headerAttr.Value; XmlNode matchAttr = node.Attributes.GetNamedItem(Constants.AttrMatch); if (matchAttr != null) { return new PropertyMatchCondition(headerName, matchAttr.Value); } else { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrMatch), node); } } return null; } } } --- NEW FILE: SetStatusActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Net; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Action parser for the set-status action. /// </summary> public sealed class SetStatusActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public SetStatusActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementSet; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode statusCodeNode = node.Attributes.GetNamedItem(Constants.AttrStatus); if (statusCodeNode == null) { return null; } return new SetStatusAction((HttpStatusCode)Convert.ToInt32(statusCodeNode.Value)); } } } --- NEW FILE: AddressConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for address conditions. /// </summary> public sealed class AddressConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode addressAttr = node.Attributes.GetNamedItem(Constants.AttrAddress); if (addressAttr != null) { return new AddressCondition(addressAttr.Value); } return null; } } } --- NEW FILE: NotAllowedActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for NotAllowedActionParser. /// </summary> public sealed class NotAllowedActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public NotAllowedActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementNotAllowed; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return false; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { return new MethodNotAllowedAction(); } } } --- NEW FILE: RewriteActionParserBase.cs --- using System; using System.Xml; using System.Collections; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Configuration; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for RewriteActionParserBase. /// </summary> public abstract class RewriteActionParserBase : IRewriteActionParser { /// <summary> /// Parses the action. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, null if no action parsed.</returns> public abstract IRewriteAction Parse(XmlNode node, object config); /// <summary> /// The name of the action. /// </summary> public abstract string Name { get; } /// <summary> /// Whether the action allows nested actions. /// </summary> public abstract bool AllowsNestedActions { get; } /// <summary> /// Whether the action allows attributes. /// </summary> public abstract bool AllowsAttributes { get; } /// <summary> /// Parses conditions from the node. /// </summary> /// <param name="node">The node.</param> /// <param name="conditions">Conditions list to add new conditions to.</param> /// <param name="negative">Whether the conditions should be negated.</param> /// <param name="config">Rewriter configuration</param> protected void ParseConditions(XmlNode node, IList conditions, bool negative, object config) { if ((config == null) || !(config is RewriterConfiguration)) { return; } // Parse attribute-based conditions. foreach (IRewriteConditionParser parser in ((RewriterConfiguration)config).ConditionParserPipeline) { IRewriteCondition condition = parser.Parse(node); if (condition != null) { conditions.Add(condition); } } // Now, process the nested <and> conditions. XmlNode childNode = node.FirstChild; while (childNode != null) { if (childNode.NodeType == XmlNodeType.Element) { if (childNode.LocalName == Constants.ElementAnd) { ParseConditions(childNode, conditions, negative, config); XmlNode childNode2 = childNode.NextSibling; node.RemoveChild(childNode); childNode = childNode2; continue; } } childNode = childNode.NextSibling; } } } } --- NEW FILE: NotFoundActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Summary description for NotFoundActionParser. /// </summary> public sealed class NotFoundActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public NotFoundActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementNotFound; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return false; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { return new NotFoundAction(); } } } --- NEW FILE: ExistsConditionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using Intelligencia.UrlRewriter.Conditions; using Intelligencia.UrlRewriter.Utilities; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Parser for exists conditions. /// </summary> public sealed class ExistsConditionParser : IRewriteConditionParser { /// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { XmlNode existsAttr = node.Attributes.GetNamedItem(Constants.AttrExists); if (existsAttr != null) { return new ExistsCondition(existsAttr.Value); } return null; } } } --- NEW FILE: SetPropertyActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Action parser for the set-Property action. /// </summary> public sealed class SetPropertyActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public SetPropertyActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementSet; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode propertyNameNode = node.Attributes.GetNamedItem(Constants.AttrProperty); if (propertyNameNode == null) { return null; } XmlNode propertyValueNode = node.Attributes.GetNamedItem(Constants.AttrValue); if (propertyValueNode == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrValue), node); } return new SetPropertyAction(propertyNameNode.Value, propertyValueNode.Value); } } } --- NEW FILE: SetCookieActionParser.cs --- // UrlRewriter - A .NET URL Rewriter module // Version 1.7 // // Copyright 2006 Intelligencia // Copyright 2006 Seth Yates // using System; using System.Xml; using System.Configuration; using Intelligencia.UrlRewriter.Utilities; using Intelligencia.UrlRewriter.Actions; using Intelligencia.UrlRewriter.Configuration; namespace Intelligencia.UrlRewriter.Parsers { /// <summary> /// Action parser for the set-cookie action. /// </summary> public sealed class SetCookieActionParser : RewriteActionParserBase { /// <summary> /// Default constructor. /// </summary> public SetCookieActionParser() { } /// <summary> /// The name of the action. /// </summary> public override string Name { get { return Constants.ElementSet; } } /// <summary> /// Whether the action allows nested actions. /// </summary> public override bool AllowsNestedActions { get { return false; } } /// <summary> /// Whether the action allows attributes. /// </summary> public override bool AllowsAttributes { get { return true; } } /// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, object config) { XmlNode cookieNameNode = node.Attributes.GetNamedItem(Constants.AttrCookie); if (cookieNameNode == null) { return null; } XmlNode cookieValueNode = node.Attributes.GetNamedItem(Constants.AttrValue); if (cookieValueNode == null) { throw new ConfigurationException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrValue), node); } return new SetCookieAction(cookieNameNode.Value, cookieValueNode.Value); } } } |