upnpmediaserver/contentdirectoryservice/inc/upnpcdutils.h
changeset 0 7f85d04be362
child 12 cdcbf344a1d3
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     2 * Copyright (c) 2005-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 "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:  ContentDirectory utils,
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CDUTILS_H
       
    21 #define CDUTILS_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <xmlengdom.h>
       
    25 #include <e32base.h>
       
    26 
       
    27 
       
    28 // CLASS DECLARATION
       
    29 
       
    30 /**
       
    31 *  Set of utils functions.
       
    32 *
       
    33 *  @lib AVContentDirectory.lib
       
    34 *  @since Series60 3.1
       
    35 */
       
    36 class UpnpCdUtils
       
    37 {
       
    38  public:
       
    39  
       
    40     static void ValidateFilePath(TDes8& aPath);
       
    41     static void ValidateFilePath(TDes& aPath);
       
    42     static void ValidateSrcUriL(TDesC8& aPath,TDesC8& aIp);
       
    43     /**
       
    44     * Removes white spaces (and '\r \n \t and space') from the given descriptor 
       
    45     * @since Series S60 3.0
       
    46     * @param aString descriptor to be processed
       
    47     */
       
    48     static void RemoveWhiteSpacesL(TDes8& aString);
       
    49 
       
    50     /**
       
    51     * Checking if there are white spaces(and '\r \n \t and space' ) in the given descriptor
       
    52     * @since Series S60 3.1
       
    53     * @param aString 
       
    54     * @return boolean
       
    55     */
       
    56     static TBool IsWhiteString(const TDesC8& aString);
       
    57     
       
    58     /**
       
    59     * Gets element
       
    60     * @since Series S60 3.1
       
    61     * @param aFragment 
       
    62     * @return TXmlEngElement
       
    63     */      
       
    64     static TXmlEngElement GetObjectElementL(RXmlEngDocument& aFragment);
       
    65     
       
    66     /**
       
    67     * Checks if Ref id value exists
       
    68     * @since Series S60 5.0 HN
       
    69     * @param aFragment 
       
    70     * @return TBool
       
    71     */     
       
    72     static TBool HasRefIdL( RXmlEngDocument& aFragment );
       
    73     
       
    74     /**
       
    75     * Encodes Xml 
       
    76     * @since Series S60 3.1
       
    77     * @param aString
       
    78     * @return descriptor pointer
       
    79     */
       
    80     static HBufC8* EncodeXmlStringL(const TDesC8& aString);
       
    81     
       
    82      
       
    83    	static HBufC* Des8ToDesL(const TDesC8& aString);
       
    84     
       
    85     /**
       
    86     * Conversion from TDes8 to TDes16
       
    87     * @since Series S60 3.1
       
    88     * @param aString
       
    89     * @return descriptor pointer
       
    90     */
       
    91     static HBufC* Des8ToDesLC(const TDesC8& aString);
       
    92     
       
    93     /**
       
    94     * Conversion from TDes16 to TDes8
       
    95     * @since Series S60 3.1
       
    96         * @param aString
       
    97     * @return descrptor pointer
       
    98     */
       
    99     static HBufC8* DesToDes8LC(const TDesC& aString);
       
   100        
       
   101     /*
       
   102     * Getter
       
   103     * @since Series S60 3.1
       
   104         * @param aUri
       
   105     * @return TInt
       
   106     */
       
   107     static TInt64 ResIdFromUriL(const TDesC8& aUri);
       
   108     
       
   109     /*
       
   110     * Getter
       
   111     * @since Series S60 3.1
       
   112     * @param aUri
       
   113     * @return TPtrC8
       
   114     */
       
   115     static TPtrC8 ResIdFromUriDesL(const TDesC8& aUri);
       
   116     
       
   117     /*
       
   118     * Sets Object Id
       
   119     * @since Series S60 3.1
       
   120     * @param aElement TXmlEngElement of the element
       
   121     * @param aId Id
       
   122     */
       
   123 
       
   124     static void SetObjectIdL(TXmlEngElement aElement, TInt aId);
       
   125     /*
       
   126     * Sets refID
       
   127     * @since Series S60 5.0 HN
       
   128     * @param aElement TXmlEngElement of the element
       
   129     * @param aRefId
       
   130     */
       
   131     static void SetObjectRefIdL(TXmlEngElement aElement, TInt aRefId);
       
   132     
       
   133     /*
       
   134     * Sets parentID
       
   135     * @since Series S60 5.0 HN
       
   136     * @param aElement TXmlEngElement of the element
       
   137     * @param aRefId
       
   138     */
       
   139     static void SetObjectParentIdL(TXmlEngElement aElement, TInt aParentId);
       
   140         
       
   141     /*
       
   142      * Sets restricted field
       
   143      * @since Series S60 5.0 HN
       
   144      * @param aElement TXmlEngElement of the element
       
   145      * @param aRestrictedFlag
       
   146      */
       
   147     static void SetRestrictedFieldL( TXmlEngElement aElement, TBool aRestrictedFlag );
       
   148 
       
   149     /*
       
   150     * Sets Container Id
       
   151     * @since Series S60 3.1
       
   152     * @param aElement TXmlEngElement of the element
       
   153     * @param aParentId ParentId
       
   154     */
       
   155     static void SetContainerIdL(TXmlEngElement aElement, TInt aParentId);
       
   156    	static HBufC8* BuildImportUriLC(TInt aResId);
       
   157    	static HBufC8* BuildImportUriShorterLC(TInt64 aResId);
       
   158 	static HBufC8* BuildContentUriL(TInt aResId, const TDesC& aFileExten, TDesC8& aObjectId);
       
   159     static HBufC8* UpnpCdUtils::RandomizeL(TInt aRange);
       
   160     /**
       
   161     * Checks whether the element is required and removes the attribute notifying it
       
   162     * @since Series S60 3.0
       
   163     * @param aElement TXmlEngElement of the element
       
   164     * @param aObjId aCd pointer to the ContentDirectory object - it provides a function which deletes
       
   165     *               a file from the private directory
       
   166     * @param ETrue if the element is required, otherwise EFalse
       
   167     */
       
   168     static TBool IsElementRequiredL(TXmlEngElement aElement);
       
   169         /**
       
   170     * Replaces the the first occurrence of true/false sequence with 1/0 within given descriptor 
       
   171     * @since Series S60 3.0
       
   172     * @param aBuf descriptor pointer
       
   173     */
       
   174     static void ReplaceTrueFalse(HBufC8* aBuf);
       
   175 
       
   176     /**
       
   177     * Gets the full name with namespace of the given element.
       
   178     * @since Series S60 3.0
       
   179     * @param aElement an element to get the name of
       
   180     * @return descriptor with the namespace:name of the element, 
       
   181     *              the caller should delete it when it is no longer needed
       
   182     */
       
   183     static HBufC8* GetElmNameWithNsL(TXmlEngElement aElement);
       
   184      
       
   185     static HBufC* EscapeAposL(const TDesC&  aValue);
       
   186     static TBool ValidateDateL(  TPtrC8 aValue );
       
   187     
       
   188     /**
       
   189     * Converts TDesC8 to TUint
       
   190     */
       
   191     static TInt StringToTUint(const TDesC8& aStr, TUint* aInt);
       
   192     
       
   193     /**
       
   194     * Checks whether input string contains a specific number of digits and whether whole number fit into specific range
       
   195     * @since Series S60 3.0
       
   196     * @param aInput input descriptor [a number]
       
   197     * @param aNumber number of digits the descriptor should contain
       
   198     * @param aExactDigitsNumber should the number have exact number of digits or not
       
   199     * @param aRange the number mustn't exceed the specified range
       
   200     * @return ETrue if condition is fulfilled
       
   201     */
       
   202     static TBool AreDigitsInSpecificRange(const TDesC8& aInput, TInt aNumber, TBool aExactDigitsNumber, TUint32 aRange); 
       
   203     
       
   204     /**
       
   205     * Validates res@duration attribute
       
   206     * @since Series S60 3.0
       
   207     * @param aInput descriptor containing duration value to validate
       
   208     * @return ETrue if res@duration has proper format
       
   209     */
       
   210     static TBool ValidateDurationValue(const TDesC8& aInput);  
       
   211     
       
   212     /**
       
   213     * Split string into pieces with delimeter
       
   214     * @since Series S60 3.0
       
   215     * @param aLexeme a lexer to parse
       
   216     * @param aDelimeter delimeter    
       
   217     */
       
   218     static void SplitStringByDelimeter(TLex8& aLexeme, TChar aDelimeter);
       
   219     
       
   220     /**
       
   221     * Skip characters in lexer
       
   222     * @since Series S60 3.0
       
   223     * @param aLexer a lexer to parse
       
   224     * @param aValue number of characters to skip
       
   225     */
       
   226     static void Skip(TLex8& aLexer, TInt aValue);
       
   227         
       
   228          /**
       
   229     * Extracts integer value from descriptor
       
   230     * @param aStr descriptor to be extracted
       
   231     * @param aInt integer to be fill in
       
   232     * @return error status
       
   233     */
       
   234     static TInt StringToInteger(const TDesC8& aStr, TInt* aInt);
       
   235             
       
   236  private:
       
   237      enum TPlaces
       
   238         {
       
   239         EYear = 4,
       
   240         EMonth = 7,
       
   241         EDay = 10,
       
   242         EHour = 13,
       
   243         EMinute = 16,
       
   244         ESecond = 19,
       
   245         EZone1 = 20,
       
   246         EHourOffset1 = 22,
       
   247         EMiliSecond = 23,
       
   248         EZone2 = 24,
       
   249         ETimeOffset1 = 25,
       
   250         EHourOffset2 = 26,
       
   251         ETimeOffset2 = 29
       
   252         };
       
   253     /*
       
   254     * C++ default constructor.
       
   255     */
       
   256     UpnpCdUtils();
       
   257 };
       
   258 
       
   259 #endif      // CDUTILS_H   
       
   260             
       
   261 // End of File