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,67 @@
/*
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; import gplx.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
public class Xoa_repo_mgr implements GfoInvkAble {
private final Xoa_fsys_mgr app_fsys; private final Xof_rule_mgr ext_rule_mgr;
public Xoa_repo_mgr(Xoa_fsys_mgr app_fsys, Xof_rule_mgr ext_rule_mgr) {this.app_fsys = app_fsys; this.ext_rule_mgr = ext_rule_mgr;}
public int Count() {return hash.Count();}
public Xof_repo_itm Get_at(int i) {return (Xof_repo_itm)hash.Get_at(i);}
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Get_by(key);}
public Xof_repo_itm Get_by_primary(byte[] key) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Primary()) return repo;
}
return null;
}
public Xof_repo_itm Get_by_wmf_fsys(byte[] key) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Wmf_fsys()) return repo;
}
return null;
}
public Xof_repo_itm Get_by_wiki_key(byte[] key) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
if (Bry_.Eq(key, repo.Wiki_domain())) return repo;
}
return null;
}
public Xof_repo_itm Add(Xof_repo_itm itm) {hash.Add(itm.Key(), itm); return itm;} private Ordered_hash hash = Ordered_hash_.new_bry_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) return Set(m.ReadStr("key"), m.ReadStr("url"), m.ReadStr("wiki"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_set = "set";
public Xof_repo_itm Set(String key, String url_str, String wiki) {
byte[] key_bry = Bry_.new_u8(key);
Xof_repo_itm itm = (Xof_repo_itm)hash.Get_by(key_bry);
byte[] wiki_domain = Bry_.new_u8(wiki);
if (itm == null) {
itm = new Xof_repo_itm(key_bry, app_fsys, ext_rule_mgr, wiki_domain);
this.Add(itm);
}
itm.Root_str_(url_str);
itm.Wiki_domain_(wiki_domain);
return itm;
}
}

View File

@@ -0,0 +1,50 @@
/*
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; import gplx.*;
public class Xof_cfg_download implements GfoInvkAble {
public Xof_cfg_download() {
this.enabled = true; // CFG: set to false b/c some tests only do parsing [[File:A.png]] and repos are not set up
this.redownload = Redownload_none; // CFG: set to none to be as conservative as possible
}
public boolean Enabled() {return enabled;} public Xof_cfg_download Enabled_(boolean v) {enabled = v; return this;} private boolean enabled;
public byte Redownload() {return redownload;} public Xof_cfg_download Redownload_(byte v) {redownload = v; return this;} private byte redownload;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_redownload)) return Redownload_to_str_(redownload);
else if (ctx.Match(k, Invk_redownload_)) redownload = Redownload_parse_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_redownload_toggle)) redownload = redownload == Redownload_none ? Redownload_missing : Redownload_none;
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_enabled_ = "enabled_", Invk_redownload = "redownload", Invk_redownload_ = "redownload_", Invk_redownload_toggle = "redownload_toggle";
byte Redownload_parse_(String s) {
if (String_.Eq(s, "none")) return Redownload_none;
else if (String_.Eq(s, "missing")) return Redownload_missing;
else if (String_.Eq(s, "all")) return Redownload_all;
else throw Exc_.new_unhandled(s);
}
public static final byte Redownload_none = 0, Redownload_missing = 1, Redownload_all = 2;
String Redownload_to_str_(byte v) {
switch (v) {
case Redownload_none: return "none";
case Redownload_missing: return "missing";
case Redownload_all: return "all";
default: throw Exc_.new_unhandled(v);
}
}
}

View File

@@ -0,0 +1,45 @@
/*
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; import gplx.*;
import gplx.dbs.*; import gplx.xowa2.files.commons.*; import gplx.xowa.xtns.math.*;
import gplx.xowa.wmfs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
public class Xof_file_mgr implements GfoInvkAble {
public Xoa_repo_mgr Repo_mgr() {return repo_mgr;} private Xoa_repo_mgr repo_mgr;
public Xof_img_mgr Img_mgr() {return img_mgr;} private final Xof_img_mgr img_mgr = new Xof_img_mgr();
public Xof_cache_mgr Cache_mgr() {return cache_mgr;} private Xof_cache_mgr cache_mgr;
public Xof_math_mgr Math_mgr() {return math_mgr;} private final Xof_math_mgr math_mgr = new Xof_math_mgr();
public Xof_rule_mgr Ext_rules() {return ext_rules;} private final Xof_rule_mgr ext_rules = new Xof_rule_mgr();
public Xoa_wmf_mgr Wmf_mgr() {return wmf_mgr;} private Xoa_wmf_mgr wmf_mgr;
public void Ctor_by_app(Xoae_app app) {
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
this.cache_mgr = new Xof_cache_mgr(usr_dlg, app.Wiki_mgr(), repo_mgr);
this.repo_mgr = new Xoa_repo_mgr(app.Fsys_mgr(), ext_rules);
this.wmf_mgr = new Xoa_wmf_mgr(usr_dlg, app.Wiki_mgr());
img_mgr.Init_by_app(app.Wmf_mgr(), app.Prog_mgr());
math_mgr.Init_by_app(app);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_repos)) return repo_mgr;
else if (ctx.Match(k, Invk_img_mgr)) return img_mgr;
else if (ctx.Match(k, Invk_ext_rules)) return ext_rules;
else if (ctx.Match(k, Invk_math)) return math_mgr;
else if (ctx.Match(k, Invk_download)) return wmf_mgr; // NOTE: do not rename "download" to wmf_mgr
else if (ctx.Match(k, Invk_cache_mgr)) return cache_mgr;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_repos = "repos", Invk_img_mgr= "img_mgr", Invk_ext_rules = "ext_rules", Invk_math = "math", Invk_download = "download", Invk_cache_mgr = "cache_mgr";
}

View File

@@ -0,0 +1,109 @@
/*
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; import gplx.*;
import gplx.core.flds.*; import gplx.ios.*; import gplx.gfui.*;
class Xofo_file {
public byte[] Name() {return name;} public Xofo_file Name_(byte[] v) {name = v; return this;} byte[] name = Bry_.Empty;
public byte[] Redirect() {return redirect;} private byte[] redirect = Bry_.Empty; public boolean Redirect_exists() {return redirect.length > 0;}
public int Orig_w() {return orig_w;} private int orig_w;
public int Orig_h() {return orig_h;} private int orig_h;
public int Orig_size() {return orig_size;} private int orig_size;
public int Bits() {return bits;} private int bits;
public int Repo_id() {return repo_id;} public Xofo_file Repo_id_(int v) {this.repo_id = v; return this;} private int repo_id = -1;
public byte[] Status_msg() {return status_msg;} public Xofo_file Status_msg_(byte[] v) {status_msg = v; return this;} private byte[] status_msg = Bry_.Empty;
public int[] Thumbs() {return (int[])thumbs.To_ary(int.class);} private Ordered_hash thumbs = Ordered_hash_.new_();
public Xofo_lnki[] Links() {return lnkis;} private Xofo_lnki[] lnkis = Xofo_lnki.Ary_empty; int links_len;
public void Links_(List_adp list) {
lnkis = (Xofo_lnki[])list.To_ary(Xofo_lnki.class);
links_len = lnkis.length;
list.Clear();
}
public void Write(boolean reverse, Gfo_fld_wtr wtr) {
Write_main(reverse, wtr);
wtr.Write_dlm_row();
}
public void Write_bldr(Gfo_fld_wtr wtr) {
Write_main(false, wtr);
wtr.Write_int_variable_fld(repo_id);
wtr.Write_bry_escape_fld(status_msg);
Xofo_lnki[] lnkis = this.Links();
int links_len = lnkis.length;
Bry_bfr bfr = wtr.Bfr();
for (int i = 0; i < links_len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
Xofo_lnki lnki = lnkis[i];
bfr .Add_int_variable(lnki.Lnki_type()) .Add_byte(Byte_ascii.Comma)
.Add_int_variable(lnki.Lnki_w()) .Add_byte(Byte_ascii.Comma)
.Add_int_variable(lnki.Lnki_h());
if (lnki.Lnki_upright() != Xop_lnki_tkn.Upright_null)
bfr.Add_byte(Byte_ascii.Comma).Add(Xop_lnki_arg_parser.Bry_upright).Add_byte(Byte_ascii.Eq).Add_double(lnki.Lnki_upright());
}
wtr.Write_dlm_row();
}
private void Write_main(boolean reverse, Gfo_fld_wtr wtr) {
if (reverse) {
wtr.Write_bry_escape_fld(redirect);
wtr.Write_bry_escape_fld(name);
}
else {
wtr.Write_bry_escape_fld(name);
wtr.Write_bry_escape_fld(redirect);
}
wtr.Write_bry_escape_fld(name_ext);
wtr.Write_int_variable_fld(orig_size);
wtr.Write_int_variable_fld(orig_w);
wtr.Write_int_variable_fld(orig_h);
wtr.Write_int_variable_fld(bits);
}
public Xofo_file Load_by_xfer_rdr(Gfo_fld_rdr fld_parser, Xofo_lnki_parser lnki_parser, Io_line_rdr rdr, List_adp link_list) {
byte[] bfr = rdr.Bfr();
fld_parser.Ini(bfr, rdr.Itm_pos_bgn());
Load_ttl_atrs(fld_parser);
Load_sql_atrs(fld_parser);
repo_id = fld_parser.Read_int();
status_msg = fld_parser.Read_bry_escape();
lnkis = lnki_parser.Parse_ary(fld_parser.Data(), fld_parser.Pos(), rdr.Itm_pos_end() - 1); // -1 to ignore closing \n
return this;
}
public void Load_by_name_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
Load_ttl_atrs(fld_parser);
}
public void Load_by_size_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
fld_parser.Move_next_escaped();
Load_sql_atrs(fld_parser);
}
public Xofo_file Load_by_merge_rdr(Gfo_fld_rdr fld_parser, Io_line_rdr rdr) {
fld_parser.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
Load_ttl_atrs(fld_parser);
Load_sql_atrs(fld_parser);
return this;
}
private void Load_ttl_atrs(Gfo_fld_rdr fld_parser) {
name = fld_parser.Read_bry_escape();
redirect = fld_parser.Read_bry_escape();
}
private void Load_sql_atrs(Gfo_fld_rdr fld_parser) {
name_ext = fld_parser.Read_bry_escape();
orig_size = fld_parser.Read_int();
orig_w = fld_parser.Read_int();
orig_h = fld_parser.Read_int();
bits = fld_parser.Read_int();
} byte[] name_ext = Bry_.Empty;
}

View File

@@ -0,0 +1,61 @@
/*
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; import gplx.*;
import gplx.core.flds.*; import gplx.ios.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.files.*;
class Xofo_lnki {
public byte[] Name() {return name;} private byte[] name;
public byte Lnki_type() {return lnki_type;} public Xofo_lnki Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type;
public int Lnki_w() {return lnki_w;} public Xofo_lnki Lnki_w_(int v) {lnki_w = v; return this;} private int lnki_w;
public int Lnki_h() {return lnki_h;} public Xofo_lnki Lnki_h_(int v) {lnki_h = v; return this;} private int lnki_h;
public double Lnki_upright() {return lnki_upright;} public Xofo_lnki Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright = Xop_lnki_tkn.Upright_null;
public double Lnki_thumbtime() {return lnki_thumbtime;} public Xofo_lnki Lnki_thumbtime_(double v) {lnki_thumbtime = v; return this;} private double lnki_thumbtime = Xof_lnki_time.Null;
public byte Xfer_status() {return xfer_status;} public Xofo_lnki Xfer_status_(byte v) {xfer_status = v; return this;} private byte xfer_status; public static final byte Xfer_status_none = 0, Xfer_status_xfer_pass = 1, Xfer_status_xfer_fail = 2, Xfer_status_convert_pass = 3, Xfer_status_convert_fail = 4;
public Xofo_lnki Xfer_status_(boolean v) {return Xfer_status_(v ? Xfer_status_xfer_pass : Xfer_status_xfer_fail);}
public boolean Orig() {return !thumb;}
public boolean Thumb() {return thumb;} public Xofo_lnki Thumb_(boolean v) {thumb = v; return this;} private boolean thumb;
public int File_w() {return file_w;} public Xofo_lnki File_w_(int v) {file_w = v; return this;} private int file_w;
public int File_h() {return file_h;} public Xofo_lnki File_h_(int v) {file_h = v; return this;} private int file_h;
public void Calc_size_(int w, int h) {file_w = w; file_h = h;}
public void Load_by_html_wtr(byte typ, int w, int h, double lnki_upright) {this.lnki_type = typ; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = lnki_upright;}
public Xofo_lnki Load_link_rdr(Gfo_fld_rdr fld_rdr, Io_line_rdr rdr, Xofo_lnki_parser lnki_parser) {
fld_rdr.Ini(rdr.Bfr(), rdr.Itm_pos_bgn());
name = fld_rdr.Read_bry_escape();
Xofo_lnki tmp = lnki_parser.Parse_ary(rdr.Bfr(), fld_rdr.Pos(), rdr.Itm_pos_end())[0];
lnki_type = tmp.Lnki_type();
lnki_w = tmp.Lnki_w();
lnki_h = tmp.Lnki_h();
lnki_upright = tmp.Lnki_upright();
return this;
}
public static void Write(Gfo_fld_wtr wtr, byte[] ttl, Xop_lnki_tkn lnki) {
wtr.Write_bry_escape_fld(ttl);
wtr.Bfr()
.Add_int_variable(lnki.Lnki_type()).Add_byte(Byte_ascii.Comma)
.Add_int_variable(lnki.W()).Add_byte(Byte_ascii.Comma)
.Add_int_variable(lnki.H())
;
boolean upright_exists = lnki.Upright() != Xop_lnki_tkn.Upright_null;
if (upright_exists) {
wtr.Bfr().Add_byte(Byte_ascii.Comma)
.Add(Xop_lnki_arg_parser.Bry_upright).Add_byte(Byte_ascii.Eq).Add_double(lnki.Upright());
}
wtr.Write_dlm_row();
}
public static final Xofo_lnki[] Ary_empty = new Xofo_lnki[0];
}

View File

@@ -0,0 +1,75 @@
/*
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; import gplx.*;
import gplx.xowa.files.*;
class Xofo_lnki_parser extends Obj_ary_parser_base {
Number_parser parser = new Number_parser(); Xofo_lnki[] ary; int ary_idx;
public Xofo_lnki[] Parse_ary(byte[] bry, int bgn, int end) {
Parse_core(bry, bgn, end, Byte_ascii.Semic, Byte_ascii.Nl);
return ary;
}
@Override protected void Ary_len_(int v) {
if (v == 0)
ary = Xofo_lnki.Ary_empty;
else {
ary = new Xofo_lnki[v]; // NOTE: always create new array; never reuse;
ary_idx = 0;
}
}
@Override protected void Parse_itm(byte[] bry, int bgn, int end) {// 1,2,3,lnki_upright=12
Xofo_lnki lnki = new Xofo_lnki();
ary[ary_idx++] = lnki;
int fld_bgn = bgn, fld_idx = 0, eq_pos = -1;
for (int i = bgn; i < end; i++) {
byte b = bry[i];
switch (b) {
case Byte_ascii.Eq: eq_pos = i; break;
case Byte_ascii.Comma:
Exec_val(lnki, fld_idx, eq_pos, bry, fld_bgn, i);
++fld_idx;
fld_bgn = i + 1;
break;
}
}
Exec_val(lnki, fld_idx, eq_pos, bry, fld_bgn, end);
}
private void Exec_val(Xofo_lnki lnki, int fld_idx, int eq_pos, byte[] bry, int fld_bgn, int i) {
int fld_val = -1;
if (fld_idx < 3) {
fld_val = Bry_.Xto_int_or(bry, fld_bgn, i, Int_.MinValue);
if (fld_val == Int_.MinValue) throw Exc_.new_("invalid int", "val", String_.new_u8(bry, fld_bgn, i));
switch (fld_idx) {
case 0: lnki.Lnki_type_((byte)fld_val); break;
case 1: lnki.Lnki_w_(fld_val); break;
case 2: lnki.Lnki_h_(fld_val); break;
default: throw Exc_.new_unhandled(fld_idx);
}
}
else {
if (Bry_.Match(bry, fld_bgn, eq_pos, Xop_lnki_arg_parser.Bry_upright)) {
double upright = Bry_.XtoDoubleByPos(bry, eq_pos + 1, i); // +1 to position after eq
lnki.Lnki_upright_(upright);
}
else if (Bry_.Match(bry, fld_bgn, eq_pos, Xop_lnki_arg_parser.Bry_thumbtime)) {
fld_val = Bry_.Xto_int_or(bry, eq_pos + 1, i, Int_.MinValue); // +1 to position after eq
if (fld_val == Int_.MinValue) throw Exc_.new_("invalid int", "val", String_.new_u8(bry, eq_pos + 1, i));
lnki.Lnki_thumbtime_(Xof_lnki_time.X_int(fld_val));
}
}
}
}

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; import gplx.*;
import org.junit.*;
import gplx.xowa.files.*;
public class Xofo_lnki_parser_tst {
Xofo_lnki_parser_fxt fxt = new Xofo_lnki_parser_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {
fxt.Raw_("8,90,80").Expd_(fxt.lnki_(8, 90, 80)).tst();
}
@Test public void Upright() {
fxt.Raw_("8,90,80,upright=.8").Expd_(fxt.lnki_(8, 90, 80).Lnki_upright_(.8d)).tst();
}
@Test public void Thumbtime() {
fxt.Raw_("8,90,80,thumbtime=8").Expd_(fxt.lnki_(8, 90, 80).Lnki_thumbtime_(8)).tst();
}
@Test public void Many() {
fxt.Raw_("8,20,30;8,90,80,upright=.8,thumbtime=8;8,30,40").Expd_(fxt.lnki_(8, 20, 30), fxt.lnki_(8, 90, 80).Lnki_upright_(.8d).Lnki_thumbtime_(8), fxt.lnki_(8, 30, 40)).tst();
}
}
class Xofo_lnki_parser_fxt {
Tst_mgr tst_mgr = new Tst_mgr();
Xofo_lnki_parser parser = new Xofo_lnki_parser();
public void Reset() {raw = null; expd = null;}
public Xofo_lnki_chkr lnki_(int t, int w, int h) {return new Xofo_lnki_chkr().Lnki_type_((byte)t).Lnki_w_(w).Lnki_h_(h);}
public Xofo_lnki_parser_fxt Raw_(String v) {raw = v; return this;} private String raw;
public Xofo_lnki_parser_fxt Expd_(Xofo_lnki_chkr... v) {expd = v; return this;} private Xofo_lnki_chkr[] expd;
public Xofo_lnki_parser_fxt tst() {
byte[] bry = Bry_.new_u8(raw);
Xofo_lnki[] actl = parser.Parse_ary(bry, 0, bry.length);
tst_mgr.Tst_ary("", expd, actl);
return this;
}
}
class Xofo_lnki_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Xofo_lnki.class;}
public Xofo_lnki_chkr Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type = Byte_.Max_value_127;
public Xofo_lnki_chkr Lnki_w_(int v) {lnki_w = v; return this;} private int lnki_w = -1;
public Xofo_lnki_chkr Lnki_h_(int v) {lnki_h = v; return this;} private int lnki_h = -1;
public Xofo_lnki_chkr Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright = -1;
public Xofo_lnki_chkr Lnki_thumbtime_(int v) {lnki_thumbtime = v; return this;} private int lnki_thumbtime = -1;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xofo_lnki actl = (Xofo_lnki)actl_obj;
int rv = 0;
rv += mgr.Tst_val(lnki_type == Byte_.Max_value_127, path, "lnki_type", lnki_type, actl.Lnki_type());
rv += mgr.Tst_val(lnki_w == -1, path, "lnki_w", lnki_w, actl.Lnki_w());
rv += mgr.Tst_val(lnki_h == -1, path, "lnki_h", lnki_h, actl.Lnki_h());
rv += mgr.Tst_val(lnki_upright == -1, path, "lnki_upright", lnki_upright, actl.Lnki_upright());
rv += mgr.Tst_val(lnki_thumbtime == -1, path, "lnki_thumbtime", lnki_thumbtime, Xof_lnki_time.X_int(actl.Lnki_thumbtime()));
return rv;
}
}

View File

@@ -0,0 +1,30 @@
/*
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; import gplx.*;
public class Xofw_file_finder_rslt {
public byte[] Ttl() {return ttl;} private byte[] ttl;
public byte[] Redirect() {return redirect;} private byte[] redirect;
public int Repo_idx() {return repo_idx;} private int repo_idx;
public byte[] Repo_wiki_key() {return repo_wiki_key;} private byte[] repo_wiki_key;
public void Init(byte[] ttl) {
this.ttl = ttl; redirect = Xop_redirect_mgr.Redirect_null_bry; repo_wiki_key = null; repo_idx = Byte_.Max_value_127;
}
public void Done(int repo_idx, byte[] repo_wiki_key, byte[] redirect) {
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key; this.redirect = redirect;
}
}

View File

@@ -0,0 +1,23 @@
/*
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; import gplx.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public interface Xofw_wiki_finder {
void Find(List_adp repo_pairs, Xof_xfer_itm file);
boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry);
}

View File

@@ -0,0 +1,72 @@
/*
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; import gplx.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*;
public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoae_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoae_wiki_mgr wiki_mgr;
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
byte[] ttl_bry = file.Lnki_ttl();
int repo_pairs_len = repo_pairs.Count();
for (int i = 0; i < repo_pairs_len; i++) {
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
byte[] wiki_key = repo_pair.Src().Wiki_domain();
if (repo_pair.Src().Wmf_api()) continue;
Xowe_wiki repo_wiki = wiki_mgr.Get_by_key_or_null(wiki_key);
if (repo_wiki == null) {continue;}
Xoa_ttl ttl = Xoa_ttl.parse_(repo_wiki, ttl_bry);
Xow_ns file_ns = repo_wiki.Ns_mgr().Ns_file();
boolean found = repo_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl.Page_db());
if (!found) {continue;}
byte[] redirect = Get_redirect(repo_wiki, file_ns, tmp_db_page);
file.Orig_ttl_and_redirect_(ttl.Page_txt(), redirect);
file.Orig_repo_id_(i);
return;
}
file.Orig_repo_id_(-1);
}
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); // NOTE: parse_(ttl_bry) should be the same across all wikis; i.e.: there should be no aliases/namespaces
Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); // NOTE: file_ns should also be the same across all wikis; being used for data_mgr.Parse below
byte[] ttl_db_key = ttl.Page_db();
rv.Init(ttl_db_key);
int repo_pairs_len = repo_pairs.Count();
for (int i = 0; i < repo_pairs_len; i++) {
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
byte[] src_wiki_key = repo_pair.Src().Wiki_domain();
Xowe_wiki src_wiki = wiki_mgr.Get_by_key_or_null(src_wiki_key);
if (src_wiki == null) continue; // src_wiki defined as repo_pair in cfg, but it has not been downloaded; continue; EX: commons set up but not downloaded
boolean found = src_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl_db_key);
if (!found) continue; // ttl does not exist in src_wiki; continue; EX: file does not exist in commons, but exists in en_wiki
byte[] redirect = Get_redirect(src_wiki, file_ns, tmp_db_page);
rv.Done(i, src_wiki_key, redirect);
return true;
}
return false;
}
private byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xowd_page_itm db_page) {
if (db_page.Redirected()) {
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
byte[] src = db_page.Text();
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
}
else
return Xop_redirect_mgr.Redirect_null_bry;
}
private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
}

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; import gplx.*;
import gplx.xowa.files.*;
public class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
int repo_idx; byte[] repo_wiki_key;
public Xofw_wiki_wkr_mock Clear_en_wiki() {return Clear(1, Bry_en_wiki);}
public Xofw_wiki_wkr_mock Clear_commons() {return Clear(0, Bry_commons);}
Xofw_wiki_wkr_mock Clear(int repo_idx, byte[] repo_wiki_key) {
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
if_ttl = then_redirect = Bry_.Empty;
return this;
}
private static final byte[] Bry_commons = Bry_.new_a7("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_a7("en.wikipedia.org");
public Xofw_wiki_wkr_mock Repo_idx_(int v) {this.repo_idx = v; return this;}
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_u8(if_ttl_str); this.then_redirect = Bry_.new_u8(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
byte[] ttl = file.Lnki_ttl();
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Orig_ttl_and_redirect_(ttl, then_redirect); file.Orig_repo_id_(repo_idx);}
else {file.Orig_ttl_and_redirect_(ttl, Bry_.Empty) ; file.Orig_repo_id_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
}
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl) {
rv.Init(ttl);
byte[] redirect = Bry_.Eq(ttl, if_ttl) ? then_redirect : null;
rv.Done(repo_idx, repo_wiki_key, redirect);
return true;
}
}

View File

@@ -0,0 +1,54 @@
/*
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; import gplx.*;
class Xoo_mgr implements GfoInvkAble {
public Xoo_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_owner)) return app;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner";
}
class Xoo_grp implements GfoInvkAble {
public Xoo_grp(Xoo_mgr mgr, String key) {this.mgr = mgr; this.key = key;} private Xoo_mgr mgr;
public String Key() {return key;} private String key;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return mgr;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner";
}
class Xoo_itm_html {
public Xoo_itm_html(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return grp;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner";
}
class Xoo_itm_file {
public Xoo_itm_file(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return grp;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner";
}
class Xoo_itm_interwiki {
public Xoo_itm_interwiki(Xoo_grp grp) {this.grp = grp;} private Xoo_grp grp;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return grp;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner";
}