@Override
  public Xobc_xodir_dir[] Get_dirs(Xoa_app app) {
    Ordered_hash hash = Ordered_hash_.New();

    // add default app dir
    String default_data_dir = context.getApplicationInfo().dataDir + "/";
    String selected =
        app.User()
            .User_db_mgr()
            .Cfg()
            .Get_app_str_or(Xobc_xodir_cfg.Key__selected_dir, default_data_dir);
    Xobc_xodir_dir itm =
        new Xobc_xodir_dir(
            String_.Eq(selected, default_data_dir), false, Bry_.new_u8(default_data_dir));
    hash.Add(default_data_dir, itm);

    // add "guessed" external dirs
    Sdcard_detection_strategy[] strategy_ary =
        new Sdcard_detection_strategy[] {
          new Strategy__storage_dir(-1),
          new Strategy__envvar__external_storage(-1),
          new Strategy__envvar__secondary_storage(
              -1) // NOTE: needed for BLU-STUDIO C 5+5 LTE; DATE: 2016-06-28
        };
    int len = strategy_ary.length;
    String root_rhs = Sdcard_detection_mgr.Get_root_rhs() + "/";
    for (int i = 0; i < len; ++i) {
      Sdcard_detection_strategy strategy = strategy_ary[i];
      String[] dir_strs = strategy.Get_dirs(context);
      for (String dir_str : dir_strs) {
        if (dir_str == null) continue;
        dir_str += root_rhs;
        if (hash.Has(dir_str)) continue;
        File dir = new File(dir_str);
        if (!dir.exists())
          continue; // dir doesn't exist; don't bother trying to create b/c permission won't be
                    // available at 4.4+
        if (!Sdcard_detection_mgr.Dir_is_writeable(dir)) continue;
        itm = new Xobc_xodir_dir(String_.Eq(selected, dir_str), false, Bry_.new_u8(dir_str));
        hash.Add(dir_str, itm);
      }
    }

    // add custom dir
    String custom =
        app.User()
            .User_db_mgr()
            .Cfg()
            .Get_app_str_or(Xobc_xodir_cfg.Key__custom_dir, "(choose your own folder)");
    itm = new Xobc_xodir_dir(String_.Eq(selected, custom), true, Bry_.new_u8(custom));
    hash.Add(custom, itm);
    return (Xobc_xodir_dir[]) hash.To_ary(Xobc_xodir_dir.class);
  }
Exemple #2
0
 //	public Io_url[] Src_fils() {return src_fils;} public Io_line_rdr_fxt Src_fils_(Io_url[] v)
 // {src_fils = v; return this;} Io_url[] src_fils;
 public Io_line_rdr_fxt tst_Match(String match, String expd) {
   rdr.Key_gen_(Io_line_rdr_key_gen_.first_pipe);
   boolean match_v = rdr.Match(Bry_.new_u8(match));
   String actl = match_v ? String_.new_u8(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end()) : "";
   Tfds.Eq(expd, actl);
   return this;
 }
 public void Srl_save(Bry_bfr bfr) {
   byte[] bmk_bry =
       Bry_.Replace(
           Bry_.new_u8(bmk_pos),
           Byte_ascii.Pipe,
           Byte_ascii.Tilde); // replace | with ~; EX: "0|1|2" -> "0~1~2"
   bfr.Add(key).Add_byte_pipe().Add(bmk_bry).Add_byte_nl();
 }
 private static void New_subs(Io_url owner_dir, List_adp list, IoItmList subs, byte[] dir_cmd) {
   subs.Sort();
   int len = subs.Len();
   int list_total = list.Len();
   byte[] owner_dir_bry = owner_dir.RawBry();
   for (int i = 0; i < len; ++i) {
     IoItm_base src = (IoItm_base) subs.Get_at(i);
     Xow_import_doc trg = null;
     if (src.Type_dir()) {
       byte[] trg_url = src.Url().RawBry();
       trg =
           new Xow_import_doc(
               Bool_.Y,
               Bool_.N,
               list_total + i,
               owner_dir_bry,
               trg_url,
               Bry_.new_u8(src.Url().NameAndExt_noDirSpr()),
               Bry_.Empty,
               Bry_.Empty,
               dir_cmd,
               Ary_empty);
     } else {
       IoItmFil src_as_fil = (IoItmFil) src;
       String size_str = Io_size_.To_str(src_as_fil.Size(), "#,###");
       boolean is_xowa_core =
           gplx.xowa.wikis.data.Xow_db_file__core_.Is_core_fil_name(
               owner_dir.NameOnly(), src.Url().NameAndExt());
       trg =
           new Xow_import_doc(
               Bool_.N,
               is_xowa_core,
               list_total + i,
               owner_dir_bry,
               src.Url().RawBry(),
               Bry_.new_u8(src.Name()),
               Bry_.new_u8(src_as_fil.ModifiedTime().XtoStr_fmt("yyyy-MM-dd")),
               Bry_.new_u8(size_str),
               dir_cmd,
               Ary_empty);
     }
     list.Add(trg);
   }
 }
