epoc32/include/mw/senxmlelement.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 1 666f914201fb
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). 
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     5
* under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description:        This is an optimized variant of XML element, which consumes
williamr@2
    15
*                significantly less heap when compared to CSenBaseElement
williamr@2
    16
*
williamr@2
    17
*/
williamr@2
    18
williamr@2
    19
williamr@2
    20
williamr@2
    21
williamr@2
    22
williamr@2
    23
williamr@2
    24
williamr@2
    25
williamr@2
    26
#ifndef SEN_XML_ELEMENT_H
williamr@2
    27
#define SEN_XML_ELEMENT_H
williamr@2
    28
williamr@2
    29
//  INCLUDES
williamr@2
    30
#include <s32mem.h>
williamr@2
    31
#include <SenElement.h>
williamr@2
    32
#include <SenNamespace.h>
williamr@2
    33
#include <SenBaseAttribute.h>
williamr@2
    34
williamr@2
    35
// CLASS DECLARATION
williamr@2
    36
williamr@2
    37
/**
williamr@2
    38
*  Implementation of an XML element functionality
williamr@2
    39
*  Content is stored in UTF-8 form XML. Note, that
williamr@2
    40
*  setting any 8-bit content into XML without encoding
williamr@2
    41
*  it into form of legal is illegal. Instead, one
williamr@2
    42
*  should use encoding methods, like ones introduced 
williamr@2
    43
*  in SenXmlUtils class to encode basic entities, or
williamr@2
    44
*  use use some other encoding like MD5 for binary 
williamr@2
    45
*  data content.
williamr@2
    46
*  @lib SenXML.dll
williamr@2
    47
*  @since Series60 3.1
williamr@2
    48
*/
williamr@2
    49
class CSenXmlElement : public CSenElement
williamr@2
    50
    {
williamr@2
    51
    public:  // Constructors and destructor
williamr@2
    52
williamr@2
    53
        /**
williamr@2
    54
         *  Standard constructor.
williamr@2
    55
         *  @param aLocalName   the local name for this element.
williamr@2
    56
         *  Leave codes:    
williamr@2
    57
         *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
    58
         *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
williamr@2
    59
         */
williamr@2
    60
williamr@2
    61
        IMPORT_C static CSenXmlElement* NewL(const TDesC8& aLocalName);
williamr@2
    62
        /**
williamr@2
    63
         *  Standard constructor.
williamr@2
    64
         *  @param aNsUri       the namespace URI for this element.
williamr@2
    65
         *  @param aLocalName   the local name for this element.
williamr@2
    66
         *  Leave codes:    
williamr@2
    67
         *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
    68
         *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
williamr@2
    69
         */
williamr@2
    70
        IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri,
williamr@2
    71
                                             const TDesC8& aLocalName);
williamr@2
    72
williamr@2
    73
        /**
williamr@2
    74
         *  Standard constructor.
williamr@2
    75
         *  @param aNsUri       the namespace URI for this element.
williamr@2
    76
         *  @param aLocalName   the local name for this element.
williamr@2
    77
         *  @param aQName       the qualified name for this element.
williamr@2
    78
         *  Leave codes:    
williamr@2
    79
         *      KErrSenInvalidCharacters if aLocalName or aQName contains
williamr@2
    80
         *      illegal characters.     
williamr@2
    81
         *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
    82
         */
williamr@2
    83
        IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri,
williamr@2
    84
                                             const TDesC8& aLocalName,
williamr@2
    85
                                             const TDesC8& aQName);
williamr@2
    86
williamr@2
    87
        /**
williamr@2
    88
         *  Standard constructor.
williamr@2
    89
         *  @param aNsUri       the namespace URI for this element.
williamr@2
    90
         *  @param aLocalName   the local name for this element.
williamr@2
    91
         *  @param aQName       the qualified name for this element.
williamr@2
    92
         *  @param apAttrs      the attributes for this element.
williamr@2
    93
         *  Leave codes:    
williamr@2
    94
         *      KErrSenInvalidCharacters if aLocalName or aQName contains
williamr@2
    95
         *      illegal characters.     
williamr@2
    96
         *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
    97
         */
williamr@2
    98
        IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri, 
williamr@2
    99
                                             const TDesC8& aLocalName,
williamr@2
   100
                                             const TDesC8& aQName,
williamr@2
   101
                                             const RAttributeArray& apAttrs);
williamr@2
   102
williamr@2
   103
        /**
williamr@2
   104
         *  Standard constructor.
williamr@2
   105
         *  @param aNsUri       the namespace URI for this element.
williamr@2
   106
         *  @param aLocalName   the local name for this element.
williamr@2
   107
         *  @param aQName       the qualified name for this element.
williamr@2
   108
         *  @param apAttrs      the attributes for this element.
williamr@2
   109
         *  @param aParent: the parent element for the new element
williamr@2
   110
         *  Leave codes:    
williamr@2
   111
         *      KErrSenInvalidCharacters if aLocalName or aQName contains
williamr@2
   112
         *      illegal characters.     
williamr@2
   113
         *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
   114
         */
williamr@2
   115
        IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri,
