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,77 @@
/*
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.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.dbs.*;
class Fsdb_regy_fil_tbl {
public Fsdb_regy_fil_itm Select(String name, boolean is_orig, int w, int thumbtime) {
return null;
}
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE regy_fil"
, "( regy_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
, ", wiki_type_id integer"
, ", wiki_date_id integer"
, ", fil_name varchar(255)"
, ", fil_is_orig tinyint"
, ", fil_w integer"
, ", fil_h integer"
, ", fil_thumbtime integer"
, ", fil_ext integer"
, ", fil_size bigint"
, ", bin_db_id integer"
, ", fil_id integer"
, ", bin_id integer"
, ");"
);
public static final String
Fld_wiki_type_id = "wiki_type_id", Fld_wiki_date_id = "wiki_date_id", Fld_fil_name = "fil_name", Fld_fil_is_orig = "fil_is_orig"
, Fld_fil_w = "fil_w", Fld_fil_h = "fil_h", Fld_fil_thumbtime = "fil_thumbtime", Fld_fil_ext = "fil_ext", Fld_fil_size = "fil_size"
, Fld_bin_db_id = "bin_db_id", Fld_fil_id = "fil_id", Fld_bin_id = "bin_id"
;
public static final Db_idx_itm
Idx_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS fsdb_fil_regy__fil ON fsdb (fil_name, fil_is_orig, fil_w, fil_h, fil_thumbtime, bin_db_id, fil_id, bin_id);")
;
}
class Fsdb_regy_fil_itm {
public int Wiki_type_id() {return wiki_type_id;} private int wiki_type_id;
public int Wiki_date_id() {return wiki_date_id;} private int wiki_date_id;
public String Fil_name() {return fil_name;} private String fil_name;
public boolean Fil_is_orig() {return fil_is_orig;} private boolean fil_is_orig;
public int Fil_w() {return fil_w;} private int fil_w;
public int Fil_h() {return fil_h;} private int fil_h;
public int Fil_thumbtime() {return fil_thumbtime;} private int fil_thumbtime;
public int Fil_ext() {return fil_ext;} private int fil_ext;
public long Fil_size() {return fil_size;} private long fil_size;
public int Bin_db_id() {return bin_db_id;} private int bin_db_id;
public int Fil_id() {return fil_id;} private int fil_id;
public int Bin_id() {return bin_id;} private int bin_id;
public void Load(DataRdr rdr) {
wiki_date_id = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_wiki_date_id);
wiki_type_id = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_wiki_type_id);
fil_name = rdr.ReadStr(Fsdb_regy_fil_tbl.Fld_fil_name);
fil_is_orig = rdr.ReadByte(Fsdb_regy_fil_tbl.Fld_fil_is_orig) != Byte_.Zero;
fil_w = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_fil_w);
fil_h = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_fil_h);
fil_thumbtime = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_fil_thumbtime);
fil_ext = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_fil_ext);
fil_size = rdr.ReadLong(Fsdb_regy_fil_tbl.Fld_fil_size);
bin_db_id = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_bin_db_id);
fil_id = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_fil_id);
bin_id = rdr.ReadInt(Fsdb_regy_fil_tbl.Fld_bin_id);
}
}

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.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
public interface Xof_fsdb_mgr {
Xof_bin_mgr Bin_mgr();
Fsm_mnt_mgr Mnt_mgr();
void Init_by_wiki(Xow_wiki wiki);
void Fsdb_search_by_list(List_adp itms, Xow_wiki wiki, Xoa_page page, Xog_js_wkr js_wkr);
}

View File

@@ -0,0 +1,69 @@
/*
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.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*;
import gplx.ios.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, GfoInvkAble {
private boolean init = false; private boolean fsdb_enabled = false;
private Xow_repo_mgr repo_mgr; private Xof_url_bldr url_bldr; private final Xof_img_size img_size = new Xof_img_size();
public Xof_bin_mgr Bin_mgr() {return bin_mgr;} private Xof_bin_mgr bin_mgr;
public Fsm_mnt_mgr Mnt_mgr() {return mnt_mgr;} private Fsm_mnt_mgr mnt_mgr = new Fsm_mnt_mgr();
public void Init_by_wiki(Xow_wiki wiki) {
if (init) return;
try {
init = true;
// if (wiki.File__fsdb_mode().Tid_v0()) return;
this.url_bldr = Xof_url_bldr.new_v2();
this.repo_mgr = wiki.File__repo_mgr();
Fsdb_db_mgr fsdb_core = wiki.File__fsdb_core();
// Fsdb_db_mgr fsdb_core = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
if (fsdb_core == null) return;
fsdb_enabled = true;
mnt_mgr.Ctor_by_load(fsdb_core);
this.bin_mgr = new Xof_bin_mgr(mnt_mgr, repo_mgr, wiki.App().File__img_mgr().Wkr_resize_img(), wiki.App().Wmf_mgr().Download_wkr().Download_xrg().Download_fmt());
bin_mgr.Wkrs__add(Xof_bin_wkr__fsdb_sql.new_(mnt_mgr));
bin_mgr.Wkrs__add(Xof_bin_wkr__http_wmf.new_(wiki));
} catch (Exception e) {throw Exc_.new_exc(e, "xo", "failed to initialize fsdb_mgr}", "wiki", wiki.Domain_str());}
}
public void Fsdb_search_by_list(List_adp itms, Xow_wiki cur_wiki, Xoa_page page, Xog_js_wkr js_wkr) {
if (!fsdb_enabled) return;
int len = itms.Count();
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.I;
Xow_wiki wiki = page.Commons_mgr().Source_wiki_or(cur_wiki);
Xou_cache_mgr cache_mgr = wiki.App().User().User_db_mgr().Cache_mgr();
for (int i = 0; i < len; i++) {
if (usr_dlg.Canceled()) return;
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)itms.Get_at(i);
Xof_orig_itm orig = wiki.File__orig_mgr().Find_by_ttl_or_null(fsdb.Lnki_ttl(), i, len);
if (orig != Xof_orig_itm.Null) { // orig exists;
gplx.xowa.files.repos.Xof_repo_itm repo = wiki.File__repo_mgr().Get_trg_by_id_or_null(orig.Repo(), fsdb.Lnki_ttl(), Bry_.Empty);
if (repo == null) continue;
fsdb.Init_at_orig(orig.Repo(), repo.Wiki_domain(), orig.Ttl(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
}
fsdb.Init_at_xfer(i, len);
Xof_file_wkr.Show_img(fsdb, usr_dlg, wiki.File__bin_mgr(), wiki.File__mnt_mgr(), cache_mgr, wiki.File__repo_mgr(), js_wkr, img_size, url_bldr, page);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_mnt_mgr)) return mnt_mgr;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_mnt_mgr = "mnt_mgr";
}

View File

@@ -0,0 +1,27 @@
/*
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.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
public class Xof_fsdb_mgr_cfg {
public static final String
Grp_xowa = "xowa"
, Key_gallery_fix_defaults = "gallery.fix_defaults"
, Key_gallery_packed = "gallery.packed"
, Key_upright_use_thumb_w = "file.upright_ignores_lnki_w"
, Key_upright_fix_default = "file.upright_fix_default"
;
}

View File

@@ -0,0 +1,110 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.core.primitives.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.gfui.*;
import gplx.fsdb.meta.*; import gplx.xowa.files.imgs.*;
class Fs_root_dir {
private Gfo_usr_dlg usr_dlg; private Xof_img_wkr_query_img_size img_size_wkr;
private Io_url url; private boolean recurse = true;
private Orig_fil_mgr cache = new Orig_fil_mgr(), fs_fil_mgr;
private Db_conn conn; private Db_cfg_tbl cfg_tbl; private Orig_fil_tbl fil_tbl;
private int fil_id_next = 0;
public void Init(Io_url url, Orig_fil_tbl fil_tbl, Gfo_usr_dlg usr_dlg, Xof_img_wkr_query_img_size img_size_wkr) {
this.url = url;
this.fil_tbl = fil_tbl; this.usr_dlg = usr_dlg; this.img_size_wkr = img_size_wkr;
}
public Orig_fil_itm Get_by_ttl(byte[] lnki_ttl) {
Orig_fil_itm rv = (Orig_fil_itm)cache.Get_by_ttl(lnki_ttl);
if (rv == null) {
rv = Get_from_db(lnki_ttl);
if (rv == null) {
rv = Get_from_fs(lnki_ttl);
if (rv == null) return Orig_fil_itm.Null;
}
cache.Add(rv);
}
return rv;
}
private Orig_fil_itm Get_from_db(byte[] lnki_ttl) {
if (conn == null) conn = Init_db_fil_mgr();
Orig_fil_itm rv = fil_tbl.Select_itm(lnki_ttl);
if (rv == null) return Orig_fil_itm.Null; // not in db
return rv;
}
private Orig_fil_itm Get_from_fs(byte[] lnki_ttl) {
if (fs_fil_mgr == null) fs_fil_mgr = Init_fs_fil_mgr();
Orig_fil_itm rv = fs_fil_mgr.Get_by_ttl(lnki_ttl);
if (rv == null) return Orig_fil_itm.Null; // not in fs
SizeAdp img_size = SizeAdp_.Zero;
if (Xof_ext_.Id_is_image(rv.Fil_ext_id()))
img_size = img_size_wkr.Exec(rv.Fil_url());
rv.Init_by_size(++fil_id_next, img_size.Width(), img_size.Height());
cfg_tbl.Update_int(Cfg_grp_root_dir, Cfg_key_fil_id_next, fil_id_next);
fil_tbl.Insert(rv);
return rv;
}
private Orig_fil_mgr Init_fs_fil_mgr() { // NOTE: need to read entire dir, b/c ttl may be "A.png", but won't know which subdir
Orig_fil_mgr rv = new Orig_fil_mgr();
Io_url[] fils = Io_mgr.I.QueryDir_args(url).Recur_(recurse).ExecAsUrlAry();
int fils_len = fils.length;
for (int i = 0; i < fils_len; i++) {
Io_url fil = fils[i];
byte[] fil_name_bry = Xto_fil_bry(fil);
Orig_fil_itm fil_itm = rv.Get_by_ttl(fil_name_bry);
if (fil_itm != Orig_fil_itm.Null) {
usr_dlg.Warn_many("", "", "file already exists: cur=~{0} new=~{1}", fil_itm.Fil_url().Raw(), fil.Raw());
continue;
}
Xof_ext ext = Xof_ext_.new_by_ttl_(fil_name_bry);
fil_itm = new Orig_fil_itm().Init_by_make(fil, fil_name_bry, ext.Id());
rv.Add(fil_itm);
}
return rv;
}
private Db_conn Init_db_fil_mgr() {
Io_url db_url = url.GenSubFil("^orig_regy.sqlite3");
boolean created = false; boolean schema_is_1 = Bool_.Y;
Db_conn conn = Db_conn_bldr.I.Get(db_url);
if (conn == null) {
conn = Db_conn_bldr.I.New(db_url);
created = true;
}
cfg_tbl = new Db_cfg_tbl(conn, schema_is_1 ? "fsdb_cfg" : "xowa_cfg");
fil_tbl.Conn_(conn, created, schema_is_1);
if (created) {
cfg_tbl.Create_tbl();
cfg_tbl.Insert_int(Cfg_grp_root_dir, Cfg_key_fil_id_next, fil_id_next);
}
else {
fil_id_next = cfg_tbl.Select_int(Cfg_grp_root_dir, Cfg_key_fil_id_next);
}
return conn;
}
public void Rls() {
cfg_tbl.Rls();
fil_tbl.Rls();
}
private static final String Cfg_grp_root_dir = "xowa.root_dir", Cfg_key_fil_id_next = "fil_id_next";
public static byte[] Xto_fil_bry(Io_url url) {
byte[] rv = Bry_.new_u8(url.NameAndExt());
rv = Bry_.Replace(rv, Byte_ascii.Space, Byte_ascii.Underline);
rv = Bry_.Upper_1st(rv);
return rv;
}
}

View File

@@ -0,0 +1,95 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.files.imgs.*;
import gplx.fsdb.meta.*;
public class Fs_root_dir_tst {
@Before public void init() {fxt.Reset();} private Fs_root_dir_fxt fxt = new Fs_root_dir_fxt();
@Test public void Basic() {
fxt.Init_fs("mem/dir/A.png", 200, 100);
fxt.Test_get("A.png", fxt.itm_().Url_("mem/dir/A.png").Size_(200, 100));
fxt.Test_db("A.png", fxt.itm_().Init(1, "mem/dir/A.png", 200, 100));
}
@Test public void Recurse() {
fxt.Init_fs("mem/dir/sub1/A1.png", 200, 100);
fxt.Test_get("A1.png", fxt.itm_().Url_("mem/dir/sub1/A1.png").Size_(200, 100));
}
@Test public void Xto_fil_bry() {
fxt.Test_xto_fil_bry("/dir/A.png" , "A.png"); // basic
fxt.Test_xto_fil_bry("/dir/A b.png" , "A_b.png"); // lower
fxt.Test_xto_fil_bry("/dir/a.png" , "A.png"); // title
}
}
class Fs_root_dir_fxt {
private Fs_root_dir root_dir = new Fs_root_dir();
private Orig_fil_tbl orig_fil_tbl;
private Io_url url;
public void Reset() {
Db_conn_bldr.I.Reg_default_mem();
Io_mgr.I.InitEngine_mem();
url = Io_url_.mem_dir_("mem/dir/");
root_dir = new Fs_root_dir();
orig_fil_tbl = new Orig_fil_tbl();
Xof_img_wkr_query_img_size img_size_wkr = new Xof_img_wkr_query_img_size_test();
root_dir.Init(url, orig_fil_tbl, Gfo_usr_dlg_.Noop, img_size_wkr);
}
public Orig_fil_mok itm_() {return new Orig_fil_mok();}
public void Init_fs(String url, int w, int h) {Save_img(url, w, h);}
public void Test_get(String name, Orig_fil_mok expd) {
Orig_fil_itm actl = root_dir.Get_by_ttl(Bry_.new_u8(name));
expd.Test(actl);
}
public void Test_db(String ttl, Orig_fil_mok expd) {
Orig_fil_itm actl = orig_fil_tbl.Select_itm(Bry_.new_u8(ttl));
expd.Test(actl);
}
public static void Save_img(String url, int w, int h) {
gplx.gfui.SizeAdp img_size = gplx.gfui.SizeAdp_.new_(w, h);
Io_mgr.I.SaveFilStr(url, img_size.XtoStr());
}
public void Test_xto_fil_bry(String url_str, String expd) {
Io_url url = Io_url_.new_fil_(url_str);
Tfds.Eq(expd, String_.new_u8(Fs_root_dir.Xto_fil_bry(url)));
}
}
class Orig_fil_mok {
private int uid = -1;
private int ext_id = -1;
private String name = null;
private int w = -1;
private int h = -1;
public Orig_fil_mok Url_(String v) {url = v; return this;} private String url = null;
public Orig_fil_mok Size_(int w, int h) {this.w = w; this.h = h; return this;}
public Orig_fil_mok Init(int uid, String url, int w, int h) {
this.uid = uid;
this.url = url; this.w = w; this.h = h;
this.name = Io_url_.new_any_(url).NameAndExt();
this.ext_id = Xof_ext_.new_by_ttl_(Bry_.new_u8(name)).Id();
return this;
}
public void Test(Orig_fil_itm actl) {
if (actl == null) Tfds.Fail("actl itm is null");
if (w != -1) Tfds.Eq(w, actl.Fil_w());
if (h != -1) Tfds.Eq(h, actl.Fil_h());
if (url != null) Tfds.Eq(url, actl.Fil_url().Raw());
if (uid != -1) Tfds.Eq(uid, actl.Fil_uid());
if (ext_id != -1) Tfds.Eq(uid, actl.Fil_ext_id());
if (name != null) Tfds.Eq(name, String_.new_u8(actl.Fil_name()));
}
}

View File

@@ -0,0 +1,49 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.ios.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*;
public class Fs_root_fsdb_mgr implements Xof_fsdb_mgr, GfoInvkAble { // read images from file-system dir
private Xowe_wiki wiki; private Fs_root_wkr_fsdb fsdb_wkr;
public Fs_root_fsdb_mgr(Xowe_wiki wiki) {this.Init_by_wiki(wiki); fsdb_wkr = new Fs_root_wkr_fsdb(wiki);}
public void Init_by_wiki(Xow_wiki wiki) {this.wiki = (Xowe_wiki)wiki;}
public void Fsdb_search_by_list(List_adp itms, Xow_wiki wiki, Xoa_page page, Xog_js_wkr js_wkr) {
int itms_len = itms.Count();
for (int i = 0; i < itms_len; i++) {
Xof_fsdb_itm itm = (Xof_fsdb_itm)itms.Get_at(i);
if (fsdb_wkr.Find_file(itm))
Js_img_mgr.Update_img(page, js_wkr, itm);
}
}
private Io_url Xto_url(byte[] v) {
if (Op_sys.Cur().Tid_is_wnt())
v = Bry_.Replace(v, Byte_ascii.Slash, Byte_ascii.Backslash);
return Bry_fmtr_eval_mgr_.Eval_url(wiki.Appe().Url_cmd_eval(), v);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_root_dir_)) fsdb_wkr.Root_dir_(Xto_url(m.ReadBry("v")));
else if (ctx.Match(k, Invk_orig_dir_)) fsdb_wkr.Orig_dir_(Xto_url(m.ReadBry("v")));
else if (ctx.Match(k, Invk_thumb_dir_)) fsdb_wkr.Thumb_dir_(Xto_url(m.ReadBry("v")));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_root_dir_ = "root_dir_", Invk_orig_dir_ = "orig_dir_", Invk_thumb_dir_ = "thumb_dir_";
public Xof_bin_mgr Bin_mgr() {throw Exc_.new_unimplemented();}
public Fsm_mnt_mgr Mnt_mgr() {return null;}
public void Rls() {}
}

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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.files.repos.*; import gplx.fsdb.meta.*;
public class Fs_root_wkr_fsdb {
private Xowe_wiki wiki;
private Io_url orig_dir, thumb_dir;
private Fs_root_dir orig_dir_mgr = new Fs_root_dir();
private String_obj_ref tmp_resize_result = String_obj_ref.null_();
private Xof_img_size img_size = new Xof_img_size();
public Fs_root_wkr_fsdb(Xowe_wiki wiki) {this.wiki = wiki;}
public boolean Find_file(Xof_fsdb_itm fsdb_itm) {
byte[] orig_ttl = fsdb_itm.Orig_ttl();
Orig_fil_itm orig_itm = orig_dir_mgr.Get_by_ttl(orig_ttl);
if (orig_itm == Orig_fil_itm.Null) return false;
Io_url orig_url = orig_itm.Fil_url();
if (fsdb_itm.File_is_orig()) {
fsdb_itm.Html_size_(orig_itm.Fil_w(), orig_itm.Fil_h());
fsdb_itm.Html_view_url_(orig_url);
fsdb_itm.Html_orig_url_(orig_url);
return true;
}
else {
String thumb_rel = orig_url.GenRelUrl_orEmpty(orig_dir);
int upright_patch = wiki.File_mgr().Patch_upright();
img_size.Html_size_calc(fsdb_itm.Lnki_exec_tid(), fsdb_itm.Lnki_w(), fsdb_itm.Lnki_h(), fsdb_itm.Lnki_type(), upright_patch, fsdb_itm.Lnki_upright(), fsdb_itm.Orig_ext().Id(), orig_itm.Fil_w(), orig_itm.Fil_h(), Xof_img_size.Thumb_width_img);
int html_w = img_size.Html_w(), html_h = img_size.Html_h();
String thumb_name = Int_.Xto_str(html_w) + orig_url.Ext();
Io_url thumb_url = thumb_dir.GenSubFil_ary(thumb_rel + orig_url.Info().DirSpr(), thumb_name);
if (!Io_mgr.I.ExistsFil(thumb_url)) {
if (!wiki.Appe().File_mgr().Img_mgr().Wkr_resize_img().Resize_exec(orig_url, thumb_url, html_w, html_h, fsdb_itm.Orig_ext().Id(), tmp_resize_result))
return false;
}
fsdb_itm.Html_size_(html_w, html_h);
fsdb_itm.Html_view_url_(thumb_url);
fsdb_itm.Html_orig_url_(orig_url);
return true;
}
}
public void Root_dir_(Io_url v) {
Io_url root_dir = v;
orig_dir = root_dir.GenSubDir("orig");
thumb_dir = root_dir.GenSubDir("thumb");
orig_dir_mgr_init(orig_dir);
}
public void Orig_dir_(Io_url v) {
orig_dir = v;
orig_dir_mgr_init(orig_dir);
}
private void orig_dir_mgr_init(Io_url orig_dir) {
orig_dir_mgr.Init(orig_dir, new Orig_fil_tbl(), wiki.Appe().Usr_dlg(), wiki.Appe().File_mgr().Img_mgr().Wkr_query_img_size());
}
public void Thumb_dir_(Io_url v) {
thumb_dir = v;
}
}

View File

@@ -0,0 +1,46 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
public class Orig_fil_itm {
public Orig_fil_itm() {}
public Orig_fil_itm(int uid, byte[] name, int ext_id, int w, int h, byte[] dir_url) {
this.fil_uid = uid; this.fil_name = name; this.fil_ext_id = ext_id; this.fil_w = w; this.fil_h = h; this.fil_dir_url = dir_url;
}
public int Fil_uid() {return fil_uid;} private int fil_uid;
public byte[] Fil_name() {return fil_name;} private byte[] fil_name;
public int Fil_ext_id() {return fil_ext_id;} private int fil_ext_id;
public int Fil_w() {return fil_w;} private int fil_w;
public int Fil_h() {return fil_h;} private int fil_h;
public byte[] Fil_dir_url() {return fil_dir_url;} private byte[] fil_dir_url;
public Io_url Fil_url() {
if (fil_url == null) {
byte[] fil_url_bry = Bry_.Add(fil_dir_url, fil_name);
fil_url = Io_url_.new_fil_(String_.new_u8(fil_url_bry));
}
return fil_url;
} private Io_url fil_url;
public Orig_fil_itm Init_by_make(Io_url url, byte[] name_bry, int ext_id) {
this.fil_url = url;
this.fil_name = name_bry;
this.fil_dir_url = Bry_.new_u8(url.OwnerDir().Raw());
this.fil_ext_id = ext_id;
return this;
}
public Orig_fil_itm Init_by_size(int uid, int w, int h) {this.fil_uid = uid; this.fil_w = w; this.fil_h = h; return this;}
public static final Orig_fil_itm Null = null;
}

View File

@@ -0,0 +1,24 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
class Orig_fil_mgr {
private Ordered_hash hash = Ordered_hash_.new_bry_();
public boolean Has(byte[] lnki_ttl) {return hash.Has(lnki_ttl);}
public Orig_fil_itm Get_by_ttl(byte[] lnki_ttl) {return (Orig_fil_itm)hash.Get_by(lnki_ttl);}
public void Add(Orig_fil_itm fil) {hash.Add(fil.Fil_name(), fil);}
}

View File

@@ -0,0 +1,81 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.dbs.*;
public class Orig_fil_tbl implements RlsAble {
private String tbl_name = "orig_fil"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private String fld_uid, fld_name, fld_ext_id, fld_w, fld_h, fld_dir_url;
private Db_conn conn; private Db_stmt stmt_insert, stmt_select;
public void Conn_(Db_conn new_conn, boolean created, boolean schema_is_1) {
this.conn = new_conn; flds.Clear();
String fld_prefix = "";
if (schema_is_1) {
fld_prefix = "fil_";
}
fld_uid = flds.Add_int(fld_prefix + "uid");
fld_name = flds.Add_str(fld_prefix + "name", 1024);
fld_ext_id = flds.Add_int(fld_prefix + "ext_id");
fld_w = flds.Add_int(fld_prefix + "w");
fld_h = flds.Add_int(fld_prefix + "h");
fld_dir_url = flds.Add_str(fld_prefix + "dir_url", 1024); // NOTE: don't put dir in separate table; note that entire root_dir_wkr is not built to scale due to need for recursively loading all files
if (created) {
Db_meta_tbl meta = Db_meta_tbl.new_(tbl_name, flds
, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_name)
);
conn.Ddl_create_tbl(meta);
}
stmt_insert = stmt_select = null;
conn.Rls_reg(this);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select = Db_stmt_.Rls(stmt_select);
}
public Orig_fil_itm Select_itm(byte[] ttl) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_name);
Orig_fil_itm rv = Orig_fil_itm.Null;
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_name, ttl).Exec_select__rls_manual();
try {
if (rdr.Move_next())
rv = Load_itm(rdr);
return rv;
}
finally {rdr.Rls();}
}
private Orig_fil_itm Load_itm(Db_rdr rdr) {
return new Orig_fil_itm
( rdr.Read_int(fld_uid)
, rdr.Read_bry_by_str(fld_name)
, rdr.Read_int(fld_ext_id)
, rdr.Read_int(fld_w)
, rdr.Read_int(fld_h)
, rdr.Read_bry_by_str(fld_dir_url)
);
}
public void Insert(Orig_fil_itm fil_itm) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_int(fld_uid, fil_itm.Fil_uid())
.Val_bry_as_str(fld_name, fil_itm.Fil_name())
.Val_int(fld_ext_id, fil_itm.Fil_ext_id())
.Val_int(fld_w, fil_itm.Fil_w())
.Val_int(fld_h, fil_itm.Fil_h())
.Val_bry_as_str(fld_dir_url, fil_itm.Fil_dir_url())
.Exec_insert();
}
}

View File

@@ -0,0 +1,33 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__bmp_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_orig("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_thumb("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/220px.png", "220,200");
}
}

View File

@@ -0,0 +1,35 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__flac_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .flac is on page [[File:A.flac]]
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Rslt_orig_exists_y().Rslt_file_exists_n()); // check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2015-02-15
fxt.Test_fsys_exists_n("mem/root/common/orig/8/b/A.flac");
}
@Test public void Orig_app() { // .flac is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/8/b/A.flac");
}
}

View File

@@ -0,0 +1,35 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__oga_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .oga is on page [[File:A.oga]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately)
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/4/f/A.oga");
}
@Test public void Orig_app() { // .oga is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/4/f/A.oga");
}
}

View File

@@ -0,0 +1,37 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.xowa.files.bins.*;
public class Xof_file_ext__ogg_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
// @Test public void Video() { // disabled; .ogg will never be video; DATE:2014-02-02
// fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 440, 400));
// fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400)); // create a thumb at 440,400 (needed for preview of video)
// fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Rslt_orig_missing().Rslt_fsdb_xowa().Rslt_conv_n());
// fxt.Test_fsys("mem/root/common/thumb/4/2/A.ogg/440px.jpg", "440,400");
// Xof_fsdb_itm itm = fxt.Test_regy_pass("A.ogg");
// fxt.Test_itm_ext(itm, Xof_ext_.Id_ogv);// chk that file is now ogv
// }
@Test public void Audio() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 0, 0)); // audio has no size
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400)); // create a thumb but it should never be used
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_n().Rslt_file_resized_n());
}
}

View File

@@ -0,0 +1,36 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__ogv_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px.jpg", "440,400");
}
@Test public void Copy_orig_w_thumbtime() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400, 10));
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Lnki_time_(10).Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px-10.jpg", "440,400");
// fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130)); DELETE: not needed; tests if new A.png can be resized from existing; DATE:2015-03-03
}
}

View File

@@ -0,0 +1,29 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__pdf_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_thumb() {// PURPOSE: download pdf thumb only; [[File:Physical world.pdf|thumb]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.pdf", 2200, 1700));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.pdf", 220, 170));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.pdf", 220));
fxt.Test_fsys("mem/root/common/thumb/e/f/A.pdf/220px.jpg", "220,170");
}
}

View File

@@ -0,0 +1,63 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__png_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Copy_orig() {
fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_orig("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
}
@Test public void Copy_orig_w_width() { // PURPOSE: if not thumb, but width is specified; do not download orig and convert; EX: [[File:The Earth seen from Apollo 17.jpg|250px]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 220, 200));
fxt.Exec_get(Xof_exec_arg.new_("A.png", Xop_lnki_type.Id_null, 220, Xop_lnki_tkn.Height_null).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Make_thumb() {
fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Height_only() { // PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 12591, 1847));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 887, 130));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/887px.png", "887,130");
}
@Test public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 4884, 4932));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 150, 150));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", 150, Xop_lnki_tkn.Height_null));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/150px.png", "150,150");
}
@Test public void Upright() { // PURPOSE.fix: upright not working; EX: w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 1378, 1829));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 170, 226));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null).Lnki_upright_(Xof_img_size.Upright_default_marker));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/170px.png", "170,226");
}
}

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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__svg_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/220px.png", "220,200");
}
@Test public void Thumb_can_be_bigger_than_orig() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
fxt.Init__orig_w_fsdb__commons_orig("A.svg", 110, 100); // create orig of 110,100
fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg", 330).Rslt_file_exists_y()); // get 330
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/330px.png", "330,300");
}
}

View File

@@ -0,0 +1,35 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__unknown_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .bin is on page [[File:A.bin]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/f/b/A.bin");
}
@Test public void Orig_app() { // .bin is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/f/b/A.bin");
}
}

View File

@@ -0,0 +1,36 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.xowa.files.bins.*;
public class Xof_file_ext__wav_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .wav is on page [[File:A.wav]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/c/3/A.wav");
}
@Test public void Orig_app() { // .wav is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/c/3/A.wav");
}
}

View File

@@ -0,0 +1,35 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__xcf_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/220px.png", "220,200");
}
}

View File

@@ -0,0 +1,189 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.gui.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
import gplx.fsdb.data.*;
class Xof_file_fxt {
private Xoae_app app; private Xof_fsdb_mgr__sql fsdb_mgr; private Xowe_wiki wiki; private Xof_orig_mgr orig_mgr;
private final Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_(); private final Fsd_img_itm tmp_img = new Fsd_img_itm();
public void Rls() {}
public void Reset() {
Io_mgr.I.InitEngine_mem(); // NOTE: files are downloaded to mem_engine, regardless of Db being mem or sqlite; always reset
Io_url root_url = Xoa_test_.Url_root();
Xoa_test_.Db_init(root_url);
app = Xoa_app_fxt.app_(Op_sys.Cur().Os_name(), root_url);
wiki = Xoa_app_fxt.wiki_tst_(app);
wiki.File__fsdb_mode().Tid_v2_bld_y_();
this.fsdb_mgr = (Xof_fsdb_mgr__sql)wiki.File_mgr().Fsdb_mgr();
this.orig_mgr = wiki.File__orig_mgr();
Xof_repo_fxt.Repos_init(app.File_mgr(), true, wiki);
Xowe_wiki_bldr.Create(wiki, 1, "dump.xml");
Xowd_db_file text_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xowd_db_file_.Tid_text); text_db.Tbl__text().Create_tbl();
Fsdb_db_mgr__v2 fsdb_core = Fsdb_db_mgr__v2_bldr.I.Get_or_make(wiki, Bool_.Y);
fsdb_mgr.Mnt_mgr().Ctor_by_load(fsdb_core);
fsdb_mgr.Mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__make("temp.xowa");
wiki.File_mgr().Init_file_mgr_by_load(wiki);
fsdb_mgr.Bin_mgr().Wkrs__del(Xof_bin_wkr_.Key_http_wmf); // never use http_wmf wkr for these tests
Xof_bin_wkr__fsdb_sql bin_wkr_fsdb = (Xof_bin_wkr__fsdb_sql)fsdb_mgr.Bin_mgr().Wkrs__get_or_null(Xof_bin_wkr_.Key_fsdb_wiki);
fsdb_mgr.Bin_mgr().Resizer_(Xof_img_wkr_resize_img_mok._);
bin_wkr_fsdb.Resize_allowed_(true);
}
public void Init__orig_w_fsdb__commons_orig(String ttl, int w, int h) {
this.Init_fsdb_db(Xof_fsdb_arg.new_comm(Bool_.N, ttl, w, h));
this.Init_orig_db(Xof_orig_arg.new_comm(ttl, w, h));
}
public void Init_orig_db(Xof_orig_arg arg) {
orig_mgr.Insert(arg.Repo(), arg.Page(), Xof_ext_.new_by_ttl_(arg.Page()).Id(), arg.W(), arg.H(), arg.Redirect());
}
public void Init_fsdb_db(Xof_fsdb_arg arg) {
Fsm_mnt_itm mnt_itm = fsdb_mgr.Mnt_mgr().Mnts__get_main();
Fsm_atr_fil atr_fil = mnt_itm.Atr_mgr().Db__core();
Fsm_bin_fil bin_fil = mnt_itm.Bin_mgr().Dbs__get_nth();
if (arg.Is_thumb())
mnt_itm.Insert_thm(tmp_thm, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Time(), arg.Page(), arg.Bin().length, gplx.ios.Io_stream_rdr_.mem_(arg.Bin()));
else
mnt_itm.Insert_img(tmp_img, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Bin().length, gplx.ios.Io_stream_rdr_.mem_(arg.Bin()));
}
public void Exec_get(Xof_exec_arg arg) {
byte[] ttl_bry = arg.Ttl();
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Init_at_lnki(arg.Exec_tid(), wiki.Domain_itm().Abrv_xo(), ttl_bry, arg.Lnki_type(), arg.Lnki_upright(), arg.Lnki_w(), arg.Lnki_h(), arg.Lnki_time(), Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
List_adp itms_list = List_adp_.new_(); itms_list.Add(itm);
orig_mgr.Find_by_list(Ordered_hash_.new_bry_(), itms_list, Xof_exec_tid.Tid_wiki_page);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_main, ttl_bry);
Xoae_page page = Xoae_page.new_(wiki, ttl);
fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
if (arg.Rslt_orig_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_orig_exists() == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");
if (arg.Rslt_file_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_file_exists() == Bool_.Y_byte, itm.File_exists(), "file_exists");
if (arg.Rslt_file_resized() != Bool_.__byte) Tfds.Eq(arg.Rslt_file_resized() == Bool_.Y_byte, itm.File_resized(), "file_resize");
}
public void Test_fsys_exists_y(String url) {Test_fsys_exists(url, Bool_.Y);}
public void Test_fsys_exists_n(String url) {Test_fsys_exists(url, Bool_.N);}
public void Test_fsys_exists(String url, boolean expd) {Tfds.Eq(expd, Io_mgr.I.ExistsFil(Io_url_.new_any_(url)));}
public void Test_fsys(String url, String expd_bin) {Tfds.Eq(expd_bin, Io_mgr.I.LoadFilStr(url));}
}
class Xof_repo_fxt {
public static void Repos_init(Xof_file_mgr file_mgr, boolean src_repo_is_wmf, Xowe_wiki wiki) {
byte[] src_commons = Bry_.new_a7("src_commons");
byte[] src_en_wiki = Bry_.new_a7("src_en_wiki");
byte[] trg_commons = Bry_.new_a7("trg_commons");
byte[] trg_en_wiki = Bry_.new_a7("trg_en_wiki");
Ini_repo_add(file_mgr, src_commons, "mem/src/commons.wikimedia.org/", Xow_domain_.Domain_str_commons, false);
Ini_repo_add(file_mgr, src_en_wiki, "mem/src/en.wikipedia.org/" , Xow_domain_.Domain_str_enwiki, false);
Ini_repo_add(file_mgr, trg_commons, "mem/root/common/", Xow_domain_.Domain_str_commons, true).Primary_(true);
Ini_repo_add(file_mgr, trg_en_wiki, "mem/root/enwiki/", Xow_domain_.Domain_str_enwiki, true).Primary_(true);
Xowe_repo_mgr wiki_repo_mgr = wiki.File_mgr().Repo_mgr();
Xof_repo_pair pair = null;
pair = wiki_repo_mgr.Add_repo(src_commons, trg_commons);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf).Tarball_(!src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
pair = wiki_repo_mgr.Add_repo(src_en_wiki, trg_en_wiki);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
}
private static Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) {
return file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
}
}
class Xof_orig_arg {
Xof_orig_arg(byte repo, byte[] page, int w, int h, byte[] redirect) {this.repo = repo; this.page = page; this.w = w; this.h = h; this.redirect = redirect;}
public byte Repo() {return repo;} private final byte repo;
public byte[] Page() {return page;} private final byte[] page;
public int W() {return w;} private final int w;
public int H() {return h;} private final int h;
public byte[] Redirect() {return redirect;} private final byte[] redirect;
public static Xof_orig_arg new_comm_file(String page) {return new_(Bool_.Y, page, Xof_img_size.Size_null, Xof_img_size.Size_null);}
public static Xof_orig_arg new_comm(String page, int w, int h) {return new_(Bool_.Y, page, w, h);}
public static Xof_orig_arg new_wiki(String page, int w, int h) {return new_(Bool_.N, page, w, h);}
public static Xof_orig_arg new_wiki_redirect(String src, String trg) {return new_(Bool_.N, src, 440, 400, trg);}
public static Xof_orig_arg new_comm_redirect(String src, String trg) {return new_(Bool_.Y, src, 440, 400, trg);}
private static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h) {return new_(repo_is_commons, page, w, h, null);}
public static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h, String redirect_str) {
byte repo = repo_is_commons ? Xof_repo_itm_.Repo_remote : Xof_repo_itm_.Repo_local;
byte[] redirect = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
return new Xof_orig_arg(repo, Bry_.new_u8(page), w, h, redirect);
}
}
class Xof_fsdb_arg {
Xof_fsdb_arg(byte[] wiki, byte[] ttl, boolean is_thumb, int ext, int w, int h, int time, byte[] bin) {
this.wiki = wiki; this.ttl = ttl; this.is_thumb = is_thumb; this.w = w; this.h = h; this.time = time; this.ext = ext; this.bin = bin;
}
public byte[] Wiki() {return wiki;} private final byte[] wiki;
public byte[] Ttl() {return ttl;} private final byte[] ttl;
public int Ext() {return ext;} private final int ext;
public boolean Is_thumb() {return is_thumb;} private final boolean is_thumb;
public int W() {return w;} private final int w;
public int H() {return h;} private final int h;
public double Time() {return time;} private final double time;
public int Page() {return page;} private final int page = Xof_lnki_page.Null;
public byte[] Bin() {return bin;} private final byte[] bin;
public DateAdp Modified() {return modified;} private final DateAdp modified = Fsd_thm_tbl.Modified_null;
public String Hash() {return hash;} private final String hash = Fsd_thm_tbl.Hash_null;
public static Xof_fsdb_arg new_comm_file(String ttl) {return new_(Xow_domain_.Domain_bry_commons, Bool_.N, ttl, Xof_img_size.Null, Xof_img_size.Null, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl) {return new_(Xow_domain_.Domain_bry_commons, Bool_.Y, ttl, W_default, H_default, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h) {return new_(Xow_domain_.Domain_bry_commons, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h, int s) {return new_(Xow_domain_.Domain_bry_commons, Bool_.Y, ttl, w, h, s);}
public static Xof_fsdb_arg new_comm_orig(String ttl, int w, int h) {return new_(Xow_domain_.Domain_bry_commons, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm(boolean thumb, String ttl, int w, int h) {return new_(Xow_domain_.Domain_bry_commons, thumb, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_wiki_thumb(String ttl, int w, int h) {return new_(Xow_domain_.Domain_bry_enwiki, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_wiki_orig(String ttl, int w, int h) {return new_(Xow_domain_.Domain_bry_enwiki, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_(byte[] wiki, boolean is_thumb, String ttl_str, int w, int h, int time) {
byte[] ttl = Bry_.new_u8(ttl_str);
int ext = Xof_ext_.new_by_ttl_(ttl).Id();
String bin_str = ext == Xof_ext_.Id_svg ? file_svg_(w, h) : file_img_(w, h);
byte[] bin = Bry_.new_a7(bin_str);
return new Xof_fsdb_arg(wiki, ttl, is_thumb, ext, w, h, time, bin);
}
private static final int W_default = 220, H_default = 200;
private static String file_img_(int w, int h) {return String_.Format("{0},{1}", w, h);}
private static String file_svg_(int w, int h) {return String_.Format("<svg width=\"{0}\" height=\"{1}\" />", w, h);}
}
class Xof_exec_arg {
public byte[] Ttl() {return ttl;} private byte[] ttl;
public byte Lnki_type() {return lnki_type;} private byte lnki_type = Xop_lnki_type.Id_thumb;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h = Xop_lnki_tkn.Height_null;
public double Lnki_upright() {return lnki_upright;} public Xof_exec_arg Lnki_upright_(double v) {lnki_upright = v; return this;} private double lnki_upright = Xop_lnki_tkn.Upright_null;
public int Lnki_time() {return lnki_time;} public Xof_exec_arg Lnki_time_(int v) {lnki_time = v; return this;} private int lnki_time = Xof_lnki_time.Null_as_int;
public int Lnki_page() {return lnki_page;} public Xof_exec_arg Lnki_page_(int v) {lnki_page = v; return this;} private int lnki_page = Xof_lnki_page.Null;
public int Exec_tid() {return exec_tid;} public Xof_exec_arg Exec_tid_(int v) {exec_tid = v; return this;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
public byte Rslt_orig_exists() {return rslt_orig_exists;} private byte rslt_orig_exists = Bool_.__byte;
public byte Rslt_file_exists() {return rslt_file_exists;} private byte rslt_file_exists = Bool_.__byte;
public byte Rslt_file_resized() {return rslt_file_resized;} private byte rslt_file_resized = Bool_.__byte;
public boolean Lnki_type_is_thumb() {return Xop_lnki_type.Id_defaults_to_thumb(lnki_type);}
public Xof_exec_arg Rslt_orig_exists_n() {rslt_orig_exists = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_orig_exists_y() {rslt_orig_exists = Bool_.Y_byte; return this;}
public Xof_exec_arg Rslt_file_exists_n() {rslt_file_exists = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_file_exists_y() {rslt_file_exists = Bool_.Y_byte; return this;}
public Xof_exec_arg Rslt_file_resized_n() {rslt_file_resized = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_file_resized_y() {rslt_file_resized = Bool_.Y_byte; return this;}
public static Xof_exec_arg new_thumb(String ttl) {return new_(ttl, Xop_lnki_type.Id_thumb, 220, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_thumb(String ttl, int w) {return new_(ttl, Xop_lnki_type.Id_thumb, w, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_thumb(String ttl, int w, int h) {return new_(ttl, Xop_lnki_type.Id_thumb, w, h);}
public static Xof_exec_arg new_orig(String ttl) {return new_(ttl, Xop_lnki_type.Id_null, Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_(String ttl, byte type, int w, int h) {
Xof_exec_arg rv = new Xof_exec_arg();
rv.ttl = Bry_.new_u8(ttl);
rv.lnki_type = type;
rv.lnki_w = w;
rv.lnki_h = h;
return rv;
}
}

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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_redirect_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Same_wiki_orig_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
fxt.Test_fsys("mem/root/enwiki/orig/7/0/A.png", "440,400");
}
@Test public void Same_wiki_thumb_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_thumb("A.png", 220, 200));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y());
fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Same_wiki_thumb_make() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Diff_wiki_orig_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_comm_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
}
// @Test public void Cross_wiki() {
// fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
// fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
// fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_fsdb_xowa());
// fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
// fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
// fxt .ini_page_create_commons ("File:A.png");
// fxt .Lnki_orig_("B.png")
// .Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
// .Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
// , fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv" , "B.png|y|A.png|1?900,800|")
// );
// fxt.tst();
// }
}