Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / ValueOfAction.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="ValueOfAction.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml.Xsl.XsltOld {
9     using Res = System.Xml.Utils.Res;
10     using System;
11     using System.Diagnostics;
12     using System.Xml;
13     using System.Xml.XPath;
14
15     internal class ValueOfAction : CompiledAction {
16         private const int ResultStored = 2;
17
18         private int    selectKey = Compiler.InvalidQueryKey;
19         private bool   disableOutputEscaping;
20
21         private static Action s_BuiltInRule = new BuiltInRuleTextAction();
22
23         internal static Action BuiltInRule() {
24             Debug.Assert(s_BuiltInRule != null);
25             return s_BuiltInRule;
26         }
27
28         internal override void Compile(Compiler compiler) {
29             CompileAttributes(compiler);
30             CheckRequiredAttribute(compiler, selectKey != Compiler.InvalidQueryKey, "select");
31             CheckEmpty(compiler);
32         }
33
34         internal override bool CompileAttribute(Compiler compiler) {
35             string name   = compiler.Input.LocalName;
36             string value  = compiler.Input.Value;
37
38             if (Ref.Equal(name, compiler.Atoms.Select)) {
39                 this.selectKey = compiler.AddQuery(value);
40             }
41             else if (Ref.Equal(name, compiler.Atoms.DisableOutputEscaping)) {
42                 this.disableOutputEscaping = compiler.GetYesNo(value);
43             }
44             else {
45                 return false;
46             }
47
48             return true;
49         }
50
51         internal override void Execute(Processor processor, ActionFrame frame) {
52             Debug.Assert(processor != null && frame != null);
53
54             switch (frame.State) {
55             case Initialized:
56                 Debug.Assert(frame != null);
57                 Debug.Assert(frame.NodeSet != null);
58
59                 string value = processor.ValueOf(frame, this.selectKey);
60
61                 if (processor.TextEvent(value, disableOutputEscaping)) {
62                     frame.Finished();
63                 }
64                 else {
65                     frame.StoredOutput = value;
66                     frame.State        = ResultStored;
67                 }
68                 break;
69
70             case ResultStored:
71                 Debug.Assert(frame.StoredOutput != null);
72                 processor.TextEvent(frame.StoredOutput);
73                 frame.Finished();
74                 break;
75
76             default:
77                 Debug.Fail("Invalid ValueOfAction execution state");
78                 break;
79             }
80         }
81     }
82
83     internal class BuiltInRuleTextAction : Action {
84         private const int ResultStored = 2;
85         internal override void Execute(Processor processor, ActionFrame frame) {
86             Debug.Assert(processor != null && frame != null);
87
88             switch (frame.State) {
89             case Initialized:
90                 Debug.Assert(frame != null);
91                 Debug.Assert(frame.NodeSet != null);
92
93                 string value = processor.ValueOf(frame.NodeSet.Current);
94
95                 if (processor.TextEvent(value, /*disableOutputEscaping:*/false)) {
96                     frame.Finished();
97                 }
98                 else {
99                     frame.StoredOutput = value;
100                     frame.State        = ResultStored;
101                 }
102                 break;
103
104             case ResultStored:
105                 Debug.Assert(frame.StoredOutput != null);
106                 processor.TextEvent(frame.StoredOutput);
107                 frame.Finished();
108                 break;
109
110             default:
111                 Debug.Fail("Invalid BuiltInRuleTextAction execution state");
112                 break;
113             }
114         }
115     }    
116 }