mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.4.1
This commit is contained in:
@@ -17,15 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xop_xatr_hash {
|
||||
private final OrderedHash hash = OrderedHash_.new_bry_();
|
||||
private final Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
private final byte[] src;
|
||||
Xop_xatr_hash(byte[] src) {this.src = src;}
|
||||
public int Len() {return hash.Count();}
|
||||
public Xop_xatr_itm Get_at(int idx) {
|
||||
return (Xop_xatr_itm)hash.FetchAt(idx);
|
||||
return (Xop_xatr_itm)hash.Get_at(idx);
|
||||
}
|
||||
public Xop_xatr_itm Get_by(String key) {
|
||||
return (Xop_xatr_itm)hash.Fetch(Bry_.new_utf8_(key));
|
||||
return (Xop_xatr_itm)hash.Get_by(Bry_.new_u8(key));
|
||||
}
|
||||
public byte[] Get_as_bry_or(String key, byte[] or) {
|
||||
Xop_xatr_itm itm = Get_by(key);
|
||||
@@ -36,7 +36,7 @@ public class Xop_xatr_hash {
|
||||
return String_.Eq(itm.Val_as_str(src), val);
|
||||
}
|
||||
private void Add(Xop_xatr_itm itm) {
|
||||
hash.AddReplace(itm.Key_bry(), itm);
|
||||
hash.Add_if_dupe_use_nth(itm.Key_bry(), itm);
|
||||
}
|
||||
public static Xop_xatr_hash new_ary(byte[] src, Xop_xatr_itm[] ary) {
|
||||
Xop_xatr_hash rv = new Xop_xatr_hash(src);
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Xop_xatr_itm {
|
||||
public int Eq_pos() {return eq_pos;} private int eq_pos;
|
||||
public boolean Invalid() {return tid < Tid_key_val;} // NOTE: Tid order is important
|
||||
public byte Quote_byte() {return quote_byte;} private byte quote_byte;
|
||||
public String Val_as_str(byte[] src) {return String_.new_utf8_(Val_as_bry(src));}
|
||||
public String Val_as_str(byte[] src) {return String_.new_u8(Val_as_bry(src));}
|
||||
public byte[] Val_as_bry(byte[] src) {if (val_bry == null) val_bry = Bry_.Mid(src, val_bgn, val_end); return val_bry;} // NOTE: val_bry is cached
|
||||
public byte[] Val_as_bry__blank_to_null(byte[] src) {byte[] rv = Val_as_bry(src); return Bry_.Len_eq_0(rv) ? null : rv;}
|
||||
public int Val_as_int_or(byte[] src, int or) {return val_bry == null ? Bry_.Xto_int_or_lax(src, val_bgn, val_end, or) : Bry_.Xto_int_or(val_bry, or);}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_ATTRIBS_REGEX
|
||||
private final ListAdp xatrs = ListAdp_.new_();
|
||||
private final List_adp xatrs = List_adp_.new_();
|
||||
private static final byte Mode_atr_bgn = 1, Mode_invalid = 2, Mode_key = 3, Mode_eq = 4, Mode_val_bgn = 5, Mode_val_quote = 6, Mode_val_raw = 7;
|
||||
private byte mode = Mode_atr_bgn;
|
||||
private int atr_bgn = -1, key_bgn = -1, key_end = -1, eq_pos = -1, val_bgn = -1, val_end = -1; boolean valid = true;
|
||||
@@ -351,7 +351,7 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT
|
||||
++i;
|
||||
}
|
||||
repeated_atrs_hash.Clear();
|
||||
return (Xop_xatr_itm[])xatrs.Xto_ary(Xop_xatr_itm.class);
|
||||
return (Xop_xatr_itm[])xatrs.To_ary(Xop_xatr_itm.class);
|
||||
}
|
||||
private void Make(Gfo_msg_log log_mgr, byte[] src, int atr_end) {
|
||||
Xop_xatr_itm xatr = null;
|
||||
@@ -381,7 +381,7 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT
|
||||
val_bfr_on = key_bfr_on = ws_is_before_val = false;
|
||||
}
|
||||
private void Invalidate_repeated_atr(Xop_xatr_itm cur, byte[] key_bry) {
|
||||
Xop_xatr_itm prv = (Xop_xatr_itm)repeated_atrs_hash.Fetch(key_bry);
|
||||
Xop_xatr_itm prv = (Xop_xatr_itm)repeated_atrs_hash.Get_by(key_bry);
|
||||
if (prv != null) {
|
||||
prv.Tid_to_repeat_();
|
||||
repeated_atrs_hash.Del(key_bry);
|
||||
|
||||
@@ -66,14 +66,14 @@ class Xop_xatr_parser_fxt {
|
||||
public Xop_xatr_itm_chkr new_invalid_(int bgn, int end) {return new Xop_xatr_itm_chkr().Expd_atr_rng_(bgn, end).Expd_typeId_(Xop_xatr_itm.Tid_invalid);}
|
||||
public Xop_xatr_itm_chkr new_atr_(String key, String val) {return new Xop_xatr_itm_chkr().Expd_key_(key).Expd_val_(val);}
|
||||
public void tst_(String src_str, Xop_xatr_itm_chkr... expd) {
|
||||
byte[] src = Bry_.new_utf8_(src_str);
|
||||
byte[] src = Bry_.new_u8(src_str);
|
||||
Gfo_msg_log msg_log = new Gfo_msg_log(Xoa_app_.Name);
|
||||
Xop_xatr_itm[] actl = parser.Parse(msg_log, src, 0, src.length);
|
||||
tst_mgr.Vars().Clear().Add("raw_bry", src);
|
||||
tst_mgr.Tst_ary("xatr:", expd, actl);
|
||||
}
|
||||
public void tst_int(String src_str, int... expd) {
|
||||
byte[] src = Bry_.new_utf8_(src_str);
|
||||
byte[] src = Bry_.new_u8(src_str);
|
||||
Gfo_msg_log msg_log = new Gfo_msg_log(Xoa_app_.Name);
|
||||
Xop_xatr_itm[] actl_atr = parser.Parse(msg_log, src, 0, src.length);
|
||||
int[] actl = new int[actl_atr.length];
|
||||
@@ -101,11 +101,11 @@ class Xop_xatr_itm_chkr implements Tst_chkr {
|
||||
if (actl.Key_bry() == null)
|
||||
err += mgr.Tst_val(expd_key == null, path, "key", expd_key, mgr.Vars_get_bry_as_str("raw_bry", actl.Key_bgn(), actl.Key_end()));
|
||||
else
|
||||
err += mgr.Tst_val(expd_key == null, path, "key", expd_key, String_.new_utf8_(actl.Key_bry()));
|
||||
err += mgr.Tst_val(expd_key == null, path, "key", expd_key, String_.new_u8(actl.Key_bry()));
|
||||
if (actl.Val_bry() == null)
|
||||
err += mgr.Tst_val(expd_val == null, path, "val", expd_val, mgr.Vars_get_bry_as_str("raw_bry", actl.Val_bgn(), actl.Val_end()));
|
||||
else
|
||||
err += mgr.Tst_val(expd_val == null, path, "val", expd_val, String_.new_utf8_(actl.Val_bry()));
|
||||
err += mgr.Tst_val(expd_val == null, path, "val", expd_val, String_.new_u8(actl.Val_bry()));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,15 +126,15 @@ public class Xop_xatr_whitelist_mgr {
|
||||
private void Ini_grp(String key_str, String base_grp, String... cur_itms) {
|
||||
byte[][] itms = Bry_.Ary(cur_itms);
|
||||
if (base_grp != null)
|
||||
itms = Bry_.Ary_add(itms, (byte[][])grp_hash.Get_by_bry(Bry_.new_ascii_(base_grp)));
|
||||
byte[] key = Bry_.new_ascii_(key_str);
|
||||
itms = Bry_.Ary_add(itms, (byte[][])grp_hash.Get_by_bry(Bry_.new_a7(base_grp)));
|
||||
byte[] key = Bry_.new_a7(key_str);
|
||||
grp_hash.Add_bry_obj(key, itms);
|
||||
}
|
||||
private void Ini_nde(int tag_tid, String... key_strs) {
|
||||
ListAdp keys = ListAdp_.new_();
|
||||
List_adp keys = List_adp_.new_();
|
||||
int len = key_strs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] key = Bry_.new_ascii_(key_strs[i]);
|
||||
byte[] key = Bry_.new_a7(key_strs[i]);
|
||||
Object grp_obj = grp_hash.Get_by_bry(key); // is the key a grp? EX: "common"
|
||||
if (grp_obj == null)
|
||||
keys.Add(key);
|
||||
@@ -147,7 +147,7 @@ public class Xop_xatr_whitelist_mgr {
|
||||
}
|
||||
len = keys.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] key_bry = (byte[])keys.FetchAt(i);
|
||||
byte[] key_bry = (byte[])keys.Get_at(i);
|
||||
Xop_xatr_whitelist_itm itm = (Xop_xatr_whitelist_itm)key_trie.Match_exact(key_bry, 0, key_bry.length);
|
||||
if (itm == null) {
|
||||
itm = Ini_key_trie_add(key_bry, true);
|
||||
@@ -157,7 +157,7 @@ public class Xop_xatr_whitelist_mgr {
|
||||
}
|
||||
}
|
||||
private void Ini_all_loose(String key_str) {
|
||||
byte[] key_bry = Bry_.new_ascii_(key_str);
|
||||
byte[] key_bry = Bry_.new_a7(key_str);
|
||||
Ini_key_trie_add(key_bry, false);
|
||||
Xop_xatr_whitelist_itm itm = Ini_key_trie_add(key_bry, false);
|
||||
key_trie.Add_obj(key_bry, itm);
|
||||
@@ -166,7 +166,7 @@ public class Xop_xatr_whitelist_mgr {
|
||||
itm.Tags()[i] = 1;
|
||||
}
|
||||
private Xop_xatr_whitelist_itm Ini_key_trie_add(byte[] key, boolean exact) {
|
||||
Object key_tid_obj = tid_hash.Fetch(key);
|
||||
Object key_tid_obj = tid_hash.Get_by(key);
|
||||
byte key_tid = key_tid_obj == null ? Xop_xatr_itm.Key_tid_generic : ((Byte_obj_val)key_tid_obj).Val();
|
||||
Xop_xatr_whitelist_itm rv = new Xop_xatr_whitelist_itm(key, key_tid, exact);
|
||||
key_trie.Add_obj(key, rv);
|
||||
@@ -251,7 +251,7 @@ public class Xop_xatr_whitelist_mgr {
|
||||
.Add_str_byte("image-set" , Style_image_set)
|
||||
.Add_str_byte("/*" , Style_comment)
|
||||
;
|
||||
private static final byte[] Val_role_presentation = Bry_.new_ascii_("presentation");
|
||||
private static final byte[] Val_role_presentation = Bry_.new_a7("presentation");
|
||||
}
|
||||
class Xop_xatr_whitelist_itm {
|
||||
public Xop_xatr_whitelist_itm(byte[] key, byte key_tid, boolean exact) {this.key = key; this.key_tid = key_tid; this.exact = exact;}
|
||||
|
||||
@@ -50,22 +50,22 @@ class Xop_xatr_whitelist_fxt {
|
||||
if (whitelist_mgr == null) whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
} private Xop_xatr_whitelist_mgr whitelist_mgr;
|
||||
public void Whitelist(byte tag_id, String key_str, boolean expd) {
|
||||
byte[] key_bry = Bry_.new_ascii_(key_str);
|
||||
byte[] key_bry = Bry_.new_a7(key_str);
|
||||
atr_itm.Key_rng_(0, key_bry.length);
|
||||
Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, key_bry, atr_itm), key_str);
|
||||
} private Xop_xatr_itm atr_itm = new Xop_xatr_itm(0, 0);
|
||||
public void Whitelist(byte tag_id, String key_str, String val_str, boolean expd) {
|
||||
byte[] key_bry = Bry_.new_ascii_(key_str);
|
||||
byte[] key_bry = Bry_.new_a7(key_str);
|
||||
atr_itm.Key_rng_(0, key_bry.length);
|
||||
atr_itm.Val_bry_(Bry_.new_ascii_(val_str));
|
||||
atr_itm.Val_bry_(Bry_.new_a7(val_str));
|
||||
Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, key_bry, atr_itm), key_str);
|
||||
}
|
||||
public void Scrub_style_pass(String style_val_str) {Scrub_style(style_val_str, style_val_str);}
|
||||
public void Scrub_style_fail(String val_str) {Scrub_style(val_str, "");}
|
||||
public void Scrub_style(String val_str, String expd) {
|
||||
byte[] val_bry = Bry_.new_ascii_(val_str);
|
||||
byte[] val_bry = Bry_.new_a7(val_str);
|
||||
atr_itm.Val_bry_(val_bry);
|
||||
whitelist_mgr.Scrub_style(atr_itm, val_bry);
|
||||
Tfds.Eq(expd, String_.new_ascii_(atr_itm.Val_bry()));
|
||||
Tfds.Eq(expd, String_.new_a7(atr_itm.Val_bry()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.primitives.*;
|
||||
public class Xop_xnde_tag {
|
||||
public Xop_xnde_tag(int id, String name_str) { // NOTE: should only be used by Xop_xnde_tag_
|
||||
this.id = id;
|
||||
this.name_bry = Bry_.new_ascii_(name_str);
|
||||
this.name_bry = Bry_.new_a7(name_str);
|
||||
this.name_str = name_str;
|
||||
name_len = name_bry.length;
|
||||
xtn_end_tag = Bry_.Add(Xop_xnde_tag_.XtnEndTag_bgn, name_bry); // always force endtag; needed for <noinclude>
|
||||
@@ -56,10 +56,10 @@ public class Xop_xnde_tag {
|
||||
public boolean Xtn_auto_close() {return xtn_auto_close;} public Xop_xnde_tag Xtn_auto_close_() {xtn_auto_close = true; return this;} private boolean xtn_auto_close;
|
||||
public boolean Ignore_empty() {return ignore_empty;} public Xop_xnde_tag Ignore_empty_() {ignore_empty = true; return this;} private boolean ignore_empty;
|
||||
public boolean Xtn_skips_template_args() {return xtn_skips_template_args;} public Xop_xnde_tag Xtn_skips_template_args_() {xtn_skips_template_args = true; return this;} private boolean xtn_skips_template_args;
|
||||
public OrderedHash Langs() {return langs;} private OrderedHash langs; private Int_obj_ref langs_key;
|
||||
public Ordered_hash Langs() {return langs;} private Ordered_hash langs; private Int_obj_ref langs_key;
|
||||
public Xop_xnde_tag Langs_(int lang_code, String name) {
|
||||
if (langs == null) {
|
||||
langs = OrderedHash_.new_();
|
||||
langs = Ordered_hash_.new_();
|
||||
langs_key = Int_obj_ref.neg1_();
|
||||
}
|
||||
Xop_xnde_tag_lang lang_tag = new Xop_xnde_tag_lang(lang_code, name);
|
||||
@@ -72,7 +72,7 @@ public class Xop_xnde_tag {
|
||||
synchronized (langs) {
|
||||
langs_key.Val_(cur_lang);
|
||||
}
|
||||
Xop_xnde_tag_lang lang = (Xop_xnde_tag_lang)langs.Fetch(langs_key);
|
||||
Xop_xnde_tag_lang lang = (Xop_xnde_tag_lang)langs.Get_by(langs_key);
|
||||
if (lang == null) return null; // cur tag is a lang tag, but no tag for this lang; EX: "<trecho>" and cur_lang=de
|
||||
return Bry_.Eq_ci_ascii(lang.Name_bry(), src, bgn, end)
|
||||
? lang
|
||||
|
||||
@@ -20,8 +20,8 @@ import gplx.xowa.langs.*;
|
||||
public class Xop_xnde_tag_ {
|
||||
public static final int EndNdeMode_normal = 0, EndNdeMode_inline = 1, EndNdeMode_escape = 2; // escape is for hr which does not support </hr>
|
||||
public static final int BgnNdeMode_normal = 0, BgnNdeMode_inline = 1;
|
||||
public static final byte[] Name_onlyinclude = Bry_.new_ascii_("onlyinclude");
|
||||
public static final byte[] XtnEndTag_bgn = Bry_.new_ascii_("</");//, XtnEndTag_end = Bry_.new_ascii_(">");
|
||||
public static final byte[] Name_onlyinclude = Bry_.new_a7("onlyinclude");
|
||||
public static final byte[] XtnEndTag_bgn = Bry_.new_a7("</");//, XtnEndTag_end = Bry_.new_a7(">");
|
||||
public static final byte
|
||||
Tid_b = 0
|
||||
, Tid_strong = 1
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Xop_xnde_tag_lang {
|
||||
public Xop_xnde_tag_lang(int lang_code_int, String name_str) {
|
||||
lang_code = Int_obj_ref.new_(lang_code_int);
|
||||
this.name_str = name_str;
|
||||
this.name_bry = Bry_.new_utf8_(name_str);
|
||||
this.name_bry = Bry_.new_u8(name_str);
|
||||
this.xtnEndTag_tmp = Bry_.Add(Xop_xnde_tag_.XtnEndTag_bgn, name_bry);
|
||||
}
|
||||
public Int_obj_ref Lang_code() {return lang_code;} private Int_obj_ref lang_code;
|
||||
|
||||
@@ -33,21 +33,21 @@ public class Xop_xnde_tag_regy {
|
||||
Init_reg(tag_regy_wiki_main , Xop_xnde_tag_.Ary);
|
||||
}
|
||||
private Xop_xnde_tag[] FilterXtns(Xop_xnde_tag[] ary, Xop_xnde_tag... more) {
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
List_adp rv = List_adp_.new_();
|
||||
for (Xop_xnde_tag itm : ary)
|
||||
if (itm.Xtn()) rv.Add(itm);
|
||||
for (Xop_xnde_tag itm : more)
|
||||
rv.Add(itm);
|
||||
return (Xop_xnde_tag[])rv.Xto_ary(Xop_xnde_tag.class);
|
||||
return (Xop_xnde_tag[])rv.To_ary(Xop_xnde_tag.class);
|
||||
}
|
||||
private void Init_reg(Btrie_slim_mgr tag_regy, Xop_xnde_tag... ary) {
|
||||
for (Xop_xnde_tag tag : ary) {
|
||||
tag_regy.Add_obj(tag.Name_bry(), tag);
|
||||
OrderedHash langs = tag.Langs();
|
||||
Ordered_hash langs = tag.Langs();
|
||||
if (langs != null) { // tag has langs; EX: <section>; DATE:2014-07-18
|
||||
int langs_len = langs.Count();
|
||||
for (int i = 0; i < langs_len; ++i) { // register each lang's tag; EX:"<Abschnitt>", "<trecho>"
|
||||
Xop_xnde_tag_lang lang = (Xop_xnde_tag_lang)langs.FetchAt(i);
|
||||
Xop_xnde_tag_lang lang = (Xop_xnde_tag_lang)langs.Get_at(i);
|
||||
tag_regy.Add_obj(lang.Name_bry(), tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xop_xnde_tag_stack {
|
||||
public void Push() {xmlTagsStack.Add(xmlTags); xmlTags = new int[Xop_xnde_tag_._MaxLen];}
|
||||
public void Pop() {xmlTags = (int[])ListAdp_.Pop(xmlTagsStack);}
|
||||
public void Pop() {xmlTags = (int[])List_adp_.Pop(xmlTagsStack);}
|
||||
public boolean Has(int id) {return xmlTags[id] != 0;}
|
||||
public void Add(int id) {++xmlTags[id];}
|
||||
public void Del(int id) {
|
||||
@@ -30,6 +30,6 @@ public class Xop_xnde_tag_stack {
|
||||
xmlTags[i] = 0;
|
||||
xmlTagsStack.Clear();
|
||||
}
|
||||
ListAdp xmlTagsStack = ListAdp_.new_();
|
||||
List_adp xmlTagsStack = List_adp_.new_();
|
||||
int[] xmlTags = new int[Xop_xnde_tag_._MaxLen];
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
|
||||
if (tag.Restricted()) {
|
||||
Xoae_page page = ctx.Cur_page();
|
||||
if ( page.Html_data().Html_restricted()
|
||||
&& page.Wiki().Domain_tid() != Xow_domain_.Tid_int_home) {
|
||||
&& page.Wiki().Domain_tid() != Xow_domain_type_.Tid_home) {
|
||||
int end_pos = gtPos + 1;
|
||||
ctx.Subs_add(root, tkn_mkr.Bry_raw(bgn_pos, end_pos, Bry_.Add(gplx.html.Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, end_pos)))); // +1 to skip <
|
||||
return end_pos;
|
||||
@@ -689,8 +689,8 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
|
||||
xnde_xtn.Xtn_parse(ctx.Wiki(), ctx, root, src, xnde);
|
||||
}
|
||||
catch (Exception e) {
|
||||
String err_msg = String_.Format("failed to render extension: title={0} excerpt={1} err={2}", String_.new_utf8_(ctx.Cur_page().Ttl().Full_txt())
|
||||
, String_.new_utf8_(src, xnde.Tag_open_end(), xnde.Tag_close_bgn())
|
||||
String err_msg = String_.Format("failed to render extension: title={0} excerpt={1} err={2}", String_.new_u8(ctx.Cur_page().Ttl().Full_txt())
|
||||
, String_.new_u8(src, xnde.Tag_open_end(), xnde.Tag_close_bgn())
|
||||
, Err_.Message_gplx_brief(e));
|
||||
if (Env_.Mode_testing())
|
||||
throw Err_.err_(e, err_msg);
|
||||
@@ -711,7 +711,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
|
||||
return rv;
|
||||
}
|
||||
private static final byte[]
|
||||
Bry_escape_lt_slash = Bry_.new_ascii_("</")
|
||||
Bry_escape_lt_slash = Bry_.new_a7("</")
|
||||
;
|
||||
public static int Find_gt_pos(Xop_ctx ctx, byte[] src, int cur_pos, int src_len) { // UNUSED
|
||||
int gt_pos = -1; // find closing >
|
||||
|
||||
Reference in New Issue
Block a user