public static Xoa_app_mode parse(String s) { Object o = type_hash.Get_by(Bry_.new_u8(s)); if (o == null) return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong" int tid = ((Int_obj_val) o).Val(); switch (tid) { case Tid_cmd: return Itm_cmd; case Tid_gui: return Itm_gui; case Tid_http: return Itm_http; case Tid_tcp: return Itm_tcp; case Tid_file: return Itm_file; default: throw Err_.new_unhandled(tid); } }
public class Pfunc_gender extends Pf_func_base { @Override public int Id() { return Xol_kwd_grp_.Id_i18n_gender; } @Override public boolean Func_require_colon_arg() { return true; } @Override public Pf_func New(int id, byte[] name) { return new Pfunc_gender().Name_(name); } @Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { byte[] user_name = Eval_argx(ctx, src, caller, self); byte[] when_m = Bry_.Empty, when_f = Bry_.Empty, when_u = Bry_.Empty; int self_args_len = self.Args_len(); if (self_args_len == 0) return; // per MW: EX: {{gender:name}} -> "" else { if (self_args_len > 0) { when_m = when_u = Pf_func_.Eval_arg_or_empty( ctx, src, caller, self, self_args_len, 0); // default when_u to when_m if (self_args_len > 1) { when_f = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1); if (self_args_len > 2) { when_u = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 2); } } } } if (self_args_len == 1) { bfr.Add(when_m); return; } // per MW: EX: {{gender:name|a}} -> "a" int gender = Get_gender(ctx.App().User(), user_name); Xol_lang_itm lang = ctx.Page().Lang(); bfr.Add(lang.Gender().Gender_eval(gender, when_m, when_f, when_u)); } private static int Get_gender(Xou_user user, byte[] user_name) { int user_name_len = user_name.length; switch (user_name_len) { case 0: return Xol_gender_.Tid_unknown; // EX: {{gender:|m|f}} case 1: if (user_name[0] == Byte_ascii.Dot) return Xol_gender_.Tid_unknown; break; // EX: {{gender:.|m|f}}; TODO_OLD: should define default gender for wiki } Object o = gender_cache.Get_by_bry(user_name); return o == null ? user.Gender() : ((Int_obj_val) o).Val(); } private static final Hash_adp_bry gender_cache = Hash_adp_bry.cs() // for tests .Add_str_int("xowa_male", Xol_gender_.Tid_male) .Add_str_int("xowa_female", Xol_gender_.Tid_female); }
public class Indicator_xnde implements Xox_xnde, Mwh_atr_itm_owner1 { public String Name() { return name; } private String name; public byte[] Html() { return html; } private byte[] html; public void Init_for_test(String name, byte[] html) { this.name = name; this.html = html; } // TEST public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) { if (xatr_id_obj == null) return; Byte_obj_val xatr_id = (Byte_obj_val) xatr_id_obj; switch (xatr_id.Val()) { case Xatr_name: this.name = xatr.Val_as_str(); break; } } public void Xtn_parse( Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde); this.html = Xop_parser_.Parse_text_to_html( wiki, ctx, ctx.Page(), ctx.Page().Ttl(), Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false); Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators(); if (this.name != null) html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable } public void Xtn_write( Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) { if (this.name == null) bfr.Add_str_a7("Error: Page status indicators' name attribute must not be empty."); } private static final byte Xatr_name = 0; private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_str_obj("name", Byte_obj_val.new_(Xatr_name)); }
public class Xoa_app_mode { Xoa_app_mode(int tid) { this.tid = tid; } public int Tid() { return tid; } private final int tid; public boolean Tid_is_gui() { return tid == Tid_gui; } public boolean Tid_is_tcp() { return tid == Tid_tcp; } public boolean Tid_is_cmd() { return tid == Tid_cmd; } public boolean Tid_is_http() { return tid == Tid_http; } public boolean Tid_supports_js() { switch (tid) { case Tid_gui: case Tid_tcp: return true; default: return false; } } public byte[] Name() { switch (tid) { case Tid_cmd: return Key_cmd; case Tid_gui: return Key_gui; case Tid_http: return Key_http; case Tid_tcp: return Key_tcp; case Tid_file: return Key_file; default: return Key_cmd; // see parse } } private static final int Tid_cmd = 1, Tid_gui = 2, Tid_tcp = 3, Tid_http = 4, Tid_file = 5; private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file"); public static final Xoa_app_mode Itm_cmd = new Xoa_app_mode(Tid_cmd), Itm_gui = new Xoa_app_mode(Tid_gui), Itm_tcp = new Xoa_app_mode(Tid_tcp), Itm_http = new Xoa_app_mode(Tid_http), Itm_file = new Xoa_app_mode(Tid_file); private static final Hash_adp_bry type_hash = Hash_adp_bry.cs() .Add_bry_int(Key_cmd, Tid_cmd) .Add_bry_int(Key_gui, Tid_gui) .Add_bry_int(Key_http, Tid_http) .Add_bry_int(Key_tcp, Tid_tcp) .Add_bry_int(Key_file, Tid_file); public static Xoa_app_mode parse(String s) { Object o = type_hash.Get_by(Bry_.new_u8(s)); if (o == null) return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong" int tid = ((Int_obj_val) o).Val(); switch (tid) { case Tid_cmd: return Itm_cmd; case Tid_gui: return Itm_gui; case Tid_http: return Itm_http; case Tid_tcp: return Itm_tcp; case Tid_file: return Itm_file; default: throw Err_.new_unhandled(tid); } } }