[NUI][XamlBuild] Fix Xaml issues reported by VD
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / EXaml / LoadEXaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI.EXaml
22 {
23     internal static class LoadEXaml
24     {
25         internal static GlobalDataList GatherDataList(string xaml)
26         {
27             var globalDataList = new GlobalDataList();
28
29             Action currentAction = new RootAction(globalDataList);
30             var rootAction = currentAction;
31
32             int index = 0;
33
34             for (; index < xaml.Length; index++)
35             {
36                 var c = xaml[index];
37
38                 if (currentAction == rootAction && '/' == c)
39                 {
40                     break;
41                 }
42                 else
43                 {
44                     currentAction = currentAction.DealChar(c);
45                 }
46             }
47
48             for (index++; index < xaml.Length; index++)
49             {
50                 globalDataList.LongStrings += xaml[index];
51             }
52
53             foreach (var op in globalDataList.PreLoadOperations)
54             {
55                 op.Do();
56             }
57
58             return globalDataList;
59         }
60
61         internal static void Load(object view, string xaml, out GlobalDataList xamlData)
62         {
63             var globalDataList = GatherDataList(xaml);
64
65             globalDataList.Root = view;
66
67             foreach (var op in globalDataList.Operations)
68             {
69                 op.Do();
70             }
71
72             xamlData = globalDataList;
73         }
74
75         internal static void Load(object view, object preloadData)
76         {
77             var globalDataList = preloadData as GlobalDataList;
78
79             if (null == globalDataList)
80             {
81                 return;
82             }
83
84             globalDataList.Root = view;
85
86             foreach (var op in globalDataList.Operations)
87             {
88                 op.Do();
89             }
90         }
91
92         internal static void RemoveEventsInXaml(object eXamlData)
93         {
94             if (eXamlData is GlobalDataList globalDataList)
95             {
96                 foreach (var op in globalDataList.RemoveEventOperations)
97                 {
98                     op.Do();
99                 }
100             }
101         }
102     }
103 }