Exemplo n.º 1
0
        public static BindingExpressionInfo ParseExpr(string expression, BindingExpressionContext context)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            int colonIndex = expression.IndexOf(':');

            if (colonIndex == -1)
            {
                throw new ArgumentException("The expression must contain a colon.", "expression");
            }

            string prefix = expression.Substring(0, colonIndex);
            string ns;

            if (!context.InScopeNamespaces.TryGetValue(prefix, out ns))
            {
                throw new ArgumentException("The are no namespaces defined for prefix '{0}'.".FormatInvariant(prefix), "expression");
            }

            string value = expression.Substring(colonIndex + 1);

            BindingExpressionBuilder exprBuilder;

            ExpressionBuilderElement el = WebSection.Instance.Compilation.ExpressionBuilders.Get(ns);

            if (el == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "There are no expression builders registered for namespace '{0}'.", ns));
            }

            exprBuilder = (BindingExpressionBuilder)Activator.CreateInstance(el.TypeInternal);

            BindingExpressionInfo exprInfo = exprBuilder.ParseExpression(value, context);

            if (exprInfo == null)
            {
                exprInfo = new BindingExpressionInfo(expression);
            }

            exprInfo.ExpressionBuilder = exprBuilder;

            return(exprInfo);
        }
Exemplo n.º 2
0
        public static BindingExpressionInfo ParseExpr(string expression, BindingExpressionContext context)
        {
            if (expression == null) throw new ArgumentNullException("expression");
             if (context == null) throw new ArgumentNullException("context");

             int colonIndex = expression.IndexOf(':');

             if (colonIndex == -1) {
              throw new ArgumentException("The expression must contain a colon.", "expression");
              }

             string prefix = expression.Substring(0, colonIndex);
             string ns;

             if (!context.InScopeNamespaces.TryGetValue(prefix, out ns)) {
            throw new ArgumentException("The are no namespaces defined for prefix '{0}'.".FormatInvariant(prefix), "expression");
             }

             string value = expression.Substring(colonIndex + 1);

             BindingExpressionBuilder exprBuilder;

             ExpressionBuilderElement el = WebSection.Instance.Compilation.ExpressionBuilders.Get(ns);

             if (el == null) {
            throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "There are no expression builders registered for namespace '{0}'.", ns));
             }

             exprBuilder = (BindingExpressionBuilder)Activator.CreateInstance(el.TypeInternal);

             BindingExpressionInfo exprInfo = exprBuilder.ParseExpression(value, context);

             if (exprInfo == null) {
            exprInfo = new BindingExpressionInfo(expression);
             }

             exprInfo.ExpressionBuilder = exprBuilder;

             return exprInfo;
        }
Exemplo n.º 3
0
        public override BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
        {
            // TODO: Fix error messages not to refer to web:bind but expression builder prefix/ns instead

            var uri = new Uri(expression, UriKind.RelativeOrAbsolute);

            if (!uri.IsAbsoluteUri)
            {
                uri = new Uri(String.Concat(SessionModule.Prefix, ":", uri.OriginalString), UriKind.Absolute);
            }

            var validValues = new List <string>()
            {
                bind.it
            };

            string path     = uri.AbsolutePath;
            string nodeName = context.NodeName ?? context.BoundNode.Name;

            if (!validValues.Contains(path))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The value of the '{0}' attribute must be one of these values: {1}.", nodeName, String.Join(", ", validValues.ToArray())));
            }

            if (context.AffectsXsltInitiation)
            {
                throw new ArgumentException("Cannot bind to session when the parameter affects XSLT initiation.");
            }

            BasePageParser pageParser = context.Parser as BasePageParser;

            if (path == bind.it && pageParser != null && pageParser.EnableSessionState == PagesEnableSessionState.False)
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.InvariantCulture, "Cannot bind to {0} because session state is disabled for this page. Try setting enable-session-state=\"true\" on the page processing instruction.", bind.it)
                          );
            }

            NameValueCollection query = (uri.Query.Length > 1) ?
                                        HttpUtility.ParseQueryString(uri.Query.Replace(';', '&')) :
                                        new NameValueCollection();

            var exprInfo = new BindingExpressionInfo(expression)
            {
                ParsedObject = uri
            };

            if (query["name"] != null)
            {
                exprInfo.ParsedValues["name"] = query["name"];
                query.Remove("name");
            }
            else
            {
                XPathNavigator nav = context.BoundNode.Clone();
                nav.MoveToParent();

                if (nav.NodeType == XPathNodeType.Element &&
                    nav.LocalName == "param" &&
                    nav.NamespaceURI == WellKnownNamespaces.XSLT)
                {
                    exprInfo.ParsedValues["name"] = nav.GetAttribute("name", "");
                }
            }

            switch (path)
            {
            case bind.it:
                exprInfo.ParsedValues["remove"] = GetBooleanOrDefault(query["remove"]);
                query.Remove("remove");
                break;

            default:
                if (query["remove"] != null)
                {
                    throw new ArgumentException(
                              String.Format(CultureInfo.InvariantCulture, "The remove option is not valid for {0}.", path)
                              );
                }
                break;
            }

            foreach (string key in query.AllKeys)
            {
                exprInfo.ParsedValues.Add(key, query[key]);
            }

            return(exprInfo);
        }
