Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,322 @@
//------------------------------------------------------------------------------
// <copyright file="XslTransform.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Xml.Xsl {
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Xml.XPath;
using System.Xml.Xsl.XsltOld;
using MS.Internal.Xml.XPath;
using MS.Internal.Xml.Cache;
using System.Collections.Generic;
using System.Xml.Xsl.XsltOld.Debugger;
using System.Security.Policy;
using System.Security.Permissions;
using System.Runtime.Versioning;
using System.Xml.XmlConfiguration;
[Obsolete("This class has been deprecated. Please use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public sealed class XslTransform {
private XmlResolver _documentResolver = null;
private bool isDocumentResolverSet = false;
private XmlResolver _DocumentResolver {
get {
if (isDocumentResolverSet)
return _documentResolver;
else
return XsltConfigSection.CreateDefaultResolver();
}
}
//
// Compiled stylesheet state
//
private Stylesheet _CompiledStylesheet;
private List<TheQuery> _QueryStore;
private RootAction _RootAction;
private IXsltDebugger debugger;
public XslTransform() {}
public XmlResolver XmlResolver {
set {
_documentResolver = value;
isDocumentResolverSet = true;
}
}
public void Load(XmlReader stylesheet) {
Load(stylesheet, XsltConfigSection.CreateDefaultResolver());
}
public void Load(XmlReader stylesheet, XmlResolver resolver) {
Load(new XPathDocument(stylesheet, XmlSpace.Preserve), resolver);
}
public void Load(IXPathNavigable stylesheet) {
Load(stylesheet, XsltConfigSection.CreateDefaultResolver());
}
public void Load(IXPathNavigable stylesheet, XmlResolver resolver) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
Load(stylesheet.CreateNavigator(), resolver);
}
public void Load(XPathNavigator stylesheet) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
Load(stylesheet, XsltConfigSection.CreateDefaultResolver());
}
public void Load(XPathNavigator stylesheet, XmlResolver resolver) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
Compile(stylesheet, resolver, /*evidence:*/null);
}
[ResourceConsumption(ResourceScope.Machine)]
[ResourceExposure(ResourceScope.Machine)]
public void Load(string url) {
XmlTextReaderImpl tr = new XmlTextReaderImpl(url);
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(tr.BaseURI); // We should ask BaseURI before we start reading because it's changing with each node
Compile(Compiler.LoadDocument(tr).CreateNavigator(), XsltConfigSection.CreateDefaultResolver(), evidence);
}
[ResourceConsumption(ResourceScope.Machine)]
[ResourceExposure(ResourceScope.Machine)]
public void Load(string url, XmlResolver resolver) {
XmlTextReaderImpl tr = new XmlTextReaderImpl(url); {
tr.XmlResolver = resolver;
}
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(tr.BaseURI); // We should ask BaseURI before we start reading because it's changing with each node
Compile(Compiler.LoadDocument(tr).CreateNavigator(), resolver, evidence);
}
public void Load(IXPathNavigable stylesheet, XmlResolver resolver, Evidence evidence) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
Load(stylesheet.CreateNavigator(), resolver, evidence);
}
public void Load(XmlReader stylesheet, XmlResolver resolver, Evidence evidence) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
Load(new XPathDocument(stylesheet, XmlSpace.Preserve), resolver, evidence);
}
public void Load(XPathNavigator stylesheet, XmlResolver resolver, Evidence evidence) {
if (stylesheet == null) {
throw new ArgumentNullException("stylesheet");
}
#if FEATURE_MONO_CAS
if (evidence == null) {
evidence = new Evidence();
}
else {
new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
}
#endif
Compile(stylesheet, resolver, evidence);
}
// ------------------------------------ Transform() ------------------------------------ //
private void CheckCommand() {
if (_CompiledStylesheet == null) {
throw new InvalidOperationException(Res.GetString(Res.Xslt_NoStylesheetLoaded));
}
}
public XmlReader Transform(XPathNavigator input, XsltArgumentList args, XmlResolver resolver) {
CheckCommand();
Processor processor = new Processor(input, args, resolver, _CompiledStylesheet, _QueryStore, _RootAction, debugger);
return processor.StartReader();
}
public XmlReader Transform(XPathNavigator input, XsltArgumentList args) {
return Transform(input, args, _DocumentResolver);
}
public void Transform(XPathNavigator input, XsltArgumentList args, XmlWriter output, XmlResolver resolver) {
CheckCommand();
Processor processor = new Processor(input, args, resolver, _CompiledStylesheet, _QueryStore, _RootAction, debugger);
processor.Execute(output);
}
public void Transform(XPathNavigator input, XsltArgumentList args, XmlWriter output) {
Transform(input, args, output, _DocumentResolver);
}
public void Transform(XPathNavigator input, XsltArgumentList args, Stream output, XmlResolver resolver) {
CheckCommand();
Processor processor = new Processor(input, args, resolver, _CompiledStylesheet, _QueryStore, _RootAction, debugger);
processor.Execute(output);
}
public void Transform(XPathNavigator input, XsltArgumentList args, Stream output) {
Transform(input, args, output, _DocumentResolver);
}
public void Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver) {
CheckCommand();
Processor processor = new Processor(input, args, resolver, _CompiledStylesheet, _QueryStore, _RootAction, debugger);
processor.Execute(output);
}
public void Transform(XPathNavigator input, XsltArgumentList args, TextWriter output) {
CheckCommand();
Processor processor = new Processor(input, args, _DocumentResolver, _CompiledStylesheet, _QueryStore, _RootAction, debugger);
processor.Execute(output);
}
public XmlReader Transform(IXPathNavigable input, XsltArgumentList args, XmlResolver resolver) {
if (input == null) {
throw new ArgumentNullException("input");
}
return Transform(input.CreateNavigator(), args, resolver);
}
public XmlReader Transform(IXPathNavigable input, XsltArgumentList args) {
if (input == null) {
throw new ArgumentNullException("input");
}
return Transform(input.CreateNavigator(), args, _DocumentResolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, resolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, _DocumentResolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, Stream output, XmlResolver resolver) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, resolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, Stream output) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, _DocumentResolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, XmlWriter output, XmlResolver resolver) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, resolver);
}
public void Transform(IXPathNavigable input, XsltArgumentList args, XmlWriter output) {
if (input == null) {
throw new ArgumentNullException("input");
}
Transform(input.CreateNavigator(), args, output, _DocumentResolver);
}
[ResourceConsumption(ResourceScope.Machine)]
[ResourceExposure(ResourceScope.Machine)]
public void Transform(String inputfile, String outputfile, XmlResolver resolver) {
FileStream fs = null;
try {
// We should read doc before creating output file in case they are the same
XPathDocument doc = new XPathDocument(inputfile);
fs = new FileStream(outputfile, FileMode.Create, FileAccess.ReadWrite);
Transform(doc, /*args:*/null, fs, resolver);
}
finally {
if (fs != null) {
fs.Close();
}
}
}
[ResourceConsumption(ResourceScope.Machine)]
[ResourceExposure(ResourceScope.Machine)]
public void Transform(String inputfile, String outputfile) {
Transform(inputfile, outputfile, _DocumentResolver);
}
// Implementation
private void Compile(XPathNavigator stylesheet, XmlResolver resolver, Evidence evidence) {
Debug.Assert(stylesheet != null);
Compiler compiler = (Debugger == null) ? new Compiler() : new DbgCompiler(this.Debugger);
NavigatorInput input = new NavigatorInput(stylesheet);
compiler.Compile(input, resolver ?? XmlNullResolver.Singleton, evidence);
Debug.Assert(compiler.CompiledStylesheet != null);
Debug.Assert(compiler.QueryStore != null);
Debug.Assert(compiler.QueryStore != null);
_CompiledStylesheet = compiler.CompiledStylesheet;
_QueryStore = compiler.QueryStore;
_RootAction = compiler.RootAction;
}
internal IXsltDebugger Debugger {
get { return this.debugger; }
}
#if false
internal XslTransform(IXsltDebugger debugger) {
this.debugger = debugger;
}
#endif
internal XslTransform(object debugger) {
if (debugger != null) {
this.debugger = new DebuggerAddapter(debugger);
}
}
private class DebuggerAddapter : IXsltDebugger {
private object unknownDebugger;
private MethodInfo getBltIn;
private MethodInfo onCompile;
private MethodInfo onExecute;
public DebuggerAddapter(object unknownDebugger) {
this.unknownDebugger = unknownDebugger;
BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
Type unknownType = unknownDebugger.GetType();
getBltIn = unknownType.GetMethod("GetBuiltInTemplatesUri", flags);
onCompile = unknownType.GetMethod("OnInstructionCompile" , flags);
onExecute = unknownType.GetMethod("OnInstructionExecute" , flags);
}
// ------------------ IXsltDebugger ---------------
public string GetBuiltInTemplatesUri() {
if (getBltIn == null) {
return null;
}
return (string) getBltIn.Invoke(unknownDebugger, new object[] {});
}
public void OnInstructionCompile(XPathNavigator styleSheetNavigator) {
if (onCompile != null) {
onCompile.Invoke(unknownDebugger, new object[] { styleSheetNavigator });
}
}
public void OnInstructionExecute(IXsltProcessor xsltProcessor) {
if (onExecute != null) {
onExecute.Invoke(unknownDebugger, new object[] { xsltProcessor });
}
}
}
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
// <copyright file="XsltArgumentList.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
using System.Collections;
using System.Security.Permissions;
namespace System.Xml.Xsl {
public abstract class XsltMessageEncounteredEventArgs : EventArgs {
public abstract string Message { get; }
}
public delegate void XsltMessageEncounteredEventHandler(object sender, XsltMessageEncounteredEventArgs e);
public class XsltArgumentList {
private Hashtable parameters = new Hashtable();
private Hashtable extensions = new Hashtable();
// Used for reporting xsl:message's during execution
internal XsltMessageEncounteredEventHandler xsltMessageEncountered = null;
public XsltArgumentList() {}
public object GetParam(string name, string namespaceUri) {
return this.parameters[new XmlQualifiedName(name, namespaceUri)];
}
public object GetExtensionObject(string namespaceUri) {
return this.extensions[namespaceUri];
}
public void AddParam(string name, string namespaceUri, object parameter) {
CheckArgumentNull(name , "name" );
CheckArgumentNull(namespaceUri, "namespaceUri");
CheckArgumentNull(parameter , "parameter" );
XmlQualifiedName qname = new XmlQualifiedName(name, namespaceUri);
qname.Verify();
this.parameters.Add(qname, parameter);
}
public void AddExtensionObject(string namespaceUri, object extension) {
CheckArgumentNull(namespaceUri, "namespaceUri");
CheckArgumentNull(extension , "extension" );
this.extensions.Add(namespaceUri, extension);
}
public object RemoveParam(string name, string namespaceUri) {
XmlQualifiedName qname = new XmlQualifiedName(name, namespaceUri);
object parameter = this.parameters[qname];
this.parameters.Remove(qname);
return parameter;
}
public object RemoveExtensionObject(string namespaceUri) {
object extension = this.extensions[namespaceUri];
this.extensions.Remove(namespaceUri);
return extension;
}
public event XsltMessageEncounteredEventHandler XsltMessageEncountered {
add {
xsltMessageEncountered += value;
}
remove {
xsltMessageEncountered -= value;
}
}
public void Clear() {
this.parameters.Clear();
this.extensions.Clear();
xsltMessageEncountered = null;
}
private static void CheckArgumentNull(object param, string paramName) {
if (param == null) {
throw new ArgumentNullException(paramName);
}
}
}
}

