mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Minor refactorings
This commit is contained in:
parent
87cb6b5a01
commit
b86228d6f2
@ -10,6 +10,5 @@
|
|||||||
<classpathentry exported="true" kind="lib" path="lib/icu4j-4_8.jar"/>
|
<classpathentry exported="true" kind="lib" path="lib/icu4j-4_8.jar"/>
|
||||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/gplx.gflucene"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/gplx.gflucene"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/luaj-vm"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -33,7 +33,6 @@ class Http_server_wkr implements Gfo_invk {
|
|||||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(64);
|
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(64);
|
||||||
private Socket_adp socket;
|
private Socket_adp socket;
|
||||||
private Http_data__client data__client;
|
private Http_data__client data__client;
|
||||||
private final Gfo_url_parser url_parser = new Gfo_url_parser();
|
|
||||||
public Http_server_wkr(Http_server_mgr server_mgr, int uid){
|
public Http_server_wkr(Http_server_mgr server_mgr, int uid){
|
||||||
this.server_mgr = server_mgr; this.uid = uid;
|
this.server_mgr = server_mgr; this.uid = uid;
|
||||||
this.app = server_mgr.App(); this.server_wtr = server_mgr.Server_wtr(); this.url_encoder = server_mgr.Encoder();
|
this.app = server_mgr.App(); this.server_wtr = server_mgr.Server_wtr(); this.url_encoder = server_mgr.Encoder();
|
||||||
@ -100,7 +99,7 @@ class Http_server_wkr implements Gfo_invk {
|
|||||||
app.Http_server().Run_xowa_cmd(app, String_.new_u8(cmd));
|
app.Http_server().Run_xowa_cmd(app, String_.new_u8(cmd));
|
||||||
}
|
}
|
||||||
private void Write_wiki(byte[] req) {
|
private void Write_wiki(byte[] req) {
|
||||||
Http_url_parser url_parser = new Http_url_parser(url_encoder);
|
Http_url_parser url_parser = new Http_url_parser();
|
||||||
String page_html = "";
|
String page_html = "";
|
||||||
if (!url_parser.Parse(req)) {
|
if (!url_parser.Parse(req)) {
|
||||||
page_html = url_parser.Err_msg();
|
page_html = url_parser.Err_msg();
|
||||||
|
@ -19,10 +19,6 @@ import gplx.langs.htmls.encoders.*;
|
|||||||
import gplx.xowa.htmls.hrefs.*;
|
import gplx.xowa.htmls.hrefs.*;
|
||||||
import gplx.xowa.wikis.pages.*;
|
import gplx.xowa.wikis.pages.*;
|
||||||
class Http_url_parser {
|
class Http_url_parser {
|
||||||
private final Gfo_url_encoder url_encoder;
|
|
||||||
public Http_url_parser(Gfo_url_encoder url_encoder) {
|
|
||||||
this.url_encoder = url_encoder;
|
|
||||||
}
|
|
||||||
public byte[] Wiki() {return wiki;} public Http_url_parser Wiki_(String v) {this.wiki = Bry_.new_u8(v); return this;} private byte[] wiki;
|
public byte[] Wiki() {return wiki;} public Http_url_parser Wiki_(String v) {this.wiki = Bry_.new_u8(v); return this;} private byte[] wiki;
|
||||||
public byte[] Page() {return page;} public Http_url_parser Page_(String v) {this.page = Bry_.new_u8(v); return this;} private byte[] page;
|
public byte[] Page() {return page;} public Http_url_parser Page_(String v) {this.page = Bry_.new_u8(v); return this;} private byte[] page;
|
||||||
public byte Action() {return action;} public Http_url_parser Action_(byte v) {this.action = v; return this;} private byte action;
|
public byte Action() {return action;} public Http_url_parser Action_(byte v) {this.action = v; return this;} private byte action;
|
||||||
@ -81,47 +77,6 @@ class Http_url_parser {
|
|||||||
this.popup_id = qarg_mgr.Read_str_or_null(Bry_.new_a7("popup_id"));
|
this.popup_id = qarg_mgr.Read_str_or_null(Bry_.new_a7("popup_id"));
|
||||||
this.popup_mode = qarg_mgr.Read_str_or_null(Bry_.new_a7("popup_mode"));
|
this.popup_mode = qarg_mgr.Read_str_or_null(Bry_.new_a7("popup_mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
// get wiki
|
|
||||||
int wiki_bgn = 1; // skip initial "/"
|
|
||||||
int wiki_end = Bry_find_.Find_fwd_or(url, Byte_ascii.Slash, wiki_bgn, url_len, url_len);
|
|
||||||
this.wiki = Bry_.Mid(url, wiki_bgn, wiki_end);
|
|
||||||
if (wiki_end == url_len) {// no slash found; url is wiki-only; EX: "/en.wikipedia.org"
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get page after "/wiki/"
|
|
||||||
byte[] wiki_separator = Xoh_href_.Bry__wiki;
|
|
||||||
int page_bgn = wiki_end + wiki_separator.length;
|
|
||||||
if (!Bry_.Eq(url, wiki_end, wiki_end + wiki_separator.length, Xoh_href_.Bry__wiki))
|
|
||||||
return Fail(url, "invalid url; must have '/wiki/' after wiki_domain");
|
|
||||||
int page_end = url_len;
|
|
||||||
|
|
||||||
// search for action arg
|
|
||||||
this.action = Xopg_page_.Tid_read;
|
|
||||||
int action_key_bgn = Bry_find_.Find_bwd(url, Qarg__action__frag, url_len);
|
|
||||||
if (action_key_bgn != Bry_find_.Not_found) {
|
|
||||||
int action_val_bgn = action_key_bgn + Qarg__action__frag.length;
|
|
||||||
int action_val_end = url_len;
|
|
||||||
boolean trim_page = true;
|
|
||||||
if (Bry_.Eq(url, action_val_bgn, action_val_end, Xoa_url_.Qarg__action__read))
|
|
||||||
this.action = Xopg_page_.Tid_read;
|
|
||||||
else if (Bry_.Eq(url, action_val_bgn, action_val_end, Xoa_url_.Qarg__action__edit))
|
|
||||||
this.action = Xopg_page_.Tid_edit;
|
|
||||||
else if (Bry_.Eq(url, action_val_bgn, action_val_end, Xoa_url_.Qarg__action__html))
|
|
||||||
this.action = Xopg_page_.Tid_html;
|
|
||||||
else if (Bry_.Eq(url, action_val_bgn, action_val_end, Qarg__action__popup))
|
|
||||||
this.popup = true;
|
|
||||||
else // no "?action=" found; ignore "?"; EX: "A?action=unknown"
|
|
||||||
trim_page = false;
|
|
||||||
if (trim_page)
|
|
||||||
page_end = action_key_bgn;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.page = url_encoder.Decode(Bry_.Mid(url, page_bgn, page_end));
|
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -138,7 +93,6 @@ class Http_url_parser {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private static final byte[]
|
private static final byte[]
|
||||||
Qarg__action__frag = Bry_.Add(Byte_ascii.Question_bry, Xoa_url_.Qarg__action, Byte_ascii.Eq_bry) // "?action="
|
Qarg__action__popup = Bry_.new_a7("popup")
|
||||||
, Qarg__action__popup = Bry_.new_a7("popup")
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,9 @@ public class Http_url_parser_tst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Http_url_parser_fxt {
|
class Http_url_parser_fxt {
|
||||||
private final Gfo_url_encoder url_encoder = Gfo_url_encoder_.New__http_url().Make();
|
public Http_url_parser Make() {return new Http_url_parser();}
|
||||||
public Http_url_parser Make() {return new Http_url_parser(url_encoder);}
|
|
||||||
public void Test__parse(String url, Http_url_parser expd) {
|
public void Test__parse(String url, Http_url_parser expd) {
|
||||||
Http_url_parser actl = new Http_url_parser(url_encoder);
|
Http_url_parser actl = new Http_url_parser();
|
||||||
actl.Parse(url == null ? null : Bry_.new_u8(url));
|
actl.Parse(url == null ? null : Bry_.new_u8(url));
|
||||||
Gftest.Eq__ary__lines(expd.To_str(), actl.To_str());
|
Gftest.Eq__ary__lines(expd.To_str(), actl.To_str());
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|||||||
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||||
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
|
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
|
||||||
public class Xoh_lnki_html__hdump__tst {
|
public class Xoh_lnki_html__hdump__tst {
|
||||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||||
@Before public void init() {fxt.Clear();}
|
@Before public void init() {fxt.Clear();}
|
||||||
@Test public void Same() {fxt.Test__html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");}
|
@Test public void Same() {fxt.Test__html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");}
|
||||||
@Test public void Diff() {fxt.Test__html("[[A|b]]" , "<a href='/wiki/A' title='A'>b</a>");}
|
@Test public void Diff() {fxt.Test__html("[[A|b]]" , "<a href='/wiki/A' title='A'>b</a>");}
|
||||||
|
@ -18,7 +18,7 @@ import gplx.xowa.htmls.core.htmls.*;
|
|||||||
import gplx.xowa.langs.vnts.*;
|
import gplx.xowa.langs.vnts.*;
|
||||||
public class Xop_parser_ {
|
public class Xop_parser_ {
|
||||||
public static final int Doc_bgn_bos = -1, Doc_bgn_char_0 = 0;
|
public static final int Doc_bgn_bos = -1, Doc_bgn_char_0 = 0;
|
||||||
public static byte[] Parse_text_to_html(Xowe_wiki wiki, Xop_ctx owner_ctx, Xoae_page page, Xoa_ttl ttl, byte[] src, boolean para_enabled) { // NOTE: must pass in same page instance; do not do Xoa_page_.new_(), else img_idx will get reset to 0; DATE:2015-02-08
|
public static byte[] Parse_text_to_html(Xowe_wiki wiki, Xop_ctx owner_ctx, Xoae_page page, byte[] src, boolean para_enabled) { // NOTE: must pass in same page instance; do not do Xoa_page_.new_(), else img_idx will get reset to 0; DATE:2015-02-08
|
||||||
// init
|
// init
|
||||||
Xop_ctx ctx = Xop_ctx.New__sub(wiki, owner_ctx, page);
|
Xop_ctx ctx = Xop_ctx.New__sub(wiki, owner_ctx, page);
|
||||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||||
|
@ -44,7 +44,6 @@ public class Xop_uniq_mgr { // REF.MW:/parser/StripState.php
|
|||||||
byte[] rv = Parse_recurse(Bool_.Y, tmp_bfr, bfr.To_bry_and_clear());
|
byte[] rv = Parse_recurse(Bool_.Y, tmp_bfr, bfr.To_bry_and_clear());
|
||||||
bfr.Add(rv);
|
bfr.Add(rv);
|
||||||
}
|
}
|
||||||
public byte[] Parse(boolean template_parsing, byte[] src) {return Parse_recurse(template_parsing, tmp_bfr, src);}
|
|
||||||
public byte[] Parse(byte[] src) {return Parse_recurse(Bool_.Y, tmp_bfr, src);}
|
public byte[] Parse(byte[] src) {return Parse_recurse(Bool_.Y, tmp_bfr, src);}
|
||||||
private byte[] Parse_recurse(boolean template_parsing, Bry_bfr bfr, byte[] src) {
|
private byte[] Parse_recurse(boolean template_parsing, Bry_bfr bfr, byte[] src) {
|
||||||
int src_len = src.length;
|
int src_len = src.length;
|
||||||
|
@ -29,7 +29,7 @@ public class Indicator_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
|||||||
}
|
}
|
||||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||||
this.html = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), ctx.Page().Ttl(), Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
this.html = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
||||||
Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators();
|
Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators();
|
||||||
if (this.name != null) html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable
|
if (this.name != null) html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,13 @@ public class Pfunc_tag extends Pf_func_base {// REF:/includes/parser/CoreParserF
|
|||||||
Eval_attrs(ctx, wiki, caller, self, src, args_len, html_wkr);
|
Eval_attrs(ctx, wiki, caller, self, src, args_len, html_wkr);
|
||||||
|
|
||||||
// process body
|
// process body
|
||||||
byte[] body = args_len == 0
|
byte[] body = Bry_.Empty;
|
||||||
? Bry_.Empty
|
if (args_len > 0) {
|
||||||
: Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
|
body = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
|
||||||
html_wkr.Tag__process_body(body);
|
// REF.MW: $inner = $frame->expand( array_shift( $args ) );
|
||||||
|
// body = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), body, false);
|
||||||
|
}
|
||||||
|
html_wkr.Tag__process_body(body);
|
||||||
|
|
||||||
// add to UNIQ hash; DATE:2017-03-31
|
// add to UNIQ hash; DATE:2017-03-31
|
||||||
byte[] val = html_wkr.Tag__build(ctx.Wiki(), ctx);
|
byte[] val = html_wkr.Tag__build(ctx.Wiki(), ctx);
|
||||||
|
@ -51,4 +51,6 @@ public class Pfunc_tag_tst {
|
|||||||
, "</ol>"
|
, "</ol>"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
// TODO: handle; $inner = $frame->expand( array_shift( $args ) );
|
||||||
|
// @Test public void Nowiki() {fxt.Test_html_full_str("{{#tag:pre|<nowiki>a<i>b</i>c</nowiki>}}" , "<pre>a<i>b</i>c</pre>");}// PURPOSE: body should get evaluated; DATE:2018-12-28
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ class Pxd_itm_dow_name extends Pxd_itm_base implements Pxd_itm_prototype {
|
|||||||
@Override public boolean Eval(Pxd_parser state) {return true;}
|
@Override public boolean Eval(Pxd_parser state) {return true;}
|
||||||
@Override public boolean Time_ini(Pxd_date_bldr bldr) {
|
@Override public boolean Time_ini(Pxd_date_bldr bldr) {
|
||||||
DateAdp cur = bldr.To_date();
|
DateAdp cur = bldr.To_date();
|
||||||
int cur_dow = cur.DayOfWeek();
|
|
||||||
|
|
||||||
// adj = requested_dow - cur_dow; EX: requesting Friday, and today is Wednesday; adj = 2 (4 - 2); DATE:2014-05-02
|
// adj = requested_dow - cur_dow; EX: requesting Friday, and today is Wednesday; adj = 2 (4 - 2); DATE:2014-05-02
|
||||||
int adj = dow_idx - cur.DayOfWeek();
|
int adj = dow_idx - cur.DayOfWeek();
|
||||||
|
@ -90,7 +90,7 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
|||||||
if (!Bry_.Eq(atr_before, Bry_.Empty)) option_bry = Bry_.Add(atr_before, option_bry);
|
if (!Bry_.Eq(atr_before, Bry_.Empty)) option_bry = Bry_.Add(atr_before, option_bry);
|
||||||
if (!Bry_.Eq(atr_after , Bry_.Empty)) option_bry = Bry_.Add(option_bry, atr_after);
|
if (!Bry_.Eq(atr_after , Bry_.Empty)) option_bry = Bry_.Add(option_bry, atr_after);
|
||||||
|
|
||||||
this.val = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), ctx.Page().Ttl(), option_bry, false);
|
this.val = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), option_bry, false);
|
||||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||||
}
|
}
|
||||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
||||||
|
@ -44,7 +44,7 @@ public class Tabber_xnde implements Xox_xnde {
|
|||||||
else {
|
else {
|
||||||
tab_head = Bry_.Mid(tab_itm, 0, eq_pos);
|
tab_head = Bry_.Mid(tab_itm, 0, eq_pos);
|
||||||
tab_body = Bry_.Mid(tab_itm, eq_pos + 1, tab_itm_len);
|
tab_body = Bry_.Mid(tab_itm, eq_pos + 1, tab_itm_len);
|
||||||
tab_body = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), ctx.Page().Ttl(), tab_body, false);
|
tab_body = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), tab_body, false);
|
||||||
}
|
}
|
||||||
tab_itms_list.Add(new Tabber_tab_itm(Bool_.N, tab_head, tab_body));
|
tab_itms_list.Add(new Tabber_tab_itm(Bool_.N, tab_head, tab_body));
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class Tabview_tab_itm {
|
|||||||
gplx.xowa.wikis.caches.Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
|
gplx.xowa.wikis.caches.Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
|
||||||
if (page_itm == null) return null;
|
if (page_itm == null) return null;
|
||||||
page_body = page_itm.Wtxt__redirect_or_direct();
|
page_body = page_itm.Wtxt__redirect_or_direct();
|
||||||
page_body = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), ctx.Page().Ttl(), page_body, false);
|
page_body = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), page_body, false);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
tab_name = args_itm;
|
tab_name = args_itm;
|
||||||
|
Loading…
Reference in New Issue
Block a user