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-03-08 21:27:59 -04:00
parent d279c70606
commit 80b9928b5c
259 changed files with 2841 additions and 2060 deletions

View File

@@ -112,8 +112,8 @@ public class Bit_ {
int[] rv = new int[Pow_ary_date_short.length];
Xto_date_short_int_ary(rv, v);
return DateAdp_.seg_(rv);
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1};
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6
private static final int[] Base2_ary = new int[]
{ 1, 2, 4, 8, 16, 32, 64, 128
, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768

View File

@@ -28,7 +28,7 @@ class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
Gfo_usr_dlg_._.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Url().Xto_api());
Schema_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"));
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
Db_stmt stmt = Db_stmt_.new_select_as_rdr(conn, qry);
Db_rdr rdr = stmt.Exec_select_as_rdr();
while (rdr.Move_next()) {

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_dir_itm {
public Fsd_dir_itm(int id, int owner, String name) {this.id = id; this.owner = owner; this.name = name;}
public int Id() {return id;} public Fsd_dir_itm Id_(int v) {id = v; return this;} private int id;
public int Owner() {return owner;} public Fsd_dir_itm Owner_(int v) {owner = v; return this;} private int owner;
public String Name() {return name;} public Fsd_dir_itm Name_(String v) {name = v; return this;} private String name;
public int Id() {return id;} private final int id;
public int Owner() {return owner;} private final int owner;
public String Name() {return name;} private final String name;
public static final Fsd_dir_itm Null = new Fsd_dir_itm(0, 0, "");
}

View File

@@ -17,13 +17,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_fil_itm {
public int Id() {return id;} public Fsd_fil_itm Id_(int v) {id = v; return this;} private int id;
public int Owner() {return owner;} public Fsd_fil_itm Owner_(int v) {owner = v; return this;} private int owner;
public int Ext_id() {return ext_id;} public Fsd_fil_itm Ext_id_(int v) {ext_id = v; return this;} private int ext_id;
public String Name() {return name;} public Fsd_fil_itm Name_(String v) {name = v; return this;} private String name;
public int Db_bin_id() {return bin_db_id;} public Fsd_fil_itm Db_bin_id_(int v) {bin_db_id = v; return this;} private int bin_db_id;
public int Id() {return id;} private int id;
public int Owner() {return owner;} private int owner;
public int Ext_id() {return ext_id;} private int ext_id;
public String Name() {return name;} private String name;
public int Db_bin_id() {return bin_db_id;} private int bin_db_id;
public int Mnt_id() {return mnt_id;} public Fsd_fil_itm Mnt_id_(int v) {mnt_id = v; return this;} private int mnt_id;
public Fsd_fil_itm Init(int id, int owner, int ext_id, String name, int bin_db_id) {this.id = id; this.owner = owner; this.ext_id = ext_id; this.name = name; this.bin_db_id = bin_db_id; return this;}
public void Init_for_insert(int bin_db_id, int dir_id, int fil_id) {
this.bin_db_id = bin_db_id; this.owner = dir_id; this.id = fil_id;
}
public static final int Null_id = 0;
public static final Fsd_fil_itm Null = new Fsd_fil_itm().Init(Null_id, 0, 0, "", Fsd_bin_tbl.Null_db_bin_id);
}

View File

@@ -78,7 +78,7 @@ public class Fsd_fil_tbl {
}
public Fsd_fil_itm Select_itm_by_name(int dir_id, String fil_name) {
if (stmt_select_by_name == null) {
Db_qry_select qry = Db_qry_select.new_().From_(tbl_name).Cols_(flds.To_str_ary()).Where_(Db_crt_.eq_many_(fld_owner_id, fld_name)).Indexed_by_(Idx_owner);
Db_qry__select_cmd qry = Db_qry__select_cmd.new_().From_(tbl_name).Cols_(flds.To_str_ary()).Where_(Db_crt_.eq_many_(fld_owner_id, fld_name)).Indexed_by_(Idx_owner);
stmt_select_by_name = conn.Rls_reg(conn.Stmt_new(qry));
}
Db_rdr rdr = Db_rdr_.Null;

View File

@@ -17,25 +17,56 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_thm_itm {
protected Fsd_thm_itm() {}
public void Ctor(int id, int owner_id, int w, double time, int page, int h, long size, String modified, String hash) {
this.id = id; this.owner_id = owner_id; this.width = w; this.thumbtime = time; this.page = page; this.height = h; this.size = size; this.modified = modified; this.hash = hash;
public int Id() {return id;} private int id;
public int Owner_id() {return owner_id;} private int owner_id;
public int W() {return w;} private int w;
public double Time() {return time;} private double time;
public int Page() {return page;} private int page;
public int H() {return h;} private int h;
public long Size() {return size;} private long size;
public String Modified() {return modified;} private String modified;
public String Hash() {return hash;} private String hash;
public int Dir_id() {return dir_id;} private int dir_id;
public int Db_bin_id() {return bin_db_id;} private int bin_db_id;
public int Mnt_id() {return mnt_id;} private int mnt_id;
public int Req_w() {return req_w;} private int req_w;
public double Req_time() {return req_time;} private double req_time;
public int Req_page() {return req_page;} private int req_page;
public void Init_by_load(int bin_db_id, int id, int owner_id, int w, double time, int page, int h, long size, String modified, String hash) {
this.bin_db_id = bin_db_id; this.id = id; this.owner_id = owner_id;
this.w = w; this.time = time; this.page = page; this.h = h; this.size = size; this.modified = modified; this.hash = hash;
}
public int Id() {return id;} public Fsd_thm_itm Id_(int v) {id = v; return this;} private int id;
public Fsd_fil_itm Owner() {return owner;} public Fsd_thm_itm Owner_(Fsd_fil_itm v) {owner = v; return this;} private Fsd_fil_itm owner = Fsd_fil_itm.Null;
public int Owner_id() {return owner_id;} public Fsd_thm_itm Owner_id_(int v) {owner_id = v; return this;} private int owner_id;
public int Width() {return width;} public Fsd_thm_itm Width_(int v) {width = v; return this;} private int width;
public double Thumbtime() {return thumbtime;} public Fsd_thm_itm Thumbtime_(double v) {thumbtime = v; return this;} private double thumbtime;
public int Page() {return page;} public Fsd_thm_itm Page_(int v) {page = v; return this;} private int page;
public int Height() {return height;} public Fsd_thm_itm Height_(int v) {height = v; return this;} private int height;
public long Size() {return size;} public Fsd_thm_itm Size_(long v) {size = v; return this;} private long size;
public String Modified() {return modified;} public Fsd_thm_itm Modified_(String v) {modified = v; return this;} private String modified;
public String Hash() {return hash;} public Fsd_thm_itm Hash_(String v) {hash = v; return this;} private String hash;
public int Dir_id() {return dir_id;} public Fsd_thm_itm Dir_id_(int v) {dir_id = v; return this;} private int dir_id;
public int Db_bin_id() {return bin_db_id;} public Fsd_thm_itm Db_bin_id_(int v) {bin_db_id = v; return this;} private int bin_db_id;
public int Mnt_id() {return mnt_id;} public Fsd_thm_itm Mnt_id_(int v) {mnt_id = v; return this;} private int mnt_id;
public static Fsd_thm_itm new_() {return new Fsd_thm_itm();} // NOTE: Owner is null by default
public static Fsd_thm_itm load_() {return new Fsd_thm_itm().Owner_(new Fsd_fil_itm());} // NOTE: Owner is new'd b/c load will use owner.Ext_id
public void Init_by_insert(int bin_db_id, int dir_id, int fil_id, int thm_id) {this.bin_db_id = bin_db_id; this.dir_id = dir_id; this.owner_id = fil_id; this.id = thm_id;}
public void Init_by_req(int w, double time, int page) {this.w = w; this.time = time; this.page = page;}
public void Init_by_match(Fsd_thm_itm comp) {
this.req_w = w;
this.req_time = time;
this.req_page = page;
this.id = comp.id;
this.owner_id = comp.owner_id;
this.w = comp.w;
this.time = comp.time;
this.page = comp.page;
this.h = comp.h;
this.size = comp.size;
this.modified = comp.modified;
this.hash = comp.hash;
this.dir_id = comp.dir_id;
this.bin_db_id = comp.bin_db_id;
this.mnt_id = comp.mnt_id;
}
public Fsd_thm_itm Mnt_id_(int v) {mnt_id = v; return this;}
public static final Fsd_thm_itm Null = new Fsd_thm_itm();
public static final Fsd_thm_itm[] Ary_empty = new Fsd_thm_itm[0];
public static Fsd_thm_itm new_() {return new Fsd_thm_itm();} Fsd_thm_itm() {}
}
class Fsdb_thm_itm_sorter implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Fsd_thm_itm lhs = (Fsd_thm_itm)lhsObj;
Fsd_thm_itm rhs = (Fsd_thm_itm)rhsObj;
int comp = Int_.Compare (lhs.W() , rhs.W()); if (comp != CompareAble_.Same) return -comp; // sort by decreasing width
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAble_.Same) return comp; // sort by increasing time
return Int_.Compare (lhs.Page() , rhs.Page()); // sort by increasing page
}
public static final Fsdb_thm_itm_sorter I = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
}

View File

