Class: UAProfToWURLF

Inherits:
Object
  • Object
show all
Defined in:
lib/wurfl/uaproftowurfl.rb

Overview

A class to handle reading a UAProfile and generating an equivalent WURFL entry. See wurfl.sourceforge.net/ for more details about the WURFL. Authors: Zev Blut, Paul McMahon ([email protected]) Version: 1.1 Additional mappings added from Andrea Trasatti Version: 1.2 More mappings added from Andrea Trasatti Version: 1.3 more mappings and a few changes for error handling.

Instance Method Summary collapse

Constructor Details

#initializeUAProfToWURLF

Returns a new instance of UAProfToWURLF.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wurfl/uaproftowurfl.rb', line 12

def initialize
  # The WURFL is considered a hashtable of hashtables for all the
  # wurfl groups.
  @wurfl = Hash.new
  #Initialize all of the sub hashes
  @wurflgroups = [
    "product_info","wml_ui","chtml_ui","xhtml_ui",
    "markup","cache","display","image_format","bugs",
    "wta","security","storage","downloadfun","wap_push",
    "j2me","mms","sound_format"
  ]
  @wurflgroups.each do |key|
    @wurfl[key] = Hash.new
  end    
  @wurfl["user_agent"] = ""
end

Instance Method Details

#AcceptDownloadableSoftware(element) ⇒ Object

SoftwarePlatform



173
174
175
# File 'lib/wurfl/uaproftowurfl.rb', line 173

def AcceptDownloadableSoftware(element)
  #?good to know?
end

#AudioInputEncoder(element) ⇒ Object Also known as: AudioInputEncorder



177
178
# File 'lib/wurfl/uaproftowurfl.rb', line 177

def AudioInputEncoder(element)
end

#BitsPerPixel(element) ⇒ Object



93
94
95
96
97
# File 'lib/wurfl/uaproftowurfl.rb', line 93

def BitsPerPixel(element)
  bits = element.text.to_i
  bits = 2 ** bits if bits !=2 
  @wurfl["image_format"]["colors"] = bits
end

#BluetoothProfile(element) ⇒ Object

Extra Components found from running on profs



863
864
# File 'lib/wurfl/uaproftowurfl.rb', line 863

def BluetoothProfile(element)
end

#break_num_x_num(val) ⇒ Object



931
932
933
934
935
936
937
# File 'lib/wurfl/uaproftowurfl.rb', line 931

def break_num_x_num(val)
  width = height = 0
  if m = /(\d*)x(\d*)/.match(val)
    width, height = m[1],m[2]
  end
  return width.to_i,height.to_i 
end

#BrowserName(element) ⇒ Object

These two can sometimes make the user agent?



570
571
572
# File 'lib/wurfl/uaproftowurfl.rb', line 570

def BrowserName(element)
  @wurfl["user_agent"]<< element.text
end

#BrowserVersion(element) ⇒ Object



574
575
576
# File 'lib/wurfl/uaproftowurfl.rb', line 574

def BrowserVersion(element)
  @wurfl["user_agent"]<< element.text
end

#CcppAccept(element) ⇒ Object

This one does a large amount of mapping



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/wurfl/uaproftowurfl.rb', line 181

