Inheritance: SystemException
Exemplo n.º 1
0
      public SystemXsltException(XsltException exception)
         : base(exception.Message, exception) {

         base.LineNumber = exception.LineNumber;

         if (!String.IsNullOrEmpty(exception.SourceUri))
            base.ModuleUri = new Uri(exception.SourceUri);
      }
Exemplo n.º 2
0
		public void DenyUnrestricted ()
		{
			// can we call everything without a SecurityException ?
			XsltException xe = new XsltException (String.Empty, null);
			Assert.AreEqual (0, xe.LineNumber, "LineNumber");
			Assert.AreEqual (0, xe.LinePosition, "LinePosition");
			Assert.IsNotNull (xe.Message, "Message");
			Assert.IsNull (xe.SourceUri, "SourceUri");
		}
Exemplo n.º 3
0
		public void Constructor0 ()
		{
			XsltException xsltException = new XsltException ();
			Assert.AreEqual (0, xsltException.LineNumber, "#1");
			Assert.AreEqual (0, xsltException.LinePosition, "#2");
			Assert.AreEqual (string.Empty, xsltException.Message, "#3");
			Assert.IsNull (xsltException.SourceUri, "#4");
			Assert.IsNull (xsltException.InnerException, "#5");
			Assert.IsNull (xsltException.Source, "#6");
			Assert.IsNull (xsltException.StackTrace, "#7");
			Assert.IsNull (xsltException.TargetSite, "#8");
		}
		public void Constructor2 ()
		{
			string msg = "mono";
			Exception cause = new ApplicationException ("cause");

			XsltException xsltException = new XsltException (msg, cause);
			Assert.AreEqual (0, xsltException.LineNumber, "#A1");
			Assert.AreEqual (0, xsltException.LinePosition, "#A2");
			Assert.AreEqual (msg, xsltException.Message, "#A3");
			Assert.IsNull (xsltException.SourceUri, "#A4");
			Assert.AreSame (cause, xsltException.InnerException, "#A5");
			Assert.IsNull (xsltException.Source, "#A6");
#if !TARGET_JVM
			Assert.IsNull (xsltException.StackTrace, "#A7");
			Assert.IsNull (xsltException.TargetSite, "#A8");
#endif
			xsltException = new XsltException ((string) null, cause);
			Assert.AreEqual (0, xsltException.LineNumber, "#B1");
			Assert.AreEqual (0, xsltException.LinePosition, "#B2");
			Assert.IsNotNull (xsltException.Message, "#B3");
			Assert.AreEqual (string.Empty, xsltException.Message, "#B4");
			Assert.IsNull (xsltException.SourceUri, "#B5");
			Assert.AreSame (cause, xsltException.InnerException, "#B6");
			Assert.IsNull (xsltException.Source, "#B7");
#if !TARGET_JVM
			Assert.IsNull (xsltException.StackTrace, "#B8");
			Assert.IsNull (xsltException.TargetSite, "#B9");
#endif
			xsltException = new XsltException (msg, (Exception) null);
			Assert.AreEqual (0, xsltException.LineNumber, "#C1");
			Assert.AreEqual (0, xsltException.LinePosition, "#C2");
			Assert.AreEqual (msg, xsltException.Message, "#C3");
			Assert.IsNull (xsltException.SourceUri, "#C4");
			Assert.IsNull (xsltException.InnerException, "#C5");
			Assert.IsNull (xsltException.Source, "#C6");
#if !TARGET_JVM
			Assert.IsNull (xsltException.StackTrace, "#C7");
			Assert.IsNull (xsltException.TargetSite, "#C8");
#endif
			xsltException = new XsltException ((string) null, (Exception) null);
			Assert.AreEqual (0, xsltException.LineNumber, "#D1");
			Assert.AreEqual (0, xsltException.LinePosition, "#D2");
			Assert.AreEqual (string.Empty, xsltException.Message, "#D3");
			Assert.IsNull (xsltException.SourceUri, "#D4");
			Assert.IsNull (xsltException.InnerException, "#D5");
			Assert.IsNull (xsltException.Source, "#D6");
#if !TARGET_JVM
			Assert.IsNull (xsltException.StackTrace, "#D7");
			Assert.IsNull (xsltException.TargetSite, "#D8");
#endif
		}
		public void Constructor1 ()
		{
			string msg = "mono";

			XsltException xsltException = new XsltException (msg);
			Assert.AreEqual (0, xsltException.LineNumber, "#1");
			Assert.AreEqual (0, xsltException.LinePosition, "#2");
			Assert.AreEqual (msg, xsltException.Message, "#3");
			Assert.IsNull (xsltException.SourceUri, "#4");
			Assert.IsNull (xsltException.InnerException, "#5");
			Assert.IsNull (xsltException.Source, "#6");
#if !TARGET_JVM
			Assert.IsNull (xsltException.StackTrace, "#7");
			Assert.IsNull (xsltException.TargetSite, "#8");
#endif
		}
