mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.4.3.1'
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.langs.htmls.*;
|
||||
class Xo_custom_html_pos_ {
|
||||
public static final byte Tid__head_end = 1, Tid__tail = 2;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("head_end", Tid__head_end)
|
||||
.Add_str_byte("tail", Tid__tail)
|
||||
;
|
||||
public static byte To_tid(byte[] bry) {
|
||||
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127);
|
||||
if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown pos", "pos", bry);
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
class Xo_custom_html_type_ {
|
||||
public static final byte Tid__css_code = 1, Tid__js_code = 2;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Gfh_tag_.Bry__style , Tid__css_code)
|
||||
.Add_bry_byte(Gfh_tag_.Bry__script , Tid__js_code)
|
||||
;
|
||||
public static byte[] To_bry(byte tid) {
|
||||
switch (tid) {
|
||||
case Tid__css_code: return Gfh_tag_.Bry__style;
|
||||
case Tid__js_code : return Gfh_tag_.Bry__script;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
public static byte To_tid(byte[] bry) {
|
||||
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127); if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown type", "type", bry);
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,16 @@ 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.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
private byte pos_val = Pos_head_end;
|
||||
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
switch (xatr_id.Val()) {
|
||||
case Xatr_pos_id: pos_val = Pos_val(xatr.Val_as_bry()); break;
|
||||
default: throw Err_.new_unhandled(xatr_id.Val());
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
private byte tag_pos = Xo_custom_html_pos_.Tid__head_end, tag_type = Xo_custom_html_type_.Tid__css_code;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
|
||||
switch (xatr_id) {
|
||||
case Xatr__pos: tag_pos = Xo_custom_html_pos_.To_tid(xatr.Val_as_bry()); break;
|
||||
case Xatr__type: tag_type = Xo_custom_html_type_.To_tid(xatr.Val_as_bry()); break;
|
||||
default: throw Err_.new_unhandled(xatr_id);
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
@@ -35,32 +33,27 @@ public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_html command only allowed in xowa_home");
|
||||
return;
|
||||
}
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, 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.Page().Html_data().Custom_head_end_concat(raw);
|
||||
else
|
||||
ctx.Page().Html_data().Custom_html_end_concat(raw);
|
||||
|
||||
// parse xnde for tag_name, tag_body
|
||||
Xox_xnde_.Parse_xatrs(wiki, this, xatr_hash, src, xnde);
|
||||
byte[] name = Xo_custom_html_type_.To_bry(tag_type);
|
||||
int raw_bgn = xnde.Tag_open_end(), raw_end = xnde.Tag_close_bgn();
|
||||
raw_bgn = Bry_find_.Find_fwd_while_ws(src, raw_bgn, raw_end);
|
||||
raw_end = Bry_find_.Find_bwd__skip_ws(src, raw_end, raw_bgn);
|
||||
if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
|
||||
if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
|
||||
byte[] raw = Bry_.Mid(src, raw_bgn, raw_end);
|
||||
|
||||
// add to custom tags
|
||||
Xopg_html_data html_data = ctx.Page().Html_data();
|
||||
Xopg_tag_mgr tag_mgr = tag_pos == Xo_custom_html_pos_.Tid__tail ? html_data.Custom_tail_tags() : html_data.Custom_head_tags();
|
||||
tag_mgr.Add(new Xopg_tag_itm(name, 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 Err_.new_wo_type("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_a7()
|
||||
.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 xatrs_hash = Hash_adp_bry.ci_a7().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
|
||||
|
||||
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
|
||||
|
||||
private static final byte Xatr__pos = 1, Xatr__type = 2;
|
||||
private static final Hash_adp_bry xatr_hash = Hash_adp_bry.ci_a7().Add_str_byte("pos", Xatr__pos).Add_str_byte("type", Xatr__type);
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ 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>"
|
||||
( "<xowa_html pos='head_end'>test</xowa_html>"
|
||||
, "<html><head><style>\ntest\n</style>\n</head><body></body></html>"
|
||||
);
|
||||
}
|
||||
@Test public void Html_end() {
|
||||
@Test public void Tail() {
|
||||
fxt.Test_parse_w_skin
|
||||
( "<xowa_html pos='html.end'>test</xowa_html>"
|
||||
, "<html><head></head><body></body>test</html>"
|
||||
( "<xowa_html pos='tail'>test</xowa_html>"
|
||||
, "<html><head></head><body></body><style>\ntest\n</style>\n</html>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xox_xowa_html_cmd_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private Xowe_wiki wiki; private Xow_html_mgr html_mgr;
|
||||
public void Clear() {
|
||||
this.wiki = fxt.Wiki();
|
||||
|
||||
Reference in New Issue
Block a user