コード例 #1
0
        /// <summary>
        /// Function to process the "requestvar" skin tag. Determines the specified
        /// collection and calls out to a helper function in SkinUtil to process
        /// the directive from the specified Http collection.
        /// </summary>
        /// <param name="req">The current HTTP Request</param>
        /// <param name="n">The current skin directive node</param>
        protected void RequestVar(HttpRequest req, XmlNode n)
        {
            //Get the specified http request collection
            string colName = GetAttribNull(n, "collection");

            //if the collection is not specified, default to the "params" collection
            if (colName == null)
            {
                colName = "Params";
            }

            switch (colName)
            {
            case "QueryString":
                //Since the querystring, form, servervariables and params collections
                //are simple name value collections and all of the same type, the
                //code to process the requestvar directive has been factored into a
                //helper function.
                NameValCol(req.QueryString, n);
                break;

            case "Form":
                NameValCol(req.Form, n);
                break;

            case "ServerVariables":
                NameValCol(req.ServerVariables, n);
                break;

            case "Params":
                NameValCol(req.Params, n);
                break;

            case "Cookies":
                //since cookies is handled seperately, there's no point in factoring
                //the code into a seperate function.
                XmlNode newNode = SkinUtil.CookieCol(n.ParentNode, req.Cookies, GetAttribNull(n, "name"), GetAttribNull(n, "namespace"));
                ReplaceNode(n.ParentNode, newNode, n);
                break;

            default:
                throw new Exception("Unrecognized Request Var collection name: " + colName);
            }
        }
コード例 #2
0
        /// <summary>
        /// Member of the IHttpHandler interface
        /// Process a dynamic web page request
        /// </summary>
        /// <param name="context">represents the current web page request</param>
        public void ProcessRequest(HttpContext context)
        {
#if DEBUG
            if (context.Request["__admin"] != null)
            {
                if (context.Request["__admin"].ToUpper() == "showXml".ToUpper())
                {
                    System.Xml.XmlDocument dom = new System.Xml.XmlDocument();
                    dom.Load(context.Request.PhysicalPath);
                    dom.Save(context.Response.Output);

                    return;
                }
            }
#endif

            ListDictionary objDict = null;

            try
            {
                //Load the XML document indicated in the request
                XmlDocument dom = new XmlDocument();
                dom.Load(context.Request.PhysicalPath);

                //get a list of all the nodes in the SkinUI Namespace
                XmlNodeList l = dom.GetElementsByTagName("*", SkinUtil.SkinUINamespace);

                //Initalize the XSLT variable
                //Create a new object dictionary to store variable declarations
                TransformInfo xsltInfo = null;
                objDict = new ListDictionary();

                //process each of the SkinUI Nodes. Note, since we delete each WebSkin
                //node as we process it, we just need to keep processing the top element
                //of the list until the list is empty.
                while (l.Count > 0)
                {
                    XmlNode n = l[0];
                    switch (n.LocalName)
                    {
                    case "class":
                        ClassDecl(context, n, objDict);
                        break;

                    case "methodcall":
                        MethodCall(context, n, objDict);
                        break;

                    case "database":
                        DatabaseDecl(n, objDict);
                        break;

                    case "query":
                        Query(context, n, objDict);
                        break;

                    case "requestvar":
                        RequestVar(context.Request, n);
                        break;

                    case "transform":
                        if (xsltInfo != null)
                        {
                            throw new Exception("Multiple SkinUI Transform tags found");
                        }
                        xsltInfo = new TransformInfo(n);
                        n.ParentNode.RemoveChild(n);
                        break;

                    default:
                        throw new Exception("Unrecognized SkinUI tag name: " + n.LocalName);
                    }
                }

                //Delete any namespace declarations off the root node for the SkinUI namespace
                for (int i = dom.DocumentElement.Attributes.Count - 1; i >= 0; i--)
                {
                    XmlAttribute a = dom.DocumentElement.Attributes[i];
                    if (a.Value == SkinUtil.SkinUINamespace && a.Prefix == "xmlns")
                    {
                        a.OwnerElement.Attributes.Remove(a);
                    }
                }

                //Get the XSLT file to use in transforms from the controller class
                string xsltFile = "";

                if (xsltInfo != null)
                {
                    if (xsltInfo.defaultTransform != "")
                    {
                        xsltFile = context.Request.PhysicalApplicationPath + xsltInfo.defaultTransform;
                    }
                    else
                    {
                        Object o = objDict[xsltInfo.variable];
                        xsltFile = GetXSLTemplate(o, xsltInfo.method, context);
                    }
                }

                //Call the helper function to perform the actual XSLT Transform
                SkinUtil.Transform(dom, xsltFile, context);
            }
            catch (Exception ex)
            {
                //Catch any exception and add it to the context as an HTTP exception
                HttpException h = new HttpException(500, ex.Message, ex);
                context.AddError(h);
            }
            finally
            {
                if (objDict != null)
                {
                    //Close and release all entries in the object dictionary
                    foreach (DictionaryEntry entry in objDict)
                    {
                        if (entry.Value is SqlConnection)
                        {
                            ((SqlConnection)entry.Value).Close();
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// helper function to process generic HTTP request name value collections
        /// </summary>
        /// <param name="col">the collection to retrieve the value(s) from</param>
        /// <param name="n">The current skin directive node</param>
        protected void NameValCol(NameValueCollection col, XmlNode n)
        {
            XmlNode newNode = SkinUtil.NameValCol(n.ParentNode, col, GetAttribNull(n, "name"), GetAttribNull(n, "namespace"));

            ReplaceNode(n.ParentNode, newNode, n);
        }