WURFL的使用

最近忙于中移动的MAS2.0的软件,MAS2.0的一个重要特点就是能支持移动化插件。说白点就是能把一个供电脑访问的网站根据不同的手机类型,删除,修改其内容用以适应手机屏幕大小(使得手机只需要上下滚动,而不需要左右滚动)。

网站提供手机访问的开发中经常需要根据不同的手机型号获得手机的性能,来决定提供哪些功能给手机访问者。这个在网站制作中用的很多,手机访问网站和电脑访问网站显示的内容在图片,视频,音频,屏幕宽度等等属性上都有所不同,不同的手机也各不相同。

为了获取手机支持的属性,就需要用到UAProfile了,使用它可以根据http连接请求中的device_id来判断是什么类型的机器访问网站,还可以查询到这种型号的机器支持的分辨率,图片格式,网络脚本类型,缓存等等。其内容之详细完全可以支持网站的手机访问开发了。

我用WURFL来获取UAProfile,其精髓就在WURFL.xml文件,现在最新版本是2007年11月18日更新的,大小6.68M。

写了个很简单的代码去获得UAProfile并打印出来

import  net.sourceforge.wurfl.wurflapi. * ;
import  java.util. * ;
import  java.io. * ;
/**
 *
 * 
@author chenyi
 
*/

public   class  Main  {
    
/** Creates a new instance of Main */
    
public Main() {
        System.setProperty(
"wurflpath","wurfl.xml");
        ListManager lm 
= ObjectsManager.getListManagerInstance();
        CapabilityMatrix cm 
= ObjectsManager.getCapabilityMatrixInstance();
        String id 
="motorola_a1000_ver1";
        HashMap deviceElementsList 
= lm.getDeviceElementsList();
        HashMap logr 
= lm.getListOfGroups();
        WurflDevice dev = (WurflDevice) deviceElementsList.get(id);
        String fb, ua;
        fb 
= dev.getFallBack();
//        ua = dev.getUserAgent();
//        
//        String model,brand;
//        model = cm.getCapabilityForDevice(id,"model_name");
//        brand = cm.getCapabilityForDevice(id,"brand_name");
        
        
if (!fb.equals("root")){
            Iterator keys 
= logr.keySet().iterator();
            
int i = 0;
            
while ( keys.hasNext() ) {
                String key 
= (String) keys.next();
                System.out.println(key);
                
//String key = (String) keys.next();
                ArrayList cap_list = (ArrayList)logr.get(key);
                Iterator capa_keys 
= cap_list.iterator();
                
while ( capa_keys.hasNext() ) {
                    String capa_key 
= (String) capa_keys.next();
                    String value 
= cm.getCapabilityForDevice(id,capa_key);
                    System.out.println(
"   "+capa_key+":   "+value);
                }

            }

            
//            keys = logr.keySet().iterator();
//            i = 0;
//            String color = null;
//            while ( keys.hasNext() ) {
//                String key = (String) keys.next();
//                ArrayList cap_list = (ArrayList)logr.get(key);
//                Iterator capa_keys = cap_list.iterator();
//                while ( capa_keys.hasNext() ) {
//                    String capa_key = (String) capa_keys.next();
//                    String value = cm.getCapabilityForDevice(id,capa_key);
//                    System.out.println(capa_key+":   "+value);
//                }
//            }
        }

    }

    
    
/**
     * 
@param args the command line arguments
     
*/

    
public static void main(String[] args) {
        
// TODO code application logic here
        new Main();
    }

    
}

我获取motorola_a1000_ver1的UAProfile最后打印出来的内容如下:

flash_lite
   flash_lite_version:  
   fl_wallpaper:   false
   fl_screensaver:   false
   fl_standalone:   false
   fl_browser:   false
   fl_sub_lcd:   false
display
   resolution_width:   208
   resolution_height:   320
   columns:   15
   max_image_width:   208
   max_image_height:   240
   rows:   20
