epoc32/include/mw/msenelement.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
     1 /*
     2 * Copyright (c) 2002-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:        The abstract interface of an XML element
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 
    22 
    23 
    24 
    25 #ifndef M_SEN_ELEMENT_H
    26 #define M_SEN_ELEMENT_H
    27 
    28 //  INCLUDES
    29 #include <e32base.h>
    30 #include <s32strm.h>
    31 #include <xml/Attribute.h>
    32 
    33 // FORWARD DECLARATIONS
    34 class CSenElement;
    35 class CSenBaseAttribute;
    36 class CSenNamespace;
    37 
    38 using namespace Xml;
    39 
    40 // CLASS DECLARATION
    41 
    42 /**
    43 *  The abstract interface of an XML element
    44 *  @lib SenXML.dll
    45 *  @since Series60 3.0
    46 */
    47 class MSenElement
    48     {
    49     public: // New functions
    50 
    51         /**
    52         *   Getter for Element's local name.
    53         *  @return KNullDesC if not set
    54         */
    55         virtual const TDesC8& LocalName() const = 0;
    56 
    57         /**
    58         *   Getter for Element's namespace URI.
    59         *   @return Namespace URI or KNullDesC if not set.
    60         */
    61         virtual const TDesC8& NamespaceURI() const = 0;
    62 
    63         /**
    64         *   Setter for Element's namespace URI.
    65         *   @param aNsUri:  Namespace URI
    66         */
    67         virtual void SetNamespaceL(const TDesC8& aNsUri) = 0;
    68 
    69         /**
    70         *   Setter for Element's namespace URI.
    71         *   @param aNsPrefix:   Namespace prefix
    72         *   @param aNsUri:      Namespace URI
    73         */
    74         virtual void SetNamespaceL( const TDesC8& aNsPrefix,
    75                                     const TDesC8& aNsUri) = 0;
    76 
    77         /**
    78         *   Method for adding a namespace for the Element.
    79         *   @param aNsPrefix:   Namespace prefix
    80         *   @param aNsUri:      Namespace URI
    81         *   @return the added Namespace, or the equivalent pre-existing one.
    82         */
    83         virtual const CSenNamespace* AddNamespaceL( const TDesC8& aPrefix,
    84                                                     const TDesC8& aUri) = 0;
    85 
    86         /**
    87          * Adds a namespace declaration.
    88          * If this element (or its parent if parameter aCheckInParent is ETrue) 
    89          * already has a Namespace with the same prefix and URI the given
    90          * Namespace is not added.
    91          * @param aNewNamespace
    92          * @param aCheckInParent
    93          * @return the added Namespace, or the equivalent pre-existing one.
    94          */
    95         virtual const CSenNamespace* AddNamespaceL( CSenNamespace& aNewNamespace,
    96                                                     TBool aCheckInParent) = 0;
    97         /**
    98         *   Getter for Element's namespace.
    99         *   @return const pointer to the CSenNamespace object of this Element.
   100         *           NULL if not set.
   101         */
   102         virtual const CSenNamespace* Namespace() = 0;
   103 
   104         /**
   105          * Get namespace that is declared for the given prefix
   106          * @param aNsPrefix:    The prefix to be used in searching.
   107         * @return the found Namespace that is declared for the given prefix
   108         * within the scope of this Element or NULL if not found.
   109          */
   110         virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix) = 0;
   111 
   112         /**
   113          * Get namespace that is declared for the given prefix and namespace
   114          * URI within the scope of this Element. 
   115          *
   116          * @param aNsPrefix:    The prefix used to search
   117          * @param aUri:         The namespace URI used to search.
   118         * @return the found Namespace that is declared for the given prefix and namespace
   119         * URI within the scope of this Element or NULL if not found.
   120          */
   121         virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix,
   122                                                 const TDesC8& aUri) = 0;
   123 
   124         /**
   125          * Get namespace that is declared for the given prefix and namespace
   126          * URI within the scope of this Element. 
   127          *
   128          * @param aNsPrefix:        The prefix used to search
   129          * @param aCheckInParent:   The flag indicating whether to check parent's
   130          *                          namespaces too if not found in the current 
   131          *                          element. 
   132          *                          ETrue to check, EFalse for not to check.
   133         * @return the found Namespace that is declared for the given prefix and namespace
   134         * URI within the scope of this Element or NULL if not found
   135          */
   136         virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix,
   137                                                 const TBool aCheckInParent) = 0;
   138 
   139         /**
   140          *  Getter for namespace prefix of this element.
   141          *  @return namespace prefix or KNullDesC8 if not set.
   142          */
   143         virtual const TDesC8& NsPrefix() const = 0;
   144 
   145         /**
   146          *  Setter for namespace prefix of this element.
   147          *  @param aPrefix: new namespace prefix for the element.
   148          */
   149         virtual void SetPrefixL(const TDesC8& aPrefix) = 0;
   150         
   151         /**
   152          *  Method for checking if the element has any content within.
   153          *  @return ETrue if has content, EFalse if not.
   154          */
   155         virtual TBool HasContent() const = 0;
   156 
   157         /**
   158          *  Getter for the content of the element.
   159          *  @return the content or KNullDesC8 if empty.
   160          */
   161         virtual TPtrC8 Content() const = 0;
   162 
   163         /**
   164          *  Getter for the content of the element, unicode version.
   165          *  @return content as unicode. Ownership IS TRANSFERRED to the caller.
   166          */
   167         virtual HBufC* ContentUnicodeL() const = 0;
   168 
   169         /**
   170          *  Sets the content to the element. Old content is overwritten.
   171          *  @param  aContent:   The content to be set. Can be KNullDesC8.
   172          *  @return The content of the element or KNullDesC8 if no content was set.
   173          */
   174         virtual TPtrC8 SetContentL(const TDesC8& aContent) = 0;
   175 
   176         /**
   177          *  Gets the write stream for the content for easy appending.
   178          *  Writing 8-bit (UTF-8) string to the returned stream will be appended
   179          *  to the content.
   180          *  @return reference to the RWriteStream.
   181          */
   182         virtual RWriteStream& ContentWriteStreamL() = 0;
   183 
   184         /**
   185          * Checks if element matches to another element by its content and 
   186          * child elements. Element can contain more data than the given 
   187          * pattern.
   188          * @since Series60 3.0
   189          * @param aCandidate    The pattern to be matched. Must contain same or 
   190          *                      less data for match to come true.
   191          * @return ETrue if content and possible children match exactly 
   192          *          to given pattern. EFalse otherwise.
   193          */
   194         virtual TBool ConsistsOfL(MSenElement& aCandidate) = 0;
   195         
   196         /**
   197          *  Getting the child elements of this element.
   198          *  @return an array of child elements. This is an empty array if there
   199          *          are no children. Any modifications made on the returned array
   200          *          modify the element object.
   201          */
   202         virtual RPointerArray<CSenElement>& ElementsL() = 0;
   203 
   204         /**
   205          *  Gets a child element from a specified index.
   206          *  @param  aIndex: the index what to get
   207          *  @return child element from a current index. NULL if no child in given
   208          *          index is found
   209          */
   210         virtual CSenElement* Child(TInt aIndex) = 0;
   211 
   212         /**
   213          *  Gets the value of the given attribute.
   214          *  @param aName:   Name of the attribute in question.
   215          *  @return the value of the attribute, or NULL if not found. Ownership is
   216          *          NOT TRANSFERRED.
   217          */
   218         virtual const TDesC8* AttrValue(const TDesC8& aName) = 0;
   219 
   220         /**
   221          *  Adds an attribute. If attribute is already existing, 
   222          *  the value of the attribute will be replaced.
   223          * @param aName     Name of the attribute to be added.
   224          * @param aValue    Value of the attribute to be added.
   225          */
   226         virtual void AddAttrL(const TDesC8& aName, const TDesC8& aValue) = 0;
   227 
   228         /**
   229          *  Gets all the attributes of this element in an array.
   230          *  @return array of attributes. Array will be empty if element has 
   231          *          no attributes.
   232          */
   233         virtual RPointerArray<CSenBaseAttribute>& AttributesL() = 0;
   234 
   235         /**
   236          *  Gets all the namespaces of this element in an array.
   237          *  @return array of namespaces. Array will be empty if element has 
   238          *          no namespaces.
   239          */
   240         virtual RPointerArray<CSenNamespace>& NamespacesL() = 0;
   241 
   242         /**
   243          *  Gets the parent element of this element.
   244          *  @return the parent element or NULL if no parent set. 
   245          *          Ownership is NOT transferred to the caller.
   246          */
   247         virtual CSenElement* Parent() = 0;
   248 
   249         /**
   250          *  Sets the parent element to this element. Notice that the element is not
   251          *  automatically added as a child of the parent. Parent's 
   252          *  AddElementL() should be called instead.
   253          *  @param apParent:    The wanted parent. Can be NULL.
   254          *  @return the parent element
   255          */
   256         virtual CSenElement* SetParent(CSenElement* apParent) = 0;
   257 
   258         /**
   259          * Detach the element from its parent.
   260          * If the element, or one of its children, is dependent
   261          * on a namespace declared in the scope of the parent
   262          * copy those namespace declarations to this element.
   263          * @return this Element. Ownership is NOT transferred to the caller.
   264          *          Returns NULL if no parent was set, and nothing was detached.
   265          */
   266         virtual CSenElement* DetachL() = 0;
   267 
   268         /**
   269          *  Gets the root element. If no parent element, returns this element.
   270          *  @return the root of the tree. Ownership is not transferred.
   271          */
   272         virtual MSenElement& Root() = 0;
   273 
   274         /**
   275          *  Gets the child element with the specified local name.
   276          *  Assumes that namespace is the same as this parent element.
   277          *  @return the child element or NULL if the child with the specified 
   278          *          local name is not found. Ownership is NOT transferred.
   279          */
   280         virtual CSenElement* Element(const TDesC8& aLocalName) = 0;
   281 
   282         /**
   283          *  Gets the child element with the specified local name and namespace URI.
   284          *  @return the child element or NULL if the child with the specified 
   285          *          criterias is not found. Ownership is NOT transferred.
   286          */
   287         virtual CSenElement* Element(const TDesC8& aNsUri,
   288                                      const TDesC8& aLocalName) = 0;
   289 
   290         /**
   291          * Create a new element ready for adding or insertion.
   292          * If the given namespace prefix is not declared yet
   293          * the element will not be created and NULL will be returned.
   294          * @param aNsPrefix:    The namespace prefix
   295          * @param aLocalName:   The new elements localname
   296          * @return  the new Element just created, or NULL if given prefix was not
   297          *          declared yet. Ownership is transferred to the caller.
   298          * Leave codes: 
   299          *      KErrSenInvalidCharacters if aLocalName or aQName contain illegal 
   300          *      characters.     
   301          *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
   302          */
   303         virtual CSenElement* CreateElementL(const TDesC8& aNsPrefix,
   304                                             const TDesC8& aLocalName) = 0;
   305 
   306         /**
   307          * Insert an Element into the list of children elements
   308          * so that the inserted Element is placed right before the aBeforeElement.
   309          * If aBeforeElement is not found, element will be appended to the last
   310          * position.
   311          * Function leaves if error occurs in inserting.
   312          * @param aInsertedElement: the element to be inserted. 
   313          *                          Ownership is transferred.
   314          * @param aBeforeElement:   the element which will be right next to the 
   315          *                          element just inserted.
   316          * @return the inserted Element
   317          */
   318         virtual CSenElement& InsertElementL(CSenElement& aInsertedElement,
   319                                             const CSenElement& aBeforeElement) = 0;
   320 
   321         /**
   322          * Adds an Element to the children elements. 
   323          * Sets this element to be the new parent of the given element.
   324          * @param aElement: the element to be added. Ownership is transferred.
   325          * @return the added Element
   326          */
   327         virtual CSenElement& AddElementL(CSenElement& aElement) = 0;
   328 
   329         /**
   330          * Constructs and adds a new element to the children elements. 
   331          * Sets this element to be the new parent of the given element.
   332          * @param aNsUri:       namespace URI of the new element
   333          * @param aLocalName:   local name of the new element
   334          * @return the added Element
   335          * Leave codes: 
   336          *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
   337          *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
   338          */
   339         virtual CSenElement& AddElementL(const TDesC8& aNsUri,
   340                                          const TDesC8& aLocalName) = 0;
   341 
   342         /**
   343          * Constructs and adds a new element to the children elements. 
   344          * Sets this element to be the new parent of the given element.
   345          * @param aNsUri:       namespace URI of the new element
   346          * @param aLocalName:   local name of the new element
   347          * @param aQName:       qualified name of the new element
   348          * @return the added Element
   349          * Leave codes: 
   350          *      KErrSenInvalidCharacters if aLocalName or aQName contain illegal 
   351          *      characters.     
   352          *      KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
   353          */
   354         virtual CSenElement& AddElementL(const TDesC8& aNsUri,
   355                                          const TDesC8& aLocalName,
   356                                          const TDesC8& aQName) = 0;
   357 
   358         /**
   359          * Constructs and adds a new element to the children elements. 
   360          * Sets this element to be the new parent of the given element.
   361          * Note: Element is created with no specific namespace, default namespace
   362          * of some of the upper level elements are in effect if there is such a 
   363          * namespace.
   364          * @param aLocalName:   local name of the new element
   365          * @return the added Element
   366          * Leave codes: 
   367          *      KErrSenInvalidCharacters if aLocalName contains illegal characters.     
   368          *      KErrSenZeroLengthDescriptor if aLocalName is zero length.
   369          */
   370         virtual CSenElement& AddElementL(const TDesC8& aLocalName) = 0;
   371 
   372         /**
   373          *  Remove an element from the childs.
   374          *  @param  aElement:   the element to be removed.
   375          *  @return The removed element. May be NULL if nothing was removed
   376          *          (if element was not found from the childs).
   377          *          The caller TAKES OWNERSHIP of the removed element.
   378          */
   379         virtual CSenElement* RemoveElement(CSenElement& aElement) = 0;
   380 
   381         /**
   382          *  Remove an element from the childs.
   383          *  @param  aNsUri:     the namespace URI of the element to be removed.
   384          *  @param  aLocalName: the local name of the element to be removed.
   385          *  @return The removed element. May be NULL if nothing was removed
   386          *          (if element was not found from the childs).
   387          *          The caller TAKES OWNERSHIP of the removed element.
   388          */
   389         virtual CSenElement* RemoveElement( const TDesC8& aNsUri,
   390                                             const TDesC8& aLocalName) = 0;
   391 
   392         /**
   393          *  Remove an element from the childs.
   394          *  @param  aLocalName: the local name of the element to be removed.
   395          *  @return The removed element. May be NULL if nothing was removed
   396          *          (if element was not found from the childs).
   397          *          The caller TAKES OWNERSHIP of the removed element.
   398          */
   399         virtual CSenElement* RemoveElement(const TDesC8& aLocalName) = 0;
   400 
   401         /**
   402          *  Replaces an element from the childs with another element. 
   403          *  Element's local name and namespace URI will be used to match the
   404          *  element to be replaced. If matching element is not found, will
   405          *  normally add the given element to the childs.
   406          *  
   407          *  @param  aElement:   the element to be added. Ownership is transferred.
   408          *  @return The old element. May be NULL if nothing was replaced
   409          *          (if element was not found from the childs).
   410          *          The caller TAKES OWNERSHIP of the old element.
   411          */
   412         virtual CSenElement* ReplaceElementL(CSenElement& aElement) = 0;
   413 
   414         /**
   415          *  Gets element as an UTF-8 form XML.
   416          *  @return element as XML (in UTF-8 format). Caller takes ownership.
   417          */
   418         virtual HBufC8* AsXmlL() = 0;
   419 
   420         /**
   421         * Gets the element as XML fragment in Unicode UCS2 format.
   422         * @since Series60 3.0
   423         * @return the service description as XML, which ownership is
   424         *         transferred to the caller.
   425         */
   426         virtual HBufC* AsXmlUnicodeL() = 0;
   427 
   428         /**
   429         * Writes this element as XML, in UTF-8 form to a stream
   430         * @since Series60 3.0
   431         * @param aWriteStream   to write into.
   432         */
   433         virtual void WriteAsXMLToL(RWriteStream& aWriteStream) = 0;
   434 
   435         /**
   436          *  Element writes its namespaces to a write stream using UTF-8 charset 
   437          *  encoding.
   438          *
   439          *  @param aWriteStream:    The stream to write to.
   440          */
   441         virtual void WriteNamespacesToL(RWriteStream& aWriteStream) = 0;
   442 
   443         /**
   444          *  Gets the current element as XML element. Mostly used to get the
   445          *  classes which implement this interface as an instance of this 
   446          *  interface.
   447          *  @return the current object as element. Ownership is NOT transferred.
   448          */
   449         virtual MSenElement* AsElement() = 0;
   450 
   451         /**
   452          *  Copies content from given element to this element appending to the 
   453          *  existing content if there is any.
   454          *  @param aSource: The source element.
   455          */
   456         virtual void CopyFromL(CSenElement& aSource) = 0;
   457 
   458         /**
   459          * (Re-) Set the name and namespace of this Element. The element will be
   460          * given the localName in the the given namespace. A prefix will be
   461          * computed from the qualified name.
   462          *
   463          * This method should be used with care and is mainly intended for
   464          * protected use in implementations.
   465          *
   466          * @param aNamespaceURI:    The new namespace URI.
   467          * @param aLocalName:       The new local name.
   468          * @param aQName:           The new qualified name.
   469          */
   470         virtual void Set(const TDesC8& aNamespaceURI,
   471                          const TDesC8& aLocalName,
   472                          const TDesC8& aQName) = 0;
   473 
   474         /**
   475          *  Adds new attributes to the element.
   476          *  @param  aAttrs: the array of attributes.
   477          */
   478         virtual void AddAttributesL(const RAttributeArray& aAttrs) = 0;
   479 
   480 };
   481 
   482 #endif // M_SEN_ELEMENT_H
   483 
   484 // End of File
   485 
   486