mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -13,3 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Xoh_cfg_file {
|
||||
public Xoh_cfg_file(Gfo_url_encoder url_encoder, Io_url xowa_dir) {
|
||||
Io_url mw_file_dir = xowa_dir.GenSubDir_nest("file", "mediawiki.file");
|
||||
img_media_play_btn = url_encoder.Encode_to_file_protocol(mw_file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = url_encoder.Encode_to_file_protocol(mw_file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = url_encoder.Encode_to_file_protocol(mw_file_dir.GenSubFil("magnify-clip.png"));
|
||||
}
|
||||
public byte[] Img_media_play_btn() {return img_media_play_btn;} private final byte[] img_media_play_btn;
|
||||
public byte[] Img_media_info_btn() {return img_media_info_btn;} private final byte[] img_media_info_btn;
|
||||
public byte[] Img_thumb_magnify() {return img_thumb_magnify;} private final byte[] img_thumb_magnify;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoh_cmd_itm {
|
||||
String Hcmd_id();
|
||||
void Hcmd_exec(Xoae_app app, Gfo_usr_dlg usr_dlg, Xoae_page page);
|
||||
void Hcmd_write(Xoae_app app, Gfo_usr_dlg usr_dlg, Xoae_page page);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,26 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_cmd_mgr {
|
||||
public int Count() {return cmds.Count();}
|
||||
public void Clear() {cmds.Clear();}
|
||||
public void Add(Xoh_cmd_itm itm) {cmds.Add(itm);} List_adp cmds = List_adp_.New();
|
||||
public void Exec(Xoae_app app, Xoae_page page) {
|
||||
int len = cmds.Count();
|
||||
if (len == 0) return;
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
usr_dlg.Prog_one(GRP_KEY, "bgn", "cmds bgn: ~{0}", len); // NOTE: this message will not show, but is needed for other messages to show; SWT swallowing 1st msg before showing others?; DATE:2013-04-25
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (usr_dlg.Canceled()) {usr_dlg.Prog_none(GRP_KEY, "cmds.done", ""); app.Log_wtr().Queue_enabled_(false); return;}
|
||||
Xoh_cmd_itm itm = null;
|
||||
try {
|
||||
itm = (Xoh_cmd_itm)cmds.Get_at(i);
|
||||
itm.Hcmd_exec(app, usr_dlg, page);
|
||||
itm.Hcmd_write(app, usr_dlg, page);
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to execute html cmd", "name", itm == null ? "unknown" : itm.Hcmd_id());}
|
||||
}
|
||||
this.Clear();
|
||||
}
|
||||
static final String GRP_KEY = "xowa.html.cmd_mgr";
|
||||
}
|
||||
|
||||
@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_consts {
|
||||
public static final String
|
||||
Atr_xowa_title_str = "xowa_title"
|
||||
, Img_w_str = "width"
|
||||
, Img_h_str = "height"
|
||||
;
|
||||
public static final byte[]
|
||||
__end = Bry_.new_a7(">")
|
||||
, __inline = Bry_.new_a7("/>")
|
||||
, __end_quote = Bry_.new_a7("\">")
|
||||
, __inline_quote = Bry_.new_a7("\"/>")
|
||||
, Space_2 = Bry_.new_a7(" ")
|
||||
|
||||
, A_mid_id = Bry_.new_a7("\" id=\"xolnki_")
|
||||
, Div_bgn_open = Bry_.new_a7("<div ")
|
||||
|
||||
, Img_bgn = Bry_.new_a7("<img src=\"")
|
||||
, Span_bgn_open = Bry_.new_a7("<span")
|
||||
, Span_end = Bry_.new_a7("</span>")
|
||||
, Span_bgn = Bry_.new_a7("<span>")
|
||||
|
||||
, Pre_bgn = Bry_.new_a7("<pre>"), Pre_end = Bry_.new_a7("</pre>")
|
||||
, Pre_bgn_open = Bry_.new_a7("<pre")
|
||||
, Pre_bgn_overflow = Bry_.new_a7("<pre style=\"overflow:auto\">")
|
||||
|
||||
, Code_bgn_closed = Bry_.new_a7("<code>")
|
||||
, Code_bgn_open = Bry_.new_a7("<code")
|
||||
, Code_end = Bry_.new_a7("</code>")
|
||||
, Id_atr = Bry_.new_a7(" id=\"")
|
||||
, Style_atr = Bry_.new_a7(" style=\"")
|
||||
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
|
||||
;
|
||||
public static final int Nbsp_int = 160;
|
||||
public static String Escape_apos(String s) {return String_.Replace(s, "'", "\"");}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.core.htmls.tidy.*; import gplx.xowa.htmls.js.*; import gplx.xowa.htmls.skins.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_mgr implements Gfo_invk {
|
||||
public Xoh_html_mgr(Xoae_app app) {}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
page_mgr.Init_by_app(app);
|
||||
}
|
||||
public Xoh_page_mgr Page_mgr() {return page_mgr;} private final Xoh_page_mgr page_mgr = new Xoh_page_mgr();
|
||||
public Xoh_skin_mgr Skin_mgr() {return skin_mgr;} private final Xoh_skin_mgr skin_mgr = new Xoh_skin_mgr();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page)) return page_mgr;
|
||||
else if (ctx.Match(k, Invk_skins)) return skin_mgr;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_page = "page", Invk_skins = "skins";
|
||||
}
|
||||
|
||||
@@ -13,3 +13,38 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_mgr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private int uid_nxt = -1;
|
||||
public void Clear() {
|
||||
this.uid_nxt = -1;
|
||||
list.Clear();
|
||||
}
|
||||
public int Len() {return list.Count();}
|
||||
public Xof_fsdb_itm Get_at(int i) {return (Xof_fsdb_itm)list.Get_at(i);}
|
||||
public Xof_fsdb_itm Make_aud() {
|
||||
Xof_fsdb_itm itm = new Xof_fsdb_itm();
|
||||
itm.Init_at_hdoc(++uid_nxt, Xof_html_elem.Tid_aud);
|
||||
list.Add(itm);
|
||||
return itm;
|
||||
}
|
||||
public Xof_fsdb_itm Make_img(boolean img_is_gallery) {
|
||||
Xof_fsdb_itm itm = new Xof_fsdb_itm();
|
||||
itm.Init_at_hdoc(++uid_nxt, img_is_gallery ? Xof_html_elem.Tid_gallery : Xof_html_elem.Tid_img);
|
||||
if (img_is_gallery)
|
||||
itm.Html_gallery_mgr_h_(gplx.xowa.xtns.gallery.Gallery_xnde.Default); // TODO_OLD:set to <gallery heights=val>; PAGE:en.w:National_Gallery_of_Art; DATE:2016-06-25
|
||||
list.Add(itm);
|
||||
return itm;
|
||||
}
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_fsdb_itm itm = this.Get_at(i);
|
||||
itm.To_bfr(bfr);
|
||||
}
|
||||
}
|
||||
public static final String Str__html_uid = "xoimg_";
|
||||
public static final byte[] Bry__html_uid = Bry_.new_a7(Str__html_uid);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,92 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.redirects.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.addons.htmls.tocs.*;
|
||||
import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*; import gplx.xowa.wikis.pages.wtxts.*;
|
||||
public class Xoh_page implements Xoa_page {
|
||||
// core
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public Xoa_url Url() {return page_url;} private Xoa_url page_url;
|
||||
public Xoa_ttl Ttl() {return page_ttl;} private Xoa_ttl page_ttl;
|
||||
public Xopg_db_data Db() {return db;} private final Xopg_db_data db = new Xopg_db_data();
|
||||
public Xopg_redirect_mgr Redirect_trail() {return redirect;} private final Xopg_redirect_mgr redirect = new Xopg_redirect_mgr();
|
||||
public Xopg_html_data Html_data() {return html;} private final Xopg_html_data html = new Xopg_html_data();
|
||||
public Xopg_wtxt_data Wtxt() {return wtxt;} private final Xopg_wtxt_data wtxt = new Xopg_wtxt_data();
|
||||
public Xopg_hdump_data Hdump_mgr() {return hdump;} private final Xopg_hdump_data hdump = new Xopg_hdump_data();
|
||||
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
|
||||
private Guid_adp page_guid;
|
||||
public Guid_adp Page_guid() {
|
||||
if (page_guid == null) {
|
||||
page_guid = Guid_adp_.New();
|
||||
}
|
||||
return page_guid;
|
||||
}
|
||||
|
||||
public boolean Xtn__timeline_exists() {return xtn__timeline_exists;} private boolean xtn__timeline_exists; public void Xtn__timeline_exists_y_() {xtn__timeline_exists = true;}
|
||||
public boolean Xtn__gallery_exists() {return xtn__gallery_exists;} private boolean xtn__gallery_exists; public void Xtn__gallery_exists_y_() {xtn__gallery_exists = true;}
|
||||
|
||||
// props
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} private byte[] sidebar_div;
|
||||
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
|
||||
public Xoh_img_mgr Img_mgr() {return img_mgr;} private Xoh_img_mgr img_mgr = new Xoh_img_mgr();
|
||||
public Xopg_module_mgr Head_mgr() {return head_mgr;} private Xopg_module_mgr head_mgr = new Xopg_module_mgr();
|
||||
|
||||
// util
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public int Exec_tid() {return exec_tid;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
|
||||
public byte[] Html_head_xtn() {return html_head_xtn;} public void Html_head_xtn_(byte[] v) {html_head_xtn = v;} private byte[] html_head_xtn = Bry_.Empty; // drd:web_browser
|
||||
public byte[] Url_bry_safe() {return Xoa_page_.Url_bry_safe(page_url, wiki, page_ttl);}
|
||||
public void Ctor_by_hview(Xow_wiki wiki, Xoa_url page_url, Xoa_ttl page_ttl, int page_id) {
|
||||
this.wiki = wiki; this.page_url = page_url; this.page_ttl = page_ttl; this.page_id = page_id;
|
||||
this.lang = wiki.Lang();
|
||||
this.Clear();
|
||||
html.Redlink_list().Disabled_(page_ttl.Ns().Id_is_module()); // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
|
||||
html.Toc_mgr().Init(gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface_.Noop, wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), page_url.Raw());
|
||||
}
|
||||
public Xoh_page Ctor_by_hdiff(Bry_bfr tmp_bfr, Xoae_page page, byte[] toc_label) {
|
||||
this.wiki = page.Wiki(); this.page_url = page.Url(); this.page_ttl = page.Ttl(); this.page_id = page.Db().Page().Id();
|
||||
this.lang = wiki.Lang();
|
||||
|
||||
db.Html().Html_bry_(page.Db().Html().Html_bry());
|
||||
|
||||
Xopg_html_data html = page.Html_data();
|
||||
html.Init_by_page(page.Ttl());
|
||||
Xoh_head_mgr mod_mgr = html.Head_mgr();
|
||||
head_mgr.Init(mod_mgr.Itm__mathjax().Enabled(), mod_mgr.Itm__popups().Bind_hover_area(), mod_mgr.Itm__gallery().Enabled(), mod_mgr.Itm__hiero().Enabled());
|
||||
this.display_ttl = html.Display_ttl();
|
||||
this.content_sub = html.Content_sub();
|
||||
this.sidebar_div = Xoh_page_.Save_sidebars(tmp_bfr, page, html);
|
||||
|
||||
html.Toc_mgr().Init(page.Wikie().Html_mgr().Tidy_mgr(), toc_label, page_url.Page_bry()); // NOTE: do not pass in noop tidy_mgr, else broken TOC html will never get corrected during hdump; DATE:2016-08-14
|
||||
return this;
|
||||
}
|
||||
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, int zip_tid, int hzip_tid, byte[] body) {
|
||||
head_mgr.Flag_(head_flag);
|
||||
this.display_ttl = display_ttl; this.content_sub = content_sub; this.sidebar_div = sidebar_div;
|
||||
db.Html().Html_bry_(body);
|
||||
db.Html().Zip_tids_(zip_tid, hzip_tid);
|
||||
}
|
||||
public void Clear() {
|
||||
redirect.Clear();
|
||||
html.Clear();
|
||||
wtxt.Clear();
|
||||
hdump.Clear();
|
||||
db.Clear();
|
||||
|
||||
display_ttl = content_sub = sidebar_div = Bry_.Empty;
|
||||
head_mgr.Clear(); commons_mgr.Clear();
|
||||
section_mgr.Clear(); img_mgr.Clear();
|
||||
}
|
||||
public static Xoh_page New_missing() {
|
||||
Xoh_page rv = new Xoh_page();
|
||||
rv.Db().Page().Exists_n_();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.htmls.*;
|
||||
public class Xoh_page_ {
|
||||
public static byte[] Save_sidebars(Bry_bfr tmp_bfr, Xoae_page page, Xopg_html_data html_data) {
|
||||
Xopg_xtn_skin_mgr mgr = html_data.Xtn_skin_mgr();
|
||||
int len = mgr.Count();
|
||||
boolean sidebar_exists = false;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_xtn_skin_itm itm = mgr.Get_at(i);
|
||||
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
|
||||
sidebar_exists = true;
|
||||
itm.Write(tmp_bfr, page);
|
||||
}
|
||||
}
|
||||
return sidebar_exists ? tmp_bfr.To_bry_and_clear() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,36 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
public class Xoh_page_bfr {
|
||||
private byte toc_mode;
|
||||
private Bry_bfr head_bfr; private final Bry_bfr body_bfr = Bry_bfr_.New();
|
||||
public void Init(Bry_bfr head_bfr) {
|
||||
this.toc_mode = Xoh_toc_data.Toc_mode__none;
|
||||
this.head_bfr = head_bfr;
|
||||
body_bfr.Clear();
|
||||
}
|
||||
public Bry_bfr Split_by_toc(byte toc_mode) {
|
||||
if (this.toc_mode != Xoh_toc_data.Toc_mode__pgbnr)// NOTE: "none" and "pgbnr" can exist on same page (especially in en.v); must make sure that "none" does not overwrite "pgbnr" else wide images; PAGE:en.v:UNESCO_World_Heritage_List DATE:2016-11-03
|
||||
this.toc_mode = toc_mode;
|
||||
return body_bfr;
|
||||
}
|
||||
public void Commit(Xoa_page pg) {
|
||||
boolean toc_mode_enabled = true, toc_mode_is_pgbnr = false; // default to Xoh_toc_data_.Toc_mode__basic
|
||||
switch (toc_mode) {
|
||||
case Xoh_toc_data.Toc_mode__none : toc_mode_enabled = false; break;
|
||||
case Xoh_toc_data.Toc_mode__pgbnr : toc_mode_is_pgbnr = true; break;
|
||||
}
|
||||
|
||||
// set flags
|
||||
pg.Html_data().Toc_mgr().Exists_y_();
|
||||
pg.Html_data().Head_mgr().Itm__pgbnr().Enabled_(toc_mode_is_pgbnr);
|
||||
|
||||
// build bfr by add bfr_0, toc, body_bfr
|
||||
if (toc_mode_enabled) {
|
||||
pg.Html_data().Toc_mgr().To_html(head_bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, toc_mode_is_pgbnr);
|
||||
head_bfr.Add_bfr_and_clear(body_bfr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,7 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoh_page_html_source {
|
||||
byte[] Get_page_html();
|
||||
}
|
||||
|
||||
@@ -13,3 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_page_html_source_ {
|
||||
public static Xoh_page_html_source
|
||||
Wtr = new Xoh_page_html_source__wtr()
|
||||
, Noop = new Xoh_page_html_source__noop()
|
||||
;
|
||||
}
|
||||
class Xoh_page_html_source__wtr implements Xoh_page_html_source {
|
||||
public byte[] Get_page_html() {return null;}
|
||||
}
|
||||
class Xoh_page_html_source__noop implements Xoh_page_html_source {
|
||||
public byte[] Get_page_html() {return null;}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,49 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.portal.*;
|
||||
public class Xoh_page_mgr implements Gfo_invk {
|
||||
private boolean font_enabled = false;
|
||||
private String font_name = "Arial";
|
||||
private byte[] font_css_bry = Bry_.Empty, custom_script = Bry_.Empty;
|
||||
private final Bry_fmt font_css_fmt = Bry_fmt.Auto("body {font-family: ~{font_name}; font-size: ~{font_size}px;}");
|
||||
public float Font_size() {return font_size;} private float font_size = Font_size_default;
|
||||
private void Font_css_bry_() {
|
||||
font_css_bry = font_css_fmt.Bld_many_to_bry(Bry_bfr_.New(), font_name, font_size);
|
||||
}
|
||||
public void Write_css(gplx.xowa.htmls.heads.Xoh_head_wtr wtr) {
|
||||
if (font_enabled)
|
||||
wtr.Write_css_style_itm(font_css_bry);
|
||||
if (Bry_.Len_gt_0(custom_script))
|
||||
wtr.Write_css_style_itm(custom_script);
|
||||
}
|
||||
|
||||
public Bry_fmt Content_code_fmt() {return content_code_fmt;} private final Bry_fmt content_code_fmt = Bry_fmt.Auto("<pre>~{page_text}</pre>");
|
||||
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private final Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
app.Cfg().Bind_many_app(this, Cfg__font_enabled, Cfg__font_name, Cfg__font_size, Cfg__font_format, Cfg__custom_script, Cfg__content_code_fmt);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Cfg__font_enabled)) font_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Cfg__font_name)) {font_name = m.ReadStr("v"); Font_css_bry_();}
|
||||
else if (ctx.Match(k, Cfg__font_size)) {font_size = m.ReadFloat("v"); Font_css_bry_();}
|
||||
else if (ctx.Match(k, Cfg__font_format)) {font_css_fmt.Fmt_(m.ReadBry("v")); Font_css_bry_();}
|
||||
else if (ctx.Match(k, Cfg__custom_script)) custom_script = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Cfg__content_code_fmt)) content_code_fmt.Fmt_(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static final String
|
||||
Cfg__font_enabled = "xowa.html.css.font.enabled"
|
||||
, Cfg__font_size = "xowa.html.css.font.size"
|
||||
;
|
||||
private static final String
|
||||
Cfg__font_name = "xowa.html.css.font.name"
|
||||
, Cfg__font_format = "xowa.html.css.font.format"
|
||||
, Cfg__custom_script = "xowa.html.css.custom.script"
|
||||
, Cfg__content_code_fmt = "xowa.html.page.content_code_fmt"
|
||||
;
|
||||
public static final float Font_size_default = 16;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,99 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_mgr implements Gfo_invk {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255), html_bfr = Bry_bfr_.Reset(Io_mgr.Len_mb);
|
||||
private Xoh_page_wtr_wkr edit_wtr, html_wtr, read_wtr;
|
||||
public Xoh_page_wtr_mgr(boolean html_capable) {
|
||||
this.html_capable = html_capable;
|
||||
this.read_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_read);
|
||||
this.edit_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_edit);
|
||||
this.html_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_html);
|
||||
}
|
||||
public boolean Html_capable() {return html_capable;} public Xoh_page_wtr_mgr Html_capable_(boolean v) {html_capable = v; return this;} private boolean html_capable;
|
||||
public byte[] Css_common_bry() {return css_common_bry;} private byte[] css_common_bry;
|
||||
public byte[] Css_wiki_bry() {return css_wiki_bry;} private byte[] css_wiki_bry;
|
||||
public byte[] Css_night_bry(boolean nightmode_enabled) {return nightmode_enabled ? css_night_bry : Bry_.Empty;} private byte[] css_night_bry;
|
||||
public boolean Scripting_enabled() {return scripting_enabled;} private boolean scripting_enabled;
|
||||
public Bry_fmtr Page_read_fmtr() {return page_read_fmtr;} private Bry_fmtr page_read_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public Bry_fmtr Page_edit_fmtr() {return page_edit_fmtr;} private Bry_fmtr page_edit_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public Bry_fmtr Page_html_fmtr() {return page_html_fmtr;} private Bry_fmtr page_html_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public byte[] Edit_rename_div_bry(Xoa_ttl ttl) {return div_edit_rename_fmtr.Bld_bry_many(tmp_bfr, ttl.Full_db());}
|
||||
public void Init_css_urls(Xoa_app app, String wiki_domain, Io_url css_common_url, Io_url css_wiki_url) {
|
||||
this.css_common_bry = css_common_url.To_http_file_bry();
|
||||
this.css_wiki_bry = css_wiki_url.To_http_file_bry();
|
||||
|
||||
// xowa_night.css;
|
||||
Io_url css_night_url = app.Fsys_mgr().Url_finder().Find_by_css_or(wiki_domain, "xowa_night.css", String_.Ary("bin", "any", "xowa", "html", "css", "nightmode"), true);
|
||||
this.css_night_bry = Bry_.new_u8("<link rel=\"stylesheet\" href=\"" + css_night_url.To_http_file_str() + "\" type=\"text/css\">");
|
||||
}
|
||||
public void Init_(boolean v) {init = v;} private boolean init = true;
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__scripting_enabled);
|
||||
}
|
||||
public byte[] Gen(Xoae_page page, byte output_tid) {return Gen(page, Xoh_page_html_source_.Noop, output_tid);}
|
||||
public byte[] Gen(Xoae_page page, Xoh_page_html_source page_html_source, byte output_tid) {
|
||||
Xoh_page_wtr_wkr wtr = Wkr(output_tid);
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
if (init) {
|
||||
init = false;
|
||||
page_read_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
page_html_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
}
|
||||
wtr.Write_page(html_bfr, page, wiki.Parser_mgr().Ctx(), page_html_source);
|
||||
return html_bfr.To_bry_and_clear_and_rls();
|
||||
}
|
||||
public Xoh_page_wtr_wkr Wkr(byte output_tid) {
|
||||
switch (output_tid) {
|
||||
case Xopg_page_.Tid_edit: return edit_wtr;
|
||||
case Xopg_page_.Tid_html: return html_wtr;
|
||||
case Xopg_page_.Tid_read: return read_wtr;
|
||||
default: throw Err_.new_unhandled(output_tid);
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page_read_)) page_read_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_page_edit_)) page_edit_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_page_html_)) page_html_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_xowa_div_edit_rename_)) div_edit_rename_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Cfg__scripting_enabled)) scripting_enabled = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private Bry_fmtr div_edit_rename_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( " <input id='xowa_edit_rename_box' width='120' height='20' />"
|
||||
, " <a href='xowa-cmd:app.gui.main_win.page_edit_rename;' class='xowa_anchor_button' style='width:100px;max-width:1024px;'>"
|
||||
, " Rename page"
|
||||
, " </a>"
|
||||
, " <a href='/wiki/Special:MovePage?wpOldTitle=~{src_full_db}' class='xowa_anchor_button' style='width:100px;max-width:1024px;'>"
|
||||
, " Special:MovePage"
|
||||
, " </a>"
|
||||
), "src_full_db");
|
||||
public static final String Invk_page_read_ = "page_read_", Invk_page_edit_ = "page_edit_", Invk_page_html_ = "page_html_", Invk_xowa_div_edit_rename_ = "xowa_div_edit_rename_";
|
||||
private static final String[] Fmtr_keys = new String[]
|
||||
{ "app_root_dir", "app_version", "app_build_date", "xowa_mode_is_server"
|
||||
, "page_id", "page_ttl_full", "page_name", "page_heading", "page_modified_on_msg"
|
||||
, "html_css_common_path", "html_css_wiki_path", "html_css_night_tag", "xowa_head"
|
||||
, "page_lang_ltr", "page_indicators", "page_content_sub", "page_jumpto", "page_pgbnr", "page_body_cls", "html_content_editable"
|
||||
, "page_data", "page_langs"
|
||||
, "portal_div_footer"
|
||||
, "portal_div_personal", "portal_div_ns", "portal_div_view"
|
||||
, "portal_div_logo", "portal_div_home", "portal_div_xtn"
|
||||
, "portal_div_admin", "portal_div_wikis", "portal_sidebar"
|
||||
, "edit_div_rename", "edit_div_preview", "js_edit_toolbar"
|
||||
};
|
||||
private static final String Cfg__scripting_enabled = "xowa.html.scripting.enabled";
|
||||
}
|
||||
/*
|
||||
NOTE_1:xowa_anchor_button
|
||||
. used for media (WP forces javascript with oggplayer. wanted "simpler" model)
|
||||
. display:inline-block; must be set for centering to work; see USSR and anthem; (display:block; must be enabled in order for padding to work)
|
||||
. text-align:center; forces img to be in center
|
||||
|
||||
General notes:
|
||||
. contentSub div is needed; PAGE:en.w:Battle of Spotsylvania Court House
|
||||
*/
|
||||
|
||||
@@ -13,3 +13,33 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_mgr_tst {
|
||||
@Before public void init() {}
|
||||
@Test public void Logo_has_correct_main_page() { // PURPOSE: Logo href should be "/site/en.wikipedia.org/wiki/", not "/wiki/Main_Page"
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr();
|
||||
Gfo_invk_.Invk_by_val(portal_mgr, Xow_portal_mgr.Invk_div_logo_, Bry_.new_a7("~{portal_nav_main_href}"));
|
||||
portal_mgr.Init_assert();
|
||||
Xoh_page_wtr_mgr page_wtr_mgr = new Xoh_page_wtr_mgr(true);
|
||||
page_wtr_mgr.Gen(wiki.Parser_mgr().Ctx().Page(), Xopg_page_.Tid_read);
|
||||
Tfds.Eq(String_.new_a7(portal_mgr.Div_logo_bry(true)), "/site/en.wikipedia.org/wiki/");
|
||||
}
|
||||
@Test public void Skip__math__basic() {
|
||||
Xop_fxt fxt = Xop_fxt.New_app_html();
|
||||
fxt.Init_lang_vnts("zh-hans", "zh-hant");
|
||||
|
||||
fxt.Test__parse_to_html_mgr(String_.Concat_lines_nl_skip_last
|
||||
( "<math>x_{1}-1</math>"
|
||||
, "<math>x-{1+2}-1</math>"
|
||||
, "-{zh-hans:A;zh-hant:B;}-"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<span id='xowa_math_txt_0'>x_{1}-1</span>" // not converted
|
||||
, "<span id='xowa_math_txt_0'>x-{1+2}-1</span>" // not converted
|
||||
, "A" // converted
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,242 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.langs.htmls.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.parsers.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.xtns.pagebanners.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_page_wtr_wkr {
|
||||
private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
private final Xoh_page_wtr_mgr mgr; private final byte page_mode;
|
||||
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr(); // In other languages
|
||||
private final gplx.xowa.addons.apps.scripts.Xoscript_mgr scripting_mgr = new gplx.xowa.addons.apps.scripts.Xoscript_mgr();
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page; private byte[] root_dir_bry;
|
||||
public Xoh_page_wtr_wkr(Xoh_page_wtr_mgr mgr, byte page_mode) {this.mgr = mgr; this.page_mode = page_mode;}
|
||||
public Xoh_page_wtr_wkr Ctgs_enabled_(boolean v) {ctgs_enabled = v; return this;} private boolean ctgs_enabled = true;
|
||||
public void Write_page(Bry_bfr rv, Xoae_page page, Xop_ctx ctx, Xoh_page_html_source page_html_source) {
|
||||
synchronized (thread_lock_1) {
|
||||
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
ctx.Page_(page); // HACK: must update page for toc_mgr; WHEN: Xoae_page rewrite
|
||||
Bry_fmtr fmtr = null;
|
||||
if (mgr.Html_capable()) {
|
||||
wdata_lang_wtr.Page_(page);
|
||||
byte view_mode = page_mode;
|
||||
switch (page_mode) {
|
||||
case Xopg_page_.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break;
|
||||
case Xopg_page_.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xopg_page_.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML
|
||||
case Xopg_page_.Tid_read: fmtr = mgr.Page_read_fmtr();
|
||||
// ctx.Page().Redlink_list().Clear(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately); NOTE: probably put in to handle reusable redlink lists; redlink lists are now instantiated per page, so clear is not useful
|
||||
break;
|
||||
}
|
||||
Bry_bfr page_bfr = wiki.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page rv to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
|
||||
Xoh_wtr_ctx hctx = null;
|
||||
if (page_mode == Xopg_page_.Tid_html && wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid_is_custom()) {
|
||||
byte[] html_bry = null;
|
||||
|
||||
// get html from html dump
|
||||
if (wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid() == Xow_hdump_mode.Hdump_save.Tid()) {
|
||||
hctx = Xoh_wtr_ctx.Hdump;
|
||||
Write_body(page_bfr, ctx, hctx, page);
|
||||
html_bry = page_bfr.To_bry_and_clear();
|
||||
}
|
||||
// get from swt browser
|
||||
else {
|
||||
html_bry = page_html_source.Get_page_html();
|
||||
}
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(html_bry));
|
||||
}
|
||||
else {
|
||||
hctx = Xoh_wtr_ctx.Basic;
|
||||
Write_body(page_bfr, ctx, hctx, page);
|
||||
Write_page_by_tid(ctx, hctx, view_mode, rv, fmtr, page_bfr.To_bry_and_rls());
|
||||
scripting_mgr.Write(rv, wiki, page);
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(rv.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
Write_body(rv, ctx, Xoh_wtr_ctx.Basic, page);
|
||||
this.page = null;
|
||||
}
|
||||
}
|
||||
private void Write_page_by_tid(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte html_gen_tid, Bry_bfr bfr, Bry_fmtr fmtr, byte[] page_data) {
|
||||
// if custom_html, use it and exit; needed for Default_tab
|
||||
byte[] custom_html = page.Html_data().Custom_html();
|
||||
if (custom_html != null) {bfr.Add(custom_html); return;}
|
||||
// temp variables
|
||||
if (root_dir_bry == null) this.root_dir_bry = app.Fsys_mgr().Root_dir().To_http_file_bry();
|
||||
Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db());
|
||||
DateAdp modified_on = page.Db().Page().Modified_on();
|
||||
byte[] modified_on_msg = wiki.Msg_mgr().Val_by_id_args(Xol_msg_itm_.Id_portal_lastmodified, modified_on.XtoStr_fmt_yyyy_MM_dd(), modified_on.XtoStr_fmt_HHmm());
|
||||
byte[] page_body_class = Xoh_page_body_cls.Calc(tmp_bfr, page_ttl, page_tid);
|
||||
// byte[] html_content_editable = wiki.Gui_mgr().Cfg_browser().Content_editable() ? Content_editable_bry : Bry_.Empty;
|
||||
byte[] html_content_editable = Bry_.Empty;
|
||||
byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr);
|
||||
byte[] js_edit_toolbar_bry = html_gen_tid == Xopg_page_.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) {
|
||||
byte[] converted_title = vnt_mgr.Convert_lang().Converted_title(); // prefer converted title
|
||||
if (converted_title == null) // converted title does not exist; use regular page title and convert it
|
||||
converted_title = vnt_mgr.Convert_lang().Auto_convert(vnt_mgr.Cur_itm(), page_ttl.Page_txt());
|
||||
page_ttl = Xoa_ttl.Parse(wiki, page_ttl.Ns().Id(), converted_title);
|
||||
}
|
||||
byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null
|
||||
byte[] page_display_title = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
|
||||
page.Html_data().Custom_tab_name_(page_name); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
|
||||
boolean nightmode_enabled = app.Gui_mgr().Nightmode_mgr().Enabled();
|
||||
fmtr.Bld_bfr_many(bfr
|
||||
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
|
||||
, page.Db().Page().Id(), page.Ttl().Full_db()
|
||||
, page_name, page.Html_data().Page_heading().Init(wiki, html_gen_tid == Xopg_page_.Tid_read, page.Html_data(), page.Ttl().Full_db(), page_display_title)
|
||||
, modified_on_msg
|
||||
, mgr.Css_common_bry(), mgr.Css_wiki_bry()
|
||||
, mgr.Css_night_bry(nightmode_enabled)
|
||||
, page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
|
||||
, page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), wiki.Xtn_mgr().Xtn_pgbnr().Write_html(page, ctx, hctx), page_body_class, html_content_editable
|
||||
, page_data, wdata_lang_wtr
|
||||
, portal_mgr.Div_footer(modified_on_msg, Xoa_app_.Version, Xoa_app_.Build_date)
|
||||
|
||||
// sidebar divs
|
||||
, portal_mgr.Div_personal_bry()
|
||||
, portal_mgr.Div_ns_bry(wiki.Utl__bfr_mkr(), page_ttl, wiki.Ns_mgr())
|
||||
, portal_mgr.Div_view_bry(wiki.Utl__bfr_mkr(), html_gen_tid, page.Html_data().Xtn_search_text())
|
||||
, portal_mgr.Div_logo_bry(nightmode_enabled), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar)
|
||||
, portal_mgr.Div_sync_bry(tmp_bfr, wiki.Page_mgr().Sync_mgr().Manual_enabled(), wiki, page)
|
||||
, portal_mgr.Div_wikis_bry(wiki.Utl__bfr_mkr())
|
||||
, portal_mgr.Sidebar_mgr().Html_bry()
|
||||
, mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry
|
||||
);
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(bfr, tmp_bfr, page); // add after </head>
|
||||
Xoh_page_wtr_wkr_.Bld_html_end(bfr, tmp_bfr, page); // add after </html>
|
||||
}
|
||||
public void Write_hdump(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page wpg) {
|
||||
if (wpg.Html_data().Xtn_pgbnr() != null) {
|
||||
ctx.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(wpg, ctx, hctx).Bfr_arg__add(bfr); // if pgbnr exists, write to top of html
|
||||
}
|
||||
this.Write_body(bfr, ctx, hctx, wpg);
|
||||
}
|
||||
public void Write_body(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page page) {
|
||||
synchronized (thread_lock_2) {
|
||||
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db()); // NOTE: can't cache page_tid b/c Write_body is called directly; DATE:2014-10-02
|
||||
byte[] data_raw = page.Db().Text().Text_bry();
|
||||
int bfr_page_bgn = bfr.Len();
|
||||
boolean page_tid_uses_pre = false;
|
||||
if (page_mode == Xopg_page_.Tid_edit)
|
||||
Write_body_edit(bfr, data_raw, page_ns_id, page_tid);
|
||||
else {
|
||||
switch (page_tid) {
|
||||
case Xow_page_tid.Tid_msg:
|
||||
case Xow_page_tid.Tid_js:
|
||||
case Xow_page_tid.Tid_css:
|
||||
case Xow_page_tid.Tid_lua: Write_body_pre (bfr, app, wiki, hctx, data_raw, tmp_bfr); page_tid_uses_pre = true; break;
|
||||
case Xow_page_tid.Tid_json: app.Wiki_mgr().Wdata_mgr().Write_json_as_html(bfr, page_ttl.Full_db(), data_raw); break;
|
||||
case Xow_page_tid.Tid_wikitext: Write_body_wikitext (bfr, app, wiki, data_raw, ctx, hctx, page, page_tid, page_ns_id); break;
|
||||
}
|
||||
}
|
||||
if ( wiki.Domain_tid() != Xow_domain_tid_.Tid__home // allow home wiki to use javascript
|
||||
&& !page.Html_data().Js_enabled() // allow special pages to use js
|
||||
&& !page_tid_uses_pre) { // if .js, .css or .lua, skip test; may have js fragments, but entire text is escaped and put in pre; don't show spurious warning; DATE:2013-11-21
|
||||
wiki.Html_mgr().Js_cleaner().Clean_bfr(wiki, page_ttl, bfr, bfr_page_bgn);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Write_body_wikitext(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, byte[] data_raw, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page page, byte page_tid, int ns_id) {
|
||||
// dump and exit if pre-generated html from html dumps
|
||||
byte[] hdump_data = page.Db().Html().Html_bry();
|
||||
if (Bry_.Len_gt_0(hdump_data)) {
|
||||
bfr.Add(hdump_data);
|
||||
return;
|
||||
}
|
||||
|
||||
// dump and exit if MediaWiki message;
|
||||
if (ns_id == Xow_ns_.Tid__mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
bfr.Add(Gfs_php_converter.Xto_php(tmp_bfr, Bool_.N, data_raw));
|
||||
return;
|
||||
}
|
||||
|
||||
// if [[File]], add boilerplate header; note that html is XOWA-generated so does not need to be tidied
|
||||
if (ns_id == Xow_ns_.Tid__file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
|
||||
// get separate bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
Bry_bfr tidy_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
|
||||
// write wikitext
|
||||
if (page.Html_data().Skip_parse()) {
|
||||
tidy_bfr.Add(page.Html_data().Custom_body());
|
||||
}
|
||||
else {
|
||||
if (page.Root() != null) { // NOTE: will be null if blank; occurs for one test: Logo_has_correct_main_page; DATE:2015-09-29
|
||||
page.Html_data().Toc_mgr().Clear(); // NOTE: always clear tocs before writing html; toc_itms added when writing html_hdr; DATE:2016-07-17
|
||||
wiki.Html_mgr().Html_wtr().Write_doc(tidy_bfr, ctx, hctx, page.Root().Data_mid(), page.Root());
|
||||
if (wiki.Html_mgr().Html_wtr().Cfg().Toc__show())
|
||||
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(tidy_bfr, page, hctx);
|
||||
}
|
||||
}
|
||||
|
||||
// if [[Category]], add catpage data
|
||||
if (ns_id == Xow_ns_.Tid__category) tidy_bfr.Add_safe(page.Html_data().Catpage_data());
|
||||
// if (ns_id == Xow_ns_.Tid__category) wiki.Ctg__catpage_mgr().Write_catpage(tidy_bfr, page, hctx);
|
||||
|
||||
// tidy html
|
||||
wiki.Html_mgr().Tidy_mgr().Exec_tidy(tidy_bfr, !hctx.Mode_is_hdump(), page.Url_bry_safe());
|
||||
|
||||
// add back to main bfr
|
||||
bfr.Add_bfr_and_clear(tidy_bfr);
|
||||
tidy_bfr.Mkr_rls();
|
||||
|
||||
// handle Categories at bottom of page; note that html is XOWA-generated so does not need to be tidied
|
||||
int ctgs_len = page.Wtxt().Ctgs__len();
|
||||
if ( ctgs_enabled
|
||||
&& ctgs_len > 0 // skip if no categories found while parsing wikitext
|
||||
&& !wiki.Html_mgr().Importing_ctgs() // do not show categories if importing categories, page will wait for category import to be done; DATE:2014-10-15
|
||||
&& !hctx.Mode_is_hdump() // do not dump categories during hdump; DATE:2016-10-12
|
||||
) {
|
||||
if (app.Mode().Tid_is_gui()) app.Usr_dlg().Prog_many("", "", "loading categories: count=~{0}", ctgs_len);
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Ctg__pagebox_wtr().Get_catlinks_by_page(wiki, page);
|
||||
wiki.Ctg__pagebox_wtr().Write_pagebox(bfr, wiki, page, pagebox_itms);
|
||||
}
|
||||
|
||||
// translate if variants are enabled
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) bfr.Add(vnt_mgr.Convert_lang().Parse_page(vnt_mgr.Cur_itm(), page.Db().Page().Id(), bfr.To_bry_and_clear()));
|
||||
|
||||
// handle uniqs
|
||||
wiki.Parser_mgr().Uniq_mgr().Parse(bfr);
|
||||
}
|
||||
private void Write_body_pre(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, Xoh_wtr_ctx hctx, byte[] data_raw, Bry_bfr tmp_bfr) {
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, data_raw, 0, data_raw.length, false, false);
|
||||
if (hctx.Mode_is_hdump())
|
||||
bfr.Add(data_raw);
|
||||
else
|
||||
app.Html_mgr().Page_mgr().Content_code_fmt().Bld_many(bfr, tmp_bfr);
|
||||
tmp_bfr.Clear();
|
||||
}
|
||||
private void Write_body_edit(Bry_bfr bfr, byte[] data_raw, int ns_id, byte page_tid) {
|
||||
if ( ns_id == Xow_ns_.Tid__mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
&& page_tid == Xow_page_tid.Tid_wikitext
|
||||
)
|
||||
data_raw = Gfs_php_converter.Xto_php(tmp_bfr, Bool_.N, data_raw);
|
||||
int data_raw_len = data_raw.length;
|
||||
if (mgr.Html_capable()) {
|
||||
data_raw = wiki.Parser_mgr().Hdr__section_editable__mgr().Slice_section(page.Url(), page.Ttl(), data_raw);
|
||||
data_raw_len = data_raw.length;
|
||||
Xoh_html_wtr_escaper.Escape(page.Wikie().Appe().Parser_amp_mgr(), bfr, data_raw, 0, data_raw_len, false, false); // NOTE: must escape; assume that browser will automatically escape (<) (which Mozilla does)
|
||||
}
|
||||
else
|
||||
bfr.Add(data_raw);
|
||||
if (data_raw_len > 0) // do not add nl if empty String
|
||||
bfr.Add_byte_nl(); // per MW:EditPage.php: "Ensure there's a newline at the end, otherwise adding lines is awkward."
|
||||
}
|
||||
// private static final byte[] Content_editable_bry = Bry_.new_a7(" contenteditable=\"true\"");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,44 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.xtns.relatedSites.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xoh_page_wtr_wkr_ {
|
||||
public static byte[] Bld_page_content_sub(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Bry_bfr tmp_bfr) {
|
||||
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(wiki.Ns_mgr(), page.Ttl());
|
||||
byte[] page_content_sub = page.Html_data().Content_sub(); // contentSub exists; SEE: {{#isin}}
|
||||
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page.Redirect_trail());
|
||||
return Bry_.Add(subpages, page_content_sub, redirect_msg);
|
||||
}
|
||||
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
|
||||
if (Bry_.Len_gt_0(display_ttl)) return display_ttl; // display_ttl explicitly set; use it
|
||||
if (ttl.Ns().Id() == Xow_ns_.Tid__special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
|
||||
tmp_bfr.Add(ttl.Ns().Name_ui_w_colon()).Add(ttl.Page_txt_wo_qargs());
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
else
|
||||
return ttl.Full_txt_w_ttl_case(); // NOTE: include ns with ttl as per defect d88a87b3
|
||||
}
|
||||
public static void Bld_head_end(Bry_bfr html_bfr, Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
byte[] head_end = Xopg_tag_wtr.Write(tmp_bfr, Bool_.Y, Xopg_tag_wtr_cbk_.Basic, page.Html_data().Custom_head_tags());
|
||||
if (Bry_.Len_eq_0(head_end)) return;
|
||||
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Gfh_tag_.Head_rhs);
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>");
|
||||
return;
|
||||
}
|
||||
html_bfr.Insert_at(insert_pos, head_end);
|
||||
}
|
||||
public static void Bld_html_end(Bry_bfr html_bfr, Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
byte[] html_end = Xopg_tag_wtr.Write(tmp_bfr, Bool_.Y, Xopg_tag_wtr_cbk_.Basic, page.Html_data().Custom_tail_tags());
|
||||
if (html_end == null) return;
|
||||
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Gfh_tag_.Html_rhs, html_bfr.Len());
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </html>");
|
||||
return;
|
||||
}
|
||||
html_bfr.Insert_at(insert_pos, html_end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,62 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_page_wtr_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_page_wtr_fxt fxt = new Xoh_page_wtr_fxt();
|
||||
@Test public void Page_name() {
|
||||
fxt.Test_page_name_by_ttl("Earth", "Earth");
|
||||
fxt.Test_page_name_by_ttl("File:A.png", "File:A.png");
|
||||
fxt.Test_page_name_by_ttl("Special:Search/earth?fulltext=y", "Special:Search/earth");
|
||||
fxt.Test_page_name_by_ttl("Special:Search/earth", "Special:Search/earth");
|
||||
fxt.Test_page_name_by_display("Special:Allpages", "All pages", "All pages");
|
||||
}
|
||||
@Test public void Edit() {
|
||||
fxt.Test_edit("	", "&#9;\n"); // NOTE: cannot by 	 or will show up in edit box as "\t" and save as "\t" instead of 	
|
||||
}
|
||||
@Test public void Css() {
|
||||
fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("<pre style='overflow:auto'>~{page_text}</pre>");
|
||||
fxt.Test_read("MediaWiki:Common.css", ".xowa {}", "<pre style='overflow:auto'>.xowa {}</pre>");
|
||||
fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("<pre>~{page_text}</pre>");
|
||||
}
|
||||
@Test public void Amp_disable() { // PURPOSE: in js documents; " should be rendered as ", not as "; DATE:2013-11-07
|
||||
fxt.Test_read("MediaWiki:Gadget.js", """, "<pre>&quot;</pre>");
|
||||
}
|
||||
}
|
||||
class Xoh_page_wtr_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
} private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); private Xowe_wiki wiki;
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public void Test_page_name_by_display(String ttl, String display, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl)), Bry_.new_a7(display))));
|
||||
}
|
||||
public void Test_page_name_by_ttl(String raw, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(raw)), null)));
|
||||
}
|
||||
public void Test_edit(String raw, String expd) {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true);
|
||||
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
|
||||
page.Db().Text().Text_bry_(Bry_.new_u8(raw));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_edit);
|
||||
wkr.Write_body(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Basic, page);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test_read(String page_name, String page_text, String expd) {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true);
|
||||
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
|
||||
page.Ttl_(Xoa_ttl.Parse(wiki, Bry_.new_a7(page_name)));
|
||||
page.Db().Text().Text_bry_(Bry_.new_u8(page_text));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_read);
|
||||
wkr.Write_body(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Basic, page);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,53 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.gfui.kits.core.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.htmls.portal.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.wikis.modules.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.htmls.tidy.*; import gplx.xowa.htmls.js.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles.*;
|
||||
public class Xow_html_mgr implements Gfo_invk {
|
||||
private final Gfo_url_encoder fsys_lnx_encoder = Gfo_url_encoder_.New__fsys_lnx().Make();
|
||||
public Xow_html_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
html_wtr = new Xoh_html_wtr(wiki, this);
|
||||
Xoae_app app = wiki.Appe();
|
||||
page_wtr_mgr = new Xoh_page_wtr_mgr(app.Gui_mgr().Kit().Tid() != Gfui_kit_.Swing_tid); // reverse logic to handle swt,drd but not mem
|
||||
img_xowa_protocol = fsys_lnx_encoder.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);
|
||||
module_mgr = new Xow_module_mgr(wiki);
|
||||
this.js_cleaner = new Xoh_js_cleaner(app);
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
html_wtr.Init_by_wiki(wiki);
|
||||
module_mgr.Init_by_wiki(wiki);
|
||||
tidy_mgr.Init_by_wiki(wiki);
|
||||
portal_mgr.Init_by_wiki(wiki);
|
||||
page_wtr_mgr.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Init_by_lang(Xol_lang_itm lang) {
|
||||
portal_mgr.Init_by_lang(lang);
|
||||
}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoh_html_wtr Html_wtr() {return html_wtr;} private Xoh_html_wtr html_wtr;
|
||||
public Xoh_page_wtr_mgr Page_wtr_mgr() {return page_wtr_mgr;} private Xoh_page_wtr_mgr page_wtr_mgr;
|
||||
public Xow_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xow_tidy_mgr tidy_mgr = new Xow_tidy_mgr();
|
||||
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private final Xoh_js_cleaner js_cleaner;
|
||||
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
public Xow_portal_mgr Portal_mgr() {return portal_mgr;} private Xow_portal_mgr portal_mgr;
|
||||
public Xow_module_mgr Head_mgr() {return module_mgr;} private Xow_module_mgr module_mgr;
|
||||
public boolean Importing_ctgs() {return importing_ctgs;} public void Importing_ctgs_(boolean v) {importing_ctgs = v;} private boolean importing_ctgs;
|
||||
public int Img_thumb_width() {return img_thumb_width;} private int img_thumb_width = 220;
|
||||
public byte[] Img_xowa_protocol() {return img_xowa_protocol;} private byte[] img_xowa_protocol;
|
||||
public boolean Img_suppress_missing_src() {return img_suppress_missing_src;} public Xow_html_mgr Img_suppress_missing_src_(boolean v) {img_suppress_missing_src = v; return this;} private boolean img_suppress_missing_src = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_article)) return page_wtr_mgr;
|
||||
else if (ctx.Match(k, Invk_portal)) return portal_mgr;
|
||||
else if (ctx.Match(k, Invk_modules)) return module_mgr;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
}
|
||||
public static final String Invk_article = "article", Invk_portal = "portal", Invk_modules = "modules";
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public interface Bridge_cmd_itm {
|
||||
byte[] Key();
|
||||
void Init_by_app(Xoa_app app);
|
||||
String Exec(Json_nde data);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,31 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Bridge_cmd_mgr {
|
||||
private final Json_parser parser;
|
||||
private final Hash_adp_bry cmd_hash = Hash_adp_bry.cs();
|
||||
public Bridge_cmd_mgr(Json_parser parser) {this.parser = parser;}
|
||||
public void Add(Bridge_cmd_itm cmd) {cmd_hash.Add_bry_obj(cmd.Key(), cmd);}
|
||||
public String Exec(GfoMsg m) {
|
||||
if (m.Args_count() == 0) throw Err_.new_("bridge.cmds", "no json specified for json_exec");
|
||||
return Exec(m.Args_getAt(0).Val_to_bry());
|
||||
}
|
||||
public String Exec(byte[] jdoc_bry) {
|
||||
Json_doc jdoc = null;
|
||||
try {jdoc = parser.Parse(jdoc_bry);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "bridge.cmds", "invalid json", "json", jdoc_bry);}
|
||||
Json_nde msg = jdoc.Root_nde();
|
||||
byte[] key_bry = msg.Get_bry(Key_cmd);
|
||||
Bridge_cmd_itm cmd = (Bridge_cmd_itm)cmd_hash.Get_by_bry(key_bry); if (cmd == null) throw Err_.new_("bridge.cmds", "unknown cmd", "key", key_bry);
|
||||
try {return cmd.Exec(msg.Get(Key_data));}
|
||||
catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "exec json failed: ~{0}", "json", jdoc_bry);
|
||||
throw Err_.new_exc(e, "bridge.cmds", "exec json failed", "json", jdoc_bry);
|
||||
}
|
||||
}
|
||||
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_data = Bry_.new_a7("data");
|
||||
public static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
public static String Msg__ok = String_.Empty;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,89 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Bridge_msg_bldr {
|
||||
private final Json_wtr wtr = new Json_wtr();
|
||||
private boolean rslt_pass; private String rslt_msg;
|
||||
private String notify_text; private String notify_status;
|
||||
private final Gfo_tree_list data_root = new Gfo_tree_list("data");
|
||||
public Bridge_msg_bldr() {
|
||||
wtr.Opt_ws_(Bool_.N);
|
||||
this.Clear();
|
||||
}
|
||||
public Bridge_msg_bldr Opt_quote_byte_apos_() {wtr.Opt_quote_byte_(Byte_ascii.Apos); return this;}
|
||||
public Bridge_msg_bldr Rslt_pass_y_() {return Rslt_pass_(Bool_.Y);}
|
||||
public Bridge_msg_bldr Rslt_pass_n_(String v) {Rslt_msg_(v); return Rslt_pass_(Bool_.N);}
|
||||
private Bridge_msg_bldr Rslt_pass_(boolean v) {synchronized(wtr){this.rslt_pass = v;} return this;}
|
||||
private Bridge_msg_bldr Rslt_msg_(String v) {synchronized(wtr){this.rslt_msg = v;} return this;}
|
||||
public Bridge_msg_bldr Notify_hint_(String v) {synchronized(wtr){this.notify_hint = v;} return this;} private String notify_hint;
|
||||
public Bridge_msg_bldr Notify_pass_(String v){synchronized(wtr){this.notify_text = v; this.notify_status = "success";} return this;}
|
||||
public Bridge_msg_bldr Notify_fail_(String v){synchronized(wtr){this.notify_text = v; this.notify_status = "error"; this.rslt_pass = false;} return this;}
|
||||
public Bridge_msg_bldr Data(String key, boolean val) {return Data_obj(key, val, Type_ids_.Id__bool);}
|
||||
public Bridge_msg_bldr Data(String key, int val) {return Data_obj(key, val, Type_ids_.Id__int);}
|
||||
public Bridge_msg_bldr Data(String key, String val) {return Data_obj(key, val, Type_ids_.Id__str);}
|
||||
public Bridge_msg_bldr Data(String key, byte[] val) {return Data_obj(key, val, Type_ids_.Id__bry);}
|
||||
private Bridge_msg_bldr Data_obj(String key, Object val, int val_tid) {
|
||||
synchronized (wtr) {data_root.Add_data(key, val, val_tid);}
|
||||
return this;
|
||||
}
|
||||
public byte[] To_json_bry() {synchronized(wtr){ Bld_json(); return wtr.To_bry_and_clear();}}
|
||||
public String To_json_str() {synchronized(wtr){ Bld_json(); return wtr.To_str_and_clear();}}
|
||||
public String To_json_str__empty() {return "{}";}
|
||||
public Bridge_msg_bldr Clear() {
|
||||
synchronized (wtr) {
|
||||
rslt_pass = true; // by default, set all msgs to pass==true
|
||||
rslt_msg = null;
|
||||
notify_hint = null;
|
||||
notify_text = null;
|
||||
notify_status = null;
|
||||
data_root.Clear();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Bld_json() {
|
||||
wtr.Clear();
|
||||
wtr.Doc_nde_bgn();
|
||||
wtr.Nde_bgn(Key_rslt);
|
||||
wtr.Kv_bool(Key_rslt_pass, rslt_pass);
|
||||
if (rslt_msg != null) wtr.Kv_str(Key_rslt_msg, rslt_msg);
|
||||
wtr.Nde_end();
|
||||
if (notify_text != null) {
|
||||
wtr.Nde_bgn(Key_notify);
|
||||
wtr.Kv_str(Key_notify_text, notify_text);
|
||||
wtr.Kv_str(Key_notify_status, notify_status);
|
||||
if (notify_hint != null)
|
||||
wtr.Kv_str(Key_notify_hint, notify_hint);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
Bld_json_for_hash(wtr, data_root);
|
||||
wtr.Doc_nde_end();
|
||||
}
|
||||
private void Bld_json_for_hash(Json_wtr wtr, Gfo_tree_list hash) {
|
||||
int len = hash.Len(); if (len == 0) return;
|
||||
wtr.Nde_bgn(hash.Key());
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_tree_itm itm = hash.Get_at(i);
|
||||
if (itm.Tid() == Gfo_tree_itm_.Tid_data) {
|
||||
Gfo_tree_data sub_kv = (Gfo_tree_data)itm;
|
||||
String key = sub_kv.Key(); Object val = sub_kv.Val();
|
||||
switch (sub_kv.Val_tid()) {
|
||||
case Type_ids_.Id__bool: wtr.Kv_bool(key, Bool_.Cast(val)); break;
|
||||
case Type_ids_.Id__int: wtr.Kv_int(key, Int_.Cast(val)); break;
|
||||
case Type_ids_.Id__bry: wtr.Kv_bry(key, (byte[])val); break;
|
||||
default: wtr.Kv_str(key, Object_.Xto_str_strict_or_null_mark(val)); break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Gfo_tree_list sub_hash = (Gfo_tree_list)itm;
|
||||
Bld_json_for_hash(wtr, sub_hash);
|
||||
}
|
||||
}
|
||||
wtr.Nde_end();
|
||||
}
|
||||
private static final byte[]
|
||||
Key_rslt = Bry_.new_a7("rslt"), Key_rslt_pass = Bry_.new_a7("pass"), Key_rslt_msg = Bry_.new_a7("msg")
|
||||
, Key_notify = Bry_.new_a7("notify"), Key_notify_text = Bry_.new_a7("text"), Key_notify_status = Bry_.new_a7("status"), Key_notify_hint = Bry_.new_a7("hint")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Bridge_msg_bldr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Bridge_msg_bldr_fxt fxt = new Bridge_msg_bldr_fxt();
|
||||
@Test public void Bld() {
|
||||
fxt.Bldr().Rslt_pass_y_().Notify_pass_("passed").Data("key1", true).Data("key2", 1).Data("key3", "val3");
|
||||
fxt.Test_to_json_str("{'rslt':{'pass':true},'notify':{'text':'passed','status':'success'},'data':{'key1':true,'key2':1,'key3':'val3'}}");
|
||||
}
|
||||
}
|
||||
class Bridge_msg_bldr_fxt {
|
||||
public Bridge_msg_bldr Bldr() {return bldr;} private final Bridge_msg_bldr bldr = new Bridge_msg_bldr().Opt_quote_byte_apos_();
|
||||
public void Clear() {}
|
||||
public void Test_to_json_str(String expd) {
|
||||
Tfds.Eq_str_lines(expd, bldr.To_json_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,31 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
interface Gfo_tree_itm {
|
||||
int Tid();
|
||||
}
|
||||
class Gfo_tree_itm_ {
|
||||
public static final int Tid_data = 1, Tid_list = 2;
|
||||
}
|
||||
class Gfo_tree_data implements Gfo_tree_itm {
|
||||
public int Tid() {return Gfo_tree_itm_.Tid_data;}
|
||||
public Gfo_tree_data(String key, Object val, int val_tid) {
|
||||
this.key = key; this.val = val; this.val_tid = val_tid;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Object Val() {return val;} private final Object val;
|
||||
public int Val_tid() {return val_tid;} private final int val_tid;
|
||||
}
|
||||
class Gfo_tree_list implements Gfo_tree_itm {
|
||||
private final Ordered_hash list = Ordered_hash_.New();
|
||||
public Gfo_tree_list(String key) {this.key = key;}
|
||||
public int Tid() {return Gfo_tree_itm_.Tid_list;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public void Clear() {list.Clear();}
|
||||
public int Len() {return list.Count();}
|
||||
public Gfo_tree_data Add_data(String key, Object val, int val_tid) {Gfo_tree_data rv = new Gfo_tree_data(key, val, val_tid); this.Add(key, rv); return rv;}
|
||||
public Gfo_tree_list Add_list(String key) {Gfo_tree_list rv = new Gfo_tree_list(key); this.Add(key, rv); return rv;}
|
||||
private void Add(String key, Gfo_tree_itm itm) {list.Add(key, itm);}
|
||||
public Gfo_tree_itm Get_at(int i) {return (Gfo_tree_itm)list.Get_at(i);}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Xoh_bridge_mgr {
|
||||
public Xoh_bridge_mgr(Json_parser parser) {this.cmd_mgr = new Bridge_cmd_mgr(parser);}
|
||||
public Bridge_cmd_mgr Cmd_mgr() {return cmd_mgr;} private final Bridge_cmd_mgr cmd_mgr;
|
||||
public Bridge_msg_bldr Msg_bldr() {return msg_bldr;} private final Bridge_msg_bldr msg_bldr = new Bridge_msg_bldr();
|
||||
}
|
||||
|
||||
@@ -13,3 +13,77 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cmd_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private boolean init;
|
||||
public void Init_by_bridge(Bridge_cmd_mgr cmd_mgr) {
|
||||
if (init) return;
|
||||
init = true;
|
||||
cmd_mgr.Add(new Dbui_cmd_row_edit ("xowa.dbui.edit_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_save ("xowa.dbui.save_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_del ("xowa.dbui.delete_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_reorder ("xowa.dbui.reorder_bgn", this));
|
||||
}
|
||||
public void Add(Dbui_tbl_itm tbl) {hash.Add_bry_obj(tbl.Key(), tbl);}
|
||||
public String Del(Json_nde data) {return Get_tbl(data).Del (data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey));}
|
||||
public String Edit(Json_nde data) {return Get_tbl(data).Edit(data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey));}
|
||||
public String Save(Json_nde data) {return Get_tbl(data).Save(data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey), To_hash(data.Get(Arg_vals)));}
|
||||
public String Reorder(Json_nde data){
|
||||
byte[] pkeys_concat = data.Get_bry(Arg_pkeys);
|
||||
return Get_tbl(data).Reorder(Bry_split_.Split(pkeys_concat, Byte_ascii.Pipe), -1);
|
||||
}
|
||||
private Dbui_tbl_itm Get_tbl(Json_nde data) {
|
||||
byte[] tbl_key = data.Get_bry(Arg_tbl_key);
|
||||
Dbui_tbl_itm rv = (Dbui_tbl_itm)hash.Get_by(tbl_key); if (rv == null) throw Err_.new_("dbui", "unknown tbl_key", "tbl_key", tbl_key);
|
||||
return rv;
|
||||
}
|
||||
private static Dbui_val_hash To_hash(Json_grp grp) {
|
||||
Dbui_val_hash rv = new Dbui_val_hash();
|
||||
int len = grp.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv kv = (Json_kv)grp.Get_at(i);
|
||||
Json_nde nde = (Json_nde)kv.Val();
|
||||
Json_kv key = (Json_kv)nde.Get_itm(Arg_key);
|
||||
Json_kv val = (Json_kv)nde.Get_itm(Arg_val);
|
||||
Dbui_val_itm fld = new Dbui_val_itm(val.Val().Data_bry(), Bry_.Empty);
|
||||
rv.Add(key.Val().Data_bry(), fld);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Dbui_cmd_mgr Instance = new Dbui_cmd_mgr(); Dbui_cmd_mgr() {}
|
||||
private static final byte[]
|
||||
Arg_tbl_key = Bry_.new_a7("tbl_key"), Arg_row_pkey = Bry_.new_a7("row_pkey"), Arg_row_id = Bry_.new_a7("row_id")
|
||||
, Arg_vals = Bry_.new_a7("vals"), Arg_key = Bry_.new_a7("key"), Arg_val = Bry_.new_a7("val")
|
||||
, Arg_pkeys = Bry_.new_a7("pkeys")
|
||||
;
|
||||
}
|
||||
class Dbui_cmd_row_del implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_del(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(Json_nde data) {return mgr.Del(data);}
|
||||
}
|
||||
class Dbui_cmd_row_edit implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_edit(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(Json_nde data) {return mgr.Edit(data);}
|
||||
}
|
||||
class Dbui_cmd_row_save implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_save(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(Json_nde data) {return mgr.Save(data);}
|
||||
}
|
||||
class Dbui_cmd_row_reorder implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_reorder(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(Json_nde data) {return mgr.Reorder(data);}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,64 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cells_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private final Dbui_cell_fmtr cell_fmtr = new Dbui_cell_fmtr();
|
||||
private final Dbui_btn_fmtr btn_fmtr = new Dbui_btn_fmtr();
|
||||
private Dbui_btn_itm[] btns;
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr, Dbui_btn_itm[] btns) {
|
||||
cell_fmtr.Ctor(val_fmtr); this.btns = btns;
|
||||
}
|
||||
public Dbui_cells_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {
|
||||
this.row_key = row_key; this.row_itm = row_itm;
|
||||
return this;
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, cell_fmtr.Init(row_key, row_itm), btn_fmtr.Init(row_key, btns));
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_drag_handle xo_cell'></div>~{vals}"
|
||||
, " <div class='xo_cell'>~{btns}"
|
||||
, " </div>"
|
||||
), "vals", "btns");
|
||||
}
|
||||
class Dbui_cell_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
private Dbui_val_fmtr val_fmtr;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr) {this.val_fmtr = val_fmtr;}
|
||||
public Dbui_cell_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {this.row_key = row_key; this.row_itm = row_itm; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = row_itm.Tbl().Cols();
|
||||
Dbui_val_itm[] vals = row_itm.Vals(); int len = vals.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_val_itm val = vals[i];
|
||||
fmtr.Bld_bfr_many(bfr, row_key, i, val_fmtr.Init(cols[i], row_key, val));
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_cell'>~{html}</div>"
|
||||
), "row_key", "val_idx", "html");
|
||||
}
|
||||
class Dbui_btn_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private byte[] row_key; private Dbui_btn_itm[] btns;
|
||||
public Dbui_btn_fmtr Init(byte[] row_key, Dbui_btn_itm[] btns) {
|
||||
this.row_key = row_key; this.btns = btns; return this;
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = btns.length;
|
||||
Io_url img_dir = gplx.xowa.htmls.heads.Xoh_head_itm__dbui.Img_dir();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_btn_itm btn = btns[i];
|
||||
fmtr.Bld_bfr_many(bfr, row_key, btn.Cmd(), img_dir.GenSubFil(btn.Img()).To_http_file_bry(), btn.Text());
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <span><a href='javascript:~{btn_cmd}(\"~{row_key}\");'><img src='~{btn_img}' title='~{btn_text}'/></a></span>"
|
||||
), "row_key", "btn_cmd", "btn_img", "btn_text");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,60 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_tbl_fmtr {
|
||||
private final Dbui_head_cell_fmtr head_cell_fmtr = new Dbui_head_cell_fmtr();
|
||||
private final Dbui_row_fmtr row_fmtr = new Dbui_row_fmtr();
|
||||
public void Write(Bry_bfr bfr, Dbui_tbl_itm tbl, byte[] origin_html, byte[] delete_confirm_msg, Dbui_row_itm[] rows) {
|
||||
tbl_fmtr.Bld_bfr_many(bfr, tbl.Key(), Dbui_tbl_itm_.Calc_width(tbl), origin_html, delete_confirm_msg, head_cell_fmtr.Init(tbl), row_fmtr.Init(tbl, rows));
|
||||
}
|
||||
private static final Bry_fmtr tbl_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div class='xo_tbl xo_sortable' data-dbui-tbl_key='~{tbl_key}'~{delete_confirm_msg} style='width: ~{width}px;'>"
|
||||
, " <div class='xo_row xo_header'>"
|
||||
, " <div class='xo_origin xo_resizable_col' style='width:20px'>~{origin}</div>~{head_cells}"
|
||||
, " </div>~{data_rows}"
|
||||
, "</div>"
|
||||
), "tbl_key", "width", "origin", "delete_confirm_msg", "head_cells", "data_rows");
|
||||
}
|
||||
class Dbui_head_cell_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private Dbui_tbl_itm tbl;
|
||||
public Dbui_head_cell_fmtr Init(Dbui_tbl_itm tbl) {this.tbl = tbl; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = tbl.Cols(); int len = cols.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_col_itm col = cols[i];
|
||||
fmtr.Bld_bfr_many(bfr, col.Width(), col.Display());
|
||||
}
|
||||
bfr.Add_str_a7("\n <div class='xo_head xo_resizable_col' style='width:50px;'> </div>"); // btns headers
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_head xo_resizable_col' style='width:~{width}px;'>~{display}</div>"
|
||||
), "width", "display");
|
||||
}
|
||||
class Dbui_row_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private final Dbui_cells_fmtr cells_fmtr = new Dbui_cells_fmtr();
|
||||
private final Dbui_val_fmtr val_fmtr = Dbui_val_fmtr_.new_view();
|
||||
private final Bry_bfr row_key_bfr = Bry_bfr_.New_w_size(255);
|
||||
private Dbui_tbl_itm tbl; private Dbui_row_itm[] rows;
|
||||
public Dbui_row_fmtr Init(Dbui_tbl_itm tbl, Dbui_row_itm[] rows) {this.tbl = tbl; this.rows = rows; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
byte[] tbl_key = tbl.Key();
|
||||
int len = rows.length;
|
||||
cells_fmtr.Ctor(val_fmtr, tbl.View_btns());
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_row_itm row = rows[i];
|
||||
row_key_bfr.Add(tbl_key).Add_byte(Byte_ascii.Underline).Add_int_variable(i);
|
||||
byte[] row_key = row_key_bfr.To_bry_and_clear();
|
||||
fmtr.Bld_bfr_many(bfr, row_key, row.Pkey(), cells_fmtr.Init(row_key, row));
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id='~{row_key}' class='xo_row xo_draggable' data-dbui-row_pkey='~{pkey}'>~{cells}"
|
||||
, " </div>"
|
||||
), "row_key", "pkey", "cells");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,27 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
import org.junit.*;
|
||||
public class Dbui_tbl_fmtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Dbui_tbl_fmtr_fxt fxt = new Dbui_tbl_fmtr_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Test_write
|
||||
// ( fxt.Make_tbl()
|
||||
// , String_.Concat_lines_nl_skip_last()
|
||||
// );
|
||||
}
|
||||
}
|
||||
class Dbui_tbl_fmtr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New_w_size(255);
|
||||
private final Dbui_tbl_fmtr tbl_fmtr = new Dbui_tbl_fmtr();
|
||||
public void Clear() {}
|
||||
public Dbui_tbl_itm Make_tbl() {
|
||||
return null;
|
||||
}
|
||||
public void Test_write(Dbui_tbl_itm tbl, String expd) {
|
||||
tbl_fmtr.Write(bfr, tbl, null, null, null);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public interface Dbui_val_fmtr {
|
||||
Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val);
|
||||
}
|
||||
class Dbui_val_fmtr__view implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
|
||||
private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.val = val; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(val.Html());
|
||||
}
|
||||
}
|
||||
class Dbui_val_fmtr__edit implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
|
||||
private Dbui_col_itm col; private byte[] row_id; private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.col = col; this.row_id = row_id; this.val = val; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
switch (col.Type()) {
|
||||
case Dbui_col_itm.Type_id_str: input_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
case Dbui_col_itm.Type_id_text: textarea_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
default: throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr input_fmtr_str = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <input class='dbui_cell xo_resizable_col' dbui_col='~{col_key}' style='border:1px solid black; width:~{width}px' value='~{value}' onkeyup='Dbui__edit__keyup(event, \"~{row_id}\");'/>"
|
||||
), "col_key", "width", "value", "row_id");
|
||||
private static final Bry_fmtr textarea_fmtr_str = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <textarea class='dbui_cell' dbui_col='~{col_key}' style='border:1px solid black; width:~{width}px; height:18px;' onkeyup='Dbui__edit__keyup(event, \"~{row_id}\");'>~{value}</textarea>"
|
||||
), "col_key", "width", "value", "row_id");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_fmtr_ {
|
||||
public static Dbui_val_fmtr new_view() {return new Dbui_val_fmtr__view();}
|
||||
public static Dbui_val_fmtr new_edit() {return new Dbui_val_fmtr__edit();}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_btn_itm {
|
||||
public Dbui_btn_itm(String cmd, String img, String text) {this.cmd = cmd; this.img = img; this.text = text;}
|
||||
public String Key() {return text;}
|
||||
public String Cmd() {return cmd;} private final String cmd;
|
||||
public String Img() {return img;} private final String img;
|
||||
public String Text() {return text;} private final String text;
|
||||
public static final Dbui_btn_itm[] Ary_empty = new Dbui_btn_itm[0];
|
||||
}
|
||||
|
||||
@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_col_itm {
|
||||
public Dbui_col_itm(int type, int width, String key, String display) {this.type = type; this.width = width; this.key = key; this.display = display;}
|
||||
public int Type() {return type;} private final int type;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Display() {return display;} private final String display;
|
||||
public int Width() {return width;} private final int width;
|
||||
public static final int Type_id_str = 1, Type_id_text = 2, Type_id_int = 3, Type_id_datetime = 4;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_row_itm {
|
||||
public Dbui_row_itm(Dbui_tbl_itm tbl, byte[] pkey, Dbui_val_itm[] vals) {
|
||||
this.tbl = tbl; this.pkey = pkey; this.vals = vals;
|
||||
}
|
||||
public Dbui_tbl_itm Tbl() {return tbl;} private final Dbui_tbl_itm tbl;
|
||||
public byte[] Pkey() {return pkey;} private final byte[] pkey;
|
||||
public Dbui_val_itm[] Vals() {return vals;} private Dbui_val_itm[] vals;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public interface Dbui_tbl_itm {
|
||||
byte[] Key();
|
||||
Dbui_col_itm[] Cols();
|
||||
Dbui_btn_itm[] View_btns();
|
||||
Dbui_btn_itm[] Edit_btns();
|
||||
String Del (byte[] row_id, byte[] row_pkey);
|
||||
String Edit(byte[] row_id, byte[] row_pkey);
|
||||
String Save(byte[] row_id, byte[] row_pkey, Dbui_val_hash vals);
|
||||
String Reorder(byte[][] pkeys, int owner);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_tbl_itm_ {
|
||||
public static int Calc_width(Dbui_tbl_itm tbl) {
|
||||
int rv = 40; // 40 for button col
|
||||
Dbui_col_itm[] ary = tbl.Cols();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv += ary[i].Width();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public void Add(byte[] key, Dbui_val_itm itm) {hash.Add(key, itm);}
|
||||
public byte[] Get_val_as_bry(String key) {return Get_val_as_bry(Bry_.new_u8(key));}
|
||||
public byte[] Get_val_as_bry(byte[] key) {
|
||||
Dbui_val_itm itm = (Dbui_val_itm)hash.Get_by(key); if (itm == null) throw Err_.new_wo_type("dbui.val_hash; unknown key", "key", key);
|
||||
return itm.Data();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_itm {
|
||||
public Dbui_val_itm(byte[] data, byte[] html) {this.data = data; this.html = html;}
|
||||
public byte[] Data() {return data;} private byte[] data;
|
||||
public byte[] Html() {return html;} private final byte[] html;
|
||||
public void Data_(byte[] v) {this.data = v;}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
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);
|
||||
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 dflt_zip_tid = gplx.core.ios.streams.Io_stream_tid_.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();
|
||||
dflt_zip_tid = props.Zip_tid_html();
|
||||
dflt_hzip_enable = props.Hzip_enabled();
|
||||
// mode_is_b256 = true;
|
||||
}
|
||||
Init_by_db(dflt_zip_tid, dflt_hzip_enable, mode_is_b256);
|
||||
load_mgr.Init_by_wiki(wiki);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,174 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.htmls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
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 final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
private Xow_override_mgr override_mgr__html, override_mgr__page;
|
||||
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();
|
||||
}
|
||||
public boolean Read_preferred() {return read_preferred;} private boolean read_preferred = true;
|
||||
public Xow_hdump_mode Html_mode() {return html_mode;} private Xow_hdump_mode html_mode = Xow_hdump_mode.Shown;
|
||||
public Xoh_make_mgr Make_mgr() {return make_mgr;} private final Xoh_make_mgr make_mgr;
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = wiki.App().Cfg();
|
||||
Xow_hdump_mode.Cfg__reg_type(cfg_mgr.Type_mgr());
|
||||
cfg_mgr.Bind_many_wiki(this, wiki, Cfg__read_preferred, Cfg__html_mode);
|
||||
}
|
||||
public void Load_by_xowe(Xoae_page wpg) {
|
||||
tmp_hpg.Ctor_by_hview(wpg.Wiki(), wpg.Url(), wpg.Ttl(), wpg.Db().Page().Id());
|
||||
Load_by_xowh(tmp_hpg, wpg.Ttl(), Bool_.Y);
|
||||
wpg.Db().Html().Html_bry_(tmp_hpg.Db().Html().Html_bry());
|
||||
wpg.Root_(new gplx.xowa.parsers.Xop_root_tkn()); // HACK: set root, else load page will fail
|
||||
Fill_page(wpg, tmp_hpg);
|
||||
}
|
||||
public boolean Load_by_xowh(Xoh_page hpg, Xoa_ttl ttl, boolean load_ctg) {
|
||||
synchronized (tmp_dbpg) {
|
||||
if (override_mgr__page == null) {
|
||||
Io_url override_root_url = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("data", "wiki");
|
||||
this.override_mgr__page = new Xow_override_mgr(override_root_url.GenSubDir_nest("page"));
|
||||
this.override_mgr__html = new Xow_override_mgr(override_root_url.GenSubDir_nest("html"));
|
||||
}
|
||||
boolean loaded = Load__dbpg(wiki, tmp_dbpg.Clear(), hpg, ttl);
|
||||
hpg.Ctor_by_hview(wiki, hpg.Url(), ttl, tmp_dbpg.Id());
|
||||
if (!loaded) { // nothing in "page" table
|
||||
byte[] page_override = override_mgr__page.Get_or_same(ttl.Page_db(), null);
|
||||
if (page_override == null) return Load__fail(hpg);
|
||||
hpg.Db().Html().Html_bry_(page_override);
|
||||
return true;
|
||||
}
|
||||
Xow_db_file html_db = wiki.Data__core_mgr().Dbs__get_by_id_or_fail(tmp_dbpg.Html_db_id());
|
||||
if (!html_db.Tbl__html().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html" table
|
||||
byte[] src = Parse(hpg, hpg.Db().Html().Zip_tid(), hpg.Db().Html().Hzip_tid(), hpg.Db().Html().Html_bry());
|
||||
|
||||
// write ctgs
|
||||
if (load_ctg) {
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Ctg__pagebox_wtr().Get_catlinks_by_page(wiki, hpg);
|
||||
if (pagebox_itms.length > 0) {
|
||||
tmp_bfr.Add(src);
|
||||
wiki.Ctg__pagebox_wtr().Write_pagebox(tmp_bfr, wiki, hpg, pagebox_itms);
|
||||
src = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
|
||||
hpg.Db().Html().Html_bry_(src);
|
||||
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();}
|
||||
public byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_tid_.Tid__raw)
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
switch (hzip_tid) {
|
||||
case Xoh_hzip_dict_.Hzip__none:
|
||||
src = make_mgr.Parse(src, hpg, hpg.Wiki());
|
||||
break;
|
||||
case Xoh_hzip_dict_.Hzip__v1:
|
||||
if (override_mgr__html != null) // null when Parse is called directly
|
||||
src = override_mgr__html.Get_or_same(hpg.Ttl().Page_db(), src);
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
break;
|
||||
case Xoh_hzip_dict_.Hzip__plain:
|
||||
gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader page_loader = new gplx.xowa.addons.wikis.pages.syncs.core.loaders.Xosync_page_loader();
|
||||
src = page_loader.Parse(wiki, hpg, src);
|
||||
break;
|
||||
}
|
||||
return src;
|
||||
}
|
||||
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
Xopg_html_data html_data = wpg.Html_data();
|
||||
html_data.Display_ttl_(tmp_hpg.Display_ttl());
|
||||
html_data.Content_sub_(tmp_hpg.Content_sub());
|
||||
html_data.Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_stub(tmp_hpg.Sidebar_div()));
|
||||
Xoh_head_mgr wpg_head = html_data.Head_mgr();
|
||||
Xopg_module_mgr hpg_head = hpg.Head_mgr();
|
||||
wpg_head.Itm__mathjax().Enabled_ (hpg_head.Math_exists());
|
||||
wpg_head.Itm__popups().Bind_hover_area_ (hpg_head.Imap_exists());
|
||||
wpg_head.Itm__gallery().Enabled_ (hpg_head.Gallery_packed_exists());
|
||||
wpg_head.Itm__hiero().Enabled_ (hpg_head.Hiero_exists());
|
||||
wpg_head.Itm__timeline().Enabled_ (hpg.Xtn__timeline_exists());
|
||||
wpg_head.Itm__gallery_styles().Enabled_ (hpg.Xtn__gallery_exists());
|
||||
wpg_head.Itm__toc().Enabled_(hpg.Html_data().Toc_mgr().Exists());
|
||||
wpg_head.Itm__pgbnr().Enabled_(hpg.Html_data().Head_mgr().Itm__pgbnr().Enabled());
|
||||
|
||||
// transfer Xtn_gallery_packed_exists; needed for hdump; PAGE:en.w:Mexico; DATE:2016-08-14
|
||||
if (hpg.Html_data().Xtn_gallery_packed_exists())
|
||||
wpg.Html_data().Xtn_gallery_packed_exists_y_();
|
||||
|
||||
// transfer images from Xoh_page to Xoae_page
|
||||
Xoh_img_mgr src_imgs = hpg.Img_mgr();
|
||||
int len = src_imgs.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
gplx.xowa.files.Xof_fsdb_itm itm = src_imgs.Get_at(i);
|
||||
wpg.Hdump_mgr().Imgs().Add(itm);
|
||||
if (!Io_mgr.Instance.ExistsFil(itm.Html_view_url())) // if exists, don't add to file_queue; needed for packed; PAGE:en.w:Mexico; DATE:2016-08-14
|
||||
wpg.File_queue().Add(itm); // add to file_queue for http_server
|
||||
}
|
||||
|
||||
// transfer redlinks
|
||||
Xopg_lnki_list src_list = hpg.Html_data().Redlink_list();
|
||||
Xopg_lnki_list trg_list = wpg.Html_data().Redlink_list();
|
||||
len = src_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
trg_list.Add_direct(src_list.Get_at(i));
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Cfg__read_preferred)) read_preferred = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Cfg__html_mode)) html_mode = Xow_hdump_mode.Parse(m.ReadStr("v"));
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Cfg__read_preferred = "xowa.wiki.hdumps.read_preferred"
|
||||
, Cfg__html_mode = "xowa.wiki.hdumps.html_mode"
|
||||
;
|
||||
|
||||
private static boolean Load__fail(Xoh_page hpg) {hpg.Db().Page().Exists_n_(); return false;}
|
||||
private static boolean Load__dbpg(Xow_wiki wiki, Xowd_page_itm dbpg, Xoh_page hpg, Xoa_ttl ttl) {
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());
|
||||
if (dbpg.Redirect_id() != -1) Load__dbpg__redirects(wiki, dbpg);
|
||||
return dbpg.Html_db_id() != -1;
|
||||
}
|
||||
private static void Load__dbpg__redirects(Xow_wiki wiki, Xowd_page_itm dbpg) {
|
||||
int redirect_count = 0;
|
||||
while (++redirect_count < 5) {
|
||||
int redirect_id = dbpg.Redirect_id();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_id(dbpg, redirect_id);
|
||||
if (redirect_id == -1) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xow_override_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private final Io_url root_dir;
|
||||
private boolean init = true;
|
||||
public Xow_override_mgr(Io_url root_dir) {this.root_dir = root_dir;}
|
||||
public void Clear() {hash.Clear();}
|
||||
public byte[] Get_or_same(byte[] ttl, byte[] src) {
|
||||
if (init) {init = false; Load_from_fsys(hash, root_dir);}
|
||||
byte[] rv = (byte[])hash.Get_by_bry(ttl);
|
||||
return rv == null ? src : rv;
|
||||
}
|
||||
private static void Load_from_fsys(Hash_adp_bry hash, Io_url root_dir) {
|
||||
Io_url[] urls = Io_mgr.Instance.QueryDir_args(root_dir).Recur_(true).ExecAsUrlAry();
|
||||
int urls_len = urls.length;
|
||||
for (int i = 0; i < urls_len; ++i) {
|
||||
Io_url url = urls[i];
|
||||
byte[] raw = Io_mgr.Instance.LoadFilBry(url); int bry_len = raw.length;
|
||||
int nl_pos = Bry_find_.Find_fwd(raw, Byte_ascii.Nl, 0, bry_len); if (nl_pos == Bry_find_.Not_found) continue;
|
||||
byte[] ttl = Bry_.Mid(raw, 0, nl_pos);
|
||||
byte[] src = Bry_.Mid(raw, nl_pos + 1, bry_len);
|
||||
hash.Add_bry_obj(ttl, src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,62 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.wkrs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.dbs.*;
|
||||
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 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) {
|
||||
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, 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);
|
||||
tmp_hpg.Ctor_by_hdiff(tmp_bfr, page, page.Wikie().Msg_mgr().Val_by_id(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc));
|
||||
Xow_db_file html_db = Get_html_db(wiki, page, html_db_is_new.Val_n_());
|
||||
return Save(tmp_hpg, html_db.Tbl__html(), html_db_is_new.Val(), true);
|
||||
}
|
||||
}
|
||||
public int Save(Xoh_page hpg, Xowd_html_tbl html_tbl, boolean insert, boolean use_hzip_dflt) {
|
||||
int hzip_tid = use_hzip_dflt ? dflt_hzip_tid : Xoh_hzip_dict_.Hzip__none;
|
||||
byte[] db_body = Write(tmp_bfr, wiki, hpg, hzip_mgr, zip_mgr, dflt_zip_tid, hzip_tid, hpg.Db().Html().Html_bry());
|
||||
if (insert) html_tbl.Insert(hpg, dflt_zip_tid, dflt_hzip_tid, db_body);
|
||||
else html_tbl.Update(hpg, dflt_zip_tid, dflt_hzip_tid, db_body);
|
||||
return db_body.length;
|
||||
}
|
||||
public void Bld_hdump(Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will keep incrementing upwards
|
||||
wiki.Html__wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, page.Wikie().Parser_mgr().Ctx(), Xoh_wtr_ctx.Hdump, page); // save as hdump_fmt
|
||||
page.Db().Html().Html_bry_(tmp_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.streams.Io_stream_tid_.Tid__raw)
|
||||
src = zip_mgr.Zip((byte)zip_tid, src);
|
||||
return src;
|
||||
}
|
||||
private static Xow_db_file Get_html_db(Xow_wiki wiki, Xoae_page page, Bool_obj_ref html_db_is_new) {
|
||||
Xow_db_file rv = Xow_db_file.Null;
|
||||
Xow_db_mgr core_data_mgr = wiki.Data__core_mgr();
|
||||
int html_db_id = page.Db().Page().Html_db_id();
|
||||
if (html_db_id == -1) {
|
||||
html_db_is_new.Val_y_();
|
||||
rv = core_data_mgr.Db__html();
|
||||
if (rv == null) rv = core_data_mgr.Dbs__make_by_tid(Xow_db_file_.Tid__html_data);
|
||||
html_db_id = rv.Id();
|
||||
page.Db().Page().Html_db_id_(html_db_id);
|
||||
core_data_mgr.Tbl__page().Update__html_db_id(page.Db().Page().Id(), html_db_id);
|
||||
}
|
||||
else {
|
||||
rv = core_data_mgr.Dbs__get_by_id_or_fail(html_db_id);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,34 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xow_hdump_mode {
|
||||
private final int tid;
|
||||
private final String key;
|
||||
private final String gui;
|
||||
|
||||
public Xow_hdump_mode(int tid, String key, String gui) {
|
||||
this.tid = tid; this.key = key; this.gui = gui;
|
||||
}
|
||||
public int Tid() {return tid;}
|
||||
// boolean Tid_is_hdump_save() {return tid == Hdump_save.tid;}
|
||||
public boolean Tid_is_custom() {return tid < Shown.tid;}
|
||||
|
||||
public static final Xow_hdump_mode
|
||||
Swt_browser = new Xow_hdump_mode(0, "swt_browser" , "SWT Browser")
|
||||
, Hdump_save = new Xow_hdump_mode(1, "hdump_save" , "Saved for HTML DB")
|
||||
, Shown = new Xow_hdump_mode(2, "shown" , "Shown")
|
||||
, Hdump_load = new Xow_hdump_mode(3, "hdump_load" , "Loaded by HTML DB")
|
||||
;
|
||||
public static void Cfg__reg_type(gplx.xowa.addons.apps.cfgs.mgrs.types.Xocfg_type_mgr type_mgr) {
|
||||
type_mgr.Lists__add("list:xowa.wiki.hdumps.html_mode", To_kv(Shown), To_kv(Swt_browser), To_kv(Hdump_save), To_kv(Hdump_load));
|
||||
}
|
||||
private static Keyval To_kv(Xow_hdump_mode mode) {return Keyval_.new_(mode.key, mode.gui);}
|
||||
public static Xow_hdump_mode Parse(String v) {
|
||||
if (String_.Eq(v, Shown.key)) return Shown;
|
||||
else if (String_.Eq(v, Hdump_save.key)) return Hdump_save;
|
||||
else if (String_.Eq(v, Hdump_load.key)) return Hdump_load;
|
||||
else if (String_.Eq(v, Swt_browser.key)) return Swt_browser;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,81 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.apps.apis.xowa.bldrs.imports.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xob_hdump_bldr implements Gfo_invk {
|
||||
private boolean enabled, hzip_enabled, hzip_diff, hzip_b256; private byte zip_tid = Byte_.Max_value_127;
|
||||
private Xowe_wiki wiki; private Xob_hdump_tbl_retriever html_tbl_retriever;
|
||||
private Xoh_stat_tbl stat_tbl; private Xoh_stat_itm stat_itm;
|
||||
private int prv_row_len = 0;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private boolean op_sys_is_wnt;
|
||||
private byte[] toc_label = Bry_.Empty;
|
||||
public Xob_hdump_bldr Enabled_(boolean v) {this.enabled = v; return this;}
|
||||
public Xob_hdump_bldr Hzip_enabled_(boolean v) {this.hzip_enabled = v; return this;}
|
||||
public Xob_hdump_bldr Hzip_diff_(boolean v) {this.hzip_diff = v; return this;}
|
||||
public Xob_hdump_bldr Zip_tid_(byte v) {this.zip_tid = v; return this;}
|
||||
public Xow_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xow_hdump_mgr hdump_mgr;
|
||||
public boolean Init(Xowe_wiki wiki, Db_conn make_conn, Xob_hdump_tbl_retriever html_tbl_retriever) {
|
||||
if (!enabled) return false;
|
||||
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.html_tbl_retriever = html_tbl_retriever;
|
||||
this.stat_tbl = new Xoh_stat_tbl(make_conn); this.stat_itm = hdump_mgr.Hzip_mgr().Hctx().Hzip__stat();
|
||||
this.toc_label = wiki.Msg_mgr().Val_by_id(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc);
|
||||
|
||||
if (zip_tid == Byte_.Max_value_127) zip_tid = Xobldr_cfg.Zip_mode__html(wiki.App());
|
||||
hdump_mgr.Init_by_db(zip_tid, hzip_enabled, hzip_b256);
|
||||
return true;
|
||||
}
|
||||
public void Insert(Xop_ctx ctx, Xoae_page wpg) {
|
||||
// clear
|
||||
tmp_hpg.Clear(); // NOTE: must clear tmp_hpg or else will leak memory during mass build; DATE:2016-01-09
|
||||
wpg.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
|
||||
// write to html
|
||||
Xoa_ttl ttl = wpg.Ttl();
|
||||
boolean is_wikitext = Xow_page_tid.Identify(wpg.Wiki().Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext;
|
||||
byte[] orig_bry = Bry_.Empty;
|
||||
if (is_wikitext) {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_hdump(tmp_bfr, ctx, Xoh_wtr_ctx.Hdump, wpg);
|
||||
orig_bry = tmp_bfr.To_bry_and_clear();
|
||||
wpg.Db().Html().Html_bry_(orig_bry);
|
||||
}
|
||||
else { // not wikitext; EX: pages in MediaWiki: ns; DATE:2016-09-12
|
||||
wpg.Db().Html().Html_bry_(wpg.Db().Text().Text_bry());
|
||||
}
|
||||
|
||||
// save to db
|
||||
Xowd_html_tbl html_tbl = html_tbl_retriever.Get_html_tbl(wpg.Ttl().Ns(), prv_row_len); // get html_tbl
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_hdiff(tmp_bfr, wpg, toc_label), html_tbl, true, is_wikitext); // save to db
|
||||
stat_tbl.Insert(tmp_hpg, stat_itm, wpg.Root().Root_src().length, tmp_hpg.Db().Html().Html_bry().length, prv_row_len); // save stats
|
||||
|
||||
// run hzip diff if enabled
|
||||
if (hzip_diff && is_wikitext) {
|
||||
byte[] expd_bry = op_sys_is_wnt ? Bry_.Replace(tmp_bfr, orig_bry, Byte_ascii.Cr_lf_bry, Byte_ascii.Nl_bry) : orig_bry; // tidy adds crlf if wnt
|
||||
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 void Commit() {
|
||||
html_tbl_retriever.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
|
||||
}
|
||||
public void Term() {this.Commit(); html_tbl_retriever.Rls_all();}
|
||||
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_diff_)) hzip_diff = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_b256_)) hzip_b256 = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
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_";
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.htmls.core.dbs.*;
|
||||
public interface Xob_hdump_tbl_retriever {
|
||||
Xowd_html_tbl Get_html_tbl(Xow_ns ns, int prv_row_len);
|
||||
void Commit();
|
||||
void Rls_all();
|
||||
}
|
||||
|
||||
@@ -13,3 +13,41 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
public class Xob_link_dump_cmd {
|
||||
private Xob_link_dump_tbl tbl; private int src_page_id; private Io_url page_db_url;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
this.page_db_url = wiki.Data__core_mgr().Db__core().Url();
|
||||
this.tbl = Xob_link_dump_tbl.Get_or_new(wiki);
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Page_bgn(int src_page_id) {this.src_page_id = src_page_id;}
|
||||
public void Add(int src_html_uid, int trg_ns_id, byte[] trg_ttl) {tbl.Insert_cmd_by_batch(src_page_id, src_html_uid, trg_ns_id, trg_ttl);}
|
||||
public void Wkr_commit() {tbl.Conn().Txn_sav();}
|
||||
public void Wkr_end() {
|
||||
try {
|
||||
tbl.Insert_end();
|
||||
tbl.Create_idx_1();
|
||||
Db_conn conn = tbl.Conn();
|
||||
new Db_attach_mgr(conn, new Db_attach_itm("page_db", page_db_url))
|
||||
.Exec_sql_w_msg("update trg_page_id", String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO link_dump"
|
||||
, "SELECT r.uid"
|
||||
, ", r.src_page_id"
|
||||
, ", r.src_html_uid"
|
||||
, ", Coalesce(p.page_id, -1)"
|
||||
, ", r.trg_ns"
|
||||
, ", r.trg_ttl"
|
||||
, "FROM link_dump r"
|
||||
, " LEFT JOIN <page_db>page p ON r.trg_ns = p.page_namespace AND r.trg_ttl = p.page_title"
|
||||
, ";"
|
||||
));;
|
||||
conn.Exec_sql("UPDATE link_dump SET trg_ns = -1 AND trg_ttl = '' WHERE trg_page_id != -1;");
|
||||
tbl.Create_idx_2();
|
||||
conn.Env_vacuum();
|
||||
} catch (Exception e) {
|
||||
Tfds.Dbg(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,55 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Rls_able {
|
||||
public static final String Tbl_name = "link_dump"; private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public static final String
|
||||
Fld_uid = flds.Add_int_pkey_autonum("uid")
|
||||
, Fld_src_page_id = flds.Add_int("src_page_id")
|
||||
, Fld_src_html_uid = flds.Add_int("src_html_uid")
|
||||
, Fld_trg_page_id = flds.Add_int_dflt("trg_page_id", -1)
|
||||
, Fld_trg_ns = flds.Add_int("trg_ns")
|
||||
, Fld_trg_ttl = flds.Add_str("trg_ttl", 255)
|
||||
;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xob_link_dump_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(Tbl_name, flds));}
|
||||
public void Create_idx_1() {
|
||||
conn.Meta_idx_create
|
||||
( Dbmeta_idx_itm.new_normal_by_tbl(Tbl_name, "src", Fld_src_page_id, Fld_src_html_uid)
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(Tbl_name, "trg_temp", Fld_trg_ns, Fld_trg_ttl)
|
||||
);
|
||||
}
|
||||
public void Create_idx_2() {
|
||||
conn.Meta_idx_create
|
||||
( Dbmeta_idx_itm.new_normal_by_tbl(Tbl_name, "trg", Fld_trg_page_id, Fld_src_page_id, Fld_src_html_uid)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("bldr__link_dump");}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int src_page_id, int src_html_uid, int trg_ns, byte[] trg_ttl) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(Tbl_name, flds.To_str_ary_wo_autonum());
|
||||
stmt_insert.Clear().Val_int(Fld_src_page_id, src_page_id)
|
||||
.Val_int(Fld_src_html_uid, src_html_uid).Val_int(Fld_trg_page_id, -1).Val_int(Fld_trg_ns, trg_ns).Val_bry_as_str(Fld_trg_ttl, trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Db_rdr Select_missing() {
|
||||
return conn.Stmt_select_order(Tbl_name, flds, String_.Ary(Fld_trg_page_id), Fld_src_page_id, Fld_src_html_uid)
|
||||
.Crt_int(Fld_trg_page_id, -1).Exec_select__rls_auto();
|
||||
}
|
||||
public static Xob_link_dump_tbl Get_or_new(Xow_wiki wiki) {
|
||||
Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(wiki.Fsys_mgr().Root_dir().GenSubFil("xowa.temp.redlink.sqlite3"));
|
||||
Xob_link_dump_tbl rv = new Xob_link_dump_tbl(conn_data.Conn());
|
||||
if (conn_data.Created()) rv.Create_tbl();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.htmls.core.dbs.*;
|
||||
public class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
private final Xow_db_file page_db;
|
||||
public Xob_ns_to_db_wkr__html(Xow_db_file page_db) {this.page_db = page_db;}
|
||||
public byte Db_tid() {return Xow_db_file_.Tid__html_data;}
|
||||
public void Tbl_init(Xow_db_file db) {
|
||||
Xowd_html_tbl tbl = db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Tbl_term(Xow_db_file db) {
|
||||
db.Tbl__text().Insert_end();
|
||||
Db_conn db_conn = db.Conn();
|
||||
new Db_attach_mgr(page_db.Conn(), new Db_attach_itm("html_db", db.Url()))
|
||||
.Exec_sql_w_msg("hdump.update page.html_db_id", Sql_update_page_html_db_id, db.Id());
|
||||
db_conn.Rls_conn();
|
||||
}
|
||||
private static final String Sql_update_page_html_db_id = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id, page_score)"
|
||||
, "SELECT p.page_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", p.page_is_redirect"
|
||||
, ", p.page_touched"
|
||||
, ", p.page_len"
|
||||
, ", p.page_random_int"
|
||||
, ", p.page_text_db_id"
|
||||
, ", {0}"
|
||||
, ", p.page_redirect_id"
|
||||
, ", p.page_score"
|
||||
, "FROM page p"
|
||||
, " JOIN <html_db>html h ON p.page_id = h.page_id"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,78 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.core.dbs.*;
|
||||
public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private int commit_interval = 10000, commit_count = 0;
|
||||
public Xob_redlink_mkr_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_html_redlinks;}
|
||||
public void Cmd_run() {Read_data();}
|
||||
private void Read_data() {
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
wiki.Init_assert();
|
||||
Xow_db_file core_db = wiki.Data__core_mgr().Db__core();
|
||||
Xob_db_file link_dump_db = Xob_db_file.New__redlink(wiki.Fsys_mgr().Root_dir());
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(link_dump_db.Conn(), new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));
|
||||
String attach_sql = attach_mgr.Resolve_sql(Sql_select_clause);
|
||||
attach_mgr.Attach();
|
||||
Xowd_page_tbl page_tbl = core_db.Tbl__page();
|
||||
int cur_html_db_id = -1, cur_page_id = -1;
|
||||
Xoh_redlink_tbl redlink_tbl = new Xoh_redlink_tbl(page_tbl.Conn());
|
||||
Db_rdr rdr = link_dump_db.Conn().Exec_rdr(attach_sql);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
// switch html_db if needed
|
||||
int html_db_id = rdr.Read_int(page_tbl.Fld_html_db_id());
|
||||
if (html_db_id != cur_html_db_id) {
|
||||
if (redlink_tbl != null) redlink_tbl.Conn().Txn_end();
|
||||
// redlink_tbl = wiki.Data__core_mgr().Dbs__get_by_id(html_db_id).Tbl__html_redlink();
|
||||
redlink_tbl.Conn().Txn_bgn("bldr__redlink");
|
||||
cur_html_db_id = html_db_id;
|
||||
}
|
||||
// commit page_id if needed
|
||||
int page_id = rdr.Read_int(page_tbl.Fld_page_id());
|
||||
if (cur_page_id != page_id) {
|
||||
if (cur_page_id != -1) Commit(redlink_tbl, cur_page_id, bfr);
|
||||
bfr.Add_int_variable(2).Add_byte_pipe(); // 2=gplx.xowa.htmls.core.makes.imgs.Xohd_img_tid.Tid_redlink
|
||||
cur_page_id = page_id;
|
||||
}
|
||||
// add html_uid to cur_page's bfr
|
||||
int html_uid = rdr.Read_int(Xob_link_dump_tbl.Fld_src_html_uid);
|
||||
bfr.Add_int_variable(html_uid).Add_byte_pipe();
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
Commit(redlink_tbl, cur_page_id, bfr); // commit cur page
|
||||
redlink_tbl.Conn().Txn_end(); // close cur tbl
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
private void Commit(Xoh_redlink_tbl redlink_tbl, int cur_page_id, Bry_bfr bfr) {
|
||||
redlink_tbl.Insert(cur_page_id, bfr.To_bry_and_clear());
|
||||
++commit_count;
|
||||
if ((commit_count % commit_interval ) == 0)
|
||||
redlink_tbl.Conn().Txn_sav();
|
||||
}
|
||||
private static final String Sql_select_clause = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT p.page_html_db_id"
|
||||
, ", p.page_id"
|
||||
, ", ld.src_html_uid"
|
||||
, "FROM link_dump ld"
|
||||
, " JOIN <page_db>page p ON p.page_id = ld.src_page_id "
|
||||
, "WHERE ld.trg_page_id = -1"
|
||||
, "ORDER BY p.page_html_db_id, p.page_id"
|
||||
, ";"
|
||||
);
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_commit_interval_ = "commit_interval_";
|
||||
}
|
||||
|
||||
@@ -13,3 +13,46 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Rls_able {
|
||||
private final String tbl_name = "html_redlink"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
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;
|
||||
public Xoh_redlink_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.fld_page_id = flds.Add_int_pkey("page_id");
|
||||
this.fld_redlink_uids = flds.Add_bry("redlink_uids");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("html_redlink__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert(int page_id, byte[] redlink_uids) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_bry(fld_redlink_uids, redlink_uids).Exec_insert();
|
||||
}
|
||||
public void Update(int page_id, byte[] redlink_uids) {
|
||||
if (stmt_update == null) stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
|
||||
stmt_update.Clear().Val_bry(fld_redlink_uids, redlink_uids).Crt_int(fld_page_id, page_id).Exec_update();
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_page_id);
|
||||
stmt_delete.Clear().Crt_int(fld_page_id, page_id).Exec_delete();
|
||||
}
|
||||
public byte[] Select_or_null(int page_id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_bry(fld_redlink_uids) : null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_delete = Db_stmt_.Rls(stmt_delete);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
stmt_update = Db_stmt_.Rls(stmt_update);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,24 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Xowd_html_row {
|
||||
public void Load(int page_id, int head_flag, int body_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
this.page_id = page_id;
|
||||
this.head_flag = head_flag;
|
||||
this.body_flag = body_flag;
|
||||
this.display_ttl = display_ttl;
|
||||
this.content_sub = content_sub;
|
||||
this.sidebar_div = sidebar_div;
|
||||
this.body = body;
|
||||
}
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Head_flag() {return head_flag;} private int head_flag;
|
||||
public int Body_flag() {return body_flag;} private int body_flag;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} private byte[] sidebar_div;
|
||||
public byte[] Body() {return body;} private byte[] body;
|
||||
|
||||
public static final int Db_row_size_fixed = (3 * 4); // page_id, head_flag, body_flag
|
||||
}
|
||||
|
||||
@@ -13,3 +13,110 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Xowd_html_tbl implements Db_tbl {
|
||||
private final String fld_page_id, fld_head_flag, fld_body_flag, fld_display_ttl, fld_content_sub, fld_sidebar_div, fld_body;
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_update;
|
||||
private final Int_flag_bldr body_flag_bldr = Make_body_flag_bldr();
|
||||
public Xowd_html_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.fld_page_id = flds.Add_int_pkey("page_id");
|
||||
this.fld_head_flag = flds.Add_int("head_flag");
|
||||
this.fld_body_flag = flds.Add_int("body_flag");
|
||||
this.fld_display_ttl = flds.Add_str("display_ttl", 1024);
|
||||
this.fld_content_sub = flds.Add_str("content_sub", 1024);
|
||||
this.fld_sidebar_div = flds.Add_str("sidebar_div", 2048);
|
||||
this.fld_body = flds.Add_bry("body");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = "html";
|
||||
public Dbmeta_fld_list Flds() {return flds;} private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
|
||||
public void Insert_bgn() {conn.Txn_bgn("html__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] body) {Insert(hpg.Page_id(), hpg.Head_mgr().Flag(), zip_tid, hzip_tid, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Insert(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
int body_flag = body_flag_bldr.Set(0, zip_tid).Set(1, hzip_tid).Encode();
|
||||
Insert(page_id, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
}
|
||||
public void Insert(int page_id, int head_flag, int body_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id);
|
||||
Fill_stmt(stmt_insert, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
stmt_insert.Exec_insert();
|
||||
}
|
||||
public void Update(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] body) {Update(hpg.Page_id(), hpg.Head_mgr().Flag(), zip_tid, hzip_tid, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Update(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
if (stmt_update == null) stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
|
||||
int body_flag = body_flag_bldr.Set(0, zip_tid).Set(1, hzip_tid).Encode();
|
||||
stmt_update.Clear();
|
||||
Fill_stmt(stmt_update, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
stmt_update.Crt_int(fld_page_id, page_id).Exec_update();
|
||||
}
|
||||
public void Upsert(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_page_id).Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_auto();
|
||||
boolean exists = rdr.Move_next();
|
||||
rdr.Rls();
|
||||
if (exists)
|
||||
Update(page_id, head_flag, zip_tid, hzip_tid, display_ttl, content_sub, sidebar_div, body);
|
||||
else
|
||||
Insert(page_id, head_flag, zip_tid, hzip_tid, display_ttl, content_sub, sidebar_div, body);
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.html: delete started: db=~{0} page_id=~{1}", conn.Conn_info().Raw(), page_id);
|
||||
conn.Stmt_delete(tbl_name, fld_page_id).Crt_int(fld_page_id, page_id).Exec_delete();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.html: delete done");
|
||||
}
|
||||
public void Update_page_id(int old_id, int new_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.html: update page_id started: db=~{0} old_id=~{1} new_id=~{2}", conn.Conn_info().Raw(), old_id, new_id);
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_page_id), fld_page_id).Val_int(fld_page_id, new_id).Crt_int(fld_page_id, old_id).Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.html: update page_id done");
|
||||
}
|
||||
public boolean Select_by_page(Xoh_page hpg) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, hpg.Page_id()).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
int body_flag = rdr.Read_int(fld_body_flag);
|
||||
body_flag_bldr.Decode(body_flag);
|
||||
hpg.Ctor_by_db(rdr.Read_int(fld_head_flag), rdr.Read_bry_by_str(fld_display_ttl), rdr.Read_bry_by_str(fld_content_sub), rdr.Read_bry_by_str(fld_sidebar_div), body_flag_bldr.Get_as_int(0), body_flag_bldr.Get_as_int(1), rdr.Read_bry(fld_body));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public boolean Select_as_row(Xowd_html_row rv, int page_id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
rv.Load
|
||||
( page_id
|
||||
, rdr.Read_int(fld_head_flag)
|
||||
, rdr.Read_int(fld_body_flag)
|
||||
, rdr.Read_bry_by_str(fld_display_ttl)
|
||||
, rdr.Read_bry_by_str(fld_content_sub)
|
||||
, rdr.Read_bry_by_str(fld_sidebar_div)
|
||||
, rdr.Read_bry(fld_body)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
stmt_update = Db_stmt_.Rls(stmt_update);
|
||||
}
|
||||
public void Fill_stmt(Db_stmt stmt, int head_flag, int body_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
stmt.Val_int(fld_head_flag, head_flag).Val_int(fld_body_flag, body_flag)
|
||||
.Val_bry_as_str(fld_display_ttl, Bry_.Coalesce_to_empty(display_ttl)).Val_bry_as_str(fld_content_sub, Bry_.Coalesce_to_empty(content_sub)).Val_bry_as_str(fld_sidebar_div, Bry_.Coalesce_to_empty(sidebar_div)).Val_bry(fld_body, body);
|
||||
}
|
||||
public static Int_flag_bldr Make_body_flag_bldr() {return new Int_flag_bldr().Pow_ary_bld_(3, 2);} // 8 different zip types; 4 different hzip types
|
||||
}
|
||||
|
||||
@@ -13,3 +13,33 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.htmls.*;
|
||||
class Xoh_display_ttl_wtr {
|
||||
public static boolean Is_style_restricted(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Mwh_atr_itm atr, byte[] atr_key) {
|
||||
if (atr_key != null
|
||||
&& Bry_.Eq(atr_key, Atr_key_style)
|
||||
) {
|
||||
byte[] atr_val = atr.Val_as_bry(); if (atr_val == null) return false; // bounds_chk
|
||||
int atr_val_len = atr_val.length;
|
||||
int atr_pos = 0;
|
||||
while (atr_pos < atr_val_len) {
|
||||
byte b = atr_val[atr_pos];
|
||||
Object o = style_trie.Match_bgn_w_byte(b, atr_val, atr_pos, atr_val_len);
|
||||
if (o != null) {
|
||||
bfr.Add(Msg_style_restricted);
|
||||
return true;
|
||||
}
|
||||
++atr_pos;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static final byte[]
|
||||
Atr_key_style = Bry_.new_a7("style")
|
||||
, Msg_style_restricted = Bry_.new_a7(" style='/* attempt to bypass $wgRestrictDisplayTitle */'")
|
||||
;
|
||||
private static final Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_str_byte__many(Byte_.By_int(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
|
||||
}
|
||||
|
||||
@@ -13,3 +13,541 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.langs.kwds.*; import gplx.langs.htmls.entitys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.htmls.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.parsers.hdrs.*;
|
||||
public class Xoh_html_wtr {
|
||||
private final Xoae_app app; private final Xowe_wiki wiki; private final Xow_html_mgr html_mgr; private final Xop_xatr_whitelist_mgr whitelist_mgr;
|
||||
private Xoae_page page;
|
||||
private int indent_level;
|
||||
private int stack_counter;
|
||||
public Xoh_html_wtr(Xowe_wiki wiki, Xow_html_mgr html_mgr) {
|
||||
this.wiki = wiki; this.app = wiki.Appe();
|
||||
this.html_mgr = html_mgr; this.whitelist_mgr = html_mgr.Whitelist_mgr();
|
||||
this.lnki_wtr = new Xoh_lnki_wtr(this, wiki, html_mgr, cfg);
|
||||
this.ref_wtr = new Ref_html_wtr(wiki);
|
||||
}
|
||||
public Xoh_html_wtr_cfg Cfg() {return cfg;} private final Xoh_html_wtr_cfg cfg = new Xoh_html_wtr_cfg();
|
||||
public Xoh_lnke_html Wkr__lnke() {return wkr__lnke;} private final Xoh_lnke_html wkr__lnke = new Xoh_lnke_html();
|
||||
public Xoh_hdr_html Wkr__hdr() {return wkr__hdr;} private final Xoh_hdr_html wkr__hdr = new Xoh_hdr_html();
|
||||
public Xoh_lnki_wtr Lnki_wtr() {return lnki_wtr;} private final Xoh_lnki_wtr lnki_wtr;
|
||||
public Ref_html_wtr Ref_wtr() {return ref_wtr;} private final Ref_html_wtr ref_wtr;
|
||||
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
cfg.Toc__show_(Bool_.Y).Lnki__title_(true).Lnki__visited_y_().Lnki__id_(Bool_.Y); // NOTE: set during Init_by_wiki, b/c all tests assume these are false
|
||||
ref_wtr.Init_by_wiki(wiki);
|
||||
lnki_wtr.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Init_by_page(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xoae_page page) {
|
||||
this.page = page;
|
||||
lnki_wtr.Init_by_page(ctx, hctx, src, page);
|
||||
}
|
||||
|
||||
public void Write_doc(Bry_bfr rv, Xop_ctx ctx, byte[] src, Xop_root_tkn root) {Write_doc(rv, ctx, Xoh_wtr_ctx.Basic, src, root);}
|
||||
public void Write_doc(Bry_bfr rv, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_root_tkn root) {
|
||||
// init
|
||||
this.indent_level = 0;
|
||||
this.stack_counter = 0;
|
||||
this.page = ctx.Page();
|
||||
page.Slink_list().Clear(); // HACK: always clear langs; necessary for reload
|
||||
lnki_wtr.Init_by_page(ctx, hctx, src, ctx.Page());
|
||||
|
||||
// write document starting from root
|
||||
Write_tkn(rv, ctx, hctx, src, null, -1, root);
|
||||
}
|
||||
public void Write_tkn_to_html(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_tkn_itm tkn) {
|
||||
this.Write_tkn(bfr, ctx, hctx, src, grp, sub_idx, tkn);
|
||||
}
|
||||
private void Write_tkn(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_tkn_itm tkn) {
|
||||
if (tkn.Ignore()) return;
|
||||
if (++stack_counter > 1500) { // NOTE:some deeply nested pages can go to 1500; PAGE:cs.s:Page:Hejčl,_Jan_-_Pentateuch.pdf/128 DATE:2016-09-01; PAGE:en.w:Wikipedia:People_by_year/Reports/Stats; DATE:2016-09-11
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "stack overflow while generating html; wiki=~{0} page=~{1}", ctx.Wiki().Domain_bry(), ctx.Page().Ttl().Full_db());
|
||||
return;
|
||||
}
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_arg_itm:
|
||||
case Xop_tkn_itm_.Tid_root:
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, tkn, i, tkn.Subs_get(i));
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_ignore: break;
|
||||
case Xop_tkn_itm_.Tid_html_ncr: Html_ncr (bfr, ctx, hctx, src, (Xop_amp_tkn_num)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_html_ref: Html_ref (bfr, ctx, hctx, src, (Xop_amp_tkn_ent)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hr: Hr (bfr, ctx, hctx, src, (Xop_hr_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_apos: Apos (bfr, ctx, hctx, src, (Xop_apos_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_list: List (bfr, ctx, hctx, src, (Xop_list_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_xnde: Xnde (bfr, ctx, hctx, src, (Xop_xnde_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_under: Under (bfr, ctx, hctx, src, (Xop_under_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tb: Tblw (bfr, ctx, hctx, src, (Xop_tblw_tkn)tkn, Gfh_tag_.Table_lhs_bgn , Gfh_tag_.Table_rhs, true); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tr: Tblw (bfr, ctx, hctx, src, (Xop_tblw_tkn)tkn, Gfh_tag_.Tr_lhs_bgn , Gfh_tag_.Tr_rhs, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_td: Tblw (bfr, ctx, hctx, src, (Xop_tblw_tkn)tkn, Gfh_tag_.Td_lhs_bgn , Gfh_tag_.Td_rhs, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_th: Tblw (bfr, ctx, hctx, src, (Xop_tblw_tkn)tkn, Gfh_tag_.Th_lhs_bgn , Gfh_tag_.Th_rhs, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tc: Tblw (bfr, ctx, hctx, src, (Xop_tblw_tkn)tkn, Gfh_tag_.Caption_lhs_bgn , Gfh_tag_.Caption_rhs, false); break;
|
||||
case Xop_tkn_itm_.Tid_newLine: New_line (bfr, ctx, hctx, src, (Xop_nl_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_bry: Bry (bfr, ctx, hctx, src, (Xop_bry_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnki: lnki_wtr.Write_lnki(bfr, hctx, src, (Xop_lnki_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnke: wkr__lnke.Write_html(bfr, html_mgr, this, hctx, ctx, src, (Xop_lnke_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hdr: wkr__hdr.Write_html(bfr, this, wiki, page, ctx, hctx, cfg, grp, sub_idx, src, (Xop_hdr_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_para:
|
||||
case Xop_tkn_itm_.Tid_pre:
|
||||
case Xop_tkn_itm_.Tid_space:
|
||||
case Xop_tkn_itm_.Tid_escape:
|
||||
tkn.Html__write(bfr, this, wiki, page, ctx, hctx, cfg, grp, sub_idx, src); break;
|
||||
default:
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, tkn.Src_bgn(), tkn.Src_end(), true, false); // NOTE: always escape text including (a) lnki_alt text; and (b) any other text, especially failed xndes; DATE:2013-06-18
|
||||
break;
|
||||
}
|
||||
--stack_counter;
|
||||
}
|
||||
private void Html_ncr(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_amp_tkn_num tkn) {
|
||||
bfr.Add_byte(Byte_ascii.Amp).Add_byte(Byte_ascii.Hash).Add_int_variable(tkn.Val()).Add_byte(Byte_ascii.Semic); // NOTE: do not literalize, else browser may not display multi-char bytes properly; EX:   gets added as   not as {192,160}; DATE:2013-12-09
|
||||
}
|
||||
private void Html_ref(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_amp_tkn_ent tkn) {
|
||||
if (tkn.Itm_is_custom()) // used by <nowiki>; EX:<nowiki><</nowiki> -> &xowa_lt; DATE:2014-11-07
|
||||
tkn.Print_literal(bfr);
|
||||
else
|
||||
tkn.Print_ncr(bfr);
|
||||
}
|
||||
private void Hr(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_hr_tkn tkn) {bfr.Add(Gfh_tag_.Hr_inl);}
|
||||
private void Apos(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_apos_tkn apos) {
|
||||
if (hctx.Mode_is_alt()) return; // ignore apos if alt; EX: [[File:A.png|''A'']] should have alt of A; DATE:2013-10-25
|
||||
int literal_apos = apos.Apos_lit();
|
||||
if (literal_apos > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Apos, literal_apos);
|
||||
switch (apos.Apos_cmd()) {
|
||||
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Gfh_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Gfh_tag_.I_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Gfh_tag_.B_lhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Gfh_tag_.I_lhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs);; break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_nil: break;
|
||||
default: throw Err_.new_unhandled(apos.Apos_cmd());
|
||||
}
|
||||
}
|
||||
private void List(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_list_tkn list) {
|
||||
if (hctx.Mode_is_alt()) { // alt; add literally; EX: "*" for "\n*"; note that \n is added in New_line()
|
||||
if (list.List_bgn() == Bool_.Y_byte) { // bgn tag
|
||||
bfr.Add_byte(list.List_itmTyp()); // add literal byte
|
||||
}
|
||||
else {} // end tag; ignore
|
||||
}
|
||||
else {
|
||||
byte list_itm_type = list.List_itmTyp();
|
||||
if (list.List_bgn() == Bool_.Y_byte) {
|
||||
if (list.List_sub_first()) List_grp_bgn(bfr, ctx, hctx, src, list_itm_type);
|
||||
List_itm_bgn(bfr, ctx, hctx, src, list_itm_type);
|
||||
}
|
||||
else {
|
||||
List_itm_end(bfr, ctx, hctx, src, list_itm_type);
|
||||
if (list.List_sub_last() == Bool_.Y_byte) List_grp_end(bfr, ctx, hctx, src, list_itm_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void List_grp_bgn(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol: tag = Gfh_tag_.Ol_lhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Gfh_tag_.Ul_lhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd:
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Gfh_tag_.Dl_lhs; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
if (bfr.Len() > 0) bfr.Add_byte_nl(); // NOTE: do not add newLine if start
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
private void List_itm_bgn(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol:
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Gfh_tag_.Li_lhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Gfh_tag_.Dt_lhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd: tag = Gfh_tag_.Dd_lhs; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_nl();
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
private void List_grp_end(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol: tag = Gfh_tag_.Ol_rhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Gfh_tag_.Ul_rhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd:
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Gfh_tag_.Dl_rhs; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_nl();
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(tag);
|
||||
}
|
||||
|
||||
private void List_itm_end(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol:
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Gfh_tag_.Li_rhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Gfh_tag_.Dt_rhs; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd: tag = Gfh_tag_.Dd_rhs; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(tag);
|
||||
}
|
||||
private void New_line(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_nl_tkn tkn) {
|
||||
if (hctx.Mode_is_alt())
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
if (tkn.Nl_tid() == Xop_nl_tkn.Tid_char) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Bry(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_bry_tkn bry) {
|
||||
bfr.Add(bry.Val());
|
||||
}
|
||||
private void Under(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_under_tkn under) {
|
||||
if (hctx.Mode_is_alt()) return;
|
||||
switch (under.Under_tid()) {
|
||||
case Xol_kwd_grp_.Id_toc:
|
||||
if (cfg.Toc__show())
|
||||
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_placeholder(page, bfr);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_notoc: case Xol_kwd_grp_.Id_forcetoc: // NOTE: skip output; changes flag on page only
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void Xnde(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (hctx.Mode_is_alt()) {
|
||||
if (xnde.Tag_close_bgn() > 0) // NOTE: some tags are not closed; WP.EX: France; <p>
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), true, false);
|
||||
else
|
||||
Xnde_subs(bfr, ctx, hctx, src, xnde);
|
||||
return;
|
||||
}
|
||||
Xop_xnde_tag tag = xnde.Tag();
|
||||
int tag_id = tag.Id();
|
||||
switch (tag_id) {
|
||||
case Xop_xnde_tag_.Tid__br:
|
||||
if (xnde.Src_end() - xnde.Src_bgn() < 4
|
||||
|| xnde.Src_bgn() == -1)
|
||||
bfr.Add(Gfh_tag_.Br_inl); else bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end()); break;
|
||||
case Xop_xnde_tag_.Tid__hr: bfr.Add(Gfh_tag_.Hr_inl); break;
|
||||
case Xop_xnde_tag_.Tid__includeonly: // NOTE: do not write tags or content
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid__noinclude: // NOTE: do not write tags
|
||||
case Xop_xnde_tag_.Tid__onlyinclude:
|
||||
Xnde_subs_escape(bfr, ctx, hctx, src, xnde, false, false);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid__nowiki:
|
||||
Xnde_subs_escape(bfr, ctx, hctx, src, xnde, false, false);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid__b: case Xop_xnde_tag_.Tid__strong:
|
||||
case Xop_xnde_tag_.Tid__i: case Xop_xnde_tag_.Tid__em: case Xop_xnde_tag_.Tid__cite: case Xop_xnde_tag_.Tid__dfn: case Xop_xnde_tag_.Tid__var:
|
||||
case Xop_xnde_tag_.Tid__u: case Xop_xnde_tag_.Tid__ins: case Xop_xnde_tag_.Tid__abbr:
|
||||
case Xop_xnde_tag_.Tid__strike: case Xop_xnde_tag_.Tid__s: case Xop_xnde_tag_.Tid__del:
|
||||
case Xop_xnde_tag_.Tid__sub: case Xop_xnde_tag_.Tid__sup: case Xop_xnde_tag_.Tid__big: case Xop_xnde_tag_.Tid__small:
|
||||
case Xop_xnde_tag_.Tid__code: case Xop_xnde_tag_.Tid__tt: case Xop_xnde_tag_.Tid__kbd: case Xop_xnde_tag_.Tid__samp: case Xop_xnde_tag_.Tid__blockquote:
|
||||
case Xop_xnde_tag_.Tid__font: case Xop_xnde_tag_.Tid__center:
|
||||
case Xop_xnde_tag_.Tid__p: case Xop_xnde_tag_.Tid__span: case Xop_xnde_tag_.Tid__div:
|
||||
case Xop_xnde_tag_.Tid__h1: case Xop_xnde_tag_.Tid__h2: case Xop_xnde_tag_.Tid__h3: case Xop_xnde_tag_.Tid__h4: case Xop_xnde_tag_.Tid__h5: case Xop_xnde_tag_.Tid__h6:
|
||||
case Xop_xnde_tag_.Tid__dt: case Xop_xnde_tag_.Tid__dd: case Xop_xnde_tag_.Tid__ol: case Xop_xnde_tag_.Tid__ul: case Xop_xnde_tag_.Tid__dl:
|
||||
case Xop_xnde_tag_.Tid__table: case Xop_xnde_tag_.Tid__tr: case Xop_xnde_tag_.Tid__td: case Xop_xnde_tag_.Tid__th: case Xop_xnde_tag_.Tid__caption: case Xop_xnde_tag_.Tid__tbody:
|
||||
case Xop_xnde_tag_.Tid__ruby: case Xop_xnde_tag_.Tid__rt: case Xop_xnde_tag_.Tid__rb: case Xop_xnde_tag_.Tid__rp:
|
||||
case Xop_xnde_tag_.Tid__time: case Xop_xnde_tag_.Tid__bdi: case Xop_xnde_tag_.Tid__data: case Xop_xnde_tag_.Tid__mark: case Xop_xnde_tag_.Tid__wbr: case Xop_xnde_tag_.Tid__bdo: // HTML 5: write literally and let browser handle them
|
||||
case Xop_xnde_tag_.Tid__q:
|
||||
Write_xnde(bfr, ctx, hctx, xnde, tag, tag_id, src);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid__pre: {
|
||||
if (xnde.Tag_open_end() == xnde.Tag_close_bgn()) return; // ignore empty tags, else blank pre line will be printed; DATE:2014-03-12
|
||||
byte[] name = tag.Name_bry();
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
Xnde_subs_escape(bfr, ctx, hctx, src, xnde, false, true);
|
||||
Gfh_tag_.Bld_rhs(bfr, name);
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid__li: {
|
||||
byte[] name = tag.Name_bry();
|
||||
int bfr_len = bfr.Len();
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
if (bfr_len > 0 && bfr.Bfr()[bfr_len - 1] != Byte_ascii.Nl) bfr.Add_byte_nl(); // NOTE: always add nl before li else some lists will merge and force long horizontal bar; EX:w:Music
|
||||
}
|
||||
if (xnde.Tag_visible()) {
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
}
|
||||
Xnde_subs(bfr, ctx, hctx, src, xnde);
|
||||
if (xnde.Tag_visible())
|
||||
Gfh_tag_.Bld_rhs(bfr, name); // NOTE: inline is never written as <b/>; will be written as <b></b>; SEE: NOTE_1
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid__timeline: {
|
||||
bfr.Add(gplx.xowa.htmls.core.wkrs.addons.timelines.Xoh_timeline_data.Hook_bry);
|
||||
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde.Tag_open_end(), xnde.Tag_close_bgn()); // NOTE: do not embed <timeline> tag inside pre, else timeline will render in black; EX:<pre><timeline>a</timeline></pre> will fail; DATE:2014-05-22
|
||||
bfr.Add_str_a7("</pre>");
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid__gallery:
|
||||
case Xop_xnde_tag_.Tid__poem:
|
||||
case Xop_xnde_tag_.Tid__hiero:
|
||||
case Xop_xnde_tag_.Tid__score:
|
||||
case Xop_xnde_tag_.Tid__ref:
|
||||
case Xop_xnde_tag_.Tid__references:
|
||||
case Xop_xnde_tag_.Tid__inputBox:
|
||||
case Xop_xnde_tag_.Tid__imageMap:
|
||||
case Xop_xnde_tag_.Tid__pages:
|
||||
case Xop_xnde_tag_.Tid__pagequality:
|
||||
case Xop_xnde_tag_.Tid__pagelist:
|
||||
case Xop_xnde_tag_.Tid__section:
|
||||
case Xop_xnde_tag_.Tid__translate:
|
||||
case Xop_xnde_tag_.Tid__dynamicPageList:
|
||||
case Xop_xnde_tag_.Tid__languages:
|
||||
case Xop_xnde_tag_.Tid__templateData:
|
||||
case Xop_xnde_tag_.Tid__source: // DATE:2015-09-29
|
||||
case Xop_xnde_tag_.Tid__syntaxHighlight:
|
||||
case Xop_xnde_tag_.Tid__listing_buy:
|
||||
case Xop_xnde_tag_.Tid__listing_do:
|
||||
case Xop_xnde_tag_.Tid__listing_drink:
|
||||
case Xop_xnde_tag_.Tid__listing_eat:
|
||||
case Xop_xnde_tag_.Tid__listing_listing:
|
||||
case Xop_xnde_tag_.Tid__listing_see:
|
||||
case Xop_xnde_tag_.Tid__listing_sleep:
|
||||
case Xop_xnde_tag_.Tid__xowa_cmd:
|
||||
case Xop_xnde_tag_.Tid__rss:
|
||||
case Xop_xnde_tag_.Tid__quiz:
|
||||
case Xop_xnde_tag_.Tid__math:
|
||||
case Xop_xnde_tag_.Tid__indicator:
|
||||
case Xop_xnde_tag_.Tid__xowa_html:
|
||||
case Xop_xnde_tag_.Tid__xowa_wiki_setup:
|
||||
case Xop_xnde_tag_.Tid__graph:
|
||||
case Xop_xnde_tag_.Tid__random_selection:
|
||||
case Xop_xnde_tag_.Tid__tabber:
|
||||
case Xop_xnde_tag_.Tid__tabview:
|
||||
case Xop_xnde_tag_.Tid__mapframe:
|
||||
case Xop_xnde_tag_.Tid__maplink:
|
||||
Xox_xnde xtn = xnde.Xnde_xtn();
|
||||
xtn.Xtn_write(bfr, app, ctx, this, hctx, page, xnde, src);
|
||||
break;
|
||||
// do not write <meta/> <link/>; PAGE:fr.s:La_Dispute DATE:2017-05-28
|
||||
case Xop_xnde_tag_.Tid__meta:
|
||||
case Xop_xnde_tag_.Tid__link:
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid__xowa_tag_bgn:
|
||||
case Xop_xnde_tag_.Tid__xowa_tag_end:
|
||||
break;
|
||||
default: // unknown tag
|
||||
if (tag.Restricted()) { // a; img; script; etc..
|
||||
if ( !page.Html_data().Html_restricted() // page is not marked restricted (only [[Special:]])
|
||||
|| page.Wiki().Domain_tid() == Xow_domain_tid_.Tid__home) { // page is in home wiki
|
||||
bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end());
|
||||
return;
|
||||
}
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(tag.Name_bry()); // escape bgn
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
switch (xnde.CloseMode()) {
|
||||
case Xop_xnde_tkn.CloseMode_inline:
|
||||
bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Angle_end);
|
||||
break;
|
||||
default: // NOTE: close tag, even if dangling; EX: <center>a -> <center>a</center>
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
Xnde_subs(bfr, ctx, hctx, src, xnde);
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash).Add(tag.Name_bry()).Add_byte(Byte_ascii.Angle_end);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void Write_xnde(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, Xop_xnde_tag tag, int tag_id, byte[] src) {
|
||||
byte[] name = tag.Name_bry();
|
||||
boolean at_bgn = true;
|
||||
Bry_bfr ws_bfr = wiki.Utl__bfr_mkr().Get_b512(); // create separate ws_bfr to handle "a<b> c </b>d" -> "a <b>c</b> d"
|
||||
int subs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Xop_tkn_itm sub = xnde.Subs_get(i);
|
||||
byte tkn_tid = sub.Tkn_tid();
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_space: // space; add to ws_bfr;
|
||||
ws_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
break;
|
||||
default:
|
||||
if (tkn_tid == Xop_tkn_itm_.Tid_html_ncr) { // html_entity   needed for fr.wikipedia.org and many spans with <span> </span>; DATE:2013-06-18
|
||||
Xop_amp_tkn_num ncr_tkn = (Xop_amp_tkn_num)sub;
|
||||
if (ncr_tkn.Val() == Byte_ascii.Space
|
||||
|| ncr_tkn.Val() == 160
|
||||
) {
|
||||
|
||||
ws_bfr.Add_mid(src, ncr_tkn.Src_bgn(), ncr_tkn.Src_end());
|
||||
continue; // just add entity; don't process rest;
|
||||
}
|
||||
}
|
||||
if (ws_bfr.Len() > 0) bfr.Add_bfr_and_clear(ws_bfr); // dump ws_bfr to real bfr
|
||||
if (at_bgn) { // 1st non-ws tkn; add open tag; <b>
|
||||
at_bgn = false;
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
}
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, sub); // NOTE: never escape; <p>, <table>, <center> etc may have nested nodes
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (at_bgn) { // occurs when xnde is empty; EX: <b></b>
|
||||
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
}
|
||||
Gfh_tag_.Bld_rhs(bfr, name); // NOTE: inline is never written as <b/>; will be written as <b></b>; SEE: NOTE_1
|
||||
if (ws_bfr.Len() > 0) bfr.Add_bfr_and_clear(ws_bfr); // dump any leftover ws to bfr; handles "<b>c </b>" -> "<b>c</b> "
|
||||
ws_bfr.Mkr_rls();
|
||||
}
|
||||
private void Xnde_atrs(int tag_id, Xoh_wtr_ctx hctx, byte[] src, int bgn, int end, Mwh_atr_itm[] ary, Bry_bfr bfr) {
|
||||
if (ary == null) return; // NOTE: some nodes will have null xatrs b/c of whitelist; EX: <pre style="overflow:auto">a</pre>; style is not on whitelist so not xatr generated, but xatr_bgn will != -1
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Mwh_atr_itm atr = ary[i];
|
||||
if (atr.Invalid()) continue;
|
||||
if (!whitelist_mgr.Chk(tag_id, src, atr)) continue;
|
||||
Xnde_atr_write(bfr, app, hctx, src, atr);
|
||||
}
|
||||
}
|
||||
private static void Xnde_atr_write(Bry_bfr bfr, Xoae_app app, Xoh_wtr_ctx hctx, byte[] src, Mwh_atr_itm atr) {
|
||||
byte[] atr_key = atr.Key_bry();
|
||||
if ( hctx.Mode_is_display_title()
|
||||
&& Xoh_display_ttl_wtr.Is_style_restricted(bfr, hctx, src, atr, atr_key))
|
||||
return;
|
||||
|
||||
bfr.Add_byte(Byte_ascii.Space); // add space before every attribute
|
||||
if (atr_key != null) {
|
||||
bfr.Add(atr_key);
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
}
|
||||
byte quote_byte = atr.Qte_byte(); if (quote_byte == Byte_ascii.Null) quote_byte = Byte_ascii.Quote;
|
||||
bfr.Add_byte(quote_byte);
|
||||
if (atr.Key_tid() == Mwh_atr_itm_.Key_tid__id) { // ids should not have spaces; DATE:2013-04-01
|
||||
if (atr.Val_bry() == null)
|
||||
Xnde_atr_write_id(bfr, app, atr.Src(), atr.Val_bgn(), atr.Val_end());
|
||||
else {
|
||||
byte[] atr_val = atr.Val_bry();
|
||||
Xnde_atr_write_id(bfr, app, atr_val, 0, atr_val.length);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (atr.Val_bry() == null)
|
||||
bfr.Add_mid(src, atr.Val_bgn(), atr.Val_end());
|
||||
else
|
||||
bfr.Add(atr.Val_bry());
|
||||
}
|
||||
bfr.Add_byte(quote_byte);
|
||||
}
|
||||
private static void Xnde_atr_write_id(Bry_bfr bfr, Xoae_app app, byte[] bry, int bgn, int end) {gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(bfr, bry, bgn, end);}
|
||||
private void Xnde_subs(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_xnde_tkn xnde) {
|
||||
int subs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, xnde.Subs_get(i));
|
||||
}
|
||||
private void Xnde_subs_escape(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_xnde_tkn xnde, boolean amp_enable, boolean nowiki) {
|
||||
int xndesubs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < xndesubs_len; i++) {
|
||||
Xop_tkn_itm sub = xnde.Subs_get(i);
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_xnde:
|
||||
Xop_xnde_tkn sub_xnde = (Xop_xnde_tkn)sub;
|
||||
switch (sub_xnde.Tag().Id()) {
|
||||
case Xop_xnde_tag_.Tid__noinclude:
|
||||
case Xop_xnde_tag_.Tid__onlyinclude:
|
||||
case Xop_xnde_tag_.Tid__includeonly:
|
||||
break;
|
||||
default:
|
||||
byte[] tag_name = sub_xnde.Tag().Name_bry();
|
||||
bfr.Add(Gfh_entity_.Lt_bry).Add(tag_name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(sub_xnde.Tag().Id(), hctx, src, sub_xnde.Atrs_bgn(), sub_xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add(Gfh_entity_.Gt_bry);
|
||||
break;
|
||||
}
|
||||
Xnde_subs_escape(bfr, ctx, hctx, src, sub_xnde, amp_enable, false);
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_txt:
|
||||
if (amp_enable)
|
||||
bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
else
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, sub.Src_bgn(), sub.Src_end(), true, nowiki);
|
||||
break;
|
||||
default:
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, sub);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Tblw(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tblw_tkn tkn, byte[] bgn, byte[] end, boolean tblw_bgn) {
|
||||
if (hctx.Mode_is_alt()) // add \s for each \n
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(bgn);
|
||||
int atrs_bgn = tkn.Atrs_bgn();
|
||||
if (atrs_bgn != -1) Xnde_atrs(tkn.Tblw_tid(), hctx, src, atrs_bgn, tkn.Atrs_end(), tkn.Atrs_ary(), bfr); //bfr.Add_byte(Byte_ascii.Space).Add_mid(src, atrs_bgn, tkn.Atrs_end());
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
++indent_level;
|
||||
}
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, tkn, i, tkn.Subs_get(i));
|
||||
if (hctx.Mode_is_alt()) {
|
||||
if (tblw_bgn) // only add \s for closing table; |} -> "\s"
|
||||
bfr.Add_byte_space();
|
||||
}
|
||||
else {
|
||||
--indent_level;
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
}
|
||||
bfr.Add(end);
|
||||
if (!page.Html_data().Writing_hdr_for_toc()) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int Sub_idx_null = -1; // DELETE: placeholder for sub_idx; WHEN: need to remove Sub_grp
|
||||
}
|
||||
/*
|
||||
NOTE_1:inline always written as <tag></tag>, not <tag/>
|
||||
see WP:Permian–Triassic extinction event
|
||||
this will cause firefox to swallow up rest of text
|
||||
<div id="ScaleBar" style="width:1px; float:left; height:38em; padding:0; background-color:#242020" />
|
||||
this will not
|
||||
<div id="ScaleBar" style="width:1px; float:left; height:38em; padding:0; background-color:#242020" ></div>
|
||||
*/
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_html_wtr_ {
|
||||
public static void Para__assert_tag_starts_on_nl(Bry_bfr bfr, int src_bgn) {
|
||||
if (!bfr.Match_end_byt_nl_or_bos()) bfr.Add_byte_nl();
|
||||
if (src_bgn != 0) bfr.Add_byte_nl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_html_wtr_cfg {
|
||||
public boolean Toc__show() {return toc__show;} public Xoh_html_wtr_cfg Toc__show_(boolean v) {toc__show = v; return this;} private boolean toc__show;
|
||||
public boolean Lnki__id() {return lnki__id;} public Xoh_html_wtr_cfg Lnki__id_(boolean v) {lnki__id = v; return this;} private boolean lnki__id;
|
||||
public boolean Lnki__title() {return lnki__title;} public Xoh_html_wtr_cfg Lnki__title_(boolean v) {lnki__title = v; return this;} private boolean lnki__title;
|
||||
public boolean Lnki__visited() {return lnki__visited;} public Xoh_html_wtr_cfg Lnki__visited_y_() {lnki__visited = true; return this;} private boolean lnki__visited;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,116 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*;
|
||||
import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_wtr_escaper {
|
||||
public static String Escape_str(Xop_amp_mgr amp_mgr, Bry_bfr tmp_bfr, String src) {
|
||||
return String_.new_u8(Escape(amp_mgr, tmp_bfr, Bry_.new_u8(src)));
|
||||
}
|
||||
public static byte[] Escape(Xop_amp_mgr amp_mgr, Bry_bfr tmp_bfr, byte[] src) {
|
||||
Escape(amp_mgr, tmp_bfr, src, 0, src.length, true, false);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public static void Escape(Xop_amp_mgr amp_mgr, Bry_bfr bfr, byte[] src, int bgn, int end, boolean interpret_amp, boolean nowiki_skip) {
|
||||
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie();
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt:
|
||||
if (nowiki_skip) {
|
||||
byte[] nowiki_name = Xop_xnde_tag_.Tag__nowiki.Name_bry();
|
||||
int nowiki_name_len = nowiki_name.length;
|
||||
if (Bry_.Eq(src, i + 1, i + 1 + nowiki_name_len, nowiki_name)) { // <nowiki found;
|
||||
int end_gt = Escape_nowiki_skip(bfr, src, i, end, nowiki_name, nowiki_name_len);
|
||||
if (end_gt != Bry_find_.Not_found) {
|
||||
i = end_gt;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
bfr.Add(Gfh_entity_.Lt_bry);
|
||||
break;
|
||||
case Byte_ascii.Gt:
|
||||
bfr.Add(Gfh_entity_.Gt_bry);
|
||||
break;
|
||||
case Byte_ascii.Amp:
|
||||
if (interpret_amp) {
|
||||
int text_bgn = i + 1; // i is &; i + 1 is first char after amp
|
||||
Object o = (text_bgn < end) ? amp_trie.Match_at(trv, src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
|
||||
if (o == null) // invalid; EX: "a&b"; "&bad;"; "&#letters;";
|
||||
bfr.Add(Gfh_entity_.Amp_bry); // escape & and continue
|
||||
else { // is either (1) a name or (2) an ncr (hex/dec)
|
||||
Gfh_entity_itm itm = (Gfh_entity_itm)o;
|
||||
int match_pos = trv.Pos();
|
||||
int itm_tid = itm.Tid();
|
||||
switch (itm_tid) {
|
||||
case Gfh_entity_itm.Tid_name_std:
|
||||
case Gfh_entity_itm.Tid_name_xowa: // name
|
||||
bfr.Add_mid(src, i, match_pos); // embed entire name
|
||||
i = match_pos - 1;
|
||||
break;
|
||||
case Gfh_entity_itm.Tid_num_dec:
|
||||
case Gfh_entity_itm.Tid_num_hex: // ncr: dec/hex; escape if invalid
|
||||
Xop_amp_mgr_rslt rslt = new Xop_amp_mgr_rslt();
|
||||
boolean pass = amp_mgr.Parse_ncr(rslt, itm_tid == Gfh_entity_itm.Tid_num_hex, src, end, i, match_pos);
|
||||
if (pass) { // parse worked; embed entire ncr; EX: "{"
|
||||
int end_pos = rslt.Pos();
|
||||
bfr.Add_mid(src, i, end_pos);
|
||||
i = end_pos - 1;
|
||||
}
|
||||
else // parse failed; escape and continue; EX: "&#a!b;"
|
||||
bfr.Add(Gfh_entity_.Amp_bry);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm_tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bfr.Add(Gfh_entity_.Amp_bry);
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
bfr.Add(Gfh_entity_.Quote_bry);
|
||||
break;
|
||||
default:
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static int Escape_nowiki_skip(Bry_bfr bfr, byte[] src, int bgn, int end, byte[] nowiki_name, int nowiki_name_len) {
|
||||
try {
|
||||
boolean tag_is_bgn = true;
|
||||
int bgn_gt = -1, end_lt = -1, end_gt = -1;
|
||||
for (int i = bgn + nowiki_name_len; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Gt:
|
||||
if (tag_is_bgn) {bgn_gt = i; tag_is_bgn = false;}
|
||||
else return Bry_find_.Not_found; // <nowiki>> found
|
||||
break;
|
||||
case Byte_ascii.Lt:
|
||||
if ( tag_is_bgn // <nowiki < found
|
||||
|| (i + nowiki_name_len + 2 > end) // not enough chars for "/nowiki>"
|
||||
|| src[i + 1] != Byte_ascii.Slash // /
|
||||
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|
||||
|| src[i + 2 + nowiki_name_len] != Byte_ascii.Gt // >
|
||||
) return Bry_find_.Not_found;
|
||||
end_lt = i;
|
||||
end_gt = i + 2 + nowiki_name_len;
|
||||
i = end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end_gt == -1) return Bry_find_.Not_found; // ">" of </nowiki> not found
|
||||
bfr.Add_mid(src, bgn_gt + 1, end_lt);
|
||||
return end_gt;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "unknown error in escape.nowiki: ~{0} ~{1}", String_.new_u8(src, bgn, end), Err_.Message_gplx_full(e));
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,336 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_html_wtr_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
|
||||
@Test public void Hr_basic() {fxt.Test_parse_page_wiki_str("----" , "<hr/>");}
|
||||
@Test public void Hr_extended() {fxt.Test_parse_page_wiki_str("--------" , "<hr/>");}
|
||||
@Test public void Lnki_basic() {fxt.Test_parse_page_wiki_str("[[a]]" , "<a href=\"/wiki/A\">a</a>");}
|
||||
@Test public void Lnki_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]" , "<a href=\"/wiki/A\">b</a>");}
|
||||
@Test public void Lnki_caption_fmt() {fxt.Test_parse_page_wiki_str("[[a|''b'']]" , "<a href=\"/wiki/A\"><i>b</i></a>");}
|
||||
@Test public void Lnki_tail_trg() {fxt.Test_parse_page_wiki_str("[[a]]b" , "<a href=\"/wiki/A\">ab</a>");}
|
||||
@Test public void Lnki_tail_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]c" , "<a href=\"/wiki/A\">bc</a>");}
|
||||
@Test public void Lnki_title() {
|
||||
fxt.Wtr_cfg().Lnki__title_(true);
|
||||
fxt.Test_parse_page_wiki_str("[[a|b]]", "<a href=\"/wiki/A\" title=\"A\">b</a>");
|
||||
fxt.Wtr_cfg().Lnki__title_(false);
|
||||
}
|
||||
@Test public void Lnki_title_page_text() {
|
||||
fxt.Wtr_cfg().Lnki__title_(true);
|
||||
fxt.Test_parse_page_wiki_str("[[a_b]]", "<a href=\"/wiki/A_b\" title=\"A b\">a_b</a>");
|
||||
fxt.Wtr_cfg().Lnki__title_(false);
|
||||
}
|
||||
@Test public void Lnki_category() {fxt.Test_parse_page_wiki_str("[[Category:A]]" , "");} // NOTE: Category does not get written in main page bfr
|
||||
@Test public void Lnki_category_force() {fxt.Test_parse_page_wiki_str("[[:Category:A]]" , "<a href=\"/wiki/Category:A\">Category:A</a>");}
|
||||
@Test public void Lnki_matches_page() {fxt.Test_parse_page_wiki_str("[[test page|t1]]", "<b>t1</b>");} // NOTE: "Test page" is hardcoded to be the test page name
|
||||
@Test public void Lnki_matches_page_but_has_anchor() {fxt.Test_parse_page_wiki_str("[[Test page#a|test 1]]", "<a href=\"/wiki/Test_page#a\">test 1</a>");} // NOTE: "Test page" is hardcoded to be the test page name
|
||||
@Test public void Lnki_anchor() {fxt.Test_parse_page_wiki_str("[[A#b]]" , "<a href=\"/wiki/A#b\">A#b</a>");}
|
||||
// @Test public void Img_invalid_wnt_char() {
|
||||
// fxt.Test_parse_page_wiki_str
|
||||
// ( "[[File:A*b.png]]"
|
||||
// , "<div class=\"floatnone\"><a href=\"File:A.png\" class=\"image\"><img alt=\"\" src=\"\" width=\"20\" height=\"30\" /></a></div>"
|
||||
// );
|
||||
// }
|
||||
// @Test public void Img_alt() { // FUTURE: enable; WHEN: after fixing xnde to handle bad xnde; EX: France
|
||||
// fxt.Test_parse_page_wiki_str("[[File:A.png|none|9x8px|alt=a<b>b</b>\"c\"d]]", Xop_fxt.html_img_none("File:A.png", "ab"c"d"));
|
||||
// }
|
||||
@Test public void Url_encode() {fxt.Test_parse_page_wiki_str("[[a;@$!*(),/ _^b|z]]" , "<a href=\"/wiki/A;@$!*(),/_%5Eb\">z</a>");} // NOTE: was "a" instead of "A"; "__" instead of "_" DATE:2014-09-07
|
||||
@Test public void Url_encode_space() {fxt.Test_parse_page_wiki_str("[[a _b|z]]" , "<a href=\"/wiki/A_b\">z</a>");}
|
||||
@Test public void Apos_i() {fxt.Test_parse_page_wiki_str("''a''" , "<i>a</i>");}
|
||||
@Test public void Apos_b() {fxt.Test_parse_page_wiki_str("'''a'''" , "<b>a</b>");}
|
||||
@Test public void Apos_ib() {fxt.Test_parse_page_wiki_str("'''''a'''''" , "<i><b>a</b></i>");}
|
||||
@Test public void Html_ent() {fxt.Test_parse_page_wiki_str("!" , "!");} // PURPOSE:ncrs should be literal, not decoded (!); DATE:2014-11-06
|
||||
@Test public void Html_ref() {fxt.Test_parse_page_wiki_str(">" , ">");}
|
||||
@Test public void List_1_itm() {
|
||||
fxt.Test_parse_page_wiki_str("*a", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_2_itms() {
|
||||
fxt.Test_parse_page_wiki_str("*a\n*b", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_nest_ul() {
|
||||
fxt.Test_parse_page_wiki_str("*a\n**b", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " <ul>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_dt_dd() {
|
||||
fxt.Test_parse_page_wiki_str(";a:b", String_.Concat_lines_nl_skip_last
|
||||
( "<dl>"
|
||||
, " <dt>a"
|
||||
, " </dt>"
|
||||
, " <dd>b"
|
||||
, " </dd>"
|
||||
, "</dl>"
|
||||
));
|
||||
}
|
||||
@Test public void List_dd_nest2() {
|
||||
fxt.Test_parse_page_wiki_str("::a", String_.Concat_lines_nl_skip_last
|
||||
( "<dl>"
|
||||
, " <dd>"
|
||||
, " <dl>"
|
||||
, " <dd>a"
|
||||
, " </dd>"
|
||||
, " </dl>"
|
||||
, " </dd>"
|
||||
, "</dl>"
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_basic() {
|
||||
fxt.Test_parse_page_wiki_str("{|\n|+a\n!b||c\n|-\n|d||e\n|}", String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <caption>a"
|
||||
, " </caption>"
|
||||
, " <tr>"
|
||||
, " <th>b"
|
||||
, " </th>"
|
||||
, " <th>c"
|
||||
, " </th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>d"
|
||||
, " </td>"
|
||||
, " <td>e"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_atrs() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "{|style='z'"
|
||||
, "|+a"
|
||||
, "!style='y'|b||style='x'|c"
|
||||
, "|-style='w'"
|
||||
, "|style='v'|d||style='u'|e"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl
|
||||
( "<table style='z'>"
|
||||
, " <caption>a"
|
||||
, " </caption>"
|
||||
, " <tr>"
|
||||
, " <th style='y'>b"
|
||||
, " </th>"
|
||||
, " <th style='x'>c"
|
||||
, " </th>"
|
||||
, " </tr>"
|
||||
, " <tr style='w'>"
|
||||
, " <td style='v'>d"
|
||||
, " </td>"
|
||||
, " <td style='u'>e"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Para_hdr_list() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, ""
|
||||
, "*b"
|
||||
, "*c"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>a</h2>"
|
||||
, ""
|
||||
, "<ul>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " <li>c"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Para_nl_is_space() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "b"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "b"
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Para_nl_2_2() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, ""
|
||||
, "b"
|
||||
, ""
|
||||
, "c"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p>b"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p>c"
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Div_2() { // WP:[[Air]]#Density of air
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<div>a</div>"
|
||||
, ""
|
||||
, "<div>b</div>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div>a</div>"
|
||||
, "<div>b</div>"
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Tblw() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|b"
|
||||
, "|-"
|
||||
, "|c"
|
||||
, "|d"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " <td>b"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>c"
|
||||
, " </td>"
|
||||
, " <td>d"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_lnki_bang() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|[[a|!]]"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td><a href=\"/wiki/A\">!</a>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tr_inside_tblw_td() { // WP:[[Earth]]
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "<tr><td>a</td></tr>"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_tr_with_newlines() {// WP:[[John Adams]] Infobox Officeholder
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, ""
|
||||
, ""
|
||||
, ""
|
||||
, "|a"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Bang_doesnt_force_tbl() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str("a! b! c", "<p>a! b! c\n</p>\n");
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Err_nlOnly() {
|
||||
fxt.Test_parse_page_wiki_str("{{\n}}", "{{\n}}"); // NOTE: was {{}}
|
||||
}
|
||||
@Test public void Xnde_inline() {
|
||||
fxt.Test_parse_page_wiki_str("<div/>", "<div></div>");
|
||||
}
|
||||
@Test public void Xnde_id_encode() { // PURPOSE: id should be url-encoded; DATE: 2013-11-13;
|
||||
fxt.Test_parse_page_wiki_str("<div id='a*'></div>", "<div id='a.2A'></div>");
|
||||
fxt.Test_parse_page_wiki_str("<div id='a b'></div>", "<div id='a_b'></div>");
|
||||
}
|
||||
@Test public void Timeline() {// PURPOSE: embed timeline contents in pre; DATE:2014-05-22
|
||||
fxt.Test_parse_page_wiki_str("<timeline>a</timeline>", "<pre class='xowa-timeline'>a</pre>");
|
||||
}
|
||||
@Test public void Amp_ncr_should_not_be_rendered_as_bytes() { // PURPOSE:   should be rendered as   not as literal bytes {192,160}; DATE:2013-12-09
|
||||
fxt.Test_parse_page_wiki_str("a b", "a b");
|
||||
}
|
||||
|
||||
// @Test public void Fix_PositionAbsolute_stripped() {
|
||||
// fxt.Test_parse_page_wiki_str("<span style=\"position:absolute;\"></span>", "<span style=\";\"></span>");
|
||||
// }
|
||||
// @Test public void Xnde_nl() {
|
||||
// fxt.Test_parse_page_wiki_str("<div id='a'\nclass='b'>c</div>", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div id='a' class='b'>c</div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Tblw() {
|
||||
// fxt.Test_parse_page_wiki_str("{|\n|}", String_.Concat_lines_nl
|
||||
// ( "<table>"
|
||||
// , " <tr>"
|
||||
// , " <td>a"
|
||||
// , " </td>"
|
||||
// , " <td>b"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -13,3 +13,29 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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(int mode, byte[] anch__href__bgn, byte[] anch__href__end) {
|
||||
this.mode = mode; this.anch__href__bgn = anch__href__bgn; this.anch__href__end = anch__href__end;
|
||||
}
|
||||
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 byte[] Anch__href__bgn() {return anch__href__bgn;} private final byte[] anch__href__bgn;
|
||||
public byte[] Anch__href__end() {return anch__href__end;} private final byte[] anch__href__end;
|
||||
|
||||
public static final int Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4, Mode_file_dump = 5;
|
||||
|
||||
public static final Xoh_wtr_ctx
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Display_title = new Xoh_wtr_ctx(Mode_display_title , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Popup = new Xoh_wtr_ctx(Mode_popup , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
, Hdump = new Xoh_wtr_ctx(Mode_hdump , gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, null)
|
||||
;
|
||||
public static Xoh_wtr_ctx File_dump(byte[] anch__href__bgn, byte[] anch__href__end) {
|
||||
return new Xoh_wtr_ctx(Mode_file_dump, anch__href__bgn, anch__href__end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,78 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_tidy_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_tidy_mgr_fxt fxt = new Xoh_tidy_mgr_fxt();
|
||||
@Test public void Wrap() {
|
||||
fxt.Test_wrap("<b>a</b>"
|
||||
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+ "<html>"
|
||||
+ "<head>"
|
||||
+ "<title>test</title>"
|
||||
+ "</head>"
|
||||
+ "<body><b>a</b>"
|
||||
+ "</body>"
|
||||
+ "</html>"
|
||||
);
|
||||
}
|
||||
@Test public void Unwrap_pass() {
|
||||
fxt.Test_unwrap
|
||||
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+ "<html>"
|
||||
+ "<head>"
|
||||
+ "<title>test</title>"
|
||||
+ "</head>"
|
||||
+ "<body><b>a</b>"
|
||||
+ "</body>"
|
||||
+ "</html>"
|
||||
, Bool_.Y, "<b>a</b>"
|
||||
);
|
||||
}
|
||||
@Test public void Unwrap_fail_bgn() {
|
||||
fxt.Test_unwrap
|
||||
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+ "<html>"
|
||||
+ "<head>"
|
||||
+ "<title>test</title>"
|
||||
+ "</head>"
|
||||
+ "<bodyx><b>a</b>"
|
||||
+ "</body>"
|
||||
+ "</html>"
|
||||
, Bool_.N, ""
|
||||
);
|
||||
}
|
||||
@Test public void Unwrap_fail_end() {
|
||||
fxt.Test_unwrap
|
||||
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+ "<html>"
|
||||
+ "<head>"
|
||||
+ "<title>test</title>"
|
||||
+ "</head>"
|
||||
+ "<body><b>a</b>"
|
||||
+ "</bodyx>"
|
||||
+ "</html>"
|
||||
, Bool_.N, ""
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoh_tidy_mgr_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
public void Clear() {
|
||||
bfr.Clear();
|
||||
}
|
||||
public void Test_wrap(String val, String expd) {
|
||||
bfr.Add_str_u8(val);
|
||||
Xow_tidy_mgr.Tidy_wrap(bfr);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test_unwrap(String val, boolean expd_pass, String expd) {
|
||||
bfr.Add_str_u8(val);
|
||||
boolean actl_pass = Xow_tidy_mgr.Tidy_unwrap(bfr);
|
||||
if (actl_pass != expd_pass) Tfds.Fail("expd={0} actl={1}", expd_pass, actl_pass);
|
||||
else if (expd_pass) {
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Init_by_app(Xoae_app app);
|
||||
void Exec_tidy(Bry_bfr bfr, byte[] page_url);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 class Xoh_tidy_wkr_ {
|
||||
public static final byte Tid_null = 0, Tid_tidy = 1, Tid_jtidy = 2;
|
||||
public static final Xoh_tidy_wkr Wkr_null = new Xoh_tidy_wkr_null();
|
||||
}
|
||||
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 Init_by_app(Xoae_app app) {}
|
||||
public void Exec_tidy(Bry_bfr bfr, byte[] page_url) {}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,70 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.w3c.tidy.Configuration;
|
||||
import org.w3c.tidy.Tidy;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.envs.*;
|
||||
class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
private Tidy tidy;
|
||||
private ByteArrayOutputStream wtr;
|
||||
public void tidy_init() {
|
||||
long bgn = System_.Ticks();
|
||||
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
|
||||
tidy.setDocType("\"\""); // --doctype \"\"; set to empty else some wikis will show paragraph text with little vertical gap; PAGE:tr.b:
|
||||
tidy.setForceOutput(true); // --force-output y
|
||||
tidy.setQuiet(true); // --quiet y
|
||||
tidy.setTidyMark(false); // --tidy-mark n
|
||||
tidy.setWraplen(0); // --wrap 0
|
||||
tidy.setIndentContent(true); // --indent y; NOTE: true indents all content in edit box
|
||||
tidy.setQuoteNbsp(true); // --quote-nbsp y
|
||||
tidy.setLiteralAttribs(true); // --literal-attributes y
|
||||
tidy.setWrapAttVals(false); // --wrap-attributes n
|
||||
tidy.setFixUri(false); // --fix-url n
|
||||
tidy.setFixBackslash(false); // --fix-backslash n
|
||||
tidy.setEncloseBlockText(true); // --enclose-block-text y; NOTE: true creates extra <p>; very noticeable in sidebar
|
||||
tidy.setNumEntities(false); // NOTE: true will convert all UTF-8 chars to &#val; which ruins readability
|
||||
tidy.setTrimEmptyElements(true); // NOTE: tidy always trims (not even an option)
|
||||
tidy.setShowWarnings(false); // NOTE: otherwise warnings printed to output window
|
||||
tidy.setShowErrors(0); // NOTE: otherwise errors printed to output window; EX: Error: <time> is not recognized!
|
||||
app.Usr_dlg().Log_many("", "", "jtidy.init; elapsed=~{0}", System_.Ticks__elapsed_in_frac(bgn));
|
||||
}
|
||||
private Xoae_app app;
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_jtidy;}
|
||||
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(Bry_bfr bfr, byte[] page_url) {
|
||||
if (tidy == null) tidy_init(); // lazy create to skip tests
|
||||
// int bfr_len = bfr.Len();
|
||||
// long bgn = Env_.TickCount();
|
||||
byte[] orig = bfr.To_bry_and_clear();
|
||||
ByteArrayInputStream rdr = new ByteArrayInputStream(orig);
|
||||
try {
|
||||
tidy.parse(rdr, wtr);
|
||||
bfr.Add(wtr.toByteArray());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
bfr.Add(orig); // jtidy failed; restore original
|
||||
app.Usr_dlg().Warn_many("", "", "jtidy.fail; page=~{0} exc=~{1}", page_url, Err_.Message_gplx_full(exc));
|
||||
}
|
||||
finally {
|
||||
wtr.reset();
|
||||
try {rdr.close();}
|
||||
catch (Exception exc) {System.out.println("jtidy close failed");}
|
||||
}
|
||||
// app.Usr_dlg().Log_many("", "", "jtidy.exec; elapsed=~{0} len=~{1}", Env_.TickCount_elapsed_in_frac(bgn), bfr_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,51 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import gplx.core.envs.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import org.w3c.tidy.Tidy;
|
||||
import org.junit.*;
|
||||
public class Xoh_tidy_wkr_jtidy_tst {
|
||||
@Before public void init() {fxt.Clear();} private Jtidy_fxt fxt = new Jtidy_fxt();
|
||||
@Test public void Image_full() {
|
||||
String nl = Op_sys.Cur().Tid_is_wnt() ? "\r\n" : "\n"; // NOTE: JTidy uses different line-endings based on OS; DATE:2015-05-11
|
||||
fxt.Test_tidy("<a href='http://𐎍𐎁_𐎜'>𐎍𐎁_𐎜</a>", "<a href='http://%F0%90%8E%8D%F0%90%8E%81_%F0%90%8E%9C'>𐎍𐎁_𐎜</a>" + nl);
|
||||
}
|
||||
}
|
||||
class Jtidy_fxt {
|
||||
public void Clear() {
|
||||
}
|
||||
public void Test_tidy(String raw, String expd) {
|
||||
Tidy tidy = new Tidy();
|
||||
tidy.setPrintBodyOnly(true);
|
||||
tidy.setWraplen(0);
|
||||
tidy.setQuiet(true);
|
||||
tidy.setShowWarnings(false);
|
||||
tidy.setShowErrors(0);
|
||||
ByteArrayInputStream rdr = null;
|
||||
try {
|
||||
rdr = new ByteArrayInputStream(raw.getBytes("UTF-8"));
|
||||
} catch (Exception e) {}
|
||||
ByteArrayOutputStream wtr = new ByteArrayOutputStream();
|
||||
tidy.parse(rdr, wtr);
|
||||
String actl = wtr.toString();
|
||||
Test_mgr.Eq_str(expd, actl);
|
||||
}
|
||||
}
|
||||
class Test_mgr {
|
||||
public static void Eq_str(String expd, String actl) {
|
||||
// byte[] expd_bry = Bry_.new_u8(expd);
|
||||
// byte[] actl_bry = Bry_.new_u8(actl);
|
||||
// int expd_len = expd_bry.length;
|
||||
// int actl_len = actl_bry.length;
|
||||
// if (expd_len != actl_len) throw new RuntimeException(String.format("expd != actl; expd:%s actl:%s", Int_.To_str(expd_len), Int_.To_str(actl_len)));
|
||||
// for (int i = 0; i < expd_len; ++i) {
|
||||
// byte expd_byte = expd_bry[i];
|
||||
// byte actl_byte = actl_bry[i];
|
||||
// if (expd_byte != actl_byte) throw new RuntimeException(String.format("expd != actl; %s expd:%s actl:%s", Int_.To_str(i), Byte_.To_str(expd_byte), Byte_.To_str(actl_byte)));
|
||||
// }
|
||||
if (!expd.equals(actl)) throw new RuntimeException(String.format("expd != actl; expd:%s actl:%s", expd, actl));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,47 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import gplx.core.envs.*;
|
||||
public class Xoh_tidy_wkr_tidy extends Process_adp implements Xoh_tidy_wkr { private Xoae_app app; private Io_url tidy_source, tidy_target;
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_tidy;}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
@Override public Process_adp Tmp_dir_(Io_url v) {
|
||||
tidy_source = v.GenSubFil("tidy_source.html");
|
||||
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(Bry_bfr bfr, byte[] page_url) {
|
||||
int bfr_len = bfr.Len();
|
||||
long bgn = System_.Ticks();
|
||||
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
|
||||
Io_mgr.Instance.LoadFilBryByBfr(tidy_target, bfr); // loads bfr by target
|
||||
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}", System_.Ticks__elapsed_in_frac(bgn), bfr_len);
|
||||
}
|
||||
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 ", 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?)
|
||||
, " --fix-uri n" // do not escape invalid chars in uris
|
||||
, " --fix-backslash n" // do not change \ to / in URLs
|
||||
, " --enclose-block-text y" // always enclose text in element with <p>
|
||||
// , " --show-body-only y" // prevent tidy from surrounding input with <html><body> // removed; strips <style> tags in body, and places them in <head> which is not outputted; DATE:2014-03-09
|
||||
// , " --output-xhtml y" // output as xhtml (p's and li's will have closing tags) // removed; creates unsightly <!--CDATA fragments in head; DATE:2014-03-09
|
||||
, " -o \"~{target}\"" // target file
|
||||
, " \"~{source}\"" // source file
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,69 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xow_tidy_mgr implements Gfo_invk, Xow_tidy_mgr_interface {
|
||||
private Xoae_app app;
|
||||
private final Xoh_tidy_wkr_tidy wkr__tidy = new Xoh_tidy_wkr_tidy(); // NOTE: app-level; not thread-safe; needed b/c of Options and exe/args DATE:2016-07-12
|
||||
private final Xoh_tidy_wkr_jtidy wkr__jtidy = new Xoh_tidy_wkr_jtidy();
|
||||
private Xoh_tidy_wkr wkr = Xoh_tidy_wkr_.Wkr_null; // TEST: set default wkr to null
|
||||
private boolean enabled = true;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
this.app = wiki.Appe();
|
||||
Process_adp.ini_(this, app.Usr_dlg(), wkr__tidy, app.Url_cmd_eval(), Process_adp.Run_mode_sync_timeout, 1 * 60, "~{<>bin_plat_dir<>}tidy" + Op_sys.Cur().Fsys_dir_spr_str() + "tidy", Xoh_tidy_wkr_tidy.Args_fmt, "source", "target");
|
||||
app.Cfg().Bind_many_app(this, Cfg__enabled, Cfg__engine, Cfg__cmd);
|
||||
}
|
||||
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {
|
||||
if (!enabled) return;
|
||||
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(bfr, page_url);
|
||||
Tidy_unwrap(bfr);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Cfg__enabled)) this.enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Cfg__cmd)) gplx.xowa.apps.progs.Xoa_prog_mgr.Init_cmd(m.ReadStr("v"), wkr__tidy);
|
||||
else if (ctx.Match(k, Cfg__engine)) {
|
||||
String engine_str = m.ReadStr("v");
|
||||
if (String_.Eq(engine_str, "tidy")) wkr = wkr__tidy; // NOTE: app-level; not thread-safe; needed b/c of Options and exe/args DATE:2016-07-12
|
||||
else if (String_.Eq(engine_str, "jtidy")) wkr = wkr__jtidy;
|
||||
else throw Err_.new_unhandled_default(engine_str);
|
||||
wkr.Init_by_app(app);
|
||||
}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static void Tidy_wrap(Bry_bfr bfr) {
|
||||
bfr.Insert_at(0, Wrap_bgn);
|
||||
bfr.Add(Wrap_end);
|
||||
}
|
||||
public static boolean Tidy_unwrap(Bry_bfr bfr) {
|
||||
byte[] bfr_bry = bfr.Bfr();
|
||||
int find = Bry_find_.Find_fwd(bfr_bry, Gfh_tag_.Body_lhs); if (find == Bry_find_.Not_found) return false;
|
||||
bfr.Delete_rng_to_bgn(find + Gfh_tag_.Body_lhs.length);
|
||||
find = Bry_find_.Find_bwd(bfr_bry, Gfh_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
|
||||
bfr.Delete_rng_to_end(find);
|
||||
return true;
|
||||
}
|
||||
private static final byte[] // MW:includes/parser/Tidy.php|getWrapped
|
||||
Wrap_bgn = Bry_.new_a7
|
||||
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+ "<html>"
|
||||
+ "<head>"
|
||||
+ "<title>test</title>"
|
||||
+ "</head>"
|
||||
+ "<body>"
|
||||
)
|
||||
, Wrap_end = Bry_.new_a7
|
||||
( "</body>"
|
||||
+ "</html>"
|
||||
);
|
||||
private static final String
|
||||
Cfg__enabled = "xowa.html.tidy.enabled"
|
||||
, Cfg__engine = "xowa.html.tidy.engine"
|
||||
, Cfg__cmd = "xowa.html.tidy.cmd"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,7 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Xow_tidy_mgr_interface {
|
||||
void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 class Xow_tidy_mgr_interface_ {
|
||||
public static final Xow_tidy_mgr_interface Noop = new Xow_tidy_mgr_interface__noop();
|
||||
}
|
||||
class Xow_tidy_mgr_interface__noop implements Xow_tidy_mgr_interface {
|
||||
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
public class Xoh_anchor_kv_bldr {
|
||||
private byte[] base_url; private boolean has_qarg;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(16), apos_bfr = Bry_bfr_.New_w_size(16);
|
||||
public Xoh_anchor_kv_bldr Init_w_qarg(byte[] base_url) {return Init(Bool_.Y, base_url);}
|
||||
public Xoh_anchor_kv_bldr Init(boolean has_qarg, byte[] base_url) {
|
||||
this.has_qarg = has_qarg; this.base_url = base_url;
|
||||
tmp_bfr.Clear();
|
||||
tmp_bfr.Add(base_url);
|
||||
return this;
|
||||
}
|
||||
public Xoh_anchor_kv_bldr Add_int(byte[] key, int val) {
|
||||
tmp_bfr.Add_byte(has_qarg ? Byte_ascii.Amp : Byte_ascii.Question);
|
||||
tmp_bfr.Add(key);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Eq);
|
||||
tmp_bfr.Add_int_variable(val);
|
||||
return this;
|
||||
}
|
||||
public Xoh_anchor_kv_bldr Add_bry(byte[] key, byte[] bry) {
|
||||
tmp_bfr.Add_byte(has_qarg ? Byte_ascii.Amp : Byte_ascii.Question);
|
||||
tmp_bfr.Add(key);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Eq);
|
||||
tmp_bfr.Add(Gfh_utl.Escape_for_atr_val_as_bry(apos_bfr, Byte_ascii.Apos, bry));
|
||||
return this;
|
||||
}
|
||||
public byte[] Bld_to_bry() {
|
||||
byte[] rv = tmp_bfr.To_bry_and_clear();
|
||||
tmp_bfr.Add(base_url);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
public class Xoh_img_path {
|
||||
public static final byte[]
|
||||
Img_cancel = Bry_.new_a7("app.general/cancel.png") // 32,32
|
||||
, Img_go_bwd = Bry_.new_a7("app.general/go_bwd.png")
|
||||
, Img_go_fwd = Bry_.new_a7("app.general/go_fwd.png")
|
||||
, Img_search = Bry_.new_a7("app.window/32px/search_exec.png")
|
||||
, Img_option = Bry_.new_a7("app.menu/tools/options.png")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,73 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
public class Xoh_lnki_bldr {
|
||||
private final Xoa_app app; private final Xoh_href_wtr href_wtr; private final byte[] img_root_dir;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
private byte[] href, title, id, caption;
|
||||
private byte[] img_rel_path; private int img_w, img_h; private boolean img_pos_is_left;
|
||||
public Xoh_lnki_bldr(Xoa_app app, Xoh_href_wtr href_wtr) {
|
||||
this.app = app; this.href_wtr = href_wtr;
|
||||
this.img_root_dir = app.Fsys_mgr().Bin_xowa_file_dir().To_http_file_bry();
|
||||
}
|
||||
public Xoh_lnki_bldr Clear() {
|
||||
href = title = id = caption = null;
|
||||
img_rel_path = null; img_w = 0; img_h = 0;
|
||||
img_pos_is_left = true;
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Gfh_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, Xoh_wtr_ctx.Popup, domain_bry, ttl);
|
||||
this.href = tmp_bfr.To_bry_and_clear();
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Href_wo_escape_(byte[] domain_bry, byte[] v) {
|
||||
this.href = Bry_.Add(Xoh_href_.Bry__site, domain_bry, Xoh_href_.Bry__wiki, v);
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Title_(byte[] title) {
|
||||
this.title = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, title);
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Img_pos_is_left_(boolean v) {this.img_pos_is_left = v; return this;}
|
||||
public Xoh_lnki_bldr Img_16x16(byte[] rel_path) {return Img_(rel_path, 16, 16);}
|
||||
private Xoh_lnki_bldr Img_(byte[] rel_path, int w, int h) {
|
||||
this.img_rel_path = rel_path;
|
||||
this.img_w = w;
|
||||
this.img_h = h;
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Caption_(byte[] text) {
|
||||
this.caption = Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
return this;
|
||||
}
|
||||
public Xoh_lnki_bldr Caption_direct_(byte[] v) {this.caption = v; return this;}
|
||||
public byte[] Bld_to_bry() {
|
||||
Bld(tmp_bfr);
|
||||
byte[] rv = tmp_bfr.To_bry_and_clear();
|
||||
this.Clear();
|
||||
return rv;
|
||||
}
|
||||
public void Bld(Bry_bfr bfr) {
|
||||
bfr.Add_str_a7("<a href='").Add(href);
|
||||
if (title != null)
|
||||
bfr.Add_str_a7("' title='").Add(title);
|
||||
if (id != null)
|
||||
bfr.Add_str_a7("' id='").Add(id);
|
||||
bfr.Add_str_a7("'>");
|
||||
if ( img_pos_is_left && img_rel_path != null)
|
||||
Bld_img(bfr);
|
||||
if (caption != null)
|
||||
bfr.Add(caption);
|
||||
if (!img_pos_is_left && img_rel_path != null)
|
||||
Bld_img(bfr);
|
||||
bfr.Add_str_a7("</a>");
|
||||
}
|
||||
private void Bld_img(Bry_bfr bfr) {
|
||||
bfr.Add_str_a7("<img src='").Add(img_root_dir).Add(img_rel_path).Add_str_a7("' width='").Add_int_variable(img_w).Add_str_a7("' height='").Add_int_variable(img_h).Add_str_a7("'/>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,67 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Gfo_decimal_parser {
|
||||
public boolean Sign() {return sign;} private boolean sign;
|
||||
public int Exponent() {return exponent;} private int exponent;
|
||||
public long Number() {return number;} private long number;
|
||||
public boolean Parse(byte[] src, int src_bgn, int src_end) {
|
||||
sign = true;
|
||||
number = 0;
|
||||
exponent = 0;
|
||||
if (src_end - src_bgn < 1) return false;
|
||||
int pos = src_bgn;
|
||||
int dot_offset = 0;
|
||||
byte b = Byte_ascii.Null;
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Dash:
|
||||
if (!sign) return false; // fail if "--"
|
||||
sign = false; // keep looping; handle "-0.12"
|
||||
++dot_offset;
|
||||
break;
|
||||
case Byte_ascii.Num_0:
|
||||
b = src[pos++];
|
||||
if (b != Byte_ascii.Dot) return false; // fail if not "0."
|
||||
++dot_offset;
|
||||
loop = false;
|
||||
break;
|
||||
default:
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int dot_pos = -1;
|
||||
boolean num_seen = false;
|
||||
while (true) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Dot:
|
||||
if (dot_pos != -1) return false; // fail if multiple dots
|
||||
dot_pos = pos - src_bgn - dot_offset - 1; // pos already advanced forward one
|
||||
break;
|
||||
case Byte_ascii.Num_0:
|
||||
if (num_seen)
|
||||
number *= 10;
|
||||
break;
|
||||
case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
if (!num_seen) num_seen = true; // save first "number"; for "0.00001" where num will be 0 and left shift will be 5
|
||||
number *= 10;
|
||||
number += b - Byte_ascii.Num_0;
|
||||
break;
|
||||
}
|
||||
if (pos == src_end) break;
|
||||
b = src[pos];
|
||||
++pos;
|
||||
}
|
||||
switch (dot_pos) {
|
||||
case -1: exponent = 0; break;
|
||||
default: exponent = dot_pos + dot_offset - src_end + 1; break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,32 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 Gfo_decimal_parser_tst {
|
||||
private final Gfo_decimal_parser_fxt fxt = new Gfo_decimal_parser_fxt();
|
||||
@Test public void Positive() {
|
||||
fxt.Test__parse("123" , Bool_.Y, 0, 123);
|
||||
fxt.Test__parse("12.3" , Bool_.Y, -1, 123);
|
||||
fxt.Test__parse("1.23" , Bool_.Y, -2, 123);
|
||||
fxt.Test__parse(".123" , Bool_.Y, -3, 123);
|
||||
fxt.Test__parse("0.123" , Bool_.Y, -3, 123);
|
||||
}
|
||||
@Test public void Negative() {
|
||||
fxt.Test__parse("-123" , Bool_.N, 0, 123);
|
||||
fxt.Test__parse("-12.3" , Bool_.N, -1, 123);
|
||||
fxt.Test__parse("-1.23" , Bool_.N, -2, 123);
|
||||
fxt.Test__parse("-.123" , Bool_.N, -3, 123);
|
||||
fxt.Test__parse("-0.123" , Bool_.N, -3, 123);
|
||||
}
|
||||
}
|
||||
class Gfo_decimal_parser_fxt {
|
||||
private final Gfo_decimal_parser bicoder = new Gfo_decimal_parser();
|
||||
public void Test__parse(String src_str, boolean expd_sign, int expd_exponent, long expd_number) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
bicoder.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_bool(expd_sign, bicoder.Sign());
|
||||
Tfds.Eq_int(expd_exponent, bicoder.Exponent());
|
||||
Tfds.Eq_long(expd_number, bicoder.Number());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*; import gplx.core.threads.poolables.*;
|
||||
public interface Xoh_data_itm extends Gfo_poolable_itm {
|
||||
int Tid();
|
||||
int Src_bgn();
|
||||
int Src_end();
|
||||
void Clear();
|
||||
boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag cur, Gfh_tag nxt);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,32 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_decimal {
|
||||
private final Gfo_decimal_parser decimal_parser = new Gfo_decimal_parser();
|
||||
public boolean Encode(Bry_bfr bfr, byte[] src, int src_bgn, int src_end) {
|
||||
if (!decimal_parser.Parse(src, src_bgn, src_end)) return false;
|
||||
// if (positive && dot_pos == -1 && num_val < 128) {
|
||||
// bfr.Add_byte((byte)(num_val + 128));
|
||||
// }
|
||||
return true;
|
||||
/*
|
||||
0.001000
|
||||
|
||||
1:size_is_1
|
||||
1:exp.neg
|
||||
6:exp.val
|
||||
5:exp.val
|
||||
|
||||
1:num.neg
|
||||
7:num.val; 111-127 for extended bits
|
||||
8:num.val
|
||||
8:num.val
|
||||
127
|
||||
125 2
|
||||
126 3
|
||||
127 4
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,6 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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 {
|
||||
}
|
||||
|
||||
@@ -13,3 +13,43 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.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_by_ints(27); // SERIALIZED
|
||||
public static final int
|
||||
Tid__timeline = -10
|
||||
, Tid__gallery = -11
|
||||
, Tid__root = 0
|
||||
, Tid__escape = 1
|
||||
, Tid__xnde = 2
|
||||
, Tid__lnke = 3
|
||||
, Tid__lnki = 4
|
||||
, Tid__hdr = 5
|
||||
, Tid__img = 6
|
||||
, Tid__thm = 7
|
||||
, Tid__gly = 8
|
||||
, Tid__img_bare = 9
|
||||
, Tid__toc = 10
|
||||
, Tid__pgbnr = 11
|
||||
, Tid__media = 12
|
||||
;
|
||||
public static final String
|
||||
Key__timeline = "timeline"
|
||||
, Key__gallery = "gallery"
|
||||
, Key__escape = "escape"
|
||||
, Key__hdr = "hdr"
|
||||
, Key__lnke = "lnke"
|
||||
, Key__lnki = "lnki"
|
||||
, Key__img = "img"
|
||||
, Key__thm = "thm"
|
||||
, Key__gly = "gly"
|
||||
, Key__xnde = "xnde"
|
||||
, Key__img_bare = "img_bare"
|
||||
, Key__toc = "toc"
|
||||
, Key__pgbnr = "pgbnr"
|
||||
, Key__media = "media"
|
||||
;
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1, Hzip__plain = 2; // SERIALIZED
|
||||
}
|
||||
|
||||
@@ -13,3 +13,134 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
public 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};
|
||||
public 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}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,34 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import org.junit.*; import gplx.core.encoders.*;
|
||||
public class Xoh_hzip_int__tst {
|
||||
private final Xoh_hzip_int__fxt fxt = new Xoh_hzip_int__fxt();
|
||||
@Test public void Reqd__1() {
|
||||
fxt.Test__encode(1, 0, "!");
|
||||
fxt.Test__encode(1, 84, "u");
|
||||
fxt.Test__encode(1, 85, "{\"!");
|
||||
fxt.Test__encode(1, 7225, "|\"!!");
|
||||
fxt.Test__encode(1, 614125, "}\"!!!");
|
||||
fxt.Test__encode(1, 52200625, "~\"!!!!");
|
||||
}
|
||||
@Test public void Reqd__2() {
|
||||
fxt.Test__encode(2, 0, "!!");
|
||||
fxt.Test__encode(2, 84, "!u");
|
||||
fxt.Test__encode(2, 85, "\"!");
|
||||
fxt.Test__encode(2, 7225, "|\"!!");
|
||||
fxt.Test__encode(2, 614125, "}\"!!!");
|
||||
fxt.Test__encode(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.New_neg1();
|
||||
public void Test__encode(int reqd, int val, String expd) {
|
||||
Gfo_hzip_int_.Encode(reqd, bfr, val);
|
||||
byte[] actl = bfr.To_bry_and_clear();
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
Tfds.Eq(val, Gfo_hzip_int_.Decode(reqd, actl, actl.length, 0, count_ref));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,72 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.New_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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,77 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
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);
|
||||
private final Xoh_page_bfr bfr_mgr = new Xoh_page_bfr();
|
||||
public Xoh_hzip_mgr() {this.hdoc_parser = new Xoh_hdoc_parser(hdoc_wkr);}
|
||||
public int Tid() {return Xoh_hzip_dict_.Tid__lnke;}
|
||||
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 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 Encode1(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);
|
||||
hdoc_parser.Parse(bfr, hpg, hctx, src);
|
||||
}
|
||||
public void Decode(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
hctx.Init_by_page(wiki, hpg);
|
||||
rdr.Init_by_page(hpg.Url_bry_safe(), src, src.length);
|
||||
Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, 0, src.length, null);
|
||||
}
|
||||
public void Decode1(Bry_bfr html_bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
|
||||
int pos = src_bgn, txt_bgn = -1;
|
||||
boolean toc_enabled = !gplx.core.envs.Op_sys.Cur().Tid_is_drd() && !hctx.Mode_is_diff();
|
||||
Bry_bfr bfr = html_bfr;
|
||||
if (toc_enabled)
|
||||
bfr_mgr.Init(html_bfr);
|
||||
while (true) {
|
||||
if (pos == src_end) break;
|
||||
byte b = src[pos];
|
||||
Object o = hctx.Pool_mgr__hzip().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;
|
||||
int hook_len = wkr.Hook().length;
|
||||
try {
|
||||
rdr.Init_by_sect(wkr.Key(), pos, pos + hook_len);
|
||||
Xoh_data_itm data = hctx.Pool_mgr__data().Get_by_tid(wkr.Tid());
|
||||
wkr.Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, pos, src_end, data);
|
||||
Xoh_wtr_itm wtr = hctx.Pool_mgr__wtr().Get_by_tid(wkr.Tid());
|
||||
if (data != null && wtr != null) {
|
||||
wtr.Init_by_decode(hpg, hctx, src, data);
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
if (data != null) data.Pool__rls();
|
||||
if (wtr != null) wtr.Pool__rls();
|
||||
if ( data != null
|
||||
&& toc_enabled
|
||||
&& data.Tid() == Xoh_hzip_dict_.Tid__toc) {
|
||||
bfr = bfr_mgr.Split_by_toc(((Xoh_toc_data)data).Toc_mode()); // NOTE: must go after wtr.Init_by_decode else toc_mode flag won't be set correctly
|
||||
}
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
gplx.langs.htmls.Gfh_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
|
||||
pos += hook_len;
|
||||
}
|
||||
finally {wkr.Pool__rls();}
|
||||
}
|
||||
}
|
||||
if (txt_bgn != -1) bfr.Add_mid(src, txt_bgn, src_end);
|
||||
if (toc_enabled) bfr_mgr.Commit(hpg);
|
||||
}
|
||||
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;}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public interface Xoh_hzip_wkr extends gplx.core.threads.poolables.Gfo_poolable_itm {
|
||||
int Tid();
|
||||
String Key();
|
||||
byte[] Hook();
|
||||
Gfo_poolable_itm Encode1(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);
|
||||
void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,40 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.xndes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.addons.timelines.*; import gplx.xowa.htmls.core.wkrs.addons.gallerys.*; import gplx.xowa.htmls.core.wkrs.addons.medias.*;
|
||||
public class Xoh_pool_mgr__data {
|
||||
private final Gfo_poolable_mgr pool__hdr, pool__lnke, pool__img, pool__img_bare, pool__toc, pool__timeline, pool__gallery, pool__media;
|
||||
public Xoh_pool_mgr__data() {
|
||||
pool__hdr = New_pool(new Xoh_hdr_data());
|
||||
pool__lnke = New_pool(new Xoh_lnke_data());
|
||||
pool__img = New_pool(new Xoh_img_data());
|
||||
pool__img_bare = New_pool(new Xoh_img_bare_data());
|
||||
pool__toc = New_pool(new Xoh_toc_data());
|
||||
pool__timeline = New_pool(new Xoh_timeline_data());
|
||||
pool__gallery = New_pool(new Xoh_gallery_data());
|
||||
pool__media = New_pool(new Xoh_media_data());
|
||||
}
|
||||
public Xoh_data_itm Get_by_tid(int tid) {
|
||||
Gfo_poolable_mgr pool = null;
|
||||
switch (tid) {
|
||||
case Xoh_hzip_dict_.Tid__hdr: pool = pool__hdr; break;
|
||||
case Xoh_hzip_dict_.Tid__lnke: pool = pool__lnke; break;
|
||||
case Xoh_hzip_dict_.Tid__img: pool = pool__img; break;
|
||||
case Xoh_hzip_dict_.Tid__img_bare: pool = pool__img_bare; break;
|
||||
case Xoh_hzip_dict_.Tid__toc: pool = pool__toc; break;
|
||||
case Xoh_hzip_dict_.Tid__timeline: pool = pool__timeline; break;
|
||||
case Xoh_hzip_dict_.Tid__gallery: pool = pool__gallery; break;
|
||||
case Xoh_hzip_dict_.Tid__media: pool = pool__media; break;
|
||||
default: return null;
|
||||
}
|
||||
return (Xoh_data_itm)pool.Get_fast();
|
||||
}
|
||||
private static Gfo_poolable_mgr New_pool(Gfo_poolable_itm proto) {
|
||||
return Gfo_poolable_mgr_.New(1, 32, proto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,62 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.xndes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.addons.timelines.*; import gplx.xowa.htmls.core.wkrs.addons.gallerys.*; import gplx.xowa.htmls.core.wkrs.addons.medias.*;
|
||||
public class Xoh_pool_mgr__hzip {
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private Gfo_poolable_mgr mkr__escape, mkr__xnde, mkr__lnke, mkr__lnki, mkr__hdr, mkr__img, mkr__thm, mkr__gly, mkr__img_bare, mkr__gallery, mkr__timeline, mkr__toc, mkr__media;
|
||||
public Xoh_escape_hzip Mw__escape() {return (Xoh_escape_hzip) mkr__escape.Get_fast();}
|
||||
public Xoh_xnde_hzip Mw__xnde() {return (Xoh_xnde_hzip) mkr__xnde.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_img_bare_hzip Mw__img_bare() {return (Xoh_img_bare_hzip) mkr__img_bare.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 Xoh_toc_hzip Mw__toc() {return (Xoh_toc_hzip) mkr__toc.Get_fast();}
|
||||
public Xoh_gallery_hzip Mw__gallery() {return (Xoh_gallery_hzip) mkr__gallery.Get_fast();}
|
||||
public Xoh_timeline_hzip Mw__timeline() {return (Xoh_timeline_hzip) mkr__timeline.Get_fast();}
|
||||
public Xoh_media_hzip Mw__media() {return (Xoh_media_hzip) mkr__media.Get_fast();}
|
||||
public void Init() {
|
||||
this.Reg_all(false, Hook__core, Hook__html, Hook__mw);
|
||||
}
|
||||
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 hook__core, int hook__html, int hook__mw) { // SERIALIZED
|
||||
mkr__escape = Reg(New_hook_len2(mode_is_b256, hook__core, 0) , new Xoh_escape_hzip());
|
||||
mkr__xnde = Reg(New_hook_len1(mode_is_b256, hook__html) , new Xoh_xnde_hzip());
|
||||
mkr__hdr = Reg(New_hook_len2(mode_is_b256, hook__mw , 1) , new Xoh_hdr_hzip());
|
||||
mkr__lnke = Reg(New_hook_len2(mode_is_b256, hook__mw , 2) , new Xoh_lnke_hzip());
|
||||
mkr__lnki = Reg(New_hook_len2(mode_is_b256, hook__mw , 3) , new Xoh_lnki_hzip());
|
||||
mkr__img = Reg(New_hook_len2(mode_is_b256, hook__mw , 4) , new Xoh_img_hzip());
|
||||
mkr__thm = Reg(New_hook_len2(mode_is_b256, hook__mw , 5) , new Xoh_thm_hzip());
|
||||
mkr__gly = Reg(New_hook_len2(mode_is_b256, hook__mw , 6) , new Xoh_gly_hzip());
|
||||
mkr__img_bare = Reg(New_hook_len2(mode_is_b256, hook__mw , 7) , new Xoh_img_bare_hzip());
|
||||
mkr__toc = Reg(New_hook_len2(mode_is_b256, hook__mw , 8) , new Xoh_toc_hzip());
|
||||
mkr__media = Reg(New_hook_len2(mode_is_b256, hook__mw , 9) , new Xoh_media_hzip());
|
||||
mkr__gallery = Reg(Xoh_gallery_data.Hook_bry , new Xoh_gallery_hzip());
|
||||
mkr__timeline = Reg(Xoh_timeline_data.Hook_bry , new Xoh_timeline_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_by_ints(b0, mode_is_b256 ? b1 : b1 + Byte_ascii.Bang);}
|
||||
private static byte[] New_hook_len1(boolean mode_is_b256, int b0) {return Bry_.New_by_ints(b0);}
|
||||
public static final byte
|
||||
Hook__core = 1
|
||||
, Hook__html = 2
|
||||
, Hook__mw = 27
|
||||
;
|
||||
public static final byte[] Hooks_ary = new byte[] {Hook__core, Hook__html, Hook__mw};
|
||||
}
|
||||
|
||||
@@ -13,3 +13,38 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.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.xndes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.addons.timelines.*; import gplx.xowa.htmls.core.wkrs.addons.gallerys.*;
|
||||
public class Xoh_pool_mgr__wtr {
|
||||
private final Gfo_poolable_mgr pool__hdr, pool__lnke, pool__img, pool__img_bare, pool__toc, pool__timeline, pool__gallery;
|
||||
public Xoh_pool_mgr__wtr() {
|
||||
pool__hdr = New_pool(new Xoh_hdr_wtr());
|
||||
pool__lnke = New_pool(new Xoh_lnke_wtr());
|
||||
pool__img = New_pool(new Xoh_img_wtr());
|
||||
pool__img_bare = New_pool(new Xoh_img_bare_wtr());
|
||||
pool__toc = New_pool(new Xoh_toc_wtr());
|
||||
pool__timeline = New_pool(new Xoh_timeline_wtr());
|
||||
pool__gallery = New_pool(new Xoh_gallery_wtr());
|
||||
}
|
||||
public Xoh_wtr_itm Get_by_tid(int tid) {
|
||||
Gfo_poolable_mgr pool = null;
|
||||
switch (tid) {
|
||||
case Xoh_hzip_dict_.Tid__hdr: pool = pool__hdr; break;
|
||||
case Xoh_hzip_dict_.Tid__lnke: pool = pool__lnke; break;
|
||||
case Xoh_hzip_dict_.Tid__img: pool = pool__img; break;
|
||||
case Xoh_hzip_dict_.Tid__img_bare: pool = pool__img_bare; break;
|
||||
case Xoh_hzip_dict_.Tid__toc: pool = pool__toc; break;
|
||||
case Xoh_hzip_dict_.Tid__timeline: pool = pool__timeline; break;
|
||||
case Xoh_hzip_dict_.Tid__gallery: pool = pool__gallery; break;
|
||||
default: return null;
|
||||
}
|
||||
return (Xoh_wtr_itm)pool.Get_fast();
|
||||
}
|
||||
private static Gfo_poolable_mgr New_pool(Gfo_poolable_itm proto) {
|
||||
return Gfo_poolable_mgr_.New(1, 32, proto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,51 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
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 = timeline = gallery = 0;
|
||||
img_full = 0;
|
||||
space = 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;
|
||||
public int Lnki_text_y() {return lnki_text_y;} public void Lnki_text_y_add() {++lnki_text_y;} private int lnki_text_y;
|
||||
public int Lnke__free() {return lnke__free;} public void Lnke__free__add() {++lnke__free;} private int lnke__free;
|
||||
public int Lnke__auto() {return lnke__auto;} public void Lnke__auto__add() {++lnke__auto;} private int lnke__auto;
|
||||
public int Lnke__text() {return lnke__text;} public void Lnke__text__add() {++lnke__text;} private int lnke__text;
|
||||
public int Img_full() {return img_full;} public void Img_full_add() {++img_full;} private int img_full;
|
||||
public int Timeline() {return timeline;} public void Timeline_add() {++timeline;} private int timeline;
|
||||
public int Gallery() {return gallery;} public void Gallery_add() {++gallery;} private int gallery;
|
||||
public int Hdr_1() {return hdr_1;} private int hdr_1;
|
||||
public int Hdr_2() {return hdr_2;} private int hdr_2;
|
||||
public int Hdr_3() {return hdr_3;} private int hdr_3;
|
||||
public int Hdr_4() {return hdr_4;} private int hdr_4;
|
||||
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 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;
|
||||
case 2: ++hdr_2; break;
|
||||
case 3: ++hdr_3; break;
|
||||
case 4: ++hdr_4; break;
|
||||
case 5: ++hdr_5; break;
|
||||
case 6: ++hdr_6; break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,61 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.hzips.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_stat_tbl implements Rls_able {
|
||||
private static final String tbl_name = "hdump_stats"; private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
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")
|
||||
, fld_body_len = flds.Add_int("body_len"), fld_display_ttl_len = flds.Add_int("display_ttl_len"), fld_content_sub_len = flds.Add_int("content_sub_len"), fld_sidebar_div_len = flds.Add_int("sidebar_div_len")
|
||||
, fld_js_math = flds.Add_int("js_math"), fld_js_imap = flds.Add_int("js_imap"), fld_js_packed = flds.Add_int("js_packed"), fld_js_hiero = flds.Add_int("js_hiero")
|
||||
, fld_a_rhs = flds.Add_int("a_rhs"), fld_lnki_text_n = flds.Add_int("lnki_text_n"), fld_lnki_text_y = flds.Add_int("lnki_text_y")
|
||||
, fld_lnke_free = flds.Add_int("lnke_free"), fld_lnke_auto = flds.Add_int("lnke_auto"), fld_lnke_text = flds.Add_int("lnke_text")
|
||||
, fld_hdr_1 = flds.Add_int("hdr_1"), fld_hdr_2 = flds.Add_int("hdr_2"), fld_hdr_3 = flds.Add_int("hdr_3"), fld_hdr_4 = flds.Add_int("hdr_4"), fld_hdr_5 = flds.Add_int("hdr_5"), fld_hdr_6 = flds.Add_int("hdr_6")
|
||||
, fld_img_full = flds.Add_int("img_full")
|
||||
;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Xoh_stat_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.Create_tbl();
|
||||
conn.Stmt_delete(tbl_name).Exec_delete(); // always zap table
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "pkey", fld_page_id)));}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
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()
|
||||
.Val_int(fld_page_id , hpg.Page_id())
|
||||
.Val_int(fld_wtxt_len , wtxt_len)
|
||||
.Val_int(fld_row_orig_len , row_orig_len)
|
||||
.Val_int(fld_row_zip_len , row_zip_len)
|
||||
.Val_int(fld_body_len , Len_or_0(hpg.Db().Html().Html_bry()))
|
||||
.Val_int(fld_display_ttl_len , Len_or_0(hpg.Display_ttl()))
|
||||
.Val_int(fld_content_sub_len , Len_or_0(hpg.Content_sub()))
|
||||
.Val_int(fld_sidebar_div_len , Len_or_0(hpg.Sidebar_div()))
|
||||
.Val_bool_as_byte(fld_js_math , js_mgr.Math_exists())
|
||||
.Val_bool_as_byte(fld_js_imap , js_mgr.Imap_exists())
|
||||
.Val_bool_as_byte(fld_js_packed , js_mgr.Gallery_packed_exists())
|
||||
.Val_bool_as_byte(fld_js_hiero , js_mgr.Hiero_exists())
|
||||
.Val_int(fld_a_rhs , hzip.A_rhs())
|
||||
.Val_int(fld_lnki_text_n , hzip.Lnki_text_n())
|
||||
.Val_int(fld_lnki_text_y , hzip.Lnki_text_y())
|
||||
.Val_int(fld_lnke_free , hzip.Lnke__free())
|
||||
.Val_int(fld_lnke_auto , hzip.Lnke__auto())
|
||||
.Val_int(fld_lnke_text , hzip.Lnke__text())
|
||||
.Val_int(fld_hdr_1 , hzip.Hdr_1())
|
||||
.Val_int(fld_hdr_2 , hzip.Hdr_2())
|
||||
.Val_int(fld_hdr_3 , hzip.Hdr_3())
|
||||
.Val_int(fld_hdr_4 , hzip.Hdr_4())
|
||||
.Val_int(fld_hdr_5 , hzip.Hdr_5())
|
||||
.Val_int(fld_hdr_6 , hzip.Hdr_6())
|
||||
.Val_int(fld_img_full , hzip.Img_full())
|
||||
.Exec_insert();
|
||||
}
|
||||
private int Len_or_0(byte[] bry) {return bry == null ? 0 : bry.length;}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*; import gplx.core.threads.poolables.*;
|
||||
public interface Xoh_wtr_itm extends Bfr_arg, Gfo_poolable_itm {
|
||||
boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_make_mgr {
|
||||
private final Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(255);
|
||||
private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
private final Xoh_hdoc_parser make_parser = new Xoh_hdoc_parser(new Xoh_hdoc_wkr__make());
|
||||
public byte[] Parse(byte[] src, Xoh_page hpg, Xow_wiki wiki) {
|
||||
hctx.Init_by_page(wiki, hpg);
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
make_parser.Parse(bfr, hpg, hctx, src);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,41 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.*;
|
||||
import gplx.xowa.htmls.sections.*;
|
||||
public class Xoh_make_fxt {
|
||||
public Xoh_make_fxt() {
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
parser_fxt.Wiki().Html_mgr().Html_wtr().Cfg().Lnki__id_(Bool_.Y).Lnki__title_(Bool_.Y);
|
||||
}
|
||||
public void Clear() {
|
||||
parser_fxt.Reset();
|
||||
page_chkr.Clear();
|
||||
}
|
||||
public Xoh_page_chkr Page_chkr() {return page_chkr;} private final Xoh_page_chkr page_chkr = new Xoh_page_chkr();
|
||||
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
public void Init_img_cache
|
||||
( String wiki_abrv, String lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page
|
||||
, boolean repo_is_commons, String html_ttl, int html_w, int html_h, double html_time, int html_page
|
||||
) {
|
||||
// fxt.Init_cache("en.wikipedia.org", "A.png", 0, 220, 110, 0.5, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1);
|
||||
}
|
||||
public void Test__html(String wtxt, String expd) {Test__html(wtxt, expd, true);}
|
||||
public void Test__html(String wtxt, String expd, boolean escape_apos) {
|
||||
if (escape_apos) expd = String_.Replace(expd, "'", "\"");
|
||||
String actl = parser_fxt.Exec__parse_to_hdump(wtxt);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public void Test__make(String html, Xoh_page_chkr chkr) {
|
||||
html = String_.Replace(html, "'", "\"");
|
||||
Xoh_page actl = new Xoh_page();
|
||||
actl.Ctor_by_hview(parser_fxt.Wiki(), Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
Xoh_make_mgr make_mgr = parser_fxt.Wiki().Html__hdump_mgr().Load_mgr().Make_mgr();
|
||||
byte[] actl_body = make_mgr.Parse(Bry_.new_u8(html), actl, parser_fxt.Wiki());
|
||||
actl.Db().Html().Html_bry_(actl_body);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
chkr.Check(actl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.*;
|
||||
import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_page_chkr {
|
||||
private final Xoh_section_mgr expd_section_mgr = new Xoh_section_mgr();
|
||||
private final Xoh_img_mgr expd_img_mgr = new Xoh_img_mgr();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Clear() {
|
||||
expd_img_mgr.Clear();
|
||||
}
|
||||
public Xoh_page_chkr Body_(String v) {this.expd_body = String_.Replace(v, "'", "\""); return this;} private String expd_body;
|
||||
public Xoh_page_chkr Sections__add(int uid, int level, String anchor, String display, String content) {
|
||||
expd_section_mgr.Add(uid, level, Bry_.new_u8(anchor), Bry_.new_u8(display)).Content_(Bry_.new_u8(content));
|
||||
return this;
|
||||
}
|
||||
public Xoh_page_chkr Imgs__add(String wiki_abrv, String lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page) {
|
||||
Xof_fsdb_itm fsdb_itm = expd_img_mgr.Make_img(false);
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_u8(wiki_abrv), Bry_.new_u8(lnki_ttl), lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, Xof_patch_upright_tid_.Tid_all);
|
||||
return this;
|
||||
}
|
||||
public void Check(Xoh_page actl) {
|
||||
if (expd_body != null) Tfds.Eq_str_lines(expd_body, String_.new_u8(actl.Db().Html().Html_bry()));
|
||||
if (expd_section_mgr.Len() > 0)
|
||||
Tfds.Eq_str_lines(To_str__section_mgr(expd_section_mgr), To_str__section_mgr(actl.Section_mgr()));
|
||||
if (expd_img_mgr.Len() > 0)
|
||||
Tfds.Eq_str_lines(To_str__img_mgr(expd_img_mgr), To_str__img_mgr(actl.Img_mgr()));
|
||||
}
|
||||
private String To_str__section_mgr(Xoh_section_mgr section_mgr) {
|
||||
section_mgr.To_bfr(bfr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private String To_str__img_mgr(Xoh_img_mgr img_mgr) {
|
||||
img_mgr.To_bfr(bfr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,85 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.xndes.tags.*; import gplx.xowa.htmls.core.wkrs.xndes.dicts.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.caches.*; 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 {
|
||||
private byte[] fsys__file, abrv__commons, abrv__wiki;
|
||||
public byte[] Fsys__res() {return fsys__res;} private byte[] fsys__res;
|
||||
public byte[] Fsys__root() {return fsys__root;} private byte[] fsys__root;
|
||||
public byte[] Fsys__file__comm() {return fsys__file__comm;} private byte[] fsys__file__comm;
|
||||
public byte[] Fsys__file__wiki() {return fsys__file__wiki;} private byte[] fsys__file__wiki;
|
||||
public byte[] Fsys__file__math() {return fsys__file__math;} private byte[] fsys__file__math;
|
||||
public Xof_repo_itm Fsys__repo(boolean local) {return local ? repo_local : repo_remote;} private Xof_repo_itm repo_remote, repo_local;
|
||||
public boolean Fsys__is_wnt() {return fsys__is_wnt;} private boolean fsys__is_wnt;
|
||||
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_domain_itm Wiki__domain_itm() {return wiki__domain_itm;} private Xow_domain_itm wiki__domain_itm;
|
||||
public Xow_ttl_parser Wiki__ttl_parser() {return wiki__ttl_parser;} private Xow_ttl_parser wiki__ttl_parser;
|
||||
public Xow_url_parser Wiki__url_parser() {return wiki__url_parser;} private Xow_url_parser wiki__url_parser;
|
||||
public boolean Xwiki_mgr__missing(byte[] domain){return app.Xwiki_mgr__missing(domain);}
|
||||
public Xou_cache_finder Cache_mgr() {return cache_mgr;} private Xou_cache_finder cache_mgr = Xou_cache_finder_.Noop;
|
||||
public byte[] Cache__wiki_abrv(boolean repo_is_commons) {return repo_is_commons ? abrv__commons : abrv__wiki;}
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private final Xof_url_bldr file__url_bldr = Xof_url_bldr.new_v2();
|
||||
public Xoa_page Page() {return page;} private Xoa_page page;
|
||||
public byte[] Page__url() {return page__url;} private byte[] page__url;
|
||||
public Xoh_pool_mgr__hzip Pool_mgr__hzip() {return pool_mgr__hzip;} private final Xoh_pool_mgr__hzip pool_mgr__hzip = new Xoh_pool_mgr__hzip();
|
||||
public Xoh_pool_mgr__data Pool_mgr__data() {return pool_mgr__data;} private final Xoh_pool_mgr__data pool_mgr__data = new Xoh_pool_mgr__data();
|
||||
public Xoh_pool_mgr__wtr Pool_mgr__wtr() {return pool_mgr__wtr;} private final Xoh_pool_mgr__wtr pool_mgr__wtr = new Xoh_pool_mgr__wtr();
|
||||
public Xoh_stat_itm Hzip__stat() {return hzip__stat;} private final Xoh_stat_itm hzip__stat = new Xoh_stat_itm();
|
||||
public Xohz_tag_regy Hzip__xnde__regy() {return hzip__xnde__regy;} private final Xohz_tag_regy hzip__xnde__regy = Xohz_tag_regy_.New_dflt();
|
||||
public Xoh_xnde_dict_reg Hzip__xnde__dict() {return hzip__xnde__dict;} private final Xoh_xnde_dict_reg hzip__xnde__dict = new Xoh_xnde_dict_reg();
|
||||
public int Uid__gly__nxt() {return ++uid__gly;} private int uid__gly;
|
||||
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);
|
||||
this.fsys__file__math = Bry_.Add(fsys__file, Bry_.new_a7("math"), Byte_ascii.Slash_bry);
|
||||
this.fsys__res = gplx.core.envs.Op_sys.Cur().Tid_is_drd() ? Fsys__res__drd : fsys__root;
|
||||
this.fsys__is_wnt = gplx.core.envs.Op_sys.Cur().Tid_is_wnt();
|
||||
Xou_cache_mgr usr_cache_mgr = app.User().User_db_mgr().Cache_mgr();
|
||||
if (usr_cache_mgr != null && usr_cache_mgr.Enabled()) cache_mgr = Xou_cache_finder_.New_db(usr_cache_mgr); // NOTE: this effectively only loads the cache db in app mode (and not in test mode)
|
||||
this.abrv__commons = Xow_domain_itm_.parse(Xow_domain_itm_.Bry__commons).Abrv_xo();
|
||||
pool_mgr__hzip.Init();
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki, Xoa_page page) {
|
||||
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.wiki__domain_itm = wiki.Domain_itm();
|
||||
|
||||
// init repos
|
||||
Xof_repo_pair[] pairs = wiki.File__repo_mgr().Repos_ary();
|
||||
int pairs_len = pairs.length;
|
||||
for (int i = 0; i < pairs_len; ++i) {
|
||||
Xof_repo_pair pair = pairs[i];
|
||||
Xof_repo_itm itm = pair.Trg();
|
||||
byte[] itm_domain = itm.Wiki_domain();
|
||||
if (Bry_.Eq(itm_domain, wiki__domain_bry))
|
||||
repo_local = itm;
|
||||
else if (Bry_.Eq(itm_domain, Xow_domain_itm_.Bry__commons))
|
||||
repo_remote = pair.Trg();
|
||||
}
|
||||
|
||||
this.abrv__wiki = wiki.Domain_itm().Abrv_xo();
|
||||
this.fsys__file__wiki = Bry_.Add(fsys__file, wiki__domain_bry, Byte_ascii.Slash_bry);
|
||||
this.page = page;
|
||||
this.page__url = page.Url_bry_safe();
|
||||
this.Clear();
|
||||
}
|
||||
private void Clear() {
|
||||
hzip__stat.Clear();
|
||||
this.uid__gly = -1;
|
||||
}
|
||||
|
||||
public void Test__cache__mgr_(Xou_cache_finder v) {this.cache_mgr = v;}
|
||||
public static final int Invalid = -1;
|
||||
private static final byte[] Fsys__res__drd = Bry_.new_a7("file:///android_asset/xowa/");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,28 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.docs.*; 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.hzips.*;
|
||||
public class Xoh_hdoc_parser {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
private final Gfh_doc_parser hdoc_parser;
|
||||
private final Xoh_tag_parser tag_parser;
|
||||
public Xoh_hdoc_parser(Xoh_hdoc_wkr hdoc_wkr) {
|
||||
this.hdoc_wkr = hdoc_wkr;
|
||||
this.tag_parser = new Xoh_tag_parser(hdoc_wkr);
|
||||
int wkr_ary_len = Xoh_pool_mgr__hzip.Hooks_ary.length + 1;
|
||||
Gfh_doc_wkr[] wkr_ary = new Gfh_doc_wkr[wkr_ary_len];
|
||||
wkr_ary[0] = tag_parser;
|
||||
for (int i = 1; i < wkr_ary_len; ++i)
|
||||
wkr_ary[i] = new Xoh_escape_data(hdoc_wkr, Xoh_pool_mgr__hzip.Hooks_ary[i - 1]);
|
||||
this.hdoc_parser = new Gfh_doc_parser(new Xoh_txt_parser(hdoc_wkr), wkr_ary);
|
||||
}
|
||||
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);
|
||||
hdoc_parser.Parse(hctx.Page__url(), src, 0, src_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public interface Xoh_hdoc_wkr {
|
||||
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_txt (int rng_bgn, int rng_end);
|
||||
void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data);
|
||||
void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser parser);
|
||||
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data parser);
|
||||
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data parser);
|
||||
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data parser);
|
||||
boolean Process_parse(Xoh_data_itm data);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
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 (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data) {hctx.Pool_mgr__hzip().Mw__escape().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser data) {hctx.Pool_mgr__hzip().Mw__xnde().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data data) {hctx.Pool_mgr__hzip().Mw__lnki().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {hctx.Pool_mgr__hzip().Mw__thm().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {hctx.Pool_mgr__hzip().Mw__gly().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public boolean Process_parse(Xoh_data_itm data) {
|
||||
Xoh_hzip_wkr wkr = null;
|
||||
switch (data.Tid()) {
|
||||
case Xoh_hzip_dict_.Tid__hdr: wkr = hctx.Pool_mgr__hzip().Mw__hdr(); break;
|
||||
case Xoh_hzip_dict_.Tid__lnke: wkr = hctx.Pool_mgr__hzip().Mw__lnke(); break;
|
||||
case Xoh_hzip_dict_.Tid__img: wkr = hctx.Pool_mgr__hzip().Mw__img(); break;
|
||||
case Xoh_hzip_dict_.Tid__img_bare: wkr = hctx.Pool_mgr__hzip().Mw__img_bare(); break;
|
||||
case Xoh_hzip_dict_.Tid__toc: wkr = hctx.Pool_mgr__hzip().Mw__toc(); break;
|
||||
case Xoh_hzip_dict_.Tid__media: wkr = hctx.Pool_mgr__hzip().Mw__media(); break;
|
||||
default: throw Err_.new_unhandled(data.Tid());
|
||||
}
|
||||
wkr.Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,32 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
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 Xoh_hzip_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private final Xoh_hdr_wtr wkr__hdr = new Xoh_hdr_wtr();
|
||||
private final Xoh_img_wtr wkr__img = new Xoh_img_wtr();
|
||||
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_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data) {bfr.Add(data.Hook());}
|
||||
public void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {}
|
||||
public boolean Process_parse(Xoh_data_itm data) {
|
||||
switch (data.Tid()) {
|
||||
case Xoh_hzip_dict_.Tid__img: wkr__img.Init_by_parse(bfr, hpg, hctx, src, (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_data)data); return true;
|
||||
case Xoh_hzip_dict_.Tid__hdr: wkr__hdr.Init_by_parse(bfr, hpg, hctx, src, (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_data)data); return true;
|
||||
case Xoh_hzip_dict_.Tid__lnke: break;
|
||||
default: throw Err_.new_unhandled(data.Tid());
|
||||
}
|
||||
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,25 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_double(double val) {this.Add_double(val); 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);}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,103 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.*;
|
||||
import gplx.xowa.files.caches.*;
|
||||
public class Xoh_hzip_fxt {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
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() {
|
||||
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.Ctor_by_hview(wiki, Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
}
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoa_page Page() {return hpg;}
|
||||
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 void Init_wiki_installed(String domain) {parser_fxt.Init_xwiki_add_user_(domain);}
|
||||
public Xou_cache_finder_mem Init_file_mgr__mem() {
|
||||
Xou_cache_finder_mem rv = Xou_cache_finder_.New_mem();
|
||||
hzip_mgr.Hctx().Test__cache__mgr_(rv);
|
||||
return rv;
|
||||
}
|
||||
public void Init_file_mgr__noop() {
|
||||
hzip_mgr.Hctx().Test__cache__mgr_(Xou_cache_finder_.Noop);
|
||||
}
|
||||
public Xowe_wiki Init_wiki_alias(String alias, String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(parser_fxt.App(), domain);
|
||||
parser_fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), null);
|
||||
return rv;
|
||||
}
|
||||
public void Init__ns_alias__add(String alias, int ns_id) {
|
||||
parser_fxt.Wiki().Ns_mgr().Aliases_add(ns_id, alias).Init();
|
||||
}
|
||||
public void Init__ns_alias__del(String alias) {
|
||||
parser_fxt.Wiki().Ns_mgr().Aliases_del(alias);
|
||||
}
|
||||
public void Test__bicode(String hzip, String html) {Test__bicode(hzip, html, html);}
|
||||
public void Test__bicode(String hzip, String html_enc, String html_dec) {
|
||||
html_enc = Gfh_utl.Replace_apos(html_enc);
|
||||
html_dec = Gfh_utl.Replace_apos(html_dec);
|
||||
Test__bicode_raw(hzip, html_enc, html_dec);
|
||||
}
|
||||
public void Test__bicode_raw(String hzip, String html_enc, String html_dec) {
|
||||
hzip = Xoh_hzip_fxt.Escape(hzip);
|
||||
Test__encode__raw(hzip, html_enc);
|
||||
Test__decode__raw(hzip, html_dec);
|
||||
}
|
||||
public void Test__encode(String hzip, String html) {
|
||||
hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html);
|
||||
Test__encode__raw(hzip, html);
|
||||
}
|
||||
public void Test__decode(String hzip, String html) {
|
||||
hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html);
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__encode__fail(String expd, String html) {
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html));
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__encode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__decode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hpg.Section_mgr().Clear();
|
||||
hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(hzip));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(html, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Exec_write_to_fsys(Io_url dir, String fil) {
|
||||
try {
|
||||
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();
|
||||
byte[] actl = bfr.To_bry_and_clear();
|
||||
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());
|
||||
} catch (Exception e) {
|
||||
Tfds.Dbg(e);
|
||||
}
|
||||
}
|
||||
public static String Escape(String v) {return String_.Replace(v, "~", "");}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
public interface Xoh_itm_parser {
|
||||
void Fail_throws_err_(boolean v);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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.docs.*;
|
||||
public abstract class Xoh_itm_parser_fxt {
|
||||
protected final Xoae_app app;
|
||||
protected 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.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(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) {
|
||||
Gfo_usr_dlg_.Test__list__init();
|
||||
Parser().Fail_throws_err_(Bool_.N);
|
||||
Exec_parse(src_str);
|
||||
Parser().Fail_throws_err_(Bool_.Y);
|
||||
Tfds.Eq_str(expd, Gfo_usr_dlg_.Test__list__term__get_1st());
|
||||
}
|
||||
public void Exec_parse(String src_str) {
|
||||
this.src = Bry_.new_u8(src_str); this.src_len = src.length;
|
||||
Xoh_page hpg = new Xoh_page(); // NOTE: no need to pass url and ttl now
|
||||
hctx.Init_by_page(wiki, hpg);
|
||||
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_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,29 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.addons.gallerys; 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.addons.*;
|
||||
import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_gallery_data implements Xoh_data_itm {// NOTE: some galleries fail hzip; use Hook_bry to catch them; PAGE:en.d:a; DATE:2016-06-24
|
||||
public int Tid() {return Xoh_hzip_dict_.Tid__gallery;}
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Clear() {
|
||||
this.src_bgn = this.src_end = -1;
|
||||
}
|
||||
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag gallery_lhs, Gfh_tag unused) {
|
||||
this.Clear();
|
||||
this.src_bgn = gallery_lhs.Src_bgn();
|
||||
this.src_end = gallery_lhs.Src_end();
|
||||
return true;
|
||||
}
|
||||
public void Init_by_decode(int src_bgn, int src_end) {
|
||||
this.src_bgn = src_bgn;
|
||||
this.src_end = src_end;
|
||||
}
|
||||
public static final byte[] Hook_bry = Bry_.new_a7(" class=\"gallery mw-gallery");
|
||||
|
||||
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_gallery_data rv = new Xoh_gallery_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,36 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.addons.gallerys; 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.addons.*;
|
||||
import gplx.core.brys.*; import gplx.core.threads.poolables.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_gallery_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public int Tid() {return Xoh_hzip_dict_.Tid__gallery;}
|
||||
public String Key() {return Xoh_hzip_dict_.Key__gallery;}
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public Gfo_poolable_itm Encode1(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_gallery_data data = (Xoh_gallery_data)data_obj;
|
||||
|
||||
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
|
||||
|
||||
hctx.Hzip__stat().Gallery_add();
|
||||
return this;
|
||||
}
|
||||
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
|
||||
int gallery_bgn = src_bgn;
|
||||
int gallery_end = Bry_find_.Find_fwd(src, Byte_ascii.Gt, src_bgn, src_end);
|
||||
if (gallery_end == -1) {
|
||||
Gfo_log_.Instance.Warn("hzip.gallery.end_not_found", "page", hpg.Url_bry_safe(), "src_bgn", src_bgn);
|
||||
gallery_end = gallery_bgn;
|
||||
}
|
||||
else
|
||||
++gallery_end;
|
||||
|
||||
Xoh_gallery_data data = (Xoh_gallery_data)data_itm;
|
||||
data.Init_by_decode(gallery_bgn, gallery_end);
|
||||
rdr.Move_to(gallery_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_gallery_hzip rv = new Xoh_gallery_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user