1 /* |
|
2 * Copyright (c) 2005 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: CXmlParserNodePath |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <contenthandler.h> |
|
21 #include "XdmDocument.h" |
|
22 #include "XdmXmlParser.h" |
|
23 #include "XdmDocumentNode.h" |
|
24 #include "XdmNodeAttribute.h" |
|
25 #include "XmlParserNodePath.h" |
|
26 #include "XmlNodePathInterface.h" |
|
27 |
|
28 // --------------------------------------------------------- |
|
29 // CXmlParserNodePath::CXmlParserNodePath |
|
30 // |
|
31 // --------------------------------------------------------- |
|
32 // |
|
33 CXmlParserNodePath::CXmlParserNodePath( CXdmXmlParser& aParserMain, |
|
34 TXdmElementType aElementType, |
|
35 MXmlNodePathInterface* aPathInterface ) : |
|
36 iElementType( aElementType ), |
|
37 iPathInterface( aPathInterface ), |
|
38 iParserMain( aParserMain ) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CXmlParserNodePath::ExtractString |
|
44 // |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 CXmlParserNodePath* CXmlParserNodePath::NewL( CXdmXmlParser& aParserMain, |
|
48 TXdmElementType aElementType, |
|
49 const CXdmDocumentNode& aTargetNode, |
|
50 MXmlNodePathInterface* aPathInterface ) |
|
51 { |
|
52 CXmlParserNodePath* self = new ( ELeave ) CXmlParserNodePath( aParserMain, aElementType, aPathInterface ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aTargetNode ); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CXmlParserNodePath::~CXmlParserNodePath |
|
61 // |
|
62 // --------------------------------------------------------- |
|
63 // |
|
64 CXmlParserNodePath::~CXmlParserNodePath() |
|
65 { |
|
66 iNodes.Close(); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CXmlParserNodePath::ConstructL |
|
71 // |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CXmlParserNodePath::ConstructL( const CXdmDocumentNode& aTargetNode ) |
|
75 { |
|
76 #ifdef _DEBUG |
|
77 iParserMain.WriteToLog( _L8( "CXmlParserNodePath::ConstructL()" ) ); |
|
78 #endif |
|
79 CXdmDocumentNode* current = CONST_CAST( CXdmDocumentNode*, &aTargetNode ); |
|
80 while( current != NULL ) |
|
81 { |
|
82 iNodes.InsertL( current, 0 ); |
|
83 current = current->Parent(); |
|
84 } |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CXmlParserNodePath::CheckNextNodeL |
|
89 // |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 TBool CXmlParserNodePath::CheckNextNodeL( const TDesC8& aNextElement, |
|
93 const RAttributeArray& aAttributes ) |
|
94 { |
|
95 #ifdef _DEBUG |
|
96 //iParserMain.WriteToLog( _L8( "CXmlParserNodePath::CheckNextNodeL" ) ); |
|
97 #endif |
|
98 if( !iComplete && aNextElement.Length() > 0 ) |
|
99 { |
|
100 TInt attrCount = aAttributes.Count(); |
|
101 RPointerArray<SXdmAttribute8> attributes; |
|
102 CleanupClosePushL( attributes ); |
|
103 for( TInt i = 0;i < attrCount;i++ ) |
|
104 { |
|
105 SXdmAttribute8 attribute; |
|
106 attribute.iName.Set( aAttributes[i].Attribute().LocalName().DesC() ); |
|
107 attribute.iValue.Set( aAttributes[i].Value().DesC() ); |
|
108 User::LeaveIfError( attributes.Append( &attribute ) ); |
|
109 } |
|
110 HBufC* unicode = HBufC::NewLC( aNextElement.Length() ); |
|
111 unicode->Des().Copy( aNextElement ); |
|
112 if( iNodes[iIndex]->Match( unicode->Des(), attributes ) ) |
|
113 { |
|
114 iIndex++; |
|
115 if( iElementType == EXdmElementAttribute ) |
|
116 iComplete = iNodes[iIndex] == iPathInterface->TargetAttribute()->Parent(); |
|
117 else /* or else if, the next if is not needed */ |
|
118 { |
|
119 if( iIndex == iNodes.Count() ) |
|
120 iComplete = ETrue; |
|
121 } |
|
122 } |
|
123 CleanupStack::PopAndDestroy( 2 ); //unicode, attributes |
|
124 } |
|
125 return iComplete; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CXmlParserNodePath::CheckNextNodeL |
|
130 // |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 TBool CXmlParserNodePath::CheckNextNode( const CXdmDocumentNode& aNextNode ) |
|
134 { |
|
135 #ifdef _DEBUG |
|
136 //iParserMain.WriteToLog( _L8( "CXmlParserNodePath::CheckNextNodeL" ) ); |
|
137 #endif |
|
138 if( !iComplete ) |
|
139 { |
|
140 if( iNodes[iIndex]->Match( aNextNode ) ) |
|
141 { |
|
142 iIndex++; |
|
143 if( iElementType == EXdmElementAttribute ) |
|
144 iComplete = iNodes[iIndex] == iPathInterface->TargetAttribute()->Parent(); |
|
145 else /* or else if, the next if is not needed */ |
|
146 { |
|
147 if( iIndex == iNodes.Count() ) |
|
148 iComplete = ETrue; |
|
149 } |
|
150 } |
|
151 } |
|
152 return iComplete; |
|
153 } |
|
154 |
|
155 // End of File |
|