Пример #1
0
  public static Keyval[] new_() {
    Ordered_hash translated = Ordered_hash_.New_bry();
    List_adp untranslated = List_adp_.New();
    Add_itm_many(
        translated,
        Xol_lang_stub_.Id_en,
        Xol_lang_stub_.Id_de,
        Xol_lang_stub_.Id_pl,
        Xol_lang_stub_.Id_zh_hans,
        Xol_lang_stub_
            .Id_zh_hant); // add langs with translations first, so they alphabetize to top of list
    int len = Xol_lang_stub_.Id__max;
    for (int i = 0; i < len; i++) { // add rest of langs, but sort by code
      Xol_lang_stub itm = Xol_lang_stub_.Get_by_id(i);
      if (translated.Has(itm.Key())) continue;
      untranslated.Add(itm);
    }
    untranslated.Sort_by(Xol_lang_stub_.Comparer_key);

    Keyval[] rv = new Keyval[len];
    int translated_max = translated.Count();
    for (int i = 0; i < translated_max; i++) rv[i] = new_itm((Xol_lang_stub) translated.Get_at(i));

    for (int i = translated_max; i < len; i++)
      rv[i] = new_itm((Xol_lang_stub) untranslated.Get_at(i - translated_max));
    return rv;
  }
  public List_adp Load(
      Xomp_mgr_db mgr_db, String machine_name, List_adp list, int list_idx, int list_len) {
    List_adp rv = List_adp_.New();

    // add remaining pages from old pool to new_pool;
    for (int i = list_idx; i < list_len; ++i) {
      rv.Add((Xomp_page_itm) list.Get_at(i));
    }

    // load pages into new pool
    Xomp_lock_mgr lock_mgr = mgr_db.Lock_mgr();
    int uid_db = lock_mgr.Uid_prv__get(machine_name);
    if (uid_db == Xomp_lock_mgr__fsys.Uid__eos)
      return rv; // assert that uids must be incrementally larger; handle one machine reaching end,
                 // and putting -1 in queue;
    int uid_new = 0;
    try {
      uid_new = this.Load_from_db(rv, uid_db);
    } finally {
      lock_mgr.Uid_prv__rls(machine_name, uid_new);
    }
    if (show_msg__fetched_pool)
      Gfo_usr_dlg_.Instance.Note_many(
          "", "", "fetched new pool: old=~{0} new=~{1}", uid_db, uid_new);
    return rv;
  }
Пример #3
0
public class Xog_tab_close_mgr {
  private List_adp list = List_adp_.New();

  public void Clear() {
    list.Clear();
  }

  public void Add(Xog_tab_close_lnr lnr) {
    list.Add(lnr);
  }

  public int Len() {
    return list.Count();
  }

  public Xog_tab_close_lnr Get_at(int i) {
    return (Xog_tab_close_lnr) list.Get_at(i);
  }

  public boolean When_close(Xog_tab_itm tab, Xoa_url url) {
    int len = list.Count();
    for (int i = 0; i < len; ++i) {
      Xog_tab_close_lnr lnr = Get_at(i);
      if (!lnr.When_close(tab, url)) return false;
    }
    return true;
  }
}
Пример #4
0
  public static void Find_pages(List_adp rv, Xowe_wiki wiki, Dpl_itm itm) {
    rv.Clear();
    List_adp includes = itm.Ctg_includes();
    if (includes == null) return;
    int includes_len = includes.Count();
    Ordered_hash old_regy = Ordered_hash_.New(),
        new_regy = Ordered_hash_.New(),
        cur_regy = Ordered_hash_.New();
    Xodb_load_mgr load_mgr = wiki.Db_mgr().Load_mgr();
    Xowd_page_itm tmp_page = new Xowd_page_itm();
    Int_obj_ref tmp_id = Int_obj_ref.New_zero();
    List_adp del_list = List_adp_.New();
    int ns_filter = itm.Ns_filter();
    Ordered_hash exclude_pages = Ordered_hash_.New();
    Find_excludes(exclude_pages, wiki, load_mgr, tmp_page, tmp_id, itm.Ctg_excludes());

    for (int i = 0; i < includes_len; i++) { // loop over includes
      byte[] include = (byte[]) includes.Get_at(i);
      cur_regy.Clear();
      del_list.Clear();
      Find_pages_in_ctg(cur_regy, wiki, load_mgr, tmp_page, tmp_id, include);
      Del_old_pages_not_in_cur(i, tmp_id, old_regy, cur_regy, del_list);
      Add_cur_pages_also_in_old(i, tmp_id, old_regy, cur_regy, new_regy, exclude_pages, ns_filter);
      old_regy = new_regy;
      new_regy = Ordered_hash_.New();
    }
    int pages_len = old_regy.Count();
    for (int i = 0; i < pages_len; i++) { // loop over old and create pages
      Int_obj_ref old_id = (Int_obj_ref) old_regy.Get_at(i);
      rv.Add(new Xowd_page_itm().Id_(old_id.Val()));
    }
    wiki.Db_mgr().Load_mgr().Load_by_ids(Cancelable_.Never, rv, 0, pages_len);
    rv.Sort_by(Xowd_page_itm_sorter.IdAsc);
  }
 public void Chk(byte[] wiki_domain, Io_url css_fil) {
   this.wiki_domain = wiki_domain;
   List_adp img_list = List_adp_.New();
   byte[] old_bry = Io_mgr.Instance.LoadFilBry(css_fil);
   byte[] rel_url_prefix = Bry_.Add(Bry_fwd_slashes, wiki_domain);
   byte[] new_bry = Convert_to_local_urls(rel_url_prefix, old_bry, img_list);
   Io_url img_dir = css_fil.OwnerDir();
   Download_fils(img_dir, img_list.To_str_ary());
   Io_mgr.Instance.SaveFilBry(css_fil, new_bry);
 }
