|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 using System.Xml; |
|
20 using System.Text; |
|
21 using System.Collections.Generic; |
|
22 using SymbianTree; |
|
23 using SymbianUtils; |
|
24 using SymbianXmlInputLib.Elements; |
|
25 using SymbianXmlInputLib.Parser.Nodes; |
|
26 |
|
27 namespace SymbianXmlInputLib.Parser |
|
28 { |
|
29 public class SXILParser : DisposableObject |
|
30 { |
|
31 #region Constructors |
|
32 public SXILParser( string aFileName, string aRootNodeName, SXILDocument aDocument ) |
|
33 { |
|
34 iFileName = aFileName; |
|
35 iDocument = aDocument; |
|
36 iRootNodeName = aRootNodeName; |
|
37 // |
|
38 XmlReaderSettings settings = new XmlReaderSettings(); |
|
39 settings.ConformanceLevel = ConformanceLevel.Auto; |
|
40 settings.IgnoreComments = true; |
|
41 settings.CheckCharacters = true; |
|
42 settings.IgnoreWhitespace = true; |
|
43 // |
|
44 iReader = XmlReader.Create( iFileName, settings ); |
|
45 iXmlDocument.Load( iReader ); |
|
46 } |
|
47 #endregion |
|
48 |
|
49 #region API |
|
50 public void Parse() |
|
51 { |
|
52 ValidateRoot(); |
|
53 ParseTopLevelNodes(); |
|
54 } |
|
55 |
|
56 public void CategoryAdd( string aName, SXILParserNodeCollection aParsers ) |
|
57 { |
|
58 SXILParserNodeCategory category = new SXILParserNodeCategory( aName ); |
|
59 category.Children = aParsers; |
|
60 iParsers.Add( category ); |
|
61 } |
|
62 |
|
63 public void CategoryAdd( string aName, params SXILParserNode[] aParserNodes ) |
|
64 { |
|
65 SXILParserNodeCategory category = new SXILParserNodeCategory( aName ); |
|
66 foreach ( SXILParserNode parserNode in aParserNodes ) |
|
67 { |
|
68 category.Children.Add( parserNode ); |
|
69 } |
|
70 iParsers.Add( category ); |
|
71 } |
|
72 #endregion |
|
73 |
|
74 #region Properties |
|
75 internal SXILDocument Document |
|
76 { |
|
77 get { return iDocument; } |
|
78 } |
|
79 #endregion |
|
80 |
|
81 #region Internal methods |
|
82 private void ValidateRoot() |
|
83 { |
|
84 XmlElement root = iXmlDocument.DocumentElement; |
|
85 if ( root != null && root.Name != iRootNodeName ) |
|
86 { |
|
87 throw new Exception( "Document Root Incorrect" ); |
|
88 } |
|
89 } |
|
90 |
|
91 private void ParseTopLevelNodes() |
|
92 { |
|
93 foreach ( XmlNode child in iXmlDocument.DocumentElement ) |
|
94 { |
|
95 bool handled = iParsers.XmlParse( child, this ); |
|
96 if ( handled ) |
|
97 { |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 private void OnElementStart() |
|
103 { |
|
104 } |
|
105 #endregion |
|
106 |
|
107 #region From DisposableObject |
|
108 protected override void CleanupManagedResources() |
|
109 { |
|
110 base.CleanupManagedResources(); |
|
111 iReader.Close(); |
|
112 } |
|
113 #endregion |
|
114 |
|
115 #region Data members |
|
116 private readonly string iFileName; |
|
117 private readonly string iRootNodeName; |
|
118 private readonly SXILDocument iDocument; |
|
119 private readonly XmlReader iReader; |
|
120 private XmlDocument iXmlDocument = new XmlDocument(); |
|
121 private SXILParserNodeCollection iParsers = new SXILParserNodeCollection(); |
|
122 #endregion |
|
123 } |
|
124 } |