mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.8.4.1
This commit is contained in:
@@ -15,7 +15,7 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_text_row_tid { // NOTE: SERIALIZED
|
||||
public static final int Tid_body = 0, Tid_img = 1, Tid_gallery = 2, Tid_imap = 3, Tid_display_ttl = 4, Tid_content_sub = 5, Tid_sidebar_div = 6;
|
||||
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
|
||||
public class Xodb_ctx {
|
||||
public boolean Html_db_enabled() {return html_db_enabled;} public void Html_db_enabled_(boolean v) {html_db_enabled = v;} private boolean html_db_enabled;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
if (search_version == gplx.xowa.specials.search.Xosrh_core.Version_1)
|
||||
db_mgr.Tbl_page().Select_by_search(cancelable, rv, search, results_max);
|
||||
else {
|
||||
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search).Provider());
|
||||
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, db_mgr.Wiki(), search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search).Provider());
|
||||
db_mgr.Tbl_page().Select_by_id_list(cancelable, true, rv);
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
hash2.Add(page.Id_val(), page);
|
||||
}
|
||||
len = hash2.Count(); // must update len (!hash2.Has() may have skipped titles)
|
||||
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), 0, len);
|
||||
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), db_mgr.Wiki(), 0, len);
|
||||
return (Xodb_page[])hash.XtoAry(Xodb_page.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
db_mgr.Tbl_page().Insert(page_stmt, page.Id(), page.Ns_id(), page.Ttl_wo_ns(), 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);
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.hdumps.*;
|
||||
public interface Xodb_mgr extends GfoInvkAble, RlsAble {
|
||||
byte Tid();
|
||||
String Tid_name();
|
||||
byte Data_storage_format(); void Data_storage_format_(byte v);
|
||||
byte Category_version();
|
||||
byte Search_version(); void Search_version_refresh();
|
||||
Xodb_ctx Db_ctx();
|
||||
DateAdp Dump_date_query();
|
||||
Xodb_load_mgr Load_mgr();
|
||||
Xodb_save_mgr Save_mgr();
|
||||
Xodb_html_mgr Html_mgr();
|
||||
Xodb_hdump_mgr Hdump_mgr();
|
||||
}
|
||||
|
||||
@@ -17,14 +17,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.hdumps.*;
|
||||
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
private boolean html_db_enabled;
|
||||
public Xodb_mgr_sql(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
fsys_mgr = new Xodb_fsys_mgr(wiki.App().Fsys_mgr().Bin_db_dir(), wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
|
||||
load_mgr = new Xodb_load_mgr_sql(this, fsys_mgr);
|
||||
save_mgr = new Xodb_save_mgr_sql(this);
|
||||
tbl_text = new Xodb_text_tbl(this);
|
||||
tbl_page = new Xodb_page_tbl(wiki);
|
||||
hdump_mgr = new Xodb_hdump_mgr(wiki);
|
||||
}
|
||||
public byte Tid() {return Tid_sql;} public static final byte Tid_sql = 1;
|
||||
public String Tid_name() {return "sqlite3";}
|
||||
@@ -33,14 +36,21 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
public byte Category_version() {return category_version;} private byte category_version = Xoa_ctg_mgr.Version_null;
|
||||
public byte Search_version() {return load_mgr.Search_version();}
|
||||
public void Search_version_refresh() {load_mgr.Search_version_refresh();}
|
||||
public void Html_db_enabled_(boolean v) {
|
||||
html_db_enabled = v; db_ctx.Html_db_enabled_(v);
|
||||
hdump_mgr.Enabled_(v);
|
||||
tbl_page.Html_db_enabled_(v);
|
||||
if (v) Xodb_hdump_mgr_setup.Hdump_db_file_init(hdump_mgr);
|
||||
}
|
||||
public Xodb_ctx Db_ctx() {return db_ctx;} private Xodb_ctx db_ctx = new Xodb_ctx();
|
||||
public Xodb_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xodb_fsys_mgr fsys_mgr;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_sql load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_sql save_mgr;
|
||||
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
|
||||
public Xodb_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xodb_hdump_mgr hdump_mgr;
|
||||
public Xodb_xowa_cfg_tbl Tbl_xowa_cfg() {return tbl_cfg;} private Xodb_xowa_cfg_tbl tbl_cfg = new Xodb_xowa_cfg_tbl();
|
||||
public Xodb_xowa_ns_tbl Tbl_xowa_ns() {return tbl_ns;} private Xodb_xowa_ns_tbl tbl_ns = new Xodb_xowa_ns_tbl();
|
||||
public Xodb_xowa_db_tbl Tbl_xowa_db() {return tbl_db;} private Xodb_xowa_db_tbl tbl_db = new Xodb_xowa_db_tbl();
|
||||
public Xodb_page_tbl Tbl_page() {return tbl_page;} private Xodb_page_tbl tbl_page = new Xodb_page_tbl();
|
||||
public Xodb_page_tbl Tbl_page() {return tbl_page;} private Xodb_page_tbl tbl_page;
|
||||
public Xodb_text_tbl Tbl_text() {return tbl_text;} private Xodb_text_tbl tbl_text;
|
||||
public Xodb_site_stats_tbl Tbl_site_stats() {return tbl_site_stats;} private Xodb_site_stats_tbl tbl_site_stats = new Xodb_site_stats_tbl();
|
||||
public Xodb_wdata_qids_tbl Tbl_wdata_qids() {return tbl_wdata_qids;} private Xodb_wdata_qids_tbl tbl_wdata_qids = new Xodb_wdata_qids_tbl();
|
||||
@@ -78,7 +88,9 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
tbl_site_stats.Provider_(provider);
|
||||
}
|
||||
public void Page_create(Db_stmt page_stmt, Db_stmt text_stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text, int random_int, int file_idx) {
|
||||
tbl_page.Insert(page_stmt, page_id, ns_id, ttl_wo_ns, redirect, modified_on, text.length, random_int, file_idx);
|
||||
int text_len = text.length;
|
||||
int html_db_id = (html_db_enabled) ? -1 : hdump_mgr.Html_db_id_default(text_len);
|
||||
tbl_page.Insert(page_stmt, page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_len, random_int, file_idx, html_db_id);
|
||||
tbl_text.Insert(text_stmt, page_id, text, data_storage_format);
|
||||
}
|
||||
public boolean Ctg_select_v1(Xoctg_view_ctg view_ctg, Db_provider ctg_provider, Xodb_category_itm ctg) {
|
||||
@@ -130,14 +142,14 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
|
||||
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
|
||||
else if (ctx.Match(k, Invk_tid_name)) return this.Tid_name();
|
||||
else if (ctx.Match(k, Invk_html_mgr)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_html_mgr)) return hdump_mgr;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_"
|
||||
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_"
|
||||
, Invk_search_version = "search_version"
|
||||
, Invk_tid_name = "tid_name", Invk_html_mgr = "html_mgr"
|
||||
, Invk_tid_name = "tid_name", Invk_html_mgr = "hdump_mgr"
|
||||
;
|
||||
public void Category_version_update(boolean version_is_1) {
|
||||
String grp = Xodb_mgr_sql.Grp_wiki_init;
|
||||
|
||||
@@ -16,19 +16,21 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.hdumps.*;
|
||||
public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public Xodb_mgr_txt(Xow_wiki wiki, Xow_data_mgr data_mgr) {
|
||||
this.wiki = wiki;
|
||||
load_mgr = new Xodb_load_mgr_txt(wiki);
|
||||
save_mgr = new Xodb_save_mgr_txt(wiki, load_mgr);
|
||||
hdump_mgr = new Xodb_hdump_mgr(wiki);
|
||||
} private Xow_wiki wiki;
|
||||
public byte Tid() {return Tid_txt;} public static final byte Tid_txt = 0;
|
||||
public String Tid_name() {return "xdat";}
|
||||
public byte Data_storage_format() {return data_storage_format;} public void Data_storage_format_(byte v) {data_storage_format = v;} private byte data_storage_format = gplx.ios.Io_stream_.Tid_file;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
|
||||
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
|
||||
public Xodb_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xodb_hdump_mgr hdump_mgr;
|
||||
public Xodb_ctx Db_ctx() {return db_ctx;} private Xodb_ctx db_ctx = new Xodb_ctx();
|
||||
public DateAdp Dump_date_query() {
|
||||
Io_url url = wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 0);
|
||||
return Io_mgr._.QueryFil(url).ModifiedTime();
|
||||
|
||||
@@ -1,54 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Bry_rdr {
|
||||
private byte[] src; private int src_len;
|
||||
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
|
||||
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
|
||||
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
|
||||
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
|
||||
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
break;
|
||||
default:
|
||||
return b == to_char ? rv : or_int;
|
||||
}
|
||||
}
|
||||
return bgn == pos ? or_int : rv;
|
||||
}
|
||||
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
|
||||
public byte[] Read_bry_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
if (b == to_char)
|
||||
return Bry_.Mid(src, bgn, pos++);
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
return bgn == pos ? or_bry : Bry_.Mid(src, bgn, src_len);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Bry_rdr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt();
|
||||
@Test public void Int() {
|
||||
fxt.Init_src("12|3456|789");
|
||||
fxt.Test_read_int(12);
|
||||
fxt.Test_read_int(3456);
|
||||
fxt.Test_read_int(789);
|
||||
fxt.Test_read_int(Int_.MinValue);
|
||||
}
|
||||
@Test public void Bry() {
|
||||
fxt.Init_src("abc|d||ef");
|
||||
fxt.Test_read_bry("abc");
|
||||
fxt.Test_read_bry("d");
|
||||
fxt.Test_read_bry("");
|
||||
fxt.Test_read_bry("ef");
|
||||
fxt.Test_read_bry(null);
|
||||
}
|
||||
}
|
||||
class Bry_rdr_fxt {
|
||||
private Bry_rdr rdr;
|
||||
public void Clear() {rdr = new Bry_rdr();}
|
||||
public Bry_rdr_fxt Init_src(String v) {rdr.Src_(Bry_.new_utf8_(v)); return this;}
|
||||
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
|
||||
public void Test_read_int(int expd_val) {
|
||||
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());
|
||||
}
|
||||
public void Test_read_bry(String expd_str) {
|
||||
byte[] actl_bry = rdr.Read_bry_to_pipe();
|
||||
String actl_str = actl_bry == null ? null : String_.new_utf8_(actl_bry);
|
||||
Tfds.Eq(expd_str, actl_str);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.dbs.hdumps.saves.*;
|
||||
public class Hdump_db_mgr {
|
||||
public Hdump_db_mgr() {
|
||||
save_mgr.Tbl_(text_tbl);
|
||||
}
|
||||
public Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
|
||||
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
|
||||
@gplx.Internal protected void Mode_mem_() {
|
||||
text_tbl = new Hdump_text_tbl_mem();
|
||||
save_mgr.Tbl_(text_tbl);
|
||||
}
|
||||
public Db_provider Db_provider_by_page(int page_id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class Hdump_db_mgr_setup {
|
||||
public static Xodb_file Setup(Xodb_mgr_sql db_mgr) {
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Update_core(fsys_mgr);
|
||||
Xodb_file html_db_file = Create_db(db_mgr, fsys_mgr);
|
||||
Create_idx(html_db_file);
|
||||
return html_db_file;
|
||||
}
|
||||
public static void Update_core(Xodb_fsys_mgr fsys_mgr) {
|
||||
Db_provider core_provider = fsys_mgr.Provider_core();
|
||||
try {
|
||||
Xodb_xowa_cfg_tbl.Insert_str(core_provider, "db.meta", "html_db.exists", "y");
|
||||
core_provider.Exec_sql("ALTER TABLE page ADD COLUMN html_db_idx integer NOT NULL DEFAULT '-1'");
|
||||
} catch (Exception e) {Gfo_usr_dlg_._.Warn_many("", "", "failed to update core: db=~{0} err=~{1}", core_provider.ConnectInfo().Raw_of_db_connect(), Err_.Message_gplx(e));}
|
||||
}
|
||||
public static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {
|
||||
Xodb_file html_db_file = fsys_mgr.Make(Xodb_file_tid.Tid_html);
|
||||
html_db_file.Provider().Exec_sql(Hdump_text_tbl.Tbl_sql);
|
||||
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), db_mgr.Fsys_mgr().Files_ary());
|
||||
return html_db_file;
|
||||
}
|
||||
public static void Create_idx(Xodb_file html_db_file) {
|
||||
Sqlite_engine_.Idx_create(html_db_file.Provider(), Hdump_text_tbl.Idx_core);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
class Hdump_file_itm {
|
||||
// lnki_ttl|lnki_ext|lnki_type|lnki_w|lnki_h|lnki_align_x|lnki_align_y|lnki_border|lnki_upright|lnki_time|lnki_page|lnki_media_icon|lnki_alt|lnki_caption
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public byte Lnki_tid() {return lnki_tid;} private byte lnki_tid;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public byte Lnki_align_x() {return lnki_align_x;} private byte lnki_align_x;
|
||||
public byte Lnki_align_y() {return lnki_align_y;} private byte lnki_align_y;
|
||||
public byte Lnki_border() {return lnki_border;} private byte lnki_border;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public boolean Lnki_media_icon() {return lnki_media_icon;} private boolean lnki_media_icon;
|
||||
public byte[] Lnki_alt() {return lnki_alt;} private byte[] lnki_alt;
|
||||
public byte[] Lnki_caption() {return lnki_caption;} private byte[] lnki_caption;
|
||||
public void Parse(byte[] src) {
|
||||
int len = src.length;
|
||||
int pos = 0;
|
||||
int fld_idx = 0, fld_bgn = 0;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Pipe) {
|
||||
switch (fld_idx) {
|
||||
case 0: lnki_ttl = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
case 2: lnki_tid = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 3: lnki_w = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 4: lnki_h = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 5: lnki_align_x = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 6: lnki_align_y = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 7: lnki_border = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
|
||||
case 8: lnki_upright = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
|
||||
case 9: lnki_time = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
|
||||
case 10: lnki_page = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
|
||||
case 11: lnki_media_icon = src[pos] == Byte_ascii.Ltr_y; break;
|
||||
case 12: lnki_alt = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
case 13: lnki_caption = Bry_.Mid(src, fld_bgn, pos); break;
|
||||
}
|
||||
++fld_idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_img_itm {
|
||||
public Hdump_img_itm(int idx, int view_w, int view_h, byte[] lnki_ttl, byte[] view_src) {
|
||||
this.idx = idx;
|
||||
this.view_w = view_w;
|
||||
this.view_h = view_h;
|
||||
this.lnki_ttl = lnki_ttl;
|
||||
this.view_src = view_src;
|
||||
}
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public int View_w() {return view_w;} private int view_w;
|
||||
public int View_h() {return view_h;} private int view_h;
|
||||
public byte[] View_src() {return view_src;} private byte[] view_src;
|
||||
@Override public String toString() {
|
||||
return String_.Concat_with_str("|", Int_.XtoStr(idx), Int_.XtoStr(view_w), Int_.XtoStr(view_h), String_.new_utf8_(lnki_ttl), String_.new_utf8_(view_src));
|
||||
}
|
||||
public static final Hdump_img_itm[] Ary_empty = new Hdump_img_itm[0];
|
||||
}
|
||||
@@ -1,85 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*;
|
||||
public class Hdump_mgr__save_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_mgr__save_fxt fxt = new Hdump_mgr__save_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Test_save("abc", fxt.Make_itm_body("abc"));
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt.Test_save("a[[File:A.png|test_caption]]b"
|
||||
, fxt.Make_itm_body("a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>b")
|
||||
, fxt.Make_itm_img(0, 0, 0, "A.png", "orig/7/0/A.png")
|
||||
);
|
||||
}
|
||||
@Test public void Display_title() {
|
||||
fxt.Test_save("{{DISPLAYTITLE:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_display_title("A"));
|
||||
}
|
||||
@Test public void Content_sub() {
|
||||
fxt.Test_save("{{#isin:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_content_sub("<a href=\"/wiki/A\">A</a>"));
|
||||
}
|
||||
@Test public void Sidebar_div() {
|
||||
fxt.Test_save("{{#related:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_sidebar_div(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
|
||||
, " <h3></h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li class=\"interwiki-relart\"><a href=\"/wiki/A\">A</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
)));
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__save_fxt extends Hdump_mgr__base_fxt {
|
||||
private int page_id = 0;
|
||||
private ListAdp text_itms = ListAdp_.new_();
|
||||
@Override public void Clear_end() {
|
||||
db_mgr.Mode_mem_();
|
||||
db_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider);
|
||||
}
|
||||
public Hdump_text_row Make_itm_body(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, 0, 0, Hdump_text_row.data_img_(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel)));}
|
||||
public Hdump_text_row Make_itm_display_title(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_display_ttl, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_content_sub(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_content_sub, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_sidebar_div(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_sidebar_div, 0, 0, Bry_.new_utf8_(v));}
|
||||
public void Test_save(String raw, Hdump_text_row... expd) {
|
||||
this.Exec_write(raw);
|
||||
hdump_mgr.Save_mgr().Update(page);
|
||||
db_mgr.Text_tbl().Select_by_page(text_itms, 0);
|
||||
Hdump_text_row[] actl = (Hdump_text_row[])text_itms.XtoAryAndClear(Hdump_text_row.class);
|
||||
Tfds.Eq_ary_str(Xto_str_ary(expd), Xto_str_ary(actl));
|
||||
}
|
||||
private static String[] Xto_str_ary(Hdump_text_row[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row itm = ary[i];
|
||||
bfr .Add_int_variable(itm.Page_id())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Tid())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Idx())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Version_id())
|
||||
.Add_byte_pipe().Add(itm.Data())
|
||||
;
|
||||
rv[i] = bfr.XtoStrAndClear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,124 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
public class Hdump_mgr__write_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_mgr__write_fxt fxt = new Hdump_mgr__write_fxt();
|
||||
@Test public void Image_full() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "orig/7/0/A.png"));
|
||||
fxt.Test_write
|
||||
( "[[File:A.png|test_caption]]"
|
||||
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>");
|
||||
}
|
||||
@Test public void Image_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "thumb/7/0/A.png/220px.png"));
|
||||
fxt.Test_write
|
||||
( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\"~<img|0> /></a>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Audio_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 220, -1, ""));
|
||||
fxt.Test_write
|
||||
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <div id=\"xowa_media_div\">~<mda.play|0>~<mda.info|0>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, ""));
|
||||
fxt.Test_write
|
||||
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <div id=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\"~<img|0> alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>~<mda.play|0>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__base_fxt {
|
||||
protected Hdump_db_mgr db_mgr;
|
||||
protected Xodb_html_mgr hdump_mgr = new Xodb_html_mgr();
|
||||
protected Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
protected Xow_wiki wiki; protected Xoa_page page;
|
||||
public Xop_fxt Fxt() {return fxt;} protected Xop_fxt fxt;
|
||||
public void Clear() {
|
||||
if (fxt == null) {
|
||||
fxt = new Xop_fxt();
|
||||
wiki = fxt.Wiki();
|
||||
page = wiki.Ctx().Cur_page();
|
||||
db_mgr = hdump_mgr.Db_mgr();
|
||||
}
|
||||
fxt.Reset();
|
||||
this.Clear_end();
|
||||
}
|
||||
@gplx.Virtual public void Clear_end() {}
|
||||
public void Exec_write(String raw) {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_utf8_(raw));
|
||||
page.Root_(root);
|
||||
hdump_mgr.Write(bfr, wiki, page);
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__write_fxt extends Hdump_mgr__base_fxt {
|
||||
private ListAdp expd_itms_xfers = ListAdp_.new_();
|
||||
@Override public void Clear_end() {expd_itms_xfers.Clear();}
|
||||
public Xof_xfer_itm Make_xfer(int uid, int img_w, int img_h, String img_src) {
|
||||
Xof_xfer_itm rv = new Xof_xfer_itm();
|
||||
rv.Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(img_src));
|
||||
return rv;
|
||||
}
|
||||
public void Expd_itms_xfers(Xof_xfer_itm... itms) {expd_itms_xfers.AddMany((Object[])itms);}
|
||||
public void Test_write(String raw, String expd_html) {
|
||||
this.Exec_write(raw);
|
||||
Tfds.Eq_str_lines(expd_html, String_.new_utf8_(page.Hdump_data().Body()));
|
||||
if (expd_itms_xfers.Count() > 0) Tfds.Eq_ary_str(Xfer_to_str_ary(expd_itms_xfers), Xfer_to_str_ary(page.Hdump_data().Imgs()));
|
||||
}
|
||||
private static String[] Xfer_to_str_ary(ListAdp list) {
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_xfer_itm itm = (Xof_xfer_itm)list.FetchAt(i);
|
||||
rv[i] = String_.Concat_with_str("|", Int_.XtoStr(itm.Html_uid()), Int_.XtoStr(itm.Html_w()), Int_.XtoStr(itm.Html_h()), String_.new_utf8_(itm.Html_view_src_rel()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_page_itm {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Page_url() {return page_url;} private byte[] page_url;
|
||||
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
|
||||
public byte[] Page_body() {return page_body;} public void Page_body_(byte[] v) {this.page_body = v;} private byte[] page_body = Bry_.Empty;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl = Bry_.Empty;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub = Bry_.Empty;
|
||||
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs = Bry_.Ary_empty;
|
||||
public Hdump_img_itm[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_img_itm[] v) {this.img_itms = v;} private Hdump_img_itm[] img_itms = Hdump_img_itm.Ary_empty;
|
||||
public void Init(int page_id, byte[] page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
|
||||
this.page_id = page_id;
|
||||
this.page_url = page_url;
|
||||
this.version_id = version_id;
|
||||
this.display_ttl = display_ttl;
|
||||
this.content_sub = content_sub;
|
||||
this.page_body = page_body;
|
||||
this.sidebar_divs = sidebar_divs;
|
||||
this.img_itms = img_itms;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_text_row {
|
||||
public Hdump_text_row(int page_id, int tid, int idx, int version_id, byte[] data) {
|
||||
this.page_id = page_id; this.tid = tid; this.idx = idx; this.version_id = version_id; this.data = data;
|
||||
}
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Tid() {return tid;} private int tid;
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public int Version_id() {return version_id;} private int version_id;
|
||||
public byte[] Data() {return data;} private byte[] data;
|
||||
public static byte[] data_img_(Bry_bfr bfr, int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {
|
||||
bfr .Add_int_variable(uid)
|
||||
.Add_byte_pipe().Add_int_variable(img_w)
|
||||
.Add_byte_pipe().Add_int_variable(img_h)
|
||||
.Add_byte_pipe().Add(lnki_ttl)
|
||||
.Add_byte_pipe().Add(img_src_rel)
|
||||
;
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
}
|
||||
@@ -1,99 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Hdump_text_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_delete;
|
||||
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.Rls_all(); provider = v;} private Db_provider provider;
|
||||
@gplx.Virtual public void Delete_by_page(int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
|
||||
try {
|
||||
stmt_delete.Clear().Val_int_(page_id).Exec_delete();
|
||||
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
|
||||
}
|
||||
@gplx.Virtual public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_int_(idx).Val_int_(version).Val_str_by_bry_(data).Exec_insert();
|
||||
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
|
||||
}
|
||||
@gplx.Virtual public void Select_by_page(ListAdp rv, int page_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Clear().Val_int_(page_id).Exec_select();
|
||||
while(rdr.MoveNextPeer()) {
|
||||
Hdump_text_row row = new Hdump_text_row
|
||||
( rdr.ReadInt(Fld_page_id)
|
||||
, rdr.ReadInt(Fld_text_tid)
|
||||
, rdr.ReadInt(Fld_text_idx)
|
||||
, rdr.ReadInt(Fld_text_version)
|
||||
, rdr.ReadBryByStr(Fld_text_data)
|
||||
);
|
||||
rv.Add(row);
|
||||
}
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
public void Rls_all() {
|
||||
if (stmt_select != null) {stmt_select.Rls(); stmt_select = null;}
|
||||
if (stmt_insert != null) {stmt_insert.Rls(); stmt_insert = null;}
|
||||
if (stmt_delete != null) {stmt_delete.Rls(); stmt_delete = null;}
|
||||
provider = null;
|
||||
}
|
||||
public static final String Tbl_name = "html_text"
|
||||
, Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_idx = "text_idx"
|
||||
, Fld_text_version = "text_version", Fld_text_data = "text_data";
|
||||
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_text_tid, Fld_text_idx, Fld_text_version, Fld_text_data};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_text"
|
||||
, "( page_id integer NOT NULL"
|
||||
, ", text_tid integer NOT NULL"
|
||||
, ", text_idx integer NOT NULL"
|
||||
, ", text_version integer NOT NULL"
|
||||
, ", text_data mediumblob NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final Db_idx_itm
|
||||
Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS html_text__core ON html_text (page_id, text_tid, text_idx);")
|
||||
;
|
||||
}
|
||||
class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
|
||||
@Override public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
|
||||
Hdump_text_row row = new Hdump_text_row(page_id, tid, idx, version, data);
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
rows.Add(row);
|
||||
}
|
||||
@Override public void Select_by_page(ListAdp rv, int page_id) {
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
@Override public void Delete_by_page(int page_id) {pages.Del(page_id);}
|
||||
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
|
||||
ListAdp rv = (ListAdp)pages.Fetch(page_id);
|
||||
if (rv == null) {
|
||||
rv = ListAdp_.new_();
|
||||
pages.Add(page_id, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Db_provider Null_provider = null;
|
||||
}
|
||||
@@ -1,60 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.saves.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.gui.*;
|
||||
public class Xodb_html_mgr implements GfoInvkAble {
|
||||
private Xodb_file hdump_db_file;
|
||||
public Xodb_html_mgr() {
|
||||
save_mgr = db_mgr.Save_mgr();
|
||||
}
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
|
||||
public Hdump_db_mgr Db_mgr() {return db_mgr;} private Hdump_db_mgr db_mgr = new Hdump_db_mgr();
|
||||
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr;
|
||||
public void Write(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0;
|
||||
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
|
||||
wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
page.Hdump_data().Body_(bfr.XtoAryAndClear());
|
||||
}
|
||||
public void Save(Xoa_page page) {
|
||||
if (!enabled) return;
|
||||
if (hdump_db_file == null) hdump_db_file = Hdump_db_file_init(this, page);
|
||||
Xow_wiki wiki = page.Wiki();
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
|
||||
this.Write(tmp_bfr, wiki, page);
|
||||
save_mgr.Update(page);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static Xodb_file Hdump_db_file_init(Xodb_html_mgr html_mgr, Xoa_page page) {
|
||||
Xow_wiki wiki = page.Wiki();
|
||||
Xodb_mgr_sql db_mgr_as_sql = wiki.Db_mgr_as_sql();
|
||||
Xodb_file rv = db_mgr_as_sql.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_html);
|
||||
if (rv == null) rv = Hdump_db_mgr_setup.Setup(db_mgr_as_sql);
|
||||
html_mgr.Db_mgr().Text_tbl().Provider_(rv.Provider());
|
||||
return rv;
|
||||
}
|
||||
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
|
||||
}
|
||||
@@ -1,26 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Xopg_hdump_data {
|
||||
public ListAdp Imgs() {return imgs;} private ListAdp imgs = ListAdp_.new_();
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
|
||||
public void Clear() {
|
||||
imgs.Clear();
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Xopg_hdump_img_itm {
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public byte[] Img_src() {return img_src;} private byte[] img_src;
|
||||
public Xopg_hdump_img_itm(int uid, int img_w, int img_h, byte[] img_src) {
|
||||
this.uid = uid; this.img_w = img_w; this.img_h = img_h; this.img_src = img_src;
|
||||
}
|
||||
@Override public String toString() {
|
||||
return String_.Concat_with_str("|", Int_.XtoStr(uid), Int_.XtoStr(img_w), Int_.XtoStr(img_h), String_.new_utf8_(img_src));
|
||||
}
|
||||
}
|
||||
@@ -1,94 +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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
private Xow_wiki wiki; private Hdump_page_itm page;
|
||||
private Gfo_usr_dlg usr_dlg; private byte[] file_dir;
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte [] file_dir) {this.usr_dlg = usr_dlg; this.file_dir = file_dir;}
|
||||
public void Init_by_page(Xow_wiki wiki, Hdump_page_itm page) {this.wiki = wiki; this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[] src = page.Page_body(); int len = src.length;
|
||||
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
|
||||
bry_rdr.Src_(src);
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
Xow_html_mgr html_mgr = wiki.Html_mgr();
|
||||
Xoh_file_html_fmtr__base html_fmtr = html_mgr.Html_wtr().Lnki_wtr().File_wtr().File_wtr().Html_fmtr();
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
|
||||
if (o == null) {
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
if (rng_bgn != -1) {
|
||||
bfr.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
byte tid = ((Byte_obj_val)o).Val();
|
||||
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
|
||||
pos = Write_img(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, tid); // note no +1; Write_img return pos after }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
|
||||
}
|
||||
private int Write_img(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int uid_bgn, byte tid) {
|
||||
bry_rdr.Pos_(uid_bgn);
|
||||
int uid = bry_rdr.Read_int_to(Byte_ascii.Gt);
|
||||
int uid_end = bry_rdr.Pos(); // note that uid_end is set to pos after }
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
|
||||
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), uid, imgs_len); return uid_end;}
|
||||
Hdump_img_itm img = imgs[uid];
|
||||
int img_view_w = img.View_w();
|
||||
if (tid == Tid_img_w) {
|
||||
bfr.Add_int_variable(img_view_w);
|
||||
return uid_end;
|
||||
}
|
||||
byte[] a_title = img.Lnki_ttl();
|
||||
byte[] a_href = Bry_.Add(A_href_bgn, a_title);
|
||||
switch (tid) {
|
||||
case Tid_mda_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return uid_end;
|
||||
case Tid_mda_mgnf: fmtr.Html_thumb_part_magnify (bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return uid_end;
|
||||
case Tid_mda_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return uid_end;
|
||||
}
|
||||
byte[] img_src = Bry_.Add(file_dir, img.View_src());
|
||||
if (tid == Tid_img) {
|
||||
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.View_h());
|
||||
}
|
||||
return uid_end;
|
||||
}
|
||||
private static final Bry_fmtr fmtr_img = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
|
||||
private static final byte[] A_href_bgn = Bry_.new_ascii_("/wiki/File:");
|
||||
public static final byte[]
|
||||
Key_img = Bry_.new_ascii_("~<img|")
|
||||
, Key_img_w = Bry_.new_ascii_("~<img.w|")
|
||||
, Key_mda_play = Bry_.new_ascii_("~<mda.play|")
|
||||
, Key_mda_info = Bry_.new_ascii_("~<mda.info|")
|
||||
, Key_mda_mgnf = Bry_.new_ascii_("~<mda.mgnf|")
|
||||
;
|
||||
private static final byte Tid_img = 1, Tid_img_w = 2, Tid_mda_play = 3, Tid_mda_info = 4, Tid_mda_mgnf = 5;
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
|
||||
.Add_bry_bval(Key_img , Tid_img)
|
||||
.Add_bry_bval(Key_img_w , Tid_img_w)
|
||||
.Add_bry_bval(Key_mda_play , Tid_mda_play)
|
||||
.Add_bry_bval(Key_mda_info , Tid_mda_info)
|
||||
.Add_bry_bval(Key_mda_mgnf , Tid_mda_mgnf)
|
||||
;
|
||||
}
|
||||
@@ -1,30 +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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
|
||||
private Hdump_page_itm page;
|
||||
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[][] sidebar_divs = page.Sidebar_divs();
|
||||
int sidebar_divs_len = sidebar_divs.length;
|
||||
for (int i = 0; i < sidebar_divs_len; ++i) {
|
||||
byte[] sidebar_div = sidebar_divs[i];
|
||||
bfr.Add(sidebar_div);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_mgr {
|
||||
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
|
||||
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] file_dir) {body_fmtr.Init_by_app(usr_dlg, file_dir);}
|
||||
public void Write(Bry_bfr bfr, Xow_wiki wiki, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
|
||||
body_fmtr.Init_by_page(wiki, page);
|
||||
sidebars_fmtr.Init_by_page(page);
|
||||
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);
|
||||
}
|
||||
}
|
||||
@@ -1,87 +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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_html_mgr_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
|
||||
@Test public void Img() {
|
||||
fxt .Init_body("~<img|0>")
|
||||
.Test_html(" src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220.png' width='220' height='110'");
|
||||
}
|
||||
@Test public void Img_w() {
|
||||
fxt .Init_body("~<img.w|0>")
|
||||
.Test_html("220");
|
||||
}
|
||||
@Test public void Mda_info() {
|
||||
fxt .Init_body("~<mda.info|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/info.png\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Mda_mgnf() {
|
||||
fxt .Init_body("~<mda.mgnf|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Mda_play() {
|
||||
fxt .Init_body("~<mda.play|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Hdump_html_mgr_fxt {
|
||||
private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
|
||||
private Hdump_page_itm page = new Hdump_page_itm();
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private Bry_fmtr skin_fmtr = Bry_fmtr.new_("~{display_ttl}~{content_sub}~{sidebar_divs}~{body_html}", "display_ttl", "content_sub", "sidebar_divs", "body_html");
|
||||
private ListAdp img_list = ListAdp_.new_();
|
||||
private Xow_wiki wiki;
|
||||
public void Clear() {
|
||||
html_mgr.Init_by_app(Gfo_usr_dlg_.Null, Bry_.new_ascii_("file:///mem/xowa/file/"));
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
public Hdump_html_mgr_fxt Init_body(String body) {page.Page_body_(Bry_.new_utf8_(body)); return this;}
|
||||
public Hdump_html_mgr_fxt Init_img(int id, int w, int h, String ttl, String src) {img_list.Add(new Hdump_img_itm(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
|
||||
public Hdump_html_mgr_fxt Test_html(String expd) {
|
||||
if (img_list.Count() > 0) page.Img_itms_((Hdump_img_itm[])img_list.XtoAryAndClear(Hdump_img_itm.class));
|
||||
html_mgr.Write(bfr, wiki, skin_fmtr, page);
|
||||
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +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.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.pages.*;
|
||||
class Hdump_load_mgr {
|
||||
private Hdump_db_mgr db_mgr;
|
||||
private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
|
||||
private int page_version;
|
||||
private byte[] page_text, display_ttl, content_sub;
|
||||
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
|
||||
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
private byte zip_tid;
|
||||
public Hdump_load_mgr(Hdump_db_mgr db_mgr, byte zip_tid) {this.db_mgr = db_mgr; this.zip_tid = zip_tid;}
|
||||
public void Clear() {
|
||||
page_version = -1;
|
||||
page_text = display_ttl = content_sub = null;
|
||||
sidebar_divs.Clear();
|
||||
img_itms.Clear();
|
||||
}
|
||||
public void Load(Hdump_page_itm page, int page_id, byte[] page_url) {
|
||||
Db_provider provider = db_mgr.Db_provider_by_page(page_id);
|
||||
text_tbl.Provider_(provider);
|
||||
text_tbl.Select_by_page(tmp_text_itms, page_id);
|
||||
Load_itm(page, page_id, page_url, tmp_text_itms);
|
||||
}
|
||||
public void Load_itm(Hdump_page_itm page, int page_id, byte[] page_url, ListAdp itms) {
|
||||
this.Clear();
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row itm = (Hdump_text_row)itms.FetchAt(i);
|
||||
switch (itm.Tid()) {
|
||||
case Hdump_text_row_tid.Tid_body: Load_itm_body(itm); break;
|
||||
case Hdump_text_row_tid.Tid_img: Load_itm_img(itm); break;
|
||||
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(zip_tid, itm.Data())); break;
|
||||
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(zip_tid, itm.Data()); break;
|
||||
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(zip_tid, itm.Data()); break;
|
||||
}
|
||||
}
|
||||
page.Init(page_id, page_url, page_version, display_ttl, content_sub, page_text
|
||||
, (byte[][])sidebar_divs.XtoAryAndClear(byte[].class)
|
||||
, (Hdump_img_itm[])img_itms.XtoAryAndClear(Hdump_img_itm.class)
|
||||
);
|
||||
}
|
||||
public void Load_itm_body(Hdump_text_row itm) {
|
||||
page_version = itm.Version_id();
|
||||
page_text = zip_mgr.Unzip(zip_tid, itm.Data());
|
||||
}
|
||||
public void Load_itm_img(Hdump_text_row itm) {
|
||||
bry_rdr.Src_(itm.Data());
|
||||
int uid = bry_rdr.Read_int_to_pipe();
|
||||
int w = bry_rdr.Read_int_to_pipe();
|
||||
int h = bry_rdr.Read_int_to_pipe();
|
||||
byte[] ttl = bry_rdr.Read_bry_to_pipe();
|
||||
byte[] src = bry_rdr.Read_bry_to_pipe();
|
||||
Hdump_img_itm img_itm = new Hdump_img_itm(uid, w, h, ttl, src);
|
||||
img_itms.Add(img_itm);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +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.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_load_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Init_row_body("<body/>");
|
||||
fxt.Expd_body("<body/>");
|
||||
fxt.Test_load(0);
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt.Init_row_img(0, "0|220|110|A.png|commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
fxt.Init_row_img(1, "1|200|100|B.png|commons.wikimedia.org/thumb/7/0/B.png/200.png");
|
||||
fxt.Expd_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
fxt.Expd_img(1, 200, 100, "B.png", "commons.wikimedia.org/thumb/7/0/B.png/200.png");
|
||||
fxt.Test_load(0);
|
||||
}
|
||||
}
|
||||
class Hdump_load_mgr_fxt {
|
||||
private Hdump_load_mgr load_mgr;
|
||||
private Hdump_page_itm page = new Hdump_page_itm();
|
||||
private ListAdp init_rows = ListAdp_.new_();
|
||||
private String expd_body;
|
||||
private ListAdp expd_imgs = ListAdp_.new_();
|
||||
private int page_id = 0;
|
||||
public void Clear() {
|
||||
load_mgr = new Hdump_load_mgr(null, gplx.ios.Io_stream_.Tid_file);
|
||||
init_rows.Clear();
|
||||
expd_body = null;
|
||||
expd_imgs.Clear();
|
||||
}
|
||||
public Hdump_load_mgr_fxt Init_row_body(String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(data))); return this;}
|
||||
public Hdump_load_mgr_fxt Init_row_img (int uid, String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img , uid, 0, Bry_.new_utf8_(data))); return this;}
|
||||
public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;}
|
||||
public Hdump_load_mgr_fxt Expd_img(int idx, int w, int h, String ttl, String src) {expd_imgs.Add(new Hdump_img_itm(idx, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
|
||||
public Hdump_load_mgr_fxt Test_load(int page_id) {
|
||||
load_mgr.Load_itm(page, page_id, Bry_.Empty, init_rows);
|
||||
if (expd_body != null) Tfds.Eq(expd_body, String_.new_utf8_(page.Page_body()));
|
||||
if (expd_imgs.Count() != 0) Tfds.Eq_ary_str((Hdump_img_itm[])expd_imgs.XtoAryAndClear(Hdump_img_itm.class), page.Img_itms());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +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.dbs.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
|
||||
public class Hdump_save_mgr {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
|
||||
private Hdump_text_tbl text_tbl;
|
||||
public void Tbl_(Hdump_text_tbl v) {text_tbl = v;}
|
||||
public void Update(Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
text_tbl.Delete_by_page(page_id);
|
||||
this.Insert(page);
|
||||
}
|
||||
public void Insert(Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
Xopg_hdump_data hdump_data = page.Hdump_data();
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, 0, 0, hdump_data.Body());
|
||||
Insert_files(page_id, hdump_data.Imgs());
|
||||
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
|
||||
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
|
||||
Insert_sidebars(page_id, page, html_data.Xtn_skin_mgr());
|
||||
}
|
||||
private void Insert_files(int page_id, ListAdp imgs) {
|
||||
int len = imgs.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_xfer_itm img = (Xof_xfer_itm)imgs.FetchAt(i);
|
||||
int uid = img.Html_uid();
|
||||
byte[] data = Hdump_text_row.data_img_(tmp_bfr, uid, img.Html_w(), img.Html_h(), img.Lnki_ttl(), img.Html_view_src_rel());
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_img, uid, 0, data);
|
||||
}
|
||||
}
|
||||
private void Insert_if_exists(int page_id, int tid, byte[] val) {
|
||||
if (Bry_.Len_gt_0(val))
|
||||
text_tbl.Insert(page_id, tid, 0, 0, val);
|
||||
}
|
||||
private void Insert_sidebars(int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
|
||||
int len = xtn_skin_mgr.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
|
||||
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
|
||||
itm.Write(tmp_bfr, page);
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_sidebar_div, i, 0, tmp_bfr.XtoAryAndClear());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,10 @@ public class Xodb_category_tbl {
|
||||
} finally {stmt.Rls(); rdr.Rls();}
|
||||
return Xodb_category_itm.Null;
|
||||
}
|
||||
public void Select_by_cat_id_in(Cancelable cancelable, OrderedHash rv, Db_provider p, int bgn, int end) {
|
||||
public void Select_by_cat_id_in(Cancelable cancelable, OrderedHash rv, Db_provider p, Xow_wiki wiki, int bgn, int end) {
|
||||
Xodb_in_wkr_category_id wkr = new Xodb_in_wkr_category_id();
|
||||
wkr.Init(rv);
|
||||
wkr.Select_in(p, cancelable, bgn, end);
|
||||
wkr.Select_in(p, cancelable, wiki, bgn, end);
|
||||
}
|
||||
public static Xodb_category_itm Read_ctg(DataRdr rdr) {
|
||||
return Xodb_category_itm.load_
|
||||
|
||||
@@ -20,20 +20,21 @@ import gplx.dbs.*;
|
||||
public abstract class Xodb_in_wkr_base {
|
||||
public abstract int Interval();
|
||||
public abstract void Fill_stmt(Db_stmt stmt, int bgn, int end);
|
||||
public abstract Db_qry Build_qry(int bgn, int end);
|
||||
public abstract void Eval_rslts(Cancelable cancelable, DataRdr rdr);
|
||||
public void Select_in(Db_provider provider, Cancelable cancelable, int full_bgn, int full_end) {
|
||||
public abstract Db_qry Build_qry(Xodb_ctx tbl_ctx, int bgn, int end);
|
||||
public abstract void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr);
|
||||
public void Select_in(Db_provider provider, Cancelable cancelable, Xow_wiki wiki, int full_bgn, int full_end) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
Db_stmt stmt = Db_stmt_.Null;
|
||||
int interval = Interval();
|
||||
Xodb_ctx db_ctx = wiki.Db_mgr().Db_ctx();
|
||||
for (int i = full_bgn; i < full_end; i += interval) {
|
||||
int part_end = i + interval;
|
||||
if (part_end > full_end) part_end = full_end;
|
||||
try {
|
||||
stmt = provider.Prepare(Build_qry(i, part_end));
|
||||
stmt = provider.Prepare(Build_qry(db_ctx, i, part_end));
|
||||
Fill_stmt(stmt, i, part_end);
|
||||
rdr = stmt.Exec_select();
|
||||
Eval_rslts(cancelable, rdr);
|
||||
Eval_rslts(cancelable, wiki, rdr);
|
||||
}
|
||||
finally {rdr.Rls(); stmt.Rls();}
|
||||
}
|
||||
|
||||
145
400_xowa/src/gplx/xowa/dbs/tbls/Xodb_in_wkr_page.java
Normal file
145
400_xowa/src/gplx/xowa/dbs/tbls/Xodb_in_wkr_page.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.criterias.*;
|
||||
class Xodb_in_wkr_page_id extends Xodb_in_wkr_page_base {
|
||||
private ListAdp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
|
||||
private OrderedHash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
|
||||
public void Init(ListAdp list, OrderedHash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
|
||||
@Override public int Interval() {return 990;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_id;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
return Db_crt_.in_(this.In_fld_name(), part_ary);
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)list.FetchAt(i);
|
||||
stmt.Val_int_(page.Id());
|
||||
}
|
||||
}
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Id_val());}
|
||||
}
|
||||
class Xodb_in_wkr_page_title extends Xodb_in_wkr_page_base {
|
||||
private OrderedHash hash;
|
||||
private int in_ns;
|
||||
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(OrderedHash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, in_ns), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(in_ns);
|
||||
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
|
||||
}
|
||||
}
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_wo_ns());}
|
||||
}
|
||||
class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
|
||||
private Xow_wiki wiki;
|
||||
private OrderedHash hash;
|
||||
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Xow_wiki wiki, OrderedHash hash) {this.wiki = wiki; this.hash = hash;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(page.Ns_id());
|
||||
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
|
||||
}
|
||||
}
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {
|
||||
Xow_ns ns = wiki.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();
|
||||
rdr_page.Ttl_(ns, ttl_wo_ns);
|
||||
return (Xodb_page)hash.Fetch(rdr_page.Ttl_w_ns());
|
||||
}
|
||||
}
|
||||
abstract class Xodb_in_wkr_page_base extends Xodb_in_wkr_base {
|
||||
public String Tbl_name() {return Xodb_page_tbl.Tbl_name;}
|
||||
public abstract String In_fld_name();
|
||||
public abstract Criteria In_filter(Object[] part_ary);
|
||||
public abstract Xodb_page Eval_rslts_key(Xodb_page rdr_page);
|
||||
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public Xodb_in_wkr_page_base Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v; return this;} private boolean fill_idx_fields_only;
|
||||
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
|
||||
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_
|
||||
( this.Tbl_name()
|
||||
, In_filter(part_ary)
|
||||
, fill_idx_fields_only ? Xodb_page_tbl.Flds_select_idx : db_ctx.Html_db_enabled() ? Xodb_page_tbl.Flds_select_all__html_y : Xodb_page_tbl.Flds_select_all__html_n
|
||||
)
|
||||
;
|
||||
}
|
||||
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
|
||||
Xodb_page temp = new Xodb_page();
|
||||
boolean html_db_enabled = wiki.Db_mgr().Hdump_mgr().Enabled();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
if (fill_idx_fields_only)
|
||||
Xodb_page_tbl.Read_page__idx(temp, rdr);
|
||||
else
|
||||
Xodb_page_tbl.Read_page__all(temp, rdr, html_db_enabled);
|
||||
Xodb_page page = Eval_rslts_key(temp);
|
||||
if (page == null) continue; // page not found
|
||||
temp.Exists_(true);
|
||||
page.Copy(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xodb_in_wkr_category_id extends Xodb_in_wkr_base {
|
||||
private OrderedHash hash;
|
||||
@Override public int Interval() {return 990;}
|
||||
public void Init(OrderedHash hash) {this.hash = hash;}
|
||||
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
|
||||
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
|
||||
String in_fld_name = Xodb_category_tbl.Fld_cat_id;
|
||||
return Db_qry_.select_cols_
|
||||
( Xodb_category_tbl.Tbl_name
|
||||
, Db_crt_.in_(in_fld_name, part_ary)
|
||||
)
|
||||
;
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(page.Id());
|
||||
}
|
||||
}
|
||||
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xodb_category_itm ctg_data = Xodb_category_tbl.Read_ctg(rdr);
|
||||
Xodb_page page = (Xodb_page)hash.Fetch(ctg_data.Id_val());
|
||||
page.Xtn_(ctg_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.criterias.*;
|
||||
public class Xodb_page_tbl {
|
||||
private Xow_wiki wiki;
|
||||
public Xodb_page_tbl(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public void Html_db_enabled_(boolean v) {html_db_enabled = v;} private boolean html_db_enabled;
|
||||
public Db_provider Provider() {return provider;} public void Provider_(Db_provider provider) {this.provider = provider;} private Db_provider provider;
|
||||
public void Delete_all() {provider.Exec_qry(Db_qry_.delete_tbl_(Tbl_name));}
|
||||
public Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx);}
|
||||
public void Insert(Db_stmt stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, int page_len, int random_int, int file_idx) {
|
||||
public void Delete_all() {provider.Exec_qry(Db_qry_.delete_tbl_(Tbl_name));}
|
||||
public Db_stmt Insert_stmt(Db_provider p) {
|
||||
return Db_stmt_.new_insert_(p, Tbl_name, html_db_enabled ? Flds_insert__html_y : Flds_insert__html_n);
|
||||
}
|
||||
public void Insert(Db_stmt stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, int page_len, int random_int, int file_idx, int html_db_id) {
|
||||
stmt.Clear()
|
||||
.Val_int_(page_id)
|
||||
.Val_int_(ns_id)
|
||||
@@ -30,8 +35,10 @@ public class Xodb_page_tbl {
|
||||
.Val_str_(Xto_touched_str(modified_on))
|
||||
.Val_int_(page_len)
|
||||
.Val_int_(random_int)
|
||||
.Val_int_(file_idx)
|
||||
.Exec_insert();
|
||||
.Val_int_(file_idx);
|
||||
if (html_db_enabled)
|
||||
stmt.Val_int_(html_db_id);
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
public int Select_id(int ns_id, byte[] ttl) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
@@ -61,33 +68,18 @@ public class Xodb_page_tbl {
|
||||
.Val_int_(page_id)
|
||||
.Exec_select();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Read_page(rv, rdr);
|
||||
Read_page__all(rv, rdr, html_db_enabled);
|
||||
return true;
|
||||
}
|
||||
} finally {rdr.Rls(); stmt.Rls();}
|
||||
return false;
|
||||
}
|
||||
public static void Read_page(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.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.Db_file_idx_ (rdr.ReadInt(Fld_page_file_idx));
|
||||
}
|
||||
public static void Read_page_for_search_suggest(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));
|
||||
}
|
||||
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) {
|
||||
Criteria crt_ttl = fwd ? Db_crt_.mte_(Fld_page_title, String_.new_utf8_(ttl_frag)) : Db_crt_.lt_(Fld_page_title, String_.new_utf8_(ttl_frag));
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, ns_id), crt_ttl, Db_crt_.mte_(Fld_page_len, min_page_len));
|
||||
if (!include_redirects)
|
||||
crt = Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, Byte_.Zero));
|
||||
String[] cols = search_suggest ? Flds_ary_search_suggest : Flds_ary_all;
|
||||
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);
|
||||
return select.Exec_qry_as_rdr(provider);
|
||||
@@ -102,7 +94,7 @@ public class Xodb_page_tbl {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xodb_page page = new Xodb_page();
|
||||
Read_page_for_search_suggest(page, rdr);
|
||||
Read_page__idx(page, rdr);
|
||||
if (max_val_check && !Bry_.HasAtBgn(page.Ttl_wo_ns(), key)) break;
|
||||
nxt_itm = page;
|
||||
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
|
||||
@@ -119,7 +111,7 @@ public class Xodb_page_tbl {
|
||||
Xodb_page prv_itm = new Xodb_page();
|
||||
boolean found = false;
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Read_page(prv_itm, rdr);
|
||||
Read_page__all(prv_itm, rdr, html_db_enabled);
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
@@ -143,7 +135,7 @@ public class Xodb_page_tbl {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xodb_page page = new Xodb_page();
|
||||
Read_page_for_search_suggest(page, rdr);
|
||||
Read_page__idx(page, rdr);
|
||||
rslt_list.Add(page);
|
||||
}
|
||||
rslt_list.SortBy(Xodb_page_sorter.TitleAsc);
|
||||
@@ -164,7 +156,7 @@ public class Xodb_page_tbl {
|
||||
}
|
||||
Xodb_in_wkr_page_id wkr = new Xodb_in_wkr_page_id();
|
||||
wkr.Init(rv, hash);
|
||||
wkr.Select_in(provider, cancelable, bgn, end);
|
||||
wkr.Select_in(provider, cancelable, wiki, bgn, end);
|
||||
return true;
|
||||
}
|
||||
public boolean Select_by_ttl(Xodb_page rv, Xow_ns ns, byte[] ttl) {
|
||||
@@ -177,7 +169,7 @@ public class Xodb_page_tbl {
|
||||
.Val_str_(String_.new_utf8_(ttl))
|
||||
.Exec_select();
|
||||
if (rdr.MoveNextPeer()) {
|
||||
Read_page(rv, rdr);
|
||||
Read_page__all(rv, rdr, html_db_enabled);
|
||||
return true;
|
||||
}
|
||||
} finally {rdr.Rls(); stmt.Rls();}
|
||||
@@ -231,7 +223,7 @@ public class Xodb_page_tbl {
|
||||
Criteria crt = gplx.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, -1), Db_crt_.mt_(Fld_page_title, ""));
|
||||
if (redirect != Bool_.__byte)
|
||||
crt = gplx.criterias.Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, redirect));
|
||||
Db_qry_select qry = Db_qry_.select_().From_(Tbl_name).Cols_(Flds_all)
|
||||
Db_qry_select 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.Prepare(qry);
|
||||
@@ -246,7 +238,7 @@ public class Xodb_page_tbl {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xodb_page page = new Xodb_page();
|
||||
Read_page(page, rdr);
|
||||
Read_page__all(page, rdr, html_db_enabled);
|
||||
rv.Add(page.Id_val(), page);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
@@ -255,159 +247,46 @@ public class Xodb_page_tbl {
|
||||
Xodb_in_wkr_page_title_ns wkr = new Xodb_in_wkr_page_title_ns();
|
||||
wkr.Fill_idx_fields_only_(fill_idx_fields_only);
|
||||
wkr.Init(wiki, rv);
|
||||
wkr.Select_in(provider, cancelable, bgn, end);
|
||||
wkr.Select_in(provider, cancelable, wiki, bgn, end);
|
||||
}
|
||||
public void Select_by_ttl_in(Cancelable cancelable, OrderedHash rv, int ns_id, int bgn, int end) {
|
||||
Xodb_in_wkr_page_title wkr = new Xodb_in_wkr_page_title();
|
||||
wkr.Init(rv, ns_id);
|
||||
wkr.Select_in(provider, cancelable, bgn, end);
|
||||
wkr.Select_in(provider, cancelable, wiki, bgn, end);
|
||||
}
|
||||
public void Update_html_db_id(int page_id, int html_db_id) {
|
||||
if (!html_db_enabled) throw Err_.new_("html_db not enabled");
|
||||
Db_stmt stmt = Db_stmt_.new_update_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_page_html_db_id);
|
||||
stmt.Val_int_(html_db_id).Val_int_(page_id).Exec_update();
|
||||
}
|
||||
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
|
||||
private static String Xto_touched_str(DateAdp v) {return v.XtoStr_fmt(Page_touched_fmt);}
|
||||
public static final String Tbl_name = "page", Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title", Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len", Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx";
|
||||
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx};
|
||||
public static String[] Flds_ary_all = String_.Ary(Flds_all), Flds_ary_search_suggest = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_len);
|
||||
public static final String Tbl_name = "page"
|
||||
, Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title", Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len"
|
||||
, Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx", Fld_page_html_db_id = "page_html_db_id";
|
||||
public static final String[]
|
||||
Flds_insert__html_n = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx)
|
||||
, Flds_insert__html_y = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx, Fld_page_html_db_id)
|
||||
, Flds_select_all__html_n = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx)
|
||||
, Flds_select_all__html_y = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx, Fld_page_html_db_id)
|
||||
, Flds_select_idx = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_len)
|
||||
;
|
||||
public static final boolean Load_idx_flds_only_y = true;
|
||||
}
|
||||
class Xodb_in_wkr_page_id extends Xodb_in_wkr_page_base {
|
||||
private ListAdp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
|
||||
private OrderedHash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
|
||||
public void Init(ListAdp list, OrderedHash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
|
||||
@Override public int Interval() {return 990;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_id;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
return Db_crt_.in_(this.In_fld_name(), part_ary);
|
||||
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.Db_file_idx_ (rdr.ReadInt(Fld_page_file_idx));
|
||||
if (html_db_enabled)
|
||||
page.Html_db_id_(rdr.ReadInt(Fld_page_html_db_id));
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)list.FetchAt(i);
|
||||
stmt.Val_int_(page.Id());
|
||||
}
|
||||
}
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Id_val());}
|
||||
}
|
||||
class Xodb_in_wkr_page_title extends Xodb_in_wkr_page_base {
|
||||
private OrderedHash hash;
|
||||
private int in_ns;
|
||||
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(OrderedHash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, in_ns), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(in_ns);
|
||||
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
|
||||
}
|
||||
}
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_wo_ns());}
|
||||
}
|
||||
class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
|
||||
private Xow_wiki wiki;
|
||||
private OrderedHash hash;
|
||||
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Xow_wiki wiki, OrderedHash hash) {this.wiki = wiki; this.hash = hash;}
|
||||
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
|
||||
@Override public Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(page.Ns_id());
|
||||
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
|
||||
}
|
||||
}
|
||||
// public override Criteria In_filter(Object[] part_ary) {
|
||||
// int len = part_ary.length;
|
||||
// Object[] vals = new Object[len];
|
||||
// for (int i = 0; i < len; i++)
|
||||
// vals[i] = Bry_.Empty;
|
||||
// Db_obj_ary_crt crt_x = Db_obj_ary_crt.new_(new Db_fld(Xodb_page_tbl.Fld_page_title, ClassAdp_.Tid_str));
|
||||
// crt_x.Vals_(new Object[][] {vals});
|
||||
// return Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), crt_x);
|
||||
//// return Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Criteria_.Or_many(crt_ary));
|
||||
// }
|
||||
// public override void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
// stmt.Val_int_(0);
|
||||
// for (int i = bgn; i < end; i++) {
|
||||
// Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
// stmt.Val_str_by_bry_(page.Ttl_wo_ns());
|
||||
// }
|
||||
// }
|
||||
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {
|
||||
Xow_ns ns = wiki.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();
|
||||
rdr_page.Ttl_(ns, ttl_wo_ns);
|
||||
return (Xodb_page)hash.Fetch(rdr_page.Ttl_w_ns());
|
||||
}
|
||||
}
|
||||
abstract class Xodb_in_wkr_page_base extends Xodb_in_wkr_base {
|
||||
public String Tbl_name() {return Xodb_page_tbl.Tbl_name;}
|
||||
public abstract String In_fld_name();
|
||||
public abstract Criteria In_filter(Object[] part_ary);
|
||||
public abstract Xodb_page Eval_rslts_key(Xodb_page rdr_page);
|
||||
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public Xodb_in_wkr_page_base Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v; return this;} private boolean fill_idx_fields_only;
|
||||
@Override public Db_qry Build_qry(int bgn, int end) {
|
||||
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_
|
||||
( this.Tbl_name()
|
||||
, In_filter(part_ary)
|
||||
, fill_idx_fields_only ? Xodb_page_tbl.Flds_ary_search_suggest : Xodb_page_tbl.Flds_ary_all
|
||||
)
|
||||
;
|
||||
}
|
||||
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
|
||||
Xodb_page temp = new Xodb_page();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
if (fill_idx_fields_only)
|
||||
Xodb_page_tbl.Read_page_for_search_suggest(temp, rdr);
|
||||
else
|
||||
Xodb_page_tbl.Read_page(temp, rdr);
|
||||
Xodb_page page = Eval_rslts_key(temp);
|
||||
if (page == null) continue; // page not found
|
||||
temp.Exists_(true);
|
||||
page.Copy(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xodb_in_wkr_category_id extends Xodb_in_wkr_base {
|
||||
private OrderedHash hash;
|
||||
@Override public int Interval() {return 990;}
|
||||
public void Init(OrderedHash hash) {this.hash = hash;}
|
||||
@Override public Db_qry Build_qry(int bgn, int end) {
|
||||
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
|
||||
String in_fld_name = Xodb_category_tbl.Fld_cat_id;
|
||||
return Db_qry_.select_cols_
|
||||
( Xodb_category_tbl.Tbl_name
|
||||
, Db_crt_.in_(in_fld_name, part_ary)
|
||||
)
|
||||
;
|
||||
}
|
||||
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xodb_page page = (Xodb_page)hash.FetchAt(i);
|
||||
stmt.Val_int_(page.Id());
|
||||
}
|
||||
}
|
||||
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xodb_category_itm ctg_data = Xodb_category_tbl.Read_ctg(rdr);
|
||||
Xodb_page page = (Xodb_page)hash.Fetch(ctg_data.Id_val());
|
||||
page.Xtn_(ctg_data);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xodb_search_title_word_tbl {
|
||||
.Val_str_by_bry_(word)
|
||||
.Exec_insert();
|
||||
}
|
||||
public static void Select_by_word(Cancelable cancelable, ListAdp rv, byte[] search, int results_max, Db_provider p) {
|
||||
public static void Select_by_word(Cancelable cancelable, ListAdp rv, Xow_wiki wiki, byte[] search, int results_max, Db_provider p) {
|
||||
Db_qry_select qry = Db_qry_.select_()
|
||||
.Cols_(Xodb_search_title_word_tbl.Fld_stw_word_id)
|
||||
.From_(Xodb_search_title_word_tbl.Tbl_name, "w")
|
||||
@@ -54,7 +54,7 @@ public class Xodb_search_title_word_tbl {
|
||||
|
||||
Xodb_in_wkr_search_title_id wkr = new Xodb_in_wkr_search_title_id();
|
||||
wkr.Init(words, rv);
|
||||
wkr.Select_in(p, cancelable, 0, words.Count());
|
||||
wkr.Select_in(p, cancelable, wiki, 0, words.Count());
|
||||
}
|
||||
public static final String Tbl_name = "search_title_word", Fld_stw_word_id = "stw_word_id", Fld_stw_word = "stw_word";
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
@@ -70,7 +70,7 @@ class Xodb_in_wkr_search_title_id extends Xodb_in_wkr_base {
|
||||
private ListAdp words, pages;
|
||||
@Override public int Interval() {return 990;}
|
||||
public void Init(ListAdp words, ListAdp pages) {this.words = words; this.pages = pages;}
|
||||
@Override public Db_qry Build_qry(int bgn, int end) {
|
||||
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
|
||||
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
|
||||
String in_fld_name = Xodb_search_title_page_tbl.Fld_stp_word_id;
|
||||
return Db_qry_.select_cols_
|
||||
@@ -85,7 +85,7 @@ class Xodb_in_wkr_search_title_id extends Xodb_in_wkr_base {
|
||||
stmt.Val_int_(word_id.Val());
|
||||
}
|
||||
}
|
||||
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
|
||||
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
|
||||
while (rdr.MoveNextPeer()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
int page_id = rdr.ReadInt(Xodb_search_title_page_tbl.Fld_stp_page_id);
|
||||
|
||||
Reference in New Issue
Block a user