|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.gcf.utils; |
|
20 |
|
21 import com.nokia.mj.impl.rt.support.Jvm; |
|
22 |
|
23 /** |
|
24 Parses the basic elements of a URI, i.e. scheme, target, parameters |
|
25 */ |
|
26 public final class URI |
|
27 { |
|
28 private static final int PROTOCOL = 1; |
|
29 private static final int TARGET = 2; |
|
30 private static final int HOST = 3; |
|
31 private static final int PORT = 4; |
|
32 private static final int PATH = 5; |
|
33 private static final int PARAMETER = 6; |
|
34 private static final int QUERY = 7; |
|
35 |
|
36 private static final String EMPTY_STRING = ""; |
|
37 |
|
38 |
|
39 |
|
40 private final String iFullURI; |
|
41 private final int[] iErrorCache; |
|
42 |
|
43 |
|
44 static |
|
45 { |
|
46 try |
|
47 { |
|
48 // Load the native libraries |
|
49 Jvm.loadSystemLibrary("javagcf"); |
|
50 } |
|
51 catch (Exception e) |
|
52 { |
|
53 StreamsLogger.ELog("Unable to load native libraries!"); |
|
54 } |
|
55 } |
|
56 |
|
57 public URI(String aURIString) |
|
58 { |
|
59 iErrorCache = new int[1]; |
|
60 iFullURI = aURIString; |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 private String parse(int aUriPortion) |
|
66 { |
|
67 return parse(aUriPortion, null); |
|
68 } |
|
69 |
|
70 |
|
71 |
|
72 private String parse(int aUriPortion, String aParameterName) |
|
73 { |
|
74 int error = 0; |
|
75 String value = null; |
|
76 synchronized (this) |
|
77 { |
|
78 value = _parse(iFullURI, aUriPortion, aParameterName, iErrorCache); |
|
79 error = iErrorCache[0]; |
|
80 } |
|
81 //JDEBUG( "parse : value = " + value ); |
|
82 if (value == null) |
|
83 { |
|
84 if (error == -1) //KErrNotFound |
|
85 { |
|
86 return EMPTY_STRING; |
|
87 } |
|
88 if (error != 0) |
|
89 { |
|
90 throw new IllegalArgumentException(); |
|
91 } |
|
92 } |
|
93 return value; |
|
94 } |
|
95 |
|
96 |
|
97 |
|
98 private native String _parse(String aURI, int aUriPortion, String aParameterName, |
|
99 int[] aError); |
|
100 |
|
101 |
|
102 |
|
103 public String getProtocol() |
|
104 { |
|
105 return parse(PROTOCOL); |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 public String getHost() |
|
111 { |
|
112 return parse(HOST); |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 public String getPort() |
|
118 { |
|
119 return parse(PORT); |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 public String getPath() |
|
125 { |
|
126 return parse(PATH); |
|
127 } |
|
128 |
|
129 |
|
130 public String getParameter(String aParameterName) |
|
131 { |
|
132 return parse(PARAMETER, aParameterName); |
|
133 } |
|
134 |
|
135 |
|
136 public String getQuery() |
|
137 { |
|
138 return parse(QUERY); |
|
139 } |
|
140 |
|
141 |
|
142 |
|
143 public String toString() |
|
144 { |
|
145 return iFullURI; |
|
146 } |
|
147 } |
|
148 |
|
149 |