Exemplo n.º 6
0
        internal string GetSingleAttribute(string attributeAtom)
        {
            NavigatorInput input   = Input;
            string         element = input.LocalName;
            string         value   = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    Debug.TraceAttribute(input);
                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

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

                    if (Keywords.Equals(name, attributeAtom))
                    {
                        value = input.Value;
                    }
                    else
                    {
                        if (!this.ForwardCompatibility)
                        {
                            throw XsltException.InvalidAttribute(element, name);
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            if (value == null)
            {
                throw new XsltException(Res.Xslt_MissingAttribute, attributeAtom);
            }
            return(value);
        }
Exemplo n.º 7
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.º 8
0
        public void CompileAttributes(Compiler compiler)
        {
            NavigatorInput input   = compiler.Input;
            string         element = input.LocalName;

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

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

                    try {
                        if (CompileAttribute(compiler) == false)
                        {
                            throw XsltException.InvalidAttribute(element, input.LocalName);
                        }
                    }catch (Exception) {
                        if (!compiler.ForwardCompatibility)
                        {
                            throw;
                        }
                        else
                        {
                            // In ForwardCompatibility mode we ignoreing all unknown or incorrect attributes
                            // If it's mandatory attribute we'l notice it absents later.
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }
        }
Exemplo n.º 9
0
        void CompileInstruction(Compiler compiler)
        {
            NavigatorInput input  = compiler.Input;
            CompiledAction action = null;

            Debug.Assert(Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace));

            string name = input.LocalName;

            if (Keywords.Equals(name, input.Atoms.ApplyImports))
            {
                action = compiler.CreateApplyImportsAction();
            }
            else if (Keywords.Equals(name, input.Atoms.ApplyTemplates))
            {
                action = compiler.CreateApplyTemplatesAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Attribute))
            {
                action = compiler.CreateAttributeAction();
            }
            else if (Keywords.Equals(name, input.Atoms.CallTemplate))
            {
                action = compiler.CreateCallTemplateAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Choose))
            {
                action = compiler.CreateChooseAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Comment))
            {
                action = compiler.CreateCommentAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Copy))
            {
                action = compiler.CreateCopyAction();
            }
            else if (Keywords.Equals(name, input.Atoms.CopyOf))
            {
                action = compiler.CreateCopyOfAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Element))
            {
                action = compiler.CreateElementAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Fallback))
            {
                return;
            }
            else if (Keywords.Equals(name, input.Atoms.ForEach))
            {
                action = compiler.CreateForEachAction();
            }
            else if (Keywords.Equals(name, input.Atoms.If))
            {
                action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf);
            }
            else if (Keywords.Equals(name, input.Atoms.Message))
            {
                action = compiler.CreateMessageAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Number))
            {
                action = compiler.CreateNumberAction();
            }
            else if (Keywords.Equals(name, input.Atoms.ProcessingInstruction))
            {
                action = compiler.CreateProcessingInstructionAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Text))
            {
                action = compiler.CreateTextAction();
            }
            else if (Keywords.Equals(name, input.Atoms.ValueOf))
            {
                action = compiler.CreateValueOfAction();
            }
            else if (Keywords.Equals(name, input.Atoms.Variable))
            {
                action = compiler.CreateVariableAction(VariableType.LocalVariable);
            }
            else
            {
                if (compiler.ForwardCompatibility)
                {
                    action = compiler.CreateNewInstructionAction();
                }
                else
                {
                    throw XsltException.UnexpectedKeyword(compiler);
                }
            }

            Debug.Assert(action != null);

            AddAction(action);
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        protected void CompileTopLevelElements(Compiler compiler)
        {
            // Navigator positioned at parent root, need to move to child and then back
            if (compiler.Recurse() == false)
            {
                Debug.WriteLine("Nothing to compile, exiting");
                return;
            }

            NavigatorInput input           = compiler.Input;
            bool           notFirstElement = false;

            do
            {
                Debug.Trace(input);
                switch (input.NodeType)
                {
                case XPathNodeType.Element:
                    string name   = input.LocalName;
                    string nspace = input.NamespaceURI;

                    if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                    {
                        if (Keywords.Equals(name, input.Atoms.Import))
                        {
                            if (notFirstElement)
                            {
                                throw new XsltException(Res.Xslt_NotFirstImport);
                            }
                            // We should compile imports in reverse order after all toplevel elements.
                            // remember it now and return to it in CompileImpoorts();
                            compiler.CompiledStylesheet.Imports.Add(compiler.GetSingleAttribute(compiler.Input.Atoms.Href));
                        }
                        else if (Keywords.Equals(name, input.Atoms.Include))
                        {
                            notFirstElement = true;
                            CompileInclude(compiler);
                        }
                        else
                        {
                            notFirstElement = true;
                            compiler.PushNamespaceScope();
                            if (Keywords.Equals(name, input.Atoms.StripSpace))
                            {
                                CompileSpace(compiler, false);
                            }
                            else if (Keywords.Equals(name, input.Atoms.PreserveSpace))
                            {
                                CompileSpace(compiler, true);
                            }
                            else if (Keywords.Equals(name, input.Atoms.Output))
                            {
                                CompileOutput(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.Key))
                            {
                                CompileKey(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.DecimalFormat))
                            {
                                CompileDecimalFormat(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.NamespaceAlias))
                            {
                                CompileNamespaceAlias(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.AttributeSet))
                            {
                                compiler.AddAttributeSet(compiler.CreateAttributeSetAction());
                            }
                            else if (Keywords.Equals(name, input.Atoms.Variable))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Keywords.Equals(name, input.Atoms.Param))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Keywords.Equals(name, input.Atoms.Template))
                            {
                                compiler.AddTemplate(compiler.CreateTemplateAction());
                            }
                            else
                            {
                                if (!compiler.ForwardCompatibility)
                                {
                                    throw XsltException.UnexpectedKeyword(compiler);
                                }
                            }
                            compiler.PopScope();
                        }
                    }
                    else if (nspace == input.Atoms.MsXsltNamespace && name == input.Atoms.Script)
                    {
                        AddScript(compiler);
                    }
                    else
                    {
                        if (Keywords.Equals(nspace, input.Atoms.Empty))
                        {
                            throw new XsltException(Res.Xslt_NullNsAtTopLevel, input.Name);
                        }
                        // Ignoring non-recognized namespace per XSLT spec 2.2
                    }
                    break;

                case XPathNodeType.ProcessingInstruction:
                case XPathNodeType.Comment:
                case XPathNodeType.Whitespace:
                case XPathNodeType.SignificantWhitespace:
                    break;

                default:
                    throw new XsltException(Res.Xslt_InvalidContents, "xsl:stylesheet");
                }
            }while (compiler.Advance());

            compiler.ToParent();
        }