View File

@@ -0,0 +1,39 @@
//------------------------------------------------------------------------------
// <copyright file="XsltContext.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
using System.Collections;
using System.Xml.XPath;
namespace System.Xml.Xsl {
public interface IXsltContextFunction {
int Minargs { get; }
int Maxargs { get; }
XPathResultType ReturnType { get; }
XPathResultType[] ArgTypes { get; }
object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext);
}
public interface IXsltContextVariable {
bool IsLocal { get; }
bool IsParam { get; }
XPathResultType VariableType { get; }
object Evaluate(XsltContext xsltContext);
}
public abstract class XsltContext : XmlNamespaceManager {
protected XsltContext(NameTable table) : base(table) {}
protected XsltContext() : base(new NameTable()) {}
// This dummy XsltContext that doesn't actualy initialize XmlNamespaceManager
// is used by XsltCompileContext
internal XsltContext(bool dummy) : base() {}
public abstract IXsltContextVariable ResolveVariable(string prefix, string name);
public abstract IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes);
public abstract bool Whitespace { get; }
public abstract bool PreserveWhitespace(XPathNavigator node);
public abstract int CompareDocument (string baseUri, string nextbaseUri);
}
}

View File

@@ -0,0 +1,154 @@
//------------------------------------------------------------------------------
// <copyright file="XsltException.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
using System.Globalization;
using System.Resources;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Xml.XPath;
namespace System.Xml.Xsl {
using Res = System.Xml.Utils.Res;
[Serializable]
public class XsltException : SystemException {
string res;
string[] args;
string sourceUri;
int lineNumber;
int linePosition;
// message != null for V1 & V2 exceptions deserialized in Whidbey
// message == null for created V2 exceptions; the exception message is stored in Exception._message
string message;
protected XsltException(SerializationInfo info, StreamingContext context) : base(info, context) {
res = (string) info.GetValue("res" , typeof(string ));
args = (string[]) info.GetValue("args" , typeof(string[] ));
sourceUri = (string) info.GetValue("sourceUri" , typeof(string ));
lineNumber = (int) info.GetValue("lineNumber" , typeof(int ));
linePosition = (int) info.GetValue("linePosition", typeof(int ));
// deserialize optional members
string version = null;
foreach ( SerializationEntry e in info ) {
if ( e.Name == "version" ) {
version = (string)e.Value;
}
}
if (version == null) {
// deserializing V1 exception
message = CreateMessage(res, args, sourceUri, lineNumber, linePosition);
}
else {
// deserializing V2 or higher exception -> exception message is serialized by the base class (Exception._message)
message = null;
}
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand,SerializationFormatter=true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
base.GetObjectData(info, context);
info.AddValue("res" , res );
info.AddValue("args" , args );
info.AddValue("sourceUri" , sourceUri );
info.AddValue("lineNumber" , lineNumber );
info.AddValue("linePosition", linePosition);
info.AddValue("version" , "2.0");
}
public XsltException() : this (string.Empty, (Exception) null) {}
public XsltException(String message) : this (message, (Exception) null) {}
public XsltException(String message, Exception innerException) :
this(Res.Xml_UserException, new string[] { message }, null, 0, 0, innerException ) {
}
internal static XsltException Create(string res, params string[] args) {
return new XsltException(res, args, null, 0, 0, null);
}
internal static XsltException Create(string res, string[] args, Exception inner) {
return new XsltException(res, args, null, 0, 0, inner);
}
internal XsltException(string res, string[] args, string sourceUri, int lineNumber, int linePosition, Exception inner)
: base(CreateMessage(res, args, sourceUri, lineNumber, linePosition), inner)
{
HResult = HResults.XmlXslt;
this.res = res;
this.sourceUri = sourceUri;
this.lineNumber = lineNumber;
this.linePosition = linePosition;
}
public virtual string SourceUri {
get { return this.sourceUri; }
}
public virtual int LineNumber {
get { return this.lineNumber; }
}
public virtual int LinePosition {
get { return this.linePosition; }
}
public override string Message {
get {
return (message == null) ? base.Message : message;
}
}
private static string CreateMessage(string res, string[] args, string sourceUri, int lineNumber, int linePosition) {
try {
string message = FormatMessage(res, args);
if (res != Res.Xslt_CompileError && lineNumber != 0) {
message += " " + FormatMessage(Res.Xml_ErrorFilePosition, sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture));
}
return message;
}
catch (MissingManifestResourceException) {
return "UNKNOWN(" + res + ")";
}
}
private static string FormatMessage(string key, params string[] args) {
string message = Res.GetString(key);
if (message != null && args != null) {
message = string.Format(CultureInfo.InvariantCulture, message, args);
}
return message;
}
}
[Serializable]
public class XsltCompileException : XsltException {
protected XsltCompileException(SerializationInfo info, StreamingContext context) : base(info, context) {}
[SecurityPermissionAttribute(SecurityAction.LinkDemand,SerializationFormatter=true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
base.GetObjectData(info, context);
}
public XsltCompileException() : base() {}
public XsltCompileException(String message) : base (message) {}
public XsltCompileException(String message, Exception innerException) : base (message, innerException) {}
public XsltCompileException(Exception inner, string sourceUri, int lineNumber, int linePosition) :
base(
lineNumber != 0 ? Res.Xslt_CompileError : Res.Xslt_CompileError2,
new string[] { sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture) },
sourceUri, lineNumber, linePosition, inner
) {}
}
}