product_info
   brand_name:   Motorola
   model_name:   A1000
   unique:   true
   ununiqueness_handler:  
   is_wireless_device:   true
   device_claims_web_support:   true
   has_pointing_device:   true
   has_qwerty_keyboard:   false
   can_skip_aligned_link_row:   true
   uaprof:   http://motorola.handango.com/phoneconfig/a1000/Profile/a1000.rdf
   uaprof2:  
   uaprof3:  
   nokia_series:   0
   nokia_edition:   0
   device_os:  
   mobile_browser:  
   mobile_browser_version:  
image_format
   wbmp:   true
   bmp:   false
   epoc_bmp:   false
   gif_animated:   false
   jpg:   true
   png:   true
   tiff:   false
   transparent_png_alpha:   false
   transparent_png_index:   false
   svgt_1_1:   false
   svgt_1_1_plus:   false
   greyscale:   false
   gif:   true
   colors:   65536
xhtml_ui
   xhtml_honors_bgcolor:   false
   xhtml_supports_forms_in_table:   false
   xhtml_support_wml2_namespace:   false
   xhtml_autoexpand_select:   false
   xhtml_select_as_dropdown:   false
   xhtml_select_as_radiobutton:   false
   xhtml_select_as_popup:   false
   xhtml_display_accesskey:   false
   xhtml_supports_invisible_text:   false
   xhtml_supports_inline_input:   false
   xhtml_supports_monospace_font:   false
   xhtml_supports_table_for_layout:   false
   xhtml_supports_css_cell_table_coloring:   false
   xhtml_format_as_css_property:   false
   xhtml_format_as_attribute:   false
   xhtml_nowrap_mode:   false
   xhtml_marquee_as_css_property:   false
   xhtml_readable_background_color1:   #FFFFFF
   xhtml_readable_background_color2:   #FFFFFF
   xhtml_allows_disabled_form_elements:   false
   xhtml_document_title_support:   true
   xhtml_preferred_charset:   utf8
   opwv_xhtml_extensions_support:   false
   xhtml_make_phone_call_string:   tel:
   xhtmlmp_preferred_mime_type:   text/html
   xhtml_table_support:   true
   xhtml_send_sms_string:   none
   xhtml_send_mms_string:   none
   xhtml_supports_file_upload:   false
   xhtml_file_upload:   not_supported
wta
   nokia_voice_call:   false
   wta_voice_call:   false
   wta_phonebook:   false
   wta_misc:   false
   wta_pdc:   false
storage
   max_deck_size:   4000
   max_url_length_in_requests:   0
   max_url_length_homepage:   0
   max_url_length_bookmark:   0
   max_url_length_cached_page:   0
   max_no_of_connection_settings:   0
   max_no_of_bookmarks:   0
   max_length_of_username:   0
   max_length_of_password:   0
   max_object_size:   0
bugs
   post_method_support:   true
   basic_authentication_support:   true
   empty_option_value_support:   true
   emptyok:   false
markup
   xhtml_support_level:   2
   preferred_markup:   html_wi_oma_xhtmlmp_1_0
   wml_1_1:   true
   wml_1_2:   true
   wml_1_3:   true
   html_wi_w3_xhtmlbasic:   true
   html_wi_oma_xhtmlmp_1_0:   true
   html_wi_imode_html_1:   false
   html_wi_imode_html_2:   false
   html_wi_imode_html_3:   false
   html_wi_imode_html_4:   false
   html_wi_imode_html_5:   false
   html_wi_imode_htmlx_1:   false
   html_wi_imode_htmlx_1_1:   false
   html_wi_imode_compact_generic:   true
   html_web_3_2:   true
   html_web_4_0:   true
   voicexml:   false
   multipart_support:   true
cache
   total_cache_disable_support:   false
   time_to_live_support:   false
chtml_ui
   chtml_display_accesskey:   false
   emoji:   false
   chtml_can_display_images_and_text_on_same_line:   false
   chtml_displays_image_in_center:   false
   imode_region:   none
   chtml_make_phone_call_string:   tel:
   chtml_table_support:   false
