creator/inc/creator_scriptparser.h
changeset 0 d6fe6244b863
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CREATORSCRIPTPARSER_H_
       
    21 #define CREATORSCRIPTPARSER_H_
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <xml/contenthandler.h>
       
    25 #include <xml/parser.h>
       
    26 
       
    27 using namespace Xml;
       
    28 
       
    29 class CCreatorScriptElement;
       
    30 class CCreatorEngine;
       
    31 class CCreatorScriptElementCache;
       
    32 
       
    33 class TCreatorScriptElementInfo
       
    34 {
       
    35 public:
       
    36     enum TElementStatus
       
    37     {
       
    38     EStatusUndefined,   // undefined
       
    39     EStatusParsing,     // currently being parsed
       
    40     EStatusParsed       // parsed
       
    41     };
       
    42     TCreatorScriptElementInfo()
       
    43         {
       
    44         iStatus = EStatusUndefined;
       
    45         iElement = 0;
       
    46         }
       
    47     TCreatorScriptElementInfo(TElementStatus aStatus, CCreatorScriptElement* aElement)
       
    48         {
       
    49         iStatus = aStatus;
       
    50         iElement = aElement;
       
    51         };
       
    52     
       
    53     TElementStatus iStatus;    
       
    54     CCreatorScriptElement* iElement;
       
    55 };
       
    56 
       
    57 class CCreatorScriptParser : public CBase, public MContentHandler
       
    58 {
       
    59 public:
       
    60 
       
    61     virtual ~CCreatorScriptParser();
       
    62     static CCreatorScriptParser* NewL(CCreatorEngine* aEngine);
       
    63     static CCreatorScriptParser* NewLC(CCreatorEngine* aEngine);    
       
    64     void ParseL(const TDesC& aFileName);
       
    65     void ParseL(RFile& aFile);
       
    66     
       
    67     TInt GetError() const;
       
    68     
       
    69 private:
       
    70 
       
    71     CCreatorScriptParser();
       
    72     void ConstructL(CCreatorEngine* aEngine);
       
    73     
       
    74     /**
       
    75      * Converts 8 bit descriptor to 16 bit descriptor
       
    76      * @param aDes 8 bit descriptor to be converted
       
    77      * @return Pointer to the new 16 bit descriptor     
       
    78      */
       
    79     HBufC* Convert8BitTo16BitLC(const TDesC8& aInput);
       
    80     const TCreatorScriptElementInfo& LastElementInfo() const;
       
    81     void GetTextFileMode(RFile& aFile, TInt& aFileSize);
       
    82 
       
    83     
       
    84 public:
       
    85     // From MContentHandler:    
       
    86     void OnStartDocumentL(const RDocumentParameters &aDocParam, TInt aErrorCode);
       
    87     void OnEndDocumentL(TInt aErrorCode);
       
    88     void OnStartElementL(   const RTagInfo& aElement, 
       
    89                             const RAttributeArray& aAttributes, 
       
    90                             TInt aErrorCode);
       
    91     void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode);
       
    92     void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
    93     void OnStartPrefixMappingL( const RString& aPrefix, 
       
    94                                 const RString& aUri, 
       
    95                                 TInt aErrorCode);
       
    96     void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
    97     void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
       
    98     void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
       
    99     void OnProcessingInstructionL(  const TDesC8& aTarget, 
       
   100                                     const TDesC8& aData, 
       
   101                                     TInt aErrorCode);
       
   102     void OnError(TInt aErrorCode);
       
   103     TAny* GetExtendedInterface(const TInt32 aUid);
       
   104     
       
   105 private:
       
   106 
       
   107     enum TFileFormat
       
   108         {
       
   109         EFormatANSIASCII,
       
   110         EFormatUTF8,
       
   111         EFormatUTF16LE,
       
   112         EFormatUTF16BE
       
   113         };
       
   114     // XML parser
       
   115     CParser* iParser;
       
   116     
       
   117     /**
       
   118      * Element stack holding the elements that are currently being parsed.
       
   119      */
       
   120     RArray<TCreatorScriptElementInfo> iElementStack;
       
   121     
       
   122     /**
       
   123      * Cache object containig the elements that are referred in future and thus should
       
   124      * not be deleted after parsing.
       
   125      */
       
   126     CCreatorScriptElementCache* iElementCache;
       
   127     
       
   128     /**
       
   129      * Pointer to the engine
       
   130      */
       
   131     CCreatorEngine* iEngine;
       
   132     
       
   133     TCreatorScriptElementInfo iDefaultElement;
       
   134     
       
   135     TFileFormat iScriptTextFormat;
       
   136     TInt iLastError;
       
   137 };
       
   138 
       
   139 #endif /*CREATORSCRIPTPARSER_H_*/