ImagePrint/ImagePrintEngine/DeviceProtocols/btprotocol/inc/cxmlhandler.h
branchGCC_SURGE
changeset 25 59ea2209bb67
parent 23 08cc4cc059d4
parent 15 a92d00fca574
equal deleted inserted replaced
23:08cc4cc059d4 25:59ea2209bb67
     1 /*
       
     2 * Copyright (c) 2004-2007 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:  Handler for XML file modify. Defines the class to store and modify XML data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CXMLHANDLER_H
       
    20 #define CXMLHANDLER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <badesca.h>
       
    25 
       
    26 /** general tags */
       
    27 _LIT8(KBtLessThan, 	"<");
       
    28 _LIT8(KBtGreaterThan,	">");
       
    29 _LIT8(KBtLessThanSlash,"</");
       
    30 _LIT8(KBtSlash, 		"/");
       
    31 _LIT8(KEof, 			"EOF");
       
    32 
       
    33 /** Maximum size of template file */
       
    34 const TInt KBtMaxFileSize = 2048;
       
    35 
       
    36 /**
       
    37 * @class 	CXmlHandler
       
    38 * @brief	Class to store and modify XML data.
       
    39 * @n
       
    40 * @b Usage:
       
    41 * <OL>
       
    42 * @li Create an instance of class
       
    43 * @li Initialize class with a data buffer by InitFromBufferL or with a file name by InitFromFileL
       
    44 * @li Get/replace/remove parts of initialized data
       
    45 * </OL>
       
    46 */
       
    47 NONSHARABLE_CLASS( CXmlHandler ): public CBase
       
    48 	{
       
    49 		public:
       
    50 
       
    51 			/**  		NewL
       
    52 			* @brief	Creates a new instance of XML handler.
       
    53 			* @return	Pointer to the instance.
       
    54 			*/
       
    55 			static CXmlHandler* NewL();
       
    56 
       
    57 			/**  		NewLC
       
    58 			* @brief	Creates a new instance of XML handler and leaves it in the cleanup stack.
       
    59 			* @return	Pointer to the instance.
       
    60 			*/
       
    61 			static CXmlHandler* NewLC();
       
    62 
       
    63 			static TPtrC8 ParseValue(const TDesC8 &aData, const TDesC8 &aStart, const TDesC8 &aEnd, TInt& aOffset);
       
    64 			static void ParseValueListL(const TDesC8 &aData, const TDesC8 &aStart, const TDesC8 &aEnd, CDesC8ArrayFlat& aList);
       
    65 
       
    66 			/**  		~CXmlHandler
       
    67 			* @brief	Destructor.
       
    68 			*/
       
    69 			~CXmlHandler();
       
    70 
       
    71 
       
    72 			/**  		Reset
       
    73 			* @brief	Resets the member variables.
       
    74 			*/
       
    75 			void Reset();
       
    76 
       
    77 			/**  		InitFromFileL
       
    78 			* @brief	Reads the named template file for handling it.
       
    79 			* @param	aFile 	Name of the file to read for handle
       
    80 			* @param	aId		Identifier for the data stored in class
       
    81 			*/
       
    82 			void InitFromFileL(const TDesC& aFile, const TInt aId = KErrNotFound);
       
    83 
       
    84 			/**  		InitFromBufferL
       
    85 			* @brief	Initialises the data to handle with given buffer.
       
    86 			* @param	aBuffer The buffer to handle
       
    87 			* @param	aId		Identifier for the data stored in class
       
    88 			*/
       
    89 			void InitFromBufferL(const TDesC8& aBuffer, const TInt aId = KErrNotFound);
       
    90 
       
    91 
       
    92 			/**   		ComposeDataL
       
    93 			* @brief	Replaces the template with string value in stored data
       
    94 			* @param	aStr	String to convert for
       
    95 			* @param	aTag	Template to replace
       
    96 			*/
       
    97 			void ComposeDataL(const TDesC8& aData, const TDesC8& aTag);
       
    98 
       
    99 			/** @overload void ComposeDataL(const TDesC8& aData, const TDesC8& aTag) */
       
   100 			void ComposeDataL(const TInt aValue, const TDesC8& aTag);
       
   101 
       
   102 			/**   		InsertDataL
       
   103 			* @brief	Inserts data in the buffer
       
   104 			* @param	aStr	String to convert for
       
   105 			* @param	aTag	Template to replace
       
   106 			*/
       
   107 			void InsertDataL(const TDesC8& aData, const TInt aOffset);
       
   108 
       
   109 			/**   		GetDataL
       
   110 			* @brief	Returns the data between given start and end descriptors.
       
   111 			*			NOTE: The start and end descriptors are @e not returned.
       
   112 			* @param	aStart	Start tag for data to find.
       
   113 			* @param	aEnd	End tag for data to find.
       
   114 			* @param	aOffset	Returns offset for the data start. KErrNotFound indicates the data not found.
       
   115 			*/
       
   116 			TPtrC8 GetDataL(const TDesC8& aStart, const TDesC8& aEnd, TInt& aOffset);
       
   117 
       
   118 			/**   		FinalizeBufferL
       
   119 			* @brief	Trims the member buffer tail. Replacing the template strings from
       
   120 			*			the buffer makes the data length in the buffer vary and generates
       
   121 			*			rubbish in the end of buffer.
       
   122 			* @param	aTag	End tag to delete all after it.
       
   123 			* @return	Pointer to the stored data.
       
   124 			*/
       
   125 			TPtrC8 FinalizeBufferL(const TDesC8& aTag);
       
   126 
       
   127 			/**   		DeleteBufferData
       
   128 			* @brief	Deletes the data from the buffer.
       
   129 			* @param	aOffset Data offset to start delete
       
   130 			* @param	aLength Length of the data to delete
       
   131 			*/
       
   132 			void DeleteBufferData(TInt aOffset, TInt aLength);
       
   133 
       
   134 			/**   		BufferId
       
   135 			* @brief	Returns the identifier of the stored data.
       
   136 			* @return	Identifier of the stored data
       
   137 			*/
       
   138 			TInt BufferId();
       
   139 
       
   140 			/**   		Buffer
       
   141 			* @brief	Returns the pointer to the stored data.
       
   142 			* @return	Pointer to the stored data
       
   143 			*/
       
   144 			TPtrC8 Buffer();
       
   145 
       
   146 			void GetDataListL(const TDesC8 &aStart, const TDesC8 &aEnd, CDesC8ArrayFlat& aList);
       
   147 
       
   148 		protected:
       
   149 
       
   150 			/**  		ConstructL
       
   151 			* @brief	Symbian second phase constructor.
       
   152 			*/
       
   153 			void ConstructL();
       
   154 
       
   155 		private:
       
   156 
       
   157 			/**  		CXmlHandler
       
   158 			* @brief	C++ constructor
       
   159 			*/
       
   160 			CXmlHandler();
       
   161 
       
   162 			/**   		ReadFileL
       
   163 			* @brief	Reads the file in iDataBuf
       
   164 			*/
       
   165 			void ReadFileL(const TDesC& aFile);
       
   166 
       
   167 		private:
       
   168 
       
   169 			/** @var HBufC8* iDataBuf
       
   170 			 *  Buffer to store the data initialized */
       
   171 			HBufC8* iDataBuf;
       
   172 
       
   173 			/** @var TInt iBufferId
       
   174 			 *  Identifier for the stored data. Initialized as KErrNotFound. */
       
   175 			TInt iBufferId;
       
   176 
       
   177 			/** @var RFs iFs
       
   178 			 *  File server session */
       
   179 			RFs iFs;
       
   180 
       
   181 	};
       
   182 
       
   183 #endif // CXMLHANDLER_H
       
   184 
       
   185 //  End of File