xdmprotocols/XdmXmlParser/inc/XmlFormatter.h
branchRCL_3
changeset 34 2669f8761a99
parent 31 2580314736af
child 35 fbd2e7cec7ef
equal deleted inserted replaced
31:2580314736af 34:2669f8761a99
     1 /*
       
     2 * Copyright (c) 2005 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:   CXmlFormatter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __XMLFORMATTER__
       
    22 #define __XMLFORMATTER__
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "XmlParserNodePath.h"
       
    27 #include "XmlNodePathInterface.h"
       
    28 
       
    29 //Konsts
       
    30 _LIT8( KXmldocumentStart,               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
       
    31 
       
    32 //Forwar declarations
       
    33 class CXdmDocument;
       
    34 class CXdmXmlParser;
       
    35 class CXdmDocumentNode;
       
    36 class MXdmNodeInterface;
       
    37 class CXmlParserNodePath;
       
    38 
       
    39 // CLASS DECLARATION
       
    40 NONSHARABLE_CLASS( CXmlFormatter ) : public CBase,
       
    41                                      public MXmlNodePathInterface
       
    42     {
       
    43     public:  // Constructors and destructor
       
    44         
       
    45         /**
       
    46         * Symbian OS Constructor
       
    47         * @return CXmlFormatter* New XML formatter
       
    48         */
       
    49         static CXmlFormatter* NewL( CXdmXmlParser& aParserMain );
       
    50         
       
    51         /**
       
    52         * Format a document
       
    53         * @param TBool Indicates whether parameter is a whole document
       
    54         * @param CXdmDocument* The target document
       
    55         * @param CXdmDocumentNode* The target element
       
    56         * @return HBufC8* The document in textual form
       
    57         */
       
    58         HBufC8* FormatLC( TBool aIsWholeDocument,
       
    59                           const CXdmDocument* aDocument,
       
    60                           const CXdmDocumentNode* aRootNode );
       
    61         
       
    62         /**
       
    63         * Format a document
       
    64         * @param TDesC8& An XML fragment to append
       
    65         * @param CXdmDocument* The target document
       
    66         * @param CXdmDocumentNode* The target element
       
    67         * @return HBufC8* The document in textual form
       
    68         */
       
    69         HBufC8* FormatLC( const TDesC8& aXmlFragment,
       
    70                           const CXdmDocument* aDocument,
       
    71                           const CXdmDocumentNode* aTargetNode );
       
    72                           
       
    73         /**
       
    74         * Destructor
       
    75         */
       
    76         virtual ~CXmlFormatter();
       
    77     
       
    78     private:  //From MXmlParserNodePathInterface
       
    79         
       
    80         /**
       
    81         * Return the target attribute
       
    82         * @return CXdmNodeAttribute* target attribute
       
    83         */
       
    84         CXdmNodeAttribute* TargetAttribute() const;
       
    85         
       
    86     private:
       
    87         
       
    88         /**
       
    89         * C++ constructor
       
    90         * @return CXmlFormatter
       
    91         */
       
    92         CXmlFormatter( CXdmXmlParser& aParserMain );
       
    93         
       
    94         /**
       
    95         * Symbian OS second-phase constructor
       
    96         * @return void
       
    97         */
       
    98         void ConstructL();
       
    99 
       
   100         /**
       
   101         * Read data from the format buffer into a contiguous segment
       
   102         * @return HBufC8* An XML document in textual form
       
   103         */  
       
   104         HBufC8* BufferToStringLC();
       
   105         
       
   106         /**
       
   107         * Check the next element in a document
       
   108         * @param CXdmDocumentNode& An XML element
       
   109         * @return void
       
   110         */
       
   111         void CheckSubsetPath( const CXdmDocumentNode& aNode );
       
   112         
       
   113         /**
       
   114         * Reset the internal format buffer
       
   115         * @return void
       
   116         */  
       
   117         void ResetFormatBuffer();
       
   118         
       
   119         /**
       
   120         * Find the (local) name of an element
       
   121         * @param TDesC8& The whole element string
       
   122         * @return TPtrC8 Name part of the element string
       
   123         */ 
       
   124         TPtrC8 FindElementName( const TDesC8& aElementString );
       
   125         
       
   126         /**
       
   127         * Format namespace declarations
       
   128         * @param CXdmDocumentNode& An XML element
       
   129         * @return MXdmNamespaceContainer& Namespace container
       
   130         */ 
       
   131         void FormatNamespaceDeclarationsL( const CXdmDocumentNode& aRootNode,
       
   132                                            const MXdmNamespaceContainer& aContainer );
       
   133                                            
       
   134         /**
       
   135         * Format the parameter element and its descendants
       
   136         * @param CXdmDocumentNode The element to format
       
   137         * @return void
       
   138         */  
       
   139         void FormatElementsL( CXdmDocumentNode* aCurrentNode );
       
   140 
       
   141         /**
       
   142         * Format a leaf element 
       
   143         * @param CXdmDocumentNode The element to format
       
   144         * @return void
       
   145         */    
       
   146         void FormatLeafElementL( CXdmDocumentNode* aCurrentNode );
       
   147         
       
   148         /**
       
   149         * Format the start of the parameter element
       
   150         * @param TDesC8& Element prefix 
       
   151         * @param TDesC8& Element URI 
       
   152         * @return void
       
   153         */ 
       
   154         void FormatElementStartL( const TDesC8& aPrefix,
       
   155                                   const TDesC8& aElementData ); 
       
   156 
       
   157         /**
       
   158         * Format the end of the parameter element
       
   159         * @param TDesC8& Element prefix 
       
   160         * @param TDesC8& Element URI 
       
   161         * @return void
       
   162         */ 
       
   163         void FormatElementEndL( const TDesC8& aPrefix,
       
   164                                 const TDesC8& aElementData );
       
   165         
       
   166         /**
       
   167         * Format an empty element 
       
   168         * @param CXdmDocumentNode The element to format
       
   169         * @return void
       
   170         */    
       
   171         void FormatEmptyElementL( CXdmDocumentNode* aEmptyNode );
       
   172         
       
   173                                                    
       
   174         /**
       
   175         * Append a namespace mapping
       
   176         * @param TDesC8& Element URI 
       
   177         * @param TDesC8& Element prefix
       
   178         * @return void
       
   179         */                                      
       
   180         void AppendNamespaceL( const TDesC8& aUri, const TDesC8& aPrefix );
       
   181         
       
   182         /**
       
   183         * Append XML fragment into the format buffer
       
   184         * @return void
       
   185         */ 
       
   186         void AppendXmlFragmentL();
       
   187         
       
   188         /**
       
   189         * Return the prefix of the parameter element
       
   190         * @param MXdmNodeInterface& An XML element
       
   191         * @return TPtrC8 Prefix
       
   192         */  
       
   193         TPtrC8 Prefix( const MXdmNodeInterface& aInterface );
       
   194         
       
   195     private: //Data
       
   196         
       
   197         TInt                                iFormBufferPos;
       
   198         TBool                               iTargetFound;
       
   199         TBool                               iIsAppended;
       
   200         CBufSeg*                            iFormatBuffer;
       
   201         TPtrC8                              iDocumentFragment;
       
   202         CXdmXmlParser&                      iParserMain;
       
   203         CXdmNodeAttribute*                  iTargetAttribute;
       
   204         CXmlParserNodePath*                 iNodePath;
       
   205         TXdmElementType                     iElementType;
       
   206        
       
   207     };
       
   208 
       
   209 #endif  //__XMLPARSERNODEPATH__
       
   210 
       
   211 
       
   212 // End of File