sound_format
   wav:   true
   mmf:   true
   smf:   true
   mld:   false
   midi_monophonic:   true
   midi_polyphonic:   true
   sp_midi:   true
   rmf:   false
   xmf:   true
   compactmidi:   false
   digiplug:   false
   nokia_ringtone:   false
   imelody:   true
   au:   false
   amr:   true
   awb:   true
   aac:   true
   mp3:   true
   voices:   24
   qcelp:   false
   evrc:   false
wml_ui
   proportional_font:   false
   built_in_back_button_support:   false
   card_title_support:   true
   softkey_support:   false
   table_support:   true
   numbered_menus:   false
   menu_with_select_element_recommended:   false
   menu_with_list_of_links_recommended:   true
   icons_on_menu_items_support:   false
   break_list_of_links_with_br_element_recommended:   true
   access_key_support:   false
   wrap_mode_support:   false
   times_square_mode_support:   false
   deck_prefetch_support:   false
   elective_forms_recommended:   true
   wizards_recommended:   false
   image_as_link_support:   false
   insert_br_element_after_widget_recommended:   false
   wml_can_display_images_and_text_on_same_line:   false
   wml_displays_image_in_center:   false
   opwv_wml_extensions_support:   false
   wml_make_phone_call_string:   wtai://wp/mc;
drm
   oma_v_1_0_forwardlock:   true
   oma_v_1_0_combined_delivery:   true
   oma_v_1_0_separate_delivery:   true
sms
   nokiaring:   false
   picturemessage:   false
   operatorlogo:   false
   largeoperatorlogo:   false
   callericon:   false
   nokiavcard:   false
   nokiavcal:   false
   sckl_ringtone:   false
   sckl_operatorlogo:   false
   sckl_groupgraphic:   false
   sckl_vcard:   false
   sckl_vcalendar:   false
   text_imelody:   false
   ems:   true
   ems_variablesizedpictures:   false
   ems_imelody:   false
   ems_odi:   false
   ems_upi:   false
   ems_version:   0
   siemens_ota:   false
   siemens_logo_width:   101
   siemens_logo_height:   29
   siemens_screensaver_width:   101
   siemens_screensaver_height:   50
   gprtf:   false
   sagem_v1:   false
   sagem_v2:   false
   panasonic:   false
wap_push
   wap_push_support:   false
   connectionless_service_indication:   false
   connectionless_service_load:   false
   connectionless_cache_operation:   false
   connectionoriented_unconfirmed_service_indication:   false
   connectionoriented_unconfirmed_service_load:   false
   connectionoriented_unconfirmed_cache_operation:   false
   connectionoriented_confirmed_service_indication:   false
   connectionoriented_confirmed_service_load:   false
   connectionoriented_confirmed_cache_operation:   false
   utf8_support:   false
   ascii_support:   false
   iso8859_support:   false
   expiration_date:   false
mms
   receiver:   true
   sender:   true
   mms_max_size:   2000000
   mms_max_height:   480
   mms_max_width:   640
   built_in_recorder:   true
   built_in_camera:   true
   mms_jpeg_baseline:   true
   mms_jpeg_progressive:   true
   mms_gif_static:   true
   mms_gif_animated:   true
   mms_png:   true
   mms_bmp:   true
   mms_wbmp:   true
   mms_amr:   true
   mms_wav:   false
   mms_midi_monophonic:   true
   mms_midi_polyphonic:   true
   mms_midi_polyphonic_voices:   24
   mms_spmidi:   true
   mms_mmf:   false
   mms_mp3:   true
   mms_evrc:   false
   mms_qcelp:   false
   mms_ota_bitmap:   false
   mms_nokia_wallpaper:   false
   mms_nokia_operatorlogo:   false
   mms_nokia_3dscreensaver:   false
   mms_nokia_ringingtone:   false
   mms_rmf:   false
   mms_xmf:   false
   mms_symbian_install:   false
   mms_jar:   false
   mms_jad:   false
   mms_vcard:   false
   mms_vcalendar:   false
   mms_wml:   false
   mms_wbxml:   false
   mms_wmlc:   false
   mms_video:   false
   mms_mp4:   false
   mms_3gpp:   false
   mms_3gpp2:   false
   mms_max_frame_rate:   0
security
   https_support:   true
   https_detectable:   false
   phone_id_provided:   false
streaming
   streaming_video:   true
   streaming_real_media_8:   false
   streaming_real_media_9:   false
   streaming_real_media_10:   false
   streaming_3gpp:   false
   streaming_mp4:   true
   streaming_wmv:   false
   streaming_mov:   false
   streaming_video_qcif:   false
   streaming_video_qcif_max_width:   0
   streaming_video_qcif_max_height:   0
   streaming_video_sqcif:   false
   streaming_video_sqcif_max_width:   0
   streaming_video_sqcif_max_height:   0
   streaming_video_max_bit_rate:   0
   streaming_video_max_video_bit_rate:   0
   streaming_video_min_video_bit_rate:   0
   streaming_video_max_audio_bit_rate:   0
   streaming_video_max_frame_rate:   0
   streaming_video_size_limit:   0
   streaming_video_vcodec_h263_0:   false
   streaming_video_vcodec_h263_3:   false
   streaming_video_vcodec_mpeg4:   false
   streaming_video_acodec_amr:   false
   streaming_video_acodec_awb:   false
   streaming_video_acodec_aac:   false
   streaming_video_acodec_aac_ltp:   false
object_download
   downloadfun_support:   false
   directdownload_support:   true
   inline_support:   false
   oma_support:   false
   ringtone:   true
   ringtone_midi_monophonic:   true
   ringtone_midi_polyphonic:   true
   ringtone_imelody:   true
   ringtone_digiplug:   false
   ringtone_compactmidi:   false
   ringtone_mmf:   true
   ringtone_rmf:   false
   ringtone_xmf:   true
   ringtone_amr:   true
   ringtone_awb:   true
   ringtone_aac:   false
   ringtone_wav:   true
   ringtone_mp3:   true
   ringtone_spmidi:   true
   ringtone_qcelp:   false
   ringtone_voices:   24
   ringtone_df_size_limit:   0
   ringtone_directdownload_size_limit:   0
   ringtone_inline_size_limit:   0
   ringtone_oma_size_limit:   0
   wallpaper:   true
   wallpaper_max_width:   208
   wallpaper_max_height:   320
   wallpaper_preferred_width:   208
   wallpaper_preferred_height:   256
   wallpaper_resize:   none
   wallpaper_wbmp:   true
   wallpaper_bmp:   false
   wallpaper_gif:   true
   wallpaper_jpg:   true
   wallpaper_png:   true
   wallpaper_tiff:   false
   wallpaper_greyscale:   false
   wallpaper_colors:   16
   wallpaper_df_size_limit:   0
   wallpaper_directdownload_size_limit:   0
   wallpaper_inline_size_limit:   0
   wallpaper_oma_size_limit:   0
   screensaver:   false
   screensaver_max_width:   0
   screensaver_max_height:   0
   screensaver_preferred_width:   0
   screensaver_preferred_height:   0
   screensaver_resize:   none
   screensaver_wbmp:   false
   screensaver_bmp:   false
   screensaver_gif:   false
   screensaver_jpg:   false
   screensaver_png:   false
   screensaver_greyscale:   false
   screensaver_colors:   2
   screensaver_df_size_limit:   0
   screensaver_directdownload_size_limit:   0
   screensaver_inline_size_limit:   0
   screensaver_oma_size_limit:   0
   picture:   false
   picture_max_width:   0
   picture_max_height:   0
   picture_preferred_width:   0
   picture_preferred_height:   0
   picture_resize:   none
   picture_wbmp:   false
   picture_bmp:   false
   picture_gif:   false
   picture_jpg:   false
   picture_png:   false
   picture_greyscale:   false
   picture_colors:   2
   picture_df_size_limit:   0
   picture_directdownload_size_limit:   0
   picture_inline_size_limit:   0
   picture_oma_size_limit:   0
   video:   true
   video_real_media_8:   false
   video_real_media_9:   false
   video_real_media_10:   false
   video_3gpp:   false
   video_3gpp2:   false
   video_mp4:   true
   video_wmv:   true
   video_mov:   false
   video_max_frame_rate:   15
   video_max_width:   176
   video_max_height:   144
   video_qcif:   true
   video_sqcif:   true
   video_preferred_width:   0
   video_preferred_height:   0
   video_df_size_limit:   0
   video_directdownload_size_limit:   0
   video_inline_size_limit:   0
   video_oma_size_limit:   0
   video_vcodec_h263_0:   true
   video_vcodec_h263_3:   false
   video_vcodec_h264:   false
   video_vcodec_mpeg4:   true
   video_acodec_amr:   true
   video_acodec_awb:   false
   video_acodec_aac:   true
   video_acodec_aac_ltp:   false
   video_acodec_qcelp:   false
   ringtone_3gpp:   false
