williamr@2: /* williamr@2: * Copyright (c) 2002-2006 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: Class implements XML base fragment using libxml2 classes williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef SEN_FRAGMENT_BASE_H williamr@2: #define SEN_FRAGMENT_BASE_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: williamr@4: #include williamr@2: #include williamr@2: #include williamr@4: #include williamr@2: williamr@2: using namespace Xml; williamr@2: williamr@2: // CONSTANTS williamr@2: williamr@2: // Fragment's internal states. williamr@2: const TInt KSenStateNotSet = -1; williamr@2: const TInt KSenStateIgnore = 0; williamr@2: const TInt KSenStateSave = 1; williamr@2: const TInt KSenStateResume = 2; williamr@2: const TInt KSenStateDelegate = 3; williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: class RWriteStream; williamr@2: //class CSenParser; williamr@2: class CSenNamespaceData; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * Class implements basic functionality of an XML fragment williamr@2: * Typically base fragment is used to parse certain part of some XML document. williamr@2: * The element is identified by local name (or qualified name) and namespace. williamr@2: * All child elements between start tag and and end tag defined this fragment williamr@2: * will become content of this BaseFragment. In other words, BaseFragment has williamr@2: * all data inside a single element. williamr@2: * BaseFragment will parse only namespace (xmlns) attributes from a document williamr@2: * and rest of the attributes are to be handled by subclasses, which should williamr@2: * overwrite SetAttributesL() method to achieve this. williamr@2: * The CSenFragmentReader class will do the actual parsing and this class will williamr@2: * act as content handler for XML parser SAX events. williamr@2: * @lib SenFragment.dll williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: class CSenFragmentBase : public CBase, public MContentHandler williamr@2: { williamr@2: friend class CSenParserImpl; williamr@2: williamr@2: public: // Constructors and destructor williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @since Series60 4.0 williamr@2: * @param aElement is the element where construction williamr@2: * data will be copied from. williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TXmlEngElement& aElement); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @since Series60 4.0 williamr@2: * @param aLocalName: is the XML localname for this fragment williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri: XML namespace URI williamr@2: * @param aLocalName: XML localname williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI williamr@2: * @param aLocalName XML localname williamr@2: * @param aPrefix XML prefix williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI williamr@2: * @param aLocalName XML localname williamr@2: * @param aPrefix XML prefix williamr@2: * @param apAttrs XML attributes williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& apAttrs); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @param aParent Element to be set as fragment's parent element. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI williamr@2: * @param aLocalName XML localname williamr@2: * @param aPrefix XML prefix williamr@2: * @param apAttrs XML attributes williamr@2: * @param aParent Parent element williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& apAttrs, williamr@2: TXmlEngElement& aParent); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @param aParent Element to be set as fragment's parent element. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI williamr@2: * @param aLocalName XML localname williamr@2: * @param aPrefix XML prefix williamr@2: * @param apAttrs XML attributes williamr@2: * @param aParent Parent element williamr@2: * @param aOwnerDocument The document which will be the owner of williamr@2: * the elements of this fragment williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& apAttrs, williamr@2: TXmlEngElement& aParent, williamr@2: RSenDocument& aOwnerDocument); williamr@2: williamr@2: /** williamr@2: * Standard 2 phase constructor. williamr@2: * @param aParent Element to be set as fragment's parent element. williamr@2: * @since Series60 4.0 williamr@2: * @param aRootElement The element which will be the root element williamr@2: * of this fragment. williamr@2: * @param aOwnerDocument The document which will be the owner of williamr@2: * the elements of this fragment williamr@2: */ williamr@2: IMPORT_C static CSenFragmentBase* NewL(TXmlEngElement& aRootElement, williamr@2: RSenDocument& aOwnerDocument); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: */ williamr@2: IMPORT_C virtual ~CSenFragmentBase(); williamr@2: williamr@2: // Functions from base classes williamr@2: williamr@2: // From MContentHandler: williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnStartDocumentL(const RDocumentParameters& aDocParam, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnEndDocumentL(TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnContentL(const TDesC8& aBytes, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt ErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnSkippedEntityL(const RString& aName, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual void OnError(TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Callback function implementing the XML content handler interface. williamr@2: * Inheriting classes can override these. williamr@2: * @since Series60 3.1 williamr@2: * @see MContentHandler williamr@2: */ williamr@2: IMPORT_C virtual TAny* GetExtendedInterface(const TInt32 aUid); williamr@2: williamr@2: // New functions williamr@2: williamr@2: /** williamr@2: * Getter for the content,which is returned as UTF-8 form XML. williamr@2: * @since Series60 4.0 williamr@2: * @return content as UTF-8 form XML. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 ContentL(); williamr@2: williamr@2: /** williamr@2: * Gets the namespace object with a given prefix. williamr@2: * @since Series60 4.0 williamr@2: * @param aPrefix: prefix that wanted namespace should have. williamr@2: * @return namespace with the given prefix. If not found or given prefix williamr@2: * is zero length, will return NULL. williamr@2: */ williamr@2: IMPORT_C virtual TXmlEngNamespace Namespace(const TDesC8& aPrefix); williamr@2: williamr@2: /** williamr@2: * @since Series60 4.0 williamr@2: * @return Detaches this fragment from its owner. All namespace williamr@2: * references from possible parent fragments are declared in williamr@2: * the scope of this fragment prior detaching. williamr@2: */ williamr@2: // IMPORT_C virtual void DetachL(); williamr@2: williamr@2: /** williamr@2: * Resets the content of the fragment, and resets the namespaces. williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C virtual void ResetContentL(); williamr@2: williamr@2: /** williamr@2: * @since Series60 4.0 williamr@2: * @return the localname of this fragment as UTF-8 form descriptor williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 LocalName() const; williamr@2: williamr@2: /** williamr@2: * Getter for Fragment's namespace URI.. williamr@2: * @since Series60 4.0 williamr@2: * @return Namespace URI or KNullDesC if not set. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 NsUri() const; williamr@2: williamr@2: /** williamr@2: * Getter for namespace prefix of this fragment. williamr@2: * @since Series60 4.0 williamr@2: * @return namespace prefix or KNullDesC if not set. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 NsPrefix() const; williamr@2: williamr@2: /** williamr@2: * Returns the current XML element of this fragment. If element williamr@2: * has not been set, this method will initialize new, un-initialized williamr@2: * element. williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: * @return reference to the element of this fragment williamr@2: */ williamr@2: IMPORT_C virtual TXmlEngElement AsElementL(); williamr@2: williamr@2: /** williamr@2: * Returns the current XML element of this fragment. If element williamr@2: * has not been set, this method will initialize new, un-initialized williamr@2: * element. williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: * @return reference to the element of this fragment williamr@2: */ williamr@2: IMPORT_C virtual RSenDocument& AsDocumentL(); williamr@2: williamr@2: /** williamr@2: * Etracts the XML element from the fragment, leaving the fragment empty. williamr@2: * Note(!): the return value (CSenElement) STRONGLY suggests that williamr@2: * subclasses INHERIT CSenFragment in order properly comply the williamr@2: * requirement of the ExtractElement() implementation. williamr@2: * @since Series60 4.0 williamr@2: * @return the current object as element. May return NULL. williamr@2: * Ownership IS TRANSFERRED to the caller. williamr@2: */ williamr@2: IMPORT_C virtual TXmlEngElement ExtractElement(); williamr@2: williamr@2: /** williamr@2: * Let the delegate MSenFragment handle the following SAX events. williamr@2: * This fragment is made the owner of the delegate and the delegate williamr@2: * is expected to make this MSenFragment the receiver of SAX events williamr@2: * once it has seen the end element for itself. williamr@2: * @since Series60 4.0 williamr@2: * @param aDelegate is the fragment to start handling the SAX events. williamr@2: */ williamr@2: IMPORT_C virtual void OnDelegateParsingL(CSenFragmentBase& aDelegate); williamr@2: williamr@2: /** williamr@2: * Creates a new fragment and lets the created MSenFragment handle the williamr@2: * following SAX events. This fragment is made the owner of the delegate williamr@2: * and the delegate is expected to make this MSenFragment act as receiver williamr@2: * for SAX events (callbacks) once it has seen the end element for itself. williamr@2: * @since Series60 4.0 williamr@2: * @param aElement The RTagInfo class holding information that williamr@2: * describes the element. williamr@2: * @param aAttributes The attributes of the new element williamr@2: * @param aErrorCode Error code williamr@2: */ williamr@2: IMPORT_C virtual void OnDelegateParsingL(const RTagInfo& aElement, williamr@2: const RAttributeArray& aAttributes, williamr@2: TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Sets a new parent for this fragment. williamr@2: * @since Series60 4.0 williamr@2: * @param aFragment: the new parent. williamr@2: */ williamr@2: IMPORT_C virtual void SetOwner(CSenFragmentBase& aFragment); williamr@2: williamr@2: /** williamr@2: * Leave codes: williamr@2: * Resumes parsing to be handled by this fragment. Usually called by some williamr@2: * delegate fragment which was set to be content handler because this williamr@2: * fragment called DelegateParsingL(). williamr@2: * @since Series60 4.0 williamr@2: * @param aElement The RTagInfo class holding information that williamr@2: * describes the element. williamr@2: * @param aErrorCode Error code williamr@2: */ williamr@2: IMPORT_C virtual void OnResumeParsingFromL(const RTagInfo& aElement, TInt aErrorCode); williamr@2: williamr@2: /** williamr@2: * Sets the attributes for the fragment. BaseFragment parses only williamr@2: * namespace (xmlns) attributes from the document. williamr@2: * Subclasses should override this method if they are intrested williamr@2: * of handling any other XML attributes and their corresponding williamr@2: * values. williamr@2: * @since Series60 4.0 williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: // IMPORT_C virtual void SetAttributesL(const RAttributeArray& aAttrs); williamr@2: williamr@2: /** williamr@2: * Writes the start element tag to the content stream. williamr@2: * Derivants can override the basic usage used in BaseFragment. williamr@2: * @since Series60 4.0 williamr@2: * @param aElement The RTagInfo class holding information that williamr@2: * describes the element. williamr@2: * @param aAttributes The attributes of the new element williamr@2: */ williamr@2: IMPORT_C void OnWriteStartElementL(const RTagInfo& aElement, williamr@2: const RAttributeArray& aAttributes); williamr@2: williamr@2: /** williamr@2: * Writes the end element tag to the content stream. williamr@2: * Derivants can override the basic usage used in BaseFragment. williamr@2: * @since Series60 4.0 williamr@2: * @param aElement The RTagInfo class holding information that williamr@2: * describes the element. williamr@2: */ williamr@2: IMPORT_C void OnWriteEndElementL(const RTagInfo& aElement); williamr@2: williamr@2: /** williamr@2: * Gets the fragment data as an unicode XML. williamr@2: * @since Series60 4.0 williamr@2: * @return fragment as XML. Caller takes ownership. williamr@2: */ williamr@2: IMPORT_C virtual HBufC* AsXmlUnicodeL(); williamr@2: williamr@2: /** williamr@2: * Gets the fragment data as an UTF-8 form XML. williamr@2: * @since Series60 4.0 williamr@2: * @return fragment as XML. Caller takes ownership. williamr@2: */ williamr@2: IMPORT_C virtual HBufC8* AsXmlL(); williamr@2: williamr@2: /** williamr@2: * Invokes AsElement().WriteAsXMLToL(aWs); williamr@2: * @since Series60 4.0 williamr@2: * @param aWs is the stream into which the UTF-8 form XML will williamr@2: * be written. williamr@2: */ williamr@2: IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWs); williamr@2: williamr@2: /** williamr@2: * Checks if fragment matches to another fragment williamr@2: * by its content and child elements. williamr@2: * Fragment can contain more data than the given candidate. williamr@2: * @since Series60 4.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: IMPORT_C virtual TBool ConsistsOfL(CSenFragmentBase& aCandidate); williamr@2: williamr@2: //From SenParserImpl.h williamr@2: IMPORT_C void SetContentHandler(CSenFragmentBase& aContentHandler); williamr@2: williamr@2: /** williamr@2: * Sets the RSenDocument williamr@2: * @param aDocument williamr@2: */ williamr@2: IMPORT_C void SetDocument(RSenDocument& aDocument); williamr@2: williamr@2: protected: williamr@2: williamr@2: /** williamr@2: * C++ default constructor. williamr@2: */ williamr@2: IMPORT_C CSenFragmentBase(); williamr@2: williamr@2: /** williamr@2: * Following BaseConstructL methods should be called from ConstructL() williamr@2: * methods of some deriving (fragment) class. williamr@2: */ williamr@2: williamr@2: /** williamr@2: * BaseConstructL, where an element is given as initializer. williamr@2: * @since Series60 4.0 williamr@2: * @param aElement from which this fragment will be constructed from. williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TXmlEngElement& aSrc); williamr@2: williamr@2: /** williamr@2: * BaseConstructL setting XML localname for this fragment. williamr@2: * @since Series60 4.0 williamr@2: * @param aLocalName XML localname for this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * BaseConstructL offering possibility to set XML namespace and localname. williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI for this fragment williamr@2: * @param aLocalName XML localname for this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Base constructor williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI for this fragment williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aQName XML qualifiedname for this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix); williamr@2: /** williamr@2: * Base constructor williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI for this fragment williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aQName XML qualifiedname for this fragment williamr@2: * @param aAttrs XML attributes for this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& aAttrs); williamr@2: williamr@2: /** williamr@2: * Base constructor williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI for this fragment williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aQName XML qualifiedname for this fragment williamr@2: * @param aAttrs XML attributes for this fragment williamr@2: * @param aParent parent to be set for this fragmemt williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& aAttrs, williamr@2: TXmlEngElement& aParent); williamr@2: williamr@2: /** williamr@2: * Base constructor williamr@2: * @since Series60 4.0 williamr@2: * @param aNsUri XML namespace URI for this fragment williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aQName XML qualifiedname for this fragment williamr@2: * @param aAttrs XML attributes for this fragment williamr@2: * @param aParent Parent to be set for this fragmemt williamr@2: * @param aOwnerDocument The document which will be the owner of williamr@2: * the elements of this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aPrefix, williamr@2: const RAttributeArray& aAttrs, williamr@2: TXmlEngElement& aParent, williamr@2: RSenDocument& aOwnerDocument); williamr@2: williamr@2: /** williamr@2: * Base constructor williamr@2: * @since Series60 4.0 williamr@2: * @param aRootElement The element which will be the root element williamr@2: * of this fragment williamr@2: * @param aOwnerDocument The document which will be the owner of williamr@2: * the elements of this fragment williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(TXmlEngElement& aRootElement, williamr@2: RSenDocument& aOwnerDocument); williamr@2: williamr@2: // New functions williamr@2: williamr@2: /** williamr@2: * Adds new XML attributes to this fragment. williamr@2: * Can be overridden to replace old attributes. williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: IMPORT_C virtual void AddAttributesL(const RAttributeArray& apAttrs); williamr@2: williamr@2: /** williamr@2: * Adds new XML attributes to specified element. williamr@2: * Can be overridden to replace old attributes. williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: IMPORT_C virtual void AddAttributesToElementL(TXmlEngElement element, williamr@2: const RAttributeArray& apAttrs); williamr@2: williamr@2: /** williamr@2: * Method renames the XML properties of this fragment. williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aPrefix XML namespace prefix for this fragment williamr@2: * @param aNamespace XML namespace URI for this fragment williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: */ williamr@2: void RenameL(const TDesC8& aLocalName, const TDesC8& aPrefix, const TDesC8& aNamespace); williamr@2: williamr@2: /** williamr@2: * Method renames the XML properties of this fragment. williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * @param aNamespace XML namespace URI for this fragment williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: */ williamr@2: void RenameL(const TDesC8& aLocalName, const TDesC8& aNamespace); williamr@2: williamr@2: /** williamr@2: * Renames local name for this XML fragment. williamr@2: * @param aLocalName XML localname for this fragment williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: */ williamr@2: void RenameLocalNameL(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Renames namespace URI for this XML fragment. williamr@2: * @param aNamespace XML namespace URI for this fragment williamr@2: * Method leaves with if there is not enough memory(OOM) williamr@2: */ williamr@2: void RenameNamespaceL(const TDesC8& aNamespace); williamr@2: williamr@2: /** williamr@2: * Renames namespace prefix for this XML fragment. williamr@2: * @param aPrefix XML namespace prefix for this fragment williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: */ williamr@2: void RenamePrefixL(const TDesC8& aPrefix); williamr@2: williamr@2: /** williamr@2: * Renames namespace prefix and namespace URI for this XML fragment. williamr@2: * @param aPrefix XML namespace prefix for this fragment williamr@2: * @param aNamespace XML namespace URI for this fragment williamr@2: * Method leaves with if there is not enough memory (OOM) williamr@2: */ williamr@2: void RenameNamespaceL(const TDesC8& aPrefix, const TDesC8& aNamespace); williamr@2: williamr@2: /** williamr@2: * Sets content to a child element. If no element with given local name williamr@2: * is not found, new one is added and content is set to that one. williamr@2: * @since Series60 4.0 williamr@2: * @param aLocalName The local name of element which content williamr@2: * is about to be set williamr@2: * @param aContent Content to be set. williamr@2: * @return the element where content was set. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: IMPORT_C TXmlEngElement SetContentOfL(const TDesC8& aLocalName, williamr@2: const TDesC8& aContent); williamr@2: /** williamr@2: * Gets the content of a given element. williamr@2: * @since Series60 4.0 williamr@2: * @param aLocalName The local name of the element which content is williamr@2: * asked williamr@2: * @return the content which was asked williamr@2: */ williamr@2: IMPORT_C TPtrC8 ContentOf(const TDesC8& aLocalName); williamr@2: williamr@2: IMPORT_C virtual TBool ConsistsOfL(TXmlEngElement& aElement, TXmlEngElement& aCandidate); williamr@2: williamr@2: /** williamr@2: * Adds namespaces from internal array for the fragment. williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C virtual void AddNamespacesL(); williamr@2: williamr@2: /** williamr@2: * Sets content to a child element. If no element with given local name williamr@2: * is not found, new one is added and content is set to that one. williamr@2: * @since Series60 4.0 williamr@2: * @param aContent Content to be set. williamr@2: */ williamr@2: IMPORT_C virtual void SetContentL(const TDesC8& aContent); williamr@2: williamr@2: /** williamr@2: * Adds the content. williamr@2: * @since Series60 4.0 williamr@2: * @param aContent Content to be set. williamr@2: */ williamr@2: IMPORT_C virtual void AddContentL(const TDesC8& aContent); williamr@2: williamr@2: /** williamr@2: * StartSavingContent changes the internal SAX parsing state of williamr@2: * this fragment to KSenStateSave, which means that next call williamr@2: * to OnStartElementL is treated as data, and not ignored williamr@2: * (in DOM fragment implementation, it would be "extended" williamr@2: * into a DOM object). williamr@2: */ williamr@2: IMPORT_C void StartSavingContent(); williamr@2: williamr@2: williamr@2: private: // New functions williamr@2: williamr@2: /** williamr@2: * Sets the XML parser to be used for parsing for the fragment. williamr@2: * @since Series60 4.0 williamr@2: * @param aReader: the reader to be used. williamr@2: * Ownership is NOT transferred. williamr@2: */ williamr@2: IMPORT_C virtual void SetParser(CSenParser& aParser); williamr@2: williamr@2: protected: // Data williamr@2: williamr@2: // State variable indicating what this fragment williamr@2: // is currently parsing. Even states (like 0) williamr@2: // mean that this fragment is ignoring the williamr@2: // data, and odd states indicate, that fragment williamr@2: // is storing the data into itself. williamr@2: TInt iState; williamr@2: williamr@2: // Owned element containing this XML fragment data. williamr@2: TXmlEngElement iElement; williamr@2: williamr@2: // Owned document representing this XML fragment williamr@2: RSenDocument iDocument; williamr@2: williamr@2: // Pointer to XML parser. Not owned. williamr@2: CSenParser* ipParser; // Not owned williamr@2: williamr@2: // Possible owner fragment, if such exists. Not owned. williamr@2: CSenFragmentBase* ipOwner; // Not owned williamr@2: CSenFragmentBase* ipDelegate; // Owned williamr@2: williamr@2: RPointerArray* ipNamespaceArray; // Owned williamr@2: williamr@2: CBufFlat* ipContentBuf; // Owned williamr@2: RBufWriteStream* ipContentWriteStream; // Owned williamr@2: }; williamr@2: williamr@2: class CSenNamespaceData : public CBase williamr@2: { williamr@2: public: williamr@2: virtual ~CSenNamespaceData(); williamr@2: williamr@2: public: williamr@2: HBufC8* ipLocalName; williamr@2: HBufC8* ipNamespaceUri; williamr@2: HBufC8* ipPrefix; williamr@2: }; williamr@2: williamr@2: #endif //SEN_FRAGMENT_BASE_H williamr@2: williamr@2: // End of File williamr@2: williamr@2: williamr@2: