1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

HTTP_Server: Add initial implementation for post-processing HTML to change to /fsys/ etc [#524]

This commit is contained in:
gnosygnu 2019-08-03 10:00:40 -04:00
parent a51906bf4b
commit a1da02a99f
16 changed files with 416 additions and 14 deletions

View File

@ -50,6 +50,8 @@ public class Gfh_atr_ {
, Bry__bgcolor = Bry_.new_a7("bgcolor") // HTML.v4
, Bry__abbr = Bry_.new_a7("abbr") // HTML.ua
, Bry__srcset = Bry_.new_a7("srcset")
// <form>
, Bry__action = Bry_.new_a7("action")
;
public static byte[] Make(Bry_bfr bfr, byte[] key, byte[] val) {
return bfr.Add_byte_space().Add(key).Add_byte_eq().Add_byte_quote().Add(val).Add_byte_quote().To_bry_and_clear();

View File

@ -80,6 +80,7 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Id__rb = 58
, Id__rp = 59
, Id__rt = 60
, Id__form = 61
;
// private static final int Id__ary_max = 60;
public static final byte[]
@ -165,6 +166,7 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
.Add_str_int("rb" , Id__rb)
.Add_str_int("rp" , Id__rp)
.Add_str_int("rt" , Id__rt)
.Add_str_int("form" , Id__form)
;
public static String To_str(int tid) {
switch (tid) {
@ -232,6 +234,7 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
case Id__rb: return "rb";
case Id__rp: return "rp";
case Id__rt: return "rt";
case Id__form: return "form";
default: throw Err_.new_unhandled(tid);
}
}

View File

@ -19,7 +19,7 @@ import gplx.core.primitives.*; import gplx.core.net.*; import gplx.langs.htmls.e
import gplx.xowa.apps.*;
import gplx.xowa.htmls.js.*;
import gplx.xowa.wikis.pages.*;
class Http_server_wkr implements Gfo_invk {
public class Http_server_wkr implements Gfo_invk {
private final int uid;
private final Http_server_mgr server_mgr;
private final Http_server_wtr server_wtr;
@ -150,9 +150,12 @@ class Http_server_wkr implements Gfo_invk {
return this;
} public static final String Invk_run = "run";
private static final byte[]
Url__home = Bry_.new_a7("/"), Url__fsys = Bry_.new_a7("/fsys/")
Url__home = Bry_.new_a7("/")
, Url__exec = Bry_.new_a7("/exec/"), Url__exec_2 = Bry_.new_a7("/xowa-cmd:")
;
public static final byte[]
Url__fsys = Bry_.new_a7("/fsys/")
;
private static final int Url__fsys_len = Url__fsys.length;
}
class Xosrv_http_wkr_ {

View File

@ -0,0 +1,138 @@
/*
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.apps.servers.http.hdocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*; import gplx.xowa.apps.servers.http.*;
import gplx.core.btries.*; import gplx.core.primitives.*; import gplx.core.net.*;
import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.xowa.htmls.core.wkrs.addons.forms.*;
class Xoh_hdoc_wkr__http_server implements Xoh_hdoc_wkr {
private Bry_bfr bfr; private Xoh_page hpg; private byte[] src;
private byte[] root_http_dir; // EX: file:///C:/xowa/
public void On_page_bgn(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
this.bfr = bfr; this.hpg = hpg; this.src = src;
if (root_http_dir == null) {
this.root_http_dir = hpg.Wiki().App().Fsys_mgr().Http_root().To_http_file_bry();
href_trie.Add_bry_byte(root_http_dir, Tid__fsys);
}
}
public void On_page_end() {}
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) {
// get atr (with null checks)
Xoh_anch_href_data href_itm = data.Href_itm();
if (href_itm == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "lnki missing href; page=~{0} src=~{1}", hpg.Url_bry_safe(), Bry_.Mid(src, data.Src_bgn(), data.Src_end()));
return;
}
Add_href(data.Src_bgn(), data.Src_end(), href_itm.Atr().Val_bgn(), href_itm.Atr().Val_end());
}
public boolean On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {
// NOTE: not parsing thm b/c Xoh_thm_data does not expose the <a> in the magnify div
// In addition, On_thm would also need to parse any <a> or <img> in the caption
return false;
}
public void On_gly(gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
}
public boolean Process_parse(Xoh_data_itm data) {
switch (data.Tid()) {
case Xoh_hzip_dict_.Tid__img: {
Xoh_img_data img_data = (Xoh_img_data)data;
Xoh_anch_href_data anch_href = img_data.Anch_href();
Add_href(data.Src_bgn(), anch_href.Rng_end(), anch_href.Atr().Val_bgn(), anch_href.Atr().Val_end());
Add_href(anch_href.Rng_end(), data.Src_end(), img_data.Img_src().Src_bgn(), img_data.Img_src().Src_end());
return true;
}
// case Xoh_hzip_dict_.Tid__img_bare:
// case Xoh_hzip_dict_.Tid__media:
// Gfo_usr_dlg_.Instance.Warn_many("", "", "htxt_wkr does not support media; url=~{0}", hpg.Url_bry_safe());
// return false;
case Xoh_hzip_dict_.Tid__form:
Xoh_form_data form_data = (Xoh_form_data)data;
Gfh_atr action_atr = form_data.Action_atr();
bfr.Add_mid(src, form_data.Src_bgn(), action_atr.Val_bgn());
if (Bry_.Match(src, action_atr.Val_bgn(), action_atr.Val_bgn() + Xoh_href_.Bry__wiki.length, Xoh_href_.Bry__wiki)) {
bfr.Add_byte_slash().Add(hpg.Wiki().Domain_bry());
}
bfr.Add_mid(src, action_atr.Val_bgn(), form_data.Src_end());
return true;
case Xoh_hzip_dict_.Tid__hdr:
case Xoh_hzip_dict_.Tid__toc:
case Xoh_hzip_dict_.Tid__lnke:
default:
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
break;
}
return true;
}
private void Add_href(int itm_bgn, int itm_end, int href_bgn, int href_end) {
// add everything up to href_bgn
bfr.Add_mid(src, itm_bgn, href_bgn);
// now "fix" href
Btrie_rv trv = new Btrie_rv();
Object tid_obj = href_trie.Match_at(trv, src, href_bgn, href_end);
if (tid_obj != null) {
byte tid = ((Byte_obj_val)tid_obj).Val();
switch (tid) {
case Tid__wiki:
bfr.Add_byte_slash().Add(hpg.Wiki().Domain_bry());
break;
case Tid__xcmd:
bfr.Add_str_a7("/exec/");
href_bgn = trv.Pos();
break;
case Tid__site:
href_bgn = trv.Pos();
break;
case Tid__fsys:
bfr.Add(Http_server_wkr.Url__fsys);
href_bgn = trv.Pos();
break;
case Tid__fsys_bug:
bfr.Add(Http_server_wkr.Url__fsys);
href_bgn = trv.Pos() - 5; // 5 = "file/".length
break;
default:
throw Err_.new_unhandled_default(tid);
}
}
// add remainder of href_val
bfr.Add_mid(src, href_bgn, href_end);
// add everything after href
bfr.Add_mid(src, href_end, itm_end);
}
public static final byte[] Path_lnxusr_xowa_file = Bry_.new_a7("file:////home/lnxusr/xowa/file/");
private static final byte[] Bry__site = Bry_.new_a7("/site");
private static final byte
Tid__wiki = 1
, Tid__xcmd = 2
, Tid__site = 3
, Tid__fsys = 4
, Tid__fsys_bug = 5
;
private static final Btrie_slim_mgr href_trie = Btrie_slim_mgr.ci_u8()
.Add_bry_byte(Xoh_href_.Bry__wiki , Tid__wiki)
.Add_bry_byte(Gfo_protocol_itm.Bry_xcmd , Tid__xcmd)
.Add_bry_byte(Bry__site , Tid__site)
.Add_bry_byte(Path_lnxusr_xowa_file , Tid__fsys_bug)
;
}

View File

@ -0,0 +1,192 @@
/*
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.apps.servers.http.hdocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*; import gplx.xowa.apps.servers.http.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.makes.*;
public class Xoh_hdoc_wkr__http_server__tst {
private final Xoh_hdoc_wkr__http_server__fxt fxt = new Xoh_hdoc_wkr__http_server__fxt();
@Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();}
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void Wiki_quot() {
fxt.Test
( "<a id=\"id1\" href=\"/wiki/A\">abc</a>"
, "<a id=\"id1\" href=\"/en.wikipedia.org/wiki/A\">abc</a>"
);
}
@Test public void Wiki_apos() {
fxt.Test
( "<a id=\"id1\" href='/wiki/A'>abc</a>"
, "<a id=\"id1\" href='/en.wikipedia.org/wiki/A'>abc</a>"
);
}
// @Test public void Lnki_caption() {
// fxt.Test
// ( "<a id=\"id1\" href='/wiki/A'>abc <a href='/wiki/B'</a>lmn</a> xyz</a>"
// , "<a id=\"id1\" href='/en.wikipedia.org/wiki/A'>abc <a href='/en.wikipedia.org/wiki/B'</a>lmn</a> xyz</a>"
// );
// }
@Test public void Xcmd() {
fxt.Test
( "<a id=\"id1\" href=\"xowa-cmd:a\">abc</a>"
, "<a id=\"id1\" href=\"/exec/a\">abc</a>"
);
}
@Test public void Site() {
fxt.Test
( "<a id=\"id1\" href=\"/site/en.wikipedia.org/wiki/Special:Search/A\">abc</a>"
, "<a id=\"id1\" href=\"/en.wikipedia.org/wiki/Special:Search/A\">abc</a>"
);
}
@Test public void Action() { // NOTE: also used by Special:ItemByTitle; EX: "<form method=\"get\" action=\"//www.wikidata.org/wiki/Special:ItemByTitle\" name=\"itembytitle\" id=\"wb-itembytitle-form1\">"
fxt.Test
( "<form id=\"searchform\" action=\"/wiki/SearchUrl\">abc</form>"
, "<form id=\"searchform\" action=\"/en.wikipedia.org/wiki/SearchUrl\">abc</form>"
);
}
@Test public void Fsys() {
fxt.Test
( "<a id=\"id1\" href=\"file:///mem/xowa/file/A.png\">abc</a>"
, "<a id=\"id1\" href=\"/fsys/file/A.png\">abc</a>"
);
}
@Test public void Fsys_bug() { // 2019-05 enwiki embedded build machine's path
fxt.Test
( "<a id=\"id1\" href=\"file:////home/lnxusr/xowa/file/A.png\">abc</a>"
, "<a id=\"id1\" href=\"/fsys/file/A.png\">abc</a>"
);
}
@Test public void Fsys_img() {
fxt.Test
( "<a href='/wiki/File:A.jpg' class='image'><img src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png\">abc</img></a>"
, "<a href='/en.wikipedia.org/wiki/File:A.jpg' class='image'><img src=\"/fsys/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png\">abc</img></a>"
);
}
@Test public void Fsys_div() {
fxt.Test
( String_.Concat_lines_nl
( "<div class='thumb tleft'>"
, " <div id='xowa_file_div_2' class='thumbinner' style='width:128px;'>"
, " <a href='/wiki/File:A.jpg' class='image' xowa_title='A.jpg'><img id='xoimg_2' alt='' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png' width='128' height='100' class='thumbimage'></a> "
, " <div class='thumbcaption'>"
, " <div class='magnify'>"
, " <a href='/wiki/File:A.jpg' class='@gplx.Internal protected' title='Enlarge'></a>"
, " </div>"
, " thumb_caption"
, " </div>"
, " </div>"
, "</div>"
)
, String_.Concat_lines_nl
( "<div class='thumb tleft'>"
, " <div id='xowa_file_div_2' class='thumbinner' style='width:128px;'>"
, " <a href='/en.wikipedia.org/wiki/File:A.jpg' class='image' xowa_title='A.jpg'><img id='xoimg_2' alt='' src='/fsys/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png' width='128' height='100' class='thumbimage'></a> "
, " <div class='thumbcaption'>"
, " <div class='magnify'>"
, " <a href='/en.wikipedia.org/wiki/File:A.jpg' class='@gplx.Internal protected' title='Enlarge'></a>"
, " </div>"
, " thumb_caption"
, " </div>"
, " </div>"
, "</div>"
)
);
}
@Test public void Fsys_gallery() {
fxt.Test
( String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>a1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_1\" alt=\"\" src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>b1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
)
, String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>a1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_1\" alt=\"\" src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>b1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
)
);
}
}
class Xoh_hdoc_wkr__http_server__fxt {
private final Xow_wiki wiki;
private final Xoh_page hpg;
private final Xoh_make_mgr hdoc_mgr = Xoh_make_mgr.New(new Xoh_hdoc_wkr__http_server());
public Xoh_hdoc_wkr__http_server__fxt() {
Xop_fxt fxt = Xop_fxt.New_app_html();
this.wiki = fxt.Wiki();
int page_id = 123;
byte[] page_ttl_bry = Bry_.new_u8("Test_Page");
Xoa_url page_url = Xoa_url.New(wiki.Domain_bry(), page_ttl_bry);
Xoa_ttl page_ttl = wiki.Ttl_parse(page_ttl_bry);
this.hpg = new Xoh_page();
hpg.Ctor_by_hview(wiki, page_url, page_ttl, page_id);
}
public void Test(String src_str, String expd) {
byte[] src = Bry_.new_u8(src_str);
byte[] actl = hdoc_mgr.Parse(src, wiki, hpg);
Gftest.Eq__ary__lines(expd, String_.new_u8(actl));
}
}

View File

@ -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();

View File

@ -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

View File

@ -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);}
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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) {

View File

@ -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;}
}

View File

@ -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;

View File

@ -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)