Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / XsltOld / SortAction.cs / 1305376 / SortAction.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml.Xsl.XsltOld { using Res = System.Xml.Utils.Res; using System; using System.Diagnostics; using System.Globalization; using System.Xml; using System.Xml.XPath; internal class SortAction : CompiledAction { private int selectKey = Compiler.InvalidQueryKey; private Avt langAvt; private Avt dataTypeAvt; private Avt orderAvt; private Avt caseOrderAvt; // Compile time precalculated AVTs private string lang; private XmlDataType dataType = XmlDataType.Text; private XmlSortOrder order = XmlSortOrder.Ascending; private XmlCaseOrder caseOrder = XmlCaseOrder.None; private Sort sort; //When we not have AVTs at all we can do this. null otherwise. private bool forwardCompatibility; private InputScopeManager manager; private string ParseLang(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return null; } // XmlComplianceUtil.IsValidLanguageID uses the outdated RFC 1766. It would be // better to remove this method completely and not call it here, but that may // change exception types for some stylesheets. if (! XmlComplianceUtil.IsValidLanguageID(value.ToCharArray(), 0, value.Length) && (value.Length == 0 || CultureInfo.GetCultureInfo(value) == null) ) { if (this.forwardCompatibility) { return null; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "lang", value); } return value; } private XmlDataType ParseDataType(string value, InputScopeManager manager) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlDataType.Text; } if (value == "text") { return XmlDataType.Text; } if (value == "number") { return XmlDataType.Number; } String prefix, localname; PrefixQName.ParseQualifiedName(value, out prefix, out localname); manager.ResolveXmlNamespace(prefix); if (prefix.Length == 0 && ! this.forwardCompatibility) { throw XsltException.Create(Res.Xslt_InvalidAttrValue, "data-type", value); } return XmlDataType.Text; } private XmlSortOrder ParseOrder(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlSortOrder.Ascending; } if (value == "ascending") { return XmlSortOrder.Ascending; } if (value == "descending") { return XmlSortOrder.Descending; } if (this.forwardCompatibility) { return XmlSortOrder.Ascending; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "order", value); } private XmlCaseOrder ParseCaseOrder(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlCaseOrder.None; } if (value == "upper-first") { return XmlCaseOrder.UpperFirst; } if (value == "lower-first") { return XmlCaseOrder.LowerFirst; } if (this.forwardCompatibility) { return XmlCaseOrder.None; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "case-order", value); } internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckEmpty(compiler); if (selectKey == Compiler.InvalidQueryKey) { selectKey = compiler.AddQuery("."); } this.forwardCompatibility = compiler.ForwardCompatibility; this.manager = compiler.CloneScopeManager(); this.lang = ParseLang( PrecalculateAvt(ref this.langAvt )); this.dataType = ParseDataType( PrecalculateAvt(ref this.dataTypeAvt ), manager); this.order = ParseOrder( PrecalculateAvt(ref this.orderAvt )); this.caseOrder = ParseCaseOrder(PrecalculateAvt(ref this.caseOrderAvt)); if(this.langAvt == null && this.dataTypeAvt == null && this.orderAvt == null && this.caseOrderAvt == null) { this.sort = new Sort(this.selectKey, this.lang, this.dataType, this.order, this.caseOrder); } } internal override bool CompileAttribute(Compiler compiler) { string name = compiler.Input.LocalName; string value = compiler.Input.Value; if (Ref.Equal(name, compiler.Atoms.Select)) { this.selectKey = compiler.AddQuery(value); } else if (Ref.Equal(name, compiler.Atoms.Lang)) { this.langAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.DataType)) { this.dataTypeAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.Order)) { this.orderAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.CaseOrder)) { this.caseOrderAvt = Avt.CompileAvt(compiler, value); } else { return false; } return true; } internal override void Execute(Processor processor, ActionFrame frame) { Debug.Assert(processor != null && frame != null); Debug.Assert(frame.State == Initialized); processor.AddSort(this.sort != null ? this.sort : new Sort( this.selectKey, this.langAvt == null ? this.lang : ParseLang( this.langAvt .Evaluate(processor, frame)), this.dataTypeAvt == null ? this.dataType : ParseDataType( this.dataTypeAvt .Evaluate(processor, frame), manager), this.orderAvt == null ? this.order : ParseOrder( this.orderAvt .Evaluate(processor, frame)), this.caseOrderAvt == null ? this.caseOrder : ParseCaseOrder(this.caseOrderAvt.Evaluate(processor, frame)) ) ); frame.Finished(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml.Xsl.XsltOld { using Res = System.Xml.Utils.Res; using System; using System.Diagnostics; using System.Globalization; using System.Xml; using System.Xml.XPath; internal class SortAction : CompiledAction { private int selectKey = Compiler.InvalidQueryKey; private Avt langAvt; private Avt dataTypeAvt; private Avt orderAvt; private Avt caseOrderAvt; // Compile time precalculated AVTs private string lang; private XmlDataType dataType = XmlDataType.Text; private XmlSortOrder order = XmlSortOrder.Ascending; private XmlCaseOrder caseOrder = XmlCaseOrder.None; private Sort sort; //When we not have AVTs at all we can do this. null otherwise. private bool forwardCompatibility; private InputScopeManager manager; private string ParseLang(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return null; } // XmlComplianceUtil.IsValidLanguageID uses the outdated RFC 1766. It would be // better to remove this method completely and not call it here, but that may // change exception types for some stylesheets. if (! XmlComplianceUtil.IsValidLanguageID(value.ToCharArray(), 0, value.Length) && (value.Length == 0 || CultureInfo.GetCultureInfo(value) == null) ) { if (this.forwardCompatibility) { return null; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "lang", value); } return value; } private XmlDataType ParseDataType(string value, InputScopeManager manager) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlDataType.Text; } if (value == "text") { return XmlDataType.Text; } if (value == "number") { return XmlDataType.Number; } String prefix, localname; PrefixQName.ParseQualifiedName(value, out prefix, out localname); manager.ResolveXmlNamespace(prefix); if (prefix.Length == 0 && ! this.forwardCompatibility) { throw XsltException.Create(Res.Xslt_InvalidAttrValue, "data-type", value); } return XmlDataType.Text; } private XmlSortOrder ParseOrder(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlSortOrder.Ascending; } if (value == "ascending") { return XmlSortOrder.Ascending; } if (value == "descending") { return XmlSortOrder.Descending; } if (this.forwardCompatibility) { return XmlSortOrder.Ascending; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "order", value); } private XmlCaseOrder ParseCaseOrder(string value) { if(value == null) { // Avt is not constant, or attribute wasn't defined return XmlCaseOrder.None; } if (value == "upper-first") { return XmlCaseOrder.UpperFirst; } if (value == "lower-first") { return XmlCaseOrder.LowerFirst; } if (this.forwardCompatibility) { return XmlCaseOrder.None; } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "case-order", value); } internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckEmpty(compiler); if (selectKey == Compiler.InvalidQueryKey) { selectKey = compiler.AddQuery("."); } this.forwardCompatibility = compiler.ForwardCompatibility; this.manager = compiler.CloneScopeManager(); this.lang = ParseLang( PrecalculateAvt(ref this.langAvt )); this.dataType = ParseDataType( PrecalculateAvt(ref this.dataTypeAvt ), manager); this.order = ParseOrder( PrecalculateAvt(ref this.orderAvt )); this.caseOrder = ParseCaseOrder(PrecalculateAvt(ref this.caseOrderAvt)); if(this.langAvt == null && this.dataTypeAvt == null && this.orderAvt == null && this.caseOrderAvt == null) { this.sort = new Sort(this.selectKey, this.lang, this.dataType, this.order, this.caseOrder); } } internal override bool CompileAttribute(Compiler compiler) { string name = compiler.Input.LocalName; string value = compiler.Input.Value; if (Ref.Equal(name, compiler.Atoms.Select)) { this.selectKey = compiler.AddQuery(value); } else if (Ref.Equal(name, compiler.Atoms.Lang)) { this.langAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.DataType)) { this.dataTypeAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.Order)) { this.orderAvt = Avt.CompileAvt(compiler, value); } else if (Ref.Equal(name, compiler.Atoms.CaseOrder)) { this.caseOrderAvt = Avt.CompileAvt(compiler, value); } else { return false; } return true; } internal override void Execute(Processor processor, ActionFrame frame) { Debug.Assert(processor != null && frame != null); Debug.Assert(frame.State == Initialized); processor.AddSort(this.sort != null ? this.sort : new Sort( this.selectKey, this.langAvt == null ? this.lang : ParseLang( this.langAvt .Evaluate(processor, frame)), this.dataTypeAvt == null ? this.dataType : ParseDataType( this.dataTypeAvt .Evaluate(processor, frame), manager), this.orderAvt == null ? this.order : ParseOrder( this.orderAvt .Evaluate(processor, frame)), this.caseOrderAvt == null ? this.caseOrder : ParseCaseOrder(this.caseOrderAvt.Evaluate(processor, frame)) ) ); frame.Finished(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PaginationProgressEventArgs.cs
- KeyInfo.cs
- AbstractSvcMapFileLoader.cs
- DigestTraceRecordHelper.cs
- SmtpNetworkElement.cs
- PolyQuadraticBezierSegment.cs
- ProcessMonitor.cs
- Sentence.cs
- updateconfighost.cs
- ModelFactory.cs
- BamlVersionHeader.cs
- TreeNodeCollection.cs
- DeviceOverridableAttribute.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- NameValueSectionHandler.cs
- Polyline.cs
- ScriptRef.cs
- ADMembershipProvider.cs
- PropertiesTab.cs
- OptimizerPatterns.cs
- URL.cs
- Style.cs
- EventLogTraceListener.cs
- SerializationSectionGroup.cs
- MouseEventArgs.cs
- AddressAlreadyInUseException.cs
- TextFormatterHost.cs
- Underline.cs
- TimeoutException.cs
- Brush.cs
- Button.cs
- XmlSerializationGeneratedCode.cs
- _NativeSSPI.cs
- DataGridViewImageColumn.cs
- IdentityHolder.cs
- ExtentJoinTreeNode.cs
- DataSvcMapFile.cs
- OleDbRowUpdatedEvent.cs
- CompositeTypefaceMetrics.cs
- TextElementEditingBehaviorAttribute.cs
- Compilation.cs
- CompilationRelaxations.cs
- KeyNotFoundException.cs
- SyndicationContent.cs
- TextBox.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- IIS7UserPrincipal.cs
- Cast.cs
- Visitor.cs
- InstanceNameConverter.cs
- DataColumnChangeEvent.cs
- ServerValidateEventArgs.cs
- ShutDownListener.cs
- KeyValueSerializer.cs
- AsyncOperationContext.cs
- HttpApplication.cs
- SoapSchemaExporter.cs
- EventRoute.cs
- DataSourceCache.cs
- EnumerableRowCollectionExtensions.cs
- ItemPager.cs
- CustomWebEventKey.cs
- ActiveXSerializer.cs
- MatrixTransform3D.cs
- RadioButton.cs
- AdornerPresentationContext.cs
- DesignerVerbCollection.cs
- ToolStripArrowRenderEventArgs.cs
- SqlBulkCopyColumnMappingCollection.cs
- SQLMoney.cs
- RectValueSerializer.cs
- Int32Rect.cs
- LinkConverter.cs
- Floater.cs
- Image.cs
- InfoCardSymmetricCrypto.cs
- InternalControlCollection.cs
- _NtlmClient.cs
- WebBrowserHelper.cs
- ResizeGrip.cs
- IISUnsafeMethods.cs
- ObjectSet.cs
- DecimalConstantAttribute.cs
- DbUpdateCommandTree.cs
- NullReferenceException.cs
- FieldToken.cs
- ImageListUtils.cs
- XmlComment.cs
- ConfigurationManagerHelper.cs
- WebPartDisplayModeEventArgs.cs
- TypeRefElement.cs
- ProfileModule.cs
- ArraySubsetEnumerator.cs
- DataGridViewColumnStateChangedEventArgs.cs
- HttpException.cs
- CredentialManagerDialog.cs
- Visual3D.cs
- VariableReference.cs
- wgx_render.cs
- DynamicValueConverter.cs