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,8 +16,9 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*;
import gplx.xowa.langs.*; import gplx.xowa.apps.langs.*; import gplx.xowa.xtns.wdatas.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.domains.crts.*;
import gplx.xowa.wikis.xwikis.cfgs.*;
public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
private Xoae_app app;
private List_adp list = List_adp_.new_(); private Hash_adp_bry hash = Hash_adp_bry.ci_a7(); // ASCII:url_domain; EX:en.wikipedia.org

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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.apps.langs.*;
public class Xow_cache_mgr {
private Xowe_wiki wiki;
public Xow_cache_mgr(Xowe_wiki wiki) {

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.intl.*;
import gplx.xowa.parsers.tmpls.*;
public class Xow_defn_cache { // stores compiled Xot_defn
private Xol_lang lang; // needed to lowercase names;
private Bry_bfr upper_1st_bfr = Bry_bfr.reset_(255);

View File

@@ -0,0 +1,97 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.lists.*; /*ComparerAble*/ import gplx.xowa.bldrs.cmds.ctgs.*;
import gplx.xowa.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.parsers.utils.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xow_data_mgr implements GfoInvkAble {
private Xop_redirect_mgr redirect_mgr;
private Xoa_url tmp_url = Xoa_url.blank();
public Xow_data_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.redirect_mgr = wiki.Redirect_mgr();}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public boolean Version_is_1() {return Bool_.Y;}
public Xoae_page Get_page(Xoa_ttl ttl, boolean called_from_tmpl) {tmp_url = wiki.Utl__url_parser().Parse(ttl.Raw()); return Get_page(tmp_url, ttl, called_from_tmpl, false);}
public Xoae_page Get_page_from_msg(Xoa_ttl ttl) {tmp_url = wiki.Utl__url_parser().Parse(ttl.Raw()); return Get_page(tmp_url, ttl, false, true);}
public Xoae_page Get_page(Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
Xoae_page rv = Xoae_page.new_(wiki, ttl);
return Get_page(rv, url, ttl, called_from_tmpl, called_from_msg);
}
public Xoae_page Get_page(Xoae_page rv, Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.new_()
Xow_ns ns = ttl.Ns();
switch (ns.Id()) {
case Xow_ns_.Id_special:
wiki.Special_mgr().Special_gen(wiki, rv, url, ttl);
return rv;
case Xow_ns_.Id_mediawiki:
if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09
&& Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13
) {
Xol_lang lang = wiki.Lang();
byte[] msg_key = ttl.Page_db();
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
msg_key = lang.Case_mgr().Case_build_1st_lower(tmp_bfr, msg_key, 0, msg_key.length);
byte[] msg_val = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), msg_key).Val(); // NOTE: do not change to Get_msg_val; Get_msg_val, also replaces $1 with values, and $1 needs to be preserved for callers;
rv.Data_raw_(msg_val);
tmp_bfr.Mkr_rls();
return rv;
}
break;
}
return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect,Xoa_url_.Qarg__redirect__yes));
}
public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) {
int redirects = 0;
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
while (true) {
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl.Page_db());
if (!exists) return rv.Missing_();
if (wiki.App().App_type().Uid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_u8(ttl.Raw()));
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
byte[] bry = db_page.Text();
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id());
if (redirect_force) return rv;
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry, bry.length);
if ( redirect_ttl == null // not a redirect
|| redirects++ > 4) // too many redirects; something went wrong
break;
rv.Redirected_ttls().Add(ttl.Full_url()); // NOTE: must be url_encoded; EX: "en.wikipedia.org/?!" should generate link of "en.wikipedia.org/%3F!?redirect=no"
if (rv.Redirected_src() == null) rv.Redirected_src_(bry); // only add src for first redirect; DATE:2014-07-11
rv.Ttl_(redirect_ttl);
ns = redirect_ttl.Ns();
ttl = redirect_ttl;
}
return rv;
}
public Xoae_page Redirect(Xoae_page page, byte[] page_bry) {
Xoa_ttl trg_ttl = Xoa_ttl.parse(wiki, page_bry);
Xoa_url trg_url = Xoa_url.new_(wiki.Domain_bry(), page_bry);
page.Ttl_(trg_ttl).Url_(trg_url).Redirected_(true);
return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes));
}
public static final int File_idx_unknown = -1;
static final String GRP_KEY = "xowa.wiki.data";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_create_enabled_)) wiki.Db_mgr().Save_mgr().Create_enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_update_modified_on_enabled_)) wiki.Db_mgr().Save_mgr().Update_modified_on_enabled_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_create_enabled_ = "create_enabled_", Invk_update_modified_on_enabled_ = "update_modified_on_enabled_";
}

View File

