williamr@2: /* williamr@2: * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@4: * under the terms of "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: The abstract interface of an XML element williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef M_SEN_ELEMENT_H williamr@2: #define M_SEN_ELEMENT_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@4: #include williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: class CSenElement; williamr@2: class CSenBaseAttribute; williamr@2: class CSenNamespace; williamr@2: williamr@2: using namespace Xml; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * The abstract interface of an XML element williamr@2: * @lib SenXML.dll williamr@2: * @since Series60 3.0 williamr@2: */ williamr@2: class MSenElement williamr@2: { williamr@2: public: // New functions williamr@2: williamr@2: /** williamr@2: * Getter for Element's local name. williamr@2: * @return KNullDesC if not set williamr@2: */ williamr@2: virtual const TDesC8& LocalName() const = 0; williamr@2: williamr@2: /** williamr@2: * Getter for Element's namespace URI. williamr@2: * @return Namespace URI or KNullDesC if not set. williamr@2: */ williamr@2: virtual const TDesC8& NamespaceURI() const = 0; williamr@2: williamr@2: /** williamr@2: * Setter for Element's namespace URI. williamr@2: * @param aNsUri: Namespace URI williamr@2: */ williamr@2: virtual void SetNamespaceL(const TDesC8& aNsUri) = 0; williamr@2: williamr@2: /** williamr@2: * Setter for Element's namespace URI. williamr@2: * @param aNsPrefix: Namespace prefix williamr@2: * @param aNsUri: Namespace URI williamr@2: */ williamr@2: virtual void SetNamespaceL( const TDesC8& aNsPrefix, williamr@2: const TDesC8& aNsUri) = 0; williamr@2: williamr@2: /** williamr@2: * Method for adding a namespace for the Element. williamr@2: * @param aNsPrefix: Namespace prefix williamr@2: * @param aNsUri: Namespace URI williamr@2: * @return the added Namespace, or the equivalent pre-existing one. williamr@2: */ williamr@2: virtual const CSenNamespace* AddNamespaceL( const TDesC8& aPrefix, williamr@2: const TDesC8& aUri) = 0; williamr@2: williamr@2: /** williamr@2: * Adds a namespace declaration. williamr@2: * If this element (or its parent if parameter aCheckInParent is ETrue) williamr@2: * already has a Namespace with the same prefix and URI the given williamr@2: * Namespace is not added. williamr@2: * @param aNewNamespace williamr@2: * @param aCheckInParent williamr@2: * @return the added Namespace, or the equivalent pre-existing one. williamr@2: */ williamr@2: virtual const CSenNamespace* AddNamespaceL( CSenNamespace& aNewNamespace, williamr@2: TBool aCheckInParent) = 0; williamr@2: /** williamr@2: * Getter for Element's namespace. williamr@2: * @return const pointer to the CSenNamespace object of this Element. williamr@2: * NULL if not set. williamr@2: */ williamr@2: virtual const CSenNamespace* Namespace() = 0; williamr@2: williamr@2: /** williamr@2: * Get namespace that is declared for the given prefix williamr@2: * @param aNsPrefix: The prefix to be used in searching. williamr@2: * @return the found Namespace that is declared for the given prefix williamr@2: * within the scope of this Element or NULL if not found. williamr@2: */ williamr@2: virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix) = 0; williamr@2: williamr@2: /** williamr@2: * Get namespace that is declared for the given prefix and namespace williamr@2: * URI within the scope of this Element. williamr@2: * williamr@2: * @param aNsPrefix: The prefix used to search williamr@2: * @param aUri: The namespace URI used to search. williamr@2: * @return the found Namespace that is declared for the given prefix and namespace williamr@2: * URI within the scope of this Element or NULL if not found. williamr@2: */ williamr@2: virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix, williamr@2: const TDesC8& aUri) = 0; williamr@2: williamr@2: /** williamr@2: * Get namespace that is declared for the given prefix and namespace williamr@2: * URI within the scope of this Element. williamr@2: * williamr@2: * @param aNsPrefix: The prefix used to search williamr@2: * @param aCheckInParent: The flag indicating whether to check parent's williamr@2: * namespaces too if not found in the current williamr@2: * element. williamr@2: * ETrue to check, EFalse for not to check. williamr@2: * @return the found Namespace that is declared for the given prefix and namespace williamr@2: * URI within the scope of this Element or NULL if not found williamr@2: */ williamr@2: virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix, williamr@2: const TBool aCheckInParent) = 0; williamr@2: williamr@2: /** williamr@2: * Getter for namespace prefix of this element. williamr@2: * @return namespace prefix or KNullDesC8 if not set. williamr@2: */ williamr@2: virtual const TDesC8& NsPrefix() const = 0; williamr@2: williamr@2: /** williamr@2: * Setter for namespace prefix of this element. williamr@2: * @param aPrefix: new namespace prefix for the element. williamr@2: */ williamr@2: virtual void SetPrefixL(const TDesC8& aPrefix) = 0; williamr@2: williamr@2: /** williamr@2: * Method for checking if the element has any content within. williamr@2: * @return ETrue if has content, EFalse if not. williamr@2: */ williamr@2: virtual TBool HasContent() const = 0; williamr@2: williamr@2: /** williamr@2: * Getter for the content of the element. williamr@2: * @return the content or KNullDesC8 if empty. williamr@2: */ williamr@2: virtual TPtrC8 Content() const = 0; williamr@2: williamr@2: /** williamr@2: * Getter for the content of the element, unicode version. williamr@2: * @return content as unicode. Ownership IS TRANSFERRED to the caller. williamr@2: */ williamr@2: virtual HBufC* ContentUnicodeL() const = 0; williamr@2: williamr@2: /** williamr@2: * Sets the content to the element. Old content is overwritten. williamr@2: * @param aContent: The content to be set. Can be KNullDesC8. williamr@2: * @return The content of the element or KNullDesC8 if no content was set. williamr@2: */ williamr@2: virtual TPtrC8 SetContentL(const TDesC8& aContent) = 0; williamr@2: williamr@2: /** williamr@2: * Gets the write stream for the content for easy appending. williamr@2: * Writing 8-bit (UTF-8) string to the returned stream will be appended williamr@2: * to the content. williamr@2: * @return reference to the RWriteStream. williamr@2: */ williamr@2: virtual RWriteStream& ContentWriteStreamL() = 0; williamr@2: williamr@2: /** williamr@2: * Checks if element matches to another element by its content and williamr@2: * child elements. Element can contain more data than the given williamr@2: * pattern. williamr@2: * @since Series60 3.0 williamr@2: * @param aCandidate The pattern to be matched. Must contain same or williamr@2: * less data for match to come true. williamr@2: * @return ETrue if content and possible children match exactly williamr@2: * to given pattern. EFalse otherwise. williamr@2: */ williamr@2: virtual TBool ConsistsOfL(MSenElement& aCandidate) = 0; williamr@2: williamr@2: /** williamr@2: * Getting the child elements of this element. williamr@2: * @return an array of child elements. This is an empty array if there williamr@2: * are no children. Any modifications made on the returned array williamr@2: * modify the element object. williamr@2: */ williamr@2: virtual RPointerArray& ElementsL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets a child element from a specified index. williamr@2: * @param aIndex: the index what to get williamr@2: * @return child element from a current index. NULL if no child in given williamr@2: * index is found williamr@2: */ williamr@2: virtual CSenElement* Child(TInt aIndex) = 0; williamr@2: williamr@2: /** williamr@2: * Gets the value of the given attribute. williamr@2: * @param aName: Name of the attribute in question. williamr@2: * @return the value of the attribute, or NULL if not found. Ownership is williamr@2: * NOT TRANSFERRED. williamr@2: */ williamr@2: virtual const TDesC8* AttrValue(const TDesC8& aName) = 0; williamr@2: williamr@2: /** williamr@2: * Adds an attribute. If attribute is already existing, williamr@2: * the value of the attribute will be replaced. williamr@2: * @param aName Name of the attribute to be added. williamr@2: * @param aValue Value of the attribute to be added. williamr@2: */ williamr@2: virtual void AddAttrL(const TDesC8& aName, const TDesC8& aValue) = 0; williamr@2: williamr@2: /** williamr@2: * Gets all the attributes of this element in an array. williamr@2: * @return array of attributes. Array will be empty if element has williamr@2: * no attributes. williamr@2: */ williamr@2: virtual RPointerArray& AttributesL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets all the namespaces of this element in an array. williamr@2: * @return array of namespaces. Array will be empty if element has williamr@2: * no namespaces. williamr@2: */ williamr@2: virtual RPointerArray& NamespacesL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets the parent element of this element. williamr@2: * @return the parent element or NULL if no parent set. williamr@2: * Ownership is NOT transferred to the caller. williamr@2: */ williamr@2: virtual CSenElement* Parent() = 0; williamr@2: williamr@2: /** williamr@2: * Sets the parent element to this element. Notice that the element is not williamr@2: * automatically added as a child of the parent. Parent's williamr@2: * AddElementL() should be called instead. williamr@2: * @param apParent: The wanted parent. Can be NULL. williamr@2: * @return the parent element williamr@2: */ williamr@2: virtual CSenElement* SetParent(CSenElement* apParent) = 0; williamr@2: williamr@2: /** williamr@2: * Detach the element from its parent. williamr@2: * If the element, or one of its children, is dependent williamr@2: * on a namespace declared in the scope of the parent williamr@2: * copy those namespace declarations to this element. williamr@2: * @return this Element. Ownership is NOT transferred to the caller. williamr@2: * Returns NULL if no parent was set, and nothing was detached. williamr@2: */ williamr@2: virtual CSenElement* DetachL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets the root element. If no parent element, returns this element. williamr@2: * @return the root of the tree. Ownership is not transferred. williamr@2: */ williamr@2: virtual MSenElement& Root() = 0; williamr@2: williamr@2: /** williamr@2: * Gets the child element with the specified local name. williamr@2: * Assumes that namespace is the same as this parent element. williamr@2: * @return the child element or NULL if the child with the specified williamr@2: * local name is not found. Ownership is NOT transferred. williamr@2: */ williamr@2: virtual CSenElement* Element(const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Gets the child element with the specified local name and namespace URI. williamr@2: * @return the child element or NULL if the child with the specified williamr@2: * criterias is not found. Ownership is NOT transferred. williamr@2: */ williamr@2: virtual CSenElement* Element(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Create a new element ready for adding or insertion. williamr@2: * If the given namespace prefix is not declared yet williamr@2: * the element will not be created and NULL will be returned. williamr@2: * @param aNsPrefix: The namespace prefix williamr@2: * @param aLocalName: The new elements localname williamr@2: * @return the new Element just created, or NULL if given prefix was not williamr@2: * declared yet. Ownership is transferred to the caller. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contain illegal williamr@2: * characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: virtual CSenElement* CreateElementL(const TDesC8& aNsPrefix, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Insert an Element into the list of children elements williamr@2: * so that the inserted Element is placed right before the aBeforeElement. williamr@2: * If aBeforeElement is not found, element will be appended to the last williamr@2: * position. williamr@2: * Function leaves if error occurs in inserting. williamr@2: * @param aInsertedElement: the element to be inserted. williamr@2: * Ownership is transferred. williamr@2: * @param aBeforeElement: the element which will be right next to the williamr@2: * element just inserted. williamr@2: * @return the inserted Element williamr@2: */ williamr@2: virtual CSenElement& InsertElementL(CSenElement& aInsertedElement, williamr@2: const CSenElement& aBeforeElement) = 0; williamr@2: williamr@2: /** williamr@2: * Adds an Element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aElement: the element to be added. Ownership is transferred. williamr@2: * @return the added Element williamr@2: */ williamr@2: virtual CSenElement& AddElementL(CSenElement& aElement) = 0; williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aNsUri: namespace URI of the new element williamr@2: * @param aLocalName: local name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: virtual CSenElement& AddElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aNsUri: namespace URI of the new element williamr@2: * @param aLocalName: local name of the new element williamr@2: * @param aQName: qualified name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contain illegal williamr@2: * characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: virtual CSenElement& AddElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName) = 0; williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * Note: Element is created with no specific namespace, default namespace williamr@2: * of some of the upper level elements are in effect if there is such a williamr@2: * namespace. williamr@2: * @param aLocalName: local name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: virtual CSenElement& AddElementL(const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aElement: the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: virtual CSenElement* RemoveElement(CSenElement& aElement) = 0; williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aNsUri: the namespace URI of the element to be removed. williamr@2: * @param aLocalName: the local name of the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: virtual CSenElement* RemoveElement( const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aLocalName: the local name of the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: virtual CSenElement* RemoveElement(const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Replaces an element from the childs with another element. williamr@2: * Element's local name and namespace URI will be used to match the williamr@2: * element to be replaced. If matching element is not found, will williamr@2: * normally add the given element to the childs. williamr@2: * williamr@2: * @param aElement: the element to be added. Ownership is transferred. williamr@2: * @return The old element. May be NULL if nothing was replaced williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the old element. williamr@2: */ williamr@2: virtual CSenElement* ReplaceElementL(CSenElement& aElement) = 0; williamr@2: williamr@2: /** williamr@2: * Gets element as an UTF-8 form XML. williamr@2: * @return element as XML (in UTF-8 format). Caller takes ownership. williamr@2: */ williamr@2: virtual HBufC8* AsXmlL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets the element as XML fragment in Unicode UCS2 format. williamr@2: * @since Series60 3.0 williamr@2: * @return the service description as XML, which ownership is williamr@2: * transferred to the caller. williamr@2: */ williamr@2: virtual HBufC* AsXmlUnicodeL() = 0; williamr@2: williamr@2: /** williamr@2: * Writes this element as XML, in UTF-8 form to a stream williamr@2: * @since Series60 3.0 williamr@2: * @param aWriteStream to write into. williamr@2: */ williamr@2: virtual void WriteAsXMLToL(RWriteStream& aWriteStream) = 0; williamr@2: williamr@2: /** williamr@2: * Element writes its namespaces to a write stream using UTF-8 charset williamr@2: * encoding. williamr@2: * williamr@2: * @param aWriteStream: The stream to write to. williamr@2: */ williamr@2: virtual void WriteNamespacesToL(RWriteStream& aWriteStream) = 0; williamr@2: williamr@2: /** williamr@2: * Gets the current element as XML element. Mostly used to get the williamr@2: * classes which implement this interface as an instance of this williamr@2: * interface. williamr@2: * @return the current object as element. Ownership is NOT transferred. williamr@2: */ williamr@2: virtual MSenElement* AsElement() = 0; williamr@2: williamr@2: /** williamr@2: * Copies content from given element to this element appending to the williamr@2: * existing content if there is any. williamr@2: * @param aSource: The source element. williamr@2: */ williamr@2: virtual void CopyFromL(CSenElement& aSource) = 0; williamr@2: williamr@2: /** williamr@2: * (Re-) Set the name and namespace of this Element. The element will be williamr@2: * given the localName in the the given namespace. A prefix will be williamr@2: * computed from the qualified name. williamr@2: * williamr@2: * This method should be used with care and is mainly intended for williamr@2: * protected use in implementations. williamr@2: * williamr@2: * @param aNamespaceURI: The new namespace URI. williamr@2: * @param aLocalName: The new local name. williamr@2: * @param aQName: The new qualified name. williamr@2: */ williamr@2: virtual void Set(const TDesC8& aNamespaceURI, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName) = 0; williamr@2: williamr@2: /** williamr@2: * Adds new attributes to the element. williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: virtual void AddAttributesL(const RAttributeArray& aAttrs) = 0; williamr@2: williamr@2: }; williamr@2: williamr@2: #endif // M_SEN_ELEMENT_H williamr@2: williamr@2: // End of File williamr@2: williamr@2: