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-02-22 21:03:49 -05:00
parent 3df6db4b7b
commit f495595da4
1119 changed files with 11513 additions and 11734 deletions

View File

@@ -16,13 +16,14 @@ 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 {
public Xoa_repo_mgr(Xoa_app app) {this.app = app;}
public Xoa_app App() {return app;} private Xoa_app app;
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.FetchAt(i);}
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Fetch(key);}
public Xof_repo_itm Get_primary(byte[] 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.FetchAt(i);
@@ -30,7 +31,7 @@ public class Xoa_repo_mgr implements GfoInvkAble {
}
return null;
}
public Xof_repo_itm Get_by_wmf(byte[] key) {
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.FetchAt(i);
@@ -55,7 +56,7 @@ public class Xoa_repo_mgr implements GfoInvkAble {
byte[] key_bry = Bry_.new_utf8_(key);
Xof_repo_itm itm = (Xof_repo_itm)hash.Fetch(key_bry);
if (itm == null) {
itm = new Xof_repo_itm(this, key_bry);
itm = new Xof_repo_itm(key_bry, app_fsys, ext_rule_mgr);
this.Add(itm);
}
itm.Root_str_(url_str).Wiki_key_(Bry_.new_utf8_(wiki));

View File

@@ -1,46 +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; import gplx.*;
public class Xoaf_download_mgr implements GfoInvkAble {
public Xoaf_download_mgr(Xoa_app app) {
this.app = app;
download_wkr = new Xof_download_wkr_io(app);
download_wkr.Download_xrg().User_agent_(Xoa_app_.User_agent).Prog_dlg_(app.Usr_dlg());
} private Xoa_app app;
public boolean Enabled() {return enabled;}
public Xoaf_download_mgr Enabled_(boolean v) {
enabled = v;
File_download_enable(app, v);
return this;
} private boolean enabled = true; // default to true; DATE:2015-01-05
public Xof_download_wkr Download_wkr() {return download_wkr;} public Xoaf_download_mgr Download_wkr_(Xof_download_wkr v) {download_wkr = v; return this;} private Xof_download_wkr download_wkr;
public Xof_img_wkr_api_size_base Api_size_wkr() {return api_size_wkr;} public Xoaf_download_mgr Api_size_wkr_(Xof_img_wkr_api_size_base v) {api_size_wkr = v; return this;} private Xof_img_wkr_api_size_base api_size_wkr = new Xof_img_wkr_api_size_base_wmf();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
public static void File_download_enable(Xoa_app app, boolean v) {
int len = app.Wiki_mgr().Count();
for (int i = 0; i < len; i++) {
Xow_wiki wiki = app.Wiki_mgr().Get_at(i);
wiki.File_mgr().Cfg_download().Enabled_(v);
}
}
}

View File

@@ -33,25 +33,3 @@ class Xof_download_wkr_test implements Xof_download_wkr {
return IoEngine_xrg_downloadFil.Rslt_pass;
}
}
class Xof_download_wkr_io implements Xof_download_wkr {
IoEngine_xrg_downloadFil xrg = Io_mgr._.DownloadFil_args("", Io_url_.Null);
public Xof_download_wkr_io(Xoa_app app) {}
public IoEngine_xrg_downloadFil Download_xrg() {return xrg;}
public String Download_err() {return download_err;} private String download_err = "";
public byte Download(boolean src_is_web, String src_str, Io_url trg_url, String prog_fmt_hdr) {
download_err = "";
if (src_is_web) {
xrg.Prog_fmt_hdr_(prog_fmt_hdr);
xrg.Init(src_str, trg_url);
xrg.Exec();
return xrg.Rslt();
}
else {
Io_url src_url = Io_url_.new_fil_(src_str);
if (!Io_mgr._.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
try {Io_mgr._.CopyFil(src_url, trg_url, true);}
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
return IoEngine_xrg_downloadFil.Rslt_pass;
}
}
}

View File

@@ -0,0 +1,40 @@
/*
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.ios.*;
public class Xof_download_wkr_io implements Xof_download_wkr {
IoEngine_xrg_downloadFil xrg = Io_mgr._.DownloadFil_args("", Io_url_.Null);
public IoEngine_xrg_downloadFil Download_xrg() {return xrg;}
public String Download_err() {return download_err;} private String download_err = "";
public byte Download(boolean src_is_web, String src_str, Io_url trg_url, String prog_fmt_hdr) {
download_err = "";
if (src_is_web) {
xrg.Prog_fmt_hdr_(prog_fmt_hdr);
xrg.Init(src_str, trg_url);
xrg.Exec();
return xrg.Rslt();
}
else {
Io_url src_url = Io_url_.new_fil_(src_str);
if (!Io_mgr._.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
try {Io_mgr._.CopyFil(src_url, trg_url, true);}
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
return IoEngine_xrg_downloadFil.Rslt_pass;
}
}
}

View File

@@ -16,35 +16,35 @@ 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.xtns.math.*;
import gplx.xowa.files.fsdb.caches.*;
import gplx.dbs.*; import gplx.xowa2.files.commons.*;
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 void Init_app(Xoa_app app, Gfo_usr_dlg usr_dlg) {
this.app = app;
img_mgr.Init_app(app); repo_mgr = new Xoa_repo_mgr(app);
math_mgr = new Xof_math_mgr(app);
math_mgr.Init(app);
download_mgr = new Xoaf_download_mgr(app);
cache_mgr = new Cache_mgr(app);
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 Xoa_app App() {return app;} private Xoa_app app;
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 Xof_img_mgr img_mgr = new Xof_img_mgr();
public Xof_math_mgr Math_mgr() {return math_mgr;} private Xof_math_mgr math_mgr;
public Xoft_rule_mgr Ext_rules() {return ext_rules;} private Xoft_rule_mgr ext_rules = new Xoft_rule_mgr();
public Xoaf_download_mgr Download_mgr() {return download_mgr;} private Xoaf_download_mgr download_mgr;
public Cache_mgr Cache_mgr() {return cache_mgr;} private Cache_mgr cache_mgr;
public void Init_by_app() {
if (!Env_.Mode_testing())
cache_mgr.Db_init(app.User().Db_mgr());
public void Init_by_app(Xoae_app app) {
Io_url db_url = app.User().Fsys_mgr().Root_dir().OwnerDir().GenSubFil_ary("xowa.user.", app.User().Key_str(), ".sqlite3");
Db_conn_bldr_data conn_data = Db_conn_bldr.I.Get_or_new("xowa.user_db", db_url);
boolean version_is_1 = Bool_.Y;
cache_mgr.Init_for_db(conn_data.Conn(), conn_data.Created(), version_is_1);
}
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 download_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

@@ -1,32 +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; import gplx.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.*;
public class Xof_img_mgr {
public Xof_img_wkr_query_img_size Wkr_query_img_size() {return wkr_query_img_size;} public Xof_img_mgr Wkr_query_img_size_(Xof_img_wkr_query_img_size v) {wkr_query_img_size = v; return this;} private Xof_img_wkr_query_img_size wkr_query_img_size;
public Xof_img_wkr_resize_img Wkr_resize_img() {return wkr_resize_img;} public Xof_img_mgr Wkr_resize_img_(Xof_img_wkr_resize_img v) {wkr_resize_img = v; return this;} private Xof_img_wkr_resize_img wkr_resize_img;
public Xof_img_wkr_convert_djvu_to_tiff Wkr_convert_djvu_to_tiff() {return wkr_convert_djvu_to_tiff;} public Xof_img_mgr Wkr_convert_djvu_to_tiff_(Xof_img_wkr_convert_djvu_to_tiff v) {wkr_convert_djvu_to_tiff = v; return this;} private Xof_img_wkr_convert_djvu_to_tiff wkr_convert_djvu_to_tiff;
public int Thumb_w_img() {return thumb_w_img;} private int thumb_w_img = Xof_img_size.Thumb_width_img;
public int Thumb_w_ogv() {return thumb_w_ogv;} private int thumb_w_ogv = Xof_img_size.Thumb_width_ogv;
public void Init_app(Xoa_app app) {
Launcher_app_mgr app_mgr = app.Launcher();
wkr_query_img_size = new Xof_img_wkr_query_img_size_imageMagick(app, app_mgr.App_query_img_size());
wkr_resize_img = new Xof_img_wkr_resize_img_imageMagick(app, app_mgr.App_resize_img(), app_mgr.App_convert_svg_to_png());
wkr_convert_djvu_to_tiff = new Xof_img_wkr_convert_djvu_to_tiff_app(app_mgr.App_convert_djvu_to_tiff());
}
}

View File

@@ -1,35 +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; import gplx.*;
public interface Xof_img_wkr_convert_djvu_to_tiff {
boolean Exec(Io_url src, Io_url trg);
}
class Xof_img_wkr_convert_djvu_to_tiff_app implements Xof_img_wkr_convert_djvu_to_tiff {
public Xof_img_wkr_convert_djvu_to_tiff_app(ProcessAdp process) {this.process = process;} ProcessAdp process;
public boolean Exec(Io_url src, Io_url trg) {
process.Run(src, trg);
return process.Exit_code_pass();
}
}
class Xof_img_wkr_convert_djvu_to_tiff_mok implements Xof_img_wkr_convert_djvu_to_tiff {
public Xof_img_wkr_convert_djvu_to_tiff_mok(int w, int h) {this.w = w; this.h = h;} private int w, h;
public boolean Exec(Io_url src, Io_url trg) {
Io_mgr._.SaveFilStr(trg, gplx.gfui.SizeAdp_.new_(w, h).XtoStr());
return true;
}
}

View File

@@ -1,130 +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; import gplx.*;
import gplx.core.btries.*;
public class Xof_repo_itm implements GfoInvkAble {
public Xof_repo_itm(Xoa_repo_mgr mgr, byte[] key) {this.mgr = mgr; this.key = key;} private final Xoa_repo_mgr mgr;
public byte[] Key() {return key;} private final byte[] key;
public boolean Wmf_fsys() {return wmf_fsys;} public Xof_repo_itm Wmf_fsys_(boolean v) {wmf_fsys = v; return this;} private boolean wmf_fsys;
public boolean Wmf_api() {return wmf_api;} public Xof_repo_itm Wmf_api_(boolean v) {wmf_api = v; return this;} private boolean wmf_api;
public boolean Tarball() {return tarball;} public Xof_repo_itm Tarball_(boolean v) {tarball = v; return this;} private boolean tarball;
public byte Dir_spr() {return dir_spr;} private byte dir_spr;
public byte[] Root() {return root;} private byte[] root;
public String Root_str() {return root_str;} private String root_str;
public Io_url Root_url() {return root_url;} Io_url root_url;
public boolean Fsys_is_wnt() {return fsys_is_wnt;} public Xof_repo_itm Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty;
public byte[] Wiki_key() {return wiki_key;} public Xof_repo_itm Wiki_key_(byte[] v) {wiki_key = v; return this;} private byte[] wiki_key;
public int Ttl_max() {return ttl_max;} public Xof_repo_itm Ttl_max_(int v) {ttl_max = v; return this;} private int ttl_max = 180;
public byte[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Mode_names_key[0], Mode_names_key[1]};
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_utf8_("orig"), Bry_.new_utf8_("thumb")};
public Xoft_rule_grp Ext_rules() {return ext_rules;} public Xof_repo_itm Ext_rules_(Xoft_rule_grp v) {ext_rules = v; return this;} private Xoft_rule_grp ext_rules;
public int Dir_depth() {return dir_depth;} public Xof_repo_itm Dir_depth_(int v) {dir_depth = v; return this;} private int dir_depth = 4;
public boolean Primary() {return primary;} public Xof_repo_itm Primary_(boolean v) {primary = v; return this;} private boolean primary;
public Xof_repo_itm Root_str_(String v) {
this.root_str = v;
root = Bry_.new_utf8_(root_str);
wmf_fsys = String_.HasAtBgn(root_str, "http") || String_.HasAtBgn(root_str, "ftp");
if (wmf_fsys) {
root_url = Io_url_.Null;
dir_spr = Byte_ascii.Slash;
wmf_api = true;
}
else {
root_url = App_cmd_arg.Val_as_url_rel_url_or(root_str, mgr.App().Fsys_mgr().File_dir(), Io_url_.new_dir_(root_str), true);
root = root_url.RawBry();
dir_spr = root_url.Info().DirSpr_byte();
root_http = mgr.App().Encoder_mgr().Fsys().Encode_http(root_url);
}
return this;
}
public static byte[] Ttl_invalid_fsys_chars(byte[] ttl) {
int ttl_len = ttl.length;
for (int i = 0; i < ttl_len; i++) {
byte b = ttl[i];
Object o = wnt_trie.Match_bgn_w_byte(b, ttl, i, ttl_len);
if (o == null) wnt_tmp_bfr.Add_byte(b); // regular char; add orig byte
else wnt_tmp_bfr.Add((byte[])o); // invalid char; add swap byte(s)
}
return wnt_tmp_bfr.Xto_bry_and_clear();
} private static final Bry_bfr wnt_tmp_bfr = Bry_bfr.reset_(255); private static final Btrie_slim_mgr wnt_trie = trie_make();
public static byte[] Ttl_shorten_ttl(int ttl_max, byte[] ttl, byte[] md5, Xof_ext ext) {
byte[] rv = ttl;
int exceed_len = rv.length - ttl_max;
if (exceed_len > 0) {
wnt_tmp_bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
wnt_tmp_bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
wnt_tmp_bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
wnt_tmp_bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
wnt_tmp_bfr.Add(ext.Ext()); // add ext; EX: ".png"
rv = wnt_tmp_bfr.Xto_bry_and_clear();
}
return rv;
}
public byte[] Gen_name_src(byte[] name) {
if (!fsys_is_wnt || wmf_fsys) return name;
int name_len = name.length;
for (int i = 0; i < name_len; i++) {
byte b = name[i];
Object o = trie.Match_bgn_w_byte(b, name, i, name_len);
if (o == null) tmp_bfr.Add_byte(b);
else tmp_bfr.Add((byte[])o);
}
byte[] rv = tmp_bfr.Xto_bry_and_clear();
return rv;
} private final Bry_bfr tmp_bfr = Bry_bfr.reset_(300);
public byte[] Gen_name_trg(byte[] bry, byte[] md5, Xof_ext ext) {
byte[] rv = Gen_name_src(bry);
byte[] ext_bry = ext.Ext();
int exceed_len = rv.length - ttl_max;
if (exceed_len > 0) {
tmp_bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
tmp_bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
tmp_bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
tmp_bfr.Add_byte(Byte_ascii.Dot);
tmp_bfr.Add(ext_bry);
rv = tmp_bfr.Xto_bry_and_clear();
}
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return mgr;
else if (ctx.Match(k, Invk_fsys_)) fsys_is_wnt = String_.Eq(m.ReadStr("v"), "wnt");
else if (ctx.Match(k, Invk_primary_)) primary = m.ReadYn("v");
else if (ctx.Match(k, Invk_ext_rules_)) Ext_rules_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_wmf_api_)) wmf_api = m.ReadYn("v");
else if (ctx.Match(k, Invk_tarball_)) tarball = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_owner = "owner", Invk_fsys_ = "fsys_", Invk_ext_rules_ = "ext_rules_", Invk_primary_ = "primary_", Invk_wmf_api_ = "wmf_api_", Invk_tarball_ = "tarball_";
public Xof_repo_itm Ext_rules_(byte[] ext_rules_key) {ext_rules = mgr.App().File_mgr().Ext_rules().Get_or_new(ext_rules_key); return this;}
public static final int Thumb_default_null = -1;
public static final byte Mode_orig = 0, Mode_thumb = 1, Mode_nil = Byte_.Max_value_127;
public static final byte Repo_remote = 0, Repo_local = 1, Repo_unknown = 126, Repo_null = Byte_.Max_value_127;
public static final int Dir_depth_null = -1, Dir_depth_wmf = 2, Dir_depth_xowa = 4;
private static final Btrie_slim_mgr trie = trie_make();
private static Btrie_slim_mgr trie_make() {
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
byte[] invalid = Op_sys.Wnt.Fsys_invalid_chars();
byte[] underline = new byte[] {Byte_ascii.Underline};
int len = invalid.length;
for (int i = 0; i < len; i++)
rv.Add_obj(new byte[] {invalid[i]}, underline);
return rv;
}
}

View File

@@ -1,41 +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; import gplx.*;
import gplx.core.primitives.*;
public class Xoft_rule_grp implements GfoInvkAble {
public Xoft_rule_grp(Xoft_rule_mgr owner, byte[] key) {this.owner = owner; this.key = key;}
public Xoft_rule_mgr Owner() {return owner;} private Xoft_rule_mgr owner;
public byte[] Key() {return key;} private byte[] key;
public Xoft_rule_itm Get_or_null(byte[] key) {return (Xoft_rule_itm)hash.Fetch(hash_ref.Val_(key));}
public Xoft_rule_itm Get_or_new(byte[] key) {
Xoft_rule_itm rv = Get_or_null(key);
if (rv == null) {
Xof_ext file_type = Xof_ext_.new_by_ext_(key);
rv = new Xoft_rule_itm(this, file_type);
hash.Add(Bry_obj_ref.new_(key), rv);
}
return rv;
} HashAdp hash = HashAdp_.new_(); Bry_obj_ref hash_ref = Bry_obj_ref.null_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return owner;
else if (ctx.Match(k, Invk_set)) return Get_or_new(Bry_.new_utf8_(m.ReadStr("v")));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_owner = "owner", Invk_set = "set";
public static final String Grp_app_default_str = "app_default";
public static byte[] Grp_app_default = Bry_.new_utf8_(Grp_app_default_str);
}

View File

@@ -1,35 +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; import gplx.*;
import gplx.xowa.apps.*;
public class Xoft_rule_itm implements GfoInvkAble {
public Xoft_rule_itm(Xoft_rule_grp owner, Xof_ext file_type) {this.owner = owner; this.file_type = file_type;}
public Xoft_rule_grp Owner() {return owner;} private Xoft_rule_grp owner;
public Xof_ext File_type() {return file_type;} private Xof_ext file_type;
public long Make_max() {return make_max;} public Xoft_rule_itm Make_max_(long v) {make_max = v; return this;} long make_max = Max_wildcard;
public long View_max() {return view_max;} public Xoft_rule_itm View_max_(long v) {view_max = v; return this;} long view_max = Max_wildcard;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return owner;
else if (ctx.Match(k, Invk_make_max_)) make_max = gplx.ios.Io_size_.Load_int_(m);
else if (ctx.Match(k, Invk_view_max_)) view_max = gplx.ios.Io_size_.Load_int_(m);
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_owner = "owner", Invk_make_max_ = "make_max_", Invk_view_max_ = "view_max_";
public static final long Max_wildcard = -1;
}

View File

@@ -1,44 +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; import gplx.*;
import gplx.xowa.apps.*;
public class Xoft_rule_mgr implements GfoInvkAble {
public Xoft_rule_mgr() {
Xoft_rule_grp app_default = new Xoft_rule_grp(this, Xoft_rule_grp.Grp_app_default);
App_default_set(app_default, Io_mgr.Len_gb, Xof_ext_.Bry__ary);
hash.Add(Xoft_rule_grp.Grp_app_default, app_default);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) return Get_or_new(Bry_.new_utf8_(m.ReadStr("v")));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_set = "set";
Xoft_rule_grp Get_or_null(byte[] key) {return (Xoft_rule_grp)hash.Fetch(key);}
public Xoft_rule_grp Get_or_new(byte[] key) {
Xoft_rule_grp rv = Get_or_null(key);
if (rv == null) {
rv = new Xoft_rule_grp(this, key);
hash.Add(key, rv);
}
return rv;
} HashAdp hash = HashAdp_.new_bry_();
private void App_default_set(Xoft_rule_grp app_default, long make_max, byte[][] keys) {
int keys_len = keys.length;
for (int i = 0; i < keys_len; i++)
app_default.Get_or_new(keys[i]).Make_max_(make_max);
}
}

View File

@@ -16,60 +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; import gplx.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public interface Xofw_wiki_finder {
void Find(ListAdp repo_pairs, Xof_xfer_itm file);
boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl_bry);
}
class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
public Xofw_wiki_wkr_base(Xow_wiki wiki, Xoa_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xow_wiki wiki; Xoa_wiki_mgr wiki_mgr;
public void Find(ListAdp 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.FetchAt(i);
byte[] wiki_key = repo_pair.Src().Wiki_key();
if (repo_pair.Src().Wmf_api()) continue;
Xow_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.Set__ttl(ttl.Page_txt(), redirect);
file.Trg_repo_idx_(i);
return;
}
file.Trg_repo_idx_(-1);
}
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp 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.FetchAt(i);
byte[] src_wiki_key = repo_pair.Src().Wiki_key();
Xow_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;
} static final Xodb_page tmp_db_page = Xodb_page.tmp_();
byte[] Get_redirect(Xow_wiki wiki, Xow_ns file_ns, Xodb_page db_page) {
if (db_page.Type_redirect()) {
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;
}
}

View File

@@ -0,0 +1,71 @@
/*
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 class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoa_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoa_wiki_mgr wiki_mgr;
public void Find(ListAdp 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.FetchAt(i);
byte[] wiki_key = repo_pair.Src().Wiki_key();
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.Set__ttl(ttl.Page_txt(), redirect);
file.Trg_repo_idx_(i);
return;
}
file.Trg_repo_idx_(-1);
}
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp 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.FetchAt(i);
byte[] src_wiki_key = repo_pair.Src().Wiki_key();
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;
} static final Xodb_page tmp_db_page = Xodb_page.tmp_();
byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xodb_page db_page) {
if (db_page.Type_redirect()) {
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;
}
}

View File

@@ -17,7 +17,7 @@ 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(Xoa_app app) {this.app = app;} private Xoa_app app;
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;