|
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.Text; |
|
19 using System.Collections.Generic; |
|
20 using System.Xml; |
|
21 using CrashItemLib.Crash.Base; |
|
22 using SymbianTree; |
|
23 using CrashXmlPlugin.FileFormat.Document; |
|
24 using CrashXmlPlugin.FileFormat.Segment.Entries; |
|
25 |
|
26 namespace CrashXmlPlugin.FileFormat.Node |
|
27 { |
|
28 internal class CXmlNode : SymNodeAddAsChild |
|
29 { |
|
30 #region Constructors |
|
31 protected CXmlNode( string aName ) |
|
32 { |
|
33 iName = aName; |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region API - Framework |
|
38 public virtual void XmlSerialize( CXmlDocumentSerializationParameters aParameters ) |
|
39 { |
|
40 string nodeName = XmlNodeName; |
|
41 // |
|
42 aParameters.Writer.WriteStartElement( null, nodeName, null ); |
|
43 XmlSerializeContent( aParameters ); |
|
44 XmlSerializeChildren( aParameters ); |
|
45 aParameters.Writer.WriteEndElement(); |
|
46 } |
|
47 |
|
48 /// <summary> |
|
49 /// Override this virtual function if you have dynamic content to serialize at the |
|
50 /// level of this node. |
|
51 /// </summary> |
|
52 /// <param name="aParameters"></param> |
|
53 protected virtual void XmlSerializeContent( CXmlDocumentSerializationParameters aParameters ) |
|
54 { |
|
55 } |
|
56 |
|
57 /// <summary> |
|
58 /// By default, this method invokes the XmlSerialize() method on all children. Override this |
|
59 /// method if you have dynamic children to serialize that are not directly added as child nodes. |
|
60 /// </summary> |
|
61 /// <param name="aParameters"></param> |
|
62 protected virtual void XmlSerializeChildren( CXmlDocumentSerializationParameters aParameters ) |
|
63 { |
|
64 SymNodeEnumeratorChildren iterator = new SymNodeEnumeratorChildren( this ); |
|
65 foreach ( SymNode node in iterator ) |
|
66 { |
|
67 try |
|
68 { |
|
69 ( (CXmlNode) node ).XmlSerialize( aParameters ); |
|
70 } |
|
71 catch ( Exception e ) |
|
72 { |
|
73 #if DEBUG |
|
74 System.Diagnostics.Debug.WriteLine( "CXmlNode Exception: " + this.GetType().Name ); |
|
75 System.Diagnostics.Debug.WriteLine( " Message: " + e.Message ); |
|
76 System.Diagnostics.Debug.WriteLine( " Stack: " + e.StackTrace ); |
|
77 #endif |
|
78 } |
|
79 } |
|
80 } |
|
81 #endregion |
|
82 |
|
83 #region Writer Helpers |
|
84 public static void WriteId( CIElement aElement, XmlWriter aWriter ) |
|
85 { |
|
86 aWriter.WriteStartElement( SegConstants.CmnId ); |
|
87 if ( aElement.IsIdExplicit ) |
|
88 { |
|
89 aWriter.WriteAttributeString( SegConstants.CmnType, SegConstants.CmnId_Explicit ); |
|
90 } |
|
91 aWriter.WriteValue( aElement.Id.ToString() ); |
|
92 aWriter.WriteEndElement(); |
|
93 } |
|
94 |
|
95 public static void WriteLink( CIElementId aLinkTo, string aSegment, XmlWriter aWriter ) |
|
96 { |
|
97 aWriter.WriteStartElement( Constants.CmnLink ); |
|
98 aWriter.WriteAttributeString( Constants.CmnLink_Seg, aSegment ); |
|
99 aWriter.WriteValue( aLinkTo.ToString() ); |
|
100 aWriter.WriteEndElement(); |
|
101 } |
|
102 |
|
103 public static void WriteLinkListStart( XmlWriter aWriter, string aSegment ) |
|
104 { |
|
105 aWriter.WriteStartElement( Constants.CmnLinkList ); |
|
106 aWriter.WriteAttributeString( Constants.CmnLink_Seg, aSegment ); |
|
107 } |
|
108 |
|
109 public static void WriteLinkListEnd( XmlWriter aWriter ) |
|
110 { |
|
111 aWriter.WriteEndElement(); |
|
112 } |
|
113 |
|
114 public static void WriteStringIfNotEmpty( XmlWriter aWriter, string aName, string aValue ) |
|
115 { |
|
116 if ( !string.IsNullOrEmpty( aValue ) ) |
|
117 { |
|
118 aWriter.WriteElementString( aName, aValue ); |
|
119 } |
|
120 } |
|
121 |
|
122 public static void WriteDate( XmlWriter aWriter, DateTime aDate, string aName ) |
|
123 { |
|
124 string date = string.Format( "{0:d4}{1:d2}{2:d2}", aDate.Year, aDate.Month, aDate.Day ); |
|
125 aWriter.WriteElementString( aName, date ); |
|
126 } |
|
127 |
|
128 public static void WriteTime( XmlWriter aWriter, DateTime aTime, string aName ) |
|
129 { |
|
130 string time = string.Format( "{0:d2}{1:d2}{2:d2}", aTime.Hour, aTime.Minute, aTime.Second ); |
|
131 aWriter.WriteElementString( aName, time ); |
|
132 } |
|
133 #endregion |
|
134 |
|
135 #region Properties |
|
136 public string Name |
|
137 { |
|
138 get { return iName; } |
|
139 protected set { iName = value; } |
|
140 } |
|
141 #endregion |
|
142 |
|
143 #region From SymNode |
|
144 protected override string XmlNodeName |
|
145 { |
|
146 get |
|
147 { |
|
148 return iName; |
|
149 } |
|
150 } |
|
151 #endregion |
|
152 |
|
153 #region Internal methods |
|
154 #endregion |
|
155 |
|
156 #region From System.Object |
|
157 public override string ToString() |
|
158 { |
|
159 return iName; |
|
160 } |
|
161 #endregion |
|
162 |
|
163 #region Data members |
|
164 private string iName = string.Empty; |
|
165 #endregion |
|
166 } |
|
167 } |