Пример #6
0
 public static Xow_import_doc New(IoItmDir owner_dir, byte[] dir_cmd) {
   List_adp sub_list = List_adp_.New();
   New_subs(owner_dir.Url(), sub_list, owner_dir.SubDirs(), dir_cmd);
   New_subs(owner_dir.Url(), sub_list, owner_dir.SubFils(), Bry_.Empty);
   Xow_import_doc[] subs = (Xow_import_doc[]) sub_list.To_ary_and_clear(Xow_import_doc.class);
   return new Xow_import_doc(
       Bool_.Y,
       Bool_.N,
       0,
       owner_dir.Url().OwnerDir().RawBry(),
       owner_dir.Url().RawBry(),
       Bry_.new_u8(owner_dir.Name()),
       Bry_.Empty,
       Bry_.Empty,
       dir_cmd,
       subs);
 }
 @Override
 public void Cmd_run() {
   Init_bldr_bmks();
   this.time_bgn = System_.Ticks();
   int total_pending = Xob_xfer_regy_tbl.Select_total_pending(bldr_conn);
   // if (total_pending > 250000 && src_bin_mgr__fsdb_version == null)
   usr_dlg.Note_many("", "", "total pending: ~{0}", total_pending);
   List_adp list = List_adp_.New();
   boolean loop = true;
   while (loop) {
     byte rslt = Select_fsdb_itms(list);
     switch (rslt) {
       case Select_rv_stop:
         if (bin_db_mgr.Tier_id_is_last(tier_id_val)) loop = false;
         else {
           ++tier_id_val;
           page_id_val = 0;
           continue;
         }
         break;
       case Select_rv_next_page:
         ++page_id_val;
         lnki_id_val = 0;
         continue;
       case Select_rv_process:
         break;
     }
     if (!loop) break; // no more ttls found
     int len = list.Count();
     usr_dlg.Prog_many("", "", "fetched pages: ~{0}", len);
     for (int i = 0; i < len; ++i) {
       Xodb_tbl_oimg_xfer_itm fsdb = (Xodb_tbl_oimg_xfer_itm) list.Get_at(i);
       Download_itm(fsdb);
       if (exit_now
           || exec_count >= exec_count_max
           || exec_fail >= exec_fail_max
           || page_id_val >= page_id_end) {
         this.Txn_sav();
         return;
       }
     }
   }
   exec_done = true;
 }
 public Xobc_import_step_itm[] Select_by_task_id(int task_id) {
   List_adp list = List_adp_.New();
   Db_rdr rdr =
       conn.Stmt_sql(
               Db_sql_.Make_by_fmt(
                   String_.Ary(
                       "SELECT  s.*",
                       "FROM    import_step s",
                       "        JOIN step_map sm ON s.step_id = sm.step_id",
                       "WHERE   sm.task_id = {0}"),
                   task_id))
           .Exec_select__rls_auto();
   try {
     while (rdr.Move_next()) {
       list.Add(New_itm(rdr));
     }
   } finally {
     rdr.Rls();
   }
   return (Xobc_import_step_itm[]) list.To_ary_and_clear(Xobc_import_step_itm.class);
 }
Пример #9
0
 public Xol_interval_itm[] Get_duration_intervals(long seconds, Xol_duration_itm[] intervals) {
   if (intervals == null) intervals = Xol_duration_itm_.Ary_default;
   Array_.Sort(intervals, Xol_duration_itm_sorter.Instance);
   int intervals_len = intervals.length;
   long val = seconds;
   List_adp rv = List_adp_.New();
   for (int i = 0; i < intervals_len; i++) {
     Xol_duration_itm itm = intervals[i];
     long itm_seconds = itm.Seconds();
     val = seconds / itm_seconds;
     if (val > 0
         || (i == intervals_len - 1
             && rv.Count()
                 == 0) // always add one seg; EX: 40 seconds, but minutes requested -> 0 minutes;
                       // DATE:2014-05-10
     ) {
       seconds -= val * itm_seconds;
       rv.Add(new Xol_interval_itm(itm, val));
     }
   }
   return (Xol_interval_itm[]) rv.To_ary(Xol_interval_itm.class);
 }
