1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-08-17 23:27:07 -04:00
parent 56128795f5
commit df7fcf8eae
231 changed files with 2433 additions and 3347 deletions

View File

@@ -19,8 +19,8 @@ package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
public class Xodb_file {
public Xodb_file(int id, byte tid) {this.id = id; this.tid = tid;}
public int Id() {return id;} private int id;
public byte Tid() {return tid;} private byte tid;
public int Id() {return id;} private final int id; // unique id in xowa_db
public byte Tid() {return tid;} private final byte tid; // db type id
public Io_url Url() {return url;} public Xodb_file Url_(Io_url v) {url = v; return this;} private Io_url url;
public String Url_rel() {return url_rel;} public Xodb_file Url_rel_(String v) {url_rel = v; return this;} private String url_rel;
public long File_len() {return file_len;} public Xodb_file File_len_add(int v) {file_len += v; return this;} private long file_len;
@@ -39,7 +39,6 @@ public class Xodb_file {
provider.Rls();
} finally {provider = null;}
}
public static Xodb_file load_(int id, byte tid, String url) {return new Xodb_file(id, tid).Url_rel_(url).Cmd_mode_(Db_cmd_mode.Ignore);}
public static Xodb_file make_(int id, byte tid, String url) {return new Xodb_file(id, tid).Url_rel_(url).Cmd_mode_(Db_cmd_mode.Create);}
}

View File