def CcppAccept(element)   
  items = get_items_from_bag(element)
  items.each do |type|
    # Use regular expression comparisons to deal with values
    # that sometimes contain q or Type that we do not need
    # to bother with.
    case type
    when /^image\/jpeg/,"image/jpg"
	@wurfl["image_format"]["jpg"] = true 
    when /^image\/gif/
	@wurfl["image_format"]["gif"] = true
    when /image\/vnd\.wap\.wbmp/
	@wurfl["image_format"]["wbmp"] = true
    when /^image\/bmp/,"image/x-bmp"
	@wurfl["image_format"]["bmp"] = true
    when /^image\/png/
	@wurfl["image_format"]["png"] = true
    when "application/smil"
 ### Where is the SMAF in MMS of WURFL?###
    when "application/vnd.smaf","application/x-smaf","application/smaf"
	#how to determine mmf version?
	$stderr.puts "CcppAccept supports MMF but what number: #{type}"
    when "audio/amr","audio/x-amr"
	@wurfl["sound_format"]["amr"] = true
    when "audio/midi","audio/mid","audio/x-midi","audio/x-mid"
	@wurfl["sound_format"]["midi_monophonic"] = true
	# We can play it safe an say mono. what about poly?
    when "audio/sp-midi"
	@wurfl["sound_format"]["sp_midi"] = true  
    when "audio/wav","audio/x-wav","application/wav","application/x-wav"
	@wurfl["sound_format"]["wav"] = true  
    when "image/tiff"
	@wurfl["image_format"]["tiff"] = true
    when "audio/imelody","audio/x-imy","text/x-iMelody","text/iMelody","text/x-imelody","audio/iMelody"
	@wurfl["sound_format"]["imelody"] = true  
    when "application/vnd.nokia.ringing-tone"
	@wurfl["sound_format"]["nokia_ringtone"] = true  
    when "audio/mpeg3"
	@wurfl["sound_format"]["mp3"] = true  
    when "text/x-eMelody"
    when "text/x-vMel"
    when /^text\/plain/
    when "text/x-vCard"
    when "text/x-vCalendar"
    when "application/vnd.wap.mms-message"
    when "application/vnd.wap.multipart.mixed"
    when "application/vnd.wap.multipart.related"
    when "application/octet-stream"
    when "application/vnd.eri.thm"
    when "application/vnd.openwave.pp"
    when "application/vnd.phonecom.im"
    when "application/vnd.phonecom.mmc-wbxml"
    when "application/vnd.phonecom.mmc-wbxml;Type=4364"
    when "application/vnd.phonecom.mmc-xml"
    when "application/vnd.syncml-xml-wbxml"
    when "application/vnd.uplanet.alert"
    when "application/vnd.uplanet.alert-wbxml"
    when "application/vnd.uplanet.bearer-choice"
    when "application/vnd.uplanet.bearer-choice-wbxml"
    when "application/vnd.uplanet.cacheop"
    when "application/vnd.uplanet.cacheop-wbxml"
    when "application/vnd.uplanet.channel"
    when "application/vnd.uplanet.channel-wbxml"
    when "application/vnd.uplanet.list"
    when "application/vnd.uplanet.listcmd"
    when "application/vnd.uplanet.listcmd-wbxml"
    when "application/vnd.uplanet.list-wbxml"
    when "application/vnd.uplanet.provisioning-status-uri"
    when "application/vnd.uplanet.signal"
    when "application/vnd.wap.coc"
    when "application/vnd.wap.multipart.header-set"
    when "application/vnd.wap.sia"
    when "application/vnd.wap.sic"
    when "application/vnd.wap.slc"
    when "application/vnd.wap.si"
    when "application/vnd.wap.sl"
	#The si and sl are probably related to the sia/sic and slc?
    when "application/vnd.wap.wbxml"
    when /^application\/vnd\.wap\.wmlc/i
	#"application/vnd.wap.wmlc;Level=1.3"
	#"application/vnd.wap.wmlc;Type=1108"
	#"application/vnd.wap.wmlc;Type=4360"
	#"application/vnd.wap.wmlc;Type=4365"
    when /application\/vnd\.wap\.wml(.)?scriptc/i
    when "application/vnd.wap.wtls-ca-certificate"
    when "application/vnd.wap.wtls-user-certificate"
    when "application/vnd.wap.xhtml+xml","application/xhtml+xml",
 "application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\""
    when "application/xml"
    when /application\/x-mmc\./
      @wurfl["downloadfun"]["downloadfun_support"] = true
      # There is much Download Fun logic to do here
      # A few examples of what we may get are included

      val = parse_download_fun_accept(type)
      if val.nil?
        next
        # Then we probably received one of these what to do about them?
        #  when "application/x-mmc.title;charset=us-ascii;size=255"
        #  when "application/x-mmc.title;charset=us-ascii;size=30"
        #  when "application/x-mmc.title;charset=UTF-8;size=80"
      end
      
      case val["object-type"]
      when "audio","ringtone"
        #application/x-mmc.audio;Content-Type=audio/midi;size=25600;voices=16
        #application/x-mmc.ringtone;Content-Type=audio/x-sagem1.0;size=1000
        #application/x-mmc.ringtone;Content-Type=audio/x-sagem2.0;size=5500
        #application/x-mmc.ringtone;Content-Type=audio/x-wav;codec=pcm;samp=8000;res=16;size=200000
        #application/x-mmc.ringtone;Content-Type=audio/x-wav;codec=pcm;samp=8000;res=8,16;size=200000
        @wurfl["downloadfun"]["ringtone"] = true
        case val["content-type"]
        when "audio/midi","audio/mid","audio/x-midi","audio/x-mid"
          @wurfl["downloadfun"]["ringtone_midi_monophonic"] = true
        when "audio/imelody","audio/x-imy","text/x-iMelody","text/iMelody","text/x-imelody"
          @wurfl["downloadfun"]["ringtone_imelody"] = true
        else
          $stderr.puts "CcppAccept unknown download fun audio Content-Type: #{val["content-type"]}"
        end

        if val.key?("voices")
          set_value_if_greater(@wurfl["sound_format"],"voices",val["voices"].to_i)
          # determine if it has multiple voices and does midi to set 
          # the polyphonic value
          if val["voices"].to_i > 1 && val["content-type"] =~ /midi/
            @wurfl["downloadfun"]["ringtone_midi_polyphonic"] = true
            @wurfl["sound_format"]["midi_polyphonic"] = true
          end
        end
        if val.key?("size")
          set_value_if_greater(@wurfl["downloadfun"],"ringtone_size_limit",val["size"].to_i)
        end
        
      when "picture"
        #application/x-mmc.picture;Content-Type=image/bmp;size=25600;color=8;h=120;w=136
        #application/x-mmc.picture;Content-Type=image/bmp;size=38000;color=16M;h=96;w=128
        #application/x-mmc.picture;Content-Type=image/gif;size=16000;color=256;h=96;w=128
        #application/x-mmc.picture;Content-Type=image/vnd.wap.wbmp;size=25600;gray=1;h=120;w=136
        #application/x-mmc.picture;Content-Type=image/wbmp;size=2000;gray=1;h=96;w=128
        @wurfl["downloadfun"]["picture"] = true
        case val["content-type"]
        when "image/bmp","image/x-bmp"
          @wurfl["downloadfun"]["picture_bmp"] = true
        when "image/gif"
          @wurfl["downloadfun"]["picture_gif"] = true
        when /wbmp/
          @wurfl["downloadfun"]["picture_wbmp"] = true
        when "image/jpeg","image/jpg"
          @wurfl["downloadfun"]["picture_jpg"] = true
        when "image/png"
          @wurfl["downloadfun"]["picture_png"] = true
        else
          $stderr.puts "CcppAccept unknown download fun picture content-type: #{val["content-type"]}"
        end

        if val.key?("gray")
          @wurfl["downloadfun"]["picture_greyscale"] = true
        end
        if val.key?("h")
          set_value_if_greater(@wurfl["downloadfun"],"picture_height",val["h"].to_i)
        end
        if val.key?("w")
          set_value_if_greater(@wurfl["downloadfun"],"picture_width",val["w"].to_i)
        end
        if val.key?("size")
          set_value_if_greater(@wurfl["downloadfun"],"picture_size_limit",val["size"].to_i)
        end
        if val.key?("color")
          val["color"]  = convert_download_fun_color(val["color"])
          set_value_if_greater(@wurfl["downloadfun"],"picture_colors",val["color"].to_i)
        end
      when "screensaver"
        #application/x-mmc.screensaver;Content-Type=image/png;size=25600;color=8;h=120;w=136
        #application/x-mmc.screensaver;Content-Type=image/png;size=32000;color=16M;h=96;w=128
        @wurfl["downloadfun"]["screensaver"] = true
        case val["content-type"]
        when "image/bmp","image/x-bmp"
          @wurfl["downloadfun"]["screensaver_bmp"] = true
        when "image/gif"
          @wurfl["downloadfun"]["screensaver_gif"] = true
        when /wbmp/
          @wurfl["downloadfun"]["screensaver_wbmp"] = true
        when "image/jpeg","image/jpg"
          @wurfl["downloadfun"]["screensaver_jpg"] = true
        when "image/png"
          @wurfl["downloadfun"]["screensaver_png"] = true
        else
          $stderr.puts "CcppAccept unknown download fun screensaver content-type: #{val["content-type"]}"
        end

        if val.key?("gray")
          @wurfl["downloadfun"]["screensaver_greyscale"] = true
        end
        if val.key?("h")
          set_value_if_greater(@wurfl["downloadfun"],"screensaver_height",val["h"].to_i)
        end
        if val.key?("w")
          set_value_if_greater(@wurfl["downloadfun"],"screensaver_width",val["w"].to_i)
        end
        if val.key?("size")
          set_value_if_greater(@wurfl["downloadfun"],"screensaver_size_limit",val["size"].to_i)
        end
        if val.key?("color")
          val["color"]  = convert_download_fun_color(val["color"])
          set_value_if_greater(@wurfl["downloadfun"],"screensaver_colors",val["color"].to_i)
        end
      when "wallpaper"
        #application/x-mmc.wallpaper;Content-Type=image/bmp;size=38000;color=16M;h=96;w=128
        #application/x-mmc.wallpaper;Content-Type=image/vnd.wap.wbmp;size=10240;gray=1;h=120;w=136
        #application/x-mmc.wallpaper;Content-Type=image/wbmp;size=2000;gray=1;h=96;w=128
        #application/x-mmc.wallpaper;type=image/bmp;size=2000;gray=1;w=101;h=64
        @wurfl["downloadfun"]["wallpaper"] = true
        case val["content-type"]
        when "image/bmp","image/x-bmp"
          @wurfl["downloadfun"]["wallpaper_bmp"] = true
        when "image/gif"
          @wurfl["downloadfun"]["wallpaper_gif"] = true
        when /wbmp/
          @wurfl["downloadfun"]["wallpaper_wbmp"] = true
        when "image/jpeg","image/jpg"
          @wurfl["downloadfun"]["wallpaper_jpg"] = true
        when "image/png"
          @wurfl["downloadfun"]["wallpaper_png"] = true
        else
          $stderr.puts "CcppAccept unknown download fun wallpaper content-type: #{val["content-type"]}"
        end

        if val.key?("gray")
          @wurfl["downloadfun"]["wallpaper_greyscale"] = true
        end
        if val.key?("h")
          set_value_if_greater(@wurfl["downloadfun"],"wallpaper_height",val["h"].to_i)
        end
        if val.key?("w")
          set_value_if_greater(@wurfl["downloadfun"],"wallpaper_width",val["w"].to_i)
        end
        if val.key?("size")
          set_value_if_greater(@wurfl["downloadfun"],"wallpaper_size_limit",val["size"].to_i)
        end
        if val.key?("color")
          val["color"]  = convert_download_fun_color(val["color"])
          set_value_if_greater(@wurfl["downloadfun"],"wallpaper_colors",val["color"].to_i)
        end

      else
        $stderr.puts "CcppAccept unknown download fun accept Object-Type: #{type}"
      end
      
    when "application/x-NokiaGameData"
    when "application/x-up-alert"
    when "application/x-up-cacheop"
    when "application/x-up-device"         
    when "image/vnd.nok-wallpaper"
    when "image/vnd.wap.wml" 
    when "image/vnd.wap.wmlscript"
      # the two above seem like errors
    when "image/x-MS-bmp"
    when "image/x-up-wpng"
    when "image/x-xbitmap"
    when "text/css"
    when "text/html"
    when "text/vnd.sun.j2me.app-descriptor"
	# Andrea: this means the device can download jad (J2ME)
    when "text/vnd.wap.co"
    when "text/vnd.wap.si"
    when "text/vnd.wap.sl"
      # can these be used to determine about WAP Push SI and SL styles?
	# Andrea: These should be valid to set the values for
	# Andrea: connectionoriented_<push>. I will need to check better,
	# Andrea: but from what I can remember, if connectionoriented is
	# Andrea: supported, connectionless should be supported too.
    when "text/vnd.wap.wml"
    when "text/vnd.wap.wmlc"
    when "text/vnd.wap.wmlscript"
    when "text/vnd.wap.wmlscriptc"
    when "text/x-co-desc"
    when "text/x-hdml"
    when "text/xml"
    when "text/x-wap.wml"
    when "video/x-mng"
    when "image/*"
    when "*/*"	
    else
	$stderr.puts "CcppAccept unknown accept type: #{type}"
    end
  end
end

#CcppAccept_Charset(element) ⇒ Object



469
470
# File 'lib/wurfl/uaproftowurfl.rb', line 469

def CcppAccept_Charset(element)
end

#CcppAccept_Encoding(element) ⇒ Object



472
473
# File 'lib/wurfl/uaproftowurfl.rb', line 472

def CcppAccept_Encoding(element)
end

#CcppAccept_Language(element) ⇒ Object



475
476
# File 'lib/wurfl/uaproftowurfl.rb', line 475

def CcppAccept_Language(element)
end

#CLIPlatform(element) ⇒ Object



544
545
# File 'lib/wurfl/uaproftowurfl.rb', line 544

def CLIPlatform(element)
end

#ColorCapable(element) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/wurfl/uaproftowurfl.rb', line 99

def ColorCapable(element)
  if element.text == "No"
    if @wurfl["image_format"].key?("colors")
	if @wurfl["image_format"]["colors"] > 2      
 @wurfl["image_format"]["greyscale"] = true
	end
    else
	$stderr.puts "ColorCapable called before BitsPerPixel, thus unable to determine if greyscale."
    end
  end
end

#convert_download_fun_color(color) ⇒ Object



980
981
982
983
984
985
986
987
988
989
990
# File 'lib/wurfl/uaproftowurfl.rb', line 980