Exemple #5
0
 public void Init_page_insert(Int_obj_ref page_id_next, int ns_id, String[] ttls) {
   Xowe_wiki wiki = this.Wiki();
   int len = ttls.length;
   DateAdp modified_on = Tfds.Now_time0_add_min(0);
   Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
   tbl_page.Insert_bgn();
   for (int i = 0; i < len; i++) {
     String ttl = ttls[i];
     int page_id = page_id_next.Val();
     tbl_page.Insert_cmd_by_batch(
         page_id, ns_id, Bry_.new_u8(ttl), false, modified_on, 0, page_id, 0, 0);
     page_id_next.Val_add(1);
   }
   tbl_page.Insert_end();
 }
 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);
 }
 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);
   }
 }
 String Replace_invalid_chars_str(String raw_str) {
   return String_.new_u8(Replace_invalid_chars(Bry_.new_u8(raw_str)));
 }
 public static Xopg_tag_itm New_js_code(String code) {
   return New_js_code(Bry_.new_u8(code));
 }
	public void Init_page_create(Xowe_wiki wiki, String ttl, String txt) {
		Xoa_ttl page_ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl));
		byte[] page_raw = Bry_.new_u8(txt);
		wiki.Db_mgr().Save_mgr().Data_create(page_ttl, page_raw);
	}
 public byte[] Eval(byte[] cmd) {
   Object rslt = GfsCore.Instance.Exec_bry(cmd);
   return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
 }
Exemple #12
0
 public Btrie_fast_mgr Add(String key, Object val) {
   return Add(Bry_.new_u8(key), val);
 }
Exemple #13
0
 public Btrie_fast_mgr Add_str_byte(String key, byte val) {
   return Add(Bry_.new_u8(key), Byte_obj_val.new_(val));
 }
Exemple #14
0
 public Btrie_fast_mgr Add_stub(byte tid, String s) {
   byte[] bry = Bry_.new_u8(s);
   Btrie_itm_stub stub = new Btrie_itm_stub(tid, bry);
   return Add(bry, stub);
 }
 private void Init(Db_engine engine) {
   init = false;
   tbl_mgr.Clear();
   idx_mgr.Clear();
   Dbmeta_parser__tbl tbl_parser = new Dbmeta_parser__tbl();
   Dbmeta_parser__idx idx_parser = new Dbmeta_parser__idx();
   Db_qry__select_in_tbl qry =
       Db_qry__select_in_tbl.new_(
           "sqlite_master",
           String_.Ary_empty,
           String_.Ary("type", "name", "sql"),
           Db_qry__select_in_tbl.Order_by_null);
   Db_rdr rdr = engine.Stmt_by_qry(qry).Exec_select__rls_auto();
   try {
     Gfo_usr_dlg_.Instance.Log_many(
         "", "", "db.schema.load.bgn: conn=~{0}", engine.Conn_info().Db_api());
     while (rdr.Move_next()) {
       String type_str = rdr.Read_str("type");
       String name = rdr.Read_str("name");
       String sql = rdr.Read_str("sql");
       try {
         int type_int = Dbmeta_itm_tid.Xto_int(type_str);
         switch (type_int) {
           case Dbmeta_itm_tid.Tid_table:
             if (String_.Has_at_bgn(name, "sqlite_"))
               continue; // ignore b/c of non-orthodox syntax; EX: "CREATE TABLE
                         // sqlite_sequence(name, seq)"; also "CREATE TABLE
                         // sqlite_stat(tbl,idx,stat)";
             tbl_mgr.Add(tbl_parser.Parse(Bry_.new_u8(sql)));
             break;
           case Dbmeta_itm_tid.Tid_index:
             if (sql == null)
               continue; // ignore "autoindex"; EX: sqlite_autoindex_temp_page_len_avg_1
             idx_mgr.Add(idx_parser.Parse(Bry_.new_u8(sql)));
             break;
           default:
             Gfo_usr_dlg_.Instance.Log_many(
                 "",
                 "",
                 "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}",
                 engine.Conn_info().Db_api(),
                 type_str,
                 name,
                 sql);
             break;
         }
       } catch (
           Exception
               e) { // tables / indexes may be unparseable; skip them; EX: CREATE TABLE unparseable
                    // (col_1 /*comment*/ int); DATE:2016-06-08
         Gfo_usr_dlg_.Instance.Log_many(
             "",
             "",
             "db.schema.unparseable: conn=~{0} type=~{1} name=~{2} sql=~{3} err=~{4}",
             engine.Conn_info().Db_api(),
             type_str,
             name,
             sql,
             Err_.Message_gplx_log(e));
       }
     }
   } finally {
     rdr.Rls();
   }
 }