Пример #10
0
 public static int[] Ary_get(Xow_domain_itm domain_itm, boolean wmf) {
   if (wmf && domain_itm != null && domain_itm.Domain_type().Tid() != Xow_domain_tid_.Tid__home)
     return Ary_wmf;
   if (Ary_nonwmf == null) {
     List_adp list = List_adp_.New();
     int len = Ary_wmf.length;
     for (int i = 0; i < len; ++i) {
       list.Add(Ary_wmf[i]);
     }
     list.Add_many(
         Xol_kwd_grp_.Id_strx_len,
         Xol_kwd_grp_.Id_strx_pos,
         Xol_kwd_grp_.Id_strx_rpos,
         Xol_kwd_grp_.Id_strx_sub,
         Xol_kwd_grp_.Id_strx_count,
         Xol_kwd_grp_.Id_strx_replace,
         Xol_kwd_grp_.Id_strx_explode,
         Xol_kwd_grp_.Id_strx_urldecode,
         Xol_kwd_grp_.Id_new_window_link);
     Ary_nonwmf = (int[]) list.To_ary_and_clear(int.class);
   }
   return Ary_nonwmf;
 }
Пример #11
0
public class Mem_tbl {
  private final List_adp where_rows = List_adp_.New();
  private final Hash_adp autonum_hash = Hash_adp_.New();

  public Mem_tbl(Dbmeta_tbl_itm meta) {
    this.meta = meta;
  }

  public Dbmeta_tbl_itm Meta() {
    return meta;
  }

  private final Dbmeta_tbl_itm meta;
  public final List_adp rows = List_adp_.New();

  public int Insert(Mem_stmt stmt) {
    Mem_row itm = new Mem_row();
    Dbmeta_fld_mgr flds = meta.Flds();
    int len = flds.Len();
    for (int i = 0; i < len; ++i) {
      Dbmeta_fld_itm fld = flds.Get_at(i);
      String fld_name = fld.Name();
      Object val = fld.Autonum() ? Autonum_calc(fld_name) : stmt.Args_get_by(fld_name);
      if (val == null) continue; // NOTE: allow Bulk_insert from test to skip filds
      itm.Set_by(fld_name, val);
    }
    rows.Add(itm);
    return 1;
  }

  private int Autonum_calc(String name) {
    Int_obj_ref autonum_itm = (Int_obj_ref) autonum_hash.Get_by(name);
    if (autonum_itm == null) {
      autonum_itm = Int_obj_ref.New(0);
      autonum_hash.Add(name, autonum_itm);
    }
    return autonum_itm.Val_add();
  }

  public int Update(Mem_stmt stmt) {
    Db_qry_update qry = (Db_qry_update) stmt.Qry();
    Criteria where_crt = qry.Where();
    if (where_crt == null) where_crt = Criteria_.All;
    Mem_stmt_args_.Fill(stmt.Stmt_args(), where_crt);
    Select_rows_where(where_rows, stmt, where_crt);
    int where_rows_len = where_rows.Count();
    String[] update_cols = qry.Cols_for_update();
    int update_cols_len = update_cols.length;
    for (int i = 0; i < where_rows_len; ++i) {
      Mem_row itm = (Mem_row) where_rows.Get_at(i);
      for (int j = 0; j < update_cols_len; ++j) itm.Set_by(update_cols[j], stmt.Args_get_at(j));
    }
    return where_rows_len;
  }

  public int Delete(Mem_stmt stmt) {
    Db_qry_delete qry = (Db_qry_delete) stmt.Qry();
    Mem_stmt_args_.Fill(stmt.Stmt_args(), qry.Where());
    Select_rows_where(where_rows, stmt, qry.Where());
    int where_rows_len = where_rows.Count();
    for (int i = 0; i < where_rows_len; ++i) {
      Mem_row itm = (Mem_row) where_rows.Get_at(i);
      rows.Del(itm);
    }
    return where_rows_len;
  }

  public Db_rdr Select(Mem_stmt stmt) {
    String[] select = null;
    Criteria where = null;
    Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.as_(stmt.Qry());
    if (qry == null) {
      Db_qry__select_cmd qry2 = (Db_qry__select_cmd) stmt.Qry();
      select = To_str_ary(qry2.Cols().Flds);
      where = qry2.Where_itm().Root;
    } else {
      select = qry.Select_flds();
      where = qry.Where();
    }
    Mem_stmt_args_.Fill(stmt.Stmt_args(), where);
    Select_rows_where(where_rows, stmt, where);
    return new Mem_rdr(select, (Mem_row[]) where_rows.To_ary_and_clear(Mem_row.class));
  }

