|
1 /* |
|
2 * Copyright (c) 2006 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: CNcdTopLevelParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32debug.h> |
|
20 #include "ncdtoplevelparser.h" |
|
21 #include "ncdparserobserver.h" |
|
22 #include "ncdunknownparser.h" |
|
23 #include "catalogsdebug.h" |
|
24 #include "ncdprotocolwords.h" |
|
25 #include "ncdprotocolutils.h" |
|
26 |
|
27 #include "ncd_parser_pp_response.h" |
|
28 #include "ncd_parser_cp_response.h" |
|
29 |
|
30 CNcdTopLevelParser* CNcdTopLevelParser::NewL( MNcdParserObserverBundle& aObservers, |
|
31 MNcdSubParserObserver& aSubParserObserver, |
|
32 TInt aDepth ) |
|
33 { |
|
34 DLTRACE(("depth=%d",aDepth)); |
|
35 CNcdTopLevelParser* self = new(ELeave) CNcdTopLevelParser( aObservers, |
|
36 aSubParserObserver, |
|
37 aDepth ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CNcdTopLevelParser::CNcdTopLevelParser( MNcdParserObserverBundle& aObservers, |
|
45 MNcdSubParserObserver& aSubParserObserver, |
|
46 TInt aDepth ) |
|
47 : CNcdSubParser( aObservers, aSubParserObserver, aDepth ) |
|
48 { |
|
49 } |
|
50 |
|
51 CNcdTopLevelParser::~CNcdTopLevelParser() |
|
52 { |
|
53 } |
|
54 |
|
55 void CNcdTopLevelParser::ConstructL() |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 void CNcdTopLevelParser::OnStartElementL( const Xml::RTagInfo& aElement, |
|
61 const Xml::RAttributeArray& aAttributes, |
|
62 TInt aErrorCode ) |
|
63 { |
|
64 |
|
65 CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode ); |
|
66 |
|
67 DLTRACEIN(("")); |
|
68 |
|
69 // Error code checks need only be done in the top level parser, |
|
70 // all calls come through it. |
|
71 if( aErrorCode != KErrNone ) |
|
72 { |
|
73 DLERROR(("%d",aErrorCode)); |
|
74 iObservers->ParserObserver()->ParseError( aErrorCode ); |
|
75 return; |
|
76 } |
|
77 |
|
78 TPtrC8 tag( aElement.LocalName().DesC() ); |
|
79 // Here we handle the tag. If we don't know how to do it, try to create a subparser. |
|
80 |
|
81 if( iSubParser == 0 ) |
|
82 { |
|
83 DLTRACE(("start tag=%S",&tag)); |
|
84 if ( tag == KTagPreminetResponse ) |
|
85 { |
|
86 iSubParser = CNcdPreminetProtocolResponseParser::NewL( *iObservers, *this, iDepth+1, |
|
87 aElement, aAttributes ); |
|
88 } |
|
89 else if ( tag == KTagConfigurationResponse ) |
|
90 { |
|
91 iSubParser = CNcdConfigurationProtocolResponseParser::NewL( *iObservers, *this, iDepth+1, |
|
92 aElement, aAttributes ); |
|
93 } |
|
94 else |
|
95 { |
|
96 iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, |
|
97 aElement, aAttributes ); |
|
98 } |
|
99 } |
|
100 |
|
101 else |
|
102 { |
|
103 // Using old subparser |
|
104 iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode ); |
|
105 } |
|
106 |
|
107 } |
|
108 |
|
109 void CNcdTopLevelParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode) |
|
110 { |
|
111 DLTRACE(("")); |
|
112 |
|
113 // Error code checks need only be done in the top level parser, |
|
114 // all calls come through it. |
|
115 if( aErrorCode != KErrNone ) |
|
116 { |
|
117 DLERROR(("%d",aErrorCode)); |
|
118 iObservers->ParserObserver()->ParseError( aErrorCode ); |
|
119 return; |
|
120 } |
|
121 |
|
122 CNcdSubParser::OnEndElementL( aElement, aErrorCode ); |
|
123 } |
|
124 |
|
125 void CNcdTopLevelParser::OnContentL(const TDesC8& aBytes, TInt aErrorCode) |
|
126 { |
|
127 DLTRACEIN(("")); |
|
128 // Error code checks need only be done in the top level parser, |
|
129 // all calls come through it. |
|
130 if( aErrorCode != KErrNone ) |
|
131 { |
|
132 DLERROR(("%d",aErrorCode)); |
|
133 iObservers->ParserObserver()->ParseError( aErrorCode ); |
|
134 return; |
|
135 } |
|
136 |
|
137 if( iSubParser ) |
|
138 { |
|
139 // Is this correct? if the content comes in chunks and a middle chunck |
|
140 // is dismissed due to this check, then an error probably occurs. |
|
141 if( /*NcdProtocolUtils::IsWhitespace( aBytes )*/false ) |
|
142 { |
|
143 // DLINFO(("Skipping %db whitespace content",aBytes.Length())); |
|
144 } |
|
145 else if( iSubParser ) |
|
146 { |
|
147 iSubParser->OnContentL( aBytes, aErrorCode ); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 DLWARNING(("Ignoring %d bytes content",aBytes.Length())); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 void CNcdTopLevelParser::StartL( const Xml::RTagInfo& /*aElement*/, |
|
159 const Xml::RAttributeArray& /*aAttributes*/, |
|
160 TInt /*aErrorCode*/ ) |
|
161 { |
|
162 } |
|
163 |
|
164 // void CNcdTopLevelParser::EndL( const Xml::RTagInfo& aElement, |
|
165 // TInt aErrorCode ) |
|
166 // { |
|
167 // } |
|
168 |
|
169 // void CNcdTopLevelParser::SubParserFinishedL( const TDesC8& aTag, |
|
170 // TInt aErrorCode ) |
|
171 // { |
|
172 // DLTRACE(("SubParserFinishedL")); |
|
173 |
|
174 // delete iSubParser; |
|
175 // iSubParser = 0; |
|
176 // } |