bearer
   max_data_rate:   9
   wifi:   false
j2me
   j2me_cldc_1_0:   true
   j2me_cldc_1_1:   false
   j2me_midp_1_0:   true
   j2me_midp_2_0:   true
   doja_1_0:   false
   doja_1_5:   false
   doja_2_0:   false
   doja_2_1:   false
   doja_2_2:   false
   doja_3_0:   false
   doja_3_5:   false
   doja_4_0:   false
   j2me_jtwi:   true
   j2me_mmapi_1_0:   true
   j2me_mmapi_1_1:   false
   j2me_wmapi_1_0:   true
   j2me_wmapi_1_1:   false
   j2me_wmapi_2_0:   false
   j2me_btapi:   false
   j2me_3dapi:   false
   j2me_loctapi:   false
   j2me_nokia_ui:   false
   j2me_motorola_lwt:   false
   j2me_siemens_color_game:   false
   j2me_siemens_extension:   false
   j2me_heap_size:   16777216
   j2me_max_jar_size:   25165824
   j2me_storage_size:   25165824
   j2me_max_record_store_size:   25165824
   j2me_screen_width:   208
   j2me_screen_height:   320
   j2me_canvas_width:   208
   j2me_canvas_height:   180
   j2me_bits_per_pixel:   16
   j2me_audio_capture_enabled:   false
   j2me_video_capture_enabled:   false
   j2me_photo_capture_enabled:   false
   j2me_capture_image_formats:   none
   j2me_http:   true
   j2me_https:   true
   j2me_socket:   true
   j2me_udp:   true
   j2me_serial:   false
   j2me_gif:   false
   j2me_gif89a:   false
   j2me_jpg:   true
   j2me_png:   true
   j2me_bmp:   false
   j2me_bmp3:   false
   j2me_wbmp:   false
   j2me_midi:   true
   j2me_wav:   true
   j2me_amr:   true
   j2me_mp3:   false
   j2me_mp4:   false
   j2me_imelody:   false
   j2me_rmf:   false
   j2me_au:   false
   j2me_aac:   false
   j2me_realaudio:   false
   j2me_xmf:   false
   j2me_wma:   false
   j2me_3gpp:   false
   j2me_h263:   false
   j2me_svgt:   false
   j2me_mpeg4:   true
   j2me_realvideo:   false
   j2me_real8:   false
   j2me_realmedia:   false
   j2me_left_softkey_code:   21
   j2me_right_softkey_code:   22
   j2me_middle_softkey_code:   23
   j2me_select_key_code:   0
   j2me_return_key_code:   0
   j2me_clear_key_code:   0
   j2me_datefield_no_accepts_null_date:   false
   j2me_datefield_broken:   false

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值