mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
HTTP Server: Append url_args to page [#489]
This commit is contained in:
parent
66039fc9b3
commit
f5abfa11da
@ -92,7 +92,7 @@ public class Http_server_mgr implements Gfo_invk {
|
||||
String cmd = url_converter.Decode_str(url_encoded_str);
|
||||
app.Gfs_mgr().Run_str(cmd);
|
||||
}
|
||||
public String Parse_page_to_html(Http_data__client data__client, byte[] wiki_domain, byte[] ttl_bry, byte mode, boolean popup_enabled, String popup_mode, String popup_id) {
|
||||
public String Parse_page_to_html(Http_data__client data__client, byte[] wiki_domain, byte[] ttl_bry, byte[] qarg, byte mode, boolean popup_enabled, String popup_mode, String popup_id) {
|
||||
synchronized (thread_lock) {
|
||||
// create a shim gui to automatically handle default XOWA gui JS calls
|
||||
if (init_gui_needed) {
|
||||
@ -112,7 +112,7 @@ public class Http_server_mgr implements Gfo_invk {
|
||||
else {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
try {
|
||||
tmp_bfr.Add(wiki.Domain_bry()).Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki).Add(ttl_bry);
|
||||
tmp_bfr.Add(wiki.Domain_bry()).Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki).Add(ttl_bry).Add_safe(qarg);
|
||||
ttl_bry = tmp_bfr.To_bry_and_clear();
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class Http_server_wkr implements Gfo_invk {
|
||||
page_html = url_parser.Err_msg();
|
||||
}
|
||||
else {
|
||||
page_html = app.Http_server().Parse_page_to_html(data__client, url_parser.Wiki(), url_parser.Page(), url_parser.Action(), url_parser.Popup(), url_parser.Popup_mode(), url_parser.Popup_id());
|
||||
page_html = app.Http_server().Parse_page_to_html(data__client, url_parser.Wiki(), url_parser.Page(), url_parser.Qarg(), url_parser.Action(), url_parser.Popup(), url_parser.Popup_mode(), url_parser.Popup_id());
|
||||
page_html = Convert_page(page_html, root_dir_http, String_.new_u8(url_parser.Wiki()));
|
||||
}
|
||||
Xosrv_http_wkr_.Write_response_as_html(client_wtr, Bool_.N, page_html);
|
||||
|
@ -21,6 +21,7 @@ import gplx.xowa.wikis.pages.*;
|
||||
class Http_url_parser {
|
||||
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[] Qarg() {return qarg;} public Http_url_parser Qarg_(String v) {this.qarg = Bry_.new_u8(v); return this;} private byte[] qarg;
|
||||
public byte Action() {return action;} public Http_url_parser Action_(byte v) {this.action = v; return this;} private byte action;
|
||||
public String Popup_mode() {return popup_mode;} public Http_url_parser Popup_mode_(String v) {this.popup_mode = v; return this;} private String popup_mode;
|
||||
public boolean Popup() {return popup;} public Http_url_parser Popup_(boolean v) {this.popup = v; return this;} private boolean popup;
|
||||
@ -31,8 +32,13 @@ class Http_url_parser {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr.Add_str_a7("wiki=").Add_safe(wiki).Add_byte_nl();
|
||||
bfr.Add_str_a7("page=").Add_safe(page).Add_byte_nl();
|
||||
bfr.Add_str_a7("qarg=").Add_safe(qarg).Add_byte_nl();
|
||||
bfr.Add_str_a7("action=").Add_byte_variable(action).Add_byte_nl();
|
||||
bfr.Add_str_a7("popup=").Add_yn(popup).Add_byte_nl();
|
||||
if (popup_id != null)
|
||||
bfr.Add_str_a7("popup_id=").Add_str_u8(popup_id).Add_byte_nl();
|
||||
if (popup_mode != null)
|
||||
bfr.Add_str_a7("popup_mode=").Add_str_u8(popup_mode).Add_byte_nl();
|
||||
bfr.Add_str_a7("err_msg=").Add_str_u8_null(err_msg).Add_byte_nl();
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
@ -72,19 +78,42 @@ class Http_url_parser {
|
||||
}
|
||||
|
||||
// get qargs
|
||||
Gfo_qarg_mgr qarg_mgr = new Gfo_qarg_mgr().Init(url_obj.Qargs());
|
||||
byte[] action_val = qarg_mgr.Read_bry_or("action", Bry_.Empty);
|
||||
if (Bry_.Eq(action_val, Xoa_url_.Qarg__action__read))
|
||||
this.action = Xopg_view_mode_.Tid__read;
|
||||
else if (Bry_.Eq(action_val, Xoa_url_.Qarg__action__edit))
|
||||
this.action = Xopg_view_mode_.Tid__edit;
|
||||
else if (Bry_.Eq(action_val, Xoa_url_.Qarg__action__html))
|
||||
this.action = Xopg_view_mode_.Tid__html;
|
||||
else if (Bry_.Eq(action_val, Qarg__action__popup)) {
|
||||
this.popup = true;
|
||||
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"));
|
||||
Gfo_qarg_itm[] qargs = url_obj.Qargs();
|
||||
int qargs_len = qargs.length;
|
||||
Bry_bfr qarg_bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < qargs_len; i++) {
|
||||
Gfo_qarg_itm qarg_itm = qargs[i];
|
||||
byte[] qarg_key = qarg_itm.Key_bry();
|
||||
byte[] qarg_val = qarg_itm.Val_bry();
|
||||
int qarg_tid = qarg_keys.Get_as_int_or(qarg_key, Byte_.Max_value_127);
|
||||
|
||||
switch (qarg_tid) {
|
||||
case Tid__action:
|
||||
if (Bry_.Eq(qarg_val, Xoa_url_.Qarg__action__read))
|
||||
this.action = Xopg_view_mode_.Tid__read;
|
||||
else if (Bry_.Eq(qarg_val, Xoa_url_.Qarg__action__edit))
|
||||
this.action = Xopg_view_mode_.Tid__edit;
|
||||
else if (Bry_.Eq(qarg_val, Xoa_url_.Qarg__action__html))
|
||||
this.action = Xopg_view_mode_.Tid__html;
|
||||
else if (Bry_.Eq(qarg_val, Qarg__action__popup))
|
||||
this.popup = true;
|
||||
break;
|
||||
case Tid__popup_id:
|
||||
this.popup_id = String_.new_u8(qarg_val);
|
||||
break;
|
||||
case Tid__popup_mode:
|
||||
this.popup_mode = String_.new_u8(qarg_val);
|
||||
break;
|
||||
default:
|
||||
qarg_bfr.Add_byte(qarg_bfr.Len_eq_0() ? Byte_ascii.Question : Byte_ascii.Amp);
|
||||
qarg_bfr.Add(qarg_key);
|
||||
qarg_bfr.Add_byte_eq();
|
||||
qarg_bfr.Add(qarg_val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (qarg_bfr.Len_gt_0())
|
||||
qarg = qarg_bfr.To_bry_and_clear();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -100,7 +129,19 @@ class Http_url_parser {
|
||||
this.err_msg += "; url=" + String_.new_u8(url);
|
||||
return false;
|
||||
}
|
||||
private static final byte
|
||||
Tid__action = 1
|
||||
, Tid__popup_id = 2
|
||||
, Tid__popup_mode = 3
|
||||
;
|
||||
private static final byte[]
|
||||
Qarg__action__popup = Bry_.new_a7("popup")
|
||||
, Qarg__popup_id = Bry_.new_a7("popup_id")
|
||||
, Qarg__popup_mode = Bry_.new_a7("popup_mode")
|
||||
;
|
||||
private static final Hash_adp_bry qarg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_int(Xoa_url_.Qarg__action, Tid__action)
|
||||
.Add_bry_int(Qarg__popup_id , Tid__popup_id)
|
||||
.Add_bry_int(Qarg__popup_mode , Tid__popup_mode)
|
||||
;
|
||||
}
|
||||
|
@ -60,6 +60,21 @@ public class Http_url_parser_tst {
|
||||
// fail: missing '/wiki/'
|
||||
fxt.Test__parse("/en.wikipedia.org/Page_1", fxt.Make().Err_msg_("invalid url; must have '/wiki/' after wiki_domain; url=/en.wikipedia.org/Page_1"));
|
||||
*/
|
||||
// add qarg_ary and test for qarg;
|
||||
}
|
||||
@Test public void Popup() {
|
||||
fxt.Test__parse
|
||||
( "/en.wikipedia.org/wiki/Page_1?action=popup&popup_id=xo_2&popup_mode=more"
|
||||
, fxt.Make().Wiki_("en.wikipedia.org").Page_("Page_1")
|
||||
.Popup_(true).Popup_id_("xo_2").Popup_mode_("more")
|
||||
);
|
||||
}
|
||||
@Test public void Qarg__search() {
|
||||
fxt.Test__parse
|
||||
( "/en.wikipedia.org/wiki/Special:XowaSearch?search=earth&fulltext=y"
|
||||
, fxt.Make().Wiki_("en.wikipedia.org").Page_("Special:XowaSearch")
|
||||
.Qarg_("?search=earth&fulltext=y")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Http_url_parser_fxt {
|
||||
|
Loading…
Reference in New Issue
Block a user