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-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
import org.junit.*;
import gplx.xowa.apps.*;
import gplx.xowa.apps.gfss.*;
public class Xoa_app_eval_tst {
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
@Before public void init() {fxt.Clear();}

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.apps; import gplx.*; import gplx.xowa.*;
import org.junit.*;
import org.junit.*; import gplx.xowa.apps.gfss.*;
public class Xoa_shell_tst {
@Test public void Fetch_page() { // PURPOSE.fix: fetch_page failed with nullRef; DATE:2013-04-12
Xop_fxt parser_fxt = new Xop_fxt();

View File

@@ -0,0 +1,78 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.net.*; import gplx.langs.jsons.*;
import gplx.ios.*;
import gplx.dbs.*; import gplx.xowa.apis.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.metas.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.langs.cases.*; import gplx.core.intls.*; import gplx.xowa.users.data.*;
import gplx.xowa.apps.urls.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.html.hrefs.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.bridges.*;
import gplx.xowa.users.*;
import gplx.xowa.wikis.*;
import gplx.xowa.wms.*;
import gplx.langs.htmls.encoders.*;
public class Xoav_app implements Xoa_app {
public Xoav_app(Gfo_usr_dlg usr_dlg, Xoa_app_type app_type, String plat_name, Io_url root_dir, Io_url file_dir, Io_url css_dir) {
Xoa_app_.Usr_dlg_(usr_dlg); this.usr_dlg = usr_dlg; this.app_type = app_type;
this.fsys_mgr = new Xoa_fsys_mgr(plat_name, root_dir, root_dir.GenSubDir("wiki"), file_dir, css_dir);
this.meta_mgr = new Xoa_meta_mgr(this);
this.file__cache_mgr = new Xof_cache_mgr(usr_dlg, null, null);
this.file__img_mgr = new Xof_img_mgr();
this.wiki_mgr = new Xoav_wiki_mgr(this, utl_case_mgr);
this.utl_msg_log = Gfo_msg_log.Test();
this.html__lnki_bldr = new Xoh_lnki_bldr(this, html__href_wtr);
this.html__bridge_mgr = new Xoh_bridge_mgr(utl__json_parser);
this.user = new Xouv_user("anonymous");
this.api_root = null;
}
public Xou_user User() {return user;} private final Xouv_user user;
public Xoapi_root Api_root() {return api_root;} private final Xoapi_root api_root;
public Xoa_app_type App_type() {return app_type;} private final Xoa_app_type app_type;
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
public Xoav_wiki_mgr Wiki_mgr() {return wiki_mgr;} private final Xoav_wiki_mgr wiki_mgr;
public Xoa_wiki_mgr Wiki_mgri() {return wiki_mgr;}
public Xof_cache_mgr File__cache_mgr() {return file__cache_mgr;} private final Xof_cache_mgr file__cache_mgr;
public Xof_img_mgr File__img_mgr() {return file__img_mgr;} private final Xof_img_mgr file__img_mgr;
public Io_download_fmt File__download_fmt() {return file__download_fmt;} private final Io_download_fmt file__download_fmt = new Io_download_fmt();
public Xoh_href_parser Html__href_parser() {return href_parser;} private final Xoh_href_parser href_parser = new Xoh_href_parser();
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public Xoh_lnki_bldr Html__lnki_bldr() {return html__lnki_bldr;} private final Xoh_lnki_bldr html__lnki_bldr;
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr;
public Xoa_meta_mgr Meta_mgr() {return meta_mgr;} private final Xoa_meta_mgr meta_mgr;
public Gfo_inet_conn Utl__inet_conn() {return inet_conn;} public void Utl__inet_conn_(Gfo_inet_conn v) {this.inet_conn = v;} private Gfo_inet_conn inet_conn;
public boolean Xwiki_mgr__missing(byte[] domain) {return wiki_mgr.Get_by_domain(domain) == null;}
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public void Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v; Xoa_app_.Usr_dlg_(usr_dlg);} private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Noop;
public Bry_bfr_mkr Utl__bfr_mkr() {return Xoa_app_.Utl__bfr_mkr();}
public Url_encoder_mgr Utl__encoder_mgr() {return Xoa_app_.Utl__encoder_mgr();}
public Json_parser Utl__json_parser() {return utl__json_parser;} private final Json_parser utl__json_parser = new Json_parser();
public boolean Bldr__running() {return bldr__running;} public void Bldr__running_(boolean v) {this.bldr__running = v;} private boolean bldr__running;
public Xop_amp_mgr Utl_amp_mgr() {return utl_amp_mgr;} private Xop_amp_mgr utl_amp_mgr = Xop_amp_mgr.I;
public Xol_case_mgr Utl_case_mgr() {return utl_case_mgr;} private Xol_case_mgr utl_case_mgr = Xol_case_mgr_.U8();
public Url_encoder Utl_encoder_fsys() {return utl_encoder_fsys;} private Url_encoder utl_encoder_fsys = Url_encoder.new_fsys_lnx_();
public Gfo_msg_log Utl_msg_log() {return utl_msg_log;} private Gfo_msg_log utl_msg_log;
public Xoav_url_parser Utl_url_parser_xo() {return utl_url_parser_xo;} private Xoav_url_parser utl_url_parser_xo = new Xoav_url_parser();
public Gfo_url_parser Utl_url_parser_gfo() {return utl_url_parser_gfo;} private final Gfo_url_parser utl_url_parser_gfo = new Gfo_url_parser();
public void Init_by_app(Io_url user_db_url) {
user.Init_db(this, wiki_mgr, user_db_url);
}
}

View File

@@ -0,0 +1,73 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.xowa.*; import gplx.xowa.langs.cases.*; import gplx.xowa.users.data.*;
import gplx.xowa.wikis.*;
public class Xoav_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
private final Xoav_app app; private final Ordered_hash hash = Ordered_hash_.new_bry_();
public Xoav_wiki_mgr(Xoav_app app, Xol_case_mgr case_mgr) {this.app = app;}
public Xowv_wiki Get_by_domain(byte[] domain) {return (Xowv_wiki)hash.Get_by(domain);}
public Xowv_wiki Import_by_fil(Io_url fil) {
Io_url wiki_dir = fil.OwnerDir();
Xowv_wiki rv = Load(Gen_domain_str(fil.NameOnly()), wiki_dir);
app.User().User_db_mgr().Site_mgr().Import(rv.Domain_str(), rv.Domain_str(), wiki_dir.Raw(), "");
return rv;
}
public void Load_by_user_data() {
Xoud_site_row[] ary = app.User().User_db_mgr().Site_mgr().Get_all();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xoud_site_row itm = ary[i];
Load(itm.Domain(), Io_url_.new_dir_(itm.Path()));
}
}
public Xowv_wiki Load_by_fil(Io_url fil) {
return Load(Gen_domain_str(fil.NameOnly()), fil.OwnerDir());
}
public boolean Has(byte[] key) {return hash.Has(key);}
public Xow_wiki Get_by_key_or_make_init_y(byte[] key) {
Xow_wiki rv = this.Get_by_domain(key);
// if (rv == null) rv = New_wiki(key); // TODO: must init wiki, but need wiki_url; DATE:2015-05-23
return rv;
}
public Xow_wiki Get_by_key_or_make_init_n(byte[] key) {return Get_by_key_or_make_init_y(key);}
public void Load_by_dir(Io_url wiki_root_dir) {
Io_url[] wiki_dirs = Io_mgr.I.QueryDir_args(wiki_root_dir).DirOnly_().ExecAsUrlAry();
for (Io_url wiki_dir : wiki_dirs) {
String wiki_dir_url = wiki_dir.Raw();
if (String_.Has_at_bgn(wiki_dir_url, "#")) continue;
Load(wiki_dir.NameOnly(), wiki_dir);
}
}
private Xowv_wiki Load(String domain_str, Io_url wiki_dir) {
byte[] domain_bry = Bry_.new_u8(domain_str);
Xowv_wiki rv = new Xowv_wiki(app, domain_bry, wiki_dir);
hash.Add_if_dupe_use_nth(domain_bry, rv);
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_import_by_fil)) return Import_by_fil(Io_url_.new_fil_(m.ReadStr("v")));
else return GfoInvkAble_.Rv_unhandled;
}
public static final String Invk_import_by_fil = "import_by_fil";
private static String Gen_domain_str(String file_name) {
int dash_pos = String_.FindFwd(file_name, "-");
if (dash_pos != Bry_find_.Not_found) file_name = String_.Mid(file_name, 0, dash_pos);
return file_name;
}
}

