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

View File

@@ -0,0 +1,130 @@
/*
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.xtns.scribunto.errs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
public interface Gfo_comp_op_1 {
boolean Comp_bool(boolean val, boolean comp);
boolean Comp_byte(byte val, byte comp);
boolean Comp_int(int val, int comp);
boolean Comp_long(long val, long comp);
boolean Comp_float(float val, float comp);
boolean Comp_double(double val, double comp);
boolean Comp_decimal(DecimalAdp val, DecimalAdp comp);
boolean Comp_char(char val, char comp);
boolean Comp_str(String val, String comp);
boolean Comp_bry(byte[] val, byte[] comp);
boolean Comp_date(DateAdp val, DateAdp comp);
boolean Comp_url(Io_url val, Io_url comp);
boolean Comp_val(Gfo_val val, Gfo_val comp);
boolean Comp_obj(Object val, Object comp);
}
class Gfo_comp_op_eq implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return val == comp;}
public boolean Comp_byte(byte val, byte comp) {return val == comp;}
public boolean Comp_int(int val, int comp) {return val == comp;}
public boolean Comp_long(long val, long comp) {return val == comp;}
public boolean Comp_float(float val, float comp) {return val == comp;}
public boolean Comp_double(double val, double comp) {return val == comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Eq(comp);}
public boolean Comp_char(char val, char comp) {return val == comp;}
public boolean Comp_str(String val, String comp) {return String_.Eq(val, comp);}
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Eq(val, comp);}
public boolean Comp_date(DateAdp val, DateAdp comp) {return val.Eq(comp);}
public boolean Comp_url(Io_url val, Io_url comp) {return val.Eq(comp);}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return val.Eq(comp);}
public boolean Comp_obj(Object val, Object comp) {return Object_.Eq(val, comp);}
}
class Gfo_comp_op_eqn implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return val != comp;}
public boolean Comp_byte(byte val, byte comp) {return val != comp;}
public boolean Comp_int(int val, int comp) {return val != comp;}
public boolean Comp_long(long val, long comp) {return val != comp;}
public boolean Comp_float(float val, float comp) {return val != comp;}
public boolean Comp_double(double val, double comp) {return val != comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return !val.Eq(comp);}
public boolean Comp_char(char val, char comp) {return val != comp;}
public boolean Comp_str(String val, String comp) {return !String_.Eq(val, comp);}
public boolean Comp_bry(byte[] val, byte[] comp) {return !Bry_.Eq(val, comp);}
public boolean Comp_date(DateAdp val, DateAdp comp) {return !val.Eq(comp);}
public boolean Comp_url(Io_url val, Io_url comp) {return !val.Eq(comp);}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return !val.Eq(comp);}
public boolean Comp_obj(Object val, Object comp) {return Object_.Eq(val, comp);}
}
class Gfo_comp_op_lt implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return !val && comp;} // false < true
public boolean Comp_byte(byte val, byte comp) {return val < comp;}
public boolean Comp_int(int val, int comp) {return val < comp;}
public boolean Comp_long(long val, long comp) {return val < comp;}
public boolean Comp_float(float val, float comp) {return val < comp;}
public boolean Comp_double(double val, double comp) {return val < comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lt(comp);}
public boolean Comp_char(char val, char comp) {return val < comp;}
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) < CompareAble_.Same;}
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) < CompareAble_.Same;}
public boolean Comp_date(DateAdp val, DateAdp comp) {return val.compareTo(comp) < CompareAble_.Same;}
public boolean Comp_url(Io_url val, Io_url comp) {return val.compareTo(comp) < CompareAble_.Same;}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return val.compareTo(comp) < CompareAble_.Same;}
public boolean Comp_obj(Object val, Object comp) {return CompareAble_.Compare_obj(val, comp) < CompareAble_.Same;}
}
class Gfo_comp_op_lte implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return !(val && !comp);} // !(true && false)
public boolean Comp_byte(byte val, byte comp) {return val <= comp;}
public boolean Comp_int(int val, int comp) {return val <= comp;}
public boolean Comp_long(long val, long comp) {return val <= comp;}
public boolean Comp_float(float val, float comp) {return val <= comp;}
public boolean Comp_double(double val, double comp) {return val <= comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lte(comp);}
public boolean Comp_char(char val, char comp) {return val <= comp;}
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) <= CompareAble_.Same;}
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) <= CompareAble_.Same;}
public boolean Comp_date(DateAdp val, DateAdp comp) {return val.compareTo(comp) <= CompareAble_.Same;}
public boolean Comp_url(Io_url val, Io_url comp) {return val.compareTo(comp) <= CompareAble_.Same;}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return val.compareTo(comp) <= CompareAble_.Same;}
public boolean Comp_obj(Object val, Object comp) {return CompareAble_.Compare_obj(val, comp) <= CompareAble_.Same;}
}
class Gfo_comp_op_mt implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return val && !comp;} // true > false
public boolean Comp_byte(byte val, byte comp) {return val > comp;}
public boolean Comp_int(int val, int comp) {return val > comp;}
public boolean Comp_long(long val, long comp) {return val > comp;}
public boolean Comp_float(float val, float comp) {return val > comp;}
public boolean Comp_double(double val, double comp) {return val > comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lt(comp);}
public boolean Comp_char(char val, char comp) {return val > comp;}
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) > CompareAble_.Same;}
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) > CompareAble_.Same;}
public boolean Comp_date(DateAdp val, DateAdp comp) {return val.compareTo(comp) > CompareAble_.Same;}
public boolean Comp_url(Io_url val, Io_url comp) {return val.compareTo(comp) > CompareAble_.Same;}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return val.compareTo(comp) > CompareAble_.Same;}
public boolean Comp_obj(Object val, Object comp) {return CompareAble_.Compare_obj(val, comp) > CompareAble_.Same;}
}
class Gfo_comp_op_mte implements Gfo_comp_op_1 {
public boolean Comp_bool(boolean val, boolean comp) {return !(!val && comp);} // !(false && true)
public boolean Comp_byte(byte val, byte comp) {return val >= comp;}
public boolean Comp_int(int val, int comp) {return val >= comp;}
public boolean Comp_long(long val, long comp) {return val >= comp;}
public boolean Comp_float(float val, float comp) {return val >= comp;}
public boolean Comp_double(double val, double comp) {return val >= comp;}
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lte(comp);}
public boolean Comp_char(char val, char comp) {return val >= comp;}
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) >= CompareAble_.Same;}
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) >= CompareAble_.Same;}
public boolean Comp_date(DateAdp val, DateAdp comp) {return val.compareTo(comp) >= CompareAble_.Same;}
public boolean Comp_url(Io_url val, Io_url comp) {return val.compareTo(comp) >= CompareAble_.Same;}
public boolean Comp_val(Gfo_val val, Gfo_val comp) {return val.compareTo(comp) >= CompareAble_.Same;}
public boolean Comp_obj(Object val, Object comp) {return CompareAble_.Compare_obj(val, comp) >= CompareAble_.Same;}
}

View File

@@ -0,0 +1,68 @@
/*
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.xtns.scribunto.errs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.criterias.*;
public interface Gfo_fld_owner {
int Fld_val_as_int(int fld_idx);
String Fld_val_as_str(int fld_idx);
Object Fld_val_as_obj(int fld_idx);
}
interface Gfo_match {
boolean Match(Gfo_fld_owner owner);
}
class Gfo_match_ {
public boolean Match(Gfo_match root, Gfo_fld_owner owner) {
return root.Match(owner);
}
}
class Gfo_match_int_1 implements Gfo_match {
public Gfo_match_int_1(int idx, Gfo_comp_op_1 comp, int rhs) {this.idx = idx; this.comp = comp; this.rhs = rhs;}
private int idx; private int rhs;
private Gfo_comp_op_1 comp;
public boolean Match(Gfo_fld_owner owner) {
int lhs = owner.Fld_val_as_int(idx);
return comp.Comp_int(lhs, rhs);
}
}
class Gfo_match_obj implements Gfo_match {
public Gfo_match_obj(int idx, Gfo_comp_op_1 comp, Gfo_val rhs) {this.idx = idx; this.comp = comp; this.rhs = rhs;}
private int idx; Gfo_val rhs;
private Gfo_comp_op_1 comp;
public boolean Match(Gfo_fld_owner owner) {
Gfo_val lhs = (Gfo_val)owner.Fld_val_as_obj(idx);
return lhs.Match_1(comp, rhs);
}
}
class Gfo_fld_crt implements Criteria {
public byte Tid() {return Criteria_.Tid_wrapper;}
public byte Fld_idx() {return fld_idx;} private byte fld_idx;
public Criteria Crt() {return crt;} private Criteria crt;
public boolean Matches(Object o) {
Gfo_fld_owner owner = (Gfo_fld_owner)o;
Object comp = owner.Fld_val_as_obj(fld_idx);
return crt.Matches(comp);
}
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
public String XtoStr() {return String_.Concat(Byte_.Xto_str(fld_idx), " ", crt.XtoStr());}
public static Gfo_fld_crt new_(byte fld_idx, Criteria crt) {
Gfo_fld_crt rv = new Gfo_fld_crt();
rv.fld_idx = fld_idx; rv.crt = crt;
return rv;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.errs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
public interface Gfo_val extends CompareAble {
boolean Eq(Gfo_val rhs);
boolean Match_1(Gfo_comp_op_1 op, Gfo_val comp);
}
class Gfo_val_mok implements Gfo_val {
public String s = "";
public boolean Eq(Gfo_val rhs) {return true;}
public int compareTo(Object obj) {return 0;}
public boolean Match_1(Gfo_comp_op_1 op, Gfo_val comp_obj) {
Gfo_val_mok comp = (Gfo_val_mok)comp_obj;
return op.Comp_str(s, comp.s);
}
}

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.xtns.scribunto.errs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
class Scrib_err_mgr implements GfoInvkAble {
private Ordered_hash hash = Ordered_hash_.new_bry_();
private int key_id = 0;
private static final byte[] Key_prefix = Bry_.new_a7("scrib_err_");
private Scrib_err_cmd Set(byte[] key) {
if (key == null) Bry_.Add(Key_prefix, Bry_.XbyInt(key_id++));
Scrib_err_cmd rv = new Scrib_err_cmd(key);
hash.Add_if_dupe_use_1st(key, rv);
return rv;
}
public void Clear() {
hash.Clear();
key_id = 0;
}
public void Process(Scrib_err_data err) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Scrib_err_cmd itm = (Scrib_err_cmd)hash.Get_at(i);
if (itm.Warn_disabled(err)) {
// log
}
else {
// warn
}
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) return Set(m.ReadBryOr("v", null));
else if (ctx.Match(k, Invk_clear)) Clear();
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_set = "set", Invk_clear = "clear";
}
class Scrib_err_data {
public Scrib_err_data(byte[] mod, byte[] fnc, byte[] err, byte[] src) {this.mod = mod; this.fnc = fnc; this.err = err; this.src = src;}
public byte[] Mod() {return mod;} private byte[] mod;
public byte[] Fnc() {return fnc;} private byte[] fnc;
public byte[] Err() {return err;} private byte[] err;
public byte[] Src() {return src;} private byte[] src;
}
class Scrib_err_cmd implements GfoInvkAble {
public Scrib_err_cmd(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private byte[] key;
public int Fail_after() {return fail_after;} private int fail_after = Int_.MaxValue;
public int Warn_every() {return warn_every;} private int warn_every = 10000; // worse case of 400 warnings for 4 million pages
public int Summary_ttls_len() {return summary_ttls_len;} private int summary_ttls_len = 8;
public String Warn_disabled_if() {return warn_disabled_if;} private String warn_disabled_if;
private void Warn_disabled_if_(String v) {
this.warn_disabled_if = v;
// compile
}
public boolean Warn_disabled(Scrib_err_data err) {
// gplx.core.criterias.Criteria c;
// c.Matches(err);
return false;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_warn_disabled_if_)) Warn_disabled_if_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_fail_after_)) fail_after = m.ReadInt("v");
else if (ctx.Match(k, Invk_warn_every_)) fail_after = m.ReadInt("v");
else if (ctx.Match(k, Invk_summary_ttls_len_)) summary_ttls_len = m.ReadInt("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_warn_disabled_if_ = "warn_disabled_if_"
, Invk_warn_every_ = "warn_every_", Invk_fail_after_ = "fail_after_"
, Invk_summary_ttls_len_ = "summmary_ttls_len_"
;
}