1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.gui.views.*;
public class Xoa_cur implements GfoInvkAble {
public Xoa_cur(Xoae_app app) {this.app = app;} private Xoae_app app;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wiki)) {
Xog_win_itm win = app.Gui_mgr().Browser_win();
return win.Active_tab() == null ? GfoInvkAble_.Null : win.Active_page().Wikie(); // null check when called from mass html gen; DATE:2014-06-04
}
else if (ctx.Match(k, Invk_win)) return app.Gui_mgr().Browser_win();
else if (ctx.Match(k, Invk_user)) return app.Usere();
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_wiki = "wiki", Invk_win = "win", Invk_user = "user";
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.core.primitives.*; import gplx.xowa.tdbs.*;
public class Xoa_hive_mgr {
public Xoa_hive_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
public Xob_xdat_itm Itm() {return xdat_itm;}
public int Find_fil(Io_url hive_root, byte[] ttl) {
Io_url hive_url = hive_root.GenSubFil(Xotdb_dir_info_.Name_reg_fil);
if (!hive_url.Eq(regy_mgr.Fil()))
regy_mgr.Init(hive_url);
return regy_mgr.Files_find(ttl);
} private Xowd_regy_mgr regy_mgr = new Xowd_regy_mgr(); Int_obj_ref bry_len = Int_obj_ref.zero_(); Xob_xdat_file xdat_rdr = new Xob_xdat_file(); Xob_xdat_itm xdat_itm = new Xob_xdat_itm();
public Xowd_regy_mgr Regy_mgr() {return regy_mgr;}
public Xob_xdat_file Get_rdr(Io_url hive_root, byte[] fil_ext_bry, int fil_idx) {
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_m001();
byte[] tmp_bry = tmp_bfr.Bfr(); bry_len.Val_zero_();
Io_url file = Xotdb_fsys_mgr.Url_fil(hive_root, fil_idx, fil_ext_bry);
tmp_bry = Io_mgr.I.LoadFilBry_reuse(file, tmp_bry, bry_len);
xdat_rdr.Clear().Parse(tmp_bry, bry_len.Val(), file);
tmp_bfr.Clear_and_rls();
return xdat_rdr;
}
}

View File

@@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.langs.*;
public class Xoa_sys_cfg implements GfoInvkAble {
private Xoae_app app;
public Xoa_sys_cfg(Xoae_app app) {this.app = app;}
public byte[] Lang() {return lang_key;}
public Xoa_sys_cfg Lang_(byte[] v) {
lang_key = Xol_lang_itm_.Get_by_key_or_en(v).Key();
if (app.Stage() == gplx.xowa.apps.Xoa_stage_.Tid_launch) { // do not update user lang unless launched; DATE:2014-05-26
Xol_lang lang = app.Lang_mgr().Get_by_key_or_load(lang_key);
app.Usere().Lang_(lang);
app.Usere().Wiki().Html_mgr().Portal_mgr().Init();
}
return this;
} private byte[] lang_key = Xol_lang_.Key_en;
public int Options_version() {return options_version;} public Xoa_sys_cfg Options_version_(int v) {options_version = v; return this;} private int options_version = 1;
public KeyVal[] Options_lang_list() {if (options_lang_list == null) options_lang_list = Options_list_lang_.new_(); return options_lang_list;} private KeyVal[] options_lang_list;
public long Free_mem_when() {return free_mem_when;} long free_mem_when;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_version)) return Xoa_app_.Version;
else if (ctx.Match(k, Invk_build_date)) return Xoa_app_.Build_date;
else if (ctx.Match(k, Invk_free_mem_when_)) free_mem_when = gplx.ios.Io_size_.parse_or_(m.ReadStr("v"), Io_mgr.Len_mb * 5);
else if (ctx.Match(k, Invk_lang)) return lang_key;
else if (ctx.Match(k, Invk_lang_)) Lang_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_lang_list)) return Options_lang_list();
else if (ctx.Match(k, Invk_options_version)) return options_version;
else if (ctx.Match(k, Invk_options_version_)) options_version = m.ReadInt("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_version = "version", Invk_build_date = "build_date", Invk_free_mem_when_ = "free_mem_when_", Invk_options_version = "options_version", Invk_options_version_ = "options_version_"
, Invk_lang = "lang", Invk_lang_ = "lang_", Invk_lang_list = "lang_list";
}
class Options_list_lang_ {
public static KeyVal[] new_() {
Ordered_hash translated = Ordered_hash_.new_bry_();
List_adp untranslated = List_adp_.new_();
Add_itm_many(translated, Xol_lang_itm_.Id_en, Xol_lang_itm_.Id_de, Xol_lang_itm_.Id_pl, Xol_lang_itm_.Id_zh_hans, Xol_lang_itm_.Id_zh_hant); // add langs with translations first, so they alphabetize to top of list
int len = Xol_lang_itm_.Id__max;
for (int i = 0; i < len; i++) { // add rest of langs, but sort by code
Xol_lang_itm itm = Xol_lang_itm_.Get_by_id(i);
if (translated.Has(itm.Key())) continue;
untranslated.Add(itm);
}
untranslated.Sort_by(Xol_lang_itm_.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_itm)translated.Get_at(i));
for (int i = translated_max; i < len; i++)
rv[i] = new_itm((Xol_lang_itm)untranslated.Get_at(i - translated_max));
return rv;
}
private static KeyVal new_itm(Xol_lang_itm itm) {
String key_str = String_.new_u8(itm.Key());
String name_str = String_.new_u8(itm.Localized_name());
return KeyVal_.new_(key_str, name_str + " [" + key_str + "]");
}
private static void Add_itm_many(Ordered_hash translated, int... langs) {
int langs_len = langs.length;
for (int i = 0; i < langs_len; i++) {
Xol_lang_itm itm = Xol_lang_itm_.Get_by_id(langs[i]);
translated.Add_if_dupe_use_nth(itm.Key(), itm);
}
}
}

