public String To_str(Object o) { if (o == null) return "<<NULL>>"; Class<?> type = Type_adp_.ClassOf_obj(o); String rv = null; if (type == String.class) rv = String_.cast(o); else if (Int_.TypeMatch(type)) return Int_.To_str(Int_.cast(o)); else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) return Yn.To_str(Bool_.cast(o)); else if (type == DateAdp.class) return DateAdp_.cast(o).XtoStr_gplx(); else rv = Object_.Xto_str_strict_or_empty(o); return String_.Replace(rv, "'", "''"); }
public Xowv_wiki(Xoav_app app, byte[] domain_bry, Io_url wiki_root_dir) { this.app = app; this.domain_bry = domain_bry; this.domain_str = String_.new_u8(domain_bry); this.domain_itm = Xow_domain_itm_.parse(domain_bry); this.domain_tid = domain_itm.Domain_type_id(); this.domain_abrv = Xow_abrv_wm_.To_abrv(Xow_domain_itm_.parse(domain_bry)); this.ns_mgr = Xow_ns_mgr_.default_(app.Utl_case_mgr()); this.lang = app.Lang_mgr() .Get_by_or_en( domain_itm .Lang_actl_key()); // NOTE: must not be null, or causes null ref exception on // redlinks in drd; DATE:2016-06-28 this.msg_mgr = new Xow_msg_mgr(this, lang); this.html__hdump_mgr = new Xow_hdump_mgr(this); this.special_mgr = new Xosp_special_mgr(this); this.fsys_mgr = new Xow_fsys_mgr(wiki_root_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str)); this.fsdb_mgr = new Xof_fsdb_mgr__sql(); this.url__parser = new Xow_url_parser(this); this.xwiki_mgr = new Xow_xwiki_mgr(this); this.stats = new Xow_site_stats_mgr(this); this.lnki_bldr = new Xoh_lnki_bldr(app, href_wtr); this.ctg_catpage_mgr = new Xoctg_catpage_mgr(this); }
public boolean ReadYn_toggle(String k, boolean cur) { Object rv = ReadOr(k, "!"); if (rv == Nil) ThrowNotFound(k); if (!parse) throw Err_.new_wo_type("only parse supported"); String rv_str = (String) rv; return (String_.Eq(rv_str, "!")) ? !cur : Yn.parse(rv_str); }
public void Init_by_wiki() { if (!init_needed) return; init_needed = false; if (String_.Eq(domain_str, "xowa")) return; // HACK: ignore "xowa" for now; WHEN:converting xowa to sqlitedb data_mgr__core_mgr = new Xow_db_mgr(this, fsys_mgr.Root_dir()); data_mgr__core_mgr.Init_by_load(gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil(this)); app.Html__css_installer() .Install(this, Xowd_css_core_mgr.Key_mobile); // must init after data_mgr this.db_core_mgr = Fsdb_db_mgr_.new_detect(this, fsys_mgr.Root_dir(), fsys_mgr.File_dir()); if (db_core_mgr == null) // no fsdb; occurs during merge; also, will be null for xowa_db; DATE:2016-05-31 db_core_mgr = Fsdb_db_mgr__v2_bldr.Get_or_make(this, true); else // fsdb exists; load it fsdb_mgr.Mnt_mgr().Ctor_by_load(db_core_mgr); file_mgr__repo_mgr.Add_repo( app, fsys_mgr.File_dir(), Xow_domain_itm_.Bry__commons, Xow_domain_itm_.Bry__commons); file_mgr__repo_mgr.Add_repo(app, fsys_mgr.File_dir(), domain_bry, domain_bry); Xof_orig_tbl[] orig_tbls = db_core_mgr == null ? new Xof_orig_tbl[0] : db_core_mgr.File__orig_tbl_ary(); orig_mgr.Init_by_wiki(this, file_mgr__fsdb_mode, orig_tbls, Xof_url_bldr.new_v2()); fsdb_mgr.Init_by_wiki(this); data_mgr__core_mgr.Db__core().Tbl__ns().Select_all(ns_mgr); data_mgr__core_mgr.Db__core().Tbl__site_stats().Select(stats); html__hdump_mgr.Init_by_db(this); app.Addon_mgr().Load_by_wiki(this); ctg_pagebox_wtr.Init_by_wiki(this); }
@gplx.Virtual protected Object ReadOr(String k, Object defaultOr) { if (args == null) return Nil; // WORKAROUND.gfui: args null for DataBndr_whenEvt_execCmd if (!String_.Eq(k, "")) { for (int i = 0; i < args.Count(); i++) { Keyval kv = (Keyval) args.Get_at(i); if (String_.Eq(k, kv.Key())) return kv.Val(); } } if (counter >= args.Count()) return Nil; for (int i = 0; i < args.Count(); i++) { Keyval kv = (Keyval) args.Get_at(i); if (String_.Eq(kv.Key(), "") && i >= counter) { counter++; return kv.Val(); } } return Nil; }
public Xow_search_tkn[] Scan(byte[] src) { this.src = src; this.src_len = src.length; tkns.Clear(); pos = 0; txt_bgn = -1; while (pos < src_len) { byte cur_b = src[pos]; Object cur_obj = trie.Match_bgn_w_byte(cur_b, src, pos, src_len); if (cur_obj == null) { // text character if (txt_bgn == -1) txt_bgn = pos; // 1st character not set; set it ++pos; } else { // AND, OR, (, ), -, \s, " int pos_end = trie.Match_pos(); byte cur_tid = ((Byte_obj_val) cur_obj).Val(); if (Cur_join_is_word(cur_tid, pos_end)) continue; // ignore words containing "and", "or"; EX: "random"; "for" if (txt_bgn != -1) { // pending word; create Tkns_add_word(Xow_search_tkn.Tid_word, txt_bgn, pos); txt_bgn = -1; } switch (cur_tid) { case Xow_search_tkn.Tid_space: // discard spaces pos = Bry_finder.Find_fwd_while(src, pos, src_len, Byte_ascii.Space); break; case Xow_search_tkn.Tid_quote: // find end quote and add as word int quote_bgn = pos + 1; int quote_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, quote_bgn, src_len); if (quote_end == Bry_.NotFound) throw Err_.new_fmt_("could not find end quote: {0}", String_.new_u8(src)); Tkns_add_word(Xow_search_tkn.Tid_word_quoted, quote_bgn, quote_end); pos = quote_end + 1; // +1 to place after quote break; case Xow_search_tkn.Tid_not: Tkns_add_word(Xow_search_tkn.Tid_not, pos, pos_end); pos = pos_end; break; case Xow_search_tkn.Tid_paren_bgn: case Xow_search_tkn.Tid_paren_end: case Xow_search_tkn.Tid_and: case Xow_search_tkn.Tid_or: tkns.Add(new_tkn(cur_tid, pos, pos_end)); pos = pos_end; break; default: throw Err_.unhandled(cur_tid); } } } if (txt_bgn != -1) { // pending word; create Tkns_add_word(Xow_search_tkn.Tid_word, txt_bgn, pos); txt_bgn = -1; } return (Xow_search_tkn[]) tkns.To_ary_and_clear(Xow_search_tkn.class); }
public GfoMsg Args_ovr(String k, Object v) { if (args == null) args = List_adp_.New(); for (int i = 0; i < args.Count(); i++) { Keyval kv = (Keyval) args.Get_at(i); if (String_.Eq(k, kv.Key())) { kv.Val_(v); return this; } } args.Add(Keyval_.new_(k, v)); return this; }
public Btrie_fast_mgr Add(byte[] key, Object val) { if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key)); int key_len = key.length; int key_end = key_len - 1; ByteTrieItm_fast cur = root; for (int i = 0; i < key_len; i++) { byte b = key[i]; ByteTrieItm_fast nxt = cur.Ary_find(b); if (nxt == null) nxt = cur.Ary_add(b, null); if (i == key_end) nxt.Val_set(val); cur = nxt; } return this; }
public String[] ReadStrAryIgnore(String k, String spr, String ignore) { return String_.Split(String_.Replace(ReadStr(k), ignore, ""), spr); }
public String[] ReadStrAry(String k, String spr) { return String_.Split(ReadStr(k), spr); }
public static String Escape_tilde(String v) {return String_.Replace(v, "~", "~~");}
int Compile_eval_cmd(byte[] fmt, int fmt_len, int eval_lhs_bgn, List_adp list) { int eval_lhs_end = Bry_finder.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Err_mgr._.fmt_(GRP_KEY, "eval_lhs_end_invalid", "could not find eval_lhs_end: ~{0}", String_.new_u8(fmt, eval_lhs_bgn, fmt_len)); byte[] eval_dlm = Bry_.Mid(fmt, eval_lhs_bgn , eval_lhs_end + Int_.Const_dlm_len); int eval_rhs_bgn = Bry_finder.Find_fwd(fmt, eval_dlm , eval_lhs_end + Int_.Const_dlm_len, fmt_len); if (eval_rhs_bgn == Bry_.NotFound) throw Err_mgr._.fmt_(GRP_KEY, "eval_rhs_bgn_invalid", "could not find eval_rhs_bgn: ~{0}", String_.new_u8(fmt, eval_lhs_end, fmt_len)); byte[] eval_cmd = Bry_.Mid(fmt, eval_lhs_end + Int_.Const_dlm_len, eval_rhs_bgn); byte[] eval_rslt = eval_mgr.Eval(eval_cmd); int eval_rhs_end = eval_rhs_bgn + Int_.Const_dlm_len + eval_dlm.length; if (eval_rslt == null) eval_rslt = Bry_.Mid(fmt, eval_lhs_bgn - 2, eval_rhs_end); // not found; return original argument list.Add(Bry_fmtr_itm.dat_bry_(eval_rslt)); return eval_rhs_end; }
public void Test_load_page(int ns_id, int page_id, String expd) { Xowe_wiki wiki = bldr_fxt.Wiki(); Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id); wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns, false); Tfds.Eq(expd, String_.new_a7(actl.Text())); }