def convert_download_fun_color(color)
  res = color
  if color =~ /M$/i
    # multiply it by a million
    res = color.to_i * 1000000
  elsif color =~ /K$"/i
    # multiply it by ten thousand
    res = color.to_i * 10000
  end
  return res
end

#convert_value(value) ⇒ Object

used to convert Yes/No to true false



949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'lib/wurfl/uaproftowurfl.rb', line 949

def convert_value(value)
  if value =~ /Yes/i
    return true
  elsif value =~ /No/i
    return false 
  end
  begin
    # try to convert to an integer
    return value.to_i
  rescue
  end
  # just leave it alone
  return value
end

#CPU(element) ⇒ Object



111
112
# File 'lib/wurfl/uaproftowurfl.rb', line 111

def CPU(element)
end

#CurrentBearerService(element) ⇒ Object



551
552
# File 'lib/wurfl/uaproftowurfl.rb', line 551

def CurrentBearerService(element)
end

#DownloadableBrowserApps(element) ⇒ Object



578
579
580
# File 'lib/wurfl/uaproftowurfl.rb', line 578

def DownloadableBrowserApps(element)
  # This might have some good information to work with
end

#DownloadableSoftwareSupport(element) ⇒ Object



478
479
480
# File 'lib/wurfl/uaproftowurfl.rb', line 478

def DownloadableSoftwareSupport(element)
  #=> "bagMapping"
end

#DrmClass(element) ⇒ Object

add the proposals to WURFL for download methods



735
736
737
# File 'lib/wurfl/uaproftowurfl.rb', line 735

def DrmClass(element)
  #=> ["drm/OMAv1_forward-lock","drm/OMAv1_combined_delivery","drm/OMAv1_separate_delivery"],
end

#DrmConstraints(element) ⇒ Object

> [“drm/OMAv1_forward-lock”,“drm/OMAv1_combined_delivery”,“drm/OMAv1_separate_delivery”],



738
739
# File 'lib/wurfl/uaproftowurfl.rb', line 738

def DrmConstraints(element)
end

#Email_URI_Schemes(element) ⇒ Object



531
532
# File 'lib/wurfl/uaproftowurfl.rb', line 531

def Email_URI_Schemes(element)
end

#FramesCapable(element) ⇒ Object



866
867
# File 'lib/wurfl/uaproftowurfl.rb', line 866

def FramesCapable(element)
end

#get_items_from_bag(element) ⇒ Object



939
940
941
942
943
944
945
946
# File 'lib/wurfl/uaproftowurfl.rb', line 939

def get_items_from_bag(element)
  items = Array.new
  return items if element.nil?
  element.elements.each("rdf:Bag/rdf:li") do |se|
    items<< se.text
  end    
  return items
end

#HtmlVersion(element) ⇒ Object



582
583
584
585
586
587
588
589
590
591
# File 'lib/wurfl/uaproftowurfl.rb', line 582

def HtmlVersion(element)
  version = element.text.to_i
  if version == 4
    @wurfl["markup"]["html4"] = true
  elsif version < 4 && version >= 3
    @wurfl["markup"]["html32"] = true      
  else
    $stderr.puts "HtmlVersion unknown version mapping:#{version}"
  end
end

#ImageCapable(element) ⇒ Object



114
115
# File 'lib/wurfl/uaproftowurfl.rb', line 114

def ImageCapable(element)
end

#InputCharSet(element) ⇒ Object



117
118
# File 'lib/wurfl/uaproftowurfl.rb', line 117

def InputCharSet(element)
end

#JavaAppletEnabled(element) ⇒ Object



593
594
# File 'lib/wurfl/uaproftowurfl.rb', line 593

def JavaAppletEnabled(element)
end

#JavaEnabled(element) ⇒ Object



482
483
484
# File 'lib/wurfl/uaproftowurfl.rb', line 482

def JavaEnabled(element)
  #=> "j2me",
end

#JavaPackage(element) ⇒ Object



534
535
536
537
# File 'lib/wurfl/uaproftowurfl.rb', line 534

def JavaPackage(element)
  $stderr.puts "JavaPackage:#{element.text}"
  # Would show the Motorola extension etc???
end

#JavaPlatform(element) ⇒ Object



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/wurfl/uaproftowurfl.rb', line 486

def JavaPlatform(element)
  items = get_items_from_bag(element)
  items.each do |platform|
    # Cheat and ignore the Versions for now
    case platform
    when /CLDC/i
	@wurfl["j2me"]["cldc_10"] = true
    when /MIDP/i
	@wurfl["j2me"]["midp_10"] = true
    when /Pjava/i
      @wurfl["j2me"]["personal_java"] = true
    else         
	$stderr.puts "JavaPlatform Mapping unknown for: #{platform}"
    end
  end
end

#JavaProtocol(element) ⇒ Object



539
540
541
542
# File 'lib/wurfl/uaproftowurfl.rb', line 539

def JavaProtocol(element)
  # Perhaps details SMS support etc?
  $stderr.puts "JavaProtocol:#{element.text}"
end

#JavaScriptEnabled(element) ⇒ Object



