Exemplo n.º 1
0
        private static OutputMethod ParseOutputMethod(string value, Compiler compiler)
        {
            XmlQualifiedName method = compiler.CreateXPathQName(value);

            if (method.Namespace != string.Empty)
            {
                return(OutputMethod.Other);
            }
            switch (method.Name)
            {
            case Keywords.s_Xml:
                return(OutputMethod.Xml);

            case Keywords.s_Html:
                return(OutputMethod.Html);

            case Keywords.s_Text:
                return(OutputMethod.Text);

            default:
                if (compiler.ForwardCompatibility)
                {
                    return(OutputMethod.Unknown);
                }
                throw XsltException.InvalidAttrValue(Keywords.s_Method, value);
            }
        }
Exemplo n.º 2
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Level))
            {
                if (value != s_any && value != s_multiple && value != s_single)
                {
                    throw XsltException.InvalidAttrValue(Keywords.s_Level, value);
                }
                this.level = value;
            }
            else if (Keywords.Equals(name, compiler.Atoms.Count))
            {
                this.countPattern = value;
                this.countKey     = compiler.AddPatternQuery(value, /*allowVars:*/ true, /*allowKey:*/ true);
            }
            else if (Keywords.Equals(name, compiler.Atoms.From))
            {
                this.from    = value;
                this.fromKey = compiler.AddPatternQuery(value, /*allowVars:*/ true, /*allowKey:*/ true);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Value))
            {
                this.value    = value;
                this.valueKey = compiler.AddQuery(value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Format))
            {
                this.formatAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Lang))
            {
                this.langAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.LetterValue))
            {
                this.letterAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.GroupingSeparator))
            {
                this.groupingSepAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.GroupingSize))
            {
                this.groupingSizeAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
 private string ParseLetter(string letter)
 {
     if (letter == null || letter == "traditional" || letter == "alphabetic")
     {
         return(letter);
     }
     if (!this.forwardCompatibility)
     {
         throw XsltException.InvalidAttrValue(Keywords.s_LetterValue, letter);
     }
     return(null);
 }
Exemplo n.º 4
0
        private void AddScript(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            ScriptingLanguage lang = ScriptingLanguage.JScript;
            string            implementsNamespace = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    if (input.LocalName == input.Atoms.Language)
                    {
                        string langName = input.Value.ToLower(CultureInfo.InvariantCulture);   // Case insensetive !
                        if (langName == "jscript" || langName == "javascript")
                        {
                            lang = ScriptingLanguage.JScript;
                        }
                        else if (langName == "vb" || langName == "visualbasic")
                        {
                            lang = ScriptingLanguage.VisualBasic;
                        }
                        else if (langName == "c#" || langName == "csharp")
                        {
                            lang = ScriptingLanguage.CSharp;
                        }
                        else
                        {
                            throw new XsltException(Res.Xslt_ScriptInvalidLang, langName);
                        }
                    }
                    else if (input.LocalName == input.Atoms.ImplementsPrefix)
                    {
                        if (!PrefixQName.ValidatePrefix(input.Value))
                        {
                            throw XsltException.InvalidAttrValue(input.LocalName, input.Value);
                        }
                        implementsNamespace = compiler.ResolveXmlNamespace(input.Value);
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }
            if (implementsNamespace == null)
            {
                throw new XsltException(Res.Xslt_MissingAttribute, input.Atoms.ImplementsPrefix);
            }
            if (!input.Recurse() || input.NodeType != XPathNodeType.Text)
            {
                throw new XsltException(Res.Xslt_ScriptEmpty);
            }
            compiler.AddScript(input.Value, lang, implementsNamespace, input.BaseURI, input.LineNumber);
            input.ToParent();
        }
Exemplo n.º 5
0
 internal bool CheckAttribute(bool valid, Compiler compiler)
 {
     if (!valid)
     {
         if (!compiler.ForwardCompatibility)
         {
             throw XsltException.InvalidAttrValue(compiler.Input.LocalName, compiler.Input.Value);
         }
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckEmpty(compiler);

            this.forwardCompatibility = compiler.ForwardCompatibility;
            this.formatList           = ParseFormat(PrecalculateAvt(ref this.formatAvt));
            this.letter      = ParseLetter(PrecalculateAvt(ref this.letterAvt));
            this.lang        = PrecalculateAvt(ref this.langAvt);
            this.groupingSep = PrecalculateAvt(ref this.groupingSepAvt);
            if (this.groupingSep != null && this.groupingSep.Length > 1)
            {
                throw XsltException.InvalidAttrValue(compiler.Atoms.GroupingSeparator, this.groupingSep);
            }
            this.groupingSize = PrecalculateAvt(ref this.groupingSizeAvt);
        }
Exemplo n.º 7
0
 private string ParseLang(string value)
 {
     if (value == null)  // Avt is not constant, or attribute wasn't defined
     {
         return(null);
     }
     if (!XmlComplianceUtil.IsValidLanguageID(value.ToCharArray(), 0, value.Length))
     {
         if (this.forwardCompatibility)
         {
             return(null);
         }
         throw XsltException.InvalidAttrValue(Keywords.s_Lang, value);
     }
     return(value);
 }
Exemplo n.º 8
0
        //
        // Attribute parsing support
        //

        internal bool GetYesNo(string value)
        {
            Debug.Assert(value != null);
            Debug.Assert((object)value == (object)Input.Value); // this is always true. Why we passing value to this function.
//            if (value == null)
//                return false;  // in XSLT it happens that default value was always false;
            if (value.Equals(Atoms.Yes))
            {
                return(true);
            }
            if (value.Equals(Atoms.No))
            {
                return(false);
            }
            throw XsltException.InvalidAttrValue(Input.LocalName, value);
        }
Exemplo n.º 9
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Match))
            {
                Debug.Assert(this.match == null);
                this.match    = value;
                this.matchKey = compiler.AddPatternQuery(value, /*allowVars:*/ false, /*allowKey:*/ true);
                Debug.WriteLine("match attribute found: \"" + this.match + "\"  (#" + this.matchKey + ")");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Name))
            {
                Debug.Assert(this.name == null);
                this.name = compiler.CreateXPathQName(value);
                Debug.WriteLine("name attribute found: " + this.name);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Priority))
            {
                Debug.Assert(Double.IsNaN(this.priority));
                this.priority = XmlConvert.ToXPathDouble(value);
                if (double.IsNaN(this.priority) && !compiler.ForwardCompatibility)
                {
                    throw XsltException.InvalidAttrValue(Keywords.s_Priority, value);
                }
            }
            else if (Keywords.Equals(name, compiler.Atoms.Mode))
            {
                Debug.Assert(this.mode == null);
                if (compiler.AllowBuiltInMode && value.Trim() == "*")
                {
                    this.mode = Compiler.BuiltInMode;
                }
                else
                {
                    this.mode = compiler.CreateXPathQName(value);
                }
                Debug.WriteLine("mode attribute found: " + this.mode);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
 void NameTest(String name, Compiler compiler)
 {
     if (name == "*")
     {
         return;
     }
     if (name.EndsWith(":*"))
     {
         if (!PrefixQName.ValidatePrefix(name.Substring(0, name.Length - 3)))
         {
             throw XsltException.InvalidAttrValue(compiler.Input.LocalName, name);
         }
     }
     else
     {
         string prefix, localname;
         PrefixQName.ParseQualifiedName(name, out prefix, out localname);
     }
 }
Exemplo n.º 11
0
 private XmlCaseOrder ParseCaseOrder(string value)
 {
     if (value == null)  // Avt is not constant, or attribute wasn't defined
     {
         return(XmlCaseOrder.None);
     }
     if (value == Keywords.s_UpperFirst)
     {
         return(XmlCaseOrder.UpperFirst);
     }
     if (value == Keywords.s_LowerFirst)
     {
         return(XmlCaseOrder.LowerFirst);
     }
     if (this.forwardCompatibility)
     {
         return(XmlCaseOrder.None);
     }
     throw XsltException.InvalidAttrValue(Keywords.s_CaseOrder, value);
 }
Exemplo n.º 12
0
 private XmlSortOrder ParseOrder(string value)
 {
     if (value == null)  // Avt is not constant, or attribute wasn't defined
     {
         return(XmlSortOrder.Ascending);
     }
     if (value == Keywords.s_Ascending)
     {
         return(XmlSortOrder.Ascending);
     }
     if (value == Keywords.s_Descending)
     {
         return(XmlSortOrder.Descending);
     }
     if (this.forwardCompatibility)
     {
         return(XmlSortOrder.Ascending);
     }
     throw XsltException.InvalidAttrValue(Keywords.s_Order, value);
 }
Exemplo n.º 13
0
 public string GetNsAlias(ref string prefix)
 {
     Debug.Assert(
         Keywords.Equals(this.input.LocalName, this.input.Atoms.StylesheetPrefix) ||
         Keywords.Equals(this.input.LocalName, this.input.Atoms.ResultPrefix)
         );
     if (Keywords.Compare(this.input.Atoms.HashDefault, prefix))
     {
         prefix = string.Empty;
         return(this.DefaultNamespace);
     }
     else
     {
         if (!PrefixQName.ValidatePrefix(prefix) || prefix.Length == 0)
         {
             throw XsltException.InvalidAttrValue(this.input.LocalName, prefix);
         }
         return(this.ResolveXPathNamespace(prefix));
     }
 }
Exemplo n.º 14
0
        private XmlDataType ParseDataType(string value, InputScopeManager manager)
        {
            if (value == null)  // Avt is not constant, or attribute wasn't defined
            {
                return(XmlDataType.Text);
            }
            if (value == Keywords.s_Text)
            {
                return(XmlDataType.Text);
            }
            if (value == Keywords.s_Number)
            {
                return(XmlDataType.Number);
            }
            String prefix, localname;

            PrefixQName.ParseQualifiedName(value, out prefix, out localname);
            manager.ResolveXmlNamespace(prefix);
            if (prefix == String.Empty && !this.forwardCompatibility)
            {
                throw XsltException.InvalidAttrValue(Keywords.s_DataType, value);
            }
            return(XmlDataType.Text);
        }
Exemplo n.º 15
0
        internal void CompileStylesheetAttributes(Compiler compiler)
        {
            NavigatorInput input        = compiler.Input;
            string         element      = input.LocalName;
            string         badAttribute = null;
            string         version      = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    Debug.TraceAttribute(input);

                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

                    if (!Keywords.Equals(nspace, input.Atoms.Empty))
                    {
                        continue;
                    }

                    Debug.WriteLine("Attribute name: \"" + name + "\"");
                    if (Keywords.Equals(name, input.Atoms.Version))
                    {
                        version = input.Value;
                        if (1 <= XmlConvert.ToXPathDouble(version))
                        {
                            compiler.ForwardCompatibility = (version != Keywords.s_Version10);
                        }
                        else
                        {
                            // XmlConvert.ToXPathDouble(version) an be NaN!
                            if (!compiler.ForwardCompatibility)
                            {
                                throw XsltException.InvalidAttrValue(Keywords.s_Version, version);
                            }
                        }
                        Debug.WriteLine("Version found: \"" + version + "\"");
                    }
                    else if (Keywords.Equals(name, input.Atoms.ExtensionElementPrefixes))
                    {
                        compiler.InsertExtensionNamespace(input.Value);
                    }
                    else if (Keywords.Equals(name, input.Atoms.ExcludeResultPrefixes))
                    {
                        compiler.InsertExcludedNamespace(input.Value);
                    }
                    else if (Keywords.Equals(name, input.Atoms.Id))
                    {
                        // Do nothing here.
                    }
                    else
                    {
                        // We can have version atribute later. For now remember this attribute and continue
                        badAttribute = name;
                    }
                }while(input.MoveToNextAttribute());
                input.ToParent();
            }

            if (version == null)
            {
                throw new XsltException(Res.Xslt_MissingAttribute, Keywords.s_Version);
            }

            if (badAttribute != null && !compiler.ForwardCompatibility)
            {
                throw XsltException.InvalidAttribute(element, badAttribute);
            }
        }