15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 |
19 |
|
20 #include "cesmrurlparserpluginimpl.h" |
|
21 #include "cmrurlparserextension.h" |
|
22 |
|
23 #include <EPos_CPosLandmark.h> |
|
24 #include <EPos_CPosLandmarkEncoder.h> |
|
25 #include <EPos_CPosLandmarkParser.h> |
|
26 #include <EPos_CPosLmOperation.h> |
|
27 #include <lbsposition.h> |
|
28 #include <EscapeUtils.h> |
|
29 #include <finditemengine.h> |
|
30 #include <calentry.h> |
|
31 |
20 #include "emailtrace.h" |
32 #include "emailtrace.h" |
21 #include <EPos_CPosLandmark.h> |
33 |
22 #include <ecom/implementationproxy.h> |
34 namespace |
23 #include <barsread.h> |
35 { |
24 #include <esmrurlparserplugindata.rsg> |
36 _LIT8( KLandmarkUrlMimeType, "maps.ovi.com" ); |
25 #include <data_caging_path_literals.hrh> |
37 } |
26 #include <barsc.h> |
|
27 #include <f32file.h> |
|
28 #include <lbsposition.h> |
|
29 |
|
30 #include "cesmrurlparserpluginimpl.h" |
|
31 #include "esmrinternaluid.h" |
|
32 |
|
33 |
|
34 _LIT( KResourceName, "esmrurlparserplugindata.rsc" ); |
|
35 _LIT( KResourceFileLocFormat, "r%02d" ); |
|
36 _LIT( KResourceFormat, "rsc" ); |
|
37 |
|
38 const TInt KCoordinateMaxLength = 10; |
|
39 const TInt KNumberOfDecimals = 4; |
|
40 const TUint KDecimalSeparator = '.'; |
|
41 |
|
42 |
|
43 |
38 |
44 // ======== MEMBER FUNCTIONS ======== |
39 // ======== MEMBER FUNCTIONS ======== |
45 |
40 |
46 |
41 // --------------------------------------------------------------------------- |
47 |
42 // CESMRUrlParserPluginImpl::CESMRUrlParserPluginImpl |
48 // --------------------------------------------------------------------------- |
|
49 // Non-leaving constructor |
|
50 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
51 // |
44 // |
52 CESMRUrlParserPluginImpl::CESMRUrlParserPluginImpl() |
45 CESMRUrlParserPluginImpl::CESMRUrlParserPluginImpl() |
53 : iIsInitialized(EFalse) |
46 { |
54 { |
47 FUNC_LOG; |
55 FUNC_LOG; |
48 } |
56 |
49 |
57 } |
50 // --------------------------------------------------------------------------- |
58 |
51 // CESMRUrlParserPluginImpl::NewL |
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // ConstructL for leaving construction |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CESMRUrlParserPluginImpl::ConstructL()// codescanner::LFunctionCantLeave |
|
65 { |
|
66 FUNC_LOG; |
|
67 |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Symbian style NewL constructor |
|
73 // --------------------------------------------------------------------------- |
52 // --------------------------------------------------------------------------- |
74 // |
53 // |
75 CESMRUrlParserPluginImpl* CESMRUrlParserPluginImpl::NewL() |
54 CESMRUrlParserPluginImpl* CESMRUrlParserPluginImpl::NewL() |
76 { |
55 { |
77 FUNC_LOG; |
56 FUNC_LOG; |
|
57 |
78 CESMRUrlParserPluginImpl* self = CESMRUrlParserPluginImpl::NewLC(); |
58 CESMRUrlParserPluginImpl* self = CESMRUrlParserPluginImpl::NewLC(); |
79 CleanupStack::Pop( self ); |
59 CleanupStack::Pop( self ); |
80 return self; |
60 return self; |
81 } |
61 } |
82 |
62 |
83 |
63 |
84 // --------------------------------------------------------------------------- |
64 // --------------------------------------------------------------------------- |
85 // Symbian style NewLC constructor |
65 // CESMRUrlParserPluginImpl::NewLC |
86 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
87 // |
67 // |
88 CESMRUrlParserPluginImpl* CESMRUrlParserPluginImpl::NewLC() |
68 CESMRUrlParserPluginImpl* CESMRUrlParserPluginImpl::NewLC() |
89 { |
69 { |
90 FUNC_LOG; |
70 FUNC_LOG; |
|
71 |
91 CESMRUrlParserPluginImpl* self = new( ELeave ) CESMRUrlParserPluginImpl; |
72 CESMRUrlParserPluginImpl* self = new( ELeave ) CESMRUrlParserPluginImpl; |
92 CleanupStack::PushL( self ); |
73 CleanupStack::PushL( self ); |
93 self->ConstructL(); |
|
94 return self; |
74 return self; |
95 } |
75 } |
96 |
76 |
97 |
77 |
98 // --------------------------------------------------------------------------- |
78 // --------------------------------------------------------------------------- |
99 // Destructor |
79 // CESMRUrlParserPluginImpl::~CESMRUrlParserPluginImpl |
100 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
101 // |
81 // |
102 CESMRUrlParserPluginImpl::~CESMRUrlParserPluginImpl() |
82 CESMRUrlParserPluginImpl::~CESMRUrlParserPluginImpl() |
103 { |
83 { |
104 FUNC_LOG; |
84 FUNC_LOG; |
105 iFile.Close(); |
85 |
106 iFs.Close(); |
86 delete iParser; |
107 } |
87 delete iEncoder; |
108 |
88 delete iExtension; |
109 // --------------------------------------------------------------------------- |
89 |
|
90 ReleaseLandmarkResources(); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CESMRUrlParserPluginImpl::FindLocationUrl |
110 // Finds location URL from given text input |
95 // Finds location URL from given text input |
111 // --------------------------------------------------------------------------- |
96 // --------------------------------------------------------------------------- |
112 // |
97 // |
113 TInt CESMRUrlParserPluginImpl::FindLocationUrl( const TDesC& aText, |
98 TInt CESMRUrlParserPluginImpl::FindLocationUrl( |
114 TPtrC& aUrl ) |
99 const TDesC& aText, |
115 |
100 TPtrC& aUrl ) |
116 { |
101 |
117 FUNC_LOG; |
102 { |
|
103 FUNC_LOG; |
|
104 |
118 TInt pos(0); |
105 TInt pos(0); |
119 TRAPD( error, pos = DoFindLocationUrlL( aText, aUrl ) ); |
106 TRAPD( error, DoFindLocationUrlL( aText, pos, aUrl ) ); |
120 if ( error != KErrNone ) |
107 if ( error != KErrNone ) |
121 { |
108 { |
122 return error; |
109 return error; |
123 } |
110 } |
124 else |
111 else |
126 return pos; |
113 return pos; |
127 } |
114 } |
128 } |
115 } |
129 |
116 |
130 // --------------------------------------------------------------------------- |
117 // --------------------------------------------------------------------------- |
|
118 // CESMRUrlParserPluginImpl::CreateUrlFromLandmarkL |
|
119 // Creates location URL from landmark object |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 HBufC* CESMRUrlParserPluginImpl::CreateUrlFromLandmarkL( |
|
123 const CPosLandmark& aLandmark ) |
|
124 { |
|
125 FUNC_LOG; |
|
126 |
|
127 CPosLandmarkEncoder& encoder = InitializeEncoderL(); |
|
128 CBufBase* buffer = encoder.SetUseOutputBufferL(); |
|
129 CleanupStack::PushL( buffer ); |
|
130 encoder.AddLandmarkL( aLandmark ); |
|
131 CPosLmOperation* operation = encoder.FinalizeEncodingL(); |
|
132 ExecuteAndDeleteLD( operation ); |
|
133 |
|
134 // Convert URL to Unicode and escape encode non-ASCII characters |
|
135 HBufC* unicode = EscapeUtils::ConvertToUnicodeFromUtf8L( buffer->Ptr( 0 ) ); |
|
136 CleanupStack::PushL( unicode ); |
|
137 HBufC* url = EscapeUtils::EscapeEncodeL( *unicode, EscapeUtils::EEscapeNormal ); |
|
138 |
|
139 CleanupStack::PopAndDestroy( 2, buffer ); // unicode |
|
140 |
|
141 //Transfer ownership of url |
|
142 return url; |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CESMRUrlParserPluginImpl::CreateLandmarkFromUrlL |
|
148 // Creates landmark object from location URL |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 CPosLandmark* CESMRUrlParserPluginImpl::CreateLandmarkFromUrlL( |
|
152 const TDesC& aUrl ) |
|
153 { |
|
154 FUNC_LOG; |
|
155 |
|
156 CPosLandmark* landmark = NULL; |
|
157 |
|
158 // Try to create landmark using landmark parser |
|
159 TRAPD( error, landmark = CreateLandmarkFromUrlInternalL( aUrl ) ); |
|
160 |
|
161 if ( error ) |
|
162 { |
|
163 // Try extension |
|
164 landmark = ExtensionL().CreateLandmarkFromUrlL( aUrl ); |
|
165 } |
|
166 |
|
167 //transfer ownership |
|
168 return landmark; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CESMRUrlParserPluginImpl::CreateGeoValueLC |
|
173 // Converts URL to Calendar GEO property |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 CCalGeoValue* CESMRUrlParserPluginImpl::CreateGeoValueLC( const TDesC& aUrl ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 |
|
180 // Convert URL to landmark |
|
181 CPosLandmark* landmark = CreateLandmarkFromUrlL( aUrl ); |
|
182 CleanupStack::PushL( landmark ); |
|
183 |
|
184 // Get position data from landmark |
|
185 TLocality position; |
|
186 User::LeaveIfError( landmark->GetPosition( position ) ); |
|
187 CleanupStack::PopAndDestroy( landmark ); |
|
188 |
|
189 // Convert position data to GEO value |
|
190 CCalGeoValue* geoVal = CCalGeoValue::NewL(); |
|
191 CleanupStack::PushL( geoVal ); |
|
192 geoVal->SetLatLongL( position.Latitude(), position.Longitude() ); |
|
193 |
|
194 return geoVal; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CESMRUrlParserPluginImpl::InitializeParserL |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 CPosLandmarkParser& CESMRUrlParserPluginImpl::InitializeParserL() |
|
202 { |
|
203 FUNC_LOG; |
|
204 |
|
205 if ( !iParser ) |
|
206 { |
|
207 iParser = CPosLandmarkParser::NewL( KLandmarkUrlMimeType ); |
|
208 } |
|
209 |
|
210 return *iParser; |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CESMRUrlParserPluginImpl::InitializeEncoderL |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 CPosLandmarkEncoder& CESMRUrlParserPluginImpl::InitializeEncoderL() |
|
218 { |
|
219 FUNC_LOG; |
|
220 |
|
221 delete iEncoder; |
|
222 iEncoder = NULL; |
|
223 iEncoder = CPosLandmarkEncoder::NewL( KLandmarkUrlMimeType ); |
|
224 return *iEncoder; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // CESMRUrlParserPluginImpl::DoFindLocationUrlL |
131 // Finds location URL from given text input |
229 // Finds location URL from given text input |
132 // --------------------------------------------------------------------------- |
230 // --------------------------------------------------------------------------- |
133 // |
231 // |
134 TInt CESMRUrlParserPluginImpl::DoFindLocationUrlL( // codescanner::intleaves |
232 |
135 const TDesC& aText, |
233 void CESMRUrlParserPluginImpl::DoFindLocationUrlL( |
136 TPtrC& aUrl ) |
234 const TDesC& aText, |
137 { |
235 TInt& aPos, |
138 FUNC_LOG; |
236 TPtrC& aUrl ) |
139 //If this parserplugin instance is not yet initialized |
237 { |
140 //init it now |
238 FUNC_LOG; |
141 if( !iIsInitialized ) |
239 |
142 { |
240 aPos = KErrNotFound; |
143 InitializeL(); |
241 aUrl.Set( KNullDesC ); |
144 } |
242 |
145 |
243 // Search URL from given text |
146 //Read basestring from resource file |
244 CFindItemEngine* itemEngine = CFindItemEngine::NewL( |
147 HBufC* baseString = ReadResourceStringLC(R_QTN_LOCATION_URL); |
245 aText, |
148 |
246 CFindItemEngine::EFindItemSearchURLBin ); |
149 //Seach if base string is found from aText |
247 CleanupStack::PushL (itemEngine ); |
150 TInt urlLocation = aText.Find(*baseString); |
248 |
151 CleanupStack::PopAndDestroy(baseString); |
249 // For each found item |
152 if( urlLocation < KErrNone ) |
250 CFindItemEngine::SFoundItem item; |
153 { |
251 itemEngine->Item( item ); |
154 User::Leave(KErrNotFound); |
252 |
155 } |
253 TInt itemCount = itemEngine->ItemCount(); |
156 |
254 for ( TInt i = 0; i < itemCount; ++i ) |
157 //Take out unnecessary part before URL and search if endmark (whitespace) |
255 { |
158 //is found. If endmark is not found, |
256 TPtrC url = aText.Mid( item.iStartPos, item.iLength ); |
159 //then all the rest of descriptor is part of URL |
257 |
160 HBufC* urlAndAfterBuf = aText.Mid( urlLocation ).AllocLC(); |
258 CPosLandmark* landmark = NULL; |
161 TInt urlAndAfterBufLength = urlAndAfterBuf->Length(); |
259 TRAPD( error, landmark = CreateLandmarkFromUrlL( url ); ) |
162 TInt urlEndmarkLocation = KErrNotFound; |
260 delete landmark; |
163 |
261 |
164 for( TInt i = 0; i < urlAndAfterBufLength; i++) |
262 if ( !error ) // Location url found |
165 { |
|
166 if( TChar( (*urlAndAfterBuf)[i] ).IsSpace() ) |
|
167 { |
263 { |
168 urlEndmarkLocation = i; |
264 aPos = item.iStartPos; |
|
265 aUrl.Set( url ); |
|
266 // Stop iteration |
169 break; |
267 break; |
170 } |
268 } |
171 } |
269 else |
172 |
270 { |
173 if( urlEndmarkLocation == KErrNotFound ) |
271 itemEngine->NextItem( item ); |
174 { |
272 } |
175 urlEndmarkLocation = urlAndAfterBufLength; |
273 } |
176 } |
274 |
177 |
275 CleanupStack::PopAndDestroy( itemEngine ); |
178 //Take out part from beginning of URL to endmark |
276 |
179 HBufC* urlToEndMark = urlAndAfterBuf->Left( urlEndmarkLocation ).AllocLC(); |
277 if ( aPos < 0 ) |
180 |
278 { |
181 //Now we should have only URL left, check with "sieve" that it is about in |
279 ExtensionL().FindLocationUrlL( aText, aUrl, aPos ); |
182 //right format |
280 } |
183 HBufC* sieve = ReadResourceStringLC(R_QTN_LOCATION_SIEVE_URL); |
281 } |
184 TInt sievedStartPoint = urlToEndMark->Match( *sieve ); |
282 |
185 |
283 // --------------------------------------------------------------------------- |
186 CleanupStack::PopAndDestroy(sieve); |
284 // CESMRUrlParserPluginImpl::ExtensionL |
187 CleanupStack::PopAndDestroy(urlToEndMark); |
285 // --------------------------------------------------------------------------- |
188 CleanupStack::PopAndDestroy(urlAndAfterBuf); |
286 // |
189 |
287 CMRUrlParserExtension& CESMRUrlParserPluginImpl::ExtensionL() |
190 if( sievedStartPoint == KErrNotFound ) |
288 { |
191 { |
289 FUNC_LOG; |
192 User::Leave(KErrNotFound); |
290 |
193 } |
291 if ( !iExtension ) |
194 |
292 { |
195 //Check that parameters are in right format |
293 iExtension = CMRUrlParserExtension::NewL(); |
196 TPtrC latValue; |
294 } |
197 TPtrC lonValue; |
295 |
198 |
296 return *iExtension; |
199 GetCoordinateParamValuesL( aText.Mid(urlLocation,urlEndmarkLocation), |
297 } |
200 latValue, lonValue ); |
298 |
201 CheckCoordinateParamL( latValue ); |
299 // --------------------------------------------------------------------------- |
202 CheckCoordinateParamL( lonValue ); |
300 // CESMRUrlParserPluginImpl::CreateLandmarkFromUrlInternalL |
203 |
|
204 //Set aURL to correspond URL part of aText and return with url position |
|
205 aUrl.Set( aText.Mid(urlLocation,urlEndmarkLocation)); |
|
206 return urlLocation; |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Creates location URL from landmark object |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 HBufC* CESMRUrlParserPluginImpl::CreateUrlFromLandmarkL( |
|
215 const CPosLandmark& aLandmark ) |
|
216 { |
|
217 FUNC_LOG; |
|
218 //If this parserplugin instance is not yet initialized |
|
219 //init it now |
|
220 if( !iIsInitialized ) |
|
221 { |
|
222 InitializeL(); |
|
223 } |
|
224 |
|
225 //Take longitude and latitude out of landmark |
|
226 TLocality position; |
|
227 User::LeaveIfError( aLandmark.GetPosition( position ) ); |
|
228 TReal64 latitude = position.Latitude(); |
|
229 TReal64 longitude = position.Longitude(); |
|
230 |
|
231 //Define TReal format type |
|
232 TRealFormat format( KCoordinateMaxLength ); |
|
233 format.iType = KRealFormatFixed; |
|
234 format.iPlaces = KNumberOfDecimals; |
|
235 format.iPoint = TChar(KDecimalSeparator); |
|
236 |
|
237 //Read strings from resourcefile |
|
238 HBufC* baseUrl = ReadResourceStringLC( R_QTN_LOCATION_URL ); |
|
239 HBufC* lat = ReadResourceStringLC( R_QTN_LOCATION_URL_LATITUDE ); |
|
240 HBufC* separator = ReadResourceStringLC( R_QTN_LOCATION_URL_PARAM_SEPARATOR ); |
|
241 HBufC* lon = ReadResourceStringLC( R_QTN_LOCATION_URL_LONGITUDE ); |
|
242 |
|
243 //Concatenate all strings and coordinates |
|
244 HBufC* url = HBufC::NewL( baseUrl->Length() + lat->Length() + separator->Length() |
|
245 + lon->Length() + format.iWidth + format.iWidth ); |
|
246 TPtr pointer = url->Des(); |
|
247 pointer.Append( *baseUrl ); |
|
248 pointer.Append( *lat ); |
|
249 pointer.AppendNum( latitude, format ); |
|
250 pointer.Append( *separator ); |
|
251 pointer.Append( *lon ); |
|
252 pointer.AppendNum( longitude, format ); |
|
253 |
|
254 CleanupStack::PopAndDestroy( lon ); |
|
255 CleanupStack::PopAndDestroy( separator ); |
|
256 CleanupStack::PopAndDestroy( lat ); |
|
257 CleanupStack::PopAndDestroy( baseUrl ); |
|
258 |
|
259 //Transfer ownership of url |
|
260 return url; |
|
261 } |
|
262 |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Creates landmark object from location URL |
301 // Creates landmark object from location URL |
266 // --------------------------------------------------------------------------- |
302 // --------------------------------------------------------------------------- |
267 // |
303 // |
268 CPosLandmark* CESMRUrlParserPluginImpl::CreateLandmarkFromUrlL( |
304 CPosLandmark* CESMRUrlParserPluginImpl::CreateLandmarkFromUrlInternalL( |
269 const TDesC& aUrl ) |
305 const TDesC& aUrl ) |
270 { |
306 { |
271 FUNC_LOG; |
307 FUNC_LOG; |
272 //If this parserplugin instance is not yet initialized |
308 |
273 //init it now |
309 // Decode URL and convert it to UTF-8 format |
274 if( !iIsInitialized ) |
310 HBufC* decodedUrl = EscapeUtils::EscapeDecodeL( aUrl ); |
275 { |
311 CleanupStack::PushL( decodedUrl ); |
276 InitializeL(); |
312 HBufC8* url = EscapeUtils::ConvertFromUnicodeToUtf8L( *decodedUrl ); |
277 } |
313 CleanupStack::PopAndDestroy( decodedUrl ); |
278 |
314 CleanupStack::PushL( url ); |
279 //Read sieve from resourcefile and check if URL matches the sieveformat |
315 |
280 HBufC* sieve = ReadResourceStringLC( R_QTN_LOCATION_SIEVE_URL ); |
316 // Create landmark using correct parser |
281 TInt matchPos = User::LeaveIfError( aUrl.Match( *sieve ) ); |
317 CPosLandmarkParser& parser = InitializeParserL(); |
282 CleanupStack::PopAndDestroy( sieve ); |
318 parser.SetInputBuffer( *url ); |
283 if( matchPos != 0 ) |
319 CPosLmOperation* operation = parser.ParseContentL(); |
284 { |
320 ExecuteAndDeleteLD( operation ); |
285 //URL was found but is not int the beginning of desc |
321 CPosLandmark* landmark = parser.LandmarkLC(); |
286 User::Leave( KErrArgument ); |
|
287 } |
|
288 |
|
289 //Parse actual coordinate values out of url |
|
290 TPtrC latValue; |
|
291 TPtrC lonValue; |
|
292 GetCoordinateParamValuesL( aUrl, latValue, lonValue ); |
|
293 |
|
294 //Check that parameters are in right format |
|
295 CheckCoordinateParamL( latValue ); |
|
296 CheckCoordinateParamL( lonValue ); |
|
297 |
|
298 //Convert parameters to TReal values |
|
299 TLex lexConverter( latValue ); |
|
300 TReal64 realLatitude; |
|
301 lexConverter.Val( realLatitude ); |
|
302 |
|
303 lexConverter.Assign( lonValue ); |
|
304 TReal64 realLongitude; |
|
305 lexConverter.Val( realLongitude ); |
|
306 |
|
307 //Create landmark with coordinatevalues |
|
308 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
309 TLocality position; |
|
310 position.SetCoordinate( realLatitude, realLongitude ); |
|
311 landmark->SetPositionL( position ); |
|
312 CleanupStack::Pop( landmark ); |
322 CleanupStack::Pop( landmark ); |
|
323 CleanupStack::PopAndDestroy( url ); |
|
324 |
313 //transfer ownership |
325 //transfer ownership |
314 return landmark; |
326 return landmark; |
315 } |
327 } |
316 |
328 |
317 // ---------------------------------------------------------------------------- |
|
318 // CESMRUrlParserPluginImpl::LocateResourceFile |
|
319 // |
|
320 // For locating resource file |
|
321 // ---------------------------------------------------------------------------- |
|
322 // |
|
323 TInt CESMRUrlParserPluginImpl::LocateResourceFile( |
|
324 const TDesC& aResource, |
|
325 const TDesC& aPath, |
|
326 TFileName &aResourceFile, |
|
327 RFs* aFs ) |
|
328 { |
|
329 FUNC_LOG; |
|
330 TFindFile resourceFile( *aFs ); |
|
331 TInt err = resourceFile.FindByDir( |
|
332 aResource, |
|
333 aPath ); |
|
334 |
|
335 if ( KErrNone == err ) |
|
336 { |
|
337 aResourceFile.Copy( resourceFile.File() ); |
|
338 } |
|
339 else |
|
340 { |
|
341 const TChar KFileFormatDelim( '.' ); |
|
342 TFileName locResourceFile; |
|
343 |
|
344 TInt pos = aResource.LocateReverse( KFileFormatDelim ); |
|
345 if ( pos != KErrNotFound ) |
|
346 { |
|
347 locResourceFile.Copy( aResource.Mid(0, pos + 1) ); |
|
348 |
|
349 TInt language( User::Language() ); |
|
350 locResourceFile.AppendFormat( KResourceFileLocFormat, language ); |
|
351 |
|
352 TFindFile resourceFile( *aFs ); |
|
353 err = resourceFile.FindByDir( |
|
354 locResourceFile, |
|
355 aPath ); |
|
356 |
|
357 if ( KErrNone == err ) |
|
358 { |
|
359 aResourceFile.Copy( resourceFile.File() ); |
|
360 aResourceFile.Replace( |
|
361 aResourceFile.Length() - KResourceFormat().Length(), |
|
362 KResourceFormat().Length(), |
|
363 KResourceFormat() ); |
|
364 } |
|
365 } |
|
366 } |
|
367 |
|
368 |
|
369 return err; |
|
370 } |
|
371 |
|
372 // ---------------------------------------------------------------------------- |
|
373 // CESMRUrlParserPluginImpl::InitializeL |
|
374 // |
|
375 // Initializes resources |
|
376 // ---------------------------------------------------------------------------- |
|
377 // |
|
378 void CESMRUrlParserPluginImpl::InitializeL() |
|
379 { |
|
380 FUNC_LOG; |
|
381 if( iIsInitialized ) |
|
382 { |
|
383 return; |
|
384 } |
|
385 //Connect to RFs session |
|
386 User::LeaveIfError( iFs.Connect( KFileServerDefaultMessageSlots ) ); |
|
387 |
|
388 //Find and open resource file containing URL strings |
|
389 TFileName fileName; |
|
390 User::LeaveIfError( LocateResourceFile( KResourceName, |
|
391 KDC_RESOURCE_FILES_DIR, |
|
392 fileName, |
|
393 &iFs ) ); |
|
394 iFile.OpenL( iFs, fileName ); |
|
395 iFile.ConfirmSignatureL(); |
|
396 iIsInitialized = ETrue; |
|
397 } |
|
398 |
|
399 // ---------------------------------------------------------------------------- |
|
400 // CESMRUrlParserPluginImpl::ReadResourceStringLC |
|
401 // Reads resource string from specified id |
|
402 // ---------------------------------------------------------------------------- |
|
403 // |
|
404 HBufC* CESMRUrlParserPluginImpl::ReadResourceStringLC( TInt aResourceId ) |
|
405 { |
|
406 FUNC_LOG; |
|
407 HBufC8* string = iFile.AllocReadLC(aResourceId); |
|
408 iReader.SetBuffer(string); |
|
409 HBufC* stringBuffer = iReader.ReadTPtrC().AllocL(); |
|
410 CleanupStack::PopAndDestroy( string ); |
|
411 CleanupStack::PushL( stringBuffer ); |
|
412 //stringBuffer ownership is transfered |
|
413 return stringBuffer; |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------------------------------- |
|
417 // CESMRUrlParserPluginImpl::CheckCoordinateParam |
|
418 // |
|
419 // Checks if coordinate parameter (lon or lat) is in correct format |
|
420 // Leaves if not |
|
421 // Correct form is: |
|
422 // -minus sign allowed only in first position |
|
423 // -only one decimalseparator sign allowed |
|
424 // -only digits allowed |
|
425 // -aParam length not allowed to be zero |
|
426 // ---------------------------------------------------------------------------- |
|
427 // |
|
428 void CESMRUrlParserPluginImpl::CheckCoordinateParamL( const TDesC& aParam ) |
|
429 { |
|
430 FUNC_LOG; |
|
431 if( aParam.Length() == 0 ) |
|
432 { |
|
433 User::Leave( KErrArgument ); |
|
434 } |
|
435 |
|
436 //check that aParam contains only digits and only one decimalseparator |
|
437 //and minus sign is first, if it exists |
|
438 TChar character; |
|
439 TBool decimalSeparatorFound = EFalse; |
|
440 TLex lex; |
|
441 lex.Assign( aParam ); |
|
442 const TUint KMinusSign = '-'; |
|
443 |
|
444 for( TInt i = 0; i < aParam.Length(); i++) |
|
445 { |
|
446 character = lex.Get(); |
|
447 //checks if first character is minus sign and continues if it is |
|
448 if( i == 0 && (TUint)character == KMinusSign) |
|
449 { |
|
450 continue; |
|
451 } |
|
452 //check that only one decimalseparator exists |
|
453 if( (TUint)character == KDecimalSeparator ) |
|
454 { |
|
455 if( decimalSeparatorFound ) |
|
456 { |
|
457 User::Leave( KErrArgument ); |
|
458 } |
|
459 else |
|
460 { |
|
461 decimalSeparatorFound = ETrue; |
|
462 } |
|
463 } |
|
464 //check that character is either digit or decimalseparator |
|
465 if( !( character.IsDigit() ) && (TUint)character != KDecimalSeparator ) |
|
466 { |
|
467 User::Leave( KErrArgument ); |
|
468 } |
|
469 } |
|
470 } |
|
471 |
|
472 // ---------------------------------------------------------------------------- |
|
473 // CESMRUrlParserPluginImpl::GetCoordinateParamValuesL |
|
474 // Returns longitude and latitude if found correctly |
|
475 // ---------------------------------------------------------------------------- |
|
476 // |
|
477 void CESMRUrlParserPluginImpl::GetCoordinateParamValuesL( const TDesC& aUrl, |
|
478 TPtrC& aLatitude, |
|
479 TPtrC& aLongitude ) |
|
480 { |
|
481 FUNC_LOG; |
|
482 //Read latitude and longitude strings from resourcefile |
|
483 HBufC* lat = ReadResourceStringLC( R_QTN_LOCATION_URL_LATITUDE ); |
|
484 HBufC* lon = ReadResourceStringLC( R_QTN_LOCATION_URL_LONGITUDE ); |
|
485 HBufC* separator = ReadResourceStringLC( R_QTN_LOCATION_URL_PARAM_SEPARATOR ); |
|
486 |
|
487 //Find out if lat and lon params and separator exists in aUrl |
|
488 TInt latPos = aUrl.Find( *lat ); |
|
489 TInt lonPos = aUrl.Find( *lon ); |
|
490 TInt separatorPos = aUrl.Find( *separator ); |
|
491 if( latPos == KErrNotFound || lonPos == KErrNotFound |
|
492 || separatorPos == KErrNotFound ) |
|
493 { |
|
494 User::Leave( KErrNotFound ); |
|
495 } |
|
496 |
|
497 //takes from aUrl parts with actual coordinate data |
|
498 aLatitude.Set( aUrl.Mid( latPos + lat->Length(), separatorPos - latPos - lat->Length() ) ); |
|
499 aLongitude.Set( aUrl.Right( aUrl.Length() - separatorPos - 1 - lon->Length() ) ); |
|
500 |
|
501 CleanupStack::PopAndDestroy( separator ); |
|
502 CleanupStack::PopAndDestroy( lon ); |
|
503 CleanupStack::PopAndDestroy( lat ); |
|
504 } |
|
505 //EOF |
329 //EOF |
506 |
330 |