596
597
# File 'lib/wurfl/uaproftowurfl.rb', line 596

def JavaScriptEnabled(element)
end

#JavaScriptVersion(element) ⇒ Object



599
600
# File 'lib/wurfl/uaproftowurfl.rb', line 599

def JavaScriptVersion(element)
end

#JVMVersion(element) ⇒ Object



503
504
# File 'lib/wurfl/uaproftowurfl.rb', line 503

def JVMVersion(element)
end

#Keyboard(element) ⇒ Object



120
121
# File 'lib/wurfl/uaproftowurfl.rb', line 120

def Keyboard(element)
end

#make_method_name(method) ⇒ Object

escape the passed method name to something valid for Ruby



926
927
928
929
# File 'lib/wurfl/uaproftowurfl.rb', line 926

def make_method_name(method)
  # should do more, but will add them as errors occur
  method.gsub(/-/,"_")
end

#MExEClassmarks(element) ⇒ Object Also known as: MexeClassmark, MexeClassmarks



506
507
508
# File 'lib/wurfl/uaproftowurfl.rb', line 506

def MExEClassmarks(element)
  #has some interesting possibilitesfor matching MIDP/WAP Java...
end

#MexeSecureDomains(element) ⇒ Object



513
514
# File 'lib/wurfl/uaproftowurfl.rb', line 513

def MexeSecureDomains(element)
end

#MexeSpec(element) ⇒ Object



510
511
# File 'lib/wurfl/uaproftowurfl.rb', line 510

def MexeSpec(element)
end

#MmsCcppAccept(element) ⇒ Object



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/wurfl/uaproftowurfl.rb', line 795

def MmsCcppAccept(element)
  items = get_items_from_bag(element)
  items.each do |type|
    case type
    when "image/jpeg","image/jpg"
	@wurfl["mms"]["mms_jpeg_baseline"] = true 
	#what about progressive?
	# Andrea: is there any way to determine from the content type?
    when "image/gif" 
	@wurfl["mms"]["mms_gif_static"] = true
	#animated?
    when "image/vnd.wap.wbmp" 
	@wurfl["mms"]["mms_wbmp"] = true
    when "image/bmp"
	@wurfl["mms"]["mms_bmp"] = true
    when "image/png"
	@wurfl["mms"]["mms_png"] = true
    when "application/smil"
    when "application/x-sms"
    when "application/vnd.3gpp.sms"
 ### Where is the SMAF in MMS of WURFL?###
 # Andrea: we had never found a device supporting SMAF and MMS
 # Andrea: should be added
    when "application/vnd.smaf"
    when "application/x-smaf"
    when "audio/amr","audio/x-amr"
	@wurfl["mms"]["mms_amr"] = true
    when "audio/midi","audio/mid","audio/x-midi","audio/x-mid"
	@wurfl["mms"]["mms_midi_monophonic"] = true
	# We can play it safe an say mono. what about poly?
    when "audio/sp-midi"
	@wurfl["mms"]["mms_spmidi"] = true
    when "audio/wav","audio/x-wav","application/wav","application/x-wav"
      @wurfl["mms"]["mms_wav"] = true
    when "text/plain"
    when "text/x-vCard","text/x-vcard"
	@wurfl["mms"]["mms_vcard"] = true
    when "application/vnd.nokia.ringing-tone"
	@wurfl["mms"]["mms_nokia_ringingtone"] = true
    when "image/vnd.nok-wallpaper"
	@wurfl["mms"]["mms_nokia_wallpaper"] = true
    when "audio/x-beatnik-rmf","audio/x-rmf","audio/rmf"
	@wurfl["mms"]["mms_rmf"] = true
    when "application/vnd.symbian.install"
	@wurfl["mms"]["mms_symbian_install"] = true
    when "application/java-archive","application/x-java-archive"
	@wurfl["mms"]["mms_jar"] = true
    when "text/vnd.sun.j2me.app-descriptor"
	@wurfl["mms"]["mms_jad"] = true
    when "application/vnd.wap.wmlc"
	@wurfl["mms"]["mms_wmlc"] = true
    when "text/x-vCalendar"
    when "application/vnd.wap.mms-message"
    when "application/vnd.wap.multipart.mixed"
    when "application/vnd.wap.multipart.related"
    else
	$stderr.puts "MmsCcppAccept unknown accept type: #{type}"
    end
  end
end

#MmsCcppAcceptCharset(element) ⇒ Object Also known as: MmsCcppAccept_Charset, MmsCcppAcceptCharSet



856
857
# File 'lib/wurfl/uaproftowurfl.rb', line 856

def MmsCcppAcceptCharset(element)
end

#MmsCcppAcceptEncoding(element) ⇒ Object



872
873
# File 'lib/wurfl/uaproftowurfl.rb', line 872

def MmsCcppAcceptEncoding(element)
end

#MmsCcppAcceptLanguage(element) ⇒ Object



875
876
# File 'lib/wurfl/uaproftowurfl.rb', line 875

def MmsCcppAcceptLanguage(element)
end

#MmsMaxAudio(element) ⇒ Object



878
879
# File 'lib/wurfl/uaproftowurfl.rb', line 878

def MmsMaxAudio(element)
end

#MmsMaxComponents(element) ⇒ Object



881
882
# File 'lib/wurfl/uaproftowurfl.rb', line 881

def MmsMaxComponents(element)
end

#MmsMaxImage(element) ⇒ Object



884
885
886
# File 'lib/wurfl/uaproftowurfl.rb', line 884

def MmsMaxImage(element)
  # examples have Values of -1...
end

#MmsMaxImageResolution(element) ⇒ Object



789
790
791
792
793
# File 'lib/wurfl/uaproftowurfl.rb', line 789

def MmsMaxImageResolution(element)
  width,height = break_num_x_num(element.text)
  @wurfl["mms"]["mms_max_width"] = width
  @wurfl["mms"]["mms_max_height"] = height
