mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Skin: Change to mustache-backed Skin.Vector [#797]
This commit is contained in:
parent
5c3d6a173b
commit
19a315b8cd
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -14,9 +14,10 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx;
|
package gplx;
|
||||||
import java.lang.*;
|
|
||||||
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.ios.*;
|
import gplx.core.primitives.Int_obj_ref;
|
||||||
import gplx.langs.htmls.entitys.*;
|
import gplx.langs.htmls.entitys.Gfh_entity_;
|
||||||
|
|
||||||
public class Bry_ {
|
public class Bry_ {
|
||||||
public static final String Cls_val_name = "byte[]";
|
public static final String Cls_val_name = "byte[]";
|
||||||
public static final byte[] Empty = new byte[0];
|
public static final byte[] Empty = new byte[0];
|
||||||
@ -475,6 +476,19 @@ public class Bry_ {
|
|||||||
else
|
else
|
||||||
return Bry_.Mid(src, txt_bgn, txt_end);
|
return Bry_.Mid(src, txt_bgn, txt_end);
|
||||||
}
|
}
|
||||||
|
public static byte[] Trim_bgn(byte[] v, byte trim, int bgn) {
|
||||||
|
boolean trimmed = false;
|
||||||
|
int len = v.length;
|
||||||
|
int pos = bgn;
|
||||||
|
for (; pos < len; pos++) {
|
||||||
|
if (v[pos] == trim) {
|
||||||
|
trimmed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return trimmed ? Bry_.Mid(v, pos, len) : v;
|
||||||
|
}
|
||||||
public static byte[] Trim_end(byte[] v, byte trim, int end) {
|
public static byte[] Trim_end(byte[] v, byte trim, int end) {
|
||||||
boolean trimmed = false;
|
boolean trimmed = false;
|
||||||
int pos = end - 1; // NOTE: -1 b/c callers will always be passing pos + 1; EX: src, src_len
|
int pos = end - 1; // NOTE: -1 b/c callers will always be passing pos + 1; EX: src, src_len
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -14,7 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx;
|
package gplx;
|
||||||
import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.tests.*;
|
|
||||||
|
import gplx.core.primitives.Int_obj_ref;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Bry__tst {
|
public class Bry__tst {
|
||||||
private final Bry__fxt fxt = new Bry__fxt();
|
private final Bry__fxt fxt = new Bry__fxt();
|
||||||
@Test public void new_ascii_() {
|
@Test public void new_ascii_() {
|
||||||
@ -256,6 +260,12 @@ public class Bry__tst {
|
|||||||
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
|
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
|
||||||
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
|
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
|
||||||
}
|
}
|
||||||
|
@Test public void Trim_bgn() {
|
||||||
|
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.one
|
||||||
|
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.many
|
||||||
|
fxt.Test_trim_bgn("a" , Byte_ascii.Space, "a"); // trim.none
|
||||||
|
fxt.Test_trim_bgn("" , Byte_ascii.Space, ""); // empty
|
||||||
|
}
|
||||||
@Test public void Trim_end() {
|
@Test public void Trim_end() {
|
||||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
|
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
|
||||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
|
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
|
||||||
@ -288,6 +298,10 @@ class Bry__fxt {
|
|||||||
byte[] raw_bry = Bry_.new_a7(raw);
|
byte[] raw_bry = Bry_.new_a7(raw);
|
||||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
|
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
|
||||||
}
|
}
|
||||||
|
public void Test_trim_bgn(String raw, byte trim, String expd) {
|
||||||
|
byte[] raw_bry = Bry_.new_a7(raw);
|
||||||
|
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_bgn(raw_bry, trim, 0)));
|
||||||
|
}
|
||||||
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
|
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
|
||||||
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
|
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
|
||||||
public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));}
|
public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,24 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
package gplx.core.gfobjs;
|
||||||
import gplx.langs.jsons.*;
|
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.Io_mgr;
|
||||||
|
import gplx.Io_url;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_itm_;
|
||||||
|
import gplx.langs.jsons.Json_itm_bool;
|
||||||
|
import gplx.langs.jsons.Json_itm_decimal;
|
||||||
|
import gplx.langs.jsons.Json_itm_int;
|
||||||
|
import gplx.langs.jsons.Json_itm_long;
|
||||||
|
import gplx.langs.jsons.Json_itm_str;
|
||||||
|
import gplx.langs.jsons.Json_kv;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.jsons.Json_parser;
|
||||||
|
|
||||||
public class Gfobj_rdr__json {
|
public class Gfobj_rdr__json {
|
||||||
private final Json_parser parser = new Json_parser();
|
private final Json_parser parser = new Json_parser();
|
||||||
public Gfobj_grp Load(Io_url url) {
|
public Gfobj_grp Load(Io_url url) {
|
||||||
@ -56,7 +72,7 @@ public class Gfobj_rdr__json {
|
|||||||
case Json_itm_.Tid__nde:
|
case Json_itm_.Tid__nde:
|
||||||
Gfobj_nde sub_gnde = Gfobj_nde.New();
|
Gfobj_nde sub_gnde = Gfobj_nde.New();
|
||||||
gnde.Add_nde(key_str, sub_gnde);
|
gnde.Add_nde(key_str, sub_gnde);
|
||||||
Parse_nde(Json_nde.cast(val), sub_gnde);
|
Parse_nde(Json_nde.Cast(val), sub_gnde);
|
||||||
break;
|
break;
|
||||||
default: throw Err_.new_unhandled_default(val_tid);
|
default: throw Err_.new_unhandled_default(val_tid);
|
||||||
}
|
}
|
||||||
@ -77,7 +93,7 @@ public class Gfobj_rdr__json {
|
|||||||
}
|
}
|
||||||
case Json_itm_.Tid__nde: {
|
case Json_itm_.Tid__nde: {
|
||||||
Gfobj_nde sub_ary = Gfobj_nde.New();
|
Gfobj_nde sub_ary = Gfobj_nde.New();
|
||||||
Parse_nde(Json_nde.cast(jsub), sub_ary);
|
Parse_nde(Json_nde.Cast(jsub), sub_ary);
|
||||||
ary[i] = sub_ary;
|
ary[i] = sub_ary;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
69
400_xowa/src/gplx/langs/jsons/JsonDocBldr.java
Normal file
69
400_xowa/src/gplx/langs/jsons/JsonDocBldr.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.String_;
|
||||||
|
|
||||||
|
public class JsonDocBldr {
|
||||||
|
private final List_adp stack = List_adp_.New();
|
||||||
|
private final Json_doc doc = new Json_doc();
|
||||||
|
private Json_grp root;
|
||||||
|
private Json_grp cur;
|
||||||
|
JsonDocBldr() {}
|
||||||
|
public JsonDocBldr Clear(boolean isRootNode) {
|
||||||
|
this.root = isRootNode ? Json_nde.NewByDoc(doc, 0) : Json_ary.NewByDoc(doc, 0, 0);
|
||||||
|
doc.Ctor(Bry_.Empty, root);
|
||||||
|
this.cur = root;
|
||||||
|
stack.Clear();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public JsonDocBldr NdeBgn(String key) {
|
||||||
|
Json_nde nde = Json_nde.NewByDoc(doc, 1);
|
||||||
|
if (cur.Tid() == Json_itm_.Tid__nde) {
|
||||||
|
Json_kv kv = new Json_kv(Json_itm_str.NewByVal(key), nde);
|
||||||
|
cur.Add(kv);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cur.Add(nde);
|
||||||
|
}
|
||||||
|
stack.Add(cur);
|
||||||
|
cur = nde;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public JsonDocBldr NdeEnd() {
|
||||||
|
this.cur = (Json_grp)List_adp_.Pop_last(stack);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public JsonDocBldr KvBool(String key, boolean val) {return Kv(key, Json_itm_bool.Get(val));}
|
||||||
|
public JsonDocBldr KvInt(String key, int val) {return Kv(key, Json_itm_int.NewByVal(val));}
|
||||||
|
public JsonDocBldr KvStr(String key, byte[] val) {return Kv(key, Json_itm_str.NewByVal(String_.new_u8(val)));}
|
||||||
|
public JsonDocBldr KvStr(String key, String val) {return Kv(key, Json_itm_str.NewByVal(val));}
|
||||||
|
private JsonDocBldr Kv(String key, Json_itm val) {
|
||||||
|
Json_kv rv = new Json_kv(Json_itm_str.NewByVal(key), val);
|
||||||
|
cur.Add(rv);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public Json_doc ToDoc() {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
public Json_nde ToRootNde() {
|
||||||
|
return doc.Root_nde();
|
||||||
|
}
|
||||||
|
public static JsonDocBldr NewRootNde() {return new JsonDocBldr().Clear(true);}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,11 +13,18 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Array_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Err_;
|
||||||
|
|
||||||
public class Json_ary extends Json_itm_base implements Json_grp {
|
public class Json_ary extends Json_itm_base implements Json_grp {
|
||||||
public Json_ary(int src_bgn, int src_end) {this.Ctor(src_bgn, src_end);}
|
private Json_ary() {}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__ary;}
|
@Override public byte Tid() {return Json_itm_.Tid__ary;}
|
||||||
public void Src_end_(int v) {this.src_end = v;}
|
public void Src_end_(int v) {}
|
||||||
@Override public Object Data() {return null;}
|
@Override public Object Data() {return null;}
|
||||||
@Override public byte[] Data_bry() {return null;}
|
@Override public byte[] Data_bry() {return null;}
|
||||||
public int Len() {return subs_len;} private int subs_len = 0, subs_max = 0;
|
public int Len() {return subs_len;} private int subs_len = 0, subs_max = 0;
|
||||||
@ -26,7 +33,7 @@ public class Json_ary extends Json_itm_base implements Json_grp {
|
|||||||
return (Json_nde)rv;
|
return (Json_nde)rv;
|
||||||
}
|
}
|
||||||
public Json_itm Get_at(int i) {return subs[i];}
|
public Json_itm Get_at(int i) {return subs[i];}
|
||||||
public Json_nde Get_as_nde(int i) {return Json_nde.cast(subs[i]);}
|
public Json_nde Get_as_nde(int i) {return Json_nde.Cast(subs[i]);}
|
||||||
public Json_ary Add_many(Json_itm... ary) {
|
public Json_ary Add_many(Json_itm... ary) {
|
||||||
int len = ary.length;
|
int len = ary.length;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
@ -75,4 +82,6 @@ public class Json_ary extends Json_itm_base implements Json_grp {
|
|||||||
if (v == null || v.Tid() != Json_itm_.Tid__ary) throw Err_.new_("json", "itm is not array");
|
if (v == null || v.Tid() != Json_itm_.Tid__ary) throw Err_.new_("json", "itm is not array");
|
||||||
return (Json_ary)v;
|
return (Json_ary)v;
|
||||||
}
|
}
|
||||||
|
public static Json_ary NewByDoc(Json_doc doc, int src_bgn, int src_end) {return new Json_ary();}
|
||||||
|
public static Json_ary NewByVal() {return new Json_ary();}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,15 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import gplx.core.primitives.*;
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.primitives.Gfo_number_parser;
|
||||||
|
|
||||||
public class Json_doc {
|
public class Json_doc {
|
||||||
private final byte[][] tmp_qry_bry = new byte[1][];
|
private final byte[][] tmp_qry_bry = new byte[1][];
|
||||||
public void Ctor(byte[] src, Json_grp new_root) {
|
public void Ctor(byte[] src, Json_grp new_root) {
|
||||||
@ -66,10 +73,10 @@ public class Json_doc {
|
|||||||
byte[] path = paths[paths_idx];
|
byte[] path = paths[paths_idx];
|
||||||
int subs_len = owner.Len();
|
int subs_len = owner.Len();
|
||||||
for (int i = 0; i < subs_len; i++) {
|
for (int i = 0; i < subs_len; i++) {
|
||||||
Json_kv itm = Json_kv.cast(owner.Get_at(i)); if (itm == null) continue; // ignore simple props, arrays, ndes
|
Json_kv itm = Json_kv.Cast(owner.Get_at(i)); if (itm == null) continue; // ignore simple props, arrays, ndes
|
||||||
if (!itm.Key_eq(path)) continue;
|
if (!itm.Key_eq(path)) continue;
|
||||||
if (paths_idx == paths_last) return itm.Val();
|
if (paths_idx == paths_last) return itm.Val();
|
||||||
Json_nde sub_nde = Json_nde.cast(itm.Val()); if (sub_nde == null) return null; // match, but has not a nde; exit
|
Json_nde sub_nde = Json_nde.Cast(itm.Val()); if (sub_nde == null) return null; // match, but has not a nde; exit
|
||||||
return Find_nde(sub_nde, paths, paths_last, paths_idx + 1);
|
return Find_nde(sub_nde, paths, paths_last, paths_idx + 1);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
XOWA: the XOWA Offline Wiki Application
|
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
|
||||||
|
|
||||||
You may use XOWA according to either of these licenses as is most appropriate
|
|
||||||
for your project on a case-by-case basis.
|
|
||||||
|
|
||||||
The terms of each license can be found in the source code repository:
|
|
||||||
|
|
||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
||||||
*/
|
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
|
||||||
public class Json_doc_bldr {
|
|
||||||
public Json_nde Nde(Json_doc jdoc) {return factory.Nde(jdoc, -1);}
|
|
||||||
public Json_nde Nde(Json_doc jdoc, Json_grp owner) {
|
|
||||||
Json_nde rv = factory.Nde(jdoc, -1);
|
|
||||||
owner.Add(rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
public Json_itm Str(byte[] v) {return Str(String_.new_u8(v));}
|
|
||||||
public Json_itm Str(String v) {return Json_itm_tmp.new_str_(v);}
|
|
||||||
public Json_itm Int(int v) {return Json_itm_tmp.new_int_(v);}
|
|
||||||
public Json_kv Kv_int(Json_grp owner, String key, int val) {Json_kv rv = factory.Kv(Json_itm_tmp.new_str_(key), Json_itm_tmp.new_int_(val)); owner.Add(rv); return rv;}
|
|
||||||
public Json_kv Kv_str(Json_grp owner, String key, String val) {Json_kv rv = factory.Kv(Json_itm_tmp.new_str_(key), Json_itm_tmp.new_str_(val)); owner.Add(rv); return rv;}
|
|
||||||
public Json_ary Kv_ary(Json_grp owner, String key, Json_itm... subs) {
|
|
||||||
Json_itm key_itm = Json_itm_tmp.new_str_(key);
|
|
||||||
Json_ary val_ary = factory.Ary(-1, -1);
|
|
||||||
Json_kv kv = factory.Kv(key_itm, val_ary);
|
|
||||||
owner.Add(kv);
|
|
||||||
int len = subs.length;
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
val_ary.Add(subs[i]);
|
|
||||||
return val_ary;
|
|
||||||
}
|
|
||||||
Json_doc doc = new Json_doc(); Json_factory factory = new Json_factory();
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,9 +13,20 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import gplx.objects.strings.unicodes.*;
|
|
||||||
import gplx.core.encoders.*;
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Double_;
|
||||||
|
import gplx.Object_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.encoders.Hex_utl_;
|
||||||
|
import gplx.objects.strings.unicodes.Ustring;
|
||||||
|
import gplx.objects.strings.unicodes.Ustring_;
|
||||||
|
|
||||||
public class Json_doc_wtr {
|
public class Json_doc_wtr {
|
||||||
private int indent = -2;
|
private int indent = -2;
|
||||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||||
@ -96,6 +107,7 @@ public class Json_doc_wtr {
|
|||||||
bfr.Add_byte_nl();
|
bfr.Add_byte_nl();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public Json_doc_wtr Kv(boolean comma, String key, byte[] val) {return Kv(comma, Bry_.new_u8(key), val);}
|
||||||
public Json_doc_wtr Kv(boolean comma, byte[] key, byte[] val) {
|
public Json_doc_wtr Kv(boolean comma, byte[] key, byte[] val) {
|
||||||
Key_internal(comma, key);
|
Key_internal(comma, key);
|
||||||
Str(val);
|
Str(val);
|
||||||
@ -108,12 +120,15 @@ public class Json_doc_wtr {
|
|||||||
bfr.Add_byte_nl();
|
bfr.Add_byte_nl();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public Json_doc_wtr Kv(boolean comma, String key, int v) {return Kv(comma, Bry_.new_u8(key), v);}
|
||||||
public Json_doc_wtr Kv(boolean comma, byte[] key, int v) {
|
public Json_doc_wtr Kv(boolean comma, byte[] key, int v) {
|
||||||
Key_internal(comma, key);
|
Key_internal(comma, key);
|
||||||
Int(v);
|
Int(v);
|
||||||
bfr.Add_byte_nl();
|
bfr.Add_byte_nl();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public Json_doc_wtr Kv(boolean comma, String key, double v) {return Kv(comma, Bry_.new_u8(key), Bry_.new_u8(Double_.To_str(v)));}
|
||||||
|
public Json_doc_wtr Kv(boolean comma, String key, boolean v) {return Kv(comma, Bry_.new_u8(key), v ? Bool_.Y_bry : Bool_.N_bry);}
|
||||||
public Json_doc_wtr Key(boolean comma, String key) {return Key(comma, Bry_.new_u8(key));}
|
public Json_doc_wtr Key(boolean comma, String key) {return Key(comma, Bry_.new_u8(key));}
|
||||||
public Json_doc_wtr Key(boolean comma, byte[] key) {
|
public Json_doc_wtr Key(boolean comma, byte[] key) {
|
||||||
Key_internal(comma, key);
|
Key_internal(comma, key);
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
XOWA: the XOWA Offline Wiki Application
|
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
|
||||||
|
|
||||||
You may use XOWA according to either of these licenses as is most appropriate
|
|
||||||
for your project on a case-by-case basis.
|
|
||||||
|
|
||||||
The terms of each license can be found in the source code repository:
|
|
||||||
|
|
||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
||||||
*/
|
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
|
||||||
public class Json_factory {
|
|
||||||
public Json_itm Null() {return Json_itm_null.Null;}
|
|
||||||
public Json_itm Bool_n() {return Json_itm_bool.Bool_n;}
|
|
||||||
public Json_itm Bool_y() {return Json_itm_bool.Bool_y;}
|
|
||||||
public Json_itm_int Int(Json_doc doc, int bgn, int end) {return new Json_itm_int(doc, bgn, end);}
|
|
||||||
public Json_itm_long Long(Json_doc doc, int bgn, int end) {return new Json_itm_long(doc, bgn, end);}
|
|
||||||
public Json_itm Decimal(Json_doc doc, int bgn, int end) {return new Json_itm_decimal(doc, bgn, end);}
|
|
||||||
public Json_itm Str(Json_doc doc, int bgn, int end, boolean exact) {return new Json_itm_str(doc, bgn, end, exact);}
|
|
||||||
public Json_kv Kv(Json_itm key, Json_itm val) {return new Json_kv(key, val);}
|
|
||||||
public Json_ary Ary(int bgn, int end) {return new Json_ary(bgn, end);}
|
|
||||||
public Json_nde Nde(Json_doc doc, int bgn) {return new Json_nde(doc, bgn);}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,18 +13,20 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Object_;
|
||||||
|
|
||||||
public interface Json_itm {
|
public interface Json_itm {
|
||||||
byte Tid();
|
byte Tid();
|
||||||
int Src_bgn();
|
|
||||||
int Src_end();
|
|
||||||
Object Data();
|
Object Data();
|
||||||
byte[] Data_bry();
|
byte[] Data_bry();
|
||||||
void Print_as_json(Bry_bfr bfr, int depth);
|
|
||||||
boolean Data_eq(byte[] comp);
|
boolean Data_eq(byte[] comp);
|
||||||
|
void Print_as_json(Bry_bfr bfr, int depth);
|
||||||
}
|
}
|
||||||
class Json_itm_null extends Json_itm_base {
|
class Json_itm_null extends Json_itm_base {
|
||||||
Json_itm_null() {this.Ctor(-1, -1);}
|
Json_itm_null() {}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__null;}
|
@Override public byte Tid() {return Json_itm_.Tid__null;}
|
||||||
@Override public Object Data() {return null;}
|
@Override public Object Data() {return null;}
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(Object_.Bry__null);}
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(Object_.Bry__null);}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,15 +13,20 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
|
||||||
public abstract class Json_itm_base implements Json_itm {
|
public abstract class Json_itm_base implements Json_itm {
|
||||||
public abstract byte Tid();
|
public abstract byte Tid();
|
||||||
public void Ctor(int src_bgn, int src_end) {this.src_bgn = src_bgn; this.src_end = src_end;}
|
|
||||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
|
||||||
public int Src_end() {return src_end;} protected int src_end;
|
|
||||||
public abstract Object Data();
|
public abstract Object Data();
|
||||||
public abstract byte[] Data_bry();
|
public abstract byte[] Data_bry();
|
||||||
public String Print_as_json() {Bry_bfr bfr = Bry_bfr_.New(); Print_as_json(bfr, 0); return bfr.To_str_and_clear();}
|
public String Print_as_json() {
|
||||||
|
Bry_bfr bfr = Bry_bfr_.New();
|
||||||
|
Print_as_json(bfr, 0);
|
||||||
|
return bfr.To_str_and_clear();
|
||||||
|
}
|
||||||
public abstract void Print_as_json(Bry_bfr bfr, int depth);
|
public abstract void Print_as_json(Bry_bfr bfr, int depth);
|
||||||
@gplx.Virtual public boolean Data_eq(byte[] comp) {return false;}
|
@gplx.Virtual public boolean Data_eq(byte[] comp) {return false;}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,14 +13,22 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
|
||||||
public class Json_itm_bool extends Json_itm_base {
|
public class Json_itm_bool extends Json_itm_base {
|
||||||
private boolean data;
|
private boolean data;
|
||||||
public Json_itm_bool(boolean data) {this.data = data; this.Ctor(-1, -1);}
|
private Json_itm_bool(boolean data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__bool;}
|
@Override public byte Tid() {return Json_itm_.Tid__bool;}
|
||||||
public boolean Data_as_bool() {return data;}
|
public boolean Data_as_bool() {return data;}
|
||||||
@Override public Object Data() {return data;}
|
@Override public Object Data() {return data;}
|
||||||
@Override public byte[] Data_bry() {return data ? Json_itm_.Bry__true : Json_itm_.Bry__false;}
|
@Override public byte[] Data_bry() {return data ? Json_itm_.Bry__true : Json_itm_.Bry__false;}
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(data ? Json_itm_.Bry__true: Json_itm_.Bry__false);}
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(data ? Json_itm_.Bry__true: Json_itm_.Bry__false);}
|
||||||
|
|
||||||
public static final Json_itm_bool Bool_n = new Json_itm_bool(false), Bool_y = new Json_itm_bool(true);
|
public static final Json_itm_bool Bool_n = new Json_itm_bool(false), Bool_y = new Json_itm_bool(true);
|
||||||
|
public static final Json_itm_bool Get(boolean v) {return v ? Bool_y : Bool_n;}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,14 +13,35 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Decimal_adp;
|
||||||
|
import gplx.Decimal_adp_;
|
||||||
|
import gplx.Double_;
|
||||||
|
import gplx.String_;
|
||||||
|
|
||||||
public class Json_itm_decimal extends Json_itm_base {
|
public class Json_itm_decimal extends Json_itm_base {
|
||||||
private final Json_doc doc; private Decimal_adp data; private byte[] data_bry;
|
private final Json_doc doc;
|
||||||
public Json_itm_decimal(Json_doc doc, int src_bgn, int src_end) {this.Ctor(src_bgn, src_end); this.doc = doc;}
|
private final int src_bgn, src_end;
|
||||||
|
private Decimal_adp data;
|
||||||
|
private byte[] data_bry;
|
||||||
|
|
||||||
|
private Json_itm_decimal(Json_doc doc, int src_bgn, int src_end, Decimal_adp data) {
|
||||||
|
this.doc = doc;
|
||||||
|
this.src_bgn = src_bgn;
|
||||||
|
this.src_end = src_end;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__decimal;}
|
@Override public byte Tid() {return Json_itm_.Tid__decimal;}
|
||||||
@Override public Object Data() {return this.Data_as_decimal();}
|
@Override public Object Data() {return this.Data_as_decimal();}
|
||||||
@Override public byte[] Data_bry() {
|
@Override public byte[] Data_bry() {
|
||||||
if (data_bry == null) data_bry = Bry_.Mid(doc.Src(), this.Src_bgn(), this.Src_end());
|
if (data_bry == null) {
|
||||||
|
data_bry = data == null
|
||||||
|
? Bry_.Mid(doc.Src(), src_bgn, src_end)
|
||||||
|
: Bry_.new_u8(Double_.To_str_loose(data.To_double()));
|
||||||
|
}
|
||||||
return data_bry;
|
return data_bry;
|
||||||
}
|
}
|
||||||
public Decimal_adp Data_as_decimal() {
|
public Decimal_adp Data_as_decimal() {
|
||||||
@ -31,5 +52,15 @@ public class Json_itm_decimal extends Json_itm_base {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add_mid(doc.Src(), this.Src_bgn(), this.Src_end());}
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||||
|
if (doc == null) {
|
||||||
|
bfr.Add_str_a7(Double_.To_str_loose(data.To_double()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bfr.Add_mid(doc.Src(), src_bgn, src_end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Json_itm_decimal NewByDoc(Json_doc doc, int src_bgn, int src_end) {return new Json_itm_decimal(doc, src_bgn, src_end, null);}
|
||||||
|
public static Json_itm_decimal NewByVal(Decimal_adp val) {return new Json_itm_decimal(null, -1, -1, val);}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,21 +13,52 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Int_;
|
||||||
|
|
||||||
public class Json_itm_int extends Json_itm_base {
|
public class Json_itm_int extends Json_itm_base {
|
||||||
private final Json_doc doc;
|
private final Json_doc doc;
|
||||||
private byte[] data_bry; private int data; private boolean data_is_null = true;
|
private final int src_bgn, src_end;
|
||||||
public Json_itm_int(Json_doc doc, int src_bgn, int src_end) {this.Ctor(src_bgn, src_end); this.doc = doc;}
|
private byte[] data_bry;
|
||||||
|
private int data;
|
||||||
|
private boolean data_needs_making;
|
||||||
|
|
||||||
|
private Json_itm_int(Json_doc doc, int src_bgn, int src_end, boolean data_needs_making, int data) {
|
||||||
|
this.doc = doc;
|
||||||
|
this.src_bgn = src_bgn;
|
||||||
|
this.src_end = src_end;
|
||||||
|
this.data_needs_making = data_needs_making;
|
||||||
|
if (!data_needs_making)
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__int;}
|
@Override public byte Tid() {return Json_itm_.Tid__int;}
|
||||||
|
@Override public Object Data() {return Data_as_int();}
|
||||||
|
@Override public byte[] Data_bry() {
|
||||||
|
if (data_bry == null) {
|
||||||
|
data_bry = doc == null
|
||||||
|
? Int_.To_bry(data)
|
||||||
|
: Bry_.Mid(doc.Src(), src_bgn, src_end);
|
||||||
|
}
|
||||||
|
return data_bry;
|
||||||
|
}
|
||||||
public int Data_as_int() {
|
public int Data_as_int() {
|
||||||
if (data_is_null) {
|
if (data_needs_making) {
|
||||||
data = doc.Utl_num_parser().Parse(doc.Src(), Src_bgn(), Src_end()).Rv_as_int();
|
data = doc.Utl_num_parser().Parse(doc.Src(), src_bgn, src_end).Rv_as_int();
|
||||||
data_is_null = false;
|
data_needs_making = false;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@Override public Object Data() {return Data_as_int();}
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||||
@Override public byte[] Data_bry() {if (data_bry == null) data_bry = Bry_.Mid(doc.Src(), this.Src_bgn(), this.Src_end()); return data_bry;}
|
if (doc == null)
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add_mid(doc.Src(), this.Src_bgn(), this.Src_end());}
|
bfr.Add_int_variable(data);
|
||||||
public static Json_itm_int cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__int ? null : (Json_itm_int)v;}
|
else
|
||||||
|
bfr.Add_mid(doc.Src(), src_bgn, src_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Json_itm_int NewByDoc(Json_doc doc, int src_bgn, int src_end) {return new Json_itm_int(doc, src_bgn, src_end, true, -1);}
|
||||||
|
public static Json_itm_int NewByVal(int val) {return new Json_itm_int(null, -1, -1, false, val);}
|
||||||
|
public static Json_itm_int Cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__int ? null : (Json_itm_int)v;}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,21 +13,51 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Long_;
|
||||||
|
|
||||||
public class Json_itm_long extends Json_itm_base {
|
public class Json_itm_long extends Json_itm_base {
|
||||||
private final Json_doc doc;
|
private final Json_doc doc;
|
||||||
private byte[] data_bry; private long data; private boolean data_is_null = true;
|
private final int src_bgn, src_end;
|
||||||
public Json_itm_long(Json_doc doc, int src_bgn, int src_end) {this.Ctor(src_bgn, src_end); this.doc = doc;}
|
private byte[] data_bry;
|
||||||
|
private long data;
|
||||||
|
private boolean data_needs_making = true;
|
||||||
|
private Json_itm_long(Json_doc doc, int src_bgn, int src_end, boolean data_needs_making, long data) {
|
||||||
|
this.doc = doc;
|
||||||
|
this.src_bgn = src_bgn;
|
||||||
|
this.src_end = src_end;
|
||||||
|
this.data_needs_making = data_needs_making;
|
||||||
|
if (!data_needs_making)
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__long;}
|
@Override public byte Tid() {return Json_itm_.Tid__long;}
|
||||||
|
@Override public Object Data() {return Data_as_long();}
|
||||||
|
@Override public byte[] Data_bry() {
|
||||||
|
if (data_bry == null) {
|
||||||
|
data_bry = doc == null
|
||||||
|
? Bry_.new_u8(Long_.To_str(data))
|
||||||
|
: Bry_.Mid(doc.Src(), src_bgn, src_end);
|
||||||
|
}
|
||||||
|
return data_bry;
|
||||||
|
}
|
||||||
public long Data_as_long() {
|
public long Data_as_long() {
|
||||||
if (data_is_null) {
|
if (data_needs_making) {
|
||||||
data = doc.Utl_num_parser().Parse(doc.Src(), Src_bgn(), Src_end()).Rv_as_long();
|
data = doc.Utl_num_parser().Parse(doc.Src(), src_bgn, src_end).Rv_as_long();
|
||||||
data_is_null = false;
|
data_needs_making = false;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@Override public Object Data() {return Data_as_long();}
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||||
@Override public byte[] Data_bry() {if (data_bry == null) data_bry = Bry_.Mid(doc.Src(), this.Src_bgn(), this.Src_end()); return data_bry;}
|
if (doc == null)
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add_mid(doc.Src(), this.Src_bgn(), this.Src_end());}
|
bfr.Add_long_variable(data);
|
||||||
public static Json_itm_long cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__long ? null : (Json_itm_long)v;}
|
else
|
||||||
|
bfr.Add_mid(doc.Src(), src_bgn, src_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Json_itm_long NewByDoc(Json_doc doc, int src_bgn, int src_end) {return new Json_itm_long(doc, src_bgn, src_end, true, -1);}
|
||||||
|
public static Json_itm_long NewByVal(long val) {return new Json_itm_long(null, -1, -1, false, val);}
|
||||||
|
public static Json_itm_long Cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__long ? null : (Json_itm_long)v;}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,38 +13,97 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import gplx.core.intls.*;
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.intls.Utf16_;
|
||||||
|
import gplx.langs.htmls.Gfh_utl;
|
||||||
|
|
||||||
public class Json_itm_str extends Json_itm_base {
|
public class Json_itm_str extends Json_itm_base {
|
||||||
private final boolean exact; private final Json_doc doc;
|
private final Json_doc doc;
|
||||||
private String data_str; private byte[] data_bry = null;
|
private final int src_bgn, src_end;
|
||||||
public Json_itm_str(Json_doc doc, int src_bgn, int src_end, boolean exact) {this.Ctor(src_bgn + 1, src_end - 1); this.doc = doc; this.exact = exact;}
|
private String data_str;
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__str;}
|
private byte[] data_bry;
|
||||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
private boolean data_needs_making;
|
||||||
bfr.Add_byte(Byte_ascii.Quote);
|
private boolean escaped;
|
||||||
gplx.langs.htmls.Gfh_utl.Escape_html_to_bfr(bfr, doc.Src(), this.Src_bgn(), this.Src_end(), true, true, true, true, false); // false to apos for backwards compatibility
|
|
||||||
bfr.Add_byte(Byte_ascii.Quote);
|
private Json_itm_str(Json_doc doc, int src_bgn, int src_end, String data_str, boolean escaped) {
|
||||||
|
this.doc = doc;
|
||||||
|
this.src_bgn = src_bgn;
|
||||||
|
this.src_end = src_end;
|
||||||
|
this.data_str = data_str;
|
||||||
|
this.data_bry = null;
|
||||||
|
this.data_needs_making = true;
|
||||||
|
this.escaped = escaped;
|
||||||
}
|
}
|
||||||
|
@Override public byte Tid() {return Json_itm_.Tid__str;}
|
||||||
@Override public Object Data() {return this.Data_as_str();}
|
@Override public Object Data() {return this.Data_as_str();}
|
||||||
|
public void Overwrite_bry(byte[] v) {
|
||||||
|
this.data_bry = v; //needed by MapLink/MapFrame
|
||||||
|
this.data_needs_making = false;
|
||||||
|
}
|
||||||
|
@Override public byte[] Data_bry() {
|
||||||
|
if (data_bry == null) {
|
||||||
|
data_bry = Data_make_bry();
|
||||||
|
}
|
||||||
|
return data_bry;
|
||||||
|
}
|
||||||
public String Data_as_str() {
|
public String Data_as_str() {
|
||||||
if (data_str == null) {
|
if (data_str == null) {
|
||||||
if (data_bry == null)
|
|
||||||
data_bry = Data_make_bry();
|
data_bry = Data_make_bry();
|
||||||
data_str = String_.new_u8(data_bry);
|
data_str = String_.new_u8(data_bry);
|
||||||
}
|
}
|
||||||
return data_str;
|
return data_str;
|
||||||
}
|
}
|
||||||
@Override public byte[] Data_bry() {if (data_bry == null) data_bry = Data_make_bry(); return data_bry;}
|
|
||||||
@Override public boolean Data_eq(byte[] comp) {
|
@Override public boolean Data_eq(byte[] comp) {
|
||||||
if (exact) return Bry_.Eq(doc.Src(), this.Src_bgn(), this.Src_end(), comp);
|
return Bry_.Match(this.Data_bry(), comp);
|
||||||
if (data_bry == null) data_bry = Data_make_bry();
|
|
||||||
return Bry_.Match(data_bry, comp);
|
|
||||||
}
|
}
|
||||||
private byte[] Data_make_bry() {
|
private byte[] Data_make_bry() {
|
||||||
byte[] src = doc.Src(); int bgn = this.Src_bgn(), end = this.Src_end();
|
// data already made; return it;
|
||||||
if (exact) return Bry_.Mid(src, bgn, end);
|
if (!data_needs_making)
|
||||||
Bry_bfr bfr = doc.Bfr();
|
return data_bry;
|
||||||
byte[] utf8_bry = doc.Tmp_u8_bry();
|
|
||||||
|
// mark data as made
|
||||||
|
this.data_needs_making = false;
|
||||||
|
|
||||||
|
// get src, bgn, end, depending on whether or not itm is from jdoc or standalone
|
||||||
|
byte[] src;
|
||||||
|
int bgn;
|
||||||
|
int end;
|
||||||
|
if (doc == null) {
|
||||||
|
src = Bry_.new_u8_safe(this.data_str);
|
||||||
|
bgn = 0;
|
||||||
|
end = src == null ? 0 : src.length;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
src = doc.Src();
|
||||||
|
bgn = src_bgn;
|
||||||
|
end = src_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not escaped -> return the src
|
||||||
|
if (!escaped) {
|
||||||
|
this.data_bry = Bry_.Mid(src, bgn, end);
|
||||||
|
return data_bry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// escaped; get some temp vars
|
||||||
|
Bry_bfr bfr;
|
||||||
|
byte[] utf8_bry;
|
||||||
|
if (doc == null) {
|
||||||
|
bfr = Bry_bfr_.New();
|
||||||
|
utf8_bry = new byte[6];
|
||||||
|
}
|
||||||
|
else { // PERF:reuse bfr / bry on jdoc itself
|
||||||
|
bfr = doc.Bfr();
|
||||||
|
utf8_bry = doc.Tmp_u8_bry();
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop and unescape
|
||||||
for (int i = bgn; i < end; i++) {
|
for (int i = bgn; i < end; i++) {
|
||||||
byte b = src[i];
|
byte b = src[i];
|
||||||
switch (b) {
|
switch (b) {
|
||||||
@ -90,6 +149,17 @@ public class Json_itm_str extends Json_itm_base {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bfr.To_bry_and_clear();
|
this.data_bry = bfr.To_bry_and_clear();
|
||||||
|
return data_bry;
|
||||||
}
|
}
|
||||||
|
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||||
|
bfr.Add_byte(Byte_ascii.Quote);
|
||||||
|
byte[] data_bry = this.Data_bry();
|
||||||
|
int data_len = data_bry.length;
|
||||||
|
Gfh_utl.Escape_html_to_bfr(bfr, data_bry, 0, data_len, true, true, true, true, false); // false to apos for backwards compatibility
|
||||||
|
bfr.Add_byte(Byte_ascii.Quote);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Json_itm_str NewByDoc(Json_doc doc, int src_bgn, int src_end, boolean escaped) {return new Json_itm_str(doc, src_bgn + 1, src_end - 1, null, escaped);}
|
||||||
|
public static Json_itm_str NewByVal(String val) {return new Json_itm_str(null, -1, -1, val, false);}
|
||||||
}
|
}
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
XOWA: the XOWA Offline Wiki Application
|
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
|
||||||
|
|
||||||
You may use XOWA according to either of these licenses as is most appropriate
|
|
||||||
for your project on a case-by-case basis.
|
|
||||||
|
|
||||||
The terms of each license can be found in the source code repository:
|
|
||||||
|
|
||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
||||||
*/
|
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
|
||||||
public class Json_itm_tmp implements Json_itm { // TEST:
|
|
||||||
public Json_itm_tmp(byte tid, String data) {this.tid = tid; this.data = data;}
|
|
||||||
public byte Tid() {return tid;} private byte tid;
|
|
||||||
public byte[] Data_bry() {return Bry_.new_u8(Object_.Xto_str_strict_or_empty(data));}
|
|
||||||
public int Src_bgn() {return -1;}
|
|
||||||
public int Src_end() {return -1;}
|
|
||||||
public Object Data() {return data;} private String data;
|
|
||||||
public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add_str_u8(data);}
|
|
||||||
public boolean Data_eq(byte[] comp) {return false;}
|
|
||||||
public void Clear() {}
|
|
||||||
public static Json_itm new_str_(String v) {return new Json_itm_tmp(Json_itm_.Tid__str, "\"" + v + "\"");}
|
|
||||||
public static Json_itm new_int_(int v) {return new Json_itm_tmp(Json_itm_.Tid__int, Int_.To_str(v));}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
|
||||||
public class Json_kv extends Json_itm_base {
|
public class Json_kv extends Json_itm_base {
|
||||||
public Json_kv(Json_itm key, Json_itm val) {this.key = key; this.val = val;}
|
public Json_kv(Json_itm key, Json_itm val) {this.key = key; this.val = val;}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__kv;}
|
@Override public byte Tid() {return Json_itm_.Tid__kv;}
|
||||||
@ -22,7 +26,7 @@ public class Json_kv extends Json_itm_base {
|
|||||||
public byte[] Key_as_bry() {return key.Data_bry();}
|
public byte[] Key_as_bry() {return key.Data_bry();}
|
||||||
public String Key_as_str() {return (String)key.Data();}
|
public String Key_as_str() {return (String)key.Data();}
|
||||||
public byte[] Val_as_bry() {return val.Data_bry();}
|
public byte[] Val_as_bry() {return val.Data_bry();}
|
||||||
public Json_nde Val_as_nde() {return Json_nde.cast(val);}
|
public Json_nde Val_as_nde() {return Json_nde.Cast(val);}
|
||||||
public Json_ary Val_as_ary() {return Json_ary.cast(val);}
|
public Json_ary Val_as_ary() {return Json_ary.cast(val);}
|
||||||
public boolean Key_eq(byte[] comp) {return ((Json_itm_str)key).Data_eq(comp);}
|
public boolean Key_eq(byte[] comp) {return ((Json_itm_str)key).Data_eq(comp);}
|
||||||
@Override public Object Data() {return null;}
|
@Override public Object Data() {return null;}
|
||||||
@ -33,5 +37,5 @@ public class Json_kv extends Json_itm_base {
|
|||||||
val.Print_as_json(bfr, depth);
|
val.Print_as_json(bfr, depth);
|
||||||
}
|
}
|
||||||
public static final Json_kv[] Ary_empty = new Json_kv[0];
|
public static final Json_kv[] Ary_empty = new Json_kv[0];
|
||||||
public static Json_kv cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__kv ? null : (Json_kv)v;}
|
public static Json_kv Cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__kv ? null : (Json_kv)v;}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,37 +13,42 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import org.junit.*;
|
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Decimal_adp;
|
||||||
|
import gplx.Decimal_adp_;
|
||||||
|
import gplx.Keyval;
|
||||||
|
import gplx.Keyval_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Json_kv_ary_srl_tst {
|
public class Json_kv_ary_srl_tst {
|
||||||
@Before public void init() {fxt.Clear();} private Json_kv_ary_srl_fxt fxt = new Json_kv_ary_srl_fxt();
|
private final Json_kv_ary_srl_fxt fxt = new Json_kv_ary_srl_fxt();
|
||||||
@Test public void Null() {fxt.Test_parse("{'k0':null}" , fxt.ary_(fxt.kv_str_("k0", null)));}
|
@Test public void Null() {fxt.Test_parse("{'k0':null}" , fxt.ary_(fxt.New_kv_str("k0", null)));}
|
||||||
@Test public void Bool_n() {fxt.Test_parse("{'k0':false}" , fxt.ary_(fxt.kv_bool_("k0", false)));}
|
@Test public void Bool_n() {fxt.Test_parse("{'k0':false}" , fxt.ary_(fxt.New_kv_bool("k0", false)));}
|
||||||
@Test public void Num() {fxt.Test_parse("{'k0':123}" , fxt.ary_(fxt.kv_int_("k0", 123)));}
|
@Test public void Num() {fxt.Test_parse("{'k0':123}" , fxt.ary_(fxt.New_kv_int("k0", 123)));}
|
||||||
@Test public void Num_exp() {fxt.Test_parse("{'k0':1.23e2}" , fxt.ary_(fxt.kv_int_("k0", 123)));} // exponent can be either "e" or "E" in JSON, but Java decimal parse only takes "E"; ISSUE#:565; DATE:2020-03-25
|
@Test public void Num_exp() {fxt.Test_parse("{'k0':1.23e2}" , fxt.ary_(fxt.New_kv_int("k0", 123)));} // exponent can be either "e" or "E" in JSON, but Java decimal parse only takes "E"; ISSUE#:565; DATE:2020-03-25
|
||||||
@Test public void Str() {fxt.Test_parse("{'k0':'v0'}" , fxt.ary_(fxt.kv_str_("k0", "v0")));}
|
@Test public void Str() {fxt.Test_parse("{'k0':'v0'}" , fxt.ary_(fxt.New_kv_str("k0", "v0")));}
|
||||||
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.kv_dec_("k0", Decimal_adp_.parse("1.23"))));}
|
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.New_kv_dec("k0", Decimal_adp_.parse("1.23"))));}
|
||||||
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("1", 1), fxt.kv_int_("2", 2), fxt.kv_int_("3", 3)))));}
|
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.ary_(fxt.New_kv_obj("k0", fxt.ary_(fxt.New_kv_int("1", 1), fxt.New_kv_int("2", 2), fxt.New_kv_int("3", 3)))));}
|
||||||
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));}
|
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.ary_(fxt.New_kv_obj("k0", fxt.ary_())));}
|
||||||
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1,'k01':2}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("k00", 1), fxt.kv_int_("k01", 2)))));}
|
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1,'k01':2}}" , fxt.ary_(fxt.New_kv_obj("k0", fxt.ary_(fxt.New_kv_int("k00", 1), fxt.New_kv_int("k01", 2)))));}
|
||||||
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));}
|
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}" , fxt.ary_(fxt.New_kv_obj("k0", fxt.ary_())));}
|
||||||
}
|
}
|
||||||
class Json_kv_ary_srl_fxt {
|
class Json_kv_ary_srl_fxt {
|
||||||
public void Clear() {
|
private final Json_parser parser = new Json_parser();
|
||||||
if (parser == null) {
|
|
||||||
parser = new Json_parser();
|
|
||||||
}
|
|
||||||
} private Json_parser parser;
|
|
||||||
public void Test_parse(String raw_str, Keyval[] expd) {
|
public void Test_parse(String raw_str, Keyval[] expd) {
|
||||||
byte[] raw_bry = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
|
byte[] raw_bry = Bry_.new_u8(Json_doc.Make_str_by_apos(raw_str));
|
||||||
Json_doc doc = parser.Parse(raw_bry);
|
Json_doc doc = parser.Parse(raw_bry);
|
||||||
Keyval[] actl = Json_kv_ary_srl.Val_by_itm_nde(doc.Root_nde());
|
Keyval[] actl = Json_kv_ary_srl.Val_by_itm_nde(doc.Root_nde());
|
||||||
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
|
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
|
||||||
}
|
}
|
||||||
public Keyval[] ary_(Keyval... ary) {return ary;}
|
public Keyval[] ary_(Keyval... ary) {return ary;}
|
||||||
public Keyval kv_obj_(String key, Object val) {return Keyval_.new_(key, val);}
|
public Keyval New_kv_obj(String key, Object val) {return Keyval_.new_(key, val);}
|
||||||
public Keyval kv_str_(String key, String val) {return Keyval_.new_(key, val);}
|
public Keyval New_kv_str(String key, String val) {return Keyval_.new_(key, val);}
|
||||||
public Keyval kv_int_(String key, int val) {return Keyval_.new_(key, val);}
|
public Keyval New_kv_int(String key, int val) {return Keyval_.new_(key, val);}
|
||||||
public Keyval kv_bool_(String key, boolean val) {return Keyval_.new_(key, Bool_.To_str_lower(val));}
|
public Keyval New_kv_bool(String key, boolean val) {return Keyval_.new_(key, Bool_.To_str_lower(val));}
|
||||||
public Keyval kv_dec_(String key, Decimal_adp val) {return Keyval_.new_(key, val.To_str());}
|
public Keyval New_kv_dec(String key, Decimal_adp val) {return Keyval_.new_(key, val.To_str());}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import gplx.Bry_bfr;
|
|||||||
import gplx.Byte_ascii;
|
import gplx.Byte_ascii;
|
||||||
import gplx.DateAdp;
|
import gplx.DateAdp;
|
||||||
import gplx.DateAdp_;
|
import gplx.DateAdp_;
|
||||||
|
import gplx.Decimal_adp_;
|
||||||
import gplx.Err_;
|
import gplx.Err_;
|
||||||
import gplx.Hash_adp_bry;
|
import gplx.Hash_adp_bry;
|
||||||
import gplx.Int_;
|
import gplx.Int_;
|
||||||
@ -29,9 +30,16 @@ import gplx.Long_;
|
|||||||
import gplx.String_;
|
import gplx.String_;
|
||||||
|
|
||||||
public class Json_nde extends Json_itm_base implements Json_grp {
|
public class Json_nde extends Json_itm_base implements Json_grp {
|
||||||
private Json_itm[] subs = Json_itm_.Ary_empty; private int subs_len = 0, subs_max = 0;
|
private final int src_bgn;
|
||||||
|
private int src_end;
|
||||||
|
private Json_itm[] subs = Json_itm_.Ary_empty;
|
||||||
|
private int subs_len = 0, subs_max = 0;
|
||||||
private Hash_adp_bry subs_hash;
|
private Hash_adp_bry subs_hash;
|
||||||
public Json_nde(Json_doc jdoc, int src_bgn) {this.jdoc = jdoc; this.Ctor(src_bgn, -1);}
|
|
||||||
|
private Json_nde(Json_doc jdoc, int src_bgn) {
|
||||||
|
this.jdoc = jdoc;
|
||||||
|
this.src_bgn = src_bgn;
|
||||||
|
}
|
||||||
@Override public byte Tid() {return Json_itm_.Tid__nde;}
|
@Override public byte Tid() {return Json_itm_.Tid__nde;}
|
||||||
public Json_doc Doc() {return jdoc;} private final Json_doc jdoc;
|
public Json_doc Doc() {return jdoc;} private final Json_doc jdoc;
|
||||||
public void Src_end_(int v) {this.src_end = v;}
|
public void Src_end_(int v) {this.src_end = v;}
|
||||||
@ -42,8 +50,8 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
|||||||
public Json_itm Get_as_itm_or_null(String key) {return Get_as_itm_or_null(Bry_.new_u8(key));}
|
public Json_itm Get_as_itm_or_null(String key) {return Get_as_itm_or_null(Bry_.new_u8(key));}
|
||||||
public Json_itm Get_as_itm_or_null(byte[] key) {if (subs_hash == null) subs_hash = subs_hash_init(); return (Json_itm)subs_hash.Get_by_bry(key);}
|
public Json_itm Get_as_itm_or_null(byte[] key) {if (subs_hash == null) subs_hash = subs_hash_init(); return (Json_itm)subs_hash.Get_by_bry(key);}
|
||||||
public Json_ary Get_as_ary(int idx) {return Json_ary.cast(Get_at(idx));}
|
public Json_ary Get_as_ary(int idx) {return Json_ary.cast(Get_at(idx));}
|
||||||
public Json_nde Get_as_nde(String key) {return Json_nde.cast(Get_as_itm_or_null(Bry_.new_u8(key)));}
|
public Json_nde Get_as_nde(String key) {return Json_nde.Cast(Get_as_itm_or_null(Bry_.new_u8(key)));}
|
||||||
public Json_nde Get_as_nde(int idx) {return Json_nde.cast(Get_at(idx));}
|
public Json_nde Get_as_nde(int idx) {return Json_nde.Cast(Get_at(idx));}
|
||||||
public Json_ary Get_as_ary(String key) {return Get_as_ary(Bry_.new_u8(key));}
|
public Json_ary Get_as_ary(String key) {return Get_as_ary(Bry_.new_u8(key));}
|
||||||
public Json_ary Get_as_ary(byte[] key) {
|
public Json_ary Get_as_ary(byte[] key) {
|
||||||
Json_itm rv = Get_as_itm_or_null(key); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
Json_itm rv = Get_as_itm_or_null(key); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
||||||
@ -105,21 +113,25 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
|||||||
public boolean Has(byte[] key) {return Get_bry(key, null) != null;}
|
public boolean Has(byte[] key) {return Get_bry(key, null) != null;}
|
||||||
public Json_kv Get_at_as_kv(int i) {
|
public Json_kv Get_at_as_kv(int i) {
|
||||||
Json_itm rv_itm = Get_at(i);
|
Json_itm rv_itm = Get_at(i);
|
||||||
Json_kv rv = Json_kv.cast(rv_itm); if (rv == null) throw Err_.new_("json", "sub is not kv", "i", i, "src", Bry_.Mid(jdoc.Src(), this.Src_bgn(), src_end));
|
Json_kv rv = Json_kv.Cast(rv_itm);
|
||||||
|
if (rv == null) {
|
||||||
|
byte[] snip = jdoc == null ? Bry_.new_a7("no source") : Bry_.Mid(jdoc.Src(), src_bgn, src_end);
|
||||||
|
throw Err_.new_("json", "sub is not kv", "i", i, "src", snip);
|
||||||
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Json_kv Get_kv(byte[] key) {return Json_kv.cast(Get_itm(key));}
|
public Json_kv Get_kv(byte[] key) {return Json_kv.Cast(Get_itm(key));}
|
||||||
public Json_nde Get(String key) {return Get(Bry_.new_u8(key));}
|
public Json_nde Get(String key) {return Get(Bry_.new_u8(key));}
|
||||||
public Json_nde Get(byte[] key) {
|
public Json_nde Get(byte[] key) {
|
||||||
Json_kv kv = Json_kv.cast(this.Get_itm(key)); if (kv == null) throw Err_.new_("json", "kv not found", "key", key);
|
Json_kv kv = Json_kv.Cast(this.Get_itm(key)); if (kv == null) throw Err_.new_("json", "kv not found", "key", key);
|
||||||
Json_nde rv = Json_nde.cast(kv.Val()); if (rv == null) throw Err_.new_("json", "nde not found", "key", key);
|
Json_nde rv = Json_nde.Cast(kv.Val()); if (rv == null) throw Err_.new_("json", "nde not found", "key", key);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
public Json_itm Get_itm(byte[] key) {
|
public Json_itm Get_itm(byte[] key) {
|
||||||
for (int i = 0; i < subs_len; i++) {
|
for (int i = 0; i < subs_len; i++) {
|
||||||
Json_itm itm = subs[i];
|
Json_itm itm = subs[i];
|
||||||
if (itm.Tid() == Json_itm_.Tid__kv) {
|
if (itm != null && itm.Tid() == Json_itm_.Tid__kv) {
|
||||||
Json_kv itm_as_kv = (Json_kv)itm;
|
Json_kv itm_as_kv = (Json_kv)itm;
|
||||||
if (Bry_.Eq(key, itm_as_kv.Key().Data_bry()))
|
if (Bry_.Eq(key, itm_as_kv.Key().Data_bry()))
|
||||||
return itm;
|
return itm;
|
||||||
@ -144,6 +156,17 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
|||||||
Json_itm val = kv.Val();
|
Json_itm val = kv.Val();
|
||||||
return (val == null) ? or : val.Data_bry();
|
return (val == null) ? or : val.Data_bry();
|
||||||
}
|
}
|
||||||
|
public void AddKvBool(String key, boolean val) {AddKv(key, Json_itm_bool.Get(val));}
|
||||||
|
public void AddKvInt(String key, int val) {AddKv(key, Json_itm_int.NewByVal(val));}
|
||||||
|
public void AddKvDouble(String key, double val) {AddKv(key, Json_itm_decimal.NewByVal(Decimal_adp_.double_(val)));}
|
||||||
|
public void AddKvStr(String key, byte[] val) {AddKv(key, Json_itm_str.NewByVal(String_.new_u8(val)));}
|
||||||
|
public void AddKvStr(String key, String val) {AddKv(key, Json_itm_str.NewByVal(val));}
|
||||||
|
public void AddKvNde(String key, Json_nde val) {AddKv(key, val);}
|
||||||
|
public void AddKvAry(String key, Json_ary val) {AddKv(key, val);}
|
||||||
|
private void AddKv(String key, Json_itm val) {
|
||||||
|
Json_kv rv = new Json_kv(Json_itm_str.NewByVal(key), val);
|
||||||
|
Add(rv);
|
||||||
|
}
|
||||||
public Json_nde Add_many(Json_itm... ary) {
|
public Json_nde Add_many(Json_itm... ary) {
|
||||||
int len = ary.length;
|
int len = ary.length;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
@ -187,5 +210,8 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
|||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
public static Json_nde cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__nde ? null : (Json_nde)v;}
|
|
||||||
|
public static Json_nde NewByDoc(Json_doc doc, int src_bgn) {return new Json_nde(doc, src_bgn);}
|
||||||
|
public static Json_nde NewByVal() {return new Json_nde(null, -1);}
|
||||||
|
public static Json_nde Cast(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid__nde ? null : (Json_nde)v;}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ import gplx.String_;
|
|||||||
import gplx.core.primitives.Gfo_number_parser;
|
import gplx.core.primitives.Gfo_number_parser;
|
||||||
|
|
||||||
public class Json_parser {
|
public class Json_parser {
|
||||||
private byte[] src; private int src_len, pos; private final Gfo_number_parser num_parser = new Gfo_number_parser();
|
private byte[] src;
|
||||||
public Json_factory Factory() {return factory;} private final Json_factory factory = new Json_factory();
|
private int src_len, pos;
|
||||||
|
private final Gfo_number_parser num_parser = new Gfo_number_parser();
|
||||||
public Json_doc Parse_by_apos_ary(String... ary) {return Parse_by_apos(String_.Concat_lines_nl(ary));}
|
public Json_doc Parse_by_apos_ary(String... ary) {return Parse_by_apos(String_.Concat_lines_nl(ary));}
|
||||||
public Json_doc Parse_by_apos(String s) {return Parse(Bry_.Replace(Bry_.new_u8(s), Byte_ascii.Apos, Byte_ascii.Quote));}
|
public Json_doc Parse_by_apos(String s) {return Parse(Bry_.Replace(Bry_.new_u8(s), Byte_ascii.Apos, Byte_ascii.Quote));}
|
||||||
public Json_doc Parse(String src) {return Parse(Bry_.new_u8(src));}
|
public Json_doc Parse(String src) {return Parse(Bry_.new_u8(src));}
|
||||||
public Json_doc Parse(byte[] src) {
|
public Json_doc Parse(byte[] src) {
|
||||||
synchronized (factory) {
|
|
||||||
this.src = src; if (src == null) return null;
|
this.src = src; if (src == null) return null;
|
||||||
this.src_len = src.length; if (src_len == 0) return null;
|
this.src_len = src.length; if (src_len == 0) return null;
|
||||||
this.pos = 0;
|
this.pos = 0;
|
||||||
@ -53,10 +53,9 @@ public class Json_parser {
|
|||||||
doc.Ctor(src, root);
|
doc.Ctor(src, root);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private Json_nde Make_nde(Json_doc doc) {
|
private Json_nde Make_nde(Json_doc doc) {
|
||||||
++pos; // brack_bgn
|
++pos; // brack_bgn
|
||||||
Json_nde nde = new Json_nde(doc, pos);
|
Json_nde nde = Json_nde.NewByDoc(doc, pos);
|
||||||
while (pos < src_len) {
|
while (pos < src_len) {
|
||||||
Skip_ws();
|
Skip_ws();
|
||||||
if (src[pos] == Byte_ascii.Curly_end) {++pos; return nde;}
|
if (src[pos] == Byte_ascii.Curly_end) {++pos; return nde;}
|
||||||
@ -82,9 +81,9 @@ public class Json_parser {
|
|||||||
while (pos < src_len) {
|
while (pos < src_len) {
|
||||||
byte b = src[pos];
|
byte b = src[pos];
|
||||||
switch (b) {
|
switch (b) {
|
||||||
case Byte_ascii.Ltr_n: return Make_literal(Bry_null_ull , 3, factory.Null());
|
case Byte_ascii.Ltr_n: return Make_literal(Bry_null_ull , 3, Json_itm_null.Null);
|
||||||
case Byte_ascii.Ltr_f: return Make_literal(Bry_bool_alse , 4, factory.Bool_n());
|
case Byte_ascii.Ltr_f: return Make_literal(Bry_bool_alse , 4, Json_itm_bool.Bool_n);
|
||||||
case Byte_ascii.Ltr_t: return Make_literal(Bry_bool_rue , 3, factory.Bool_y());
|
case Byte_ascii.Ltr_t: return Make_literal(Bry_bool_rue , 3, Json_itm_bool.Bool_y);
|
||||||
case Byte_ascii.Quote: return Make_string(doc);
|
case Byte_ascii.Quote: return Make_string(doc);
|
||||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||||
@ -107,7 +106,7 @@ public class Json_parser {
|
|||||||
}
|
}
|
||||||
private Json_itm Make_string(Json_doc doc) {
|
private Json_itm Make_string(Json_doc doc) {
|
||||||
int bgn = pos++; // ++: quote_bgn
|
int bgn = pos++; // ++: quote_bgn
|
||||||
boolean exact = true;
|
boolean escaped = false;
|
||||||
while (pos < src_len) {
|
while (pos < src_len) {
|
||||||
switch (src[pos]) {
|
switch (src[pos]) {
|
||||||
case Byte_ascii.Backslash:
|
case Byte_ascii.Backslash:
|
||||||
@ -116,10 +115,10 @@ public class Json_parser {
|
|||||||
case Byte_ascii.Ltr_u: pos += 5; break; // \uFFFF 1 u + 4 hex-dec; ISSUE#:486; DATE:2019-06-02
|
case Byte_ascii.Ltr_u: pos += 5; break; // \uFFFF 1 u + 4 hex-dec; ISSUE#:486; DATE:2019-06-02
|
||||||
default: ++pos; break; // \? " \ / b f n r t
|
default: ++pos; break; // \? " \ / b f n r t
|
||||||
}
|
}
|
||||||
exact = false;
|
escaped = true;
|
||||||
break;
|
break;
|
||||||
case Byte_ascii.Quote:
|
case Byte_ascii.Quote:
|
||||||
return factory.Str(doc, bgn, ++pos, exact); // ++: quote_end
|
return Json_itm_str.NewByDoc(doc, bgn, ++pos, escaped); // ++: quote_end
|
||||||
default:
|
default:
|
||||||
++pos;
|
++pos;
|
||||||
break;
|
break;
|
||||||
@ -149,16 +148,16 @@ public class Json_parser {
|
|||||||
}
|
}
|
||||||
num_parser.Parse(src, num_bgn, pos);
|
num_parser.Parse(src, num_bgn, pos);
|
||||||
if (num_parser.Has_frac())
|
if (num_parser.Has_frac())
|
||||||
return factory.Decimal(doc, num_bgn, pos);
|
return Json_itm_decimal.NewByDoc(doc, num_bgn, pos);
|
||||||
else {
|
else {
|
||||||
if (num_parser.Is_int())
|
if (num_parser.Is_int())
|
||||||
return factory.Int(doc, num_bgn, pos);
|
return Json_itm_int.NewByDoc(doc, num_bgn, pos);
|
||||||
else
|
else
|
||||||
return factory.Long(doc, num_bgn, pos);
|
return Json_itm_long.NewByDoc(doc, num_bgn, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Json_ary Make_ary(Json_doc doc) {
|
private Json_ary Make_ary(Json_doc doc) {
|
||||||
Json_ary rv = factory.Ary(pos++, pos); // brack_bgn
|
Json_ary rv = Json_ary.NewByDoc(doc, pos++, pos); // brack_bgn
|
||||||
while (pos < src_len) {
|
while (pos < src_len) {
|
||||||
Skip_ws();
|
Skip_ws();
|
||||||
if (src[pos] == Byte_ascii.Brack_end) {++pos; return rv;}
|
if (src[pos] == Byte_ascii.Brack_end) {++pos; return rv;}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,13 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import gplx.core.primitives.*;
|
|
||||||
|
import gplx.Keyval_;
|
||||||
|
import gplx.Ordered_hash;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.primitives.Int_obj_val;
|
||||||
|
|
||||||
public class Json_parser__list_nde__base extends Json_parser__itm__base {
|
public class Json_parser__list_nde__base extends Json_parser__itm__base {
|
||||||
public void Parse_grp(String context, Json_grp grp) {
|
public void Parse_grp(String context, Json_grp grp) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -22,11 +27,11 @@ public class Json_parser__list_nde__base extends Json_parser__itm__base {
|
|||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_nde sub = null;
|
Json_nde sub = null;
|
||||||
if (grp.Tid() == Json_itm_.Tid__nde) {
|
if (grp.Tid() == Json_itm_.Tid__nde) {
|
||||||
Json_kv kv = Json_nde.cast(grp).Get_at_as_kv(i);
|
Json_kv kv = Json_nde.Cast(grp).Get_at_as_kv(i);
|
||||||
sub = kv.Val_as_nde();
|
sub = kv.Val_as_nde();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sub = Json_nde.cast(grp.Get_at(i));
|
sub = Json_nde.Cast(grp.Get_at(i));
|
||||||
}
|
}
|
||||||
Parse_nde(context, sub);
|
Parse_nde(context, sub);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,83 +13,92 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
package gplx.langs.jsons;
|
||||||
import org.junit.*;
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Decimal_adp;
|
||||||
|
import gplx.Decimal_adp_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Json_parser_tst {
|
public class Json_parser_tst {
|
||||||
private final Json_parser_fxt fxt = new Json_parser_fxt();
|
private final Json_parser_fxt fxt = new Json_parser_fxt();
|
||||||
@Before public void init() {fxt.Clear();}
|
@Test public void Null() {fxt.Test_parse_obj("{'k0':null}" , null);}
|
||||||
@Test public void Null() {fxt.Test_parse_val0("{'k0':null}" , null);}
|
@Test public void Bool_n() {fxt.Test_parse_obj("{'k0':false}" , false);}
|
||||||
@Test public void Bool_n() {fxt.Test_parse_val0("{'k0':false}" , false);}
|
@Test public void Bool_y() {fxt.Test_parse_obj("{'k0':true}" , true);}
|
||||||
@Test public void Bool_y() {fxt.Test_parse_val0("{'k0':true}" , true);}
|
@Test public void Num() {fxt.Test_parse_obj("{'k0':123}" , 123);}
|
||||||
@Test public void Num() {fxt.Test_parse_val0("{'k0':123}" , 123);}
|
@Test public void Num_neg() {fxt.Test_parse_obj("{'k0':-123}" , -123);}
|
||||||
@Test public void Num_neg() {fxt.Test_parse_val0("{'k0':-123}" , -123);}
|
@Test public void Str() {fxt.Test_parse_obj("{'k0':'v0'}" , "v0");}
|
||||||
@Test public void Str() {fxt.Test_parse_val0("{'k0':'v0'}" , "v0");}
|
@Test public void Str_esc_quote() {fxt.Test_parse_obj("{'k0':'a\\\"b'}" , "a\"b");}
|
||||||
@Test public void Str_esc_quote() {fxt.Test_parse_val0("{'k0':'a\\\"b'}" , "a\"b");}
|
@Test public void Str_encoded_basic() {fxt.Test_parse_obj("{'k0':'a\\u0021b'}" , "a!b");}
|
||||||
@Test public void Str_encoded_basic() {fxt.Test_parse_val0("{'k0':'a\\u0021b'}" , "a!b");}
|
@Test public void Str_encoded_surrogate() {fxt.Test_parse_obj("{'k0':'a\\ud83c\\udf0eb'}", "a🌎b");} // check for UTF surrogate-pairs; symbol is earth globe americas (U+1F30E); ISSUE#:487; DATE:2019-06-02
|
||||||
@Test public void Str_encoded_surrogate() {fxt.Test_parse_val0("{'k0':'a\\ud83c\\udf0eb'}", "a🌎b");} // check for UTF surrogate-pairs; symbol is earth globe americas (U+1F30E); ISSUE#:487; DATE:2019-06-02
|
@Test public void Num_dec() {fxt.Test_parse_dec("{'k0':1.23}" , Decimal_adp_.parse("1.23"));}
|
||||||
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1.23")));}
|
@Test public void Num_exp() {fxt.Test_parse_obj("{'k0':1e+2}" , 100);}
|
||||||
@Test public void Num_exp() {fxt.Test_parse("{'k0':1e+2}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1e+2")));}
|
@Test public void Num_mix() {fxt.Test_parse_dec("{'k0':-1.23e-1}" , Decimal_adp_.parse("-1.23e-1"));}
|
||||||
@Test public void Num_mix() {fxt.Test_parse("{'k0':-1.23e-1}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "-1.23e-1")));}
|
@Test public void Str_many() {fxt.Test_parse("{'k0':'v0','k1':'v1','k2':'v2'}" , fxt.Init_nde().Add_many(fxt.Init_kv("k0", "v0"), fxt.Init_kv("k1", "v1"), fxt.Init_kv("k2", "v2")));}
|
||||||
@Test public void Str_many() {fxt.Test_parse("{'k0':'v0','k1':'v1','k2':'v2'}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0"), fxt.itm_kv_("k1", "v1"), fxt.itm_kv_("k2", "v2")));}
|
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.Init_nde().Add_many(fxt.Init_kv_ary_int("k0")));}
|
||||||
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0")));}
|
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.Init_nde().Add_many(fxt.Init_kv_ary_int("k0", 1, 2, 3)));}
|
||||||
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));}
|
@Test public void Ary_str() {fxt.Test_parse("{'k0':['a','b','c']}" , fxt.Init_nde().Add_many(fxt.Init_kvary_str_("k0", "a", "b", "c")));}
|
||||||
@Test public void Ary_str() {fxt.Test_parse("{'k0':['a','b','c']}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_str_("k0", "a", "b", "c")));}
|
@Test public void Ary_ws() {fxt.Test_parse("{'k0': [ 1 , 2 , 3 ] }" , fxt.Init_nde().Add_many(fxt.Init_kv_ary_int("k0", 1, 2, 3)));}
|
||||||
@Test public void Ary_ws() {fxt.Test_parse("{'k0': [ 1 , 2 , 3 ] }", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));}
|
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1}}" , fxt.Init_nde().Add_many(fxt.Init_kv("k0", fxt.Init_nde().Add_many(fxt.Init_kv("k00", 1)))));}
|
||||||
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));}
|
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}" , fxt.Init_nde().Add_many(fxt.Init_kv("k0", fxt.Init_nde())));}
|
||||||
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_())));}
|
@Test public void Subs_ws() {fxt.Test_parse("{'k0': { 'k00' : 1 } }" , fxt.Init_nde().Add_many(fxt.Init_kv("k0", fxt.Init_nde().Add_many(fxt.Init_kv("k00", 1)))));}
|
||||||
@Test public void Subs_ws() {fxt.Test_parse("{'k0': { 'k00' : 1 } }", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));}
|
@Test public void Ws() {fxt.Test_parse(" { 'k0' : 'v0' } " , fxt.Init_nde().Add_many(fxt.Init_kv("k0", "v0")));}
|
||||||
@Test public void Ws() {fxt.Test_parse(" { 'k0' : 'v0' } ", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0")));}
|
@Test public void Root_is_ary() {fxt.Test_parse("[1,2,3]" , fxt.Init_ary().Add_many(fxt.Init_int(1), fxt.Init_int(2), fxt.Init_int(3)));}
|
||||||
@Test public void Root_is_ary() {fxt.Test_parse("[ 1 , 2 , 3 ]", fxt.itm_ary_().Add_many(fxt.itm_int_(1), fxt.itm_int_(2), fxt.itm_int_(3)));}
|
|
||||||
public static String Replace_apos_as_str(String v) {return String_.new_u8(Replace_apos(Bry_.new_u8(v)));}
|
|
||||||
public static byte[] Replace_apos(byte[] v) {return Bry_.Replace(v, Byte_ascii.Apos, Byte_ascii.Quote);}
|
|
||||||
}
|
}
|
||||||
class Json_parser_fxt {
|
class Json_parser_fxt {
|
||||||
public void Clear() {
|
private final Json_parser parser = new Json_parser();
|
||||||
if (parser == null) {
|
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||||
parser = new Json_parser();
|
public Json_itm Init_int(int v) {return Json_itm_int.NewByVal(v);}
|
||||||
factory = parser.Factory();
|
public Json_itm Init_str(String v) {return Json_itm_str.NewByVal(v);}
|
||||||
}
|
public Json_ary Init_ary() {return Json_ary.NewByVal();}
|
||||||
} Json_parser parser; Json_factory factory; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
public Json_nde Init_nde() {return Json_nde.NewByVal();}
|
||||||
public Json_itm itm_int_(int v) {return Json_itm_tmp.new_int_(v);}
|
public Json_kv Init_kv_null(String k) {return new Json_kv(Init_str(k), Json_itm_null.Null);}
|
||||||
Json_itm itm_str_(String v) {return Json_itm_tmp.new_str_(v);}
|
public Json_kv Init_kv(String k, String v) {return new Json_kv(Init_str(k), Init_str(v));}
|
||||||
public Json_ary itm_ary_() {return factory.Ary(-1, -1);}
|
public Json_kv Init_kv(String k, int v) {return new Json_kv(Init_str(k), Init_int(v));}
|
||||||
public Json_nde itm_nde_() {return factory.Nde(null, -1);}
|
public Json_kv Init_kv(String k, boolean v) {return new Json_kv(Init_str(k), v ? Json_itm_bool.Bool_y : Json_itm_bool.Bool_n);}
|
||||||
public Json_kv itm_kv_null_(String k) {return factory.Kv(itm_str_(k), factory.Null());}
|
public Json_kv Init_kv(String k, Json_nde v) {return new Json_kv(Init_str(k), v);}
|
||||||
public Json_kv itm_kv_(String k, String v) {return factory.Kv(itm_str_(k), itm_str_(v));}
|
public Json_kv Init_kv_ary_int(String k, int... v) {
|
||||||
public Json_kv itm_kv_(String k, int v) {return factory.Kv(itm_str_(k), itm_int_(v));}
|
Json_ary ary = Json_ary.NewByVal();
|
||||||
public Json_kv itm_kv_(String k, boolean v) {return factory.Kv(itm_str_(k), v ? factory.Bool_y() : factory.Bool_n());}
|
|
||||||
public Json_kv itm_kv_dec_(String k, String v) {return factory.Kv(itm_str_(k), new Json_itm_tmp(Json_itm_.Tid__decimal, v));}
|
|
||||||
public Json_kv itm_kv_(String k, Json_nde v) {return factory.Kv(itm_str_(k), v);}
|
|
||||||
public Json_kv itm_kv_ary_int_(String k, int... v) {
|
|
||||||
Json_ary ary = factory.Ary(-1, -1);
|
|
||||||
int len = v.length;
|
int len = v.length;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
ary.Add(itm_int_(v[i]));
|
ary.Add(Init_int(v[i]));
|
||||||
return factory.Kv(itm_str_(k), ary);
|
return new Json_kv(Init_str(k), ary);
|
||||||
}
|
}
|
||||||
public Json_kv itm_kv_ary_str_(String k, String... v) {
|
public Json_kv Init_kvary_str_(String k, String... v) {
|
||||||
Json_ary ary = factory.Ary(-1, -1);
|
Json_ary ary = Json_ary.NewByVal();
|
||||||
int len = v.length;
|
int len = v.length;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
ary.Add(itm_str_(v[i]));
|
ary.Add(Init_str(v[i]));
|
||||||
return factory.Kv(itm_str_(k), ary);
|
return new Json_kv(Init_str(k), ary);
|
||||||
}
|
}
|
||||||
public void Test_parse(String raw_str, Json_itm... expd_ary) {
|
public void Test_parse(String raw_str, Json_itm... expd_ary) {
|
||||||
byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
|
byte[] raw = Bry_.new_u8(Json_doc.Make_str_by_apos(raw_str));
|
||||||
Json_doc doc = parser.Parse(raw);
|
Json_doc doc = parser.Parse(raw);
|
||||||
doc.Root_grp().Print_as_json(tmp_bfr, 0);
|
doc.Root_grp().Print_as_json(tmp_bfr, 0);
|
||||||
String actl = tmp_bfr.To_str_and_clear();
|
String actl = tmp_bfr.To_str_and_clear();
|
||||||
String expd = Xto_str(raw, doc, expd_ary, 0, expd_ary.length);
|
String expd = Xto_str(raw, doc, expd_ary, 0, expd_ary.length);
|
||||||
Tfds.Eq_str_lines(expd, actl, actl);
|
Tfds.Eq_str_lines(expd, actl, actl);
|
||||||
}
|
}
|
||||||
public void Test_parse_val0(String raw_str, Object expd) {
|
public void Test_parse_obj(String raw_str, Object expd) {
|
||||||
byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
|
Json_kv kv = Parse_and_get_kv0(raw_str);
|
||||||
Json_doc doc = parser.Parse(raw);
|
|
||||||
Json_kv kv = Json_kv.cast(doc.Root_nde().Get_at(0)); // assume root has kv as first sub; EX: {"a":"b"}
|
|
||||||
Object actl = kv.Val().Data(); // NOTE: Data_bry is escaped val; EX: a\"b has DataBry of a"b
|
Object actl = kv.Val().Data(); // NOTE: Data_bry is escaped val; EX: a\"b has DataBry of a"b
|
||||||
Tfds.Eq(expd, actl);
|
Gftest.Eq__obj_or_null(expd, actl);
|
||||||
}
|
}
|
||||||
String Xto_str(byte[] raw, Json_doc doc, Json_itm[] ary, int bgn, int end) {
|
public void Test_parse_dec(String raw_str, Decimal_adp expd) {
|
||||||
|
Json_kv kv = Parse_and_get_kv0(raw_str);
|
||||||
|
Json_itm_decimal decimal_itm = (Json_itm_decimal)kv.Val();
|
||||||
|
Gftest.Eq__bool(true, decimal_itm.Data_as_decimal().Eq(expd));
|
||||||
|
}
|
||||||
|
private Json_kv Parse_and_get_kv0(String raw_str) {
|
||||||
|
byte[] raw = Bry_.new_u8(Json_doc.Make_str_by_apos(raw_str));
|
||||||
|
Json_doc doc = parser.Parse(raw);
|
||||||
|
return Json_kv.Cast(doc.Root_nde().Get_at(0)); // assume root has kv as first sub; EX: {"a":"b"}
|
||||||
|
}
|
||||||
|
private String Xto_str(byte[] raw, Json_doc doc, Json_itm[] ary, int bgn, int end) {
|
||||||
for (int i = bgn; i < end; i++) {
|
for (int i = bgn; i < end; i++) {
|
||||||
Json_itm itm = ary[i];
|
Json_itm itm = ary[i];
|
||||||
itm.Print_as_json(tmp_bfr, 0);
|
itm.Print_as_json(tmp_bfr, 0);
|
||||||
|
112
400_xowa/src/gplx/langs/mustaches/JsonMustacheNde.java
Normal file
112
400_xowa/src/gplx/langs/mustaches/JsonMustacheNde.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_itm_;
|
||||||
|
import gplx.langs.jsons.Json_kv;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.objects.Object_;
|
||||||
|
|
||||||
|
public class JsonMustacheNde implements Mustache_doc_itm {
|
||||||
|
private final Json_nde nde;
|
||||||
|
public JsonMustacheNde(Json_nde nde) {this.nde = nde;}
|
||||||
|
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||||
|
Json_itm itm = nde.Get_itm(Bry_.new_u8(key));
|
||||||
|
if (itm == null) { // mustacheKey does not exist in current jsonNde
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else { // mustacheKey exists
|
||||||
|
switch (itm.Tid()) {
|
||||||
|
// array / bool node -> ignore; EX: `{{#person}}Never shown{{/person}}`
|
||||||
|
case Json_itm_.Tid__bool:
|
||||||
|
case Json_itm_.Tid__ary:
|
||||||
|
case Json_itm_.Tid__nde:
|
||||||
|
return false;
|
||||||
|
// item node -> render it; EX: `Hello {{name}}`
|
||||||
|
default:
|
||||||
|
bfr.Add_bry(Json_kv.Cast(itm).Val_as_bry());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||||
|
Json_itm itm = nde.Get_itm(Bry_.new_u8(key));
|
||||||
|
if (itm == null) { // mustacheKey does not exist in current jsonNde
|
||||||
|
return Mustache_doc_itm_.Ary__bool__n;
|
||||||
|
}
|
||||||
|
else { // mustacheKey exists
|
||||||
|
if (itm.Tid() == Json_itm_.Tid__kv) {
|
||||||
|
Json_kv kv = Json_kv.Cast(itm);
|
||||||
|
switch (kv.Val().Tid()) {
|
||||||
|
// bool node -> render; EX: `{{#person}}Never shown{{/person}}`
|
||||||
|
case Json_itm_.Tid__bool:
|
||||||
|
boolean dataVal = Bool_.Cast(kv.Val().Data());
|
||||||
|
return dataVal ? Mustache_doc_itm_.Ary__bool__y : Mustache_doc_itm_.Ary__bool__n;
|
||||||
|
// array node -> render; EX: `{{#repo}} <b>{{name}}</b>{{/repo}}`
|
||||||
|
case Json_itm_.Tid__ary:
|
||||||
|
return ToJsonMustachNdeAry(itm);
|
||||||
|
// item node -> render only if key matchers
|
||||||
|
default:
|
||||||
|
return new Mustache_doc_itm[] {new JsonMustacheVal(true, key, kv.Val().Data())};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Mustache_doc_itm_.Ary__bool__n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static Mustache_doc_itm[] ToJsonMustachNdeAry(Json_itm itm) {
|
||||||
|
Json_ary dataAry = Json_ary.cast_or_null(Json_kv.Cast(itm).Val());
|
||||||
|
int subs_len = dataAry.Len();
|
||||||
|
Mustache_doc_itm[] rv = new Mustache_doc_itm[subs_len];
|
||||||
|
for (int i = 0; i < subs_len; i++) {
|
||||||
|
Json_itm sub = dataAry.Get_at(i);
|
||||||
|
if (sub.Tid() == Json_itm_.Tid__nde) {
|
||||||
|
rv[i] = new JsonMustacheNde((Json_nde)sub);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rv[i] = new JsonMustacheVal(false, Mustache_tkn_def.ItemString, sub.Data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class JsonMustacheVal implements Mustache_doc_itm {
|
||||||
|
private final boolean fromArray;
|
||||||
|
private final String jsonKey;
|
||||||
|
private final Object jsonVal;
|
||||||
|
public JsonMustacheVal(boolean fromArray, String jsonKey, Object jsonVal) {
|
||||||
|
this.fromArray = fromArray;
|
||||||
|
this.jsonKey = jsonKey;
|
||||||
|
this.jsonVal = jsonVal;
|
||||||
|
}
|
||||||
|
public boolean Mustache__write(String mustacheKey, Mustache_bfr bfr) {
|
||||||
|
if ( (String_.Eq(mustacheKey, jsonKey)) // print if `{{match}}`; EX: `{{#prop}}{{prop}}{{/prop}}`
|
||||||
|
|| (String_.Eq(mustacheKey, Mustache_tkn_def.ItemString) && fromArray)) { // print if `{{.}}` and from array; EX: `{{#array}}{{.}}{{/array}}`
|
||||||
|
bfr.Add_bry(Bry_.new_u8(Object_.To_str(jsonVal)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,8 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
import gplx.langs.jsons.*;
|
|
||||||
public interface Mustache_doc_itm {
|
public interface Mustache_doc_itm {
|
||||||
boolean Mustache__write(String key, Mustache_bfr bfr);
|
boolean Mustache__write(String key, Mustache_bfr bfr);
|
||||||
Mustache_doc_itm[] Mustache__subs(String key);
|
Mustache_doc_itm[] Mustache__subs(String key);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,18 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
import org.junit.*; import gplx.core.primitives.*;
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Hash_adp;
|
||||||
|
import gplx.Hash_adp_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import gplx.core.primitives.Bool_obj_ref;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.jsons.Json_parser;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Mustache_itm_render_tst {
|
public class Mustache_itm_render_tst {
|
||||||
private final Mustache_itm_render_fxt fxt = new Mustache_itm_render_fxt();
|
private final Mustache_itm_render_fxt fxt = new Mustache_itm_render_fxt();
|
||||||
@Test public void Text() {
|
@Test public void Text() {
|
||||||
@ -121,6 +131,13 @@ public class Mustache_itm_render_tst {
|
|||||||
, "a1"
|
, "a1"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@Test public void Dot() {
|
||||||
|
fxt.Test__parse
|
||||||
|
( "{'subs':['a', 'b', 'c', 'd']}"
|
||||||
|
, "{{#subs}}{{.}},{{/subs}}"
|
||||||
|
, "a,b,c,d,"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class Mustache_itm_render_fxt {
|
class Mustache_itm_render_fxt {
|
||||||
private final Mustache_tkn_parser parser = new Mustache_tkn_parser();
|
private final Mustache_tkn_parser parser = new Mustache_tkn_parser();
|
||||||
@ -136,6 +153,16 @@ class Mustache_itm_render_fxt {
|
|||||||
actl_itm.Render(bfr, ctx);
|
actl_itm.Render(bfr, ctx);
|
||||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||||
}
|
}
|
||||||
|
public void Test__parse(String jdoc, String src_str, String expd) {
|
||||||
|
Json_nde jnde = Json_parser.ParseToJdoc(Json_doc.Make_str_by_apos(jdoc)).Root_nde();
|
||||||
|
JsonMustacheNde nde = new JsonMustacheNde(jnde);
|
||||||
|
|
||||||
|
byte[] src_bry = Bry_.new_a7(src_str);
|
||||||
|
Mustache_tkn_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length);
|
||||||
|
ctx.Init(nde);
|
||||||
|
actl_itm.Render(bfr, ctx);
|
||||||
|
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class Mustache_doc_itm__mock implements Mustache_doc_itm {
|
class Mustache_doc_itm__mock implements Mustache_doc_itm {
|
||||||
private final Hash_adp hash_prop = Hash_adp_.New(), hash_bool = Hash_adp_.New(), hash_subs = Hash_adp_.New();
|
private final Hash_adp hash_prop = Hash_adp_.New(), hash_bool = Hash_adp_.New(), hash_subs = Hash_adp_.New();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,15 +13,24 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
|
||||||
public class Mustache_render_ctx {
|
public class Mustache_render_ctx {
|
||||||
private final List_adp stack = List_adp_.New();
|
private final List_adp stack = List_adp_.New();
|
||||||
private Mustache_doc_itm cur;
|
private Mustache_doc_itm cur;
|
||||||
private Mustache_doc_itm[] subs; private int subs_idx, subs_len; private byte cur_is_bool;
|
private Mustache_doc_itm[] subs;
|
||||||
|
private int subs_idx, subs_len;
|
||||||
|
private byte cur_is_bool;
|
||||||
|
|
||||||
public Mustache_render_ctx Init(Mustache_doc_itm cur) {
|
public Mustache_render_ctx Init(Mustache_doc_itm cur) {
|
||||||
this.cur = cur;
|
this.cur = cur;
|
||||||
this.subs = null;
|
this.subs = null;
|
||||||
this.subs_idx = subs_len = 0; this.cur_is_bool = Bool_.__byte;
|
this.subs_idx = subs_len = 0;
|
||||||
|
this.cur_is_bool = Bool_.__byte;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public boolean Render_variable(Mustache_bfr bfr, String key) {
|
public boolean Render_variable(Mustache_bfr bfr, String key) {
|
||||||
@ -30,10 +39,12 @@ public class Mustache_render_ctx {
|
|||||||
Mustache_doc_itm itm = cur;
|
Mustache_doc_itm itm = cur;
|
||||||
while (itm != Mustache_doc_itm_.Null_itm) {
|
while (itm != Mustache_doc_itm_.Null_itm) {
|
||||||
boolean resolved = itm.Mustache__write(key, bfr);
|
boolean resolved = itm.Mustache__write(key, bfr);
|
||||||
|
// current itm handles key -> exit
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
rv = true;
|
rv = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// current itm does not handle key -> go up stack
|
||||||
else {
|
else {
|
||||||
--stack_pos;
|
--stack_pos;
|
||||||
if (stack_pos == -1) // nothing else in stack
|
if (stack_pos == -1) // nothing else in stack
|
||||||
@ -47,12 +58,15 @@ public class Mustache_render_ctx {
|
|||||||
public void Section_bgn(String key) {
|
public void Section_bgn(String key) {
|
||||||
Mustache_stack_itm stack_itm = new Mustache_stack_itm(cur, subs, subs_idx, subs_len, cur_is_bool); // note that cur is "owner" since subs_idx == 0
|
Mustache_stack_itm stack_itm = new Mustache_stack_itm(cur, subs, subs_idx, subs_len, cur_is_bool); // note that cur is "owner" since subs_idx == 0
|
||||||
stack.Add(stack_itm);
|
stack.Add(stack_itm);
|
||||||
subs = cur.Mustache__subs(key); if (subs == null) subs = Mustache_doc_itm_.Ary__empty; // subs == null if property does not exist; EX: "folder{{#files}}file{{/files}}" and folder = new Folder(File[0]);
|
subs = cur.Mustache__subs(key);
|
||||||
|
if (subs == null) // subs == null if property does not exist; EX: "folder{{#files}}file{{/files}}" and folder = new Folder(File[0]);
|
||||||
|
subs = Mustache_doc_itm_.Ary__empty;
|
||||||
subs_len = subs.length;
|
subs_len = subs.length;
|
||||||
subs_idx = -1;
|
subs_idx = -1;
|
||||||
}
|
}
|
||||||
public boolean Section_do(boolean inverted) {
|
public boolean Section_do(boolean inverted) {
|
||||||
if (++subs_idx >= subs_len) return false;
|
if (++subs_idx >= subs_len)
|
||||||
|
return false;
|
||||||
Mustache_doc_itm sub = subs[subs_idx];
|
Mustache_doc_itm sub = subs[subs_idx];
|
||||||
if (subs_idx == 0) { // special logic to handle 1st item; note that there always be at least one item
|
if (subs_idx == 0) { // special logic to handle 1st item; note that there always be at least one item
|
||||||
if (sub == Mustache_doc_itm_.Itm__bool__n) {
|
if (sub == Mustache_doc_itm_.Itm__bool__n) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,7 +13,13 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Byte_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.String_;
|
||||||
|
|
||||||
class Mustache_tkn_def {
|
class Mustache_tkn_def {
|
||||||
public byte[] Variable_lhs = Dflt_variable_lhs;
|
public byte[] Variable_lhs = Dflt_variable_lhs;
|
||||||
public byte[] Variable_rhs = Dflt_variable_rhs;
|
public byte[] Variable_rhs = Dflt_variable_rhs;
|
||||||
@ -31,9 +37,13 @@ class Mustache_tkn_def {
|
|||||||
, Grp_end = Byte_ascii.Slash // {{/section}}
|
, Grp_end = Byte_ascii.Slash // {{/section}}
|
||||||
, Inverted = Byte_ascii.Pow // {{^inverted}}
|
, Inverted = Byte_ascii.Pow // {{^inverted}}
|
||||||
, Comment = Byte_ascii.Bang // {{!comment}}
|
, Comment = Byte_ascii.Bang // {{!comment}}
|
||||||
, Partial = Byte_ascii.Angle_bgn // {{>partial}}
|
, Partial = Byte_ascii.Angle_end // {{>partial}}
|
||||||
, Delimiter_bgn = Byte_ascii.Eq // {{=<% %>=}}
|
, Delimiter_bgn = Byte_ascii.Eq // {{=<% %>=}}
|
||||||
, Delimiter_end = Byte_ascii.Curly_end // {{=<% %>=}}
|
, Delimiter_end = Byte_ascii.Curly_end // {{=<% %>=}}
|
||||||
|
, Item = Byte_ascii.Dot // {{.}}
|
||||||
|
;
|
||||||
|
public static final String
|
||||||
|
ItemString = String_.new_u8(Byte_.To_bry(Item))
|
||||||
;
|
;
|
||||||
public Mustache_tkn_def() {
|
public Mustache_tkn_def() {
|
||||||
Variable_lhs_len = Variable_lhs.length;
|
Variable_lhs_len = Variable_lhs.length;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,7 +13,15 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.Io_url;
|
||||||
|
import gplx.String_;
|
||||||
|
|
||||||
public interface Mustache_tkn_itm {
|
public interface Mustache_tkn_itm {
|
||||||
int Tid();
|
int Tid();
|
||||||
String Key();
|
String Key();
|
||||||
@ -103,8 +111,16 @@ class Mustache_tkn_inverted extends Mustache_tkn_base { // EX: {{^section}}missi
|
|||||||
@Override public void Render(Mustache_bfr bfr, Mustache_render_ctx ctx) {Mustache_tkn_section.Render_static(Bool_.Y, this, bfr, ctx);}
|
@Override public void Render(Mustache_bfr bfr, Mustache_render_ctx ctx) {Mustache_tkn_section.Render_static(Bool_.Y, this, bfr, ctx);}
|
||||||
}
|
}
|
||||||
class Mustache_tkn_partial extends Mustache_tkn_base { // EX: {{>a}} -> abc (deferred eval)
|
class Mustache_tkn_partial extends Mustache_tkn_base { // EX: {{>a}} -> abc (deferred eval)
|
||||||
public Mustache_tkn_partial(byte[] key) {super(Mustache_tkn_itm_.Tid__partial, key);}
|
private Mustache_tkn_itm template_root;
|
||||||
|
public Mustache_tkn_partial(byte[] key, Io_url dir) {
|
||||||
|
super(Mustache_tkn_itm_.Tid__partial, key);
|
||||||
|
Mustache_tkn_parser parser = new Mustache_tkn_parser(dir);
|
||||||
|
template_root = parser.Parse(String_.new_a7(Bry_.Trim_bgn(key, Byte_ascii.Space, 0)));
|
||||||
|
}
|
||||||
|
@Override public void Render(Mustache_bfr bfr, Mustache_render_ctx ctx) {
|
||||||
|
template_root.Render(bfr, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class Mustache_tkn_delimiter extends Mustache_tkn_base {// EX: {{=<% %>=}} -> <% variable %>
|
class Mustache_tkn_delimiter extends Mustache_tkn_base { // EX: {{=<% %>=}} -> <% variable %>
|
||||||
public Mustache_tkn_delimiter(byte[] key) {super(Mustache_tkn_itm_.Tid__delimiter, key);}
|
public Mustache_tkn_delimiter(byte[] key) {super(Mustache_tkn_itm_.Tid__delimiter, key);}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,10 +13,32 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_find_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Err;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.Io_mgr;
|
||||||
|
import gplx.Io_url;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
|
||||||
public class Mustache_tkn_parser {
|
public class Mustache_tkn_parser {
|
||||||
private byte[] src; private int src_end;
|
private byte[] src; private int src_end;
|
||||||
|
private Io_url template_root;
|
||||||
private final Mustache_tkn_def tkn_def = new Mustache_tkn_def();
|
private final Mustache_tkn_def tkn_def = new Mustache_tkn_def();
|
||||||
|
public Mustache_tkn_parser() {
|
||||||
|
}
|
||||||
|
public Mustache_tkn_parser(Io_url template_root) {
|
||||||
|
this.template_root = template_root;
|
||||||
|
}
|
||||||
|
public Mustache_tkn_itm Parse(String template) { return Parse(template, Bry_.Empty); }
|
||||||
|
public Mustache_tkn_itm Parse(String template, byte[] default_text) {
|
||||||
|
byte[] template_data = Io_mgr.Instance.LoadFilBryOr(template_root.GenSubFil_nest(template + ".mustache"), default_text);
|
||||||
|
return Parse(template_data, 0, template_data.length);
|
||||||
|
}
|
||||||
public Mustache_tkn_itm Parse(byte[] src) {return Parse(src, 0, src.length);}
|
public Mustache_tkn_itm Parse(byte[] src) {return Parse(src, 0, src.length);}
|
||||||
public Mustache_tkn_itm Parse(byte[] src, int src_bgn, int src_end) {
|
public Mustache_tkn_itm Parse(byte[] src, int src_bgn, int src_end) {
|
||||||
this.src = src; this.src_end = src_end;
|
this.src = src; this.src_end = src_end;
|
||||||
@ -80,7 +102,7 @@ public class Mustache_tkn_parser {
|
|||||||
default: throw Err_.new_unhandled(tkn_data.tid);
|
default: throw Err_.new_unhandled(tkn_data.tid);
|
||||||
case Mustache_tkn_def.Variable: tkn = new Mustache_tkn_variable(val_bry); break;
|
case Mustache_tkn_def.Variable: tkn = new Mustache_tkn_variable(val_bry); break;
|
||||||
case Mustache_tkn_def.Comment: tkn = new Mustache_tkn_comment(); break;
|
case Mustache_tkn_def.Comment: tkn = new Mustache_tkn_comment(); break;
|
||||||
case Mustache_tkn_def.Partial: tkn = new Mustache_tkn_partial(val_bry); break;
|
case Mustache_tkn_def.Partial: tkn = new Mustache_tkn_partial(val_bry, template_root); break;
|
||||||
case Mustache_tkn_def.Delimiter_bgn: tkn = new Mustache_tkn_delimiter(val_bry); break; // TODO_OLD: implement delimiter; EX: {{=<% %>=}}
|
case Mustache_tkn_def.Delimiter_bgn: tkn = new Mustache_tkn_delimiter(val_bry); break; // TODO_OLD: implement delimiter; EX: {{=<% %>=}}
|
||||||
case Mustache_tkn_def.Escape_bgn: tkn = new Mustache_tkn_escape(val_bry); break;
|
case Mustache_tkn_def.Escape_bgn: tkn = new Mustache_tkn_escape(val_bry); break;
|
||||||
case Mustache_tkn_def.Section: tkn = new Mustache_tkn_section(val_bry); break;
|
case Mustache_tkn_def.Section: tkn = new Mustache_tkn_section(val_bry); break;
|
||||||
|
@ -0,0 +1,275 @@
|
|||||||
|
package gplx.xowa.addons.htmls.sidebars;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Io_url;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.mustaches.JsonMustacheNde;
|
||||||
|
import gplx.langs.mustaches.Mustache_bfr;
|
||||||
|
import gplx.langs.mustaches.Mustache_render_ctx;
|
||||||
|
import gplx.langs.mustaches.Mustache_tkn_itm;
|
||||||
|
import gplx.langs.mustaches.Mustache_tkn_parser;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.langs.msgs.Xol_msg_mgr;
|
||||||
|
|
||||||
|
public class Db_Nav_template {
|
||||||
|
public Mustache_tkn_itm Navigation_root() {return navigation_root;} private Mustache_tkn_itm navigation_root;
|
||||||
|
private Xol_msg_mgr msg_mgr;
|
||||||
|
private Json_nde msgdata;
|
||||||
|
private Xowe_wiki wiki;
|
||||||
|
private static boolean once = true;
|
||||||
|
private static Mustache_tkn_itm menu_root;
|
||||||
|
|
||||||
|
public static void Build_Sidebar(Xowe_wiki wiki, Bry_bfr bfr, byte[] id, byte[] text, byte[] itms) {
|
||||||
|
if (once) {
|
||||||
|
once = false;
|
||||||
|
Io_url template_root = wiki.Appe().Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "xtns", "Skin-Vector", "templates");
|
||||||
|
Mustache_tkn_parser parser = new Mustache_tkn_parser(template_root);
|
||||||
|
menu_root = parser.Parse("Menu");
|
||||||
|
}
|
||||||
|
Json_nde data = s_getMenuData(wiki, text, itms, MENU_TYPE_PORTAL);
|
||||||
|
|
||||||
|
// Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||||
|
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(new JsonMustacheNde(data));
|
||||||
|
Mustache_bfr mbfr = Mustache_bfr.New_bfr(bfr);
|
||||||
|
menu_root.Render(mbfr, mctx);
|
||||||
|
// byte[] result = mbfr.To_bry_and_clear();
|
||||||
|
// System.out.println(String_.new_u8(result));
|
||||||
|
}
|
||||||
|
public void Init(Xowe_wiki wiki) {
|
||||||
|
Io_url template_root = wiki.Appe().Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "xtns", "Skin-Vector", "templates");
|
||||||
|
Mustache_tkn_parser parser = new Mustache_tkn_parser(template_root);
|
||||||
|
navigation_root = parser.Parse("Navigation");
|
||||||
|
this.wiki = wiki;
|
||||||
|
|
||||||
|
msg_mgr = wiki.Lang().Msg_mgr();
|
||||||
|
build_msg();
|
||||||
|
|
||||||
|
Test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] msgs = new String[] {
|
||||||
|
"vector-opt-out-tooltip",
|
||||||
|
"vector-opt-out",
|
||||||
|
"navigation-heading",
|
||||||
|
"vector-action-toggle-sidebar",
|
||||||
|
"vector-jumptonavigation",
|
||||||
|
"vector-jumptosearch",
|
||||||
|
"vector-jumptocontent",
|
||||||
|
"sitesubtitle",
|
||||||
|
"sitetitle",
|
||||||
|
"tagline"
|
||||||
|
};
|
||||||
|
|
||||||
|
//all thes messages should be preprocessed (per language) as $data["msg-{$message}"] = $this->msg( $message )->text();
|
||||||
|
private void build_msg() {
|
||||||
|
int msg_len = msgs.length;
|
||||||
|
msgdata = Json_nde.NewByVal();
|
||||||
|
for (int i = 0; i < msg_len; i++) {
|
||||||
|
String msg = msgs[i];
|
||||||
|
msgdata.AddKvStr("msg-" + msg, msg_mgr.Val_by_str_or_empty(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void Test() {
|
||||||
|
Json_nde jnde = Json_nde.NewByVal();
|
||||||
|
jnde.AddKvStr("class", "CLASS");
|
||||||
|
jnde.AddKvStr("text", "TEXT");
|
||||||
|
jnde.AddKvStr("href", "URL_str");
|
||||||
|
jnde.AddKvBool("exists", true);
|
||||||
|
jnde.AddKvBool("primary", true);
|
||||||
|
jnde.AddKvStr("link-class", String_.Empty);
|
||||||
|
jnde.AddKvStr("context", "subject");
|
||||||
|
|
||||||
|
Json_nde namespaces = Json_nde.NewByVal();
|
||||||
|
namespaces.AddKvNde("subject", jnde);
|
||||||
|
|
||||||
|
//Json_nde data_namespaces = new Json_nde(null, -1);
|
||||||
|
msgdata.AddKvNde("data-namespace-tabs",
|
||||||
|
getMenuData(
|
||||||
|
Bry_.new_a7("namespaces"),
|
||||||
|
namespaces,
|
||||||
|
MENU_TYPE_TABS
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||||
|
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(new JsonMustacheNde(msgdata));
|
||||||
|
Mustache_bfr mbfr = Mustache_bfr.New_bfr(tmp_bfr);
|
||||||
|
navigation_root.Render(mbfr, mctx);
|
||||||
|
byte[] result = mbfr.To_bry_and_clear();
|
||||||
|
System.out.println(String_.new_u8(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Vector/SkinVector.php */
|
||||||
|
private static int MENU_TYPE_DROPDOWN = 0, MENU_TYPE_TABS = 1, MENU_TYPE_PORTAL = 2, MENU_TYPE_DEFAULT = 3;
|
||||||
|
private static byte[][] extraClasses = new byte[][] {
|
||||||
|
Bry_.new_a7("vector-menu vector-menu-dropdown vectorMenu"),
|
||||||
|
Bry_.new_a7("vector-menu vector-menu-tabs vectorTabs"),
|
||||||
|
Bry_.new_a7("vector-menu vector-menu-portal portal"),
|
||||||
|
Bry_.new_a7("vector-menu")
|
||||||
|
};
|
||||||
|
private Json_nde getMenuData(byte[] label, Json_nde urls, int type) { return getMenuData(label, urls, type, false); }
|
||||||
|
private Json_nde getMenuData(byte[] label_bry, Json_nde urls, int type, boolean setLabelToSelected) {
|
||||||
|
//private function getMenuData(
|
||||||
|
// string $label,
|
||||||
|
// array $urls = [],
|
||||||
|
// int $type = self::MENU_TYPE_DEFAULT,
|
||||||
|
// bool $setLabelToSelected = false
|
||||||
|
// ) : array {
|
||||||
|
// $skin = $this->getSkin();
|
||||||
|
// $extraClasses = [
|
||||||
|
// self::MENU_TYPE_DROPDOWN => 'vector-menu vector-menu-dropdown vectorMenu',
|
||||||
|
// self::MENU_TYPE_TABS => 'vector-menu vector-menu-tabs vectorTabs',
|
||||||
|
// self::MENU_TYPE_PORTAL => 'vector-menu vector-menu-portal portal',
|
||||||
|
// self::MENU_TYPE_DEFAULT => 'vector-menu',
|
||||||
|
// ];
|
||||||
|
// // A list of classes to apply the list element and override the default behavior.
|
||||||
|
// $listClasses = [
|
||||||
|
// // `.menu` is on the portal for historic reasons.
|
||||||
|
// // It should not be applied elsewhere per T253329.
|
||||||
|
// self::MENU_TYPE_DROPDOWN => 'menu vector-menu-content-list',
|
||||||
|
// ];
|
||||||
|
// $isPortal = $type === self::MENU_TYPE_PORTAL;
|
||||||
|
|
||||||
|
boolean isPortal = type == MENU_TYPE_PORTAL;
|
||||||
|
|
||||||
|
// // For some menu items, there is no language key corresponding with its menu key.
|
||||||
|
// // These inconsitencies are captured in MENU_LABEL_KEYS
|
||||||
|
// $msgObj = $skin->msg( self::MENU_LABEL_KEYS[ $label ] ?? $label );
|
||||||
|
//
|
||||||
|
// $props = [
|
||||||
|
// 'id' => "p-$label",
|
||||||
|
|
||||||
|
String label = String_.new_u8(label_bry);
|
||||||
|
String msg = label; // for now
|
||||||
|
String linkertooltip = String_.Empty;
|
||||||
|
String listClasses = type == MENU_TYPE_DROPDOWN
|
||||||
|
? "menu vector-menu-content-list"
|
||||||
|
: "vector-menu-content-list";
|
||||||
|
String plabel = "p-" + label;
|
||||||
|
|
||||||
|
Json_nde props = Json_nde.NewByVal();
|
||||||
|
props.AddKvStr("id", plabel);
|
||||||
|
|
||||||
|
// 'label-id' => "p-{$label}-label",
|
||||||
|
props.AddKvStr("label-id", plabel +"-label");
|
||||||
|
|
||||||
|
// If no message exists fallback to plain text (T252727)
|
||||||
|
// 'label' => $msgObj->exists() ? $msgObj->text() : $label,
|
||||||
|
props.AddKvStr("label", msg);
|
||||||
|
|
||||||
|
// 'list-classes' => $listClasses[$type] ?? 'vector-menu-content-list',
|
||||||
|
props.AddKvStr("list-classes", listClasses);
|
||||||
|
|
||||||
|
// 'html-items' => '',
|
||||||
|
|
||||||
|
// 'is-dropdown' => $type === self::MENU_TYPE_DROPDOWN,
|
||||||
|
props.AddKvBool("is-dropdown", type == MENU_TYPE_DROPDOWN);
|
||||||
|
props.AddKvStr("html-tooltip", wiki.Msg_mgr().Val_html_accesskey_and_title(plabel));
|
||||||
|
|
||||||
|
// 'html-tooltip' => Linker::tooltip( 'p-' . $label ),
|
||||||
|
props.AddKvStr("html-tooltip", linkertooltip);
|
||||||
|
|
||||||
|
// foreach ( $urls as $key => $item ) {
|
||||||
|
// $props['html-items'] .= $this->getSkin()->makeListItem( $key, $item );
|
||||||
|
// // Check the class of the item for a `selected` class and if so, propagate the items
|
||||||
|
// // label to the main label.
|
||||||
|
// if ( $setLabelToSelected ) {
|
||||||
|
// if ( isset( $item['class'] ) && stripos( $item['class'], 'selected' ) !== false ) {
|
||||||
|
// $props['label'] = $item['text'];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
props.AddKvStr("html-items", "<li id=\"ca-nstab-main\" class=\"selected\"><a href=\"/wiki/Main_Page\" title=\"View the content page [c]\" accesskey=\"c\">Main Page</a></li>");
|
||||||
|
|
||||||
|
// $afterPortal = '';
|
||||||
|
// if ( $isPortal ) {
|
||||||
|
// // The BaseTemplate::getAfterPortlet method ran the SkinAfterPortlet
|
||||||
|
// // hook and if content is added appends it to the html-after-portal method.
|
||||||
|
// // This replicates that historic behaviour.
|
||||||
|
// // This code should eventually be upstreamed to SkinMustache in core.
|
||||||
|
// // Currently in production this supports the Wikibase 'edit' link.
|
||||||
|
// $content = $this->getAfterPortlet( $label );
|
||||||
|
// if ( $content !== '' ) {
|
||||||
|
// $afterPortal = Html::rawElement(
|
||||||
|
// 'div',
|
||||||
|
// [ 'class' => [ 'after-portlet', 'after-portlet-' . $label ] ],
|
||||||
|
// $content
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// $props['html-after-portal'] = $afterPortal;
|
||||||
|
//
|
||||||
|
// // Mark the portal as empty if it has no content
|
||||||
|
// $class = ( count( $urls ) == 0 && !$props['html-after-portal'] )
|
||||||
|
// ? 'vector-menu-empty emptyPortlet' : '';
|
||||||
|
// $props['class'] = trim( "$class $extraClasses[$type]" );
|
||||||
|
// return $props;
|
||||||
|
|
||||||
|
props.AddKvStr("class", extraClasses[type]);
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Json_nde s_getMenuData(Xowe_wiki wiki, byte[] label, byte[] urls, int type) { return s_getMenuData(wiki, label, urls, type, false); }
|
||||||
|
private static Json_nde s_getMenuData(Xowe_wiki wiki, byte[] label_bry, byte[] urls, int type, boolean setLabelToSelected) {
|
||||||
|
boolean isPortal = type == MENU_TYPE_PORTAL;
|
||||||
|
|
||||||
|
String label = String_.new_u8(label_bry);
|
||||||
|
String msg = label; // for now
|
||||||
|
String linkertooltip = String_.Empty;
|
||||||
|
String listClasses = type == MENU_TYPE_DROPDOWN
|
||||||
|
? "menu vector-menu-content-list"
|
||||||
|
: "vector-menu-content-list";
|
||||||
|
String plabel = "p-" + label;
|
||||||
|
|
||||||
|
Json_nde props = Json_nde.NewByVal();
|
||||||
|
props.AddKvStr("id", plabel);
|
||||||
|
props.AddKvStr("label-id", plabel +"-label");
|
||||||
|
props.AddKvStr("label", msg);
|
||||||
|
props.AddKvStr("list-classes", listClasses);
|
||||||
|
props.AddKvBool("is-dropdown", type == MENU_TYPE_DROPDOWN);
|
||||||
|
props.AddKvStr("html-tooltip", wiki.Msg_mgr().Val_html_accesskey_and_title(plabel));
|
||||||
|
props.AddKvStr("html-tooltip", linkertooltip);
|
||||||
|
|
||||||
|
// foreach ( $urls as $key => $item ) {
|
||||||
|
// $props['html-items'] .= $this->getSkin()->makeListItem( $key, $item );
|
||||||
|
// // Check the class of the item for a `selected` class and if so, propagate the items
|
||||||
|
// // label to the main label.
|
||||||
|
// if ( $setLabelToSelected ) {
|
||||||
|
// if ( isset( $item['class'] ) && stripos( $item['class'], 'selected' ) !== false ) {
|
||||||
|
// $props['label'] = $item['text'];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
props.AddKvStr("html-items", urls);
|
||||||
|
|
||||||
|
// $afterPortal = '';
|
||||||
|
// if ( $isPortal ) {
|
||||||
|
// // The BaseTemplate::getAfterPortlet method ran the SkinAfterPortlet
|
||||||
|
// // hook and if content is added appends it to the html-after-portal method.
|
||||||
|
// // This replicates that historic behaviour.
|
||||||
|
// // This code should eventually be upstreamed to SkinMustache in core.
|
||||||
|
// // Currently in production this supports the Wikibase 'edit' link.
|
||||||
|
// $content = $this->getAfterPortlet( $label );
|
||||||
|
// if ( $content !== '' ) {
|
||||||
|
// $afterPortal = Html::rawElement(
|
||||||
|
// 'div',
|
||||||
|
// [ 'class' => [ 'after-portlet', 'after-portlet-' . $label ] ],
|
||||||
|
// $content
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// $props['html-after-portal'] = $afterPortal;
|
||||||
|
//
|
||||||
|
// // Mark the portal as empty if it has no content
|
||||||
|
// $class = ( count( $urls ) == 0 && !$props['html-after-portal'] )
|
||||||
|
// ? 'vector-menu-empty emptyPortlet' : '';
|
||||||
|
// $props['class'] = trim( "$class $extraClasses[$type]" );
|
||||||
|
// return $props;
|
||||||
|
props.AddKvStr("class", extraClasses[type]);
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,25 +13,41 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
package gplx.xowa.addons.htmls.sidebars;
|
||||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Bry_fmt;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.core.brys.Bfr_arg;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
|
||||||
class Xoh_sidebar_htmlr {
|
class Xoh_sidebar_htmlr {
|
||||||
public static byte[] To_html(Bry_bfr bfr, Xowe_wiki wiki, List_adp grps) {
|
public static byte[] To_html(Bry_bfr bfr, Xowe_wiki wiki, List_adp grps) {
|
||||||
Xoh_sidebar_itms_fmtr itms_fmtr = new Xoh_sidebar_itms_fmtr();
|
Xoh_sidebar_itms_fmtr itms_fmtr = new Xoh_sidebar_itms_fmtr();
|
||||||
int len = grps.Count();
|
int len = grps.Count();
|
||||||
boolean popups_enabled = wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled();
|
boolean popups_enabled = wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled();
|
||||||
|
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Xoh_sidebar_itm grp = (Xoh_sidebar_itm)grps.Get_at(i);
|
Xoh_sidebar_itm grp = (Xoh_sidebar_itm)grps.Get_at(i);
|
||||||
itms_fmtr.Init_by_grp(popups_enabled, grp);
|
itms_fmtr.Init_by_grp(popups_enabled, grp);
|
||||||
fmt.Bld_many(bfr, grp.Id(), grp.Text(), itms_fmtr);
|
itms_fmtr.Bfr_arg__add(tmp_bfr);
|
||||||
|
Db_Nav_template.Build_Sidebar(wiki, bfr, grp.Id(), grp.Text(), tmp_bfr.To_bry_and_clear());
|
||||||
}
|
}
|
||||||
|
// dummy toolbox
|
||||||
|
// id="p-tb" used by some js
|
||||||
|
bfr.Add_str_a7("<div class=\"portal\" id=\"p-tb\"></div>");
|
||||||
return bfr.To_bry_and_clear();
|
return bfr.To_bry_and_clear();
|
||||||
}
|
}
|
||||||
private static final Bry_fmt fmt = Bry_fmt.Auto_nl_skip_last
|
private static final Bry_fmt fmt = Bry_fmt.Auto_nl_skip_last
|
||||||
( "<div class=\"portal\" id=\"~{grp_id}\">"
|
( "<div class=\"portal\" id=\"~{grp_id}\">"
|
||||||
, " <h3>~{grp_text}</h3>"
|
, " <h3 id=\"p-navigation-label\">"
|
||||||
, " <div class=\"body\">"
|
, " <span>~{grp_text}</span>"
|
||||||
, " <ul>~{itms}"
|
, " </h3>"
|
||||||
|
, " <!-- Please do not use the .body class, it is deprecated. -->"
|
||||||
|
, " <div class=\"body vector-menu-content\">"
|
||||||
|
, " <!-- Please do not use the .menu class, it is deprecated. -->"
|
||||||
|
, " <ul class=\"vector-menu-content-list\">~{itms}"
|
||||||
, " </ul>"
|
, " </ul>"
|
||||||
, " </div>"
|
, " </div>"
|
||||||
, "</div>"
|
, "</div>"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,11 +13,28 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
package gplx.xowa.addons.htmls.sidebars;
|
||||||
import org.junit.*;
|
|
||||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Io_mgr;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import gplx.xowa.Xoa_app_fxt;
|
||||||
|
import gplx.xowa.Xoae_app;
|
||||||
|
import gplx.xowa.Xop_fxt;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.langs.msgs.Xol_msg_itm;
|
||||||
|
import gplx.xowa.langs.msgs.Xol_msg_mgr;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Xoh_sidebar_mgr_tst {
|
public class Xoh_sidebar_mgr_tst {
|
||||||
@Before public void init() {fxt.Clear();} private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt();
|
@Before public void init() {fxt.Clear();}
|
||||||
|
private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt();
|
||||||
@Test public void Grp() {
|
@Test public void Grp() {
|
||||||
fxt.Init__msg__grp("key", "text", "title");
|
fxt.Init__msg__grp("key", "text", "title");
|
||||||
fxt.Exec__make("* key");
|
fxt.Exec__make("* key");
|
||||||
@ -71,7 +88,39 @@ public class Xoh_sidebar_mgr_tst {
|
|||||||
fxt.Exec__make("** href_key<!--a-->|main_key<!--b-->");
|
fxt.Exec__make("** href_key<!--a-->|main_key<!--b-->");
|
||||||
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
||||||
}
|
}
|
||||||
@Test public void Smoke() {
|
@Test public void Itm_template_msg() {
|
||||||
|
fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random");
|
||||||
|
fxt.Exec__make("** href|main");
|
||||||
|
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||||
|
}
|
||||||
|
@Test public void Itm_template_key() {
|
||||||
|
fxt.Exec__make("** {{ns:Special}}:Random|main");
|
||||||
|
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||||
|
}
|
||||||
|
// @Test
|
||||||
|
public void Popups() {
|
||||||
|
fxt.Init__popups_enabled(true);
|
||||||
|
fxt.Exec__make
|
||||||
|
( "* navigation"
|
||||||
|
, "** mainpage|mainpage-description"
|
||||||
|
);
|
||||||
|
fxt.Test__objs
|
||||||
|
( fxt.Make__grp("navigation", "").Subs__add
|
||||||
|
( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage")
|
||||||
|
));
|
||||||
|
fxt.Test__html
|
||||||
|
( "<div class=\"portal\" id=\"n-navigation\">"
|
||||||
|
, " <h3>navigation</h3>"
|
||||||
|
, " <div class=\"body\">"
|
||||||
|
, " <ul>"
|
||||||
|
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Mainpage\" class='xowa-hover-off' title=\"\">mainpage-description</a></li>"
|
||||||
|
, " </ul>"
|
||||||
|
, " </div>"
|
||||||
|
, "</div>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// @Test
|
||||||
|
public void Smoke() {
|
||||||
fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title");
|
fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title");
|
||||||
fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href");
|
fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href");
|
||||||
fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str);
|
fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str);
|
||||||
@ -114,36 +163,6 @@ public class Xoh_sidebar_mgr_tst {
|
|||||||
, "</div>"
|
, "</div>"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@Test public void Itm_template_msg() {
|
|
||||||
fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random");
|
|
||||||
fxt.Exec__make("** href|main");
|
|
||||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
|
||||||
}
|
|
||||||
@Test public void Itm_template_key() {
|
|
||||||
fxt.Exec__make("** {{ns:Special}}:Random|main");
|
|
||||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
|
||||||
}
|
|
||||||
@Test public void Popups() {
|
|
||||||
fxt.Init__popups_enabled(true);
|
|
||||||
fxt.Exec__make
|
|
||||||
( "* navigation"
|
|
||||||
, "** mainpage|mainpage-description"
|
|
||||||
);
|
|
||||||
fxt.Test__objs
|
|
||||||
( fxt.Make__grp("navigation", "").Subs__add
|
|
||||||
( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage")
|
|
||||||
));
|
|
||||||
fxt.Test__html
|
|
||||||
( "<div class=\"portal\" id=\"n-navigation\">"
|
|
||||||
, " <h3>navigation</h3>"
|
|
||||||
, " <div class=\"body\">"
|
|
||||||
, " <ul>"
|
|
||||||
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Mainpage\" class='xowa-hover-off' title=\"\">mainpage-description</a></li>"
|
|
||||||
, " </ul>"
|
|
||||||
, " </div>"
|
|
||||||
, "</div>"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
private static final String Null_str = "";
|
private static final String Null_str = "";
|
||||||
}
|
}
|
||||||
class Xoh_sidebar_mgr_fxt {
|
class Xoh_sidebar_mgr_fxt {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,16 +13,32 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.apps.site_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
package gplx.xowa.apps.site_cfgs;
|
||||||
import gplx.core.net.*; import gplx.langs.jsons.*; import gplx.xowa.apps.gfs.*;
|
|
||||||
import gplx.xowa.langs.*;
|
import gplx.Bry_;
|
||||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*;
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Bry_split_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.net.Gfo_url_parser;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.xowa.Xow_wiki;
|
||||||
|
import gplx.xowa.apps.gfs.Gfs_php_converter;
|
||||||
|
import gplx.xowa.wikis.domains.Xow_domain_itm_;
|
||||||
|
import gplx.xowa.wikis.domains.Xow_domain_tid_;
|
||||||
|
import gplx.xowa.wikis.xwikis.Xow_xwiki_mgr;
|
||||||
|
|
||||||
class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
|
class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
|
||||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||||
private final Gfo_url_parser url_parser = new Gfo_url_parser();
|
private final Gfo_url_parser url_parser = new Gfo_url_parser();
|
||||||
public Xoa_site_cfg_itm__interwikimap() {this.Ctor(Xoa_site_cfg_loader__inet.Qarg__interwikimap);}
|
public Xoa_site_cfg_itm__interwikimap() {
|
||||||
|
this.Ctor(Xoa_site_cfg_loader__inet.Qarg__interwikimap);
|
||||||
|
}
|
||||||
@Override public void Parse_json_ary_itm(Bry_bfr bfr, Xow_wiki wiki, int i, Json_itm itm) {
|
@Override public void Parse_json_ary_itm(Bry_bfr bfr, Xow_wiki wiki, int i, Json_itm itm) {
|
||||||
Json_nde nde = Json_nde.cast(itm);
|
Json_nde nde = Json_nde.Cast(itm);
|
||||||
if (i != 0) bfr.Add_byte_nl();
|
if (i != 0) bfr.Add_byte_nl();
|
||||||
byte[] iw_key = nde.Get_bry_or_null("prefix"); if (iw_key == null) throw Err_.new_("site_meta", "invalid interwiki", "key", iw_key);
|
byte[] iw_key = nde.Get_bry_or_null("prefix"); if (iw_key == null) throw Err_.new_("site_meta", "invalid interwiki", "key", iw_key);
|
||||||
byte[] iw_url = nde.Get_bry_or_null("url"); if (iw_url == null) throw Err_.new_("site_meta", "invalid interwiki", "url", iw_key);
|
byte[] iw_url = nde.Get_bry_or_null("url"); if (iw_url == null) throw Err_.new_("site_meta", "invalid interwiki", "url", iw_key);
|
||||||
@ -123,4 +139,3 @@ class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
|
|||||||
, Arg0_wm = Bry_.new_a7("$1")
|
, Arg0_wm = Bry_.new_a7("$1")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,19 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
package gplx.xowa.bldrs.wms.revs;
|
||||||
import gplx.langs.jsons.*; import gplx.core.net.*;
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Ordered_hash;
|
||||||
|
import gplx.core.net.Gfo_inet_conn;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.jsons.Json_parser;
|
||||||
|
import gplx.xowa.bldrs.wms.Xowm_api_mgr;
|
||||||
|
|
||||||
class Xowm_rev_wkr__meta__wm implements Xowm_rev_wkr__meta {
|
class Xowm_rev_wkr__meta__wm implements Xowm_rev_wkr__meta {
|
||||||
private final Json_parser json_parser = new Json_parser();
|
private final Json_parser json_parser = new Json_parser();
|
||||||
private final Xowm_json_parser__page json_page_parser = new Xowm_json_parser__page();
|
private final Xowm_json_parser__page json_page_parser = new Xowm_json_parser__page();
|
||||||
@ -35,7 +46,7 @@ class Xowm_rev_wkr__meta__wm implements Xowm_rev_wkr__meta {
|
|||||||
}
|
}
|
||||||
private void Parse_doc(Ordered_hash hash, byte[] json) {
|
private void Parse_doc(Ordered_hash hash, byte[] json) {
|
||||||
Json_doc jdoc = json_parser.Parse(json);
|
Json_doc jdoc = json_parser.Parse(json);
|
||||||
Json_nde pages_nde = Json_nde.cast(jdoc.Get_grp_many(Jpath__query_pages));
|
Json_nde pages_nde = Json_nde.Cast(jdoc.Get_grp_many(Jpath__query_pages));
|
||||||
int len = pages_nde.Len();
|
int len = pages_nde.Len();
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Parse_page(hash, pages_nde.Get_at_as_kv(i).Val_as_nde());
|
Parse_page(hash, pages_nde.Get_at_as_kv(i).Val_as_nde());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,11 +13,24 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
package gplx.xowa.langs.msgs;
|
||||||
import gplx.core.brys.fmtrs.*;
|
|
||||||
import gplx.xowa.addons.htmls.sidebars.*;
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.GfoMsg;
|
||||||
|
import gplx.Gfo_invk;
|
||||||
|
import gplx.Gfo_invk_;
|
||||||
|
import gplx.GfsCtx;
|
||||||
|
import gplx.core.brys.fmtrs.Bry_fmtr;
|
||||||
|
import gplx.xowa.Xow_wiki;
|
||||||
|
import gplx.xowa.addons.htmls.sidebars.Xoh_sidebar_itm;
|
||||||
|
import gplx.xowa.langs.Xol_lang_itm;
|
||||||
|
|
||||||
public class Xow_msg_mgr implements Gfo_invk {
|
public class Xow_msg_mgr implements Gfo_invk {
|
||||||
private final Xow_wiki wiki; private Xol_lang_itm lang; private final Xol_msg_mgr msg_mgr;
|
private final Xow_wiki wiki;
|
||||||
|
private final Xol_msg_mgr msg_mgr;
|
||||||
|
private Xol_lang_itm lang;
|
||||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.New__tmp();
|
private final Bry_fmtr tmp_fmtr = Bry_fmtr.New__tmp();
|
||||||
public Xow_msg_mgr(Xow_wiki wiki, Xol_lang_itm lang) {
|
public Xow_msg_mgr(Xow_wiki wiki, Xol_lang_itm lang) {
|
||||||
this.wiki = wiki;
|
this.wiki = wiki;
|
||||||
@ -74,6 +87,7 @@ public class Xow_msg_mgr implements Gfo_invk {
|
|||||||
if (itm.Has_tmpl_txt()) rv = wiki.Wtxt__expand_tmpl(rv);
|
if (itm.Has_tmpl_txt()) rv = wiki.Wtxt__expand_tmpl(rv);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
public byte[] Val_html_accesskey_and_title(String id) {return Val_html_accesskey_and_title(Bry_.new_u8(id));}
|
||||||
public byte[] Val_html_accesskey_and_title(byte[] id) {
|
public byte[] Val_html_accesskey_and_title(byte[] id) {
|
||||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||||
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
|
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
|
||||||
|
@ -95,6 +95,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
|||||||
boolean subst_found = false;
|
boolean subst_found = false;
|
||||||
boolean name_had_subst = false;
|
boolean name_had_subst = false;
|
||||||
boolean template_prefix_found = false;
|
boolean template_prefix_found = false;
|
||||||
|
// byte tmpl_case_match = wiki.Ns_mgr().Ns_template().Case_match();
|
||||||
|
|
||||||
// tmpl_name does not exist in db; may be dynamic, subst, transclusion, etc..
|
// tmpl_name does not exist in db; may be dynamic, subst, transclusion, etc..
|
||||||
if (defn == Xot_defn_.Null) {
|
if (defn == Xot_defn_.Null) {
|
||||||
@ -285,6 +286,29 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
|||||||
break;
|
break;
|
||||||
case Xot_defn_.Tid_func:
|
case Xot_defn_.Tid_func:
|
||||||
try {
|
try {
|
||||||
|
/* System.out.println(String_.new_a7(caller.Frame_ttl()));
|
||||||
|
if (true) {//(caller.Frame_ttl().length == 22 && caller.Frame_ttl()[21] == 't') {
|
||||||
|
int alen = caller.Args_len();
|
||||||
|
String s = "";
|
||||||
|
for (int i = 0; i < alen; i++) {
|
||||||
|
Arg_nde_tkn atkn = caller.Args_get_by_idx(i);
|
||||||
|
if (atkn.KeyTkn_exists()) {
|
||||||
|
Arg_itm_tkn argtkn = atkn.Key_tkn();
|
||||||
|
s += String_.new_a7(argtkn.Dat_ary()) + ":";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s += String.valueOf(i);
|
||||||
|
s += String_.new_a7(atkn.Val_tkn().Dat_ary()) + "\n";
|
||||||
|
}
|
||||||
|
System.out.println(s);
|
||||||
|
int a=1;
|
||||||
|
}
|
||||||
|
if (Bry_.Eq(caller.Frame_ttl(), Bry_.new_a7("Template:BookCat/core"))) {
|
||||||
|
return true;
|
||||||
|
//int a=1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//System.out.println(String_.new_u8(caller.Frame_ttl()));
|
||||||
Xot_invk_tkn_.Eval_func(ctx, src, caller, this, bfr, defn, argx_ary);
|
Xot_invk_tkn_.Eval_func(ctx, src, caller, this, bfr, defn, argx_ary);
|
||||||
rv = true;
|
rv = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -306,10 +330,12 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
|||||||
Bry_bfr rslt_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
Bry_bfr rslt_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||||
try {
|
try {
|
||||||
Xopg_tmpl_prepend_mgr prepend_mgr = ctx.Page().Tmpl_prepend_mgr().Bgn(bfr);
|
Xopg_tmpl_prepend_mgr prepend_mgr = ctx.Page().Tmpl_prepend_mgr().Bgn(bfr);
|
||||||
rv = defn_tmpl.Tmpl_evaluate(Xop_ctx.New__sub(wiki, ctx, ctx.Page()), invk_tmpl, rslt_bfr); // create new ctx so __NOTOC__ only applies to template, not page; PAGE:de.w:13._Jahrhundert DATE:2017-06-17
|
//rv = defn_tmpl.Tmpl_evaluate(Xop_ctx.New__sub(wiki, ctx, ctx.Page()), invk_tmpl, rslt_bfr); // create new ctx so __NOTOC__ only applies to template, not page; PAGE:de.w:13._Jahrhundert DATE:2017-06-17
|
||||||
|
rv = defn_tmpl.Tmpl_evaluate(ctx, invk_tmpl, rslt_bfr);
|
||||||
prepend_mgr.End(ctx, bfr, rslt_bfr.Bfr(), rslt_bfr.Len(), Bool_.Y);
|
prepend_mgr.End(ctx, bfr, rslt_bfr.Bfr(), rslt_bfr.Len(), Bool_.Y);
|
||||||
if (name_had_subst) { // current invk had "subst:"; parse incoming invk again to remove effects of subst; PAGE:pt.w:Argentina DATE:2014-09-24
|
if (name_had_subst) { // current invk had "subst:"; parse incoming invk again to remove effects of subst; PAGE:pt.w:Argentina DATE:2014-09-24
|
||||||
byte[] tmp_src = rslt_bfr.To_bry_and_clear();
|
byte[] tmp_src = rslt_bfr.To_bry_and_clear();
|
||||||
|
if (tmp_src.length != 0)
|
||||||
rslt_bfr.Add(wiki.Parser_mgr().Main().Expand_tmpl(tmp_src)); // this could be cleaner / more optimized
|
rslt_bfr.Add(wiki.Parser_mgr().Main().Expand_tmpl(tmp_src)); // this could be cleaner / more optimized
|
||||||
}
|
}
|
||||||
bfr.Add_bfr_and_clear(rslt_bfr);
|
bfr.Add_bfr_and_clear(rslt_bfr);
|
||||||
@ -341,7 +367,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
|||||||
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}}
|
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}}
|
||||||
byte[] transclude_src = null;
|
byte[] transclude_src = null;
|
||||||
if (page_ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
|
if (page_ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
|
||||||
Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db());
|
Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db(), wiki.Ns_mgr().Ns_template().Case_match());
|
||||||
if (tmpl != null) transclude_src = tmpl.Data_raw();
|
if (tmpl != null) transclude_src = tmpl.Data_raw();
|
||||||
}
|
}
|
||||||
if (transclude_src == null && ctx.Tmpl_load_enabled()) { // ttl is template not in cache, or some other ns; do load
|
if (transclude_src == null && ctx.Tmpl_load_enabled()) { // ttl is template not in cache, or some other ns; do load
|
||||||
@ -378,7 +404,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
|||||||
Xot_defn_tmpl transclude_tmpl = null;
|
Xot_defn_tmpl transclude_tmpl = null;
|
||||||
switch (page_ttl.Ns().Id()) {
|
switch (page_ttl.Ns().Id()) {
|
||||||
case Xow_ns_.Tid__template: // ttl is template not in cache, or some other ns; do load
|
case Xow_ns_.Tid__template: // ttl is template not in cache, or some other ns; do load
|
||||||
Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db());
|
Xot_defn_tmpl tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Defn_cache().Get_by_key(page_ttl.Page_db(), wiki.Ns_mgr().Ns_template().Case_match());
|
||||||
if (tmpl != null) {
|
if (tmpl != null) {
|
||||||
if (tmpl.Root() == null) tmpl.Parse_tmpl(ctx);
|
if (tmpl.Root() == null) tmpl.Parse_tmpl(ctx);
|
||||||
transclude_tmpl = tmpl;
|
transclude_tmpl = tmpl;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,17 +13,26 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
package gplx.xowa.wikis.caches;
|
||||||
import gplx.core.intls.*; import gplx.core.caches.*;
|
|
||||||
import gplx.xowa.langs.*;
|
import gplx.Bry_bfr;
|
||||||
import gplx.xowa.wikis.nss.*;
|
import gplx.Bry_bfr_;
|
||||||
import gplx.xowa.parsers.tmpls.*;
|
import gplx.core.caches.Gfo_cache_mgr;
|
||||||
public class Xow_defn_cache { // stores compiled Xot_defn
|
import gplx.xowa.langs.Xol_lang_itm;
|
||||||
|
import gplx.xowa.parsers.tmpls.Xot_defn;
|
||||||
|
import gplx.xowa.wikis.nss.Xow_ns_case_;
|
||||||
|
|
||||||
|
public class Xow_defn_cache {
|
||||||
private final Xol_lang_itm lang; // needed to lowercase names;
|
private final Xol_lang_itm lang; // needed to lowercase names;
|
||||||
private final Bry_bfr upper_1st_bfr = Bry_bfr_.Reset(255);
|
private final Bry_bfr upper_1st_bfr = Bry_bfr_.Reset(255);
|
||||||
private final Gfo_cache_mgr cache = new Gfo_cache_mgr().Max_size_(64 * 1024 * 1024).Reduce_by_(32 * 1024 * 1024);
|
private final Gfo_cache_mgr cache = new Gfo_cache_mgr().Max_size_(64 * 1024 * 1024).Reduce_by_(32 * 1024 * 1024);
|
||||||
public Xow_defn_cache(Xol_lang_itm lang) {this.lang = lang;}
|
public Xow_defn_cache(Xol_lang_itm lang) {this.lang = lang;}
|
||||||
public Xot_defn Get_by_key(byte[] name) {return (Xot_defn)cache.Get_by_key(name);}
|
public Xot_defn Get_by_key(byte[] name) {return (Xot_defn)cache.Get_by_key(name);}
|
||||||
|
public Xot_defn Get_by_key(byte[] name, byte case_match) {
|
||||||
|
if (case_match == Xow_ns_case_.Tid__1st)
|
||||||
|
name = lang.Case_mgr().Case_build_1st_upper(upper_1st_bfr, name, 0, name.length);
|
||||||
|
return (Xot_defn)cache.Get_by_key(name);
|
||||||
|
}
|
||||||
public void Free_mem_all() {cache.Clear();}
|
public void Free_mem_all() {cache.Clear();}
|
||||||
public void Add(Xot_defn defn, byte case_match) {
|
public void Add(Xot_defn defn, byte case_match) {
|
||||||
byte[] name = defn.Name();
|
byte[] name = defn.Name();
|
||||||
|
403
400_xowa/src/gplx/xowa/xtns/lst/Db_Section_list.java
Normal file
403
400_xowa/src/gplx/xowa/xtns/lst/Db_Section_list.java
Normal file
@ -0,0 +1,403 @@
|
|||||||
|
/* search for '</?section' then find fwd '>'
|
||||||
|
any </section ignore
|
||||||
|
|
||||||
|
within bgn to end need to dig out 'begin' or 'end' or the language sensitivities
|
||||||
|
also the key value
|
||||||
|
|
||||||
|
store
|
||||||
|
name of section, start or end
|
||||||
|
if start position after close >
|
||||||
|
if end position before <
|
||||||
|
*/
|
||||||
|
package gplx.xowa.xtns.lst;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
|
||||||
|
import gplx.xowa.Xoa_ttl;
|
||||||
|
import gplx.xowa.Xoae_page;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.parsers.Xop_ctx;
|
||||||
|
import gplx.xowa.parsers.Xop_root_tkn;
|
||||||
|
import gplx.xowa.parsers.Xop_parser;
|
||||||
|
import gplx.xowa.parsers.Xop_parser_;
|
||||||
|
import gplx.xowa.parsers.Xop_parser_tid_;
|
||||||
|
import gplx.xowa.parsers.Xop_tkn_mkr;
|
||||||
|
import gplx.xowa.parsers.tmpls.Xot_invk_temp;
|
||||||
|
import gplx.xowa.parsers.lnkis.files.Xop_file_logger_;
|
||||||
|
import gplx.xowa.parsers.tmpls.Xot_defn_tmpl;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.Hash_adp_bry;
|
||||||
|
|
||||||
|
public class Db_Section_list {
|
||||||
|
private List_adp sects;
|
||||||
|
private List_adp heads;
|
||||||
|
private byte[] src;
|
||||||
|
private Xop_ctx ctx;
|
||||||
|
private Xop_ctx sub_ctx;
|
||||||
|
private Xowe_wiki wiki;
|
||||||
|
private Xoa_ttl ttl;
|
||||||
|
private byte[] ttl_bry;
|
||||||
|
private static final byte Include_between = 0, Include_to_eos = 1, Include_to_bos = 2;
|
||||||
|
public Db_Section_list(byte[] src, int langid, Xop_ctx ctx, Xop_ctx sub_ctx, Xoa_ttl ttl, byte[] ttl_bry) {
|
||||||
|
byte b;
|
||||||
|
this.src = src;
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.wiki = ctx.Wiki();
|
||||||
|
this.sub_ctx = sub_ctx;
|
||||||
|
this.ttl = ttl;
|
||||||
|
this.ttl_bry = ttl_bry;
|
||||||
|
int src_len = src.length;
|
||||||
|
int pos = 0;
|
||||||
|
int bgn, end, atr;
|
||||||
|
sects = List_adp_.New();
|
||||||
|
begin_end keyword;
|
||||||
|
switch (langid) {
|
||||||
|
case 1: // german!!!
|
||||||
|
keyword = new DE_begin_end();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
keyword = new EN_begin_end();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (pos < src_len) {
|
||||||
|
b = src[pos++];
|
||||||
|
if (b == '<') {
|
||||||
|
if (pos + 10 < src_len && (src[pos] | 32) == 's' && (src[pos+1] | 32) == 'e' && (src[pos+2] | 32) == 'c' && (src[pos+3] | 32) == 't' && (src[pos+4] | 32) == 'i' && (src[pos+5] | 32) == 'o' && (src[pos+6] | 32) == 'n' && src[pos+7] == ' ') {
|
||||||
|
bgn = pos - 1;
|
||||||
|
pos += 8;
|
||||||
|
atr = pos;
|
||||||
|
while (pos < src_len) {
|
||||||
|
b = src[pos++];
|
||||||
|
if (b == '>')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pos == src_len) // no end found
|
||||||
|
break;
|
||||||
|
end = pos;
|
||||||
|
// now find a keyword
|
||||||
|
begin_end_result bg = keyword.Find(src, atr, end);
|
||||||
|
if (bg != null) {
|
||||||
|
sects.Add(new Section(src, bg.start, bg.type, bgn, end));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (b == '\n') { // check for headers
|
||||||
|
if (pos + 10 < src_len && src[pos] == '=') {
|
||||||
|
int count = 1;
|
||||||
|
pos++;
|
||||||
|
while (pos < src_len) {
|
||||||
|
b = src[pos++];
|
||||||
|
if (b != '=')
|
||||||
|
break;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
// now find the next <nl>
|
||||||
|
if (b != '\n') {
|
||||||
|
int npos = pos;
|
||||||
|
while (npos < src_len) {
|
||||||
|
b = src[npos++];
|
||||||
|
if (b == '\n')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (b == '\n') {
|
||||||
|
// now count any '=' backwards
|
||||||
|
int ncount = 0;
|
||||||
|
while (npos > pos) {
|
||||||
|
b = src[--npos];
|
||||||
|
if (b == '=')
|
||||||
|
ncount++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ncount == count) { // we have a header
|
||||||
|
heads.Add(new Header(src, pos, npos, count));
|
||||||
|
pos = npos + count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public byte[] Include(byte[] from, byte[] to) {
|
||||||
|
if (to == Lst_pfunc_itm.Null_arg) { // no end arg; EX: {{#lst:page|bgn}}; NOTE: different than {{#lst:page|bgn|}}
|
||||||
|
if (from == Lst_pfunc_itm.Null_arg) { // no bgn arg; EX: {{#lst:page}}
|
||||||
|
return Compile3(src);
|
||||||
|
}
|
||||||
|
else // bgn exists; set end to bgn; EX: {{#lst:page|bgn}} is same as {{#lst:page|bgn|bgn}}; NOTE: {{#lst:page|bgn|}} means write from bgn to eos
|
||||||
|
to = from;
|
||||||
|
}
|
||||||
|
Bry_bfr bfr = Bry_bfr_.New();
|
||||||
|
byte include_mode = Include_between;
|
||||||
|
if (Bry_.Len_eq_0(to))
|
||||||
|
include_mode = Include_to_eos;
|
||||||
|
else if (Bry_.Len_eq_0(from))
|
||||||
|
include_mode = Include_to_bos;
|
||||||
|
int bgn_pos = 0; boolean bgn_found = false; int src_page_bry_len = src.length;
|
||||||
|
int sections_len = sects.Count();
|
||||||
|
for (int i = 0; i < sections_len; i++) {
|
||||||
|
Section sect = (Section)sects.Get_at(i);
|
||||||
|
byte section_tid = (byte)sect.type;
|
||||||
|
if (section_tid == begin_end_result.BEGIN && Matchkey(sect, from)) {
|
||||||
|
int sect_bgn_rhs = sect.end;
|
||||||
|
if (include_mode == Include_to_eos) { // write from cur to eos; EX: {{#lst:page|bgn|}}
|
||||||
|
bfr.Add_mid(src, sect_bgn_rhs, src_page_bry_len);
|
||||||
|
bgn_found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else { // bgn and end
|
||||||
|
if (!bgn_found) { // NOTE: !bgn_found to prevent "resetting" of dupe; EX: <s begin=key0/>a<s begin=key0/>b; should start from a not b
|
||||||
|
bgn_pos = sect_bgn_rhs;
|
||||||
|
bgn_found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (section_tid == begin_end_result.END && Matchkey(sect, to)) {
|
||||||
|
int sect_end_lhs = sect.bgn;
|
||||||
|
if (include_mode == Include_to_bos) { // write from bos to cur; EX: {{#lst:page||end}}
|
||||||
|
bfr.Add_mid(src, 0, sect_end_lhs);
|
||||||
|
bgn_found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (bgn_found) { // NOTE: bgn_found to prevent writing from bos; EX: a<s end=key0/>b should not write anything
|
||||||
|
bfr.Add_mid(src, bgn_pos, sect_end_lhs);
|
||||||
|
bgn_found = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bgn_found) // bgn_found, but no end; write to end of page; EX: "a <section begin=key/> b" -> " b"
|
||||||
|
bfr.Add_mid(src, bgn_pos, src_page_bry_len);
|
||||||
|
|
||||||
|
return Compile3(bfr.To_bry());
|
||||||
|
}
|
||||||
|
public byte[] Exclude(byte[] sect_exclude, byte[] sect_replace) {
|
||||||
|
if (Bry_.Len_eq_0(sect_exclude)) { // no exclude arg; EX: {{#lstx:page}} or {{#lstx:page}}
|
||||||
|
return Compile3(src); // write all and exit
|
||||||
|
}
|
||||||
|
int sections_len = sects.Count();
|
||||||
|
int bgn_pos = 0;
|
||||||
|
Bry_bfr bfr = Bry_bfr_.New();
|
||||||
|
for (int i = 0; i < sections_len; i++) {
|
||||||
|
Section sect = (Section)sects.Get_at(i);
|
||||||
|
byte section_tid = (byte)sect.type;
|
||||||
|
if (section_tid == begin_end_result.BEGIN && Matchkey(sect, sect_exclude)) {
|
||||||
|
bfr.Add_mid(src, bgn_pos, sect.bgn); // write everything from bgn_pos up to exclude
|
||||||
|
}
|
||||||
|
else if (section_tid == begin_end_result.END && Matchkey(sect, sect_exclude)) { // exclude end found
|
||||||
|
if (sect_replace != null)
|
||||||
|
bfr.Add(sect_replace); // write replacement
|
||||||
|
bgn_pos = sect.end; // reset bgn_pos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bfr.Add_mid(src, bgn_pos, src.length);
|
||||||
|
return Compile3(bfr.To_bry());
|
||||||
|
}
|
||||||
|
public byte[] Header(byte[] lhs_hdr, byte[] rhs_hdr) {
|
||||||
|
return Bry_.Empty;
|
||||||
|
}
|
||||||
|
private boolean Matchkey(Section sect, byte[] find) {
|
||||||
|
if (find == Lst_pfunc_itm.Null_arg) return false;
|
||||||
|
int pos = sect.keybgn;
|
||||||
|
int keylen = sect.keyend - pos;
|
||||||
|
int find_end = find.length;
|
||||||
|
if (find_end != keylen) return false;
|
||||||
|
for (int i = 0; i < find_end; i++) {
|
||||||
|
if (src[pos + i] != find[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// need ctx hence wiki and page
|
||||||
|
private byte[] Compile(byte[] page_bry) {
|
||||||
|
Xop_root_tkn xtn_root = null;
|
||||||
|
// set recursing flag
|
||||||
|
Xoae_page page = ctx.Page();
|
||||||
|
Bry_bfr full_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||||
|
try {
|
||||||
|
wiki.Parser_mgr().Lst__recursing_(true);
|
||||||
|
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||||
|
page.Html_data().Indicators().Enabled_(Bool_.N); // disable <indicator> b/c <page> should not add to current page; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||||
|
xtn_root = Bld_root_nde(full_bfr, lst_page_regy, page_bry); // NOTE: this effectively reparses page twice; needed b/c of "if {| : ; # *, auto add new_line" which can build different tokens
|
||||||
|
} finally {
|
||||||
|
wiki.Parser_mgr().Lst__recursing_(false);
|
||||||
|
full_bfr.Mkr_rls();
|
||||||
|
}
|
||||||
|
page.Html_data().Indicators().Enabled_(Bool_.Y);
|
||||||
|
if (xtn_root == null) return null;
|
||||||
|
//html_wtr.Write_tkn_to_html(bfr, ctx, hctx, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private byte[] Compile2(byte[] msg_val) {
|
||||||
|
Xowe_wiki wikie = (Xowe_wiki)wiki;
|
||||||
|
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(wikie.Parser_mgr().Ctx());
|
||||||
|
sub_ctx.Parse_tid_(Xop_parser_tid_.Tid__wtxt);
|
||||||
|
Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
|
||||||
|
Xop_root_tkn sub_root = tkn_mkr.Root(msg_val);
|
||||||
|
return wikie.Parser_mgr().Main().Expand_tmpl(sub_root, sub_ctx, tkn_mkr, msg_val);
|
||||||
|
}
|
||||||
|
private byte[] Compile3(byte[] sub_src) {
|
||||||
|
// parse page; note adding to stack to prevent circular recursions
|
||||||
|
if (!wiki.Parser_mgr().Tmpl_stack_add(ttl.Full_db())) return null;
|
||||||
|
Xot_defn_tmpl tmpl = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(sub_ctx, sub_ctx.Tkn_mkr(), ttl.Ns(), ttl_bry, sub_src); // NOTE: parse as tmpl to ignore <noinclude>
|
||||||
|
wiki.Parser_mgr().Tmpl_stack_del(); // take template off stack; evaluate will never recurse, but will fail if ttl is still on stack; DATE:2014-03-10
|
||||||
|
|
||||||
|
// eval tmpl
|
||||||
|
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||||
|
try {
|
||||||
|
tmpl.Tmpl_evaluate(sub_ctx, Xot_invk_temp.New_root(ttl.Page_txt()), tmp_bfr);
|
||||||
|
sub_src = tmp_bfr.To_bry_and_clear();
|
||||||
|
} finally {
|
||||||
|
tmp_bfr.Mkr_rls();
|
||||||
|
}
|
||||||
|
return sub_src;
|
||||||
|
}
|
||||||
|
private Xop_root_tkn Bld_root_nde(Bry_bfr page_bfr, Hash_adp_bry lst_page_regy, byte[] wikitext) {
|
||||||
|
Xop_ctx tmp_ctx = Xop_ctx.New__sub__reuse_lst(wiki, ctx, lst_page_regy);
|
||||||
|
tmp_ctx.Page().Ttl_(ctx.Page().Ttl()); // NOTE: must set tmp_ctx.Ttl to ctx.Ttl; EX: Flatland and First World; DATE:2013-04-29
|
||||||
|
tmp_ctx.Lnki().File_logger_(Xop_file_logger_.Noop); // NOTE: set file_wkr to null, else items will be double-counted
|
||||||
|
tmp_ctx.Parse_tid_(Xop_parser_tid_.Tid__defn);
|
||||||
|
Xop_parser tmp_parser = Xop_parser.new_(wiki, wiki.Parser_mgr().Main().Tmpl_lxr_mgr(), wiki.Parser_mgr().Main().Wtxt_lxr_mgr());
|
||||||
|
Xop_root_tkn rv = tmp_ctx.Tkn_mkr().Root(wikitext);
|
||||||
|
tmp_parser.Parse_text_to_wdom(rv, tmp_ctx, tmp_ctx.Tkn_mkr(), wikitext, Xop_parser_.Doc_bgn_bos);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Section {
|
||||||
|
public int keybgn;
|
||||||
|
public int keyend;
|
||||||
|
public int type;
|
||||||
|
public int bgn;
|
||||||
|
public int end;
|
||||||
|
Section(byte[] src, int keybgn, int type, int bgn, int end) {
|
||||||
|
this.type = type;
|
||||||
|
this.bgn = bgn;
|
||||||
|
this.end = end;
|
||||||
|
byte b = src[keybgn];
|
||||||
|
if (b == '\'' || b == '"')
|
||||||
|
keybgn++;
|
||||||
|
keyend = end - 2;
|
||||||
|
while (keyend > bgn) {
|
||||||
|
b = src[keyend - 1];
|
||||||
|
if (b != ' ' && b != '\t' && b != '\n')
|
||||||
|
break;
|
||||||
|
keyend--;
|
||||||
|
}
|
||||||
|
if (b == '\'' || b == '"')
|
||||||
|
keyend--;
|
||||||
|
this.keybgn = keybgn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Header {
|
||||||
|
public int bgn;
|
||||||
|
public int end;
|
||||||
|
public int level;
|
||||||
|
Header(byte[] src, int bgn, int end, int level) {
|
||||||
|
this.level = level;
|
||||||
|
byte b;
|
||||||
|
while (bgn < end) {
|
||||||
|
b = src[bgn];
|
||||||
|
if (b == ' ' || b == '\t')
|
||||||
|
bgn++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.bgn = bgn;
|
||||||
|
while (end > bgn) {
|
||||||
|
b = src[end - 1];
|
||||||
|
if (b == ' ' || b == '\t')
|
||||||
|
bgn--;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface begin_end {
|
||||||
|
begin_end_result Find(byte[] src, int bgn, int end);
|
||||||
|
}
|
||||||
|
|
||||||
|
class EN_begin_end implements begin_end {
|
||||||
|
public begin_end_result Find(byte[] src, int bgn, int end) {
|
||||||
|
while (bgn < end) {
|
||||||
|
byte b = src[bgn++];
|
||||||
|
switch (b) {
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
if ((src[bgn] | 32) == 'e' && (src[bgn+1] | 32) == 'g' && (src[bgn+2] | 32) == 'i' && (src[bgn+3] | 32) == 'n' && src[bgn+4] == '=') {
|
||||||
|
bgn += 5;
|
||||||
|
b = src[bgn];
|
||||||
|
return new begin_end_result(begin_end_result.BEGIN, bgn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
if ((src[bgn] | 32) == 'n' && (src[bgn+1] | 32) == 'd' && src[bgn+2] == '=') {
|
||||||
|
bgn += 3;
|
||||||
|
b = src[bgn];
|
||||||
|
return new begin_end_result(begin_end_result.END, bgn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class DE_begin_end implements begin_end {
|
||||||
|
public begin_end_result Find(byte[] src, int bgn, int end) {
|
||||||
|
while (bgn < end) {
|
||||||
|
byte b = src[bgn++];
|
||||||
|
switch (b) {
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
if ((src[bgn] | 32) == 'e' && (src[bgn+1] | 32) == 'g' && (src[bgn+2] | 32) == 'i' && (src[bgn+3] | 32) == 'n' && src[bgn+4] == '=') {
|
||||||
|
bgn += 5;
|
||||||
|
b = src[bgn];
|
||||||
|
return new begin_end_result(begin_end_result.BEGIN, bgn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// End
|
||||||
|
// Ende
|
||||||
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
if ((src[bgn] | 32) == 'n' && (src[bgn+1] | 32) == 'd') {
|
||||||
|
if (src[bgn+2] == '=') {
|
||||||
|
bgn += 3;
|
||||||
|
}
|
||||||
|
else if ((src[bgn+2] | 32) == 'e' && src[bgn+3] == '=') {
|
||||||
|
bgn += 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
b = src[bgn];
|
||||||
|
return new begin_end_result(begin_end_result.END, bgn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Anfang
|
||||||
|
case 'a':
|
||||||
|
case 'A':
|
||||||
|
if ((src[bgn] | 32) == 'n' && (src[bgn+1] | 32) == 'f' && (src[bgn+2] | 32) == 'a' && (src[bgn+3] | 32) == 'n' && (src[bgn+4] | 32) == 'g' && src[bgn+5] == '=') {
|
||||||
|
bgn += 6;
|
||||||
|
b = src[bgn];
|
||||||
|
return new begin_end_result(begin_end_result.END, bgn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class begin_end_result {
|
||||||
|
public static int BEGIN = 1;
|
||||||
|
public static int END = 2;
|
||||||
|
public int type;
|
||||||
|
public int start;
|
||||||
|
begin_end_result(int type, int start) {
|
||||||
|
this.type = type;
|
||||||
|
this.start = start;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,11 +13,43 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.pagebanners;
|
||||||
import gplx.core.btries.*; import gplx.langs.mustaches.*;
|
|
||||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.parsers.utils.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
|
import gplx.Bry_;
|
||||||
import gplx.xowa.files.*;
|
import gplx.Bry_bfr;
|
||||||
import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.encoders.*;
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Bry_find_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Double_;
|
||||||
|
import gplx.Gfo_usr_dlg_;
|
||||||
|
import gplx.Hash_adp_bry;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.Ordered_hash;
|
||||||
|
import gplx.Ordered_hash_;
|
||||||
|
import gplx.langs.htmls.encoders.Gfo_url_encoder_;
|
||||||
|
import gplx.langs.mustaches.JsonMustacheNde;
|
||||||
|
import gplx.langs.mustaches.Mustache_bfr;
|
||||||
|
import gplx.langs.mustaches.Mustache_render_ctx;
|
||||||
|
import gplx.xowa.Xoa_ttl;
|
||||||
|
import gplx.xowa.Xoae_app;
|
||||||
|
import gplx.xowa.Xoae_page;
|
||||||
|
import gplx.xowa.Xow_wiki;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.files.Xof_exec_tid;
|
||||||
|
import gplx.xowa.files.Xof_file_itm;
|
||||||
|
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||||
|
import gplx.xowa.langs.kwds.Xol_kwd_grp_;
|
||||||
|
import gplx.xowa.parsers.Xop_ctx;
|
||||||
|
import gplx.xowa.parsers.lnkis.Xop_lnki_tkn;
|
||||||
|
import gplx.xowa.parsers.lnkis.files.Xop_file_logger_;
|
||||||
|
import gplx.xowa.parsers.tmpls.Arg_nde_tkn;
|
||||||
|
import gplx.xowa.parsers.tmpls.Xop_func_arg_itm;
|
||||||
|
import gplx.xowa.parsers.tmpls.Xot_invk;
|
||||||
|
import gplx.xowa.parsers.utils.Xop_sanitizer;
|
||||||
|
import gplx.xowa.xtns.pfuncs.Pf_func;
|
||||||
|
import gplx.xowa.xtns.pfuncs.Pf_func_base;
|
||||||
|
|
||||||
// REF.MW:https://github.com/wikimedia/mediawiki-extensions-WikidataPageBanner/blob/master/includes/WikidataPageBannerFunctions.php
|
// REF.MW:https://github.com/wikimedia/mediawiki-extensions-WikidataPageBanner/blob/master/includes/WikidataPageBannerFunctions.php
|
||||||
// TODO.DATE:2019-11-11: calculate enableToc and hasPosition;
|
// TODO.DATE:2019-11-11: calculate enableToc and hasPosition;
|
||||||
public class Pgbnr_func extends Pf_func_base {
|
public class Pgbnr_func extends Pf_func_base {
|
||||||
@ -68,6 +100,7 @@ public class Pgbnr_func extends Pf_func_base {
|
|||||||
icon_title = icon_ttl.Page_txt();
|
icon_title = icon_ttl.Page_txt();
|
||||||
}
|
}
|
||||||
icons_list.Add(new Pgbnr_icon(tmp_bfr, icon_name, icon_title, icon_href));
|
icons_list.Add(new Pgbnr_icon(tmp_bfr, icon_name, icon_title, icon_href));
|
||||||
|
// itm.Add_new_icon(tmp_bfr, icon_name, icon_title, icon_href);
|
||||||
}
|
}
|
||||||
if (tid == Arg__origin) { // REF.MW:addFocus
|
if (tid == Arg__origin) { // REF.MW:addFocus
|
||||||
double tmp_data_pos_x = Double_.NaN, tmp_data_pos_y = Double_.NaN;
|
double tmp_data_pos_x = Double_.NaN, tmp_data_pos_y = Double_.NaN;
|
||||||
@ -167,7 +200,8 @@ public class Pgbnr_func extends Pf_func_base {
|
|||||||
}
|
}
|
||||||
itm.Init_from_html(max_width, banner_file, banner_url, srcset, cfg.enable_heading_override, toc_html, isPanorama);
|
itm.Init_from_html(max_width, banner_file, banner_url, srcset, cfg.enable_heading_override, toc_html, isPanorama);
|
||||||
|
|
||||||
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(itm);
|
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(new JsonMustacheNde(itm.Mustache__json()));
|
||||||
|
// Mustache_render_ctx mctx = new Mustache_render_ctx().Init(itm);
|
||||||
Mustache_bfr mbfr = Mustache_bfr.New_bfr(tmp_bfr);
|
Mustache_bfr mbfr = Mustache_bfr.New_bfr(tmp_bfr);
|
||||||
wiki.Xtn_mgr().Xtn_pgbnr().Template_root().Render(mbfr, mctx);
|
wiki.Xtn_mgr().Xtn_pgbnr().Template_root().Render(mbfr, mctx);
|
||||||
return mbfr.To_bry_and_clear();
|
return mbfr.To_bry_and_clear();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,9 +13,22 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.pagebanners;
|
||||||
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
|
|
||||||
import gplx.xowa.htmls.core.htmls.*;
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import gplx.core.brys.Bfr_arg;
|
||||||
|
import gplx.xowa.Xoa_app_fxt;
|
||||||
|
import gplx.xowa.Xoae_app;
|
||||||
|
import gplx.xowa.Xop_fxt;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Pgbnr_func_tst {
|
public class Pgbnr_func_tst {
|
||||||
private final Pgbnr_func_fxt fxt = new Pgbnr_func_fxt();
|
private final Pgbnr_func_fxt fxt = new Pgbnr_func_fxt();
|
||||||
@Before public void init() {fxt.Clear();}
|
@Before public void init() {fxt.Clear();}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,9 +13,16 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.pagebanners;
|
||||||
import gplx.core.brys.fmtrs.*;
|
|
||||||
import gplx.langs.mustaches.*;
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_fmt;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.mustaches.Mustache_bfr;
|
||||||
|
import gplx.langs.mustaches.Mustache_doc_itm;
|
||||||
|
import gplx.langs.mustaches.Mustache_doc_itm_;
|
||||||
|
|
||||||
public class Pgbnr_icon implements Mustache_doc_itm {
|
public class Pgbnr_icon implements Mustache_doc_itm {
|
||||||
private final byte[] name, title, href, html;
|
private final byte[] name, title, href, html;
|
||||||
public Pgbnr_icon(Bry_bfr tmp_bfr, byte[] name, byte[] title, byte[] href) {
|
public Pgbnr_icon(Bry_bfr tmp_bfr, byte[] name, byte[] title, byte[] href) {
|
||||||
@ -23,6 +30,10 @@ public class Pgbnr_icon implements Mustache_doc_itm {
|
|||||||
fmt.Bld_many(tmp_bfr, name, title);
|
fmt.Bld_many(tmp_bfr, name, title);
|
||||||
this.html = tmp_bfr.To_bry_and_clear();
|
this.html = tmp_bfr.To_bry_and_clear();
|
||||||
}
|
}
|
||||||
|
public byte[] Name() {return name;}
|
||||||
|
public byte[] Title() {return title;}
|
||||||
|
public byte[] Href() {return href;}
|
||||||
|
public byte[] Html() {return html;}
|
||||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||||
if (String_.Eq(key, "name")) bfr.Add_bry(name);
|
if (String_.Eq(key, "name")) bfr.Add_bry(name);
|
||||||
else if (String_.Eq(key, "title")) bfr.Add_bry(title);
|
else if (String_.Eq(key, "title")) bfr.Add_bry(title);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,23 +13,42 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.pagebanners;
|
||||||
import gplx.langs.mustaches.*; import gplx.xowa.parsers.lnkis.*;
|
|
||||||
import gplx.xowa.files.*;
|
import gplx.Bry_;
|
||||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.langs.htmls.encoders.*;
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Bry_fmt;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.htmls.Gfh_atr_;
|
||||||
|
import gplx.langs.htmls.docs.Gfh_tag;
|
||||||
|
import gplx.langs.htmls.encoders.Gfo_url_encoder_;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.mustaches.Mustache_bfr;
|
||||||
|
import gplx.langs.mustaches.Mustache_doc_itm;
|
||||||
|
import gplx.langs.mustaches.Mustache_doc_itm_;
|
||||||
|
import gplx.xowa.Xoa_ttl;
|
||||||
|
import gplx.xowa.files.Xof_file_itm;
|
||||||
|
import gplx.xowa.htmls.core.wkrs.imgs.atrs.Xoh_img_xoimg_data;
|
||||||
|
|
||||||
public class Pgbnr_itm implements Mustache_doc_itm {
|
public class Pgbnr_itm implements Mustache_doc_itm {
|
||||||
public Xoa_ttl banner_ttl;
|
public Xoa_ttl banner_ttl;
|
||||||
public byte[] banner_img_src;
|
public byte[] banner_img_src;
|
||||||
public byte[] toc;
|
public byte[] toc;
|
||||||
public Xof_file_itm banner_file_itm;
|
public Xof_file_itm banner_file_itm;
|
||||||
private byte[] banner_anch_title, banner_hdr_text, originx, banner_anch_href, srcset;
|
private byte[] banner_anch_title, banner_hdr_text, originx, srcset;
|
||||||
private double data_pos_x, data_pos_y;
|
private double data_pos_x, data_pos_y;
|
||||||
private int max_width;
|
public /**/ int max_width;
|
||||||
private boolean bottomtoc, isHeadingOverrideEnabled;
|
public /**/ byte[] banner_anch_href;
|
||||||
|
private boolean bottomtoc;
|
||||||
|
public /**/ boolean isHeadingOverrideEnabled;
|
||||||
private byte[] file_ttl;
|
private byte[] file_ttl;
|
||||||
private Pgbnr_icon[] icons;
|
private Pgbnr_icon[] icons;
|
||||||
private byte[] img_id_atr, img_xottl_atr, img_xoimg_atr;
|
private byte[] img_id_atr, img_xottl_atr, img_xoimg_atr;
|
||||||
private boolean isPanorama;
|
public /**/ boolean isPanorama;
|
||||||
private boolean enable_toc = true;
|
private boolean enable_toc = true;
|
||||||
private boolean hasPosition = false;
|
private boolean hasPosition = false;
|
||||||
|
|
||||||
@ -42,6 +61,15 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
|||||||
public double Data_pos_y() {return data_pos_y;}
|
public double Data_pos_y() {return data_pos_y;}
|
||||||
public boolean Show_toc_in_html() {return show_toc_in_html;} private boolean show_toc_in_html = false; // default to false so that TOC does not show up in both PageBanner and HTML body; DATE:2019-11-17
|
public boolean Show_toc_in_html() {return show_toc_in_html;} private boolean show_toc_in_html = false; // default to false so that TOC does not show up in both PageBanner and HTML body; DATE:2019-11-17
|
||||||
|
|
||||||
|
// hdump serialised info
|
||||||
|
public boolean Precoded() {return precoded;} private boolean precoded = false;
|
||||||
|
public byte[] Pgbnr_bry() {return pgbnr_bry;} private byte[] pgbnr_bry;
|
||||||
|
public void Pgbnr_bry_(byte[] v) {
|
||||||
|
if (v == null) return;
|
||||||
|
pgbnr_bry = v;
|
||||||
|
precoded = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void Clear_by_hdump() {
|
public void Clear_by_hdump() {
|
||||||
this.exists = false;
|
this.exists = false;
|
||||||
this.srcset = style = null;
|
this.srcset = style = null;
|
||||||
@ -63,11 +91,18 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
|||||||
}
|
}
|
||||||
public void Init_from_wtxt(Xoa_ttl banner_ttl, Xof_file_itm banner_file_itm, byte[] banner_anch_title, byte[] banner_hdr_text, boolean bottomtoc
|
public void Init_from_wtxt(Xoa_ttl banner_ttl, Xof_file_itm banner_file_itm, byte[] banner_anch_title, byte[] banner_hdr_text, boolean bottomtoc
|
||||||
, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons) {
|
, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons) {
|
||||||
|
Init_from_wtxt(banner_ttl, banner_file_itm, banner_anch_title, banner_hdr_text, bottomtoc
|
||||||
|
, toc, data_pos_x, data_pos_y, originx, icons, false);
|
||||||
|
}
|
||||||
|
public void Init_from_wtxt(Xoa_ttl banner_ttl, Xof_file_itm banner_file_itm, byte[] banner_anch_title, byte[] banner_hdr_text, boolean bottomtoc
|
||||||
|
, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons, boolean enable_toc) {
|
||||||
this.banner_ttl = banner_ttl; this.banner_file_itm = banner_file_itm;
|
this.banner_ttl = banner_ttl; this.banner_file_itm = banner_file_itm;
|
||||||
this.banner_anch_title = banner_anch_title; this.banner_hdr_text = banner_hdr_text; this.bottomtoc = bottomtoc; this.toc = toc; this.icons = icons;
|
this.banner_anch_title = banner_anch_title; this.banner_hdr_text = banner_hdr_text; this.bottomtoc = bottomtoc; this.toc = toc; this.icons = icons;
|
||||||
this.data_pos_x = data_pos_x; this.data_pos_y = data_pos_y; this.originx = originx;
|
this.data_pos_x = data_pos_x; this.data_pos_y = data_pos_y; this.originx = originx;
|
||||||
this.banner_img_src = banner_file_itm.Html_view_url().To_http_file_bry();
|
this.banner_img_src = banner_file_itm.Html_view_url().To_http_file_bry();
|
||||||
this.file_ttl = Gfo_url_encoder_.Href_quotes.Encode(banner_file_itm.Lnki_ttl()); // NOTE: Encode(Lnki_ttl) not Orig_ttl; else "%27s" instead of "'s" PAGE:en.v:'s-Hertogenbosch; DATE:2016-07-12
|
this.file_ttl = Gfo_url_encoder_.Href_quotes.Encode(banner_file_itm.Lnki_ttl()); // NOTE: Encode(Lnki_ttl) not Orig_ttl; else "%27s" instead of "'s" PAGE:en.v:'s-Hertogenbosch; DATE:2016-07-12
|
||||||
|
this.enable_toc = enable_toc;
|
||||||
|
show_toc_in_html = !enable_toc;
|
||||||
}
|
}
|
||||||
public void Init_from_html(int max_width, byte[] banner_anch_href, byte[] banner_img_src, byte[] srcset, boolean isHeadingOverrideEnabled, byte[] toc, boolean isPanorama) {
|
public void Init_from_html(int max_width, byte[] banner_anch_href, byte[] banner_img_src, byte[] srcset, boolean isHeadingOverrideEnabled, byte[] toc, boolean isPanorama) {
|
||||||
this.max_width = max_width;
|
this.max_width = max_width;
|
||||||
@ -126,4 +161,76 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
|||||||
, Atr_key__data_pos_y = Bry_.new_a7("data-pos-y")
|
, Atr_key__data_pos_y = Bry_.new_a7("data-pos-y")
|
||||||
, Atr_val__style_dflt = Bry_.new_a7("max-width:-1px")
|
, Atr_val__style_dflt = Bry_.new_a7("max-width:-1px")
|
||||||
;
|
;
|
||||||
|
public Json_nde Mustache__json() {
|
||||||
|
return buildargs();
|
||||||
|
}
|
||||||
|
private Json_nde buildargs() {
|
||||||
|
Json_nde jnde = Json_nde.NewByVal();
|
||||||
|
jnde.AddKvStr("title", banner_hdr_text);
|
||||||
|
jnde.AddKvStr("tooltip", banner_anch_title);
|
||||||
|
jnde.AddKvStr("bannerfile", banner_anch_href);
|
||||||
|
jnde.AddKvStr("banner", banner_img_src);
|
||||||
|
jnde.AddKvStr("srcset", srcset == null ? Bry_.Empty : Bry_.Empty);
|
||||||
|
jnde.AddKvStr("originx", originx);
|
||||||
|
jnde.AddKvStr("toc", toc);
|
||||||
|
jnde.AddKvStr("img_id_atr", img_id_atr);
|
||||||
|
jnde.AddKvStr("img_xottl", img_xottl_atr);
|
||||||
|
jnde.AddKvStr("img_xoimg", img_xoimg_atr);
|
||||||
|
jnde.AddKvStr("file_ttl", file_ttl);
|
||||||
|
jnde.AddKvDouble("data-pos-x", data_pos_x);
|
||||||
|
jnde.AddKvDouble("data-pos-y", data_pos_y);
|
||||||
|
jnde.AddKvInt("maxWidth", max_width);
|
||||||
|
jnde.AddKvBool("hasIcons", icons.length > 0);
|
||||||
|
jnde.AddKvBool("bottomtoc", bottomtoc);
|
||||||
|
jnde.AddKvBool("isHeadingOverrideEnabled", isHeadingOverrideEnabled);
|
||||||
|
jnde.AddKvBool("isPanorama", isPanorama);
|
||||||
|
jnde.AddKvBool("enable-toc", enable_toc);
|
||||||
|
jnde.AddKvBool("hasPosition", hasPosition);
|
||||||
|
Json_ary ary = null;
|
||||||
|
if (json_icon_list != null) {
|
||||||
|
ary = Json_ary.NewByVal();
|
||||||
|
int iconlen = json_icon_list.Len();
|
||||||
|
for (int i = 0; i < iconlen; i++) {
|
||||||
|
Json_nde inde = (Json_nde)json_icon_list.Get_at(i);
|
||||||
|
ary.Add(inde);
|
||||||
|
}
|
||||||
|
if (iconlen > 0) {
|
||||||
|
jnde.AddKvAry("icons", ary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int iconLen = icons.length;
|
||||||
|
if (iconLen > 0) {
|
||||||
|
ary = Json_ary.NewByVal();
|
||||||
|
Bry_bfr tmpBfr = Bry_bfr_.New();
|
||||||
|
for (int i = 0; i < iconLen; i++) {
|
||||||
|
Pgbnr_icon icon = icons[i];
|
||||||
|
Json_nde iconNde = Pgbnr_iconx(tmpBfr, icon.Name(), icon.Title(), icon.Href());
|
||||||
|
ary.Add(iconNde);
|
||||||
|
}
|
||||||
|
jnde.AddKvAry("icons", ary);
|
||||||
|
}
|
||||||
|
return jnde;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List_adp json_icon_list;
|
||||||
|
public void Add_new_icon(Bry_bfr tmp_bfr, byte[] name, byte[] title, byte[] href) {
|
||||||
|
if (json_icon_list == null) json_icon_list = List_adp_.New();
|
||||||
|
json_icon_list.Add(Pgbnr_iconx(tmp_bfr, name, title, href));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Json_nde Pgbnr_iconx(Bry_bfr tmp_bfr, byte[] name, byte[] title, byte[] href) {
|
||||||
|
fmt.Bld_many(tmp_bfr, name, title);
|
||||||
|
byte[] html = tmp_bfr.To_bry_and_clear();
|
||||||
|
Json_nde jnde = Json_nde.NewByVal();
|
||||||
|
jnde.AddKvStr("name", name);
|
||||||
|
jnde.AddKvStr("title", title);
|
||||||
|
jnde.AddKvStr("url", href);
|
||||||
|
jnde.AddKvStr("html", html);
|
||||||
|
return jnde;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Bry_fmt fmt = Bry_fmt.New
|
||||||
|
( Bry_.New_u8_nl_apos("<span aria-disabled=\"false\" title=\"~{title}\" class=\"oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-~{name} oo-ui-iconElement oo-ui-iconWidget\"></span>")
|
||||||
|
, "name", "title"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package gplx.xowa.xtns.pagebanners;
|
|||||||
import gplx.Bry_;
|
import gplx.Bry_;
|
||||||
import gplx.Bry_bfr;
|
import gplx.Bry_bfr;
|
||||||
import gplx.Int_ary_;
|
import gplx.Int_ary_;
|
||||||
import gplx.Io_mgr;
|
|
||||||
import gplx.core.brys.Bfr_arg;
|
import gplx.core.brys.Bfr_arg;
|
||||||
import gplx.langs.mustaches.Mustache_tkn_itm;
|
import gplx.langs.mustaches.Mustache_tkn_itm;
|
||||||
import gplx.langs.mustaches.Mustache_tkn_parser;
|
import gplx.langs.mustaches.Mustache_tkn_parser;
|
||||||
@ -86,9 +85,11 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
|
|||||||
|
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
// load template file;
|
// load template file;
|
||||||
byte[] template_data = Io_mgr.Instance.LoadFilBryOr(wiki.Appe().Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "xtns", "WikidataPageBanner", "templates", "banner.mustache"), Template_dflt);
|
//byte[] template_data = Io_mgr.Instance.LoadFilBryOr(wiki.Appe().Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "xtns", "WikidataPageBanner", "templates", "banner.mustache"), Template_dflt);
|
||||||
Mustache_tkn_parser parser = new Mustache_tkn_parser();
|
//Mustache_tkn_parser parser = new Mustache_tkn_parser();
|
||||||
template_root = parser.Parse(template_data, 0, template_data.length);
|
//template_root = parser.Parse(template_data, 0, template_data.length);
|
||||||
|
Mustache_tkn_parser parser = new Mustache_tkn_parser(wiki.Appe().Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "xtns", "WikidataPageBanner", "templates"));
|
||||||
|
template_root = parser.Parse("banner", Template_dflt);
|
||||||
}
|
}
|
||||||
public Bfr_arg Write_html(Xoae_page wpg, Xop_ctx pctx, Xoh_wtr_ctx hctx) {
|
public Bfr_arg Write_html(Xoae_page wpg, Xop_ctx pctx, Xoh_wtr_ctx hctx) {
|
||||||
this.wpg = wpg; this.pctx = pctx; this.hctx = hctx;
|
this.wpg = wpg; this.pctx = pctx; this.hctx = hctx;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,8 +13,31 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
package gplx.xowa.xtns.scribunto.libs;
|
||||||
import gplx.langs.jsons.*;
|
|
||||||
|
import gplx.Array_;
|
||||||
|
import gplx.Bool_;
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.CompareAble_;
|
||||||
|
import gplx.Double_;
|
||||||
|
import gplx.Float_;
|
||||||
|
import gplx.Int_;
|
||||||
|
import gplx.Keyval;
|
||||||
|
import gplx.Keyval_;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.Long_;
|
||||||
|
import gplx.Object_;
|
||||||
|
import gplx.Type_;
|
||||||
|
import gplx.Type_ids_;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_itm_;
|
||||||
|
import gplx.langs.jsons.Json_kv;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.langs.jsons.Json_parser;
|
||||||
|
import gplx.langs.jsons.Json_wtr;
|
||||||
|
|
||||||
public class Scrib_lib_text__json_util {
|
public class Scrib_lib_text__json_util {
|
||||||
private final Json_wtr wtr = new Json_wtr();
|
private final Json_wtr wtr = new Json_wtr();
|
||||||
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, Keyval[] kv_ary, boolean is_encoding) {
|
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, Keyval[] kv_ary, boolean is_encoding) {
|
||||||
@ -104,7 +127,7 @@ public class Scrib_lib_text__json_util {
|
|||||||
int itm_tid = itm.Tid();
|
int itm_tid = itm.Tid();
|
||||||
switch (itm_tid) {
|
switch (itm_tid) {
|
||||||
case Json_itm_.Tid__ary: return Decode_ary_sub(Json_ary.cast(itm));
|
case Json_itm_.Tid__ary: return Decode_ary_sub(Json_ary.cast(itm));
|
||||||
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.cast(itm));
|
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.Cast(itm));
|
||||||
default: return itm.Data();
|
default: return itm.Data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,7 +254,7 @@ class KeyVal__sorter__key_is_numeric implements gplx.core.lists.ComparerAble {
|
|||||||
Keyval rhs_itm = (Keyval)rhsObj;
|
Keyval rhs_itm = (Keyval)rhsObj;
|
||||||
int lhs_int = Int_.Parse_or(lhs_itm.Key(), Int_.Min_value);
|
int lhs_int = Int_.Parse_or(lhs_itm.Key(), Int_.Min_value);
|
||||||
int rhs_int = Int_.Parse_or(rhs_itm.Key(), Int_.Min_value);
|
int rhs_int = Int_.Parse_or(rhs_itm.Key(), Int_.Min_value);
|
||||||
return CompareAble_.Compare(lhs_int, rhs_int);
|
return CompareAble_.Compare((Integer)lhs_int, (Integer)rhs_int);
|
||||||
}
|
}
|
||||||
public static final KeyVal__sorter__key_is_numeric Instance = new KeyVal__sorter__key_is_numeric(); KeyVal__sorter__key_is_numeric() {}
|
public static final KeyVal__sorter__key_is_numeric Instance = new KeyVal__sorter__key_is_numeric(); KeyVal__sorter__key_is_numeric() {}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
|||||||
public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser();
|
public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser();
|
||||||
public void Init_by_app() {}
|
public void Init_by_app() {}
|
||||||
public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) {
|
public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) {
|
||||||
Json_kv itm_0 = Json_kv.cast(jdoc.Root_nde().Get_at(0)); // get 1st node
|
Json_kv itm_0 = Json_kv.Cast(jdoc.Root_nde().Get_at(0)); // get 1st node
|
||||||
return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type)
|
return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type)
|
||||||
|| Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_id)
|
|| Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_id)
|
||||||
? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2
|
? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,10 +13,51 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.wbases;
|
||||||
import gplx.core.primitives.*; import gplx.langs.jsons.*;
|
|
||||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.domains.*;
|
import gplx.Bry_;
|
||||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.pfuncs.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.stores.*;
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.Byte_ascii;
|
||||||
|
import gplx.Int_;
|
||||||
|
import gplx.Io_mgr;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.Ordered_hash;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.Tfds;
|
||||||
|
import gplx.core.primitives.Gfo_number_parser;
|
||||||
|
import gplx.core.primitives.Int_obj_ref;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.xowa.Xoa_ttl;
|
||||||
|
import gplx.xowa.Xoae_app;
|
||||||
|
import gplx.xowa.Xoae_page;
|
||||||
|
import gplx.xowa.Xop_fxt;
|
||||||
|
import gplx.xowa.Xowe_wiki;
|
||||||
|
import gplx.xowa.wikis.domains.Xow_abrv_wm_;
|
||||||
|
import gplx.xowa.wikis.domains.Xow_domain_itm;
|
||||||
|
import gplx.xowa.wikis.nss.Xow_ns_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp_list;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_references_grp;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_entity_type_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_base;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_entity;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_globecoordinate;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_monolingualtext;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_quantity;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_string;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_time;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_time_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_value;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wbase_pid;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_sitelink_itm;
|
||||||
|
import gplx.xowa.xtns.wbases.pfuncs.Wbase_statement_mgr_;
|
||||||
|
import gplx.xowa.xtns.wbases.pfuncs.Wdata_external_lang_links_data;
|
||||||
|
import gplx.xowa.xtns.wbases.stores.Wbase_prop_mgr_loader_;
|
||||||
|
import gplx.xowa.xtns.wbases.stores.Wbase_qid_mgr;
|
||||||
|
|
||||||
public class Wdata_wiki_mgr_fxt {
|
public class Wdata_wiki_mgr_fxt {
|
||||||
private Xoae_app app; private Xowe_wiki wiki; private Wdata_doc_bldr wdoc_bldr;
|
private Xoae_app app; private Xowe_wiki wiki; private Wdata_doc_bldr wdoc_bldr;
|
||||||
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
|
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
|
||||||
@ -181,7 +222,7 @@ public class Wdata_wiki_mgr_fxt {
|
|||||||
}
|
}
|
||||||
public void Test_write_json_as_html(String raw_str, String expd) {
|
public void Test_write_json_as_html(String raw_str, String expd) {
|
||||||
byte[] raw_bry = Bry_.new_a7(raw_str);
|
byte[] raw_bry = Bry_.new_a7(raw_str);
|
||||||
raw_bry = gplx.langs.jsons.Json_parser_tst.Replace_apos(raw_bry);
|
raw_bry = Bry_.new_u8(Json_doc.Make_str_by_apos(raw_str));
|
||||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||||
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
|
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
|
||||||
Tfds.Eq(expd, bfr.To_str_and_rls());
|
Tfds.Eq(expd, bfr.To_str_and_rls());
|
||||||
|
@ -39,11 +39,11 @@ public class Wbase_claim_factory {
|
|||||||
public Wbase_claim_base Parse(byte[] qid, int pid, byte snak_tid, Json_nde nde, byte value_tid, Json_itm value_itm) {
|
public Wbase_claim_base Parse(byte[] qid, int pid, byte snak_tid, Json_nde nde, byte value_tid, Json_itm value_itm) {
|
||||||
switch (value_tid) {
|
switch (value_tid) {
|
||||||
case Wbase_claim_type_.Tid__string: return new Wbase_claim_string(pid, snak_tid, value_itm.Data_bry());
|
case Wbase_claim_type_.Tid__string: return new Wbase_claim_string(pid, snak_tid, value_itm.Data_bry());
|
||||||
case Wbase_claim_type_.Tid__entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
case Wbase_claim_type_.Tid__entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_nde.Cast(value_itm));
|
||||||
case Wbase_claim_type_.Tid__time: return Parse_datavalue_time (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
case Wbase_claim_type_.Tid__time: return Parse_datavalue_time (qid, pid, snak_tid, Json_nde.Cast(value_itm));
|
||||||
case Wbase_claim_type_.Tid__quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
case Wbase_claim_type_.Tid__quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_nde.Cast(value_itm));
|
||||||
case Wbase_claim_type_.Tid__globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
case Wbase_claim_type_.Tid__globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_nde.Cast(value_itm));
|
||||||
case Wbase_claim_type_.Tid__monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
case Wbase_claim_type_.Tid__monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_nde.Cast(value_itm));
|
||||||
default: throw Err_.new_unhandled_default(value_tid);
|
default: throw Err_.new_unhandled_default(value_tid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ public class Wbase_claim_factory {
|
|||||||
byte[] numericId = null;
|
byte[] numericId = null;
|
||||||
byte[] id = null;
|
byte[] id = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wbase_claim_entity_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wbase_claim_entity_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
byte[] subValBry = sub.Val().Data_bry();
|
byte[] subValBry = sub.Val().Data_bry();
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
@ -70,7 +70,7 @@ public class Wbase_claim_factory {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
byte[] lang = null, text = null;
|
byte[] lang = null, text = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wbase_claim_monolingualtext_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wbase_claim_monolingualtext_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
@ -85,7 +85,7 @@ public class Wbase_claim_factory {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
byte[] lat = null, lng = null, alt = null, prc = null, glb = null;
|
byte[] lat = null, lng = null, alt = null, prc = null, glb = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wbase_claim_globecoordinate_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wbase_claim_globecoordinate_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
@ -103,7 +103,7 @@ public class Wbase_claim_factory {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
byte[] amount = null, unit = null, ubound = null, lbound = null;
|
byte[] amount = null, unit = null, ubound = null, lbound = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wbase_claim_quantity_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wbase_claim_quantity_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
@ -120,7 +120,7 @@ public class Wbase_claim_factory {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null;
|
byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wbase_claim_time_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wbase_claim_time_.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,9 +13,32 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
package gplx.xowa.xtns.wbases.parsers;
|
||||||
import gplx.core.primitives.*;
|
|
||||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
import gplx.Bry_;
|
||||||
|
import gplx.Byte_;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.core.primitives.Int_obj_ref;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_kv;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp_list;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_references_grp;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_rank_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_type_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_base;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_value;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_claim;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_datavalue;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_mainsnak;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_reference;
|
||||||
|
|
||||||
class Wdata_claims_parser_v2 {
|
class Wdata_claims_parser_v2 {
|
||||||
private final Wbase_claim_factory factory = new Wbase_claim_factory();
|
private final Wbase_claim_factory factory = new Wbase_claim_factory();
|
||||||
public void Make_claim_itms(byte[] qid, List_adp claim_itms_list, byte[] src, Json_kv claim_grp) {
|
public void Make_claim_itms(byte[] qid, List_adp claim_itms_list, byte[] src, Json_kv claim_grp) {
|
||||||
@ -23,7 +46,7 @@ class Wdata_claims_parser_v2 {
|
|||||||
int claim_itms_len = claim_itms_ary.Len();
|
int claim_itms_len = claim_itms_ary.Len();
|
||||||
int pid = Parse_pid(claim_grp.Key().Data_bry());
|
int pid = Parse_pid(claim_grp.Key().Data_bry());
|
||||||
for (int i = 0; i < claim_itms_len; ++i) {
|
for (int i = 0; i < claim_itms_len; ++i) {
|
||||||
Json_nde claim_itm_nde = Json_nde.cast(claim_itms_ary.Get_at(i));
|
Json_nde claim_itm_nde = Json_nde.Cast(claim_itms_ary.Get_at(i));
|
||||||
Wbase_claim_base itm = Parse_claim_itm(qid, claim_itm_nde, pid);
|
Wbase_claim_base itm = Parse_claim_itm(qid, claim_itm_nde, pid);
|
||||||
if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20
|
if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20
|
||||||
claim_itms_list.Add(itm);
|
claim_itms_list.Add(itm);
|
||||||
@ -34,13 +57,13 @@ class Wdata_claims_parser_v2 {
|
|||||||
byte rank_tid = Wbase_claim_rank_.Tid__unknown;
|
byte rank_tid = Wbase_claim_rank_.Tid__unknown;
|
||||||
Wbase_claim_base claim_itm = null; Wbase_claim_grp_list qualifiers = null; int[] qualifiers_order = null; Wbase_references_grp[] snaks_grp = null;
|
Wbase_claim_base claim_itm = null; Wbase_claim_grp_list qualifiers = null; int[] qualifiers_order = null; Wbase_references_grp[] snaks_grp = null;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wdata_dict_claim.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_claim.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_claim.Tid__mainsnak: claim_itm = Parse_mainsnak(qid, Json_nde.cast(sub.Val()), pid); break;
|
case Wdata_dict_claim.Tid__mainsnak: claim_itm = Parse_mainsnak(qid, Json_nde.Cast(sub.Val()), pid); break;
|
||||||
case Wdata_dict_claim.Tid__rank: rank_tid = Wbase_claim_rank_.Reg.Get_tid_or(sub.Val().Data_bry(), Wbase_claim_rank_.Tid__unknown); break;
|
case Wdata_dict_claim.Tid__rank: rank_tid = Wbase_claim_rank_.Reg.Get_tid_or(sub.Val().Data_bry(), Wbase_claim_rank_.Tid__unknown); break;
|
||||||
case Wdata_dict_claim.Tid__references: snaks_grp = Parse_references(qid, Json_ary.cast_or_null(sub.Val())); break;
|
case Wdata_dict_claim.Tid__references: snaks_grp = Parse_references(qid, Json_ary.cast_or_null(sub.Val())); break;
|
||||||
case Wdata_dict_claim.Tid__qualifiers: qualifiers = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
|
case Wdata_dict_claim.Tid__qualifiers: qualifiers = Parse_qualifiers(qid, Json_nde.Cast(sub.Val())); break;
|
||||||
case Wdata_dict_claim.Tid__qualifiers_order: qualifiers_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
case Wdata_dict_claim.Tid__qualifiers_order: qualifiers_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
||||||
case Wdata_dict_claim.Tid__type: break; // ignore: "statement"
|
case Wdata_dict_claim.Tid__type: break; // ignore: "statement"
|
||||||
case Wdata_dict_claim.Tid__id: break; // ignore: "Q2$F909BD1C-D34D-423F-9ED2-3493663321AF"
|
case Wdata_dict_claim.Tid__id: break; // ignore: "Q2$F909BD1C-D34D-423F-9ED2-3493663321AF"
|
||||||
@ -58,7 +81,7 @@ class Wdata_claims_parser_v2 {
|
|||||||
int len = owner.Len();
|
int len = owner.Len();
|
||||||
Wbase_references_grp[] rv = new Wbase_references_grp[len];
|
Wbase_references_grp[] rv = new Wbase_references_grp[len];
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_nde grp_nde = Json_nde.cast(owner.Get_at(i));
|
Json_nde grp_nde = Json_nde.Cast(owner.Get_at(i));
|
||||||
rv[i] = Parse_references_grp(qid, grp_nde);
|
rv[i] = Parse_references_grp(qid, grp_nde);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
@ -69,11 +92,11 @@ class Wdata_claims_parser_v2 {
|
|||||||
int[] snaks_order = null;
|
int[] snaks_order = null;
|
||||||
int len = owner.Len();
|
int len = owner.Len();
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(owner.Get_at(i));
|
Json_kv sub = Json_kv.Cast(owner.Get_at(i));
|
||||||
byte tid = Wdata_dict_reference.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_reference.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_reference.Tid__hash: hash = sub.Val_as_bry(); break;
|
case Wdata_dict_reference.Tid__hash: hash = sub.Val_as_bry(); break;
|
||||||
case Wdata_dict_reference.Tid__snaks: snaks = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
|
case Wdata_dict_reference.Tid__snaks: snaks = Parse_qualifiers(qid, Json_nde.Cast(sub.Val())); break;
|
||||||
case Wdata_dict_reference.Tid__snaks_order: snaks_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
case Wdata_dict_reference.Tid__snaks_order: snaks_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +107,7 @@ class Wdata_claims_parser_v2 {
|
|||||||
if (qualifiers_nde == null) return rv; // NOTE:sometimes references can have 0 snaks; return back an empty Wbase_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
|
if (qualifiers_nde == null) return rv; // NOTE:sometimes references can have 0 snaks; return back an empty Wbase_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
|
||||||
int len = qualifiers_nde.Len();
|
int len = qualifiers_nde.Len();
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv qualifier_kv = Json_kv.cast(qualifiers_nde.Get_at(i));
|
Json_kv qualifier_kv = Json_kv.Cast(qualifiers_nde.Get_at(i));
|
||||||
int pid = Parse_pid(qualifier_kv.Key().Data_bry());
|
int pid = Parse_pid(qualifier_kv.Key().Data_bry());
|
||||||
Wbase_claim_grp claims_grp = Parse_props_grp(qid, pid, Json_ary.cast_or_null(qualifier_kv.Val()));
|
Wbase_claim_grp claims_grp = Parse_props_grp(qid, pid, Json_ary.cast_or_null(qualifier_kv.Val()));
|
||||||
rv.Add(claims_grp);
|
rv.Add(claims_grp);
|
||||||
@ -104,7 +127,7 @@ class Wdata_claims_parser_v2 {
|
|||||||
List_adp list = List_adp_.New();
|
List_adp list = List_adp_.New();
|
||||||
int len = props_ary.Len();
|
int len = props_ary.Len();
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_nde qualifier_nde = Json_nde.cast(props_ary.Get_at(i));
|
Json_nde qualifier_nde = Json_nde.Cast(props_ary.Get_at(i));
|
||||||
Wbase_claim_base qualifier_itm = Parse_mainsnak(qid, qualifier_nde, pid);
|
Wbase_claim_base qualifier_itm = Parse_mainsnak(qid, qualifier_nde, pid);
|
||||||
list.Add(qualifier_itm);
|
list.Add(qualifier_itm);
|
||||||
}
|
}
|
||||||
@ -114,11 +137,11 @@ class Wdata_claims_parser_v2 {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
byte snak_tid = Byte_.Max_value_127;
|
byte snak_tid = Byte_.Max_value_127;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wdata_dict_mainsnak.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_mainsnak.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_mainsnak.Tid__snaktype: snak_tid = Wbase_claim_value_type_.Reg.Get_tid_or_fail(sub.Val().Data_bry()); break;
|
case Wdata_dict_mainsnak.Tid__snaktype: snak_tid = Wbase_claim_value_type_.Reg.Get_tid_or_fail(sub.Val().Data_bry()); break;
|
||||||
case Wdata_dict_mainsnak.Tid__datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_nde.cast(sub.Val()));
|
case Wdata_dict_mainsnak.Tid__datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_nde.Cast(sub.Val()));
|
||||||
case Wdata_dict_mainsnak.Tid__datatype: break; // ignore: has values like "wikibase-property"; EX: www.wikidata.org/wiki/Property:P397; DATE:2015-06-12
|
case Wdata_dict_mainsnak.Tid__datatype: break; // ignore: has values like "wikibase-property"; EX: www.wikidata.org/wiki/Property:P397; DATE:2015-06-12
|
||||||
case Wdata_dict_mainsnak.Tid__property: break; // ignore: pid already available above
|
case Wdata_dict_mainsnak.Tid__property: break; // ignore: pid already available above
|
||||||
case Wdata_dict_mainsnak.Tid__hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390"
|
case Wdata_dict_mainsnak.Tid__hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390"
|
||||||
@ -130,7 +153,7 @@ class Wdata_claims_parser_v2 {
|
|||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
Json_itm value_itm = null; byte value_tid = Wbase_claim_type_.Tid__unknown;
|
Json_itm value_itm = null; byte value_tid = Wbase_claim_type_.Tid__unknown;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
Json_kv sub = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte tid = Wdata_dict_datavalue.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_datavalue.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_datavalue.Tid__type: value_tid = Wbase_claim_type_.Get_tid_or_unknown(sub.Val().Data_bry()); break;
|
case Wdata_dict_datavalue.Tid__type: value_tid = Wbase_claim_type_.Get_tid_or_unknown(sub.Val().Data_bry()); break;
|
||||||
|
@ -100,13 +100,13 @@ abstract class Wdata_doc_parser_fxt_base {
|
|||||||
}
|
}
|
||||||
public void Test_qualifiers(String raw, Wbase_claim_base... expd_itms) {
|
public void Test_qualifiers(String raw, Wbase_claim_base... expd_itms) {
|
||||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||||
Json_nde qualifiers_nde = Json_nde.cast(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
Json_nde qualifiers_nde = Json_nde.Cast(Json_kv.Cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||||
Wbase_claim_grp_list actl = wdoc_parser.Parse_qualifiers(Q1_bry, qualifiers_nde);
|
Wbase_claim_grp_list actl = wdoc_parser.Parse_qualifiers(Q1_bry, qualifiers_nde);
|
||||||
Tfds.Eq_ary_str(expd_itms, To_ary(actl));
|
Tfds.Eq_ary_str(expd_itms, To_ary(actl));
|
||||||
}
|
}
|
||||||
public void Test_references(String raw, int[] expd_order, Wbase_claim_base... expd_itms) {
|
public void Test_references(String raw, int[] expd_order, Wbase_claim_base... expd_itms) {
|
||||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||||
Json_ary owner = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
Json_ary owner = Json_ary.cast_or_null(Json_kv.Cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||||
Wbase_references_grp[] actl = wdoc_parser.Parse_references(Q1_bry, owner);
|
Wbase_references_grp[] actl = wdoc_parser.Parse_references(Q1_bry, owner);
|
||||||
Wbase_references_grp actl_grp = actl[0];
|
Wbase_references_grp actl_grp = actl[0];
|
||||||
Tfds.Eq_ary(expd_order, actl_grp.Snaks_order());
|
Tfds.Eq_ary(expd_order, actl_grp.Snaks_order());
|
||||||
@ -114,7 +114,7 @@ abstract class Wdata_doc_parser_fxt_base {
|
|||||||
}
|
}
|
||||||
public void Test_pid_order(String raw, int... expd) {
|
public void Test_pid_order(String raw, int... expd) {
|
||||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||||
Json_ary nde = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
Json_ary nde = Json_ary.cast_or_null(Json_kv.Cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||||
int[] actl = wdoc_parser.Parse_pid_order(Q1_bry, nde);
|
int[] actl = wdoc_parser.Parse_pid_order(Q1_bry, nde);
|
||||||
Tfds.Eq_ary(expd, actl);
|
Tfds.Eq_ary(expd, actl);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
package gplx.xowa.xtns.wbases.parsers; import gplx.*;
|
||||||
import gplx.core.primitives.*; import gplx.langs.jsons.*;
|
import gplx.core.primitives.*; import gplx.langs.jsons.*;
|
||||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||||
public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||||
@ -36,18 +36,18 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
}
|
}
|
||||||
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
||||||
try {
|
try {
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv wiki_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv wiki_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
byte[] site_bry = wiki_kv.Key().Data_bry();
|
byte[] site_bry = wiki_kv.Key().Data_bry();
|
||||||
byte[] title_bry = null; byte[][] badges_bry_ary = null;
|
byte[] title_bry = null; byte[][] badges_bry_ary = null;
|
||||||
if (wiki_kv.Val().Tid() == Json_itm_.Tid__nde) { // v1.2: "enwiki":{name:"Earth", badges:[]}
|
if (wiki_kv.Val().Tid() == Json_itm_.Tid__nde) { // v1.2: "enwiki":{name:"Earth", badges:[]}
|
||||||
Json_nde val_nde = Json_nde.cast(wiki_kv.Val());
|
Json_nde val_nde = Json_nde.Cast(wiki_kv.Val());
|
||||||
Json_kv name_kv = Json_kv.cast(val_nde.Get_at(0));
|
Json_kv name_kv = Json_kv.Cast(val_nde.Get_at(0));
|
||||||
title_bry = name_kv.Val().Data_bry();
|
title_bry = name_kv.Val().Data_bry();
|
||||||
Json_kv badges_kv = Json_kv.cast(val_nde.Get_at(1));
|
Json_kv badges_kv = Json_kv.Cast(val_nde.Get_at(1));
|
||||||
if (badges_kv != null) {// TEST:some tests do not define a badges nde; ignore if null; DATE:2014-09-19
|
if (badges_kv != null) {// TEST:some tests do not define a badges nde; ignore if null; DATE:2014-09-19
|
||||||
Json_ary badges_ary = Json_ary.cast_or_null(badges_kv.Val());
|
Json_ary badges_ary = Json_ary.cast_or_null(badges_kv.Val());
|
||||||
badges_bry_ary = badges_ary.Xto_bry_ary();
|
badges_bry_ary = badges_ary.Xto_bry_ary();
|
||||||
@ -65,11 +65,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
||||||
try {
|
try {
|
||||||
byte[] langval_key = label_or_description ? Bry_label : Bry_description;
|
byte[] langval_key = label_or_description ? Bry_label : Bry_description;
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv data_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||||
Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, data_kv.Val().Data_bry());
|
Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, data_kv.Val().Data_bry());
|
||||||
rv.Add(lang_bry, itm);
|
rv.Add(lang_bry, itm);
|
||||||
@ -79,11 +79,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
}
|
}
|
||||||
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
||||||
try {
|
try {
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv data_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||||
byte[][] vals_bry_ary = null;
|
byte[][] vals_bry_ary = null;
|
||||||
Json_itm data_val = data_kv.Val();
|
Json_itm data_val = data_kv.Val();
|
||||||
@ -93,11 +93,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
vals_bry_ary = vals_ary.Xto_bry_ary();
|
vals_bry_ary = vals_ary.Xto_bry_ary();
|
||||||
break;
|
break;
|
||||||
case Json_itm_.Tid__nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21
|
case Json_itm_.Tid__nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21
|
||||||
Json_nde vals_nde = Json_nde.cast(data_val);
|
Json_nde vals_nde = Json_nde.Cast(data_val);
|
||||||
int vals_len = vals_nde.Len();
|
int vals_len = vals_nde.Len();
|
||||||
vals_bry_ary = new byte[vals_len][];
|
vals_bry_ary = new byte[vals_len][];
|
||||||
for (int j = 0; j < vals_len; ++j) {
|
for (int j = 0; j < vals_len; ++j) {
|
||||||
Json_kv vals_sub_kv = Json_kv.cast(vals_nde.Get_at(j));
|
Json_kv vals_sub_kv = Json_kv.Cast(vals_nde.Get_at(j));
|
||||||
vals_bry_ary[j] = vals_sub_kv.Val().Data_bry();
|
vals_bry_ary[j] = vals_sub_kv.Val().Data_bry();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -116,7 +116,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
byte[] src = doc.Src();
|
byte[] src = doc.Src();
|
||||||
int len = list_nde.Len();
|
int len = list_nde.Len();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Json_nde claim_nde = Json_nde.cast(list_nde.Get_at(i));
|
Json_nde claim_nde = Json_nde.Cast(list_nde.Get_at(i));
|
||||||
Wbase_claim_base claim_itm = Make_claim_itm(src, claim_nde);
|
Wbase_claim_base claim_itm = Make_claim_itm(src, claim_nde);
|
||||||
temp_list.Add(claim_itm);
|
temp_list.Add(claim_itm);
|
||||||
}
|
}
|
||||||
@ -150,10 +150,10 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
int len = prop_nde.Len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys)
|
int len = prop_nde.Len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys)
|
||||||
Wbase_claim_base rv = null;
|
Wbase_claim_base rv = null;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Json_kv kv = Json_kv.cast(prop_nde.Get_at(i));
|
Json_kv kv = Json_kv.Cast(prop_nde.Get_at(i));
|
||||||
Json_itm kv_key = kv.Key();
|
Json_itm kv_key = kv.Key();
|
||||||
Byte_obj_val bv = (Byte_obj_val)Prop_key_hash.Get_by_mid(src, kv_key.Src_bgn(), kv_key.Src_end());
|
Byte_obj_val bv = (Byte_obj_val)Prop_key_hash.Get_by_bry(kv_key.Data_bry());
|
||||||
if (bv == null) {Warn("invalid prop node: ~{0}", String_.new_u8(src, kv_key.Src_bgn(), kv_key.Src_end())); return null;}
|
if (bv == null) {Warn("invalid prop node: ~{0}", String_.new_u8(kv_key.Data_bry())); return null;}
|
||||||
switch (bv.Val()) {
|
switch (bv.Val()) {
|
||||||
case Prop_tid_m:
|
case Prop_tid_m:
|
||||||
rv = New_prop_by_m(src, Json_ary.cast_or_null(kv.Val()));
|
rv = New_prop_by_m(src, Json_ary.cast_or_null(kv.Val()));
|
||||||
@ -176,13 +176,13 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
}
|
}
|
||||||
private Wbase_claim_base New_prop_by_m(byte[] src, Json_ary ary) {
|
private Wbase_claim_base New_prop_by_m(byte[] src, Json_ary ary) {
|
||||||
byte snak_tid = Wbase_claim_value_type_.Reg.Get_tid_or_fail(ary.Get_at(0).Data_bry());
|
byte snak_tid = Wbase_claim_value_type_.Reg.Get_tid_or_fail(ary.Get_at(0).Data_bry());
|
||||||
int pid = Json_itm_int.cast(ary.Get_at(1)).Data_as_int();
|
int pid = Json_itm_int.Cast(ary.Get_at(1)).Data_as_int();
|
||||||
switch (snak_tid) {
|
switch (snak_tid) {
|
||||||
case Wbase_claim_value_type_.Tid__novalue : return Wbase_claim_value.New_novalue(pid);
|
case Wbase_claim_value_type_.Tid__novalue : return Wbase_claim_value.New_novalue(pid);
|
||||||
case Wbase_claim_value_type_.Tid__somevalue : return Wbase_claim_value.New_somevalue(pid);
|
case Wbase_claim_value_type_.Tid__somevalue : return Wbase_claim_value.New_somevalue(pid);
|
||||||
}
|
}
|
||||||
Json_itm val_tid_itm = ary.Get_at(2);
|
Json_itm val_tid_itm = ary.Get_at(2);
|
||||||
byte val_tid = Wbase_claim_type_.Get_tid_or_unknown(src, val_tid_itm.Src_bgn(), val_tid_itm.Src_end());
|
byte val_tid = Wbase_claim_type_.Get_tid_or_unknown(val_tid_itm.Data_bry());
|
||||||
return Make_itm(pid, snak_tid, val_tid, ary);
|
return Make_itm(pid, snak_tid, val_tid, ary);
|
||||||
}
|
}
|
||||||
private Wbase_claim_base Make_itm(int pid, byte snak_tid, byte val_tid, Json_ary ary) {
|
private Wbase_claim_base Make_itm(int pid, byte snak_tid, byte val_tid, Json_ary ary) {
|
||||||
@ -190,31 +190,31 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
case Wbase_claim_type_.Tid__string:
|
case Wbase_claim_type_.Tid__string:
|
||||||
return new Wbase_claim_string(pid, snak_tid, ary.Get_at(3).Data_bry());
|
return new Wbase_claim_string(pid, snak_tid, ary.Get_at(3).Data_bry());
|
||||||
case Wbase_claim_type_.Tid__entity: {
|
case Wbase_claim_type_.Tid__entity: {
|
||||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
Json_nde sub_nde = Json_nde.Cast(ary.Get_at(3));
|
||||||
Json_kv entity_kv = Json_kv.cast(sub_nde.Get_at(1));
|
Json_kv entity_kv = Json_kv.Cast(sub_nde.Get_at(1));
|
||||||
return new Wbase_claim_entity(pid, snak_tid, Wbase_claim_entity_type_.Tid__item, entity_kv.Val().Data_bry());
|
return new Wbase_claim_entity(pid, snak_tid, Wbase_claim_entity_type_.Tid__item, entity_kv.Val().Data_bry());
|
||||||
}
|
}
|
||||||
case Wbase_claim_type_.Tid__time: {
|
case Wbase_claim_type_.Tid__time: {
|
||||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
Json_nde sub_nde = Json_nde.Cast(ary.Get_at(3));
|
||||||
return new Wbase_claim_time(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4), Get_val(sub_nde, 5));
|
return new Wbase_claim_time(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4), Get_val(sub_nde, 5));
|
||||||
}
|
}
|
||||||
case Wbase_claim_type_.Tid__globecoordinate: case Wbase_claim_type_.Tid__bad: {
|
case Wbase_claim_type_.Tid__globecoordinate: case Wbase_claim_type_.Tid__bad: {
|
||||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
Json_nde sub_nde = Json_nde.Cast(ary.Get_at(3));
|
||||||
return new Wbase_claim_globecoordinate(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4));
|
return new Wbase_claim_globecoordinate(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4));
|
||||||
}
|
}
|
||||||
case Wbase_claim_type_.Tid__quantity: {
|
case Wbase_claim_type_.Tid__quantity: {
|
||||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
Json_nde sub_nde = Json_nde.Cast(ary.Get_at(3));
|
||||||
return new Wbase_claim_quantity(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3));
|
return new Wbase_claim_quantity(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3));
|
||||||
}
|
}
|
||||||
case Wbase_claim_type_.Tid__monolingualtext: {
|
case Wbase_claim_type_.Tid__monolingualtext: {
|
||||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
Json_nde sub_nde = Json_nde.Cast(ary.Get_at(3));
|
||||||
return new Wbase_claim_monolingualtext(pid, snak_tid, Get_val(sub_nde, 1), Get_val(sub_nde, 0));
|
return new Wbase_claim_monolingualtext(pid, snak_tid, Get_val(sub_nde, 1), Get_val(sub_nde, 0));
|
||||||
}
|
}
|
||||||
default: {throw Err_.new_unhandled(val_tid);}
|
default: {throw Err_.new_unhandled(val_tid);}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static byte[] Get_val(Json_nde sub_nde, int i) {
|
private static byte[] Get_val(Json_nde sub_nde, int i) {
|
||||||
Json_kv kv = Json_kv.cast(sub_nde.Get_at(i));
|
Json_kv kv = Json_kv.Cast(sub_nde.Get_at(i));
|
||||||
return kv.Val().Data_bry();
|
return kv.Val().Data_bry();
|
||||||
}
|
}
|
||||||
private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);}
|
private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);}
|
||||||
@ -227,11 +227,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
|||||||
.Add_bry_byte(Wdata_dict_claim_v1.Bry_rank , Prop_tid_rank)
|
.Add_bry_byte(Wdata_dict_claim_v1.Bry_rank , Prop_tid_rank)
|
||||||
.Add_bry_byte(Wdata_dict_claim_v1.Bry_refs , Prop_tid_refs);
|
.Add_bry_byte(Wdata_dict_claim_v1.Bry_refs , Prop_tid_refs);
|
||||||
Ordered_hash Bld_hash(Json_doc doc, byte[] key) {
|
Ordered_hash Bld_hash(Json_doc doc, byte[] key) {
|
||||||
Json_nde nde = Json_nde.cast(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry;
|
Json_nde nde = Json_nde.Cast(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int len = nde.Len();
|
int len = nde.Len();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Json_kv kv = Json_kv.cast(nde.Get_at(i));
|
Json_kv kv = Json_kv.Cast(nde.Get_at(i));
|
||||||
byte[] kv_key = kv.Key().Data_bry();
|
byte[] kv_key = kv.Key().Data_bry();
|
||||||
rv.Add(kv_key, kv);
|
rv.Add(kv_key, kv);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,9 +13,30 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
package gplx.xowa.xtns.wbases.parsers;
|
||||||
import gplx.langs.jsons.*; import gplx.core.btries.*;
|
|
||||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
import gplx.Bry_;
|
||||||
|
import gplx.Byte_;
|
||||||
|
import gplx.Err_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.Ordered_hash;
|
||||||
|
import gplx.Ordered_hash_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.jsons.Json_ary;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_itm;
|
||||||
|
import gplx.langs.jsons.Json_kv;
|
||||||
|
import gplx.langs.jsons.Json_nde;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp_list;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.Wbase_references_grp;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_base;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_alias_itm;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_langtext;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_dict_sitelink;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_langtext_itm;
|
||||||
|
import gplx.xowa.xtns.wbases.core.Wdata_sitelink_itm;
|
||||||
|
|
||||||
public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
||||||
private Wdata_claims_parser_v2 claims_parser = new Wdata_claims_parser_v2();
|
private Wdata_claims_parser_v2 claims_parser = new Wdata_claims_parser_v2();
|
||||||
public byte[] Parse_qid(Json_doc doc) {
|
public byte[] Parse_qid(Json_doc doc) {
|
||||||
@ -26,21 +47,21 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
|||||||
}
|
}
|
||||||
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
||||||
try {
|
try {
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv data_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
Json_nde data_nde = Json_nde.cast(data_kv.Val());
|
Json_nde data_nde = Json_nde.Cast(data_kv.Val());
|
||||||
int data_nde_len = data_nde.Len();
|
int data_nde_len = data_nde.Len();
|
||||||
Json_kv site_kv = null, name_kv = null; Json_ary badges_ary = null;
|
Json_kv site_kv = null, name_kv = null; Json_ary badges_ary = null;
|
||||||
for (int j = 0; j < data_nde_len; ++j) {
|
for (int j = 0; j < data_nde_len; ++j) {
|
||||||
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
|
Json_kv sub = Json_kv.Cast(data_nde.Get_at(j));
|
||||||
byte tid = Wdata_dict_sitelink.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_sitelink.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_sitelink.Tid__site: site_kv = Json_kv.cast(sub); break;
|
case Wdata_dict_sitelink.Tid__site: site_kv = Json_kv.Cast(sub); break;
|
||||||
case Wdata_dict_sitelink.Tid__title: name_kv = Json_kv.cast(sub); break;
|
case Wdata_dict_sitelink.Tid__title: name_kv = Json_kv.Cast(sub); break;
|
||||||
case Wdata_dict_sitelink.Tid__badges: badges_ary = Json_ary.cast_or_null(Json_kv.cast(sub).Val()); break;
|
case Wdata_dict_sitelink.Tid__badges: badges_ary = Json_ary.cast_or_null(Json_kv.Cast(sub).Val()); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] site_bry = site_kv.Val().Data_bry();
|
byte[] site_bry = site_kv.Val().Data_bry();
|
||||||
@ -53,20 +74,20 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
|||||||
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
||||||
try {
|
try {
|
||||||
byte[] langval_key = label_or_description ? Bry_labels : Bry_descriptions;
|
byte[] langval_key = label_or_description ? Bry_labels : Bry_descriptions;
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv data_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
Json_nde data_nde = Json_nde.cast(data_kv.Val());
|
Json_nde data_nde = Json_nde.Cast(data_kv.Val());
|
||||||
Json_kv text_kv = null;
|
Json_kv text_kv = null;
|
||||||
int data_nde_len = data_nde.Len();
|
int data_nde_len = data_nde.Len();
|
||||||
for (int j = 0; j < data_nde_len; ++j) {
|
for (int j = 0; j < data_nde_len; ++j) {
|
||||||
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
|
Json_kv sub = Json_kv.Cast(data_nde.Get_at(j));
|
||||||
byte tid = Wdata_dict_langtext.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_langtext.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_langtext.Tid__language: break;
|
case Wdata_dict_langtext.Tid__language: break;
|
||||||
case Wdata_dict_langtext.Tid__value: text_kv = Json_kv.cast(sub); break;
|
case Wdata_dict_langtext.Tid__value: text_kv = Json_kv.Cast(sub); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||||
@ -78,19 +99,19 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
|||||||
}
|
}
|
||||||
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
||||||
try {
|
try {
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||||
Ordered_hash rv = Ordered_hash_.New_bry();
|
Ordered_hash rv = Ordered_hash_.New_bry();
|
||||||
int list_len = list_nde.Len();
|
int list_len = list_nde.Len();
|
||||||
for (int i = 0; i < list_len; ++i) {
|
for (int i = 0; i < list_len; ++i) {
|
||||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv data_kv = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
Json_ary vals_ary = Json_ary.cast_or_null(data_kv.Val());
|
Json_ary vals_ary = Json_ary.cast_or_null(data_kv.Val());
|
||||||
int vals_len = vals_ary.Len();
|
int vals_len = vals_ary.Len();
|
||||||
byte[][] vals = new byte[vals_len][];
|
byte[][] vals = new byte[vals_len][];
|
||||||
for (int j = 0; j < vals_len; ++j) {
|
for (int j = 0; j < vals_len; ++j) {
|
||||||
Json_nde lang_nde = Json_nde.cast(vals_ary.Get_at(j));
|
Json_nde lang_nde = Json_nde.Cast(vals_ary.Get_at(j));
|
||||||
int k_len = lang_nde.Len();
|
int k_len = lang_nde.Len();
|
||||||
for (int k = 0; k < k_len; ++k) {
|
for (int k = 0; k < k_len; ++k) {
|
||||||
Json_kv sub = Json_kv.cast(lang_nde.Get_at(k));
|
Json_kv sub = Json_kv.Cast(lang_nde.Get_at(k));
|
||||||
byte tid = Wdata_dict_langtext.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
byte tid = Wdata_dict_langtext.Reg.Get_tid_or_max_and_log(qid, sub.Key().Data_bry()); if (tid == Byte_.Max_value_127) continue;
|
||||||
switch (tid) {
|
switch (tid) {
|
||||||
case Wdata_dict_langtext.Tid__language: break;
|
case Wdata_dict_langtext.Tid__language: break;
|
||||||
@ -108,12 +129,12 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
|||||||
public Ordered_hash Parse_claims(byte[] qid, Json_doc doc) {
|
public Ordered_hash Parse_claims(byte[] qid, Json_doc doc) {
|
||||||
synchronized (this) {// TS; DATE:2016-07-06
|
synchronized (this) {// TS; DATE:2016-07-06
|
||||||
try {
|
try {
|
||||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic;
|
Json_nde list_nde = Json_nde.Cast(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic;
|
||||||
List_adp temp_list = List_adp_.New();
|
List_adp temp_list = List_adp_.New();
|
||||||
byte[] src = doc.Src();
|
byte[] src = doc.Src();
|
||||||
int len = list_nde.Len();
|
int len = list_nde.Len();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Json_kv claim_nde = Json_kv.cast(list_nde.Get_at(i));
|
Json_kv claim_nde = Json_kv.Cast(list_nde.Get_at(i));
|
||||||
claims_parser.Make_claim_itms(qid, temp_list, src, claim_nde);
|
claims_parser.Make_claim_itms(qid, temp_list, src, claim_nde);
|
||||||
}
|
}
|
||||||
return Wdata_doc_parser_v1.Claims_list_to_hash(temp_list);
|
return Wdata_doc_parser_v1.Claims_list_to_hash(temp_list);
|
||||||
|
47
400_xowa/tst/gplx/langs/jsons/JsonDocBldrTest.java
Normal file
47
400_xowa/tst/gplx/langs/jsons/JsonDocBldrTest.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.langs.jsons;
|
||||||
|
|
||||||
|
import gplx.Bry_bfr;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JsonDocBldrTest {
|
||||||
|
private JsonDocBldrTestUtil util = new JsonDocBldrTestUtil();
|
||||||
|
@Test public void Basic() {
|
||||||
|
JsonDocBldr bldr = JsonDocBldr.NewRootNde();
|
||||||
|
bldr.NdeBgn("nde")
|
||||||
|
.KvBool("bool", true)
|
||||||
|
.KvInt("int", 123)
|
||||||
|
.KvStr("str", "abc")
|
||||||
|
.NdeEnd();
|
||||||
|
util.Test(bldr
|
||||||
|
, "{ 'nde':"
|
||||||
|
, " { 'bool':true"
|
||||||
|
, " , 'int':123"
|
||||||
|
, " , 'str':'abc'"
|
||||||
|
, " }"
|
||||||
|
, "}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class JsonDocBldrTestUtil {
|
||||||
|
public void Test(JsonDocBldr bldr, String... ary) {
|
||||||
|
Bry_bfr bfr = Bry_bfr_.New();
|
||||||
|
bldr.ToDoc().Root_grp().Print_as_json(bfr, 0);
|
||||||
|
Gftest.Eq__ary__lines(Json_doc.Make_str_by_apos(ary), bfr.To_str_and_clear());
|
||||||
|
}
|
||||||
|
}
|
71
400_xowa/tst/gplx/langs/mustaches/JsonMustacheNdeTest.java
Normal file
71
400_xowa/tst/gplx/langs/mustaches/JsonMustacheNdeTest.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.langs.mustaches;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Bry_bfr_;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import gplx.langs.jsons.Json_doc;
|
||||||
|
import gplx.langs.jsons.Json_parser;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JsonMustacheNdeTest {
|
||||||
|
private JsonMustacheNdeTestUtil util = new JsonMustacheNdeTestUtil();
|
||||||
|
|
||||||
|
@Test public void Str() {
|
||||||
|
util.TestWrite("[{{key}}]", "{'key':'abc'}", "[abc]");
|
||||||
|
}
|
||||||
|
@Test public void Bool() {
|
||||||
|
String mustache = "[{{#key}}y{{/key}}]";
|
||||||
|
util.TestWrite(mustache, "{'key':true}", "[y]");
|
||||||
|
util.TestWrite(mustache, "{'key':false}", "[]");
|
||||||
|
}
|
||||||
|
@Test public void Ary() {
|
||||||
|
String mustache = "[{{#group}}{{key}} {{/group}}]";
|
||||||
|
util.TestWrite(mustache, "{'group':[{'key':'a'}, {'key':'b'}, {'key':'c'}]}", "[a b c ]");
|
||||||
|
}
|
||||||
|
@Test public void SectionPropWithDot() {
|
||||||
|
String mustache = "[{{#key}}{{.}}{{/key}}]";
|
||||||
|
util.TestWrite(mustache, "{'key':'test'}", "[test]");
|
||||||
|
util.TestWrite(mustache, "{'key1':'test'}", "[]");
|
||||||
|
}
|
||||||
|
@Test public void SectionPropWithoutDot() {
|
||||||
|
String mustache = "[{{#prop}}{{propx}}{{/prop}}]";
|
||||||
|
util.TestWrite(mustache, "{'prop':'test'}", "[]");
|
||||||
|
util.TestWrite(mustache, "{'propx':'test'}", "[]");
|
||||||
|
}
|
||||||
|
@Test public void Dot() {// NOTE: online demo gives `([object Object])`; https://mustache.github.io/#demo
|
||||||
|
String mustache = "({{.}})";
|
||||||
|
util.TestWrite(mustache, "{'key':'test'}", "()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class JsonMustacheNdeTestUtil {
|
||||||
|
public void TestWrite(String mustache, String json, String expd) {
|
||||||
|
// parse JSON to mustache itm
|
||||||
|
Json_doc jdoc = Json_parser.ParseToJdoc(Json_doc.Make_str_by_apos(json));
|
||||||
|
JsonMustacheNde nde = new JsonMustacheNde(jdoc.Root_nde());
|
||||||
|
|
||||||
|
// parse template
|
||||||
|
Mustache_tkn_itm actl_itm = new Mustache_tkn_parser().Parse(Bry_.new_u8(mustache));
|
||||||
|
|
||||||
|
// render
|
||||||
|
Mustache_bfr bfr = new Mustache_bfr(Bry_bfr_.New());
|
||||||
|
actl_itm.Render(bfr, new Mustache_render_ctx().Init(nde));
|
||||||
|
|
||||||
|
// test
|
||||||
|
Gftest.Eq__ary__lines(expd, bfr.To_str_and_clear());
|
||||||
|
}
|
||||||
|
}
|
@ -140,10 +140,14 @@ app.wikis.get('~{wiki_key}') {
|
|||||||
app.wikis.get('~{wiki_key}').html.portal {
|
app.wikis.get('~{wiki_key}').html.portal {
|
||||||
div_personal =
|
div_personal =
|
||||||
<:["
|
<:["
|
||||||
<div id="p-personal" class="">
|
<nav id="p-personal" class="vector-menu" aria-labelledby="p-personal-label" role="navigation">
|
||||||
<h3>~{<>msgs.get('personaltools');<>}</h3>
|
<h3 id="p-personal-label">
|
||||||
|
<span>~{<>app.user.msgs.get('personaltools');<>}</span>
|
||||||
|
</h3>
|
||||||
|
<div class="body vector-menu-content">
|
||||||
~{portal_indicators_pagesource}
|
~{portal_indicators_pagesource}
|
||||||
</div>
|
</div>
|
||||||
|
</nav>
|
||||||
"]:>
|
"]:>
|
||||||
;
|
;
|
||||||
div_ns =
|
div_ns =
|
||||||
@ -195,8 +199,10 @@ app.wikis.get('~{wiki_key}').html.portal {
|
|||||||
;
|
;
|
||||||
div_home =
|
div_home =
|
||||||
<:["
|
<:["
|
||||||
<div class="portal" id='xowa-portal-home'>
|
<nav id="xowa-portal-home" class="vector-menu vector-menu-portal portal" aria-labelledby="xowa-portal-home" role="navigation">
|
||||||
<h3>XOWA</h3>
|
<h3>
|
||||||
|
<span>XOWA</span>
|
||||||
|
</h3>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/site/home/wiki/Main_Page" class='xowa-hover-off'>~{<>app.user.msgs.get('mainpage-description');<>}</a></li>
|
<li><a href="/site/home/wiki/Main_Page" class='xowa-hover-off'>~{<>app.user.msgs.get('mainpage-description');<>}</a></li>
|
||||||
@ -209,32 +215,36 @@ app.wikis.get('~{wiki_key}').html.portal {
|
|||||||
<li><a href="/site/home/wiki/Special:XowaCfg" class='xowa-hover-off'~{<>app.user.msgs.get_html_accesskey_and_title('xowa-portal-options');<>}>~{<>app.user.msgs.get('xowa-portal-options');<>}</a></li>
|
<li><a href="/site/home/wiki/Special:XowaCfg" class='xowa-hover-off'~{<>app.user.msgs.get_html_accesskey_and_title('xowa-portal-options');<>}>~{<>app.user.msgs.get('xowa-portal-options');<>}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
"]:>
|
"]:>
|
||||||
;
|
;
|
||||||
div_sync =
|
div_sync =
|
||||||
<:["
|
<:["
|
||||||
<div id="xowa-portal-sync" class="portal">
|
<nav id="xowa-portal-sync" class="vector-menu vector-menu-portal portal" aria-labelledby="xowa-portal-sync" role="navigation">
|
||||||
<h3>~{<>app.user.msgs.get('xowa-portal-sync');<>}</h3>
|
<h3>
|
||||||
|
<span>~{<>app.user.msgs.get('xowa-portal-sync');<>}</span>
|
||||||
|
</h3>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/wiki/Special:XowaSyncHtml?page=~{page_url}" class='xowa-hover-off'~{<>app.user.msgs.get_html_accesskey_and_title('xowa-portal-sync_html');<>}>~{<>app.user.msgs.get('xowa-portal-sync_html');<>}</a></li>
|
<li><a href="/wiki/Special:XowaSyncHtml?page=~{page_url}" class='xowa-hover-off'~{<>app.user.msgs.get_html_accesskey_and_title('xowa-portal-sync_html');<>}>~{<>app.user.msgs.get('xowa-portal-sync_html');<>}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
<!--
|
<!--
|
||||||
-->
|
-->
|
||||||
"]:>
|
"]:>
|
||||||
;
|
;
|
||||||
div_wikis =
|
div_wikis =
|
||||||
<:["
|
<:["
|
||||||
<div id="xowa-portal-wikis" class="portal">
|
<nav id="xowa-portal-wikis" class="vector-menu vector-menu-portal portal" aria-labelledby="xowa-portal-wikis" role="navigation">
|
||||||
<h3>~{toggle_btn}</h3>
|
<h3 id="p-wiki">
|
||||||
<div class="body">
|
<span>~{toggle_btn}</span>
|
||||||
|
</h3>
|
||||||
|
<div class="body vector-menu-content">
|
||||||
<ul~{toggle_hdr}>~{<>app.gui.html.portal.wikis.itms_as_html;<>}
|
<ul~{toggle_hdr}>~{<>app.gui.html.portal.wikis.itms_as_html;<>}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
"]:>
|
"]:>
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -472,9 +482,13 @@ app.wikis.scripts.set
|
|||||||
app.wikis.get('~{wiki_key}').html.portal
|
app.wikis.get('~{wiki_key}').html.portal
|
||||||
.div_personal_(
|
.div_personal_(
|
||||||
<:["
|
<:["
|
||||||
<div id="p-personal" class="">
|
<nav id="p-personal" class="vector-menu" aria-labelledby="p-personal-label" role="navigation">
|
||||||
<h3>~{<>app.user.msgs.get('personaltools');<>}</h3>
|
<h3 id="p-personal-label">
|
||||||
|
<span>~{<>app.user.msgs.get('personaltools');<>}</span>
|
||||||
|
</h3>
|
||||||
|
<div class="body vector-menu-content">
|
||||||
</div>
|
</div>
|
||||||
|
</nav>
|
||||||
"]:>
|
"]:>
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -104,6 +104,18 @@ if (!window.xowa) {
|
|||||||
},
|
},
|
||||||
remove: function () {},
|
remove: function () {},
|
||||||
fire: function () {}
|
fire: function () {}
|
||||||
|
} : name === 'wikipage.collapsibleContent' ? {
|
||||||
|
add: function (f) {
|
||||||
|
//fc = f;
|
||||||
|
f(mw.collapsibleContent);
|
||||||
|
// f(window.jQuery ? $collapsible.find( '> .mw-collapsible-content' ) : null);
|
||||||
|
},
|
||||||
|
remove: function () {},
|
||||||
|
fire: function (t) {
|
||||||
|
// different order!!!! wrong order HACK
|
||||||
|
mw.collapsibleContent = t;
|
||||||
|
//fc(t);
|
||||||
|
}
|
||||||
} : {
|
} : {
|
||||||
add: function () {},
|
add: function () {},
|
||||||
remove: function () {},
|
remove: function () {},
|
||||||
|
22
res/bin/any/xowa/xtns/Skin-Vector/templates/Menu.mustache
Normal file
22
res/bin/any/xowa/xtns/Skin-Vector/templates/Menu.mustache
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{{!
|
||||||
|
See @typedef MenuDefinition
|
||||||
|
}}
|
||||||
|
{{! `role` is unnecessary but kept to support selectors in any gadgets or user styles. }}
|
||||||
|
<!-- Please do not use role attribute as CSS selector, it is deprecated. -->
|
||||||
|
<nav id="{{id}}" {{#class}}class="{{.}}"{{/class}} aria-labelledby="{{label-id}}" role="navigation" {{{html-tooltip}}}
|
||||||
|
{{{html-user-language-attributes}}}>
|
||||||
|
{{#is-dropdown}}
|
||||||
|
<input type="checkbox" class="vector-menu-checkbox vectorMenuCheckbox" aria-labelledby="{{label-id}}" />
|
||||||
|
{{/is-dropdown}}
|
||||||
|
<h3 id="{{label-id}}">
|
||||||
|
<span>{{label}}</span>
|
||||||
|
</h3>
|
||||||
|
{{! `body` class for backwards compatibility but let editors know not to use
|
||||||
|
it via HTML comment below: }}
|
||||||
|
<!-- Please do not use the .body class, it is deprecated. -->
|
||||||
|
<div class="body vector-menu-content">
|
||||||
|
<!-- Please do not use the .menu class, it is deprecated. -->
|
||||||
|
<ul class="{{list-classes}}">{{{html-items}}}</ul>
|
||||||
|
{{{html-after-portal}}}
|
||||||
|
</div>
|
||||||
|
</nav>
|
@ -0,0 +1,16 @@
|
|||||||
|
<div id="mw-navigation">
|
||||||
|
<h2>{{msg-navigation-heading}}</h2>
|
||||||
|
<div id="mw-head">
|
||||||
|
{{#data-personal-menu}}{{>Menu}}{{/data-personal-menu}}
|
||||||
|
<div id="left-navigation">
|
||||||
|
{{#data-namespace-tabs}}{{>Menu}}{{/data-namespace-tabs}}
|
||||||
|
{{#data-variants}}{{>Menu}}{{/data-variants}}
|
||||||
|
</div>
|
||||||
|
<div id="right-navigation">
|
||||||
|
{{#data-page-actions}}{{>Menu}}{{/data-page-actions}}
|
||||||
|
{{#data-page-actions-more}}{{>Menu}}{{/data-page-actions-more}}
|
||||||
|
{{#data-search-box}}{{>SearchBox}}{{/data-search-box}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{#data-sidebar}}{{>legacy/Sidebar}}{{/data-sidebar}}
|
||||||
|
</div>
|
@ -0,0 +1,13 @@
|
|||||||
|
{{!
|
||||||
|
See @typedef SidebarData
|
||||||
|
string html-logo-attributes for site logo. Must be used inside tag e.g. `class="logo" lang="en-gb"`
|
||||||
|
}}
|
||||||
|
|
||||||
|
<div id="mw-panel">
|
||||||
|
<div id="p-logo" role="banner">
|
||||||
|
<a {{{html-logo-attributes}}}></a>
|
||||||
|
</div>
|
||||||
|
{{#data-portals-first}}{{>Menu}}{{/data-portals-first}}
|
||||||
|
{{#array-portals-rest}}{{>Menu}}{{/array-portals-rest}}
|
||||||
|
{{#data-portals-languages}}{{>Menu}}{{/data-portals-languages}}
|
||||||
|
</div>
|
@ -0,0 +1,69 @@
|
|||||||
|
{{!
|
||||||
|
string|null html-site-notice the contents of a banner defined in MediaWiki:Sitenotice.
|
||||||
|
Also used by CentralNotice to inject banners into Vector.
|
||||||
|
Indicator[] array-indicators wiki-defined badges such as "good article",
|
||||||
|
"featured article". An empty array if none are defined.
|
||||||
|
string page-langcode the content language of the article. Assumed to be escaped HTML.
|
||||||
|
string html-title
|
||||||
|
bool page-isarticle
|
||||||
|
string msg-tagline
|
||||||
|
string html-subtitle
|
||||||
|
string html-undelete-link
|
||||||
|
string html-newtalk
|
||||||
|
string msg-vector-jumptonavigation
|
||||||
|
string msg-vector-jumptosearch
|
||||||
|
string html-body-content
|
||||||
|
string html-categories
|
||||||
|
string html-after-content
|
||||||
|
string msg-navigation-heading heading for entire navigation that is
|
||||||
|
usually hidden to screen readers
|
||||||
|
MenuDefinition data-personal-menu
|
||||||
|
MenuDefinition data-namespace-tabs
|
||||||
|
MenuDefinition data-variants
|
||||||
|
MenuDefinition data-page-actions
|
||||||
|
MenuDefinition data-page-actions-more
|
||||||
|
object data-search-box. See SearchBox.mustache for documentation.
|
||||||
|
object data-sidebar. See Sidebar.mustache for documentation.
|
||||||
|
object data-footer for footer template partial. see Footer.mustache for documentation.
|
||||||
|
}}
|
||||||
|
<div id="mw-page-base" class="noprint"></div>
|
||||||
|
<div id="mw-head-base" class="noprint"></div>
|
||||||
|
<div id="content" class="mw-body" role="main">
|
||||||
|
<a id="top"></a>
|
||||||
|
<div id="siteNotice" class="mw-body-content">{{{html-site-notice}}}</div>
|
||||||
|
{{>Indicators}}
|
||||||
|
<h1 id="firstHeading" class="firstHeading" lang="{{page-langcode}}">{{{html-title}}}</h1>
|
||||||
|
<div id="bodyContent" class="mw-body-content">
|
||||||
|
{{#page-isarticle}}<div id="siteSub" class="noprint">{{msg-tagline}}</div>{{/page-isarticle}}
|
||||||
|
<div id="contentSub"{{{html-user-language-attributes}}}>{{{html-subtitle}}}</div>
|
||||||
|
<div id="contentSub2">{{{html-undelete-link}}}</div>
|
||||||
|
{{{html-newtalk}}}
|
||||||
|
{{!
|
||||||
|
Keep this empty `div` for compatibility with gadgets and user scripts
|
||||||
|
using this place to insert extra elements before.
|
||||||
|
}}
|
||||||
|
<div id="jump-to-nav"></div>
|
||||||
|
<a class="mw-jump-link" href="#mw-head">{{msg-vector-jumptonavigation}}</a>
|
||||||
|
<a class="mw-jump-link" href="#searchInput">{{msg-vector-jumptosearch}}</a>
|
||||||
|
{{{html-body-content}}}
|
||||||
|
{{{html-categories}}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{{html-after-content}}}
|
||||||
|
<div id="mw-navigation">
|
||||||
|
<h2>{{msg-navigation-heading}}</h2>
|
||||||
|
<div id="mw-head">
|
||||||
|
{{#data-personal-menu}}{{>Menu}}{{/data-personal-menu}}
|
||||||
|
<div id="left-navigation">
|
||||||
|
{{#data-namespace-tabs}}{{>Menu}}{{/data-namespace-tabs}}
|
||||||
|
{{#data-variants}}{{>Menu}}{{/data-variants}}
|
||||||
|
</div>
|
||||||
|
<div id="right-navigation">
|
||||||
|
{{#data-page-actions}}{{>Menu}}{{/data-page-actions}}
|
||||||
|
{{#data-page-actions-more}}{{>Menu}}{{/data-page-actions-more}}
|
||||||
|
{{#data-search-box}}{{>SearchBox}}{{/data-search-box}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{#data-sidebar}}{{>legacy/Sidebar}}{{/data-sidebar}}
|
||||||
|
</div>
|
||||||
|
{{#data-footer}}{{>Footer}}{{/data-footer}}
|
@ -1,7 +1,7 @@
|
|||||||
<div class="ext-wpb-pagebanner pre-content">
|
<div class="ext-wpb-pagebanner">
|
||||||
<div class="{{#isPanorama}}wpb-banner-image-panorama {{/isPanorama}}wpb-topbanner{{extraClass}}">
|
<div class="{{#isPanorama}}wpb-banner-image-panorama {{/isPanorama}}wpb-topbanner{{extraClass}}">
|
||||||
{{#isHeadingOverrideEnabled}}<h1 class="wpb-name">{{title}}</h1>{{/isHeadingOverrideEnabled}}
|
{{#isHeadingOverrideEnabled}}<h1 class="wpb-name">{{title}}</h1>{{/isHeadingOverrideEnabled}}
|
||||||
<a class="image" dir="ltr" title="{{tooltip}}" href="{{bannerfile}}" xowa_title="{{file_ttl}}"><img{{{img_id_atr}}}{{{img_xottl}}}{{{img_xoimg}}} src="{{banner}}" srcset="{{srcset}}" class="wpb-banner-image"{{#hasPosition}} data-pos-x="{{data-pos-x}}" data-pos-y="{{data-pos-y}}" {{/hasPosition}} style="max-width:{{maxWidth}}px"></a>
|
<a class="image" dir="ltr" title="{{tooltip}}" href="{{bannerfile}}" xowa_title="{{file_ttl}}"><img{{{img_id_atr}}}{{{img_xottl}}}{{{img_xoimg}}} src="{{banner}}" srcset="{{srcset}}" class="wpb-banner-image"{{#hasPosition}} data-pos-x="{{data-pos-x}}" data-pos-y="{{data-pos-y}}"{{/hasPosition}}></a>
|
||||||
{{#hasIcons}}
|
{{#hasIcons}}
|
||||||
<div class="wpb-iconbox">
|
<div class="wpb-iconbox">
|
||||||
{{#icons}}
|
{{#icons}}
|
||||||
|
Loading…
Reference in New Issue
Block a user