mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
HTTP_Server: Add initial implementation for post-processing HTML to change to /fsys/ etc [#524]
This commit is contained in:
@@ -25,7 +25,7 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
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();
|
||||
this.make_mgr = Xoh_make_mgr.New_make();
|
||||
}
|
||||
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;
|
||||
@@ -83,7 +83,7 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
|
||||
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());
|
||||
src = make_mgr.Parse(src, hpg.Wiki(), hpg);
|
||||
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();
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Tid__toc = 10
|
||||
, Tid__pgbnr = 11
|
||||
, Tid__media = 12
|
||||
, Tid__form = 13
|
||||
;
|
||||
public static final String
|
||||
Key__timeline = "timeline"
|
||||
@@ -50,6 +51,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Key__toc = "toc"
|
||||
, Key__pgbnr = "pgbnr"
|
||||
, Key__media = "media"
|
||||
, Key__form = "form"
|
||||
;
|
||||
public static final int // SERIALIZED:html_db.html.body_flag
|
||||
Hzip__none = 0
|
||||
|
||||
@@ -18,12 +18,17 @@ 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) {
|
||||
private final Xoh_hdoc_parser make_parser;
|
||||
Xoh_make_mgr(Xoh_hdoc_wkr hdoc_wkr) {
|
||||
this.make_parser = new Xoh_hdoc_parser(hdoc_wkr);
|
||||
}
|
||||
public byte[] Parse(byte[] src, Xow_wiki wiki, Xoh_page hpg) {
|
||||
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();
|
||||
}
|
||||
public static Xoh_make_mgr New_make() {return new Xoh_make_mgr(new Xoh_hdoc_wkr__make());}
|
||||
public static Xoh_make_mgr New(Xoh_hdoc_wkr hdoc_wkr) {return new Xoh_make_mgr(hdoc_wkr);}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Xoh_make_fxt {
|
||||
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());
|
||||
byte[] actl_body = make_mgr.Parse(Bry_.new_u8(html), parser_fxt.Wiki(), actl);
|
||||
actl.Db().Html().Html_bry_(actl_body);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
chkr.Check(actl);
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface Xoh_hdoc_wkr {
|
||||
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);
|
||||
boolean 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);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
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 boolean 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(); return true;}
|
||||
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;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "anchor hook should start with <a; url=~{0}", hpg.Url_bry_safe());
|
||||
}
|
||||
}
|
||||
public void On_thm(gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {
|
||||
public boolean On_thm(gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {
|
||||
Xoh_img_data img_data = (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_data)data.Img_data();
|
||||
// add thm html before img
|
||||
bfr.Add_mid(src, data.Src_bgn(), img_data.Src_bgn());
|
||||
@@ -79,6 +79,7 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
wkr__img.Init_by_parse(bfr, hpg, hctx, src, img_data);
|
||||
// add thm html after img
|
||||
bfr.Add_mid(src, img_data.Src_end(), data.Src_end());
|
||||
return true;
|
||||
}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {
|
||||
// <gallery> section; loop itms and call wkr__img on each image while concatenating anything inbetween
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xoh_htxt_fxt {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
private final Xoh_make_mgr make_mgr = new Xoh_make_mgr();
|
||||
private final Xoh_make_mgr make_mgr = Xoh_make_mgr.New_make();
|
||||
public Xoh_htxt_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/"
|
||||
@@ -41,7 +41,7 @@ public class Xoh_htxt_fxt {
|
||||
}
|
||||
public void Test__decode__raw(String htxt, String expd) {
|
||||
hpg.Section_mgr().Clear();
|
||||
byte[] actl = make_mgr.Parse(Bry_.new_u8(htxt), hpg, hpg.Wiki());
|
||||
byte[] actl = make_mgr.Parse(Bry_.new_u8(htxt), hpg.Wiki(), hpg);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test__hpg__redlinks(String... expd_ttls) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
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.forms; 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_form_data implements Xoh_data_itm {
|
||||
public int Tid() {return Xoh_hzip_dict_.Tid__form;}
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public Gfh_atr Action_atr() {return action_atr;} private Gfh_atr action_atr;
|
||||
public void Clear() {
|
||||
this.src_bgn = this.src_end = -1;
|
||||
this.action_atr = null;
|
||||
}
|
||||
public 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) {
|
||||
return Parse1(hdoc_wkr, hctx, tag_rdr, src, cur);
|
||||
}
|
||||
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag lhs_tag) {
|
||||
// init
|
||||
this.Clear();
|
||||
this.src_bgn = lhs_tag.Src_bgn();
|
||||
|
||||
// get action
|
||||
this.action_atr = lhs_tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__action);
|
||||
|
||||
// get tail; </form>
|
||||
Gfh_tag rhs_tag = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__form);
|
||||
this.src_end = rhs_tag.Src_end();
|
||||
|
||||
// process
|
||||
return hdoc_wkr.Process_parse(this);
|
||||
}
|
||||
public static final byte[] Hook_bry = Bry_.new_a7("<form");
|
||||
|
||||
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_form_data rv = new Xoh_form_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; 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.addons.forms.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_tag_parser implements Gfh_doc_wkr {
|
||||
@@ -27,6 +28,7 @@ public class Xoh_tag_parser implements Gfh_doc_wkr {
|
||||
private final Xoh_lnki_data wkr__lnki = new Xoh_lnki_data();
|
||||
private final Xoh_thm_data wkr__thm = new Xoh_thm_data();
|
||||
private final Xoh_gly_grp_data wkr__gly = new Xoh_gly_grp_data();
|
||||
private final Xoh_form_data wkr__form = new Xoh_form_data();
|
||||
public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;}
|
||||
public Xoh_tag_parser(Xoh_hdoc_wkr hdoc_wkr) {this.hdoc_wkr = hdoc_wkr;}
|
||||
public void Init(Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
@@ -88,6 +90,10 @@ public class Xoh_tag_parser implements Gfh_doc_wkr {
|
||||
if (wkr__gly.Parse1(hdoc_wkr, hctx, src, tag_rdr, cur)) return wkr__gly.Src_end();
|
||||
}
|
||||
break;
|
||||
case Gfh_tag_.Id__form:
|
||||
if (wkr__form.Parse1(hdoc_wkr, hctx, tag_rdr, src, cur))
|
||||
return wkr__form.Src_end();
|
||||
break;
|
||||
}
|
||||
if (rv == -1) {
|
||||
rv = cur_end;
|
||||
|
||||
@@ -56,8 +56,7 @@ public class Xoh_thm_data implements Gfh_style_wkr {
|
||||
}
|
||||
tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div);
|
||||
this.src_end = tag_rdr.Pos();
|
||||
hdoc_wkr.On_thm(this);
|
||||
return true;
|
||||
return hdoc_wkr.On_thm(this);
|
||||
}
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_val_bgn, int atr_val_end, int itm_bgn, int itm_End, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
if ( Bry_.Match(src, key_bgn, key_end, Gfh_style_key_.Bry__width)
|
||||
|
||||
Reference in New Issue
Block a user