mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.12.1.1
This commit is contained in:
@@ -34,7 +34,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.11.4.1";
|
||||
public static final String Version = "2.12.1.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
||||
@@ -22,7 +22,8 @@ public interface Xoa_page {
|
||||
Xoa_url Url();
|
||||
byte[] Url_bry_safe();
|
||||
Xoa_ttl Ttl();
|
||||
void Xtn_gallery_packed_exists_y_();
|
||||
boolean Exists();
|
||||
|
||||
Xoa_page__commons_mgr Commons_mgr();
|
||||
void Xtn_gallery_packed_exists_y_();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
Bry_.Replace_reuse(rv, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
return rv;
|
||||
}
|
||||
public String Page_db_as_str() {return String_.new_u8(Page_db());}
|
||||
public String Page_db_as_str() {return String_.new_u8(Page_db());}
|
||||
public byte[] Page_url_w_anch() {return Gfo_url_encoder_.Href.Encode(Bry_.Mid(full_txt, page_bgn, qarg_bgn == -1 ? full_txt.length : qarg_bgn - 1));}
|
||||
public int Leaf_bgn() {return leaf_bgn;}
|
||||
public byte[] Base_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, page_bgn, leaf_bgn - 1);}
|
||||
public byte[] Leaf_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, leaf_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
@@ -52,7 +53,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
public byte[] Anch_txt() {return anch_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, anch_bgn, full_txt.length);}
|
||||
public byte[] Talk_txt() {return ns.Id_is_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Subj_txt() {return ns.Id_is_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Full_url() {return Xoa_url_encoder.Instance.Encode(full_txt);}
|
||||
public byte[] Full_url() {return Gfo_url_encoder_.Href.Encode(full_txt);}
|
||||
public String Full_db_as_str() {return String_.new_u8(Full_db());}
|
||||
public byte[] Full_db() {return ns.Gen_ttl(this.Page_db());}
|
||||
public byte[] Full_db_w_anch() {return Replace_spaces(full_txt);}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
public Xoae_app(Gfo_usr_dlg usr_dlg, Xoa_app_mode mode, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url user_dir, Io_url css_dir, String bin_dir_name) {
|
||||
Xoa_app_.Usr_dlg_(usr_dlg);
|
||||
this.mode = mode;
|
||||
Io_url.Http_file_str_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys;
|
||||
Io_url.Http_file_str_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx;
|
||||
fsys_mgr = new Xoa_fsys_mgr(bin_dir_name, root_dir, wiki_dir, file_dir, css_dir);
|
||||
log_wtr = usr_dlg.Log_wkr();
|
||||
cfg_mgr = new Xoa_cfg_mgr(this);
|
||||
|
||||
@@ -16,11 +16,11 @@ 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; import gplx.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; import gplx.xowa.htmls.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.htmls.tocs.*;
|
||||
import gplx.xowa.htmls.modules.popups.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.htmls.modules.popups.*;
|
||||
public class Xoae_page implements Xoa_page {
|
||||
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
@@ -28,13 +28,13 @@ public class Xoae_page implements Xoa_page {
|
||||
hdr_mgr = new Xow_hdr_mgr(this);
|
||||
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_is_module());
|
||||
Ttl_(ttl);
|
||||
} Xoae_page() {} // called by Null
|
||||
} Xoae_page() {} // called by Empty
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xoae_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl;
|
||||
public Xoa_url Url() {return url;} public Xoae_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank();
|
||||
public byte[] Url_bry_safe() {return url == null ? Bry_.Empty : url.Raw();}
|
||||
public void Xtn_gallery_packed_exists_y_() {html_data.Xtn_gallery_packed_exists_y_();}
|
||||
public boolean Exists() {return !Missing();}
|
||||
public void Xtn_gallery_packed_exists_y_() {html_data.Xtn_gallery_packed_exists_y_();}
|
||||
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public Xopg_revision_data Revision_data() {return revision_data;} private Xopg_revision_data revision_data = new Xopg_revision_data();
|
||||
@@ -58,7 +58,7 @@ public class Xoae_page implements Xoa_page {
|
||||
public List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.new_();
|
||||
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
|
||||
public List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.new_();
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr(); public void Ref_mgr_(Ref_itm_mgr v) {this.ref_mgr = v;}
|
||||
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
|
||||
public List_adp Slink_list() {return slink_list;} private List_adp slink_list = List_adp_.new_();
|
||||
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
|
||||
@@ -79,7 +79,8 @@ public class Xoae_page implements Xoa_page {
|
||||
tmpl_stack_ary_len = new_len;
|
||||
return true;
|
||||
} private byte[][] tmpl_stack_ary = Bry_.Ary_empty; private int tmpl_stack_ary_len = 0, tmpl_stack_ary_max = 0;
|
||||
public void Clear() { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
|
||||
public void Clear_all() {Clear(true);}
|
||||
public void Clear(boolean clear_scrib) { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
|
||||
hdr_mgr.Clear();
|
||||
lnki_list.Clear();
|
||||
file_math.Clear();
|
||||
@@ -88,7 +89,7 @@ public class Xoae_page implements Xoa_page {
|
||||
html_cmd_mgr.Clear();
|
||||
hdump_data.Clear();
|
||||
wdata_external_lang_links.Reset();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
|
||||
if (clear_scrib) gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
|
||||
slink_list.Clear();
|
||||
html_data.Clear();
|
||||
tab_data.Clear();
|
||||
@@ -100,13 +101,9 @@ public class Xoae_page implements Xoa_page {
|
||||
tmpl_prepend_mgr.Clear();
|
||||
commons_mgr.Clear();
|
||||
}
|
||||
public static final Xoae_page Null = null;
|
||||
private Xoae_page Edit_mode_create_() {edit_mode = Xoa_page_.Edit_mode_create; return this;}
|
||||
public static final Xoae_page Empty = new Xoae_page().Missing_();
|
||||
public static Xoae_page test_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page new_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page create_(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
Xoae_page rv = new Xoae_page(wiki, ttl);
|
||||
rv.edit_mode = Xoa_page_.Edit_mode_create;
|
||||
return rv;
|
||||
}
|
||||
public static Xoae_page New(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page New_test(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page New_edit(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl).Edit_mode_create_();}
|
||||
}
|
||||
|
||||
@@ -61,9 +61,9 @@ public class Xop_fxt {
|
||||
public void Lang_by_id_(int id) {ctx.Cur_page().Lang_(wiki.Appe().Lang_mgr().Get_by_or_new(Xol_lang_stub_.Get_by_id(id).Key()));}
|
||||
public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr;
|
||||
public Xop_fxt Reset() {
|
||||
ctx.Clear();
|
||||
ctx.Clear_all();
|
||||
ctx.App().Free_mem(false);
|
||||
ctx.Cur_page().Clear();
|
||||
ctx.Cur_page().Clear_all();
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr.Instance.InitEngine_mem(); // clear created pages
|
||||
@@ -286,12 +286,13 @@ public class Xop_fxt {
|
||||
hdom_wtr.Write_all(actl_bfr, ctx, root.Root_src(), root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
|
||||
public String Exec_parse_page_wiki_as_str(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
Bry_bfr actl_bfr = Bry_bfr.new_();
|
||||
hdom_wtr.Write_all(actl_bfr, ctx, raw_bry, root);
|
||||
hdom_wtr.Write_all(actl_bfr, ctx, hctx, raw_bry, root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
|
||||
|
||||
@@ -218,7 +218,7 @@ public class Xowe_wiki implements Xow_wiki, GfoInvkAble, GfoEvObj {
|
||||
if (rls_list == null) return;
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
RlsAble rls = (RlsAble)rls_list.Get_at(i);
|
||||
Rls_able rls = (Rls_able)rls_list.Get_at(i);
|
||||
rls.Rls();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Xoapi_import implements GfoInvkAble {
|
||||
public byte Zip_tid_text() {return zip_tid_text;} private byte zip_tid_text = Io_stream_.Tid_gzip;
|
||||
public byte Zip_tid_html() {return zip_tid_html;} private byte zip_tid_html = Io_stream_.Tid_gzip;
|
||||
public boolean Hzip_enabled() {return hzip_enabled;} private boolean hzip_enabled = Bool_.Y;
|
||||
public boolean Hzip_mode_is_b256() {return hzip_mode_is_b256;} private boolean hzip_mode_is_b256 = Bool_.Y;
|
||||
public String User_name() {return user_name;} private String user_name = "anonymous";
|
||||
public Xowd_core_db_props New_props(String domain_str, long dump_file_size) {
|
||||
Xowd_db_layout layout_text, layout_html, layout_file;
|
||||
@@ -40,7 +41,7 @@ public class Xoapi_import implements GfoInvkAble {
|
||||
layout_html = dump_file_size < layout_html_max ? Xowd_db_layout.Itm_few : Xowd_db_layout.Itm_lot;
|
||||
layout_file = dump_file_size < layout_file_max ? Xowd_db_layout.Itm_few : Xowd_db_layout.Itm_lot;
|
||||
}
|
||||
return new Xowd_core_db_props(2, layout_text, layout_html, layout_file, zip_tid_text, zip_tid_html, hzip_enabled);
|
||||
return new Xowd_core_db_props(2, layout_text, layout_html, layout_file, zip_tid_text, zip_tid_html, hzip_enabled, hzip_mode_is_b256);
|
||||
}
|
||||
public byte[] New_ns_file_map(long dump_file_size) {
|
||||
return dump_file_size < layout_text_max ? Bry_.Empty : Ns_file_map__each;
|
||||
@@ -72,6 +73,8 @@ public class Xoapi_import implements GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_zip_tid_html_)) zip_tid_html = Io_stream_.To_tid(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_hzip_enabled)) return Yn.To_str(hzip_enabled);
|
||||
else if (ctx.Match(k, Invk_hzip_enabled_)) hzip_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_mode_is_b256)) return Yn.To_str(hzip_mode_is_b256);
|
||||
else if (ctx.Match(k, Invk_hzip_mode_is_b256_)) hzip_mode_is_b256 = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_user_name)) return user_name;
|
||||
else if (ctx.Match(k, Invk_user_name_)) user_name = m.ReadStr("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
@@ -91,7 +94,8 @@ public class Xoapi_import implements GfoInvkAble {
|
||||
, Invk_zip_tid_text = "zip_tid_text" , Invk_zip_tid_text_ = "zip_tid_text_", Invk_zip_tid_list = "zip_tid_list"
|
||||
, Invk_zip_tid_html = "zip_tid_html" , Invk_zip_tid_html_ = "zip_tid_html_"
|
||||
, Invk_user_name = "user_name" , Invk_user_name_ = "user_name_"
|
||||
, Invk_hzip_enabled = "hzip_enabled" , Invk_hzip_enabled_ = "hzip_enabled_"
|
||||
, Invk_hzip_enabled = "hzip_enabled" , Invk_hzip_enabled_ = "hzip_enabled_"
|
||||
, Invk_hzip_mode_is_b256 = "hzip_mode_is_b256" , Invk_hzip_mode_is_b256_ = "hzip_mode_is_b256_"
|
||||
;
|
||||
public static final byte[] Ns_file_map__each = Bry_.new_a7("<each>");
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Xoapi_view implements GfoInvkAble {
|
||||
public void Save_as() {
|
||||
if (this.Active_tab_is_null()) return;
|
||||
Xog_tab_itm tab = win.Tab_mgr().Active_tab();
|
||||
String file_name = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_safe.Encode_str(String_.new_u8(tab.Page().Ttl().Full_url())) + ".html";
|
||||
String file_name = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_wnt.Encode_str(String_.new_u8(tab.Page().Ttl().Full_url())) + ".html";
|
||||
String file_url = app.Gui_mgr().Kit().New_dlg_file(Gfui_kit_.File_dlg_type_save, "Select file to save to:").Init_file_(file_name).Ask();
|
||||
if (String_.Len_eq_0(file_url)) return;
|
||||
Io_mgr.Instance.SaveFilStr(file_url, tab.Html_box().Text());
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xoa_fsys_mgr implements GfoInvkAble {
|
||||
this.cfg_app_fil = bin_xowa_dir.GenSubFil_nest("cfg", "app", "xowa.gfs");
|
||||
this.cfg_lang_core_dir = bin_xowa_dir.GenSubDir_nest("cfg", "lang", "core");
|
||||
this.cfg_wiki_core_dir = bin_xowa_dir.GenSubDir_nest("cfg", "wiki", "core");
|
||||
this.cfg_site_meta_fil = bin_xowa_dir.GenSubDir_nest("cfg", "wiki", "site_meta.sqlite3");
|
||||
this.cfg_site_meta_fil = bin_xowa_dir.GenSubFil_nest("cfg", "wiki", "site_meta.sqlite3");
|
||||
this.home_wiki_dir = bin_xowa_dir.GenSubDir_nest("wiki", Xow_domain_itm_.Str__home);
|
||||
}
|
||||
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
|
||||
|
||||
@@ -16,8 +16,8 @@ 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.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.tests.*;
|
||||
import gplx.core.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
|
||||
import gplx.core.tests.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
|
||||
public class Xob_fxt {
|
||||
public Xob_fxt Ctor_mem() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
|
||||
@@ -140,8 +140,10 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
|
||||
usr_dlg.Prog_many("", "", "parsing: ns=~{0} db=~{1} pg=~{2} count=~{3} time=~{4} rate=~{5} ttl=~{6}"
|
||||
, ns.Id(), db_id, page.Id(), exec_count
|
||||
, Env_.TickCount_elapsed_in_sec(time_bgn), rate_mgr.Rate_as_str(), String_.new_u8(page.Ttl_page_db()));
|
||||
ctx.Clear();
|
||||
Exec_pg_itm_hook(ns_ord, ns, page, page.Text());
|
||||
ctx.Clear_all();
|
||||
byte[] page_src = page.Text();
|
||||
if (page_src != null) // some pages have no text; ignore them else null ref; PAGE: it.d:miercuri DATE:2015-12-05
|
||||
Exec_pg_itm_hook(ns_ord, ns, page, page_src);
|
||||
ctx.App().Utl__bfr_mkr().Clear_fail_check(); // make sure all bfrs are released
|
||||
if (ctx.Wiki().Cache_mgr().Tmpl_result_cache().Count() > 50000)
|
||||
ctx.Wiki().Cache_mgr().Tmpl_result_cache().Clear();
|
||||
@@ -155,7 +157,7 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
|
||||
Free();
|
||||
}
|
||||
catch (Exception exc) {
|
||||
bldr.Usr_dlg().Warn_many(GRP_KEY, "parse", "failed to parse ~{0} error ~{1}", String_.new_u8(page.Ttl_page_db()), Err_.Message_lang(exc));
|
||||
bldr.Usr_dlg().Warn_many("", "", "parse failed: wiki=~{0} ttl=~{1} err=~{2}", wiki.Domain_str(), page.Ttl_full_db(), Err_.Message_gplx_log(exc));
|
||||
ctx.App().Utl__bfr_mkr().Clear();
|
||||
this.Free();
|
||||
}
|
||||
@@ -216,7 +218,6 @@ public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xo
|
||||
, Invk_poll_mgr = "poll_mgr", Invk_reset_db_ = "reset_db_"
|
||||
, Invk_exec_count_max_ = "exec_count_max_", Invk_exit_now_ = "exit_now_", Invk_exit_after_commit_ = "exit_after_commit_"
|
||||
;
|
||||
private static final String GRP_KEY = "xowa.bldr.parse";
|
||||
}
|
||||
class Xob_dump_mgr_base_ {
|
||||
public static void Load_all_tmpls(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, Xob_dump_src_id page_src) {
|
||||
|
||||
@@ -16,8 +16,8 @@ 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.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.brys.*; import gplx.core.ios.*; import gplx.xowa.wikis.ctgs.*;
|
||||
import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.core.brys.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.xowa.wikis.ctgs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
private DateAdp_parser date_parser = DateAdp_parser.new_(); private Sql_file_parser sql_parser; Uca_trie trie; private Bry_bfr uca_bfr = Bry_bfr.reset_(255);
|
||||
public abstract Io_sort_cmd Make_sort_cmd(Sql_file_parser sql_parser);
|
||||
|
||||
@@ -25,7 +25,7 @@ import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
|
||||
public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private Db_conn bldr_conn; private Db_cfg_tbl bldr_cfg_tbl;
|
||||
private Xof_bin_mgr src_bin_mgr; private Xof_bin_wkr__fsdb_sql src_fsdb_wkr; private boolean src_bin_mgr__cache_enabled = Bool_.N; private String src_bin_mgr__fsdb_version; private String[] src_bin_mgr__fsdb_skip_wkrs; private boolean src_bin_mgr__wmf_enabled;
|
||||
private Fsm_mnt_itm trg_mnt_itm; private Fsm_cfg_mgr trg_cfg_mgr; private Fsm_atr_fil trg_atr_fil; private Fsm_bin_fil trg_bin_fil; private long trg_bin_db_max;
|
||||
private Fsm_mnt_itm trg_mnt_itm; private Fsm_cfg_mgr trg_cfg_mgr; private Fsm_atr_fil trg_atr_fil; private Fsm_bin_fil trg_bin_fil; private long trg_bin_db_max; private String trg_bin_mgr__fsdb_version;
|
||||
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_bin_db_mgr bin_db_mgr; private int[] ns_ids; private int prv_lnki_tier_id = -1;
|
||||
private long download_size_max = Io_mgr.Len_mb_long * 5; private int[] download_keep_tier_ids = Int_.Ary(0);
|
||||
private Xobu_poll_mgr poll_mgr; private int poll_interval; private long time_bgn;
|
||||
@@ -66,7 +66,8 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
// trg_mnt_itm
|
||||
this.trg_bin_db_max = app.Api_root().Bldr().Wiki().Import().File_db_max();
|
||||
Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
Io_url trg_file_dir_v1 = String_.Eq(trg_bin_mgr__fsdb_version, "v1") ? wiki.Fsys_mgr().File_dir().GenNewNameOnly(wiki.Domain_str() + "-prv") : wiki.Fsys_mgr().File_dir(); // NOTE: convoluted way of setting trg to -prv if trg_bin_mgr__fsdb_version_v1 is set; otherwise set to "en.wikipedia.org" which will noop; DATE:2015-12-02
|
||||
Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), trg_file_dir_v1);
|
||||
if (trg_db_mgr == null) trg_db_mgr = Fsdb_db_mgr__v2_bldr.Instance.Get_or_make(wiki, Bool_.Y);
|
||||
Fsm_mnt_mgr trg_mnt_mgr = new Fsm_mnt_mgr(); trg_mnt_mgr.Ctor_by_load(trg_db_mgr);
|
||||
trg_mnt_mgr.Mnts__get_insert_idx_(Fsm_mnt_mgr.Mnt_idx_main); // NOTE: do not delete; mnt_mgr default to Mnt_idx_user; DATE:2014-04-25
|
||||
@@ -317,6 +318,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
else if (ctx.Match(k, Invk_src_bin_mgr__fsdb_skip_wkrs_)) src_bin_mgr__fsdb_skip_wkrs = m.ReadStrAry("v", "|");
|
||||
else if (ctx.Match(k, Invk_src_bin_mgr__wmf_enabled_)) src_bin_mgr__wmf_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_src_bin_mgr__cache_enabled_)) src_bin_mgr__cache_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_trg_bin_mgr__fsdb_version_)) trg_bin_mgr__fsdb_version = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk_poll_mgr)) return poll_mgr;
|
||||
else if (ctx.Match(k, Invk_download_keep_tier_ids)) download_keep_tier_ids = Int_.Ary_parse(m.ReadStr("v"), "|");
|
||||
else if (ctx.Match(k, Invk_download_size_max)) download_size_max = Io_size_.To_long_by_msg_mb(m, download_size_max);
|
||||
@@ -331,6 +333,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
, Invk_src_bin_mgr__fsdb_version_ = "src_bin_mgr__fsdb_version_", Invk_src_bin_mgr__fsdb_skip_wkrs_ = "src_bin_mgr__fsdb_skip_wkrs_"
|
||||
, Invk_src_bin_mgr__wmf_enabled_ = "src_bin_mgr__wmf_enabled_"
|
||||
, Invk_src_bin_mgr__cache_enabled_ = "src_bin_mgr__cache_enabled_", Invk_ns_ids_ = "ns_ids_"
|
||||
, Invk_trg_bin_mgr__fsdb_version_ = "trg_bin_mgr__fsdb_version_"
|
||||
, Invk_download_size_max = "download_size_max", Invk_download_keep_tier_ids = "download_keep_tier_ids"
|
||||
;
|
||||
public static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry);
|
||||
if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json
|
||||
Xoae_page page = ctx.Cur_page();
|
||||
page.Clear();
|
||||
page.Clear_all();
|
||||
page.Bldr__ns_ord_(ns_ord);
|
||||
page.Ttl_(ttl).Revision_data().Id_(db_page.Id());
|
||||
page.Redlink_lnki_list().Clear();
|
||||
|
||||
@@ -68,7 +68,7 @@ class Dg_file_tbl {
|
||||
.Exec_insert();
|
||||
}
|
||||
}
|
||||
class Dg_rule_tbl implements RlsAble {
|
||||
class Dg_rule_tbl implements Rls_able {
|
||||
private String tbl_name = "dg_rule"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_file_id, fld_rule_id, fld_rule_idx, fld_rule_score, fld_rule_text;
|
||||
private Db_conn conn; private Db_stmt stmt_insert;
|
||||
@@ -101,7 +101,7 @@ class Dg_rule_tbl implements RlsAble {
|
||||
.Exec_insert();
|
||||
}
|
||||
}
|
||||
class Dg_page_score_tbl implements RlsAble {
|
||||
class Dg_page_score_tbl implements Rls_able {
|
||||
private String tbl_name = "dg_page_score"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_log_tid, fld_page_id, fld_page_ns, fld_page_ttl, fld_page_len, fld_page_score, fld_page_rule_count, fld_clude_type;
|
||||
private Db_conn conn; private Db_stmt stmt_insert;
|
||||
@@ -141,7 +141,7 @@ class Dg_page_score_tbl implements RlsAble {
|
||||
.Exec_insert();
|
||||
}
|
||||
}
|
||||
class Dg_page_rule_tbl implements RlsAble {
|
||||
class Dg_page_rule_tbl implements Rls_able {
|
||||
private String tbl_name = "dg_page_rule"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_log_tid, fld_page_id, fld_rule_id, fld_rule_score_total;
|
||||
private Db_conn conn; private Db_stmt stmt_insert;
|
||||
|
||||
@@ -16,8 +16,8 @@ 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.btries.*; import gplx.core.ios.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.core.btries.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_xml_parser {
|
||||
Btrie_fast_mgr trie = Xob_xml_parser_.trie_(); Bry_bfr data_bfr = Bry_bfr.new_(); DateAdp_parser date_parser = DateAdp_parser.new_();
|
||||
public Xob_xml_parser Tag_len_max_(int v) {tag_len_max = v; return this;} private int tag_len_max = 255; // max size of any (a) xml tag, (b) int or (c) date; everything else goes into a data_bfr
|
||||
|
||||
@@ -16,7 +16,8 @@ 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_xml_parser_tst {
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
|
||||
@@ -16,16 +16,23 @@ 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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.drds.pages.*;
|
||||
import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.files.gui.*;
|
||||
public class Xod_app {
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
private final Xod_file_mgr file_mgr = new Xod_file_mgr();
|
||||
public Xod_app(Xoav_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public Xod_page_itm Get_page(String wiki_domain, String page_ttl) {
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_key_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
public Xow_wiki Get_wiki(String wiki_domain) {
|
||||
return app.Wiki_mgri().Get_by_key_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
}
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, String page_ttl) {
|
||||
return page_mgr.Get_page(wiki, page_ttl);
|
||||
}
|
||||
public void Load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
file_mgr.Load_files(wiki, pg, js_wkr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public class Xod_app_tst {
|
||||
private final Xod_app_tstr tstr = new Xod_app_tstr();
|
||||
@Before public void init() {tstr.Init_mem();}
|
||||
@Test public void Get() {
|
||||
// tstr.Data_mgr().Page__insert(1, "A", "2015-10-19 00:01:02");
|
||||
// tstr.Data_mgr().Html__insert(1, "abc");
|
||||
// tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19 00:01:02", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
tstr.Data_mgr().Page__insert(1, "A", "2015-10-19 00:01:02");
|
||||
tstr.Data_mgr().Html__insert(1, "abc");
|
||||
tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19 00:01:02", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
}
|
||||
}
|
||||
class Xod_app_tstr {
|
||||
@@ -41,7 +41,8 @@ class Xod_app_tstr {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public void Test__get(String ttl, Xod_page_itm expd) {
|
||||
Xod_page_itm itm = drd_provider.Get_page("en.wikipedia.org", ttl);
|
||||
Xow_wiki wiki = drd_provider.Get_wiki("en.wikipedia.org");
|
||||
Xod_page_itm itm = drd_provider.Get_page(wiki, ttl);
|
||||
Tfds.Eq(expd.To_str(), itm.To_str());
|
||||
}
|
||||
public Xod_page_itm Make_page(int page_id, String ttl, String modified_on, Xoh_section_itm... section_ary) {
|
||||
|
||||
39
400_xowa/src/gplx/xowa/drds/files/Xod_file_mgr.java
Normal file
39
400_xowa/src/gplx/xowa/drds/files/Xod_file_mgr.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.drds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.core.threads.*;
|
||||
import gplx.xowa.drds.pages.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.htmls.*;
|
||||
public class Xod_file_mgr {
|
||||
private final Gfo_thread_pool thread_pool = new Gfo_thread_pool();
|
||||
public void Load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
Xoh_page hpg = pg.Hpg();
|
||||
List_adp img_list = To_img_list(hpg.Img_mgr());
|
||||
Xof_file_wkr img_wkr = new Xof_file_wkr(wiki.File__orig_mgr(), wiki.File__bin_mgr(), wiki.File__mnt_mgr(), wiki.App().User().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), js_wkr, hpg, img_list);
|
||||
thread_pool.Add_at_end(img_wkr);
|
||||
thread_pool.Run();
|
||||
}
|
||||
private static List_adp To_img_list(Xoh_img_mgr img_mgr) {
|
||||
List_adp rv = List_adp_.new_();
|
||||
int len = img_mgr.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(img_mgr.Get_at(i));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.drds.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
|
||||
import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xod_page_itm {
|
||||
public Xod_page_itm() {}
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public long Rev_id() {return rev_id;} private long rev_id;
|
||||
public String Ttl_text() {return ttl_text;} private String ttl_text;
|
||||
@@ -35,6 +34,7 @@ public class Xod_page_itm {
|
||||
public String Head_name() {return head_ttl;} private String head_ttl;
|
||||
public String First_allowed_editor_role() {return first_allowed_editor_role;} private String first_allowed_editor_role;
|
||||
public List_adp Section_list() {return section_list;} private List_adp section_list = List_adp_.new_();
|
||||
public Xoh_page Hpg() {return hpg;} private Xoh_page hpg;
|
||||
public void Init(int page_id, int rev_id
|
||||
, String ttl_text, String ttl_db, String redirected, String description, String modified_on
|
||||
, boolean is_editable, boolean is_main_page, boolean is_disambiguation, int lang_count
|
||||
@@ -46,8 +46,7 @@ public class Xod_page_itm {
|
||||
this.is_editable = is_editable; this.is_main_page = is_main_page; this.is_disambiguation = is_disambiguation; this.lang_count = lang_count;
|
||||
this.head_url = head_url; this.head_ttl= head_ttl; this.first_allowed_editor_role = first_allowed_editor_role;
|
||||
}
|
||||
public void Init() {}
|
||||
public void Init(Xoa_ttl ttl, Xowd_page_itm db_page) {
|
||||
public void Init_by_dbpg(Xoa_ttl ttl, Xowd_page_itm db_page) {
|
||||
this.page_id = db_page.Id();
|
||||
this.rev_id = page_id;
|
||||
this.ttl_text = String_.new_u8(ttl.Page_txt());
|
||||
@@ -63,6 +62,9 @@ public class Xod_page_itm {
|
||||
this.head_ttl = null;
|
||||
this.first_allowed_editor_role = null;
|
||||
}
|
||||
public void Init_by_hpg(Xoh_page hpg) {
|
||||
this.hpg = hpg;
|
||||
}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
bfr .Add_int_variable(page_id).Add_byte_pipe()
|
||||
|
||||
@@ -21,15 +21,17 @@ import gplx.xowa.htmls.*; import gplx.xowa.htmls.sections.*;
|
||||
public class Xod_page_mgr {
|
||||
public Xod_page_itm Get_page(Xow_wiki wiki, String page_ttl) {
|
||||
Xod_page_itm rv = new Xod_page_itm();
|
||||
|
||||
// load meta info like page_id, modified, etc
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(page_ttl));
|
||||
Xowd_page_itm dbpg = new Xowd_page_itm();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());
|
||||
rv.Init(ttl, dbpg);
|
||||
rv.Init_by_dbpg(ttl, dbpg);
|
||||
|
||||
// load page data
|
||||
Xoh_page hpg = new Xoh_page();
|
||||
hpg.Init(wiki, Xoa_url.new_(wiki.Domain_bry(), ttl.Page_db()), ttl, 1);
|
||||
rv.Init_by_hpg(hpg);
|
||||
wiki.Html__hdump_mgr().Load_mgr().Load(hpg, ttl);
|
||||
Load_sections(rv, hpg);
|
||||
return rv;
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.bits.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_img_size {
|
||||
public int Html_w() {return html_w;} private int html_w;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import org.junit.*; import gplx.core.bits.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_img_size_tst {
|
||||
private final Xof_img_size_fxt fxt = new Xof_img_size_fxt();
|
||||
@Before public void init() {
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.bits.*;
|
||||
public class Xof_patch_upright_tid_ {
|
||||
public static final int Tid_unpatched = 0, Tid_use_thumb_w = 1, Tid_fix_default = 2;
|
||||
public static final int Tid_all = Tid_use_thumb_w | Tid_fix_default;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
|
||||
class Xofc_dir_tbl implements RlsAble {
|
||||
class Xofc_dir_tbl implements Rls_able {
|
||||
private String tbl_name = "file_cache_dir"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_id, fld_name;
|
||||
private Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr(); private Db_stmt select_stmt;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
|
||||
class Xofc_fil_tbl implements RlsAble {
|
||||
class Xofc_fil_tbl implements Rls_able {
|
||||
private String tbl_name = "file_cache_fil"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_uid, fld_dir_id, fld_name, fld_is_orig, fld_w, fld_h, fld_time, fld_page, fld_ext, fld_size, fld_cache_time;
|
||||
private Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr(); private Db_stmt select_itm_stmt, select_itm_v2_stmt;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xou_cache_tbl implements RlsAble {
|
||||
public class Xou_cache_tbl implements Rls_able {
|
||||
private String tbl_name = "file_cache"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String
|
||||
fld_lnki_wiki_abrv, fld_lnki_ttl, fld_lnki_type, fld_lnki_upright, fld_lnki_w, fld_lnki_h, fld_lnki_time, fld_lnki_page, fld_user_thumb_w
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.commons; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xof_commons_image_tbl implements RlsAble {
|
||||
public class Xof_commons_image_tbl implements Rls_able {
|
||||
private Db_stmt stmt_insert;
|
||||
public Db_conn Conn() {return conn;}
|
||||
public void Conn_(Db_conn v) {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.dbs.*;
|
||||
public class Orig_fil_tbl implements RlsAble {
|
||||
public class Orig_fil_tbl implements Rls_able {
|
||||
private String tbl_name = "orig_fil"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_uid, fld_name, fld_ext_id, fld_w, fld_h, fld_dir_url;
|
||||
private Db_conn conn; private Db_stmt stmt_insert, stmt_select;
|
||||
|
||||
@@ -70,7 +70,7 @@ class Xof_file_fxt {
|
||||
List_adp itms_list = List_adp_.new_(); itms_list.Add(itm);
|
||||
orig_mgr.Find_by_list(Ordered_hash_.New_bry(), itms_list, Xof_exec_tid.Tid_wiki_page);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__main, ttl_bry);
|
||||
Xoae_page page = Xoae_page.new_(wiki, ttl);
|
||||
Xoae_page page = Xoae_page.New(wiki, ttl);
|
||||
fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
|
||||
if (arg.Rslt_orig_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_orig_exists() == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");
|
||||
if (arg.Rslt_file_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_file_exists() == Bool_.Y_byte, itm.File_exists(), "file_exists");
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
|
||||
public class Xof_orig_tbl implements RlsAble {
|
||||
public class Xof_orig_tbl implements Rls_able {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_repo, fld_ttl, fld_status, fld_ext, fld_w, fld_h, fld_redirect;
|
||||
private final Db_conn conn; private final Xof_orig_tbl__in_wkr select_in_wkr = new Xof_orig_tbl__in_wkr();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
|
||||
ini_src_fils();
|
||||
wiki.Appe().File_mgr().Wmf_mgr().Enabled_(true);
|
||||
wiki.File_mgr().Cfg_download().Enabled_(true);
|
||||
queue.Exec(wiki, Xoae_page.new_(wiki, wiki.Ttl_parse(Bry_.new_a7("A"))));
|
||||
queue.Exec(wiki, Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_a7("A"))));
|
||||
tst_trg_fils();
|
||||
if (this.html_orig_src != null) Tfds.Eq(this.html_orig_src , xfer_itm.Html_orig_url().To_http_file_str());
|
||||
if (this.Html_view_src() != null) Tfds.Eq(this.Html_view_src(), xfer_itm.Html_view_url().To_http_file_str());
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Xoa_gui_mgr implements GfoEvObj, GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_kit)) return kit;
|
||||
else if (ctx.Match(k, Invk_kit_)) this.kit = Gfui_kit_.Get_by_key(m.ReadStrOr("v", Gfui_kit_.Swt().Key()));
|
||||
else if (ctx.Match(k, Invk_run)) Run(RlsAble_.Null);
|
||||
else if (ctx.Match(k, Invk_run)) Run(Rls_able_.Null);
|
||||
else if (ctx.Match(k, Invk_browser_type)) kit.Cfg_set("HtmlBox", "BrowserType", gplx.gfui.Swt_kit.Cfg_Html_BrowserType_parse(m.ReadStr("v")));
|
||||
else if (ctx.Match(k, Invk_xul_runner_path_)) kit.Cfg_set("HtmlBox", "XulRunnerPath", Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("v")).Xto_api());
|
||||
else if (ctx.Match(k, Invk_bnds)) return bnd_mgr;
|
||||
@@ -94,7 +94,7 @@ public class Xoa_gui_mgr implements GfoEvObj, GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_menus)) return menu_mgr;
|
||||
else if (ctx.Match(k, Invk_cmds)) return cmd_mgr;
|
||||
else if (ctx.Match(k, Invk_url_macros)) return url_macro_mgr;
|
||||
else if (ctx.Match(k, Xoue_user.Evt_lang_changed)) Lang_changed((Xol_lang_itm)m.ReadObj("v", ParseAble_.Null));
|
||||
else if (ctx.Match(k, Xoue_user.Evt_lang_changed)) Lang_changed((Xol_lang_itm)m.ReadObj("v", null));
|
||||
else throw Err_.new_unhandled(k);
|
||||
return this;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class Xoa_gui_mgr implements GfoEvObj, GfoInvkAble {
|
||||
, Invk_main_win = "main_win", Invk_browser_win = "browser_win", Invk_bnds = "bnds"
|
||||
, Invk_bindings = "bindings", Invk_win_opts = "win_opts", Invk_layout = "layout", Invk_html = "html"
|
||||
, Invk_search_suggest = "search_suggest", Invk_menus = "menus", Invk_cmds = "cmds", Invk_url_macros = "url_macros";
|
||||
public void Run(RlsAble splash_win) {
|
||||
public void Run(Rls_able splash_win) {
|
||||
Gfo_log_bfr log_bfr = app.Log_bfr();
|
||||
try {
|
||||
Xoa_gui_mgr ui_mgr = app.Gui_mgr();
|
||||
|
||||
@@ -72,7 +72,7 @@ class Xog_history_stack_fxt {
|
||||
public Xog_history_stack_fxt Exec_add_one(String ttl_str, String arg_str) {
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
Xoae_page page = Xoae_page.test_(wiki, ttl);
|
||||
Xoae_page page = Xoae_page.New_test(wiki, ttl);
|
||||
byte[] url_bry = ttl_bry;
|
||||
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_u8(arg_str));
|
||||
Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(url_bry);
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.guis.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.net.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.doms.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.doms.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
public class Xog_url_wkr {
|
||||
private final Xoa_url tmp_url = Xoa_url.blank();
|
||||
@@ -60,12 +60,16 @@ public class Xog_url_wkr {
|
||||
}
|
||||
private Xoa_url Exec_url_file(Xoae_app app, Xowe_wiki cur_wiki, Xoae_page page, Xog_win_itm win, byte[] href_bry) { // EX: file:///xowa/A.png
|
||||
Xowe_wiki wiki = (Xowe_wiki)page.Commons_mgr().Source_wiki_or(cur_wiki);
|
||||
Io_url href_url = Io_url_.http_any_(String_.new_u8(gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode(href_bry)), Op_sys.Cur().Tid_is_wnt());
|
||||
Io_url href_url = Io_url_.http_any_(String_.new_u8(Gfo_url_encoder_.Http_url.Decode(href_bry)), Op_sys.Cur().Tid_is_wnt());
|
||||
gplx.gfui.Gfui_html html_box = win.Active_html_box();
|
||||
byte[] href_bry_encoded = Gfo_url_encoder_.Fsys_lnx.Encode(href_bry); // encode to href_bry; note must encode to same href_bry as Xof_url_bldr, which uses Gfo_url_encoder_.Fsys_lnx; PAGE:en.w:File:Volc<6C>n_Chimborazo,_"El_Taita_Chimborazo".jpg DATE:2015-12-06
|
||||
String xowa_ttl = wiki.Gui_mgr().Cfg_browser().Content_editable()
|
||||
? html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_for_editable_mode, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_str, null)
|
||||
: Xoh_dom_.Title_by_href(href_bry, Bry_.new_u8(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__root_html_get)));
|
||||
if (xowa_ttl == null) {app.Gui_mgr().Kit().Ask_ok("", "", "could not find find anchor with href in html: href=~{0}", href_bry); return Rslt_handled;}
|
||||
: Xoh_dom_.Title_by_href(href_bry_encoded, Bry_.new_u8(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__root_html_get)));
|
||||
if (xowa_ttl == null) {
|
||||
app.Gui_mgr().Kit().Ask_ok("", "", "could not find anchor with href in html: href=~{0}", href_bry);
|
||||
return Rslt_handled;
|
||||
}
|
||||
byte[] lnki_ttl = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode(Xoa_ttl.Replace_spaces(Bry_.new_u8(xowa_ttl)));
|
||||
Xof_fsdb_itm fsdb = Xof_orig_file_downloader.Make_fsdb(wiki, lnki_ttl, img_size, url_bldr);
|
||||
if (!Io_mgr.Instance.ExistsFil(href_url)) {
|
||||
|
||||
@@ -63,7 +63,7 @@ class Xog_launcher_tabs {
|
||||
Xoa_url launch_url = home_wiki.Utl__url_parser().Parse_by_urlbar_or_null(launch_str); if (launch_url == null) return;
|
||||
Xowe_wiki launch_wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_key_or_make_init_y(launch_url.Wiki_bry());
|
||||
Xoa_ttl launch_ttl = Xoa_ttl.parse(launch_wiki, launch_url.Page_bry());
|
||||
Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(launch_wiki, Xoae_page.new_(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23
|
||||
Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(launch_wiki, Xoae_page.New(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23
|
||||
tab.Show_url_bgn(launch_url);
|
||||
}
|
||||
public static final Xog_launcher_tabs Instance = new Xog_launcher_tabs(); Xog_launcher_tabs() {}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
wiki.Parser_mgr().Ctx().Cur_page_(page);
|
||||
if (page.Missing()) {
|
||||
if (wiki.Db_mgr().Save_mgr().Create_enabled()) {
|
||||
page = Xoae_page.create_(wiki, ttl);
|
||||
page = Xoae_page.New_edit(wiki, ttl);
|
||||
view_mode = Xopg_page_.Tid_edit;
|
||||
history_mgr.Add(page); // NOTE: must put new_page on stack so that pressing back will pop new_page, not previous page
|
||||
Xog_tab_itm_read_mgr.Show_page(this, page, false);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Xog_tab_itm_edit_mgr {
|
||||
Xog_html_itm html_itm = tab.Html_itm();
|
||||
|
||||
byte[] new_text = Get_new_text(tab);
|
||||
Xoae_page new_page = Xoae_page.new_(wiki, page.Ttl());
|
||||
Xoae_page new_page = Xoae_page.New(wiki, page.Ttl());
|
||||
new_page.Revision_data().Id_(page.Revision_data().Id()); // NOTE: page_id needed for sqlite (was not needed for xdat)
|
||||
new_page.Data_raw_(new_text);
|
||||
wiki.Parser_mgr().Parse(new_page, true); // refresh html
|
||||
@@ -102,7 +102,7 @@ public class Xog_tab_itm_edit_mgr {
|
||||
ctx.Defn_trace().Clear(); // TODO: move_me
|
||||
ctx.Defn_trace_(Xot_defn_trace_dbg.Instance);
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
Xoae_page new_page = Xoae_page.new_(wiki, ttl);
|
||||
Xoae_page new_page = Xoae_page.New(wiki, ttl);
|
||||
byte[] data = tab.Html_itm().Get_elem_value_for_edit_box_as_bry();
|
||||
new_page.Data_raw_(data);
|
||||
wiki.Parser_mgr().Parse(new_page, true);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
Xowe_wiki cur_wiki = active_tab_is_null ? win.App().Usere().Wiki() : active_tab.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(cur_wiki, Xows_special_meta_.Itm__default_tab.Ttl_bry());
|
||||
Xoa_url url = cur_wiki.Utl__url_parser().Parse_by_urlbar_or_null(ttl.Full_db_as_str()); if (url == null) throw Err_.new_("url", "invalid url", "url", url);
|
||||
Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null, cur_wiki, Xoae_page.new_(cur_wiki, ttl));
|
||||
Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null, cur_wiki, Xoae_page.New(cur_wiki, ttl));
|
||||
rv.Page_update_ui();
|
||||
rv.Show_url_bgn(url);
|
||||
return rv;
|
||||
@@ -218,7 +218,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
}
|
||||
public void Tabs_new_link(String link, boolean focus) {
|
||||
Xowe_wiki wiki = active_tab.Wiki();
|
||||
Xog_tab_itm new_tab = Tabs_new(focus, false, wiki, Xoae_page.new_(wiki, active_tab.Page().Ttl())); // NOTE: do not use ttl from link, else middle-clicking pages with anchors won't work; DATE:2015-05-03
|
||||
Xog_tab_itm new_tab = Tabs_new(focus, false, wiki, Xoae_page.New(wiki, active_tab.Page().Ttl())); // NOTE: do not use ttl from link, else middle-clicking pages with anchors won't work; DATE:2015-05-03
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse_by_urlbar_or_null(link); if (url == null) return; // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27
|
||||
new_tab.Show_url_bgn(url);
|
||||
if (focus)
|
||||
|
||||
@@ -77,7 +77,7 @@ public class Xog_error_win extends JFrame implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_send_mail)) {
|
||||
try {
|
||||
Gfo_url_encoder url_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_safe;
|
||||
Gfo_url_encoder url_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_wnt;
|
||||
String subject = url_encoder.Encode_str("XOWA boot error: " + error_data.Err_msg());
|
||||
String body = url_encoder.Encode_str(error_data.Err_details());
|
||||
Desktop.getDesktop().mail(new URI("mailto:gnosygnu+xowa_error_boot@gmail.com?subject=" + subject + "&body=" + body));
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.guis.views.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
public class Xog_splash_win implements RlsAble {
|
||||
public class Xog_splash_win implements Rls_able {
|
||||
private SplashScreen splash;
|
||||
private Graphics2D graphics; private boolean graphics_init = true;
|
||||
public Xog_splash_win(boolean app_mode_is_gui) {
|
||||
|
||||
@@ -55,6 +55,7 @@ public class Xoh_page implements Xoa_page {
|
||||
}
|
||||
public Xoh_page Ctor_by_page(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
this.page_id = page.Revision_data().Id();
|
||||
this.wiki = page.Wiki();
|
||||
this.body = page.Hdump_data().Body();
|
||||
this.page_url = page.Url();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
|
||||
@@ -153,11 +153,11 @@ public class Xoh_page_wtr_wkr {
|
||||
wiki.Html_mgr().Html_wtr().Write_all(tidy_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page.Root().Data_mid(), page.Root());
|
||||
|
||||
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, hctx, tidy_bfr);
|
||||
|
||||
// tidy html
|
||||
gplx.xowa.htmls.core.htmls.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
|
||||
if (tidy_mgr.Enabled()) tidy_mgr.Run_tidy_html(page, tidy_bfr);
|
||||
if (tidy_mgr.Enabled()) tidy_mgr.Run_tidy_html(page, tidy_bfr, !hctx.Mode_is_hdump());
|
||||
|
||||
// add back to main bfr
|
||||
bfr.Add_bfr_and_clear(tidy_bfr);
|
||||
|
||||
@@ -20,20 +20,20 @@ import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xohp_ctg_grp_mgr {
|
||||
final Bry_fmtr grp_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " ~{grp_lbl}"
|
||||
, " <ul>~{grp_itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "~{grp_lbl}"
|
||||
, "<ul>~{grp_itms}"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
), "grp_lbl", "grp_itms")
|
||||
;
|
||||
final Bry_fmtr itm_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li>"
|
||||
, " <a href=\"~{itm_href}\" class=\"internal\" title=\"~{itm_title}\">~{itm_text}</a>"
|
||||
, " </li>"
|
||||
( ""
|
||||
, "<li>"
|
||||
, "<a href=\"~{itm_href}\" class=\"internal\" title=\"~{itm_title}\">~{itm_text}</a>"
|
||||
, "</li>"
|
||||
), "itm_href", "itm_title", "itm_text"
|
||||
);
|
||||
Xoh_ctg_itm_fmtr itm_mgr = new Xoh_ctg_itm_fmtr();
|
||||
|
||||
@@ -23,17 +23,17 @@ public class Xohp_ctg_grp_mgr_tst {
|
||||
@Test public void Basic() {
|
||||
fxt.Init_ctgs("A", "B").Test_html(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " Categories"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "Categories"
|
||||
, "<ul>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
|
||||
, "</li>"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ public class Xow_html_mgr implements GfoInvkAble {
|
||||
Xoae_app app = wiki.Appe();
|
||||
page_wtr_mgr = new Xoh_page_wtr_mgr(app.Gui_mgr().Kit().Tid() != gplx.gfui.Gfui_kit_.Swing_tid); // reverse logic to handle swt,drd but not mem
|
||||
Io_url file_dir = app.Fsys_mgr().Bin_xowa_file_dir().GenSubDir_nest("mediawiki.file");
|
||||
img_media_play_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("magnify-clip.png"));
|
||||
img_xowa_protocol = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(app.Fsys_mgr().Bin_xowa_file_dir().GenSubFil_nest("app.general", "xowa_exec.png"));
|
||||
img_media_play_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx.Encode_to_file_protocol(file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx.Encode_to_file_protocol(file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx.Encode_to_file_protocol(file_dir.GenSubFil("magnify-clip.png"));
|
||||
img_xowa_protocol = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx.Encode_to_file_protocol(app.Fsys_mgr().Bin_xowa_file_dir().GenSubFil_nest("app.general", "xowa_exec.png"));
|
||||
portal_mgr = new Xow_portal_mgr(wiki);
|
||||
imgs_mgr = new Xoh_imgs_mgr(this);
|
||||
module_mgr = new Xow_module_mgr(wiki);
|
||||
|
||||
@@ -23,24 +23,27 @@ public class Xow_hdump_mgr {
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
|
||||
public Xow_hdump_mgr(Xow_wiki wiki) {
|
||||
this.save_mgr = new Xow_hdump_mgr__save(wiki, hzip_mgr, zip_mgr, tmp_hpg, tmp_bfr);
|
||||
this.save_mgr = new Xow_hdump_mgr__save(wiki, hzip_mgr, zip_mgr, tmp_hpg);
|
||||
this.load_mgr = new Xow_hdump_mgr__load(wiki, hzip_mgr, zip_mgr, tmp_hpg, tmp_bfr);
|
||||
}
|
||||
public Xow_hdump_mgr__save Save_mgr() {return save_mgr;} private Xow_hdump_mgr__save save_mgr;
|
||||
public Xow_hdump_mgr__load Load_mgr() {return load_mgr;} private Xow_hdump_mgr__load load_mgr;
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;} private final Xoh_hzip_mgr hzip_mgr = new Xoh_hzip_mgr();
|
||||
public void Init_by_db(Xow_wiki wiki) {
|
||||
byte default_zip_tid = gplx.core.ios.Io_stream_.Tid_raw;
|
||||
boolean default_hzip_enable = false;
|
||||
byte dflt_zip_tid = gplx.core.ios.Io_stream_.Tid_raw;
|
||||
boolean dflt_hzip_enable = false;
|
||||
boolean mode_is_b256 = false;
|
||||
if (wiki.Data__core_mgr() != null) { // TEST: handle null data mgr
|
||||
Xowd_core_db_props props = wiki.Data__core_mgr().Props();
|
||||
default_zip_tid = props.Zip_tid_html();
|
||||
default_hzip_enable = props.Hzip_enabled();
|
||||
dflt_zip_tid = props.Zip_tid_html();
|
||||
dflt_hzip_enable = props.Hzip_enabled();
|
||||
// dflt_hzip_enable = props.Hzip_enabled();
|
||||
// mode_is_b256 = true;
|
||||
}
|
||||
Init_by_db(default_zip_tid, default_hzip_enable);
|
||||
Init_by_db(dflt_zip_tid, dflt_hzip_enable, mode_is_b256);
|
||||
}
|
||||
public void Init_by_db(byte default_zip_tid, boolean default_hzip_enable) {
|
||||
int dflt_hzip_tid = default_hzip_enable ? Xoh_hzip_dict_.Hzip__v1 : Xoh_hzip_dict_.Hzip__none;
|
||||
save_mgr.Init_by_db(default_zip_tid, dflt_hzip_tid);
|
||||
public void Init_by_db(byte dflt_zip_tid, boolean dflt_hzip_enable, boolean mode_is_b256) {
|
||||
int dflt_hzip_tid = dflt_hzip_enable ? Xoh_hzip_dict_.Hzip__v1 : Xoh_hzip_dict_.Hzip__none;
|
||||
save_mgr.Init_by_db(dflt_zip_tid, dflt_hzip_tid, Bool_.N);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xow_hdump_mgr__load {
|
||||
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
public Xow_hdump_mgr__load(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys, wiki.Domain_bry());
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx, wiki.Domain_bry());
|
||||
}
|
||||
public Xoh_make_mgr Make_mgr() {return make_mgr;} private final Xoh_make_mgr make_mgr;
|
||||
public void Load(Xoae_page wpg) {
|
||||
@@ -45,13 +45,12 @@ public class Xow_hdump_mgr__load {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public byte[] Decode_as_bry(Bry_bfr bfr, Xoh_page hpg, byte[] src, boolean mode_is_diff) {hzip_mgr.Hctx().Mode_is_diff_(mode_is_diff); hzip_mgr.Decode(bfr, wiki, hpg, src); return bfr.To_bry_and_clear();}
|
||||
private byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
hzip_mgr.Decode(tmp_bfr.Clear(), wiki, hpg, src);
|
||||
src = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1)
|
||||
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
|
||||
return src;
|
||||
}
|
||||
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
|
||||
@@ -117,7 +117,7 @@ class Xodb_hdump_mgr__base_fxt {
|
||||
wiki = fxt.Wiki();
|
||||
page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
hdump_mgr = wiki.Html__hdump_mgr();
|
||||
hdump_mgr.Init_by_db(gplx.core.ios.Io_stream_.Tid_raw, false);
|
||||
hdump_mgr.Init_by_db(gplx.core.ios.Io_stream_.Tid_raw, false, false);
|
||||
}
|
||||
fxt.Reset();
|
||||
page.Revision_data().Id_(0);
|
||||
|
||||
@@ -16,16 +16,19 @@ 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.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.heads.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.heads.*;
|
||||
import gplx.core.ios.*; import gplx.core.primitives.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xow_hdump_mgr__save {
|
||||
private final Xow_wiki wiki; private final Xoh_hzip_mgr hzip_mgr; private final Io_stream_zip_mgr zip_mgr;
|
||||
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private Bool_obj_ref html_db_is_new = Bool_obj_ref.n_();
|
||||
private final Xoh_page tmp_hpg; private final Xoh_hzip_bfr tmp_bfr = Xoh_hzip_bfr.New_txt(32); private Bool_obj_ref html_db_is_new = Bool_obj_ref.n_();
|
||||
private int dflt_zip_tid, dflt_hzip_tid;
|
||||
public Xow_hdump_mgr__save(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
public Xow_hdump_mgr__save(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg;
|
||||
}
|
||||
public void Init_by_db(int dflt_zip_tid, int dflt_hzip_tid) {this.dflt_zip_tid = dflt_zip_tid; this.dflt_hzip_tid = dflt_hzip_tid;}
|
||||
public void Init_by_db(int dflt_zip_tid, int dflt_hzip_tid, boolean mode_is_b256) {
|
||||
this.dflt_zip_tid = dflt_zip_tid; this.dflt_hzip_tid = dflt_hzip_tid; tmp_bfr.Mode_is_b256_(mode_is_b256);
|
||||
}
|
||||
public byte[] Src_as_hzip() {return src_as_hzip;} private byte[] src_as_hzip;
|
||||
public int Save(Xoae_page page) {
|
||||
synchronized (tmp_hpg) {
|
||||
Bld_hdump(page);
|
||||
@@ -45,11 +48,9 @@ public class Xow_hdump_mgr__save {
|
||||
wiki.Html__wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // save as hdump_fmt
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear());
|
||||
}
|
||||
private static byte[] Write(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
hzip_mgr.Encode(bfr.Clear(), wiki, hpg, src);
|
||||
src = bfr.To_bry_and_clear();
|
||||
}
|
||||
private byte[] Write(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (hzip_tid != Xoh_hzip_dict_.Hzip__none) src = hzip_mgr.Encode_as_bry((Xoh_hzip_bfr)bfr.Clear(), wiki, hpg, src);
|
||||
src_as_hzip = src;
|
||||
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Zip((byte)zip_tid, src);
|
||||
return src;
|
||||
|
||||
@@ -16,22 +16,26 @@ 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.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.apps.apis.xowa.bldrs.imports.*;
|
||||
public class Xob_hdump_bldr implements GfoInvkAble {
|
||||
private boolean enabled, hzip_enabled, hzip_compare;
|
||||
private boolean enabled, hzip_enabled, hzip_diff, hzip_b256; private byte zip_tid = Byte_.Max_value_127;
|
||||
private Xowe_wiki wiki; private Xow_hdump_mgr hdump_mgr;
|
||||
private Xob_ns_to_db_mgr ns_to_db_mgr; int prv_row_len = 0;
|
||||
private Hzip_stat_tbl stats_tbl; private Hzip_stat_itm tmp_stat_itm;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
private Xoh_stat_tbl stats_tbl; private Xoh_stat_itm tmp_stat_itm;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
private boolean op_sys_is_wnt;
|
||||
public boolean Init(Xowe_wiki wiki, Db_conn make_conn) {
|
||||
if (!enabled) return false;
|
||||
this.wiki = wiki; this.hdump_mgr = wiki.Html__hdump_mgr(); this.tmp_stat_itm = hdump_mgr.Hzip_mgr().Hctx().Bicode__stat();
|
||||
this.stats_tbl = new Hzip_stat_tbl(make_conn);
|
||||
this.op_sys_is_wnt = gplx.core.envs.Op_sys.Cur().Tid_is_wnt();
|
||||
this.wiki = wiki; this.hdump_mgr = wiki.Html__hdump_mgr(); this.tmp_stat_itm = hdump_mgr.Hzip_mgr().Hctx().Hzip__stat();
|
||||
this.stats_tbl = new Xoh_stat_tbl(make_conn);
|
||||
Xoapi_import import_cfg = wiki.Appe().Api_root().Bldr().Wiki().Import();
|
||||
hdump_mgr.Init_by_db(import_cfg.Zip_tid_html(), hzip_enabled);
|
||||
if (zip_tid == Byte_.Max_value_127) zip_tid = import_cfg.Zip_tid_html();
|
||||
hdump_mgr.Init_by_db(zip_tid, hzip_enabled, hzip_b256);
|
||||
Xowd_db_mgr core_data_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(core_data_mgr.Db__core()), core_data_mgr, import_cfg.Html_db_max());
|
||||
Xob_ns_file_itm.Init_ns_bldr_data(Xowd_db_file_.Tid_html_data, wiki.Ns_mgr(), gplx.xowa.apps.apis.xowa.bldrs.imports.Xoapi_import.Ns_file_map__each);
|
||||
@@ -40,13 +44,11 @@ public class Xob_hdump_bldr implements GfoInvkAble {
|
||||
public void Insert(Xoae_page page) {
|
||||
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 in hdump mode
|
||||
byte[] html_orig_bry = tmp_bfr.To_bry_and_clear();
|
||||
page.Hdump_data().Body_(html_orig_bry); // write to body bry
|
||||
byte[] orig_bry = tmp_bfr.To_bry_and_clear();
|
||||
page.Hdump_data().Body_(orig_bry); // write to body bry
|
||||
Xowd_db_file html_db = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len); // get html_db
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, page), html_db, true); // save to db
|
||||
if (hzip_compare) {
|
||||
// Compare(html_orig_bry, hdump_mgr.Save_mgr());
|
||||
}
|
||||
if (hzip_diff) Hzip_exec(orig_bry);
|
||||
stats_tbl.Insert(tmp_hpg, tmp_stat_itm, page.Root().Root_src().length, tmp_hpg.Body().length, prv_row_len); // save stats
|
||||
}
|
||||
public void Bld_term() {this.Commit(); ns_to_db_mgr.Rls_all();}
|
||||
@@ -54,12 +56,21 @@ public class Xob_hdump_bldr implements GfoInvkAble {
|
||||
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 Hzip_exec(byte[] orig_bry) {
|
||||
byte[] expd_bry = op_sys_is_wnt ? Bry_.Replace(tmp_bfr, orig_bry, Byte_ascii.Cr_lf_bry, Byte_ascii.Nl_bry) : orig_bry;
|
||||
byte[] actl_bry = hdump_mgr.Load_mgr().Decode_as_bry(tmp_bfr, tmp_hpg, hdump_mgr.Save_mgr().Src_as_hzip(), Bool_.Y);
|
||||
byte[][] diff = Bry_diff_.Diff_1st_line(expd_bry, actl_bry);
|
||||
if (diff != null)
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", String_.Format("hzip diff: page={0} lhs='{1}' rhs='{2}'", tmp_hpg.Url_bry_safe(), diff[0], diff[1]));
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_zip_tid_)) zip_tid = m.ReadByte("v");
|
||||
else if (ctx.Match(k, Invk_hzip_enabled_)) hzip_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_compare_)) hzip_compare = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_diff_)) hzip_diff = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_b256_)) hzip_b256 = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_enabled_ = "enabled_", Invk_hzip_enabled_ = "hzip_enabled_", Invk_hzip_compare_ = "hzip_compare_";
|
||||
private static final String Invk_enabled_ = "enabled_", Invk_zip_tid_ = "zip_tid_", Invk_hzip_enabled_ = "hzip_enabled_", Invk_hzip_diff_ = "hzip_diff_", Invk_hzip_b256_ = "hzip_b256_";
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*;
|
||||
class Xob_link_dump_tbl implements RlsAble {
|
||||
class Xob_link_dump_tbl implements Rls_able {
|
||||
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")
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*; import gplx.core.brys.*;
|
||||
public class Xoh_page_tbl implements RlsAble {
|
||||
public class Xoh_page_tbl implements Rls_able {
|
||||
private final String tbl_name = "html"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_head_flag, fld_body_flag, fld_display_ttl, fld_content_sub, fld_sidebar_div, fld_body;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert, stmt_delete, stmt_update;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xoh_redlink_tbl implements RlsAble {
|
||||
public class Xoh_redlink_tbl implements Rls_able {
|
||||
private final String tbl_name = "html_redlink"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_redlink_uids;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert, stmt_delete, stmt_update;
|
||||
|
||||
@@ -17,12 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_wtr_ctx {
|
||||
Xoh_wtr_ctx(byte mode) {this.mode = mode;} private byte mode;
|
||||
Xoh_wtr_ctx(int mode) {this.mode = mode;}
|
||||
public int Mode() {return mode;} private final int mode;
|
||||
public boolean Mode_is_alt() {return mode == Mode_alt;}
|
||||
public boolean Mode_is_display_title() {return mode == Mode_display_title;}
|
||||
public boolean Mode_is_popup() {return mode == Mode_popup;}
|
||||
public boolean Mode_is_hdump() {return mode == Mode_hdump;}
|
||||
public static final byte Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4;
|
||||
public static final int Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4;
|
||||
public static final Xoh_wtr_ctx
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt)
|
||||
|
||||
@@ -37,9 +37,10 @@ public class Xoh_tidy_mgr implements GfoInvkAble {
|
||||
: (Xoh_tidy_wkr)wkr_tidy
|
||||
;
|
||||
}
|
||||
public void Run_tidy_html(Xoae_page page, Bry_bfr bfr) {
|
||||
public void Run_tidy_html(Xoae_page page, Bry_bfr bfr, boolean indent) {
|
||||
if (bfr.Len_eq_0()) return; // document is empty; do not exec b/c tidy will never generate files for 0 len files, and previous file will remain; DATE:2014-06-04
|
||||
Tidy_wrap(bfr);
|
||||
wkr.Indent_(indent);
|
||||
wkr.Exec_tidy(page, bfr);
|
||||
Tidy_unwrap(bfr);
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public interface Xoh_tidy_wkr {
|
||||
byte Tid();
|
||||
void Indent_(boolean v);
|
||||
void Exec_tidy(Xoae_page page, Bry_bfr bfr);
|
||||
}
|
||||
|
||||
@@ -38,5 +38,6 @@ public class Xoh_tidy_wkr_ {
|
||||
}
|
||||
class Xoh_tidy_wkr_null implements Xoh_tidy_wkr {
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_null;}
|
||||
public void Indent_(boolean v) {}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
public void tidy_init() {
|
||||
long bgn = Env_.TickCount();
|
||||
wtr = new ByteArrayOutputStream();
|
||||
System.setProperty("line.separator", "\n");
|
||||
tidy = new Tidy(); // obtain a new Tidy instance
|
||||
tidy.setInputEncoding("UTF-8"); // -utf8
|
||||
tidy.setOutputEncoding("UTF-8"); // -utf8
|
||||
@@ -55,6 +56,10 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Indent_(boolean v) {
|
||||
if (tidy == null) tidy_init(); // lazy create to skip tests
|
||||
tidy.setIndentContent(v);
|
||||
}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {
|
||||
if (tidy == null) tidy_init(); // lazy create to skip tests
|
||||
// int bfr_len = bfr.Len();
|
||||
|
||||
@@ -27,24 +27,26 @@ public class Xoh_tidy_wkr_tidy extends Process_adp implements Xoh_tidy_wkr { pr
|
||||
tidy_target = v.GenSubFil("tidy_target.html");
|
||||
return super.Tmp_dir_(v);
|
||||
}
|
||||
public void Indent_(boolean v) {Indent_val = v ? "y" : "n";}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {
|
||||
int bfr_len = bfr.Len();
|
||||
long bgn = Env_.TickCount();
|
||||
Io_mgr.Instance.SaveFilBfr(tidy_source, bfr); // saves bfr to source; clears bfr
|
||||
this.Run(tidy_source.Raw(), tidy_target.Raw()); // converts source to target
|
||||
this.Run(tidy_source.Raw(), tidy_target.Raw()); // converts source to target
|
||||
Io_mgr.Instance.LoadFilBryByBfr(tidy_target, bfr); // loads bfr by target
|
||||
if (bfr.Len_eq_0()) // something went wrong; load from source
|
||||
if (bfr.Len_eq_0()) // something went wrong; load from source
|
||||
Io_mgr.Instance.LoadFilBryByBfr(tidy_source, bfr); // loads bfr by target
|
||||
app.Usr_dlg().Log_many("", "", "tidy exec; elapsed=~{0} len=~{1}", Env_.TickCount_elapsed_in_frac(bgn), bfr_len);
|
||||
}
|
||||
public static final String Args_fmt = String_.Concat // see https://meta.wikimedia.org/wiki/Data_dumps; missing numeric-entities:yes; enclose-text: yes
|
||||
private static String Indent_val = "y";
|
||||
public static String Args_fmt = String_.Concat // see https://meta.wikimedia.org/wiki/Data_dumps; missing numeric-entities:yes; enclose-text: yes
|
||||
( "-utf8" // default is ascii
|
||||
, " --force-output y" // always generate output; do not fail on error
|
||||
, " --quiet y" // suppress command-line header
|
||||
, " --tidy-mark n" // do not add tidy watermark
|
||||
, " --doctype ''''" // set to empty else some wikis will show paragraph text with little vertical gap; PAGE:tr.b:
|
||||
, " --wrap 0" // default is 80; do not limit lines to 80 chars
|
||||
, " --indent y" // indent block levels
|
||||
, " --indent ", Indent_val // indent block levels
|
||||
, " --quote-nbsp y" // preserve nbsp as entities; do not convert to Unicode character 160
|
||||
, " --literal-attributes y" // do not alter whitespace chars in attributes
|
||||
, " --wrap-attributes n" // do not line-wrap attribute values (assume tidy will try to take a="b\nc" and change to a="b c" which may cause some fidelity issues?)
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Xoh_lnki_bldr {
|
||||
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, v); return this;}
|
||||
public Xoh_lnki_bldr Href_(Xow_wiki wiki, byte[] bry) {return Href_(wiki.Domain_bry(), wiki.Ttl_parse(bry));}
|
||||
public Xoh_lnki_bldr Href_(byte[] domain_bry, Xoa_ttl ttl) {
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, domain_bry, ttl, Bool_.Y);
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, Xoh_wtr_ctx.Mode_popup, domain_bry, ttl);
|
||||
this.href = tmp_bfr.To_bry_and_clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_lnki_wtr_utl {
|
||||
private final Xoa_app app; private final Xow_wiki wiki; private final Xoh_href_wtr href_wtr; private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
|
||||
public Xoh_lnki_wtr_utl(Xow_wiki wiki, Xoh_href_wtr href_wtr) {
|
||||
@@ -25,7 +25,7 @@ public class Xoh_lnki_wtr_utl {
|
||||
}
|
||||
public byte[] Bld_href(byte[] page) {return Bld_href(wiki.Domain_bry(), wiki.Ttl_parse(page));}
|
||||
public byte[] Bld_href(byte[] domain_bry, Xoa_ttl ttl) {
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, domain_bry, ttl, Bool_.Y);
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, Xoh_wtr_ctx.Mode_popup, domain_bry, ttl);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Bld_title(byte[] text) {
|
||||
|
||||
21
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_dict.java
Normal file
21
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_dict.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_hzip_dict {
|
||||
|
||||
}
|
||||
@@ -20,36 +20,15 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
public class Xoh_hzip_dict_ {
|
||||
public static final byte Escape = Byte_.By_int(27); // SERIALIZED: 27=escape byte
|
||||
public static final byte[] Escape_bry = Bry_.new_ints(27); // SERIALIZED
|
||||
private static final byte Base85_ascii = 33;
|
||||
public static final byte // SERIALIZED
|
||||
Tid__space = 0 + Base85_ascii
|
||||
, Tid__hdr = 1 + Base85_ascii
|
||||
, Tid__lnke = 2 + Base85_ascii
|
||||
, Tid__lnki = 3 + Base85_ascii
|
||||
, Tid__img = 4 + Base85_ascii
|
||||
, Tid__thm = 5 + Base85_ascii
|
||||
, Tid__gly = 6 + Base85_ascii
|
||||
, Tid__escape = 84 + Base85_ascii
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__escape = Bry_.new_ints(Escape, Tid__escape)
|
||||
, Bry__space = Bry_.new_ints(Escape, Tid__space)
|
||||
, Bry__hdr = Bry_.new_ints(Escape, Tid__hdr)
|
||||
, Bry__lnke = Bry_.new_ints(Escape, Tid__lnke)
|
||||
, Bry__lnki = Bry_.new_ints(Escape, Tid__lnki)
|
||||
, Bry__img = Bry_.new_ints(Escape, Tid__img)
|
||||
, Bry__thm = Bry_.new_ints(Escape, Tid__thm)
|
||||
, Bry__gly = Bry_.new_ints(Escape, Tid__gly)
|
||||
;
|
||||
public static final String
|
||||
Key__escape = "escape"
|
||||
, Key__space = "space"
|
||||
, Key__hdr = "hdr"
|
||||
, Key__lnke = "lnke"
|
||||
, Key__lnki = "lnki"
|
||||
, Key__img = "img"
|
||||
, Key__thm = "thm"
|
||||
, Key__gly = "gly"
|
||||
, Key__xnde = "xnde"
|
||||
;
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1;
|
||||
}
|
||||
|
||||
148
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int.java
Normal file
148
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.encoders.*;
|
||||
public class Xoh_hzip_int {
|
||||
private boolean mode_is_b256; private byte pad_byte; private byte[] prefix_ary;
|
||||
public Xoh_hzip_int Mode_is_b256_(boolean v) {
|
||||
mode_is_b256 = v;
|
||||
if (mode_is_b256) {
|
||||
pad_byte = Byte_.Zero;
|
||||
prefix_ary = prefix_ary__b256;
|
||||
}
|
||||
else {
|
||||
pad_byte = Byte_ascii.Bang;
|
||||
prefix_ary = prefix_ary__b085;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Encode(int reqd_len, Bry_bfr bfr, int val) {
|
||||
int calc_len = Calc_len(mode_is_b256, val);
|
||||
int full_len = Full_len(mode_is_b256, val, calc_len, reqd_len, B256__pow__ary);
|
||||
int hdr_adj = full_len == calc_len || full_len == reqd_len ? 0 : 1;
|
||||
int bfr_len = bfr.Len();
|
||||
bfr.Add_byte_repeat(pad_byte, full_len); // fill with 0s; asserts that underlying array will be large enough for following write
|
||||
byte[] bfr_bry = bfr.Bfr(); // NOTE: set bry reference here b/c Add_byte_repeat may create a new one
|
||||
if (mode_is_b256)
|
||||
Set_bry(val, bfr_bry, bfr_len + hdr_adj, reqd_len, calc_len, pad_byte, B256__pow__ary);
|
||||
else
|
||||
Base85_.Set_bry(val, bfr_bry, bfr_len + hdr_adj, reqd_len); // calc base85 val for val; EX: 7224 -> "uu"
|
||||
if (hdr_adj == 1)
|
||||
bfr_bry[bfr_len] = prefix_ary[full_len]; // write the hdr_byte; EX: 256 -> 253, 1, 0 where 253 is the hdr_byte
|
||||
}
|
||||
public int Decode(int reqd_len, byte[] src, int src_len, int src_bgn, Int_obj_ref pos_ref) {
|
||||
int radix = 256; byte offset = Byte_.Zero;
|
||||
boolean hdr_byte_exists = false;
|
||||
int full_len = 1; // default to 1
|
||||
byte b0 = src[src_bgn];
|
||||
if (mode_is_b256) {
|
||||
switch (b0) {
|
||||
case prefix__b256__2: full_len = 2; hdr_byte_exists = true; break;
|
||||
case prefix__b256__3: full_len = 3; hdr_byte_exists = true; break;
|
||||
case prefix__b256__4: full_len = 4; hdr_byte_exists = true; break;
|
||||
case prefix__b256__5: full_len = 5; hdr_byte_exists = true; break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
radix = 85; offset = Byte_ascii.Bang;
|
||||
switch (b0) {
|
||||
case Byte_ascii.Curly_bgn : full_len = 3; hdr_byte_exists = true; break;
|
||||
case Byte_ascii.Pipe : full_len = 4; hdr_byte_exists = true; break;
|
||||
case Byte_ascii.Curly_end : full_len = 5; hdr_byte_exists = true; break;
|
||||
case Byte_ascii.Tilde : full_len = 6; hdr_byte_exists = true; break;
|
||||
}
|
||||
}
|
||||
if (full_len < reqd_len) full_len = reqd_len; // len should be padded
|
||||
int src_end = src_bgn + full_len;
|
||||
pos_ref.Val_(src_end);
|
||||
if (hdr_byte_exists) ++src_bgn;
|
||||
return To_int_by_bry(src, src_bgn, src_end, offset, radix);
|
||||
}
|
||||
private static int Calc_len(boolean mode_is_b256, int v) {
|
||||
if (mode_is_b256) {
|
||||
if (v < B256__max__expd__1) return 1;
|
||||
else if (v < B256__max__expd__2) return 2;
|
||||
else if (v < B256__max__expd__3) return 3;
|
||||
else return 4;
|
||||
}
|
||||
else
|
||||
return Base85_.Bry_len(v);
|
||||
}
|
||||
private static int Full_len(boolean mode_is_b256, int v, int calc_len, int reqd_len, int[] pow_ary) {
|
||||
int reqd_max = v;
|
||||
if (mode_is_b256) {
|
||||
reqd_max = B256__pow__ary[reqd_len]; // EX: if reqd_len = 2, then reqd_max = 65536
|
||||
int hdr_byte_adj = 1; // default to hdr_byte
|
||||
if ( calc_len == reqd_len // only do this check if calc_len == reqd_len; i.e.: reqd_len = 2; only want to check values that would be represented with two digits where 1st digit might be 252-255; EX: 64512 is "252, 0" but 252 is reserverd; instead "253, 252, 0"
|
||||
&& v < (reqd_max - (4 * B256__pow__ary[calc_len - 1])) // calculates if current value will produce a 252-255 range in the 1st byte; note that 4 is for 255-252
|
||||
) {
|
||||
hdr_byte_adj = 0;
|
||||
}
|
||||
return calc_len + hdr_byte_adj;
|
||||
}
|
||||
else {
|
||||
reqd_max = Base85_.Pow85[reqd_len];
|
||||
if (v < reqd_max) return reqd_len;
|
||||
if (v < Base85_.Pow85[2]) return 3;
|
||||
else if (v < Base85_.Pow85[3]) return 4;
|
||||
else if (v < Base85_.Pow85[4]) return 5;
|
||||
else return 6;
|
||||
}
|
||||
}
|
||||
private static void Set_bry(int val, byte[] src, int src_bgn, int reqd_len, int calc_len, byte pad_byte, int[] pow_ary) {
|
||||
int val_len = -1, pad_len = -1;
|
||||
boolean pad = calc_len < reqd_len;
|
||||
if (pad) {
|
||||
val_len = reqd_len;
|
||||
pad_len = reqd_len - calc_len;
|
||||
}
|
||||
else {
|
||||
val_len = calc_len;
|
||||
pad_len = 0;
|
||||
}
|
||||
if (pad) {
|
||||
for (int i = 0; i < pad_len; i++) // fill src with pad_len
|
||||
src[i + src_bgn] = pad_byte;
|
||||
}
|
||||
for (int i = val_len - pad_len; i > 0; --i) {
|
||||
int div = pow_ary[i - 1];
|
||||
byte tmp = (byte)(val / div);
|
||||
src[src_bgn + val_len - i] = (byte)(tmp + pad_byte);
|
||||
val -= tmp * div;
|
||||
}
|
||||
}
|
||||
private static int To_int_by_bry(byte[] src, int bgn, int end, byte offset, int radix) {
|
||||
int rv = 0, factor = 1;
|
||||
for (int i = end - 1; i >= bgn; --i) {
|
||||
rv += ((src[i] & 0xFF) - offset) * factor; // PATCH.JAVA:need to convert to unsigned byte
|
||||
factor *= radix;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static final int
|
||||
B256__max__expd__1 = 256 // 256
|
||||
, B256__max__expd__2 = 65536 // 65,536
|
||||
, B256__max__expd__3 = 16777216 // 16,777,216
|
||||
;
|
||||
private static final int[] B256__pow__ary = new int[] {1, B256__max__expd__1, B256__max__expd__2, B256__max__expd__3, Int_.Max_value};
|
||||
private static final byte prefix__b256__2 = (byte)(252 & 0xFF), prefix__b256__3 = (byte)(253 & 0xFF), prefix__b256__4 = (byte)(254 & 0xFF), prefix__b256__5 = (byte)(255 & 0xFF);
|
||||
private static final byte[]
|
||||
prefix_ary__b256 = new byte[] {0, 0, prefix__b256__2, prefix__b256__3, prefix__b256__4, prefix__b256__5}
|
||||
, prefix_ary__b085 = new byte[] {0, 0, 0, Byte_ascii.Curly_bgn, Byte_ascii.Pipe, Byte_ascii.Curly_end, Byte_ascii.Tilde}
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_hzip_int_tst {
|
||||
private final Xoh_hzip_int_fxt fxt = new Xoh_hzip_int_fxt();
|
||||
@Test public void B256__reqd__1() {
|
||||
fxt.Init__b256();
|
||||
fxt.Test__b256(1, 0 , 0);
|
||||
fxt.Test__b256(1, 252 , 252, 252);
|
||||
fxt.Test__b256(1, 253 , 252, 253);
|
||||
fxt.Test__b256(1, 254 , 252, 254);
|
||||
fxt.Test__b256(1, 255 , 252, 255);
|
||||
fxt.Test__b256(1, 256 , 253, 1, 0);
|
||||
fxt.Test__b256(1, 65535 , 253, 255, 255);
|
||||
fxt.Test__b256(1, 65536 , 254, 1, 0, 0);
|
||||
fxt.Test__b256(1, 16777216 , 255, 1, 0, 0, 0);
|
||||
}
|
||||
@Test public void B256__reqd__2() {
|
||||
fxt.Init__b256();
|
||||
fxt.Test__b256(2, 0 , 0, 0);
|
||||
fxt.Test__b256(2, 252 , 0, 252);
|
||||
fxt.Test__b256(2, 253 , 0, 253);
|
||||
fxt.Test__b256(2, 254 , 0, 254);
|
||||
fxt.Test__b256(2, 255 , 0, 255);
|
||||
fxt.Test__b256(2, 256 , 1, 0);
|
||||
fxt.Test__b256(2, 64511 , 251, 255);
|
||||
fxt.Test__b256(2, 64512 , 253, 252, 0);
|
||||
fxt.Test__b256(2, 65535 , 253, 255, 255);
|
||||
fxt.Test__b256(2, 65536 , 254, 1, 0, 0);
|
||||
fxt.Test__b256(2, 16777216 , 255, 1, 0, 0, 0);
|
||||
}
|
||||
@Test public void B085__reqd__1() {
|
||||
fxt.Init__b085();
|
||||
fxt.Test__b085(1, 0, "!");
|
||||
fxt.Test__b085(1, 84, "u");
|
||||
fxt.Test__b085(1, 85, "{\"!");
|
||||
fxt.Test__b085(1, 7225, "|\"!!");
|
||||
fxt.Test__b085(1, 614125, "}\"!!!");
|
||||
fxt.Test__b085(1, 52200625, "~\"!!!!");
|
||||
}
|
||||
@Test public void B085__reqd__2() {
|
||||
fxt.Init__b085();
|
||||
fxt.Test__b085(2, 0, "!!");
|
||||
fxt.Test__b085(2, 84, "!u");
|
||||
fxt.Test__b085(2, 85, "\"!");
|
||||
fxt.Test__b085(2, 7225, "|\"!!");
|
||||
fxt.Test__b085(2, 614125, "}\"!!!");
|
||||
fxt.Test__b085(2, 52200625, "~\"!!!!");
|
||||
}
|
||||
}
|
||||
class Xoh_hzip_int_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final gplx.core.primitives.Int_obj_ref count_ref = gplx.core.primitives.Int_obj_ref.neg1_();
|
||||
private final Xoh_hzip_int hzint = new Xoh_hzip_int();
|
||||
public void Init__b256() {hzint.Mode_is_b256_(Bool_.Y);}
|
||||
public void Init__b085() {hzint.Mode_is_b256_(Bool_.N);}
|
||||
public void Test__b256(int reqd, int val, int... expd_ints) {
|
||||
hzint.Encode(reqd, bfr, val);
|
||||
byte[] actl = bfr.To_bry_and_clear();
|
||||
byte[] expd = Byte_.Ary_by_ints(expd_ints);
|
||||
Tfds.Eq_ary(expd, actl, Int_.To_str(val));
|
||||
Tfds.Eq(val, hzint.Decode(reqd, actl, actl.length, 0, count_ref));
|
||||
}
|
||||
public void Test__b085(int reqd, int val, String expd) {
|
||||
hzint.Encode(reqd, bfr, val);
|
||||
byte[] actl = bfr.To_bry_and_clear();
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
Tfds.Eq(val, hzint.Decode(reqd, actl, actl.length, 0, count_ref));
|
||||
}
|
||||
}
|
||||
@@ -16,43 +16,57 @@ 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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_hzip_mgr {
|
||||
private final Xoh_hdoc_parser hdoc_parser = new Xoh_hdoc_parser(new Xoh_hdoc_wkr__hzip());
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hzip_mgr implements Xoh_hzip_wkr {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr = new Xoh_hdoc_wkr__hzip();
|
||||
private final Xoh_hdoc_parser hdoc_parser;
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Xoh_hzip_dict_.Escape);
|
||||
public Xoh_hzip_mgr() {this.hdoc_parser = new Xoh_hdoc_parser(hdoc_wkr);}
|
||||
public String Key() {return "root";}
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public Xoh_hdoc_ctx Hctx() {return hctx;} private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
public void Init_by_app(Xoa_app app) {hctx.Init_by_app(app);}
|
||||
public void Encode(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
public byte[] Encode_as_bry(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {Encode(bfr, wiki, hpg, src); return bfr.To_bry_and_clear();}
|
||||
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {throw Err_.new_unimplemented();}
|
||||
public void Encode(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
hctx.Init_by_page(wiki, hpg.Url_bry_safe());
|
||||
hdoc_parser.Parse(bfr, hpg, hctx, src);
|
||||
}
|
||||
public void Decode(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
byte[] page_url = hpg.Url_bry_safe();
|
||||
byte[] page_url = hpg.Url_bry_safe(); int src_len = src.length;
|
||||
hctx.Init_by_page(wiki, page_url);
|
||||
int pos = 0, txt_bgn = -1, src_len = src.length;
|
||||
rdr.Init_by_page(page_url, src, src_len);
|
||||
while (pos < src_len) {
|
||||
if (src[pos] == Xoh_hzip_dict_.Escape) {
|
||||
if (txt_bgn != -1) {bfr.Add_mid(src, txt_bgn, pos); txt_bgn = -1;} // handle pending txt
|
||||
int nxt_pos = pos + 1; if (nxt_pos == src_len) break; // handle escape at end of document
|
||||
Xoh_hzip_wkr wkr = hctx.Mkr().Hzip__wkr(src[nxt_pos]);
|
||||
try {
|
||||
rdr.Init_by_hook(wkr.Key(), pos, pos + 2);
|
||||
wkr.Decode(bfr, Bool_.Y, hctx, hpg, rdr, src, pos);
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
wkr.Pool__rls();
|
||||
gplx.langs.htmls.Html_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
|
||||
pos += 2; // 2: skip escape and hook
|
||||
}
|
||||
}
|
||||
else {
|
||||
Decode(bfr, hdoc_wkr, hctx, hpg, Bool_.Y, rdr, src, 0, src_len);
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
|
||||
int pos = src_bgn, txt_bgn = -1;
|
||||
while (true) {
|
||||
if (pos == src_end) break;
|
||||
byte b = src[pos];
|
||||
Object o = hctx.Wkr_mkr().Get(b, src, pos, src_end);
|
||||
if (o == null) {
|
||||
if (txt_bgn == -1) txt_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
if (txt_bgn != -1) {bfr.Add_mid(src, txt_bgn, pos); txt_bgn = -1;} // handle pending txt
|
||||
Xoh_hzip_wkr wkr = (Xoh_hzip_wkr)o;
|
||||
try {
|
||||
rdr.Init_by_sect(wkr.Key(), pos, pos + 2);
|
||||
wkr.Decode(bfr, hdoc_wkr, hctx, hpg, Bool_.Y, rdr, src, pos, src_end);
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
gplx.langs.htmls.Html_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
|
||||
pos += 2; // 2: skip escape and hook
|
||||
}
|
||||
finally {wkr.Pool__rls();}
|
||||
}
|
||||
}
|
||||
if (txt_bgn != -1) bfr.Add_mid(src, txt_bgn, src_len);
|
||||
}
|
||||
if (txt_bgn != -1) bfr.Add_mid(src, txt_bgn, src_end);
|
||||
return src_end;
|
||||
}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hzip_mgr rv = new Xoh_hzip_mgr(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ 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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public interface Xoh_hzip_wkr extends gplx.core.threads.poolables.Gfo_poolable_itm {
|
||||
String Key();
|
||||
int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr parser, byte[] src, int hook_bgn);
|
||||
byte[] Hook();
|
||||
Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj);
|
||||
int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.btries.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.wkrs.escapes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
|
||||
public class Xoh_hzip_wkr_mgr {
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private Gfo_poolable_mgr mkr__escape, mkr__lnke, mkr__lnki, mkr__hdr, mkr__img, mkr__thm, mkr__gly;
|
||||
public Xoh_escape_hzip Mw__escape() {return (Xoh_escape_hzip) mkr__escape.Get_fast();}
|
||||
public Xoh_hdr_hzip Mw__hdr() {return (Xoh_hdr_hzip) mkr__hdr.Get_fast();}
|
||||
public Xoh_lnke_hzip Mw__lnke() {return (Xoh_lnke_hzip) mkr__lnke.Get_fast();}
|
||||
public Xoh_lnki_hzip Mw__lnki() {return (Xoh_lnki_hzip) mkr__lnki.Get_fast();}
|
||||
public Xoh_img_hzip Mw__img() {return (Xoh_img_hzip) mkr__img.Get_fast();}
|
||||
public Xoh_thm_hzip Mw__thm() {return (Xoh_thm_hzip) mkr__thm.Get_fast();}
|
||||
public Xoh_gly_hzip Mw__gly() {return (Xoh_gly_hzip) mkr__gly.Get_fast();}
|
||||
public void Init() {
|
||||
this.Reg_all(false, Byte_ascii.Escape);
|
||||
}
|
||||
public Xoh_hzip_wkr Get(byte b, byte[] src, int src_bgn, int src_end) {
|
||||
Object mgr_obj = trie.Match_bgn_w_byte(b, src, src_bgn, src_end); if (mgr_obj == null) return null;
|
||||
Gfo_poolable_mgr mgr = (Gfo_poolable_mgr)mgr_obj;
|
||||
return (Xoh_hzip_wkr)mgr.Get_fast();
|
||||
}
|
||||
private void Reg_all(boolean mode_is_b256, int escape__mw) {
|
||||
mkr__escape = Reg(New_hook_len2(mode_is_b256, escape__mw, 84), new Xoh_escape_hzip());
|
||||
mkr__hdr = Reg(New_hook_len2(mode_is_b256, escape__mw, 1), new Xoh_hdr_hzip());
|
||||
mkr__lnke = Reg(New_hook_len2(mode_is_b256, escape__mw, 2), new Xoh_lnke_hzip());
|
||||
mkr__lnki = Reg(New_hook_len2(mode_is_b256, escape__mw, 3), new Xoh_lnki_hzip());
|
||||
mkr__img = Reg(New_hook_len2(mode_is_b256, escape__mw, 4), new Xoh_img_hzip());
|
||||
mkr__thm = Reg(New_hook_len2(mode_is_b256, escape__mw, 5), new Xoh_thm_hzip());
|
||||
mkr__gly = Reg(New_hook_len2(mode_is_b256, escape__mw, 6), new Xoh_gly_hzip());
|
||||
}
|
||||
private Gfo_poolable_mgr Reg(byte[] hook, Gfo_poolable_itm proto) {
|
||||
Gfo_poolable_mgr rv = Gfo_poolable_mgr_.New(1, 32, proto, Object_.Ary(hook));
|
||||
trie.Add_obj(hook, rv);
|
||||
return rv;
|
||||
}
|
||||
private static byte[] New_hook_len2(boolean mode_is_b256, int b0, int b1) {
|
||||
return Bry_.new_ints(b0, mode_is_b256 ? b1 : b1 + Byte_ascii.Bang);
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,14 @@ 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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Hzip_stat_itm {
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
public class Xoh_stat_itm {
|
||||
public void Clear() {
|
||||
a_rhs = lnki_text_n = lnki_text_y = lnke__free = lnke__auto = lnke__text = 0;
|
||||
hdr_1 = hdr_2 = hdr_3 = hdr_4 = hdr_5 = hdr_6 = 0;
|
||||
img_full = 0;
|
||||
space = 0;
|
||||
escape = 0;
|
||||
Bry_.Clear(escape_bry);
|
||||
}
|
||||
public int A_rhs() {return a_rhs;} public void A_rhs_add() {++a_rhs;} private int a_rhs;
|
||||
public int Lnki_text_n() {return lnki_text_n;} public void Lnki_text_n_add() {++lnki_text_n;} private int lnki_text_n;
|
||||
@@ -38,7 +39,7 @@ public class Hzip_stat_itm {
|
||||
public int Hdr_5() {return hdr_5;} private int hdr_5;
|
||||
public int Hdr_6() {return hdr_6;} private int hdr_6;
|
||||
public int Space() {return space;} public void Space_add(int v) {space += v;} private int space;
|
||||
public int Escape() {return escape;} public void Escape_add_one() {++escape;} private int escape;
|
||||
public byte[] Escape_bry() {return escape_bry;} public void Escape_add(byte v) {escape_bry[v] += 1;} private final byte[] escape_bry = new byte[256];
|
||||
public void Hdr_add(int hdr_num) {
|
||||
switch (hdr_num) {
|
||||
case 1: ++hdr_1; break;
|
||||
@@ -50,4 +51,13 @@ public class Hzip_stat_itm {
|
||||
default: throw Err_.new_unhandled(hdr_num);
|
||||
}
|
||||
}
|
||||
public void Lnki_add(int orig_len, int hzip_len, int flag) {
|
||||
}
|
||||
public void Lnke_add(byte lnke_type) {
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free: ++lnke__free; break;
|
||||
case Xoh_lnke_dict_.Type__auto: ++lnke__auto; break;
|
||||
case Xoh_lnke_dict_.Type__text: ++lnke__text; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Hzip_stat_tbl implements RlsAble {
|
||||
public class Xoh_stat_tbl implements Rls_able {
|
||||
private static final String tbl_name = "hdump_stats"; private static final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private static final String
|
||||
fld_page_id = flds.Add_int_pkey("page_id"), fld_wtxt_len = flds.Add_int("wtxt_len"), fld_row_orig_len = flds.Add_int("row_orig_len"), fld_row_zip_len = flds.Add_int("row_zip_len")
|
||||
@@ -30,7 +30,7 @@ public class Hzip_stat_tbl implements RlsAble {
|
||||
, fld_img_full = flds.Add_int("img_full")
|
||||
;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Hzip_stat_tbl(Db_conn conn) {
|
||||
public Xoh_stat_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.Create_tbl();
|
||||
conn.Stmt_delete(tbl_name).Exec_delete(); // always zap table
|
||||
@@ -40,7 +40,7 @@ public class Hzip_stat_tbl implements RlsAble {
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
public void Insert(Xoh_page hpg, Hzip_stat_itm hzip, int wtxt_len, int row_orig_len, int row_zip_len) {
|
||||
public void Insert(Xoh_page hpg, Xoh_stat_itm hzip, int wtxt_len, int row_orig_len, int row_zip_len) {
|
||||
Xopg_module_mgr js_mgr = hpg.Head_mgr();
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear()
|
||||
@@ -23,7 +23,7 @@ import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xow
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_make_mgr {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr_old bry_rdr = new Bry_rdr_old(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private final Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(255); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr_old bry_rdr = new Bry_rdr_old(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private Xoh_cfg_file cfg_file; private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
|
||||
private final byte[] root_dir, file_dir; private byte[] file_dir_comm, file_dir_wiki, hiero_img_dir; private final byte[] wiki_domain;
|
||||
private final Bry_rdr parser = new Bry_rdr();
|
||||
|
||||
@@ -16,7 +16,8 @@ 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.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.wkrs.mkrs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.metas.*;
|
||||
public class Xoh_hdoc_ctx {
|
||||
@@ -27,29 +28,34 @@ public class Xoh_hdoc_ctx {
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public byte[] Wiki__domain_bry() {return wiki__domain_bry;} private byte[] wiki__domain_bry;
|
||||
public Xow_ttl_parser Wiki__ttl_parser() {return wiki__ttl_parser;} private Xow_ttl_parser wiki__ttl_parser;
|
||||
public Xoa_url_parser Wiki__url_parser() {return wiki__url_parser;} private Xoa_url_parser wiki__url_parser;
|
||||
public boolean Xwiki_mgr__missing(byte[] domain){return app.Xwiki_mgr__missing(domain);}
|
||||
public Xoa_file_mgr File__mgr() {return file__mgr;} private final Xoa_file_mgr file__mgr = new Xoa_file_mgr();
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private Xof_url_bldr file__url_bldr = new Xof_url_bldr();
|
||||
public Xoh_hdoc_mkr Mkr() {return mkr;} private Xoh_hdoc_mkr mkr = new Xoh_hdoc_mkr();
|
||||
public byte[] Page__url() {return page__url;} private byte[] page__url;
|
||||
public Hzip_stat_itm Bicode__stat() {return bicode__stat;} private final Hzip_stat_itm bicode__stat = new Hzip_stat_itm();
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private final Xof_url_bldr file__url_bldr = new Xof_url_bldr();
|
||||
public Xoh_hzip_wkr_mgr Wkr_mkr() {return wkr_mgr;} private final Xoh_hzip_wkr_mgr wkr_mgr = new Xoh_hzip_wkr_mgr();
|
||||
public byte[] Page__url() {return page__url;} private byte[] page__url;
|
||||
public Xoh_stat_itm Hzip__stat() {return hzip__stat;} private final Xoh_stat_itm hzip__stat = new Xoh_stat_itm();
|
||||
public int Lnki__uid__nxt() {return ++lnki__uid;} private int lnki__uid; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
public boolean Mode_is_diff() {return mode_is_diff;} private boolean mode_is_diff; public void Mode_is_diff_(boolean v) {mode_is_diff = v;}
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
this.app = app;
|
||||
this.fsys__root = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.fsys__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.fsys__file__comm = Bry_.Add(fsys__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
wkr_mgr.Init();
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki, byte[] page_url) {
|
||||
if (fsys__root == null) Init_by_app(wiki.App()); // LAZY INIT
|
||||
this.wiki__url_parser = wiki.Utl__url_parser();
|
||||
this.wiki__ttl_parser = wiki;
|
||||
this.wiki__domain_bry = wiki.Domain_bry();
|
||||
this.fsys__file__wiki = Bry_.Add(fsys__file, wiki__domain_bry, Byte_ascii.Slash_bry);
|
||||
this.page__url = page_url;
|
||||
this.Clear();
|
||||
}
|
||||
}
|
||||
private void Clear() {
|
||||
bicode__stat.Clear();
|
||||
hzip__stat.Clear();
|
||||
this.lnki__uid = 1; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
}
|
||||
public static final int Invalid = -1;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.wkrs.tags.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
|
||||
import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.wkrs.tags.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*;
|
||||
public class Xoh_hdoc_parser {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
private final Html_doc_parser hdoc_parser;
|
||||
@@ -27,11 +27,10 @@ public class Xoh_hdoc_parser {
|
||||
this.tag_parser = new Xoh_tag_parser(hdoc_wkr);
|
||||
this.hdoc_parser = new Html_doc_parser(new Xoh_txt_parser(hdoc_wkr)
|
||||
, tag_parser
|
||||
, new Xoh_escape_parser(hdoc_wkr)
|
||||
, new Xoh_space_parser(hdoc_wkr)
|
||||
, new Xoh_escape_data(hdoc_wkr)
|
||||
);
|
||||
}
|
||||
public void Parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src) {
|
||||
public void Parse(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src) {
|
||||
int src_len = src.length;
|
||||
tag_parser.Init(hctx, src, 0, src_len);
|
||||
hdoc_wkr.On_new_page(bfr, hpg, hctx, src, 0, src_len);
|
||||
|
||||
@@ -19,14 +19,13 @@ package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public interface Xoh_hdoc_wkr {
|
||||
void On_new_page(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end);
|
||||
void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end);
|
||||
void On_escape (int rng_bgn, int rng_end);
|
||||
void On_txt (int rng_bgn, int rng_end);
|
||||
void On_space (int rng_bgn, int rng_end);
|
||||
void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg);
|
||||
void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg);
|
||||
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg);
|
||||
void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg);
|
||||
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg);
|
||||
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg);
|
||||
void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser);
|
||||
void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser);
|
||||
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser);
|
||||
void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser);
|
||||
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser);
|
||||
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser);
|
||||
}
|
||||
|
||||
@@ -19,19 +19,19 @@ package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
private Bry_bfr bfr; private Xoh_hdoc_ctx hctx; private byte[] src; private int src_end;
|
||||
public void On_new_page(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hctx = hctx; this.src = src; this.src_end = src_end;
|
||||
private final Xoh_stat_itm stat_itm = new Xoh_stat_itm();
|
||||
private Xoh_hzip_bfr bfr; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private Xoh_page hpg;
|
||||
public void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
|
||||
stat_itm.Clear();
|
||||
}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_escape (int rng_bgn, int rng_end) {hctx.Mkr().Escape__hzip().Encode(bfr, stat_itm).Pool__rls();}
|
||||
public void On_space (int rng_bgn, int rng_end) {hctx.Mkr().Space__hzip().Encode(bfr, stat_itm, src, src_end, rng_bgn, rng_end).Pool__rls();}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg) {hctx.Mkr().Hdr__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg) {hctx.Mkr().Lnke__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {hctx.Mkr().Lnki__hzip().Encode(bfr, hctx, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {hctx.Mkr().Thm__hzip().Encode(bfr, this, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {hctx.Mkr().Img__hzip().Encode(bfr, stat_itm, src, arg, Bool_.Y).Pool__rls();}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg) {hctx.Mkr().Gly__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_escape (int rng_bgn, int rng_end) {hctx.Wkr_mkr().Mw__escape().Encode(bfr, this, hctx, hpg, Bool_.Y, src, null).Pool__rls();}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser) {hctx.Wkr_mkr().Mw__hdr().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser) {hctx.Wkr_mkr().Mw__lnke().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser) {hctx.Wkr_mkr().Mw__lnki().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser) {hctx.Wkr_mkr().Mw__img().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser) {hctx.Wkr_mkr().Mw__thm().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser) {hctx.Wkr_mkr().Mw__gly().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,18 @@ import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
private Bry_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private Xoh_hzip_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private final Xoh_hdr_make wkr__hdr = new Xoh_hdr_make();
|
||||
private final Xoh_img_bldr wkr__img = new Xoh_img_bldr();
|
||||
public void On_new_page(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
public void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
|
||||
}
|
||||
public void On_escape (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_space (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg) {wkr__hdr.Make(bfr, hpg, src, arg);}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {wkr__img.Make_by_parse(bfr, hpg, hctx, src, arg);}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg) {}
|
||||
public void On_escape (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser) {wkr__hdr.Make(bfr, hpg, src, parser);}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser) {wkr__img.Make_by_parse(bfr, hpg, hctx, src, parser);}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser) {}
|
||||
}
|
||||
|
||||
38
400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_bfr.java
Normal file
38
400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_bfr.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_hzip_bfr extends Bry_bfr { private final Xoh_hzip_int hzint = new Xoh_hzip_int();
|
||||
private final byte stop_byte;
|
||||
public Xoh_hzip_bfr(int bfr_max, boolean mode_is_b256, byte stop_byte) {
|
||||
this.Init(bfr_max);
|
||||
this.stop_byte = stop_byte;
|
||||
Mode_is_b256_(mode_is_b256);
|
||||
}
|
||||
public Xoh_hzip_bfr Mode_is_b256_(boolean mode_is_b256) {
|
||||
hzint.Mode_is_b256_(mode_is_b256);
|
||||
return this;
|
||||
}
|
||||
public Xoh_hzip_bfr Add_hzip_bry(byte[] bry) {Add(bry); Add_byte(stop_byte); return this;}
|
||||
public Xoh_hzip_bfr Add_hzip_mid(byte[] src, int bgn, int end) {Add_mid(src, bgn, end); Add_byte(stop_byte); return this;}
|
||||
public Xoh_hzip_bfr Add_hzip_int(int reqd, int val) {
|
||||
hzint.Encode(reqd, this, val);
|
||||
return this;
|
||||
}
|
||||
public static Xoh_hzip_bfr New_txt(int bfr_max) {return new Xoh_hzip_bfr(bfr_max, Bool_.N, gplx.xowa.htmls.core.hzips.Xoh_hzip_dict_.Escape);}
|
||||
}
|
||||
@@ -15,24 +15,29 @@ 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.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_hzip_fxt {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(32);
|
||||
private final Xoh_hzip_mgr hzip_mgr;
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
private boolean mode_is_b256;
|
||||
public Xoh_hzip_fxt() {
|
||||
Xowe_wiki wiki = parser_fxt.Wiki();
|
||||
this.wiki = parser_fxt.Wiki();
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), wiki); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
wiki.Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr();
|
||||
hpg.Init(wiki, Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
}
|
||||
public Xow_wiki Wiki() {return parser_fxt.Wiki();}
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoh_hzip_fxt Init_mode_is_b256_(boolean v) {bfr.Mode_is_b256_(v); mode_is_b256 = v; return this;}
|
||||
public Xoh_hzip_fxt Init_mode_diff_y_() {hzip_mgr.Hctx().Mode_is_diff_(Bool_.Y); return this;}
|
||||
public void Clear() {hpg.Clear();}
|
||||
public Xowe_wiki Prep_create_wiki(String alias, String domain) {
|
||||
public void Init_wiki_installed(String domain) {parser_fxt.Init_xwiki_add_user_(domain);}
|
||||
public Xowe_wiki Init_wiki_alias(String alias, String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.wiki_(parser_fxt.App(), domain);
|
||||
parser_fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), null);
|
||||
return rv;
|
||||
@@ -74,7 +79,7 @@ public class Xoh_hzip_fxt {
|
||||
}
|
||||
public void Exec_write_to_fsys(Io_url dir, String fil) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(32).Mode_is_b256_(mode_is_b256);
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Io_mgr.Instance.LoadFilBry(dir.GenSubFil(fil)));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
@@ -82,7 +87,9 @@ public class Xoh_hzip_fxt {
|
||||
Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.html"), actl);
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 4;
|
||||
hzip_mgr.Hctx().Mode_is_diff_(Bool_.Y);
|
||||
hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, actl);
|
||||
hzip_mgr.Hctx().Mode_is_diff_(Bool_.N);
|
||||
gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 2;
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.decode.html"), bfr.To_bry_and_clear());
|
||||
@@ -18,9 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public abstract class Xoh_itm_parser_fxt_base {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public abstract class Xoh_itm_parser_fxt {
|
||||
private final Xoae_app app;
|
||||
private final Xowe_wiki wiki;
|
||||
private final Bry_err_wkr err_wkr = new Bry_err_wkr();
|
||||
protected byte[] src; protected int src_len;
|
||||
protected final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
public Xoh_itm_parser_fxt() {
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
this.wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
hctx.Init_by_app(app);
|
||||
}
|
||||
private Xoh_itm_parser Parser() {return Parser_get();}
|
||||
public abstract Xoh_itm_parser Parser_get();
|
||||
public void Test__parse__fail(String src_str, String expd) {
|
||||
@@ -32,8 +40,9 @@ public abstract class Xoh_itm_parser_fxt_base {
|
||||
}
|
||||
public void Exec_parse(String src_str) {
|
||||
this.src = Bry_.new_u8(src_str); this.src_len = src.length;
|
||||
rdr.Init_by_page(Xoa_page_.Main_page_bry, src, src_len);
|
||||
Exec_parse_hook(rdr, 0, src_len);
|
||||
hctx.Init_by_page(wiki, Xoa_page_.Main_page_bry);
|
||||
err_wkr.Init_by_page(Xoa_page_.Main_page_str, src);
|
||||
Exec_parse_hook(err_wkr, hctx, 0, src_len);
|
||||
}
|
||||
public abstract void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end);
|
||||
public abstract void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end);
|
||||
}
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.escapes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_escape_parser implements Html_doc_wkr {
|
||||
public class Xoh_escape_data implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr wkr;
|
||||
public Xoh_escape_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public Xoh_escape_data(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public byte[] Hook() {return Xoh_hzip_dict_.Escape_bry;}
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
|
||||
int rv = pos + 1;
|
||||
@@ -19,18 +19,24 @@ package gplx.xowa.htmls.core.wkrs.escapes; import gplx.*; import gplx.xowa.*; im
|
||||
import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_escape_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private byte escape_byte;
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public String Key() {return Xoh_hzip_dict_.Key__escape;}
|
||||
public Xoh_escape_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm) {
|
||||
stat_itm.Escape_add_one();
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__escape);
|
||||
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
|
||||
bfr.Add(hook);
|
||||
hctx.Hzip__stat().Escape_add(escape_byte);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_escape_hzip rv = new Xoh_escape_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {
|
||||
Xoh_escape_hzip rv = new Xoh_escape_hzip();
|
||||
rv.pool_mgr = mgr; rv.pool_idx = idx;
|
||||
rv.hook = (byte[])args[0];
|
||||
rv.escape_byte = rv.hook[0];
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,33 +23,15 @@ import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__gly;}
|
||||
public Xoh_gly_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_gly_grp_parser arg) {
|
||||
bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
|
||||
Xoh_gly_grp_parser data = (Xoh_gly_grp_parser)data_obj;
|
||||
bfr.Add_mid(src, data.Rng_bgn(), data.Rng_end());
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
return hook_bgn;
|
||||
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
|
||||
return src_bgn + 2;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
// private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1, 1, 1, 1 , 2, 1, 1, 1 , 1, 2, 2);
|
||||
// private static final int // SERIALIZED
|
||||
// Flag__file__w_diff_from_html = 0
|
||||
// , Flag__file__time_exists = 1
|
||||
// , Flag__file__page_exists = 2
|
||||
// , Flag__file__is_orig = 3
|
||||
// , Flag__file__repo_is_local = 4
|
||||
// , Flag__file__src_exists = 5
|
||||
// , Flag__img__cls_other_exists = 6
|
||||
// , Flag__anch__ns_is_image = 7
|
||||
// , Flag__anch__cls_tid = 8 // none, image
|
||||
// , Flag__anch__ns_id_needs_saving = 9
|
||||
// , Flag__img__alt_diff_from_anch_title = 10
|
||||
// , Flag__anch__href_diff_file = 11
|
||||
// , Flag__anch__title_missing = 12
|
||||
// , Flag__img__cls_tid = 13 // none, thumbimage, thumbborder
|
||||
// , Flag__anch__href_tid = 14 // wiki, site, anch, inet
|
||||
// ;
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
}
|
||||
|
||||
@@ -20,43 +20,63 @@ import gplx.core.brys.*; import gplx.core.threads.poolables.*; import gplx.xowa.
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_hdr_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__hdr;}
|
||||
public Xoh_hdr_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_hdr_parser arg) {
|
||||
int level = arg.Hdr_level();
|
||||
stat_itm.Hdr_add(level);
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook
|
||||
bfr.Add_int_digits(1, level); // add level; EX: 2 in <h2>
|
||||
bfr.Add_mid(src, arg.Capt_bgn(), arg.Capt_end()).Add_byte(Xoh_hzip_dict_.Escape); // add caption
|
||||
bfr.Add_safe(arg.Anch_bry()); // add anchor
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
|
||||
Xoh_hdr_parser data = (Xoh_hdr_parser)data_obj;
|
||||
boolean capt_rhs_exists = flag_bldr.Set_as_bool (Flag__capt_rhs_exists , data.Capt_rhs_exists());
|
||||
boolean anch_is_diff = flag_bldr.Set_as_bool (Flag__anch_is_diff , data.Anch_is_diff());
|
||||
int hdr_level = flag_bldr.Set_as_int (Flag__hdr_level , data.Hdr_level());
|
||||
|
||||
bfr.Add(hook);
|
||||
bfr.Add_hzip_int(1, flag_bldr.Encode());
|
||||
bfr.Add_hzip_mid(src, data.Capt_bgn(), data.Capt_end()); // add caption
|
||||
if (anch_is_diff) bfr.Add_hzip_mid(src, data.Anch_bgn(), data.Anch_end()); // add anchor
|
||||
if (capt_rhs_exists) bfr.Add_hzip_mid(src, data.Capt_rhs_bgn(), data.Capt_rhs_end());// add capt_rhs
|
||||
|
||||
hctx.Hzip__stat().Hdr_add(hdr_level);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte level = rdr.Read_byte();
|
||||
int capt_bgn = rdr.Pos();
|
||||
int capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
int anch_bgn = rdr.Pos();
|
||||
int anch_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
|
||||
int flag = rdr.Read_int_by_base85(1); flag_bldr.Decode(flag);
|
||||
boolean capt_rhs_exists = flag_bldr.Get_as_bool(Flag__capt_rhs_exists);
|
||||
boolean anch_is_diff = flag_bldr.Get_as_bool(Flag__anch_is_diff);
|
||||
byte hdr_level = flag_bldr.Get_as_byte(Flag__hdr_level);
|
||||
|
||||
bfr.Add(Bry__hdr__0).Add_byte(level);
|
||||
int capt_bgn = rdr.Pos(); int capt_end = rdr.Find_fwd_lr();
|
||||
int anch_bgn = -1, anch_end = -1;
|
||||
if (anch_is_diff) {
|
||||
anch_bgn = rdr.Pos(); anch_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
byte[] capt_manual_end = capt_rhs_exists ? rdr.Read_bry_to() : null;
|
||||
|
||||
bfr.Add(Bry__hdr__0).Add_byte_as_a7(hdr_level);
|
||||
bfr.Add(Bry__hdr__1);
|
||||
if (anch_end > anch_bgn)
|
||||
if (anch_is_diff)
|
||||
bfr.Add_mid (src, anch_bgn, anch_end);
|
||||
else
|
||||
bfr.Add_mid_w_swap (src, capt_bgn, capt_end, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
bfr.Add(Bry__hdr__2);
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
bfr.Add(Bry__hdr__3).Add_byte(level);
|
||||
bfr.Add(Bry__hdr__3);
|
||||
if (capt_rhs_exists)
|
||||
bfr.Add(capt_manual_end);
|
||||
bfr.Add(Bry__hdr__4).Add_byte_as_a7(hdr_level);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
return rdr.Pos();
|
||||
}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1, 1, 3);
|
||||
private static final int // SERIALIZED
|
||||
Flag__capt_rhs_exists = 0
|
||||
, Flag__anch_is_diff = 1
|
||||
, Flag__hdr_level = 2
|
||||
;
|
||||
private static final byte[]
|
||||
Bry__hdr__0 = Bry_.new_a7("<h")
|
||||
, Bry__hdr__1 = Bry_.new_a7(">\n <span class=\"mw-headline\" id=\"")
|
||||
, Bry__hdr__1 = Bry_.new_a7("><span class=\"mw-headline\" id=\"")
|
||||
, Bry__hdr__2 = Bry_.new_a7("\">")
|
||||
, Bry__hdr__3 = Bry_.new_a7("</span>\n</h")
|
||||
, Bry__hdr__3 = Bry_.new_a7("</span>")
|
||||
, Bry__hdr__4 = Bry_.new_a7("</h")
|
||||
;
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_hzip rv = new Xoh_hdr_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_hzip rv = new Xoh_hdr_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
}
|
||||
|
||||
@@ -21,46 +21,53 @@ public class Xoh_hdr_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Same() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"6A~~"
|
||||
( "~\"'A~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h6>"
|
||||
, " <span class='mw-headline' id='A'>A</span>"
|
||||
, "</h6>"
|
||||
( "<h6><span class='mw-headline' id='A'>A</span></h6>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Diff() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2<i>A</i>~A~"
|
||||
( "~\"+<i>A</i>~A~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A'><i>A</i></span>"
|
||||
, "</h2>"
|
||||
( "<h2><span class='mw-headline' id='A'><i>A</i></span></h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Diff_by_underscore() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2A 1~~"
|
||||
( "~\"#A 1~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A_1'>A 1</span>"
|
||||
, "</h2>"
|
||||
( "<h2><span class='mw-headline' id='A_1'>A 1</span></h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Diff_by_lnki() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"+<a href=\"/wiki/Category:A\" title=\"Category:A\">Category:A</a>~Category:A~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2><span class='mw-headline' id='Category:A'><a href='/wiki/Category:A' title='Category:A'>Category:A</a></span></h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Same_w_underscore() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2A_1~~"
|
||||
( "~\"#A_1~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A_1'>A_1</span>"
|
||||
, "</h2>"
|
||||
( "<h2><span class='mw-headline' id='A_1'>A_1</span></h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Tidy__bad_end() {
|
||||
fxt.Test__bicode(
|
||||
"~\"?A~AB~B~"
|
||||
, "<h6><span class='mw-headline' id='AB'>A</span>B</h6>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ public class Xoh_hdr_make {
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, Xoh_hdr_parser arg) {
|
||||
// , int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch
|
||||
// register section
|
||||
int rng_bgn = arg.Rng_bgn(), rng_end = arg.Rng_end();
|
||||
int rng_bgn = arg.Src_bgn(), rng_end = arg.Src_end();
|
||||
int level = arg.Hdr_level();
|
||||
Xoh_section_mgr section_mgr = hpg.Section_mgr();
|
||||
int section_len = section_mgr.Len();
|
||||
if (section_len != 0) // guard against -1 index; should not happen
|
||||
section_mgr.Set_content(section_len - 1, src, rng_bgn - 2); // -2 to skip "\n\n"
|
||||
byte[] capt = Bry_.Mid(src, arg.Capt_bgn(), arg.Capt_end());
|
||||
byte[] anch = arg.Anch_bry();
|
||||
byte[] anch = Bry_.Mid(src, arg.Anch_bgn(), arg.Anch_end());
|
||||
if (anch == null) anch = Bry_.Replace(capt, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
hpg.Section_mgr().Add(section_len, level, anch, capt).Content_bgn_(rng_end + 1); // +1 to skip "\n"
|
||||
bfr.Add_mid(src, rng_bgn, rng_end);
|
||||
|
||||
@@ -18,26 +18,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_hdr_parser {
|
||||
// gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public int Hdr_level() {return hdr_level;} private int hdr_level;
|
||||
public int Anch_bgn() {return anch_bgn;} private int anch_bgn;
|
||||
public int Anch_end() {return anch_end;} private int anch_end;
|
||||
public boolean Anch_is_diff() {return anch_is_diff;} private boolean anch_is_diff;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
public byte[] Anch_bry() {return anch_bry;} private byte[] anch_bry;
|
||||
public int Parse(Xoh_hdoc_wkr wkr, byte[] src, Html_tag_rdr rdr, int hdr_level, int rng_bgn, Html_tag span) {// <h2><span class='mw-headline' id='A_1'>A 1</span></h2>
|
||||
this.rng_bgn = rng_bgn; this.hdr_level = hdr_level;
|
||||
Html_atr anch_atr = span.Atrs__get_by_or_fail(Html_atr_.Bry__id);
|
||||
int anch_bgn = anch_atr.Val_bgn(), anch_end = anch_atr.Val_end();
|
||||
this.capt_bgn = span.Src_end();
|
||||
rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span> since <span> can be nested, but <h2> cannot
|
||||
this.capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get </span> before </h2>
|
||||
this.anch_bry = null;
|
||||
if (!Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline))
|
||||
this.anch_bry = Bry_.Mid(src, anch_bgn, anch_end); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
|
||||
this.rng_end = rdr.Pos();
|
||||
wkr.On_hdr(this);
|
||||
return rng_end;
|
||||
public int Capt_rhs_bgn() {return capt_rhs_bgn;} private int capt_rhs_bgn;
|
||||
public int Capt_rhs_end() {return capt_rhs_end;} private int capt_rhs_end;
|
||||
public boolean Capt_rhs_exists() {return capt_rhs_exists;} private boolean capt_rhs_exists;
|
||||
public void Clear() {
|
||||
this.anch_bgn = anch_end = capt_bgn = capt_end = capt_rhs_bgn = capt_rhs_end -1;
|
||||
this.anch_is_diff = capt_rhs_exists = false;
|
||||
}
|
||||
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Html_tag_rdr tag_rdr, byte[] src, Html_tag hdr_head, Html_tag span_head) {
|
||||
this.Clear();
|
||||
this.src_bgn = hdr_head.Src_bgn(); this.hdr_level = hdr_head.Name_id();
|
||||
Html_atr anch_atr = span_head.Atrs__get_by_or_fail(Html_atr_.Bry__id);
|
||||
this.anch_bgn = anch_atr.Val_bgn(); this.anch_end = anch_atr.Val_end();
|
||||
this.capt_bgn = span_head.Src_end();
|
||||
Html_tag hdr_tail = tag_rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span_head> since <span_head> can be nested, but <h2> cannot
|
||||
Html_tag span_tail = tag_rdr.Tag__peek_bwd_tail(Html_tag_.Id__span); // get </span_head> before </h2>
|
||||
this.capt_end = span_tail.Src_bgn();
|
||||
if (span_tail.Src_end() != hdr_tail.Src_bgn()) {
|
||||
capt_rhs_exists = true;
|
||||
capt_rhs_bgn = span_tail.Src_end(); capt_rhs_end = hdr_tail.Src_bgn();
|
||||
}
|
||||
this.anch_is_diff = !Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
|
||||
this.src_end = tag_rdr.Pos();
|
||||
hdoc_wkr.On_hdr(this);
|
||||
return true;
|
||||
}
|
||||
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
|
||||
}
|
||||
|
||||
@@ -24,20 +24,20 @@ public class Xoh_img_bldr {
|
||||
public Xoh_img_wtr Wtr() {return wtr;} private final Xoh_img_wtr wtr = new Xoh_img_wtr();
|
||||
public Xof_fsdb_itm Fsdb_itm() {return fsdb_itm;} private Xof_fsdb_itm fsdb_itm;
|
||||
public void Make_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_img_parser arg) {
|
||||
Make( bfr, hpg, hctx, src, arg.Img_src().File_ttl_bry(), arg.Img_xoimg()
|
||||
, arg.Anch_href().Rel_nofollow_exists(), arg.Anch_href().Atr(), arg.Anch_cls().Atr(), arg.Anch_title()
|
||||
Make( bfr, hpg, hctx, src, arg.Img_src().File_ttl_bry(), arg.Img_xoimg(), arg.Img_xoimg().Val_dat_exists()
|
||||
, arg.Rel_nofollow_exists(), arg.Anch_href().Atr(), arg.Anch_cls().Atr(), arg.Anch_title()
|
||||
, arg.Img_w(), arg.Img_h(), arg.Img_src().Atr(), arg.Img_cls().Atr(), arg.Img_alt());
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, byte[] lnki_ttl, Xoh_img_xoimg_parser img_xoimg
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, byte[] lnki_ttl, Xoh_img_xoimg_parser img_xoimg, boolean img_xoimg_exists
|
||||
, boolean anch_rel_is_nofollow, Bfr_arg anch_href, Bfr_arg anch_cls, Bfr_arg anch_ttl
|
||||
, int img_w, int img_h, Bfr_arg img_src, Bfr_arg img_cls, Bfr_arg img_alt) {
|
||||
wtr.Clear();
|
||||
this.fsdb_itm = hpg.Img_mgr().Make_img();
|
||||
if (img_xoimg.Val_dat_exists()) {
|
||||
if (img_xoimg_exists) {
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, img_xoimg.Lnki_type(), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
hctx.File__mgr().Check_cache(fsdb_itm);
|
||||
wtr.Img_xoimg_(src, img_xoimg.Val_bgn(), img_xoimg.Val_end());
|
||||
wtr.Img_xoimg_(img_xoimg);
|
||||
wtr.Img_src_empty_().Img_w_(0).Img_h_(0);
|
||||
}
|
||||
else if (img_w != -1) {
|
||||
@@ -45,6 +45,8 @@ public class Xoh_img_bldr {
|
||||
}
|
||||
if (anch_rel_is_nofollow) wtr.Anch_rel_nofollow_();
|
||||
wtr.Anch_href_(anch_href).Anch_cls_(anch_cls).Anch_title_(anch_ttl).Anch_xowa_title_(lnki_ttl);
|
||||
wtr.Img_id_(Xoh_img_mgr.Bry__html_uid, fsdb_itm.Html_uid()).Img_alt_(img_alt).Img_cls_(img_cls);
|
||||
if (!hctx.Mode_is_diff())
|
||||
wtr.Img_id_(Xoh_img_mgr.Bry__html_uid, fsdb_itm.Html_uid());
|
||||
wtr.Img_alt_(img_alt).Img_cls_(img_cls);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__img;}
|
||||
private final Xoh_img_xoimg_parser xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
private final Xoh_img_xoimg_parser xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
|
||||
public Xoh_img_bldr Bldr() {return bldr;} private Xoh_img_bldr bldr = new Xoh_img_bldr();
|
||||
public Bfr_arg__href Anch_href_arg() {return anch_href_arg;} private final Bfr_arg__href anch_href_arg = new Bfr_arg__href();
|
||||
public Xoh_img_xoimg_hzip Xoimg() {return xoimg;} private final Xoh_img_xoimg_hzip xoimg = new Xoh_img_xoimg_hzip();
|
||||
private final Bry_obj_ref
|
||||
anch_cls_mid = Bry_obj_ref.New_empty()
|
||||
, anch_title_mid = Bry_obj_ref.New_empty()
|
||||
@@ -34,30 +38,30 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
, img_src_mid = Bry_obj_ref.New_empty()
|
||||
, img_cls_mid = Bry_obj_ref.New_empty()
|
||||
;
|
||||
public Xoh_img_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg, boolean write_hdr) {
|
||||
// img_map: <img id="xowa_file_img_100" alt="" src="file:///J:/xowa/file/commons.wikimedia.org/orig/b/8/a/7/Solar_System_Template_Final.png" width="666" height="36" usemap="#imagemap_1_1">
|
||||
Xoh_anch_href_parser anch_href = arg.Anch_href();
|
||||
Bry_obj_ref anch_page = arg.Anch_page();
|
||||
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
|
||||
Xoh_img_parser data = (Xoh_img_parser)data_obj;
|
||||
Xoh_anch_href_itm anch_href = data.Anch_href();
|
||||
Bry_obj_ref anch_page = data.Anch_page();
|
||||
byte anch_href_tid = anch_href.Tid();
|
||||
boolean anch__ns_id_needs_saving = anch_href.Tid_has_ns() && anch_href.Page_ns_id() != Xow_ns_.Tid__file;
|
||||
Html_atr anch_title = arg.Anch_title();
|
||||
Xoa_ttl anch_href_ttl = anch_href.Page_ttl();
|
||||
Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg();
|
||||
Xoh_img_cls_parser img_cls = arg.Img_cls();
|
||||
Xoh_img_src_parser img_src = arg.Img_src();
|
||||
boolean img__alt_diff_from_anch_title = arg.Img_alt__diff__anch_title();
|
||||
boolean anch__ns_is_custom = anch_href.Ttl_ns_custom() != null;
|
||||
boolean anch__ns_id_needs_saving = Xoh_anch_href_itm.Ns_exists(anch_href.Tid()) && anch_href.Ttl_ns_id() != Xow_ns_.Tid__file;
|
||||
Html_atr anch_title = data.Anch_title();
|
||||
Xoh_img_xoimg_parser img_xoimg = data.Img_xoimg();
|
||||
Xoh_img_cls_parser img_cls = data.Img_cls();
|
||||
Xoh_img_src_parser img_src = data.Img_src();
|
||||
boolean img__alt_diff_from_anch_title = data.Img_alt__diff__anch_title();
|
||||
boolean file__src_exists = !img_xoimg.Val_dat_exists();
|
||||
boolean anch_href_diff_file = !Bry_.Match(anch_page.Val(), anch_page.Val_bgn(), anch_page.Val_end(), anch_href.Page_ttl().Page_db());
|
||||
boolean anch_href_diff_file = !Bry_.Match(anch_page.Val(), anch_page.Val_bgn(), anch_page.Val_end(), anch_href.Ttl_page_db());
|
||||
|
||||
flag_bldr.Set(Flag__file__w_diff_from_html , file__src_exists && arg.Img_w__diff__file_w());
|
||||
flag_bldr.Set(Flag__file__w_diff_from_html , file__src_exists && data.Img_w__diff__file_w());
|
||||
flag_bldr.Set(Flag__file__time_exists , file__src_exists && img_src.File_time_exists());
|
||||
flag_bldr.Set(Flag__file__page_exists , file__src_exists && img_src.File_page_exists());
|
||||
flag_bldr.Set(Flag__file__is_orig , file__src_exists && img_src.File_is_orig());
|
||||
flag_bldr.Set(Flag__file__repo_is_local , file__src_exists && !img_src.Repo_is_commons());
|
||||
flag_bldr.Set(Flag__file__src_exists , file__src_exists);
|
||||
flag_bldr.Set(Flag__img__cls_other_exists , img_cls.Other_exists());
|
||||
flag_bldr.Set(Flag__anch__ns_is_image , anch_href.Page_ns_id_is_image());
|
||||
flag_bldr.Set(Flag__anch__cls_tid , arg.Anch_cls().Tid());
|
||||
flag_bldr.Set(Flag__anch__ns_is_custom , anch__ns_is_custom);
|
||||
flag_bldr.Set(Flag__anch__cls_tid , data.Anch_cls().Tid());
|
||||
flag_bldr.Set(Flag__anch__ns_id_needs_saving , anch__ns_id_needs_saving);
|
||||
flag_bldr.Set(Flag__img__alt_diff_from_anch_title , img__alt_diff_from_anch_title);
|
||||
flag_bldr.Set(Flag__anch__href_diff_file , anch_href_diff_file);
|
||||
@@ -66,43 +70,52 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
flag_bldr.Set(Flag__anch__href_tid , anch_href.Tid());
|
||||
// Tfds.Dbg(flag_bldr.Encode(), Array_.To_str(flag_bldr.Val_ary()));
|
||||
|
||||
if (write_hdr) bfr.Add(Xoh_hzip_dict_.Bry__img);
|
||||
if (wkr_is_root) bfr.Add(hook);
|
||||
Xoh_hzip_int_.Encode(2, bfr, flag_bldr.Encode());
|
||||
if (anch_href_tid == Xoh_anch_href_parser.Tid__inet)
|
||||
anch_href_mid.Mid_(src, anch_href.Val_bgn(), anch_href.Val_end());
|
||||
else
|
||||
anch_href_mid.Val_(anch_href_ttl.Page_db());
|
||||
switch (anch_href_tid) {
|
||||
case Xoh_anch_href_itm.Tid__inet:
|
||||
anch_href_mid.Mid_(src, anch_href.Rng_bgn(), anch_href.Rng_end());
|
||||
break;
|
||||
case Xoh_anch_href_itm.Tid__site:
|
||||
anch_href_mid.Val_(tmp_bfr.Add_mid(src, anch_href.Site_bgn(), anch_href.Site_end()).Add_byte(Byte_ascii.Pipe).Add(anch_href.Ttl_page_db()).To_bry_and_clear());
|
||||
break;
|
||||
case Xoh_anch_href_itm.Tid__wiki:
|
||||
case Xoh_anch_href_itm.Tid__anch:
|
||||
anch_href_mid.Val_(anch_href.Ttl_page_db());
|
||||
break;
|
||||
}
|
||||
bfr.Add_bry_ref_obj(anch_href_mid);
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (anch_href_diff_file) {
|
||||
arg.Anch_page().Bfr_arg__add(bfr);
|
||||
data.Anch_page().Bfr_arg__add(bfr);
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
switch (anch_href_tid) {
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
case Xoh_anch_href_parser.Tid__inet:
|
||||
case Xoh_anch_href_itm.Tid__anch:
|
||||
case Xoh_anch_href_itm.Tid__inet:
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
case Xoh_anch_href_itm.Tid__wiki:
|
||||
case Xoh_anch_href_itm.Tid__site:
|
||||
if (anch__ns_id_needs_saving)
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl.Ns().Id());
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href.Ttl_ns_id());
|
||||
break;
|
||||
}
|
||||
if (anch__ns_is_custom) bfr.Add(data.Anch_href().Ttl_ns_custom()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (file__src_exists) {
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_h());
|
||||
if (arg.Img_w__diff__file_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + data.Img_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + data.Img_h());
|
||||
if (data.Img_w__diff__file_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
if (img_src.File_time_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_time());
|
||||
if (img_src.File_page_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_page());
|
||||
}
|
||||
else
|
||||
bfr.Add_mid(src, img_xoimg.Val_bgn(), img_xoimg.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
xoimg.Encode(bfr, hctx.Hzip__stat(), src, img_xoimg);
|
||||
if (anch_title.Val_dat_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img__alt_diff_from_anch_title) bfr.Add_mid(src, arg.Img_alt().Val_bgn(), arg.Img_alt().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img__alt_diff_from_anch_title) bfr.Add_mid(src, data.Img_alt().Val_bgn(), data.Img_alt().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
|
||||
// decode rdr
|
||||
int flag = rdr.Read_int_by_base85(2);
|
||||
flag_bldr.Decode(flag);
|
||||
@@ -110,7 +123,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
boolean file__repo_is_local = flag_bldr.Get_as_bool(Flag__file__repo_is_local);
|
||||
boolean file__src_exists = flag_bldr.Get_as_bool(Flag__file__src_exists);
|
||||
boolean img__cls_other_exists = flag_bldr.Get_as_bool(Flag__img__cls_other_exists);
|
||||
boolean anch__ns_is_image = flag_bldr.Get_as_bool(Flag__anch__ns_is_image);
|
||||
boolean anch__ns_is_custom = flag_bldr.Get_as_bool(Flag__anch__ns_is_custom);
|
||||
boolean anch__ns_id_needs_saving = flag_bldr.Get_as_bool(Flag__anch__ns_id_needs_saving);
|
||||
int anch__cls_tid = flag_bldr.Get_as_int(Flag__anch__cls_tid);
|
||||
boolean img__alt_diff_from_anch_title = flag_bldr.Get_as_bool(Flag__img__alt_diff_from_anch_title);
|
||||
@@ -119,21 +132,36 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
int img_cls = flag_bldr.Get_as_int(Flag__img__cls_tid);
|
||||
int anch__href_tid = flag_bldr.Get_as_int(Flag__anch__href_tid);
|
||||
byte[] page_db = rdr.Read_bry_to();
|
||||
byte[] site_bry = null;
|
||||
switch (anch__href_tid) {
|
||||
case Xoh_anch_href_itm.Tid__anch:
|
||||
case Xoh_anch_href_itm.Tid__inet:
|
||||
case Xoh_anch_href_itm.Tid__wiki:
|
||||
break;
|
||||
case Xoh_anch_href_itm.Tid__site:
|
||||
int pipe_pos = Bry_find_.Find_fwd(page_db, Byte_ascii.Pipe);
|
||||
site_bry = Bry_.Mid(page_db, 0, pipe_pos);
|
||||
page_db = Bry_.Mid(page_db, pipe_pos + 1);
|
||||
break;
|
||||
}
|
||||
byte[] file_db = page_db;
|
||||
if (anch_href_diff_file) file_db = rdr.Read_bry_to();
|
||||
int anch_href_ns = -1;
|
||||
if (anch__ns_id_needs_saving)
|
||||
anch_href_ns = Xoh_lnki_dict_.Ns_decode(rdr);
|
||||
int img_xoimg_bgn = -1, img_xoimg_end = -1, img_w = -1, img_h = -1, file_time = -1, file_page = -1;
|
||||
int ns_custom_bgn = -1, ns_custom_end = -1;
|
||||
if (anch__ns_is_custom) {
|
||||
ns_custom_bgn = rdr.Pos();
|
||||
ns_custom_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int img_w = -1, img_h = -1, file_time = -1, file_page = -1;
|
||||
xoimg_parser.Clear();
|
||||
if (file__src_exists) {
|
||||
img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
img_h = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
}
|
||||
else {
|
||||
img_xoimg_bgn = rdr.Pos();
|
||||
img_xoimg_end = rdr.Find_fwd_lr();
|
||||
xoimg_parser.Parse(rdr, src, img_xoimg_bgn, img_xoimg_end);
|
||||
xoimg.Decode(bfr, hctx, hpg, rdr, src, xoimg_parser);
|
||||
}
|
||||
int anch_title_bgn = -1, anch_title_end = -1;
|
||||
if (!anch__title_missing) {
|
||||
@@ -156,22 +184,24 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
|
||||
// transform values
|
||||
boolean anch_rel_is_nofollow = false;
|
||||
if (anch__ns_id_needs_saving) {
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
anch_href_arg.Set_by_page(anch_href_ttl.Full_db());
|
||||
if (anch__href_tid == Xoh_anch_href_itm.Tid__inet) {
|
||||
Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db);
|
||||
anch_rel_is_nofollow = true;
|
||||
}
|
||||
else {
|
||||
if (anch__href_tid == Xoh_anch_href_parser.Tid__inet) {
|
||||
anch_href_arg.Set_by_raw(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db));
|
||||
anch_rel_is_nofollow = true;
|
||||
if (anch__href_tid == Xoh_anch_href_itm.Tid__site)
|
||||
tmp_bfr.Add(Xoh_href_.Bry__site).Add(site_bry);
|
||||
if (anch__ns_id_needs_saving) {
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(anch_href_ttl.Full_url());
|
||||
}
|
||||
else {
|
||||
if (anch__ns_is_image)
|
||||
anch_href_arg.Set_by_raw(Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, gplx.xowa.wikis.nss.Xow_ns_.Alias__image__bry, Byte_ascii.Colon_bry, gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db)));
|
||||
else
|
||||
anch_href_arg.Set_by_file(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db));
|
||||
byte[] ns_bry = anch__ns_is_custom ? Bry_.Mid(src, ns_custom_bgn, ns_custom_end) : Xow_ns_.Bry__file;
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(ns_bry).Add_byte_colon();
|
||||
Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db);
|
||||
}
|
||||
}
|
||||
anch_href_arg.Set_by_raw(tmp_bfr.To_bry_and_clear());
|
||||
// NOTE: src must go underneath ttl
|
||||
Xof_url_bldr url_bldr = hctx.File__url_bldr();
|
||||
url_bldr.Init_by_root(file__repo_is_local ? hctx.Fsys__file__wiki() : hctx.Fsys__file__comm(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
@@ -179,20 +209,18 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
|
||||
anch_cls_mid.Val_(Xoh_anch_cls_.To_val(anch__cls_tid));
|
||||
anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end); if (anch_title_bgn == anch_title_end) anch_title_mid.Val_(null);
|
||||
if (!anch__title_missing) anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end); else {anch_title_mid.Val_(null);} // if (anch_title_bgn == anch_title_end) anch_title_mid.Val_(null);
|
||||
img_alt_mid.Mid_(src, img_alt_bgn, img_alt_end); if (img_alt_mid.Val_is_empty()) img_alt_mid.Val_(Bry_.Empty);
|
||||
img_src_mid.Val_(img_src);
|
||||
img_cls_mid.Val_(Xoh_img_cls_.To_val_or_null(img_cls, img_cls_other));
|
||||
|
||||
bldr.Make(bfr, hpg, hctx, src, file_db, xoimg_parser, anch_rel_is_nofollow, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
|
||||
if (write_to_bfr) bldr.Wtr().Bfr_arg__add(bfr);
|
||||
bldr.Make(bfr, hpg, hctx, src, file_db, xoimg_parser, !file__src_exists, anch_rel_is_nofollow, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
|
||||
if (wkr_is_root) bldr.Wtr().Bfr_arg__add(bfr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
public static int Md5_depth = 2;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1, 1, 1, 1 , 2, 1, 1, 1 , 1, 2, 2);
|
||||
private static final int // SERIALIZED
|
||||
@@ -203,7 +231,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
, Flag__file__repo_is_local = 4
|
||||
, Flag__file__src_exists = 5
|
||||
, Flag__img__cls_other_exists = 6
|
||||
, Flag__anch__ns_is_image = 7
|
||||
, Flag__anch__ns_is_custom = 7
|
||||
, Flag__anch__cls_tid = 8 // none, image
|
||||
, Flag__anch__ns_id_needs_saving = 9
|
||||
, Flag__img__alt_diff_from_anch_title = 10
|
||||
|
||||
@@ -22,32 +22,55 @@ public class Xoh_img_hzip__dump__tst {
|
||||
@Before public void Clear() {fxt.Clear();}
|
||||
@Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!!A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
( "~%!!A.png~)#Sabc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Anch() { // [[File:A.png#b|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%\"<A.png#file~A.png~)#Sabc~"
|
||||
, "<a href='/wiki/File:A.png#file' class='image' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link__cs() { // [[File:A.png|link=File:a.ogg|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!Aa.ogg~A.png~)#Sabc~"
|
||||
, "<a href='/wiki/File:a.ogg' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Href__encoding() { // [[File:Aéb.png|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!!Aéb.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/File:A%C3%A9b.png' class='image' title='abc' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
( "~%!qAéb.png~)#Sabc~"
|
||||
, "<a href='/wiki/File:A%C3%A9b.png' class='image' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Href__encoding__link() { // [[File:Aéb.png|abc|link=Aéb]]
|
||||
fxt.Test__bicode
|
||||
( "~%#gAéb~Aéb.png~#)#Sabc~"
|
||||
, "<a href='/wiki/A%C3%A9b' class='image' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Href__apos() { // [[File:A'b.png|border|link=A'b_link|A'b_capt]]
|
||||
String html = "<a href=\"/wiki/A%27b_link\" class=\"image\" xowa_title=\"A'b.png\"><img id=\"xoimg_0\" data-xoimg=\"0|220|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" class=\"thumbborder\" alt=\"A'b_capt\"></a>";
|
||||
fxt.Test__bicode_raw("~%#oA'b_link~A'b.png~#)#SA'b_capt~", html, html);
|
||||
}
|
||||
@Test public void Link__wm__n() { // [[File:A.png|link=http://a.org|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!Dhttp://a.org~A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
( "~%!Dhttp://a.org~A.png~)#Sabc~"
|
||||
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
// @Test public void Link__wm__y() { // [[File:A.png|link=//en.wiktionary.org/wiki/A|abc]]
|
||||
// fxt.Test__bicode
|
||||
// ( "~%!i=!!!!A~abc~"
|
||||
// , "<a href='/site/en.wiktionary.org/wiki/A' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
// );
|
||||
// }
|
||||
@Test public void Link__wm__y() { // [[File:A.png|link=http://en.wikitionary.org/wiki/Special:Search/A|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%\"men.wiktionary.org|Search/A~A.png~\")#Sabc~"
|
||||
, "<a href='/site/en.wiktionary.org/wiki/Special:Search/A' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
// lhs='<a href="/site/en.wiktionary.org/wiki/Special:Search/A" class="image" title="B" xowa_title="Commons-logo.svg"><img data-xoimg="0|40|40|-1|-1|-1" src="" width="0" height="0" alt="B"></a>
|
||||
@Test public void Href__image() { // [[Image:A.png|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%-%A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/Image:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
( "~%-%A.png~Image~)#Sabc~"
|
||||
, "<a href='/wiki/Image:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Missing() { // PURPOSE: bad dump shouldn't write corrupt data
|
||||
|
||||
@@ -18,12 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_parser {
|
||||
public class Xoh_img_parser {
|
||||
private byte[] src;
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public Xoh_anch_href_parser Anch_href() {return anch_href;} private Xoh_anch_href_parser anch_href = new Xoh_anch_href_parser();
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public Xoh_anch_href_itm Anch_href() {return anch_href;} private Xoh_anch_href_itm anch_href = new Xoh_anch_href_itm();
|
||||
public Xoh_anch_cls_parser Anch_cls() {return anch_cls;} private Xoh_anch_cls_parser anch_cls = new Xoh_anch_cls_parser();
|
||||
public Html_atr Anch_title() {return anch_title;} private Html_atr anch_title;
|
||||
public Bry_obj_ref Anch_page() {return anch_page;} private Bry_obj_ref anch_page = Bry_obj_ref.New_empty();
|
||||
@@ -35,29 +36,46 @@ public class Xoh_img_parser {
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public boolean Img_w__diff__file_w() {return img_w != img_src.File_w();}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_head) {
|
||||
this.src = src; Bry_rdr rdr = tag_rdr.Rdr();
|
||||
this.rng_bgn = anch_head.Src_bgn(); // <a
|
||||
if (!anch_href.Parse(rdr, hctx.App(), hctx.Wiki__ttl_parser(), anch_head)) return Xoh_hdoc_ctx.Invalid; // href='/wiki/File:A.png'
|
||||
if (!anch_cls.Parse(rdr, src, anch_head)) return Xoh_hdoc_ctx.Invalid; // class='image'
|
||||
this.anch_title = anch_head.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
|
||||
Html_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
|
||||
public boolean Rel_nofollow_exists() {
|
||||
if (anch_href.Site_exists()) {
|
||||
if (rel_nofollow_exists == Bool_.__byte) {
|
||||
Xow_domain_itm itm = Xow_domain_itm_.parse(Bry_.Mid(src, anch_href.Site_bgn(), anch_href.Site_end()));
|
||||
rel_nofollow_exists = itm.Domain_type_id() == Xow_domain_tid_.Int__other ? Bool_.Y_byte : Bool_.N_byte;
|
||||
}
|
||||
return rel_nofollow_exists == Bool_.Y_byte;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} private byte rel_nofollow_exists;
|
||||
private void Clear() {
|
||||
this.rel_nofollow_exists = Bool_.__byte;
|
||||
this.src_bgn = src_end = img_w = img_h = -1;
|
||||
this.anch_title = this.img_alt = Html_atr.Noop;
|
||||
}
|
||||
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_head) {
|
||||
this.Clear();
|
||||
this.src = src; Bry_err_wkr err_wkr = tag_rdr.Err_wkr();
|
||||
this.src_bgn = anch_head.Src_bgn(); // <a
|
||||
if (!anch_href.Parse(err_wkr, hctx, anch_head)) return false; // href='/wiki/File:A.png'
|
||||
if (!anch_cls.Parse(err_wkr, src, anch_head)) return false; // class='image'
|
||||
this.anch_title = anch_head.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
|
||||
Html_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
|
||||
if (xowa_title.Val_dat_exists()) anch_page.Val_(xowa_title.Val());
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img
|
||||
img_xoimg_parser.Parse(rdr, src, img_tag); // data-xoimg='...'
|
||||
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
|
||||
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
|
||||
this.img_alt = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
|
||||
img_cls.Parse(rdr, src, img_tag); // class='thumbborder'
|
||||
if (!img_src.Parse(rdr, hctx.Wiki__domain_bry(), img_tag)) return Xoh_hdoc_ctx.Invalid; // src='...'
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img
|
||||
img_xoimg_parser.Parse(err_wkr, src, img_tag); // data-xoimg='...'
|
||||
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
|
||||
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
|
||||
this.img_alt = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
|
||||
img_cls.Parse(err_wkr, src, img_tag); // class='thumbborder'
|
||||
if (!img_src.Parse(err_wkr, hctx.Wiki__domain_bry(), img_tag)) return false; // src='...'
|
||||
if (anch_page.Val_is_empty()) {
|
||||
anch_page.Val_(img_src.File_ttl_bry());
|
||||
if (anch_page.Val_is_empty())
|
||||
anch_page.Val_(anch_href.Page_ttl().Page_db());
|
||||
anch_page.Val_(anch_href.Ttl_page_db());
|
||||
}
|
||||
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.rng_end = anch_tail.Src_end();
|
||||
return rng_end;
|
||||
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.src_end = anch_tail.Src_end();
|
||||
return true;
|
||||
}
|
||||
public static final byte[]
|
||||
Bry__cls__anch__image = Bry_.new_a7("image")
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Xoh_img_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public Xoh_img_wtr Img_id_(byte[] prefix, int uid) {img_id.Set_by_arg(img_id_val.Set(prefix, uid)); return this;}
|
||||
public Xoh_img_wtr Img_w_(int v) {img_w.Set_by_int(v); return this;}
|
||||
public Xoh_img_wtr Img_h_(int v) {img_h.Set_by_int(v); return this;}
|
||||
public Xoh_img_wtr Img_xoimg_(byte[] src, int bgn, int end) {img_xoimg.Set_by_mid(src, bgn, end); return this;}
|
||||
public Xoh_img_wtr Img_xoimg_(Bfr_arg v) {img_xoimg.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Img_cls_(Bfr_arg v) {img_cls.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Img_src_(Bfr_arg v) {img_src.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Img_src_empty_() {img_src.Set_by_bry(Bry_.Empty); return this;}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xoh_anch_cls_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
public boolean Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
|
||||
int src_bgn = atr.Val_bgn(); int src_end = atr.Val_end();
|
||||
if (src_bgn == -1) {
|
||||
@@ -30,7 +30,7 @@ public class Xoh_anch_cls_parser {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
rdr.Init_by_sub(owner_rdr, "anch.cls", src_bgn, src_end);
|
||||
rdr.Init_by_wkr(err_wkr, "anch.cls", src_bgn, src_end);
|
||||
this.tid = rdr.Chk_or(Xoh_anch_cls_.Trie, Byte_ascii.Max_7_bit);
|
||||
return tid != Byte_ascii.Max_7_bit;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,17 @@ public class Xoh_img_cls_parser {
|
||||
public int Other_end() {return other_end;} private int other_end;
|
||||
public boolean Other_exists() {return other_end > other_bgn;}
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
public void Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='thumbborder'
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
Parse(err_wkr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
private void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
private void Parse(Bry_err_wkr err_wkr, byte[] src, int src_bgn, int src_end) {
|
||||
if (src_bgn == -1) {
|
||||
this.cls_tid = Xoh_img_cls_.Tid__none;
|
||||
this.other_bgn = this.other_end = -1;
|
||||
return;
|
||||
}
|
||||
rdr.Init_by_sub(owner_rdr, "img.cls", src_bgn, src_end);
|
||||
rdr.Init_by_wkr(err_wkr, "img.cls", src_bgn, src_end);
|
||||
this.cls_tid = rdr.Chk(Xoh_img_cls_.Trie);
|
||||
if (rdr.Is(Byte_ascii.Space)) {
|
||||
this.other_bgn = rdr.Pos();
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr(); private byte[] src;
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash); private byte[] src;
|
||||
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
|
||||
public int Val_bgn() {return val_bgn;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} private int val_end;
|
||||
@@ -45,18 +45,18 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
file_ttl_bry = null;
|
||||
atr = null;
|
||||
}
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) {
|
||||
public boolean Parse(Bry_err_wkr err_wkr, byte[] domain_bry, Html_tag tag) {
|
||||
this.Clear();
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
|
||||
if (!atr.Val_dat_exists()) return true; // empty src; just return true;
|
||||
return Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end());
|
||||
return Parse(err_wkr, domain_bry, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
|
||||
public boolean Parse(Bry_err_wkr err_wkr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
|
||||
this.Clear();
|
||||
this.src = owner_rdr.Src();
|
||||
this.src = err_wkr.Src();
|
||||
this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
if (val_end == val_bgn) return true; // empty src; just return true;
|
||||
file_w = file_time = file_page = -1;
|
||||
rdr.Init_by_sub(owner_rdr, "img.src.xowa", val_bgn, val_end).Dflt_dlm_(Byte_ascii.Slash);
|
||||
rdr.Init_by_wkr(err_wkr, "img.src.xowa", val_bgn, val_end);
|
||||
rdr.Fail_throws_err_(Bool_.N);
|
||||
repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/"
|
||||
if (repo_bgn == -1) return false;
|
||||
|
||||
@@ -36,8 +36,7 @@ public class Xoh_img_src_parser_tst {
|
||||
// fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'");
|
||||
// }
|
||||
}
|
||||
class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt_base {
|
||||
private final Xoh_img_src_parser parser = new Xoh_img_src_parser();
|
||||
class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_src_parser parser = new Xoh_img_src_parser();
|
||||
@Override public Xoh_itm_parser Parser_get() {return parser;}
|
||||
public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) {
|
||||
Exec_parse(src_str);
|
||||
@@ -48,7 +47,7 @@ class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt_base {
|
||||
Tfds.Eq_int(expd_time, parser.File_time());
|
||||
Tfds.Eq_int(expd_page, parser.File_page());
|
||||
}
|
||||
@Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) {
|
||||
parser.Parse(owner_rdr, Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
|
||||
@Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) {
|
||||
parser.Parse(err_wkr, Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.files.*;
|
||||
public class Xoh_img_xoimg_hzip {
|
||||
public void Encode(Bry_bfr bfr, Xoh_stat_itm stat_itm, byte[] src, Xoh_img_xoimg_parser arg) {
|
||||
boolean page_exists = arg.Lnki_page() != Xof_lnki_page.Null;
|
||||
boolean time_exists = arg.Lnki_time() != Xof_lnki_time.Null;
|
||||
boolean upright_exists = arg.Lnki_upright() != Xof_img_size.Upright_null;
|
||||
boolean height_exists = arg.Lnki_h() != Xof_img_size.Size__neg1;
|
||||
boolean width_exists = arg.Lnki_w() != Xof_img_size.Size__neg1;
|
||||
flag_bldr.Set(Flag__page_exists , page_exists);
|
||||
flag_bldr.Set(Flag__time_exists , time_exists);
|
||||
flag_bldr.Set(Flag__upright_exists , upright_exists);
|
||||
flag_bldr.Set(Flag__height_exists , height_exists);
|
||||
flag_bldr.Set(Flag__width_exists , width_exists);
|
||||
flag_bldr.Set(Flag__lnki_type , arg.Lnki_type());
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
if (width_exists) Xoh_hzip_int_.Encode(2, bfr, arg.Lnki_w());
|
||||
if (height_exists) Xoh_hzip_int_.Encode(2, bfr, arg.Lnki_h());
|
||||
if (upright_exists) bfr.Add_double(arg.Lnki_upright()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (time_exists) bfr.Add_double(arg.Lnki_time()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (page_exists) Xoh_hzip_int_.Encode(2, bfr, arg.Lnki_page());
|
||||
}
|
||||
public void Decode(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, Xoh_img_xoimg_parser arg) {
|
||||
int flag = rdr.Read_int_by_base85(1);
|
||||
flag_bldr.Decode(flag);
|
||||
boolean page_exists = flag_bldr.Get_as_bool(Flag__page_exists);
|
||||
boolean time_exists = flag_bldr.Get_as_bool(Flag__time_exists);
|
||||
boolean upright_exists = flag_bldr.Get_as_bool(Flag__upright_exists);
|
||||
boolean height_exists = flag_bldr.Get_as_bool(Flag__height_exists);
|
||||
boolean width_exists = flag_bldr.Get_as_bool(Flag__width_exists);
|
||||
byte tid = flag_bldr.Get_as_byte(Flag__lnki_type);
|
||||
int w = width_exists ? rdr.Read_int_by_base85(2) : Xof_img_size.Size__neg1;
|
||||
int h = height_exists ? rdr.Read_int_by_base85(2) : Xof_img_size.Size__neg1;
|
||||
double upright = upright_exists ? rdr.Read_double_to(Xoh_hzip_dict_.Escape) : Xof_img_size.Upright_null;
|
||||
double time = time_exists ? rdr.Read_double_to(Xoh_hzip_dict_.Escape) : Xof_lnki_time.Null;
|
||||
int page = page_exists ? rdr.Read_int_by_base85(2) : Xof_lnki_page.Null;
|
||||
arg.Set(tid, w, h, upright, time, page);
|
||||
}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1 , 1, 1, 1, 3);
|
||||
private static final int // SERIALIZED
|
||||
Flag__page_exists = 0
|
||||
, Flag__time_exists = 1
|
||||
, Flag__upright_exists = 2
|
||||
, Flag__height_exists = 3
|
||||
, Flag__width_exists = 4 // none, thumbimage, thumbborder
|
||||
, Flag__lnki_type = 5 // null, none, frameless, frame, thumb; gplx.xowa.parsers.lnkis.Xop_lnki_type
|
||||
;
|
||||
}
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_img_xoimg_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public class Xoh_img_xoimg_parser implements Bfr_arg {
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Pipe);
|
||||
public int Val_bgn() {return val_bgn;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} private int val_end;
|
||||
public boolean Val_dat_exists() {return val_end > val_bgn;}
|
||||
@@ -32,15 +32,23 @@ public class Xoh_img_xoimg_parser {
|
||||
public void Clear() {
|
||||
val_bgn = val_end = -1;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
public void Set(byte tid, int w, int h, double upright, double time, int page) {
|
||||
this.lnki_type = tid;
|
||||
this.lnki_w = w;
|
||||
this.lnki_h = h;
|
||||
this.lnki_upright = upright;
|
||||
this.lnki_time = time;
|
||||
this.lnki_page = page;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
public void Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
|
||||
Parse(err_wkr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_err_wkr err_wkr, byte[] src, int src_bgn, int src_end) {
|
||||
if (src_bgn == -1)
|
||||
this.Clear();
|
||||
else {
|
||||
rdr.Init_by_sub(owner_rdr, "img.xoimg", src_bgn, src_end).Dflt_dlm_(Byte_ascii.Pipe);
|
||||
rdr.Init_by_wkr(err_wkr, "img.xoimg", src_bgn, src_end);
|
||||
this.val_bgn = src_bgn;
|
||||
this.val_end = src_end;
|
||||
this.lnki_type = (byte)(rdr.Read_byte_to() - Byte_ascii.Num_0);
|
||||
@@ -51,6 +59,16 @@ public class Xoh_img_xoimg_parser {
|
||||
this.lnki_page = rdr.Read_int_to();
|
||||
}
|
||||
}
|
||||
public void Bfr_arg__clear() {}
|
||||
public boolean Bfr_arg__exists() {return true;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_int_variable(lnki_type).Add_byte_pipe();
|
||||
bfr.Add_int_variable(lnki_w).Add_byte_pipe();
|
||||
bfr.Add_int_variable(lnki_h).Add_byte_pipe();
|
||||
bfr.Add_double(lnki_upright).Add_byte_pipe();
|
||||
bfr.Add_double(lnki_time).Add_byte_pipe();
|
||||
bfr.Add_int_variable(lnki_page);
|
||||
}
|
||||
public static final byte[]
|
||||
Bry__name = Bry_.new_a7("data-xoimg")
|
||||
, Bry__html = Bry_.new_a7("\" data-xoimg=\"")
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user