williamr@2
   116
                                             const TDesC8& aLocalName,
williamr@2
   117
                                             const TDesC8& aQName,
williamr@2
   118
                                             const RAttributeArray& apAttrs,
williamr@2
   119
                                             CSenElement& aParent);
williamr@2
   120
williamr@2
   121
        /**
williamr@2
   122
        * Destructor.
williamr@2
   123
        */
williamr@2
   124
        IMPORT_C virtual ~CSenXmlElement();
williamr@2
   125
williamr@2
   126
    public: // New functions
williamr@2
   127
    
williamr@2
   128
        /**
williamr@2
   129
         *  Adds attributes to the element. Calls internally AddAttributesL()
williamr@2
   130
         *  Can be overridden to replace old attributes.
williamr@2
   131
         *  @param  aAttrs: the array of attributes.
williamr@2
   132
         */
williamr@2
   133
        IMPORT_C virtual void SetAttributesL(const RAttributeArray& apAttrs);
williamr@2
   134
    
williamr@2
   135
        // Functions from base classes
williamr@2
   136
    
williamr@2
   137
        // From CSenElement
williamr@2
   138
    
williamr@2
   139
        /**
williamr@2
   140
        *   Getter for Element's local name.
williamr@2
   141
        *   @return Localname or KNullDesC if not set.
williamr@2
   142
        */  
williamr@2
   143
        IMPORT_C virtual const TDesC8& LocalName() const;
williamr@2
   144
williamr@2
   145
        /**
williamr@2
   146
        *   Getter for Element's namespace URI.
williamr@2
   147
        *   @return Namespace URI or KNullDesC if not set.
williamr@2
   148
        */
williamr@2
   149
        IMPORT_C virtual const TDesC8& NamespaceURI() const;
williamr@2
   150
williamr@2
   151
        /**
williamr@2
   152
         *  Getter for namespace prefix of this element.
williamr@2
   153
         *  @return namespace prefix or KNullDesC if not set.
williamr@2
   154
         */
williamr@2
   155
        IMPORT_C virtual const TDesC8& NsPrefix() const;
williamr@2
   156
williamr@2
   157
        /**
williamr@2
   158
         *  Setter for namespace prefix of this element.
williamr@2
   159
         *  @param aPrefix: new namespace prefix for the element.
williamr@2
   160
         */
williamr@2
   161
        IMPORT_C virtual void SetPrefixL(const TDesC8& aPrefix);
williamr@2
   162
williamr@2
   163
        /**
williamr@2
   164
         *  Method for checking if the element has any content within.
williamr@2
   165
         *  @return ETrue if has content, EFalse if not.
williamr@2
   166
         */
williamr@2
   167
        IMPORT_C virtual TBool HasContent() const;
williamr@2
   168
williamr@2
   169
        /**
williamr@2
   170
         *  Getter for the content of the element.
williamr@2
   171
         *  @return the content or KNullDesC if empty.
williamr@2
   172
         */
williamr@2
   173
        IMPORT_C virtual TPtrC8 Content() const;
williamr@2
   174
williamr@2
   175
        /**
williamr@2
   176
         *  Getter for the content of the element, unicode version.
williamr@2
   177
         *  @return content as unicode. Ownership IS TRANSFERRED to the caller.
williamr@2
   178
         */
williamr@2
   179
        IMPORT_C virtual HBufC* ContentUnicodeL() const;
williamr@2
   180
williamr@2
   181
        /**
williamr@2
   182
         *  Sets the content to the element. Old content is overwritten.
williamr@2
   183
         *  @param  aContent:   The content to be set. Can be KNullDesC8.
williamr@2
   184
         *  @return The content of the element or KNullDesC8 if no content was set.
williamr@2
   185
         */
williamr@2
   186
        IMPORT_C virtual TPtrC8 SetContentL(const TDesC8& aContent);
williamr@2
   187
williamr@2
   188
        /**
williamr@2
   189
         *  Gets the write stream for the content for easy appending.
williamr@2
   190
         *  Writing 8-bit (UTF-8) string to the returned stream will be appended
williamr@2
   191
         *  to the content.
williamr@2
   192
         *  @return reference to the RWriteStream.
williamr@2
   193
         */
williamr@2
   194
        IMPORT_C virtual RWriteStream& ContentWriteStreamL();
williamr@2
   195
williamr@2
   196
        /**
williamr@2
   197
         * Checks if element matches to another element
williamr@2
   198
         * by its content and child elements. Element
williamr@2
   199
         * can contain more data than the given pattern.
williamr@2
   200
         * @since Series60 3.0
williamr@2
   201
         * @param aCandidate    The pattern to be matched. Must contain same or 
williamr@2
   202
         *                  less data for match to come true.
williamr@2
   203
         * @return ETrue if content and possible children match exactly 
williamr@2
   204
         *          to given pattern. EFalse otherwise.
williamr@2
   205
         */
williamr@2
   206
        IMPORT_C virtual TBool ConsistsOfL(MSenElement& aCandidate);
williamr@2
   207
williamr@2
   208
        /**
williamr@2
   209
        *   Setter for Element's namespace URI.
williamr@2
   210
        *   @param aNsUri:  Namespace URI
williamr@2
   211
        */