@@ -75,11 +75,11 @@ public class Fsd_thm_tbl {
.Val_int(fld_w, width)
.Val_int(fld_h, height);
if (this.Schema_thm_page()) {
stmt_insert.Val_double (fld_time, gplx.xowa.files.Xof_doc_thumb.Db_save_double(thumbtime));
stmt_insert.Val_int (fld_page, gplx.xowa.files.Xof_doc_page.Db_save_int(page));
stmt_insert.Val_double (fld_time, gplx.xowa.files.Xof_lnki_time.Db_save_double(thumbtime));
stmt_insert.Val_int (fld_page, gplx.xowa.files.Xof_lnki_page.Db_save_int(page));
}
else
stmt_insert.Val_int (fld_thumbtime, gplx.xowa.files.Xof_doc_thumb.Db_save_int(thumbtime));
stmt_insert.Val_int (fld_thumbtime, gplx.xowa.files.Xof_lnki_time.Db_save_int(thumbtime));
stmt_insert
.Val_int(fld_bin_db_id, bin_db_id)
.Val_long(fld_size, size)
@@ -88,7 +88,7 @@ public class Fsd_thm_tbl {
.Exec_insert();
}
private Db_stmt Select_by_fil_w_stmt() {
Db_qry_select qry = Db_qry_.select_().From_(tbl_name).Cols_all_();
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Cols_all_();
gplx.core.criterias.Criteria crt
= this.Schema_thm_page()
? Db_crt_.eq_many_(fld_owner_id, fld_w, fld_time, fld_page)
@@ -103,14 +103,14 @@ public class Fsd_thm_tbl {
try {
stmt_select_by_fil_w.Clear()
.Crt_int(fld_owner_id, owner_id)
.Crt_int(fld_w, thm.Width())
.Crt_int(fld_w, thm.W())
;
if (this.Schema_thm_page()) {
stmt_select_by_fil_w.Crt_double(fld_time, gplx.xowa.files.Xof_doc_thumb.Db_save_double(thm.Thumbtime()));
stmt_select_by_fil_w.Crt_int(fld_page, gplx.xowa.files.Xof_doc_page.Db_save_int(thm.Page()));
stmt_select_by_fil_w.Crt_double(fld_time, gplx.xowa.files.Xof_lnki_time.Db_save_double(thm.Time()));
stmt_select_by_fil_w.Crt_int(fld_page, gplx.xowa.files.Xof_lnki_page.Db_save_int(thm.Page()));
}
else {
stmt_select_by_fil_w.Crt_int(fld_time, gplx.xowa.files.Xof_doc_thumb.Db_save_int(thm.Thumbtime()));
stmt_select_by_fil_w.Crt_int(fld_time, gplx.xowa.files.Xof_lnki_time.Db_save_int(thm.Time()));
}
rdr = stmt_select_by_fil_w.Exec_select_as_rdr();
return rdr.Move_next()
@@ -119,6 +119,21 @@ public class Fsd_thm_tbl {
}
finally {rdr.Rls();}
}
public boolean Select_itm_by_fil_width2(int owner_id, Fsd_thm_itm thm) {
if (stmt_select_by_fil_w == null) stmt_select_by_fil_w = conn.Rls_reg(conn.Stmt_select(tbl_name, flds, fld_owner_id));
Db_rdr rdr = Db_rdr_.Null;
try {
ListAdp list = ListAdp_.new_();
rdr = stmt_select_by_fil_w.Clear().Crt_int(fld_owner_id, thm.Owner_id()).Exec_select_as_rdr();
while (rdr.Move_next()) {
Fsd_thm_itm itm = Fsd_thm_itm.new_();
Ctor_by_load(itm, rdr, this.Schema_thm_page());
list.Add(itm);
}
return Match_nearest(list, thm, schema_thm_page);
}
finally {rdr.Rls();}
}
private boolean Ctor_by_load(Fsd_thm_itm itm, Db_rdr rdr, boolean schema_thm_page) {
int id = rdr.Read_int(fld_id);
int owner_id = rdr.Read_int(fld_owner_id);
@@ -131,17 +146,39 @@ public class Fsd_thm_tbl {
double time = 0;
int page = 0;
if (schema_thm_page) {
time = gplx.xowa.files.Xof_doc_thumb.Db_load_double(rdr, fld_time);
page = gplx.xowa.files.Xof_doc_page.Db_load_int(rdr, fld_page);
time = gplx.xowa.files.Xof_lnki_time.Db_load_double(rdr, fld_time);
page = gplx.xowa.files.Xof_lnki_page.Db_load_int(rdr, fld_page);
}
else {
time = gplx.xowa.files.Xof_doc_thumb.Db_load_int(rdr, fld_thumbtime);
page = gplx.xowa.files.Xof_doc_page.Null;
time = gplx.xowa.files.Xof_lnki_time.Db_load_int(rdr, fld_thumbtime);
page = gplx.xowa.files.Xof_lnki_page.Null;
}
itm.Ctor(id, owner_id, width, time, page, height, size, modified, hash);
itm.Db_bin_id_(bin_db_id);
itm.Init_by_load(bin_db_id, id, owner_id, width, time, page, height, size, modified, hash);
return true;
}
public static final DateAdp Modified_null = null;
public static final String Hash_null = "";
public static boolean Match_nearest(ListAdp list, Fsd_thm_itm thm, boolean schema_thm_page) {
int len = list.Count(); if (len == 0) return Bool_.N;
list.SortBy(Fsdb_thm_itm_sorter.I);
int thm_w = thm.W(), thm_page = thm.Page(); double thm_time = thm.Time();
Fsd_thm_itm max = null;
for (int i = 0; i < len; ++i) {
Fsd_thm_itm comp = (Fsd_thm_itm)list.FetchAt(i);
int comp_w = comp.W();
int comp_page = schema_thm_page ? comp.Page() : thm_page;
if ( thm_w == comp_w
&& thm_time == comp.Time()
&& thm_page == comp_page
) { // exact match
thm.Init_by_match(comp);
return Bool_.Y;
}
if (comp_w > thm_w) max = comp;
else break;
}
if (max == null) return Bool_.N;
thm.Init_by_match(max);
return Bool_.Y;
}
}

View File

@@ -0,0 +1,58 @@
/*
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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import org.junit.*;
public class Fsd_thm_tbl_tst {
@Before public void init() {fxt.Clear();} private Fsd_thm_tbl_fxt fxt = new Fsd_thm_tbl_fxt();
@Test public void Basic() {
fxt.Init_list(fxt.Make(100), fxt.Make(200), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(400), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(200), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(100), fxt.Make(100));
fxt.Test_match_nearest_itm(fxt.Make(350), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(150), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(500), Fsd_thm_itm.Null);
}
@Test public void Empty() {
fxt.Init_list(); // no items
fxt.Test_match_nearest_itm(fxt.Make(100), Fsd_thm_itm.Null);
}
}
class Fsd_thm_tbl_fxt {
private final ListAdp list = ListAdp_.new_();
public void Clear() {list.Clear();}
public Fsd_thm_itm Make(int w) {
double time = gplx.xowa.files.Xof_lnki_time.Null;
int page = gplx.xowa.files.Xof_lnki_page.Null;
Fsd_thm_itm rv = Fsd_thm_itm.new_();
rv.Init_by_req(w, time, page);
return rv;
}
public void Init_list(Fsd_thm_itm... ary) {list.AddMany((Object[])ary);}
public void Test_match_nearest_itm(Fsd_thm_itm req, Fsd_thm_itm expd) {
Fsd_thm_tbl.Match_nearest(list, req, Bool_.Y);
if (expd == Fsd_thm_itm.Null) {
Tfds.Eq(req.Req_w(), 0);
}
else {
Tfds.Eq(expd.W(), req.W());
Tfds.Eq(expd.Time(), req.Time());
Tfds.Eq(expd.Page(), req.Page());
}
}
}

View File

@@ -42,14 +42,12 @@ public class Fsm_abc_mgr implements RlsAble {
}
public void Fil_insert(Fsd_fil_itm rv , byte[] dir, byte[] fil, int ext_id, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
int bin_db_id = bin_mgr.Get_id_for_insert(bin_len);
rv.Db_bin_id_(bin_db_id);
int fil_id = atr_mgr.Fil_insert(rv, dir, fil, ext_id, modified, hash, bin_db_id, bin_len, bin_rdr);
bin_len = bin_mgr.Insert(bin_db_id, fil_id, Fsd_bin_tbl.Owner_tid_fil, bin_len, bin_rdr);
bin_mgr.Increment(bin_len);
}
public void Thm_insert(Fsd_thm_itm rv, byte[] dir, byte[] fil, int ext_id, int w, int h, double thumbtime, int page, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
int bin_db_id = bin_mgr.Get_id_for_insert(bin_len);
rv.Db_bin_id_(bin_db_id);
int thm_id = atr_mgr.Thm_insert(rv, dir, fil, ext_id, w, h, thumbtime, page, modified, hash, bin_db_id, bin_len, bin_rdr);
bin_len = bin_mgr.Insert(bin_db_id, thm_id, Fsd_bin_tbl.Owner_tid_thm, bin_len, bin_rdr);
bin_mgr.Increment(bin_len);

View File

@@ -73,7 +73,7 @@ public class Fsm_atr_fil implements RlsAble {
public int Fil_insert(Fsd_fil_itm rv, String dir, String fil, int ext_id, DateAdp modified, String hash, int bin_db_id, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
int dir_id = Dir_id__get_or_insert(dir);
int fil_id = Fil_id__get_or_insert(Xtn_tid_none, dir_id, fil, ext_id, modified, hash, bin_db_id, bin_len);
rv.Id_(fil_id).Owner_(dir_id);
rv.Init_for_insert(bin_db_id, dir_id, fil_id);
return fil_id;
}
public int Img_insert(Fsd_img_itm rv, String dir, String fil, int ext_id, int img_w, int img_h, DateAdp modified, String hash, int bin_db_id, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
@@ -87,7 +87,7 @@ public class Fsm_atr_fil implements RlsAble {
int fil_id = Fil_id__get_or_insert(Xtn_tid_thm, dir_id, fil, ext_id, modified, hash, Fsd_bin_tbl.Null_db_bin_id, Fsd_bin_tbl.Null_size); // NOTE: bin_db_id must be set to NULL
int thm_id = abc_mgr.Next_id();
tbl_thm.Insert(thm_id, fil_id, thm_w, thm_h, thumbtime, page, bin_db_id, bin_len, modified, hash);
rv.Id_(thm_id).Owner_id_(fil_id).Dir_id_(dir_id);
rv.Init_by_insert(bin_db_id, dir_id, fil_id, thm_id);
return thm_id;
}
public static Fsm_atr_fil make_(Fsm_abc_mgr abc_mgr, int id, Io_url url, String path_bgn) {

View File

@@ -40,7 +40,7 @@ public class Fsm_bin_tbl {
}
public Fsm_bin_fil[] Select_all(Io_url dir) {
ListAdp rv = ListAdp_.new_();
Db_qry qry = Db_qry_select.new_().From_(tbl_name).Cols_all_().Where_(Db_crt_.eq_many_(Db_meta_fld.Ary_empy)).OrderBy_asc_(fld_uid);
Db_qry qry = Db_qry__select_cmd.new_().From_(tbl_name).Cols_all_().Where_(Db_crt_.eq_many_(Db_meta_fld.Ary_empy)).OrderBy_asc_(fld_uid);
Db_rdr rdr = Db_rdr_.Null;
try {
rdr = conn.Stmt_new(qry).Clear().Exec_select_as_rdr();

View File

@@ -76,12 +76,15 @@ public class Fsm_mnt_mgr implements GfoInvkAble {
return false;
}
public int Insert_to_mnt() {return insert_to_mnt;} public Fsm_mnt_mgr Insert_to_mnt_(int v) {insert_to_mnt = v; return this;} private int insert_to_mnt = Mnt_idx_user;
public void Fil_insert(Fsd_fil_itm rv , byte[] dir, byte[] fil, int ext_id, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
public void Fil_insert(byte[] dir, byte[] fil, int ext_id, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {Fil_insert(new Fsd_fil_itm(), dir, fil, ext_id, modified, hash, bin_len, bin_rdr);}
public void Fil_insert(Fsd_fil_itm rv, byte[] dir, byte[] fil, int ext_id, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
ary[insert_to_mnt].Fil_insert(rv, dir, fil, ext_id, modified, hash, bin_len, bin_rdr);
}
public void Thm_insert(Fsd_thm_itm rv, byte[] dir, byte[] fil, int ext_id, int w, int h, double thumbtime, int page, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
ary[insert_to_mnt].Thm_insert(rv, dir, fil, ext_id, w, h, thumbtime, page, modified, hash, bin_len, bin_rdr);
public void Thm_insert(byte[] dir, byte[] fil, int ext_id, int w, int h, double time, int page, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {Thm_insert(Fsd_thm_itm.new_(), dir, fil, ext_id, w, h, time, page, modified, hash, bin_len, bin_rdr);}
public void Thm_insert(Fsd_thm_itm rv, byte[] dir, byte[] fil, int ext_id, int w, int h, double time, int page, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
ary[insert_to_mnt].Thm_insert(rv, dir, fil, ext_id, w, h, time, page, modified, hash, bin_len, bin_rdr);
}
public void Img_insert(byte[] dir, byte[] fil, int ext_id, int img_w, int img_h, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {Img_insert(new Fsd_img_itm(), dir, fil, ext_id, img_w, img_h, modified, hash, bin_len, bin_rdr);}
public void Img_insert(Fsd_img_itm rv, byte[] dir, byte[] fil, int ext_id, int img_w, int img_h, DateAdp modified, String hash, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
ary[insert_to_mnt].Img_insert(rv, dir, fil, ext_id, modified, hash, bin_len, bin_rdr, img_w, img_h);
}

View File

@@ -26,7 +26,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "2.3.1.1";
public static final String Version = "2.3.2.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";
@@ -46,7 +46,6 @@ public class Xoa_app_ {
public static Io_stream_zip_mgr Utl__zip_mgr() {return utl__zip_mgr;} private static final Io_stream_zip_mgr utl__zip_mgr = new Io_stream_zip_mgr();
public static Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} public static void Gfs_mgr_(Xoa_gfs_mgr v) {gfs_mgr = v;} private static Xoa_gfs_mgr gfs_mgr;
// public static Xoa_lang_mgr Lang_mgr() {return lang_mgr;} public static void Lang_mgr_(Xoa_lang_mgr v) {lang_mgr = v;} private static Xoa_lang_mgr lang_mgr;
public static final byte Mode_console = 0, Mode_gui = 1, Mode_http = 2;
}

View File

@@ -19,12 +19,13 @@ package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx
public class Xoapi_toggle_itm implements GfoInvkAble {
public Xoapi_toggle_itm(byte[] key_bry) {this.key_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Heading_bry() {return heading_bry;} private byte[] heading_bry;
public byte[] Icon_src() {return icon_src;} private byte[] icon_src = Bry_.Empty;
public byte[] Icon_title() {return icon_title;} private byte[] icon_title = Bry_.Empty;
public byte[] Elem_display() {return elem_display;} private byte[] elem_display = Bry_.Empty;
public byte[] Html_toggle_hdr_cls() {return html_toggle_hdr_cls;} public Xoapi_toggle_itm Html_toggle_hdr_cls_(byte[] v) {html_toggle_hdr_cls = v; return this;} private byte[] html_toggle_hdr_cls = Bry_.Empty;
public boolean Visible() {return visible;} private boolean visible;
public Xoapi_toggle_itm Init(Xowe_wiki wiki) {
public Xoapi_toggle_itm Init(Xowe_wiki wiki, byte[] heading_bry) {
if (Img_src_y == null) {
Io_url img_dir = wiki.Appe().User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "portal");
Img_src_y = img_dir.GenSubFil("twisty_down.png").To_http_file_bry();
@@ -34,6 +35,7 @@ public class Xoapi_toggle_itm implements GfoInvkAble {
byte[] img_title_msg = visible ? Img_title_msg_y : Img_title_msg_n;
icon_title = wiki.Msg_mgr().Val_by_key_obj(img_title_msg);
elem_display = visible ? Img_display_y : Img_display_n;
this.heading_bry = heading_bry;
Html_toggle_gen();
return this;
}
@@ -65,8 +67,8 @@ public class Xoapi_toggle_itm implements GfoInvkAble {
}
Bry_fmtr fmtr = Bry_fmtr.new_(); Bry_bfr bfr = Bry_bfr.new_(8);
html_toggle_btn
= fmtr.Fmt_("<a href='javascript:xowa_toggle_visible(\"~{key}\");'><img id='~{key}-toggle-icon' src='~{src}' title='~{title}' /></a>")
.Keys_("key", "src", "title").Bld_bry_many(bfr, key_bry, icon_src, icon_title)
= fmtr.Fmt_("<a href='javascript:xowa_toggle_visible(\"~{key}\");' style='text-decoration: none !important;'>~{heading}<img id='~{key}-toggle-icon' src='~{src}' title='~{title}' /></a>")
.Keys_("key", "src", "title", "heading").Bld_bry_many(bfr, key_bry, icon_src, icon_title, heading_bry)
;
html_toggle_hdr
= fmtr.Fmt_(" id='~{key}-toggle-elem' style='~{display}~{toggle_hdr_cls}'")

View File

@@ -21,7 +21,7 @@ import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.x
public class Db_mgr_fxt {
public Db_mgr_fxt Ctor_fsys() {bldr_fxt = new Xob_fxt().Ctor(Xoa_test_.Url_root().GenSubDir("root")); return this;}
public Db_mgr_fxt Ctor_mem() {bldr_fxt = new Xob_fxt().Ctor_mem(); return this;} private Xob_fxt bldr_fxt;
public Xodb_page page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xodb_page().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Type_redirect_(type_redirect).Text_len_(text_len);}
public Xodb_page page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xodb_page().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Redirected_(type_redirect).Wtxt_len_(text_len);}
public Xowe_wiki Wiki() {return bldr_fxt.Wiki();}
public Xob_bldr Bldr() {return bldr_fxt.Bldr();}
public Db_mgr_fxt doc_ary_(Xodb_page... v) {bldr_fxt.doc_ary_(v); return this;}
@@ -56,14 +56,14 @@ public class Db_mgr_fxt {
wiki.Db_mgr_as_sql().Load_mgr().Load_by_ttl(actl, ns, ttl_bry);
Tfds.Eq(expd.Id(), actl.Id());
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on());
Tfds.Eq(expd.Type_redirect(), actl.Type_redirect());
Tfds.Eq(expd.Text_len(), actl.Text_len());
Tfds.Eq(expd.Redirected(), actl.Redirected());
Tfds.Eq(expd.Wtxt_len(), actl.Wtxt_len());
} private Xodb_page actl = new Xodb_page();
public void Test_load_page(int ns_id, int page_id, String expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns, false);
Tfds.Eq(expd, String_.new_ascii_(actl.Text()));
Tfds.Eq(expd, String_.new_ascii_(actl.Wtxt()));
}
public void Test_search(String search_word_str, int... expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();

View File

@@ -35,7 +35,7 @@ public class Xob_base_fxt {
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public GfoInvkAble Bldr_itm() {return bldr_itm;} GfoInvkAble bldr_itm;
public Xodb_page page_(String ttl) {return page_(ttl, "");}
public Xodb_page page_(String ttl, String text) {return new Xodb_page().Ttl_(Bry_.new_utf8_(ttl), wiki.Ns_mgr()).Text_(Bry_.new_utf8_(text));}
public Xodb_page page_(String ttl, String text) {return new Xodb_page().Ttl_(Bry_.new_utf8_(ttl), wiki.Ns_mgr()).Wtxt_(Bry_.new_utf8_(text));}
public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);}
public void Init_fxts(Xob_bldr bldr, Xowe_wiki wiki, Xob_base_fxt... fxt_ary) {
int fxt_ary_len = fxt_ary.length;

View File

@@ -20,6 +20,7 @@ import gplx.core.primitives.*;
import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.imports.*; import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.bldrs.imports.*; import gplx.xowa.bldrs.oimgs.*;
import gplx.xowa.bldrs.wikis.redirects.*; import gplx.xowa.bldrs.wikis.images.*;
import gplx.xowa.bldrs.files.*; import gplx.xowa.files.origs.*;
import gplx.xowa.html.hdumps.bldrs.*;
public class Xob_cmd_mgr implements GfoInvkAble {
public Xob_cmd_mgr(Xob_bldr bldr) {this.bldr = bldr;} private Xob_bldr bldr;
public void Clear() {list.Clear(); dump_rdrs.Clear();}
@@ -60,6 +61,7 @@ public class Xob_cmd_mgr implements GfoInvkAble {
else if (String_.Eq(cmd_key, Xob_download_wkr.KEY_oimg)) return Add(new Xob_download_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_page_regy_cmd.KEY_oimg)) return Add(new Xob_page_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_exec_sql.KEY)) return Add(new Xob_cmd_exec_sql(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_rl_regy_cmd.Cmd_key_const)) return Add(new Xob_rl_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_redirect_cmd.KEY_redirect)) return Add(new Xob_redirect_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_wiki_image_sql.KEY)) return Add(new Xob_wiki_image_sql(bldr, wiki));

View File

@@ -52,7 +52,7 @@ public class Xob_fxt {
public Xob_fxt doc_ary_(Xodb_page... v) {doc_ary = v; return this;} private Xodb_page[] doc_ary;
public Xodb_page doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);}
public Xodb_page doc_(int id, String date, String title, String text) {
Xodb_page rv = new Xodb_page().Id_(id).Ttl_(Bry_.new_utf8_(title), wiki.Ns_mgr()).Text_(Bry_.new_utf8_(text));
Xodb_page rv = new Xodb_page().Id_(id).Ttl_(Bry_.new_utf8_(title), wiki.Ns_mgr()).Wtxt_(Bry_.new_utf8_(text));
int[] modified_on = new int[7];
dateParser.Parse_iso8651_like(modified_on, date);
rv.Modified_on_(DateAdp_.seg_(modified_on));

View File

@@ -168,7 +168,7 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
rdr = Xob_xfer_regy_tbl.Select_by_lnki_page_id(conn, page_id_val, select_interval);
while (rdr.MoveNextPeer()) {
pages_found = true; // at least one page found; set true
Xodb_tbl_oimg_xfer_itm itm = Xodb_tbl_oimg_xfer_itm.new_rdr_(rdr);
Xodb_tbl_oimg_xfer_itm itm = Xodb_tbl_oimg_xfer_itm.new_rdr_( rdr);
if (itm.Lnki_page_id() == page_id_val // if same page_id but lnki_id < last, then ignore; needed b/c select selects by page_id, and need to be handle breaks between pages
&& itm.Lnki_id() <= lnki_id_val)
continue;
@@ -310,20 +310,17 @@ class Xodb_tbl_oimg_xfer_itm extends Xof_fsdb_itm { public int Lnki_id() {ret
rv.lnki_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_id);
rv.lnki_page_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_page_id);
rv.lnki_ext_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_ext);
rv.File_is_orig_ (rdr.ReadByte(Xob_xfer_regy_tbl.Fld_file_is_orig) == Bool_.Y_byte);
byte[] ttl = rdr.ReadBryByStr(Xob_xfer_regy_tbl.Fld_lnki_ttl);
rv.Ctor_by_orig
( rdr.ReadByte(Xob_xfer_regy_tbl.Fld_orig_repo)
, ttl
rv.Ctor_by_fsdb_make
( rdr.ReadBryByStr(Xob_xfer_regy_tbl.Fld_lnki_ttl)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h) // set lnki_size; Xof_bin_mgr uses lnki_size
, Xof_lnki_time.Db_load_double(rdr, Xob_xfer_regy_tbl.Fld_lnki_time)
, Xof_lnki_page.Db_load_int(rdr, Xob_xfer_regy_tbl.Fld_lnki_page)
, rdr.ReadByte(Xob_xfer_regy_tbl.Fld_orig_repo)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_w)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_h)
, Bry_.Empty
, rdr.ReadByte(Xob_xfer_regy_tbl.Fld_file_is_orig) == Bool_.Y_byte
);
rv.Lnki_ttl_(ttl);
rv.Html_size_(rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h)); // set html_size as file_size (may try to optimize later by removing similar thumbs (EX: 220,221 -> 220))
rv.Lnki_size_(rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h)); // set lnki_size; Xof_bin_mgr uses lnki_size;
rv.Lnki_page_ (Xof_doc_page.Db_load_int(rdr, Xob_xfer_regy_tbl.Fld_lnki_page));
rv.Lnki_time_ (Xof_doc_thumb.Db_load_double(rdr, Xob_xfer_regy_tbl.Fld_lnki_time));
return rv;
}
}

View File

@@ -32,7 +32,7 @@ class Xob_lnki_temp_tbl {
.Val_int(w)
.Val_int(h)
.Val_double(upright)
.Val_double(gplx.xowa.files.Xof_doc_thumb.Db_save_double(thumbtime))
.Val_double(gplx.xowa.files.Xof_lnki_time.Db_save_double(thumbtime))
.Val_int(page)
.Exec_insert();
}

View File

@@ -29,6 +29,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
private int[] ns_ids = Int_.Ary(Xow_ns_.Id_main);// , Xow_ns_.Id_category, Xow_ns_.Id_template
private boolean wiki_ns_file_is_case_match_all = true; private Xowe_wiki commons_wiki;
private Xob_hdump_bldr hdump_bldr; private long hdump_max = Io_mgr.Len_gb;
private Xob_link_dump_cmd link_dump_cmd;
public Xob_lnki_temp_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
@Override public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.lnki_temp";
@Override public byte Init_redirect() {return Bool_.N_byte;}
@@ -73,12 +74,14 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
if (gen_hdump) {
hdump_bldr = new Xob_hdump_bldr(wiki.Db_mgr_as_sql(), conn, hdump_max);
hdump_bldr.Bld_init();
link_dump_cmd = new Xob_link_dump_cmd();
link_dump_cmd.Init_by_wiki(wiki);
}
conn.Txn_mgr().Txn_bgn_if_none();
log_mgr.Txn_bgn();
}
@Override public void Exec_pg_itm_hook(Xow_ns ns, Xodb_page db_page, byte[] page_src) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Gen_ttl(db_page.Ttl_wo_ns()));
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Gen_ttl(db_page.Ttl_page_db()));
byte[] ttl_bry = ttl.Page_db();
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry);
if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json
@@ -98,16 +101,30 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
if (gen_hdump) {
page.Root_(root);
hdump_bldr.Insert_page(page);
link_dump_cmd.Page_bgn(page.Revision_data().Id());
ListAdp lnki_list = page.Lnki_list();
int len = lnki_list.Count();
for (int i = 0; i < len; ++i) {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)lnki_list.FetchAt(i);
Xoa_ttl trg_ttl = lnki.Ttl();
link_dump_cmd.Add(lnki.Html_id(), trg_ttl.Ns().Id(), trg_ttl.Page_db());
}
}
root.Clear();
}
}
@Override public void Exec_commit_hook() {
conn.Txn_mgr().Txn_end_all_bgn_if_none(); // save lnki_temp
if (gen_hdump) hdump_bldr.Commit();
if (gen_hdump) {
hdump_bldr.Commit();
link_dump_cmd.Wkr_commit();
}
}
@Override public void Exec_end_hook() {
if (gen_hdump) hdump_bldr.Bld_term();
if (gen_hdump) {
hdump_bldr.Bld_term();
link_dump_cmd.Wkr_end();
}
Gfo_usr_dlg_._.Warn_many("", "", invoke_wkr.Err_filter_mgr().Print());
wiki.Appe().Log_mgr().Txn_end();
conn.Txn_mgr().Txn_end();
@@ -116,15 +133,15 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
if (lnki.Ttl().ForceLiteralLink()) return; // ignore literal links which creat a link to file, but do not show the image; EX: [[:File:A.png|thumb|120px]] creates a link to File:A.png, regardless of other display-oriented args
byte[] ttl = lnki.Ttl().Page_db();
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
double lnki_thumbtime = lnki.Thumbtime();
double lnki_thumbtime = lnki.Time();
int lnki_page = lnki.Page();
byte[] ttl_commons = Xto_commons(wiki_ns_file_is_case_match_all, commons_wiki, ttl);
if ( Xof_doc_page.Null_n(lnki_page) // page set
&& Xof_doc_thumb.Null_n(lnki_thumbtime)) // thumbtime set
if ( Xof_lnki_page.Null_n(lnki_page) // page set
&& Xof_lnki_time.Null_n(lnki_thumbtime)) // thumbtime set
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Cur_page().Ttl().Page_db_as_str(), String_.new_utf8_(ttl));
if (lnki.Ns_id() == Xow_ns_.Id_media)
lnki_src_tid = Xob_lnki_src_tid.Tid_media;
Xob_lnki_temp_tbl.Insert(stmt, ctx.Cur_page().Revision_data().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), lnki_src_tid, lnki.Lnki_w(), lnki.Lnki_h(), lnki.Upright(), lnki_thumbtime, lnki_page);
Xob_lnki_temp_tbl.Insert(stmt, ctx.Cur_page().Revision_data().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), lnki_src_tid, lnki.W(), lnki.H(), lnki.Upright(), lnki_thumbtime, lnki_page);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wdata_enabled_)) wdata_enabled = m.ReadYn("v");

View File

@@ -28,12 +28,12 @@ public class Xob_orig_qry_cmd extends Xob_itm_basic_base implements Xob_cmd {
Xob_bmk_mgr bmk = new Xob_bmk_mgr();
bmk.Init(conn, this.Cmd_key(), true, false, true);
bmk.Load();
Xof_fsdb_itm itm = new Xof_fsdb_itm();
// Xof_fsdb_itm itm = new Xof_fsdb_itm();
DataRdr rdr = DataRdr_.Null;
try {
// rdr = Select(conn, bmk.Repo_prv(), bmk.Ttl_prv());
while (rdr.MoveNextPeer()) {
Load_itm(itm, rdr);
// Load_itm(itm, rdr);
// QueryItm
}
}
@@ -48,9 +48,6 @@ public class Xob_orig_qry_cmd extends Xob_itm_basic_base implements Xob_cmd {
}
*/
}
private void Load_itm(Xof_fsdb_itm itm, DataRdr rdr) {
itm.Lnki_ttl_(null);
}
public DataRdr Select(Db_conn p, byte prv_repo_id, byte[] prv_ttl) {
String sql = String_.Concat_lines_nl_skip_last
( "SELECT lnki_ttl"

View File

@@ -53,8 +53,8 @@ public class Xob_xfer_temp_cmd_orig extends Xob_itm_basic_base implements Xob_cm
, orig_w, orig_h
, orig_w, orig_h // file_w, file_h is same as orig_w,orig_h; i.e.: make same file_w as orig_w
, Xof_img_size.Null, Xof_img_size.Null // html_w, html_h is -1; i.e.: will not be displayed in page at specific size (this matches logic in Xob_xfer_temp_cmd_thumb)
, Xof_doc_thumb.Null
, Xof_doc_page.Null
, Xof_lnki_time.Null
, Xof_lnki_page.Null
, 0);
}
conn.Txn_mgr().Txn_end_all();

View File

@@ -47,8 +47,8 @@ class Xob_xfer_temp_itm {
= orig_w = orig_h = orig_page_id = Int_.Neg1;
join_ttl = redirect_src = orig_media_type = null;
lnki_upright = Xop_lnki_tkn.Upright_null;
lnki_thumbtime = Xof_doc_thumb.Null;
lnki_page = Xof_doc_page.Null;
lnki_thumbtime = Xof_lnki_time.Null;
lnki_page = Xof_lnki_page.Null;
}
public void Load(DataRdr rdr) {
lnki_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_id);
@@ -59,7 +59,7 @@ class Xob_xfer_temp_itm {
lnki_w = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_w);
lnki_h = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_h);
lnki_upright = rdr.ReadDouble(Xob_lnki_regy_tbl.Fld_lnki_upright);
lnki_thumbtime = Xof_doc_thumb.Db_load_double(rdr, Xob_lnki_regy_tbl.Fld_lnki_time);
lnki_thumbtime = Xof_lnki_time.Db_load_double(rdr, Xob_lnki_regy_tbl.Fld_lnki_time);
lnki_page = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page);
lnki_count = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_count);
orig_repo = rdr.ReadByte(Xob_orig_regy_tbl.Fld_orig_repo);
@@ -89,13 +89,13 @@ class Xob_xfer_temp_itm {
// }
lnki_ext = orig_ext_id;
orig_media_type_tid = Xof_media_type.Xto_byte(orig_media_type);
if ( Xof_doc_thumb.Null_n(lnki_thumbtime) // thumbtime defined
if ( Xof_lnki_time.Null_n(lnki_thumbtime) // thumbtime defined
&& orig_media_type_tid != Xof_media_type.Tid_video // video can have thumbtime
)
lnki_thumbtime = Xof_doc_thumb.Null; // set thumbtime to NULL; actually occurs for one file: [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
if ( Xof_doc_page.Null_n(lnki_page)
lnki_thumbtime = Xof_lnki_time.Null; // set thumbtime to NULL; actually occurs for one file: [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
if ( Xof_lnki_page.Null_n(lnki_page)
&& !Xof_ext_.Id_supports_page(orig_ext_id)) // djvu / pdf can have page parameters, which are currently being stored in thumbtime; DATE:2014-01-18
lnki_page = Xof_doc_page.Null;
lnki_page = Xof_lnki_page.Null;
if (orig_page_id == -1) { // no orig found (i.e.: not in local's / remote's image.sql);
chk_tid = Chk_tid_orig_page_id_is_null;
return false;

View File

@@ -54,7 +54,7 @@ public class Xob_xfer_temp_itm_tst {
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
);
fxt.Test_lnki_thumbtime(Xof_doc_thumb.Null);
fxt.Test_lnki_thumbtime(Xof_lnki_time.Null);
fxt.Reset().Test_bgn
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video)
@@ -67,7 +67,7 @@ public class Xob_xfer_temp_itm_tst {
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(Xof_doc_page.Null);
fxt.Test_lnki_page(Xof_lnki_page.Null);
fxt.Reset().Test_bgn
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf)
@@ -136,7 +136,7 @@ class Xob_xfer_temp_itm_fxt {
( Xof_ext_.Id_png, 1, Xof_repo_itm.Repo_remote
, "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xob_lnki_src_tid.Tid_file
, 220, 200, 1, 2, 440, 400, 3
, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null, Xof_doc_page.Null
, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null
, Xof_media_type.Name_bitmap, "png"
));
GfoNdeList subs = GfoNdeList_.new_();

View File

@@ -38,7 +38,7 @@ class Xob_xfer_temp_tbl {
.Val_int(file_h)
.Val_int(html_w)
.Val_int(html_h)
.Val_double(Xof_doc_thumb.Db_save_double(thumbtime))
.Val_double(Xof_lnki_time.Db_save_double(thumbtime))
.Val_int(page)
.Val_int(count)
.Exec_insert();

View File

@@ -60,33 +60,33 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
int page_id = page.Id();
DateAdp modified = page.Modified_on();
if (modified.compareTo(modified_latest) == CompareAble_.More) modified_latest = modified;
byte[] text = page.Text();
int text_len = page.Text_len();
byte[] text = page.Wtxt();
int text_len = page.Wtxt_len();
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
boolean redirect = redirect_ttl != null;
page.Type_redirect_(redirect);
page.Redirected_(redirect);
Xow_ns ns = page.Ns();
int random_int = ns.Count() + 1;
ns.Count_(random_int);
if (dg_enabled) {
if (dg_match_mgr.Match(1, page_id, ns.Id(), page.Ttl_wo_ns(), page.Ttl_w_ns(), wiki.Lang(), text)) return;
if (dg_match_mgr.Match(1, page_id, ns.Id(), page.Ttl_page_db(), page.Ttl_full_db(), wiki.Lang(), text)) return;
}
text = zip_mgr.Zip(data_storage_format, text);
int text_stmt_idx = text_stmts_mgr.Stmt_by_ns(ns.Bldr_file_idx(), text.length); // NOTE: was text.length, but want text_len which is original page_len, not compressed; DATE:2014-08-04
Db_stmt text_stmt = text_stmts_mgr.Stmt_at(text_stmt_idx);
try {
db_mgr.Page_create(page_stmt, text_stmt, page_id, page.Ns_id(), page.Ttl_wo_ns(), redirect, modified, text, random_int, text_stmt_idx);
db_mgr.Page_create(page_stmt, text_stmt, page_id, page.Ns_id(), page.Ttl_page_db(), redirect, modified, text, random_int, text_stmt_idx);
}
catch (Exception e) {
usr_dlg.Warn_many("", "", "failed to insert page: id=~{0} ns=~{1} title=~{2} error=~{3}", page.Id(), page.Ns_id(), String_.new_utf8_(page.Ttl_wo_ns()), Err_.Message_gplx_brief(e));
usr_dlg.Warn_many("", "", "failed to insert page: id=~{0} ns=~{1} title=~{2} error=~{3}", page.Id(), page.Ns_id(), String_.new_utf8_(page.Ttl_page_db()), Err_.Message_gplx_brief(e));
page_stmt.Reset_stmt(); // must new stmt variable, else java.sql.SQLException: "statement is not executing"
text_stmt.Reset_stmt(); // must new stmt variable, else java.sql.SQLException: "statement is not executing"
}
if (redirect && redirect_id_enabled) {
redirect_tbl.Insert(page_id, page.Ttl_wo_ns(), redirect_ttl);
redirect_tbl.Insert(page_id, page.Ttl_page_db(), redirect_ttl);
}
++page_count_all;
if (ns.Id_main() && !page.Type_redirect()) ++page_count_main;
if (ns.Id_main() && !page.Redirected()) ++page_count_main;
if (page_count_all % txn_commit_interval == 0) {
Db_conn conn = text_stmts_mgr.Conn_at(text_stmt_idx);
conn.Txn_mgr().Txn_end_all_bgn_if_none();

View File

@@ -34,9 +34,9 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvk
Xob_xdat_file_wtr[] page_wtr_regy = new Xob_xdat_file_wtr[Ns_ordinal_max]; static final int Ns_ordinal_max = Xow_ns_mgr_.Ordinal_max; // ASSUME: no more than 128 ns in a wiki
Xob_stat_type data_rpt_typ; Xob_stat_mgr stat_mgr = new Xob_stat_mgr(); byte page_storage_type;
public void Wkr_run(Xodb_page page) {
int id = page.Id(); byte[] ttl_wo_ns = page.Ttl_wo_ns(), text = page.Text(); int ttl_len = ttl_wo_ns.length, text_len = text.length; Xow_ns ns = page.Ns();
int id = page.Id(); byte[] ttl_wo_ns = page.Ttl_page_db(), text = page.Wtxt(); int ttl_len = ttl_wo_ns.length, text_len = text.length; Xow_ns ns = page.Ns();
boolean redirect = redirect_mgr.Is_redirect(text, text_len);
page.Type_redirect_(redirect);
page.Redirected_(redirect);
// page: EX: \t123\t2012-06-09\ttitle\ttext\n; NOTE: 512k * ~20 ns = 10 MB max memory; no need for intermediary flushing
Xob_xdat_file_wtr page_wtr = Page_wtr_get(ns);
@@ -47,7 +47,7 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvk
// idx: EX: 00100|aB64|Ttl;
Xob_tmp_wtr ttl_wtr = ttl_wtr_mgr.Get_or_new(ns);
int file_idx = page_wtr.Fil_idx(), row_idx = page_wtr.Idx_pos() - ListAdp_.LastIdxOffset;
page.Text_db_id_(file_idx).Db_row_idx_(row_idx);
page.Wtxt_db_id_(file_idx).Tdb_row_idx_(row_idx);
if (ttl_wtr.FlushNeeded(Xodb_page_.Txt_ttl_len__fixed + ttl_len)) ttl_wtr.Flush(bldr.Usr_dlg());
Xodb_page_.Txt_ttl_save(ttl_wtr.Bfr(), id, file_idx, row_idx, redirect, text_len, ttl_wo_ns);
}

View File

@@ -34,7 +34,7 @@ public abstract class Xob_search_base extends Xob_itm_dump_base implements Xobd_
public void Wkr_run(Xodb_page page) {
// if (page.Ns_id() != Xow_ns_.Id_main) return; // limit to main ns for now
try {
byte[] ttl = page.Ttl_wo_ns();
byte[] ttl = page.Ttl_page_db();
byte[][] words = Split(lang, list, dump_bfr, ttl);
Xob_tmp_wtr wtr = tmp_wtr_mgr.Get_or_new(ns_main == null ? page.Ns() : ns_main);
int words_len = words.length;
@@ -48,7 +48,7 @@ public abstract class Xob_search_base extends Xob_itm_dump_base implements Xobd_
byte[] word = words[i];
wtr.Bfr() .Add(word) .Add_byte(Byte_ascii.Pipe)
.Add_base85_len_5(page.Id()) .Add_byte(Byte_ascii.Semic)
.Add_base85_len_5(page.Text().length) .Add_byte(Byte_ascii.NewLine);
.Add_base85_len_5(page.Wtxt().length) .Add_byte(Byte_ascii.NewLine);
}
} catch (Exception e) {bldr.Usr_dlg().Warn_many("", "", "search_index:fatal error: err=~{0}", Err_.Message_gplx_brief(e));} // never let single page crash entire import
}

View File

@@ -98,12 +98,12 @@ public class Xobc_core_calc_stats extends Xob_itm_basic_base implements Xob_cmd
int rv = 0;
byte[] bry = Io_mgr._.LoadFilBry(fil);
Xob_xdat_file xdat_file = new Xob_xdat_file().Parse(bry, bry.length, fil);
Xodb_page page = Xodb_page.tmp_();
Xodb_page page = Xodb_page.new_tmp();
int count = xdat_file.Count();
for (int i = 0; i < count; i++) {
byte[] ttl_bry = xdat_file.Get_bry(i);
Xodb_page_.Txt_ttl_load(page, ttl_bry);
rv += page.Type_redirect() ? 0 : 1;
rv += page.Redirected() ? 0 : 1;
}
return rv;
}

View File

@@ -25,7 +25,7 @@ public class Xobc_core_make_id extends Xob_itm_dump_base implements Xobd_wkr, Gf
this.Init_dump(KEY, wiki.Tdb_fsys_mgr().Site_dir().GenSubDir(Xotdb_dir_info_.Name_id));
}
public void Wkr_run(Xodb_page page) {
byte[] ttl = page.Ttl_wo_ns();
byte[] ttl = page.Ttl_page_db();
if (dump_bfr.Len() + row_fixed_len + ttl.length > dump_fil_len) Io_mgr._.AppendFilBfr(dump_url_gen.Nxt_url(), dump_bfr);
Xodb_page_.Txt_id_save(dump_bfr, page);
}

View File

@@ -178,7 +178,7 @@ public class Xobc_tst {
ListAdp actl = ListAdp_.new_();
Xodb_page page = new Xodb_page();
while (parser.Read(page)) {
actl.Add(String_.new_utf8_(page.Text()));
actl.Add(String_.new_utf8_(page.Wtxt()));
}
Tfds.Eq_ary(expd, actl.XtoStrAry());
}

View File

@@ -31,7 +31,7 @@ public class Xob_category_registry_sql implements Xob_cmd {
Xodb_mgr_sql db_mgr = Xodb_mgr_sql.Get_or_load(wiki);
Db_conn conn = db_mgr.Core_data_mgr().Conn_core();
Db_qry_select qry = Db_qry_select.new_()
Db_qry__select_cmd qry = Db_qry__select_cmd.new_()
.Cols_(Xodb_page_tbl.Fld_page_title, Xodb_page_tbl.Fld_page_id)
.From_(Xodb_page_tbl.Tbl_name)
.Where_(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, Xow_ns_.Id_category))

View File

@@ -65,7 +65,7 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
}
}
@gplx.Virtual public void Log(byte err_tid, Xodb_page page, byte[] src, int ctg_bgn) {
String title = String_.new_utf8_(page.Ttl_w_ns());
String title = String_.new_utf8_(page.Ttl_full_db());
int ctg_end = ctg_bgn + 40; if (ctg_end > src.length) ctg_end = src.length;
String ctg_str = String_.Replace(String_.new_utf8_(src, ctg_bgn, ctg_end), "\n", "");
String err = "";

View File

@@ -41,7 +41,7 @@ class Xodb_page_wkr_ctg_fxt {
byte[] bry = Bry_.new_utf8_("[[Category:");
wkr.Wkr_hooks().Add(bry, bry);
mgr.Wkr_add(wkr);
Xodb_page page = new Xodb_page().Text_(src);//.Ttl_(Bry_.new_utf8_("Test"), new Xow_ns_mgr());
Xodb_page page = new Xodb_page().Wtxt_(src);//.Ttl_(Bry_.new_utf8_("Test"), new Xow_ns_mgr());
mgr.Wkr_bgn(bldr);
mgr.Wkr_run(page);
byte[][] ttl = (byte[][])wkr.Found().Xto_ary(byte[].class);

View File

@@ -134,9 +134,9 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
if ((exec_count % progress_interval) == 0)
usr_dlg.Prog_many("", "", "parsing: ns=~{0} db=~{1} pg=~{2} count=~{3} time=~{4} rate=~{5} ttl=~{6}"
, ns.Id(), db_id, page.Id(), exec_count
, Env_.TickCount_elapsed_in_sec(time_bgn), rate_mgr.Rate_as_str(), String_.new_utf8_(page.Ttl_wo_ns()));
, Env_.TickCount_elapsed_in_sec(time_bgn), rate_mgr.Rate_as_str(), String_.new_utf8_(page.Ttl_page_db()));
ctx.Clear();
Exec_pg_itm_hook(ns, page, page.Text());
Exec_pg_itm_hook(ns, page, page.Wtxt());
ctx.App().Utl__bfr_mkr().Clear_fail_check(); // make sure all bfrs are released
if (ctx.Wiki().Cache_mgr().Tmpl_result_cache().Count() > 50000)
ctx.Wiki().Cache_mgr().Tmpl_result_cache().Clear();
@@ -145,12 +145,12 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
if ((exec_count % poll_interval) == 0)
poll_mgr.Poll();
if ((exec_count % commit_interval) == 0)
Exec_commit(ns.Id(), db_id, page.Id(), page.Ttl_wo_ns());
Exec_commit(ns.Id(), db_id, page.Id(), page.Ttl_page_db());
if ((exec_count % cleanup_interval) == 0)
Free();
}
catch (Exception exc) {
bldr.Usr_dlg().Warn_many(GRP_KEY, "parse", "failed to parse ~{0} error ~{1}", String_.new_utf8_(page.Ttl_wo_ns()), Err_.Message_lang(exc));
bldr.Usr_dlg().Warn_many(GRP_KEY, "parse", "failed to parse ~{0} error ~{1}", String_.new_utf8_(page.Ttl_page_db()), Err_.Message_lang(exc));
ctx.App().Utl__bfr_mkr().Clear();
this.Free();
}
@@ -230,7 +230,7 @@ class Xob_dump_mgr_base_ {
for (int i = 0; i < page_count; i++) {
page = (Xodb_page)pages.FetchAt(i);
Xot_defn_tmpl defn = new Xot_defn_tmpl();
defn.Init_by_new(ns_tmpl, ns_tmpl.Gen_ttl(page.Ttl_wo_ns()), page.Text(), null, false); // NOTE: passing null, false; will be overriden later when Parse is called
defn.Init_by_new(ns_tmpl, ns_tmpl.Gen_ttl(page.Ttl_page_db()), page.Wtxt(), null, false); // NOTE: passing null, false; will be overriden later when Parse is called
defn_cache.Add(defn, ns_tmpl.Case_match());
++load_count;
if ((load_count % 10000) == 0) usr_dlg.Prog_many("", "", "tmpl_loading: ~{0}", load_count);

View File

@@ -65,7 +65,7 @@ class Xob_dump_src_id {
while (rdr.MoveNextPeer()) {
Xodb_page page = New_page(db_mgr, cur_ns, rdr);
list.Add(page);
size_len += page.Text_len();
size_len += page.Wtxt_len();
if (size_len > size_max)
break;
}
@@ -84,12 +84,12 @@ class Xob_dump_src_id {
}
private static Xodb_page New_page(Xodb_mgr_sql db_mgr, int ns_id, DataRdr rdr) {
Xodb_page rv = new Xodb_page();
rv.Ns_id_(ns_id);
rv.Id_(rdr.ReadInt(Xodb_page_tbl.Fld_page_id));
rv.Ttl_wo_ns_(rdr.ReadBryByStr(Xodb_page_tbl.Fld_page_title));
rv.Ns_id_(ns_id);
rv.Ttl_page_db_(rdr.ReadBryByStr(Xodb_page_tbl.Fld_page_title));
byte[] old_text = rdr.ReadBry(Xodb_text_tbl.Fld_old_text);
old_text = db_mgr.Wiki().Appe().Zip_mgr().Unzip(db_mgr.Data_storage_format(), old_text);
rv.Text_(old_text);
rv.Wtxt_(old_text);
return rv;
}
private static String New_rdr__redirect_clause(byte redirect) {

View File

@@ -43,7 +43,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src, page_src.length);
byte[] redirect_ttl_bry = Xoa_ttl.Replace_spaces(redirect_ttl.Page_db()); // NOTE: spaces can still exist b/c redirect is scraped from #REDIRECT which sometimes has a mix; EX: "A_b c"
redirect_ttl_bry = encoder.Decode(redirect_ttl_bry);
redirect_tbl.Insert(page.Id(), Xoa_ttl.Replace_spaces(page.Ttl_wo_ns()), -1, redirect_ttl.Ns().Id(), redirect_ttl_bry, redirect_ttl.Anch_txt(), 1);
redirect_tbl.Insert(page.Id(), Xoa_ttl.Replace_spaces(page.Ttl_page_db()), -1, redirect_ttl.Ns().Id(), redirect_ttl_bry, redirect_ttl.Anch_txt(), 1);
}
@Override public void Exec_commit_hook() {
conn.Txn_mgr().Txn_end_all_bgn_if_none();

View File

@@ -33,15 +33,15 @@ public class Xob_redirect_tbl {
public void Update_trg_redirect_id(Io_url core_url, int max_redirected_depth) {
Sqlite_engine_.Db_attach(conn, "page_db", core_url.Raw()); // link database with page table
conn.Exec_sql(Sql_get_page_data); // fill in page_id, page_ns, page_is_redirect for trg_ttl; EX: Page_A has "#REDIRECT Page_B"; Page_B is in redirect tbl; find its id, ttl, redirect status
for (int i = 0; i < max_redirected_depth; i++) { // loop to find redirected redirects; note that it is bounded by depth (to guard against circular redirects)
for (int i = 0; i < max_redirected_depth; i++) { // loop to find redirected redirects; note that it is bounded by depth (to guard against circular redirects)
int affected = conn.Exec_sql(Sql_get_redirect_redirects); // find redirects that are also redirects
if (affected == 0) break; // no more redirected redirects; stop
if (affected == 0) break; // no more redirected redirects; stop
conn.Exec_sql(Sql_get_redirect_page_data); // get page data for redirects
}
Sqlite_engine_.Db_detach(conn, "page_db");
}
public void Update_src_redirect_id(Io_url core_url, Db_conn core_provider) {
core_provider.Exec_sql(Sql_ddl__page_redirect_id); // create page.page_redirect_id
core_provider.Exec_sql(Sql_ddl__page_redirect_id); // create page.page_redirect_id
Sqlite_engine_.Idx_create(conn, Idx_trg_src);
Sqlite_engine_.Db_attach(conn, "page_db", core_url.Raw()); // link database with page table
conn.Exec_sql(Sql_update_redirect_id); // update page_redirect_id

View File

@@ -39,7 +39,7 @@ public class Xob_xml_page_bldr {
}
public Xob_xml_page_bldr Add(Xodb_page doc) {
bfr.Add(Indent_2).Add(Xob_xml_parser_.Bry_page_bgn).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_title_bgn).Add(doc.Ttl_w_ns()).Add(Xob_xml_parser_.Bry_title_end).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_title_bgn).Add(doc.Ttl_full_db()).Add(Xob_xml_parser_.Bry_title_end).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_id_bgn).Add_int_variable(doc.Id()).Add(Xob_xml_parser_.Bry_id_end).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_redirect_bgn_frag).Add(Nde_inline).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_revision_bgn).Add_byte_nl();
@@ -51,7 +51,7 @@ public class Xob_xml_page_bldr {
bfr.Add(Indent_6).Add(Xob_xml_parser_.Bry_contributor_end).Add_byte_nl();
bfr.Add(Indent_6).Add(Xob_xml_parser_.Bry_minor_bgn_frag).Add(Nde_inline).Add_byte_nl();
bfr.Add(Indent_6).Add(Xob_xml_parser_.Bry_comment_bgn).Add(Revision_comment).Add(Xob_xml_parser_.Bry_comment_end).Add_byte_nl();
bfr.Add(Indent_6).Add(Xob_xml_parser_.Bry_text_bgn).Add(doc.Text()).Add(Xob_xml_parser_.Bry_text_end).Add_byte_nl();
bfr.Add(Indent_6).Add(Xob_xml_parser_.Bry_text_bgn).Add(doc.Wtxt()).Add(Xob_xml_parser_.Bry_text_end).Add_byte_nl();
bfr.Add(Indent_4).Add(Xob_xml_parser_.Bry_revision_end).Add_byte_nl();
bfr.Add(Indent_2).Add(Xob_xml_parser_.Bry_page_end).Add_byte_nl();
return this;

View File

@@ -80,7 +80,7 @@ public class Xob_xml_parser {
title_needed = false;
}
break;
case Xob_xml_parser_.Id_text_end: data_bfr_add = false; rv.Text_(data_bfr.Xto_bry_and_clear()); break;
case Xob_xml_parser_.Id_text_end: data_bfr_add = false; rv.Wtxt_(data_bfr.Xto_bry_and_clear()); break;
case Xob_xml_parser_.Id_amp: case Xob_xml_parser_.Id_quot: case Xob_xml_parser_.Id_lt: case Xob_xml_parser_.Id_gt:
case Xob_xml_parser_.Id_cr_nl: case Xob_xml_parser_.Id_cr:
if (data_bfr_add) data_bfr.Add_byte(itm.Subst_byte());

View File

@@ -44,28 +44,28 @@ public class Xob_xml_parser_tst {
@Test public void Xml() {
Xodb_page doc = doc_(1, "a", "&quot;a &amp; b &lt;&gt; a | b&quot;", Date_1);
fil = page_bldr.Add(doc).XtoByteStreamRdr();
tst_parse(fil, doc.Text_(Bry_.new_utf8_("\"a & b <> a | b\"")), 0);
tst_parse(fil, doc.Wtxt_(Bry_.new_utf8_("\"a & b <> a | b\"")), 0);
}
@Test public void Tab() {
Xodb_page doc = doc_(1, "a", "a \t b", Date_1);
fil = page_bldr.Add(doc).XtoByteStreamRdr();
tst_parse(fil, doc.Text_(Bry_.new_utf8_("a &#09; b")), 0);
tst_parse(fil, doc.Wtxt_(Bry_.new_utf8_("a &#09; b")), 0);
}
@Test public void Tab_disable() {
Xodb_page doc = doc_(1, "a", "a \t b", Date_1);
page_parser.Trie_tab_del_();
fil = page_bldr.Add(doc).XtoByteStreamRdr();
tst_parse(fil, doc.Text_(Bry_.new_utf8_("a \t b")), 0);
tst_parse(fil, doc.Wtxt_(Bry_.new_utf8_("a \t b")), 0);
}
@Test public void Cr_nl() {
Xodb_page doc = doc_(1, "a", "a \r\n b", Date_1);
fil = page_bldr.Add(doc).XtoByteStreamRdr();
tst_parse(fil, doc.Text_(Bry_.new_utf8_("a \n b")), 0);
tst_parse(fil, doc.Wtxt_(Bry_.new_utf8_("a \n b")), 0);
}
@Test public void Cr() {
Xodb_page doc = doc_(1, "a", "a \r b", Date_1);
fil = page_bldr.Add(doc).XtoByteStreamRdr();
tst_parse(fil, doc.Text_(Bry_.new_utf8_("a \n b")), 0);
tst_parse(fil, doc.Wtxt_(Bry_.new_utf8_("a \n b")), 0);
}
@Test public void Text_long() {
String s = String_.Repeat("a", 1024);
@@ -87,24 +87,24 @@ public class Xob_xml_parser_tst {
@Test public void Ns_file() {
Xodb_page doc = doc_(1, "File:a", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_file, doc.Ns_id());
Tfds.Eq("a", String_.new_utf8_(doc.Ttl_wo_ns()));
Tfds.Eq("a", String_.new_utf8_(doc.Ttl_page_db()));
}
@Test public void Ns_main() {
Xodb_page doc = doc_(1, "a", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
Tfds.Eq("a", String_.new_utf8_(doc.Ttl_wo_ns()));
Tfds.Eq("a", String_.new_utf8_(doc.Ttl_page_db()));
}
@Test public void Ns_main_book() {
Xodb_page doc = doc_(1, "Book", "a", Date_1);
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
Tfds.Eq("Book", String_.new_utf8_(doc.Ttl_wo_ns()));
Tfds.Eq("Book", String_.new_utf8_(doc.Ttl_page_db()));
}
@Test public void XmlEntities() {
Xodb_page orig = doc_(1, "A&amp;b", "a", Date_1);
Xodb_page actl = new Xodb_page();
fil = page_bldr.Add(orig).XtoByteStreamRdr();
page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), 0, ns_mgr);
Tfds.Eq("A&b", String_.new_utf8_(actl.Ttl_w_ns()));
Tfds.Eq("A&b", String_.new_utf8_(actl.Ttl_full_db()));
}
@Test public void Root() {
Xodb_page doc = doc_(1, "a", "a", Date_1);
@@ -122,13 +122,13 @@ public class Xob_xml_parser_tst {
Xodb_page actl = new Xodb_page();
int rv = page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), cur_pos, ns_mgr);
Tfds.Eq(expd.Id(), actl.Id(), "id");
Tfds.Eq(String_.new_utf8_(expd.Ttl_w_ns()), String_.new_utf8_(actl.Ttl_w_ns()), "title");
Tfds.Eq(String_.new_utf8_(expd.Text()), String_.new_utf8_(actl.Text()), "text");
Tfds.Eq(String_.new_utf8_(expd.Ttl_full_db()), String_.new_utf8_(actl.Ttl_full_db()), "title");
Tfds.Eq(String_.new_utf8_(expd.Wtxt()), String_.new_utf8_(actl.Wtxt()), "text");
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on(), "timestamp");
return rv;
}
Xodb_page doc_(int id, String title, String text, String date) {
Xodb_page rv = new Xodb_page().Id_(id).Ttl_(Bry_.new_ascii_(title), ns_mgr).Text_(Bry_.new_ascii_(text));
Xodb_page rv = new Xodb_page().Id_(id).Ttl_(Bry_.new_ascii_(title), ns_mgr).Wtxt_(Bry_.new_ascii_(text));
int[] modified_on = new int[7];
dateParser.Parse_iso8651_like(modified_on, date);
rv.Modified_on_(DateAdp_.seg_(modified_on));

View File

@@ -61,7 +61,7 @@ public class Xoctg_html_mgr implements GfoInvkAble {
boolean id_exists = wiki.Db_mgr().Load_mgr().Load_by_id(dbo_page, itm.Id());
Xoa_ttl itm_ttl = null;
if (id_exists)
itm_ttl = Xoa_ttl.parse_(wiki, dbo_page.Ns_id(), dbo_page.Ttl_wo_ns());
itm_ttl = Xoa_ttl.parse_(wiki, dbo_page.Ns_id(), dbo_page.Ttl_page_db());
else {
itm_ttl = Xoa_ttl.parse_(wiki, itm.Sortkey());
if (itm_ttl == null)

View File

@@ -31,7 +31,7 @@ public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
int len = itms.Count();
for (int i = 0; i < len; i++) {
Xodb_page page = (Xodb_page)itms.FetchAt(i);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_category, page.Ttl_wo_ns());
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_category, page.Ttl_page_db());
byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
byte[] lnki_href = href_parser.Build_to_bry(wiki, ttl);
byte[] lnki_ttl = ttl.Full_txt();

View File

@@ -73,7 +73,7 @@ class Xoctg_pagelist_mgr_fxt {
Xodb_page page = new Xodb_page();
Xodb_category_itm ctg_xtn = Xodb_category_itm.load_(0, 0, hidden, 0, 0, 0);
page.Xtn_(ctg_xtn);
page.Ttl_wo_ns_(Bry_.new_ascii_(ttl));
page.Ttl_page_db_(Bry_.new_ascii_(ttl));
init_ctgs.AddMany(page);
}
} private ListAdp init_ctgs = ListAdp_.new_();

View File

@@ -52,7 +52,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
}
public boolean Load_by_ttl(Xodb_page rv, Xow_ns ns, byte[] ttl) {return db_mgr.Tbl_page().Select_by_ttl(rv, ns, ttl);}
public void Load_by_ttls(Cancelable cancelable, OrderedHash rv, boolean fill_idx_fields_only, int bgn, int end) {db_mgr.Tbl_page().Select_by_ttl_in(cancelable, rv, db_mgr.Db_ctx(), fill_idx_fields_only, bgn, end);}
public void Load_page(Xodb_page rv, Xow_ns ns, boolean timestamp_enabled) {rv.Text_(db_mgr.Tbl_text().Select(rv.Text_db_id(), rv.Id()));}
public void Load_page(Xodb_page rv, Xow_ns ns, boolean timestamp_enabled) {rv.Wtxt_(db_mgr.Tbl_text().Select(rv.Wtxt_db_id(), rv.Id()));}
public boolean Load_by_id (Xodb_page rv, int id) {return db_mgr.Tbl_page().Select_by_id(rv, id);}
public void Load_by_ids(Cancelable cancelable, ListAdp rv, int bgn, int end) {db_mgr.Tbl_page().Select_by_id_list(cancelable, false, rv, bgn, end);}
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
@@ -98,9 +98,9 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
view_grp = rv.Grp_by_tid(cur_tid);
prv_tid = cur_tid;
}
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, db_page.Ns_id(), db_page.Ttl_wo_ns());
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, db_page.Ns_id(), db_page.Ttl_page_db());
Xoctg_view_itm view_itm = new Xoctg_view_itm().Sortkey_(db_ctg.Sortkey()).Ttl_(ttl);
view_itm.Load_by_ttl_data(cur_tid, db_page.Id(), Xodb_page.Timestamp_null, db_page.Text_len());
view_itm.Load_by_ttl_data(cur_tid, db_page.Id(), Xodb_page.Modified_on_null_int, db_page.Wtxt_len());
view_grp.Itms_add(view_itm);
}
len = Xoa_ctg_mgr.Tid__max;
@@ -154,7 +154,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
for (int i = 0; i < len; i++) {
Xodb_page page = new Xodb_page();
byte[] ttl = Xoa_ttl.Replace_spaces(ctg_ttls[i]); // NOTE: ctg_ttls has spaces since v1 rendered it literally;
page.Ttl_wo_ns_(ttl);
page.Ttl_page_db_(ttl);
if (!hash.Has(ttl))
hash.Add(ttl, page);
}

