javacommons/gcfbase/src.s60/uri.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  URI parser specific to symbian
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "turi.h"
       
    22 #include "com_nokia_mj_impl_gcf_utils_URI.h"
       
    23 #include "jstringutils.h"
       
    24 #include "s60commonutils.h"
       
    25 
       
    26 using namespace java::util;
       
    27 
       
    28 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_gcf_utils_URI__1parse
       
    29 (JNIEnv* aJni, jobject, jstring aUriString, jint aUriPortion,
       
    30  jstring aParameterName, jintArray aErrorCache)
       
    31 {
       
    32     JStringUtils uriString(*aJni, aUriString);
       
    33     TUri uri;
       
    34     TInt error = uri.Parse(uriString);
       
    35     TPtrC uriPart(KNullDesC());
       
    36     if (error == KErrNone)
       
    37     {
       
    38         switch (aUriPortion)
       
    39         {
       
    40         case com_nokia_mj_impl_gcf_utils_URI_PROTOCOL:
       
    41             uriPart.Set(uri.Scheme());
       
    42             break;
       
    43         case com_nokia_mj_impl_gcf_utils_URI_HOST:
       
    44             uriPart.Set(uri.Host());
       
    45             break;
       
    46         case com_nokia_mj_impl_gcf_utils_URI_PORT:
       
    47             uriPart.Set(uri.Port());
       
    48             break;
       
    49         case com_nokia_mj_impl_gcf_utils_URI_PATH:
       
    50             uriPart.Set(uri.Path());
       
    51             break;
       
    52         case com_nokia_mj_impl_gcf_utils_URI_PARAMETER:
       
    53         {
       
    54             JStringUtils parameterName(*aJni, aParameterName);
       
    55             error = uri.GetParameterValue(parameterName, uriPart);
       
    56             break;
       
    57         }
       
    58         case com_nokia_mj_impl_gcf_utils_URI_QUERY:
       
    59             uriPart.Set(uri.Query());
       
    60             break;
       
    61         default:
       
    62             __ASSERT_DEBUG(EFalse, User::Invariant());
       
    63         }
       
    64     }
       
    65     jstring result = NULL;
       
    66     // Return an empty string if the parameter value is not found
       
    67     if (error == KErrNone)
       
    68     {
       
    69         result = S60CommonUtils::NativeToJavaString(*aJni, uriPart);
       
    70     }
       
    71     else
       
    72     {
       
    73         // Cache the error code in the array, as we can't return it
       
    74         aJni->SetIntArrayRegion(aErrorCache, 0, 1, &error);
       
    75     }
       
    76     return result;
       
    77 }
       
    78 
       
    79