@@ -0,0 +1,163 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.xowa.tdbs.*;
public class Xow_data_mgr_tst {
Xow_data_mgr_fxt fxt = new Xow_data_mgr_fxt();
@Before public void init() {fxt.Clear(); Tfds.Now_enabled_y_();}
@After public void term() {Tfds.Now_enabled_n_();}
@Test public void Create() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!;|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
@Test public void Update() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Update("B12", "B12 changed")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!>|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 changed\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
@Test public void Update_zip() {
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Id_main].Ext_tid_(gplx.ios.Io_stream_.Tid_zip);
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
// fxt .Create("A1", "A1 data")
// .Create("B12", "B12 data")
// .Create("C123", "C123 data")
// .Update("B12", "B12 changed")
// .Tst_regy_title("0|A1|C123|3\n")
// .Tst_data_title(String_.Concat_lines_nl
// ( "!!!!>|!!!!?|!!!!@|"
// , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
// , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
// , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
// ))
// .Tst_data_page(String_.Concat_lines_nl
// ( "zipped:!!!!9|!!!!>|!!!!=|"
// , "!!!!!\t##PX+\tA1\tA1 data\t"
// , "!!!!\"\t##PX/\tB12\tB12 changed\t"
// , "!!!!#\t##PX0\tC123\tC123 data\t"
// ))
// ;
}
@Test public void Create_out_of_order() {
fxt .Create("C123", "C123 data")
.Create("B12", "B12 data")
.Create("A1", "A1 data")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!#|!!!!!|!!!!#|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!!|!!!!!|!!!!!|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!=|!!!!;|!!!!9|"
, "!!!!!\t##PX+\tC123\tC123 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tA1\tA1 data\t"
))
;
}
@Test public void Rename() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Rename("C123", "C1234")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!;|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
}
class Xow_data_mgr_fxt {
Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public void Clear() {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
wiki.Db_mgr().Save_mgr().Page_id_next_(0);
}
public Xow_data_mgr_fxt Create(String ttl_str, String data) {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(ttl_str));
wiki.Db_mgr().Save_mgr().Data_create(ttl, Bry_.new_u8(data));
return this;
}
public Xow_data_mgr_fxt Update(String ttl_str, String data) {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(ttl_str));
Xoae_page page = Xoae_page.test_(wiki, ttl);
wiki.Db_mgr().Save_mgr().Data_update(page, Bry_.new_u8(data));
return this;
}
public Xow_data_mgr_fxt Rename(String old_ttl, String new_ttl) {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(old_ttl));
Xoae_page page = Xoae_page.test_(wiki, ttl);
wiki.Db_mgr().Save_mgr().Data_rename(page, ttl.Ns().Id(), Bry_.new_u8(new_ttl));
return this;
}
public Xow_data_mgr_fxt Tst_regy_title(String expd) {return Tst_regy(Xotdb_dir_info_.Name_title, expd);}
Xow_data_mgr_fxt Tst_regy(String name, String expd) {
Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/" + name + "/reg.csv");
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(file_orig));
return this;
}
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Id_main, 0, expd);}
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Id_main, 0, expd);}
public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) {
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil);
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(url));
return this;
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*;
public class Xowd_page_itm implements Xobl_data_itm {
public class Xowd_page_itm {
public Xowd_page_itm() {this.Clear();}
public int Id() {return id;} public Xowd_page_itm Id_(int v) {id = v; id_val = null; return this;} private int id;
public Int_obj_val Id_val() {if (id_val == null) id_val = Int_obj_val.new_(id); return id_val;} private Int_obj_val id_val;

View File

@@ -0,0 +1,29 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xoa_ttl_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Xoa_ttl.class;}
public int Chk(Tst_mgr mgr, String path, Object o) {
Xoa_ttl actl = (Xoa_ttl)o;
int rv = 0;
rv += mgr.Tst_val(expd_str == null, path, "raw", expd_str, String_.new_u8(actl.Raw()));
return rv;
}
public String Expd_str() {return expd_str;} public Xoa_ttl_chkr Expd_str_(String v) {expd_str = v; return this;} private String expd_str;
public static Xoa_ttl_chkr new_(String v) {return new Xoa_ttl_chkr().Expd_str_(v);} private Xoa_ttl_chkr() {}
}

View File

@@ -0,0 +1,56 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xop_ttl_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "ttl");
public static final Gfo_msg_itm
Len_0 = Gfo_msg_itm_.new_warn_(owner, "Len_0")
, Len_max = Gfo_msg_itm_.new_warn_(owner, "Len_max")
, Ttl_has_ns_but_no_page = Gfo_msg_itm_.new_warn_(owner, "Ttl_has_ns_but_no_page")
, Ttl_is_ns_only = Gfo_msg_itm_.new_warn_(owner, "Ttl_is_ns_only")
, Amp_unknown = Gfo_msg_itm_.new_warn_(owner, "Amp_unknown")
, Comment_eos = Gfo_msg_itm_.new_warn_(owner, "Comment_eos")
, Invalid_char = Gfo_msg_itm_.new_warn_(owner, "Invalid_char")
;
}
class Xop_redirect_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "redirect");
public static final Gfo_msg_itm
False_match = Gfo_msg_itm_.new_warn_(owner, "False_match")
, Lnki_not_found = Gfo_msg_itm_.new_warn_(owner, "Lnki_not_found")
;
}
class Xop_tag_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tag");
public static final Gfo_msg_itm
Invalid = Gfo_msg_itm_.new_warn_(owner, "Invalid")
;
}
// class Pf_func_lang_log {
// private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tmpl_func_lang");
// public static final Gfo_msg_itm
// Arg_out_of_bounds = Gfo_msg_itm_.new_warn_(owner, "Arg_out_of_bounds")
// ;
// }
// class Mwl_expr_log {
// private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "expr");
// public static final Gfo_msg_itm
// Divide_by_zero = Gfo_msg_itm_.new_warn_(owner, "Divide_by_zero")
// , Expr_len0 = Gfo_msg_itm_.new_warn_(owner, "Expr_len0")
// ;
// }

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);
}
}