williamr@2
   212
        IMPORT_C virtual void SetNamespaceL(const TDesC8& aNsUri);
williamr@2
   213
williamr@2
   214
        /**
williamr@2
   215
        *   Setter for Element's namespace URI.
williamr@2
   216
        *   @param aNsPrefix:   Namespace prefix
williamr@2
   217
        *   @param aNsUri:      Namespace URI
williamr@2
   218
        */
williamr@2
   219
        IMPORT_C virtual void SetNamespaceL(const TDesC8& aNsPrefix,
williamr@2
   220
                                            const TDesC8& aNsUri);
williamr@2
   221
williamr@2
   222
        /**
williamr@2
   223
         * Adds a namespace declaration.
williamr@2
   224
         * If this element (or its parent if parameter aCheckInParent is ETrue) 
williamr@2
   225
         * already has a Namespace with the same prefix and URI the given
williamr@2
   226
         * Namespace is not added.
williamr@2
   227
         * @param aNewNamespace
williamr@2
   228
         * @param aCheckInParent
williamr@2
   229
         * @return the added Namespace, or the equivalent pre-existing one.
williamr@2
   230
         */ 
williamr@2
   231
        IMPORT_C virtual const CSenNamespace* AddNamespaceL(CSenNamespace& aNewNamespace,
williamr@2
   232
                                                            TBool aCheckInParent);
williamr@2
   233
        /**
williamr@2
   234
        *   Method for adding a namespace for the Element.
williamr@2
   235
        *   @param aPrefix: Namespace prefix
williamr@2
   236
        *   @param aUri:    Namespace URI
williamr@2
   237
        *   @return the added Namespace, or the equivalent pre-existing one.
williamr@2
   238
        */
williamr@2
   239
        IMPORT_C virtual const CSenNamespace* AddNamespaceL(const TDesC8& aPrefix,
williamr@2
   240
                                                            const TDesC8& aUri);
williamr@2
   241
        /**
williamr@2
   242
        *   Getter for Element's namespace.
williamr@2
   243
        *   @return const pointer to the CSenNamespace object of this Element.
williamr@2
   244
        *           NULL if not set.
williamr@2
   245
        */ 
williamr@2
   246
        IMPORT_C virtual const CSenNamespace* Namespace();
williamr@2
   247
williamr@2
   248
        /**
williamr@2
   249
         * Getter for new namespace, using a namespace prefix as a search criteria.
williamr@2
   250
         * @param aNsPrefix is the new namespace prefix for this element
williamr@2
   251
         * @return the found Namespace that is declared for the given prefix
williamr@2
   252
         * within the scope of this Element. If no such prefix is
williamr@2
   253
         * declared return null.
williamr@2
   254
         */     
williamr@2
   255
        IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix);
williamr@2
   256
williamr@2
   257
        /**
williamr@2
   258
         * Getter for new namespace, using a namespace prefix as a search criteria,
williamr@2
   259
         * supporting both normal and recursive search mode (checking the parent).
williamr@2
   260
         * @param aNsPrefix:        The prefix used to search
williamr@2
   261
         * @param aCheckInParent:   The flag indicating whether to check parent's
williamr@2
   262
         *                          namespaces too if not found in the current 
williamr@2
   263
         *                          element. 
williamr@2
   264
         *                          ETrue to check, EFalse for not to check.
williamr@2
   265
         * @return the found Namespace that is declared for the given prefix 
williamr@2
   266
         *                   and namespace URI within the scope of this Element
williamr@2
   267
         *                   or NULL if not found
williamr@2
   268
         */ 
williamr@2
   269
        IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix,
williamr@2
   270
                                                        const TBool aCheckInParent);
williamr@2
   271
williamr@2
   272
        /**
williamr@2
   273
         * Getter for new namespace, using both namespace prefix and namespace URI as search criteria.
williamr@2
   274
         * @param aNsPrefix:    The prefix used to search
williamr@2
   275
         * @param aUri:         The namespace URI used to search.
williamr@2
   276
         * @return the found Namespace that is declared for the given prefix 
williamr@2
   277
         *                   and namespace URI within the scope of this Element
williamr@2
   278
         *                   or NULL if not found.
williamr@2
   279
         */     
williamr@2
   280
        IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix,
williamr@2
   281
                                                        const TDesC8& aUri);
williamr@2
   282
williamr@2
   283
        /**
williamr@2
   284
         *  Getting the child elements of this element matching the given criteria.
williamr@2
   285
         *  @param aElementArray:   Array to be filled with the matching elements,
williamr@2
   286
         *                          or empty array if no matching found. 
williamr@2
   287
         *                          Any modifications made on the returned items
williamr@2
   288
         *                          modify the real childs too.
williamr@2
   289
         *  @param aNsUri:          namespace URI to be matched
williamr@2
   290
         *  @param aLocalName:      local name to be matched
williamr@2
   291
         *  @return KErrNone        ok
williamr@2
   292
         *          KErrNotFound    No child elements exist.
williamr@2
   293
         */     
