Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / XmlUtils / System / Xml / Xsl / XsltOld / AttributeAction.cs / 1 / AttributeAction.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.Xml;
using System.Xml.XPath;
internal class AttributeAction : ContainerAction {
private const int NameDone = 2;
private Avt nameAvt;
private Avt nsAvt;
private InputScopeManager manager;
// Compile time precalculated AVTs
private string name;
private string nsUri;
private PrefixQName qname; // When we not have AVTs at all we can do this. null otherwise.
private static PrefixQName CreateAttributeQName(string name, string nsUri, InputScopeManager manager) {
// if name == "xmlns" we don't need to generate this attribute.
// to avoid i'ts generation we can return false and not add AtributeCation to it's parent container action
// for now not creating this.qname will do the trick at execution time
if (name == Keywords.s_Xmlns) return null;
if (nsUri == Keywords.s_XmlnsNamespace) {
throw XsltException.Create(Res.Xslt_ReservedNS, nsUri);
}
PrefixQName qname = new PrefixQName();
qname.SetQName(name);
qname.Namespace = nsUri != null ? nsUri : manager.ResolveXPathNamespace(qname.Prefix);
if (qname.Prefix.StartsWith("xml", StringComparison.Ordinal)) {
if (qname.Prefix.Length == 3) { // prefix == "xml"
if (qname.Namespace == Keywords.s_XmlNamespace && (qname.Name == "lang" || qname.Name == "space")) {
// preserve prefix for xml:lang and xml:space
}
else {
qname.ClearPrefix();
}
}
else if (qname.Prefix == Keywords.s_Xmlns) {
if (qname.Namespace == Keywords.s_XmlnsNamespace) {
// if NS wasn't specified we have to use prefix to find it and this is imposible for 'xmlns'
throw XsltException.Create(Res.Xslt_InvalidPrefix, qname.Prefix);
}
else {
qname.ClearPrefix();
}
}
}
return qname;
}
internal override void Compile(Compiler compiler) {
CompileAttributes(compiler);
CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name);
this.name = PrecalculateAvt(ref this.nameAvt);
this.nsUri = PrecalculateAvt(ref this.nsAvt );
// if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
if (this.nameAvt == null && this.nsAvt == null) {
if(this.name != Keywords.s_Xmlns) {
this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager());
}
}
else {
this.manager = compiler.CloneScopeManager();
}
if (compiler.Recurse()) {
CompileTemplate(compiler);
compiler.ToParent();
}
}
internal override bool CompileAttribute(Compiler compiler) {
string name = compiler.Input.LocalName;
string value = compiler.Input.Value;
if (Keywords.Equals(name, compiler.Atoms.Name)) {
this.nameAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.Namespace)) {
this.nsAvt = Avt.CompileAvt(compiler, value);
}
else {
return false;
}
return true;
}
internal override void Execute(Processor processor, ActionFrame frame) {
Debug.Assert(processor != null && frame != null);
switch (frame.State) {
case Initialized:
if(this.qname != null) {
frame.CalulatedName = this.qname;
}
else {
frame.CalulatedName = CreateAttributeQName(
this.nameAvt == null ? this.name : this.nameAvt.Evaluate(processor, frame),
this.nsAvt == null ? this.nsUri : this.nsAvt .Evaluate(processor, frame),
this.manager
);
if(frame.CalulatedName == null) {
// name == "xmlns" case. Ignore xsl:attribute
frame.Finished();
break;
}
}
goto case NameDone;
case NameDone :
{
PrefixQName qname = frame.CalulatedName;
if (processor.BeginEvent(XPathNodeType.Attribute, qname.Prefix, qname.Name, qname.Namespace, false) == false) {
// Come back later
frame.State = NameDone;
break;
}
processor.PushActionFrame(frame);
frame.State = ProcessingChildren;
break; // Allow children to run
}
case ProcessingChildren:
if (processor.EndEvent(XPathNodeType.Attribute) == false) {
frame.State = ProcessingChildren;
break;
}
frame.Finished();
break;
default:
Debug.Fail("Invalid ElementAction execution state");
break;
}
}
}
}
// 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.Xml;
using System.Xml.XPath;
internal class AttributeAction : ContainerAction {
private const int NameDone = 2;
private Avt nameAvt;
private Avt nsAvt;
private InputScopeManager manager;
// Compile time precalculated AVTs
private string name;
private string nsUri;
private PrefixQName qname; // When we not have AVTs at all we can do this. null otherwise.
private static PrefixQName CreateAttributeQName(string name, string nsUri, InputScopeManager manager) {
// if name == "xmlns" we don't need to generate this attribute.
// to avoid i'ts generation we can return false and not add AtributeCation to it's parent container action
// for now not creating this.qname will do the trick at execution time
if (name == Keywords.s_Xmlns) return null;
if (nsUri == Keywords.s_XmlnsNamespace) {
throw XsltException.Create(Res.Xslt_ReservedNS, nsUri);
}
PrefixQName qname = new PrefixQName();
qname.SetQName(name);
qname.Namespace = nsUri != null ? nsUri : manager.ResolveXPathNamespace(qname.Prefix);
if (qname.Prefix.StartsWith("xml", StringComparison.Ordinal)) {
if (qname.Prefix.Length == 3) { // prefix == "xml"
if (qname.Namespace == Keywords.s_XmlNamespace && (qname.Name == "lang" || qname.Name == "space")) {
// preserve prefix for xml:lang and xml:space
}
else {
qname.ClearPrefix();
}
}
else if (qname.Prefix == Keywords.s_Xmlns) {
if (qname.Namespace == Keywords.s_XmlnsNamespace) {
// if NS wasn't specified we have to use prefix to find it and this is imposible for 'xmlns'
throw XsltException.Create(Res.Xslt_InvalidPrefix, qname.Prefix);
}
else {
qname.ClearPrefix();
}
}
}
return qname;
}
internal override void Compile(Compiler compiler) {
CompileAttributes(compiler);
CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name);
this.name = PrecalculateAvt(ref this.nameAvt);
this.nsUri = PrecalculateAvt(ref this.nsAvt );
// if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
if (this.nameAvt == null && this.nsAvt == null) {
if(this.name != Keywords.s_Xmlns) {
this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager());
}
}
else {
this.manager = compiler.CloneScopeManager();
}
if (compiler.Recurse()) {
CompileTemplate(compiler);
compiler.ToParent();
}
}
internal override bool CompileAttribute(Compiler compiler) {
string name = compiler.Input.LocalName;
string value = compiler.Input.Value;
if (Keywords.Equals(name, compiler.Atoms.Name)) {
this.nameAvt = Avt.CompileAvt(compiler, value);
}
else if (Keywords.Equals(name, compiler.Atoms.Namespace)) {
this.nsAvt = Avt.CompileAvt(compiler, value);
}
else {
return false;
}
return true;
}
internal override void Execute(Processor processor, ActionFrame frame) {
Debug.Assert(processor != null && frame != null);
switch (frame.State) {
case Initialized:
if(this.qname != null) {
frame.CalulatedName = this.qname;
}
else {
frame.CalulatedName = CreateAttributeQName(
this.nameAvt == null ? this.name : this.nameAvt.Evaluate(processor, frame),
this.nsAvt == null ? this.nsUri : this.nsAvt .Evaluate(processor, frame),
this.manager
);
if(frame.CalulatedName == null) {
// name == "xmlns" case. Ignore xsl:attribute
frame.Finished();
break;
}
}
goto case NameDone;
case NameDone :
{
PrefixQName qname = frame.CalulatedName;
if (processor.BeginEvent(XPathNodeType.Attribute, qname.Prefix, qname.Name, qname.Namespace, false) == false) {
// Come back later
frame.State = NameDone;
break;
}
processor.PushActionFrame(frame);
frame.State = ProcessingChildren;
break; // Allow children to run
}
case ProcessingChildren:
if (processor.EndEvent(XPathNodeType.Attribute) == false) {
frame.State = ProcessingChildren;
break;
}
frame.Finished();
break;
default:
Debug.Fail("Invalid ElementAction execution state");
break;
}
}
}
}
// 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
- Menu.cs
- BlockCollection.cs
- GetPageNumberCompletedEventArgs.cs
- SpecialNameAttribute.cs
- DataGridRowHeader.cs
- BasicBrowserDialog.designer.cs
- HostedHttpTransportManager.cs
- PropertyMetadata.cs
- GridItemProviderWrapper.cs
- OleDbDataAdapter.cs
- RawAppCommandInputReport.cs
- TypedServiceChannelBuilder.cs
- XmlAttributeCache.cs
- ActivitySurrogate.cs
- XmlImplementation.cs
- SQLMembershipProvider.cs
- InkPresenterAutomationPeer.cs
- NetSectionGroup.cs
- UnknownBitmapDecoder.cs
- Win32Native.cs
- StackSpiller.Bindings.cs
- BuildProviderAppliesToAttribute.cs
- SimpleHandlerFactory.cs
- MarkupObject.cs
- RecordManager.cs
- GlyphRunDrawing.cs
- Update.cs
- Matrix3D.cs
- ListItemCollection.cs
- AspNetSynchronizationContext.cs
- GridItemProviderWrapper.cs
- XmlSchemaComplexContentExtension.cs
- DbDataRecord.cs
- NotSupportedException.cs
- GetWinFXPath.cs
- FullTrustAssembliesSection.cs
- ReadContentAsBinaryHelper.cs
- CaseInsensitiveHashCodeProvider.cs
- SqlCommand.cs
- DoubleAnimation.cs
- SerializationStore.cs
- DataGridViewCellStyleConverter.cs
- Expression.cs
- XPathAxisIterator.cs
- XmlILOptimizerVisitor.cs
- FontConverter.cs
- ServicePointManager.cs
- _NetworkingPerfCounters.cs
- StringConverter.cs
- ErrorProvider.cs
- IntPtr.cs
- SystemIPInterfaceStatistics.cs
- WebReferenceCollection.cs
- ParameterModifier.cs
- Image.cs
- AnnotationMap.cs
- ScrollChrome.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- AssociatedControlConverter.cs
- DataServiceProcessingPipeline.cs
- ExpressionBindingCollection.cs
- ErrorTableItemStyle.cs
- ProcessInputEventArgs.cs
- CompositeCollectionView.cs
- HorizontalAlignConverter.cs
- HtmlControlPersistable.cs
- SerTrace.cs
- SchemeSettingElement.cs
- CodeGenerator.cs
- OdbcException.cs
- SettingsSavedEventArgs.cs
- AdapterDictionary.cs
- Column.cs
- metadatamappinghashervisitor.cs
- TextEndOfSegment.cs
- Size3DValueSerializer.cs
- InkCanvasFeedbackAdorner.cs
- XmlMemberMapping.cs
- SortFieldComparer.cs
- SingleResultAttribute.cs
- _RequestLifetimeSetter.cs
- DataServiceProviderWrapper.cs
- FunctionNode.cs
- XPathNavigatorException.cs
- FixedSOMFixedBlock.cs
- ListView.cs
- ToolbarAUtomationPeer.cs
- CriticalFinalizerObject.cs
- ColumnMapProcessor.cs
- CommandBinding.cs
- SmtpClient.cs
- LayoutEngine.cs
- ComponentCodeDomSerializer.cs
- TrustManagerMoreInformation.cs
- DoubleLinkList.cs
- UserMapPath.cs
- FormViewDeleteEventArgs.cs
- DataGridViewColumnConverter.cs
- EntityDataSourceViewSchema.cs
- ReceiveCompletedEventArgs.cs