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: Central place for debug-type macros williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef SEN_ELEMENT_H williamr@2: #define SEN_ELEMENT_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@4: #include williamr@2: #include williamr@2: williamr@2: #include williamr@2: williamr@2: using namespace Xml; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * Abstract class definition of XML element williamr@2: * @lib SenXML.dll williamr@2: * @since Series60 3.0 williamr@2: */ williamr@2: class CSenElement : public CBase, public MSenElement williamr@2: { williamr@2: public: // Functions from base classes williamr@2: williamr@2: // From MSenElement williamr@2: williamr@2: /** williamr@2: * Getter for local name. williamr@2: * @since Series60 3.0 williamr@2: * @return KNullDesC if not set (argumentless constructor). williamr@2: */ williamr@2: virtual const TDesC8& LocalName() const = 0; williamr@2: williamr@2: /** williamr@2: * Getter for namespace URI. williamr@2: * @since Series60 3.0 williamr@2: * @return 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: * @since Series60 3.0 williamr@2: * @param @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: * @since Series60 3.0 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: * @since Series60 3.0 williamr@2: * @param aPrefix: Namespace prefix williamr@2: * @param aUri: 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: * Getter for Element's namespace. williamr@2: * @since Series60 3.0 williamr@2: * @return const pointer to the CSenNamespace object of this Element. williamr@2: * Returns NULL, if not set. williamr@2: */ williamr@2: virtual const CSenNamespace* Namespace() = 0; williamr@2: williamr@2: /** williamr@2: * @since Series60 3.0 williamr@2: * @param prefix williamr@2: * @return the namespace that is declared for the given prefix williamr@2: * within the scope of this Element. If no such prefix is williamr@2: * declared return NULL. 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: * @since Series60 3.0 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 williamr@2: * and namespace URI within the scope of this Element williamr@2: * 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: * @since Series60 3.0 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 williamr@2: * and namespace URI within the scope of this Element williamr@2: * 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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 (UCS2) version williamr@2: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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 williamr@2: * by it's content and child elements. Element williamr@2: * can contain more data than the given pattern. williamr@2: * @since Series60 3.0 williamr@2: * @param aCandidate The pattern to be matched. Must contain williamr@2: * same or 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: * Get a list of direct children element that have the given williamr@2: * name and namespace. williamr@2: * @since Series60 3.0 williamr@2: * @param aElementArray RPointerArray that will hold matching elements williamr@2: * @param namespaceURI williamr@2: * @param localName williamr@2: * @return KErrNone or some system-wide error code, williamr@2: * if an error has occurred. williamr@2: */ williamr@2: virtual TInt ElementsL(RPointerArray& aElementArray, williamr@2: const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * Get a list of direct children element that have the given williamr@2: * name and same namespace as this parent Element. williamr@2: * @since Series60 3.0 williamr@2: * @param aElementArray RPointerArray that will hold matching elements williamr@2: * @param localName williamr@2: * @return KErrNone or some system-wide error code, williamr@2: * if an error has occurred. williamr@2: */ williamr@2: virtual TInt ElementsL(RPointerArray& aElementArray, williamr@2: const TDesC8& aLocalName) = 0; williamr@2: williamr@2: /** williamr@2: * @since Series60 3.0 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 modify williamr@2: * the element object. williamr@2: */ williamr@2: virtual RPointerArray& ElementsL() = 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: * @since Series60 3.0 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: /** williamr@2: * Gets the value of the given attribute. williamr@2: * @since Series60 3.0 williamr@2: * @param aName: Name of the attribute in question. williamr@2: * @return the value of the attribute, or NULL if not found. williamr@2: * Ownership is not transferred to caller. 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * From MSenElement Sets the parent element to this element. williamr@2: * Notice that the element is not automatically added as a williamr@2: * child of the parent. Parent's AddElementL() must be called williamr@2: * to achieve that. williamr@2: * williamr@2: * @since Series60 3.0 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: * @since Series60 3.0 williamr@2: * @return this Element. Ownership is NOT transferred to the caller. williamr@2: * or 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 a child element from a specified index. williamr@2: * @since Series60 3.0 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 root element. If no parent element, returns this element. williamr@2: * @since Series60 3.0 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: * @since Series60 3.0 williamr@2: * @param aLocalName is the XML localname of the requested child 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: * @since Series60 3.0 williamr@2: * @param aNsUri is the XML namespace of the requested child element williamr@2: * @param aLocalName is the XML localname of the requested child element 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: * @since Series60 3.0 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 contain illegal 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * @since Series60 3.0 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: * williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero williamr@2: * 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: * @since Series60 3.0 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 williamr@2: * characters. williamr@2: * 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: * @since Series60 3.0 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 child element was not found). 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: * @since Series60 3.0 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 child element was not found). 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 a child element. williamr@2: * @since Series60 3.0 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 child element was not found). williamr@2: * 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 a child element with another element. williamr@2: * Element's local name and namespace URI will be used to check williamr@2: * whether or not that element matches with any existing child. williamr@2: * If no matching child element is found this method will add a williamr@2: * new child element. williamr@2: * williamr@2: * @since Series60 3.0 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 the element as an XML buffer. Buffer will williamr@2: * contain all the child elements. williamr@2: * @since Series60 3.0 williamr@2: * @return element as XML. Caller takes ownership. williamr@2: */ williamr@2: virtual HBufC8* AsXmlL() = 0; williamr@2: williamr@2: /** williamr@2: * Gets the element as an unicode (UCS2) XML buffer. williamr@2: * Buffer will contain all the child elements. williamr@2: * @since Series60 3.0 williamr@2: * @return element as XML. Caller takes ownership. williamr@2: */ williamr@2: virtual HBufC* AsXmlUnicodeL() = 0; williamr@2: williamr@2: /** williamr@2: * Element writes itself to a write stream using UTF-8 williamr@2: * character-set encoding. williamr@2: * @since Series60 3.0 williamr@2: * @param aWriteStream The stream to write to. williamr@2: */ williamr@2: virtual void WriteAsXMLToL(RWriteStream& aWriteStream) = 0; williamr@2: williamr@2: /** williamr@2: * Element writes its namespaces to a write stream williamr@2: * using UTF-8 character-set encoding. williamr@2: * @since Series60 3.0 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: * Offers the M-class interface pointer to this XML williamr@2: * element. williamr@2: * @since Series60 3.0 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: * @since Series60 3.0 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: * This method should be used with care and is mainly intended for williamr@2: * protected use in implementations. williamr@2: * @since Series60 3.0 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, const TDesC8& aLocalName, const TDesC8& aQName) = 0; williamr@2: williamr@2: /** williamr@2: * Adds new attributes to the element. williamr@2: * @since Series60 3.0 williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: virtual void AddAttributesL(const RAttributeArray& apAttrs) = 0; williamr@2: }; williamr@2: williamr@2: #endif //SEN_ELEMENT_H williamr@2: williamr@2: // End of File williamr@2: