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-09-13 21:54:44 -04:00
parent 2145f6382c
commit 5fe27b5b3b
649 changed files with 4726 additions and 3432 deletions

View File

@@ -16,6 +16,7 @@ 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.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.apps.langs.*;
public class Xow_lang_itm {
private final Xow_lang_grp html_grp; private final Xow_xwiki_itm xwiki; private final Xoac_lang_itm lang;
public Xow_lang_itm(Xow_lang_grp html_grp, Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.xtns.wdatas.core.*;
import gplx.xowa.html.hrefs.*;
import gplx.xowa.apps.langs.*;
public class Xow_lang_mgr {
Xow_lang_mgr() {
int len = Xol_lang_itm_.Id__max;

View File

@@ -16,7 +16,7 @@ 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.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
import gplx.xowa.langs.*; import gplx.xowa.parsers.*;
public class Xow_lang_mgr_fxt {
public void Clear() {
app = Xoa_app_fxt.app_();

View File

@@ -47,13 +47,4 @@ public class Xow_xwiki_itm implements gplx.CompareAble {
public static Xow_xwiki_itm new_(byte[] key_bry, byte[] url_fmt, int lang_id, int domain_tid, byte[] domain_bry) {
return new Xow_xwiki_itm(key_bry, url_fmt, lang_id, domain_tid, domain_bry, domain_bry);
}
public static Xow_xwiki_itm new_by_mw(Bry_bfr bfr, Gfo_url_parser url_parser, Gfo_url url, byte[] key, byte[] mw_url, byte[] domain_name) {// EX: "commons|//commons.wikimedia.org/wiki/Category:$1|Wikimedia Commons" "DMOZ|http://www.dmoz.org/Regional/Europe/$1/"|DMOZ"
byte[] gfs_url = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(bfr, mw_url); // EX: "//commons.wikimedia.org/wiki/Category:$1" -> "//commons.wikimedia.org/wiki/Category:~{0}"
url_parser.Parse(url, gfs_url, 0, gfs_url.length);
byte[] domain_bry = url.Segs__get_at_1st(); // extract "commons.wikimedia.org"
Xow_domain_itm domain = Xow_domain_itm_.parse(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_actl_key());
int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id();
return new Xow_xwiki_itm(key, gfs_url, lang_id, domain.Domain_type_id(), domain_bry, domain_name);
}
}

View File

@@ -0,0 +1,53 @@
/*
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.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.net.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.domains.*;
public class Xow_xwiki_itm_bldr {
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
private final Gfo_url_parser url_parser = new Gfo_url_parser(); private final Gfo_url url = new Gfo_url();
public Xow_xwiki_itm Bld(Xow_domain_itm cur_domain, byte[] key, byte[] mw_url, byte[] domain_name) {
byte[] xo_url = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, mw_url); // EX: "//commons.wikimedia.org/wiki/Category:$1" -> "//commons.wikimedia.org/wiki/Category:~{0}"
url_parser.Parse(url, xo_url, 0, xo_url.length);
byte[] domain_bry = url.Segs__get_at_1st(); // extract "commons.wikimedia.org"
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain_itm.Lang_actl_key());
int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id();
if (domain_name == null) { // no hard-coded name; currently dmoz or commons
domain_name = (byte[])domain_name_hash.Get_by_bry(domain_bry); // NOTE: domain_name is needed for "Related Sites" in wikivoyage
if (domain_name == null) {
if ( cur_domain.Domain_type_id() != Xow_domain_type_.Int__wikipedia // cur_domain is not wikipedia
&& domain_itm.Domain_type_id() == Xow_domain_type_.Int__wikipedia // domain_itm is wikipedia
&& cur_domain.Lang_actl_uid() == domain_itm.Lang_actl_uid() // cur_domain lang matches domain_lang
) {
domain_name = Bry__domain_name__wikipedia; // EX: in "en.wikivoyage.org", "en.wikipedia.org" should have name of "Wikipedia" (not "en.wikipedia.org")
}
else
domain_name = domain_bry; // default to domain_bry
}
}
return new Xow_xwiki_itm(key, xo_url, lang_id, domain_itm.Domain_type_id(), domain_bry, domain_name);
}
private static final Hash_adp_bry domain_name_hash = Hash_adp_bry.cs()
.Add_str_obj("commons.wikimedia.org" , Bry_.new_a7("Wikimedia Commons"))
.Add_str_obj("www.dmoz.org" , Bry_.new_a7("DMOZ"))
;
private static final byte[] Bry__domain_name__wikipedia = Bry_.new_a7("Wikipedia");
public static final Xow_xwiki_itm_bldr I = new Xow_xwiki_itm_bldr(); Xow_xwiki_itm_bldr() {}
}

View File

@@ -16,28 +16,20 @@ 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.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.core.net.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.wikis.domains.*;
public class Xow_xwiki_itm_tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_itm_fxt fxt = new Xow_xwiki_itm_fxt();
@Test public void Commons() {fxt.Test_new_by_mw("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_domain_type_.Int__commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_new_by_mw("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_domain_type_.Int__wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_new_by_mw("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_domain_type_.Int__wikipedia , Xol_lang_itm_.Id_fr);}
@Before public void init() {fxt.Clear();} private Xow_xwiki_itm_fxt fxt = new Xow_xwiki_itm_fxt();
@Test public void Commons() {fxt.Test_bld("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_domain_type_.Int__commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_bld("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_domain_type_.Int__wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_bld("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_domain_type_.Int__wikipedia , Xol_lang_itm_.Id_fr);}
}
class Xow_xwiki_itm_fxt {
private Bry_bfr tmp_bfr;
private Gfo_url_parser url_parser;
private Gfo_url tmp_url;
private byte[] key;
private Xow_domain_itm domain_itm;
public void Clear() {
tmp_bfr = Bry_bfr.new_(255);
url_parser = new Gfo_url_parser();
tmp_url = new Gfo_url();
key = Bry_.new_a7("test");
domain_itm = Xow_domain_itm.new_(Bry_.new_a7("en.wikivoyage.org"), Xow_domain_type_.Int__wikivoyage, Xol_lang_.Key_en); // NOTE: use "en.wikivoyage.org" to domain_name; needed for "Related sites"
}
public void Test_new_by_mw(String url_php, String expd_domain, String expd_url_fmt, int expd_wiki_tid, int expd_lang_tid) {
Xow_xwiki_itm itm = Xow_xwiki_itm.new_by_mw(tmp_bfr, url_parser, tmp_url, key, Bry_.new_u8(url_php), key);
public void Test_bld(String url, String expd_domain, String expd_url_fmt, int expd_wiki_tid, int expd_lang_tid) {
Xow_xwiki_itm itm = Xow_xwiki_itm_bldr.I.Bld(domain_itm, domain_itm.Domain_bry(), Bry_.new_u8(url), null);
Tfds.Eq(expd_domain , String_.new_u8(itm.Domain_bry()));
Tfds.Eq(expd_url_fmt , String_.new_u8(itm.Url_fmt()));
Tfds.Eq(expd_wiki_tid , itm.Domain_tid(), "wiki");

View File

@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.net.*;
import gplx.xowa.langs.*;
import gplx.xowa.langs.*; import gplx.xowa.apps.langs.*;
import gplx.xowa.html.hrefs.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.cfgs.*;
public class Xow_xwiki_mgr implements GfoInvkAble {
private Xowe_wiki wiki; private Xow_xwiki_mgr_srl srl;
private final Ordered_hash list = Ordered_hash_.new_bry_();
@@ -27,7 +27,7 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
public Xow_xwiki_mgr() {} // FIXME: current placeholder for viewer
public Xow_xwiki_mgr(Xowe_wiki wiki, Gfo_url_parser url_parser) {
this.wiki = wiki;
srl = new Xow_xwiki_mgr_srl(this, url_parser);
srl = new Xow_xwiki_mgr_srl(wiki.Domain_itm(), this);
}
public Xow_lang_mgr Lang_mgr() {return lang_mgr;} private final Xow_lang_mgr lang_mgr = Xow_lang_mgr.dflt_();
public int Len() {return list.Count();}
@@ -144,9 +144,9 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
case Xow_domain_type_.Int__species:
case Xow_domain_type_.Int__meta:
case Xow_domain_type_.Int__incubator: domain_str = String_.Format("{0}.wikimedia.org", wiki_name); break; // EX: commons.wikimedia.org
case Xow_domain_type_.Int__wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
case Xow_domain_type_.Int__wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
case Xow_domain_type_.Int__mediawiki: domain_str = String_.Format("www.mediawiki.org", wiki_name); break;
case Xow_domain_type_.Int__wmfblog: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
case Xow_domain_type_.Int__wmfblog: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
default: domain_str = String_.Format("{0}.{1}.org", lang_key_str, wiki_name); break; // EX: en.wiktionary.org
}
byte[] domain_bry = Bry_.new_u8(domain_str);

View File

@@ -16,14 +16,12 @@ 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.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.net.*;
import gplx.srls.dsvs.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
import gplx.srls.dsvs.*; import gplx.xowa.wikis.domains.*;
class Xow_xwiki_mgr_srl extends Dsv_wkr_base {
private byte[] key, url_fmt, name;
private final Xow_xwiki_mgr mgr;
private final Gfo_url_parser url_parser; private final Gfo_url tmp_url = new Gfo_url(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Xow_xwiki_mgr_srl(Xow_xwiki_mgr mgr, Gfo_url_parser url_parser) {
this.mgr = mgr; this.url_parser = url_parser;
private final Xow_domain_itm cur_domain; private final Xow_xwiki_mgr mgr;
public Xow_xwiki_mgr_srl(Xow_domain_itm cur_domain, Xow_xwiki_mgr mgr) {
this.cur_domain = cur_domain; this.mgr = mgr;
}
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
@@ -35,7 +33,7 @@ class Xow_xwiki_mgr_srl extends Dsv_wkr_base {
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Xow_xwiki_itm itm = Xow_xwiki_itm.new_by_mw(tmp_bfr, url_parser, tmp_url, key, url_fmt, name);
Xow_xwiki_itm itm = Xow_xwiki_itm_bldr.I.Bld(cur_domain, key, url_fmt, name);
mgr.Add_itm(itm);
}
}

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.wikis.xwikis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
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_wo_type("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) {Err_.Noop(e); throw Err_.new_wo_type("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.wikis.xwikis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
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.wikis.xwikis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
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 Err_.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_a7("grp"), Make_itm = Bry_.new_a7("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.wikis.xwikis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
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.wikis.xwikis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
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 Err_.new_wo_type("leafs cannot have itms", "type", itm_type, "key", itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_.new_wo_type("leafs cannot have itms", "key", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Err_.new_wo_type("leafs cannot have itms", "idx", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_.new_wo_type("leafs cannot have itms", "key", String_.new_u8(itm_key));}
public void Nde_subs_del(byte[] key) {throw Err_.new_wo_type("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);
}
}