commsfwtools/preparedefaultcommsdatabase/Tools/ced/src/CXMLFile.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "dbdef.h"
       
    17 #include <ecom/ecom.h>
       
    18 #include <xml/parser.h>
       
    19 #include <xml/xmlparsererrors.h>
       
    20 #include "CXMLFile.h"
       
    21 
       
    22 #include "filedump.h"
       
    23 extern CFileDump* gMsg;		// logging
       
    24 
       
    25 using namespace Xml;
       
    26 
       
    27 _LIT8(KParserDataType, "text/xml");
       
    28 
       
    29 CXMLData::CXMLData(CXMLDatabase* aXmlDb, TBool aForceXMLProcessing, TBool aAppendMode) 
       
    30 : xmlDb(aXmlDb)
       
    31 , bForceXMLProcessing(aForceXMLProcessing)
       
    32 , iAppendMode(aAppendMode)
       
    33 	{
       
    34 	__DECLARE_NAME(_S("CXMLData"));
       
    35 	}
       
    36 
       
    37 CXMLData::~CXMLData()
       
    38 	{
       
    39 	}
       
    40 
       
    41 CXMLData*
       
    42 CXMLData::NewL(RFs& aFs, const TDesC& aName, CXMLDatabase* aXmlDb, 
       
    43                TBool aForceXMLProcessing,
       
    44                TBool aAppendMode)
       
    45 	{
       
    46 	CXMLData* p = new(ELeave) CXMLData(aXmlDb,aForceXMLProcessing, aAppendMode);
       
    47 	CleanupStack::PushL(p);
       
    48 
       
    49 	if(!p->ConstructL(aFs,aName,aXmlDb))
       
    50 		{
       
    51 		CleanupStack::PopAndDestroy(p);	
       
    52 		p = NULL;
       
    53 		}
       
    54 	else
       
    55 		{
       
    56 		CleanupStack::Pop(p);
       
    57 		}
       
    58 	
       
    59 	return p;
       
    60 	}
       
    61 
       
    62 //
       
    63 // Parse the XML settings file
       
    64 //
       
    65 TBool CXMLData::ConstructL(RFs& aFs, const TDesC& aName, CXMLDatabase* aXmlDb)
       
    66 	{    	
       
    67 	// Create the content handler for the XML file
       
    68 	//CXMLContentHandler contentHandler;
       
    69 	CXMLContentHandler* contentHandler = CXMLContentHandler::NewL(aXmlDb,
       
    70 	                                                              bForceXMLProcessing,
       
    71 	                                                              iAppendMode);
       
    72 	TBool retCode = EFalse;
       
    73 	
       
    74 	// Create the XML parser (SAX-type)
       
    75 	gMsg->Msg(_L("Create the parser"));
       
    76 	CParser* parser = CParser::NewLC(KParserDataType, *contentHandler);
       
    77 	
       
    78 	// Perform the parsing
       
    79 	gMsg->Msg(_L("Starting the parsing"));
       
    80 	ParseL(*parser, aFs, aName);
       
    81     CleanupStack::PopAndDestroy(parser);    
       
    82 	
       
    83     // Modify the table entry references to the format used by CommDB
       
    84 	TBool bSuccess = contentHandler->ModifyTableEntryReferencesL();
       
    85 	if(bSuccess) 
       
    86 	    {
       
    87 	    retCode = ETrue;
       
    88 	    // Log the table entries
       
    89 	    contentHandler->LogTableEntries();
       
    90 	    }
       
    91 	
       
    92 	CleanupStack::PopAndDestroy(contentHandler);
       
    93 	
       
    94 	return retCode;
       
    95 	}
       
    96 
       
    97 // Get a setting from the XML database for a specific table entry given the name of the
       
    98 // table parameter
       
    99 TInt CXMLData::GetSetting(const TInt aEntryIndex, const TDesC & aParamName, TPtrC & aParamValue)
       
   100 	{
       
   101     CXMLTableEntry* entry = xmlDb->GetTableEntry(aEntryIndex);
       
   102 	
       
   103 	for(TInt k = 0; k < entry->GetNumberParameters(); k++)
       
   104 		{
       
   105 		const TBuf<MAX_BUFFER_LEN>& paramName = entry->GetParameterName(k);
       
   106 		
       
   107 		if(paramName.Compare(aParamName) == 0)
       
   108 			{
       
   109 			aParamValue.Set(TPtrC(entry->GetParameterValue(k)));
       
   110 			return ETrue;
       
   111 			}
       
   112 		}
       
   113 	
       
   114     return EFalse;
       
   115 	}
       
   116 
       
   117 // Get the starting index for all table entries of a specific table. If table entries
       
   118 // of the specified table do not exist then -1 is returned
       
   119 TInt CXMLData::GetStartingIndex(const TDesC& aTableName)
       
   120 	{
       
   121 	TInt numEntries = xmlDb->GetNumberTableEntries();
       
   122 	
       
   123     for(TInt i = 0; i < numEntries; i++)
       
   124 		{
       
   125 		CXMLTableEntry* entry = xmlDb->GetTableEntry(i);
       
   126 		const TBuf<MAX_BUFFER_LEN>& tableName = entry->GetTableName();
       
   127 		
       
   128 		if(tableName.Compare(aTableName) == 0)
       
   129 			return i;
       
   130 		}
       
   131 	
       
   132 	return -1;
       
   133 	}
       
   134 
       
   135 // Get the last index for the table entries of a specific table. If table entries
       
   136 // of the specified table do not exist then -1 is returned
       
   137 TInt CXMLData::GetLastIndex(const TDesC& aTableName)
       
   138 	{
       
   139 	TInt numEntries = xmlDb->GetNumberTableEntries();
       
   140 	
       
   141     for(TInt i = numEntries-1; i >= 0; i--)
       
   142 		{
       
   143 		CXMLTableEntry* entry = xmlDb->GetTableEntry(i);
       
   144 		const TBuf<MAX_BUFFER_LEN>& tableName = entry->GetTableName();
       
   145 		
       
   146 		if(tableName.Compare(aTableName) == 0)
       
   147 			return i;
       
   148 		}
       
   149 	
       
   150 	return -1;
       
   151 	}
       
   152 
       
   153 // Get the number of parameters for a specific table entry
       
   154 TInt CXMLData::GetEntryNumberParameters(const TInt aEntryIndex)
       
   155 	{
       
   156 	return xmlDb->GetTableEntry(aEntryIndex)->GetNumberParameters();
       
   157 	}
       
   158 
       
   159 // Get the type of operation to perform for this table entry
       
   160 const TBuf<MAX_BUFFER_LEN>& CXMLData::GetOperation(const TInt aEntryIndex)
       
   161 	{
       
   162 	return xmlDb->GetTableEntry(aEntryIndex)->GetOperation();
       
   163 	}
       
   164 	
       
   165 TInt CXMLData::GetElementRecordID(const TInt aEntryIndex) const
       
   166     {
       
   167     return xmlDb->GetTableEntry(aEntryIndex)->GetRecordID();
       
   168     }