end

#MmsMaxMessageSize(element) ⇒ Object

Need MMS Mappings taken from Siemens example MmsCharacteristics



784
785
786
787
# File 'lib/wurfl/uaproftowurfl.rb', line 784

def MmsMaxMessageSize(element)
  size = element.text.to_i
  @wurfl["mms"]["mms_max_size"] = size
end

#MmsMaxText(element) ⇒ Object



888
889
# File 'lib/wurfl/uaproftowurfl.rb', line 888

def MmsMaxText(element)
end

#MmsVersion(element) ⇒ Object



859
860
# File 'lib/wurfl/uaproftowurfl.rb', line 859

def MmsVersion(element)
end

#Model(element) ⇒ Object



123
124
125
# File 'lib/wurfl/uaproftowurfl.rb', line 123

def Model(element)
  @wurfl["product_info"]["model_name"] = element.text
end

#NumberOfSoftKeys(element) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/wurfl/uaproftowurfl.rb', line 127

def NumberOfSoftKeys(element)
  num = element.text.to_i
  if num > 0
    @wurfl["wml_ui"]["softkey_support"] = true
    @wurfl["j2me"]["j2me_softkeys"] = num # in theory we should only check this if j2me support exists
  end
end

#OmaDownload(element) ⇒ Object



740
741
742
# File 'lib/wurfl/uaproftowurfl.rb', line 740

def OmaDownload(element)
  # "download_methods/OMAv1_download"
end

#OSName(element) ⇒ Object



516
517
# File 'lib/wurfl/uaproftowurfl.rb', line 516

def OSName(element)
end

#OSVendor(element) ⇒ Object



519
520
# File 'lib/wurfl/uaproftowurfl.rb', line 519

def OSVendor(element)
end

#OSVersion(element) ⇒ Object



869
870
# File 'lib/wurfl/uaproftowurfl.rb', line 869

def OSVersion(element)
end

#output_WURFL(filters = nil) ⇒ Object

Generates a WURFL entry. For now simply outputs the XML to Standard Out.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/wurfl/uaproftowurfl.rb', line 70

def output_WURFL(filters=nil)
  puts "<device fall_back=\"generic\" id=\"UAProf\" user_agent=\"#{@wurfl["user_agent"]}\">"
  @wurflgroups.each do |group|
    next if @wurfl[group].size == 0 || (!filters.nil? && (@wurfl[group].keys & filters.to_a).size == 0)
    puts "  <group id=\"#{group}\">"
    @wurfl[group].sort.each do |key,value|
	next if !filters.nil? && !filters.include?(key)
	puts "    <capability name=\"#{key}\" value=\"#{value}\"/>"
    end
    puts "  </group>"
  end
  puts "</device>"
end

#OutputCharSet(element) ⇒ Object Also known as: OutputCharset



135
136
# File 'lib/wurfl/uaproftowurfl.rb', line 135

def OutputCharSet(element)
end

#parse_download_fun_accept(accept) ⇒ Object



992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/wurfl/uaproftowurfl.rb', line 992

def parse_download_fun_accept(accept)
  #application/x-mmc.object_type;content-type=format;size=n;other=y
  m = /application\/x-mmc\.(.*);(content-)?type=(.*);size=(\d*);(.*)/i.match(accept)
  return nil if m.nil? # no match

  res = Hash.new
  res["object-type"] = m[1]
  res["content-type"] = m[3]
  res["size"] = m[4]
  if m[5]
    others = m[5].split(";")
    others.each do |keypair|
      key,value = keypair.split("=")
      res[key] = value
    end
  end

  return res
end

#parse_UAProf(uaproffile) ⇒ Object

Takes a UAProfile file (in the future could also take a URL) and then calls the method named after each UAProfile entry. This then maps the UAProfile component entry to a WURFL entry. This method can be called multiple times to create patched WURFL entry.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wurfl/uaproftowurfl.rb', line 34

def parse_UAProf(uaproffile)
  file = File.new(uaproffile)
  begin
    doc = REXML::Document.new(file)
  rescue Exception => err
    $stderr.puts "Exception while parsing the UAProfile RDF file #{uaproffile}."
    $stderr.puts "This UAProfToWurfl instance is invalid."
    $stderr.puts err.class
    $stderr.puts err.message
    $stderr.puts err.backtrace
    return
  end

  #get rdf:Description ID as that says the profile of phone..?
  doc.elements.each("rdf:RDF/rdf:Description/prf:component/rdf:Description/*") do |element|
    #doc.elements.each("//rdf:Description/*") do |element|
    next if element.expanded_name == "rdf:type" #ignore the type value
    methodname = make_method_name(element.name)
    if self.respond_to?(methodname)
	begin
 method = self.method(methodname)
 method.call(element)
	rescue Exception => err
 $stderr.puts "Uncaught exception calling #{element.name}"
 $stderr.puts err.class
 $stderr.puts err.message
 $stderr.puts err.backtrace
	end
    else
	$stderr.puts "Undefined UAProf component: #{element.name}"
    end
  end
end

#PixelAspectRatio(element) ⇒ Object Also known as: PixelsAspectRatio



138
139
# File 'lib/wurfl/uaproftowurfl.rb', line 138

def PixelAspectRatio(element)
end

#PointingResolution(element) ⇒ Object



141
142
# File 'lib/wurfl/uaproftowurfl.rb', line 141

def PointingResolution(element)
end

#PreferenceForFrames(element) ⇒ Object



602
603
# File 'lib/wurfl/uaproftowurfl.rb', line 602

def PreferenceForFrames(element)
end

#Push_Accept(element) ⇒ Object

PushCharacteristics



745
746
747
748
749
750
751
# File 'lib/wurfl/uaproftowurfl.rb', line 745