williamr@2
   294
        IMPORT_C virtual TInt ElementsL(RPointerArray<CSenElement>& aElementArray,
williamr@2
   295
                                        const TDesC8& aNsUri,
williamr@2
   296
                                        const TDesC8& aLocalName);
williamr@2
   297
        
williamr@2
   298
        /**
williamr@2
   299
         *  Getting the child elements of this element matching the given criteria.
williamr@2
   300
         *  @param aElementArray:   Array to be filled with the matching elements,
williamr@2
   301
         *                          or empty array if no matching found. 
williamr@2
   302
         *                          Any modifications made on the returned items
williamr@2
   303
         *                          modify the real childs too.
williamr@2
   304
         *  @param aNsUri:          namespace URI to be matched
williamr@2
   305
         *  @param aLocalName:      local name to be matched
williamr@2
   306
         *  @return KErrNone        ok
williamr@2
   307
         *          KErrNotFound    No child elements exist.
williamr@2
   308
         */     
williamr@2
   309
        IMPORT_C virtual TInt ElementsL(RPointerArray<CSenElement>& aElementArray,
williamr@2
   310
                                        const TDesC8& aLocalName);
williamr@2
   311
williamr@2
   312
        /**
williamr@2
   313
         *  Getting the child elements of this element.
williamr@2
   314
         *  @return an array of child elements. This is an empty array if there
williamr@2
   315
         *          are no children. Any modifications made on the returned array
williamr@2
   316
         *          modify the element object.
williamr@2
   317
         */     
williamr@2
   318
        IMPORT_C virtual RPointerArray<CSenElement>& ElementsL();
williamr@2
   319
williamr@2
   320
        /**
williamr@2
   321
         *  Gets all the attributes of this element in an array.
williamr@2
   322
         *  @return array of attributes. Array will be empty if element has 
williamr@2
   323
         *          no attributes.
williamr@2
   324
         */     
williamr@2
   325
        IMPORT_C virtual RPointerArray<CSenBaseAttribute>& AttributesL();
williamr@2
   326
williamr@2
   327
        /**
williamr@2
   328
         *  Gets all the namespaces of this element in an array.
williamr@2
   329
         *  @return array of namespaces. Array will be empty if element has 
williamr@2
   330
         *          no namespaces.
williamr@2
   331
         */     
williamr@2
   332
        IMPORT_C virtual RPointerArray<CSenNamespace>& NamespacesL();
williamr@2
   333
williamr@2
   334
        /**
williamr@2
   335
         *  Gets the value of the given attribute.
williamr@2
   336
         *  @param aName:   Name of the attribute in question.
williamr@2
   337
         *  @return the value of the attribute, or NULL if not found. Ownership is
williamr@2
   338
         *          NOT TRANSFERRED.
williamr@2
   339
         */     
williamr@2
   340
        IMPORT_C virtual const TDesC8* AttrValue(const TDesC8& aName);
williamr@2
   341
        
williamr@2
   342
        /**
williamr@2
   343
         *  Adds an attribute. If attribute is already existing, 
williamr@2
   344
         *  the value of the attribute will be replaced.
williamr@2
   345
         */
williamr@2
   346
        IMPORT_C virtual void AddAttrL(const TDesC8& aName, const TDesC8& aValue);
williamr@2
   347
williamr@2
   348
        /**
williamr@2
   349
         *  Gets the parent element of this element.
williamr@2
   350
         *  @return the parent element or NULL if no parent set. 
williamr@2
   351
         *          Ownership is NOT transferred to the caller.
williamr@2
   352
         */     
williamr@2
   353
        IMPORT_C virtual CSenElement* Parent();
williamr@2
   354
williamr@2
   355
        /**
williamr@2
   356
         *  Sets the parent element to this element. Notice that the element is not
williamr@2
   357
         *  automatically added as a child of the parent. Parent's 
williamr@2
   358
         *  AddElementL() should be called instead.
williamr@2
   359
         *  @param apParent:    The wanted parent. Can be NULL.
williamr@2
   360
         *  @return the parent element
williamr@2
   361
         */ 
williamr@2
   362
        IMPORT_C virtual CSenElement* SetParent(CSenElement* apParent);
williamr@2
   363
williamr@2
   364
        /**
williamr@2
   365
         *  Gets the root element. If no parent element, returns this element.
williamr@2
   366
         *  @return the root of the tree. Ownership is NOT transferred.
williamr@2
   367
         */     
williamr@2
   368
        IMPORT_C virtual MSenElement& Root();
williamr@2
   369
williamr@2
   370
        /**
williamr@2
   371
         *  Gets the child element with the specified local name.
williamr@2
   372
         *  Assumes that namespace is the same as this parent element.
williamr@2
   373
         *  @return the child element or NULL if the child with the specified 
williamr@2
   374
         *          local name is not found. Ownership is NOT transferred.
williamr@2
   375
         */ 
williamr@2
   376
        IMPORT_C virtual CSenElement* Element(const TDesC8& aLocalName);
williamr@2
   377
williamr@2
   378
        /**
williamr@2
   379
         *  Gets the child element with the specified local name and namespace URI.
williamr@2
   380
         *  @return the child element or NULL if the child with the specified 
williamr@2
   381
         *          criterias is not found. Ownership is NOT transferred.
williamr@2
   382
         */ 