View File

@@ -51,7 +51,7 @@ class Xodb_load_mgr_sql_fxt {
public Xodb_page[] pages_(Xodb_page... ary) {return ary;}
public Xodb_page ctg_(int id, String ttl, boolean hidden, int count_subcs, int count_files, int count_pages) {
Xodb_page rv = new Xodb_page().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_wo_ns_(Bry_.new_ascii_(ttl));
Xodb_page rv = new Xodb_page().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_page_db_(Bry_.new_ascii_(ttl));
Xodb_category_itm ctg = Xodb_category_itm.load_(id, 0, hidden, count_subcs, count_files, count_pages);
rv.Xtn_(ctg);
return rv;
@@ -66,7 +66,7 @@ class Xodb_load_mgr_sql_fxt {
DateAdp modified = DateAdp_.Now();
for (int i = 0; i < len; i++) {
Xodb_page page = ary[i];
db_mgr.Tbl_page().Insert(page_stmt, page.Id(), page.Ns_id(), page.Ttl_wo_ns(), false, modified, 10, page.Id(), 0, 0);
db_mgr.Tbl_page().Insert(page_stmt, page.Id(), page.Ns_id(), page.Ttl_page_db(), false, modified, 10, page.Id(), 0, 0);
Xodb_category_itm ctg_itm = (Xodb_category_itm)page.Xtn();
db_mgr.Tbl_category().Insert(category_stmt, ctg_itm.Id(), ctg_itm.Count_pages(), ctg_itm.Count_subcs(), ctg_itm.Count_files(), Bool_.Xto_byte(ctg_itm.Hidden()), 0);
}
@@ -76,7 +76,7 @@ class Xodb_load_mgr_sql_fxt {
int len = ary.length;
byte[][] ttls = new byte[len][];
for (int i = 0; i < len; i++) {
ttls[i] = ary[i].Ttl_wo_ns();
ttls[i] = ary[i].Ttl_page_db();
}
Xodb_page[] actl = wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_list(ttls);
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(actl));
@@ -88,7 +88,7 @@ class Xodb_load_mgr_sql_fxt {
Xodb_page page = ary[i];
Xodb_category_itm ctg_itm = (Xodb_category_itm)page.Xtn();
bfr.Add_int_variable(page.Id()).Add_byte_pipe();
bfr.Add(page.Ttl_wo_ns()).Add_byte_pipe();
bfr.Add(page.Ttl_page_db()).Add_byte_pipe();
bfr.Add_byte(Bool_.Xto_byte(ctg_itm.Hidden())).Add_byte_nl();
}
return bfr.Xto_str_and_clear();
@@ -146,7 +146,7 @@ class Xodb_load_mgr_sql_fxt {
String[] rv = new String[len];
for (int i = 0; i< len; i++) {
Xodb_page itm = (Xodb_page)list.FetchAt(i);
rv[i] = String_.new_ascii_(itm.Ttl_wo_ns());
rv[i] = String_.new_ascii_(itm.Ttl_page_db());
}
return rv;
}
@@ -185,7 +185,7 @@ class Xoctg_mok_ctg {
Xoctg_page_xtn db_ctg = new Xoctg_page_xtn(ctg_tid, ttl);
Xodb_page page = new Xodb_page();
int page_id = next_id.Val_add_post();
page.Id_(page_id).Ns_id_(ns_id).Ttl_wo_ns_(ttl).Xtn_(db_ctg);
page.Id_(page_id).Ns_id_(ns_id).Ttl_page_db_(ttl).Xtn_(db_ctg);
grp.Itms().Add(page);
}
grp.Last_plus_one_sortkey_(Bry_.new_ascii_(last_itm_plus_one_sortkey));

View File

@@ -24,7 +24,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
} private Xowe_wiki wiki; Xotdb_fsys_mgr fsys_mgr;
Xob_xdat_file tmp_xdat_file = new Xob_xdat_file(); Xob_xdat_itm tmp_xdat_itm = new Xob_xdat_itm();
public void Load_init (Xowe_wiki wiki) {}
public void Load_page(Xodb_page rv, Xow_ns ns, boolean timestamp_enabled) {Load_page(rv, rv.Text_db_id(), rv.Db_row_idx(), ns, timestamp_enabled, tmp_xdat_file, tmp_xdat_itm);}
public void Load_page(Xodb_page rv, Xow_ns ns, boolean timestamp_enabled) {Load_page(rv, rv.Wtxt_db_id(), rv.Tdb_row_idx(), ns, timestamp_enabled, tmp_xdat_file, tmp_xdat_itm);}
public void Load_page(Xodb_page rv, int txt_fil_idx, int txt_row_idx, Xow_ns ns, boolean timestamp_enabled, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm) {
Io_url file = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns.Id(), txt_fil_idx);
byte[] bry = gplx.ios.Io_stream_rdr_.Load_all(file); int bry_len = bry.length;
@@ -36,13 +36,13 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
if (!Load_xdat_itm(tmp_xdat_itm, ns, Xotdb_dir_info_.Tid_ttl, ttl, Xodb_page_.Txt_ttl_pos, Byte_ascii.Tab, true)) return false;
Xodb_page_.Txt_ttl_load(rv, tmp_xdat_itm.Itm_bry());
rv.Exists_(true);
return Bry_.Eq(rv.Ttl_wo_ns(), ttl);
return Bry_.Eq(rv.Ttl_page_db(), ttl);
}
public void Load_by_ttls(Cancelable cancelable, OrderedHash rv, boolean fill_idx_fields_only, int bgn, int end) {// NOTE: Load_by_ttls just a wrapper around Load_by_ttl; for xdat, Load_by_ttl is fast enough
for (int i = bgn; i < end; i++) {
if (cancelable.Canceled()) return;
Xodb_page page = (Xodb_page)rv.FetchAt(i);
Load_by_ttl(page, page.Ns(), page.Ttl_wo_ns());
Load_by_ttl(page, page.Ns(), page.Ttl_page_db());
}
}
public void Load_by_ids(Cancelable cancelable, ListAdp list, int bgn, int end) {
@@ -60,7 +60,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
prv_fil_idx = cur_fil_idx;
}
if (!this.Load_by_id(tmp_page, tmp_xdat_file, id_bry)) continue; // id not found in file; ignore
itm.Ns_id_(tmp_page.Ns_id()).Ttl_wo_ns_(tmp_page.Ttl_wo_ns());
itm.Ns_id_(tmp_page.Ns_id()).Ttl_page_db_(tmp_page.Ttl_page_db());
msg_wtr.Write_prog_cur(i, wiki.Appe().Usr_dlg());
}
} Xodb_page tmp_page = new Xodb_page();
@@ -115,7 +115,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
int page_id = Base85_utl.XtoIntByAry(raw, pos, pos + 4);
pos += 6; // 5 + 1 for semic;
int page_len = Base85_utl.XtoIntByAry(raw, pos, pos + 4);
rv.Add(Xodb_page.srch_(page_id, page_len));
rv.Add(Xodb_page.new_srch(page_id, page_len));
pos += 6; // 5 + 1 for pipe
// if (match.Itms_len() == max_results) break;
}
@@ -259,7 +259,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
Xob_random_itm file = files[file_idx];
tmp_xdat_file.GetAt(tmp_xdat_itm, random_idx - file.Bgn()); // get nth row; EX: random_idx=120; .Bgn=103 -> get 17th
Xodb_page page = Xodb_page_.Txt_ttl_load(tmp_xdat_itm.Itm_bry());
return page.Ttl_wo_ns();
return page.Ttl_page_db();
}
private static Xob_random_itm[] Build_random_itms(Xowd_regy_mgr mgr, Int_obj_ref count) {
// convert regy to list of random_itms (similar to regy_itms, but has integer bgn / end; EX: [0]:0,50; [1]:51-102; [2]:103-130)
@@ -299,7 +299,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
Xodb_page itm = (Xodb_page)ctgs.FetchAt(i);
byte itm_tid = Load_ctg_v1_tid(itm.Ns_id());
Xoctg_view_itm sub = Load_ctg_v1_sub(itm_tid, itm);
sub.Ttl_(Xoa_ttl.parse_(wiki, itm.Ns_id(), itm.Ttl_wo_ns())).Sortkey_(itm.Ttl_wo_ns());
sub.Ttl_(Xoa_ttl.parse_(wiki, itm.Ns_id(), itm.Ttl_page_db())).Sortkey_(itm.Ttl_page_db());
view_ctg.Grp_by_tid(itm_tid).Itms_add(sub);
}
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
@@ -342,7 +342,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
}
private static Xoctg_view_itm Load_ctg_v1_sub(byte tid, Xodb_page data) {
Xoctg_view_itm rv = new Xoctg_view_itm();
rv.Load_by_ttl_data(tid, data.Id(), 0, data.Text_len());
rv.Load_by_ttl_data(tid, data.Id(), 0, data.Wtxt_len());
return rv;
}
@@ -355,7 +355,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
}
int name_bgn = timestamp_end + 1;
int name_end = Bry_finder.Find_fwd(src, Xodb_page_.Txt_page_dlm, name_bgn, src_len);
page.Text_(Bry_.Mid(src, name_end + 1, row_end - 1)); // +1 to skip dlm
page.Wtxt_(Bry_.Mid(src, name_end + 1, row_end - 1)); // +1 to skip dlm
}
Xowd_regy_mgr Get_regy_by_site(byte regy_tid) {
Xowd_regy_mgr rv = site_regys[regy_tid];
@@ -410,7 +410,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
for (; row_idx < rows_len; row_idx++) {
xdat_file.GetAt(xdat_itm, row_idx);
Xodb_page ttl_itm = Xodb_page_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Type_redirect()) continue;
if (!include_redirects && ttl_itm.Redirected()) continue;
++count;
nxt_itm = ttl_itm;
if (count == total) {
@@ -449,7 +449,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
for (; row_idx > -1; row_idx--) {
xdat_file.GetAt(xdat_itm, row_idx);
Xodb_page ttl_itm = Xodb_page_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Type_redirect()) continue;
if (!include_redirects && ttl_itm.Redirected()) continue;
// list.Add(ttl_itm);
++count;
prv_itm = ttl_itm;
@@ -525,8 +525,8 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
Xodb_page page = new Xodb_page();
this.Load_by_ttl(page, ns, ttl);
Load_ctg_v2_main(ctg_temp, page.Ttl_wo_ns());
Xodb_category_itm ctg_itm = Xodb_category_itm.load_(page.Id(), page.Text_db_id(), ctg_temp.Hidden(), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_subc), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_file), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_page));
Load_ctg_v2_main(ctg_temp, page.Ttl_page_db());
Xodb_category_itm ctg_itm = Xodb_category_itm.load_(page.Id(), page.Wtxt_db_id(), ctg_temp.Hidden(), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_subc), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_file), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_page));
page.Xtn_(ctg_itm);
rv[i] = page;
}

View File

@@ -93,7 +93,7 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
tbl_text.Insert(text_stmt, page_id, text, data_storage_format);
}
public boolean Ctg_select_v1(Xoctg_view_ctg view_ctg, Db_conn ctg_provider, Xodb_category_itm ctg) {
Db_qry_select qry = Db_qry_.select_().Cols_(Xodb_categorylinks_tbl.Fld_cl_from)
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(Xodb_categorylinks_tbl.Fld_cl_from)
.From_(Xodb_categorylinks_tbl.Tbl_name)
.Where_(Db_crt_.eq_(Xodb_categorylinks_tbl.Fld_cl_to_id, ctg.Id()))
;
@@ -118,9 +118,9 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
byte ctg_tid = Xodb_load_mgr_txt.Load_ctg_v1_tid(page.Ns_id());
Xoctg_view_grp ctg_grp = view_ctg.Grp_by_tid(ctg_tid);
Xoctg_view_itm ctg_itm = new Xoctg_view_itm();
ctg_itm.Load_by_ttl_data(ctg_tid, page.Id(), 0, page.Text_len());
ctg_itm.Ttl_(Xoa_ttl.parse_(wiki, page.Ns_id(), page.Ttl_wo_ns()));
ctg_itm.Sortkey_(page.Ttl_wo_ns());
ctg_itm.Load_by_ttl_data(ctg_tid, page.Id(), 0, page.Wtxt_len());
ctg_itm.Ttl_(Xoa_ttl.parse_(wiki, page.Ns_id(), page.Ttl_page_db()));
ctg_itm.Sortkey_(page.Ttl_page_db());
ctg_grp.Itms_add(ctg_itm);
rv = true;
}

View File