Exemplo n.º 4
0
 public override BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
 {
     return(new BindingExpressionInfo(expression));
 }
Exemplo n.º 5
0
        protected void ParseParameter()
        {
            XPathNavigator nav = this.Navigator;

             string nameValue = nav.GetAttribute("name", "");

             if (this.Parameters.Contains(nameValue)) {
            return;
             }

             PageParameterInfo paramInfo = null;

             if (nav.MoveToAttribute("bind", WebModule.Namespace)) {

            var exprBuilderContext = new BindingExpressionContext(this, nav.Clone());

            BindingExpressionInfo exprInfo = null;

            try {
               exprInfo = BindingExpressionBuilder.ParseExpr(nav.Value, exprBuilderContext);

            } catch (Exception ex) {
               throw CreateParseException(ex.Message);
            }

            if (exprInfo != null) {
               exprInfo.LineNumber = ((IXmlLineInfo)nav).LineNumber;
            }

            nav.MoveToParent();

            IDictionary<string, string> namespacesInScope = nav.GetNamespacesInScope(XmlNamespaceScope.All);

            bool hasDefaultValue = !String.IsNullOrEmpty(nav.GetAttribute("select", ""));
            string asValue = nav.GetAttribute("as", "");
            bool required = nav.GetAttribute("required", "") == "yes";

            paramInfo = PageParameterInfo.FromSequenceType(nameValue, asValue, namespacesInScope);

            if (hasDefaultValue) {
               if (paramInfo.MinLength > 0) {
                  paramInfo.MinLength = 0;
               }

            } else if (required) {

               if (paramInfo.MinLength == 0) {
                  paramInfo.MinLength = 1;
               }
            }

            paramInfo.Binding = exprInfo;
             }

             if (paramInfo != null) {
            this.Parameters.Add(paramInfo);
             }
        }