View File

@@ -0,0 +1,75 @@
//------------------------------------------------------------------------------
// <copyright file="XsltSettings.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <spec>http://webdata/xml/specs/XslCompiledTransform.xml</spec>
//------------------------------------------------------------------------------
using System.CodeDom.Compiler;
namespace System.Xml.Xsl {
public sealed class XsltSettings {
private bool enableDocumentFunction;
private bool enableScript;
private bool checkOnly;
private bool includeDebugInformation;
private int warningLevel = -1; // -1 means not set
private bool treatWarningsAsErrors;
#if !DISABLE_XSLT_COMPILER
private TempFileCollection tempFiles;
#endif
public XsltSettings() { }
public XsltSettings(bool enableDocumentFunction, bool enableScript) {
this.enableDocumentFunction = enableDocumentFunction;
this.enableScript = enableScript;
}
public static XsltSettings Default {
get { return new XsltSettings(false, false); }
}
public static XsltSettings TrustedXslt {
get { return new XsltSettings(true, true); }
}
public bool EnableDocumentFunction {
get { return enableDocumentFunction; }
set { enableDocumentFunction = value; }
}
public bool EnableScript {
get { return enableScript; }
set { enableScript = value; }
}
internal bool CheckOnly {
get { return checkOnly; }
set { checkOnly = value; }
}
internal bool IncludeDebugInformation {
get { return includeDebugInformation; }
set { includeDebugInformation = value; }
}
internal int WarningLevel {
get { return warningLevel; }
set { warningLevel = value; }
}
internal bool TreatWarningsAsErrors {
get { return treatWarningsAsErrors; }
set { treatWarningsAsErrors = value; }
}
#if !DISABLE_XSLT_COMPILER
internal TempFileCollection TempFiles {
get { return tempFiles; }
set { tempFiles = value; }
}
#endif
}
}