@@ -80,7 +80,7 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
Xodb_page db_page = new Xodb_page();
db_mgr.Load_mgr().Load_by_id(db_page, page.Revision_data().Id());
text = zip_mgr.Zip(db_mgr.Data_storage_format(), text);
db_mgr.Tbl_text().Update(db_page.Text_db_id(), page.Revision_data().Id(), text);
db_mgr.Tbl_text().Update(db_page.Wtxt_db_id(), page.Revision_data().Id(), text);
}
public void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl) {
Db_qry qry = Db_qry_.update_common_("page", Db_crt_.eq_("page_id", page.Revision_data().Id())

View File

@@ -30,7 +30,7 @@ public class Xodb_save_mgr_txt implements Xodb_save_mgr {
public void Clear() {page_id_next = 0;} // TEST: needed for ctg_test
public void Data_create(Xoa_ttl ttl, byte[] text) {
Xow_ns ns_itm = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
Xodb_page db_page = Xodb_page.tmp_();
Xodb_page db_page = Xodb_page.new_tmp();
boolean found = load_mgr.Load_by_ttl(db_page, ns_itm, ttl_bry);
if (found) throw Err_mgr._.fmt_(GRP_KEY, "title_exists", "create requested but title already exists: ~{0}", String_.new_utf8_(ttl_bry));
int text_len = text.length;
@@ -50,7 +50,7 @@ public class Xodb_save_mgr_txt implements Xodb_save_mgr {
tmp_bfr.Mkr_rls();
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
db_page.Set_all_(page_id, fil_idx, row_idx, redirect_ttl != null, text_len, ttl.Page_db());
db_page.Init(page_id, ttl.Page_db(), redirect_ttl != null, text_len, fil_idx, row_idx);
Xodb_page_.Txt_ttl_save(tmp, db_page);
byte[] ttl_row_bry = tmp.Mkr_rls().Xto_bry_and_clear();
Xowd_hive_mgr ttl_hive = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_ttl);
@@ -68,18 +68,18 @@ public class Xodb_save_mgr_txt implements Xodb_save_mgr {
private void Data_update_under(Xoae_page page, byte[] text, byte[] new_ttl) {
Xoa_ttl ttl = page.Ttl();
Xow_ns ns = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
Xodb_page db_page = Xodb_page.tmp_();
Xodb_page db_page = Xodb_page.new_tmp();
if (!load_mgr.Load_by_ttl(db_page, ns, ttl_bry)) throw Err_mgr._.fmt_(GRP_KEY, "title_missing", "update requested but title does not exist: ~{0}", String_.new_utf8_(ttl_bry));
byte[] old_ttl = ttl_bry;
if (new_ttl != null) {
ttl_bry = new_ttl;
db_page.Ttl_wo_ns_(new_ttl);
db_page.Ttl_page_db_(new_ttl);
}
// update page
Xob_xdat_file page_rdr = new Xob_xdat_file(); Xob_xdat_itm page_itm = new Xob_xdat_itm();
load_mgr.Load_page(tmp_page, db_page.Text_db_id(), db_page.Db_row_idx(), ns, true, page_rdr, page_itm);
load_mgr.Load_page(tmp_page, db_page.Wtxt_db_id(), db_page.Tdb_row_idx(), ns, true, page_rdr, page_itm);
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
if (text == null) text = tmp_page.Text();
if (text == null) text = tmp_page.Wtxt();
int text_len = text.length;
DateAdp modified_on = tmp_page.Modified_on();
if (update_modified_on_enabled) {
@@ -88,13 +88,13 @@ public class Xodb_save_mgr_txt implements Xodb_save_mgr {
}
Xodb_page_.Txt_page_save(tmp_bfr, db_page.Id(), modified_on, ttl_bry, text, true);
page_rdr.Update(tmp_bfr, page_itm, tmp_bfr.Xto_bry_and_clear());
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ttl.Ns().Id(), db_page.Text_db_id());
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ttl.Ns().Id(), db_page.Wtxt_db_id());
this.Data_save(Xotdb_dir_info_.Tid_page, page_rdr, page_rdr_url, tmp_bfr);
tmp_bfr.Mkr_rls();
// update ttl
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
db_page.Text_len_(text_len);
db_page.Type_redirect_(redirect_ttl != null);
db_page.Wtxt_len_(text_len);
db_page.Redirected_(redirect_ttl != null);
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_b512();
Xodb_page_.Txt_ttl_save(tmp, db_page);
byte[] ttl_row_bry = tmp.Xto_bry_and_clear();

View File

@@ -43,7 +43,7 @@ public class Xodb_categorylinks_tbl {
gplx.core.criterias.Criteria comp_crt = !arg_is_from
? Db_crt_.mte_(Fld_cl_sortkey, arg_sortkey_str) // from: sortkey >= 'val'
: Db_crt_.lte_(Fld_cl_sortkey, arg_sortkey_str); // until: sortkey <= 'val'
Db_qry_select qry = Db_qry_.select_().Cols_(Fld_cl_from, Fld_cl_sortkey).From_(Tbl_name)
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(Fld_cl_from, Fld_cl_sortkey).From_(Tbl_name)
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_cl_to_id, -1), Db_crt_.eq_(Fld_cl_type_id, arg_tid), comp_crt))
.OrderBy_(Fld_cl_sortkey, !arg_is_from)
.Limit_(limit + 1); // + 1 to get last_plus_one for next page / previous page

View File

@@ -51,10 +51,10 @@ class Xodb_in_wkr_page_title extends Xodb_in_wkr_page_base {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int(in_ns);
stmt.Val_bry_as_str(page.Ttl_wo_ns());
stmt.Val_bry_as_str(page.Ttl_page_db());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_wo_ns());}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_page_db());}
}
class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
private Xow_ns_mgr ns_mgr;
@@ -73,15 +73,15 @@ class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int(page.Ns_id());
stmt.Val_bry_as_str(page.Ttl_wo_ns());
stmt.Val_bry_as_str(page.Ttl_page_db());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {
Xow_ns ns = ns_mgr.Ids_get_or_null(rdr_page.Ns_id());
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
byte[] ttl_wo_ns = rdr_page.Ttl_wo_ns();
byte[] ttl_wo_ns = rdr_page.Ttl_page_db();
rdr_page.Ttl_(ns, ttl_wo_ns);
return (Xodb_page)hash.Fetch(rdr_page.Ttl_w_ns());
return (Xodb_page)hash.Fetch(rdr_page.Ttl_full_db());
}
}
abstract class Xodb_in_wkr_page_base extends Xodb_in_wkr_base {

View File

@@ -35,7 +35,7 @@ public class Xodb_page_tbl {
public boolean Select_by_ttl(Xodb_page rv, Xow_ns ns, byte[] ttl) {
Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null;
try {
stmt = Db_stmt_.new_select_as_rdr(conn, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_ns, Fld_page_title), html_db_enabled ? Select_by_id_flds__hdump : Select_by_id_flds__basic));
stmt = Db_stmt_.new_select_as_rdr(conn, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_ns, Fld_page_title), html_db_enabled ? Select_by_id_flds__hdump : Select_by_id_flds__basic, Db_qry__select_in_tbl.Order_by_null));
rdr = stmt.Val_int(ns.Id()).Val_str(String_.new_utf8_(ttl)).Exec_select_as_rdr();
if (rdr.Move_next()) {
Read_page__all2(rv, rdr, html_db_enabled);
@@ -45,17 +45,22 @@ public class Xodb_page_tbl {
return false;
}
public static void Read_page__all2(Xodb_page page, Db_rdr rdr, boolean html_db_enabled) {
page.Id_ (rdr.Read_int(Fld_page_id));
page.Ns_id_ (rdr.Read_int(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.Read_bry_by_str(Fld_page_title));
page.Modified_on_ (DateAdp_.parse_fmt(rdr.Read_str(Fld_page_touched), Page_touched_fmt));
page.Type_redirect_ (rdr.Read_byte(Fld_page_is_redirect) == 1);
page.Text_len_ (rdr.Read_int(Fld_page_len));
page.Text_db_id_ (rdr.Read_int(Fld_page_file_idx));
int html_db_id = -1, redirected_id = -1;
if (html_db_enabled) {
page.Html_db_id_(rdr.Read_int(Fld_page_html_db_id));
page.Redirect_id_(rdr.Read_int(Fld_page_is_redirect));
html_db_id = rdr.Read_int(Fld_page_html_db_id);
redirected_id = rdr.Read_int(Fld_page_redirect_id);
}
page.Init_by_sql
( rdr.Read_int(Fld_page_id)
, rdr.Read_int(Fld_page_ns)
, rdr.Read_bry_by_str(Fld_page_title)
, DateAdp_.parse_fmt(rdr.Read_str(Fld_page_touched), Page_touched_fmt)
, rdr.Read_bool_by_byte(Fld_page_is_redirect)
, rdr.Read_int(Fld_page_len)
, rdr.Read_int(Fld_page_file_idx)
, html_db_id
, redirected_id
);
}
public boolean Select_by_id(Xodb_page rv, int page_id) {
DataRdr rdr = DataRdr_.Null;
@@ -103,7 +108,7 @@ public class Xodb_page_tbl {
stmt.Exec_insert();
}
public DataRdr Select_all(Db_conn p) {
Db_qry_select qry = Db_qry_select.new_().From_(Tbl_name).Cols_(Fld_page_id, Fld_page_title).OrderBy_asc_(Fld_page_id);
Db_qry__select_cmd qry = Db_qry__select_cmd.new_().From_(Tbl_name).Cols_(Fld_page_id, Fld_page_title).OrderBy_asc_(Fld_page_id);
return p.Exec_qry_as_rdr(qry);
}
private DataRdr Load_ttls_starting_with_rdr(int ns_id, byte[] ttl_frag, boolean include_redirects, int max_results, int min_page_len, int browse_len, boolean fwd, boolean search_suggest) {
@@ -113,7 +118,7 @@ public class Xodb_page_tbl {
crt = Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, Byte_.Zero));
String[] cols = search_suggest ? Flds_select_idx : html_db_enabled ? Flds_select_all__html_y : Flds_select_all__html_n;
int limit = fwd ? max_results + 1 : max_results; // + 1 to get next item
Db_qry_select select = Db_qry_.select_cols_(Tbl_name, crt, cols).Limit_(limit).OrderBy_(Fld_page_title, fwd);
Db_qry__select_cmd select = Db_qry_.select_cols_(Tbl_name, crt, cols).Limit_(limit).OrderBy_(Fld_page_title, fwd);
return select.Exec_qry_as_rdr(conn);
}
public void Load_ttls_for_all_pages(Cancelable cancelable, ListAdp rslt_list, Xodb_page rslt_nxt, Xodb_page rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
@@ -127,7 +132,7 @@ public class Xodb_page_tbl {
if (cancelable.Canceled()) return;
Xodb_page page = new Xodb_page();
Read_page__idx(page, rdr);
if (max_val_check && !Bry_.HasAtBgn(page.Ttl_wo_ns(), key)) break;
if (max_val_check && !Bry_.HasAtBgn(page.Ttl_page_db(), key)) break;
nxt_itm = page;
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
else {
@@ -211,7 +216,7 @@ public class Xodb_page_tbl {
public void Select_by_search(Cancelable cancelable, ListAdp rv, byte[] search, int results_max) {
if (Bry_.Len_eq_0(search)) return; // do not allow empty search
Criteria crt = gplx.core.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, Xow_ns_.Id_main), Db_crt_.like_(Fld_page_title, ""));
Db_qry_select qry = Db_qry_.select_().From_(Tbl_name).Cols_(Fld_page_id, Fld_page_len, Fld_page_ns, Fld_page_title).Where_(crt); // NOTE: use fields from main index only
Db_qry__select_cmd qry = Db_qry_.select_().From_(Tbl_name).Cols_(Fld_page_id, Fld_page_len, Fld_page_ns, Fld_page_title).Where_(crt); // NOTE: use fields from main index only
DataRdr rdr = DataRdr_.Null;
Db_stmt stmt = Db_stmt_.Null;
search = Bry_.Replace(search, Byte_ascii.Asterisk, Byte_ascii.Percent);
@@ -223,8 +228,8 @@ public class Xodb_page_tbl {
Xodb_page page = new Xodb_page();
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Text_len_ (rdr.ReadInt(Fld_page_len));
page.Ttl_page_db_ (rdr.ReadBryByStr(Fld_page_title));
page.Wtxt_len_ (rdr.ReadInt(Fld_page_len));
rv.Add(page);
}
} finally {rdr.Rls(); stmt.Rls();}
@@ -239,7 +244,7 @@ public class Xodb_page_tbl {
Criteria crt = gplx.core.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, -1), Db_crt_.mt_(Fld_page_title, ""));
if (redirect != Bool_.__byte)
crt = gplx.core.criterias.Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, redirect));
Db_qry_select qry = Db_qry_.select_().From_(Tbl_name).Cols_(html_db_enabled ? Flds_select_all__html_y : Flds_select_all__html_n)
Db_qry__select_cmd qry = Db_qry_.select_().From_(Tbl_name).Cols_(html_db_enabled ? Flds_select_all__html_y : Flds_select_all__html_n)
.Where_(crt)
.Limit_(limit);
return p.Stmt_new(qry);
@@ -286,22 +291,27 @@ public class Xodb_page_tbl {
;
public static final boolean Load_idx_flds_only_y = true;
public static void Read_page__all(Xodb_page page, DataRdr rdr, boolean html_db_enabled) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Modified_on_ (DateAdp_.parse_fmt(rdr.ReadStr(Fld_page_touched), Page_touched_fmt));
page.Type_redirect_ (rdr.ReadByte(Fld_page_is_redirect) == 1);
page.Text_len_ (rdr.ReadInt(Fld_page_len));
page.Text_db_id_ (rdr.ReadInt(Fld_page_file_idx));
int html_db_id = -1, redirected_id = -1;
if (html_db_enabled) {
page.Html_db_id_(rdr.ReadInt(Fld_page_html_db_id));
page.Redirect_id_(rdr.ReadInt(Fld_page_redirect_id));
html_db_id = rdr.ReadInt(Fld_page_html_db_id);
redirected_id = rdr.ReadInt(Fld_page_redirect_id);
}
page.Init_by_sql
( rdr.ReadInt(Fld_page_id)
, rdr.ReadInt(Fld_page_ns)
, rdr.ReadBryByStr(Fld_page_title)
, DateAdp_.parse_fmt(rdr.ReadStr(Fld_page_touched), Page_touched_fmt)
, rdr.ReadByte(Fld_page_is_redirect) == 1
, rdr.ReadInt(Fld_page_len)
, rdr.ReadInt(Fld_page_file_idx)
, html_db_id
, redirected_id
);
}
public static void Read_page__idx(Xodb_page page, DataRdr rdr) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Text_len_ (rdr.ReadInt(Fld_page_len));
page.Ttl_page_db_ (rdr.ReadBryByStr(Fld_page_title));
page.Wtxt_len_ (rdr.ReadInt(Fld_page_len));
}
}

View File

@@ -28,7 +28,7 @@ public class Xodb_search_title_word_tbl {
.Exec_insert();
}
public static void Select_by_word(Cancelable cancelable, ListAdp rv, Xodb_ctx db_ctx, byte[] search, int results_max, Db_conn p) {
Db_qry_select qry = Db_qry_.select_()
Db_qry__select_cmd qry = Db_qry_.select_()
.Cols_(Xodb_search_title_word_tbl.Fld_stw_word_id)
.From_(Xodb_search_title_word_tbl.Tbl_name, "w")
;

View File

@@ -51,7 +51,7 @@ public class Xodb_text_tbl {
ListAdp pages = ListAdp_.new_();
for (int i = 0; i < len; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
if (page.Text_db_id() == file.Id())
if (page.Wtxt_db_id() == file.Id())
pages.Add(page);
}
len = pages.Count();
@@ -74,7 +74,7 @@ public class Xodb_text_tbl {
byte[] old_text = rdr.ReadBry(Fld_old_text);
old_text = zip_mgr.Unzip(db_mgr.Data_storage_format(), old_text);
Xodb_page page = (Xodb_page)hash.Fetch(Int_obj_val.new_(page_id));
page.Text_(old_text);
page.Wtxt_(old_text);
}
} finally {rdr.Rls(); stmt.Rls();}
}

View File