williamr@2
   383
        IMPORT_C virtual CSenElement* Element(const TDesC8& aNsUri,
williamr@2
   384
                                              const TDesC8& aLocalName);
williamr@2
   385
williamr@2
   386
        /**
williamr@2
   387
         * Create a new element ready for adding or insertion.
williamr@2
   388
         * If the given namespace prefix is not declared yet
williamr@2
   389
         * the element will not be created and NULL will be returned.
williamr@2
   390
         * @param aNsPrefix:    The namespace prefix
williamr@2
   391
         * @param aLocalName:   The new elements localname
williamr@2
   392
         * @return  the new Element just created, or NULL if given prefix was not
williamr@2
   393
         *          declared yet. Ownership is transferred to the caller.
williamr@2
   394
         *  Leave codes:    
williamr@2
   395
         *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
   396
         *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
   397
         */     
williamr@2
   398
        IMPORT_C virtual CSenElement* CreateElementL(const TDesC8& aNsPrefix,
williamr@2
   399
                                                     const TDesC8& aLocalName);
williamr@2
   400
williamr@2
   401
        /**
williamr@2
   402
         * Insert an Element into the list of children elements
williamr@2
   403
         * so that the inserted Element is placed right before the aBeforeElement.
williamr@2
   404
         * If aBeforeElement is not found, element will be appended to the last
williamr@2
   405
         * position.
williamr@2
   406
         * Function leaves if error occurs in inserting.
williamr@2
   407
         * @param aInsertedElement: the element to be inserted. 
williamr@2
   408
         *                          Ownership is transferred.
williamr@2
   409
         * @param aBeforeElement:   the element which will be right next to the 
williamr@2
   410
         *                          element just inserted.
williamr@2
   411
         * @return the inserted Element
williamr@2
   412
         */     
williamr@2
   413
        IMPORT_C virtual CSenElement& InsertElementL(CSenElement& aElement,
williamr@2
   414
                                                     const CSenElement& aBeforeElement);
williamr@2
   415
williamr@2
   416
        /**
williamr@2
   417
         * Adds an Element to the children elements. 
williamr@2
   418
         * Sets this element to be the new parent of the given element.
williamr@2
   419
         * @param aElement: the element to be added. Ownership is transferred.
williamr@2
   420
         * @return the added Element
williamr@2
   421
         */ 
williamr@2
   422
        IMPORT_C virtual CSenElement& AddElementL(CSenElement& aElement);
williamr@2
   423
williamr@2
   424
        /**
williamr@2
   425
         * Constructs and adds a new element to the children elements. 
williamr@2
   426
         * Sets this element to be the new parent of the given element.
williamr@2
   427
         * @param aNsUri:       namespace URI of the new element
williamr@2
   428
         * @param aLocalName:   local name of the new element
williamr@2
   429
         * @return the added Element
williamr@2
   430
         *  Leave codes:    
williamr@2
   431
         *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
   432
         *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
williamr@2
   433
         */     
williamr@2
   434
        IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aNsUri,
williamr@2
   435
                                                  const TDesC8& aLocalName);
williamr@2
   436
williamr@2
   437
        /**
williamr@2
   438
         * Constructs and adds a new element to the children elements. 
williamr@2
   439
         * Sets this element to be the new parent of the given element.
williamr@2
   440
         * @param aNsUri:       namespace URI of the new element
williamr@2
   441
         * @param aLocalName:   local name of the new element
williamr@2
   442
         * @param aQName:       qualified name of the new element
williamr@2
   443
         * @return the added Element
williamr@2
   444
         *  Leave codes:    
williamr@2
   445
         *      KErrSenInvalidCharacters if aLocalName or aQName contain illegal 
williamr@2
   446
         *      characters.     
williamr@2
   447
         *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
   448
         */ 
williamr@2
   449
        IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aNsUri,
williamr@2
   450
                                                  const TDesC8& aLocalName,
williamr@2
   451
                                                  const TDesC8& aQName);
williamr@2
   452
williamr@2
   453
        /**
williamr@2
   454
         * Constructs and adds a new element to the children elements. 
williamr@2
   455
         * Sets this element to be the new parent of the given element.
williamr@2
   456
         * Note: Element is created with no specific namespace, default namespace
williamr@2
   457
         * of some of the upper level elements are in effect if there is such a 
williamr@2
   458
         * namespace.
williamr@2
   459
         * @param aLocalName:   local name of the new element
williamr@2
   460
         * @return the added Element
williamr@2
   461
         *  Leave codes:    
williamr@2
   462
         *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
   463
         *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
williamr@2
   464
         */     
williamr@2
   465
        IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aLocalName);
williamr@2
   466
williamr@2
   467
        /**
williamr@2
   468
         *  Remove an element from the childs.
williamr@2
   469
         *  @param  aElement:   the element to be removed.
williamr@2
   470
         *  @return The removed element. May be NULL if nothing was removed
williamr@2
   471
         *          (if element was not found from the childs).
williamr@2
   472
         *          The caller TAKES OWNERSHIP of the removed element.
williamr@2
   473
         */     