@@ -16,9 +16,9 @@ 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.*;
public class Xodb_file_tid_ {
public static final byte Tid_core = 1, Tid_text = 2, Tid_category = 3, Tid_search = 4, Tid_wikidata = 5, Tid_temp = 6;
public static final String Key_core = "core", Key_text = "text", Key_category = "category", Key_wikidata = "wikidata", Key_temp = "temp", Key_search = "search";
public class Xodb_file_tid {
public static final byte Tid_core = 1, Tid_text = 2, Tid_category = 3, Tid_search = 4, Tid_wikidata = 5, Tid_temp = 6, Tid_html = 7; // SERIALIZED
public static final String Key_core = "core", Key_text = "text", Key_category = "category", Key_wikidata = "wikidata", Key_temp = "temp", Key_search = "search", Key_html = "html";
public static String Xto_key(byte v) {
switch (v) {
case Tid_core: return Key_core;
@@ -27,6 +27,7 @@ public class Xodb_file_tid_ {
case Tid_wikidata: return Key_wikidata;
case Tid_temp: return Key_temp;
case Tid_search: return Key_search;
case Tid_html: return Key_html;
default: throw Err_.unhandled(v);
}
}

View File

@@ -16,23 +16,17 @@ 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.dbs.*; import gplx.xowa.dbs.tbls.*;
public class Xodb_fsys_mgr {
public Xodb_fsys_mgr Ctor(Io_url src_dir, Io_url trg_dir, String trg_name) {
this.src_dir = src_dir;
this.trg_dir = trg_dir;
this.trg_name = trg_name;
return this;
} private Io_url src_dir; private String trg_name;
public Db_provider Core_provider() {return core_provider;} private Db_provider core_provider;
public Db_provider Page_provider() {return page_provider;} private Db_provider page_provider;
public Db_provider Category_provider() {return category_provider;} private Db_provider category_provider;
public Db_provider Wdata_provider() {return wikidata_provider;} private Db_provider wikidata_provider;
public Io_url Trg_dir() {return trg_dir;} private Io_url trg_dir;
private final Io_url src_dir; private final Io_url trg_dir; private final String wiki_name;
public Xodb_fsys_mgr(Io_url src_dir, Io_url trg_dir, String wiki_name) {this.src_dir = src_dir; this.trg_dir = trg_dir; this.wiki_name = wiki_name;}
public Xodb_file[] Files_ary() {return files_ary;}
public Db_provider Provider_core() {return provider_core;} private Db_provider provider_core;
public Db_provider Provider_page() {return provider_page;} private Db_provider provider_page;
public Db_provider Provider_ctg() {return provider_ctg;} public void Provider_ctg_(Xodb_file file) {provider_ctg = file.Provider();} private Db_provider provider_ctg;
public Db_provider Provider_wdata() {return provider_wdata;}public void Provider_wdata_(Xodb_file file) {provider_wdata = file.Provider();} private Db_provider provider_wdata;
public int Tid_text_idx() {return tid_text_idx;} public Xodb_fsys_mgr Tid_text_idx_(int v) {tid_text_idx = v; return this;} private int tid_text_idx = File_id_core;
public long Tid_text_max() {return tid_text_max;} long tid_text_max = Heap_max_infinite;
static final int File_id_core = 0;
public Xodb_file[] Ary() {return files_ary;}
public long Tid_text_max() {return tid_text_max;} private long tid_text_max = Heap_max_infinite;
public void Init_by_files(Db_provider p, Xodb_file[] v) {
files_ary = v; files_ary_len = v.length;
boolean category_provider_core_null = true;
@@ -41,55 +35,44 @@ public class Xodb_fsys_mgr {
Io_url url = trg_dir.GenSubFil(file.Url_rel()); // relative name only
file.Connect_(Db_connect_.sqlite_(url)).Url_(url);
switch (file.Tid()) {
case Xodb_file_tid_.Tid_core : file.Provider_(p); Init_by_tid_core(file); break;
case Xodb_file_tid_.Tid_category : if (category_provider_core_null) {Init_by_tid_category(file); category_provider_core_null = false;}break;
case Xodb_file_tid_.Tid_wikidata : Init_by_tid_wikidata(file); break;
case Xodb_file_tid_.Tid_text : Init_by_tid_text(file); break;
case Xodb_file_tid.Tid_core : file.Provider_(p); Set_file_core(file); break;
case Xodb_file_tid.Tid_category : if (category_provider_core_null) {Provider_ctg_(file); category_provider_core_null = false;} break;
case Xodb_file_tid.Tid_wikidata : Provider_wdata_(file); break;
case Xodb_file_tid.Tid_text : Set_file_text(file); break;
}
}
}
public void Init_make(Xow_ns_mgr ns_mgr, String ns_map_str, long text_max) {
Init_by_tid_core(Make(Xodb_file_tid_.Tid_core));
Init_by_ns_map(ns_mgr, Xodb_ns_map_mgr.Parse(Bry_.new_ascii_(ns_map_str)));
if (text_max > 0)
Init_by_tid_text(Init_make_file(Xodb_file_tid_.Tid_text, text_max));
}
public Xodb_file Init_make_file(byte tid, long max) {
if (max == Max_core_db) return files_ary[File_id_core];
return Make(tid).File_max_(max);
}
private void Init_by_tid_core(Xodb_file file) {core_provider = page_provider = category_provider = wikidata_provider = file.Provider();}
public void Init_by_tid_category(Xodb_file file) {category_provider = file.Provider();}
public void Init_by_tid_wikidata(Xodb_file file) {wikidata_provider = file.Provider();}
private void Init_by_ns_map(Xow_ns_mgr ns_mgr, Xodb_ns_map_mgr ns_map) {
public void Init_by_ns_map(Xow_ns_mgr ns_mgr, String ns_map_str, long text_max) {
Set_file_core(Make(Xodb_file_tid.Tid_core));
Xodb_ns_map_mgr ns_map = Xodb_ns_map_mgr.Parse(Bry_.new_ascii_(ns_map_str));
Xodb_ns_map_itm[] ns_map_itms = ns_map.Itms();
int ns_map_itms_len = ns_map_itms.length;
for (int i = 0; i < ns_map_itms_len; i++) {
Xodb_ns_map_itm itm = ns_map_itms[i];
int[] ns_ids = itm.Ns_ids();
int ns_ids_len = ns_ids.length;
Xodb_file file = Make(Xodb_file_tid_.Tid_text);
Xodb_file file = Make(Xodb_file_tid.Tid_text);
for (int j = 0; j < ns_ids_len; j++) {
int ns_id = ns_ids[j];
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id); if (ns == null) continue; // some dumps may not have ns; for example, pre-2013 dumps won't have Module (828)
ns.Bldr_file_idx_(file.Id());
}
}
if (text_max > 0)
Set_file_text(Make(Xodb_file_tid.Tid_text).File_max_(text_max));
}
private void Init_by_tid_text(Xodb_file file) {
tid_text_idx = file.Id();
tid_text_max = file.File_max();
}
public Xodb_file Get_by_db_idx(int db_idx) {return files_ary[db_idx];}
public Xodb_file Get_or_make(byte file_tid, int file_idx) {return file_idx < files_ary_len ? files_ary[file_idx] : Make(file_tid);}
private void Set_file_core(Xodb_file file) {provider_core = provider_page = provider_ctg = provider_wdata = file.Provider();}
private void Set_file_text(Xodb_file file) {tid_text_idx = file.Id(); tid_text_max = file.File_max();}
public Io_url Get_url(byte file_tid) {
Xodb_file file = Get_tid_root(file_tid);
return trg_dir.GenSubFil(file.Url_rel());
}
public Xodb_file Get_by_idx(int idx) {return files_ary[idx];}
public Xodb_file Get_or_make(byte file_tid, int file_idx) {return file_idx < files_ary_len ? files_ary[file_idx] : Make(file_tid);}
public Xodb_file Get_tid_root(byte file_tid) {
for (int i = 0; i < files_ary_len; i++) {
Xodb_file file = files_ary[i];
if (file.Tid() == file_tid) return file; // assume 1st file is root
if (file.Tid() == file_tid) return file; // assume 1st found file is root
}
return null;
}
@@ -100,33 +83,25 @@ public class Xodb_fsys_mgr {
Sqlite_engine_.Idx_create(usr_dlg, file.Provider(), Int_.XtoStr(file.Id()), idxs);
}
}
public void Overwrite(int file_idx) {Create_sqlite3(src_dir, trg_dir, trg_name, file_idx);}
public Xodb_file Get_or_make(String name) {
Io_url url = trg_dir.GenSubFil(name + ".sqlite3");
if (!Io_mgr._.ExistsFil(url))
Io_mgr._.CopyFil(src_dir.GenSubFil("xowa.sqlite3"), url, true);
return Xodb_file.make_(-1, Xodb_file_tid_.Tid_temp, url.NameAndExt()).Connect_(Db_connect_.sqlite_(url));
}
public Xodb_file Make(byte file_tid) {
int file_idx = files_ary_len;
Io_url url = Create_sqlite3(src_dir, trg_dir, trg_name, file_idx);
Io_url url = Create_sqlite3(src_dir, trg_dir, wiki_name, file_idx);
Xodb_file rv = Xodb_file.make_(file_idx, file_tid, url.NameAndExt()).Connect_(Db_connect_.sqlite_(url));
gplx.xowa.dbs.tbls.Xodb_xowa_cfg_tbl.Insert_str(rv.Provider(), "db.meta", "type_name", Xodb_file_tid_.Xto_key(file_tid));
Xodb_xowa_cfg_tbl.Insert_str(rv.Provider(), "db.meta", "type_name", Xodb_file_tid.Xto_key(file_tid));
files_ary = (Xodb_file[])Array_.Resize(files_ary, files_ary_len + 1);
files_ary[files_ary_len] = rv;
++files_ary_len;
files_ary[files_ary_len++] = rv;
return rv;
} private Xodb_file[] files_ary = new Xodb_file[0]; int files_ary_len = 0;
} private Xodb_file[] files_ary = new Xodb_file[0]; private int files_ary_len = 0;
public void Rls() {
for (int i = 0; i < files_ary_len; i++)
files_ary[i].Rls();
}
private static Io_url Create_sqlite3(Io_url src_dir, Io_url trg_dir, String trg_name, int file_idx) {
private static Io_url Create_sqlite3(Io_url src_dir, Io_url trg_dir, String wiki_name, int file_idx) {
Io_url src_fil = src_dir.GenSubFil("xowa.sqlite3"); // /bin/any/sql/xowa/xowa.sqlite3
Io_url trg_fil = trg_dir.GenSubFil_ary(trg_name, ".", Int_.XtoStr_PadBgn(file_idx, 3), ".sqlite3"); // /wiki/en.wikipedia.org/en.wikipedia.org.000.sqlite3
Io_url trg_fil = trg_dir.GenSubFil_ary(wiki_name, ".", Int_.XtoStr_PadBgn(file_idx, 3), ".sqlite3"); // /wiki/en.wikipedia.org/en.wikipedia.org.000.sqlite3
Io_mgr._.CopyFil(src_fil, trg_fil, true);
return trg_fil;
}
private static final int File_id_core = 0;
public static final int Heap_max_infinite = 0;
public static final long Max_core_db = -1;
}

View File

@@ -19,7 +19,7 @@ package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
import gplx.xowa.apps.*; import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.dbs.tbls.*;
public class Xodb_load_mgr_sql implements Xodb_load_mgr {
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = db_mgr.Fsys_mgr();} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
public byte Search_version() {
if (search_provider == null) Search_version_init();
return search_version;
@@ -56,15 +56,15 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
public void Load_by_ids(Cancelable cancelable, ListAdp rv, int bgn, int end) {db_mgr.Tbl_page().Select_by_id_list(cancelable, false, rv, bgn, end);}
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
int cat_page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xodb_mgr_sql.Page_id_null) return false;
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), cat_page_id); if (ctg == Xodb_category_itm.Null) return false;
Db_provider p = fsys_mgr.Get_by_db_idx(ctg.File_idx()).Provider();
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), cat_page_id); if (ctg == Xodb_category_itm.Null) return false;
Db_provider p = fsys_mgr.Get_by_idx(ctg.File_idx()).Provider();
return db_mgr.Ctg_select_v1(rv, p, ctg);
}
public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.not_implemented_();}
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) {
int cat_page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xodb_mgr_sql.Page_id_null) return;
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), cat_page_id); if (ctg == Xodb_category_itm.Null) return;
Db_provider p = fsys_mgr.Get_by_db_idx(ctg.File_idx()).Provider();
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), cat_page_id); if (ctg == Xodb_category_itm.Null) return;
Db_provider p = fsys_mgr.Get_by_idx(ctg.File_idx()).Provider();
ListAdp list = ListAdp_.new_();
Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, p, list);
Load_ctg_v2a_ui_sift(rv, ctg, list);
@@ -112,7 +112,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
private Db_provider search_provider = null;
private void Search_version_init() {
if (search_provider == null) {
Xodb_file search_file = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_search);
Xodb_file search_file = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search);
if (search_file == null) {
search_provider = Db_provider_.Null;
search_version = gplx.xowa.specials.search.Xosrh_core.Version_1;
@@ -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, 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);
}
}
@@ -141,10 +141,10 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
public int Load_ctg_count(byte[] ttl) {
int page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ttl);
if (page_id == Xodb_mgr_sql.Page_id_null) return 0; // title not found; return 0;
return db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), page_id).Count_all();
return db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), page_id).Count_all();
}
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Tbl_wdata_qids().Select_qid(fsys_mgr.Wdata_provider(), wiki_alias, ns_num, ttl);}
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Tbl_wdata_pids().Select_pid(fsys_mgr.Wdata_provider(), lang_key, pid_name);}
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Tbl_wdata_qids().Select_qid(fsys_mgr.Provider_wdata(), wiki_alias, ns_num, ttl);}
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Tbl_wdata_pids().Select_pid(fsys_mgr.Provider_wdata(), lang_key, pid_name);}
public byte[] Find_random_ttl(Xow_ns ns) {return db_mgr.Tbl_page().Select_random(ns);}
public void Clear() {}
public Xodb_page[] Load_ctg_list(byte[][] ctg_ttls) {
@@ -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.Category_provider(), 0, len);
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), 0, len);
return (Xodb_page[])hash.XtoAry(Xodb_page.class);
}
}