@@ -40,7 +40,7 @@ public class Xodb_xowa_cfg_tbl {
public int Select_val_as_int(String grp, String key) {return Int_.parse_(Select_val(grp, key));}
public String Select_val(String grp, String key) {return Select_val_or(grp, key, null);}
public String Select_val_or(String grp, String key, String or) {
Db_qry_select qry = Db_qry_.select_val_(Tbl_name, Fld_cfg_val, Where_grp_key(grp, key));
Db_qry__select_cmd qry = Db_qry_.select_val_(Tbl_name, Fld_cfg_val, Where_grp_key(grp, key));
String rv = (String)qry.ExecRdr_val(conn);
return rv == null ? or : rv;
}

View File

@@ -72,7 +72,7 @@ public class Xof_ext_ {
private static final Xof_ext[] Ary = new Xof_ext[Id__max];
public static byte[] Get_ext_by_id_(int id) {
if (id < 0 || id >= Id__max) throw Err_.new_fmt_("index out of bounds; {id}", id);
if (id < 0 || id >= Id__max) throw Err_.new_fmt_("index out of bounds; {0}", id);
return Bry__ary[id];
}
public static int Get_id_by_ext_(byte[] ext_bry) {

View File

@@ -20,19 +20,24 @@ public interface Xof_file_itm {
byte[] Lnki_ttl();
byte[] Lnki_md5();
Xof_ext Lnki_ext();
// byte[] Lnki_redirect();
byte Lnki_type();
int Lnki_w();
int Lnki_h();
double Lnki_upright();
double Lnki_time();
int Lnki_page();
byte Orig_repo_id();
byte[] Orig_repo_name();
byte[] Orig_ttl();
int Orig_ext();
int Orig_w();
int Orig_h();
// byte Orig_repo();
byte[] Orig_redirect();
boolean Img_is_thumbable();
int File_w();
int Html_uid();
byte Html_elem_tid();
int Html_w();
int Html_h();
// Io_url Html_url();
int Gallery_mgr_h();
}

View File

@@ -0,0 +1,136 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.threads.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
import gplx.xowa.html.hdumps.core.*;
class Xof_redlink_wkr implements Gfo_thread_wkr {
private Xog_js_wkr js_wkr; private int[] uids;
public Xof_redlink_wkr(Xog_js_wkr js_wkr, int[] uids) {
this.js_wkr = js_wkr; this.uids = uids;
}
public String Name() {return "xowa.redlinks";}
public boolean Resume() {return true;}
public void Exec() {
int len = uids.length;
for (int i = 0; i < len; ++i) {
int uid = uids[i];
js_wkr.Html_atr_set(Int_.Xto_str(uid), "", "");
}
}
}
public class Xof_file_wkr implements Gfo_thread_wkr {
private final Xof_orig_mgr orig_mgr; private final Xof_bin_mgr bin_mgr; private final Fsm_mnt_mgr mnt_mgr; private final Xof_cache_mgr cache_mgr;
private final Gfo_usr_dlg usr_dlg; private final Xow_repo_mgr repo_mgr; private final Xog_js_wkr js_wkr;
private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_(); private final Xof_img_size img_size = new Xof_img_size();
private final Xoa_page hpg; private final ListAdp imgs; private final byte exec_tid;
public Xof_file_wkr(Xof_orig_mgr orig_mgr, Xof_bin_mgr bin_mgr, Fsm_mnt_mgr mnt_mgr, Xof_cache_mgr cache_mgr, Xow_repo_mgr repo_mgr, Xog_js_wkr js_wkr, Xoa_page hpg, ListAdp imgs, byte exec_tid) {
this.orig_mgr = orig_mgr; this.bin_mgr = bin_mgr; this.mnt_mgr = mnt_mgr; this.cache_mgr = cache_mgr;
this.usr_dlg = Gfo_usr_dlg_._; this.repo_mgr = repo_mgr; this.js_wkr = js_wkr;
this.hpg = hpg; this.imgs = imgs; this.exec_tid = exec_tid;
}
public String Name() {return "xowa.load_imgs";}
public boolean Resume() {return true;}
public void Exec() {
int len = imgs.Count();
for (int i = 0; i < len; ++i)
Ctor_by_hdump(exec_tid, hpg, (Xohd_data_itm__base)imgs.FetchAt(i));
}
private void Ctor_by_hdump(byte exec_tid, Xoa_page hpg, Xohd_data_itm__base hdump) {
Xof_fsdb_itm fsdb = new Xof_fsdb_itm();
fsdb.Ctor_by_lnki(hdump.Lnki_ttl(), hdump.Lnki_type(), hdump.Lnki_w(), hdump.Lnki_h(), Xof_patch_upright_tid_.Tid_all, hdump.Lnki_upright(), hdump.Lnki_time(), hdump.Lnki_page());
fsdb.Lnki_ext_(Xof_ext_.new_by_id_(hdump.Lnki_ext()));
fsdb.Html_uid_(hdump.Html_uid());
fsdb.Orig_exists_n_();
Xof_orig_itm orig = orig_mgr.Find_by_ttl_or_null(fsdb.Lnki_ttl()); if (orig == Xof_orig_itm.Null) return;
Eval_orig(exec_tid, orig, fsdb, url_bldr, repo_mgr, img_size);
Show_img(exec_tid, fsdb, usr_dlg, bin_mgr, mnt_mgr, cache_mgr, repo_mgr, js_wkr, img_size, url_bldr, hpg);
}
public static void Show_img(byte exec_tid, Xof_fsdb_itm fsdb, Gfo_usr_dlg usr_dlg, Xof_bin_mgr bin_mgr, Fsm_mnt_mgr mnt_mgr, Xof_cache_mgr cache_mgr, Xow_repo_mgr repo_mgr, Xog_js_wkr js_wkr, Xof_img_size img_size, Xof_url_bldr url_bldr, Xoa_page hpg) {
try {
if (fsdb.Orig_ext() < 0) {
usr_dlg.Warn_many("", "", "file.missing.ext: file=~{0} width=~{1} page=~{2}", fsdb.Lnki_ttl(), fsdb.Lnki_w(), hpg.Ttl().Full_db());
return;
}
Xof_repo_pair repo_pair = null;
switch (fsdb.Orig_repo_id()) {
case Xof_repo_itm.Repo_local:
case Xof_repo_itm.Repo_remote:
repo_pair = repo_mgr.Repos_get_by_id(fsdb.Orig_repo_id());
break;
}
if (repo_pair == null) {
usr_dlg.Warn_many("", "", "file.missing.repo: file=~{0} width=~{1} page=~{2}", fsdb.Lnki_ttl(), fsdb.Lnki_w(), hpg.Ttl().Full_db());
return;
}
Xof_repo_itm repo = repo_pair.Trg();
fsdb.Ctor_for_html(exec_tid, img_size, repo, url_bldr);
if (fsdb.Lnki_ext().Is_not_viewable(exec_tid)) return; // file not viewable; exit; EX: exec_tid = page and fsdb is audio
if (!Io_mgr._.ExistsFil(fsdb.Html_view_url())) {
if (bin_mgr.Find_to_url_as_bool(exec_tid, fsdb)) {
if (fsdb.Fsdb_insert()) Save_bin(fsdb, mnt_mgr);
}
else {
usr_dlg.Warn_many("", "", "file.missing.bin: file=~{0} width=~{1} page=~{2}", fsdb.Lnki_ttl(), fsdb.Lnki_w(), hpg.Ttl().Full_db());
fsdb.File_exists_n_();
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, fsdb.Html_uid()); // TODO: update caption with "" if image is missing
return;
}
}
Js_img_mgr.Update_img(hpg, js_wkr, fsdb);
cache_mgr.Reg_and_check_for_size_0(fsdb);
} catch (Exception e) {
usr_dlg.Warn_many("", "", "file.unknown: ~{0}", Err_.Message_gplx_brief(e));
}
}
public static void Eval_orig(byte exec_tid, Xof_orig_itm orig, Xof_fsdb_itm fsdb, Xof_url_bldr url_bldr, Xow_repo_mgr repo_mgr, Xof_img_size img_size) {
fsdb.Orig_exists_y_();
byte repo_id = orig.Repo();
Xof_repo_pair repo_pair = repo_mgr.Repos_get_by_id(repo_id);
Xof_repo_itm repo_itm = repo_pair.Trg();
fsdb.Ctor_by_orig(repo_id, repo_pair.Wiki_domain(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
fsdb.Ctor_for_html(exec_tid, img_size, repo_itm, url_bldr);
}
private static void Save_bin(Xof_fsdb_itm itm, Fsm_mnt_mgr mnt_mgr) {
Io_url html_url = itm.Html_view_url();
long bin_len = Io_mgr._.QueryFil(html_url).Size();
gplx.ios.Io_stream_rdr bin_rdr = gplx.ios.Io_stream_rdr_.file_(html_url);
try {
bin_rdr.Open();
mnt_mgr.Txn_open();
if (itm.Lnki_ext().Id_is_thumbable_img()) {
if (itm.File_is_orig())
mnt_mgr.Img_insert(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
else
mnt_mgr.Thm_insert(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), itm.Lnki_time(), itm.Lnki_page(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
else {
if (itm.Lnki_ext().Id_is_video() && !itm.File_is_orig()) // insert as thumbnail
mnt_mgr.Thm_insert(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), itm.Lnki_time(), itm.Lnki_page(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
else
mnt_mgr.Fil_insert(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
mnt_mgr.Txn_save();
}
catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to save file: ttl=~{0} url=~{1} err=~{2}", String_.new_utf8_(itm.Lnki_ttl()), html_url.Raw(), Err_.Message_gplx(e));
}
finally {bin_rdr.Rls();}
}
}

View File

@@ -19,19 +19,16 @@ package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
public class Xof_fsdb_mode {
private int tid;
Xof_fsdb_mode(int tid) {this.tid = tid;}
public boolean Tid_unknown() {return tid == Tid_int_unknown;}
public boolean Tid_wmf() {return tid == Tid_int_wmf;}
public boolean Tid_view() {return tid == Tid_int_view;}
public boolean Tid_make() {return tid == Tid_int_make;}
public void Tid_view_y_() {tid = Tid_int_view;}
public void Tid_make_y_() {tid = Tid_int_make;}
private static final int
Tid_int_unknown = 0
, Tid_int_wmf = 1
Tid_int_wmf = 1
, Tid_int_view = 2
, Tid_int_make = 3
;
// public static Xof_fsdb_mode new_unknown() {return new Xof_fsdb_mode(Tid_int_unknown);}
public static Xof_fsdb_mode new_wmf() {return new Xof_fsdb_mode(Tid_int_wmf);}
public static Xof_fsdb_mode new_view() {return new Xof_fsdb_mode(Tid_int_view);}
}

View File

@@ -20,96 +20,70 @@ import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.
import gplx.xowa.parsers.lnkis.*;
public class Xof_lnki_file_mgr {
private boolean page_init_needed = true;
private final ListAdp fsdb_list = ListAdp_.new_();
private final OrderedHash orig_regy = OrderedHash_.new_bry_(), xfer_list = OrderedHash_.new_bry_();
private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_(); private Xof_img_size tmp_img_size = new Xof_img_size();
private final ListAdp fsdb_list = ListAdp_.new_(); private final OrderedHash orig_regy = OrderedHash_.new_bry_(), fsdb_hash = OrderedHash_.new_bry_();
private final Xof_img_size img_size = new Xof_img_size(); private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_();
public void Clear() {
page_init_needed = true;
fsdb_list.Clear();
xfer_list.Clear();
orig_regy.Clear();
fsdb_list.Clear(); fsdb_hash.Clear(); orig_regy.Clear();
}
public boolean Find(Xowe_wiki wiki, Xoae_page page, byte exec_tid, Xof_xfer_itm xfer_itm) {
public boolean Find(Xowe_wiki wiki, Xoae_page page, byte exec_tid, Xof_xfer_itm xfer) {
try {
if (page_init_needed) {
page_init_needed = false;
wiki.File_mgr().Fsdb_mgr().Init_by_wiki(wiki); // NOTE: fsdb_mgr may not be init'd for wiki; assert that that it is
Create_xfer_itms(page.Lnki_list(), wiki.File_mgr().Patch_upright()); // NOTE: Patch_upright check must occur after Init_by_wiki; DATE:2014-05-31
wiki.File_mgr().Fsdb_mgr().Init_by_wiki(wiki); // NOTE: fsdb_mgr may not be init'd for wiki; assert that that it is
Make_fsdb_list(page.Lnki_list(), wiki.File_mgr().Patch_upright()); // NOTE: Patch_upright check must occur after Init_by_wiki; DATE:2014-05-31
wiki.File_mgr().Fsdb_mgr().Orig_mgr().Find_by_list(orig_regy, fsdb_list, exec_tid);
Hash_xfer_itms();
Make_fsdb_hash();
}
Xof_fsdb_itm fsdb_itm = (Xof_fsdb_itm)xfer_list.Fetch(xfer_itm.Lnki_ttl());
if (fsdb_itm == null) // no orig_data found for the current item
return false;
else {
if (fsdb_itm.Orig_repo_name() == null) return false; // itm not found; return now, else null exception later;
xfer_itm.Lnki_ext_(fsdb_itm.Lnki_ext()); // WORKAROUND: hacky, but fsdb_itm knows when ogg is ogv whereas xfer_itm does not; so, always override xfer_itm.ext with fsdb's; DATE:2014-02-02
xfer_itm.Url_bldr_(url_bldr); // default Url_bldr for xfer_itm uses @ for thumbtime; switch to -; DATE:2014-02-02
Init_fsdb_by_xfer(fsdb_itm, xfer_itm); // copy xfer itm props to fsdb_itm;
xfer_itm.Set__orig(fsdb_itm.Orig_w(), fsdb_itm.Orig_h(), xfer_itm.Orig_file_len()); // copy orig props from orig_itm to xfer_itm
Xof_repo_itm repo = wiki.File_mgr().Repo_mgr().Repos_get_by_wiki(fsdb_itm.Orig_repo_name()).Trg();
fsdb_itm.Ctor_by_html(repo, url_bldr, tmp_img_size, exec_tid);
xfer_itm.Trg_repo_(repo);
xfer_itm.Html_orig_src_(Bry_.new_utf8_(fsdb_itm.Html_orig_url().To_http_file_str())); // always set orig_url; note that w,h are not necessary for orig url; orig url needed for [[Media:]] links; DATE:2014-01-19
gplx.ios.IoItmFil fil = Io_mgr._.QueryFil(fsdb_itm.Html_view_url());
if (fil.Exists()) {
if (fil.Size() == 0) // NOTE: fix; XOWA used to write 0 byte files if file was missing, delete them and do not return true; DATE:2014-06-21
Io_mgr._.DeleteFil(fsdb_itm.Html_view_url());
else {
xfer_itm.Calc_by_fsdb(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_view_url(), fsdb_itm.Html_orig_url());
return true;
}
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)fsdb_hash.Fetch(xfer.Lnki_ttl());
xfer.File_exists_n_();
if (fsdb == null) return false; // no orig_data found for the ttl
Xof_repo_itm repo = wiki.File_mgr().Repo_mgr().Repos_get_by_wiki(fsdb.Orig_repo_name()).Trg();
fsdb.Lnki_size_(xfer.Lnki_w(), xfer.Lnki_h()); // NOTE: must overwrite fsdb.size with xfer.size when the same image shows up in multiple sizes on a page; (only one item in wiki_orig); EX: w:Portal:Canada; [[File:Flag of Canada.svg|300x150px]]; [[File:Flag of Canada.svg|23px]]; DATE:2014-02-14
fsdb.Ctor_for_html(exec_tid, img_size, repo, url_bldr);
xfer.Url_bldr_(url_bldr); // default Url_bldr for xfer uses @ for thumbtime; switch to -; DATE:2014-02-02
xfer.Trg_repo_(repo);
xfer.Lnki_ext_(fsdb.Lnki_ext()); // WORKAROUND: hacky, but fsdb knows when ogg is ogv whereas xfer does not; so, always override xfer.ext with fsdb's; DATE:2014-02-02
xfer.Init_by_orig(fsdb.Orig_repo_id(), fsdb.Orig_repo_name(), fsdb.Orig_ttl(), fsdb.Orig_ext(), fsdb.Orig_w(), fsdb.Orig_h(), fsdb.Orig_redirect(), xfer.Orig_file_len()); // copy orig props from orig_itm to xfer
xfer.Html_orig_url_(Bry_.new_utf8_(fsdb.Html_orig_url().To_http_file_str())); // always set orig_url; note that w,h are not necessary for orig url; orig url needed for [[Media:]] links; DATE:2014-01-19
gplx.ios.IoItmFil fil = Io_mgr._.QueryFil(fsdb.Html_view_url());
if (fil.Exists()) {
if (fil.Size() == 0) // NOTE: fix; XOWA used to write 0 byte files if file was missing, delete them and do not return true; DATE:2014-06-21
Io_mgr._.DeleteFil(fsdb.Html_view_url());
else {
xfer.Calc_by_fsdb(fsdb.Html_w(), fsdb.Html_h(), fsdb.Html_view_url(), fsdb.Html_orig_url());
xfer.File_exists_y_();
return true;
}
// TODO: replace above with this block; WHEN: mocking file database tests; DATE:2014-05-03
// boolean found = Io_mgr._.ExistsFil(fsdb_itm.Html_url());
// Io_url html_url = found ? fsdb_itm.Html_url() : null;
// xfer_itm.Atrs_calc_by_fsdb(fsdb_itm.Html_w(), fsdb_itm.Html_h(), html_url, fsdb_itm.Html_orig_url());
// return found;
}
return false;
} catch (Exception e) {
wiki.Appe().Usr_dlg().Warn_many("", "", "failed to find img: img=~{0} err=~{1}", String_.new_utf8_(xfer_itm.Lnki_ttl()), Err_.Message_gplx_brief(e));
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to find img: img=~{0} err=~{1}", String_.new_utf8_(xfer.Lnki_ttl()), Err_.Message_gplx_brief(e));
return false;
}
}
private void Create_xfer_itms(ListAdp lnki_list, int upright_patch) {
private void Make_fsdb_list(ListAdp lnki_list, int upright_patch) {
int len = lnki_list.Count();
for (int i = 0; i < len; i++) {
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)lnki_list.FetchAt(i);
Xof_fsdb_itm fsdb_itm = new Xof_fsdb_itm();
Init_fsdb_by_lnki(fsdb_itm, lnki_tkn, upright_patch);
fsdb_list.Add(fsdb_itm);
Xof_fsdb_itm fsdb = new Xof_fsdb_itm();
fsdb.Ctor_by_lnki(lnki_tkn.Ttl().Page_db(), lnki_tkn.Lnki_type(), lnki_tkn.W(), lnki_tkn.H(), upright_patch, lnki_tkn.Upright(), lnki_tkn.Time(), lnki_tkn.Page());
fsdb_list.Add(fsdb);
}
}
private void Hash_xfer_itms() {
private void Make_fsdb_hash() {
int len = fsdb_list.Count();
for (int i = 0; i < len; i++) {
Xof_fsdb_itm fsdb_itm = (Xof_fsdb_itm)fsdb_list.FetchAt(i);
Hash_xfer_itms_add(fsdb_itm.Lnki_ttl(), fsdb_itm);
Hash_xfer_itms_add(fsdb_itm.Orig_ttl(), fsdb_itm); // redirect
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)fsdb_list.FetchAt(i);
Make_fsdb_hash_add(fsdb.Lnki_ttl(), fsdb);
Make_fsdb_hash_add(fsdb.Orig_ttl(), fsdb); // redirect
}
}
private void Hash_xfer_itms_add(byte[] key, Xof_fsdb_itm itm) {
private void Make_fsdb_hash_add(byte[] key, Xof_fsdb_itm itm) {
if ( Bry_.Len_gt_0(key) // ignore null / empty itms; needed for redirects
&& !xfer_list.Has(key) // don't add if already there
&& !fsdb_hash.Has(key) // don't add if already there
&& orig_regy.Has(key) // add if found in orig_regy
)
xfer_list.Add(key, itm);
}
private void Init_fsdb_by_lnki(Xof_fsdb_itm fsdb_itm, Xop_lnki_tkn lnki_tkn, int lnki_upright_patch) {
byte[] lnki_ttl = lnki_tkn.Ttl().Page_db();
Xof_ext lnki_ext = Xof_ext_.new_by_ttl_(lnki_ttl);
byte[] lnki_md5 = Xof_xfer_itm_.Md5_(lnki_ttl);
fsdb_itm.Ctor_by_lnki(lnki_ttl, lnki_ext, lnki_md5, lnki_tkn.Lnki_type(), lnki_tkn.Lnki_w(), lnki_tkn.Lnki_h(), lnki_upright_patch, lnki_tkn.Upright(), lnki_tkn.Thumbtime(), lnki_tkn.Page());
}
private void Init_fsdb_by_xfer(Xof_fsdb_itm fsdb_itm, Xof_xfer_itm xfer_itm) { // DELETE: DATE:2014-02-04
fsdb_itm.Lnki_size_(xfer_itm.Lnki_w(), xfer_itm.Lnki_h()); // NOTE: must overwrite fsdb_itm.size with xfer_itm.size when the same image shows up in multiple sizes on a page; (only one item in wiki_orig); EX: w:Portal:Canada; [[File:Flag of Canada.svg|300x150px]]; [[File:Flag of Canada.svg|23px]]; DATE:2014-02-14
fsdb_itm.Lnki_type_(xfer_itm.Lnki_type()); // NOTE: must overwrite lnki_type, else multiple images on same page with different type wont show; PAGE:en.w:History_of_painting; DATE:2014-03-06
fsdb_itm.Lnki_page_(xfer_itm.Lnki_page());
fsdb_itm.Lnki_time_(xfer_itm.Lnki_time());
// byte[] lnki_ttl = xfer_itm.Lnki_ttl();
// Xof_ext lnki_ext = xfer_itm.Lnki_ext();
// byte[] lnki_md5 = Xof_xfer_itm_.Md5_(lnki_ttl);
// fsdb_itm.Init_by_lnki(lnki_ttl, lnki_ext, lnki_md5, xfer_itm.Lnki_type(), xfer_itm.Lnki_w(), xfer_itm.Lnki_h(), xfer_itm.Lnki_upright(), xfer_itm.Lnki_thumbtime(), xfer_itm.Lnki_page());
fsdb_hash.Add(key, itm);
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
public class Xof_doc_page {
public class Xof_lnki_page {
public static final int Null = -1;
public static boolean Null_y(int v) {return v == Null;}
public static boolean Null_n(int v) {return v != Null;}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
public class Xof_doc_thumb {
public class Xof_lnki_time {
public static double Db_save_double(double v) {return v;}
public static double Db_load_double(DataRdr rdr, String fld) {return rdr.ReadDouble(fld);}
public static double Db_load_double(Db_rdr rdr, String fld) {return rdr.Read_double(fld);}
@@ -33,9 +33,9 @@ public class Xof_doc_thumb {
public static final int Null_as_int = -1;
public static double Convert_to_xowa_thumbtime (int ext, double val) {return Xof_ext_.Id_supports_thumbtime(ext) ? val : Null;}
public static int Convert_to_xowa_page (int ext, double val) {return Xof_ext_.Id_supports_page(ext) ? (int)val : Xof_doc_page.Null;}
public static int Convert_to_xowa_page (int ext, double val) {return Xof_ext_.Id_supports_page(ext) ? (int)val : Xof_lnki_page.Null;}
public static double Convert_to_fsdb_thumbtime (int ext, double thumbtime, int page) {
return page != Xof_doc_page.Null
return page != Xof_lnki_page.Null
&& Xof_ext_.Id_supports_page(ext) // redefine thumbtime to page if pdf
? page
: thumbtime

View File

@@ -20,7 +20,7 @@ import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*;
public class Xof_url_bldr {
private final Bry_bfr bfr = Bry_bfr.reset_(400);
private byte[] ttl; private byte[] md5; private Xof_ext ext; private boolean file_is_thumb; private int file_w;
private double time = Xof_doc_thumb.Null; private int page = Xof_doc_page.Null; private byte time_dlm = Byte_ascii.At;
private double time = Xof_lnki_time.Null; private int page = Xof_lnki_page.Null; private byte time_dlm = Byte_ascii.At;
private byte[] root; private byte dir_spr; private boolean fsys_tid_is_wnt; private boolean wmf_dir_hive; private boolean wmf_protocol_is_file; private int md5_dir_depth; private byte[] area;
public Xof_url_bldr Root_(byte[] v) {root = v; return this;}
public Xof_url_bldr Init_by_root(byte[] root, byte dir_spr, boolean wmf_dir_hive, boolean wmf_protocol_is_file, int md5_dir_depth) {
@@ -63,13 +63,9 @@ public class Xof_url_bldr {
public byte[] Xto_bry() {Bld(); byte[] rv = bfr.Xto_bry_and_clear(); Clear(); return rv;}
public String Xto_str() {Bld(); String rv = bfr.Xto_str(); Clear(); return rv;}
public Io_url Xto_url() {Bld(); Io_url rv = Io_url_.new_fil_(bfr.Xto_str()); Clear(); return rv;}
public Io_url To_url(Xow_repo_mgr repo_mgr, Xof_fsdb_itm itm, boolean orig) {return To_url(repo_mgr.Repos_get_by_wiki(itm.Orig_repo_name()), itm, orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb, Bool_.N);}
public Io_url To_url(Xof_repo_pair repo_pair, Xof_fsdb_itm itm, boolean orig) {return To_url(repo_pair, itm, orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb, Bool_.N);}
public Io_url To_url(Xof_repo_pair repo_pair, Xof_fsdb_itm itm, byte mode, boolean src) {
return src
? this.Init_for_src_file(mode, repo_pair.Src(), itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), itm.Html_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url()
: this.Init_for_trg_file(mode, repo_pair.Trg(), itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), itm.Html_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url()
;
public Io_url To_url_trg(Xof_repo_itm repo_itm, Xof_fsdb_itm itm, boolean orig) {
byte mode = orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb;
return this.Init_for_trg_file(mode, repo_itm, itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), itm.Html_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
}
private void Bld() {
Add_core();
@@ -104,9 +100,9 @@ public class Xof_url_bldr {
private Xof_url_bldr Add_thumb_xowa() {
bfr.Add_byte(dir_spr); // add dir_spr; EX: "\"
bfr.Add_int_variable(file_w).Add(Bry_px); // add file_w; EX: "220px"
if (Xof_doc_thumb.Null_n(time))
bfr.Add_byte(time_dlm).Add_str(Xof_doc_thumb.X_str(time)); // add time EX: "@5"
else if (page != Xof_doc_page.Null)
if (Xof_lnki_time.Null_n(time))
bfr.Add_byte(time_dlm).Add_str(Xof_lnki_time.X_str(time)); // add time EX: "@5"
else if (page != Xof_lnki_page.Null)
bfr.Add_byte(Byte_ascii.Dash).Add_int_variable(page); // add page EX: "-5"
bfr.Add_byte(Byte_ascii.Dot); // add . EX: "."
if (file_is_thumb)
@@ -122,8 +118,8 @@ public class Xof_url_bldr {
case Xof_ext_.Id_ogg:
case Xof_ext_.Id_ogv:
case Xof_ext_.Id_webm:
if (Xof_doc_thumb.Null_n(time))
bfr.Add(Bry_seek).Add_str(Xof_doc_thumb.X_str(time)).Add_byte(Byte_ascii.Dash);// add seek; EX: "seek%3D5-"
if (Xof_lnki_time.Null_n(time))
bfr.Add(Bry_seek).Add_str(Xof_lnki_time.X_str(time)).Add_byte(Byte_ascii.Dash);// add seek; EX: "seek%3D5-"
else
bfr.Add(Bry_mid); // add mid; EX: "mid-"
break;
@@ -164,7 +160,7 @@ public class Xof_url_bldr {
return this;
}
private void Add_thumb_wmf_page(byte[] bry_page_1, byte[] bry_page) {
if (Xof_doc_thumb.Null_y(page))
if (Xof_lnki_time.Null_y(page))
bfr.Add(bry_page_1); // add "lossy-page1-" EX: "lossy-page1-"
else {
bfr.Add(bry_page); // add "lossy-page" EX: "lossy-page"
@@ -174,7 +170,7 @@ public class Xof_url_bldr {
}
private Xof_url_bldr Clear() {
root = area = ttl = md5 = null;
file_w = 0; time = Xof_doc_thumb.Null;
file_w = 0; time = Xof_lnki_time.Null;
ext = null;
bfr.Clear();
return this;

View File

@@ -36,13 +36,13 @@ class Xof_url_bldr_fxt {
public Xof_url_bldr_fxt Root_(String v) {root = v; return this;} private String root;
public Xof_url_bldr_fxt Md5_(String v) {md5 = v; return this;} private String md5;
public Xof_url_bldr_fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_utf8_(v)); return this;} private String ttl; Xof_ext ext;
public Xof_url_bldr_fxt Page_(int v) {page = v; return this;} private int page = Xof_doc_page.Null;
public Xof_url_bldr_fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_doc_thumb.Null;
public Xof_url_bldr_fxt Page_(int v) {page = v; return this;} private int page = Xof_lnki_page.Null;
public Xof_url_bldr_fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_lnki_time.Null;
public Xof_url_bldr_fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
private void Clear() {
dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
seek = Xof_doc_thumb.Null;
page = Xof_doc_page.Null;
seek = Xof_lnki_time.Null;
page = Xof_lnki_page.Null;
}
public Xof_url_bldr_fxt tst() {
url_bldr.Init_by_root(Bry_.new_utf8_(root), dir_spr, Bool_.Y, Bool_.N, 2);

View File

@@ -17,33 +17,39 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
public class Xof_xfer_itm implements Xof_file_itm {
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Lnki_md5() {return lnki_md5;} private byte[] lnki_md5;
public Xof_ext Lnki_ext() {return lnki_ext;} public void Lnki_ext_(Xof_ext v) {lnki_ext = v;} private Xof_ext lnki_ext;
public byte[] Lnki_redirect() {return lnki_redirect;} private byte[] lnki_redirect;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time = Xof_doc_thumb.Null;
public int Lnki_page() {return lnki_page;} private int lnki_page = Xof_doc_page.Null;
public int Orig_w() {return orig_w;} private int orig_w;
public int Orig_h() {return orig_h;} private int orig_h;
public int Orig_file_len() {return orig_file_len;} private int orig_file_len;
public int Html_uid() {return html_uid;} private int html_uid = -1;
public byte Html_elem_tid() {return html_elem_tid;} public Xof_xfer_itm Html_elem_tid_(byte v) {html_elem_tid = v; return this;} private byte html_elem_tid = Xof_html_elem.Tid_none;
public int Html_w() {return html_w;} private int html_w;
public int Html_h() {return html_h;} private int html_h;
public byte[] Html_view_src() {return html_view_src;} private byte[] html_view_src = Bry_.Empty;
public byte[] Html_orig_src() {return html_orig_src;} public void Html_orig_src_(byte[] v) {this.html_orig_src = v;} private byte[] html_orig_src = Bry_.Empty;
public boolean Html_pass() {return html_pass;} private boolean html_pass;
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} public Xof_xfer_itm Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v; return this;} private Js_img_wkr html_img_wkr;
public int File_w() {return file_w == -1 ? html_w : file_w;} public void File_w_(int v) {file_w = v;} private int file_w = -1; // NOTE: for itm_meta, file_w == html_w
public boolean Img_is_thumbable() {return img_is_thumbable;} private boolean img_is_thumbable; // SEE:NOTE_1:Lnki_thumbable
public boolean Img_is_orig() {return !img_is_thumbable;}
public int Gallery_mgr_h() {return gallery_mgr_h;} public Xof_xfer_itm Gallery_mgr_h_(int v) {gallery_mgr_h = v; return this;} private int gallery_mgr_h = Int_.Neg1;
public boolean File_found() {return file_found;} public Xof_xfer_itm File_found_(boolean v) {file_found = v; return this;} private boolean file_found;
public class Xof_xfer_itm implements Xof_file_itm {
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Lnki_md5() {return lnki_md5;} private byte[] lnki_md5;
public Xof_ext Lnki_ext() {return lnki_ext;} private Xof_ext lnki_ext;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time = Xof_lnki_time.Null;
public int Lnki_page() {return lnki_page;} private int lnki_page = Xof_lnki_page.Null;
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_itm.Repo_null;
public byte[] Orig_repo_name() {return orig_repo_name;} private byte[] orig_repo_name;
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
public int Orig_ext() {return orig_ext;} private int orig_ext;
public int Orig_w() {return orig_w;} private int orig_w;
public int Orig_h() {return orig_h;} private int orig_h;
public byte[] Orig_redirect() {return orig_redirect;} private byte[] orig_redirect;
public int Orig_file_len() {return orig_file_len;} private int orig_file_len;
public int File_w() {return file_w == -1 ? html_w : file_w;} public void File_w_(int v) {file_w = v;} private int file_w = -1; // NOTE: for itm_meta, file_w == html_w
public int Html_uid() {return html_uid;} private int html_uid = -1;
public byte Html_elem_tid() {return html_elem_tid;} private byte html_elem_tid = Xof_html_elem.Tid_none;
public int Html_w() {return html_w;} private int html_w;
public int Html_h() {return html_h;} private int html_h;
public byte[] Html_view_url() {return html_view_url;} private byte[] html_view_url = Bry_.Empty;
public byte[] Html_orig_url() {return html_orig_url;} public void Html_orig_url_(byte[] v) {this.html_orig_url = v;} private byte[] html_orig_url = Bry_.Empty;
public int Gallery_mgr_h() {return gallery_mgr_h;} public Xof_xfer_itm Gallery_mgr_h_(int v) {gallery_mgr_h = v; return this;} private int gallery_mgr_h = Int_.Neg1;
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} public Xof_xfer_itm Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v; return this;} private Js_img_wkr html_img_wkr;
public boolean Html_pass() {return html_pass;} private boolean html_pass;
public boolean Img_is_thumbable() {return img_is_thumbable;} private boolean img_is_thumbable; // SEE:NOTE_1:Lnki_thumbable
public boolean Img_is_orig() {return !img_is_thumbable;}
public boolean File_found() {return file_found;} public Xof_xfer_itm File_found_(boolean v) {file_found = v; return this;}
public boolean File_exists() {return file_exists;} public void File_exists_y_() {file_exists = Bool_.Y;} public void File_exists_n_() {file_exists = Bool_.N;} private boolean file_exists;
private boolean file_found;
public Xof_meta_itm Meta_itm() {return meta_itm;} private Xof_meta_itm meta_itm;
public Xof_repo_itm Trg_repo() {return trg_repo;}
public Xof_xfer_itm Trg_repo_(Xof_repo_itm v) {
@@ -59,13 +65,13 @@ public class Xof_xfer_itm implements Xof_file_itm {
public Xof_url_bldr Url_bldr(){ return url_bldr;}
public Xof_xfer_itm Url_bldr_(Xof_url_bldr v) {url_bldr = v; return this;} private Xof_url_bldr url_bldr = Xof_url_bldr.Temp;
public Xof_xfer_itm Clear() {
lnki_type = Byte_.Max_value_127;
lnki_w = lnki_h = file_w = orig_w = orig_h = html_w = html_h = gallery_mgr_h = Int_.Neg1;
lnki_upright = Int_.Neg1; lnki_time = Xof_doc_thumb.Null; lnki_page = Xof_doc_page.Null;
img_is_thumbable = false;
lnki_type = orig_repo_id = Byte_.Max_value_127;
lnki_w = lnki_h = file_w = orig_ext = orig_w = orig_h = html_w = html_h = gallery_mgr_h = Int_.Neg1;
lnki_upright = Int_.Neg1; lnki_time = Xof_lnki_time.Null; lnki_page = Xof_lnki_page.Null;
file_found = file_exists = img_is_thumbable = false;
orig_file_len = 0; // NOTE: cannot be -1, or else will always download orig; see ext rule chk and (orig_file_len < 0)
lnki_redirect = null; lnki_ttl = null; lnki_md5 = null; lnki_ext = null;
html_orig_src = html_view_src = Bry_.Empty;
orig_repo_name = orig_ttl = orig_redirect = null; lnki_ttl = null; lnki_md5 = null; lnki_ext = null;
html_orig_url = html_view_url = Bry_.Empty;
trg_repo_idx = Int_.Neg1; meta_itm = null;
html_uid = Int_.Neg1; html_elem_tid = Xof_html_elem.Tid_none;
return this;
@@ -74,40 +80,60 @@ public class Xof_xfer_itm implements Xof_file_itm {
Xof_xfer_itm rv = new Xof_xfer_itm();
rv.lnki_type = lnki_type; rv.lnki_w = lnki_w; rv.lnki_h = lnki_h; rv.lnki_upright = lnki_upright; rv.lnki_time = lnki_time; rv.lnki_page = lnki_page;
rv.img_is_thumbable = img_is_thumbable;
rv.orig_w = orig_w; rv.orig_h = orig_h; rv.orig_file_len = orig_file_len;
rv.lnki_redirect = lnki_redirect; rv.lnki_ttl = lnki_ttl; rv.lnki_md5 = lnki_md5; rv.lnki_ext = lnki_ext;
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_src = html_view_src; rv.html_orig_src = html_orig_src;
rv.orig_repo_id = orig_repo_id; rv.orig_repo_name = orig_repo_name; rv.orig_ttl = orig_ttl; rv.orig_ext = orig_ext; rv.orig_w = orig_w; rv.orig_h = orig_h; rv.orig_redirect = orig_redirect;
rv.orig_file_len = orig_file_len;
rv.lnki_ttl = lnki_ttl; rv.lnki_md5 = lnki_md5; rv.lnki_ext = lnki_ext;
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_url = html_view_url; rv.html_orig_url = html_orig_url;
rv.file_w = file_w;
rv.trg_repo_idx = trg_repo_idx;
rv.trg_repo_root = trg_repo_root;
rv.meta_itm = meta_itm; // NOTE: shared reference
rv.html_uid = html_uid; rv.html_elem_tid = html_elem_tid;
rv.gallery_mgr_h = gallery_mgr_h;
rv.file_exists = file_exists;
return rv;
}
public Xof_xfer_itm Init_by_lnki(byte[] ttl, byte[] redirect, byte lnki_type, int w, int h, double upright, double thumbtime, int lnki_page) {
public Xof_xfer_itm Init_by_lnki(byte[] ttl, byte[] redirect, byte lnki_type, int w, int h, double upright, double time, int page) {
this.Set__ttl(ttl, redirect);
this.lnki_type = lnki_type; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = upright; this.lnki_time = thumbtime; this.lnki_page = lnki_page;
this.lnki_type = lnki_type; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = upright; this.lnki_time = time; this.lnki_page = page;
img_is_thumbable = Xof_xfer_itm_.Lnki_thumbable_calc(lnki_type, lnki_w, lnki_h);
if (lnki_time != Xof_doc_thumb.Null && !lnki_ext.Id_is_media()) // thumbtime is set, but ext is not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0:02]] DATE:2014-07-22
lnki_time = Xof_doc_thumb.Null; // disable thumbtime
if (lnki_time != Xof_lnki_time.Null && !lnki_ext.Id_is_media()) // thumbtime is set, but ext is not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0:02]] DATE:2014-07-22
lnki_time = Xof_lnki_time.Null; // disable thumbtime
return this;
}
public void Init_by_orig_old(int w, int h, int orig_file_len) {
this.orig_w = w; this.orig_h = h; this.orig_file_len = orig_file_len;
}
public void Init_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, int orig_ext, int orig_w, int orig_h, byte[] orig_redirect, int orig_file_len) {
this.orig_repo_id = orig_repo_id; this.orig_repo_name = orig_repo_name;
this.orig_ttl = orig_ttl; this.orig_ext = orig_ext;
this.orig_w = orig_w; this.orig_h = orig_h; this.orig_redirect = orig_redirect;
if (orig_ext != lnki_ext.Id())
this.Lnki_ext_(Xof_ext_.new_by_id_(orig_ext)); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
this.Lnki_ttl_(orig_redirect); // update fsdb with atrs of B.png
this.orig_file_len = orig_file_len;
}
private void Lnki_ttl_(byte[] v) {
lnki_ttl = v;
lnki_ext = Xof_ext_.new_by_ttl_(v);
lnki_md5 = Xof_xfer_itm_.Md5_calc(v);
}
public void Init_for_gallery(int html_w, int html_h, int file_w) {
this.html_w = html_w; this.html_h = html_h;
this.file_w = file_w;
}
public void Init_for_gallery_update(int html_w, int html_h, String view_src, String orig_src) {
this.html_w = html_w; this.html_h = html_h;
this.html_view_src = Bry_.new_utf8_(view_src);
this.html_orig_src = Bry_.new_utf8_(orig_src);
this.html_view_url = Bry_.new_utf8_(view_src);
this.html_orig_url = Bry_.new_utf8_(orig_src);
this.html_pass = true;
this.file_found = true;
}
public void Init_for_test__img(int html_w, int html_h, byte[] html_view_src, byte[] html_orig_src) {this.html_w = html_w; this.html_h = html_h; this.html_view_src = html_view_src; this.html_orig_src = html_orig_src;}
public void Init_for_test__img(int html_w, int html_h, byte[] html_view_url, byte[] html_orig_url) {this.html_w = html_w; this.html_h = html_h; this.html_view_url = html_view_url; this.html_orig_url = html_orig_url;}
public Xof_xfer_itm Set__ttl(byte[] ttl, byte[] redirect) {
this.lnki_redirect = redirect;
this.lnki_ttl = lnki_redirect == Xop_redirect_mgr.Redirect_null_bry ? Bry_.Copy(ttl) : lnki_redirect;
this.orig_redirect = redirect;
this.lnki_ttl = orig_redirect == Xop_redirect_mgr.Redirect_null_bry ? Bry_.Copy(ttl) : orig_redirect;
this.lnki_ttl = Xof_xfer_itm_.Md5_decoder.Decode_lax(Xof_xfer_itm_.Ttl_standardize(lnki_ttl)); // NOTE: this line is repeated in static method below
this.lnki_md5 = Xof_xfer_itm_.Md5_calc(lnki_ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
this.lnki_ext = Xof_ext_.new_by_ttl_(lnki_ttl);
@@ -115,7 +141,6 @@ public class Xof_xfer_itm implements Xof_file_itm {
}
public void Set__html_size(int html_w, int html_h) {this.html_w = html_w; this.html_h = html_h; }
public Xof_xfer_itm Set__html_uid_tid(int uid, byte tid) {html_uid = uid; html_elem_tid = tid; return this;}
public Xof_xfer_itm Set__orig(int w, int h, int orig_file_len) {this.orig_w = w; this.orig_h = h; this.orig_file_len = orig_file_len; return this;}
public void Set__meta(Xof_meta_itm meta_itm, Xof_repo_itm trg_repo, int thumb_w_img) {
this.meta_itm = meta_itm; Trg_repo_(trg_repo); this.thumb_w_img = thumb_w_img;
this.orig_w = meta_itm.Orig_w(); this.orig_h = meta_itm.Orig_h(); // orig_w / orig_h needed for imap; DATE:2014-08-08
@@ -125,13 +150,15 @@ public class Xof_xfer_itm implements Xof_file_itm {
html_pass = true;
this.html_w = html_w;
this.html_h = html_h;
this.html_orig_src = Bry_.new_utf8_(orig_url.To_http_file_str());
this.html_view_src = Bry_.new_utf8_(view_url.To_http_file_str());
this.html_orig_url = Bry_.new_utf8_(orig_url.To_http_file_str());
this.html_view_url = Bry_.new_utf8_(view_url.To_http_file_str());
}
public void Lnki_ext_(Xof_ext v) {lnki_ext = v;}
public Xof_xfer_itm Html_elem_tid_(byte v) {html_elem_tid = v; return this;}
public boolean Calc_by_meta() {return Calc_by_meta(false);}
public boolean Calc_by_meta(boolean caller_is_file_page) {
html_pass = false;
html_orig_src = html_view_src = Bry_.Empty;
html_orig_url = html_view_url = Bry_.Empty;
html_w = lnki_w; html_h = lnki_h;
if (meta_itm == null || trg_repo == null) return false;
if (meta_itm.Ptr_ttl_exists()) {
@@ -143,19 +170,19 @@ public class Xof_xfer_itm implements Xof_file_itm {
html_w = Xof_img_size.Thumb_width_ogv;
if (img_is_thumbable) { // file is thumb
if (lnki_ext.Id_is_video()) { // video is a special case; src is thumb_w but html_w / html_h is based on calc
html_orig_src = Trg_html(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated);
if (meta_itm.Thumbs_indicates_oga() && lnki_ext.Id_is_ogv()) {lnki_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_src, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_doc_thumb.X_int(lnki_time));
html_orig_url = Trg_html(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated);
if (meta_itm.Thumbs_indicates_oga() && lnki_ext.Id_is_ogv()) {lnki_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_url, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_lnki_time.X_int(lnki_time));
if (thumb != null) {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, thumb.Width(), thumb.Height(), html_w, html_h, img_is_thumbable, lnki_upright);
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_view_url = Trg_html(Xof_repo_itm.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_pass = true;
return true;
}
}
else { // regular thumb
html_orig_src = Trg_html(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated);
html_orig_url = Trg_html(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated);
if (lnki_ext.Id_is_audio()) return true; // if audio, do not thumb; even if user requests thumb;
Xof_meta_thumb[] thumbs = meta_itm.Thumbs(); int thumbs_len = thumbs.length; Xof_meta_thumb thumb = null;
if (lnki_h > 0 && orig_w < 1 && thumbs_len > 0) { // if height is specified and no orig, then iterate over thumbs to find similar height; NOTE: this is a fallback case; orig_w/h is optimal; EX: c:Jacques-Louis David and <gallery>
@@ -175,7 +202,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, meta_itm.Orig_w(), meta_itm.Orig_h(), html_w, html_h, img_is_thumbable, lnki_upright, limit_size); // calc html_h and html_w; can differ from lnki_w, lnki_h; note that -1 width is handled by thumb_w_img
html_w = calc_size.Val_0();
if (html_h != -1) html_h = calc_size.Val_1(); // NOTE: if -1 (no height specified) do not set height; EX:Tokage_2011-07-15.jpg; DATE:2013-06-03
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, this.File_w());
html_view_url = Trg_html(Xof_repo_itm.Mode_thumb, this.File_w());
thumb = meta_itm.Thumbs_get_img(html_w, 0);
if (thumb == null) { // exact thumb not found
if (html_w == meta_itm.Orig_w() // html_w matches orig_w; occurs when thumb,upright requested, but upright size is larger than orig; PAGE:en.w:St. Petersburg
@@ -183,7 +210,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
&& meta_itm.Orig_exists() == Xof_meta_itm.Exists_y
) {
html_h = meta_itm.Orig_h();
html_view_src = Trg_html(Xof_repo_itm.Mode_orig, -1);
html_view_url = Trg_html(Xof_repo_itm.Mode_orig, -1);
html_pass = true;
return true;
}
@@ -201,21 +228,21 @@ public class Xof_xfer_itm implements Xof_file_itm {
}
else { // file is orig
byte mode_id = lnki_ext.Id_is_svg() ? Xof_repo_itm.Mode_thumb : Xof_repo_itm.Mode_orig; // svgs will always return thumb; EX:[[A.svg]] -> A.svg.png
html_view_src = html_orig_src = Trg_html(mode_id, this.File_w());
if (meta_itm.Thumbs_indicates_oga() && lnki_ext.Id_is_ogv()) {lnki_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_src, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
html_view_url = html_orig_url = Trg_html(mode_id, this.File_w());
if (meta_itm.Thumbs_indicates_oga() && lnki_ext.Id_is_ogv()) {lnki_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_url, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
if (lnki_ext.Id_is_audio()) return true; // if audio, return true; SEE:NOTE_2
else if (lnki_ext.Id_is_video()) {
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_doc_thumb.X_int(lnki_time)); // get thumb at lnki_time; NOTE: in most cases this will just be the 1st thumb; note that orig video files don't have an official thumb
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_lnki_time.X_int(lnki_time)); // get thumb at lnki_time; NOTE: in most cases this will just be the 1st thumb; note that orig video files don't have an official thumb
if (thumb != null) {
html_w = thumb.Width(); html_h = thumb.Height(); // NOTE: take thumb_size; do not rescale to html_w, html_h b/c html_w will default to 220; native width of thumbnail should be used; DATE:2013-04-11
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_view_url = Trg_html(Xof_repo_itm.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_pass = true;
return true;
}
}
if (meta_itm.Orig_exists() == Xof_meta_itm.Exists_y) { // file found previously >>> gen html
html_w = meta_itm.Orig_w(); html_h = meta_itm.Orig_h();
html_view_src = Trg_html(mode_id, this.File_w());
html_view_url = Trg_html(mode_id, this.File_w());
html_pass = true;
return true;
}
@@ -228,7 +255,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
private boolean Calc_by_meta_found(byte lnki_type, int model_w, int model_h) {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, model_w, model_h, html_w, html_h, img_is_thumbable, lnki_upright, false); // recalc html_w, html_h; note that false passed b/c truncation is not needed
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, model_w); // note that thumb.Width is used (the actual file width), not html_w
html_view_url = Trg_html(Xof_repo_itm.Mode_thumb, model_w); // note that thumb.Width is used (the actual file width), not html_w
html_pass = true;
return true;
}

View File

@@ -40,36 +40,34 @@ public class Xof_bin_mgr implements GfoInvkAble {
Io_stream_rdr rdr = Find_as_rdr(exec_tid, itm);
if (rdr == Io_stream_rdr_.Null) return Io_url_.Null;
Io_url trg = itm.Html_view_url();
if (itm.Rslt_fil_created()) return trg; // rdr is opened directly from trg; return its url; occurs when url goes through imageMagick / inkscape, or when thumb is already on disk;
Io_stream_wtr_.Save_rdr(trg, rdr); // rdr is stream; either from http_wmf or fsdb; save to trg and return;
if (itm.Rslt_bin() == Xof_bin_wkr_.Tid_fsdb_xowa) { // rdr is coming from fsdb; register in cache
if (!Env_.Mode_testing())
cache_mgr.Reg(itm, rdr.Len());
}
if (itm.File_resized()) return trg; // rdr is opened directly from trg; return its url; occurs when url goes through imageMagick / inkscape, or when thumb is already on disk;
Io_stream_wtr_.Save_rdr(trg, rdr); // rdr is stream; either from http_wmf or fsdb; save to trg and return;
if (!Env_.Mode_testing()) cache_mgr.Reg(itm, rdr.Len());
return trg;
}
public Io_stream_rdr Find_as_rdr(byte exec_tid, Xof_fsdb_itm itm) {
Io_stream_rdr rv = Io_stream_rdr_.Null;
Xof_repo_itm repo = repo_mgr.Repos_get_by_wiki(itm.Orig_repo_name()).Trg();
boolean file_is_orig = itm.File_is_orig();
if (file_is_orig || exec_tid == Xof_exec_tid.Tid_viewer_app) { // orig or viewer_app; note that viewer_app always return orig
Io_url trg = url_bldr.To_url(repo_mgr, itm, Bool_.Y);
Io_url trg = url_bldr.To_url_trg(repo, itm, Bool_.Y);
itm.Html_view_url_(trg);
for (int i = 0; i < wkrs_len; i++) {
Xof_bin_wkr wkr = wkrs[i];
rv = wkr.Get_as_rdr(itm, Bool_.N, itm.Html_w());
if (rv == Io_stream_rdr_.Null) continue; // orig not found; continue;
itm.Rslt_bin_(wkr.Tid());
itm.File_exists_y_();
return rv;
}
}
else { // thumb
Io_url trg = url_bldr.To_url(repo_mgr, itm, Bool_.N);
Io_url trg = url_bldr.To_url_trg(repo, itm, Bool_.N);
itm.Html_view_url_(trg);
for (int i = 0; i < wkrs_len; i++) {
Xof_bin_wkr wkr = wkrs[i];
rv = wkr.Get_as_rdr(itm, Bool_.Y, itm.Html_w()); // get thumb's bin
if (rv != Io_stream_rdr_.Null) { // thumb's bin exists;
itm.Rslt_bin_(wkr.Tid());
itm.File_exists_y_();
return rv;
}
usr_dlg.Log_direct(String_.Format("thumb not found; ttl={0} w={1} ", String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w()));
@@ -79,12 +77,11 @@ public class Xof_bin_mgr implements GfoInvkAble {
continue; // nothing found; continue;
}
if (!wkr.Resize_allowed()) continue;
Io_url orig = url_bldr.To_url(repo_mgr, itm, Bool_.Y); // get orig url
Io_url orig = url_bldr.To_url_trg(repo, itm, Bool_.Y); // get orig url
Io_stream_wtr_.Save_rdr(orig, rv);
boolean resized = Resize(exec_tid, itm, file_is_orig, orig, trg);
if (!resized) continue;
itm.Rslt_bin_(wkr.Tid());
itm.Rslt_fil_created_(true);
itm.File_exists_y_();
rv = Io_stream_rdr_.file_(trg); // return stream of resized url; (result of imageMagick / inkscape)
rv.Open();
return rv;
@@ -95,7 +92,7 @@ public class Xof_bin_mgr implements GfoInvkAble {
private boolean Resize(byte exec_tid, Xof_fsdb_itm itm, boolean file_is_orig, Io_url src, Io_url trg) {
tmp_size.Html_size_calc(exec_tid, itm.Lnki_w(), itm.Lnki_h(), itm.Lnki_type(), mnt_mgr.Patch_upright(), itm.Lnki_upright(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), Xof_img_size.Thumb_width_img);
boolean rv = resizer.Exec(src, trg, tmp_size.Html_w(), tmp_size.Html_h(), itm.Lnki_ext().Id(), resize_warning);
itm.Rslt_cnv_(rv ? Xof_cnv_wkr_.Tid_y : Xof_cnv_wkr_.Tid_n);
itm.File_resized_y_();
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@@ -41,10 +41,10 @@ public class Xof_bin_wkr__fsdb_sql implements Xof_bin_wkr, GfoInvkAble {
private void Find_ids(byte[] orig_repo, byte[] orig_ttl, int orig_ext, double lnki_time, int lnki_page, boolean is_thumb, int w, Int_obj_ref tmp_itm_id, Int_obj_ref tmp_bin_id, Int_obj_ref tmp_mnt_id) {
synchronized (tmp_bin_id) {
byte[] dir = orig_repo, fil = orig_ttl;
double time = Xof_doc_thumb.Convert_to_fsdb_thumbtime(orig_ext, lnki_time, lnki_page);
double time = Xof_lnki_time.Convert_to_fsdb_thumbtime(orig_ext, lnki_time, lnki_page);
if (is_thumb) {
Fsd_thm_itm thm_itm = Fsd_thm_itm.load_();
Init_thm(orig_ext, w, lnki_time, lnki_page, thm_itm);
Fsd_thm_itm thm_itm = Fsd_thm_itm.new_();
thm_itm.Init_by_req(w, lnki_time, lnki_page);
boolean found = mnt_mgr.Thm_select_bin(dir, fil, thm_itm);
tmp_itm_id.Val_(thm_itm.Id());
tmp_bin_id.Val_(found ? thm_itm.Db_bin_id() : Fsd_bin_tbl.Null_db_bin_id);
@@ -58,12 +58,6 @@ public class Xof_bin_wkr__fsdb_sql implements Xof_bin_wkr, GfoInvkAble {
}
}
}
private void Init_thm(int src_ext_id, int src_w, double src_time, int src_page, Fsd_thm_itm trg) {
trg.Owner().Ext_id_(src_ext_id);
trg.Width_(src_w);
trg.Thumbtime_(src_time);
trg.Page_(src_page);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.MatchIn(k, Invk_url_)) mnt_mgr.Init_by_wiki(m.ReadIoUrl("v"), Bool_.Y);
else return GfoInvkAble_.Rv_unhandled;

View File

@@ -24,15 +24,18 @@ public class Xof_bin_wkr__http_wmf implements Xof_bin_wkr {
public byte Tid() {return Xof_bin_wkr_.Tid_http_wmf;}
public boolean Resize_allowed() {return bin_wkr_resize;} public void Resize_allowed_(boolean v) {bin_wkr_resize = v;} private boolean bin_wkr_resize = true;
public int Fail_timeout() {return fail_timeout;} public Xof_bin_wkr__http_wmf Fail_timeout_(int v) {fail_timeout = v; return this;} private int fail_timeout = 0; // NOTE: always default to 0; manually set to 1000 for fsdb_make only; DATE:2014-06-21
public Io_stream_rdr Get_as_rdr(Xof_fsdb_itm itm, boolean is_thumb, int w) {
Download_init(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), is_thumb, w, itm.Lnki_time(), itm.Lnki_page(), Io_url_.Null);
public Io_stream_rdr Get_as_rdr(Xof_fsdb_itm fsdb, boolean is_thumb, int w) {
Download_init(fsdb.Orig_repo_name(), fsdb.Lnki_ttl(), fsdb.Lnki_md5(), fsdb.Lnki_ext(), is_thumb, w, fsdb.Lnki_time(), fsdb.Lnki_page(), Io_url_.Null);
Io_stream_rdr rdr = download_wkr.Exec_as_rdr();
boolean rv = rdr.Len() != IoItmFil.Size_invalid; // NOTE: use IoItmFil.Size_invalid, not Io_stream_rdr_.Read_done; DATE:2014-06-21
if (!rv) Handle_error();
fsdb.Fsdb_insert_y_();
return rv ? rdr : Io_stream_rdr_.Null;
}
public boolean Get_to_fsys(Xof_fsdb_itm itm, boolean is_thumb, int w, Io_url bin_url) {
return Get_to_fsys(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), is_thumb, w, itm.Lnki_time(), itm.Lnki_page(), bin_url);
public boolean Get_to_fsys(Xof_fsdb_itm fsdb, boolean is_thumb, int w, Io_url bin_url) {
boolean rv = Get_to_fsys(fsdb.Orig_repo_name(), fsdb.Lnki_ttl(), fsdb.Lnki_md5(), fsdb.Lnki_ext(), is_thumb, w, fsdb.Lnki_time(), fsdb.Lnki_page(), bin_url);
if (rv) fsdb.Fsdb_insert_y_();
return rv;
}
private boolean Get_to_fsys(byte[] orig_repo, byte[] orig_ttl, byte[] orig_md5, Xof_ext orig_ext, boolean lnki_is_thumb, int file_w, double lnki_time, int lnki_page, Io_url file_url) {
Download_init(orig_repo, orig_ttl, orig_md5, orig_ext, lnki_is_thumb, file_w, lnki_time, lnki_page, file_url);

View File

@@ -0,0 +1,65 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
class Xofc_cache_itm {
public Xofc_cache_itm
( Bry_bfr lnki_key_bfr, int uid, byte db_state
, int lnki_wiki, byte[] lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page
, int orig_wiki, byte[] orig_ttl, int orig_ext, int file_w, int file_h, double file_time, int file_page
, long temp_file_size, int temp_view_count, long temp_view_date, int temp_w
) {
this.uid = uid; this.db_state = db_state;
this.lnki_wiki = lnki_wiki; this.lnki_ttl = lnki_ttl; this.lnki_type = lnki_type; this.lnki_upright = lnki_upright; this.lnki_w = lnki_w; this.lnki_h = lnki_h; this.lnki_time = lnki_time; this.lnki_page = lnki_page;
this.orig_wiki = orig_wiki; this.orig_ttl = orig_ttl; this.orig_ext = orig_ext; this.file_w = file_w; this.file_h = file_h; this.file_time = file_time; this.file_page = file_page;
this.temp_file_size = temp_file_size; this.temp_view_count = temp_view_count; this.temp_view_date = temp_view_date; this.temp_w = temp_w;
lnki_key_bfr
.Add_int_variable(lnki_wiki).Add_byte_pipe()
.Add(lnki_ttl).Add_byte_pipe()
.Add_int_variable(lnki_type).Add_byte_pipe()
.Add_double(lnki_upright).Add_byte_pipe()
.Add_int_variable(lnki_w).Add_byte_pipe()
.Add_int_variable(lnki_h).Add_byte_pipe()
.Add_double(lnki_time).Add_byte_pipe()
.Add_int_variable(lnki_page)
;
lnki_key = lnki_key_bfr.Xto_bry_and_clear();
}
public int Uid() {return uid;} private int uid;
public byte Db_state() {return db_state;} public void Db_state_(byte v) {db_state = v;} private byte db_state;
public byte[] Lnki_key() {return lnki_key;} private final byte[] lnki_key;
public int Lnki_wiki() {return lnki_wiki;} private final int lnki_wiki;
public byte[] Lnki_ttl() {return lnki_ttl;} private final byte[] lnki_ttl;
public int Lnki_type() {return lnki_type;} private final int lnki_type;
public double Lnki_upright() {return lnki_upright;} private final double lnki_upright;
public int Lnki_w() {return lnki_w;} private final int lnki_w;
public int Lnki_h() {return lnki_h;} private final int lnki_h;
public double Lnki_time() {return lnki_time;} private final double lnki_time;
public int Lnki_page() {return lnki_page;} private final int lnki_page;
public int Orig_wiki() {return orig_wiki;} private final int orig_wiki;
public byte[] Orig_ttl() {return orig_ttl;} private final byte[] orig_ttl;
public int Orig_ext() {return orig_ext;} private final int orig_ext;
public int File_w() {return file_w;} private final int file_w;
public int File_h() {return file_h;} private final int file_h;
public double File_time() {return file_time;} private final double file_time;
public int File_page() {return file_page;} private final int file_page;
public long Temp_file_size() {return temp_file_size;} private long temp_file_size;
public int Temp_view_count() {return temp_view_count;} private int temp_view_count;
public long Temp_view_date() {return temp_view_date;} private long temp_view_date;
public int Temp_w() {return temp_w;} private int temp_w;
public static final Xofc_cache_itm Null = null;
}

View File

@@ -0,0 +1,154 @@
/*
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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.dbs.*;
class Xofc_cache_tbl {
private String tbl_name = "user_file_cache"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private String
fld_uid
, fld_lnki_wiki, fld_lnki_ttl, fld_lnki_type, fld_lnki_upright, fld_lnki_w, fld_lnki_h, fld_lnki_time, fld_lnki_page
, fld_orig_wiki, fld_orig_ttl, fld_orig_ext, fld_file_w, fld_file_h, fld_file_time, fld_file_page
, fld_temp_file_size, fld_temp_view_count, fld_temp_view_date, fld_temp_w
;
private Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr(); private Db_stmt select_stmt;
private final Bry_bfr lnki_key_bfr = Bry_bfr.reset_(255);
public void Conn_(Db_conn new_conn, boolean created) {
this.conn = new_conn; flds.Clear();
fld_uid = flds.Add_int_pkey_autonum("uid");
fld_lnki_wiki = flds.Add_int("lnki_wiki");
fld_lnki_ttl = flds.Add_str("lnki_ttl", 255);
fld_lnki_type = flds.Add_int("lnki_type");
fld_lnki_upright = flds.Add_double("lnki_upright");
fld_lnki_w = flds.Add_int("lnki_w");
fld_lnki_h = flds.Add_int("lnki_h");
fld_lnki_time = flds.Add_double("lnki_time");
fld_lnki_page = flds.Add_int("lnki_page");
fld_orig_wiki = flds.Add_int("orig_wiki");
fld_orig_ttl = flds.Add_str("orig_ttl", 255);
fld_orig_ext = flds.Add_int("orig_ext");
fld_file_w = flds.Add_int("file_w");
fld_file_h = flds.Add_int("file_h");
fld_file_time = flds.Add_double("file_time");
fld_file_page = flds.Add_int("file_page");
fld_temp_file_size = flds.Add_long("temp_file_size");
fld_temp_view_count = flds.Add_int("temp_view_count");
fld_temp_view_date = flds.Add_long("temp_view_date");
fld_temp_w = flds.Add_int("temp_w");
if (created) {
Db_meta_tbl meta = Db_meta_tbl.new_(tbl_name, flds
, Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_lnki_wiki, fld_lnki_ttl, fld_lnki_type, fld_lnki_upright, fld_lnki_w, fld_lnki_h, fld_lnki_time, fld_lnki_page)
);
conn.Exec_create_tbl_and_idx(meta);
}
select_stmt = null;
stmt_bldr.Conn_(conn, tbl_name, flds, fld_uid);
}
public Xofc_cache_itm Select_one(int lnki_wiki, byte[] lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page) {
if (select_stmt == null) select_stmt = conn.Rls_reg(conn.Stmt_select(tbl_name, flds, String_.Ary(fld_lnki_wiki, fld_lnki_ttl, fld_lnki_type, fld_lnki_upright, fld_lnki_w, fld_lnki_h, fld_lnki_time, fld_lnki_page)));
Db_rdr rdr = Db_rdr_.Null;
try {
rdr = select_stmt.Clear()
.Crt_int (fld_lnki_wiki , lnki_wiki)
.Crt_bry_as_str (fld_lnki_ttl , lnki_ttl)
.Crt_int (fld_lnki_type , lnki_type)
.Crt_double (fld_lnki_upright , lnki_upright)
.Crt_int (fld_lnki_w , lnki_w)
.Crt_int (fld_lnki_h , lnki_h)
.Crt_double (fld_lnki_time , lnki_time)
.Crt_int (fld_lnki_page , lnki_page)
.Exec_select_as_rdr();
return rdr.Move_next() ? new_itm(rdr) : Xofc_cache_itm.Null;
}
finally {rdr.Rls();}
}
public void Select_all(Bry_bfr fil_key_bldr, OrderedHash hash) {
hash.Clear();
Db_stmt stmt = conn.Stmt_select(tbl_name, flds, Db_meta_fld.Ary_empy);
Db_rdr rdr = Db_rdr_.Null;
try {
rdr = stmt.Exec_select_as_rdr();
while (rdr.Move_next()) {
Xofc_cache_itm itm = new_itm(rdr);
byte[] key = Bry_.Empty;
hash.Add(key, itm);
}
}
finally {rdr.Rls();}
}
public void Db_save(Xofc_cache_itm itm) {
try {
Db_stmt stmt = stmt_bldr.Get(itm.Db_state());
switch (itm.Db_state()) {
case Db_cmd_mode.Tid_create: stmt.Clear().Val_int(fld_uid, itm.Uid()); Db_save_modify(stmt, itm); stmt.Exec_insert(); break;
case Db_cmd_mode.Tid_update: stmt.Clear(); Db_save_modify(stmt, itm); stmt.Crt_int(fld_uid, itm.Uid()).Exec_update(); break;
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_uid, itm.Uid()); stmt.Exec_delete(); break;
case Db_cmd_mode.Tid_ignore: break;
default: throw Err_.unhandled(itm.Db_state());
}
itm.Db_state_(Db_cmd_mode.Tid_ignore);
} catch (Exception e) {stmt_bldr.Rls(); throw Err_.err_(e, Err_.Message_gplx(e));}
}
private void Db_save_modify(Db_stmt stmt, Xofc_cache_itm itm) {
stmt.Val_int (itm.Lnki_wiki())
.Val_bry_as_str (itm.Lnki_ttl())
.Val_int (itm.Lnki_type())
.Val_double (itm.Lnki_upright())
.Val_int (itm.Lnki_w())
.Val_int (itm.Lnki_h())
.Val_double (itm.Lnki_time())
.Val_int (itm.Lnki_page())
.Val_int (itm.Orig_wiki())
.Val_bry_as_str (itm.Orig_ttl())
.Val_int (itm.Orig_ext())
.Val_int (itm.File_w())
.Val_int (itm.File_h())
.Val_double (itm.File_time())
.Val_int (itm.File_page())
.Val_long (itm.Temp_file_size())
.Val_int (itm.Temp_view_count())
.Val_long (itm.Temp_view_date())
.Val_int (itm.Temp_w())
;
}
private Xofc_cache_itm new_itm(Db_rdr rdr) {
return new Xofc_cache_itm
( lnki_key_bfr
, rdr.Read_int (fld_uid)
, Db_cmd_mode.Tid_ignore
, rdr.Read_int (fld_lnki_wiki)
, rdr.Read_bry_by_str (fld_lnki_ttl)
, rdr.Read_int (fld_lnki_type)
, rdr.Read_double (fld_lnki_upright)
, rdr.Read_int (fld_lnki_w)
, rdr.Read_int (fld_lnki_h)
, Xof_lnki_time.Db_load_double (rdr, fld_lnki_time)
, Xof_lnki_page.Db_load_int (rdr, fld_lnki_page)
, rdr.Read_int (fld_orig_wiki)
, rdr.Read_bry_by_str (fld_orig_ttl)
, rdr.Read_int (fld_orig_ext)
, rdr.Read_int (fld_file_w)
, rdr.Read_int (fld_file_h)
, Xof_lnki_time.Db_load_double (rdr, fld_file_time)
, Xof_lnki_page.Db_load_int (rdr, fld_file_page)
, rdr.Read_long (fld_temp_file_size)
, rdr.Read_int (fld_temp_view_count)
, rdr.Read_long (fld_temp_view_date)
, rdr.Read_int (fld_temp_w)
);
}
}

View File

@@ -54,7 +54,7 @@ public class Xofc_fil_itm implements CompareAble {
.Add_yn(is_orig).Add_byte_pipe()
.Add_int_variable(w).Add_byte_pipe()
.Add_int_variable(h).Add_byte_pipe()
.Add_int_variable(Xof_doc_thumb.X_int(time))
.Add_int_variable(Xof_lnki_time.X_int(time))
;
return bfr.Xto_bry_and_clear();
}
@@ -63,7 +63,7 @@ public class Xofc_fil_itm implements CompareAble {
.Add(name).Add_byte_pipe()
.Add_yn(is_orig).Add_byte_pipe()
.Add_int_variable(w).Add_byte_pipe()
.Add_double(Xof_doc_thumb.Db_save_double(time)).Add_byte_pipe()
.Add_double(Xof_lnki_time.Db_save_double(time)).Add_byte_pipe()
.Add_int_variable(page)
;
return bfr.Xto_bry_and_clear();

View File

@@ -48,7 +48,7 @@ class Xofc_fil_mgr {
if (itm == Xofc_fil_itm.Null) { // not in memory
itm = tbl.Select_one_v1(dir_id, name, is_orig, w, h, time);
if (itm == Xofc_fil_itm.Null) { // not in db
itm = Make_v1(dir_id, name, is_orig, w, h, time, Xof_doc_page.Null, ext, size);
itm = Make_v1(dir_id, name, is_orig, w, h, time, Xof_lnki_page.Null, ext, size);
created.Val_(true);
}
else // NOTE: itm loaded from tbl; add to hash; do not add if created b/c Make adds to hash;
@@ -127,8 +127,8 @@ class Xofc_fil_mgr {
byte[] md5 = Xof_xfer_itm_.Md5_(ttl);
int itm_ext_id = itm.Ext().Id();
Io_url fil_url = url_bldr.Init_for_trg_file(mode_id, trg_repo, ttl, md5, itm.Ext(), itm.W()
, Xof_doc_thumb.Convert_to_xowa_thumbtime (itm_ext_id, itm.Time())
, Xof_doc_thumb.Convert_to_xowa_page (itm_ext_id, itm.Time())
, Xof_lnki_time.Convert_to_xowa_thumbtime (itm_ext_id, itm.Time())
, Xof_lnki_time.Convert_to_xowa_page (itm_ext_id, itm.Time())
).Xto_url();
Io_mgr._.DeleteFil_args(fil_url).MissingFails_off().Exec();
itm.Cmd_mode_delete_();

View File

@@ -77,7 +77,7 @@ class Xofc_fil_tbl {
.Val_bool_as_byte(fld_is_orig, itm.Is_orig())
.Val_int(fld_w, itm.W())
.Val_int(fld_h, itm.H())
.Val_int(fld_time, Xof_doc_thumb.Db_save_int(itm.Time()))
.Val_int(fld_time, Xof_lnki_time.Db_save_int(itm.Time()))
.Val_int(fld_page, itm.Page())
.Val_int(fld_ext, itm.Ext().Id())
.Val_long(fld_size, itm.Size())
@@ -98,7 +98,7 @@ class Xofc_fil_tbl {
.Crt_bool_as_byte(fld_is_orig, fil_is_orig)
.Crt_int(fld_w, fil_w)
.Crt_int(fld_h, fil_h)
.Crt_int(fld_time, Xof_doc_thumb.Db_save_int(fil_thumbtime))
.Crt_int(fld_time, Xof_lnki_time.Db_save_int(fil_thumbtime))
.Exec_select_as_rdr();
return rdr.Move_next() ? new_itm(rdr) : Xofc_fil_itm.Null;
}
@@ -113,7 +113,7 @@ class Xofc_fil_tbl {
.Crt_bry_as_str(fld_name, name)
.Crt_bool_as_byte(fld_is_orig, is_orig)
.Crt_int(fld_w, w)
.Crt_int(fld_time, Xof_doc_thumb.Db_save_int(time))
.Crt_int(fld_time, Xof_lnki_time.Db_save_int(time))
.Crt_int(fld_page, page)
.Exec_select_as_rdr();
return rdr.Move_next() ? new_itm(rdr) : Xofc_fil_itm.Null;
@@ -146,8 +146,8 @@ class Xofc_fil_tbl {
, rdr.Read_byte(fld_is_orig) != Byte_.Zero
, rdr.Read_int(fld_w)
, rdr.Read_int(fld_h)
, Xof_doc_thumb.Db_load_int(rdr, fld_time)
, Xof_doc_page.Null
, Xof_lnki_time.Db_load_int(rdr, fld_time)
, Xof_lnki_page.Null
, Xof_ext_.new_by_id_(rdr.Read_int(fld_ext))
, rdr.Read_long(fld_size)
, rdr.Read_long(fld_cache_time)

View File

@@ -17,85 +17,94 @@ 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.xowa.files.gui.*; import gplx.xowa.files.repos.*;
public class Xof_fsdb_itm {
private int lnki_upright_patch;
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Lnki_md5() {return lnki_md5;} private byte[] lnki_md5;
public Xof_ext Lnki_ext() {return lnki_ext;} public void Lnki_ext_(Xof_ext v) {lnki_ext = v;} private Xof_ext lnki_ext;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public byte Lnki_type_as_mode() {return lnki_type_as_mode;} private byte lnki_type_as_mode;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public Xof_fsdb_itm Lnki_size_(int w, int h) {lnki_w = w; lnki_h = h; return this;}
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} public void Lnki_time_(double v) {lnki_time = v;} private double lnki_time = Xof_doc_thumb.Null;
public int Lnki_page() {return lnki_page;} public void Lnki_page_(int v) {lnki_page = v;} private int lnki_page = Xof_doc_page.Null;
public byte Orig_repo_id() {return orig_repo_id;} public void Orig_repo_id_(byte v) {orig_repo_id = v;} private byte orig_repo_id = Xof_repo_itm.Repo_null;
public byte[] Orig_repo_name() {return orig_repo_name;} public void Orig_repo_name_(byte[] v) {orig_repo_name = v;} private byte[] orig_repo_name;
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
public int Orig_w() {return orig_w;} private int orig_w = Xop_lnki_tkn.Width_null;
public int Orig_h() {return orig_h;} private int orig_h = Xop_lnki_tkn.Height_null;
public Xof_fsdb_itm Orig_size_(int w, int h) {orig_w = w; orig_h = h; return this;}
public byte[] Orig_redirect() {return orig_redirect;} public void Orig_redirect_(byte[] v) {orig_redirect = v;} private byte[] orig_redirect = Bry_.Empty;
public byte Orig_status() {return orig_status;} public void Orig_status_(byte v) {orig_status = v;} private byte orig_status = gplx.xowa.files.origs.Xof_orig_wkr_.Status_null;
public boolean File_is_orig() {return file_is_orig;} public void File_is_orig_(boolean v) {file_is_orig = v;} private boolean file_is_orig;
public int File_w() {return file_w;} private int file_w;
public int Html_uid() {return html_uid;} public void Html_uid_(int v) {html_uid = v;} private int html_uid;
public byte Html_elem_tid() {return html_elem_tid;} public void Html_elem_tid_(byte v) {html_elem_tid = v;} private byte html_elem_tid;
public int Html_w() {return html_w;} private int html_w;
public int Html_h() {return html_h;} private int html_h;
public Xof_fsdb_itm Html_size_(int w, int h) {html_w = w; html_h = h; return this;}
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} public void Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v;} private Js_img_wkr html_img_wkr;
public Io_url Html_view_url() {return html_view_url;} public void Html_view_url_(Io_url v) {html_view_url = v;} private Io_url html_view_url;
public Io_url Html_orig_url() {return html_orig_url;} public void Html_orig_url_(Io_url v) {html_orig_url = v;} private Io_url html_orig_url = Io_url_.Null;
public int Gallery_mgr_h() {return gallery_mgr_h;} public void Gallery_mgr_h_(int v) {gallery_mgr_h = v;} private int gallery_mgr_h = Int_.Neg1;
public byte Rslt_bin() {return rslt_bin;} public void Rslt_bin_(byte v) {rslt_bin = v;} private byte rslt_bin;
public byte Rslt_cnv() {return rslt_cnv;} public void Rslt_cnv_(byte v) {rslt_cnv = v;} private byte rslt_cnv;
public boolean Rslt_fil_created() {return rslt_fil_created;} public void Rslt_fil_created_(boolean v) {rslt_fil_created = v;} private boolean rslt_fil_created;
public void Ctor_by_orig(byte repo, byte[] ttl, int w, int h, byte[] redirect) {
this.orig_repo_id = repo; this.orig_ttl = ttl; this.orig_w = w; this.orig_h = h; this.orig_redirect = redirect;
}
public void Ctor_by_orig_redirect(byte[] redirect_ttl) {
orig_redirect = redirect_ttl;
lnki_ttl = redirect_ttl;
lnki_ext = Xof_ext_.new_by_ttl_(lnki_ttl);
lnki_md5 = Xof_xfer_itm_.Md5_calc(lnki_ttl);
}
public void Ctor_by_html(Xof_repo_itm repo, Xof_url_bldr url_bldr, Xof_img_size img_size, byte exec_tid) {
Html_size_calc(img_size, exec_tid);
byte[] name_bry = Bry_.Len_eq_0(orig_redirect) ? lnki_ttl : orig_redirect;
if (!lnki_ext.Id_is_media() && lnki_time != Xof_doc_thumb.Null) // file is not media, but has thumbtime; this check can't be moved to Lnki_time_() b/c it needs ext
lnki_time = Xof_doc_thumb.Null; // set time to null; needed else url will reference thumbtime; PAGE:en.w:Moon; EX:[[File:Lunar libration with phase Oct 2007 450px.gif|thumbtime=0:02]]; DATE:2014-07-20
html_view_url = url_bldr.Init_for_trg_file(lnki_type_as_mode, repo, name_bry, lnki_md5, lnki_ext, html_w, lnki_time, lnki_page).Xto_url();
html_orig_url = url_bldr.Init_for_trg_file(Xof_repo_itm.Mode_orig, repo, name_bry, lnki_md5, lnki_ext, Xof_img_size.Size_null_deprecated, Xof_doc_thumb.Null, Xof_doc_page.Null).Xto_url();
}
public void Ctor_by_lnki(byte[] lnki_ttl, Xof_ext ext, byte[] md5, byte lnki_type, int lnki_w, int lnki_h, int lnki_upright_patch, double lnki_upright, double lnki_time, int lnki_page) {
this.lnki_ttl = lnki_ttl; this.lnki_ext = ext; this.lnki_md5 = md5;
this.lnki_w = lnki_w; this.lnki_h = lnki_h;
public class Xof_fsdb_itm {
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Lnki_md5() {return lnki_md5;} private byte[] lnki_md5;
public Xof_ext Lnki_ext() {return lnki_ext;} private Xof_ext lnki_ext;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time = Xof_lnki_time.Null;
public int Lnki_page() {return lnki_page;} private int lnki_page = Xof_lnki_page.Null;
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_itm.Repo_null;
public byte[] Orig_repo_name() {return orig_repo_name;} private byte[] orig_repo_name;
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
public int Orig_ext() {return orig_ext;} private int orig_ext;
public int Orig_w() {return orig_w;} private int orig_w = Xop_lnki_tkn.Width_null;
public int Orig_h() {return orig_h;} private int orig_h = Xop_lnki_tkn.Height_null;
public byte[] Orig_redirect() {return orig_redirect;} private byte[] orig_redirect = Bry_.Empty;
public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig;
public int File_w() {return file_w;} private int file_w;
public int Html_uid() {return html_uid;} private int html_uid;
public byte Html_elem_tid() {return html_elem_tid;} private byte html_elem_tid;
public int Html_w() {return html_w;} private int html_w;
public int Html_h() {return html_h;} private int html_h;
public Io_url Html_view_url() {return html_view_url;} private Io_url html_view_url;
public Io_url Html_orig_url() {return html_orig_url;} private Io_url html_orig_url = Io_url_.Null;
public int Gallery_mgr_h() {return gallery_mgr_h;} private int gallery_mgr_h = Int_.Neg1;
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} private Js_img_wkr html_img_wkr;
public boolean Orig_exists() {return orig_exists;} public void Orig_exists_y_() {orig_exists = Bool_.Y;} public void Orig_exists_n_() {orig_exists = Bool_.N;} private boolean orig_exists;
public boolean File_exists() {return file_exists;} public void File_exists_y_() {file_exists = Bool_.Y;} public void File_exists_n_() {file_exists = Bool_.N;} public void File_exists_(boolean v) {file_exists = v;} private boolean file_exists;
public boolean File_resized() {return file_resized;} public void File_resized_y_() {file_resized = Bool_.Y;} private boolean file_resized;
public boolean Fsdb_insert() {return fsdb_insert;} public void Fsdb_insert_y_() {fsdb_insert = true;} private boolean fsdb_insert;
public void Ctor_by_lnki(byte[] lnki_ttl, byte lnki_type, int lnki_w, int lnki_h, int lnki_upright_patch, double lnki_upright, double lnki_time, int lnki_page) {
this.lnki_type = lnki_type; this.lnki_w = lnki_w; this.lnki_h = lnki_h;
this.lnki_upright_patch = lnki_upright_patch;
this.lnki_upright = lnki_upright; this.lnki_time = lnki_time; this.lnki_page = lnki_page;
this.Lnki_type_(lnki_type);
this.orig_ttl = lnki_ttl;
this.orig_ttl = lnki_ttl;
// this.file_is_orig = !(Xop_lnki_type.Id_defaults_to_thumb(lnki_type) || lnki_w != Xop_lnki_tkn.Width_null || lnki_h != Xop_lnki_tkn.Height_null); // DELETE: overriden below.
this.Lnki_ttl_(lnki_ttl);
} private int lnki_upright_patch;
public void Ctor_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, int orig_ext, int orig_w, int orig_h, byte[] orig_redirect) {
this.orig_repo_id = orig_repo_id; this.orig_repo_name = orig_repo_name;
this.orig_ttl = orig_ttl; this.orig_ext = orig_ext;
this.orig_w = orig_w; this.orig_h = orig_h; this.orig_redirect = orig_redirect;
if (orig_ext != lnki_ext.Id())
this.Lnki_ext_(Xof_ext_.new_by_id_(orig_ext)); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
this.Lnki_ttl_(orig_redirect); // update fsdb with atrs of B.png
}
public void Html_size_calc(Xof_img_size img_size, byte exec_tid) {
if (!lnki_ext.Id_is_audio_strict()) { // audio does not have html size calculated; everything else does
img_size.Html_size_calc(exec_tid, lnki_w, lnki_h, lnki_type, lnki_upright_patch, lnki_upright, lnki_ext.Id(), orig_w, orig_h, Xof_img_size.Thumb_width_img);
html_w = img_size.Html_w(); html_h = img_size.Html_h(); file_w = img_size.File_w();
file_is_orig = img_size.File_is_orig();
lnki_type_as_mode = file_is_orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb;
}
public void Ctor_for_html(byte exec_tid, Xof_img_size img_size, Xof_repo_itm repo, Xof_url_bldr url_bldr) {
Calc_html_size(exec_tid, img_size);
html_view_url = url_bldr.To_url_trg(repo, this, file_is_orig);
html_orig_url = url_bldr.To_url_trg(repo, this, Bool_.Y);
}
public void Lnki_type_(byte v) {
this.lnki_type = v;
if (lnki_ext.Id_is_audio_strict())
file_is_orig = true;
else
this.file_is_orig = !(Xop_lnki_type.Id_defaults_to_thumb(lnki_type) || lnki_w != Xop_lnki_tkn.Width_null || lnki_h != Xop_lnki_tkn.Height_null);
this.lnki_type_as_mode = file_is_orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb;
}
public void Lnki_ttl_(byte[] v) {
public void Ctor_by_fsdb_make
( byte[] lnki_ttl, int lnki_w, int lnki_h, double lnki_time, int lnki_page
, byte orig_repo_id, int orig_w, int orig_h, byte[] orig_redirect
, boolean file_is_orig
) {
this.lnki_w = lnki_w; this.lnki_h = lnki_h; this.lnki_time = lnki_time; this.lnki_page = lnki_page;
this.orig_repo_id = orig_repo_id; this.orig_ttl = lnki_ttl; this.orig_w = orig_w; this.orig_h = orig_h; this.orig_redirect = orig_redirect;
this.file_is_orig = file_is_orig;
this.html_w = lnki_w; this.html_h = lnki_h; // set html_size as file_size (may try to optimize later by removing similar thumbs (EX: 220,221 -> 220))
this.Lnki_ttl_(lnki_ttl);
}
public void Lnki_ext_(Xof_ext v) {lnki_ext = v;}
public void Lnki_size_(int w, int h) {this.lnki_w = w; this.lnki_h = h;}
public void Orig_repo_name_(byte[] v) {orig_repo_name = v;}
public void Html_view_url_(Io_url v) {html_view_url = v;}
public void Html_orig_url_(Io_url v) {html_orig_url = v;}
public void Html_size_(int w, int h) {html_w = w; html_h = h;}
public void Html_uid_(int v) {html_uid = v;}
public void Html_elem_tid_(byte v) {html_elem_tid = v;}
public void Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v;}
public void Gallery_mgr_h_(int v) {gallery_mgr_h = v;}
private void Lnki_ttl_(byte[] v) {
lnki_ttl = v;
lnki_ext = Xof_ext_.new_by_ttl_(v);
lnki_md5 = Xof_xfer_itm_.Md5_calc(v);
}
private void Calc_html_size(byte exec_tid, Xof_img_size img_size) {
if (!lnki_ext.Id_is_media() && lnki_time != Xof_lnki_time.Null) // file is not media, but has thumbtime; this check can't be moved to Lnki_time_() b/c it needs ext
lnki_time = Xof_lnki_time.Null; // set time to null; needed else url will reference thumbtime; PAGE:en.w:Moon; EX:[[File:Lunar libration with phase Oct 2007 450px.gif|thumbtime=0:02]]; DATE:2014-07-20
if (lnki_ext.Id_is_audio_strict()) // audio does not have html size calculated; everything else does
file_is_orig = Bool_.Y;
else {
img_size.Html_size_calc(exec_tid, lnki_w, lnki_h, lnki_type, lnki_upright_patch, lnki_upright, lnki_ext.Id(), orig_w, orig_h, Xof_img_size.Thumb_width_img);
html_w = img_size.Html_w(); html_h = img_size.Html_h(); file_w = img_size.File_w();
file_is_orig = img_size.File_is_orig();
}
}
}

View File

@@ -1,141 +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.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.xowa.files.caches.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.gui.*; import gplx.xowa.wmfs.apis.*;
class Xof_fsdb_wkr {
private final Gfo_usr_dlg usr_dlg; private final Xof_fsdb_mgr fsdb_mgr; private final Xof_cache_mgr cache_mgr; private final Xow_repo_mgr repo_mgr; private final Xof_url_bldr url_bldr;
private final Xof_img_size img_size = new Xof_img_size(); private final ListAdp get_list = ListAdp_.new_();
public Xof_fsdb_wkr(Xof_fsdb_mgr fsdb_mgr, Gfo_usr_dlg usr_dlg, Xof_cache_mgr cache_mgr, Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr) {
this.fsdb_mgr = fsdb_mgr; this.usr_dlg = usr_dlg; this.cache_mgr = cache_mgr; this.repo_mgr = repo_mgr; this.url_bldr = url_bldr;
}
public void Fsdb_search(byte exec_tid, ListAdp itms, Xoa_page page, Xog_js_wkr js_wkr) {
synchronized (get_list) {
get_list.Clear();
int itms_len = itms.Count();
for (int i = 0; i < itms_len; i++) {
if (usr_dlg.Canceled()) return;
Xof_fsdb_itm itm = (Xof_fsdb_itm)itms.FetchAt(i);
switch (itm.Orig_status()) {
case Xof_orig_wkr_.Status_found: // item is on disk and in orig_regy; just update data, html_view and cache_mgr;
Xof_repo_itm repo_itm = repo_mgr.Repos_get_by_wiki(itm.Orig_repo_name()).Trg();
itm.Ctor_by_html(repo_itm, url_bldr, img_size, exec_tid);
Js_img_mgr.Update_img(page, js_wkr, itm); // NOTE: needed when opening 2+ tabs and missing image is on 2+ pages; 2nd page will have img as Xof_orig_wkr_.Status_found; DATE:2014-10-20
cache_mgr.Reg_and_check_for_size_0(itm);
break;
case Xof_orig_wkr_.Status_missing_orig:
case Xof_orig_wkr_.Status_noop: // NOTE: previous attempt was noop; only occurs if oga and exec_tid != viewer
case Xof_orig_wkr_.Status_null: get_list.Add(itm); break; // item is either not on disk, or not in orig_regy; add to list and try to get from fsdb_mgr
case Xof_orig_wkr_.Status_missing_qry:
case Xof_orig_wkr_.Status_missing_bin: break; // item is missing; just exit
default: throw Err_.unhandled(itm.Orig_status());
}
}
int get_len = get_list.Count();
for (int i = 0; i < get_len; i++) {
if (usr_dlg.Canceled()) return;
Xof_fsdb_itm itm = (Xof_fsdb_itm)get_list.FetchAt(i);
try {
Get_itm(exec_tid, itm, page, js_wkr);
} catch (Exception e) {usr_dlg.Warn_many("", "", "file.search.error: page=~{0} img=~{1} err=~{2}", String_.new_utf8_(page.Ttl().Raw()), String_.new_utf8_(itm.Lnki_ttl()), Err_.Message_gplx_brief(e));}
}
}
}
private void Get_itm(byte exec_tid, Xof_fsdb_itm itm, Xoa_page page, Xog_js_wkr js_wkr) {
if (itm.Lnki_ext().Is_not_viewable(exec_tid)) return; // do not get if not needed; EX: exec_tid = page and itm is audio
if (Find_by_itm(exec_tid, itm, fsdb_mgr.Orig_mgr(), img_size)) { // itm exists in orig_regy
Xof_repo_pair repo_pair = repo_mgr.Repos_get_by_wiki(itm.Orig_repo_name());
if (repo_pair == null) {
fsdb_mgr.Orig_mgr().Insert(Xof_repo_itm.Repo_unknown, itm.Orig_ttl(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), itm.Orig_redirect(), Xof_orig_wkr_.Status_missing_qry);
return;
}
byte repo_tid = repo_pair.Repo_idx(); // NOTE: should be itm.Orig_repo, but throws null refs
if (itm.Lnki_ext().Is_not_viewable(exec_tid)) { // check viewable again b/c orig_mgr may have changed ext; EX: ogg -> oga
itm.Rslt_bin_(Xof_bin_wkr_.Tid_noop);
fsdb_mgr.Orig_mgr().Insert(repo_tid, itm.Orig_ttl(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), itm.Orig_redirect(), Xof_orig_wkr_.Status_noop);
return;
}
if (fsdb_mgr.Bin_mgr().Find_to_url_as_bool(exec_tid, itm)) {
fsdb_mgr.Orig_mgr().Insert(repo_tid, itm.Orig_ttl(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), itm.Orig_redirect(), Xof_orig_wkr_.Status_found);
// TODO: this "breaks" tests b/c mock bin_wkr is fsdb;
if (itm.Rslt_bin() != Xof_bin_wkr_.Tid_fsdb_xowa) // if bin is from fsdb, don't save it; occurs when page has new file listed twice; 1st file inserts into fsdb; 2nd file should find in fsdb and not save again
Save_itm(itm);
Js_img_mgr.Update_img(page, js_wkr, itm);
}
else {
usr_dlg.Warn_many("", "", "file not found: page=~{0} file=~{1} width=~{2}", page.Url().Xto_full_str_safe(), String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w());
itm.Rslt_bin_(Xof_bin_wkr_.Tid_not_found);
fsdb_mgr.Orig_mgr().Insert(repo_tid, itm.Orig_ttl(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), itm.Orig_redirect(), Xof_orig_wkr_.Status_missing_bin);
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid()); // TODO: update caption with "" if image is missing
}
}
else {
fsdb_mgr.Orig_mgr().Insert(Xof_repo_itm.Repo_unknown, itm.Orig_ttl(), itm.Lnki_ext().Id(), itm.Orig_w(), itm.Orig_h(), itm.Orig_redirect(), Xof_orig_wkr_.Status_missing_qry);
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid()); // TODO: update caption with "" if image is missing
}
}
private void Save_itm(Xof_fsdb_itm itm) {
Io_url html_url = itm.Html_view_url();
long bin_len = Io_mgr._.QueryFil(html_url).Size();
gplx.ios.Io_stream_rdr bin_rdr = gplx.ios.Io_stream_rdr_.file_(html_url);
try {
bin_rdr.Open();
if (itm.Lnki_ext().Id_is_thumbable_img()) {
if (itm.File_is_orig()) {
Fsd_img_itm img_itm = new Fsd_img_itm();
fsdb_mgr.Mnt_mgr().Img_insert(img_itm, itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
else {
Fsd_thm_itm thm_itm = Fsd_thm_itm.new_();
fsdb_mgr.Mnt_mgr().Thm_insert(thm_itm, itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), itm.Lnki_time(), itm.Lnki_page(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
}
else {
if (itm.Lnki_ext().Id_is_video() && !itm.File_is_orig()) { // insert as thumbnail
Fsd_thm_itm thm_itm = Fsd_thm_itm.new_();
fsdb_mgr.Mnt_mgr().Thm_insert(thm_itm, itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Html_w(), itm.Html_h(), itm.Lnki_time(), itm.Lnki_page(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
else {
Fsd_fil_itm fil_itm = new Fsd_fil_itm();
fsdb_mgr.Mnt_mgr().Fil_insert(fil_itm, itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), Fsd_thm_tbl.Modified_null, Fsd_thm_tbl.Hash_null, bin_len, bin_rdr);
}
}
if (!Env_.Mode_testing())
cache_mgr.Reg(itm, bin_len);
}
catch (Exception e) {
usr_dlg.Warn_many("", "", "failed to save file: ttl=~{0} url=~{1} err=~{2}", String_.new_utf8_(itm.Lnki_ttl()), html_url.Raw(), Err_.Message_gplx(e));
}
finally {bin_rdr.Rls();}
}
private static boolean Find_by_itm(byte get_exec_tid, Xof_fsdb_itm itm, Xof_orig_mgr orig_mgr, Xof_img_size img_size) {
byte[] itm_ttl = itm.Lnki_ttl();
Xof_orig_itm orig = orig_mgr.Find_by_ttl_or_null(itm_ttl);
if (orig == Xof_orig_itm.Null) { // not found in any wkr
itm.Orig_status_(Xof_orig_wkr_.Status_missing_orig);
return false; // exit now
}
itm.Orig_status_(Xof_orig_wkr_.Status_found);
byte[] orig_redirect = orig.Redirect();
if (Bry_.Len_gt_0(orig_redirect)) // redirect found
itm.Ctor_by_orig_redirect(orig_redirect);
itm.Orig_size_(orig.W(), orig.H());
itm.Html_size_calc(img_size, get_exec_tid); // orig found; recalc size
return true;
}
}

View File

@@ -21,7 +21,7 @@ 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 Xof_fsdb_wkr wkr; private boolean init = false; private boolean fsdb_enabled = false;
private boolean init = false; private boolean fsdb_enabled = false; private Xof_cache_mgr cache_mgr; 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_orig_mgr Orig_mgr() {return orig_mgr;} private final Xof_orig_mgr orig_mgr = new Xof_orig_mgr();
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 final Fsm_mnt_mgr mnt_mgr = new Fsm_mnt_mgr();
@@ -33,8 +33,8 @@ public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, GfoInvkAble {
Xow_core_data_mgr core_data_mgr = wiki.Data_mgr__core_mgr();
boolean schema_is_1 = core_data_mgr == null ? Bool_.Y : core_data_mgr.Cfg__schema_is_1(); // TEST: needed b/c some tests rely on txt_data_mgr
Xoa_app app = wiki.App();
Xof_cache_mgr cache_mgr = app.File_mgr__cache_mgr(); Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_();
Xow_repo_mgr repo_mgr = wiki.File_mgr__repo_mgr(); Xof_img_mgr img_mgr = app.File_mgr__img_mgr();
this.cache_mgr = app.File_mgr__cache_mgr(); this.url_bldr = Xof_url_bldr.new_v2_();
this.repo_mgr = wiki.File_mgr__repo_mgr(); Xof_img_mgr img_mgr = app.File_mgr__img_mgr();
Io_url db_dir = wiki.Fsys_mgr().File_dir();
Xof_fsdb_mode fsdb_mode = wiki.File_mgr__fsdb_mode();
orig_mgr.Init_by_wiki(db_dir, schema_is_1, wiki.Domain_bry(), app.Wmf_mgr().Download_wkr(), repo_mgr, url_bldr, fsdb_mode);
@@ -43,14 +43,17 @@ public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, GfoInvkAble {
mnt_mgr.Init_by_wiki(db_dir, schema_is_1);
this.bin_mgr = new Xof_bin_mgr(mnt_mgr, repo_mgr, cache_mgr, app.Wmf_mgr(), url_bldr);
bin_mgr.Init_by_wiki(img_mgr.Wkr_resize_img());
wkr = new Xof_fsdb_wkr(this, Xoa_app_.Usr_dlg(), cache_mgr, repo_mgr, url_bldr);
} catch (Exception exc) {throw Err_.new_fmt_("failed to initialize fsdb_mgr: wiki={0) err={1}", wiki.Domain_str(), Err_.Message_gplx_brief(exc));}
}
public void Fsdb_search_by_list(byte exec_tid, ListAdp itms, Xoa_page page, Xog_js_wkr js_wkr) {
if (!fsdb_enabled) return;
OrderedHash rv = OrderedHash_.new_bry_();
orig_mgr.Find_by_list(rv, itms, exec_tid);
wkr.Fsdb_search(exec_tid, itms, page, js_wkr);
int len = itms.Count();
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._;
for (int i = 0; i < len; i++) {
if (usr_dlg.Canceled()) return;
Xof_fsdb_itm itm = (Xof_fsdb_itm)itms.FetchAt(i);
Xof_file_wkr.Show_img(exec_tid, itm, usr_dlg, bin_mgr, mnt_mgr, cache_mgr, repo_mgr, js_wkr, img_size, url_bldr, page);
}
}
public void Txn_save() {
if (!fsdb_enabled) return;

View File

@@ -30,7 +30,7 @@ public class Fs_root_wkr_fsdb {
Orig_fil_itm orig_itm = orig_dir_mgr.Get_by_ttl(lnki_ttl);
if (orig_itm == Orig_fil_itm.Null) return false;
Io_url orig_url = orig_itm.Fil_url();
if (fsdb_itm.Lnki_type_as_mode() == Xof_repo_itm.Mode_orig) {
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);

View File

@@ -22,12 +22,12 @@ public class Xof_file_ext__bmp_tst {
@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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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

@@ -23,13 +23,13 @@ public class Xof_file_ext__flac_tst {
@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_missing().Rslt_fsdb_null()); // do not qry or get bin; (since file is not "viewable" immediately); DATE:2015-02-15
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_found().Rslt_fsdb_xowa());
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

@@ -20,16 +20,16 @@ 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]]; do not qry or get bin; (since file is not "viewable" immediately)
@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_missing().Rslt_fsdb_null());
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_found().Rslt_fsdb_xowa());
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

@@ -32,6 +32,6 @@ public class Xof_file_ext__ogg_tst {
@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_found().Rslt_fsdb_null().Rslt_conv_n());
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

@@ -23,14 +23,14 @@ public class Xof_file_ext__ogv_tst {
@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_found().Rslt_fsdb_xowa().Rslt_conv_n());
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_found().Rslt_fsdb_xowa().Rslt_conv_n());
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));
// 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

@@ -23,23 +23,23 @@ public class Xof_file_ext__png_tst {
@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_found().Rslt_fsdb_xowa());
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_found().Rslt_fsdb_xowa());
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_found().Rslt_fsdb_xowa());
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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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

View File

@@ -23,18 +23,18 @@ public class Xof_file_ext__svg_tst {
@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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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_fsdb_xowa()); // get 330
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

@@ -20,16 +20,16 @@ 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]]; do not qry or get bin; (since file is not "viewable" immediately); DATE:2014-08-17
@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_missing().Rslt_fsdb_null());
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_found().Rslt_fsdb_xowa());
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

@@ -21,16 +21,16 @@ 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]]; do not qry or get bin; (since file is not "viewable" immediately); DATE:2014-08-17
@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_missing().Rslt_fsdb_null());
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_found().Rslt_fsdb_xowa());
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

@@ -23,13 +23,13 @@ public class Xof_file_ext__xcf_tst {
@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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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_found().Rslt_fsdb_xowa().Rslt_conv_y());
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

@@ -20,7 +20,7 @@ import gplx.fsdb.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gp
import gplx.xowa.wikis.*; import gplx.xowa.files.repos.*;
import gplx.fsdb.data.*;
class Xof_file_fxt {
private Xoae_app app; private Xof_fsdb_mgr fsdb_mgr;
private Xoae_app app; private Xof_fsdb_mgr fsdb_mgr; private Xowe_wiki wiki;
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() {fsdb_mgr.Rls();}
public void Reset() {
@@ -28,7 +28,7 @@ class Xof_file_fxt {
Io_url fsys_db = Xoa_test_.Url_file_enwiki();
Xoa_test_.Db_init(fsys_db);
app = Xoa_app_fxt.app_(Op_sys.Cur().Os_name(), fsys_db);
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
wiki = Xoa_app_fxt.wiki_tst_(app);
wiki.File_mgr__fsdb_mode().Tid_make_y_();
Xof_repo_fxt.Repos_init(app.File_mgr(), true, wiki);
wiki.Db_mgr_create_as_sql(); // NOTE: must create as sql_db_mgr not txt_db_mgr
@@ -44,7 +44,7 @@ class Xof_file_fxt {
this.Init_orig_db(Xof_orig_arg.new_comm(ttl, w, h));
}
public void Init_orig_db(Xof_orig_arg arg) {
fsdb_mgr.Orig_mgr().Insert(arg.Repo(), arg.Page(), Xof_ext_.new_by_ttl_(arg.Page()).Id(), arg.W(), arg.H(), arg.Redirect(), Xof_orig_wkr_.Status_found);
fsdb_mgr.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) {
if (arg.Is_thumb())
@@ -53,16 +53,17 @@ class Xof_file_fxt {
fsdb_mgr.Mnt_mgr().Img_insert(tmp_img, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Modified(), arg.Hash(), arg.Bin().length, gplx.ios.Io_stream_rdr_.mem_(arg.Bin()));
}
public void Exec_get(Xof_exec_arg arg) {
byte[] ttl = arg.Ttl();
byte[] md5 = Xof_xfer_itm_.Md5_(ttl);
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
byte[] ttl_bry = arg.Ttl();
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Ctor_by_lnki(ttl, ext, md5, arg.Lnki_type(), arg.Lnki_w(), arg.Lnki_h(), Xof_patch_upright_tid_.Tid_all, arg.Lnki_upright(), arg.Lnki_time(), Xof_doc_page.Null);
itm.Ctor_by_lnki(ttl_bry, arg.Lnki_type(), arg.Lnki_w(), arg.Lnki_h(), Xof_patch_upright_tid_.Tid_all, arg.Lnki_upright(), arg.Lnki_time(), Xof_lnki_page.Null);
ListAdp itms_list = ListAdp_.new_(); itms_list.Add(itm);
fsdb_mgr.Fsdb_search_by_list(arg.Exec_tid(), itms_list, Xoae_page.Empty, Xog_js_wkr_.Null);
if (arg.Rslt_orig() != Xof_orig_wkr_.Status_null) Tfds.Eq(arg.Rslt_orig(), itm.Orig_status(), "rslt_orig");
if (arg.Rslt_fsdb() != Xof_bin_wkr_.Tid_null) Tfds.Eq(arg.Rslt_fsdb(), itm.Rslt_bin(), "rslt_fsdb");
if (arg.Rslt_conv() != Xof_cnv_wkr_.Tid_null) Tfds.Eq(arg.Rslt_conv(), itm.Rslt_cnv(), "rslt_conv");
fsdb_mgr.Orig_mgr().Find_by_list(OrderedHash_.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(arg.Exec_tid(), itms_list, page, Xog_js_wkr_.Null);
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);}
@@ -123,18 +124,18 @@ class Xof_fsdb_arg {
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_doc_page.Null;
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_doc_thumb.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_doc_thumb.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_doc_thumb.Null_as_int);}
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_doc_thumb.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_doc_thumb.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_doc_thumb.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_doc_thumb.Null_as_int);}
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_utf8_(ttl_str);
int ext = Xof_ext_.new_by_ttl_(ttl).Id();
@@ -152,20 +153,19 @@ class Xof_exec_arg {
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_doc_thumb.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_doc_page.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 byte Exec_tid() {return exec_tid;} public Xof_exec_arg Exec_tid_(byte v) {exec_tid = v; return this;} private byte exec_tid = Xof_exec_tid.Tid_wiki_page;
public byte Rslt_orig() {return rslt_orig;} private byte rslt_orig = Xof_orig_wkr_.Status_null;
public byte Rslt_fsdb() {return rslt_fsdb;} private byte rslt_fsdb = Xof_bin_wkr_.Tid_null;
public byte Rslt_conv() {return rslt_conv;} private byte rslt_conv = Xof_cnv_wkr_.Tid_null;
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_noop() {rslt_orig = Xof_orig_wkr_.Status_noop; return this;}
public Xof_exec_arg Rslt_orig_missing() {rslt_orig = Xof_orig_wkr_.Status_missing_orig; return this;}
public Xof_exec_arg Rslt_orig_found() {rslt_orig = Xof_orig_wkr_.Status_found; return this;}
public Xof_exec_arg Rslt_fsdb_xowa() {rslt_fsdb = Xof_bin_wkr_.Tid_fsdb_xowa; return this;}
public Xof_exec_arg Rslt_fsdb_null() {rslt_fsdb = Xof_bin_wkr_.Tid_null; return this;}
public Xof_exec_arg Rslt_conv_y() {rslt_conv = Xof_cnv_wkr_.Tid_y; return this;}
public Xof_exec_arg Rslt_conv_n() {rslt_conv = Xof_cnv_wkr_.Tid_n; return this;}
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);}

View File

@@ -24,28 +24,28 @@ public class Xof_file_redirect_tst {
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_fsdb_xowa());
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_fsdb_xowa());
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_fsdb_xowa().Rslt_conv_y());
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_fsdb_xowa());
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() {

View File

@@ -21,7 +21,7 @@ import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.views.*;
public class Js_img_mgr {
public static void Update_img(Xoae_page page, Xof_xfer_itm itm) {
Xog_js_wkr js_wkr = Env_.Mode_testing() ? Xog_js_wkr_.Null : page.Tab().Html_itm();
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_src()), itm.Orig_w(), itm.Orig_h(), String_.new_utf8_(itm.Html_orig_src()), itm.Lnki_ttl(), itm.Gallery_mgr_h());
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_url()), itm.Orig_w(), itm.Orig_h(), String_.new_utf8_(itm.Html_orig_url()), itm.Lnki_ttl(), itm.Gallery_mgr_h());
}
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_fsdb_itm itm) {
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url().To_http_file_str(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url().To_http_file_str(), itm.Lnki_ttl(), itm.Gallery_mgr_h());

View File

@@ -24,25 +24,18 @@ public class Xof_orig_itm {
public int W() {return w;} private int w;
public int H() {return h;} private int h;
public byte[] Redirect() {return redirect;} private byte[] redirect; // redirect trg; EX: A.png is redirected to B.jpg; record will have A.png|jpg|220|200|B.jpg where jpg|220|200 are the attributes of B.jpg
public byte Status() {return status;} private byte status;
public boolean Insert_new() {return insert_new;} public void Insert_new_y_() {insert_new = Bool_.Y;} private boolean insert_new;
public void Clear() {
this.repo = Repo_null;
this.page = this.redirect = null;
this.ext = Xof_ext_.Id_unknown;
this.w = this.h = Xof_img_size.Null;
this.status = Status_null;
}
public Xof_orig_itm Init(byte repo, byte[] page, int ext, int w, int h, byte[] redirect) {return Init(repo, page, ext, w, h, redirect, Status_null);}
public Xof_orig_itm Init(byte repo, byte[] page, int ext, int w, int h, byte[] redirect, byte status) {
public Xof_orig_itm Init(byte repo, byte[] page, int ext, int w, int h, byte[] redirect) {
this.repo = repo; this.page = page; this.ext = ext;
this.w = w; this.h = h; this.redirect = redirect; this.status = status;
this.w = w; this.h = h; this.redirect = redirect;
return this;
}
public static final byte Status_null = Byte_.Max_value_127;
public static final byte Repo_comm = 0, Repo_wiki = 1, Repo_null = Byte_.Max_value_127; // SERIALIZED: "wiki_orig.orig_repo"
public static byte Repo_by_domain(byte[] domain) {return Bry_.Eq(domain, Xow_domain_.Domain_bry_commons) ? Repo_comm : Repo_wiki;}
public static Xof_orig_itm new_clone(Xof_orig_itm itm) {
return new Xof_orig_itm().Init(itm.repo, itm.page, itm.ext, itm.w, itm.h, itm.redirect, itm.status);
}
public static final Xof_orig_itm Null = null;
}

View File

@@ -22,35 +22,50 @@ import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.
public class Xof_orig_mgr {
private Xof_orig_wkr[] wkrs; private int wkrs_len;
private Xof_url_bldr url_bldr; private Xow_repo_mgr repo_mgr;
private final Xof_img_size img_size = new Xof_img_size();
public Xof_orig_mgr() {this.Wkrs__clear();}
public void Init_by_wiki(Io_url db_dir, boolean schema_is_1, byte[] domain_bry, Xof_download_wkr download_wkr, Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, Xof_fsdb_mode fsdb_mode) {
this.repo_mgr = repo_mgr; this.url_bldr = url_bldr;
if (fsdb_mode.Tid_wmf()) {
Xof_orig_wkr wmf_api = new Xof_orig_wkr__wmf_api(new Xoapi_orig_wmf(), download_wkr, repo_mgr, domain_bry); // NOTE: do not reinstate without handling scrib / pfunc calls to Orig_mgr
this.Wkrs__add_many(wmf_api);
}
else {
if (!fsdb_mode.Tid_wmf()) { // add view,make; don't add if wmf
Xof_orig_wkr__orig_db wkr_xowa_db = new Xof_orig_wkr__orig_db();
Xof_orig_tbl.Conn__get_or_make(db_dir, wkr_xowa_db.Tbl(), schema_is_1, fsdb_mode);
this.Wkrs__add_many(wkr_xowa_db);
}
if (!fsdb_mode.Tid_make()) // add view,wmf; don't add if make
this.Wkrs__add_many(new Xof_orig_wkr__wmf_api(new Xoapi_orig_wmf(), download_wkr, repo_mgr, domain_bry));
}
public Xof_orig_itm Find_by_ttl_or_null(byte[] ttl) {
for (int i = 0; i < wkrs_len; i++) {
Xof_orig_wkr wkr = wkrs[i];
Xof_orig_itm itm = wkr.Find_as_itm(ttl);
if (itm != Xof_orig_itm.Null) return itm;
Xof_orig_itm orig = wkr.Find_as_itm(ttl);
if (orig == Xof_orig_itm.Null) continue;
if (orig.Insert_new()) this.Insert(orig.Repo(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
return orig;
}
return Xof_orig_itm.Null;
}
public void Find_by_list(OrderedHash rv, ListAdp itms, byte exec_tid) {
for (int i = 0; i < wkrs_len; i++) {
Xof_orig_wkr wkr = wkrs[i];
if (wkr.Find_by_list(rv, itms)) break;
wkr.Find_by_list(rv, itms);
}
int len = itms.Count();
for (int i = 0; i < len; i++) {
try {
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)itms.FetchAt(i);
fsdb.Orig_exists_n_(); // default to status = missing
Xof_orig_itm orig = (Xof_orig_itm)rv.Fetch(fsdb.Lnki_ttl());
if (orig == Xof_orig_itm.Null) continue;
if (orig.Insert_new()) this.Insert(orig.Repo(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
Xof_file_wkr.Eval_orig(exec_tid, orig, fsdb, url_bldr, repo_mgr, img_size);
if (!Io_mgr._.ExistsFil(fsdb.Html_view_url()))
fsdb.File_exists_n_();
} catch (Exception e) {
throw Err_.err_(e, "orig: {0}", Err_.Message_gplx_brief(e));
}
}
Xof_orig_rdr_func.Eval(rv, itms, exec_tid, url_bldr, repo_mgr);
}
public void Insert(byte repo, byte[] page, int ext, int w, int h, byte[] redirect, byte status) {
public void Insert(byte repo, byte[] page, int ext, int w, int h, byte[] redirect) {
for (int i = 0; i < wkrs_len; i++) {
Xof_orig_wkr wkr = wkrs[i];
if (wkr.Add_orig(repo, page, ext, w, h, redirect)) break;

View File

@@ -1,53 +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.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
public class Xof_orig_rdr_func {
public static void Eval(OrderedHash itms_by_ttl, ListAdp itms_all, byte exec_tid, Xof_url_bldr url_bldr, Xow_repo_mgr repo_mgr) {
Xof_img_size img_size = new Xof_img_size();
int len = itms_all.Count();
for (int i = 0; i < len; i++) {
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)itms_all.FetchAt(i);
fsdb.Orig_status_(Xof_orig_wkr_.Status_missing_orig); // default to status = missing
Xof_orig_itm orig = (Xof_orig_itm)itms_by_ttl.Fetch(fsdb.Lnki_ttl()); if (orig == null) continue; // not in orig; skip; will do full search later
fsdb.Orig_status_(orig.Status());
if (orig.Status() > Xof_orig_wkr_.Status_found) continue; // only ignore if marked missing; DATE:2014-02-01
byte repo_id = orig.Repo();
Xof_repo_itm repo = null;
if (Xof_repo_itm.Repo_is_known(repo_id)) { // bounds check
fsdb.Orig_repo_id_(repo_id);
Xof_repo_pair repo_pair = repo_mgr.Repos_get_by_id(repo_id);
if (repo_pair == null) // shouldn't happen, but try to avoid null ref;
repo_pair = repo_mgr.Repos_get_at(repo_id);
fsdb.Orig_repo_name_(repo_pair.Wiki_domain());
repo = repo_pair.Trg();
}
fsdb.Lnki_ext_(Xof_ext_.new_by_id_(orig.Ext())); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
fsdb.Orig_size_(orig.W(), orig.H());
fsdb.Orig_status_(Xof_orig_wkr_.Status_found);
if (Bry_.Len_gt_0(orig.Redirect())) // redirect exists;
fsdb.Ctor_by_orig_redirect(orig.Redirect());
fsdb.Html_size_calc(img_size, exec_tid);
Io_url html_url = url_bldr.Init_for_trg_file(fsdb.Lnki_type_as_mode(), repo, fsdb.Lnki_ttl(), fsdb.Lnki_md5(), fsdb.Lnki_ext(), fsdb.Html_w(), fsdb.Lnki_time(), fsdb.Lnki_page()).Xto_url();
fsdb.Html_view_url_(html_url);
if (!Io_mgr._.ExistsFil(html_url))
fsdb.Orig_status_(Xof_orig_wkr_.Status_missing_orig);
// build url; check if exists;
}
}
}

View File

@@ -31,9 +31,9 @@ public class Xof_orig_tbl {
tbl_name = "wiki_orig";
fld_prefix = "orig_";
}
fld_repo = flds.Add_byte(fld_prefix + "repo");
fld_ttl = flds.Add_str(fld_prefix + "ttl", 1024);
fld_status = flds.Add_byte("status"); // NOTE: "status" in v1 and v2
fld_repo = flds.Add_byte(fld_prefix + "repo");
fld_ext = flds.Add_int(fld_prefix + "ext");
fld_w = flds.Add_int(fld_prefix + "w");
fld_h = flds.Add_int(fld_prefix + "h");
@@ -51,7 +51,7 @@ public class Xof_orig_tbl {
Xof_orig_itm rv = Xof_orig_itm.Null;
Db_rdr rdr = Db_rdr_.Null;
try {
Db_stmt stmt = conn.Stmt_select(tbl_name, flds.To_str_ary(), fld_ttl);
Db_stmt stmt = conn.Stmt_select(tbl_name, flds, fld_ttl);
rdr = stmt.Clear().Crt_bry_as_str(fld_ttl, ttl).Exec_select_as_rdr();
if (rdr.Move_next())
rv = Make_itm(rdr);
@@ -59,13 +59,29 @@ public class Xof_orig_tbl {
finally {rdr.Rls();}
return rv;
}
public boolean Exists__repo_ttl(byte repo, byte[] ttl) {
Db_rdr rdr = Db_rdr_.Null;
try {
rdr = conn.Stmt_select(tbl_name, flds, fld_repo, fld_ttl).Crt_byte(fld_repo, repo).Crt_bry_as_str(fld_ttl, ttl).Exec_select_as_rdr();
return rdr.Move_next();
}
finally {rdr.Rls();}
}
public void Insert(byte repo, byte[] ttl, int ext, int w, int h, byte[] redirect) {
Db_stmt stmt = Db_stmt_.Null;
stmt = conn.Stmt_insert(tbl_name, flds);
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
stmt.Clear()
.Val_bry_as_str(fld_ttl, ttl).Val_byte(fld_status, Xof_orig_wkr_.Status_found).Val_byte(fld_repo, repo).Val_int(fld_ext, ext).Val_int(fld_w, w).Val_int(fld_h, h).Val_bry_as_str(fld_redirect, redirect)
.Val_byte(fld_repo, repo).Val_bry_as_str(fld_ttl, ttl).Val_byte(fld_status, Status_found)
.Val_int(fld_ext, ext).Val_int(fld_w, w).Val_int(fld_h, h).Val_bry_as_str(fld_redirect, redirect)
.Exec_insert();
}
public void Update(byte repo, byte[] ttl, int ext, int w, int h, byte[] redirect) {
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, String_.Ary(fld_repo, fld_ttl));
stmt.Clear()
.Val_byte(fld_status, Status_found)
.Val_int(fld_ext, ext).Val_int(fld_w, w).Val_int(fld_h, h).Val_bry_as_str(fld_redirect, redirect)
.Crt_byte(fld_repo, repo).Crt_bry_as_str(fld_ttl, ttl)
.Exec_update();
}
public Xof_orig_itm Make_itm(Db_rdr rdr) {
byte repo = rdr.Read_byte(fld_repo);
Xof_orig_itm rv = new Xof_orig_itm().Init
@@ -75,9 +91,8 @@ public class Xof_orig_tbl {
, rdr.Read_int(fld_w)
, rdr.Read_int(fld_h)
, rdr.Read_bry_by_str(fld_redirect)
, Xof_repo_itm.Repo_is_known(repo) ? Xof_orig_wkr_.Status_found : Xof_orig_wkr_.Status_missing_orig // NOTE: orig_db may mistakenly have status of found; rely on repo to set status; PAGE:ru.w:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
);
return rv;
return rv.W() == Xof_img_size.Null ? Xof_orig_itm.Null : rv;
}
public static final String Db_conn_bldr_type = "xowa.file.orig_regy";
public static Db_conn Conn__get_or_make(Io_url root_dir, Xof_orig_tbl tbl, boolean schema_is_1, Xof_fsdb_mode fsdb_mode) {
@@ -95,6 +110,7 @@ public class Xof_orig_tbl {
tbl.Conn_(conn, created, schema_is_1);
return conn;
}
private static final byte Status_found = 1;
}
class Xof_orig_tbl__in_wkr extends Db_in_wkr__base {
private Xof_orig_tbl tbl; private String tbl_name; private Db_meta_fld_list flds; private String fld_ttl;
@@ -118,8 +134,9 @@ class Xof_orig_tbl__in_wkr extends Db_in_wkr__base {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
Xof_orig_itm itm = tbl.Make_itm(rdr);
if (itm == Xof_orig_itm.Null) continue;
byte[] itm_ttl = itm.Page();
rv.Add_if_new(itm_ttl, itm); // guard against dupes (shouldn't happen)
rv.Add_if_new(itm_ttl, itm); // guard against dupes; fails on en.w:Paris; DATE:2015-03-08
}
}
}

View File

@@ -37,7 +37,7 @@ class Xof_orig_tbl_fxt {
}
public Xof_orig_itm Exec_insert(String ttl, int w, int h) {
byte[] ttl_bry = Bry_.new_utf8_(ttl);
Xof_orig_itm rv = new Xof_orig_itm().Init(Xof_orig_itm.Repo_comm, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty, Xof_orig_wkr_.Status_found);
Xof_orig_itm rv = new Xof_orig_itm().Init(Xof_orig_itm.Repo_comm, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
tbl.Insert(rv.Repo(), rv.Page(), rv.Ext(), rv.W(), rv.H(), rv.Redirect());
return rv;
}
@@ -48,7 +48,7 @@ class Xof_orig_tbl_fxt {
for (int i = 0; i < itms_len; ++i) {
String itm = itms[i];
Xof_fsdb_itm fsdb_itm = new Xof_fsdb_itm();
fsdb_itm.Ctor_by_orig_redirect(Bry_.new_utf8_(itm));
fsdb_itm.Ctor_by_lnki(Bry_.new_utf8_(itm), Xop_lnki_type.Id_none, Xof_img_size.Null, Xof_img_size.Null, Xof_patch_upright_tid_.Tid_all, Xof_img_size.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null);
list.Add(fsdb_itm);
}
tbl.Select_by_list(rv, list);

View File

@@ -20,7 +20,7 @@ import gplx.xowa.files.fsdb.*;
public interface Xof_orig_wkr {
byte Tid();
Xof_orig_itm Find_as_itm(byte[] ttl);
boolean Find_by_list(OrderedHash rv, ListAdp itms);
void Find_by_list(OrderedHash rv, ListAdp itms);
boolean Add_orig(byte repo, byte[] page, int ext_id, int w, int h, byte[] redirect);
void Db_txn_save();
void Db_rls();

View File

@@ -20,21 +20,7 @@ import gplx.xowa.wmfs.apis.*;
public class Xof_orig_wkr_ {
public static final Xof_orig_wkr[] Ary_empty = new Xof_orig_wkr[0];
public static final byte
Tid_null = Byte_.Max_value_127
, Tid_noop = 0
, Tid_missing = 1
, Tid_mock = 2
, Tid_xowa_db = 3
, Tid_xowa_reg = 4
, Tid_wmf_api = 5
, Tid_dir = 6
;
public static final byte
Status_null = Byte_.Max_value_127
, Status_noop = 0
, Status_found = 1
, Status_missing_orig = 2
, Status_missing_qry = 3
, Status_missing_bin = 4
Tid_xowa_db = 1
, Tid_wmf_api = 2
;
}

View File

@@ -18,14 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.dbs.*;
public class Xof_orig_wkr__orig_db implements Xof_orig_wkr {
public byte Tid() {return Xof_orig_wkr_.Tid_xowa_reg;}
public byte Tid() {return Xof_orig_wkr_.Tid_xowa_db;}
public Xof_orig_tbl Tbl() {return tbl;} private final Xof_orig_tbl tbl = new Xof_orig_tbl();
public void Conn_(Db_conn conn, boolean created, boolean schema_is_1) {tbl.Conn_(conn, created, schema_is_1);}
public boolean Find_by_list(OrderedHash rv, ListAdp itms) {tbl.Select_by_list(rv, itms); return true;}
public void Find_by_list(OrderedHash rv, ListAdp itms) {tbl.Select_by_list(rv, itms);}
public Xof_orig_itm Find_as_itm(byte[] ttl) {return tbl.Select_itm(ttl);}
public boolean Add_orig(byte repo, byte[] page, int ext_id, int w, int h, byte[] redirect) {
if (tbl.Select_itm(page) != Xof_orig_itm.Null) return false; // do not add if already there; needed b/c fsdb_wkr always calls Insert when itm is found;
tbl.Insert(repo, page, ext_id, w, h, redirect);
if (tbl.Exists__repo_ttl(repo, page))
tbl.Update(repo, page, ext_id, w, h, redirect);
else
tbl.Insert(repo, page, ext_id, w, h, redirect);
return true;
}
public void Db_txn_save() {tbl.Conn().Txn_mgr().Txn_end_all();}

Some files were not shown because too many files have changed in this diff Show More