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
2014-06-30 00:04:32 -04:00
parent 85594d3cdd
commit bae88e739c
2482 changed files with 198730 additions and 0 deletions

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.fmtrs; import gplx.*; import gplx.xowa.*;
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.fmtrs; import gplx.*; import gplx.xowa.*;
public class Xoa_fmtr_itm implements GfoInvkAble {
public Xoa_fmtr_itm(Xoa_app app) {this.app = app;} private Xoa_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.XtoStrAndClear();
}
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_utf8_(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(Xoa_app app) {this.app = app;} private Xoa_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_utf8_(cmd));
return Bry_.new_utf8_(Object_.XtoStr_OrNullStr(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.fmtrs; import gplx.*; import gplx.xowa.*;
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 Xoa_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.gfs.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_ascii_(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.fmtrs; import gplx.*; import gplx.xowa.*;
import gplx.ios.*;
public class Xoa_fmtr_mgr implements GfoInvkAble {
public Xoa_fmtr_mgr(Xoa_app app) {this.app = app;} private Xoa_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.fmtrs; import gplx.*; import gplx.xowa.*;
public class Xoa_fmtr_sort_mgr implements GfoInvkAble {
private OrderedHash itms = OrderedHash_.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_new(itm.Key(), itm);
}
}
public void Exec() {
wkr.Itms_((Xoa_fmtr_sort_itm[])itms.XtoAry(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;
}
}