commsfwtools/preparedefaultcommsdatabase/Tools/ced/inc/CXMLContentHandler.h
changeset 0 dfb7c4ff071f
child 21 07656293a99c
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 
       
    17 #ifndef __CXMLCONTENTHANDLER_H__
       
    18 #define __CXMLCONTENTHANDLER_H__
       
    19 
       
    20 #include <xml/contenthandler.h>
       
    21 #include <e32hashtab.h>
       
    22 
       
    23 
       
    24 #define MAX_BUFFER_LEN  256 // max length of path/filename/column/table name
       
    25 
       
    26 
       
    27 // Forward class declarations
       
    28 class RFile;
       
    29 class CXMLDatabase;
       
    30 class CXMLTableEntry;
       
    31 
       
    32 
       
    33 NONSHARABLE_CLASS(CXMLContentHandler) : public CBase,
       
    34                                         public Xml::MContentHandler
       
    35 	{
       
    36 	public:
       
    37 		
       
    38 		static CXMLContentHandler* NewL( CXMLDatabase* aXmlDb,
       
    39 		                                 const TBool aForceFlag,
       
    40 		                                 const TBool aAppendFlag );
       
    41 		virtual ~CXMLContentHandler();
       
    42 		
       
    43 		// From MContentHandler
       
    44 		void OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt aErrorCode);
       
    45 		void OnEndDocumentL(TInt aErrorCode);
       
    46 		void OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt aErrorCode);
       
    47 		void OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode);
       
    48 		void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
    49 		void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
       
    50 		void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
    51 		void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
       
    52 		void OnSkippedEntityL(const RString& aName, TInt aErrorCode) ;
       
    53 		void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
       
    54 		void OnExtensionL(const RString& aData, TInt aToken, TInt aErrorCode);
       
    55 		void OnError(TInt aErrorCode);
       
    56 		TAny* GetExtendedInterface(const TInt32 aUid);
       
    57 		
       
    58 		
       
    59 		// Set the XML database to use for storing the parsed elements
       
    60 		inline void SetXMLDatabase(CXMLDatabase* aXmlDb)
       
    61 			{
       
    62 			iXmlDb = aXmlDb;
       
    63 			}
       
    64 		
       
    65 		// Set the level of strictness for processing XML files with invalid
       
    66 		// table entry links
       
    67 		inline void ForceXMLProcessing(const TBool aFlag)
       
    68 			{
       
    69 			iForceXMLProcessing = aFlag;
       
    70 			}
       
    71 		
       
    72 		/**
       
    73 		This parameter is needed when resolving the COMMDB_IDs.
       
    74 		If this is true th resolve should be done from the DB otherwise
       
    75 		from the XML db.
       
    76 		*/
       
    77 		inline void SetAppendMode(const TBool aAppendFlag)
       
    78 		    {
       
    79 		    isInAppendMode = aAppendFlag;
       
    80 		    }
       
    81 		
       
    82 		TBool ModifyTableEntryReferencesL();
       
    83 		void  LogTableEntries();
       
    84 		
       
    85 	private:
       
    86 	    //ctors
       
    87 	    CXMLContentHandler(CXMLDatabase* aXmlDb,
       
    88 		                   const TBool aForceFlag,
       
    89 		                   const TBool aAppendFlag);
       
    90 	    void ConstructL();
       
    91 	    
       
    92 		void  SetTableIDs();
       
    93 		void  RemoveNameParams();
       
    94 		TBool ResolveTableEntryReferences(
       
    95 		                  CXMLTableEntry*       entry,
       
    96         			const TInt                  paramIndex,
       
    97         			const TBuf<MAX_BUFFER_LEN>& refEntryName,
       
    98         			const TBuf<MAX_BUFFER_LEN>& refEntryTable,
       
    99         			const TBuf<MAX_BUFFER_LEN>& orgEntryTable);
       
   100         			
       
   101         
       
   102         TBool ResolveRefsFromDbL(
       
   103                           CXMLTableEntry*                   entry,
       
   104         			const TInt                              paramIndex,
       
   105         			const TPtrC&                            refEntryName,
       
   106         			const TPtrC&                            refEntryTable,
       
   107         			const TPtrC&                            orgEntryTable);
       
   108         			
       
   109         void FillUpHashMapL(RHashMap<TPtrC, TMDBElementId>& aHashMap);
       
   110         
       
   111         void SetCfgLinkingFromXMLFile(const TDesC&    aRefTable,
       
   112                                       const TInt      aParamIndex,
       
   113                                             CXMLTableEntry* aEntry);
       
   114         
       
   115         void SetRecordIDsL();
       
   116         
       
   117         bool IsTableKnown(const TDesC&    aRefTable);
       
   118         
       
   119 		
       
   120 	public:
       
   121 		static const TInt KExpectedLeaveCode;
       
   122 		
       
   123 	private:
       
   124 	    typedef enum {EXMLContentStateFirst = 0, 
       
   125 	                  ENone                 = EXMLContentStateFirst,
       
   126 	                  EInDeprecatedTable,
       
   127 	                  EInTable,
       
   128 	                  EInRecord,            // 'InRecord' => 'InTable' too (it's a stack).
       
   129 	                  EInParam,             // 'InParam'  => 'InRecord too (it's a stack).
       
   130 	                  EXMLContentStateLast  = EInRecord} TXMLContentState;
       
   131 	    
       
   132 		TBool                iLeaveOnStartElement;
       
   133 		TInt                 iNumElements;
       
   134 		TInt                 iNumSkippedEntities;
       
   135 		TInt                 iNumPrefixMappings;
       
   136 		TInt                 iNumPrefixUnmappings;
       
   137 		TInt                 iError;
       
   138 		CXMLDatabase*        iXmlDb;
       
   139 		TBool                iForceXMLProcessing;
       
   140 		TBool                isInAppendMode;
       
   141 		TXMLContentState     iXMLContentState;
       
   142 		TBuf<MAX_BUFFER_LEN> iCurrentRecordName;        // Is actually just iCurrentTableName, without the "Table" suffix.
       
   143 		TBuf<MAX_BUFFER_LEN> iCurrentTableName;
       
   144 		TBuf<MAX_BUFFER_LEN> iCurrentParameterValue;
       
   145 		TBuf<MAX_BUFFER_LEN> iCurrentParameter;
       
   146 		
       
   147 		//for reading the database
       
   148 		CMDBSession*         iCmdbSession;
       
   149 		
       
   150     	RHashMap<TPtrC, TMDBElementId>* iTableNameIDpairs;
       
   151 		
       
   152 	};
       
   153 
       
   154 
       
   155 NONSHARABLE_CLASS(CXMLTableEntry) : public CBase
       
   156 	{
       
   157 	
       
   158 	public:
       
   159 		
       
   160     	enum TLinkType
       
   161         /**
       
   162         Specifies the type of the link
       
   163         @publishedAll
       
   164         @released
       
   165         */
       
   166     	{
       
   167     	EResolve_XML_Ref,           //The link is tableName.RecordName
       
   168     	ERecord_ID_Reference,       //The link is tableName.RecordID
       
   169     	ESkip_XML__Ref,             //The link is tableName.-1
       
   170     	ENot_A_Link                 //The parameter is not a link
       
   171     	};
       
   172     	
       
   173 		// Constructor with parameter the name of the table this
       
   174 		// table entry belongs to
       
   175 		static CXMLTableEntry* NewL(const TDesC& aTableName);
       
   176 		virtual ~CXMLTableEntry();
       
   177 		
       
   178 	public:
       
   179 		TInt GetNumberParameters() const
       
   180 			{
       
   181 			return paramName.Count();
       
   182 			}
       
   183         
       
   184 		TInt GetRecordID() const
       
   185 		    {
       
   186 		    return iRecordID;
       
   187 		    }
       
   188 		
       
   189 		void SetRecordID(TInt aID)
       
   190 		    {
       
   191 		    iRecordID = aID;
       
   192 		    }
       
   193 		inline void SetDeleteFlag(const TBool aDeleteFlag)
       
   194 		    {
       
   195 		    iDeleteFlag = aDeleteFlag;
       
   196 		    }
       
   197 		inline const TBool GetDeleteFlag() const
       
   198 		    {
       
   199 		    return iDeleteFlag;
       
   200 		    }
       
   201 		void AddParameterL(const TBuf<MAX_BUFFER_LEN>& aParamName, const TBuf<MAX_BUFFER_LEN>& aParamValue);
       
   202 		void SetParameterValue(const TInt aIndex, const TBuf<MAX_BUFFER_LEN>& aParamValue);
       
   203 		void RemoveParameter(const TInt aIndex);
       
   204 		void RenameParameter(const TInt aIndex, const TBuf<MAX_BUFFER_LEN>& aNewName);
       
   205 		
       
   206 		void SetEntryId(const TInt aId)
       
   207 			{
       
   208 			entryId = aId;
       
   209 			}
       
   210 		void SetOperation(const TBuf<MAX_BUFFER_LEN>& aOperation)
       
   211 			{
       
   212 			operation.Copy(aOperation);
       
   213 			}
       
   214 		const TBuf<MAX_BUFFER_LEN>& GetParameterName(const TUint aIndex) const
       
   215 			{
       
   216 			return *paramName[aIndex];
       
   217 			}
       
   218 		const TBuf<MAX_BUFFER_LEN>& GetParameterValue(const TUint aIndex) const
       
   219 			{
       
   220 			return *paramValue[aIndex];
       
   221 			}
       
   222 	    inline const TLinkType& GetLinkType(const TUint aIndex) const
       
   223 	        {
       
   224 	        return iLinkType[aIndex];
       
   225 	        }
       
   226 	    inline void SetLinkType(const TLinkType& aLinkType)
       
   227 	        {
       
   228 	        iLinkType.Append(aLinkType);
       
   229 	        }
       
   230 	    inline void ModifyLinkType(const TUint aPos, const TLinkType& aLinkType)
       
   231 	        {
       
   232 	        iLinkType[aPos] = aLinkType;
       
   233 	        }
       
   234 		const TBuf<MAX_BUFFER_LEN>& GetTableName() const
       
   235 			{
       
   236 			return tableName;
       
   237 			}
       
   238 		const TBuf<MAX_BUFFER_LEN>& GetOperation() const
       
   239 			{
       
   240 			return operation;
       
   241 			}
       
   242 
       
   243 		TInt GetEntryId() const
       
   244 			{
       
   245 			return entryId;
       
   246 			}
       
   247 		
       
   248 	protected:
       
   249 		CXMLTableEntry();
       
   250 		
       
   251 	private:
       
   252 		void ConstructL(const TDesC& aTableName);
       
   253 		
       
   254 	private:
       
   255 		TInt entryId;
       
   256 		TInt iRecordID;
       
   257 		TBuf<MAX_BUFFER_LEN>                  tableName;
       
   258 		RPointerArray< TBuf<MAX_BUFFER_LEN> > paramName;
       
   259 		RPointerArray< TBuf<MAX_BUFFER_LEN> > paramValue;
       
   260 		//as only interger values are stored here it's not important to have
       
   261 		//RPointerArray
       
   262 		RArray<TLinkType>                     iLinkType;
       
   263 		TBuf<MAX_BUFFER_LEN>                  operation;
       
   264 		TBool                                 iDeleteFlag;
       
   265 	};
       
   266 
       
   267 NONSHARABLE_CLASS(CXMLDatabase) : public CBase
       
   268 	{
       
   269 	
       
   270 public:
       
   271 	// Constructor with parameter the name of the table this
       
   272 	// table entry belongs to
       
   273 	static CXMLDatabase* NewL();
       
   274 	virtual ~CXMLDatabase();
       
   275 	
       
   276 public:
       
   277 	// Functions to manipulate the database elements
       
   278 	void AddTableEntry(CXMLTableEntry* aEntry);
       
   279 	CXMLTableEntry* GetTableEntry(const TInt aIndex);
       
   280 	TInt GetNumberTableEntries() const;
       
   281 	CXMLTableEntry* GetLastTableEntry();
       
   282 	void CheckDeletedElems();
       
   283 	
       
   284 	
       
   285 protected:
       
   286 	CXMLDatabase();
       
   287 	
       
   288 private:
       
   289     RPointerArray<CXMLTableEntry> tableEntries;
       
   290 	};
       
   291 
       
   292 #endif