00001 /* 00002 * ============================================================================== 00003 * Name : SenBaseFragment.h 00004 * Part of : Web Services Xml 00005 * Interface : 00006 * Description : Class implements basic functionality of an XML fragment 00007 * Version : 00008 * 00009 * Copyright © 2002-2005 Nokia. All rights reserved. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia. All rights are reserved. Copying, including 00013 * reproducing, storing, adapting or translating, any 00014 * or all of this material requires the prior written consent of 00015 * Nokia. This material also contains confidential 00016 * information which may not be disclosed to others without the 00017 * prior written consent of Nokia. 00018 * ============================================================================== 00019 */ 00020 00021 #ifndef SEN_BASE_FRAGMENT_H 00022 #define SEN_BASE_FRAGMENT_H 00023 00024 // INCLUDES 00025 #include <MSenContentHandlerClient.h> 00026 #include <SenElement.h> 00027 #include <SenFragment.h> 00028 00029 // CONSTANTS 00030 00031 // Fragment's internal states. 00032 const TInt KStateNotSet = -1; 00033 const TInt KStateIgnore = 0; 00034 const TInt KStateSave = 1; 00035 const TInt KStateResume = 2; 00036 00037 // FORWARD DECLARATIONS 00038 class CSenXmlReader; 00039 00040 // CLASS DECLARATION 00041 00057 class CSenBaseFragment : public CSenFragment, public MSenContentHandlerClient 00058 { 00059 public: // Constructors and destructor 00060 00067 IMPORT_C static CSenBaseFragment* NewL(const CSenElement& aElement); 00068 00078 IMPORT_C static CSenBaseFragment* NewL(const TDesC8& aLocalName); 00079 00090 IMPORT_C static CSenBaseFragment* NewL(const TDesC8& aNsUri, 00091 const TDesC8& aLocalName); 00092 00104 IMPORT_C static CSenBaseFragment* NewL(const TDesC8& aNsUri, 00105 const TDesC8& aLocalName, 00106 const TDesC8& aQName); 00107 00120 IMPORT_C static CSenBaseFragment* NewL(const TDesC8& aNsUri, 00121 const TDesC8& aLocalName, 00122 const TDesC8& aQName, 00123 const RAttributeArray& apAttrs); 00124 00140 IMPORT_C static CSenBaseFragment* NewL(const TDesC8& aNsUri, 00141 const TDesC8& aLocalName, 00142 const TDesC8& aQName, 00143 const RAttributeArray& apAttrs, 00144 CSenElement& aParent); 00145 00149 IMPORT_C virtual ~CSenBaseFragment(); 00150 00151 00152 // New functions 00153 00159 IMPORT_C virtual TPtrC8 Content(); 00167 IMPORT_C virtual CSenNamespace* Namespace(const TDesC8& aPrefix); 00168 00173 IMPORT_C virtual void EnsureNamespace(const TDesC8& aPrefix); 00174 00181 IMPORT_C virtual void DetachL(); 00182 00191 IMPORT_C virtual void SaveNamespacesL(const RAttributeArray& aAttrs, 00192 TBool aEnsure); 00193 00198 IMPORT_C virtual void ResetContentL(); 00199 00200 // Functions from base classes 00201 00202 // From CSenFragment 00203 00208 IMPORT_C virtual const TDesC8& LocalName() const; 00209 00215 IMPORT_C virtual const TDesC8& NsUri() const; 00216 00222 IMPORT_C virtual const TDesC8& NsPrefix() const; 00223 00230 IMPORT_C virtual CSenElement& AsElement(); 00231 00241 IMPORT_C virtual CSenElement* ExtractElement(); 00242 00249 IMPORT_C virtual CSenXmlReader* Reader(); 00250 00257 IMPORT_C virtual void SetReader(CSenXmlReader& aReader); 00258 00271 IMPORT_C virtual void ParseL(const TDesC8& aXml); 00272 00281 IMPORT_C virtual TInt BuildFrom(const TDesC8& aXml); 00282 00293 IMPORT_C virtual void DelegateParsingL(MSenFragment& aDelegate); 00294 00308 IMPORT_C virtual void DelegateParsingL(const TDesC8& aNsUri, 00309 const TDesC8& aLocalName, 00310 const TDesC8& aQName, 00311 const RAttributeArray& aAttrs); 00312 00319 IMPORT_C virtual void ParseWithL(CSenXmlReader& aReader); 00320 00326 IMPORT_C virtual void SetOwner(MSenFragment& aFragment); 00327 00339 IMPORT_C virtual void ResumeParsingFromL(const TDesC8& aNsUri, 00340 const TDesC8& aLocalName, 00341 const TDesC8& aQName); 00342 00352 IMPORT_C virtual void SetAttributesL(const RAttributeArray& aAttrs); 00353 00363 IMPORT_C void WriteStartElementL(const TDesC8& aNsUri, 00364 const TDesC8& aLocalName, 00365 const TDesC8& aQName, 00366 const RAttributeArray& aAttrs); 00367 00376 IMPORT_C void WriteEndElementL(const TDesC8& aNsUri, 00377 const TDesC8& aLocalName, 00378 const TDesC8& aQName); 00379 00385 IMPORT_C virtual HBufC* AsXmlUnicodeL(); 00386 00392 IMPORT_C virtual HBufC8* AsXmlL(); 00393 00400 IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWs); 00401 00412 IMPORT_C virtual TBool ConsistsOfL(MSenFragment& aCandidate); 00413 00414 protected: 00415 00419 IMPORT_C CSenBaseFragment(); 00420 00431 IMPORT_C void BaseConstructL(const CSenElement& aElement); 00432 00438 IMPORT_C void BaseConstructL(const TDesC8& aLocalName); 00439 00446 IMPORT_C void BaseConstructL(const TDesC8& aNsUri, 00447 const TDesC8& aLocalName); 00448 00456 IMPORT_C void BaseConstructL(const TDesC8& aNsUri, 00457 const TDesC8& aLocalName, 00458 const TDesC8& aQName); 00467 IMPORT_C void BaseConstructL(const TDesC8& aNsUri, 00468 const TDesC8& aLocalName, 00469 const TDesC8& aQName, 00470 const RAttributeArray& aAttrs); 00471 00481 IMPORT_C void BaseConstructL(const TDesC8& aNsUri, 00482 const TDesC8& aLocalName, 00483 const TDesC8& aQName, 00484 const RAttributeArray& aAttrs, 00485 CSenElement& aParent); 00486 00492 IMPORT_C void BaseConstructL(CSenXmlReader& aReader); 00493 00494 // New functions 00495 00500 IMPORT_C virtual void AllocContentSaverL(); 00501 00511 IMPORT_C virtual void StartElementL(const TDesC8& aNsUri, 00512 const TDesC8& aLocalName, 00513 const TDesC8& aQName, 00514 const RAttributeArray& aAttrs); 00515 00524 IMPORT_C virtual void EndElementL(const TDesC8& aNsUri, 00525 const TDesC8& aLocalName, 00526 const TDesC8& aQName); 00527 00537 IMPORT_C virtual void CharactersL(const TDesC8& aChars, 00538 TInt aStart, 00539 TInt aLength); 00540 00547 IMPORT_C TInt StartEntity(TDesC8& aName); 00548 00561 IMPORT_C MSenElement& SetContentOfL(const TDesC8& aLocalName, 00562 const TDesC8 &aContent); 00570 IMPORT_C TPtrC8 ContentOf(const TDesC8& aLocalName); 00571 00572 private: // New functions 00573 00577 TPtrC8 ContentL(); 00578 00579 // Functions from base classes 00580 00581 // From MSenContentHandlerClient 00582 00583 IMPORT_C virtual TInt StartDocument(); 00584 IMPORT_C virtual TInt EndDocument(); 00585 IMPORT_C virtual TInt StartElement(const TDesC8& aNsUri, 00586 const TDesC8& aLocalName, 00587 const TDesC8& aQName, 00588 const RAttributeArray& aAttrs); 00589 00590 IMPORT_C virtual TInt EndElement(const TDesC8& aNsUri, 00591 const TDesC8& aLocalName, 00592 const TDesC8& aQName); 00593 00594 IMPORT_C virtual TInt Characters(const TDesC8& aChars, 00595 const TInt aStart, 00596 const TInt aLength); 00597 00598 IMPORT_C virtual TInt Error(TInt aErrorCode); 00599 00600 protected: // Data 00601 00602 // State variable indicating what this fragment 00603 // is currently parsing. Even states (like 0) 00604 // mean that this fragment is ignoring the 00605 // data, and odd states indicate, that fragment 00606 // is storing the data into itself. 00607 TInt iState; 00608 // Owned element containing this XML fragment data. 00609 CSenElement* ipElement; 00610 // Pointer to XML parser. Not owned. 00611 CSenXmlReader* iXmlReader; 00612 // Possible owner fragment, if such exists. Not owned. 00613 MSenFragment* ipOwner; 00614 // Internal write stream, into which UTF-8 form XML is stored 00615 RWriteStream iWs; 00616 00617 private: // Data 00618 00619 // Owned pointer to delegate fragment 00620 CSenFragment* ipDelegate; 00621 // Not owned. Holds namespaces that are referred to from 00622 // within the content but were not declared within this 00623 // BaseFragment. 00624 RPointerArray<CSenNamespace> iNamespaces; 00625 // Owned. Holds prefixes that have been declared within the 00626 // scope of this BaseFragment 00627 RPointerArray<HBufC8> iPrefixes; 00628 // Actual flat buffer to content which includes namespaces. 00629 CBufFlat* ipContentWithNamespaces; 00630 // Indicating that content writing stream is initialized. 00631 TBool hasContentWriteStream; 00632 // Indicates whether or not ipElement member is an owned 00633 TBool iElementOwned; 00634 }; 00635 00636 //SEN_BASE_FRAGMENT_H 00637 #endif 00638 00639 // End of File 00640 00641 00642