Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / XmlUtils / System / Xml / Xsl / XsltOld / SortAction.cs / 1 / 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, Keywords.s_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 == 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.Length == 0 && ! this.forwardCompatibility) {
throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_DataType, 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 == Keywords.s_Ascending) {
return XmlSortOrder.Ascending;
}
if (value == Keywords.s_Descending) {
return XmlSortOrder.Descending;
}
if (this.forwardCompatibility) {
return XmlSortOrder.Ascending;
}
throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_Order, value);
}
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.Create(Res.Xslt_InvalidAttrValue, Keywords.s_CaseOrder, 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 (Keywords.Equals(name, compiler.Atoms.Select)) {
this.selectKey = compiler.AddQuery(value);
}
else if (Keywords.Equals(name, compiler.Atoms.Lang)) {
this.langAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.DataType)) {
this.dataTypeAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.Order)) {
this.orderAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(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, Keywords.s_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 == 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.Length == 0 && ! this.forwardCompatibility) {
throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_DataType, 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 == Keywords.s_Ascending) {
return XmlSortOrder.Ascending;
}
if (value == Keywords.s_Descending) {
return XmlSortOrder.Descending;
}
if (this.forwardCompatibility) {
return XmlSortOrder.Ascending;
}
throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_Order, value);
}
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.Create(Res.Xslt_InvalidAttrValue, Keywords.s_CaseOrder, 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 (Keywords.Equals(name, compiler.Atoms.Select)) {
this.selectKey = compiler.AddQuery(value);
}
else if (Keywords.Equals(name, compiler.Atoms.Lang)) {
this.langAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.DataType)) {
this.dataTypeAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.Order)) {
this.orderAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(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
- KnownBoxes.cs
- ProxyAttribute.cs
- InputManager.cs
- XmlSchemaExternal.cs
- DriveInfo.cs
- Facet.cs
- TcpProcessProtocolHandler.cs
- PageThemeBuildProvider.cs
- SimpleBitVector32.cs
- SmtpMail.cs
- Gdiplus.cs
- XpsFixedDocumentReaderWriter.cs
- Boolean.cs
- CharacterHit.cs
- ScriptingWebServicesSectionGroup.cs
- WebPartEditVerb.cs
- ConfigXmlCDataSection.cs
- formatter.cs
- sqlcontext.cs
- OutKeywords.cs
- DispatcherOperation.cs
- SchemaExporter.cs
- NotCondition.cs
- FrameworkTextComposition.cs
- ParserContext.cs
- ObjectQueryExecutionPlan.cs
- TextModifier.cs
- Win32NamedPipes.cs
- DesignerOptions.cs
- SetterBaseCollection.cs
- ParallelTimeline.cs
- SharedStream.cs
- WebPartConnectionsDisconnectVerb.cs
- ConnectionsZone.cs
- BitmapEffectDrawing.cs
- ButtonColumn.cs
- Italic.cs
- ColorConvertedBitmapExtension.cs
- NullRuntimeConfig.cs
- XamlFilter.cs
- DetailsViewRow.cs
- ScriptControlDescriptor.cs
- OdbcCommand.cs
- LinkLabel.cs
- PropertyMetadata.cs
- TextTreeUndoUnit.cs
- FrameworkElementFactory.cs
- GridViewDeletedEventArgs.cs
- DataRowView.cs
- PackWebRequestFactory.cs
- WebServiceAttribute.cs
- Compilation.cs
- Quad.cs
- ValidatorCompatibilityHelper.cs
- SecurityKeyIdentifier.cs
- ClientCultureInfo.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- ResourceProviderFactory.cs
- Formatter.cs
- COM2AboutBoxPropertyDescriptor.cs
- ObjectQueryProvider.cs
- DataGridRelationshipRow.cs
- SessionEndingCancelEventArgs.cs
- DesignerRegionCollection.cs
- EdmItemCollection.OcAssemblyCache.cs
- WebPartDisplayModeCancelEventArgs.cs
- RadioButtonList.cs
- WebConfigurationHostFileChange.cs
- PreviewPageInfo.cs
- TriggerAction.cs
- Stylesheet.cs
- CompositionTarget.cs
- TdsParserStateObject.cs
- HttpVersion.cs
- SizeValueSerializer.cs
- TableRowCollection.cs
- WindowsStatic.cs
- AsyncCodeActivityContext.cs
- CapabilitiesAssignment.cs
- TiffBitmapEncoder.cs
- PropertyExpression.cs
- CodeTypeDeclaration.cs
- WebPartVerbsEventArgs.cs
- EventLogInformation.cs
- StringBlob.cs
- CFStream.cs
- XmlWriterSettings.cs
- _HeaderInfoTable.cs
- EventPropertyMap.cs
- ListControl.cs
- SafeEventLogReadHandle.cs
- DiscardableAttribute.cs
- LocalizeDesigner.cs
- Bookmark.cs
- AdCreatedEventArgs.cs
- UnsafeNativeMethodsMilCoreApi.cs
- SHA256.cs
- InputLanguageProfileNotifySink.cs
- TypeResolver.cs
- SizeAnimationBase.cs