|
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: CNcdSubParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdprotocolutils.h" |
|
20 #include "ncdsubparser.h" |
|
21 #include "ncdparserobserver.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdprotocolutils.h" |
|
24 |
|
25 CNcdSubParser::CNcdSubParser( MNcdParserObserverBundle& aObservers, |
|
26 MNcdSubParserObserver& aSubParserObserver, |
|
27 TInt aDepth, TType aType ) |
|
28 : iType( aType ), |
|
29 iDepth( aDepth ), |
|
30 iObservers( &aObservers ), |
|
31 iSubParserObserver( &aSubParserObserver ) |
|
32 { |
|
33 } |
|
34 |
|
35 CNcdSubParser::~CNcdSubParser() |
|
36 { |
|
37 delete iSubParser; |
|
38 delete iTag; |
|
39 delete iBuffer; |
|
40 } |
|
41 |
|
42 void CNcdSubParser::ConstructL( const Xml::RTagInfo& aElement ) |
|
43 { |
|
44 NcdProtocolUtils::AssignDesL( iTag, aElement.LocalName().DesC() ); |
|
45 } |
|
46 |
|
47 const TDesC8& CNcdSubParser::Tag() const |
|
48 { |
|
49 if( iTag ) |
|
50 { |
|
51 return *iTag; |
|
52 } |
|
53 else |
|
54 { |
|
55 return KNullDesC8(); |
|
56 } |
|
57 } |
|
58 |
|
59 TInt CNcdSubParser::Depth() const |
|
60 { |
|
61 return iDepth; |
|
62 } |
|
63 |
|
64 CNcdSubParser::TType CNcdSubParser::Type() const |
|
65 { |
|
66 return iType; |
|
67 } |
|
68 |
|
69 void CNcdSubParser::OnStartDocumentL( |
|
70 const Xml::RDocumentParameters& /*aDocParam*/, TInt aErrorCode) |
|
71 { |
|
72 DLTRACE(("error=%d",aErrorCode)); |
|
73 (void) aErrorCode; // suppresses compiler warning |
|
74 // iDocParam.Open( aDocParam.CharacterSetName() ); |
|
75 } |
|
76 |
|
77 void CNcdSubParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
78 { |
|
79 // DLTRACE(("tag=%S error=%d",iTag,aErrorCode)); |
|
80 // iDocParam.Close(); |
|
81 } |
|
82 |
|
83 |
|
84 void CNcdSubParser::OnStartElementL( |
|
85 const Xml::RTagInfo& /*aElement*/, |
|
86 const Xml::RAttributeArray& /*aAttributes*/, |
|
87 TInt aErrorCode ) |
|
88 { |
|
89 DLTRACE(("error=%d",aErrorCode)); |
|
90 (void) aErrorCode; // suppresses compiler warning |
|
91 delete iBuffer; |
|
92 iBuffer = 0; |
|
93 } |
|
94 |
|
95 void CNcdSubParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode) |
|
96 { |
|
97 DLTRACEIN(("")); |
|
98 if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() ) |
|
99 { |
|
100 DLTRACE(("end tag=%S",&aElement.LocalName().DesC())); |
|
101 iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode ); |
|
102 } |
|
103 else if( iSubParser ) |
|
104 { |
|
105 iSubParser->OnEndElementL( aElement, aErrorCode ); |
|
106 } |
|
107 else |
|
108 { |
|
109 DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC())); |
|
110 } |
|
111 } |
|
112 |
|
113 void CNcdSubParser::SubParserFinishedL( const TDesC8& aTag, TInt /*aErrorCode*/ ) |
|
114 { |
|
115 DLTRACE(("tag=%S subparser=%X",&aTag,iSubParser)); |
|
116 (void) aTag; // suppresses compiler warning |
|
117 delete iSubParser; |
|
118 iSubParser = 0; |
|
119 } |
|
120 |
|
121 void CNcdSubParser::OnContentL(const TDesC8& aBytes, TInt aErrorCode ) |
|
122 { |
|
123 DLTRACEIN(("content size=%d",aBytes.Length())); |
|
124 // if( aBytes.Length() < 1000 ) |
|
125 // { |
|
126 // DLINFODUMP(aBytes.Ptr(),aBytes.Length(),1024) ; |
|
127 // DLINFO(("data=%S",&aBytes)); |
|
128 // } |
|
129 if( iSubParser ) |
|
130 { |
|
131 iSubParser->OnContentL( aBytes, aErrorCode ); |
|
132 } |
|
133 |
|
134 else |
|
135 { |
|
136 if (iBuffer) |
|
137 { |
|
138 TInt oldLength = iBuffer->Length(); |
|
139 iBuffer = iBuffer->ReAllocL(oldLength + aBytes.Length()); |
|
140 } |
|
141 else |
|
142 { |
|
143 iBuffer = HBufC8::NewL(aBytes.Length()); |
|
144 } |
|
145 iBuffer->Des().Append(aBytes); |
|
146 DLINFO(("buffer=%X size=%d",this,iBuffer->Length())); |
|
147 } |
|
148 DLTRACEOUT(("")); |
|
149 } |
|
150 |
|
151 void CNcdSubParser::OnStartPrefixMappingL( |
|
152 const RString& /*aPrefix*/, const RString& /*aUri*/, |
|
153 TInt aErrorCode) |
|
154 { |
|
155 DLTRACE(("error=%d",aErrorCode)); |
|
156 (void) aErrorCode; // suppresses compiler warning |
|
157 } |
|
158 |
|
159 void CNcdSubParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt aErrorCode) |
|
160 { |
|
161 DLTRACE(("error=%d",aErrorCode)); |
|
162 (void) aErrorCode; // suppresses compiler warning |
|
163 } |
|
164 |
|
165 void CNcdSubParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt aErrorCode) |
|
166 { |
|
167 DLTRACE(("error=%d",aErrorCode)); |
|
168 (void) aErrorCode; // suppresses compiler warning |
|
169 } |
|
170 |
|
171 void CNcdSubParser::OnSkippedEntityL(const RString& /*aName*/, TInt aErrorCode) |
|
172 { |
|
173 DLTRACE(("error=%d",aErrorCode)); |
|
174 (void) aErrorCode; // suppresses compiler warning |
|
175 } |
|
176 |
|
177 |
|
178 void CNcdSubParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, |
|
179 TInt aErrorCode) |
|
180 { |
|
181 DLTRACE(("error=%d",aErrorCode)); |
|
182 (void) aErrorCode; // suppresses compiler warning |
|
183 } |
|
184 |
|
185 |
|
186 // When the CParser gives OnError(), it will not continue even if further |
|
187 // data is fed to it. |
|
188 void CNcdSubParser::OnError(TInt aErrorCode) |
|
189 { |
|
190 DLTRACE(("error=%d",aErrorCode)); |
|
191 iObservers->ParserObserver()->ParseError( aErrorCode ); |
|
192 } |
|
193 |
|
194 |
|
195 TAny* CNcdSubParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
196 { |
|
197 DLTRACE(("")); |
|
198 return 0; |
|
199 } |
|
200 |
|
201 |
|
202 |
|
203 const TDesC8& CNcdSubParser::AttributeValue( const TDesC8& aAttributeName, |
|
204 const Xml::RAttributeArray& aAttributes ) |
|
205 { |
|
206 for( TInt i = 0; i < aAttributes.Count(); i++ ) |
|
207 { |
|
208 if( aAttributes[i].Attribute().LocalName().DesC() == aAttributeName ) |
|
209 { |
|
210 return aAttributes[i].Value().DesC(); |
|
211 } |
|
212 } |
|
213 return KNullDesC8; |
|
214 } |
|
215 |
|
216 const TDesC8& CNcdSubParser::AttributePrefix( const TDesC8& aAttributeName, |
|
217 const Xml::RAttributeArray& aAttributes ) |
|
218 { |
|
219 for( TInt i = 0; i < aAttributes.Count(); i++ ) |
|
220 { |
|
221 if( aAttributes[i].Attribute().LocalName().DesC() == aAttributeName ) |
|
222 { |
|
223 return aAttributes[i].Attribute().Prefix().DesC(); |
|
224 } |
|
225 } |
|
226 return KNullDesC8; |
|
227 } |
|
228 |