connectivitymodules/SeCon/services/csc/inc/capparser.h
branchRCL_3
changeset 19 0aa8cc770c8a
parent 18 453dfc402455
child 20 4a793f564d72
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 2005-2008 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 "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:  CapParser header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef _CAPPARSER_H_
       
    21 #define _CAPPARSER_H_
       
    22 
       
    23 // INCLUDES
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <badesca.h>
       
    27 
       
    28 //
       
    29 // Class CapParser
       
    30 //
       
    31 NONSHARABLE_CLASS( CapParser )
       
    32     {
       
    33 
       
    34 public:
       
    35     /**
       
    36      * Parses element's id and type (eg. "<Memory>" -> EMemory, EElementBegin)
       
    37      * @param aText
       
    38      * @param aId
       
    39      * @param aType
       
    40      * @return none
       
    41      */
       
    42     static void ParseElement(const TDesC& aText, TInt& aId, TInt& aType);
       
    43     
       
    44 public:
       
    45     /**
       
    46      * Constructs element with value (eg. "<Free>23456</Free>").
       
    47      * @param aText
       
    48      * @param aId
       
    49      * @param aValue
       
    50      * @return none
       
    51      */
       
    52     static void MakeElementL(TDes& aText, TInt aId, const TDesC& aValue);   
       
    53     /**
       
    54      * Constructs element without value (eg. "<Memory>" or "</Memory>").
       
    55      * @param aText
       
    56      * @param aId
       
    57      * @param aType
       
    58      * @return none
       
    59      */
       
    60     static void MakeElementL(TDes& aText, TInt aId, TInt aType);
       
    61     /**
       
    62      * Constructs element with attributes "Version" and "Date"(eg. 
       
    63      * "<FW Version="2.2"/>").
       
    64      * @param aText
       
    65      * @param aId
       
    66      * @param aVersion
       
    67      * @param aDate
       
    68      * @return none
       
    69      */
       
    70     static void MakeElementL(TDes& aText, TInt aId, const TDesC& aVersion, 
       
    71                             const TDesC& aDate);
       
    72     /**
       
    73      * Constructs element with attributes
       
    74      * @param aText
       
    75      * @param aId
       
    76      * @param aAttributes
       
    77      * @return none
       
    78      */
       
    79     static void MakeElementL(TDes& aText, TInt aId, CDesCArrayFlat* aAttributes);
       
    80     
       
    81 public:
       
    82     /**
       
    83      * Returns capability element id (eg. EMemory).
       
    84      * @param aText
       
    85      * @return none
       
    86      */
       
    87     static TInt ElementId(const TDesC& aText);
       
    88     /**
       
    89      * Returns capability element tag (eg. "Memory").
       
    90      * @param aText
       
    91      * @param aId
       
    92      * @return none
       
    93      */
       
    94     static void GetTagL(TDes& aText, TInt aId);
       
    95     
       
    96 private:
       
    97     /**
       
    98      * Replaces special characters to xml compliant.
       
    99      * @param aText
       
   100      * @param aValue
       
   101      * @return none
       
   102      */
       
   103     static void ReplaceSpecialCharsL( TDes& aText, const TDesC& aValue );
       
   104     };
       
   105 
       
   106 
       
   107 //
       
   108 // Class TXmlParser
       
   109 //
       
   110 NONSHARABLE_CLASS( TXmlParser )
       
   111     {
       
   112 
       
   113 public:
       
   114     enum TElementType
       
   115         {
       
   116         EElementValue,
       
   117         EElementBegin,
       
   118         EElementEnd,
       
   119         EElementEmpty,
       
   120         EElementAtt,
       
   121         EElementComment,
       
   122         EElementVersion,
       
   123         EElementDocType,
       
   124         EElementUnknown
       
   125         };
       
   126 
       
   127 
       
   128 public:
       
   129     /**
       
   130      * Sets a tag
       
   131      * @param aText The tag
       
   132      * @return none
       
   133      */
       
   134     void Set(const TDesC& aText);
       
   135     /**
       
   136      * Returns type
       
   137      * @return type
       
   138      */
       
   139     TInt Type() const;
       
   140     /**
       
   141      * Returns a pointer to a tag
       
   142      * @return The tag pointer
       
   143      */
       
   144     TPtrC Tag() const;
       
   145     /**
       
   146      * Gets the tag
       
   147      * @param aText The tag buffer
       
   148      * @return none
       
   149      */
       
   150     void GetTag(TDes& aText) const;
       
   151 
       
   152 private:
       
   153     /**
       
   154      * Parses value (eg. <Language>en</Language>)
       
   155      * @return Operation success
       
   156      */
       
   157     TBool ElementValue();
       
   158     /**
       
   159      * Parses beginning tag (eg. <General>)
       
   160      * @return Operation success
       
   161      */
       
   162     TBool ElementBegin();
       
   163     /**
       
   164      * Parses ending tag (eg. </General>)
       
   165      * @return Operation success
       
   166      */
       
   167     TBool ElementEnd();
       
   168     /**
       
   169      * Parses empty element (eg. <CaseSenN/>)
       
   170      * @return Operation success
       
   171      */
       
   172     TBool ElementEmpty();
       
   173     /**
       
   174      * Parses attribute element (eg. <HW Version="1.5"/>)
       
   175      * Note: Attribute values cannot contain equals (=) or quotations (")
       
   176      * @return Operation success
       
   177      */
       
   178     TBool ElementAtt();
       
   179     /**
       
   180      * Identifies comment element ("<!-- OBEX Capability Object -->").
       
   181      * @return Operation success
       
   182      */
       
   183     TBool ElementComment();
       
   184     /**
       
   185      * Parses unknown elements
       
   186      * @return Operation success
       
   187      */
       
   188     TBool ElementUnknown();
       
   189     /**
       
   190      * Identifies version element ("<?xml version="1.0" ?>") 
       
   191      * @return Operation success
       
   192      */
       
   193     TBool ElementVersion();
       
   194     /**
       
   195      * Identifies document type element 
       
   196      * ("<!DOCTYPE Capability SYSTEM "obex-capability.dtd">").
       
   197      * @return Operation success
       
   198      */
       
   199     TBool ElementDocType();
       
   200 
       
   201 private:
       
   202     /**
       
   203      * Inits the parser
       
   204      * @return none
       
   205      */
       
   206     void Init();
       
   207     /**
       
   208      * Parses xml-element.  
       
   209      * @return none
       
   210      */
       
   211     void Parse();
       
   212 
       
   213 public:
       
   214     /**
       
   215      * Validates the character
       
   216      * @param aChar The char to be validated.
       
   217      * @return ETrue if the char is valid
       
   218      */
       
   219     static TBool ValidChar(const TChar aChar);
       
   220     /**
       
   221      * Validates the tag
       
   222      * @param aText The tag to be validated.
       
   223      * @return ETrue if the tag is valid
       
   224      */
       
   225     static TBool ValidTag(const TDesC& aText);
       
   226     /**
       
   227      * Returns the number of characters (aChar)
       
   228      * @param aText The buffer
       
   229      * @param aChar The character
       
   230      * @return The number of characters
       
   231      */
       
   232     static TInt Count(const TDesC& aText, const TChar aChar);
       
   233     /**
       
   234      * Returns the position of the first non space character
       
   235      * @param aText The buffer
       
   236      * @return The position
       
   237      */
       
   238     static TInt FirstNonSpace(const TDesC& aText);
       
   239     /**
       
   240      * Returns the position of the last non space character
       
   241      * @param aText The buffer
       
   242      * @return The position
       
   243      */
       
   244     static TInt LastNonSpace(const TDesC& aText);
       
   245     /**
       
   246      * Function returns a sub-string between aPos1 and aPos2
       
   247      * @param aText The buffer
       
   248      * @param aText Start position
       
   249      * @param aText End position
       
   250      * @return The pointer to the substring
       
   251      */
       
   252     static TPtrC SubStr(const TDesC& aText, TInt aPos1, TInt aPos2);
       
   253     /**
       
   254      * Function performs string copy with length checking.
       
   255      * @param aTarget Target buffer
       
   256      * @param aSource Source buffer
       
   257      * @return none
       
   258      */
       
   259     static void StrCopy(TDes& aTarget, const TDesC& aSource);
       
   260 
       
   261 private:    
       
   262     /**
       
   263      * Returns a string
       
   264      * @return A pointer to a string
       
   265      */
       
   266     TPtrC Str() const;
       
   267     /**
       
   268      * Trimmer function
       
   269      * @return none
       
   270      */
       
   271     void TrimOriginal();
       
   272     /**
       
   273      * Function returns sub string between aPos1 and aPos2
       
   274      * @param aPos1 Start position
       
   275      * @param aPos2 End posiotion
       
   276      * @return none
       
   277      */
       
   278     TPtrC SubStr(TInt pos1, TInt pos2);
       
   279 
       
   280 private:
       
   281     TPtrC iOriginal;
       
   282     TPtrC iText;
       
   283     TPtrC iTag;
       
   284     TPtrC iValue;
       
   285     TInt  iType;
       
   286 
       
   287     TInt iSlash;
       
   288     TInt iFirst;
       
   289     TInt iLast;
       
   290     };
       
   291 
       
   292 #endif 
       
   293 
       
   294 // End of file
       
   295 
       
   296