def Push_Accept(element)
  set_wap_push
  items = get_items_from_bag(element)
  items.each do |type|
    $stderr.puts "Push_Accept unknown type: #{type}"
  end
end

#Push_Accept_AppID(element) ⇒ Object



770
771
772
773
# File 'lib/wurfl/uaproftowurfl.rb', line 770

def Push_Accept_AppID(element)
  set_wap_push
  #!! maps to confirmed and unconfirmed service indication/loads? !!
end

#Push_Accept_Charset(element) ⇒ Object



753
754
755
756
757
758
759
760
761
762
763
# File 'lib/wurfl/uaproftowurfl.rb', line 753

def Push_Accept_Charset(element)
  set_wap_push
  items = get_items_from_bag(items)
  items.each do |charset|     
    if charset =~ /utf8/i
	@wurfl["wap_push"]["utf8_support"] = true
    elsif charset =~ /iso8859/i
	@wurfl["wap_push"]["iso8859_support"] = true
    end
  end
end

#Push_Accept_Encoding(element) ⇒ Object



764
765
766
# File 'lib/wurfl/uaproftowurfl.rb', line 764

def Push_Accept_Encoding(element)
  set_wap_push
end

#Push_Accept_Language(element) ⇒ Object



767
768
769
# File 'lib/wurfl/uaproftowurfl.rb', line 767

def Push_Accept_Language(element)
  set_wap_push
end

#Push_MaxPushReq(element) ⇒ Object

Feels like the WURFL PUSH data is lacking in some items



778
779
780
# File 'lib/wurfl/uaproftowurfl.rb', line 778

def Push_MaxPushReq(element)
  set_wap_push
end

#Push_MsgSize(element) ⇒ Object

!! maps to confirmed and unconfirmed service indication/loads? !!



774
775
776
777
# File 'lib/wurfl/uaproftowurfl.rb', line 774

def Push_MsgSize(element)
  set_wap_push
  # Feels like the WURFL PUSH data is lacking in some items
end

#RecipientAppAgent(element) ⇒ Object



522
523
# File 'lib/wurfl/uaproftowurfl.rb', line 522

def RecipientAppAgent(element)
end

#ScreenSize(element) ⇒ Object



144
145
146
147
148
# File 'lib/wurfl/uaproftowurfl.rb', line 144

def ScreenSize(element)
  width, height = break_num_x_num(element.text)
  @wurfl["display"]["resolution_width"] = width
  @wurfl["display"]["resolution_height"] = height
end

#ScreenSizeChar(element) ⇒ Object



150
151
152
153
154
# File 'lib/wurfl/uaproftowurfl.rb', line 150

def ScreenSizeChar(element)
  columns,rows = break_num_x_num(element.text)
  @wurfl["display"]["columns"] = columns
  @wurfl["display"]["rows"] = rows
end

#SecuritySupport(element) ⇒ Object



554
555
556
557
558
559
560
561
562
# File 'lib/wurfl/uaproftowurfl.rb', line 554

def SecuritySupport(element)
  items = get_items_from_bag(element)
  items.each do |secure|
    if /WTLS/.match(secure)
	#check and just assume that this means https?
	#@wurfl["security"]["https_support"] = true
    end
  end
end

#set_value_if_greater(wurflhash, key, value) ⇒ Object



964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
# File 'lib/wurfl/uaproftowurfl.rb', line 964

def set_value_if_greater(wurflhash,key,value)
  if wurflhash.key?(key)
    if value.is_a?(Fixnum)
      if wurflhash[key] < value
        wurflhash[key] = value
      end
    else
      # Should probably just overwrite the entry then.
      $stderr.puts "set_value_if_greater called with something that is not a number.Key:#{key};Value:#{value}"
    end
  else
    # it is not set so set it
    wurflhash[key] = value
  end
end

#set_wap_pushObject

Utility methods



920
921
922
923
# File 'lib/wurfl/uaproftowurfl.rb', line 920

def set_wap_push
  # if Push items exist then set wap_push/wap_push_support = true
  @wurfl["wap_push"]["wap_push_support"] = true
end

#SoftwareNumber(element) ⇒ Object Also known as: SofwareNumber



525
526
# File 'lib/wurfl/uaproftowurfl.rb', line 525

def SoftwareNumber(element)
end

#SoundOutputCapable(element) ⇒ Object



159
160
# File 'lib/wurfl/uaproftowurfl.rb', line 159

def SoundOutputCapable(element)
end

#StandardFontProportional(element) ⇒ Object



156
157
# File 'lib/wurfl/uaproftowurfl.rb', line 156

def StandardFontProportional(element)
end

#SupportedBearers(element) ⇒ Object Also known as: SupportedBearer



564
565
# File 'lib/wurfl/uaproftowurfl.rb', line 564

def SupportedBearers(element)
end

#SupportedBluetoothVersion(element) ⇒ Object

NetworkCharacteristics



548
549
# File 'lib/wurfl/uaproftowurfl.rb', line 548

def SupportedBluetoothVersion(element)
end

#SupportedPictogramSet(element) ⇒ Object

WapCharacteristics



634
635
636
637
# File 'lib/wurfl/uaproftowurfl.rb', line 634

def SupportedPictogramSet(element)
  # There could be WAP ones, but no list?
  #=> "chtml_ui/emoji",
end

#TablesCapable(element) ⇒ Object Also known as: TableCapable



605
606
607
608
# File 'lib/wurfl/uaproftowurfl.rb', line 605

def TablesCapable(element)
  value = convert_value(element.text)
  @wurfl["wml_ui"]["table_support"] = value
end

#TextInputCapable(element) ⇒ Object



162
163
# File 'lib/wurfl/uaproftowurfl.rb', line 162

def TextInputCapable(element)
end

#Vendor(element) ⇒ Object



168
169
170
# File 'lib/wurfl/uaproftowurfl.rb', line 168