View File

@@ -0,0 +1,75 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
interface Xoac_lang_obj {}
public class Xoac_lang_grp implements Cfg_nde_obj, Xoac_lang_obj {
public Xoac_lang_grp(byte[] key) {this.key_bry = key; this.name_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Name_bry() {return name_bry;} public Xoac_lang_grp Name_bry_(byte[] v) {name_bry = v; return this;} private byte[] name_bry;
public int Sort_idx() {return sort_idx;} private int sort_idx;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return true;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {
Cfg_nde_obj rv = null;
if (Bry_.Eq(itm_type, Make_grp)) rv = new Xoac_lang_grp(itm_key);
else if (Bry_.Eq(itm_type, Make_itm)) rv = new Xoac_lang_itm(itm_key);
else throw Exc_.new_unhandled(itm_type);
rv.Nde_atrs_set(itm_atrs);
return rv;
}
public int Nde_subs_len() {return itms.Count();}
public Cfg_nde_obj Nde_subs_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {return (Cfg_nde_obj)itms.Get_by(key);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {
if (!itm_obj.Nde_typ_is_grp()) {
Xoac_lang_itm itm = (Xoac_lang_itm)itm_obj;
if (!regy.Has(itm.Key_bry())) regy.Add(itm.Key_bry(), itm);
itm.Grp_(this);
}
itms.Add(itm_key, itm_obj);
}
public void Nde_subs_del(byte[] key) {
Cfg_nde_obj cur_obj = (Cfg_nde_obj)Nde_subs_get(key);
if (!cur_obj.Nde_typ_is_grp()) {
Xoac_lang_itm cur_itm = (Xoac_lang_itm)cur_obj;
Xoac_lang_itm reg_itm = (Xoac_lang_itm)regy.Get_by(key);
if (cur_itm.Uid() == reg_itm.Uid()) regy.Del(cur_itm.Key_bry());
}
itms.Del(key);
}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) name_bry = ary[0];
if (ary_len > 1) sort_idx = Bry_.Xto_int_or(ary[1], -1);
}
public static final byte[] Make_grp = Bry_.new_u8("grp"), Make_itm = Bry_.new_u8("itm");
public int Itms_len() {return itms.Count();}
public Cfg_nde_obj Itms_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
Ordered_hash itms = Ordered_hash_.new_bry_();
private static Ordered_hash regy = Ordered_hash_.new_bry_();
public static Xoac_lang_itm Regy_get_or_null(byte[] key) {return (Xoac_lang_itm)regy.Get_by(key);}
public static Xoac_lang_itm Regy_get_or_new (byte[] key) {
Xoac_lang_itm rv = Regy_get_or_null(key);
if (rv == null) {
rv = new Xoac_lang_itm(key);
regy.Add(key, rv);
}
return rv;
}
}

View File

