mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
43
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_cmd.java
Normal file
43
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_cmd.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*;
|
||||
public class Xop_xowa_cmd implements Xox_xnde {
|
||||
public Xop_root_tkn Xtn_root() {throw Exc_.new_unimplemented_w_msg("xowa_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {return xtn_html;} private byte[] xtn_html;
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
if (itm_bgn == src.length) return; // NOTE: handle inline where there is no content to parse; EX: <xowa_cmd/>
|
||||
if (src[itm_bgn] == Byte_ascii.Nl) ++itm_bgn; // ignore 1st \n;
|
||||
if (src[itm_end - 1] == Byte_ascii.Nl) --itm_end; // ignore last \n;
|
||||
byte[] raw = Bry_.Mid(src, itm_bgn, itm_end);
|
||||
byte[] xtn_src = raw;
|
||||
if (wiki.Sys_cfg().Xowa_cmd_enabled()) { // only exec if enabled for wiki
|
||||
Object rslt = wiki.Appe().Gfs_mgr().Run_str(String_.new_u8(raw));
|
||||
xtn_src = Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
|
||||
}
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_ctx sub_ctx = Xop_ctx.new_sub_(wiki);
|
||||
Xop_root_tkn sub_root = tkn_mkr.Root(xtn_src);
|
||||
xtn_html = wiki.Parser().Parse_text_to_wtxt(sub_root, sub_ctx, ctx.Tkn_mkr(), xtn_src);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
bfr.Add(xtn_html);
|
||||
//throw Exc_.new_unimplemented_w_msg("xowa_cmd.xtn_write should not be called");
|
||||
}
|
||||
}
|
||||
94
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_cmd_tst.java
Normal file
94
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_cmd_tst.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xop_xowa_cmd_tst {
|
||||
@Before public void init() {
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
fxt.Reset();
|
||||
} private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
GfsCore._.AddCmd(fxt.App(), Xoae_app.Invk_app);
|
||||
fxt.Wiki().Sys_cfg().Xowa_cmd_enabled_(false);
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "<xowa_cmd>"
|
||||
, "app.users.get('anonymous').name;"
|
||||
, "</xowa_cmd>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "app.users.get('anonymous').name;"
|
||||
));
|
||||
fxt.Wiki().Sys_cfg().Xowa_cmd_enabled_(true);
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "<xowa_cmd>"
|
||||
, "app.users.get('anonymous').name;"
|
||||
, "</xowa_cmd>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "anonymous"
|
||||
));
|
||||
fxt.Wiki().Sys_cfg().Xowa_cmd_enabled_(false);
|
||||
}
|
||||
@Test public void Template() { // PURPOSE: xowa_cmd should do template expansion; DATE:2014-05-29
|
||||
fxt.Init_page_create("Template:Xowa_cmd_test", "val_0");
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "<xowa_cmd>{{xowa_cmd_test}}</xowa_cmd>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "val_0"
|
||||
));
|
||||
}
|
||||
@Test public void Ref() { // PURPOSE: ref should not be expanded twice; DATE:2014-05-29
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "<xowa_cmd><ref name='a'></ref><references/></xowa_cmd>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-a_0-0\" class=\"reference\"><a href=\"#cite_note-a-0\">[1]</a></sup><ol class=\"references\">"
|
||||
, "<li id=\"cite_note-a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-a_0-0\">^</a></span> <span class=\"reference-text\"></span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
// @Test public void Wiki_list_fmtrs() {
|
||||
// fxt.Wiki().Sys_cfg().Xowa_cmd_enabled_(true);
|
||||
// fxt.App().Setup_mgr().Maint_mgr().Wiki_mgr().Add(Bry_.new_a7("en.wikipedia.org"));
|
||||
// fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
// ( "{|"
|
||||
// , "<xowa_cmd>"
|
||||
// , "app.fmtrs.new_grp {"
|
||||
// , " src = 'app.setup.maint.wikis;';"
|
||||
// , " fmt ='"
|
||||
// , "|-"
|
||||
// , "|~{<>domain;<>}'"
|
||||
// , ";"
|
||||
// , " run;"
|
||||
// , "}"
|
||||
// , "</xowa_cmd>"
|
||||
// , "|}"
|
||||
// ), String_.Concat_lines_nl
|
||||
// ( "<table>"
|
||||
// , " <tr>"
|
||||
// , " <td>en.wikipedia.org"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
//// , " <tr>"
|
||||
//// , " <td>home"
|
||||
//// , " </td>"
|
||||
//// , " </tr>"
|
||||
// , "</table>"
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_func.java
Normal file
34
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_func.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Xop_xowa_func extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_xowa;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Xop_xowa_func().Name_(name);}
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
if (ctx.Wiki().Sys_cfg().Xowa_cmd_enabled()) { // only exec if enabled for wiki
|
||||
int args_len = self.Args_len();
|
||||
byte[] arg_0 = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
|
||||
Object rslt = ctx.App().Gfs_mgr().Run_str(String_.new_u8(arg_0));
|
||||
bfr.Add(Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt)));
|
||||
}
|
||||
else {
|
||||
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
|
||||
}
|
||||
}
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_func_tst.java
Normal file
31
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_func_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xop_xowa_func_tst {
|
||||
@Before public void init() {
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
} private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Template() {
|
||||
GfsCore._.AddCmd(fxt.App(), Xoae_app.Invk_app);
|
||||
fxt.Wiki().Sys_cfg().Xowa_cmd_enabled_(true);
|
||||
fxt.Init_defn_add("A", "{{#xowa|{{{1}}}}}");
|
||||
fxt.Test_parse_page_all_str("{{A|app.users.get('anonymous').name;}}", "anonymous");
|
||||
}
|
||||
}
|
||||
65
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xox_xowa_html_cmd.java
Normal file
65
400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xox_xowa_html_cmd.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.html.*;
|
||||
public class Xox_xowa_html_cmd implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
private byte pos_val = Pos_head_end;
|
||||
public Xop_root_tkn Xtn_root() {throw Exc_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {throw Exc_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
|
||||
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_key_obj) {
|
||||
if (xatr_key_obj == null) return;
|
||||
Byte_obj_val xatr_key = (Byte_obj_val)xatr_key_obj;
|
||||
switch (xatr_key.Val()) {
|
||||
case Xatr_pos_id: pos_val = Pos_val(xatr.Val_as_bry(src)); break;
|
||||
default: throw Exc_.new_unhandled(xatr_key.Val());
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (!wiki.Sys_cfg().Xowa_cmd_enabled()) { // not allowed; warn and exit
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_html command only allowed in xowa_home");
|
||||
return;
|
||||
}
|
||||
Xop_xatr_itm.Xatr_parse(wiki.Appe(), this, atr_hash, wiki, src, xnde);
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
if (src[itm_bgn] == Byte_ascii.Nl) ++itm_bgn; // ignore 1st \n;
|
||||
// if (src[itm_end - 1] == Byte_ascii.Nl) --itm_end; // ignore last \n;
|
||||
byte[] raw = Bry_.Mid(src, itm_bgn, itm_end);
|
||||
if (pos_val == Pos_head_end)
|
||||
ctx.Cur_page().Html_data().Custom_head_end_concat(raw);
|
||||
else
|
||||
ctx.Cur_page().Html_data().Custom_html_end_concat(raw);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
|
||||
private static byte Pos_val(byte[] bry) {
|
||||
Object o = pos_val_hash.Get_by_bry(bry);
|
||||
if (o == null) throw Exc_.new_("unknown pos", "pos", String_.new_u8(bry));
|
||||
return ((Byte_obj_val)o).Val();
|
||||
}
|
||||
private static final byte Pos_head_end = 1, Pos_html_end = 2;
|
||||
private static final byte[]
|
||||
Xatr_pos_key = Bry_.new_a7("pos")
|
||||
, Xatr_pos_val__head_end = Bry_.new_a7("head.end")
|
||||
, Xatr_pos_val__html_end = Bry_.new_a7("html.end")
|
||||
;
|
||||
private static final Hash_adp_bry pos_val_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Xatr_pos_val__head_end, Pos_head_end)
|
||||
.Add_bry_byte(Xatr_pos_val__html_end, Pos_html_end)
|
||||
;
|
||||
private static final byte Xatr_pos_id = 1;
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_ascii_().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.gui.*; import gplx.xowa.pages.*;
|
||||
public class Xox_xowa_html_cmd_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xox_xowa_html_cmd_fxt fxt = new Xox_xowa_html_cmd_fxt();
|
||||
@Test public void Head_end() {
|
||||
fxt.Test_parse_w_skin
|
||||
( "<xowa_html pos='head.end'>test</xowa_html>"
|
||||
, "<html><head>test</head><body></body></html>"
|
||||
);
|
||||
}
|
||||
@Test public void Html_end() {
|
||||
fxt.Test_parse_w_skin
|
||||
( "<xowa_html pos='html.end'>test</xowa_html>"
|
||||
, "<html><head></head><body></body>test</html>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xox_xowa_html_cmd_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
private Xowe_wiki wiki; private Xow_html_mgr html_mgr;
|
||||
public void Clear() {
|
||||
this.wiki = fxt.Wiki();
|
||||
html_mgr = wiki.Html_mgr();
|
||||
wiki.Sys_cfg().Xowa_cmd_enabled_(true);
|
||||
fxt.Page().Html_data().Module_mgr().Itm__css().Enabled_(false);
|
||||
html_mgr.Page_wtr_mgr().Page_read_fmtr().Fmt_("<html><head></head><body>~{page_data}</body></html>");
|
||||
}
|
||||
public void Test_parse_w_skin(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(raw_bry);
|
||||
fxt.Page().Root_(root);
|
||||
html_mgr.Html_wtr().Write_all(bfr, fxt.Ctx(), raw_bry, root);
|
||||
byte[] actl = html_mgr.Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read).Write(html_mgr.Page_wtr_mgr(), fxt.Page(), fxt.Ctx(), bfr);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user