20
|
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: Definitions for the class CATParseXML.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "../inc/CATParseXML.h"
|
|
20 |
#include "../inc/catdatasaver.h"
|
|
21 |
#include "../inc/CATBase.h"
|
|
22 |
|
|
23 |
#include <xercesc/parsers/XercesDOMParser.hpp>
|
|
24 |
|
|
25 |
const char cCanNotFindEpocroot[] = "Can not find EPOCROOT from devices.xml.\n";
|
|
26 |
const char cErrorInDeviceXml[] = "Error in devices.xml!\n";
|
|
27 |
const char cCanNotFind[] = "Can not find file: %s.\n";
|
|
28 |
|
|
29 |
CATParseXML::CATParseXML(void)
|
|
30 |
{
|
|
31 |
LOG_FUNC_ENTRY("CATParseXML::CATParseXML");
|
|
32 |
try
|
|
33 |
{
|
|
34 |
xercesc::XMLPlatformUtils::Initialize();
|
|
35 |
}
|
|
36 |
catch ( ... )
|
|
37 |
{
|
|
38 |
//Print error
|
|
39 |
printf("XML initialization failed.\n");
|
|
40 |
}
|
|
41 |
}
|
|
42 |
|
|
43 |
CATParseXML::~CATParseXML(void)
|
|
44 |
{
|
|
45 |
LOG_FUNC_ENTRY("CATParseXML::~CATParseXML");
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// CATParseXML::GetEpocRootPathFromXML
|
|
50 |
// Find epocroot path in xml file
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
string CATParseXML::GetEpocRootPathFromXML(const char* pSourcePath)
|
|
53 |
{
|
|
54 |
LOG_FUNC_ENTRY("CATParseXML::GetEpocRootPathFromXML");
|
|
55 |
string sEpocRootPath;
|
|
56 |
// Check that source exists
|
|
57 |
if ( ! CATBase::FileExists( pSourcePath ) )
|
|
58 |
{
|
|
59 |
LOG_STRING( "Source xml not found." );
|
|
60 |
return sEpocRootPath;
|
|
61 |
}
|
|
62 |
try
|
|
63 |
{
|
|
64 |
xercesc::XercesDOMParser* parser = new xercesc::XercesDOMParser();
|
|
65 |
xercesc::DOMDocument* pDomDoc;
|
|
66 |
|
|
67 |
// Get devices.xml document
|
|
68 |
parser->parse( pSourcePath );
|
|
69 |
pDomDoc = parser->getDocument();
|
|
70 |
|
|
71 |
// Get root element
|
|
72 |
xercesc::DOMElement* pRootElem = pDomDoc->getDocumentElement();
|
|
73 |
|
|
74 |
if( pRootElem )
|
|
75 |
{
|
|
76 |
// Get all "device" elements
|
|
77 |
LPWSTR wTemp = CATDataSaver::CharToWChar( "device" );
|
|
78 |
xercesc::DOMNodeList* pDeviceNodeList = pRootElem->getElementsByTagName( wTemp );
|
|
79 |
if( wTemp )
|
|
80 |
delete[] wTemp;
|
|
81 |
|
|
82 |
// Find default SDK
|
|
83 |
|
|
84 |
bool bEpocRootFound = false;
|
|
85 |
int iLength = pDeviceNodeList->getLength();
|
|
86 |
for( int i = 0 ; i < iLength ; i++ )
|
|
87 |
{
|
|
88 |
xercesc::DOMNode* pDeviceNode = pDeviceNodeList->item(i);
|
|
89 |
|
|
90 |
xercesc::DOMNamedNodeMap* pAttributeList = pDeviceNode->getAttributes();
|
|
91 |
|
|
92 |
// Find attribute "default"
|
|
93 |
|
|
94 |
int iAttribListLength = pAttributeList->getLength();
|
|
95 |
for( int x = 0 ; x < iAttribListLength ; x++ )
|
|
96 |
{
|
|
97 |
xercesc::DOMNode* pAttribNode = pAttributeList->item(x);
|
|
98 |
const LPWSTR pNodeName = (const LPWSTR)pAttribNode->getNodeName();
|
|
99 |
|
|
100 |
if( wcscmp( pNodeName, L"default" ) == 0 )
|
|
101 |
{
|
|
102 |
const LPWSTR pNodeValue = (const LPWSTR)pAttribNode->getNodeValue();
|
|
103 |
|
|
104 |
// Find node value 'yes'
|
|
105 |
if( wcscmp( pNodeValue, L"yes" ) == 0 )
|
|
106 |
{
|
|
107 |
// Find <epocroot> node
|
|
108 |
xercesc::DOMNode* pChildNode = pDeviceNode->getFirstChild();
|
|
109 |
if( !pChildNode )
|
|
110 |
break;
|
|
111 |
while( !bEpocRootFound )
|
|
112 |
{
|
|
113 |
if( wcscmp( pChildNode->getNodeName() , L"epocroot" ) == 0 )
|
|
114 |
{
|
|
115 |
bEpocRootFound = true;
|
|
116 |
|
|
117 |
// Node value is child text node
|
|
118 |
xercesc::DOMNode* pTempTextNode = pChildNode->getFirstChild();
|
|
119 |
const LPWSTR pPathNodeValue = (const LPWSTR)pTempTextNode->getNodeValue();
|
|
120 |
|
|
121 |
CATDataSaver::WCharToChar( sEpocRootPath, pPathNodeValue );
|
|
122 |
|
|
123 |
break;
|
|
124 |
}
|
|
125 |
pChildNode = pChildNode->getNextSibling();
|
|
126 |
if( !pChildNode )
|
|
127 |
break;
|
|
128 |
}
|
|
129 |
} // If node value yes
|
|
130 |
} // If node name default
|
|
131 |
if( bEpocRootFound )
|
|
132 |
break;
|
|
133 |
} // for x
|
|
134 |
if( bEpocRootFound )
|
|
135 |
break;
|
|
136 |
} // for i
|
|
137 |
}
|
|
138 |
if(parser)
|
|
139 |
delete parser; //lint !e118
|
|
140 |
xercesc::XMLPlatformUtils::Terminate();
|
|
141 |
}
|
|
142 |
catch (...)
|
|
143 |
{
|
|
144 |
printf("XML parsing failed.");
|
|
145 |
}
|
|
146 |
return sEpocRootPath;
|
|
147 |
}
|
|
148 |
// End of file
|