williamr@2
   474
        IMPORT_C virtual CSenElement* RemoveElement(CSenElement& aElement);
williamr@2
   475
williamr@2
   476
        /**
williamr@2
   477
         *  Remove an element from the childs.
williamr@2
   478
         *  @param  aNsUri:     the namespace URI of the element to be removed.
williamr@2
   479
         *  @param  aLocalName: the local name of the element to be removed.
williamr@2
   480
         *  @return The removed element. May be NULL if nothing was removed
williamr@2
   481
         *          (if element was not found from the childs).
williamr@2
   482
         *          The caller TAKES OWNERSHIP of the removed element.
williamr@2
   483
         */     
williamr@2
   484
        IMPORT_C virtual CSenElement* RemoveElement(const TDesC8& aNsUri,
williamr@2
   485
                                                    const TDesC8& aLocalName);
williamr@2
   486
williamr@2
   487
        /**
williamr@2
   488
         *  Remove an element from the childs.
williamr@2
   489
         *  @param  aLocalName: the local name of the element to be removed.
williamr@2
   490
         *  @return The removed element. May be NULL if nothing was removed
williamr@2
   491
         *          (if element was not found from the childs).
williamr@2
   492
         *          The caller TAKES OWNERSHIP of the removed element.
williamr@2
   493
         */     
williamr@2
   494
        IMPORT_C virtual CSenElement* RemoveElement(const TDesC8& aLocalName);
williamr@2
   495
williamr@2
   496
        /**
williamr@2
   497
         *  Replaces an element from the childs with another element. 
williamr@2
   498
         *  Element's local name and namespace URI will be used to match the
williamr@2
   499
         *  element to be replaced. If matching element is not found, will
williamr@2
   500
         *  normally add the given element to the childs.
williamr@2
   501
         *  @param  aElement:   the element to be added. Ownership is transferred.
williamr@2
   502
         *  @return The old element. May be NULL if nothing was replaced
williamr@2
   503
         *          (if element was not found from the childs).
williamr@2
   504
         *          The caller TAKES OWNERSHIP of the old element.
williamr@2
   505
         */ 
williamr@2
   506
        IMPORT_C virtual CSenElement* ReplaceElementL(CSenElement& aElement);
williamr@2
   507
williamr@2
   508
        /**
williamr@2
   509
         *  Gets the element as an XML buffer. Buffer will contain all the childs
williamr@2
   510
         *  @return element as XML. Caller takes ownership.
williamr@2
   511
         */
williamr@2
   512
        IMPORT_C virtual HBufC8* AsXmlL();
williamr@2
   513
williamr@2
   514
        /**
williamr@2
   515
         *  Gets the element as an unicode XML buffer. 
williamr@2
   516
         *  Buffer will contain all the childs etc.
williamr@2
   517
         *  @return element as XML. Caller takes ownership.
williamr@2
   518
         */     
williamr@2
   519
        IMPORT_C virtual HBufC* AsXmlUnicodeL();
williamr@2
   520
williamr@2
   521
        /**
williamr@2
   522
         *  Element writes itself to a write stream using UTF-8 charset encoding.
williamr@2
   523
         *  @param aWriteStream:    The stream to write to.
williamr@2
   524
         */     
williamr@2
   525
        IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWriteStream);
williamr@2
   526
williamr@2
   527
        /**
williamr@2
   528
         *  Element writes its namespaces to a write stream using UTF-8 charset 
williamr@2
   529
         *  encoding.
williamr@2
   530
         *  @param aWriteStream:    The stream to write to.
williamr@2
   531
         */     
williamr@2
   532
        IMPORT_C virtual void WriteNamespacesToL(RWriteStream& aWriteStream);
williamr@2
   533
williamr@2
   534
        /**
williamr@2
   535
         *  Gets the current element as XML element. Mostly used to get the
williamr@2
   536
         *  classes which implement this interface as an instance of this 
williamr@2
   537
         *  interface.
williamr@2
   538
         *  @return the current object as element. Ownership is NOT transferred.
williamr@2
   539
         */     
williamr@2
   540
        IMPORT_C virtual MSenElement* AsElement();
williamr@2
   541
williamr@2
   542
        /**
williamr@2
   543
         *  Copies content from given element to this element appending to the 
williamr@2
   544
         *  existing content if there is any.
williamr@2
   545
         *  @param aSource: The source element.
williamr@2
   546
         */ 
williamr@2
   547
        IMPORT_C void CopyFromL(CSenElement& aSource);
williamr@2
   548
williamr@2
   549
        /**
williamr@2
   550
         * Detach the element from its parent.
williamr@2
   551
         * If the element, or one of its children, is dependent
williamr@2
   552
         * on a namespace declared in the scope of the parent
williamr@2
   553
         * copy those namespace declarations to this element.
williamr@2
   554
         * @return this Element. Ownership IS TRANSFERRED to the caller.
williamr@2
   555
         */ 
williamr@2
   556
        IMPORT_C virtual CSenElement* DetachL();
williamr@2
   557
