Ejemplo n.º 1
0
        //
        // Create a rule from an element
        //
        static CapabilitiesRule RuleFromElement(ParseState parseState, XmlNode element)
        {
            int                 ruletype;
            DelayedRegex        regex;
            CapabilitiesPattern pat;

            // grab tag name

            if (element.Name == "filter")
            {
                ruletype = CapabilitiesRule.Filter;
            }
            else if (element.Name == "case")
            {
                ruletype = CapabilitiesRule.Case;
            }
            else if (element.Name == "use")
            {
                HandlerBase.CheckForNonCommentChildNodes(element);

                string var   = HandlerBase.RemoveRequiredAttribute(element, "var");
                string strAs = HandlerBase.RemoveAttribute(element, "as");
                HandlerBase.CheckForUnrecognizedAttributes(element);

                if (strAs == null)
                {
                    strAs = String.Empty;
                }

                parseState.Evaluator.AddDependency(var);

                return(new CapabilitiesUse(var, strAs));
            }
            else
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Unknown_tag_in_caps_config, element.Name),
                          element);
            }

            // grab attributes
            String matchpat = HandlerBase.RemoveAttribute(element, "match");
            String testpat  = HandlerBase.RemoveAttribute(element, "with");

            HandlerBase.CheckForUnrecognizedAttributes(element);

            if (matchpat == null)
            {
                if (testpat != null)
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_specify_test_without_match), element);
                }
                regex = null;
                pat   = null;
            }
            else
            {
                try {
                    regex = new DelayedRegex(matchpat);
                }
                catch (Exception e) {
                    throw new ConfigurationErrorsException(e.Message, e, element);
                }

                if (testpat == null)
                {
                    pat = CapabilitiesPattern.Default;
                }
                else
                {
                    pat = new CapabilitiesPattern(testpat);
                }
            }

            // grab contents
            ArrayList subrules = RuleListFromElement(parseState, element, false);

            return(new CapabilitiesSection(ruletype, regex, pat, subrules));
        }
Ejemplo n.º 2
0
        /*
         * Create
         *
         * Given a partially composed config object (possibly null)
         * and some input from the config system, return a
         * further partially composed config object
         */
        internal Object InternalCreate(Object parent, XmlNode node)
        {
            HandlerMap map;

            // start list as shallow clone of parent

            if (parent == null)
            {
                map = new HandlerMap();
            }
            else
            {
                map = new HandlerMap((HandlerMap)parent);
            }

            map.BeginGroup();

            // process XML section
            HandlerBase.CheckForUnrecognizedAttributes(node);

            foreach (XmlNode child in node.ChildNodes)
            {
                // skip whitespace and comments

                if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> and <clear> elements

                if (child.Name.Equals("add"))
                {
                    String verb      = HandlerBase.RemoveRequiredAttribute(child, "verb");
                    String path      = HandlerBase.RemoveRequiredAttribute(child, "path");
                    String classname = HandlerBase.RemoveRequiredAttribute(child, "type");

                    int     phase     = 1;
                    XmlNode phaseNode = HandlerBase.GetAndRemoveIntegerAttribute(child, "phase", ref phase);
                    if (phaseNode != null)
                    {
                        ValidatePhase(phase, phaseNode);
                    }

                    bool validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);


                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    try {
                        map.Add(new HandlerMapping(verb, path, classname, !validate), phase);
                    }
                    catch (Exception e) {
                        throw new ConfigurationException(e.Message, e, child);
                    }
                }
                else if (child.Name.Equals("remove"))
                {
                    String verb     = HandlerBase.RemoveRequiredAttribute(child, "verb");
                    String path     = HandlerBase.RemoveRequiredAttribute(child, "path");
                    bool   validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);


                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (!map.RemoveMapping(verb, path) && validate)
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.No_mapping_to_remove, verb, path),
                                  child);
                    }
                }
                else if (child.Name.Equals("clear"))
                {
                    int     phase     = 1;
                    XmlNode phaseNode = HandlerBase.GetAndRemoveIntegerAttribute(child, "phase", ref phase);
                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (phaseNode == null)
                    {
                        map.ClearAll();
                    }
                    else
                    {
                        ValidatePhase(phase, phaseNode);
                        map.ClearPhase(phase);
                    }
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }

            map.EndGroup();

            return(map);
        }