Exemplo n.º 6
0
        protected void ParsePagePI()
        {
            XPathNavigator nav = this.Navigator;

             IDictionary<string, string> attribs = GetAttributes(nav.Value);

             // language
             string language = GetNonEmptyNoWhitespaceAttribute(attribs, page.language);

             if (language != null) {
            this.Language = language;
             }

             // class-name
             string className = GetFullClassNameAttribute(attribs, page.class_name);

             if (!String.IsNullOrEmpty(className)) {
            this.GeneratedTypeFullName = className;
             }

             // content-type
             string contentType = GetNonEmptyAttribute(attribs, page.content_type);

             if (contentType != null) {
            this.ContentType = contentType;
             }

             // enable-session-state
             object enableSs = GetEnumAttribute(attribs, page.enable_session_state, typeof(PagesEnableSessionState));

             if (enableSs != null) {
            this.EnableSessionState = (PagesEnableSessionState)enableSs;
             }

             // validate-request
             bool valReq = default(bool);

             if (GetBooleanAttribute(attribs, page.validate_request, ref valReq)) {
            this.ValidateRequest = valReq;
             }

             // accept-verbs
             string acceptVerbs = GetNonEmptyAttribute(attribs, page.accept_verbs);

             if (acceptVerbs != null) {

            string[] verbs = acceptVerbs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < verbs.Length; i++) {
               this.AcceptVerbs.Add(verbs[i].Trim());
            }
             }

             // XSLT related attributes

             XPathNavigator nav2 = nav.CreateNavigator();
             nav2.MoveToRoot();
             nav2.MoveToChild(XPathNodeType.Element);

             IDictionary<string, string> namespacesInScope = nav2.GetNamespacesInScope(XmlNamespaceScope.All);

             // initial-template
             string initialTempl = GetNonEmptyAttribute(attribs, page.initial_template);

             if (initialTempl != null) {

            if (this.PageType != XsltPageType.StandardStylesheet) {
               throw CreateParseException("The '{0}' attribute can only be used on standard XSLT pages.", page.initial_template);
            }

            string itLocal = initialTempl;
            string itNamespace = "";

            if (initialTempl.Contains(":")) {
               string[] itParts = initialTempl.Split(':');
               itLocal = itParts[1];
               string itPrefix = itParts[0];

               if (namespacesInScope.ContainsKey(itPrefix)) {
                  itNamespace = namespacesInScope[itPrefix];
               }
            }

            this.InitialTemplate = new XmlQualifiedName(itLocal, itNamespace);
             }

             // initial-template-binding

             string initialTemplBind = GetNonEmptyAttribute(attribs, page.bind_initial_template);

             if (initialTemplBind != null) {

            if (this.PageType != XsltPageType.StandardStylesheet) {
               throw CreateParseException("The '{0}' attribute can only be used on standard XSLT pages.", page.bind_initial_template);
            }

            var exprBuilderContext = new BindingExpressionContext(this, nav.Clone(), namespacesInScope) {
               NodeName = page.bind_initial_template,
               AffectsXsltInitiation = true
            };

            try {
               this.InitialTemplateBinding = BindingExpressionBuilder.ParseExpr(initialTemplBind, exprBuilderContext);

            } catch (Exception ex) {
               throw CreateParseException(ex.Message);
            }

            if (this.InitialTemplateBinding != null) {
               this.InitialTemplateBinding.LineNumber = ((IXmlLineInfo)nav).LineNumber;
            }
             }

             // processor
             string processor = GetNonEmptyAttribute(attribs, page.processor);

             if (processor != null) {

            if (!Processors.Xslt.Exists(processor)) {
               throw CreateParseException("The processor '{0}' is not registered.", processor);
            }

            this.ProcessorName = processor;
             }
        }
Exemplo n.º 7
0
        public override BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
        {
            // TODO: Fix error messages not to refer to web:bind but expression builder prefix/ns instead

             var uri = new Uri(expression, UriKind.RelativeOrAbsolute);

             if (!uri.IsAbsoluteUri) {
            uri = new Uri(String.Concat(SessionModule.Prefix, ":", uri.OriginalString), UriKind.Absolute);
             }

             var validValues = new List<string>() { bind.it };

             string path = uri.AbsolutePath;
             string nodeName = context.NodeName ?? context.BoundNode.Name;

             if (!validValues.Contains(path))
            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The value of the '{0}' attribute must be one of these values: {1}.", nodeName, String.Join(", ", validValues.ToArray())));

             if (context.AffectsXsltInitiation) {
            throw new ArgumentException("Cannot bind to session when the parameter affects XSLT initiation.");
             }

             BasePageParser pageParser = context.Parser as BasePageParser;

             if (path == bind.it && pageParser != null && pageParser.EnableSessionState == PagesEnableSessionState.False)
            throw new ArgumentException(
               String.Format(CultureInfo.InvariantCulture, "Cannot bind to {0} because session state is disabled for this page. Try setting enable-session-state=\"true\" on the page processing instruction.", bind.it)
            );

             NameValueCollection query = (uri.Query.Length > 1) ?
            HttpUtility.ParseQueryString(uri.Query.Replace(';', '&')) :
            new NameValueCollection();

             var exprInfo = new BindingExpressionInfo(expression) {
            ParsedObject = uri
             };

             if (query["name"] != null) {

            exprInfo.ParsedValues["name"] = query["name"];
            query.Remove("name");

             } else {

            XPathNavigator nav = context.BoundNode.Clone();
            nav.MoveToParent();

            if (nav.NodeType == XPathNodeType.Element
               && nav.LocalName == "param"
               && nav.NamespaceURI == WellKnownNamespaces.XSLT) {

               exprInfo.ParsedValues["name"] = nav.GetAttribute("name", "");
            }
             }

             switch (path) {
            case bind.it:
               exprInfo.ParsedValues["remove"] = GetBooleanOrDefault(query["remove"]);
               query.Remove("remove");
               break;

            default:
               if (query["remove"] != null) {
                  throw new ArgumentException(
                     String.Format(CultureInfo.InvariantCulture, "The remove option is not valid for {0}.", path)
                  );
               }
               break;
             }

             foreach (string key in query.AllKeys) {
            exprInfo.ParsedValues.Add(key, query[key]);
             }

             return exprInfo;
        }