Exemplo n.º 12
0
        internal XsltException(string message, Exception innerException, XPathNavigator nav) : base(XsltException.CreateMessage(message, nav), innerException)
        {
            IXmlLineInfo xmlLineInfo = nav as IXmlLineInfo;

            this.lineNumber   = ((xmlLineInfo == null) ? 0 : xmlLineInfo.LineNumber);
            this.linePosition = ((xmlLineInfo == null) ? 0 : xmlLineInfo.LinePosition);
            this.sourceUri    = ((nav == null) ? string.Empty : nav.BaseURI);
        }
Exemplo n.º 13
0
 internal XsltException(string msgFormat, string message, Exception innerException, int lineNumber, int linePosition, string sourceUri) : base(XsltException.CreateMessage(msgFormat, message, lineNumber, linePosition, sourceUri), innerException)
 {
     this.lineNumber   = lineNumber;
     this.linePosition = linePosition;
     this.sourceUri    = sourceUri;
 }
Exemplo n.º 14
0
		public virtual void Evaluate (XslTransformProcessor p, Hashtable withParams)
		{
			if (XslTransform.TemplateStackFrameError) {
				try {
					EvaluateCore (p, withParams);
				} catch (XsltException ex) {
					AppendTemplateFrame (ex);
					throw ex;
				} catch (Exception) {
					// Note that this catch causes different
					// type of error to be thrown (esp.
					// this causes NUnit test regression).
					XsltException e = new XsltException ("Error during XSLT processing: ", null, p.CurrentNode);
					AppendTemplateFrame (e);
					throw e;
				}
			}
			else
				EvaluateCore (p, withParams);
		}
Exemplo n.º 15
0
		void AppendTemplateFrame (XsltException ex)
		{
			ex.AddTemplateFrame (LocationMessage);
		}
Exemplo n.º 16
0
		public void PermitOnlySerializationFormatter_GetObjectData ()
		{
			StreamingContext sc = new StreamingContext (StreamingContextStates.All);
			XsltException xe = new XsltException (String.Empty, null);
			xe.GetObjectData (null, sc);
		}