View File

@@ -59,7 +59,7 @@ class Xodb_load_mgr_sql_fxt {
public void Init_save_ctgs(Xodb_page[] ary) {
int len = ary.length;
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
Db_provider p = db_mgr.Fsys_mgr().Core_provider();
Db_provider p = db_mgr.Fsys_mgr().Provider_core();
p.Txn_mgr().Txn_bgn_if_none();
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(p);
Db_stmt category_stmt = db_mgr.Tbl_category().Insert_stmt(p);

View File

@@ -16,7 +16,7 @@ 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.dbs.*; import gplx.xowa.dbs.hdumps.*;
public interface Xodb_mgr extends GfoInvkAble, RlsAble {
byte Tid();
String Tid_name();
@@ -26,4 +26,5 @@ public interface Xodb_mgr extends GfoInvkAble, RlsAble {
DateAdp Dump_date_query();
Xodb_load_mgr Load_mgr();
Xodb_save_mgr Save_mgr();
Xodb_html_mgr Html_mgr();
}

View File

@@ -17,14 +17,14 @@ 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.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
public Xodb_mgr_sql(Xow_wiki wiki) {
this.wiki = wiki;
load_mgr = new Xodb_load_mgr_sql(this);
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);
fsys_mgr.Ctor(wiki.App().Fsys_mgr().Bin_db_dir(), wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
}
public byte Tid() {return Tid_sql;} public static final byte Tid_sql = 1;
public String Tid_name() {return "sqlite3";}
@@ -33,9 +33,10 @@ 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 Xodb_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xodb_fsys_mgr fsys_mgr = new Xodb_fsys_mgr();
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_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();
@@ -52,14 +53,14 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
public DateAdp Dump_date_query() {
DateAdp rv = wiki.Props().Modified_latest();
if (rv != null) return rv;
Io_url url = fsys_mgr.Get_url(Xodb_file_tid_.Tid_core);
Io_url url = fsys_mgr.Get_url(Xodb_file_tid.Tid_core);
return Io_mgr._.QueryFil(url).ModifiedTime();
}
public void Init_make(String ns_map) {
public void Init_by_ns_map(String ns_map) {
Xoi_dump_mgr dump_mgr = wiki.App().Setup_mgr().Dump_mgr();
data_storage_format = dump_mgr.Data_storage_format();
fsys_mgr.Init_make(wiki.Ns_mgr(), ns_map, dump_mgr.Db_text_max());
Core_provider_(fsys_mgr.Core_provider());
fsys_mgr.Init_by_ns_map(wiki.Ns_mgr(), ns_map, dump_mgr.Db_text_max());
Core_provider_(fsys_mgr.Provider_core());
state = State_make;
}
public void Init_load(Db_connect connect) {
@@ -129,13 +130,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;
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_tid_name = "tid_name", Invk_html_mgr = "html_mgr"
;
public void Category_version_update(boolean version_is_1) {
String grp = Xodb_mgr_sql.Grp_wiki_init;
@@ -146,7 +148,7 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
tbl_cfg.Insert_str(grp, key, Byte_.XtoStr(category_version));
}
public void Delete_by_tid(byte tid) {
Xodb_file[] ary = fsys_mgr.Ary();
Xodb_file[] ary = fsys_mgr.Files_ary();
int len = ary.length;
for (int i = 0; i < len; i++) {
Xodb_file file = ary[i] ;
@@ -156,8 +158,8 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
Io_mgr._.DeleteFil_args(sqlite.Url()).MissingFails_off().Exec();
file.Cmd_mode_(Db_cmd_mode.Delete);
}
tbl_db.Commit_all(fsys_mgr.Core_provider(), ary);
this.Init_load(fsys_mgr.Core_provider().ConnectInfo());
tbl_db.Commit_all(fsys_mgr.Provider_core(), ary);
this.Init_load(fsys_mgr.Provider_core().ConnectInfo());
}
public static final String Grp_wiki_init = "wiki.init";

View File

@@ -16,7 +16,7 @@ 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.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
public class Xodb_mgr_txt implements Xodb_mgr {
public Xodb_mgr_txt(Xow_wiki wiki, Xow_data_mgr data_mgr) {
this.wiki = wiki;
@@ -28,6 +28,7 @@ public class Xodb_mgr_txt implements Xodb_mgr {
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 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();

View File

@@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.ios.*;
public class Xodb_save_mgr_sql implements Xodb_save_mgr {
public Xodb_save_mgr_sql(Xodb_mgr_sql db_mgr) {
this.db_mgr = db_mgr; zip_mgr = db_mgr.Wiki().App().Zip_mgr();
} Xodb_mgr_sql db_mgr; Io_stream_zip_mgr zip_mgr;
} private Xodb_mgr_sql db_mgr; private Io_stream_zip_mgr zip_mgr;
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next;
@@ -44,8 +44,8 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
int file_idx = fsys_mgr.Tid_text_idx();
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text, text.length);
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(fsys_mgr.Page_provider());
Db_provider text_provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_idx).Provider();
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(fsys_mgr.Provider_page());
Db_provider text_provider = db_mgr.Fsys_mgr().Get_by_idx(file_idx).Provider();
Db_stmt text_stmt = db_mgr.Tbl_text().Insert_stmt(text_provider);
text = zip_mgr.Zip(db_mgr.Data_storage_format(), text);
try {
@@ -72,7 +72,7 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
if (redirect_changed) kv_ary[kv_idx++] = KeyVal_.new_("page_is_redirect", redirect_changed);
if (modified_changed) kv_ary[kv_idx++] = KeyVal_.new_("page_touched", Xto_touched_str(modified));
qry = Db_qry_.update_common_("page", Db_crt_.eq_("page_id", page.Revision_data().Id()), kv_ary);
Db_provider provider = db_mgr.Fsys_mgr().Core_provider();
Db_provider provider = db_mgr.Fsys_mgr().Provider_core();
provider.Txn_mgr().Txn_bgn_if_none();
provider.Exec_qry(qry);
provider.Txn_mgr().Txn_end_all();
@@ -88,12 +88,12 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
, KeyVal_.new_("page_title", String_.new_utf8_(trg_ttl))
);
try {
db_mgr.Fsys_mgr().Core_provider().Exec_qry(qry);
db_mgr.Fsys_mgr().Provider_core().Exec_qry(qry);
} catch (Exception exc) {
if (String_.Has(Err_.Message_gplx_brief(exc), "columns page_namespace, page_random_int are not unique")) { // HACK: terrible hack, but moving pages across ns will break UNIQUE index
db_mgr.Fsys_mgr().Core_provider().Exec_sql("DROP INDEX page__name_random;"); // is UNIQUE by default
db_mgr.Fsys_mgr().Core_provider().Exec_sql("CREATE INDEX page__name_random ON page (page_namespace, page_random_int);");
db_mgr.Fsys_mgr().Core_provider().Exec_qry(qry);
db_mgr.Fsys_mgr().Provider_core().Exec_sql("DROP INDEX page__name_random;"); // is UNIQUE by default
db_mgr.Fsys_mgr().Provider_core().Exec_sql("CREATE INDEX page__name_random ON page (page_namespace, page_random_int);");
db_mgr.Fsys_mgr().Provider_core().Exec_qry(qry);
}
}
}

View File

@@ -16,10 +16,43 @@ 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.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;
}
public int Next_insert_id() {return 0;}
}
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);
}
}