  private String[] To_str_ary(Sql_select_fld_list flds) {
    int len = flds.Len();
    String[] rv = new String[len];
    for (int i = 0; i < len; ++i) rv[i] = flds.Get_at(i).Fld;
    return rv;
  }

  private void Select_rows_where(List_adp rv, Mem_stmt stmt, Criteria crt) {
    rv.Clear();
    int rows_len = rows.Count();
    for (int i = 0; i < rows_len; ++i) {
      Mem_row itm = (Mem_row) rows.Get_at(i);
      if (crt.Matches(itm)) rv.Add(itm);
    }
  }
}
Пример #12
0
public class Dpl_xnde implements Xox_xnde {
  private Dpl_itm itm = new Dpl_itm();
  private List_adp pages = List_adp_.New();

  public void Xatr__set(
      Xowe_wiki wiki,
      byte[] src,
      Mwh_atr_itm xatr,
      Object xatr_id_obj) {} // NOTE: <dynamicPageList> has no attributes

  public void Xtn_parse(
      Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
    itm.Parse(wiki, ctx, ctx.Page().Ttl().Full_txt_w_ttl_case(), src, xnde);
    Dpl_page_finder.Find_pages(pages, wiki, itm);
    if (itm.Sort_ascending() != Bool_.__byte) pages.Sort_by(new Dpl_page_sorter(itm));
  }

  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) {
    Xowe_wiki wiki = ctx.Wiki();
    Dpl_html_data html_mode = Dpl_html_data.new_(Dpl_itm_keys.Key_unordered);
    int itms_len = pages.Count();
    if (itms_len == 0) {
      if (!itm.Suppress_errors()) bfr.Add_str_a7("No pages meet these criteria.");
      return;
    }
    int itms_bgn = 0;
    if (itm.Offset() != Int_.Min_value) {
      itms_bgn = itm.Offset();
    }
    if (itm.Count() != Int_.Min_value && itms_bgn + itm.Count() < itms_len) {
      itms_len = itms_bgn + itm.Count();
    }
    boolean show_ns = itm.Show_ns();
    Bry_bfr tmp_bfr = Bry_bfr_.Get();
    Xop_amp_mgr amp_mgr = wiki.Appe().Parser_amp_mgr();
    try {
      bfr.Add(html_mode.Grp_bgn()).Add_byte_nl();
      for (int i = itms_bgn; i < itms_len; i++) {
        Xowd_page_itm page = (Xowd_page_itm) pages.Get_at(i);
        Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page.Ns_id(), page.Ttl_page_db());
        byte[] ttl_page_txt = show_ns ? ttl.Full_txt_w_ttl_case() : ttl.Page_txt();
        if (ttl_page_txt == null)
          continue; // NOTE: apparently DynamicPageList allows null pages; DATE:2013-07-22
        switch (html_mode.Tid()) {
          case Dpl_html_data.Tid_list_ul:
          case Dpl_html_data.Tid_list_ol:
            bfr.Add(Xoh_consts.Space_2).Add(html_mode.Itm_bgn()).Add(Gfh_bldr_.Bry__a_lhs_w_href);
            bfr.Add_str_a7("/wiki/")
                .Add(Gfo_url_encoder_.Href.Encode(ttl.Full_db()))
                .Add_byte_quote(); // NOTE: Full_db to encode spaces as underscores;
                                   // PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19
            Gfh_atr_.Add(
                bfr,
                Gfh_atr_.Bry__title,
                Xoh_html_wtr_escaper.Escape(
                    amp_mgr,
                    tmp_bfr,
                    ttl
                        .Full_txt_w_ttl_case())); // NOTE: Full_txt b/c title always includes ns,
                                                  // even if show_ns is off;
                                                  // PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20
            if (itm.No_follow()) bfr.Add(Bry_nofollow);
            bfr.Add_byte(Byte_ascii.Gt);
            Xoh_html_wtr_escaper.Escape(
                amp_mgr, bfr, ttl_page_txt, 0, ttl_page_txt.length, false, false);
            bfr.Add(Gfh_bldr_.Bry__a_rhs).Add(html_mode.Itm_end()).Add_byte_nl();
            // TODO_OLD:
            // lnki_wtr.Clear().Href_wiki_(ttl).Title_(ttl).Nofollow_().Write_head(bfr).Write_text(bfr).Write_tail(bfr)
            break;
          default:
            break;
        }
      }
      bfr.Add(html_mode.Grp_end()).Add_byte_nl();
    } finally {
      tmp_bfr.Mkr_rls();
    }
  }

  private static byte[] Bry_nofollow = Bry_.new_a7(" rel=\"nofollow\"");
}