browserutilities/feedsengine/FeedsServer/XmlUtils/inc/XmlUtils.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 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 "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Misc. libxml2 related utilities.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef XML_UTILS_H
       
    20 #define XML_UTILS_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <xmlengdom.h>
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // MACROS
       
    29 
       
    30 // DATA TYPES
       
    31 
       
    32 // FUNCTION PROTOTYPES
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CXmlEncoding;
       
    36 class CXmlEntity;
       
    37 class RXmlEngDocument;
       
    38 class TXmlEngElement;
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 
       
    43 /**
       
    44 *  Misc. libxml2 related utilities.
       
    45 *
       
    46 *  \b Library: FeedsEngine.lib
       
    47 *
       
    48 *  @since 3.0
       
    49 */
       
    50 class CXmlUtils: public CBase
       
    51     {
       
    52     public: // Constructors and destructor
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         */
       
    56         static CXmlUtils* NewL();
       
    57         
       
    58         /**
       
    59         * Destructor.
       
    60         */        
       
    61         virtual ~CXmlUtils();
       
    62 
       
    63 
       
    64     public:  // New methods
       
    65         /**
       
    66         * Returns a document from the provided buffer.
       
    67         *
       
    68         * @since 3.0
       
    69         * @param aBuffer A buffer in any char-encoding.
       
    70         * @param aCharSet The char-set.
       
    71         * @return A document.
       
    72         */
       
    73         RXmlEngDocument ParseBufferL(const TDesC8& aBuffer,
       
    74                 const TDesC& aCharSet) const;
       
    75 
       
    76         /**
       
    77         * Resolves any entities and escaped chars in the given url.
       
    78         *
       
    79         * @since 3.0
       
    80         * @param aUrl The url to clean up.
       
    81         * @return void.
       
    82         */
       
    83         void CleanupUrlL(TDes& aUrl) const;
       
    84 
       
    85         /**
       
    86         * Remove any markup found in the given descriptor.
       
    87         *
       
    88         * @since 3.0
       
    89         * @param aBuffer The buffer to clean up.
       
    90         * @param aNewLineChar The char used to insert a newline.
       
    91         * @return ETrue if markup was found in aOrig.
       
    92         */
       
    93         TBool CleanupMarkupL(TDes& aBuffer, TInt aNewLineChar) const;
       
    94 
       
    95         /**
       
    96         * Resolves any entities found in aOrig the named entity into its char-value.
       
    97         *
       
    98         * @since 3.0
       
    99         * @param aBuffer The buffer to clean up.
       
   100         * @return ETrue if entities were found in aOrig.
       
   101         */
       
   102         TBool ResolveEntitiesL(TDes& aBuffer) const;
       
   103 
       
   104         /**
       
   105         * Performs a deep extraction of the text children of the given node.  The result
       
   106         * is returned as a 16-bit descriptor.  The char encoding is always ucs2.
       
   107         *
       
   108         * @since 3.0
       
   109         * @param aElement A element.
       
   110         * @return The text or NULL.
       
   111         */
       
   112         HBufC* ExtractTextL(TXmlEngElement aElement) const;
       
   113 
       
   114         /**
       
   115         * Performs a deep extraction of the text children of the given node.  The result
       
   116         * is returned as a 16-bit descriptor.    The char encoding is always ucs2.  This
       
   117         * method is different from ExtractTextL in that it doesn't resolve entities or
       
   118         * do any other clean up.  It also has a length param.
       
   119         *
       
   120         * @since 3.1
       
   121         * @param aElement A element.
       
   122         * @param aMaxLength The max length to extract or 0 to extract the entire string.
       
   123         * @param aFromEnd If ETrue the aMaxLength chars are taken from the end of the string.
       
   124         * @return The text or NULL.
       
   125         */
       
   126         HBufC* ExtractSimpleTextL(TXmlEngElement aElement, TInt aMaxLength,
       
   127                 TBool aFromEnd = EFalse) const;
       
   128 
       
   129         /**
       
   130         * Returns the first element in the given document.
       
   131         *
       
   132         * @since 3.0
       
   133         * @param aDocument A document.
       
   134         * @return A element or NULL-Element.
       
   135         */
       
   136         TXmlEngElement GetDocumentFirstElement(RXmlEngDocument aDocument) const;
       
   137         
       
   138         /**
       
   139         * Returns the first child of the given node.
       
   140         *
       
   141         * @since 3.0
       
   142         * @param aElement A element.
       
   143         * @return A element or NULL-Element.
       
   144         */
       
   145         TXmlEngElement GetFirstElementChild(TXmlEngElement aElement) const;
       
   146 
       
   147         /**
       
   148         * Returns the first child of the given node with the provided name.  aUtf8Name
       
   149         * MUST be null terminated.
       
   150         *
       
   151         * @since 3.0
       
   152         * @param aElement A element.
       
   153         * @param aName The name of the node.
       
   154         * @return A element or NULL-Element.
       
   155         */
       
   156         TXmlEngElement GetFirstNamedChild(TXmlEngElement aElement, const TDesC8& aUtf8Name) const;
       
   157 
       
   158         /**
       
   159         * Returns the next sibling of the given node.
       
   160         *
       
   161         * @since 3.0
       
   162         * @param aNode A element.
       
   163         * @return A element or NULL-Element.
       
   164         */
       
   165         TXmlEngElement GetNextSiblingElement(TXmlEngElement aElement);
       
   166 
       
   167         /**
       
   168         * Returns true if the given node has a name of aName.  This method doesn't 
       
   169         * compare the namespace.
       
   170         *
       
   171         * @since 3.0
       
   172         * @param aElement A element.
       
   173         * @param aName The name of the node.
       
   174         * @return ETrue if they match.
       
   175         */
       
   176         TBool IsNamed(TXmlEngElement aElement, const TDesC8& aUtf8Name) const;
       
   177 
       
   178         /**
       
   179         * Returns true if the given node has match the given namespace and name.
       
   180         *
       
   181         * @since 3.0
       
   182         * @param aElement A element.
       
   183         * @param aNameSpace The namespace of the node.
       
   184         * @param aName The name of the node.
       
   185         * @return ETrue if they match.
       
   186         */
       
   187         TBool IsNamed(TXmlEngElement aElement, const TDesC8& aUtf8NameSpace, 
       
   188                 const TDesC8& aUtf8Name) const;
       
   189 
       
   190         /**
       
   191         * Returns the attribute's value or NULL if the attribute wasn't present.
       
   192         *
       
   193         * @since 3.0
       
   194         * @param aElement A element.
       
   195         * @param aAttribute The attribute to extract.
       
   196         * @return The value or NULL.
       
   197         */
       
   198         HBufC* AttributeL(TXmlEngElement aElement, const TDesC8& aAttribute) const;
       
   199 
       
   200 
       
   201     private:  // New methods
       
   202         /**
       
   203         * C++ default constructor.
       
   204         */
       
   205         CXmlUtils();
       
   206 
       
   207         /**
       
   208         * By default Symbian 2nd phase constructor is private.
       
   209         */
       
   210         void ConstructL();
       
   211                 
       
   212         /**
       
   213         * Cleanup stack callback method to cleanup ParseBufferL.
       
   214         *
       
   215         * @since 3.0
       
   216         * @param aPtr A libxml2 parser context ptr.
       
   217         * @return void.
       
   218         */
       
   219         static void CleanupParseBuffer(TAny *aPtr);
       
   220 
       
   221         /**
       
   222         * Skip any chars before the XML-prolog.
       
   223         *
       
   224         * @since 3.0
       
   225         * @param aBuffer A xml buffer.
       
   226         * @param aLen The length of the xml buffer.
       
   227         * @return void.
       
   228         */
       
   229         void SkipCharsBeforeXmlProlog(const TUint8** aString, TInt& aLen) const;
       
   230         
       
   231         /**
       
   232         * Remove any markup found in the given descriptor.
       
   233         *
       
   234         * @since 3.0
       
   235         * @param aBuffer The string to be stripped of markup.
       
   236         * @param aNewLineChar The char used to insert a newline.
       
   237         * @return ETrue if markup was found in aBuffer.
       
   238         */
       
   239         TBool StripMarkupL(TDes& aBuffer, TInt aNewLineChar) const;        
       
   240 
       
   241         /**
       
   242         * Remove any CDATA markers in the given descriptor.
       
   243         *
       
   244         * @since 3.1
       
   245         * @param aBuffer The string to be stripped of markup.
       
   246         * @return ETrue if CDATA markers were found in aBuffer.
       
   247         */
       
   248         TBool StripCDataMarkers(TDes& aBuffer) const;
       
   249         
       
   250         
       
   251     private:  // Data
       
   252         TLeakTracker  iLeakTracker;
       
   253         
       
   254         RXmlEngDOMImplementation iImpl;
       
   255         CXmlEncoding*  iXmlEncoding;
       
   256         CXmlEntity*    iXmlEntity;
       
   257     };
       
   258 
       
   259 #endif      // XML_UTILS_H
       
   260             
       
   261 // End of File