View File

@@ -17,17 +17,20 @@ 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 img_id, byte[] img_src, int img_w, int img_h) {
this.img_id = img_id;
this.img_src = img_src;
this.img_w = img_w;
this.img_h = img_h;
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 Img_id() {return img_id;} private int img_id;
public byte[] Img_src() {return img_src;} private byte[] img_src;
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public void Write_html(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, img_src, img_w, img_h);
} private static final Bry_fmtr fmtr = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
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];
}

View File

@@ -0,0 +1,85 @@
/*
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;
}
}

View File

@@ -0,0 +1,124 @@
/*
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;
}
}

View File

@@ -20,11 +20,11 @@ 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;} private byte[] page_body;
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs;
public Hdump_img_itm[] Img_itms() {return img_itms;} private Hdump_img_itm[] img_itms;
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;

View File

@@ -1,47 +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.pages.*; import gplx.xowa.pages.skins.*;
class Hdump_page_itm_save {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
private Hdump_db_mgr text_db_mgr = new Hdump_db_mgr();
public void Insert(Db_provider provider, Xoa_page page) {
int page_id = page.Revision_data().Id();
Xopg_html_data html_data = page.Html_data();
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_body, Version_id, Bry_.Empty, Bry_.Empty);
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
Insert_sidebars(provider, page_id, page, html_data.Xtn_skin_mgr());
}
private void Insert_if_exists(Db_provider provider, int page_id, int tid, byte[] val) {
if (Bry_.Len_gt_0(val))
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, tid, Version_id, Bry_.Empty, val);
}
private void Insert_sidebars(Db_provider provider, 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(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_sidebar_div, Version_id, Bry_.Empty, tmp_bfr.XtoAryAndClear());
}
}
}
private static final int Version_id = 0;
}

View File

@@ -16,19 +16,22 @@ 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_text_row {
public int Id() {return id;} private int id;
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 Version() {return version;} private int version;
public byte[] Meta() {return meta;} private byte[] meta;
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 int Sub_id() {return sub_id;} public void Sub_id_(int v) {sub_id = v;} private int sub_id;
public Hdump_text_row Init(int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
this.id = id; this.page_id = page_id; this.tid = tid; this.version = version; this.meta = meta; this.data = data;
return this;
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();
}
}
class Hdump_text_row_tid {
public static final int Tid_body = 0, Tid_img = 1, Tid_display_ttl = 2, Tid_content_sub = 3, Tid_sidebar_div = 4;
}

View File

@@ -0,0 +1,21 @@
/*
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_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;
}

View File

@@ -17,23 +17,31 @@ 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.*;
class Hdump_text_tbl {
private Db_stmt stmt_select, stmt_insert;//, stmt_update, stmt_delete;
@gplx.Virtual public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
stmt_insert.Val_int_(id).Val_int_(page_id).Val_int_(tid).Val_int_(version).Val_str_by_bry_(meta).Val_str_by_bry_(data).Exec_insert();
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 Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
@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.Val_int_(page_id).Exec_select();
DataRdr rdr = stmt_select.Clear().Val_int_(page_id).Exec_select();
while(rdr.MoveNextPeer()) {
Hdump_text_row row = new Hdump_text_row().Init
( rdr.ReadInt(Fld_text_id)
, rdr.ReadInt(Fld_page_id)
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_meta)
, rdr.ReadBryByStr(Fld_text_data)
);
rv.Add(row);
@@ -41,28 +49,36 @@ class Hdump_text_tbl {
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_text_id = "text_id", Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_version = "text_version"
, Fld_text_meta = "text_meta", Fld_text_data = "text_data";
private static final String[] Flds_all = new String[] {Fld_text_id, Fld_page_id, Fld_text_tid, Fld_text_version, Fld_text_meta, Fld_text_data};
, 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"
, "( text_id integer NOT NULL PRIMARY KEY"
, ", page_id integer NOT NULL"
, "( page_id integer NOT NULL"
, ", text_tid integer NOT NULL"
, ", text_idx integer NOT NULL"
, ", text_version integer NOT NULL"
, ", text_meta varchar(4000) 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(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
Hdump_text_row row = new Hdump_text_row().Init(id, page_id, tid, version, meta, data);
@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, Db_provider provider, int page_id) {
@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) {
@@ -70,6 +86,7 @@ class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashA
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) {
@@ -78,4 +95,5 @@ class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashA
}
return rv;
}
public static final Db_provider Null_provider = null;
}

View File

@@ -0,0 +1,60 @@
/*
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_";
}

View File

@@ -15,15 +15,12 @@ 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.html; 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();} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
@Test public void Basic() {
// fxt.Test_save("A b c", fxt.itm_text_("A b c"));
}
}
class Hdump_html_mgr_fxt {
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;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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));
}
}

View File

@@ -1,66 +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.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.core.btries.*;
class Hdump_html_fmtr__body implements Bry_fmtr_arg {
private Bry_rdr bry_rdr = new Bry_rdr();
private Hdump_page_itm page;
private Gfo_usr_dlg usr_dlg; private byte[] app_dir = Bry_.Empty;
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {this.usr_dlg = usr_dlg; this.app_dir = app_dir;}
public void Init_by_page(Hdump_page_itm page) {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;
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;
}
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 "."
switch (tid) {
case Tid_app_dir: bfr.Add(app_dir); break;
case Tid_img: pos = Write_img(bfr, page, src, imgs, imgs_len, pos); break;
}
++pos; // + 1 to skip trailing }
}
}
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
}
private int Write_img(Bry_bfr bfr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int idx_bgn) {
int idx_val = bry_rdr.Read_int_to(Byte_ascii.Curly_end);
int idx_end = bry_rdr.Pos();
if (idx_val == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid(src, idx_bgn, idx_end)); return idx_end;}
if (!Int_.Between(idx_val, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), idx_val, imgs_len); return idx_end;}
imgs[idx_val].Write_html(bfr);
return idx_end;
}
private static final byte Tid_app_dir = 0, Tid_img = 1;
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
.Add_str_byte("~{xo.dir" , Tid_app_dir)
.Add_str_byte("~{xo.img." , Tid_img)
;
}

View File

@@ -0,0 +1,94 @@
/*
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)
;
}

View File

@@ -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.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
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;}

View File

@@ -15,13 +15,13 @@ 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.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
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[] app_dir) {body_fmtr.Init_by_app(usr_dlg, app_dir);}
public void Write(Bry_bfr bfr, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
body_fmtr.Init_by_page(page);
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);
}

View File

@@ -0,0 +1,87 @@
/*
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;
}
}

View File

@@ -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.*;
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 {
@@ -26,7 +26,8 @@ class Hdump_load_mgr {
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();
public Hdump_load_mgr(Hdump_db_mgr db_mgr) {this.db_mgr = db_mgr;}
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;
@@ -35,7 +36,8 @@ class Hdump_load_mgr {
}
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.Select_by_page(tmp_text_itms, provider, 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) {
@@ -46,9 +48,9 @@ class Hdump_load_mgr {
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(Io_stream_.Tid_gzip, itm.Data())); break;
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); 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
@@ -57,16 +59,17 @@ class Hdump_load_mgr {
);
}
public void Load_itm_body(Hdump_text_row itm) {
page_version = Bry_.Xto_int(itm.Meta());
page_text = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data());
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.Meta());
int img_id = itm.Sub_id();
byte[] img_src = bry_rdr.Read_bry_to_pipe();
int img_w = bry_rdr.Read_int_to_pipe();
int img_h = bry_rdr.Read_int_to_pipe();
Hdump_img_itm img_itm = new Hdump_img_itm(img_id, img_src, img_w, img_h);
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);
}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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;
}
}

View File

@@ -0,0 +1,62 @@
/*
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());
}
}
}
}

View File

@@ -27,7 +27,7 @@ public class Xodb_text_tbl {
public void Update(int file_id, int page_id, byte[] text) {
Db_stmt stmt = Db_stmt_.Null;
try {
Db_provider provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_id).Provider();
Db_provider provider = db_mgr.Fsys_mgr().Get_by_idx(file_id).Provider();
stmt = Db_stmt_.new_update_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_old_text);
stmt.Val_bry_(text).Val_int_(page_id).Exec_update();
} finally {stmt.Rls();}
@@ -35,7 +35,7 @@ public class Xodb_text_tbl {
public byte[] Select(int file_id, int page_id) {
Db_stmt stmt = Db_stmt_.Null;
try {
Db_provider provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_id).Provider();
Db_provider provider = db_mgr.Fsys_mgr().Get_by_idx(file_id).Provider();
stmt = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_old_text);
byte[] rv = (byte[])stmt.Val_int_(page_id).Exec_select_val();
rv = zip_mgr.Unzip(db_mgr.Data_storage_format(), rv);