epoc32/include/xmlengdocument.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2 * Copyright (c) 2004-2006 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:       Document node functions
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 
    22 
    23 #ifndef XMLENGINE_DOCUMENT_H_INCLUDED
    24 #define XMLENGINE_DOCUMENT_H_INCLUDED
    25 
    26 #include <f32file.h> 
    27 
    28 #include "xmlengnode.h"
    29 #include "xmlengserializationoptions.h"
    30 
    31 // FORWARD DECLARATION
    32 class RXmlEngDOMImplementation;
    33 
    34 /**
    35  * Instance of RXmlEngDocument class represents an XML document in the DOM tree.
    36  * 
    37  * Is a storage all nodes and information about XML data.
    38  * 
    39  * @lib XmlEngineDOM.lib
    40  * @since S60 v3.1
    41  */
    42 class RXmlEngDocument : public TXmlEngNode
    43 {
    44 public:    
    45     /**
    46      * Default constructor.
    47      *
    48      * Instance of RXmlEngDocument must be "opened" with one of OpenL() overloads.
    49      *
    50      * @since S60 v3.1
    51 	 */
    52     IMPORT_C RXmlEngDocument();
    53     
    54     /** 
    55      * Opens the document.
    56      *
    57 	 * @since S60 v3.2
    58 	 * @param aDOMImpl DOM implementation object
    59      * @return KErrNone if succeed.
    60      */
    61     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl);
    62 	
    63 	/** 
    64      * Opens the document.
    65      *
    66 	 * @since S60 v3.2
    67 	 * @param aDOMImpl DOM implementation object
    68  	 * @param aInternal Document pointer
    69      * @return KErrNone if succeed.
    70      */
    71     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl, void* aInternal);
    72     
    73     /** 
    74      * Opens the document.
    75      *
    76 	 * @since S60 v3.2
    77 	 * @param aDOMImpl DOM implementation object
    78  	 * @param aRoot element taht will be root of the DOM tree
    79      * @return KErrNone if succeed.
    80      */
    81     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl, TXmlEngElement aRoot);
    82     
    83     /**
    84      * Closes document
    85      *
    86      * @since S60 v3.1
    87 	 */
    88     IMPORT_C  void Close();
    89 
    90     /**
    91      * Serializes document tree into a file. For nodes containing binary data in the form of BinaryDataContainer,
    92      * FileContainer or ChunkContainer, client can implement custom serialization by implementing the interface
    93      * MXmlEngDataSerializer and specify the pointer in iDataSerializer member of aSaveOptions parameter. If no
    94      * custom serialization is specified, the binary data container nodes are serialized like text nodes.
    95      *
    96      * @since S60 v3.2
    97 	 * @param aFileName A file name (with path)
    98  	 * @param aRoot Root node to be serialized	
    99 	 * @param aSaveOptions Options that control how serialization is performed 
   100      * @return Number of byte written
   101      * @leave KErrNoMemory, KErrGeneral, KXmlEngErrWrongEncoding, KErrDiskFull.
   102      */
   103     IMPORT_C TInt SaveL( const TDesC& aFileName,
   104     					 TXmlEngNode aRoot = TXmlEngNode(),
   105     					 const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   106    
   107     /**
   108      * Serializes document tree into a file.  For nodes containing binary data in the form of BinaryDataContainer,
   109      * FileContainer or ChunkContainer, client can implement custom serialization by implementing the interface
   110      * MXmlEngDataSerializer and specify the pointer in iDataSerializer member of aSaveOptions parameter. If no
   111      * custom serialization is specified, the binary data container nodes are serialized like text nodes.
   112      *
   113      * @since S60 v3.2
   114 	 * @param aRFs File Server session
   115 	 * @param aFileName A file name (with path)	 
   116  	 * @param aRoot Root node to be serialized	
   117 	 * @param aSaveOptions Options that control how serialization is performed 
   118      * @return Number of byte written
   119      * @leave KErrNoMemory, KErrGeneral, KXmlEngErrWrongEncoding, KErrDiskFull.
   120      */                        
   121     IMPORT_C TInt SaveL( RFs& aRFs,
   122                          const TDesC& aFileName,
   123                          TXmlEngNode aRoot = TXmlEngNode(),
   124                          const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   125     
   126     /**
   127      * Serializes a document tree into provided output stream, which supports progressive writing of data.
   128      * For nodes containing binary data in the form of BinaryDataContainer, FileContainer or ChunkContainer,
   129      * client can implement custom serialization by implementing the interface MXmlEngDataSerializer and specify
   130      * the pointer in iDataSerializer member of aSaveOptions parameter. If no custom serialization is specified,
   131      * the binary data container nodes are serialized like text nodes.
   132      *
   133      * @since S60 v3.1
   134 	 * @param aStream  An output stream to write serialized DOM tree
   135 	 * @param aRoot Root node to be serialized
   136 	 * @param aSaveOptions Options that control how serialization is performed	 	 
   137      * @return Number of byte written
   138      * @leave KXmlEngErrWrongUseOfAPI or one of general codes (e.g.KErrNoMemory)
   139      * @see MXmlEngOutputStream
   140      */
   141     IMPORT_C TInt SaveL( MXmlEngOutputStream& aStream,
   142 						 TXmlEngNode aRoot = TXmlEngNode(),
   143 						 const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   144 
   145     /**
   146      * Saves document tree into memory buffer
   147      *
   148      * @since S60 v3.1
   149 	 * @param aBuffer Resulting buffer
   150      * @param aRoot A "root" of the subtree to serialize
   151      * @param aSaveOptions Various options to be effective during serialization
   152      * @return Number of bytes in updated buffer     
   153      * @leave KErrNoMemory, KErrGeneral, KXmlEngErrWrongEncoding.
   154      *
   155      * @note Result returned via aBuffer argument owns the memory buffer; it is up to 
   156      *      method caller to free it like in this sample:
   157      *
   158      * @see TXmlEngSerializationOptions
   159      */
   160     IMPORT_C TInt SaveL(RBuf8& aBuffer, 
   161     					TXmlEngNode aRoot = TXmlEngNode(), 
   162                         const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions()) const;
   163    
   164     /**
   165      * Creates complete copy of the document
   166      *
   167      * @since S60 v3.1
   168 	 * @return Complete copy of the document tree
   169      */
   170 	IMPORT_C RXmlEngDocument CloneDocumentL() const;
   171 
   172     /**
   173      * Creates new element from specific namespace to be a root of the document tree.
   174      * Any existing document element of the document is destroyed
   175      *
   176      * @since S60 v3.1
   177 	 * @param aName Element name
   178      * @param aNamespaceUri Element namespace URI
   179      * @param aPrefix Element namemespace prefix
   180      * @return A new root element
   181      */
   182     IMPORT_C TXmlEngElement CreateDocumentElementL(const TDesC8& aName, 
   183                                              const TDesC8& aNamespaceUri = KNullDesC8, 
   184                                              const TDesC8& aPrefix = KNullDesC8);
   185 
   186     /**
   187      * Replaces (and destroys) document element with another one
   188      * New document element is added as the last child to the document node
   189      *
   190      * @since S60 v3.1
   191 	 * @param aNewDocElement New document tree
   192      *
   193      * @note Use TXmlEngElement::ReconcileNamespacesL() on the new document element
   194      *      if it or its descendants can contain references to namespace declarations
   195      *      out of the element
   196      * @see TXmlEngElement::ReconcileNamespacesL()
   197      */
   198     IMPORT_C void SetDocumentElement(TXmlEngElement aNewDocElement);
   199 
   200     /**
   201      * Get document encoding
   202      *
   203      * @since S60 v3.1
   204 	 * @return Encoding of the source XML data.
   205      */
   206     IMPORT_C TPtrC8 XmlEncoding() const;
   207 
   208     /**
   209      * Get xml version
   210      *
   211      * @since S60 v3.1
   212 	 * @return Version number of XML taken from XML declaration
   213      */
   214     IMPORT_C TPtrC8 XmlVersion() const;
   215   
   216     /**
   217      * Retrieves base URI (if defined) of the document or NULL
   218      *
   219      * @since S60 v3.1
   220 	 * @return Document URI
   221      */
   222     IMPORT_C TPtrC8 DocumentUri() const;
   223 
   224     /**
   225      * Check if document is standalone
   226      *
   227      * @since S60 v3.1
   228 	 * @return Whether standalone="true" was specified in XML declaration in the source XML file.
   229      */
   230     IMPORT_C TBool IsStandalone() const;
   231 
   232     /**
   233      * Sets XML version number to be shown in XML declaration when document is serialized.
   234      *
   235      * @since S60 v3.1
   236 	 * @param aVersion New version
   237      */
   238     IMPORT_C void  SetXmlVersionL(const TDesC8& aVersion);
   239 
   240     /**
   241      * Sets location of the document.
   242      * Document's URI is used as top-level base URI definition.
   243      *
   244      * @since S60 v3.1
   245 	 * @param aUri New document URI
   246      */
   247     IMPORT_C void  SetDocumentUriL(const TDesC8& aUri);
   248 
   249     /**
   250      * Sets 'standalone' attribute of XML declaration for a document
   251      *
   252      * @since S60 v3.1
   253 	 * @param aStandalone Is document standalone
   254      */
   255     IMPORT_C void  SetStandalone(TBool aStandalone);
   256 
   257     /**
   258      * Get dom implementation.
   259      *
   260      * @since S60 v3.1
   261 	 * @return Object that represents current DOM implementation
   262      *
   263      * @note There is no practical use of implementation object in this version
   264      *      of API other than for creating new RXmlEngDocument instances, but
   265      *      it will change in the future, when an implementation object 
   266      *      is used for changing configuration settings at run-time.
   267      */
   268     IMPORT_C RXmlEngDOMImplementation Implementation() const;
   269     
   270     /**
   271      * Get document element
   272      *
   273      * @since S60 v3.1
   274 	 * @return A document element - the top-most element in the document tree
   275      */
   276     IMPORT_C TXmlEngElement DocumentElement() const;
   277 
   278     /**
   279      * Sets "document" property on the node and all its descendants to be this RXmlEngDocument node 
   280      *
   281      * @since S60 v3.1
   282 	 * @param aSource Node that should be added.
   283      * @return Adopted node
   284      */
   285     IMPORT_C TXmlEngNode AdoptNodeL(TXmlEngNode aSource);
   286 
   287     /**
   288      * Creates new attribute,
   289      *
   290      * @since S60 v3.1
   291 	 * @param aName Name of the atribute; no prefix allowed
   292      * @param aValue Value of the attribute (optional)
   293      * @return Handler to the newly created attribute 
   294      * 
   295      * @note 
   296      * aValue should represent a correct value of an attribute if it is put as is into XML file
   297      * (with all characters correctly escaped with entity references when XML spec requires)
   298      * 
   299      * TXmlEngElement class provides a rich set of attribute creation methods, which not
   300      * just create attribute but also link it into element.
   301      * 
   302      * There is no way to create attributes with namespace (despite the DOM spec); 
   303      * you have to use one of the TXmlEngElement::AddNewAttributeL(..) methods instead
   304      *
   305      * Returned handler is the only reference to the allocated memory
   306      * until you have attached the attribute to some element node
   307      */
   308     IMPORT_C TXmlEngAttr CreateAttributeL(const TDesC8& aName,
   309                                     const TDesC8& aValue = KNullDesC8);
   310 
   311     /**
   312      * Creates new text node and copies the content string into it.
   313      *
   314      * @since S60 v3.1
   315 	 * @param aCharacters Text node content
   316      * @return Created node
   317      */
   318     IMPORT_C TXmlEngTextNode CreateTextNodeL(const TDesC8& aCharacters = KNullDesC8);
   319 
   320     /**
   321      * Creates new binary container and copies the content string into it.
   322      * Pointer to the container is stored in the document's 
   323      * data container list that can be fetched using GetDataContainerList().
   324      * @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )
   325      *
   326      * @since S60 v3.2
   327 	 * @param aCid Content identifier     
   328 	 * @param aData Binary octets
   329      * @return Created node
   330      */
   331     IMPORT_C TXmlEngBinaryContainer CreateBinaryContainerL( const TDesC8& aCid,
   332     												  const TDesC8& aData );
   333 
   334     /**
   335      * Creates new chunk container that stores reference to 
   336      * memory chunk.
   337      * Pointer to the container is stored in the document's 
   338      * data container list that can be fetched using GetDataContainerList().
   339      * @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )     
   340      *
   341      * @since S60 v3.2
   342 	 * @param aCid Content identifier 
   343 	 * @param aChunk RChunk reference
   344 	 * @param aChunkOffset Offset to the binary data in aChunk
   345 	 * @param aDataSize Size of binary data in aChunk
   346      * @return Created node
   347      */
   348     IMPORT_C TXmlEngChunkContainer CreateChunkContainerL( const TDesC8& aCid, 
   349     												const RChunk& aChunk,
   350 					                                const TInt aChunkOffset,
   351 					                                const TInt aDataSize );
   352 
   353     /**
   354      * Creates new file container that stores reference to 
   355      * file in file system.
   356      * Pointer to the container is stored in the document's 
   357      * data container list that can be fetched using GetDataContainerList().
   358      * @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )     
   359      *
   360      * @since S60 v3.2
   361 	 * @param aCid Content identifier
   362 	 * @param aFile RFile reference
   363      * @return Created node
   364      */
   365     IMPORT_C TXmlEngFileContainer CreateFileContainerL( const TDesC8& aCid, 
   366     											  const RFile& aFile );
   367 
   368     /**
   369      * Creates new element node that belongs to specific namespace.
   370      * A namespace declaration node is created on the element.
   371      *
   372      * @since S60 v3.1
   373 	 * @param aNamespaceUri Namespace of new element
   374      * @param aPrefix Prefix to use for namespace binding and QName of the element
   375      * @param aLocalName Local name of the element 
   376      * @return Created node
   377      * @note If null namespace uri is provided element will be created without namespace.
   378      */  
   379     IMPORT_C TXmlEngElement CreateElementL(const TDesC8& aLocalName, 
   380                                      const TDesC8& aNamespaceUri = KNullDesC8, 
   381                                      const TDesC8& aPrefix = KNullDesC8);
   382 
   383     /**
   384      * Creates new comment node and copies the content string into it.
   385      *
   386      * @since S60 v3.1
   387 	 * @param aText New comment
   388      * @return Created node
   389      */
   390     IMPORT_C TXmlEngComment CreateCommentL(const TDesC8& aText = KNullDesC8);
   391 
   392     /**
   393      * Creates new CDATA section node and copies the content into it.
   394      *
   395      * @since S60 v3.1
   396 	 * @param aContents CDATASection content
   397      * @return Created node
   398      */
   399     IMPORT_C TXmlEngCDATASection CreateCDATASectionL(const TDesC8& aContents = KNullDesC8);
   400 
   401     /**
   402      * Creates new entity reference node for aEntityName entity
   403      *
   404      * @since S60 v3.1
   405 	 * @param aEntityRef is a string in one of the forms:
   406      *     -  <i>name</i>
   407      *     -  <b>&</b><i>name</i>
   408      *     -  <b>&</b><i>name</i><b>;</b>
   409      * where <i>name</i> is the name of the entity
   410      * @return Created node
   411      * 
   412      * @note &lt; , &gt; , &apos; , &quot; and other <b>predefined</b> entity references
   413      *      should not be created with this method. These entity refs are rather 
   414      *      "character references" and encoded/decoded automatically.
   415      */
   416     IMPORT_C TXmlEngEntityReference CreateEntityReferenceL(const TDesC8& aEntityRef);
   417 
   418     /**
   419      * Creates new processing instruction node and set its "target" and "data" values
   420      *
   421      * @since S60 v3.1
   422 	 * @param aTarget Target
   423      * @param aData Data
   424      * @return Created node
   425      */
   426     IMPORT_C TXmlEngProcessingInstruction CreateProcessingInstructionL(const TDesC8& aTarget, 
   427                                                                  const TDesC8& aData = KNullDesC8);
   428                                                                  
   429     /**
   430      * Registers specified attribute as xml:id.
   431      * First parametr allows user, to specify sub-tree, not to search whole document.
   432      * To search whole tree see @see RegisterXmlId(const TDesC8,const TDesC8)
   433      *
   434      * @since S60 v3.2
   435      * @param aStartElement Root of tree to search (should be part of the document)
   436      * @param aLocalName Name of attribute
   437 	 * @param aNamespaceUri Namespace of new element (default empty)
   438      */
   439     IMPORT_C void RegisterXmlIdL(TXmlEngElement aStartElement,
   440                                  const TDesC8& aLocalName, 
   441                                  const TDesC8& aNamespaceUri = KNullDesC8);
   442 
   443     /**
   444      * Registers specified attribute as xml:id.
   445      * Not to search whole tree see @see RegisterXmlId(TXmlEngElement,const TDesC8,const TDesC8)
   446      *
   447      * @since S60 v3.2
   448      * @param aLocalName Name of attribute
   449 	 * @param aNamespaceUri Namespace of new element (default empty)
   450      */
   451     IMPORT_C void RegisterXmlIdL(const TDesC8& aLocalName, 
   452                                  const TDesC8& aNamespaceUri = KNullDesC8);
   453        
   454     /**
   455      * Looks for element with specified value of xml:id
   456      *
   457      * @since S60 v3.2
   458 	 * @param aValue Name of attribute
   459      * @return found element or null-element.
   460      */
   461     IMPORT_C TXmlEngElement FindElementByXmlIdL(const TDesC8& aValue ) const;  
   462 
   463     /**
   464      * Retrieves an array of data containers owned by this document.
   465      *
   466 	 * @note The document ceases to be the owner of data container when data container
   467 	 *		 (or one of its predecessors) is removed from the document or data container 
   468 	 * 	 	 (or one of its predecessors) becomes a part of another document.
   469 	 *		 Unlinking data container (or one of its predecessors) doesn't remove
   470 	 *		 ownership of data container from the this document so the list might
   471 	 *		 contain containers that are not linked to this document anymore.    
   472      * @since S60 v3.2
   473 	 * @param aList Array of data containers
   474      */
   475     IMPORT_C void GetDataContainerList( RArray<TXmlEngDataContainer>& aList );         
   476                                                                  
   477 protected:
   478     friend class RXmlEngDOMParser;
   479     friend class TXmlEngNode;
   480     friend class TXmlEngAttr;
   481     friend class TXmlEngElement;
   482     friend class RXmlEngDOMImplementation;
   483 
   484 protected:
   485     /**
   486      * Constructor
   487      *
   488      * @since S60 v3.1
   489 	 * @param aInternal Document pointer
   490 	 */
   491     inline RXmlEngDocument(void* aInternal);
   492 
   493     /**
   494      * DISABLED for document; CloneDocumentL() must be used
   495      *
   496      * @since S60 v3.1
   497 	 */
   498     inline TXmlEngNode CopyL() const; 
   499 
   500     /**
   501      * DISABLED for document; Destroy() must be used
   502      *
   503      * @since S60 v3.1
   504 	 */    
   505     inline void Remove();
   506 
   507     /**
   508      * DISABLED for document; Destroy() must be used
   509      *
   510      * @since S60 v3.1
   511 	 */ 
   512     inline void ReplaceWith(TXmlEngNode aNode);
   513 private:
   514     /**
   515      * Main implementation of SaveL() functions that puts together all common code
   516      * and serializes to buffer or output stream.
   517      *
   518      * @since S60 v3.2
   519 	 * @param aNode Root node to be serialized     
   520 	 * @param aBuffer buffer with serialized data.
   521 	 * @param aOutputStream stream that should be used during serialization
   522 	 * @param aSaveOptions Options that control how serialization is performed
   523      * @return Number of bytes written
   524      * @leave KErrNoMemory, KErrGeneral, KXmlEngErrWrongEncoding, KErrDiskFull.     
   525 	 */ 
   526 	TInt SaveNodeL( TXmlEngNode aNode,
   527 					RBuf8& aBuffer,
   528                	    MXmlEngOutputStream* aOutputStream = NULL,
   529                	    TXmlEngSerializationOptions aOpt = TXmlEngSerializationOptions()) const;	
   530 
   531     /**
   532      * "Secondary" constructor that should be called on every newly created document node.
   533      * Initializes container for nodes owned by the document.
   534      *
   535      * The need for such secondary constructor is in the fact that underlying libxml2
   536      * library knows nothing about ownership of unlinked nodes -- this feature is
   537      * implemented in C++ DOM wrapper.
   538      *
   539      * @since S60 v3.1
   540 	 */ 
   541     void InitOwnedNodeListL();
   542 
   543     /**
   544      * Adds aNode to the list of owned nodes - the nodes that are not linked yet into a 
   545      * document tree, but still destroyed with the document that owns them.
   546      *
   547      * @since S60 v3.1
   548 	 * @param aNode Node that should be added to document
   549      *
   550      * In case of OOM (during growing node list container) the argument node is freed with
   551      * xmlFreeNode()
   552      */ 
   553     void TakeOwnership(TXmlEngNode aNode);
   554 
   555     /**
   556      * Remove aNode from the list of owned nodes.
   557      *
   558      * @since S60 v3.1
   559 	 * @param aNode Node that should be removed from document
   560      */
   561     void RemoveOwnership(TXmlEngNode aNode);
   562 
   563 protected:
   564     /**  Pointer to DOM implementation object */
   565     RXmlEngDOMImplementation* iImpl;
   566 
   567 };// class RXmlEngDocument
   568 
   569 
   570 
   571 #include "xmlengdocument.inl"
   572 
   573 #endif /* XMLENGINE_DOCUMENT_H_INCLUDED */