Exemplo n.º 8
0
        public override BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
        {
            // TODO: Fix error messages not to refer to web:bind but expression builder prefix/ns instead

            var uri = new Uri(expression, UriKind.RelativeOrAbsolute);

            if (!uri.IsAbsoluteUri)
            {
                uri = new Uri(String.Concat(RequestModule.Prefix, ":", uri.OriginalString), UriKind.Absolute);
            }

            var validValues = new List <string>()
            {
                bind.query, bind.cookie, bind.form,
                bind.header, bind.http_method
            };

            string path     = uri.AbsolutePath;
            string nodeName = context.NodeName ?? context.BoundNode.Name;

            if (!validValues.Contains(path))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The value of the '{0}' attribute must be one of these values: {1}.", nodeName, String.Join(", ", validValues.ToArray())));
            }

            BasePageParser pageParser = context.Parser as BasePageParser;

            NameValueCollection query = (uri.Query.Length > 1) ?
                                        HttpUtility.ParseQueryString(uri.Query.Replace(';', '&')) :
                                        new NameValueCollection();

            var exprInfo = new BindingExpressionInfo(expression)
            {
                ParsedObject = uri
            };

            if (query["name"] != null)
            {
                exprInfo.ParsedValues["name"] = query["name"];
                query.Remove("name");
            }
            else
            {
                XPathNavigator nav = context.BoundNode.Clone();
                nav.MoveToParent();

                if (nav.NodeType == XPathNodeType.Element &&
                    nav.LocalName == "param" &&
                    nav.NamespaceURI == WellKnownNamespaces.XSLT)
                {
                    exprInfo.ParsedValues["name"] = nav.GetAttribute("name", "");
                }
            }

            if (query["accept"] != null)
            {
                switch (path)
                {
                case bind.http_method:
                    throw new ArgumentException(
                              String.Format(CultureInfo.InvariantCulture, "When '{0}' is set to '{1}' use the '{2}' attribute instead of the 'accept' option.", XsltPageParser.page.bind_initial_template, bind.http_method, XsltPageParser.page.accept_verbs)
                              );
                }

                exprInfo.ParsedValues["accept"] = query["accept"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                query.Remove("accept");
            }
            else
            {
                if (context.AffectsXsltInitiation)
                {
                    if (path != bind.http_method)
                    {
                        throw new ArgumentException(
                                  String.Format(CultureInfo.InvariantCulture, "The 'accept' option is required for '{0}'. Try this: {1}?accept=[comma-separated template names]", XsltPageParser.page.bind_initial_template, path)
                                  );
                    }
                    else if (pageParser != null && pageParser.AcceptVerbs.Count == 0)
                    {
                        throw new ArgumentException(
                                  String.Format(CultureInfo.InvariantCulture, "The '{0}' attribute is required when '{1}' is set to '{2}'.", XsltPageParser.page.accept_verbs, XsltPageParser.page.bind_initial_template, path)
                                  );
                    }
                }
            }

            switch (path)
            {
            case bind.cookie:
                exprInfo.ParsedValues["remove"] = GetBooleanOrDefault(query["remove"]);
                query.Remove("remove");
                break;

            default:
                if (query["remove"] != null)
                {
                    throw new ArgumentException(
                              String.Format(CultureInfo.InvariantCulture, "The remove option is not valid for {0}.", path)
                              );
                }
                break;
            }

            foreach (string key in query.AllKeys)
            {
                exprInfo.ParsedValues.Add(key, query[key]);
            }

            return(exprInfo);
        }
Exemplo n.º 9
0
 public virtual BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
 {
     return(null);
 }
Exemplo n.º 10
0
 public virtual BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
 {
     return null;
 }
Exemplo n.º 11
0
 public override BindingExpressionInfo ParseExpression(string expression, BindingExpressionContext context)
 {
     return new BindingExpressionInfo(expression);
 }