webengine/wmlengine/src/FileLoader/include/fileloader_csaveddeckhandler.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2003 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 the License "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 loading file scheme.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CSavedDeckHandler_H
       
    21 #define CSavedDeckHandler_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "urlloader_urlloaderint.h"
       
    25 #include <f32file.h>
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // DATA TYPES
       
    32 // This data type does not have a destructor
       
    33 // and does not take ownership of the strings
       
    34 class CSavedDeckPart
       
    35 {
       
    36 public:
       
    37     CSavedDeckPart():iUrl(NULL,0),iData(NULL,0),iContentTypeString(NULL,0){}
       
    38     void Reset();
       
    39     TPtrC8 iUrl;
       
    40     TPtrC8 iData;
       
    41     TPtrC8 iContentTypeString;
       
    42     TUint32 iCharset;
       
    43 	TUint32 iOriCharset;
       
    44 };
       
    45 
       
    46 // FUNCTION PROTOTYPES
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 
       
    50 // CLASS DECLARATION
       
    51 
       
    52 /**
       
    53 *  Handling the loading and parsing of a saved deck.
       
    54 *  
       
    55 *
       
    56 *  @lib fileloader.lib
       
    57 *  @since 2.0
       
    58 */
       
    59 class CSavedDeckHandler : public CBase
       
    60 {
       
    61 public:  // Constructors and destructor
       
    62 
       
    63     /**
       
    64     * Two-phased constructor.
       
    65     * @param aData The buffer loaded from the file system.
       
    66     */
       
    67     static CSavedDeckHandler* NewLC(TPtrC8& aData);
       
    68 
       
    69     /**
       
    70     * Destructor.
       
    71     */
       
    72     virtual ~CSavedDeckHandler();
       
    73 
       
    74 public: // New functions
       
    75 
       
    76     /**
       
    77     * Parse the saved deck buffer into the parts and store each part in cache.
       
    78     * @since 2.0
       
    79     * @param aData The file content loaded from the file system.
       
    80     * @param aRequestUrl The original request URL.
       
    81     * @param aResponseData The body of the first data part.
       
    82 	*						It will be sent back as the response.
       
    83     * @param aResponseUrl The Original URL of the first part of the response.
       
    84     * @param aContentTypeString The string representation of the content type
       
    85 	*							 of the first data part. It is used only if a
       
    86 	*							 WAP token cannot be identified.
       
    87     * @param aCharset The character set of the first data part.
       
    88     * @param aSavedDeck A flag indicating if this is a saved deck or not.
       
    89     * @return KErrCorrupt or KErrNone
       
    90     */
       
    91     static TInt ParseSavedDeck(TPtrC8& aData,
       
    92                                TPtrC& aRequestUrl,
       
    93                                TPtr8& aResponseData,
       
    94                                TPtr& aResponseUrl,
       
    95                                TPtr8& aContentTypeString,
       
    96                                TUint& aCharset,
       
    97                                TBool& aSavedDeck);
       
    98 
       
    99 
       
   100     /**
       
   101     * Parse the saved deck buffer into the parts and store each part in cache.
       
   102     * @since 2.0
       
   103     * @param aData The file content loaded from the file system.
       
   104     * @param aRequestUrl The original request URL.
       
   105     * @param aResponseData The body of the first data part.
       
   106 	*						It will be sent back as the response.
       
   107     * @param aResponseUrl The Original URL of the first part of the response.
       
   108     * @param aContentType The WAP token content type of the first data part.
       
   109     * @param aContentTypeString The string representation of the content type
       
   110 	*							 of the first data part. It is used only if a
       
   111 	*							 WAP token cannot be identified.
       
   112     * @param aCharset The character set of the first data part.
       
   113     * @param aSavedDeck A flag indicating if this is a saved deck or not.
       
   114     * @return void
       
   115     */
       
   116     static void ParseSavedDeckL(TPtrC8& aData,
       
   117                                 TPtrC& aRequestUrl,
       
   118                                 TPtr8& aResponseData,
       
   119                                 TPtr& aResponseUrl,
       
   120                                 TPtr8&  aContentTypeString,
       
   121                                 TUint& aCharset,
       
   122                                 TBool& aSavedDeck);
       
   123 
       
   124 private:
       
   125 
       
   126     /**
       
   127     * C++ default constructor.
       
   128     */
       
   129     CSavedDeckHandler(TPtrC8& aData);
       
   130 
       
   131     /**
       
   132     * By default Symbian 2nd phase constructor is private.
       
   133     */
       
   134     void ConstructL();
       
   135 
       
   136     /**
       
   137     * Check if the loaded file is a saved deck, based on the path and extension.
       
   138     */
       
   139     static TBool IsSavedDeck(TPtrC& aRequestUrl);
       
   140 
       
   141     /**
       
   142     * Extract the next data part from the buffer.
       
   143     */
       
   144     void GetNextPartL(CSavedDeckPart& aSavedDeckPart);
       
   145 
       
   146     /**
       
   147     * Copy the data and URL of the first part, to be returned as the response.
       
   148     */
       
   149     void PrepareResponseLC(CSavedDeckPart& aSavedDeckPart,
       
   150                            TPtr8& aResponseData,
       
   151                            TPtr& aResponseUrl,
       
   152                            TPtr8& aContentTypeString,
       
   153                            TUint& aCharset);
       
   154 
       
   155     /**
       
   156     * Send a response part to cache.
       
   157     */
       
   158     void LoadPartToCacheL(CSavedDeckPart& aSavedDeckPart);
       
   159 
       
   160 	/**
       
   161 	* Convert charset to string
       
   162 	*/
       
   163     TPtrC8 ConvertCharsetToStr(TUint32 aCharSet);
       
   164 
       
   165     /**
       
   166     * Extract a TUint from a buffer and advance the pointer.
       
   167 	*/
       
   168     TUint GetUintFromBuffer(TPtrC8& aPtr)
       
   169 	{
       
   170 		TUint i;
       
   171         TUint8* c = (TUint8*)(&i);
       
   172         Mem::Copy(c, aPtr.Ptr(), sizeof(TUint));
       
   173 		aPtr.Set(aPtr.Mid(sizeof(TUint)));
       
   174 		return i;
       
   175 	}
       
   176 
       
   177 private:    // Data
       
   178 
       
   179     // The file content loaded from the file system.
       
   180     TPtrC8 iData;
       
   181 
       
   182     // A descriptior pointing to the current position to process in the loaded file.
       
   183     TPtrC8 iDataReader;
       
   184 };
       
   185 
       
   186 #endif      // CSavedDeckHandler_H
       
   187 
       
   188 // End of File