mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.1.1
This commit is contained in:
@@ -1,89 +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.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.abrvs.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xohd_hdump_rdr {
|
||||
private final Bry_bfr_mkr bfr_mkr; private final Xow_hzip_mgr hzip_mgr;
|
||||
private final Xohd_abrv_mgr abrv_mgr; private final Xohd_page_html_mgr__load load_mgr;
|
||||
private Xowd_db_mgr core_data_mgr; private final Xowd_page_itm dbpg = new Xowd_page_itm();
|
||||
private final Xow_wiki wiki;
|
||||
public Xohd_hdump_rdr(Xoa_app app, Xow_wiki wiki) {
|
||||
this.bfr_mkr = app.Utl__bfr_mkr(); this.hzip_mgr = wiki.Html__hzip_mgr(); this.wiki = wiki;
|
||||
abrv_mgr = new Xohd_abrv_mgr(app.Usr_dlg(), app.Fsys_mgr(), app.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
load_mgr = new Xohd_page_html_mgr__load(); // TODO: get db_id
|
||||
}
|
||||
public void Init_by_db(Xowd_db_mgr core_data_mgr) {this.core_data_mgr = core_data_mgr;}
|
||||
public void Get_by_ttl(Xoae_page page) {
|
||||
Xog_page hpg = new Xog_page();
|
||||
Get_by_ttl(hpg, page.Ttl());
|
||||
page.Hdump_data().Body_(hpg.Page_body());
|
||||
page.Root_(new Xop_root_tkn());
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
html_data.Display_ttl_(hpg.Display_ttl());
|
||||
html_data.Content_sub_(hpg.Content_sub());
|
||||
html_data.Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_stub(hpg.Sidebar_div()));
|
||||
Load_module_mgr(html_data.Head_mgr(), hpg);
|
||||
for (gplx.xowa.htmls.hdumps.core.Xohd_data_itm__base itm : hpg.Img_itms())
|
||||
page.Hdump_data().Imgs_add(itm);
|
||||
}
|
||||
public void Get_by_ttl(Xog_page rv, Xoa_ttl ttl) {
|
||||
synchronized (dbpg) {
|
||||
dbpg.Clear();
|
||||
if ( !Get_by_ttl__fill_hpg(rv, ttl)
|
||||
|| rv.Page_body() == null) { // occurs when row exists in page_table, but not in html_table
|
||||
rv.Exists_n_();
|
||||
return;
|
||||
}
|
||||
Bry_bfr bfr = bfr_mkr.Get_m001();
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.abrv: ttl=~{0}", ttl.Full_db_as_str());
|
||||
byte[] body_bry = abrv_mgr.Parse(bfr, rv);
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.hzip: ttl=~{0}", ttl.Full_db_as_str());
|
||||
body_bry = hzip_mgr.Parse(bfr, ttl.Page_db(), body_bry, rv.Redlink_uids());
|
||||
bfr.Mkr_rls();
|
||||
rv.Page_body_(body_bry);
|
||||
}
|
||||
}
|
||||
private boolean Get_by_ttl__fill_hpg(Xog_page rv, Xoa_ttl ttl) {
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.meta: ttl=~{0}", ttl.Full_db_as_str());
|
||||
core_data_mgr.Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db()); // get rows from db
|
||||
if (dbpg.Redirect_id() != -1) Get_by_ttl__resolve_redirect(dbpg, rv);
|
||||
if (dbpg.Html_db_id() == -1) return false; // dbpg does not hdump; exit;
|
||||
rv.Init(wiki, dbpg.Id(), null, ttl); // FIXME
|
||||
Xowd_db_file html_db = core_data_mgr.Dbs__get_at(dbpg.Html_db_id());
|
||||
load_mgr.Load_page(wiki, rv, html_db.Tbl__html(), dbpg.Id(), ttl);
|
||||
return true;
|
||||
}
|
||||
private void Get_by_ttl__resolve_redirect(Xowd_page_itm dbpg, Xog_page hpg) {
|
||||
int redirect_count = 0;
|
||||
while (redirect_count < 5) {
|
||||
int redirect_id = dbpg.Redirect_id();
|
||||
core_data_mgr.Tbl__page().Select_by_id(dbpg, redirect_id);
|
||||
if (redirect_id == -1) break;
|
||||
}
|
||||
}
|
||||
public static void Load_module_mgr(Xoh_head_mgr page_module_mgr, Xog_page hpg) {
|
||||
Xopg_module_mgr dump_module_mgr = hpg.Head_mgr();
|
||||
page_module_mgr.Itm__mathjax().Enabled_ (dump_module_mgr.Math_exists());
|
||||
page_module_mgr.Itm__popups().Bind_hover_area_ (dump_module_mgr.Imap_exists());
|
||||
page_module_mgr.Itm__gallery().Enabled_ (dump_module_mgr.Gallery_packed_exists());
|
||||
page_module_mgr.Itm__hiero().Enabled_ (dump_module_mgr.Hiero_exists());
|
||||
}
|
||||
}
|
||||
@@ -1,63 +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.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.abrvs.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.dbs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
public class Xohd_hdump_wtr {
|
||||
private final Bry_bfr_mkr bfr_mkr; private final Xoh_page_wtr_mgr page_wtr_mgr;
|
||||
private final Xohd_page_html_mgr__save save_mgr; private Xowd_db_mgr core_data_mgr;
|
||||
public Xohd_hdump_wtr(Xoa_app app, Xowe_wiki wiki) {
|
||||
this.bfr_mkr = app.Utl__bfr_mkr(); this.page_wtr_mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
save_mgr = new Xohd_page_html_mgr__save();
|
||||
}
|
||||
public void Init_by_db(Xowd_db_mgr core_data_mgr) {
|
||||
this.core_data_mgr = core_data_mgr;
|
||||
}
|
||||
public void Save(Xoae_page page) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_m001();
|
||||
Generate_hdump(tmp_bfr, page);
|
||||
int html_db_id = page.Revision_data().Html_db_id();
|
||||
Xowd_db_file hdump_db = Xowd_db_file.Null;
|
||||
if (html_db_id == -1) {
|
||||
hdump_db = core_data_mgr.Db__html();
|
||||
if (hdump_db == null) {
|
||||
hdump_db = core_data_mgr.Dbs__make_by_tid(Xowd_db_file_.Tid_html_data);
|
||||
Xowd_html_tbl tbl = hdump_db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
}
|
||||
|
||||
html_db_id = hdump_db.Id();
|
||||
page.Revision_data().Html_db_id_(html_db_id);
|
||||
core_data_mgr.Tbl__page().Update__html_db_id(page.Revision_data().Id(), html_db_id);
|
||||
}
|
||||
else {
|
||||
hdump_db = core_data_mgr.Dbs__get_at(html_db_id);
|
||||
html_db_id = hdump_db.Id();
|
||||
// return; // DELETE: don't remember why return was here; DATE:2015-06-06
|
||||
}
|
||||
save_mgr.Update(tmp_bfr, hdump_db.Tbl__html(), page);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
public void Generate_hdump(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
page_wtr_mgr.Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
if (!Env_.Mode_testing()) page.Wikie().Html_mgr().Hzip_mgr().Write(tmp_bfr, new Xodump_stats_itm(), page.Url().To_bry_full_wo_qargs(), tmp_bfr.To_bry_and_clear()); // hzip data;
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
@@ -1,159 +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.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.xtns.hieros.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xohd_hdump_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xohd_hdump_wtr_fxt fxt = new Xohd_hdump_wtr_fxt();
|
||||
// @Test public void Image_full() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
|
||||
// fxt.Test_write_all
|
||||
// ( "[[File:A.png|test_caption]]"
|
||||
// , "<a xtid='a_img_full' xatrs='1|0|0||0|test_caption'/>"
|
||||
// );
|
||||
// }
|
||||
@Test public void Image_thumb() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.N, Xof_ext_.Id_png));
|
||||
// fxt.Test_write_all
|
||||
// ( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
}
|
||||
@Test public void Audio_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
|
||||
fxt.Test_write_all
|
||||
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
, " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
|
||||
fxt.Test_write_all
|
||||
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
, " <div id=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div><xowa_play id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Hiero() {
|
||||
Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
|
||||
hiero_fxt.Reset();
|
||||
hiero_fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
|
||||
}
|
||||
@Test public void Gallery() {
|
||||
Gallery_mgr_base.File_found_mode = Bool_.__byte;
|
||||
fxt.Test_write_all
|
||||
( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
|
||||
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
|
||||
, " <div xowa_gly_box_w='0'>"
|
||||
, " <div class=\"thumb\" style=\"width: 150px;\">"
|
||||
, " <div xowa_gly_img_pad='0'>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class=\"gallerytext\"><p>A1"
|
||||
, "</p>"
|
||||
, ""
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xodb_hdump_mgr__base_fxt {
|
||||
protected Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
protected Xowe_wiki wiki; protected Xoae_page page;
|
||||
private Xohd_hdump_wtr hdump_wtr;
|
||||
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.Parser_mgr().Ctx().Cur_page();
|
||||
hdump_wtr = new Xohd_hdump_wtr(fxt.App(), fxt.Wiki());
|
||||
}
|
||||
fxt.Reset();
|
||||
page.Revision_data().Id_(0);
|
||||
this.Clear_end();
|
||||
}
|
||||
@gplx.Virtual public void Clear_end() {}
|
||||
@gplx.Virtual public void Exec_write(String raw) {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
page.Root_(root);
|
||||
hdump_wtr.Generate_hdump(bfr, page);
|
||||
}
|
||||
public Xohd_data_itm__base Make_xfer(String lnki_ttl, int html_uid, int html_w, int html_h, boolean file_is_orig, int file_ext_id) {
|
||||
return new Xohd_data_itm__img().Data_init_base
|
||||
(Bry_.new_u8(lnki_ttl), Byte_.Zero, Xof_img_size.Upright_null, 0, 0, Xof_lnki_time.Null, Xof_lnki_page.Null, Xohd_data_itm__base.File_repo_id_null, file_ext_id, file_is_orig, html_w, html_uid, html_w, html_h);
|
||||
}
|
||||
}
|
||||
class Xohd_hdump_wtr_fxt extends Xodb_hdump_mgr__base_fxt {
|
||||
private List_adp expd_itms_xfers = List_adp_.new_();
|
||||
@Override public void Clear_end() {expd_itms_xfers.Clear();}
|
||||
public void Expd_itms_xfers(Xohd_data_itm__base... itms) {expd_itms_xfers.Add_many((Object[])itms);}
|
||||
public void Test_write_all (String raw, String expd_html) {Test_write(Bool_.N, raw, expd_html);}
|
||||
public void Test_write_frag(String raw, String expd_frag) {Test_write(Bool_.Y, raw, expd_frag);}
|
||||
public void Test_write(boolean frag, String raw, String expd_html) {
|
||||
this.Exec_write(raw);
|
||||
String actl_html = String_.new_u8(page.Hdump_data().Body());
|
||||
if (frag)
|
||||
Tfds.Eq_true(String_.Has(actl_html, expd_html), actl_html);
|
||||
else
|
||||
Tfds.Eq_str_lines(expd_html, actl_html);
|
||||
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(List_adp list) {
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_data_itm__base itm = (Xohd_data_itm__base)list.Get_at(i);
|
||||
rv[i] = itm.Data_print();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xohd_abrv_ {
|
||||
public static final byte
|
||||
Tid_dir = 1, Tid_img = 2, Tid_img_style = 3, Tid_file_play = 4, Tid_file_info = 5, Tid_file_mgnf = 6
|
||||
, Tid_hiero_dir = 7, Tid_gallery_box_max = 8, Tid_gallery_box_w = 9, Tid_gallery_img_w = 10, Tid_gallery_img_pad = 11
|
||||
, Tid_redlink = 12, Tid_toc = 13, Tid_hdr_bgn = 14, Tid_hdr_end = 15
|
||||
;
|
||||
public static final byte[]
|
||||
Key_dir = Bry_.new_a7("~{xowa_dir}")
|
||||
, Key_img = Bry_.new_a7("xowa_img='")
|
||||
, Key_img_style = Bry_.new_a7("xowa_img_style='")
|
||||
, Key_file_play = Bry_.new_a7("<xowa_play id='")
|
||||
, Key_file_info = Bry_.new_a7("<xowa_info id='")
|
||||
, Key_file_mgnf = Bry_.new_a7("<xowa_mgnf id='")
|
||||
, Key_hiero_dir = Bry_.new_a7("~{xowa_hiero_dir}")
|
||||
, Key_gallery_box_max = Bry_.new_a7("xowa_gly_box_max='")
|
||||
, Key_gallery_box_w = Bry_.new_a7("xowa_gly_box_w='")
|
||||
, Key_gallery_img_w = Bry_.new_a7("xowa_gly_img_w='")
|
||||
, Key_gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
|
||||
, Key_redlink = Bry_.new_a7("xowa_redlink='")
|
||||
, Key_toc = Bry_.new_a7("~{xowa_toc}")
|
||||
, Key_hdr_bgn = Bry_.new_a7("<h")
|
||||
, Key_hdr_end = Bry_.new_a7("</h")
|
||||
;
|
||||
public static final byte[]
|
||||
A_href_bgn = Bry_.new_a7("/wiki/File:")
|
||||
, Bry_img_style_bgn = Bry_.new_a7("style='width:")
|
||||
, Bry_img_style_end = Bry_.new_a7("px;'")
|
||||
, Html_redlink_bgn = Bry_.Add(Bry_.new_a7("\" "), Key_redlink)
|
||||
, Html_redlink_end = Bry_.new_a7("'>")
|
||||
;
|
||||
public static Btrie_slim_mgr new_trie() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
|
||||
trie_itm(rv, Tid_dir , Byte_ascii.Null , Key_dir);
|
||||
trie_itm(rv, Tid_img , Byte_ascii.Apos , Key_img);
|
||||
trie_itm(rv, Tid_img_style , Byte_ascii.Apos , Key_img_style);
|
||||
trie_itm(rv, Tid_file_play , Byte_ascii.Apos , Key_file_play);
|
||||
trie_itm(rv, Tid_file_info , Byte_ascii.Apos , Key_file_info);
|
||||
trie_itm(rv, Tid_file_mgnf , Byte_ascii.Apos , Key_file_mgnf);
|
||||
trie_itm(rv, Tid_hiero_dir , Byte_ascii.Null , Key_hiero_dir);
|
||||
trie_itm(rv, Tid_gallery_box_max , Byte_ascii.Apos , Key_gallery_box_max);
|
||||
trie_itm(rv, Tid_gallery_box_w , Byte_ascii.Apos , Key_gallery_box_w);
|
||||
trie_itm(rv, Tid_gallery_img_w , Byte_ascii.Apos , Key_gallery_img_w);
|
||||
trie_itm(rv, Tid_gallery_img_pad , Byte_ascii.Apos , Key_gallery_img_pad);
|
||||
trie_itm(rv, Tid_redlink , Byte_ascii.Apos , Key_redlink);
|
||||
trie_itm(rv, Tid_toc , Byte_ascii.Null , Key_toc);
|
||||
// trie_itm(rv, Tid_hdr_bgn , Byte_ascii.Null , Key_hdr_bgn);
|
||||
// trie_itm(rv, Tid_hdr_end , Byte_ascii.Null , Key_hdr_end);
|
||||
return rv;
|
||||
}
|
||||
private static void trie_itm(Btrie_slim_mgr trie, byte tid, byte subst_end_byte, byte[] key_bry) {
|
||||
boolean elem_is_xnde = key_bry[0] == Byte_ascii.Lt;
|
||||
Hdump_html_fmtr_itm itm = new Hdump_html_fmtr_itm(tid, elem_is_xnde, subst_end_byte, key_bry);
|
||||
trie.Add_obj(key_bry, itm);
|
||||
}
|
||||
}
|
||||
@@ -1,162 +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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.lnkis.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_abrv_mgr {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Bry_rdr bry_rdr = new Bry_rdr(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private Xoh_cfg_file cfg_file; private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
|
||||
private byte[] root_dir, file_dir, file_dir_comm, file_dir_wiki, hiero_img_dir;
|
||||
private byte[] wiki_domain;
|
||||
private final Xohd_abrv_wkr__hdr wkr__hdr = new Xohd_abrv_wkr__hdr();
|
||||
public Xohd_abrv_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.file_dir = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.hiero_img_dir = gplx.xowa.xtns.hieros.Hiero_xtn_mgr.Hiero_root_dir(fsys_mgr).GenSubDir("img").To_http_file_bry();
|
||||
this.cfg_file = new Xoh_cfg_file(fsys_encoder, fsys_mgr.Bin_xowa_dir());
|
||||
this.html_fmtr = Xoh_file_html_fmtr__hdump.Base;
|
||||
this.wiki_domain = wiki_domain;
|
||||
}
|
||||
private void Init() {
|
||||
file_dir_comm = tmp_bfr.Add(file_dir).Add(Xow_domain_itm_.Bry__commons).Add_byte_slash().To_bry_and_clear();
|
||||
file_dir_wiki = tmp_bfr.Add(file_dir).Add(wiki_domain).Add_byte_slash().To_bry_and_clear();
|
||||
}
|
||||
public byte[] Parse(Bry_bfr rv, Xog_page hpg) {
|
||||
this.Init();
|
||||
byte[] src = hpg.Page_body(); int len = src.length;
|
||||
Xohd_data_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
|
||||
bry_rdr.Init(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) { // regular char; set bgn and move to next char
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else { // special tkn
|
||||
if (rng_bgn != -1) { // pending rng exists; add it
|
||||
rv.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
pos = trie.Match_pos(); // position after match; EX: "xowa_img='" positions after "'"
|
||||
Hdump_html_fmtr_itm itm = (Hdump_html_fmtr_itm)o;
|
||||
pos = Write_data(rv, html_fmtr, hpg, src, imgs, imgs_len, pos, itm); // note no +1; Write_data return pos after }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) rv.Add_mid(src, rng_bgn, len);
|
||||
return rv.To_bry_and_clear();
|
||||
}
|
||||
private int Write_data(Bry_bfr bfr, Xoh_file_html_fmtr__base fmtr, Xog_page hpg, byte[] src, Xohd_data_itm__base[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) {
|
||||
bry_rdr.Pos_(uid_bgn);
|
||||
int uid = itm.Subst_end_byte() == Byte_ascii.Null ? -1 : bry_rdr.Read_int_to(itm.Subst_end_byte());
|
||||
int uid_end = bry_rdr.Pos(); // set uid_end after subst_end
|
||||
int rv = uid_end;
|
||||
byte tid = itm.Tid();
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_dir: bfr.Add(root_dir); return rv;
|
||||
case Xohd_abrv_.Tid_hiero_dir: bfr.Add(hiero_img_dir); return rv;
|
||||
case Xohd_abrv_.Tid_redlink: return Write_redlink(bfr, hpg, uid, rv);
|
||||
case Xohd_abrv_.Tid_hdr_bgn: return wkr__hdr.Write_bgn(bfr, hpg, uid, rv);
|
||||
case Xohd_abrv_.Tid_hdr_end: return wkr__hdr.Write_end(bfr, hpg, uid, rv);
|
||||
}
|
||||
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().To_str(), 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; hpg=~{0} idx=~{1} len=~{2}", hpg.Url().To_str(), uid, imgs_len); return uid_end;}
|
||||
if (uid >= imgs.length) return rv;
|
||||
Xohd_data_itm__base img = imgs[uid];
|
||||
int img_view_w = img.Html_w();
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_img_style:
|
||||
bfr.Add(Xohd_abrv_.Bry_img_style_bgn);
|
||||
bfr.Add_int_variable(img_view_w);
|
||||
bfr.Add(Xohd_abrv_.Bry_img_style_end);
|
||||
return rv;
|
||||
}
|
||||
byte[] a_title = img.Lnki_ttl();
|
||||
byte[] a_href = Bry_.Add(Xohd_abrv_.A_href_bgn, a_title);
|
||||
try {
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, cfg_file.Img_media_info_btn()); return rv;
|
||||
case Xohd_abrv_.Tid_file_mgnf: fmtr.Html_thumb_part_magnify (bfr, uid, a_href, a_title, cfg_file.Img_thumb_magnify()); return rv;
|
||||
case Xohd_abrv_.Tid_file_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, cfg_file.Img_media_play_btn()); return rv;
|
||||
case Xohd_abrv_.Tid_gallery_box_max: {
|
||||
Xohd_data_itm__gallery_mgr gly = (Xohd_data_itm__gallery_mgr)hpg.Gallery_itms().Get_by(uid);
|
||||
if (gly != null) { // -1 means no box_max
|
||||
byte[] style = Gallery_mgr_base.box_style_max_width_fmtr.Bld_bry_many(tmp_bfr, gly.Box_max());
|
||||
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
case Xohd_abrv_.Tid_gallery_box_w: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)img;
|
||||
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
|
||||
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
|
||||
return rv;
|
||||
}
|
||||
case Xohd_abrv_.Tid_gallery_img_w: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)img;
|
||||
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
|
||||
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
|
||||
return rv;
|
||||
}
|
||||
case Xohd_abrv_.Tid_gallery_img_pad: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)img;
|
||||
byte[] style = Gallery_mgr_base.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
|
||||
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
url_bldr.Init_by_root(img.Orig_repo_id() == Xof_repo_itm_.Repo_remote ? file_dir_comm : file_dir_wiki, Byte_ascii.Slash, false, false, 2);
|
||||
url_bldr.Init_by_itm(img.File_is_orig() ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, img.Lnki_ttl(), Xof_file_wkr_.Md5(img.Lnki_ttl()), Xof_ext_.new_by_id_(img.Orig_ext()), img.File_w(), img.Lnki_time(), img.Lnki_page());
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
if (tid == Xohd_abrv_.Tid_img) {
|
||||
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.Html_h());
|
||||
}
|
||||
} catch (Exception e) {Xoa_app_.Usr_dlg().Warn_many("", "", "abrv.read: page=~{0} itm=~{1} err=~{2}", hpg.Url_bry_safe(), img == null ? "<NULL>" : img.Data_print(), Err_.Message_gplx_full(e));}
|
||||
return rv;
|
||||
}
|
||||
private int Write_redlink(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
if (hpg.Redlink_uids().Has(redlink_key.Val_(uid)))
|
||||
bfr.Add(Xoh_redlink_utl.Cls_bry);
|
||||
else
|
||||
bfr.Del_by_1();
|
||||
return rv;
|
||||
} private final Int_obj_ref redlink_key = Int_obj_ref.neg1_();
|
||||
public static final Bry_fmtr fmtr_img = Bry_fmtr.new_("src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
|
||||
private static final Btrie_slim_mgr trie = Xohd_abrv_.new_trie();
|
||||
}
|
||||
class Hdump_html_fmtr_itm {
|
||||
public Hdump_html_fmtr_itm(byte tid, boolean elem_is_xnde, byte subst_end_byte, byte[] key) {this.tid = tid; this.key = key; this.elem_is_xnde = elem_is_xnde; this.subst_end_byte = subst_end_byte;}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public boolean Elem_is_xnde() {return elem_is_xnde;} private final boolean elem_is_xnde;
|
||||
public byte Subst_end_byte() {return subst_end_byte;} private final byte subst_end_byte;
|
||||
}
|
||||
class Xohd_abrv_wkr__hdr {
|
||||
public int Write_bgn(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
return rv;
|
||||
}
|
||||
public int Write_end(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_abrv_mgr_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_data_img_basic("A.png", 0, 220, 110);
|
||||
} private final Xohd_abrv_mgr_fxt fxt = new Xohd_abrv_mgr_fxt();
|
||||
@Test public void Img() {
|
||||
fxt .Init_body("<img xowa_img='0' />")
|
||||
.Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
|
||||
}
|
||||
@Test public void Img_style() {
|
||||
fxt .Init_body("<div xowa_img_style='0'>")
|
||||
.Test_html("<div style='width:220px;'>");
|
||||
}
|
||||
@Test public void File_info() {
|
||||
fxt .Init_body("<xowa_info id='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/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_mgnf() {
|
||||
fxt .Init_body("<xowa_mgnf id='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/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_play() {
|
||||
fxt .Init_body("<xowa_play id='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/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Hiero_dir() {
|
||||
fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
|
||||
.Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
|
||||
}
|
||||
@Test public void Gallery() {
|
||||
fxt.Clear_imgs();
|
||||
fxt .Init_data_gly(0, 800);
|
||||
fxt .Init_data_img_gly("A.png", 0, 220, 110, 155, 150, 15);
|
||||
fxt .Init_body(String_.Concat_lines_nl_skip_last
|
||||
( "<ul xowa_gly_box_max='0'>"
|
||||
, " <li class='gallerybox' xowa_gly_box_w='0'>"
|
||||
, " <div xowa_gly_box_w='0'>"
|
||||
, " <div class='thumb' xowa_gly_img_w='0'>"
|
||||
, " <div xowa_gly_img_pad='0'>"
|
||||
))
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( "<ul style=\"max-width:800px;_width:800px;\">"
|
||||
, " <li class='gallerybox' style=\"width:155px;\">"
|
||||
, " <div style=\"width:155px;\">"
|
||||
, " <div class='thumb' style=\"width:150px;\">"
|
||||
, " <div style=\"margin:15px auto;\">"
|
||||
));
|
||||
}
|
||||
@Test public void Redlink() {
|
||||
fxt .Init_data_redlink(1, 2);
|
||||
fxt .Init_body(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/A\" xowa_redlink='1'>A</a>"
|
||||
, "<a href=\"/wiki/B\" xowa_redlink='2'>B</a>"
|
||||
, "<a href=\"/wiki/C\" xowa_redlink='3'>C</a>"
|
||||
))
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/A\" class='new'>A</a>"
|
||||
, "<a href=\"/wiki/B\" class='new'>B</a>"
|
||||
, "<a href=\"/wiki/C\">C</a>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xohd_abrv_mgr_fxt {
|
||||
private Xohd_abrv_mgr abrv_mgr;
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private List_adp img_list = List_adp_.new_();
|
||||
private Xowe_wiki wiki;
|
||||
public Xog_page Hpg() {return hpg;} private Xog_page hpg = new Xog_page();
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
abrv_mgr = new Xohd_abrv_mgr(Gfo_usr_dlg_.Instance, app.Fsys_mgr(), app.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
}
|
||||
public void Clear_imgs() {img_list.Clear();}
|
||||
public Xohd_abrv_mgr_fxt Init_body(String body) {hpg.Page_body_(Bry_.new_u8(body)); return this;}
|
||||
public Xohd_abrv_mgr_fxt Init_data_gly(int uid, int box_max) {hpg.Gallery_itms().Add(uid, new Xohd_data_itm__gallery_mgr(uid, box_max)); return this;}
|
||||
public Xohd_abrv_mgr_fxt Init_data_img_basic(String ttl, int html_uid, int html_w, int html_h) {
|
||||
Xohd_data_itm__img img = new Xohd_data_itm__img();
|
||||
img.Data_init_base(Bry_.new_u8(ttl), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null
|
||||
, Xof_lnki_time.Null, Xof_lnki_page.Null
|
||||
, Xohd_data_itm__base.File_repo_id_commons, Xof_ext_.Id_png, Bool_.N, html_w
|
||||
, html_uid, html_w, html_h
|
||||
);
|
||||
img_list.Add(img);
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Init_data_img_gly(String ttl, int html_uid, int html_w, int html_h, int box_w, int img_w, int img_pad) {
|
||||
Xohd_data_itm__gallery_itm img = new Xohd_data_itm__gallery_itm();
|
||||
img.Data_init_gallery(box_w, img_w, img_pad);
|
||||
img.Data_init_base(Bry_.new_u8(ttl), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null
|
||||
, Xof_lnki_time.Null, Xof_lnki_page.Null
|
||||
, Xohd_data_itm__base.File_repo_id_commons, Xof_ext_.Id_png, Bool_.N, html_w
|
||||
, html_uid, html_w, html_h
|
||||
);
|
||||
img_list.Add(img);
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Init_data_redlink(int... uids) {
|
||||
int uids_len = uids.length;
|
||||
for (int i = 0; i < uids_len; ++i) {
|
||||
Int_obj_ref redlink_uid = Int_obj_ref.new_(uids[i]);
|
||||
hpg.Redlink_uids().Add(redlink_uid, redlink_uid);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Test_html(String expd) {
|
||||
if (img_list.Count() > 0) hpg.Img_itms_((Xohd_data_itm__base[])img_list.To_ary_and_clear(Xohd_data_itm__base.class));
|
||||
byte[] actl = abrv_mgr.Parse(bfr, hpg);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.guis.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
public class Xob_hdump_bldr {
|
||||
private final Xowd_db_mgr wiki_db_mgr; private final Xob_ns_to_db_mgr ns_to_db_mgr; int prv_row_len = 0;
|
||||
private final Xodump_stats_itm stats_itm = new Xodump_stats_itm(); private final Xodump_stats_tbl stats_tbl;
|
||||
private final Xog_page tmp_hpg = new Xog_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
private final Xohd_page_html_mgr__save hdump_save_mgr = new Xohd_page_html_mgr__save();
|
||||
private final boolean hzip_enabled;
|
||||
public Xob_hdump_bldr(Xow_ns_mgr ns_mgr, Xodb_mgr_sql db_mgr, Db_conn make_conn, long hdump_db_max, boolean hzip_enabled) {
|
||||
this.wiki_db_mgr = db_mgr.Core_data_mgr();
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(wiki_db_mgr.Db__core()), wiki_db_mgr, hdump_db_max);
|
||||
this.stats_tbl = new Xodump_stats_tbl(make_conn);
|
||||
Xob_ns_file_itm.Init_ns_bldr_data(Xowd_db_file_.Tid_html_data, ns_mgr, gplx.xowa.apps.apis.xowa.bldrs.imports.Xoapi_import.Ns_file_map__each);
|
||||
this.hzip_enabled = hzip_enabled;
|
||||
}
|
||||
public void Bld_term() {
|
||||
this.Commit();
|
||||
Db_term();
|
||||
}
|
||||
public void Insert_page(Xoae_page page) {
|
||||
Hzip_data(page);
|
||||
tmp_hpg.Ctor_from_page(tmp_bfr, page);
|
||||
Xowd_db_file db_file = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len);
|
||||
this.prv_row_len = hdump_save_mgr.Insert(tmp_bfr, db_file.Tbl__html(), tmp_hpg, page.Hdump_data());
|
||||
stats_tbl.Insert(tmp_hpg, stats_itm, page.Root().Root_src().length, tmp_hpg.Page_body().length, prv_row_len);
|
||||
}
|
||||
public void Commit() {
|
||||
ns_to_db_mgr.Commit();
|
||||
// wiki_db_mgr.Tbl__cfg().Update_long(Cfg_grp_hdump_make, Cfg_itm_hdump_size, hdump_db_size); // update cfg; should happen after commit entries
|
||||
}
|
||||
private void Db_term() {
|
||||
ns_to_db_mgr.Rls_all();
|
||||
}
|
||||
// private static final String Cfg_grp_hdump_make = "hdump.make", Cfg_itm_hdump_size = "hdump.size";
|
||||
private void Hzip_data(Xoae_page page) {
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
Xow_hzip_mgr hzip_mgr = wiki.Html_mgr().Hzip_mgr();
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // write to html again, except in hdump mode
|
||||
if (hzip_enabled) hzip_mgr.Write(tmp_bfr, stats_itm, page.Url().To_bry_full_wo_qargs(), tmp_bfr.To_bry_and_clear()); // hzip data
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
private final Xowd_db_file page_db;
|
||||
public Xob_ns_to_db_wkr__html(Xowd_db_file page_db) {this.page_db = page_db;}
|
||||
public byte Db_tid() {return Xowd_db_file_.Tid_html_data;}
|
||||
public void Tbl_init(Xowd_db_file db) {
|
||||
Xowd_html_tbl tbl = db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Tbl_term(Xowd_db_file db) {
|
||||
db.Tbl__text().Insert_end();
|
||||
Db_conn db_conn = db.Conn();
|
||||
db.Tbl__html().Create_idx();
|
||||
Db_attach_cmd.new_(page_db.Conn(), "html_db", db.Url())
|
||||
.Add_fmt("hdump.update page.html_db_id", Sql_update_page_html_db_id, db.Id())
|
||||
.Exec();
|
||||
db_conn.Rls_conn();
|
||||
}
|
||||
private static final String Sql_update_page_html_db_id = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id)"
|
||||
, "SELECT p.page_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", p.page_is_redirect"
|
||||
, ", p.page_touched"
|
||||
, ", p.page_len"
|
||||
, ", p.page_random_int"
|
||||
, ", p.page_text_db_id"
|
||||
, ", {0}"
|
||||
, ", p.page_redirect_id"
|
||||
, "FROM page p"
|
||||
, " JOIN <attach_db>html h ON p.page_id = h.page_id"
|
||||
);
|
||||
}
|
||||
@@ -1,117 +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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.hdumps.core.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.guis.*;
|
||||
class Xob_hdump_img_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private Xowd_html_tbl html_tbl;
|
||||
public Xob_hdump_img_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Key_const;} public static final String Key_const = "hdump.make.imgs";
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_run() {Exec_main();}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
private void Exec_main() {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
Db_conn conn = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
|
||||
Db_rdr rdr = conn.Stmt_new(gplx.dbs.qrys.Db_qry_sql.rdr_(Sql_select)).Exec_select__rls_auto();
|
||||
html_tbl = new Xowd_html_tbl(conn, wiki.Db_mgr_as_sql().Core_data_mgr().Props().Zip_tid_text());
|
||||
int cur_page_id = -1;
|
||||
while (rdr.Move_next()) {
|
||||
int lnki_page_id = rdr.Read_int("lnki_page_id");
|
||||
if (lnki_page_id != cur_page_id) {
|
||||
Save(cur_page_id, bfr.To_bry_and_clear());
|
||||
cur_page_id = lnki_page_id;
|
||||
}
|
||||
// int html_uid = rdr.Read_int(1);
|
||||
// byte[] lnki_ttl = rdr.Read_bry(2);
|
||||
// int html_w = rdr.Read_int(3);
|
||||
// int html_h = rdr.Read_int(4);
|
||||
// int file_repo_id = rdr.Read_int(5);
|
||||
// int file_ext_id = rdr.Read_int(6);
|
||||
// boolean file_is_orig = rdr.Read_int(7) == 1;
|
||||
// double file_time = rdr.Read_double(8);
|
||||
// int file_page = rdr.Read_int(9);
|
||||
// Xohd_data_itm__base.Data_write_static(bfr, 0, lnki_ttl, Byte_.Zero, 0, 0, Xof_img_size.Upright_null, html_uid, html_w, html_h, file_repo_id, file_ext_id, file_is_orig, html_w, file_time, file_page);
|
||||
}
|
||||
Save(cur_page_id, bfr.To_bry_and_clear());;
|
||||
}
|
||||
private void Save(int page_id, byte[] data) {
|
||||
if (page_id == -1 || data.length == 0) return;
|
||||
html_tbl.Insert(page_id, Xohd_data_tid.Tid_img, data);
|
||||
}
|
||||
private static final String Sql_select = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT lt.lnki_page_id"
|
||||
, ", lt.html_uid"
|
||||
, ", lt.lnki_ttl"
|
||||
, ", xr.file_w"
|
||||
, ", xr.file_h"
|
||||
, ", xr.orig_repo"
|
||||
, ", xr.lnki_ext"
|
||||
, ", xr.file_is_orig"
|
||||
, ", xr.lnki_time"
|
||||
, ", xr.lnki_page"
|
||||
, "FROM xfer_regy xr"
|
||||
, " JOIN lnki_temp lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
// , " LEFT JOIN xtn_gallery lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
// , " LEFT JOIN xtn_imap lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
, "ORDER BY "
|
||||
, " lt.lnki_page_id"
|
||||
, ", lt.lnki_uid"
|
||||
);
|
||||
}
|
||||
interface Page_async_cmd {
|
||||
void Prep();
|
||||
void Exec();
|
||||
}
|
||||
class Page_async_cmd__img implements Page_async_cmd {
|
||||
private Xog_page hpg;
|
||||
private List_adp missing = List_adp_.new_();
|
||||
public Page_async_cmd__img(Xog_page hpg) {this.hpg = hpg;}
|
||||
public void Prep() {
|
||||
int len = hpg.Img_count();
|
||||
Xohd_data_itm__base[] ary = hpg.Img_itms();
|
||||
missing.Clear();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_data_itm__base itm = ary[i];
|
||||
boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
|
||||
if (!exists) missing.Add(itm);
|
||||
}
|
||||
}
|
||||
public void Exec() {
|
||||
int len = missing.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// Xohd_data_itm__base itm = (Xohd_data_itm__base)missing.Get_at(i);
|
||||
// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
|
||||
// Write file(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
CREATE TABLE xtn_gallery
|
||||
( src_page_id integer NOT NULL
|
||||
, html_uid integer NOT NULL
|
||||
, box_max integer NOT NULL
|
||||
, box_w integer NOT NULL
|
||||
, img_w integer NOT NULL
|
||||
, img_pad integer NOT NULL
|
||||
);
|
||||
*/
|
||||
@@ -1,56 +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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.dbs.*;
|
||||
public class Xob_link_dump_cmd {
|
||||
private Xob_link_dump_tbl tbl; private int src_page_id; private Io_url page_db_url;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
this.page_db_url = wiki.Data__core_mgr().Db__core().Url();
|
||||
this.tbl = Xob_link_dump_tbl.Get_or_new(wiki);
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Page_bgn(int src_page_id) {this.src_page_id = src_page_id;}
|
||||
public void Add(int src_html_uid, int trg_ns_id, byte[] trg_ttl) {tbl.Insert_cmd_by_batch(src_page_id, src_html_uid, trg_ns_id, trg_ttl);}
|
||||
public void Wkr_commit() {tbl.Conn().Txn_sav();}
|
||||
public void Wkr_end() {
|
||||
try {
|
||||
tbl.Insert_end();
|
||||
tbl.Create_idx_1();
|
||||
Db_conn conn = tbl.Conn();
|
||||
Db_attach_cmd.new_(conn, "page_db", page_db_url)
|
||||
.Add_fmt("update trg_page_id", String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO link_dump"
|
||||
, "SELECT r.uid"
|
||||
, ", r.src_page_id"
|
||||
, ", r.src_html_uid"
|
||||
, ", Coalesce(p.page_id, -1)"
|
||||
, ", r.trg_ns"
|
||||
, ", r.trg_ttl"
|
||||
, "FROM link_dump r"
|
||||
, " LEFT JOIN page_db.page p ON r.trg_ns = p.page_namespace AND r.trg_ttl = p.page_title"
|
||||
, ";"
|
||||
))
|
||||
.Exec();
|
||||
conn.Exec_sql("UPDATE link_dump SET trg_ns = -1 AND trg_ttl = '' WHERE trg_page_id != -1;");
|
||||
tbl.Create_idx_2();
|
||||
conn.Env_vacuum();
|
||||
} catch (Exception e) {
|
||||
Tfds.Write(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*;
|
||||
class Xob_link_dump_tbl implements RlsAble {
|
||||
public static final String Tbl_name = "link_dump"; private static final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
public static final String
|
||||
Fld_uid = flds.Add_int_pkey_autonum("uid")
|
||||
, Fld_src_page_id = flds.Add_int("src_page_id")
|
||||
, Fld_src_html_uid = flds.Add_int("src_html_uid")
|
||||
, Fld_trg_page_id = flds.Add_int_dflt("trg_page_id", -1)
|
||||
, Fld_trg_ns = flds.Add_int("trg_ns")
|
||||
, Fld_trg_ttl = flds.Add_str("trg_ttl", 255)
|
||||
;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xob_link_dump_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(Tbl_name, flds));}
|
||||
public void Create_idx_1() {
|
||||
conn.Ddl_create_idx
|
||||
( Db_meta_idx.new_normal_by_tbl(Tbl_name, "src", Fld_src_page_id, Fld_src_html_uid)
|
||||
, Db_meta_idx.new_normal_by_tbl(Tbl_name, "trg_temp", Fld_trg_ns, Fld_trg_ttl)
|
||||
);
|
||||
}
|
||||
public void Create_idx_2() {
|
||||
conn.Ddl_create_idx
|
||||
( Db_meta_idx.new_normal_by_tbl(Tbl_name, "trg", Fld_trg_page_id, Fld_src_page_id, Fld_src_html_uid)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("bldr__link_dump");}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int src_page_id, int src_html_uid, int trg_ns, byte[] trg_ttl) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(Tbl_name, flds.To_str_ary_wo_autonum());
|
||||
stmt_insert.Clear().Val_int(Fld_src_page_id, src_page_id)
|
||||
.Val_int(Fld_src_html_uid, src_html_uid).Val_int(Fld_trg_page_id, -1).Val_int(Fld_trg_ns, trg_ns).Val_bry_as_str(Fld_trg_ttl, trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Db_rdr Select_missing() {
|
||||
return conn.Stmt_select_order(Tbl_name, flds, String_.Ary(Fld_trg_page_id), Fld_src_page_id, Fld_src_html_uid)
|
||||
.Crt_int(Fld_trg_page_id, -1).Exec_select__rls_auto();
|
||||
}
|
||||
public static Xob_link_dump_tbl Get_or_new(Xow_wiki wiki) {
|
||||
Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(wiki.Fsys_mgr().Root_dir().GenSubFil("xowa.temp.redlink.sqlite3"));
|
||||
Xob_link_dump_tbl rv = new Xob_link_dump_tbl(conn_data.Conn());
|
||||
if (conn_data.Created()) rv.Create_tbl();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,89 +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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private int commit_interval = 10000, commit_count = 0;
|
||||
public Xob_redlink_mkr_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_html_redlinks;}
|
||||
public void Cmd_run() {Read_data();}
|
||||
private void Read_data() {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
wiki.Init_assert();
|
||||
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
|
||||
Xob_db_file link_dump_db = Xob_db_file.new__redlink(wiki.Fsys_mgr().Root_dir());
|
||||
Db_attach_rdr attach_rdr = new Db_attach_rdr(link_dump_db.Conn(), "page_db", core_db.Url());
|
||||
attach_rdr.Attach();
|
||||
Xowd_page_tbl page_tbl = core_db.Tbl__page();
|
||||
int cur_html_db_id = -1, cur_page_id = -1; Xowd_html_tbl html_dump_tbl = null;
|
||||
Db_rdr rdr = attach_rdr.Exec_as_rdr(Sql_select);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
// switch html_db if needed
|
||||
int html_db_id = rdr.Read_int(page_tbl.Fld_html_db_id());
|
||||
if (html_db_id != cur_html_db_id) {
|
||||
if (html_dump_tbl != null) html_dump_tbl.Conn().Txn_end();
|
||||
html_dump_tbl = wiki.Data__core_mgr().Dbs__get_at(html_db_id).Tbl__html();
|
||||
html_dump_tbl.Conn().Txn_bgn("bldr__redlink");
|
||||
cur_html_db_id = html_db_id;
|
||||
}
|
||||
// commit page_id if needed
|
||||
int page_id = rdr.Read_int(page_tbl.Fld_page_id());
|
||||
if (cur_page_id != page_id) {
|
||||
if (cur_page_id != -1) Commit(html_dump_tbl, cur_page_id, bfr);
|
||||
bfr.Add_int_variable(gplx.xowa.htmls.hdumps.core.Xohd_data_tid.Tid_redlink).Add_byte_pipe();
|
||||
cur_page_id = page_id;
|
||||
}
|
||||
// add html_uid to cur_page's bfr
|
||||
int html_uid = rdr.Read_int(Xob_link_dump_tbl.Fld_src_html_uid);
|
||||
bfr.Add_int_variable(html_uid).Add_byte_pipe();
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
Commit(html_dump_tbl, cur_page_id, bfr); // commit cur page
|
||||
html_dump_tbl.Conn().Txn_end(); // close cur tbl
|
||||
attach_rdr.Detach();
|
||||
}
|
||||
private void Commit(Xowd_html_tbl html_dump_tbl, int cur_page_id, Bry_bfr bfr) {
|
||||
html_dump_tbl.Insert(cur_page_id, Xowd_html_row.Tid_redlink, bfr.To_bry_and_clear());
|
||||
++commit_count;
|
||||
if ((commit_count % commit_interval ) == 0)
|
||||
html_dump_tbl.Conn().Txn_sav();
|
||||
}
|
||||
private static final String Sql_select = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT p.page_html_db_id"
|
||||
, ", p.page_id"
|
||||
, ", ld.src_html_uid"
|
||||
, "FROM link_dump ld"
|
||||
, " JOIN <attach_db>page p ON p.page_id = ld.src_page_id "
|
||||
, "WHERE ld.trg_page_id = -1"
|
||||
, "ORDER BY p.page_html_db_id, p.page_id"
|
||||
, ";"
|
||||
);
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_commit_interval_ = "commit_interval_";
|
||||
}
|
||||
@@ -1,23 +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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public interface Xohd_data_itm {
|
||||
int Data_tid();
|
||||
void Data_write(Bry_bfr bfr);
|
||||
String Data_print();
|
||||
}
|
||||
@@ -1,101 +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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.files.repos.*;
|
||||
public abstract class Xohd_data_itm__base implements Xohd_data_itm {
|
||||
public abstract int Img_tid();
|
||||
public int Data_tid() {return Xohd_data_tid.Tid_img;}
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public int Orig_repo_id() {return orig_repo_id;} private int orig_repo_id;
|
||||
public int Orig_ext() {return orig_ext;} private int orig_ext;
|
||||
public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig;
|
||||
public int File_w() {return file_w;} private int file_w;
|
||||
public int Html_uid() {return html_uid;} private int html_uid;
|
||||
public int Html_w() {return html_w;} private int html_w;
|
||||
public int Html_h() {return html_h;} private int html_h;
|
||||
public Io_url Html_view_url() {return html_view_url;} public void File_url_(Io_url v) {html_view_url = v;} private Io_url html_view_url;
|
||||
public abstract byte Html_elem_tid();
|
||||
public Xohd_data_itm__base Data_init_base
|
||||
( byte[] lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page
|
||||
, int orig_repo_id, int orig_ext, boolean file_is_orig, int file_w
|
||||
, int html_uid, int html_w, int html_h
|
||||
) {
|
||||
this.lnki_ttl = lnki_ttl; this.orig_ext = orig_ext; this.lnki_type = lnki_type;
|
||||
this.lnki_w = lnki_w; this.lnki_h = lnki_h; this.lnki_upright = lnki_upright; this.lnki_time = lnki_time; this.lnki_page = lnki_page;
|
||||
this.orig_repo_id = orig_repo_id; this.file_is_orig = file_is_orig; this.file_w = file_w;
|
||||
this.html_uid = html_uid; this.html_w = html_w; this.html_h = html_h;
|
||||
return this;
|
||||
}
|
||||
public void Data_write(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(Xohd_data_tid.Tid_img).Add_byte_pipe()
|
||||
.Add_int_variable(this.Img_tid()).Add_byte_pipe()
|
||||
.Add(lnki_ttl).Add_byte_pipe()
|
||||
.Add_int_variable(orig_ext).Add_byte_pipe()
|
||||
.Add_byte(lnki_type).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_w).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_h).Add_byte_pipe()
|
||||
.Add_double(lnki_upright).Add_byte_pipe()
|
||||
.Add_double(lnki_time).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_page).Add_byte_pipe()
|
||||
.Add_int_variable(orig_repo_id).Add_byte_pipe()
|
||||
.Add_yn(file_is_orig).Add_byte_pipe()
|
||||
.Add_int_variable(file_w).Add_byte_pipe()
|
||||
.Add_int_variable(html_uid).Add_byte_pipe()
|
||||
.Add_int_variable(html_w).Add_byte_pipe()
|
||||
.Add_int_variable(html_h).Add_byte_pipe()
|
||||
;
|
||||
Data_write_hook(bfr);
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
public String Data_print() {
|
||||
return String_.Concat_with_str("|", Int_.To_str(this.Img_tid()), String_.new_u8(lnki_ttl), Int_.To_str(html_uid), Int_.To_str(html_w), Int_.To_str(html_h)
|
||||
, Int_.To_str(orig_repo_id), Int_.To_str(orig_ext), Yn.To_str(file_is_orig), Int_.To_str(file_w), Double_.To_str(lnki_time), Int_.To_str(lnki_page)
|
||||
);
|
||||
}
|
||||
@gplx.Virtual public void Data_parse(Bry_rdr rdr) {
|
||||
this.lnki_ttl = Xoa_app_.Utl__encoder_mgr().Http_url().Decode(rdr.Read_bry_to_pipe());
|
||||
this.orig_ext = rdr.Read_int_to_pipe();
|
||||
this.lnki_type = rdr.Read_byte_to_pipe();
|
||||
this.lnki_w = rdr.Read_int_to_pipe();
|
||||
this.lnki_h = rdr.Read_int_to_pipe();
|
||||
this.lnki_upright = rdr.Read_double_to_pipe();
|
||||
this.lnki_time = rdr.Read_double_to_pipe();
|
||||
this.lnki_page = rdr.Read_int_to_pipe();
|
||||
this.orig_repo_id = rdr.Read_int_to_pipe();
|
||||
this.file_is_orig = rdr.Read_yn_to_pipe();
|
||||
this.file_w = rdr.Read_int_to_pipe();
|
||||
this.html_uid = rdr.Read_int_to_pipe();
|
||||
this.html_w = rdr.Read_int_to_pipe();
|
||||
this.html_h = rdr.Read_int_to_pipe();
|
||||
}
|
||||
@gplx.Virtual public void Data_write_hook(Bry_bfr bfr) {}
|
||||
@Override public String toString() {return this.Data_print();} // TEST
|
||||
public static final int Tid_basic = 0, Tid_gallery = 1;
|
||||
public static final int
|
||||
File_repo_id_commons = Xof_repo_itm_.Repo_remote
|
||||
, File_repo_id_local = Xof_repo_itm_.Repo_local
|
||||
, File_repo_id_null = Xof_repo_itm_.Repo_null
|
||||
;
|
||||
public static final Xohd_data_itm__base[] Ary_empty = new Xohd_data_itm__base[0];
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.files.*;
|
||||
public class Xohd_data_itm__gallery_itm extends Xohd_data_itm__base {
|
||||
@Override public int Img_tid() {return Xohd_data_itm__base.Tid_gallery;}
|
||||
@Override public byte Html_elem_tid() {return Xof_html_elem.Tid_img;}
|
||||
public int Box_w() {return box_w;} private int box_w;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_pad() {return img_pad;} private int img_pad;
|
||||
public Xohd_data_itm__gallery_itm Data_init_gallery(int box_w, int img_w, int img_pad) {
|
||||
this.box_w = box_w;
|
||||
this.img_w = img_w;
|
||||
this.img_pad = img_pad;
|
||||
return this;
|
||||
}
|
||||
@Override public void Data_write_hook(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(box_w).Add_byte_pipe()
|
||||
.Add_int_variable(img_w).Add_byte_pipe()
|
||||
.Add_int_variable(img_pad).Add_byte_pipe()
|
||||
;
|
||||
}
|
||||
@Override public void Data_parse(Bry_rdr rdr) {
|
||||
super.Data_parse(rdr);
|
||||
this.box_w = rdr.Read_int_to_pipe();
|
||||
this.img_w = rdr.Read_int_to_pipe();
|
||||
this.img_pad = rdr.Read_int_to_pipe();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xohd_data_itm__gallery_mgr implements Xohd_data_itm {
|
||||
public Xohd_data_itm__gallery_mgr(int uid, int box_max) {
|
||||
this.uid = uid;
|
||||
this.box_max = box_max;
|
||||
}
|
||||
public int Data_tid() {return Xohd_data_tid.Tid_gallery;}
|
||||
public void Data_write(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(Xohd_data_tid.Tid_gallery).Add_byte_pipe()
|
||||
.Add_int_variable(uid).Add_byte_pipe()
|
||||
.Add_int_variable(box_max).Add_byte_pipe()
|
||||
;
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
public String Data_print() {return Int_.To_str(box_max);}
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Box_max() {return box_max;} private int box_max;
|
||||
}
|
||||
@@ -1,23 +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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xohd_data_itm__img extends Xohd_data_itm__base {
|
||||
@Override public int Img_tid() {return Xohd_data_itm__base.Tid_basic;}
|
||||
@Override public byte Html_elem_tid() {return Xof_html_elem.Tid_img;}
|
||||
}
|
||||
@@ -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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xohd_data_tid { // SERIALIZED
|
||||
public static final int
|
||||
Tid_img = 1
|
||||
, Tid_redlink = 2
|
||||
, Tid_gallery = 3
|
||||
, Tid_imap = 4
|
||||
;
|
||||
}
|
||||
@@ -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.htmls.hdumps.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.htmls.hdumps.data.srl.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
public class Xohd_page_html_mgr__load {
|
||||
private final Xohd_page_srl_mgr srl_mgr = Xohd_page_srl_mgr.Instance;
|
||||
private final Bry_rdr rdr = new Bry_rdr(); private final List_adp rows = List_adp_.new_(), imgs = List_adp_.new_();
|
||||
public void Load_page(Xow_wiki wiki, Xog_page hpg, Xowd_html_tbl tbl, int page_id, Xoa_ttl page_ttl) {
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.text: ttl=~{0}", page_ttl.Full_db_as_str());
|
||||
tbl.Select_by_page(rows, page_id);
|
||||
Parse_rows(wiki, hpg, page_id, Xoa_url.blank(), page_ttl, rows);
|
||||
}
|
||||
public void Parse_rows(Xow_wiki wiki, Xog_page hpg, int page_id, Xoa_url page_url, Xoa_ttl page_ttl, List_adp rows) { // TEST:
|
||||
hpg.Init(wiki, page_id, page_url, page_ttl);
|
||||
imgs.Clear();
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_html_row row = (Xowd_html_row)rows.Get_at(i);
|
||||
switch (row.Tid()) {
|
||||
case Xowd_html_row.Tid_html: srl_mgr.Load(hpg, row.Data()); break;
|
||||
case Xowd_html_row.Tid_img:
|
||||
case Xowd_html_row.Tid_redlink:
|
||||
Parse_data(hpg, row); break;
|
||||
}
|
||||
}
|
||||
rows.Clear();
|
||||
}
|
||||
private void Parse_data(Xog_page hpg, Xowd_html_row row) {
|
||||
rdr.Init(row.Data());
|
||||
while (!rdr.Pos_is_eos()) {
|
||||
int tid = rdr.Read_int_to_pipe();
|
||||
switch (tid) {
|
||||
case Xohd_data_tid.Tid_img : Load_data_img(); break; // 1|0|A.png|0|220|110|...
|
||||
case Xohd_data_tid.Tid_gallery : Load_data_gallery(hpg); break; // 3|0|800
|
||||
case Xohd_data_tid.Tid_redlink : Load_data_redlink(hpg); break; // 2|2|0|1
|
||||
}
|
||||
}
|
||||
if (imgs.Count() > 0) hpg.Img_itms_((Xohd_data_itm__base[])imgs.To_ary_and_clear(Xohd_data_itm__base.class));
|
||||
}
|
||||
public static Xohd_data_itm__base Load_img(Bry_rdr rdr) {
|
||||
int tid = rdr.Read_int_to_pipe();
|
||||
Xohd_data_itm__base img_itm = null;
|
||||
switch (tid) {
|
||||
case Xohd_data_itm__base.Tid_basic : img_itm = new Xohd_data_itm__img(); break;
|
||||
case Xohd_data_itm__base.Tid_gallery : img_itm = new Xohd_data_itm__gallery_itm(); break;
|
||||
default : throw Err_.new_unhandled(tid);
|
||||
}
|
||||
img_itm.Data_parse(rdr);
|
||||
// Xoa_app_.Usr_dlg().Log_many("", "", "itm: ~{0}", img_itm.Data_print());
|
||||
rdr.Pos_add_one();
|
||||
return img_itm;
|
||||
}
|
||||
private void Load_data_img() {
|
||||
Xohd_data_itm__base img = Load_img(rdr);
|
||||
if (img == null) return;
|
||||
imgs.Add(img);
|
||||
}
|
||||
private void Load_data_redlink(Xog_page hpg) {
|
||||
Ordered_hash redlink_hash = hpg.Redlink_uids();
|
||||
while (!rdr.Pos_is_eos()) {
|
||||
Int_obj_ref redlink_uid = Int_obj_ref.new_(rdr.Read_int_to_pipe());
|
||||
redlink_hash.Add(redlink_uid, redlink_uid);
|
||||
}
|
||||
}
|
||||
private void Load_data_gallery(Xog_page hpg) {
|
||||
int uid = rdr.Read_int_to_pipe();
|
||||
int box_max = rdr.Read_int_to_pipe();
|
||||
hpg.Gallery_itms().Add_if_dupe_use_nth(uid, new Xohd_data_itm__gallery_mgr(uid, box_max)); // TODO: temporarily added b/c last build did not add gallery uid correctly
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.htmls.hdumps.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.srl.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xohd_page_html_mgr__save {
|
||||
private Xohd_page_srl_mgr srl_mgr = Xohd_page_srl_mgr.Instance;
|
||||
public void Update(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xoae_page page) {
|
||||
Xog_page hpg = new Xog_page();
|
||||
hpg.Ctor_from_page(tmp_bfr, page);
|
||||
tbl.Delete(page.Revision_data().Id());
|
||||
this.Insert(tmp_bfr, tbl, hpg, page.Hdump_data());
|
||||
}
|
||||
public int Insert(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xog_page hpg, Xopg_hdump_data hdump_data) {
|
||||
int rv = 0;
|
||||
int page_id = hpg.Page_id();
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_html , srl_mgr.Save(hpg, tmp_bfr));
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_img , Write_imgs(tmp_bfr, hdump_data.Imgs()));
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_redlink , Write_redlinks(tmp_bfr, hdump_data.Redlink_mgr()));
|
||||
return rv;
|
||||
}
|
||||
private int Insert_row(Xowd_html_tbl tbl, int page_id, int row_tid, byte[] bry) {return bry == null ? 0 : tbl.Insert(page_id, row_tid, bry);}
|
||||
public static byte[] Write_redlinks(Bry_bfr bfr, Xopg_redlink_idx_list redlink_mgr) {
|
||||
int len = redlink_mgr.Len(); if (len == 0) return null;
|
||||
for (int i = 0; i < len; ++i)
|
||||
bfr.Add_int_variable(redlink_mgr.Get_at(i)).Add_byte_pipe();
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static byte[] Write_imgs(Bry_bfr bfr, List_adp imgs) {
|
||||
int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_data_itm itm = (Xohd_data_itm)imgs.Get_at(i);
|
||||
itm.Data_write(bfr);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.guis.*;
|
||||
public interface Xohd_page_srl_itm { // INFO: serializes Xog_page to a byte[] before storing in the wiki_page_html table
|
||||
byte Tid();
|
||||
void Save(Xog_page hpg, Bry_bfr bfr);
|
||||
int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref);
|
||||
}
|
||||
abstract class Xohd_page_srl_itm__base implements Xohd_page_srl_itm {
|
||||
public abstract byte Tid();
|
||||
protected void Save_tid_n_() {save_tid = false;} private boolean save_tid = true;
|
||||
public void Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
byte[] bry = Save_itm(hpg); if (bry == null) return; // subclasses return null if nothing to save
|
||||
int len = bry.length; if (len == 0) return; // don't bother saving 0-len
|
||||
if (save_tid) // body doesn't save tid
|
||||
bfr.Add_byte(this.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, len);
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public abstract byte[] Save_itm(Xog_page hpg);
|
||||
public int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
|
||||
int itm_len = Xow_hzip_int_.Load_bin_int_abrv(bry, bry_len, itm_bgn, count_ref); if (itm_len == -1) throw Err_.new_wo_type("bry_itm has invalid len", "page", hpg.Page_id(), "tid", this.Tid());
|
||||
int data_bgn = itm_bgn + count_ref.Val(); if (itm_len == 0) return data_bgn;
|
||||
int data_end = data_bgn + itm_len;
|
||||
byte[] itm_data = Bry_.Mid(bry, data_bgn, data_end);
|
||||
this.Load_itm(hpg, itm_data);
|
||||
return data_end - itm_bgn;
|
||||
}
|
||||
public abstract void Load_itm(Xog_page hpg, byte[] data);
|
||||
}
|
||||
@@ -1,34 +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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
public class Xohd_page_srl_itm_ {
|
||||
public static final byte // SERIALIZED
|
||||
Tid_body = 0
|
||||
, Tid_html_module = 1
|
||||
, Tid_display_ttl = 2
|
||||
, Tid_content_sub = 3
|
||||
, Tid_sidebar_div = 4
|
||||
;
|
||||
public static final Xohd_page_srl_itm[] Itms = new Xohd_page_srl_itm[] // NOTE: ary_idx must match tid above
|
||||
{ new Xohd_page_srl_itm__body()
|
||||
, new Xohd_page_srl_itm__html_module()
|
||||
, new Xohd_page_srl_itm__display_ttl()
|
||||
, new Xohd_page_srl_itm__content_sub()
|
||||
, new Xohd_page_srl_itm__sidebar_div()
|
||||
};
|
||||
}
|
||||
@@ -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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_page_srl_itm_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xohd_page_srl_itm_fxt fxt = new Xohd_page_srl_itm_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A"), fxt.Make_srl_body("A"));
|
||||
}
|
||||
@Test public void Html_modules() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N), fxt.Make_srl_body("A"), fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N));
|
||||
}
|
||||
@Test public void Body_all() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N).Display_ttl_("B").Content_sub_("C").Sidebar_div_("D")
|
||||
, fxt.Make_srl_body("A")
|
||||
, fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N)
|
||||
, fxt.Make_srl_display_ttl("B")
|
||||
, fxt.Make_srl_content_sub("C")
|
||||
, fxt.Make_srl_sidebar_div("D")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xohd_page_srl_itm_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(8);
|
||||
public void Clear() {bfr.Clear();}
|
||||
public Xog_page_bldr Make_page() {return new Xog_page_bldr();}
|
||||
public Xohd_page_srl_itm_mok Make_srl_body(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_body, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_display_ttl(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_display_ttl, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_content_sub(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_content_sub, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_sidebar_div(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_sidebar_div, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl(byte tid, String s) {return new Xohd_page_srl_itm_mok(tid, Bry_.new_u8(s));}
|
||||
public Xohd_page_srl_itm_mok Make_srl_html_modules(boolean... v) {
|
||||
return new Xohd_page_srl_itm_mok(Xohd_page_srl_itm_.Tid_html_module, new byte[] {Xohd_page_srl_itm__html_module.Calc_flag(v[0], v[1], v[2], v[3])});
|
||||
}
|
||||
public void Test_page(Xog_page_bldr hpg_bldr, Xohd_page_srl_itm_mok... expd_itms) {
|
||||
Xog_page hpg = hpg_bldr.Bld();
|
||||
byte[] actl = Xohd_page_srl_mgr.Instance.Save(hpg, bfr);
|
||||
Tfds.Eq_ary(Xohd_page_srl_itm_mok.Xto_bry(bfr, expd_itms), actl);
|
||||
Xog_page actl_hpg = new Xog_page();
|
||||
Xohd_page_srl_mgr.Instance.Load(actl_hpg, actl);
|
||||
Tfds.Eq_ary(actl, Xohd_page_srl_mgr.Instance.Save(hpg, bfr));
|
||||
}
|
||||
}
|
||||
class Xog_page_bldr {
|
||||
public byte[] Body() {return body;} public Xog_page_bldr Body_(String v) {body = Bry_.new_u8(v); return this;} private byte[] body;
|
||||
public boolean[] Html_modules() {return html_modules;} public Xog_page_bldr Html_modules_(boolean... v) {html_modules = v; return this;} private boolean[] html_modules;
|
||||
public byte[] Display_ttl() {return display_ttl;} public Xog_page_bldr Display_ttl_(String v) {display_ttl = Bry_.new_u8(v); return this;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} public Xog_page_bldr Content_sub_(String v) {content_sub = Bry_.new_u8(v); return this;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} public Xog_page_bldr Sidebar_div_(String v) {sidebar_div = Bry_.new_u8(v); return this;} private byte[] sidebar_div;
|
||||
public Xog_page Bld() {
|
||||
Xog_page rv = new Xog_page();
|
||||
rv.Page_body_(body);
|
||||
Xopg_module_mgr mod_mgr = rv.Head_mgr();
|
||||
if (html_modules != null) {
|
||||
mod_mgr.Math_exists_(html_modules[0]);
|
||||
mod_mgr.Imap_exists_(html_modules[1]);
|
||||
mod_mgr.Gallery_packed_exists_(html_modules[2]);
|
||||
mod_mgr.Hiero_exists_(html_modules[3]);
|
||||
}
|
||||
rv.Display_ttl_(display_ttl);
|
||||
rv.Content_sub_(content_sub);
|
||||
rv.Sidebar_div_(sidebar_div);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xohd_page_srl_itm_mok {
|
||||
public Xohd_page_srl_itm_mok(byte tid, byte[] data) {this.tid = tid; this.data = data;}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public int Len() {return data.length;}
|
||||
public byte[] Data() {return data;} private final byte[] data;
|
||||
public static byte[] Xto_bry(Bry_bfr bfr, Xohd_page_srl_itm_mok[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_page_srl_itm_mok itm = ary[i];
|
||||
if (itm.Tid() != Xohd_page_srl_itm_.Tid_body)
|
||||
bfr.Add_byte(itm.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, itm.Len());
|
||||
bfr.Add(itm.Data());
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.guis.*;
|
||||
class Xohd_page_srl_itm__body extends Xohd_page_srl_itm__base {
|
||||
public Xohd_page_srl_itm__body() {this.Save_tid_n_();}
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_body;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Page_body();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Page_body_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__display_ttl extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_display_ttl;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Display_ttl();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Display_ttl_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__content_sub extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_content_sub;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Content_sub();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Content_sub_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__sidebar_div extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_sidebar_div;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Sidebar_div();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Sidebar_div_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__html_module implements Xohd_page_srl_itm {
|
||||
public byte Tid() {return Xohd_page_srl_itm_.Tid_html_module;}
|
||||
public int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
|
||||
itm_bgn += 2; // skip bin_int_abrv of [1, 0]
|
||||
byte flag = bry[itm_bgn];
|
||||
hpg.Head_mgr().Init(Bitmask_.Has_byte(flag, Tid_math), Bitmask_.Has_byte(flag, Tid_imap), Bitmask_.Has_byte(flag, Tid_packed), Bitmask_.Has_byte(flag, Tid_hiero));
|
||||
return 3;
|
||||
}
|
||||
public void Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
byte flag = Calc_flag(hpg);
|
||||
if (flag == 0) return;
|
||||
bfr.Add_byte(this.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, 1);
|
||||
bfr.Add_byte(flag);
|
||||
}
|
||||
private static byte Calc_flag(Xog_page hpg) {
|
||||
Xopg_module_mgr module_mgr = hpg.Head_mgr();
|
||||
return Calc_flag(module_mgr.Math_exists(), module_mgr.Imap_exists(), module_mgr.Gallery_packed_exists(), module_mgr.Hiero_exists());
|
||||
}
|
||||
public static byte Calc_flag(boolean math, boolean imap, boolean packed, boolean hiero) {
|
||||
byte rv = 0;
|
||||
if (math) rv = Bitmask_.Add_byte(rv, Tid_math);
|
||||
if (imap) rv = Bitmask_.Add_byte(rv, Tid_imap);
|
||||
if (packed) rv = Bitmask_.Add_byte(rv, Tid_packed);
|
||||
if (hiero) rv = Bitmask_.Add_byte(rv, Tid_hiero);
|
||||
return rv;
|
||||
}
|
||||
private static final byte // SERIALIZED; only supports 8 different types
|
||||
Tid_math = 1
|
||||
, Tid_imap = 2
|
||||
, Tid_packed = 4
|
||||
, Tid_hiero = 8
|
||||
;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_page_srl_mgr {
|
||||
private final Xohd_page_srl_itm[] itm_ary; private final Xohd_page_srl_itm itm_body;
|
||||
private final Int_obj_ref count_ref = Int_obj_ref.zero_();
|
||||
public Xohd_page_srl_mgr(Xohd_page_srl_itm[] itm_ary) {
|
||||
this.itm_ary = itm_ary;
|
||||
this.itm_body = itm_ary[0];
|
||||
}
|
||||
public byte[] Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
for (Xohd_page_srl_itm itm : itm_ary)
|
||||
itm.Save(hpg, bfr);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Load(Xog_page hpg, byte[] bry) {
|
||||
if (bry == null) return;
|
||||
int bry_len = bry.length; if (bry_len == 0) return;
|
||||
int pos = itm_body.Load(hpg, bry, bry_len, 0, count_ref); // assume every page has a body; saves 1 byte by not specifying tid for body
|
||||
while (pos < bry_len) {
|
||||
byte itm_tid = bry[pos]; // itm_tid is always 1-byte
|
||||
Xohd_page_srl_itm itm = itm_ary[itm_tid]; // itm_tid always matches itm_ary's idx
|
||||
pos += itm.Load(hpg, bry, bry_len, pos + 1, count_ref) + 1; // +1 to skip tid
|
||||
}
|
||||
}
|
||||
public static final Xohd_page_srl_mgr Instance = new Xohd_page_srl_mgr(Xohd_page_srl_itm_.Itms);
|
||||
}
|
||||
@@ -1,39 +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.htmls.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xopg_hdump_data {
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
|
||||
public Xopg_redlink_idx_list Redlink_mgr() {return redlink_mgr;} private final Xopg_redlink_idx_list redlink_mgr = new Xopg_redlink_idx_list();
|
||||
public List_adp Imgs() {return imgs;} private final List_adp imgs = List_adp_.new_();
|
||||
public void Imgs_add(Xohd_data_itm itm) {imgs.Add(itm);}
|
||||
public void Imgs_add_img(Xohd_data_itm__base img, Xof_file_itm xfer, int tid) {
|
||||
img.Data_init_base
|
||||
( xfer.Lnki_ttl(), xfer.Lnki_type(), xfer.Lnki_upright(), xfer.Lnki_w(), xfer.Lnki_h(), xfer.Lnki_time(), xfer.Lnki_page()
|
||||
, xfer.Orig_repo_id(), xfer.Orig_ext().Id(), xfer.File_is_orig(), xfer.File_w()
|
||||
, xfer.Html_uid(), xfer.Html_w(), xfer.Html_h()
|
||||
);
|
||||
imgs.Add(img);
|
||||
}
|
||||
public void Clear() {
|
||||
body = null;
|
||||
imgs.Clear();
|
||||
redlink_mgr.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +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.htmls.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xopg_module_mgr {
|
||||
public boolean Math_exists() {return math_exists;} public void Math_exists_(boolean v) {math_exists = v;} private boolean math_exists;
|
||||
public boolean Imap_exists() {return imap_exists;} public void Imap_exists_(boolean v) {imap_exists = v;} private boolean imap_exists;
|
||||
public boolean Gallery_packed_exists() {return gallery_packed_exists;} public void Gallery_packed_exists_(boolean v) {gallery_packed_exists = v;} private boolean gallery_packed_exists;
|
||||
public boolean Hiero_exists() {return hiero_exists;} public void Hiero_exists_(boolean v) {hiero_exists = v;} private boolean hiero_exists;
|
||||
public void Init(boolean math, boolean imap, boolean packed, boolean hiero) {
|
||||
this.math_exists = math;
|
||||
this.imap_exists = imap;
|
||||
this.gallery_packed_exists = packed;
|
||||
this.hiero_exists = hiero;
|
||||
}
|
||||
public void Clear() {
|
||||
math_exists = imap_exists = gallery_packed_exists = hiero_exists = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user