Exemple #16
0
class Hiero_html_wtr {
  private Hiero_phoneme_mgr phoneme_mgr;
  private Bry_bfr temp_bfr = Bry_bfr.reset_(255);

  public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) {
    this.phoneme_mgr = phoneme_mgr;
  }

  public void Init_for_write(Xoh_wtr_ctx hctx) {
    this.hiero_img_dir =
        hctx.Mode_is_hdump()
            ? gplx.xowa.html.hdumps.abrvs.Xohd_abrv_.Key_hiero_dir
            : Hiero_xtn_mgr.Img_src_dir;
  }

  private byte[] hiero_img_dir = null;

  public void Hr(Bry_bfr bfr) {
    bfr.Add(Html_tag_.Hr_inl).Add_byte_nl();
  }

  public void Tbl_eol(Bry_bfr bfr) {
    bfr.Add(Tbl_eol_bry);
  }

  public byte[] Td_height(int height) {
    return temp_bfr.Add(Option_bgn_bry)
        .Add_int_variable(height)
        .Add(Option_end_bry)
        .Xto_bry_and_clear();
  }

  private static final byte[] Option_bgn_bry = Bry_.new_a7("height: "),
      Option_end_bry = Bry_.new_a7("px;");

  public void Td(Bry_bfr bfr, byte[] glyph) {
    bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry);
  }

  private static final byte[] Td_bgn_bry = Bry_.new_a7("\n          <td>"),
      Td_end_bry = Bry_.new_a7("\n          </td>");

  public void Cartouche_bgn(Bry_bfr bfr) {
    bfr.Add(Cartouche_bgn_lhs_bry)
        .Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100)
        .Add(Cartouche_bgn_rhs_bry);
  }

  private static final String Tbl_bgn_str = "<table class=\"mw-hiero-table\">";
  private static final byte[]
      Cartouche_bgn_lhs_bry =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last(
                  "",
                  "          <td>",
                  "            " + Tbl_bgn_str,
                  "              <tr>",
                  "                <td class='mw-hiero-box' style='height: ")),
      Cartouche_bgn_rhs_bry =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last(
                  "px;'>",
                  "                </td>",
                  "              </tr>",
                  "              <tr>",
                  "                <td>",
                  "                  " + Tbl_bgn_str,
                  "                    <tr>"));

  public void Cartouche_end(Bry_bfr bfr) {
    bfr.Add(Cartouche_end_lhs_bry)
        .Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100)
        .Add(Cartouche_end_rhs_bry);
  }

  private static final byte[]
      Cartouche_end_lhs_bry =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last(
                  "",
                  "                    </tr>",
                  "                  </table>",
                  "                </td>",
                  "              </tr>",
                  "              <tr>",
                  "                <td class='mw-hiero-box' style='height: ")),
      Cartouche_end_rhs_bry =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last(
                  "px;'>",
                  "                </td>",
                  "              </tr>",
                  "            </table>",
                  "          </td>"));

  public byte[] Cartouche_img(
      Xoh_wtr_ctx hctx,
      boolean bgn,
      byte[] glyph) { // render open / close cartouche; note that MW has two branches, but they are
    // both the same
    int height = (int) ((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100);
    Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph);
    if (phoneme_itm == null) throw Err_.new_fmt_("missing phoneme: {0}", String_.new_u8(glyph));
    byte[] code = phoneme_itm.Gardiner_code();
    byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry;
    return cartouche_img_fmtr.Bld_bry_many(temp_bfr, hiero_img_dir, code, height, title);
  }

  private static final Bry_fmtr cartouche_img_fmtr =
      Bry_fmtr.new_(
          String_.Concat(
              "\n            <img src='~{path}hiero_~{code}.png'",
              " height='~{height}' title='~{title}'",
              " alt='~{title}' />"),
          "path",
          "code",
          "height",
          "title");

  public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) {
    html_bfr.Add(Tbl_inner_bgn)
        .Add_bfr_and_clear(text_bfr)
        .Add(Tbl_inner_end); // 	$html .= self::TABLE_START . "<tr>\n" . $tableContentHtml .
    // '</tr></table>';
  }

  private static final byte[]
      Tbl_inner_bgn =
          Bry_.new_u8(
              String_.Concat_lines_nl_skip_last(
                  "      <table class=\"mw-hiero-table\">", "        <tr>")),
      Tbl_inner_end =
          Bry_.new_u8(String_.Concat_lines_nl_skip_last("", "        </tr>", "      </table>"));

  public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) {
    bfr.Add(Outer_tbl_bgn);
    bfr.Add_bfr_and_clear(html_bfr);
    bfr.Add(Outer_tbl_end);
  }

  private static final byte[]
      Outer_tbl_bgn =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last(
                  "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>",
                  "  <tr>",
                  "    <td>",
                  "")),
      Outer_tbl_end =
          Bry_.new_a7(
              String_.Concat_lines_nl_skip_last("", "    </td>", "  </tr>", "</table>", ""));

  public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) {
    byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code);
    byte[] img_title =
        temp_bfr.Add(code_esc)
            .Add_byte_space()
            .Add_byte(Byte_ascii.Brack_bgn)
            .Add(glyph_esc)
            .Add_byte(Byte_ascii.Brack_end)
            .Xto_bry_and_clear(); // "~{code} [~{glyph}]"
    return Img(img_cls, td_height, glyph_esc, code_esc, img_title);
  }

  public byte[] Img_file(byte[] img_cls, byte[] td_height, byte[] glyph_esc) {
    return Img(img_cls, td_height, glyph_esc, glyph_esc, glyph_esc);
  }

  private byte[] Img(
      byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) {
    byte[] img_src = Bld_img_src(hiero_img_dir, img_src_name);
    return glyph_img_fmtr.Bld_bry_many(
        temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src, img_title, glyph);
  }

  private static final byte[] Tbl_eol_bry =
      Bry_.new_a7(
          String_.Concat_lines_nl_skip_last(
              "", "        </tr>", "      </table>", "      " + Tbl_bgn_str, "        <tr>"));
  private static final Bry_fmtr glyph_img_fmtr =
      Bry_fmtr.new_(
          "\n            <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />",
          "img_cls",
          "img_margin",
          "option",
          "img_src",
          "img_title",
          "glyph");

  public byte[] Void(boolean half) { // render void
    int width = Hiero_html_mgr.Max_height;
    if (half) width /= 2;
    return void_fmtr.Bld_bry_many(temp_bfr, width);
  }

  private static final Bry_fmtr void_fmtr =
      Bry_fmtr.new_(
          String_.Concat_lines_nl_skip_last(
              "",
              "            <table class=\"mw-hiero-table\" style=\"width: ~{width}px;\">",
              "              <tr>",
              "                <td>&#160;",
              "                </td>",
              "              </tr>",
              "            </table>"),
          "width");

  private static byte[] Bld_img_src(byte[] hiero_img_dir, byte[] name) {
    return Bry_.Add(hiero_img_dir, Img_src_prefix, name, Img_src_ext);
  }

  private static final byte[] Img_src_prefix = Bry_.new_a7("hiero_"),
      Img_src_ext = Bry_.new_a7(".png");
}