View File

@@ -0,0 +1,21 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public interface Gfo_sort_able {
void Sort(gplx.lists.ComparerAble comparer);
}

View File

@@ -0,0 +1,65 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_fmtr_itm implements GfoInvkAble {
public Xoa_fmtr_itm(Xoae_app app) {this.app = app;} private Xoae_app app;
public String Src() {return src;} public Xoa_fmtr_itm Src_(String v) {this.src = v; return this;} private String src;
public byte[] Fmt() {return fmt;} public Xoa_fmtr_itm Fmt_(byte[] v) {this.fmt = v; return this;} private byte[] fmt;
public Object Sorter() {
GfoInvkAble src_invk = (GfoInvkAble)app.Gfs_mgr().Run_str(src);
return GfoInvkAble_.InvkCmd(src_invk, Invk_sorter);
}
public String Run() {
GfoInvkAble src_invk = (GfoInvkAble)app.Gfs_mgr().Run_str(src);
int len = Int_.cast(GfoInvkAble_.InvkCmd(src_invk, Invk_len));
Bry_bfr bfr = Bry_bfr.new_();
Bfmtr_eval_invk eval_mgr = new Bfmtr_eval_invk(app);
Bry_fmtr fmtr = Bry_fmtr.new_bry_(fmt).Eval_mgr_(eval_mgr);
for (int i = 0; i < len; i++) {
GfoInvkAble itm_invk = (GfoInvkAble)GfoInvkAble_.InvkCmd_val(src_invk, Invk_get_at, i);
eval_mgr.Invk_(itm_invk);
fmtr.Bld_bfr(bfr, Bry_.Ary_empty);
}
return bfr.Xto_str_and_clear();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_src)) return src;
else if (ctx.Match(k, Invk_src_)) src = m.ReadStr("v");
else if (ctx.Match(k, Invk_fmt)) return String_.new_u8(fmt);
else if (ctx.Match(k, Invk_fmt_)) fmt = m.ReadBry("v");
else if (ctx.Match(k, Invk_sorter)) return this.Sorter();
else if (ctx.Match(k, Invk_run)) return Run();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_src = "src", Invk_src_ = "src_", Invk_fmt = "fmt", Invk_fmt_ = "fmt_"
, Invk_run = "run"
;
public static final String Invk_get_at = "get_at", Invk_len = "len"
, Invk_sorter = "sorter"
;
}
class Bfmtr_eval_invk implements Bry_fmtr_eval_mgr {
public Bfmtr_eval_invk(Xoae_app app) {this.app = app;} private Xoae_app app;
public Bfmtr_eval_invk Invk_(GfoInvkAble invk) {this.invk = invk; return this;} private GfoInvkAble invk;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public byte[] Eval(byte[] cmd) {
Object rslt = app.Gfs_mgr().Run_str_for(invk, String_.new_u8(cmd));
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
}

View File

@@ -0,0 +1,42 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_fmtr_itm_tst {
@Before public void init() {fxt.Clear();} private Xoa_fmtr_itm_fxt fxt = new Xoa_fmtr_itm_fxt();
@Test public void Basic() {
fxt.Init_src("app.wikis;");
fxt.Init_fmt("domain=~{<>domain;<>};");
fxt.Test_run("domain=en.wikipedia.org;");
}
}
class Xoa_fmtr_itm_fxt {
private Xoae_app app; private Xoa_fmtr_itm itm;
public void Clear() {
app = Xoa_app_fxt.app_();
Xoa_app_fxt.wiki_tst_(app); // create enwiki
itm = new Xoa_fmtr_itm(app);
GfsCore._.MsgParser_(gplx.langs.gfss.Gfs_msg_bldr._);
}
public Xoa_fmtr_itm_fxt Init_src(String v) {itm.Src_(v); return this;}
public Xoa_fmtr_itm_fxt Init_fmt(String v) {itm.Fmt_(Bry_.new_a7(v)); return this;}
public void Test_run(String expd) {
String actl = itm.Run();
Tfds.Eq(expd, actl);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.ios.*;
public class Xoa_fmtr_mgr implements GfoInvkAble {
public Xoa_fmtr_mgr(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_new_grp)) return new Xoa_fmtr_itm(app);
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_new_grp = "new_grp";
}

View File

@@ -0,0 +1,66 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_fmtr_sort_mgr implements GfoInvkAble {
private Ordered_hash itms = Ordered_hash_.new_();
private Xoa_fmtr_sort_wkr wkr = new Xoa_fmtr_sort_wkr();
private Gfo_sort_able sort_able;
public Xoa_fmtr_sort_mgr(Gfo_sort_able sort_able) {this.sort_able = sort_able;}
public void Clear() {itms.Clear();}
public void Add_many(String[] keys) {
int keys_len = keys.length;
for (int i = 0; i < keys_len; i++) {
Xoa_fmtr_sort_itm itm = new Xoa_fmtr_sort_itm(keys[i], true);
itms.Add_if_dupe_use_1st(itm.Key(), itm);
}
}
public void Exec() {
wkr.Itms_((Xoa_fmtr_sort_itm[])itms.To_ary(Xoa_fmtr_sort_itm.class));
sort_able.Sort(wkr);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_add_many)) this.Add_many(m.ReadStrAry("k", "|"));
else if (ctx.Match(k, Invk_exec)) this.Exec();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_clear = "clear", Invk_add_many = "add_many", Invk_exec = "exec";
}
class Xoa_fmtr_sort_itm {
public Xoa_fmtr_sort_itm(String key, boolean asc) {this.key = key; this.comp_mult = asc ? CompareAble_.More : CompareAble_.Less;}
public int Comp_mult() {return comp_mult;} private int comp_mult;
public String Key() {return key;} private String key;
}
class Xoa_fmtr_sort_wkr implements gplx.lists.ComparerAble {
public Xoa_fmtr_sort_itm[] Itms() {return itms;} public void Itms_(Xoa_fmtr_sort_itm[] v) {itms = v; itms_len = v.length;} private Xoa_fmtr_sort_itm[] itms; private int itms_len;
public int compare(Object lhsObj, Object rhsObj) {
GfoInvkAble lhs_invk = (GfoInvkAble)lhsObj;
GfoInvkAble rhs_invk = (GfoInvkAble)rhsObj;
for (int i = 0; i < itms_len; i++) {
Xoa_fmtr_sort_itm itm = itms[i];
String itm_key = itm.Key();
Object lhs_val = GfoInvkAble_.InvkCmd(lhs_invk, itm_key);
Object rhs_val = GfoInvkAble_.InvkCmd(rhs_invk, itm_key);
int compare = CompareAble_.Compare_obj(lhs_val, rhs_val) * itm.Comp_mult();
if (compare != CompareAble_.Same)
return compare;
}
return CompareAble_.Same;
}
}

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.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.gfss.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_fsys_mgr implements GfoInvkAble {
public Xoa_fsys_mgr(String plat_name, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url css_dir) {

View File

@@ -0,0 +1,89 @@
/*
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.apps.gfss; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Gfs_bldr {
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr.new_();
public byte[] Xto_bry() {return bfr.Xto_bry_and_clear();}
public Gfs_bldr Add_byte(byte b) {bfr.Add_byte(b); return this;}
public Gfs_bldr Add_blob(byte[] bry) {bfr.Add(bry); return this;}
public Gfs_bldr Add_proc_init_many(String... ary) {return Add_proc_core_many(false, ary);}
public Gfs_bldr Add_proc_init_one(String itm) {return Add_proc_core_many(false, itm);}
public Gfs_bldr Add_proc_cont_one(String itm) {return Add_proc_core_many(true, itm);}
public Gfs_bldr Add_proc_cont_many(String... ary) {return Add_proc_core_many(true, ary);}
Gfs_bldr Add_proc_core_many(boolean cont, String... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
if (i != 0 || cont) bfr.Add_byte(Byte_ascii.Dot);
bfr.Add_str(ary[i]);
}
return this;
}
public Gfs_bldr Add_indent(int i) {bfr.Add_byte_repeat(Byte_ascii.Space, i * 2); return this;}
public Gfs_bldr Add_parens_str(String v) {return Add_parens_str(Bry_.new_u8(v));}
public Gfs_bldr Add_parens_str(byte[] v) {return this.Add_paren_bgn().Add_arg_str(v).Add_paren_end();}
public Gfs_bldr Add_parens_str_many(String... ary) {
this.Add_paren_bgn();
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) this.Add_comma();
this.Add_arg_str(Bry_.new_u8(ary[i]));
}
this.Add_paren_end();
return this;
}
public Gfs_bldr Add_arg_int(int v) {bfr.Add_int_variable(v); return this;}
public Gfs_bldr Add_arg_yn(boolean v) {Add_quote_0(); bfr.Add_byte(v ? Byte_ascii.Ltr_y : Byte_ascii.Ltr_n); Add_quote_0(); return this;}
public Gfs_bldr Add_arg_str(byte[] v) {bfr.Add_byte(Byte_ascii.Apos); Add_str_escape_apos(bfr, v); bfr.Add_byte(Byte_ascii.Apos); return this;}
public Gfs_bldr Add_indent() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Space); return this;}
public Gfs_bldr Add_nl() {bfr.Add_byte_nl(); return this;}
public Gfs_bldr Add_comma() {bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); return this;}
public Gfs_bldr Add_curly_bgn_nl() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Curly_bgn).Add_byte_nl(); return this;}
public Gfs_bldr Add_curly_end_nl() {bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl(); return this;}
public Gfs_bldr Add_paren_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn); return this;}
public Gfs_bldr Add_paren_end() {bfr.Add_byte(Byte_ascii.Paren_end); return this;}
public Gfs_bldr Add_quote_xtn_bgn() {bfr.Add(Bry_xquote_bgn); return this;}
public Gfs_bldr Add_quote_xtn_end() {bfr.Add(Bry_xquote_end); return this;}
public Gfs_bldr Add_quote_xtn_apos_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Nl); return this;}
public Gfs_bldr Add_quote_xtn_apos_end() {bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic).Add_byte(Byte_ascii.Nl); return this;}
public Gfs_bldr Add_quote_0() {bfr.Add_byte(Byte_ascii.Apos); return this;}
public Gfs_bldr Add_term_nl() {bfr.Add(Bry_semic_nl); return this;}
public Gfs_bldr Add_eq_str(String k, byte[] v) {
bfr.Add_str(k);
bfr.Add(Bry_eq);
bfr.Add_byte_apos();
bfr.Add(v);
bfr.Add_byte_apos();
bfr.Add(Bry_semic_nl);
return this;
}
private static final byte[] Bry_eq = Bry_.new_a7(" = "), Bry_semic_nl = Bry_.new_a7(";\n");
private void Add_str_escape_apos(Bry_bfr bfr, byte[] src) {
int len = src.length;
for (int i = 0; i < len; i++) {
byte b = src[i];
if (b == Byte_ascii.Apos)
bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
else
bfr.Add_byte(b);
}
}
public static final byte[]
Bry_xquote_bgn = Bry_.new_a7("<:['\n")
, Bry_xquote_end = Bry_.new_a7("']:>\n")
;
}

View File

@@ -15,8 +15,8 @@ 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.apps; import gplx.*; import gplx.xowa.*;
import gplx.gfs.*;
package gplx.xowa.apps.gfss; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.langs.gfss.*;
import gplx.xowa.users.*; import gplx.xowa.apps.fsys.*;
public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
private final GfoInvkAble root_invk; private final Xoa_fsys_mgr app_fsys_mgr; private final Xou_fsys_mgr usr_fsys_mgr;
@@ -44,7 +44,7 @@ public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
Gfo_usr_dlg_.I.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx_full(e));
}
}
public GfoMsg Parse_root_msg(String v) {return gplx.gfs.Gfs_msg_bldr._.ParseToMsg(v);}
public GfoMsg Parse_root_msg(String v) {return gplx.langs.gfss.Gfs_msg_bldr._.ParseToMsg(v);}
public Gfs_wtr Wtr() {return wtr;} private Gfs_wtr wtr = new Gfs_wtr();
public void Run_url(Io_url url) {
Run_url_for(GfsCore._.Root(), url);
@@ -97,11 +97,11 @@ public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
return this;
} private static final String Invk_run_file_by_type = "run_file_by_type", Invk_fail_if_unhandled_ = "fail_if_unhandled_", Invk_txns = "txns";
public static void Msg_parser_init() {
GfsCore._.MsgParser_(gplx.gfs.Gfs_msg_bldr._);
GfsCore._.MsgParser_(gplx.langs.gfss.Gfs_msg_bldr._);
}
public static byte[] Cfg_save_escape(String v) {return Cfg_save_escape(Bry_.new_u8(v));}
public static byte[] Cfg_save_escape(byte[] v) {
return Bry_finder.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Bry_apos_1, Bry_apos_2);
return Bry_find_.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Bry_apos_1, Bry_apos_2);
} static final byte[] Bry_apos_1 = Bry_.new_a7("'"), Bry_apos_2 = Bry_.new_a7("''");
public static String Build_code(String... ary) {
int len = ary.length;

View File

@@ -15,8 +15,8 @@ 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.apps; import gplx.*; import gplx.xowa.*;
import gplx.php.*;
package gplx.xowa.apps.gfss; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.langs.phps.*;
public class Xoa_gfs_php_mgr {
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
int len = src.length;
@@ -67,8 +67,8 @@ public class Xoa_gfs_php_mgr {
}
case Byte_ascii.Curly_bgn: {
int num_bgn = pos + 1;
int num_end = Bry_finder.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
if ( num_end == Bry_finder.Not_found
int num_end = Bry_find_.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
if ( num_end == Bry_find_.Not_found
|| num_end == len
|| src[num_end] != Byte_ascii.Curly_end
)

View File

@@ -15,7 +15,7 @@ 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.apps; import gplx.*; import gplx.xowa.*;
package gplx.xowa.apps.gfss; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_gfs_php_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoa_gfs_php_mgr_fxt fxt = new Xoa_gfs_php_mgr_fxt();

View File

@@ -1,75 +0,0 @@
/*
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
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 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) {
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_.To_int_or(ary[1], -1);
}
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_();
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

@@ -1,145 +0,0 @@
/*
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
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

@@ -1,37 +0,0 @@
/*
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.apps.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
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 Err_.new_wo_type("langs cannot have itms", "type", itm_type, "key", itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_.new_wo_type("langs 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("langs cannot have itms", "idx", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_.new_wo_type("langs cannot have itms", "key", String_.new_u8(itm_key));}
public void Nde_subs_del(byte[] key) {throw Err_.new_wo_type("langs cannot delete itms", "key", String_.new_u8(key));}
public void Nde_atrs_set(byte[][] ary) {
if (ary.length != 1) throw Err_.new_wo_type("expecting name only", "name", String_.AryXtoStr(String_.Ary(ary)));
local_name_bry = ary[0];
}
}

View File

@@ -16,7 +16,8 @@ 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.apps.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wmfs.data.*;
import gplx.xowa.nss.*;
import gplx.xowa.wms.sites.*;
public class Xoa_meta_mgr {
private final Xoa_app app;
private final Hash_adp_bry ns__hash = Hash_adp_bry.cs();

View File

@@ -0,0 +1,25 @@
/*
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url {
public byte[] Wiki_bry() {return wiki_bry;} public void Wiki_bry_(byte[] v) {wiki_bry = v;} private byte[] wiki_bry;
public byte[] Page_bry() {return page_bry;} public void Page_bry_(byte[] v) {page_bry = v;} private byte[] page_bry;
public byte[] Anch_bry() {return anch_bry;} public void Anch_bry_(byte[] v) {anch_bry = v;} private byte[] anch_bry;
public byte[] Qarg_bry() {return qarg_bry;} public void Qarg_bry_(byte[] v) {qarg_bry = v;} private byte[] qarg_bry;
public void Clear() {wiki_bry = page_bry = null;}
}

View File

@@ -0,0 +1,43 @@
/*
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url_parser {
private static final byte[] Bry_site = Bry_.new_a7("/site/"), Bry_wiki = Bry_.new_a7("/wiki/"), Bry_http = Bry_.new_a7("http:");
public void Parse_xo_href(Xoav_url rv, byte[] src, byte[] cur_wiki_bry) {
rv.Clear();
int pos = Bry_.Has_at_bgn(src, Bry_http) ? Bry_http.length : 0; // DRD: DRD:2.2 adds "http:" to all links
int src_len = src.length;
if (Bry_.Has_at_bgn(src, Bry_site, pos, src_len))
pos = Parse_wiki(rv, src, src_len, pos);
else
rv.Wiki_bry_(cur_wiki_bry);
if (Bry_.Has_at_bgn(src, Bry_wiki, pos, src_len)) pos = Parse_page(rv, src, src_len, pos);
}
private int Parse_wiki(Xoav_url rv, byte[] src, int src_len, int pos) {
int wiki_bgn = pos + Bry_site.length;
int wiki_end = Bry_find_.Find_fwd(src, Byte_ascii.Slash, wiki_bgn, src_len); if (wiki_end == Bry_.NotFound) throw Err_.new_wo_type("could not find wiki_end", "src", String_.new_u8(src));
rv.Wiki_bry_(Bry_.Mid(src, wiki_bgn, wiki_end));
return wiki_end;
}
private int Parse_page(Xoav_url rv, byte[] src, int src_len, int pos) {
int page_bgn = pos + Bry_wiki.length;
int page_end = src_len;
rv.Page_bry_(Bry_.Mid(src, page_bgn, page_end));
return page_end;
}
}

View File

@@ -0,0 +1,43 @@
/*
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoav_url_parser_tst {
@Before public void init() {fxt.Clear();} private final Xoav_url_parser_fxt fxt = new Xoav_url_parser_fxt();
@Test public void Page() {
fxt.Exec_parse_xo_href("http:/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
@Test public void Site() {
fxt.Exec_parse_xo_href("http:/site/en.wikipedia.org/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
}
class Xoav_url_parser_fxt {
private Xoav_url_parser url_parser = new Xoav_url_parser(); private Xoav_url url = new Xoav_url();
public void Clear() {
cur_wiki = Bry_.new_a7("en.wikipedia.org");
url.Clear();
}
public Xoav_url_parser_fxt Init_cur_wiki(String v) {cur_wiki = Bry_.new_u8(v); return this;} private byte[] cur_wiki;
public Xoav_url_parser_fxt Test_wiki(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Wiki_bry()); return this;}
public Xoav_url_parser_fxt Test_page(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Page_bry()); return this;}
public Xoav_url_parser_fxt Exec_parse_xo_href(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
url_parser.Parse_xo_href(url, src_bry, cur_wiki);
return this;
}
}