williamr@2
   558
        /**
williamr@2
   559
         *  Gets a child element from a specified index.
williamr@2
   560
         *  @param  aIndex: the index what to get
williamr@2
   561
         *  @return child element from a current index. NULL if no child in given
williamr@2
   562
         *          index is found
williamr@2
   563
         */ 
williamr@2
   564
        IMPORT_C virtual CSenElement* Child(TInt aIndex);
williamr@2
   565
williamr@2
   566
        /**
williamr@2
   567
         * (Re-) Set the name and namespace of this Element. The element will be
williamr@2
   568
         * given the localName in the the given namespace. A prefix will be
williamr@2
   569
         * computed from the qualified name.
williamr@2
   570
         * This method should be used with care and is mainly intended for
williamr@2
   571
         * protected use in implementations.
williamr@2
   572
         * @param aNamespaceURI:    The new namespace URI.
williamr@2
   573
         * @param aLocalName:       The new local name.
williamr@2
   574
         * @param aQName:           The new qualified name.
williamr@2
   575
         */ 
williamr@2
   576
        IMPORT_C virtual void Set(const TDesC8& aNsUri,
williamr@2
   577
                                  const TDesC8& aLocalName,
williamr@2
   578
                                  const TDesC8& aQName);
williamr@2
   579
williamr@2
   580
        /**
williamr@2
   581
         *  Adds new attributes to the element.
williamr@2
   582
         *  @param  aAttrs: the array of attributes.
williamr@2
   583
         */ 
williamr@2
   584
        IMPORT_C virtual void AddAttributesL(const RAttributeArray& apAttrs);
williamr@2
   585
williamr@2
   586
        void Compress();
williamr@2
   587
        
williamr@2
   588
    protected:  // New functions
williamr@2
   589
    
williamr@2
   590
        /**
williamr@2
   591
        * C++ default constructor.
williamr@2
   592
        */
williamr@2
   593
        IMPORT_C CSenXmlElement();
williamr@2
   594
williamr@2
   595
        /**
williamr@2
   596
         *  Following BaseConstructL methods should be called from the deriving
williamr@2
   597
         *  classes ConstructL() methods. Parameter info is found in the
williamr@2
   598
         *  corresponding NewL-methods.
williamr@2
   599
         */
williamr@2
   600
        IMPORT_C void BaseConstructL(const TDesC8& aLocalName);
williamr@2
   601
williamr@2
   602
        IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
williamr@2
   603
                                     const TDesC8& aLocalName);
williamr@2
   604
        
williamr@2
   605
        IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
williamr@2
   606
                                     const TDesC8& aLocalName,
williamr@2
   607
                                     const TDesC8& aQName);
williamr@2
   608
williamr@2
   609
        IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
williamr@2
   610
                                     const TDesC8& aLocalName,
williamr@2
   611
                                     const TDesC8& aQName,
williamr@2
   612
                                     const RAttributeArray& apAttrs);
williamr@2
   613
williamr@2
   614
        IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
williamr@2
   615
                                     const TDesC8& aLocalName,
williamr@2
   616
                                     const TDesC8& aQName,
williamr@2
   617
                                     const RAttributeArray& apAttrs,
williamr@2
   618
                                     CSenElement& aParent);
williamr@2
   619
    
williamr@2
   620
        /**
williamr@2
   621
         *  Method for finding an attribute with given name.
williamr@2
   622
         *  @param aName    a name of the attribute to be searched for
williamr@2
   623
         *  @return the 1st attribute with the name, or NULL. 
williamr@2
   624
         *              Ownership is not transferred.
williamr@2
   625
         */
williamr@2
   626
        IMPORT_C virtual CSenBaseAttribute* FindAttr(const TDesC8& aName);
williamr@2
   627
williamr@2
   628
        /**
williamr@2
   629
         *  Method for finding index for a wanted element.
williamr@2
   630
         *  @param aNsUri       a namespace URI which needs to match
williamr@2
   631
         *  @param aLocalName   a local name which needs to match
williamr@2
   632
         *  @return Index of the element with given characteristics.
williamr@2
   633
         *          or KErrNotFound if none matching
williamr@2
   634
         */
williamr@2
   635
        IMPORT_C virtual TInt IndexOfElement(const TDesC8& aNsUri,
williamr@2
   636
                                             const TDesC8& aLocalName) const;
williamr@2
   637
        
williamr@2
   638
        /**
williamr@2
   639
         *  Writes element's attributes into a writestream.
williamr@2
   640
         *  @param aWriteStream writestream to write into
williamr@2
   641
         */
williamr@2
   642
        IMPORT_C virtual void WriteAttrsToL(RWriteStream& aWriteStream);
williamr@2
   643
williamr@2
   644
        /**
williamr@2
   645
         *  Helper function to write an attribute into a writestream.
williamr@2
   646
         *  @param aWriteStream writestream to write into
williamr@2
   647
         *  @param aName    attribute name
williamr@2
   648
         *  @param aValue   attribute value
williamr@2
   649
         */
williamr@2
   650
        IMPORT_C virtual void WriteAttrToL(RWriteStream& aWriteStream,
williamr@2
   651
                                           const TDesC8& aName,
williamr@2
   652
                                           const TDesC8& aValue);