def Vendor(element)
  @wurfl["product_info"]["brand_name"] = element.text
end

#VideoInputEncoder(element) ⇒ Object



528
529
# File 'lib/wurfl/uaproftowurfl.rb', line 528

def VideoInputEncoder(element)
end

#VoiceInputCapable(element) ⇒ Object



165
166
# File 'lib/wurfl/uaproftowurfl.rb', line 165

def VoiceInputCapable(element)
end

#WapDeviceClass(element) ⇒ Object



639
640
# File 'lib/wurfl/uaproftowurfl.rb', line 639

def WapDeviceClass(element)
end

#WapPushMsgPriority(element) ⇒ Object



891
892
# File 'lib/wurfl/uaproftowurfl.rb', line 891

def WapPushMsgPriority(element)
end

#WapPushMsgSize(element) ⇒ Object



894
895
# File 'lib/wurfl/uaproftowurfl.rb', line 894

def WapPushMsgSize(element)
end

#WapSupportedApplications(element) ⇒ Object



897
898
# File 'lib/wurfl/uaproftowurfl.rb', line 897

def WapSupportedApplications(element)
end

#WapVersion(element) ⇒ Object



642
643
# File 'lib/wurfl/uaproftowurfl.rb', line 642

def WapVersion(element)
end

#WmlDeckSize(element) ⇒ Object



645
646
647
# File 'lib/wurfl/uaproftowurfl.rb', line 645

def WmlDeckSize(element)
  @wurfl["storage"]["max_deck_size"] = element.text.to_i
end

#WmlScriptLibraries(element) ⇒ Object Also known as: WmlscriptLibraries



649
650
# File 'lib/wurfl/uaproftowurfl.rb', line 649

def WmlScriptLibraries(element)
end

#WmlScriptVersion(element) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/wurfl/uaproftowurfl.rb', line 652

def WmlScriptVersion(element)
  items = get_items_from_bag(element)
  items.each do |version|
    case version
    when "1.0"
	@wurfl["markup"]["wmlscript10"] = true
    when "1.1"
	@wurfl["markup"]["wmlscript11"] = true
    when /1\.2/i
      @wurfl["markup"]["wmlscript12"] = true
    else
	$stderr.puts "WmlScriptVersion unknown version mapping: #{version}"
    end
  end
end

#WmlVersion(element) ⇒ Object



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'lib/wurfl/uaproftowurfl.rb', line 668

def WmlVersion(element)
  items = get_items_from_bag(element)
  items.each do |version|
    case version
    when "1.0"
	# It appears we do not care about this one
    when "1.1"
	@wurfl["markup"]["wml_11"] = true
    when "1.2"
	@wurfl["markup"]["wml_12"] = true
    when "1.3"
	@wurfl["markup"]["wml_13"] = true
    else
	$stderr.puts "WmlVersion unknown version mapping: #{version}"
    end
  end
end

#WtaiLibraries(element) ⇒ Object

Conversions needed on Bag



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/wurfl/uaproftowurfl.rb', line 687

def WtaiLibraries(element)
  items = get_items_from_bag(element)
  items.each do |lib|
    case lib
    when "WTAVoiceCall"
	@wurfl["wta"]["wta_voice_call"] = true
    when "WTANetText"
	@wurfl["wta"]["wta_net_text"] = true
    when "WTAPhoneBook"
	@wurfl["wta"]["wta_phonebook"] = true
    when "WTACallLog"
	@wurfl["wta"]["wta_call_log"] = true
    when "WTAMisc"
	@wurfl["wta"]["wta_misc"] = true
    when "WTAGSM"
	@wurfl["wta"]["wta_gsm"] = true
    when "WTAIS136"
	@wurfl["wta"]["wta_is136"] = true
    when "WTAPDC"
	@wurfl["wta"]["wta_pdc"] = true
    when "AddPBEntry"
      @wurfl["wta"]["wta_phonebook"] = true
    when "MakeCall"
      @wurfl["wta"]["nokia_voice_call"] = true
    when "WTAIGSM"
      @wurfl["wta"]["wta_gsm"] = true
    when "WTAIPublic.makeCall"
      @wurfl["wta"]["nokia_voice_call"] = true
    when "WTA.Public.addPBEntry"
      @wurfl["wta"]["wta_phonebook"] = true
    when "WTA.Public.makeCall"
      @wurfl["wta"]["nokia_voice_call"] = true
    when "WTAPublic.makeCall"
      @wurfl["wta"]["nokia_voice_call"] = true
    when "SendDTMF","WTA.Public.sendDTMF"
      # Not in WURFL
    when "WTAPublic"
      # Not enough information      
    else
	$stderr.puts "WtaiLibraries unknown mapping: #{lib}"
    end
  end
end

#WtaVersion(element) ⇒ Object Also known as: wtaVersion



731
732
# File 'lib/wurfl/uaproftowurfl.rb', line 731

def WtaVersion(element)
end

#XhtmlModules(element) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/wurfl/uaproftowurfl.rb', line 620

def XhtmlModules(element)
  #What does the mobile profile module look like?
  $stderr.puts "XhtmlModules items are:"
  items = get_items_from_bag(element)
  items.each do |mods|
    $stderr.puts "XhtmlModules item: #{mods}"
    if mods =~ /mobile*profile/i
	#Wow this worked?!
	@wurfl["markup"]["xhtml_mobileprofile"] = true
    end
  end
end

#XhtmlVersion(element) ⇒ Object



610
611
612
613
614
615
616
617
618
# File 'lib/wurfl/uaproftowurfl.rb', line 610

def XhtmlVersion(element)
  version = element.text.to_i
  if version >= 1
    if version != 1
	$stderr.puts "XhtmlVersion that might map to a new WURFL trait. Version:#{version}" 
    end
    @wurfl["markup"]["xhtml_basic"] = true
  end
end