@@ -0,0 +1,145 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Xoac_lang_grp_tst {
Xoac_lang_grp_fxt fxt = new Xoac_lang_grp_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Add_itm_new() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+|euro|itm|de|German"
)
, fxt.grp_("euro").Itms_
( fxt.itm_("fr").Local_name_("French")
, fxt.itm_("de").Local_name_("German")
));
}
@Test public void Add_itm_nl() {
fxt.Define_bulk(String_.Concat_lines_nl
( ""
, "+|euro|itm|fr|French"
, ""
)
, fxt.grp_("euro").Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Add_grp() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+||grp|euro|European~1"
, "+|euro|itm|fr|French"
)
, fxt.grp_("euro").Name_("European").Sort_idx_(1).Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Set_grp() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+||grp|euro|European"
)
, fxt.grp_("euro").Name_("European").Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Del() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+|euro|itm|de|German"
, "-|euro|fr"
)
, fxt.grp_("euro").Itms_
( fxt.itm_("de").Local_name_("German")
));
}
@Test public void Add_grp_nest() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+||grp|wiki"
, "+|wiki|grp|euro|European"
, "+|euro|itm|de|German"
)
, fxt.grp_("wiki").Itms_
( fxt.grp_("euro").Itms_
( fxt.itm_("de").Local_name_("German")
)));
}
}
class Xoac_lang_grp_fxt {
Xoa_lang_mgr lang_mgr; Tst_mgr tst_mgr = new Tst_mgr();
public void Clear() {
Xoae_app app = Xoa_app_fxt.app_();
lang_mgr = app.Lang_mgr();
}
public Xoac_lang_itm_chkr itm_(String key) {return new Xoac_lang_itm_chkr(key);}
public Xoac_lang_grp_chkr grp_(String key) {return new Xoac_lang_grp_chkr(key);}
public Xoac_lang_grp_fxt Define_bulk(String raw, Xoac_lang_grp_chkr... expd) {
lang_mgr.Groups().Set_bulk(Bry_.new_u8(raw));
tst_mgr.Tst_ary("", expd, To_ary(lang_mgr.Groups()));
return this;
}
Xoac_lang_grp[] To_ary(Cfg_nde_root root) {
int len = root.Root_len();
Xoac_lang_grp[] rv = new Xoac_lang_grp[len];
for (int i = 0; i < len; i++) {
rv[i] = (Xoac_lang_grp)root.Root_get_at(i); // ASSUME: root only has grps (no itms)
}
return rv;
}
}
abstract class Xoac_lang_chkr_base implements Tst_chkr {
public abstract Class<?> TypeOf();
public abstract int Chk(Tst_mgr mgr, String path, Object actl);
}
class Xoac_lang_itm_chkr extends Xoac_lang_chkr_base {
public Xoac_lang_itm_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_lang_itm_chkr Local_name_(String v) {local_name = v; return this;} private String local_name;
@Override public Class<?> TypeOf() {return Xoac_lang_itm.class;}
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_lang_itm actl = (Xoac_lang_itm)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(local_name == null, path, "local_name", local_name, String_.new_u8(actl.Local_name_bry()));
return rv;
}
}
class Xoac_lang_grp_chkr extends Xoac_lang_chkr_base {
public Xoac_lang_grp_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_lang_grp_chkr Name_(String v) {name = v; return this;} private String name;
public Xoac_lang_grp_chkr Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = -1;
public Xoac_lang_grp_chkr Itms_(Xoac_lang_chkr_base... v) {this.itms = v; return this;} private Xoac_lang_chkr_base[] itms;
@Override public Class<?> TypeOf() {return Xoac_lang_grp.class;}
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_lang_grp actl = (Xoac_lang_grp)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(name == null, path, "name", name, String_.new_u8(actl.Name_bry()));
rv += mgr.Tst_val(sort_idx == -1, path, "sort_idx", sort_idx, actl.Sort_idx());
rv += mgr.Tst_sub_ary(itms, To_ary(actl), path, rv);
return rv;
}
Xoac_lang_obj[] To_ary(Xoac_lang_grp grp) {
int len = grp.Itms_len();
Xoac_lang_obj[] rv = new Xoac_lang_obj[len];
for (int i = 0; i < len; i++)
rv[i] = (Xoac_lang_obj)grp.Itms_get_at(i); // ASSUME: grp only has itms (no grps)
return rv;
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xoac_lang_itm implements Cfg_nde_obj, Xoac_lang_obj {
public Xoac_lang_itm(byte[] key) {this.key_bry = key; local_name_bry = key_bry; uid = uid_next++;} static int uid_next = 0;
public Xoac_lang_grp Grp() {return grp;} public Xoac_lang_itm Grp_(Xoac_lang_grp v) {grp = v; return this;} private Xoac_lang_grp grp;
public int Uid() {return uid;} private int uid;
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Local_name_bry() {return local_name_bry;} public Xoac_lang_itm Local_name_bry_(byte[] v) {local_name_bry = v; return this;} private byte[] local_name_bry;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return false;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Exc_.new_("langs cannot have itms", "type", itm_type, "key", itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Exc_.new_("langs cannot have itms", "key", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Exc_.new_("langs cannot have itms", "idx", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Exc_.new_("langs cannot have itms", "key", String_.new_u8(itm_key));}
public void Nde_subs_del(byte[] key) {throw Exc_.new_("langs cannot delete itms", "key", String_.new_u8(key));}
public void Nde_atrs_set(byte[][] ary) {
if (ary.length != 1) throw Exc_.new_("expecting name only", "name", String_.AryXtoStr(String_.Ary(ary)));
local_name_bry = ary[0];
}
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.core.strings.*;
public class Xoac_wiki_cfg_bldr_cmd {
public Xoac_wiki_cfg_bldr_cmd(String key, String text) {this.key = key; this.text = text;}
public String Key() {return key;} private String key;
public String Text() {return text;} private String text;
public String Exec(String_bldr sb, String wiki, String src) {
String sect_txt_bgn = sb.Add("// ").Add(key).Add(".bgn\n").Xto_str_and_clear();
String sect_txt_end = sb.Add("// ").Add(key).Add(".end\n").Xto_str_and_clear();
String sect_txt_all = sb.Add(sect_txt_bgn).Add(text + "\n").Add(sect_txt_end).Xto_str_and_clear(); // NOTE: always add \n; convenience for single line cmds
// int sect_pos_bgn = String_.FindFwd(src, sect_txt_bgn);
// if (sect_pos_bgn == String_.Find_none) // new cmd; add to end of file
return src + sect_txt_all;
// int sect_pos_end = String_.FindFwd(src, sect_txt_end);
// if (sect_pos_end == String_.Find_none)
// throw Err_.new_("section_fail: " + wiki + " " + key);
// try {
// return sb.Add(String_.Mid(src, 0, sect_pos_bgn)).Add(sect_txt_all).Add(String_.Mid(src, sect_pos_end + String_.Len(sect_txt_end), String_.Len(text))).Xto_str_and_clear();
// } catch (Exception e) {Exc_.Noop(e); throw Err_.new_("section_fail: " + wiki + " " + key);}
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xoac_wiki_cfg_bldr_fil implements GfoInvkAble {
public Xoac_wiki_cfg_bldr_fil(String wiki) {this.wiki = wiki;}
public String Wiki() {return wiki;} private String wiki;
public int Itms_count() {return list.Count();}
public Xoac_wiki_cfg_bldr_cmd Itms_get_at(int i) {return (Xoac_wiki_cfg_bldr_cmd)list.Get_at(i);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_new_cmd_)) {Itms_add(m.ReadStr("id"), m.ReadStr("text"));}
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_new_cmd_ = "new_cmd_";
public Xoac_wiki_cfg_bldr_cmd Itms_add(String key, String text) {
Xoac_wiki_cfg_bldr_cmd rv = new Xoac_wiki_cfg_bldr_cmd(key, text);
list.Add(rv);
return rv;
}
List_adp list = List_adp_.new_();
}

View File

@@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
interface Xoac_wiki_obj {}
public class Xoac_wiki_grp implements Cfg_nde_obj, Xoac_wiki_obj {
public Xoac_wiki_grp(byte[] key) {this.key_bry = key; this.name_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
public boolean Nde_typ_is_grp() {return true;}
public byte[] Nde_key() {return key_bry;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {
Cfg_nde_obj rv = null;
if (Bry_.Eq(itm_type, Make_grp)) rv = new Xoac_wiki_grp(itm_key);
else if (Bry_.Eq(itm_type, Make_itm)) rv = new Xoac_wiki_itm(itm_key);
else throw Exc_.new_unhandled(itm_type);
rv.Nde_atrs_set(itm_atrs);
return rv;
}
public int Nde_subs_len() {return itms.Count();}
public Cfg_nde_obj Nde_subs_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {return (Cfg_nde_obj)itms.Get_by(key);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {itms.Add(itm_key, itm_obj);}
public void Nde_subs_del(byte[] key) {itms.Del(key);}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) name_bry = ary[0];
}
public static final byte[] Make_grp = Bry_.new_u8("grp"), Make_itm = Bry_.new_u8("itm");
public int Itms_len() {return itms.Count();}
public Cfg_nde_obj Itms_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
Ordered_hash itms = Ordered_hash_.new_bry_();
}

View File

@@ -0,0 +1,99 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import org.junit.*;
import gplx.xowa.wikis.*;
public class Xoac_wiki_grp_tst {
Xoac_wiki_grp_fxt fxt = new Xoac_wiki_grp_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Add_itm_new() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|core|itm|commons|commons"
, "+|core|itm|meta|meta;m"
, "+|peer|itm|wiktionary|wikt;wiktionary"
, "+|peer|itm|wikisource|s"
)
, fxt.grp_("core").Itms_
( fxt.itm_("commons").Aliases_("commons")
, fxt.itm_("meta").Aliases_("meta", "m")
)
, fxt.grp_("peer").Itms_
( fxt.itm_("wiktionary").Aliases_("wikt", "wiktionary")
, fxt.itm_("wikisource").Aliases_("s")
)
);
}
}
class Xoac_wiki_grp_fxt {
Xoae_wiki_mgr wiki_mgr; Tst_mgr tst_mgr = new Tst_mgr();
public void Clear() {
Xoae_app app = Xoa_app_fxt.app_();
wiki_mgr = app.Wiki_mgr();
}
public Xoac_wiki_itm_chkr itm_(String key) {return new Xoac_wiki_itm_chkr(key);}
public Xoac_wiki_grp_chkr grp_(String key) {return new Xoac_wiki_grp_chkr(key);}
public Xoac_wiki_grp_fxt Define_bulk(String raw, Xoac_wiki_grp_chkr... expd) {
wiki_mgr.Groups().Set_bulk(Bry_.new_u8(raw));
tst_mgr.Tst_ary("", expd, To_ary(wiki_mgr.Groups()));
return this;
}
Xoac_wiki_grp[] To_ary(Cfg_nde_root root) {
int len = root.Root_len();
Xoac_wiki_grp[] rv = new Xoac_wiki_grp[len];
for (int i = 0; i < len; i++) {
rv[i] = (Xoac_wiki_grp)root.Root_get_at(i); // ASSUME: root only has grps (no itms)
}
return rv;
}
}
interface Xoac_wiki_chkr_obj extends Tst_chkr {}
class Xoac_wiki_itm_chkr implements Xoac_wiki_chkr_obj {
public Xoac_wiki_itm_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_wiki_itm_chkr Aliases_(String... v) {aliases = v; return this;} private String[] aliases;
public Class<?> TypeOf() {return Xoac_wiki_itm.class;}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_wiki_itm actl = (Xoac_wiki_itm)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(aliases == null, path, "aliases", String_.AryXtoStr(aliases), String_.AryXtoStr(String_.Ary(actl.Aliases())));
return rv;
}
}
class Xoac_wiki_grp_chkr implements Xoac_wiki_chkr_obj {
public Xoac_wiki_grp_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_wiki_grp_chkr Name_(String v) {name = v; return this;} private String name;
public Xoac_wiki_grp_chkr Itms_(Xoac_wiki_chkr_obj... v) {this.itms = v; return this;} private Xoac_wiki_chkr_obj[] itms;
public Class<?> TypeOf() {return Xoac_wiki_grp.class;}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_wiki_grp actl = (Xoac_wiki_grp)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(name == null, path, "name", name, String_.new_u8(actl.Name_bry()));
rv += mgr.Tst_sub_ary(itms, To_ary(actl), path, rv);
return rv;
}
Xoac_wiki_obj[] To_ary(Xoac_wiki_grp grp) {
int len = grp.Itms_len();
Xoac_wiki_obj[] rv = new Xoac_wiki_obj[len];
for (int i = 0; i < len; i++)
rv[i] = (Xoac_wiki_obj)grp.Itms_get_at(i); // ASSUME: grp only has itms (no grps)
return rv;
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xoac_wiki_itm implements Cfg_nde_obj, Xoac_wiki_obj {
public Xoac_wiki_itm(byte[] key) {this.key_bry = key;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[][] Aliases() {return aliases;} private byte[][] aliases;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return false;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Exc_.new_("leafs cannot have itms", "type", itm_type, "key", itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Exc_.new_("leafs cannot have itms", "key", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Exc_.new_("leafs cannot have itms", "idx", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Exc_.new_("leafs cannot have itms", "key", String_.new_u8(itm_key));}
public void Nde_subs_del(byte[] key) {throw Exc_.new_("leafs cannot delete itms", "key", String_.new_u8(key));}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) aliases = Bry_.Split(ary[0], Byte_ascii.Semic);
}
}

View File

@@ -0,0 +1,102 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xoad_wtr_dump {
public Xoad_wtr_dump(Io_url log_dir) {this.log_dir = log_dir;} Io_url log_dir;
//Xoad_dump_itm[] fil_ary = new Xoad_dump_itm[64]; int fil_ary_len = 0;
int fil_ary_size = 0;
final int bfr_ary_size_max = 1024 * 1024 * 1;
public void Write(byte[] ttl, int page_idx, Gfo_msg_log msg_log) {
int ary_len = msg_log.Ary_len(); boolean flush_me = false;
for (int i = 0; i < ary_len; i++) {
Gfo_msg_data data = msg_log.Ary_get(i);
Xoad_dump_itm rv = GetByItm(data);
if (rv.BfrLen() > bfr_ary_size_max) flush_me = true;
fil_ary_size += rv.Write(ttl, page_idx, data);
}
if (fil_ary_size > bfr_ary_size_max || flush_me)
Flush();
}
public void Flush() {
int len = dump_itms.Count();
for (int i = 0; i < len; i++) {
Xoad_dump_itm data = (Xoad_dump_itm)dump_itms.Get_at(i);
if (data != null) {
data.Flush(log_dir);
data.Rls();
}
}
dump_itms.Clear();
fil_ary_size = 0;
}
Xoad_dump_itm GetByItm(Gfo_msg_data data) {
byte[] path_bry = data.Item().Path_bry();
Xoad_dump_itm rv = (Xoad_dump_itm)dump_itms.Get_by(path_bry);
if (rv == null) {
rv = new Xoad_dump_itm(path_bry, data.Item().Key_bry());
dump_itms.Add(path_bry, rv);
}
return rv;
} private Ordered_hash dump_itms = Ordered_hash_.new_bry_();
}
class Xoad_dump_itm {
Bry_bfr bfr = Bry_bfr.new_(4096);
int pageIdx_last;
public int BfrLen() {return bfr.Len();}
public Xoad_dump_itm(byte[] ownerKey, byte[] itmKey) {
fil_name = String_.new_u8(ownerKey) + "__" + String_.new_u8(itmKey);
} String fil_name;
public void Flush(Io_url log_dir) {
Io_url fil_url = log_dir.GenSubFil_ary(fil_name, ".txt");
Io_mgr.I.AppendFilByt(fil_url, bfr.Bfr(), bfr.Len());
bfr.Reset_if_gt(Io_mgr.Len_kb);
}
public void Rls() {
bfr.Rls();
bfr = null;
}
public int Write(byte[] ttl, int page_idx, Gfo_msg_data eny) {
int old = bfr.Len();
if (page_idx != pageIdx_last) {pageIdx_last = page_idx; bfr.Add(ttl).Add_byte_nl();}
bfr.Add_byte_repeat(Byte_ascii.Space, 4);
byte[] src = eny.Src_bry();
if (src.length != 0) {
int mid_bgn = eny.Src_bgn(), mid_end = eny.Src_end();
int all_bgn = mid_bgn - 40; if (all_bgn < 0) all_bgn = 0;
int all_end = mid_end + 40; if (all_end > src.length) all_end = src.length;
Write_mid(src, all_bgn, mid_bgn);
bfr.Add_byte(Byte_ascii.Tilde).Add_byte(Byte_ascii.Num_0).Add_byte(Byte_ascii.Tilde);
Write_mid(src, mid_bgn, mid_end);
bfr.Add_byte(Byte_ascii.Tilde).Add_byte(Byte_ascii.Num_1).Add_byte(Byte_ascii.Tilde);
Write_mid(src, mid_end, all_end);
bfr.Add_byte_nl();
}
return bfr.Len() - old;
}
private void Write_mid(byte[] src, int bgn, int end) {
if (end - bgn == 0) return;
for (int i = bgn; i < end; i++) {
byte b = src[i];
switch (b) {
case Byte_ascii.Nl: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Ltr_n); break;
case Byte_ascii.Tab: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Ltr_t); break;
default: bfr.Add_byte(b); break;
}
}
}
}