|
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.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.Xml; |
|
21 using System.IO; |
|
22 using CrashItemLib.Sink; |
|
23 using SymbianUtils; |
|
24 |
|
25 namespace CrashXmlPlugin.FileFormat.Document |
|
26 { |
|
27 internal class CXmlDocumentSerializationParameters : CISinkSerializationParameters |
|
28 { |
|
29 #region Constructors |
|
30 public CXmlDocumentSerializationParameters( CISinkSerializationParameters aCopy, CXmlDocumentRoot aDocument ) |
|
31 : base( aCopy ) |
|
32 { |
|
33 PrepareDefaultExtensions(); |
|
34 iDocument = aDocument; |
|
35 // |
|
36 Stream stream = base.CreateFile( out iFileName ); |
|
37 // |
|
38 XmlWriterSettings settings = CreateWriterSettings(); |
|
39 settings.CloseOutput = true; |
|
40 // |
|
41 iWriter = XmlWriter.Create( stream, settings ); |
|
42 } |
|
43 |
|
44 public CXmlDocumentSerializationParameters( CISinkSerializationParameters aCopy, CXmlDocumentRoot aDocument, StringBuilder aBuilder ) |
|
45 : base( aCopy ) |
|
46 { |
|
47 PrepareDefaultExtensions(); |
|
48 iDocument = aDocument; |
|
49 // |
|
50 XmlWriterSettings settings = CreateWriterSettings(); |
|
51 settings.ConformanceLevel = ConformanceLevel.Fragment; |
|
52 settings.OmitXmlDeclaration = true; |
|
53 // |
|
54 iWriter = XmlWriter.Create( aBuilder, settings ); |
|
55 iFileName = string.Empty; |
|
56 } |
|
57 #endregion |
|
58 |
|
59 #region From |
|
60 protected override void PrepareDefaultExtensions() |
|
61 { |
|
62 if ( string.IsNullOrEmpty( base.FileExtensionFailed ) ) |
|
63 { |
|
64 base.FileExtensionFailed = KXmlDefaultExtensionFailure; |
|
65 } |
|
66 if ( string.IsNullOrEmpty( base.FileExtensionSuccess ) ) |
|
67 { |
|
68 base.FileExtensionSuccess = KXmlDefaultExtensionSuccess; |
|
69 } |
|
70 } |
|
71 #endregion |
|
72 |
|
73 #region Properties |
|
74 public CXmlDocumentRoot Document |
|
75 { |
|
76 get { return iDocument; } |
|
77 } |
|
78 |
|
79 public XmlWriter Writer |
|
80 { |
|
81 get { return iWriter; } |
|
82 } |
|
83 |
|
84 public string FileName |
|
85 { |
|
86 get { return iFileName; } |
|
87 } |
|
88 #endregion |
|
89 |
|
90 #region Internal constants |
|
91 private const string KXmlDefaultExtensionSuccess = ".xml"; |
|
92 private const string KXmlDefaultExtensionFailure = ".failedxml"; |
|
93 #endregion |
|
94 |
|
95 #region From DisposableObject |
|
96 protected override void CleanupManagedResources() |
|
97 { |
|
98 try |
|
99 { |
|
100 base.CleanupManagedResources(); |
|
101 } |
|
102 finally |
|
103 { |
|
104 iWriter.Flush(); |
|
105 iWriter.Close(); |
|
106 } |
|
107 } |
|
108 #endregion |
|
109 |
|
110 #region Internal methods |
|
111 private static XmlWriterSettings CreateWriterSettings() |
|
112 { |
|
113 XmlWriterSettings settings = new XmlWriterSettings(); |
|
114 settings.Indent = true; |
|
115 settings.IndentChars = " "; |
|
116 settings.NewLineHandling = NewLineHandling.None; |
|
117 settings.Encoding = Encoding.UTF8; |
|
118 // |
|
119 return settings; |
|
120 } |
|
121 #endregion |
|
122 |
|
123 #region Data members |
|
124 private readonly string iFileName; |
|
125 private readonly XmlWriter iWriter; |
|
126 private readonly CXmlDocumentRoot iDocument; |
|
127 #endregion |
|
128 } |
|
129 } |