williamr@2
   653
williamr@2
   654
        /**
williamr@2
   655
         *  Writes all internal elements into a writestream.
williamr@2
   656
         *  @param aWriteStream writestream to write into
williamr@2
   657
         */
williamr@2
   658
        IMPORT_C virtual void WriteElementsToL(RWriteStream& aWriteStream);
williamr@2
   659
williamr@2
   660
        /**
williamr@2
   661
         *  Writes all element's content into a writestream.
williamr@2
   662
         *  @param aWriteStream writestream to write into
williamr@2
   663
         */
williamr@2
   664
        IMPORT_C virtual void WriteContentToL(RWriteStream& aWriteStream);
williamr@2
   665
williamr@2
   666
        /**
williamr@2
   667
        *   Adds an attribute into this element. Used also adding new namespaces
williamr@2
   668
        *   into the element.
williamr@2
   669
        * @param aQName     Attribute's qualified name
williamr@2
   670
        * @param aLocalName Attribute's local name
williamr@2
   671
        * @param aValue     Attribute's value
williamr@2
   672
        * @return value of the attribute as string (TDesC&)
williamr@2
   673
        *   Leave codes:    
williamr@2
   674
        *       KErrSenInvalidCharacters if aLocalName or aQName contain illegal 
williamr@2
   675
        *       characters.     
williamr@2
   676
        *       KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
williamr@2
   677
        */
williamr@2
   678
        IMPORT_C virtual const TDesC8& AddAttributeL(const TDesC8& aQName,
williamr@2
   679
                                                     const TDesC8& aLocalName,
williamr@2
   680
                                                     const TDesC8& aValue);
williamr@2
   681
williamr@2
   682
        /**
williamr@2
   683
        *   Adds an attribute into this element. Used also adding new namespaces
williamr@2
   684
        *   into the element.
williamr@2
   685
        * @param aLocalName Attribute's local name
williamr@2
   686
        * @param aValue     Attribute's value
williamr@2
   687
        * @return value of the attribute as string (TDesC&)
williamr@2
   688
        *   Leave codes:    
williamr@2
   689
        *       KErrSenInvalidCharacters if aLocalName contains illegal characters.     
williamr@2
   690
        *       KErrSenZeroLengthDescriptor if aAttrName is zero length, or
williamr@2
   691
        *       if the local name part of it is zero length.
williamr@2
   692
        */
williamr@2
   693
        IMPORT_C virtual const TDesC8& AddAttributeL(const TDesC8& aAttrName,
williamr@2
   694
                                                     const TDesC8& aValue);
williamr@2
   695
williamr@2
   696
        /** 
williamr@2
   697
        * Adds an attribute into this element.
williamr@2
   698
        * @param apAttribute    Attribute to be added. Ownership is transferred
williamr@2
   699
        *                       to this element.
williamr@2
   700
        * @return attribute value as a string (TDesC8&)
williamr@2
   701
        */
williamr@2
   702
        IMPORT_C const TDesC8& AddAttributeL(CSenBaseAttribute* apAttribute);
williamr@2
   703
williamr@2
   704
        /**
williamr@2
   705
         *  Allocates a new buffer for saving content, if none allocated yet.
williamr@2
   706
         */
williamr@2
   707
        IMPORT_C virtual void AllocContentBufL();
williamr@2
   708
        
williamr@2
   709
        /**
williamr@2
   710
         *  Writes element into a dynamic buffer.
williamr@2
   711
         *  @param aBuf a dynamic buffer where to append everything.
williamr@2
   712
         *  @return the modified buffer as TPtrC8.
williamr@2
   713
         */
williamr@2
   714
        IMPORT_C virtual TPtrC8 WriteToBufL(CBufBase& aBuf);
williamr@2
   715
williamr@2
   716
    private:
williamr@2
   717
        void AddNamespaceMissingFromL(RPointerArray<CSenNamespace>& aNamespaces);
williamr@2
   718
williamr@2
   719
    private:    // Data
williamr@2
   720
         
williamr@2
   721
        HBufC8* ipLocalName;                            // Owned
williamr@2
   722
williamr@2
   723
        CBufFlat* ipContentBuf;                         // Owned
williamr@2
   724
williamr@2
   725
        RBufWriteStream* ipContentWriteStream;          // Owned
williamr@2
   726
williamr@2
   727
        RPointerArray<CSenBaseAttribute>* ipAttrs;      // Elements owned
williamr@2
   728
williamr@2
   729
        RPointerArray<CSenElement>* ipElements;         // Elements owned
williamr@2
   730
williamr@2
   731
        RPointerArray<CSenNamespace>* ipNamespaces;     // Elements owned
williamr@2
   732
williamr@2
   733
        CSenElement*    ipParent;                       // Not owned
williamr@2
   734
williamr@2
   735
        CSenNamespace*  ipNamespace;                    // Not Owned (deleted in upper level array)
williamr@2
   736
        
williamr@2
   737
    };
williamr@2
   738
williamr@2
   739
#endif // SEN_XML_ELEMENT_H
williamr@2
   740
williamr@2
   741
// End of File
williamr@2
   742