diff --git a/100_core/src_110_primitive/gplx/Bry_.java b/100_core/src_110_primitive/gplx/Bry_.java index b5613c161..19726494a 100644 --- a/100_core/src_110_primitive/gplx/Bry_.java +++ b/100_core/src_110_primitive/gplx/Bry_.java @@ -955,6 +955,15 @@ public class Bry_ { } return ary; } + public static byte[] Lower_1st(byte[] ary) { + if (ary == null) return null; + int len = ary.length; + if (len == 0) return ary; + byte b = ary[0]; + if (b > 64 && b < 91) + ary[0] = (byte)(b + 32); + return ary; + } public static byte[] Lower_ascii(byte[] ary) { int len = ary.length; for (int i = 0; i < len; i++) { diff --git a/100_core/src_110_primitive/gplx/Bry_bfr_mkr.java b/100_core/src_110_primitive/gplx/Bry_bfr_mkr.java index b625ebea2..dced6ae7f 100644 --- a/100_core/src_110_primitive/gplx/Bry_bfr_mkr.java +++ b/100_core/src_110_primitive/gplx/Bry_bfr_mkr.java @@ -50,11 +50,19 @@ public class Bry_bfr_mkr { } } class Bry_bfr_mkr_mgr { - public Bry_bfr_mkr_mgr(byte mgr_id, int reset) {this.mgr_id = mgr_id; this.reset = reset;} private int reset; + private final Object thread_lock; + public Bry_bfr_mkr_mgr(byte mgr_id, int reset) {// NOTE: random IndexOutOfBounds errors in Get around free[--free_len] with free_len being -1; put member variable initialization within thread_lock to try to avoid; DATE:2014-09-21 + thread_lock = new Object(); + synchronized (thread_lock) { + this.mgr_id = mgr_id; + this.reset = reset; + this.free = Int_.Ary_empty; + this.free_len = 0; + } + } private int reset; public byte Mgr_id() {return mgr_id;} private byte mgr_id; private Bry_bfr[] ary = Ary_empty; private int nxt_idx = 0, ary_max = 0; - private int[] free = Int_.Ary_empty; private int free_len = 0; - private Object thread_lock = new Object(); + private int[] free; private int free_len; public void Reset_if_gt(int v) { this.Clear(); // TODO: for now, just call clear } @@ -94,13 +102,14 @@ class Bry_bfr_mkr_mgr { Bry_bfr rv = null; int rv_idx = -1; if (free_len > 0) { - rv_idx = free[--free_len]; - rv = ary[rv_idx]; + try {rv_idx = free[--free_len];} + catch (Exception e) {throw Err_.new_("failed to get free index; free_len={0} free.length={1} err={2}", free_len, free.length, Err_.Message_lang(e));} + try {rv = ary[rv_idx];} + catch (Exception e) {throw Err_.new_("failed to get bfr; rv_idx={0} ary.length={1} err={2}", rv_idx, ary.length, Err_.Message_lang(e));} } else { - if (nxt_idx == ary_max) { + if (nxt_idx == ary_max) Expand(); - } rv_idx = nxt_idx++; rv = ary[rv_idx]; if (rv == null) { diff --git a/100_core/src_110_primitive/gplx/Int_.java b/100_core/src_110_primitive/gplx/Int_.java index 7338275c8..7baefb954 100644 --- a/100_core/src_110_primitive/gplx/Int_.java +++ b/100_core/src_110_primitive/gplx/Int_.java @@ -254,4 +254,5 @@ public class Int_ implements GfoInvkAble { rv[i] = Int_.parse_(ary[i]); return rv; } + public static byte[] Xto_bry(int v) {return Bry_.new_ascii_(Xto_str(v));} } diff --git a/100_core/src_140_list/gplx/Hash_adp_bry.java b/100_core/src_140_list/gplx/Hash_adp_bry.java index 14886c2b5..7a7cde669 100644 --- a/100_core/src_140_list/gplx/Hash_adp_bry.java +++ b/100_core/src_140_list/gplx/Hash_adp_bry.java @@ -28,10 +28,10 @@ public class Hash_adp_bry extends gplx.lists.HashAdp_base implements HashAdp { @Override protected boolean Has_base(Object key) {return super.Has_base(key_ref.Init((byte[])key));} public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));} public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));} + public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;} public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;} public Hash_adp_bry Add_str_byte(String key, byte val) {this.Add_base(Bry_.new_utf8_(key), Byte_obj_val.new_(val)); return this;} public Hash_adp_bry Add_str_obj(String key, Object val) {this.Add_base(Bry_.new_utf8_(key), val); return this;} - public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;} public Hash_adp_bry Add_bry_obj(byte[] key, Object val) {this.Add_base(key, val); return this;} public Hash_adp_bry Add_many_str(String... ary) { int ary_len = ary.length; diff --git a/140_dbs/src_100_core/gplx/dbs/Db_provider.java b/140_dbs/src_100_core/gplx/dbs/Db_provider.java index 98ec57992..199725f65 100644 --- a/140_dbs/src_100_core/gplx/dbs/Db_provider.java +++ b/140_dbs/src_100_core/gplx/dbs/Db_provider.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.dbs; import gplx.*; public class Db_provider { - @gplx.Internal protected Db_provider(Db_engine engine) { + public Db_provider(Db_engine engine) { this.engine = engine; this.txn_mgr = new Db_txn_mgr_base(engine); } diff --git a/140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java b/140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java index 358bbcfea..cdf9a5d9f 100644 --- a/140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java +++ b/140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java @@ -25,13 +25,13 @@ class Db_rdr__basic implements Db_rdr { try {return rdr.next();} catch (Exception e) {throw Err_.new_fmt_("move_next failed; check column casting error in SQL: err={0} sql={1}", Err_.Message_lang(e), sql);} } - public byte[] Read_bry(int i) {try {return rdr.getBytes(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bry_.Cls_name, Err_.Message_lang(e));}} - public byte[] Read_bry_by_str(int i) {try {return Bry_.new_utf8_(rdr.getString(i));} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}} - public String Read_str(int i) {try {return rdr.getString(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}} - public int Read_int(int i) {try {return rdr.getInt(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Int_.Cls_name, Err_.Message_lang(e));}} - public long Read_long(int i) {try {return rdr.getLong(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Long_.Cls_name, Err_.Message_lang(e));}} - public float Read_float(int i) {try {return rdr.getFloat(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Float_.Cls_name, Err_.Message_lang(e));}} - public double Read_double(int i) {try {return rdr.getDouble(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Double_.Cls_name, Err_.Message_lang(e));}} - public byte Read_byte(int i) {try {return rdr.getByte(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_name, Err_.Message_lang(e));}} + public byte[] Read_bry(int i) {try {return rdr.getBytes(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bry_.Cls_name, Err_.Message_lang(e));}} + public byte[] Read_bry_by_str(int i) {try {return Bry_.new_utf8_(rdr.getString(i + 1));} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}} + public String Read_str(int i) {try {return rdr.getString(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}} + public int Read_int(int i) {try {return rdr.getInt(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Int_.Cls_name, Err_.Message_lang(e));}} + public long Read_long(int i) {try {return rdr.getLong(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Long_.Cls_name, Err_.Message_lang(e));}} + public float Read_float(int i) {try {return rdr.getFloat(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Float_.Cls_name, Err_.Message_lang(e));}} + public double Read_double(int i) {try {return rdr.getDouble(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Double_.Cls_name, Err_.Message_lang(e));}} + public byte Read_byte(int i) {try {return rdr.getByte(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_name, Err_.Message_lang(e));}} public void Close() {try {rdr.close();} catch (Exception e) {throw Err_.new_("close failed: err={0}", Err_.Message_lang(e));}} } diff --git a/140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java b/140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java index f940a19a6..8f7f76c53 100644 --- a/140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java +++ b/140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java @@ -35,7 +35,7 @@ public class Db_qry__select_in_tbl implements Db_qry { } public String Group_by_sql() {return group_by_sql;} private final String group_by_sql; public String Having_sql() {return having_sql;} private final String having_sql; - public String Order_by_sql() {return order_by_sql;} private final String order_by_sql; + public String Order_by_sql() {return order_by_sql;} public Db_qry__select_in_tbl Order_by_sql_(String v) {order_by_sql = v; return this;} private String order_by_sql; public String Limit_sql() {return limit_sql;} private final String limit_sql; public static Db_qry__select_in_tbl new_(String tbl_name, String[] where_flds, String[] select_flds) {return new Db_qry__select_in_tbl(tbl_name, select_flds, where_flds, null, null, null, null);} public String KeyOfDb_qry() {return "select_in_tbl";} @@ -49,12 +49,13 @@ public class Db_qry__select_in_tbl implements Db_qry { if (i != 0) sb.Add(","); sb.Add(select_flds[i]); } - sb.Add(" FROM ").Add(tbl_name).Add(" "); - if (where_flds != null) {sb.Add("WHERE "); Where_sql(sb);} + sb.Add(" FROM ").Add(tbl_name); + if (where_flds != null) {sb.Add(" WHERE "); Where_sql(sb);} if (group_by_sql != null) sb.Add(group_by_sql); if (having_sql != null) sb.Add(having_sql); - if (order_by_sql != null) sb.Add(order_by_sql); + if (order_by_sql != null) {sb.Add(" ORDER BY "); sb.Add(order_by_sql);} if (limit_sql != null) sb.Add(limit_sql); return sb.XtoStr(); } + public static final String[] Where_flds__all = null; } diff --git a/140_dbs/src_200_engine/gplx/dbs/Db_engine.java b/140_dbs/src_200_engine/gplx/dbs/Db_engine.java index bce385553..c9217c9e9 100644 --- a/140_dbs/src_200_engine/gplx/dbs/Db_engine.java +++ b/140_dbs/src_200_engine/gplx/dbs/Db_engine.java @@ -18,6 +18,7 @@ along with this program. If not, see . package gplx.dbs; import gplx.*; public interface Db_engine { String Key(); + String Conn_info_tid(); Db_conn_info Conn_info(); void Conn_open(); void Conn_term(); @@ -33,6 +34,7 @@ public interface Db_engine { } class Db_engine_null implements Db_engine { public String Key() {return Db_conn_info_.Null.Key();} + public String Conn_info_tid() {return Db_conn_info_.Null.Key();} public Db_conn_info Conn_info() {return Db_conn_info_.Null;} public void Conn_open() {} public void Conn_term() {} diff --git a/140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java b/140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java index 56981b18c..a15b577ff 100644 --- a/140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java +++ b/140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java @@ -18,7 +18,8 @@ along with this program. If not, see . package gplx.dbs; import gplx.*; public class Db_engine_regy { private final HashAdp hash = HashAdp_.new_(); - Db_engine_regy() { + public Db_engine_regy() {} + Db_engine_regy(int dflt) { this.Add(Db_engine_null._) .Add(TdbEngine._) .Add(Mysql_engine._) @@ -28,5 +29,5 @@ public class Db_engine_regy { } public Db_engine_regy Add(Db_engine engine) {hash.Add(engine.Key(), engine); return this;} public Db_engine Get(String key) {return (Db_engine)hash.FetchOrFail(key);} - public static final Db_engine_regy _ = new Db_engine_regy(); + public static final Db_engine_regy _ = new Db_engine_regy(1); } diff --git a/140_dbs/src_200_engine/gplx/dbs/Db_engine_sql_base.java b/140_dbs/src_200_engine/gplx/dbs/Db_engine_sql_base.java index adeecb1f4..e14b1dcaa 100644 --- a/140_dbs/src_200_engine/gplx/dbs/Db_engine_sql_base.java +++ b/140_dbs/src_200_engine/gplx/dbs/Db_engine_sql_base.java @@ -19,6 +19,7 @@ package gplx.dbs; import gplx.*; import java.sql.*; abstract class Db_engine_sql_base implements Db_engine { public abstract String Key(); + public abstract String Conn_info_tid(); public Db_conn_info Conn_info() {return conn_info;} protected Db_conn_info conn_info; @gplx.Virtual public void Txn_bgn() {Execute(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));} @gplx.Virtual public void Txn_end() {Execute(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));} diff --git a/140_dbs/src_300_sqlDbs/gplx/dbs/Mysql_engine.java b/140_dbs/src_300_sqlDbs/gplx/dbs/Mysql_engine.java index 0818be62e..499dfe597 100644 --- a/140_dbs/src_300_sqlDbs/gplx/dbs/Mysql_engine.java +++ b/140_dbs/src_300_sqlDbs/gplx/dbs/Mysql_engine.java @@ -20,6 +20,7 @@ import gplx.stores.*; import java.sql.*; class Mysql_engine extends Db_engine_sql_base { @Override public String Key() {return Db_conn_info__mysql.Key_const;} + @Override public String Conn_info_tid() {return this.Key();} @Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;} @Override public Db_engine Make_new(Db_conn_info connectInfo) { Mysql_engine rv = new Mysql_engine(); diff --git a/140_dbs/src_300_sqlDbs/gplx/dbs/Postgres_engine.java b/140_dbs/src_300_sqlDbs/gplx/dbs/Postgres_engine.java index b038c8822..ffcf1cd0e 100644 --- a/140_dbs/src_300_sqlDbs/gplx/dbs/Postgres_engine.java +++ b/140_dbs/src_300_sqlDbs/gplx/dbs/Postgres_engine.java @@ -20,6 +20,7 @@ import gplx.stores.*; import java.sql.*; class Postgres_engine extends Db_engine_sql_base { @Override public String Key() {return Db_conn_info__postgres.Key_const;} + @Override public String Conn_info_tid() {return this.Key();} @Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;} @Override public Db_engine Make_new(Db_conn_info connectInfo) { Postgres_engine rv = new Postgres_engine(); diff --git a/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine.java b/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine.java index da41c1c9f..5eb292489 100644 --- a/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine.java +++ b/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine.java @@ -20,6 +20,7 @@ import gplx.stores.*; import java.sql.*; class Sqlite_engine extends Db_engine_sql_base { @Override public String Key() {return Db_conn_info__sqlite.Key_const;} + @Override public String Conn_info_tid() {return this.Key();} @Override public Db_engine Make_new(Db_conn_info connectInfo) { Sqlite_engine rv = new Sqlite_engine(); rv.ctor_SqlEngineBase(connectInfo); diff --git a/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine_.java b/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine_.java index 9e9136bb4..cdf0a32a8 100644 --- a/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine_.java +++ b/140_dbs/src_300_sqlDbs/gplx/dbs/Sqlite_engine_.java @@ -81,6 +81,7 @@ public class Sqlite_engine_ { Pragma_page_size(p, 4096); return p; } + public static Db_engine New_engine() {return Sqlite_engine._;} public static final int Stmt_arg_max = 999; // 999 is max number of variables allowed by sqlite public static final boolean Supports_read_binary_stream = false; public static final boolean Supports_indexed_by = true; diff --git a/140_dbs/src_400_tdbs/gplx/dbs/TdbEngine.java b/140_dbs/src_400_tdbs/gplx/dbs/TdbEngine.java index 3d6142bb2..c07387565 100644 --- a/140_dbs/src_400_tdbs/gplx/dbs/TdbEngine.java +++ b/140_dbs/src_400_tdbs/gplx/dbs/TdbEngine.java @@ -18,6 +18,7 @@ along with this program. If not, see . package gplx.dbs; import gplx.*; class TdbEngine implements Db_engine { public String Key() {return KeyDef;} public static final String KeyDef = "tdb"; + public String Conn_info_tid() {return this.Key();} public Db_conn_info Conn_info() {return conn_info;} Db_conn_info conn_info; public TdbDatabase Db() {return db;} TdbDatabase db; public void Conn_open() { diff --git a/400_xowa/src/gplx/core/btries/Btrie_slim_mgr.java b/400_xowa/src/gplx/core/btries/Btrie_slim_mgr.java index eaf6d95a3..254963317 100644 --- a/400_xowa/src/gplx/core/btries/Btrie_slim_mgr.java +++ b/400_xowa/src/gplx/core/btries/Btrie_slim_mgr.java @@ -39,6 +39,7 @@ public class Btrie_slim_mgr implements Btrie_mgr { cur = nxt; } } + public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));} public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(key), Byte_obj_val.new_(val));} public Btrie_slim_mgr Add_bry(String key, String val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(key), Bry_.new_utf8_(val));} public Btrie_slim_mgr Add_bry(String key, byte[] val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(key), val);} diff --git a/400_xowa/src/gplx/json/Json_doc.java b/400_xowa/src/gplx/json/Json_doc.java index 16834bfd1..f5e18d4be 100644 --- a/400_xowa/src/gplx/json/Json_doc.java +++ b/400_xowa/src/gplx/json/Json_doc.java @@ -37,7 +37,7 @@ public class Json_doc { tmp_qry_bry[0] = qry_bry; Json_itm rv = Find_nde(root, tmp_qry_bry, 0, 0); if (rv == null) return null; return (Json_grp)rv; - } byte[][] tmp_qry_bry = new byte[1][]; + } private byte[][] tmp_qry_bry = new byte[1][]; public Json_grp Get_grp(byte[][] qry_bry) { Json_itm rv = Find_nde(root, qry_bry, qry_bry.length - 1, 0); if (rv == null) return null; return (Json_grp)rv; diff --git a/400_xowa/src/gplx/json/Json_itm_ary.java b/400_xowa/src/gplx/json/Json_itm_ary.java index b5b3c57dc..8e6873bb9 100644 --- a/400_xowa/src/gplx/json/Json_itm_ary.java +++ b/400_xowa/src/gplx/json/Json_itm_ary.java @@ -59,6 +59,13 @@ public class Json_itm_ary extends Json_itm_base implements Json_grp { Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth); bfr.Add_byte(Byte_ascii.Brack_end).Add_byte_nl(); } - Json_itm[] subs = Json_itm_.Ary_empty; + public byte[][] Xto_bry_ary() { + if (subs_len == 0) return Bry_.Ary_empty; + byte[][] rv = new byte[subs_len][]; + for (int i = 0; i < subs_len; ++i) + rv[i] = subs[i].Data_bry(); + return rv; + } + private Json_itm[] subs = Json_itm_.Ary_empty; public static Json_itm_ary cast_(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid_array ? null : (Json_itm_ary)v;} } diff --git a/400_xowa/src/gplx/xowa/Xoa_app_.java b/400_xowa/src/gplx/xowa/Xoa_app_.java index 7381058b2..bda98ebd6 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app_.java +++ b/400_xowa/src/gplx/xowa/Xoa_app_.java @@ -17,13 +17,14 @@ along with this program. If not, see . */ package gplx.xowa; import gplx.*; import gplx.gfui.*; import gplx.xowa.users.*; +import gplx.xowa.hdumps.*; import gplx.xowa.hdumps.core.*; public class Xoa_app_ { public static void Run(String... args) { Xoa_app_boot_mgr boot_mgr = new Xoa_app_boot_mgr(); boot_mgr.Run(args); } public static final String Name = "xowa"; - public static final String Version = "1.9.3.1"; + public static final String Version = "1.9.4.1"; public static String Build_date = "2012-12-30 00:00:00"; public static String Op_sys; public static String User_agent = ""; @@ -35,6 +36,18 @@ public class Xoa_app_ { rv.Log_wtr().Queue_enabled_(true); return rv; } + public static void Run_viewer() { + Io_url root_dir = Io_url_.new_dir_("J:\\gplx\\xowa\\"); + Xoav_app app = new Xoav_app(Gfo_usr_dlg_._, root_dir, "drd"); + app.Wiki_mgr().Load_default(); + + Xowv_wiki wiki = app.Wiki_mgr().Get_by_domain(Bry_.new_ascii_("simple.wikibooks.org")); + Hdump_page hpg = new Hdump_page(); + wiki.Hdump_mgr().Load(hpg, Bry_.new_utf8_("Main_Page")); + String html = String_.new_utf8_(hpg.Page_body()); + ConsoleAdp._.WriteLine(html); + ConsoleAdp._.ReadLine(""); + } public static final byte Mode_console = 0, Mode_gui = 1, Mode_http = 2; } class Xoa_app_boot_mgr { @@ -87,6 +100,7 @@ class Xoa_app_boot_mgr { , App_cmd_arg.opt_("server_port_recv").Example_("55000").Note_("applies to --app_mode server; port where xowa server will receive messages; clients should send messages to this port") , App_cmd_arg.opt_("server_port_send").Example_("55001").Note_("applies to --app_mode server; port where xowa server will send messages; clients should listen for messages from this port") , App_cmd_arg.opt_("http_server_port").Example_("8080").Note_("applies to --app_mode http_server; port used by http_server; default is 8080") + , App_cmd_arg.opt_("http_server_home").Example_("home/wiki/Main_Page").Note_("applies to --app_mode http_server; default home page for root address. EX: navigating to localhost:8080 will navigate to localhost:8080/home/wiki/Main_Page") , App_cmd_arg.sys_header_("show_license").Dflt_(true) , App_cmd_arg.sys_args_("show_args").Dflt_(true) , App_cmd_arg.sys_help_() @@ -124,6 +138,7 @@ class Xoa_app_boot_mgr { int server_port_recv = args_mgr.Args_get("server_port_recv").Val_as_int_or(55000); int server_port_send = args_mgr.Args_get("server_port_send").Val_as_int_or(55001); int http_server_port = args_mgr.Args_get("http_server_port").Val_as_int_or(8080); + String http_server_home = args_mgr.Args_get("http_server_home").Val_as_str_or("home/wiki/Main_Page"); Xoa_app_.Op_sys = args_mgr.Args_get("bin_dir_name").Val_as_str_or(Bin_dir_name()); Xoa_app_.User_agent = String_.Format("XOWA/{0} ({1}) [gnosygnu@gmail.com]", Xoa_app_.Version, Xoa_app_.Op_sys); String cmd_text = args_mgr.Args_get("cmd_text").Val_as_str_or(null); @@ -138,6 +153,7 @@ class Xoa_app_boot_mgr { app.Api_root().App().Startup().Tabs().Manual_(launch_url); app.Tcp_server().Rdr_port_(server_port_recv).Wtr_port_(server_port_send); app.Http_server().Port_(http_server_port); + app.Http_server().Home_(http_server_home); app.Init(); chkpoint = "init_gfs"; } catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0} ~{1}", chkpoint, Err_.Message_gplx(e));} diff --git a/400_xowa/src/gplx/xowa/Xoa_app_fxt.java b/400_xowa/src/gplx/xowa/Xoa_app_fxt.java index 03b6e880b..a10be37df 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app_fxt.java +++ b/400_xowa/src/gplx/xowa/Xoa_app_fxt.java @@ -45,7 +45,7 @@ public class Xoa_app_fxt { } public static void Init_gui(Xoa_app app) { app.Gui_mgr().Browser_win().Init_by_kit(gplx.gfui.Mem_kit._); - app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(); + app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(Xoa_page.Empty); } public static Xob_bldr bldr_(Xoa_app app) { Xob_bldr rv = new Xob_bldr(app); diff --git a/400_xowa/src/gplx/xowa/Xoa_test_.java b/400_xowa/src/gplx/xowa/Xoa_test_.java index 7c7876ceb..16787313d 100644 --- a/400_xowa/src/gplx/xowa/Xoa_test_.java +++ b/400_xowa/src/gplx/xowa/Xoa_test_.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.xowa; import gplx.*; public class Xoa_test_ { - public static boolean Db_skip() {return false;} + public static boolean Db_skip() {return Bool_.N;} public static boolean Fsdb_is_mem = false; public static Io_url Url_root() {return Io_url_.Usr().GenSubDir_nest("xowa", "dev", "tst", "400_xowa");} public static Io_url Url_wiki_enwiki() {return Url_root().GenSubDir_nest("root", "wiki", "en.wikipedia.org");} diff --git a/400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java b/400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java index 5f7ab619c..e8f1767e5 100644 --- a/400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java +++ b/400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java @@ -22,9 +22,12 @@ public class Xoapi_wiki implements GfoInvkAble { public void Init_by_kit(Xoa_app app) { win = app.Gui_mgr().Browser_win(); } - public void Main_page() {win.Page__navigate_by_url_bar(win.Active_page().Wiki().Domain_str() + Xoh_href_parser.Href_wiki_str);} // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14 public void Random() {win.Page__navigate_by_url_bar("Special:Random");} public void Sandbox() {win.Page__navigate_by_url_bar("Project:Sandbox");} + public void Main_page() { + win.Tab_mgr().Active_tab_assert(); // force an active tab in case all tabs are closed; needed for win.Active_page() below; DATE:2014-09-17 + win.Page__navigate_by_url_bar(win.Active_page().Wiki().Domain_str() + Xoh_href_parser.Href_wiki_str); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14 + } public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_main_page)) this.Main_page(); else if (ctx.Match(k, Invk_random)) this.Random(); diff --git a/400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java b/400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java index c3dcd352b..db327b0ce 100644 --- a/400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java +++ b/400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java @@ -16,15 +16,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; -import org.junit.*; -import gplx.xowa.html.portal.*; +import org.junit.*; import gplx.xowa.html.portal.*; import gplx.xowa.wikis.xwikis.*; public class Xob_init_base_tst { @Before public void init() {fxt.Clear();} private Xob_init_base_fxt fxt = new Xob_init_base_fxt(); @Test public void Dirty_wiki_itms() { Xoa_app app = fxt.App(); Xow_wiki wiki = fxt.Wiki(); Xoa_available_wikis_mgr wikis_list = fxt.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis(); Tfds.Eq("", wikis_list.Itms_as_html()); // assert - app.User().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org"); + Xow_xwiki_itm xwiki_itm = app.User().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org"); + xwiki_itm.Offline_(Bool_.Y); // simulate add via Available_from_fsys; DATE:2014-09-21 Tfds.Eq("", wikis_list.Itms_as_html()); // still empty new Xob_init_txt(app.Bldr(), wiki).Cmd_end(); // mock "init" task Tfds.Eq("\n
  • en.wikipedia.org
  • ", wikis_list.Itms_as_html()); // no longer empty diff --git a/400_xowa/src/gplx/xowa/bldrs/oimgs/Xodb_db_file.java b/400_xowa/src/gplx/xowa/bldrs/oimgs/Xodb_db_file.java index 9fe2bd352..95030b6ea 100644 --- a/400_xowa/src/gplx/xowa/bldrs/oimgs/Xodb_db_file.java +++ b/400_xowa/src/gplx/xowa/bldrs/oimgs/Xodb_db_file.java @@ -18,8 +18,7 @@ along with this program. If not, see . package gplx.xowa.bldrs.oimgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; public class Xodb_db_file { - Xodb_db_file(String name, Io_url url, Db_provider provider, boolean created) {this.name = name; this.url = url; this.provider = provider; this.created = created;} - public String Name() {return name;} private String name; + Xodb_db_file(Io_url url, Db_provider provider, boolean created) {this.url = url; this.provider = provider; this.created = created;} public Io_url Url() {return url;} private Io_url url; public Db_provider Provider() {return provider;} private Db_provider provider; public boolean Created() {return created;} public void Created_clear() {created = false;} private boolean created; @@ -37,7 +36,7 @@ public class Xodb_db_file { Xodb_xowa_cfg_tbl.Create_table(provider); Xodb_xowa_cfg_tbl.Create_index(provider); } - return new Xodb_db_file(name, url, provider, created.Val()); + return new Xodb_db_file(url, provider, created.Val()); } public static final String Name__wiki_image = "xowa.wiki.image.sqlite3", Name__wiki_redirect = "xowa.wiki.redirect.sqlite3" diff --git a/400_xowa/src/gplx/xowa/dbs/tbls/Xodb_page_tbl.java b/400_xowa/src/gplx/xowa/dbs/tbls/Xodb_page_tbl.java index 69a215eb6..3fb70a59b 100644 --- a/400_xowa/src/gplx/xowa/dbs/tbls/Xodb_page_tbl.java +++ b/400_xowa/src/gplx/xowa/dbs/tbls/Xodb_page_tbl.java @@ -51,15 +51,15 @@ public class Xodb_page_tbl { return false; } public static void Read_page__all2(Xodb_page page, Db_rdr rdr, boolean html_db_enabled) { - page.Id_ (rdr.Read_int(1)); - page.Ns_id_ (rdr.Read_int(2)); - page.Ttl_wo_ns_ (rdr.Read_bry_by_str(3)); - page.Modified_on_ (DateAdp_.parse_fmt(rdr.Read_str(4), Page_touched_fmt)); - page.Type_redirect_ (rdr.Read_byte(5) == 1); - page.Text_len_ (rdr.Read_int(6)); - page.Db_file_idx_ (rdr.Read_int(7)); + page.Id_ (rdr.Read_int(0)); + page.Ns_id_ (rdr.Read_int(1)); + page.Ttl_wo_ns_ (rdr.Read_bry_by_str(2)); + page.Modified_on_ (DateAdp_.parse_fmt(rdr.Read_str(3), Page_touched_fmt)); + page.Type_redirect_ (rdr.Read_byte(4) == 1); + page.Text_len_ (rdr.Read_int(5)); + page.Db_file_idx_ (rdr.Read_int(6)); if (html_db_enabled) - page.Html_db_id_(rdr.Read_int(8)); + page.Html_db_id_(rdr.Read_int(7)); } public boolean Select_by_id(Xodb_page rv, int page_id) { DataRdr rdr = DataRdr_.Null; diff --git a/400_xowa/src/gplx/xowa/files/Xof_url_bldr.java b/400_xowa/src/gplx/xowa/files/Xof_url_bldr.java index 2940dbe90..85a1bb8c5 100644 --- a/400_xowa/src/gplx/xowa/files/Xof_url_bldr.java +++ b/400_xowa/src/gplx/xowa/files/Xof_url_bldr.java @@ -19,7 +19,7 @@ package gplx.xowa.files; import gplx.*; import gplx.xowa.*; public class Xof_url_bldr { private final Bry_bfr bfr = Bry_bfr.reset_(400); private byte[] ttl; private byte[] md5; private Xof_ext ext; private boolean file_is_thumb; private int file_w; - private double time = Xof_doc_thumb.Null; private int page = Xof_doc_page.Null; private byte time_dlm = Byte_ascii.At; + private double time = Xof_doc_thumb.Null; private int page = Xof_doc_page.Null; private byte time_dlm = Byte_ascii.At; private byte[] root; private byte dir_spr; private boolean fsys_tid_is_wnt; private boolean wmf_dir_hive; private boolean wmf_protocol_is_file; private int md5_dir_depth; private byte[] area; public Xof_url_bldr Root_(byte[] v) {root = v; return this;} public Xof_url_bldr Init_by_root(byte[] root, byte dir_spr, boolean wmf_dir_hive, boolean wmf_protocol_is_file, int md5_dir_depth) { diff --git a/400_xowa/src/gplx/xowa/files/gui/Js_img_mgr.java b/400_xowa/src/gplx/xowa/files/gui/Js_img_mgr.java index 19d2f4a23..02451e091 100644 --- a/400_xowa/src/gplx/xowa/files/gui/Js_img_mgr.java +++ b/400_xowa/src/gplx/xowa/files/gui/Js_img_mgr.java @@ -30,6 +30,7 @@ public class Js_img_mgr { } private static void Update_img(Xoa_page page, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, byte[] lnki_ttl, int gallery_mgr_h, Js_img_wkr img_wkr) { if (Env_.Mode_testing()) return; + if (page.App().Mode() != Xoa_app_.Mode_gui) return; // do not update html widget unless app is gui; null ref on http server; DATE:2014-09-17 Xog_html_itm html_itm = page.Tab().Html_itm(); switch (elem_tid) { case Xof_html_elem.Tid_gallery_v2: diff --git a/400_xowa/src/gplx/xowa/gui/views/Xog_launcher_tabs.java b/400_xowa/src/gplx/xowa/gui/views/Xog_launcher_tabs.java index da2f62c82..647448463 100644 --- a/400_xowa/src/gplx/xowa/gui/views/Xog_launcher_tabs.java +++ b/400_xowa/src/gplx/xowa/gui/views/Xog_launcher_tabs.java @@ -38,8 +38,7 @@ class Xog_launcher_tabs { int launch_urls_len = launch_urls.length; for (int i = 0; i < launch_urls_len; ++i) { String launch_url = launch_urls[i]; - Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(); - Launch_tab(tab, win, home_wiki, launch_url); + Launch_tab(win, home_wiki, launch_url); } fil_marker.End(); return true; @@ -52,18 +51,17 @@ class Xog_launcher_tabs { } private void Restore_tab_failover(Xoa_app app, Xow_wiki home_wiki, Xog_win_itm win) { try { - Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(); // NOTE: was win.Active_tab which throws a nullRef; DATE:2014-09-01 - Launch_tab(tab, win, home_wiki, gplx.xowa.users.Xouc_pages_mgr.Page_xowa); + Launch_tab(win, home_wiki, gplx.xowa.users.Xouc_pages_mgr.Page_xowa); } catch (Exception e) { app.Usr_dlg().Warn_many("", "", "failed to launch failover tab: err=~{0}", Err_.Message_gplx(e)); } } - private void Launch_tab(Xog_tab_itm tab, Xog_win_itm win, Xow_wiki home_wiki, String launch_str) { + private void Launch_tab(Xog_win_itm win, Xow_wiki home_wiki, String launch_str) { Xoa_url launch_url = Xoa_url_parser.Parse_from_url_bar(win.App(), home_wiki, launch_str); Xow_wiki launch_wiki = launch_url.Wiki(); Xoa_ttl launch_ttl = Xoa_ttl.parse_(launch_wiki, launch_url.Page_bry()); - tab.Page_(Xoa_page.new_(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23 + Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(Xoa_page.new_(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23 tab.Show_url_bgn(launch_url); } public static final Xog_launcher_tabs _ = new Xog_launcher_tabs(); Xog_launcher_tabs() {} diff --git a/400_xowa/src/gplx/xowa/gui/views/Xog_tab_itm.java b/400_xowa/src/gplx/xowa/gui/views/Xog_tab_itm.java index a7d0dd766..616cbdca9 100644 --- a/400_xowa/src/gplx/xowa/gui/views/Xog_tab_itm.java +++ b/400_xowa/src/gplx/xowa/gui/views/Xog_tab_itm.java @@ -20,8 +20,8 @@ import gplx.threads.*; import gplx.gfui.*; import gplx.xowa.gui.history.*; impor import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.cfgs2.*; import gplx.xowa.pages.*; public class Xog_tab_itm implements GfoInvkAble { private Xog_win_itm win; private Xocfg_tab_mgr cfg_tab_mgr; - public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data) { - this.tab_mgr = tab_mgr; this.tab_data = tab_data; + public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data, Xoa_page page) { + this.tab_mgr = tab_mgr; this.tab_data = tab_data; this.page = page; this.win = tab_mgr.Win(); this.cfg_tab_mgr = win.App().Cfg_regy ().App().Gui_mgr().Tab_mgr(); html_itm = new Xog_html_itm(this); cmd_sync = win.Kit().New_cmd_sync(this); @@ -71,14 +71,14 @@ public class Xog_tab_itm implements GfoInvkAble { public Xog_html_itm Html_itm() {return html_itm;} private Xog_html_itm html_itm; public Gfui_html Html_box() {return html_itm.Html_box();} public Xoa_page Page() {return page;} - public void Page_(Xoa_page page) {Page_(true, page);} - public void Page_(boolean update_ui, Xoa_page page) { + public void Page_(Xoa_page page) { this.page = page; - if (update_ui) { - this.Tab_name_(); - tab_box.Tab_tip_text_(page.Url().Xto_full_str()); - } - } private Xoa_page page; + this.Page_update_ui(); // force tab button to update when page changes + } private Xoa_page page; + public void Page_update_ui() { + this.Tab_name_(); + tab_box.Tab_tip_text_(page.Url().Xto_full_str()); + } public void Tab_name_() { byte[] tab_name = page.Html_data().Custom_name(); if (tab_name == null) tab_name = page.Ttl().Full_txt(); @@ -245,8 +245,9 @@ class Load_page_wkr implements Gfo_thread_wkr { else // not low in memory app.Utl_bry_bfr_mkr().Clear(); // clear bry_bfr_mk only; NOTE: call before page parse, not when page is first added, else threading errors; DATE:2014-05-30 Xoa_page page = wiki.GetPageByTtl(url, ttl, wiki.Lang(), tab, false); - if (wiki.Db_mgr().Hdump_mgr().Enabled() && page.Revision_data().Html_db_id() != -1) - wiki.Db_mgr().Hdump_mgr().Load(wiki, page); + int html_db_id = page.Revision_data().Html_db_id(); + if (wiki.Db_mgr().Hdump_mgr().Enabled() && html_db_id != -1) + wiki.Db_mgr().Hdump_mgr().Load(wiki, page, html_db_id); else wiki.ParsePage(page, false); GfoInvkAble_.InvkCmd_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_loaded_swt, page); diff --git a/400_xowa/src/gplx/xowa/gui/views/Xog_tab_mgr.java b/400_xowa/src/gplx/xowa/gui/views/Xog_tab_mgr.java index 6b4be1432..09246d5d8 100644 --- a/400_xowa/src/gplx/xowa/gui/views/Xog_tab_mgr.java +++ b/400_xowa/src/gplx/xowa/gui/views/Xog_tab_mgr.java @@ -53,7 +53,7 @@ public class Xog_tab_mgr implements GfoEvObj { } public Xog_tab_itm Active_tab() {return active_tab;} private Xog_tab_itm active_tab; public Xog_tab_itm Active_tab_assert() { - if (active_tab == Xog_tab_itm_.Null) this.Tabs_new_dflt(false, true); // update_ui=false; create dflt tab, but do not update name; will be updated later by whatever loads page + if (active_tab == Xog_tab_itm_.Null) this.Tabs_new_dflt(true); return active_tab; } public boolean Active_tab_is_null() {return active_tab == Xog_tab_itm_.Null;} @@ -70,24 +70,23 @@ public class Xog_tab_mgr implements GfoEvObj { } } public int Tabs_len() {return tab_regy.Count();} - public Xog_tab_itm Tabs_new_init() {return this.Tabs_new(true, true);} + public Xog_tab_itm Tabs_new_init(Xoa_page page) {return this.Tabs_new(true, true, page);} public Xog_tab_itm Tabs_get_at(int i) {return (Xog_tab_itm)tab_regy.FetchAt(i);} public Xog_tab_itm Tabs_new_dflt() {return Tabs_new_dflt(false);} - public Xog_tab_itm Tabs_new_dflt(boolean focus) {return Tabs_new_dflt(false, focus);} - public Xog_tab_itm Tabs_new_dflt(boolean update_ui, boolean focus) { + public Xog_tab_itm Tabs_new_dflt(boolean focus) { boolean active_tab_is_null = this.Active_tab_is_null(); Xow_wiki cur_wiki = active_tab_is_null ? win.App().User().Wiki() : active_tab.Page().Wiki(); - Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null); Xoa_ttl ttl = Xoa_ttl.parse_(cur_wiki, gplx.xowa.specials.xowa.default_tab.Default_tab_page.Ttl_full_bry); Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), cur_wiki, ttl.Full_db_as_str()); - rv.Page_(update_ui, Xoa_page.new_(cur_wiki, ttl)); + Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null, Xoa_page.new_(cur_wiki, ttl)); + rv.Page_update_ui(); rv.Show_url_bgn(url); return rv; } - private Xog_tab_itm Tabs_new(boolean focus, boolean active_tab_is_null) { + private Xog_tab_itm Tabs_new(boolean focus, boolean active_tab_is_null, Xoa_page page) { String tab_key = "tab_" + Int_.Xto_str(tab_uid++); int tab_idx = tab_regy.Count(); Gfui_tab_itm_data tab_data = new Gfui_tab_itm_data(tab_key, tab_idx); - Xog_tab_itm rv = new Xog_tab_itm(this, tab_data); + Xog_tab_itm rv = new Xog_tab_itm(this, tab_data, page); Gfui_tab_itm tab_box = tab_mgr.Tabs_add(tab_data); rv.Make_html_box(tab_uid, tab_box, win, tab_mgr); tab_box.Subs_add(rv.Html_itm().Html_box()); @@ -202,8 +201,7 @@ public class Xog_tab_mgr implements GfoEvObj { Xow_wiki wiki = active_tab.Page().Wiki(); Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), wiki, link); // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27 Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry()); - Xog_tab_itm new_tab = Tabs_new(focus, false); - new_tab.Page_(false, Xoa_page.new_(wiki, ttl)); + Xog_tab_itm new_tab = Tabs_new(focus, false, Xoa_page.new_(wiki, ttl)); new_tab.Tab_name_(String_.new_utf8_(Xoa_ttl.Replace_unders(url.Page_bry()))); new_tab.Show_url_bgn(url); if (focus) diff --git a/400_xowa/src/gplx/xowa/hdumps/Db_provider_key.java b/400_xowa/src/gplx/xowa/hdumps/Db_provider_key.java new file mode 100644 index 000000000..ccbf7d957 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Db_provider_key.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.dbs.*; +public class Db_provider_key { + public Db_provider_key(String key, Db_conn_info conn_info, GfoInvkAbleCmd init_cmd) {this.key = key; this.conn_info = conn_info; this.init_cmd = init_cmd;} + public String Key() {return key;} private final String key; + public Db_conn_info Conn_info() {return conn_info;} private Db_conn_info conn_info; + public GfoInvkAbleCmd Init_cmd() {return init_cmd;} private GfoInvkAbleCmd init_cmd; +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Db_provider_mkr.java b/400_xowa/src/gplx/xowa/hdumps/Db_provider_mkr.java new file mode 100644 index 000000000..65edba1e9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Db_provider_mkr.java @@ -0,0 +1,70 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.dbs.*; +public class Db_provider_mkr { + private final HashAdp engine_regy = HashAdp_.new_(); + public void Engines_add(Db_engine engine) {engine_regy.AddReplace(engine.Conn_info_tid(), engine);} + public Db_provider Get(Db_provider_key provider_key) { + Db_provider rv = Get_or_new(provider_key); + GfoInvkAbleCmd init_cmd = provider_key.Init_cmd(); + if (init_cmd != GfoInvkAbleCmd.Null) + GfoInvkAble_.InvkCmd_val(init_cmd.InvkAble(), init_cmd.Cmd(), rv); + return rv; + } + private Db_provider Get_or_new(Db_provider_key key) { + Db_conn_info conn_info = key.Conn_info(); + Db_engine prototype = (Db_engine)engine_regy.Fetch(conn_info.Key()); + Db_engine engine = prototype.Make_new(conn_info); + engine.Conn_open(); // auto-open + return new Db_provider(engine); + } +} +class Mem_db_rdr implements Db_rdr { + private int idx = -1, len; + private Mem_db_row[] rows = new Mem_db_row[0]; + private Mem_db_rdr(Mem_db_row[] rows) { + this.rows = rows; + this.len = rows.length; + } + public boolean Move_next() {return ++idx < len;} + public byte[] Read_bry(int i) {return (byte[])rows[idx].Get_at(i);} + public byte[] Read_bry_by_str(int i) {return Bry_.new_utf8_((String)rows[idx].Get_at(i));} + public String Read_str(int i) {return (String)rows[idx].Get_at(i);} + public byte Read_byte(int i) {return Byte_.cast_(rows[idx].Get_at(i));} + public int Read_int(int i) {return Int_.cast_(rows[idx].Get_at(i));} + public long Read_long(int i) {return Long_.cast_(rows[idx].Get_at(i));} + public float Read_float(int i) {return Float_.cast_(rows[idx].Get_at(i));} + public double Read_double(int i) {return Double_.cast_(rows[idx].Get_at(i));} + public void Close() {rows = null;} + public static Mem_db_rdr new_by_rows(Mem_db_row[] rows) {return new Mem_db_rdr(rows);} + public static Mem_db_rdr new_by_obj_ary(Object[][] obj_arys) { + int obj_arys_len = obj_arys.length; + Mem_db_row[] rows = new Mem_db_row[obj_arys_len]; + for (int i = 0; i < obj_arys_len; ++i) { + Object[] obj_ary = obj_arys[i]; + rows[i] = new Mem_db_row(obj_ary); + } + return new Mem_db_rdr(rows); + } +} +class Mem_db_row { + private Object[] vals; + public Mem_db_row(Object[] vals) {this.vals = vals;} + public Object Get_at(int i) {return vals[i];} +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xoav_app.java b/400_xowa/src/gplx/xowa/hdumps/Xoav_app.java new file mode 100644 index 000000000..23cff6033 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xoav_app.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.xowa.apps.fsys.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.langs.cases.*; import gplx.intl.*; +public class Xoav_app { + public Xoav_app(Gfo_usr_dlg usr_dlg, Io_url root_dir, String plat_name) { + this.usr_dlg = usr_dlg; + this.fsys_mgr = new Xoa_fsys_mgr(root_dir, plat_name); + this.wiki_mgr = new Xoav_wiki_mgr(this, fsys_mgr.Wiki_dir(), utl_case_mgr); + this.db_mgr = new Db_provider_mkr(); + this.utl_msg_log = Gfo_msg_log.Test(); + db_mgr.Engines_add(gplx.dbs.Sqlite_engine_.New_engine()); + } + public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xoa_fsys_mgr fsys_mgr; + public Xoav_wiki_mgr Wiki_mgr() {return wiki_mgr;} private final Xoav_wiki_mgr wiki_mgr; + public Db_provider_mkr Db_mgr() {return db_mgr;} private Db_provider_mkr db_mgr; + + public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} private Gfo_usr_dlg usr_dlg; + public Bry_bfr_mkr Utl_bfr_mkr() {return utl_bfr_mkr;} private Bry_bfr_mkr utl_bfr_mkr = new Bry_bfr_mkr(); + public Xop_amp_mgr Utl_amp_mgr() {return utl_amp_mgr;} private Xop_amp_mgr utl_amp_mgr = new Xop_amp_mgr(); + public Xol_case_mgr Utl_case_mgr() {return utl_case_mgr;} private Xol_case_mgr utl_case_mgr = new Xol_case_mgr(Gfo_case_mgr_.Tid_utf8); + public Url_encoder Utl_encoder_fsys() {return utl_encoder_fsys;} private Url_encoder utl_encoder_fsys = Url_encoder.new_fsys_lnx_(); + public Gfo_msg_log Utl_msg_log() {return utl_msg_log;} private Gfo_msg_log utl_msg_log; +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xoav_wiki_mgr.java b/400_xowa/src/gplx/xowa/hdumps/Xoav_wiki_mgr.java new file mode 100644 index 000000000..49c882c63 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xoav_wiki_mgr.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.xowa.langs.cases.*; +public class Xoav_wiki_mgr { + private final Xoav_app app; private final OrderedHash hash = OrderedHash_.new_bry_(); + private Io_url wiki_root_dir; + public Xoav_wiki_mgr(Xoav_app app, Io_url wiki_root_dir, Xol_case_mgr case_mgr) {this.app = app; this.wiki_root_dir = wiki_root_dir;} + public Xowv_wiki Get_by_domain(byte[] domain) {return (Xowv_wiki)hash.Fetch(domain);} + public void Load_default() { + Io_url[] wiki_dirs = Io_mgr._.QueryDir_args(wiki_root_dir).DirOnly_().ExecAsUrlAry(); + for (Io_url wiki_dir : wiki_dirs) { + String wiki_dir_url = wiki_dir.Raw(); + if (String_.HasAtBgn(wiki_dir_url, "#")) continue; + Xowv_wiki wiki = new Xowv_wiki(app, wiki_dir.NameOnly(), wiki_dir); + hash.Add(wiki.Domain_bry(), wiki); + } + } +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xodb_hdump_mgr.java b/400_xowa/src/gplx/xowa/hdumps/Xodb_hdump_mgr.java index 0a4a81230..acf0c1d47 100644 --- a/400_xowa/src/gplx/xowa/hdumps/Xodb_hdump_mgr.java +++ b/400_xowa/src/gplx/xowa/hdumps/Xodb_hdump_mgr.java @@ -22,16 +22,16 @@ public class Xodb_hdump_mgr { private Xodb_file hdump_db_file; public Xodb_hdump_mgr(Xow_wiki wiki) { this.wiki = wiki; - load_mgr = new Hdump_load_mgr(this); + load_mgr = new Hdump_load_mgr(); Tbl_(new Hdump_text_tbl()); text_tbl.Init_by_wiki(wiki); Xoa_app app = wiki.App(); - html_mgr.Init_by_app(app); + html_mgr.Init_by_app(app.Usr_dlg(), app.Fsys_mgr(), app.Encoder_mgr().Fsys()); } public Xow_wiki Wiki() {return wiki;} private final Xow_wiki wiki; @gplx.Internal protected Hdump_load_mgr Load_mgr() {return load_mgr;} private Hdump_load_mgr load_mgr; @gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr(); - public Hdump_html_mgr Html_mgr() {return html_mgr;} private Hdump_html_mgr html_mgr = new Hdump_html_mgr(); + public Hdump_html_body Html_mgr() {return html_mgr;} private Hdump_html_body html_mgr = new Hdump_html_body(); public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl; public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled; @gplx.Internal protected void Tbl_mem_() {Tbl_(new Hdump_text_tbl_mem());} @@ -58,16 +58,16 @@ public class Xodb_hdump_mgr { wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page); page.Hdump_data().Body_(bfr.XtoAryAndClear()); } - public void Load(Xow_wiki wiki, Xoa_page page) { + public void Load(Xow_wiki wiki, Xoa_page page, int html_db_id) { if (!Enabled_chk()) return; page.Root_(new Xop_root_tkn()); - Hdump_page hpg = new Hdump_page(); - load_mgr.Load(hpg, page.Revision_data().Id(), page.Url()); + Hdump_page hpg = new Hdump_page().Init(page.Revision_data().Id(), page.Url()); + load_mgr.Load(hpg, wiki.Db_mgr_as_sql().Fsys_mgr(), html_db_id, page.Revision_data().Id()); Load_page(wiki, page, hpg); } private void Load_page(Xow_wiki wiki, Xoa_page page, Hdump_page hpg) { Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001(); - html_mgr.Write(tmp_bfr, wiki, hpg); + html_mgr.Init_by_page(wiki.Domain_bry(), hpg).Write(tmp_bfr); page.Hdump_data().Body_(tmp_bfr.XtoAryAndClear()); Xopg_html_data html_data = page.Html_data(); html_data.Display_ttl_(hpg.Display_ttl()); diff --git a/400_xowa/src/gplx/xowa/hdumps/Xodbv_dbs_tbl.java b/400_xowa/src/gplx/xowa/hdumps/Xodbv_dbs_tbl.java new file mode 100644 index 000000000..71524cd57 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xodbv_dbs_tbl.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.dbs.*; import gplx.xowa.dbs.*; +public class Xodbv_dbs_tbl { + public static final String Tbl_name = "xowa_db", Fld_db_id = "db_id", Fld_db_type = "db_type", Fld_db_url = "db_url"; + private static final String[] Flds__all = new String[] {Fld_db_id, Fld_db_type, Fld_db_url}; + public Xodb_file[] Select_all(Db_provider provider, Io_url wiki_root_dir) { + Db_rdr rdr = Db_rdr_.Null; + ListAdp list = ListAdp_.new_(); + try { + Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_(Tbl_name, Db_qry__select_in_tbl.Where_flds__all, Flds__all).Order_by_sql_(Fld_db_id); + Db_stmt stmt = Db_stmt_.new_select_as_rdr(provider, qry); + rdr = stmt.Exec_select_as_rdr(); + while (rdr.Move_next()) { + Xodb_file db = Xodb_file.load_(rdr.Read_int(0), rdr.Read_byte(1), rdr.Read_str(2)); + db.Url_(wiki_root_dir.GenSubFil(db.Url_rel())); + list.Add(db); + } + } finally {rdr.Close();} + Xodb_file[] rv = (Xodb_file[])list.XtoAry(Xodb_file.class); + Chk_sequential(rv); + return rv; + } + private void Chk_sequential(Xodb_file[] ary) { + int len = ary.length; + int expd_id = 0; + for (int i = 0; i < len; i++) { + Xodb_file itm = ary[i]; + int actl_id = itm.Id(); + if (expd_id != actl_id) throw Err_.new_fmt_("database ids are not sequential; expd={0} actl={1}", expd_id, actl_id); + ++expd_id; + } + } + //Db_stmt_bldr stmt_bldr = new Db_stmt_bldr(Tbl_name, String_.Ary(Fld_db_id), Fld_db_type, Fld_db_url); +} +// class Xod_db_fil { +// public Xod_db_fil(int idx, Io_url url) {this.idx = idx; this.url = url;} +// public int Idx() {return idx;} private int idx; +// public Io_url Url() {return url;} private Io_url url; +// } diff --git a/400_xowa/src/gplx/xowa/hdumps/Xodbv_page_tbl.java b/400_xowa/src/gplx/xowa/hdumps/Xodbv_page_tbl.java new file mode 100644 index 000000000..b4d22c311 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xodbv_page_tbl.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.dbs.*; +public class Xodbv_page_tbl { + public static final String Tbl_name = "page" + , Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title" + , Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len" + , Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx" + , Fld_page_html_db_id = "page_html_db_id"; + private static final String[] Select_by_id_flds__hdump = new String[] {Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx, Fld_page_html_db_id}; + public boolean Select_by_ttl(Xodb_page rv, Db_provider provider, Xow_ns ns, byte[] ttl) { + Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null; + try { + stmt = Db_stmt_.new_select_as_rdr(provider, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_ns, Fld_page_title), Select_by_id_flds__hdump)); + rdr = stmt.Val_int_(ns.Id()).Val_str_(String_.new_utf8_(ttl)).Exec_select_as_rdr(); + if (rdr.Move_next()) { + Read_page__all(rv, rdr); + return true; + } + } finally {rdr.Close(); stmt.Rls();} + return false; + } + public static void Read_page__all(Xodb_page page, Db_rdr rdr) { + page.Id_ (rdr.Read_int(0)); + page.Ns_id_ (rdr.Read_int(1)); + page.Ttl_wo_ns_ (rdr.Read_bry_by_str(2)); + page.Modified_on_ (DateAdp_.parse_fmt(rdr.Read_str(3), Page_touched_fmt)); + page.Type_redirect_ (rdr.Read_byte(4) == 1); + page.Text_len_ (rdr.Read_int(5)); + page.Db_file_idx_ (rdr.Read_int(6)); + page.Html_db_id_ (rdr.Read_int(7)); + } + private static final String Page_touched_fmt = "yyyyMMddHHmmss"; +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xowd_db_tbl_mgr.java b/400_xowa/src/gplx/xowa/hdumps/Xowd_db_tbl_mgr.java new file mode 100644 index 000000000..521343311 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xowd_db_tbl_mgr.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +public class Xowd_db_tbl_mgr { + public Xodbv_page_tbl Tbl__page() {return tbl__page;} private Xodbv_page_tbl tbl__page = new Xodbv_page_tbl(); + public Xodbv_dbs_tbl Tbl__dbs_new() {return new Xodbv_dbs_tbl();} +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xowd_hdump_mgr.java b/400_xowa/src/gplx/xowa/hdumps/Xowd_hdump_mgr.java new file mode 100644 index 000000000..c656b4c82 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xowd_hdump_mgr.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.intl.*; import gplx.dbs.*; +import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.apps.fsys.*; +public class Xowd_hdump_mgr { + private final Xoav_app app; private final Xowv_wiki wiki; private final Xowv_db_mgr wiki_db_mgr; + private Xodb_page dbpg = new Xodb_page(); private Hdump_page hpg = new Hdump_page(); + private Hdump_load_mgr load_mgr = new Hdump_load_mgr(); + private Hdump_html_body html_body = new Hdump_html_body(); + public Xowd_hdump_mgr(Xoav_app app, Xowv_wiki wiki) { + this.app = app; this.wiki = wiki; this.wiki_db_mgr = wiki.Db_mgr(); + html_body.Init_by_app(app.Usr_dlg(), app.Fsys_mgr(), app.Utl_encoder_fsys()); + } + public void Load(Hdump_page rv, byte[] ttl_bry) { + Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry); + wiki_db_mgr.Tbl_mgr().Tbl__page().Select_by_ttl(dbpg, app.Db_mgr().Get(wiki_db_mgr.Key__core()), ttl.Ns(), ttl.Page_db()); + load_mgr.Load2(hpg, app.Db_mgr().Get(wiki_db_mgr.Key_by_idx(dbpg.Html_db_id())), dbpg.Id()); + Bry_bfr bfr = app.Utl_bfr_mkr().Get_m001(); + html_body.Init_by_page(wiki.Domain_bry(), hpg).Write(bfr); + rv.Page_body_(bfr.Mkr_rls().XtoAryAndClear()); + } +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr.java b/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr.java new file mode 100644 index 000000000..706591be7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.dbs.*; import gplx.xowa.dbs.*; +public class Xowv_db_mgr implements GfoInvkAble { + private Io_url wiki_root_dir; + public Xowv_db_mgr(String domain_str, Io_url wiki_root_dir) { + this.tbl_mgr = new Xowd_db_tbl_mgr(); this.wiki_root_dir = wiki_root_dir; + this.key__core = Xowv_db_mgr.Db_key__core__default(this, domain_str, wiki_root_dir); + } + public Xowd_db_tbl_mgr Tbl_mgr() {return tbl_mgr;} private Xowd_db_tbl_mgr tbl_mgr; + private Xodb_file[] db_files; private Db_provider_key[] db_keys; private int db_keys_len; + public Db_provider_key Key__core() {return key__core;} private Db_provider_key key__core; + public Db_provider_key Key_by_idx(int idx) {if (!Int_.Between(idx, 0, db_keys_len)) throw Err_.new_("database does not exist: idx={0}", idx); return db_keys[idx];} + private void Core_init(Db_provider provider) { + db_files = tbl_mgr.Tbl__dbs_new().Select_all(provider, wiki_root_dir); + db_keys = Db_keys_make(db_files); + db_keys_len = db_keys.length; + } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_core_init)) Core_init((Db_provider)m.ReadObj("v")); + else return GfoInvkAble_.Rv_unhandled; + return this; + } private static final String Invk_core_init = "core_init"; + private static Db_provider_key Db_key__core__default(Xowv_db_mgr db_mgr, String domain_str, Io_url wiki_root_dir) { + Io_url core_db_url = wiki_root_dir.GenSubFil_ary(domain_str, ".000.sqlite3"); + GfoInvkAbleCmd init_cmd = GfoInvkAbleCmd.new_(db_mgr, Invk_core_init); + return new Db_provider_key(core_db_url.Raw(), Db_conn_info_.sqlite_(core_db_url), init_cmd); + } + private static Db_provider_key[] Db_keys_make(Xodb_file[] ary) { + int len = ary.length; + Db_provider_key[] rv = new Db_provider_key[len]; + for (int i = 0; i < len; ++i) { + Xodb_file itm = ary[i]; + Io_url itm_url = itm.Url(); + rv[i] = new Db_provider_key(itm_url.Raw(), Db_conn_info_.sqlite_(itm_url), GfoInvkAbleCmd.Null); + } + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr_tst.java b/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr_tst.java new file mode 100644 index 000000000..c638314bb --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xowv_db_mgr_tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.dbs.*; +import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.xtns.hieros.*; import gplx.xowa.xtns.gallery.*; +public class Xowv_db_mgr_tst { + @Before public void init() {} private Xowv_db_mgr_fxt fxt = new Xowv_db_mgr_fxt(); + @Test public void Basic() { + fxt.Init_rdr(fxt.Make_row(0, "mem/a", 2),fxt.Make_row(0, "mem/a", 2), fxt.Make_row(0, "mem/a", 2)); +// fxt.Exec_open_core(); +// fxt.Test_dbs(fxt.Make_db(0, "mem/a", 0), fxt.Make_db(1, "mem/2", 2), fxt.Make_db("mem/3, 3")); + } +} +class Xowv_db_mgr_fxt { +// private Xoav_app app; private Xowv_wiki wiki; + public void Init_rdr(Mem_db_row... rows) { +// Mem_db_rdr rdr = Mem_db_rdr.new_by_rows(rows); +// app = new Xoav_app(null, nul, null); +// Mem_db_engine engine = new Mem_db_engine(); +// engine.Pending_rdrs_add(rdr); +// app.Db_mgr().Engines_add(engine); + } + public Mem_db_row Make_row(Object... vals) {return new Mem_db_row(vals);} + public void Exec_open_core() { +// app.Db_mgr().Get(wiki.Db_mgr().Key__core()); + } + public void Test_dbs(Xodb_file[] expd) { +// Tfds.Eq(expd, wiki.Db_mgr().Files()); + } +} diff --git a/400_xowa/src/gplx/xowa/hdumps/Xowv_wiki.java b/400_xowa/src/gplx/xowa/hdumps/Xowv_wiki.java new file mode 100644 index 000000000..3f8b72cf0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/hdumps/Xowv_wiki.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; +import gplx.xowa.wikis.xwikis.*; import gplx.xowa.langs.cases.*; +public class Xowv_wiki { + private Xoav_app app; + public Xowv_wiki(Xoav_app app, String domain_str, Io_url wiki_root_dir) { + this.app = app; + this.domain_str = domain_str; this.domain_bry = Bry_.new_utf8_(domain_str); + this.ns_mgr = Xow_ns_mgr_.default_(app.Utl_case_mgr()); // new Xow_ns_mgr(app.Utl_case_mgr()); // FIXME + this.db_mgr = new Xowv_db_mgr(domain_str, wiki_root_dir); + this.hdump_mgr = new Xowd_hdump_mgr(app, this); + this.xwiki_mgr = new Xow_xwiki_mgr(); + } + public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry; + public String Domain_str() {return domain_str;} private final String domain_str; + public Xow_ns_mgr Ns_mgr() {return ns_mgr;} private final Xow_ns_mgr ns_mgr; + public Xowv_db_mgr Db_mgr() {return db_mgr;} private final Xowv_db_mgr db_mgr; + public Xowd_hdump_mgr Hdump_mgr() {return hdump_mgr;} private final Xowd_hdump_mgr hdump_mgr; + public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private Xow_xwiki_mgr xwiki_mgr; + public Xoa_ttl Ttl_parse(byte[] ttl) { + return Xoa_ttl.parse(app.Utl_bfr_mkr(), app.Utl_amp_mgr(), app.Utl_case_mgr(), xwiki_mgr, ns_mgr, app.Utl_msg_log(), ttl, 0, ttl.length); + } +} diff --git a/400_xowa/src/gplx/xowa/hdumps/core/Hdump_img_bldr.java b/400_xowa/src/gplx/xowa/hdumps/core/Hdump_img_bldr.java index 37b3279af..0e78d6efb 100644 --- a/400_xowa/src/gplx/xowa/hdumps/core/Hdump_img_bldr.java +++ b/400_xowa/src/gplx/xowa/hdumps/core/Hdump_img_bldr.java @@ -33,20 +33,20 @@ class Hdump_img_bldr_cmd extends Xob_itm_basic_base implements Xob_cmd { Db_rdr rdr = stmt.Exec_select_as_rdr(); int cur_page_id = -1; while (rdr.Move_next()) { - int lnki_page_id = rdr.Read_int(1); + int lnki_page_id = rdr.Read_int(0); if (lnki_page_id != cur_page_id) { Save(cur_page_id, bfr.XtoAryAndClear()); cur_page_id = lnki_page_id; } - int html_uid = rdr.Read_int(2); - byte[] lnki_ttl = rdr.Read_bry(3); - int html_w = rdr.Read_int(4); - int html_h = rdr.Read_int(5); - int file_repo_id = rdr.Read_int(6); - int file_ext_id = rdr.Read_int(7); - boolean file_is_orig = rdr.Read_int(8) == 1; - double file_time = rdr.Read_double(9); - int file_page = rdr.Read_int(10); + int html_uid = rdr.Read_int(1); + byte[] lnki_ttl = rdr.Read_bry(2); + int html_w = rdr.Read_int(3); + int html_h = rdr.Read_int(4); + int file_repo_id = rdr.Read_int(5); + int file_ext_id = rdr.Read_int(6); + boolean file_is_orig = rdr.Read_int(7) == 1; + double file_time = rdr.Read_double(8); + int file_page = rdr.Read_int(9); Hdump_data_img__base.Data_write_static(bfr, 0, lnki_ttl, html_uid, html_w, html_h, file_repo_id, file_ext_id, file_is_orig, html_w, file_time, file_page); } Save(cur_page_id, bfr.XtoAryAndClear());; diff --git a/400_xowa/src/gplx/xowa/hdumps/core/Hdump_page.java b/400_xowa/src/gplx/xowa/hdumps/core/Hdump_page.java index 27e7b3d55..9f4df39d9 100644 --- a/400_xowa/src/gplx/xowa/hdumps/core/Hdump_page.java +++ b/400_xowa/src/gplx/xowa/hdumps/core/Hdump_page.java @@ -29,7 +29,7 @@ public class Hdump_page { public int[] Redlink_uids() {return redlink_uids;} public void Redlink_uids_(int[] v) {redlink_uids = v;} private int[] redlink_uids; public Hdump_data_img__base[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_data_img__base[] v) {this.img_itms = v;} private Hdump_data_img__base[] img_itms; public OrderedHash Gly_itms() {return gly_itms;} private OrderedHash gly_itms = OrderedHash_.new_(); - public void Init(int page_id, Xoa_url page_url) { + public Hdump_page Init(int page_id, Xoa_url page_url) { this.page_id = page_id; this.page_url = page_url; content_sub = sidebar_div = Bry_.Empty; @@ -37,5 +37,6 @@ public class Hdump_page { img_itms = Hdump_data_img__base.Ary_empty; module_mgr.Clear(); gly_itms.Clear(); + return this; } } diff --git a/400_xowa/src/gplx/xowa/hdumps/core/Xob_lnki_regy_mgr.java b/400_xowa/src/gplx/xowa/hdumps/core/Xob_lnki_regy_mgr.java index 157038917..07dbca17c 100644 --- a/400_xowa/src/gplx/xowa/hdumps/core/Xob_lnki_regy_mgr.java +++ b/400_xowa/src/gplx/xowa/hdumps/core/Xob_lnki_regy_mgr.java @@ -80,12 +80,12 @@ class Redlink_wkr { Db_rdr rdr = Db_rdr_.Null; int cur_page_id = -1; while (rdr.Move_next()) { - int lnki_page_id = rdr.Read_int(1); + int lnki_page_id = rdr.Read_int(0); if (lnki_page_id != cur_page_id) { Save(cur_page_id, bfr.XtoAryAndClear()); cur_page_id = lnki_page_id; } - int html_uid = rdr.Read_int(2); + int html_uid = rdr.Read_int(1); bfr.Add_int_variable(html_uid).Add_byte_pipe(); } Save(cur_page_id, bfr.XtoAryAndClear());; @@ -98,9 +98,9 @@ class Redlink_wkr { Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null; while (rdr.Move_next()) { - int lnki_id = rdr.Read_int(1); - int lnki_page_id = rdr.Read_int(2); - byte[] page_ids = rdr.Read_bry(3); + int lnki_id = rdr.Read_int(0); + int lnki_page_id = rdr.Read_int(1); + byte[] page_ids = rdr.Read_bry(2); Save_rl_html(stmt, lnki_id, lnki_page_id, bry_rdr.Src_(page_ids)); } } diff --git a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_body.java b/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_body.java index 3c1130e80..00a089ddb 100644 --- a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_body.java +++ b/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_body.java @@ -18,35 +18,30 @@ along with this program. If not, see . package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.html.*; import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.xtns.gallery.*; -public class Hdump_html_body implements Bry_fmtr_arg { - private Bry_rdr bry_rdr = new Bry_rdr(); - private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_(); - private Xow_wiki wiki; private Hdump_page hpg; - private byte[] root_remote, root_local; - private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._; private byte[] root_dir, file_dir, hiero_img_dir; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); - private Xoh_cfg_file cfg_file; - public void Init_by_app(Xoa_app app) { - this.usr_dlg = app.Usr_dlg(); - this.root_dir = app.Fsys_mgr().Root_dir().To_http_file_bry(); - this.file_dir = app.Fsys_mgr().File_dir().To_http_file_bry(); - this.hiero_img_dir = gplx.xowa.xtns.hieros.Hiero_xtn_mgr.Hiero_root_dir(app).GenSubDir("img").To_http_file_bry(); - cfg_file = new Xoh_cfg_file(app.Encoder_mgr().Fsys(), app.Fsys_mgr().Bin_xowa_dir()); +public class Hdump_html_body { + private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Bry_rdr bry_rdr = new Bry_rdr(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._; + private Hdump_page hpg; private Xoh_cfg_file cfg_file; private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2_(); private Xoh_file_html_fmtr__base html_fmtr; + private byte[] root_dir, file_dir, file_dir_comm, file_dir_wiki, hiero_img_dir; + public Hdump_html_body Init_by_app(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder) { + this.usr_dlg = usr_dlg; + this.root_dir = fsys_mgr.Root_dir().To_http_file_bry(); + this.file_dir = fsys_mgr.File_dir().To_http_file_bry(); + this.hiero_img_dir = gplx.xowa.xtns.hieros.Hiero_xtn_mgr.Hiero_root_dir(fsys_mgr).GenSubDir("img").To_http_file_bry(); + this.cfg_file = new Xoh_cfg_file(fsys_encoder, fsys_mgr.Bin_xowa_dir()); + this.html_fmtr = Xoh_file_html_fmtr__hdump.Base; + return this; } - public void Init_by_page(Xow_wiki wiki, Hdump_page hpg) { - this.wiki = wiki; this.hpg = hpg; - root_remote = tmp_bfr.Add(file_dir).Add(Xow_wiki_.Domain_commons_bry).Add_byte_slash().XtoAryAndClear(); - root_local = tmp_bfr.Add(file_dir).Add(wiki.Domain_bry()).Add_byte_slash().XtoAryAndClear(); + public Hdump_html_body Init_by_page(byte[] domain_bry, Hdump_page hpg) { + this.hpg = hpg; + file_dir_comm = tmp_bfr.Add(file_dir).Add(Xow_wiki_.Domain_commons_bry).Add_byte_slash().XtoAryAndClear(); + file_dir_wiki = tmp_bfr.Add(file_dir).Add(domain_bry).Add_byte_slash().XtoAryAndClear(); + return this; } - public void Init_by_drd(Url_encoder fsys_encoder, Xoa_fsys_mgr fsys_mgr) { - cfg_file = new Xoh_cfg_file(fsys_encoder, fsys_mgr.Bin_xowa_dir()); - } - public void XferAry(Bry_bfr bfr, int idx) { + public void Write(Bry_bfr bfr) { byte[] src = hpg.Page_body(); int len = src.length; Hdump_data_img__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length; bry_rdr.Src_(src); int pos = 0; int rng_bgn = -1; - Xow_html_mgr html_mgr = wiki.Html_mgr(); - Xoh_file_html_fmtr__base html_fmtr = html_mgr.Html_wtr().Lnki_wtr().File_wtr().File_wtr().Html_fmtr(); while (pos < len) { byte b = src[pos]; Object o = trie.Match_bgn_w_byte(b, src, pos, len); @@ -66,15 +61,6 @@ public class Hdump_html_body implements Bry_fmtr_arg { } if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len); } - private int Write_redlink(Bry_bfr bfr, Hdump_page hpg, int uid, int rv) { - int[] redlink_uids = hpg.Redlink_uids(); if (redlink_uids == null) return rv; - int redlink_uid_max = redlink_uids.length; - if (uid < redlink_uid_max && redlink_uids[uid] == 1) - bfr.Add(Redlink_cls_new); - else - bfr.Del_by_1(); - return rv; - } private static final byte[] Redlink_cls_new = Bry_.new_ascii_("class='new'"); private int Write_data(Bry_bfr bfr, Xoh_file_html_fmtr__base fmtr, Hdump_page hpg, byte[] src, Hdump_data_img__base[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) { bry_rdr.Pos_(uid_bgn); int uid = itm.Subst_end_byte() == Byte_ascii.Nil ? -1 : bry_rdr.Read_int_to(itm.Subst_end_byte()); @@ -132,7 +118,7 @@ public class Hdump_html_body implements Bry_fmtr_arg { return rv; } } - url_bldr.Init_by_root(img.File_repo_id() == Xof_repo_itm.Repo_remote ? root_remote : root_local, Byte_ascii.Slash, false, false, 2); + url_bldr.Init_by_root(img.File_repo_id() == Xof_repo_itm.Repo_remote ? file_dir_comm : file_dir_wiki, Byte_ascii.Slash, false, false, 2); url_bldr.Init_by_itm(img.File_is_orig() ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb, img.Lnki_ttl(), Xof_xfer_itm_.Md5_(img.Lnki_ttl()), Xof_ext_.new_by_id_(img.File_ext_id()), img.File_w(), img.File_time(), img.File_page()); byte[] img_src = url_bldr.Xto_bry(); if (tid == Hdump_html_consts.Tid_img) { @@ -140,6 +126,15 @@ public class Hdump_html_body implements Bry_fmtr_arg { } return rv; } + private int Write_redlink(Bry_bfr bfr, Hdump_page hpg, int uid, int rv) { + int[] redlink_uids = hpg.Redlink_uids(); if (redlink_uids == null) return rv; + int redlink_uid_max = redlink_uids.length; + if (uid < redlink_uid_max && redlink_uids[uid] == 1) + bfr.Add(Redlink_cls_new); + else + bfr.Del_by_1(); + return rv; + } private static final byte[] Redlink_cls_new = Bry_.new_ascii_("class='new'"); public static final Bry_fmtr fmtr_img = Bry_fmtr.new_("src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h"); private static final Btrie_slim_mgr trie = Hdump_html_consts.trie_(); } diff --git a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr_tst.java b/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr_tst.java index 54a7062ed..08438396d 100644 --- a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr_tst.java @@ -101,7 +101,7 @@ public class Hdump_html_mgr_tst { } } class Hdump_html_mgr_fxt { - private Hdump_html_mgr html_mgr; + private Hdump_html_body html_mgr; private Bry_bfr bfr = Bry_bfr.reset_(255); private ListAdp img_list = ListAdp_.new_(); private Xow_wiki wiki; @@ -139,7 +139,7 @@ class Hdump_html_mgr_fxt { } public Hdump_html_mgr_fxt Test_html(String expd) { if (img_list.Count() > 0) hpg.Img_itms_((Hdump_data_img__base[])img_list.XtoAryAndClear(Hdump_data_img__base.class)); - html_mgr.Write(bfr, wiki, hpg); + html_mgr.Init_by_page(wiki.Domain_bry(), hpg).Write(bfr); Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear()); return this; } diff --git a/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr.java b/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr.java index 543d25e22..f46f53444 100644 --- a/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr.java +++ b/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr.java @@ -16,17 +16,21 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; -import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; -import gplx.xowa.pages.skins.*; +import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; +import gplx.xowa.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.skins.*; public class Hdump_load_mgr { - private Xodb_hdump_mgr hdump_mgr; private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private Bry_rdr rdr = new Bry_rdr(); // private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr(); - private ListAdp tmp_rows = ListAdp_.new_(), img_itms = ListAdp_.new_(); - public Hdump_load_mgr(Xodb_hdump_mgr hdump_mgr) {this.hdump_mgr = hdump_mgr;} + private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private Bry_rdr rdr = new Bry_rdr(); // private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr(); + private ListAdp tmp_rows = ListAdp_.new_(), img_itms = ListAdp_.new_(); + public Hdump_load_mgr() {} public byte Zip_tid() {return zip_tid;} public void Zip_tid_(byte v) {zip_tid = v;} private byte zip_tid = gplx.ios.Io_stream_.Tid_file; - public void Load(Hdump_page hpg, int page_id, Xoa_url page_url) { - Db_provider provider = hdump_mgr.Db_provider_by_page(page_id); + public void Load2(Hdump_page hpg, Db_provider provider, int page_id) { text_tbl.Provider_(provider).Select_by_page(tmp_rows, page_id); - Load_rows(hpg, page_id, page_url, tmp_rows); + Load_rows(hpg, page_id, Xoa_url.blank_(), tmp_rows); + } + public void Load(Hdump_page hpg, Xodb_fsys_mgr db_fsys_mgr, int html_db_id, int page_id) { + Db_provider provider = db_fsys_mgr.Get_by_idx(html_db_id).Provider(); + text_tbl.Provider_(provider).Select_by_page(tmp_rows, page_id); + Load_rows(hpg, page_id, hpg.Page_url(), tmp_rows); } public void Load_rows(Hdump_page hpg, int page_id, Xoa_url page_url, ListAdp rows) { hpg.Init(page_id, page_url); @@ -46,7 +50,7 @@ public class Hdump_load_mgr { while (!rdr.Pos_is_eos()) { int tid = rdr.Read_int_to_pipe(); switch (tid) { - case Hdump_data_tid.Tid_img : Load_data_img(); break; // 1|0|220|110|A.png|commons/7/0/orig/A.png + case Hdump_data_tid.Tid_img : Load_data_img(); break; // 1|0|A.png|0|220|110|... case Hdump_data_tid.Tid_gallery : Load_data_gallery(hpg); break; // 3|0|800 case Hdump_data_tid.Tid_redlink : Load_data_redlink(hpg); break; // 2|2|0|1 } diff --git a/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr_tst.java b/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr_tst.java index 849f5e0b9..31a2fa779 100644 --- a/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/hdumps/loads/Hdump_load_mgr_tst.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; -import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.pages.*; +import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.dbs.*; public class Hdump_load_mgr_tst { @Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt(); @Test public void Body() { @@ -50,7 +50,7 @@ class Hdump_load_mgr_fxt { private ListAdp expd_imgs = ListAdp_.new_(); private int page_id = 0; private Xoa_url page_url; public void Clear() { - load_mgr = new Hdump_load_mgr(null); + load_mgr = new Hdump_load_mgr(); load_mgr.Zip_tid_(gplx.ios.Io_stream_.Tid_file); init_rows.Clear(); expd_body = expd_display_ttl = expd_content_sub = expd_sidebar_div = null; diff --git a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java index cadf18f9a..0bfd60a98 100644 --- a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java +++ b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java @@ -139,23 +139,3 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr { public static final Xoh_file_html_fmtr__base Base = new Xoh_file_html_fmtr__base(); } -class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base { - private Bry_bfr tmp_bfr = Bry_bfr.reset_(128); - @gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();} - @Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) { - tmp_bfr.Add(Hdump_html_consts.Key_img_style); - tmp_bfr.Add_int_variable(uid); - tmp_bfr.Add_byte_apos(); - byte[] div2_width_repl = tmp_bfr.XtoAryAndClear(); - fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content); - } - @Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_mgnf, uid);} - @Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_info, uid);} - @Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_play, uid);} - public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) { - bfr.Add(key); - bfr.Add_int_variable(uid); - bfr.Add(Bry_xnde_end); - } private static final byte[] Bry_xnde_end = Bry_.new_ascii_("'/>"); - public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {} -} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__hdump.java b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__hdump.java new file mode 100644 index 000000000..ff87b76e6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__hdump.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; +import gplx.xowa.files.*; import gplx.xowa.hdumps.htmls.*; +public class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base { + private Bry_bfr tmp_bfr = Bry_bfr.reset_(128); + @gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();} + @Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) { + tmp_bfr.Add(Hdump_html_consts.Key_img_style); + tmp_bfr.Add_int_variable(uid); + tmp_bfr.Add_byte_apos(); + byte[] div2_width_repl = tmp_bfr.XtoAryAndClear(); + fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content); + } + @Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_mgnf, uid);} + @Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_info, uid);} + @Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_play, uid);} + public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) { + bfr.Add(key); + bfr.Add_int_variable(uid); + bfr.Add(Bry_xnde_end); + } private static final byte[] Bry_xnde_end = Bry_.new_ascii_("'/>"); + public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {} +} diff --git a/400_xowa/src/gplx/xowa/html/portal/Xoa_available_wikis_mgr.java b/400_xowa/src/gplx/xowa/html/portal/Xoa_available_wikis_mgr.java index 59e9e09a9..5b2fb096c 100644 --- a/400_xowa/src/gplx/xowa/html/portal/Xoa_available_wikis_mgr.java +++ b/400_xowa/src/gplx/xowa/html/portal/Xoa_available_wikis_mgr.java @@ -30,6 +30,7 @@ public class Xoa_available_wikis_mgr implements GfoInvkAble { for (int i = 0; i < len; i++) { Xow_xwiki_itm itm = xwiki_mgr.Get_at(i); if (itm.Wiki_tid() == Xow_wiki_domain_.Tid_home) continue;// don't show home wiki + if (!itm.Offline()) continue; // only show items marked Offline (added by Available_from_fsys); DATE:2014-09-21 itms_as_html_fmtr.Bld_bfr_many(tmp_bfr, itm.Domain(), itm_cls); } itms_as_html = tmp_bfr.XtoStr(); diff --git a/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java b/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java index 318d4eb64..5783ba2a8 100644 --- a/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java +++ b/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java @@ -63,6 +63,7 @@ public class Http_server_mgr implements GfoInvkAble { } public Xoa_app App() {return app;} private Xoa_app app; public int Port() {return port;} public Http_server_mgr Port_(int v) {port = v; return this;} private int port = 8080; + public String Home() {return home;} public void Home_(String v) {home = v;} private String home = "home/wiki/Main_Page"; private boolean init_gui_done = false; private void Init_gui() { // create a shim gui to automatically handle default XOWA gui JS calls if (init_gui_done) return; @@ -78,7 +79,7 @@ public class Http_server_mgr implements GfoInvkAble { Xoa_ttl ttl = Xoa_ttl.parse_(wiki, page_ttl); // get the ttl Xoa_page page = wiki.GetPageByTtl(page_url, ttl); // get page and parse it if (app.Gui_mgr().Browser_win().Active_tab() == null) // no active tab - app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(); // create at least one active tab; DATE:2014-07-30 + app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(page); // create at least one active tab; DATE:2014-07-30 app.Gui_mgr().Browser_win().Active_page_(page); // HACK: init gui_mgr's page for output (which server ordinarily doesn't need) if (page.Missing()) { // if page does not exist, replace with message; else null_ref error; DATE:2014-03-08 page.Data_raw_(Bry_.new_ascii_("'''Page not found.'''")); @@ -218,8 +219,7 @@ class HttpRequest implements Runnable{ if(!req.contains("%file%")){ if(req.equals("/")){ - req+="home/wiki/Main_Page"; //Forward to main page - /*Maybe add here a address from a config file, so that a custom main page could be defined*/ + req += app.Http_server().Home(); } if(req.endsWith("wiki/")) req+="Main_Page"; if(req.endsWith("wiki")) req+="/Main_Page"; diff --git a/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java b/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java index d7e80d959..ee50ca53f 100644 --- a/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java +++ b/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java @@ -41,65 +41,65 @@ public class Wmf_dump_list_parser_tst { , fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56") ); } - @Test public void Update() { // 2014-07-06 - Hash_adp_bry excluded_domains = Hash_adp_bry.cs_().Add_many_str - ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org" - , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org" - , "strategy.wikipedia.org", "ten.wikipedia.org", "test2.wikipedia.org", "test.wikipedia.org" - , "usability.wikipedia.org", "vote.wikipedia.org"); - Wmf_dump_itm[] itms = new Wmf_dump_list_parser().Parse(Io_mgr._.LoadFilBry("C:\\xowa\\bin\\any\\html\\xowa\\maint\\backup-index.html")); - Array_.Sort(itms); - Bry_bfr sql_bfr = Bry_bfr.new_(); - Bry_bfr bld_bfr = Bry_bfr.new_(); - int itms_len = itms.length; - int counter = 1; - for (int i = 0; i < itms_len; i++) { - Wmf_dump_itm itm = itms[i]; - byte[] abrv = itm.Wiki_abrv(); - if (Bry_.Eq(abrv, Bry_.new_ascii_("testwikidatawiki"))) continue; - byte[] domain_bry = Xob_bz2_file.Parse__domain_name(abrv, 0, abrv.length); - if (domain_bry == null) continue; // not a standard WMF wiki; ignore - if (Bry_finder.Find_fwd(domain_bry, Bry_.new_ascii_("wikimania")) != Bry_.NotFound) continue; - if (excluded_domains.Has(domain_bry)) continue; - Xow_wiki_domain domain_itm = Xow_wiki_domain_.parse_by_domain(domain_bry); - byte[] tid_name = Xto_display_name(Xow_wiki_domain_.Key_by_tid(domain_itm.Tid())); - sql_bfr - .Add_byte(Byte_ascii.Paren_bgn) - .Add_int_variable(counter++) - .Add_byte(Byte_ascii.Comma) - .Add_int_variable(1) - .Add_byte(Byte_ascii.Comma) - .Add_byte(Byte_ascii.Apos) - .Add(domain_itm.Lang_orig()) - .Add_byte(Byte_ascii.Apos) - .Add_byte(Byte_ascii.Comma) - .Add_byte(Byte_ascii.Apos) - .Add(tid_name) - .Add_byte(Byte_ascii.Apos) - .Add_byte(Byte_ascii.Paren_end) - .Add_byte(Byte_ascii.Comma) - .Add_str("--" + String_.new_utf8_(abrv)) - .Add_byte_nl() - ; - bld_bfr - .Add_byte(Byte_ascii.Comma) - .Add_byte(Byte_ascii.Space) - .Add_byte(Byte_ascii.Quote) - .Add(domain_bry) - .Add_byte(Byte_ascii.Quote) - .Add_byte_nl() - ; - } - Io_url temp = Io_url_.new_fil_("C:\\import_update.txt"); - Io_mgr._.SaveFilBfr(temp, sql_bfr); -// Io_mgr._.AppendFilBfr(temp, bld_bfr); - } - private static byte[] Xto_display_name(byte[] v) { - if (Bry_.Eq(v, Xow_wiki_domain_.Key_wikimediafoundation_bry)) return Bry_.new_ascii_("Wikimedia Foundation"); - else if (Bry_.Eq(v, Xow_wiki_domain_.Key_species_bry)) return Bry_.new_ascii_("Wikispecies"); - else if (Bry_.Eq(v, Xow_wiki_domain_.Key_mediawiki_bry)) return Bry_.new_ascii_("MediaWiki"); - else return Bry_.Add(Byte_ascii.Case_upper(v[0]), Bry_.Mid(v, 1, v.length)); - } +// @Test public void Update() { // 2014-07-06 +// Hash_adp_bry excluded_domains = Hash_adp_bry.cs_().Add_many_str +// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org" +// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org" +// , "strategy.wikipedia.org", "ten.wikipedia.org", "test2.wikipedia.org", "test.wikipedia.org" +// , "usability.wikipedia.org", "vote.wikipedia.org"); +// Wmf_dump_itm[] itms = new Wmf_dump_list_parser().Parse(Io_mgr._.LoadFilBry("C:\\xowa\\bin\\any\\html\\xowa\\maint\\backup-index.html")); +// Array_.Sort(itms); +// Bry_bfr sql_bfr = Bry_bfr.new_(); +// Bry_bfr bld_bfr = Bry_bfr.new_(); +// int itms_len = itms.length; +// int counter = 1; +// for (int i = 0; i < itms_len; i++) { +// Wmf_dump_itm itm = itms[i]; +// byte[] abrv = itm.Wiki_abrv(); +// if (Bry_.Eq(abrv, Bry_.new_ascii_("testwikidatawiki"))) continue; +// byte[] domain_bry = Xob_bz2_file.Parse__domain_name(abrv, 0, abrv.length); +// if (domain_bry == null) continue; // not a standard WMF wiki; ignore +// if (Bry_finder.Find_fwd(domain_bry, Bry_.new_ascii_("wikimania")) != Bry_.NotFound) continue; +// if (excluded_domains.Has(domain_bry)) continue; +// Xow_wiki_domain domain_itm = Xow_wiki_domain_.parse_by_domain(domain_bry); +// byte[] tid_name = Xto_display_name(Xow_wiki_domain_.Key_by_tid(domain_itm.Tid())); +// sql_bfr +// .Add_byte(Byte_ascii.Paren_bgn) +// .Add_int_variable(counter++) +// .Add_byte(Byte_ascii.Comma) +// .Add_int_variable(1) +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Apos) +// .Add(domain_itm.Lang_orig()) +// .Add_byte(Byte_ascii.Apos) +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Apos) +// .Add(tid_name) +// .Add_byte(Byte_ascii.Apos) +// .Add_byte(Byte_ascii.Paren_end) +// .Add_byte(Byte_ascii.Comma) +// .Add_str("--" + String_.new_utf8_(abrv)) +// .Add_byte_nl() +// ; +// bld_bfr +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Space) +// .Add_byte(Byte_ascii.Quote) +// .Add(domain_bry) +// .Add_byte(Byte_ascii.Quote) +// .Add_byte_nl() +// ; +// } +// Io_url temp = Io_url_.new_fil_("C:\\import_update.txt"); +// Io_mgr._.SaveFilBfr(temp, sql_bfr); +//// Io_mgr._.AppendFilBfr(temp, bld_bfr); +// } +// private static byte[] Xto_display_name(byte[] v) { +// if (Bry_.Eq(v, Xow_wiki_domain_.Key_wikimediafoundation_bry)) return Bry_.new_ascii_("Wikimedia Foundation"); +// else if (Bry_.Eq(v, Xow_wiki_domain_.Key_species_bry)) return Bry_.new_ascii_("Wikispecies"); +// else if (Bry_.Eq(v, Xow_wiki_domain_.Key_mediawiki_bry)) return Bry_.new_ascii_("MediaWiki"); +// else return Bry_.Add(Byte_ascii.Case_upper(v[0]), Bry_.Mid(v, 1, v.length)); +// } } class Wmf_dump_list_parser_fxt { public void Clear() {} diff --git a/400_xowa/src/gplx/xowa/specials/Xoa_special_mgr.java b/400_xowa/src/gplx/xowa/specials/Xoa_special_mgr.java index d5f3f992f..5b7377ef2 100644 --- a/400_xowa/src/gplx/xowa/specials/Xoa_special_mgr.java +++ b/400_xowa/src/gplx/xowa/specials/Xoa_special_mgr.java @@ -19,7 +19,7 @@ package gplx.xowa.specials; import gplx.*; import gplx.xowa.*; public class Xoa_special_mgr implements GfoInvkAble { private OrderedHash hash = OrderedHash_.new_(); public Xoa_special_mgr() { - hash.Add(gplx.xowa.xtns.wdatas.Wdata_itemByTitle_cfg.Key, new gplx.xowa.xtns.wdatas.Wdata_itemByTitle_cfg()); + hash.Add(gplx.xowa.xtns.wdatas.specials.Wdata_itemByTitle_cfg.Key, new gplx.xowa.xtns.wdatas.specials.Wdata_itemByTitle_cfg()); } public void Add(String key, GfoInvkAble cfg) {hash.Add(key, cfg);} public GfoInvkAble Get_or_null(String key) {return (GfoInvkAble)hash.Fetch(key);} diff --git a/400_xowa/src/gplx/xowa/specials/Xows_mgr.java b/400_xowa/src/gplx/xowa/specials/Xows_mgr.java index 299ae45d0..4e1abfecb 100644 --- a/400_xowa/src/gplx/xowa/specials/Xows_mgr.java +++ b/400_xowa/src/gplx/xowa/specials/Xows_mgr.java @@ -20,7 +20,7 @@ import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.specials.allPages.*; import gplx.xowa.specials.search.*; import gplx.xowa.specials.nearby.*; import gplx.xowa.specials.randoms.*; import gplx.xowa.specials.statistics.*; import gplx.xowa.xtns.translates.*; import gplx.xowa.specials.movePage.*; import gplx.xowa.specials.xowa.system_data.*; import gplx.xowa.specials.xowa.default_tab.*; import gplx.xowa.specials.xowa.popup_history.*; -import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.specials.*; public class Xows_mgr { private Hash_adp_bry hash; public Xows_mgr(Xow_wiki wiki, Xol_lang lang) { diff --git a/400_xowa/src/gplx/xowa/users/Xou_user.java b/400_xowa/src/gplx/xowa/users/Xou_user.java index 5bb7c90c2..343c89b2e 100644 --- a/400_xowa/src/gplx/xowa/users/Xou_user.java +++ b/400_xowa/src/gplx/xowa/users/Xou_user.java @@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.users; import gplx.*; import gplx.xowa.*; -import gplx.xowa.users.dbs.*; -import gplx.xowa.wikis.*; import gplx.xowa.users.history.*; import gplx.xowa.xtns.scribunto.*; +import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.users.dbs.*; import gplx.xowa.users.history.*; import gplx.xowa.xtns.scribunto.*; public class Xou_user implements GfoInvkAble { public Xou_user(Xoa_app app, Io_url user_dir) { this.app = app; this.key_str = user_dir.NameOnly(); key_bry = Bry_.new_utf8_(key_str); @@ -53,8 +52,10 @@ public class Xou_user implements GfoInvkAble { public void Init_by_app() { Io_url user_system_cfg = fsys_mgr.App_data_cfg_dir().GenSubFil(Xou_fsys_mgr.Name_user_system_cfg); if (!Io_mgr._.ExistsFil(user_system_cfg)) Xou_user_.User_system_cfg_make(app.Usr_dlg(), user_system_cfg); - if (!Env_.Mode_testing()) + if (!Env_.Mode_testing()) { db_mgr.App_init(); + this.Available_from_fsys(); + } } public void App_term() { session_mgr.Window_mgr().Save_window(app.Gui_mgr().Browser_win().Win_box()); @@ -105,7 +106,9 @@ public class Xou_user implements GfoInvkAble { // || !Io_mgr._.ExistsDir(dir.GenSubFil_nest("ns")) ) continue; byte[] dir_name_as_bry = Bry_.new_utf8_(name); - Available_add(usr_wiki, dir_name_as_bry); + Xow_xwiki_itm xwiki = Available_add(usr_wiki, dir_name_as_bry); + if (xwiki != null) // Add_full can return null if adding invalid lang; should not apply here, but guard against null ref + xwiki.Offline_(true); // mark xwiki as offline; needed for available wikis sidebar; DATE:2014-09-21 app.Setup_mgr().Maint_mgr().Wiki_mgr().Add(dir_name_as_bry); } } @@ -116,5 +119,7 @@ public class Xou_user implements GfoInvkAble { for (int i = 0; i < wikis_len; i++) Available_add(usr_wiki, wikis[i]); } - private void Available_add(Xow_wiki usr_wiki, byte[] wiki_name) {usr_wiki.Xwiki_mgr().Add_full(wiki_name, wiki_name);} + private Xow_xwiki_itm Available_add(Xow_wiki usr_wiki, byte[] wiki_name) { + return usr_wiki.Xwiki_mgr().Add_full(wiki_name, wiki_name); + } } diff --git a/400_xowa/src/gplx/xowa/users/Xou_user_tst.java b/400_xowa/src/gplx/xowa/users/Xou_user_tst.java index f28a7d6df..ab38ec894 100644 --- a/400_xowa/src/gplx/xowa/users/Xou_user_tst.java +++ b/400_xowa/src/gplx/xowa/users/Xou_user_tst.java @@ -16,19 +16,41 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.users; import gplx.*; import gplx.xowa.*; -import org.junit.*; +import org.junit.*; import gplx.xowa.wikis.xwikis.*; public class Xou_user_tst { - @Test public void Run() { - Xoa_app app = Xoa_app_fxt.app_(); + private Xou_user_fxt fxt = new Xou_user_fxt(); + @Test public void Run() { Io_url user_system_cfg_url = Io_url_.mem_fil_("mem/xowa/user/test_user/app/data/cfg/user_system_cfg.gfs"); - Fil_tst(user_system_cfg_url, ""); // check that it is blank - app.Init(); // run Init - Fil_tst(user_system_cfg_url, Xou_user_.User_system_cfg_text); // check that it is created - Io_mgr._.SaveFilStr(user_system_cfg_url, ""); // simulate edit by blanking out file - app.Init(); // run Init again - Fil_tst(user_system_cfg_url, ""); // check that it is still blank + fxt.Test_fil(user_system_cfg_url, ""); // check that it is blank + fxt.App().Init(); // run Init + fxt.Test_fil(user_system_cfg_url, Xou_user_.User_system_cfg_text); // check that it is created + Io_mgr._.SaveFilStr(user_system_cfg_url, ""); // simulate edit by blanking out file + fxt.App().Init(); // run Init again + fxt.Test_fil(user_system_cfg_url, ""); // check that it is still blank } - private void Fil_tst(Io_url url, String expd) { - Tfds.Eq_str_lines(expd, Io_mgr._.LoadFilStr(url)); + @Test public void Available_from_fsys() { + Io_mgr._.CreateDir(fxt.App().Fsys_mgr().Wiki_dir().GenSubDir("en.wikipedia.org")); + fxt.App().User().Available_from_fsys(); + fxt.Test_xwikis + ( fxt.Make_xwiki(Bool_.N, "home") + , fxt.Make_xwiki(Bool_.Y, "en.wikipedia.org") // available_from_fsys should mark as offline=y + ); + } +} +class Xou_user_fxt { + public Xoa_app App() {return app;} private Xoa_app app = Xoa_app_fxt.app_(); + public String Make_xwiki(boolean offline, String name) {return String_.Concat_with_str("|", Yn.Xto_str(offline), name);} + public void Test_fil(Io_url url, String expd) { + Tfds.Eq_str_lines(expd, Io_mgr._.LoadFilStr(url)); + } + public void Test_xwikis(String... expd) { + Xow_xwiki_mgr xwiki_mgr = app.User().Wiki().Xwiki_mgr(); + int len = xwiki_mgr.Len(); + String[] actl = new String[len]; + for (int i = 0; i < len; ++i) { + Xow_xwiki_itm xwiki_itm = xwiki_mgr.Get_at(i); + actl[i] = Make_xwiki(xwiki_itm.Offline(), String_.new_utf8_(xwiki_itm.Name())); + } + Tfds.Eq_ary_str(expd, actl); } } diff --git a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java index 6d9f4327f..f22bb820a 100644 --- a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java @@ -18,6 +18,7 @@ along with this program. If not, see . package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; public class Xow_xwiki_mgr implements GfoInvkAble { private Xow_xwiki_mgr_srl srl; + public Xow_xwiki_mgr() {} // FIXME: current placeholder for viewer public Xow_xwiki_mgr(Xow_wiki wiki) {this.wiki = wiki; srl = new Xow_xwiki_mgr_srl(this);} public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki; public Xow_lang_mgr Lang_mgr() {return lang_mgr;} private Xow_lang_mgr lang_mgr = Xow_lang_mgr.dflt_(); @@ -26,20 +27,21 @@ public class Xow_xwiki_mgr implements GfoInvkAble { public Xow_xwiki_itm Get_at(int i) {return (Xow_xwiki_itm)list.FetchAt(i);} public Xow_xwiki_itm Get_by_key(byte[] key) {return (Xow_xwiki_itm)hash.Get_by_bry(key);} public Xow_xwiki_itm Get_by_mid(byte[] src, int bgn, int end) {return (Xow_xwiki_itm)hash.Get_by_mid(src, bgn, end);} - public void Add_full(String alias, String domain) {Add_full(Bry_.new_ascii_(alias), Bry_.new_ascii_(domain), null);} - public void Add_full(byte[] alias, byte[] domain) {Add_full(alias, domain, null);} - public void Add_full(byte[] alias, byte[] domain, byte[] fmt) { + public Xow_xwiki_itm Add_full(String alias, String domain) {return Add_full(Bry_.new_ascii_(alias), Bry_.new_ascii_(domain), null);} + public Xow_xwiki_itm Add_full(byte[] alias, byte[] domain) {return Add_full(alias, domain, null);} + public Xow_xwiki_itm Add_full(byte[] alias, byte[] domain, byte[] fmt) { byte wiki_tid = Byte_.Zero; int lang_tid = -1; Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(domain); wiki_tid = wiki_type.Tid(); if (Bry_.Len_gt_0(wiki_type.Lang())) { // domain has lang (EX: "en.") Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang()); - if (lang_itm == null) return; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org + if (lang_itm == null) return null; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org lang_tid = lang_itm.Id(); } Xow_xwiki_itm itm = new Xow_xwiki_itm(alias, fmt, wiki_tid, lang_tid, domain); Add_itm(itm, null); + return itm; } public void Sort_by_key() { list.Sort(); diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java index b9a1da32e..1d9b41aee 100644 --- a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.xowa.wikis.*; import gplx.xowa.html.modules.*; +import gplx.xowa.wikis.*; import gplx.xowa.html.modules.*; import gplx.xowa.apps.fsys.*; public class Hiero_xtn_mgr extends Xox_mgr_base implements GfoInvkAble { @Override public boolean Enabled_default() {return true;} @Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_ascii_("hiero"); @@ -28,7 +28,7 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements GfoInvkAble { if (xtn_init_done) return; if (!Enabled()) return; Xoa_app app = wiki.App(); - Io_url ext_root_dir = Hiero_root_dir(app); + Io_url ext_root_dir = Hiero_root_dir(app.Fsys_mgr()); Img_src_dir = Bry_.new_utf8_(ext_root_dir.GenSubDir("img").To_http_file_str()); app.Gfs_mgr().Run_url_for(this, ext_root_dir.GenSubFil_nest("data", "tables.gfs")); html_wtr = new Hiero_html_mgr(this); @@ -52,5 +52,5 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements GfoInvkAble { else return super.Invk(ctx, ikey, k, m); } public static final String Invk_prefabs = "prefabs", Invk_files = "files", Invk_phonemes = "phonemes"; - public static Io_url Hiero_root_dir(Xoa_app app) {return app.Fsys_mgr().Bin_xtns_dir().GenSubDir("Wikihiero");} + public static Io_url Hiero_root_dir(Xoa_fsys_mgr fsys_mgr) {return fsys_mgr.Bin_xtns_dir().GenSubDir("Wikihiero");} } diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/Pf_func_.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/Pf_func_.java index 64a8ceb9f..e2494231b 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/Pf_func_.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/Pf_func_.java @@ -349,9 +349,9 @@ public class Pf_func_ { case Xol_kwd_grp_.Id_lstx: return gplx.xowa.xtns.lst.Lst_pfunc_lstx._; case Xol_kwd_grp_.Id_invoke: return new gplx.xowa.xtns.scribunto.Scrib_invoke_func(); - case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wdatas.Wdata_pf_property(); - case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wdatas.Wdata_pf_noExternalLangLinks(); - case Xol_kwd_grp_.Id_wbreponame: return new gplx.xowa.xtns.wdatas.Wdata_pf_wbreponame(); + case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_property(); + case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_noExternalLangLinks(); + case Xol_kwd_grp_.Id_wbreponame: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_wbreponame(); case Xol_kwd_grp_.Id_mapSources_deg2dd: return gplx.xowa.xtns.mapSources.Map_deg2dd_func._; case Xol_kwd_grp_.Id_mapSources_dd2dms: return gplx.xowa.xtns.mapSources.Map_dd2dms_func._; diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexist_mgr.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexist_mgr.java index a03de57cc..c5caa524a 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexist_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexist_mgr.java @@ -52,13 +52,21 @@ public class Pfunc_ifexist_mgr { } private boolean Find_ttl_for_media_ns(Pfunc_ifexist_itm itm, Xow_wiki wiki, Xow_ns ns, byte[] ttl_bry) { Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); - boolean rv = Find_ttl_in_db(itm, wiki, file_ns, ttl_bry); if (rv) return true; // rarely true, but check first anyway + boolean rv = Find_ttl_in_db(itm, wiki, file_ns, ttl_bry); if (rv) return true; // rarely true, but check local wiki's [[File:]] table anyway Xow_wiki commons_wiki = wiki.App().Wiki_mgr().Wiki_commons(); - if (commons_wiki == null) - return wiki.File_mgr().Exists(ttl_bry); // user may not have commons_wiki; try to check files - else { + boolean env_is_testing = Env_.Mode_testing(); + if ( commons_wiki != null // null check + && ( commons_wiki.Init_assert().Db_mgr().Tid() == gplx.xowa.dbs.Xodb_mgr_sql.Tid_sql // make sure tid=sql; tid=txt automatically created for online images; DATE:2014-09-21 + || env_is_testing + ) + ) { file_ns = commons_wiki.Ns_mgr().Ns_file(); - return Find_ttl_in_db(itm, commons_wiki, file_ns, ttl_bry); // accurate test of whether or not Media file exists + return Find_ttl_in_db(itm, commons_wiki, file_ns, ttl_bry); // accurate test using page table in commons wiki (provided commons is up to date) + } + else { + if (!env_is_testing) + wiki.File_mgr().Fsdb_mgr().Init_by_wiki__add_bin_wkrs(wiki); // NOTE: must init Fsdb_mgr (else provider == null), and with bin_wkrs (else no images will ever load); DATE:2014-09-21 + return wiki.File_mgr().Exists(ttl_bry); // less-accurate test using either (1) orig_wiki table in local wiki (v2) or (2) meta_db_mgr (v1) } } } diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_filepath.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_filepath.java index 45fd6a601..c75e80361 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_filepath.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_filepath.java @@ -25,7 +25,7 @@ public class Pfunc_filepath extends Pf_func_base { byte[] val_ary = Eval_argx(ctx, src, caller, self); if (val_ary == Bry_.Empty) return; Xow_wiki wiki = ctx.Wiki(); val_ary = Bry_.Add(Bry_file, val_ary); - Xoa_ttl ttl = Xoa_ttl.new_(wiki, ctx.App().Msg_log_null(), val_ary, val_ary, 0, val_ary.length); if (ttl == null) return; // text is not valid ttl; return; + Xoa_ttl ttl = Xoa_ttl.new_(wiki, ctx.App().Msg_log_null(), val_ary, 0, val_ary.length); if (ttl == null) return; // text is not valid ttl; return; Xoa_page page = Load_page(wiki, ttl); if (page.Missing()) return; // page not found in commons; exit; byte[] ttl_bry = page.Ttl().Page_url(); diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_titleparts.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_titleparts.java index 2e58672cc..34ee2d273 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_titleparts.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_titleparts.java @@ -23,7 +23,7 @@ public class Pfunc_titleparts extends Pf_func_base { // get argx int args_len = self.Args_len(); byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return; // no argx; return empty - Xoa_ttl argx_as_ttl = Xoa_ttl.new_(ctx.Wiki(), ctx.App().Msg_log_null(), argx, argx, 0, argx.length); // transform to title in order to upper first, replace _, etc.. + Xoa_ttl argx_as_ttl = Xoa_ttl.new_(ctx.Wiki(), ctx.App().Msg_log_null(), argx, 0, argx.length); // transform to title in order to upper first, replace _, etc.. if (argx_as_ttl == null) {bb.Add(argx); return;} // NOTE: argx_as_ttl will be null if invalid, such as [[a|b]]; PAGE:en.w:owl and {{taxobox/showtaxon|Dinosauria}} else argx = argx_as_ttl.Full_txt(); diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlfunc.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlfunc.java index 5bc5546eb..12a2d1d80 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlfunc.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlfunc.java @@ -26,7 +26,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a } public static void UrlString(Xop_ctx ctx, byte tid, boolean encode, byte[] src, Bry_bfr trg, byte[] qry_arg) { Xow_wiki wiki = ctx.Wiki(); - Xoa_ttl ttl = Xoa_ttl.new_(wiki, ctx.Msg_log(), src, src, 0, src.length); + Xoa_ttl ttl = Xoa_ttl.new_(wiki, ctx.Msg_log(), src, 0, src.length); if (ttl == null) return; // NOTE: guard against null ttl; EX: {{fullurl:{{transclude|{{{1}}}}}|action=edit}} -> {{fullurl:Template:{{{1}}}|action=edit}} -> Template:{{{1}}} will be a null ttl byte[] ttl_ary = ttl.Full_url();// NOTE: Full_url does encoding; don't encode again Xow_xwiki_itm xwiki = ttl.Wik_itm(); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_fxt.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_fxt.java index 17f0ad4ab..588d0c6c2 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_fxt.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_fxt.java @@ -120,22 +120,22 @@ public class Scrib_core_fxt { else this.Expd_server_rcvd_add("000000380000006F{[\"op\"]=\"return\",[\"nvalues\"]=1,[\"values\"]={[1]=\"" + expd + "\"}}"); this.Init_server_prep_add("a:2:{s:6:\"values\";a:1:{i:1;s:6:\"ignore\";}s:2:\"op\";s:6:\"return\";}"); - core.Frame_current_(Xot_invk_mock.new_(args)); + core.Frame_current_(Xot_invk_mock.new_(Frame_ttl_test, args)); core.Interpreter().ExecuteModule(9); Test_server_logs(); return this; } public Scrib_core_fxt Test_GetAllExpandedArguments(KeyVal... args) { - core.Frame_current_(Xot_invk_mock.new_(args)); + core.Frame_current_(Xot_invk_mock.new_(Frame_ttl_test, args)); core.Interpreter().ExecuteModule(9); Test_server_logs(); return this; } public Scrib_core_fxt Test_Invoke(String mod_name, String mod_code, String prc_name, KeyVal... args) { - core.Invoke(wiki, core.Ctx(), Bry_.Empty, Xot_invk_mock.Null, Xot_invk_mock.new_(args), tmp_bfr, Bry_.new_utf8_(mod_name), Bry_.new_utf8_(mod_code), Bry_.new_utf8_(prc_name)); + core.Invoke(wiki, core.Ctx(), Bry_.Empty, Xot_invk_mock.Null, Xot_invk_mock.new_(Frame_ttl_test, args), tmp_bfr, Bry_.new_utf8_(mod_name), Bry_.new_utf8_(mod_code), Bry_.new_utf8_(prc_name)); Test_server_logs(); return this; - } + } private static final byte[] Frame_ttl_test = Bry_.new_ascii_("test"); private void Test_server_logs() { if (expd_server_rcvd_list.Count() > 0) { Tfds.Eq_ary_str(expd_server_rcvd_list.XtoStrAry(), server.Log_rcvd().XtoStrAry()); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_frame_.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_frame_.java index 7cfa01378..9b7d28e97 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_frame_.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_frame_.java @@ -27,7 +27,7 @@ public class Scrib_frame_ { public static Xot_invk Get_frame(Scrib_core core, String frame_id) { if (String_.Eq(frame_id, "current")) return core.Frame_current(); else if (String_.Eq(frame_id, "parent")) return core.Frame_parent(); - else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, KeyVal_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12 + else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, null, KeyVal_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12 else { return (Xot_invk)core.Frame_created_list().Fetch(frame_id); // NOTE: can return null; some calls expect nil; EX:mw.lua and "currentFrame = newFrame( 'empty' )"; DATE:2014-07-12 } diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func_fxt.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func_fxt.java index bcabb9854..dc20c4729 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func_fxt.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func_fxt.java @@ -103,19 +103,17 @@ public class Scrib_invoke_func_fxt { Tfds.Eq(expd, (String)server.Log_rcvd().FetchAt(i)); } public void Init_frame_parent(String ttl, KeyVal... ary) { - core.Frame_parent_(Xot_invk_mock.test_(ary)); - core.Frame_parent().Frame_ttl_(Bry_.new_utf8_(ttl)); + core.Frame_parent_(Xot_invk_mock.test_(Bry_.new_utf8_(ttl), ary)); } public void Init_frame_current(KeyVal... ary) { - core.Frame_current_(Xot_invk_mock.test_(ary)); - core.Frame_current().Frame_ttl_(Bry_.new_ascii_("Module:Mod_0")); + core.Frame_current_(Xot_invk_mock.test_(Bry_.new_ascii_("Module:Mod_0"), ary)); } public void Clear_for_lib() { fxt = new Xop_fxt(); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib core_fxt = new Scrib_core_fxt(fxt); core = core_fxt.Core(); Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null); - Xot_invk current_frame = Xot_invk_mock.test_(); current_frame.Frame_ttl_(Bry_.new_ascii_("Module:Mod_0")); + Xot_invk current_frame = Xot_invk_mock.test_(Bry_.new_ascii_("Module:Mod_0")); core.Invoke_init(core.Wiki(), core.Ctx(), Bry_.Empty, parent_frame, current_frame); core.When_page_changed(fxt.Page()); } diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_mw.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_mw.java index b3f136673..87d5ca042 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_mw.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_mw.java @@ -227,7 +227,7 @@ public class Scrib_lib_mw implements Scrib_lib { String val = tmp_bfr.XtoStrAndClear(); kv_args[i] = KeyVal_.new_(key, val); } - Xot_invk_mock mock_frame = Xot_invk_mock.new_(kv_args); + Xot_invk_mock mock_frame = Xot_invk_mock.new_(Bry_.new_utf8_(frame_id), kv_args); // use frame_id for Frame_ttl; in lieu of a better candidate; DATE:2014-09-21 tmp_ctx.Parse_tid_(Xop_parser_.Parse_tid_page_tmpl); // default xnde names to template; needed for test, but should be in place; DATE:2014-06-27 cur_wiki.Parser().Parse_text_to_wtxt(tmp_root, tmp_ctx, tmp_ctx.Tkn_mkr(), text_bry); tmp_root.Tmpl_evaluate(tmp_ctx, text_bry, mock_frame, tmp_bfr); @@ -242,7 +242,7 @@ public class Scrib_lib_mw implements Scrib_lib { Bry_obj_ref argx_ref = Bry_obj_ref.null_(); Bry_obj_ref fnc_name_ref = Bry_obj_ref.new_(fnc_name); KeyVal[] parser_func_args = CallParserFunction_parse_args(cur_wiki.App().Utl_num_parser(), argx_ref, fnc_name_ref, args.Ary()); - Xot_invk_mock frame = Xot_invk_mock.new_(parent_frame.Defn_tid(), 0, parser_func_args); + Xot_invk_mock frame = Xot_invk_mock.new_(parent_frame.Defn_tid(), 0, fnc_name, parser_func_args); // pass something as frame_ttl; choosng fnc_name; DATE:2014-09-21 Xol_func_name_itm finder = cur_wiki.Lang().Func_regy().Find_defn(fnc_name, 0, fnc_name_len); Xot_defn defn = finder.Func(); if (defn == Xot_defn_.Null) throw Err_.new_fmt_("callParserFunction: function \"{0}\" was not found", String_.new_utf8_(fnc_name)); @@ -305,7 +305,7 @@ public class Scrib_lib_mw implements Scrib_lib { if (sub_src == null) // ttl is not in template cache, or is a ttl in non-Template ns; load title sub_src = core.Wiki().Cache_mgr().Page_cache().Get_or_load_as_src(ttl); if (sub_src != null) { - Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, args_ary); + Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-09-21 Xot_defn_tmpl transclude_tmpl = ctx.Wiki().Parser().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ttl.Ns(), ttl.Page_db(), sub_src); Bry_bfr sub_bfr = cur_wiki.Utl_bry_bfr_mkr().Get_k004(); transclude_tmpl.Tmpl_evaluate(ctx, sub_frame, sub_bfr); @@ -349,8 +349,7 @@ public class Scrib_lib_mw implements Scrib_lib { if (ttl == null) throw Err_.new_("newChild: invalid title; title={0}", (String)ttl_obj); } KeyVal[] args_ary = args.Pull_kv_ary(2); - Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, args_ary); - new_frame.Frame_ttl_(ttl.Full_txt()); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14 + Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14 String new_frame_id = "frame" + Int_.Xto_str(frame_list_len); frame_list.Add(new_frame_id, new_frame); return rslt.Init_obj(new_frame_id); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title.java index 920dc0b82..ff0d76487 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title.java @@ -40,16 +40,17 @@ public class Scrib_lib_title implements Scrib_lib { case Proc_fileExists: return FileExists(args, rslt); case Proc_getCurrentTitle: return GetCurrentTitle(args, rslt); case Proc_protectionLevels: return ProtectionLevels(args, rslt); + case Proc_cascadingProtection: return CascadingProtection(args, rslt); default: throw Err_.unhandled(key); } } - private static final int Proc_newTitle = 0, Proc_makeTitle = 1, Proc_getUrl = 2, Proc_getContent = 3, Proc_fileExists = 4, Proc_getCurrentTitle = 5, Proc_protectionLevels = 6; + private static final int Proc_newTitle = 0, Proc_makeTitle = 1, Proc_getUrl = 2, Proc_getContent = 3, Proc_fileExists = 4, Proc_getCurrentTitle = 5, Proc_protectionLevels = 6, Proc_cascadingProtection = 7; public static final String Invk_newTitle = "newTitle", Invk_makeTitle = "makeTitle" , Invk_getUrl = "getUrl", Invk_getContent = "getContent", Invk_fileExists = "fileExists", Invk_getCurrentTitle = "getCurrentTitle" - , Invk_protectionLevels = "protectionLevels" + , Invk_protectionLevels = "protectionLevels", Invk_cascadingProtection = "cascadingProtection" ; - private static final String[] Proc_names = String_.Ary(Invk_newTitle, Invk_makeTitle, Invk_getUrl, Invk_getContent, Invk_fileExists, Invk_getCurrentTitle, Invk_protectionLevels); + private static final String[] Proc_names = String_.Ary(Invk_newTitle, Invk_makeTitle, Invk_getUrl, Invk_getContent, Invk_fileExists, Invk_getCurrentTitle, Invk_protectionLevels, Invk_cascadingProtection); public boolean NewTitle(Scrib_proc_args args, Scrib_proc_rslt rslt) { byte[] ttl_bry = args.Pull_bry(0); Object ns_obj = args.Cast_obj_or_null(1); @@ -156,6 +157,13 @@ public class Scrib_lib_title implements Scrib_lib { // Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null); return rslt.Init_many_objs(""); // NOTE: always return no protection; protectionLevels are stored in different table which is currently not mirrored; DATE:2014-04-09 } + public boolean CascadingProtection(Scrib_proc_args args, Scrib_proc_rslt rslt) { + byte[] ttl_bry = args.Pull_bry(0); + Xow_wiki wiki = core.Wiki(); + Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null); + return rslt.Init_obj(CascadingProtection_rv); + } + public static final KeyVal[] CascadingProtection_rv = KeyVal_.Ary(KeyVal_.new_("sources", Bool_.N), KeyVal_.new_("restrictions", KeyVal_.Ary_empty)); private KeyVal[] Xto_kv_ary(Xoa_ttl ttl) { Xow_ns ns = ttl.Ns(); boolean ttl_exists = core.Wiki().Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, ttl.Ns(), ttl.Page_db()); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title_tst.java index 7b693d27d..a1e652135 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_title_tst.java @@ -75,6 +75,9 @@ public class Scrib_lib_title_tst { @Test public void ProtectionLevels() { fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_protectionLevels, Object_.Ary("A") , ""); } + @Test public void CascadingProtection() { + fxt.Test_scrib_proc_obj(lib, Scrib_lib_title.Invk_cascadingProtection, Object_.Ary("A") , Scrib_lib_title.CascadingProtection_rv); + } private static String ttl_data_(int ns_id, String ns_str, String ttl) {return ttl_data_(ns_id, ns_str, ttl, "", "", ttl);} private static String ttl_data_(int ns_id, String ns_str, String ttl, String anchor) {return ttl_data_(ns_id, ns_str, ttl, anchor, "", ttl);} private static String ttl_data_(int ns_id, String ns_str, String ttl, String anchor, String xwiki) {return ttl_data_(ns_id, ns_str, ttl, anchor, xwiki, ttl);} diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase.java index c042857c9..2270e6bb9 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase.java @@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; -import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Scrib_lib_wikibase implements Scrib_lib { public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core; public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod; @@ -47,11 +46,10 @@ public class Scrib_lib_wikibase implements Scrib_lib { boolean base_0 = args.Pull_bool(1); Xow_wiki wiki = core.Wiki(); Wdata_wiki_mgr wdata_mgr = wiki.App().Wiki_mgr().Wdata_mgr(); - Wdata_doc page_doc = wdata_mgr.Pages_get_by_ttl_name(ttl_bry); - if (page_doc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry); return rslt.Init_ary_empty();} - if (parser == null) parser = new Wdata_doc_parser(wiki.App().Usr_dlg()); - return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(parser, page_doc, true, base_0)); - } private Wdata_doc_parser parser; + Wdata_doc wdoc = wdata_mgr.Pages_get_by_ttl_name(ttl_bry); + if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry); return rslt.Init_ary_empty();} + return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, base_0)); + } public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) { byte[] ttl_bry = args.Pull_bry(0); Xow_wiki wiki = core.Wiki(); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity.java index 7ff688694..46d2403e3 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; public class Scrib_lib_wikibase_entity implements Scrib_lib { public Scrib_lib_wikibase_entity(Scrib_core core) {this.core = core;} private Scrib_core core; public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod; @@ -49,7 +49,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib { byte[] lang = wiki.Wdata_wiki_lang(); Wdata_doc wdoc = wdata_mgr.Pages_get(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13 int pid_int = wdata_mgr.Pids_get(lang, pid); if (pid_int == Wdata_wiki_mgr.Pid_null) return rslt.Init_str_empty(); - Wdata_prop_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty(); + Wdata_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty(); Bry_bfr bfr = app.Utl_bry_bfr_mkr().Get_b512(); wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang); return rslt.Init_obj(bfr.Mkr_rls().XtoAryAndClear()); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java index 6e3296ddf..749181e18 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java @@ -16,85 +16,74 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; -import gplx.json.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; class Scrib_lib_wikibase_srl { - public static KeyVal[] Srl(Wdata_doc_parser parser, Wdata_doc doc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua + public static KeyVal[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua int base_adj = legacy_style ? 0 : 1; ListAdp rv = ListAdp_.new_(); if (header_enabled) { - rv.Add(KeyVal_.new_("id", doc.Qid())); - rv.Add(KeyVal_.new_("type", Wdata_doc_consts.Val_ent_entity_type_item_str)); + rv.Add(KeyVal_.new_("id", wdoc.Qid())); + rv.Add(KeyVal_.new_("type", Wdata_dict_value_entity.Val_entity_type_item_str)); rv.Add(KeyVal_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua } - Json_itm_nde root = doc.Doc().Root(); - int len = root.Subs_len(); - for (int i = 0; i < len; i++) { - Json_itm_kv sub = (Json_itm_kv)root.Subs_get_at(i); - String key = sub.Key_as_str(); - if (String_.Eq(key, Wdata_doc_consts.Key_atr_label_str)) rv.Add(KeyVal_.new_("labels", Srl_nde_langs("language", "value", (Json_grp)sub.Val()))); - else if (String_.Eq(key, Wdata_doc_consts.Key_atr_description_str)) rv.Add(KeyVal_.new_("descriptions", Srl_nde_langs("language", "value", (Json_grp)sub.Val()))); - else if (String_.Eq(key, Wdata_doc_consts.Key_atr_links_str)) rv.Add(KeyVal_.new_("sitelinks", Srl_nde_sitelinks("site", "title", (Json_grp)sub.Val()))); - else if (String_.Eq(key, Wdata_doc_consts.Key_atr_aliases_str)) rv.Add(KeyVal_.new_("aliases", Srl_aliases((Json_grp)sub.Val(), base_adj))); - else if (String_.Eq(key, Wdata_doc_consts.Key_atr_claims_str)) rv.Add(KeyVal_.new_(Wdata_doc_consts.Key_atr_claims_str, Srl_claims(parser, doc.Doc().Src(), (Json_itm_ary)sub.Val(), legacy_style, base_adj))); - } + Srl_root(rv, Wdata_doc_parser_v2.Str_labels , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Label_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_descriptions , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Description_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_sitelinks , Srl_sitelinks (Wdata_dict_sitelink.Str_site , Wdata_dict_sitelink.Str_title, wdoc.Sitelink_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_aliases , Srl_aliases (base_adj, wdoc.Alias_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_claims , Srl_claims (base_adj, legacy_style, wdoc.Claim_list())); return (KeyVal[])rv.XtoAry(KeyVal.class); } - private static KeyVal[] Srl_nde_sitelinks(String key_label, String val_label, Json_grp grp) { - int len = grp.Subs_len(); + private static void Srl_root(ListAdp rv, String label, KeyVal[] ary) { + if (ary == null) return; // don't add node if empty; EX: labels:{} should not add "labels" kv + rv.Add(KeyVal_.new_(label, ary)); + } + private static KeyVal[] Srl_langtexts(String lang_label, String text_label, OrderedHash list) { + int len = list.Count(); if (len == 0) return null; KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Json_itm_kv sub = (Json_itm_kv)grp.Subs_get_at(i); - String lang = sub.Key_as_str(); // key is lang; EX: enwiki - Json_itm sub_val = sub.Val(); - Json_itm_kv sub_kv = null; - if (sub_val.Tid() == Json_itm_.Tid_nde) { // new fmt; EX: '"enwiki":{"name":"Earth", "badges":[]}'; DATE:2014-02-03 - Json_itm_nde sub_nde = (Json_itm_nde)sub.Val(); // key is nde; see EX: above - sub_kv = (Json_itm_kv)sub_nde.Subs_get_by_key(Wdata_doc_.Key_name); // get "name" sub - } - else // old fmt; EX: '"enwiki":"Earth"';DATE:2014-02-06 - sub_kv = sub; - Object description = sub_kv == null ? null : sub_kv.Val().Data(); // get val of "name"; EX: Earth - rv[i] = KeyVal_.new_(lang, KeyVal_.Ary(KeyVal_.new_(key_label, lang), KeyVal_.new_(val_label, description))); + Wdata_langtext_itm itm = (Wdata_langtext_itm)list.FetchAt(i); + String lang = String_.new_utf8_(itm.Lang()); + String text = String_.new_utf8_(itm.Text()); + rv[i] = KeyVal_.new_(lang, KeyVal_.Ary(KeyVal_.new_(lang_label, lang), KeyVal_.new_(text_label, text))); } return rv; } - private static KeyVal[] Srl_nde_langs(String key_label, String val_label, Json_grp grp) { - int len = grp.Subs_len(); + private static KeyVal[] Srl_sitelinks(String key_label, String val_label, OrderedHash list) { + int len = list.Count(); if (len == 0) return null; KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Json_itm_kv sub = (Json_itm_kv)grp.Subs_get_at(i); - String lang = sub.Key_as_str(); - Object description = sub.Val().Data(); - rv[i] = KeyVal_.new_(lang, KeyVal_.Ary(KeyVal_.new_(key_label, lang), KeyVal_.new_(val_label, description))); + Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); + String site = String_.new_utf8_(itm.Site()); + String name = String_.new_utf8_(itm.Name()); + rv[i] = KeyVal_.new_(site, KeyVal_.Ary(KeyVal_.new_(key_label, site), KeyVal_.new_(val_label, name))); } return rv; } - private static KeyVal[] Srl_aliases(Json_grp grp, int base_adj) { - int len = grp.Subs_len(); + private static KeyVal[] Srl_aliases(int base_adj, OrderedHash list) { + int len = list.Count(); if (len == 0) return null; KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Json_itm_kv sub = (Json_itm_kv)grp.Subs_get_at(i); - String lang = sub.Key_as_str(); - rv[i] = KeyVal_.new_(lang, Srl_aliases_langs(lang, (Json_grp)sub.Val(), base_adj)); + Wdata_alias_itm itm = (Wdata_alias_itm)list.FetchAt(i); + String lang = String_.new_utf8_(itm.Lang()); + rv[i] = KeyVal_.new_(lang, Srl_aliases_langs(base_adj, lang, itm.Vals())); } return rv; } - private static KeyVal[] Srl_aliases_langs(String lang, Json_grp ary, int base_adj) { - int len = ary.Subs_len(); + private static KeyVal[] Srl_aliases_langs(int base_adj, String lang, byte[][] ary) { + int len = ary.length; KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Json_itm sub = ary.Subs_get_at(i); - rv[i] = KeyVal_.int_(i + base_adj, KeyVal_.Ary(KeyVal_.new_("language", lang), KeyVal_.new_("value", sub.Data()))); // NOTE: using same base_adj logic as claims + byte[] itm = ary[i]; + rv[i] = KeyVal_.int_(i + base_adj, KeyVal_.Ary(KeyVal_.new_(Wdata_dict_langtext.Str_language, lang), KeyVal_.new_(Wdata_dict_langtext.Str_value, String_.new_utf8_(itm)))); // NOTE: using same base_adj logic as claims } return rv; } - private static KeyVal[] Srl_claims(Wdata_doc_parser parser, byte[] src, Json_itm_ary claims_nde, boolean legacy_style, int base_adj) { - OrderedHash props = parser.Bld_props(src, claims_nde); - int len = props.Count(); + private static KeyVal[] Srl_claims(int base_adj, boolean legacy_style, OrderedHash claim_grps) { + int len = claim_grps.Count(); if (len == 0) return null; int rv_len = legacy_style ? len * 2 : len; // NOTE: legacyStyle returns 2 sets of properties: official "P" and legacy "p"; DATE:2014-05-11 KeyVal[] rv = new KeyVal[rv_len]; for (int i = 0; i < len; i++) { - Wdata_prop_grp grp = (Wdata_prop_grp)props.FetchAt(i); + Wdata_claim_grp grp = (Wdata_claim_grp)claim_grps.FetchAt(i); String pid_str = Int_.Xto_str(grp.Id()); KeyVal[] grp_val = Srl_claims_prop_grp("P" + pid_str, grp, base_adj); rv[i] = KeyVal_.new_("P" + pid_str, grp_val); @@ -103,123 +92,126 @@ class Scrib_lib_wikibase_srl { } return rv; } - private static KeyVal[] Srl_claims_prop_grp(String pid, Wdata_prop_grp grp, int base_adj) { + private static KeyVal[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) { int len = grp.Itms_len(); KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Wdata_prop_itm_core itm = grp.Itms_get_at(i); + Wdata_claim_itm_core itm = grp.Itms_get_at(i); rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm)); // NOTE: must be super 0 or super 1; DATE:2014-05-09 } return rv; } - private static KeyVal[] Srl_claims_prop_itm(String pid, Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm) { ListAdp list = ListAdp_.new_(); list.Add(KeyVal_.new_("id", String_.new_utf8_(itm.Wguid()))); list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm))); - list.Add(KeyVal_.new_(Wdata_doc_consts.Key_claims_rank_str, itm.Rank_str())); + list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid()))); list.Add(KeyVal_.new_("type", itm.Prop_type())); return (KeyVal[])list.XtoAryAndClear(KeyVal.class); } - private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[3]; rv[0] = KeyVal_.new_("datavalue", Srl_claims_prop_itm_core_val(itm)); rv[1] = KeyVal_.new_("property", pid); - rv[2] = KeyVal_.new_("snaktype", itm.Snak_str()); + rv[2] = KeyVal_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid())); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_val(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_val(Wdata_claim_itm_core itm) { switch (itm.Snak_tid()) { - case Wdata_prop_itm_base_.Snak_tid_somevalue: - case Wdata_prop_itm_base_.Snak_tid_novalue: // NOTE: not sure about this logic, but can't find somevalue snaktid formattercode in wikibase; DATE:2014-04-07 + case Wdata_dict_snak_tid.Tid_somevalue: + case Wdata_dict_snak_tid.Tid_novalue: // NOTE: not sure about this logic, but can't find somevalue snaktid formattercode in wikibase; DATE:2014-04-07 return DataValue_nil; default: - switch (itm.Val_tid_byte()) { - case Wdata_prop_itm_base_.Val_tid_string : return Srl_claims_prop_itm_core_str(itm); - case Wdata_prop_itm_base_.Val_tid_entity : return Srl_claims_prop_itm_core_entity(itm); - case Wdata_prop_itm_base_.Val_tid_time : return Srl_claims_prop_itm_core_time(itm); - case Wdata_prop_itm_base_.Val_tid_globecoordinate : return Srl_claims_prop_itm_core_globecoordinate(itm); - case Wdata_prop_itm_base_.Val_tid_quantity : return Srl_claims_prop_itm_core_quantity(itm); - case Wdata_prop_itm_base_.Val_tid_monolingualtext : return Srl_claims_prop_itm_core_monolingualtext(itm); + switch (itm.Val_tid()) { + case Wdata_dict_val_tid.Tid_string : return Srl_claims_prop_itm_core_str(itm); + case Wdata_dict_val_tid.Tid_entity : return Srl_claims_prop_itm_core_entity(itm); + case Wdata_dict_val_tid.Tid_time : return Srl_claims_prop_itm_core_time(itm); + case Wdata_dict_val_tid.Tid_globecoordinate : return Srl_claims_prop_itm_core_globecoordinate(itm); + case Wdata_dict_val_tid.Tid_quantity : return Srl_claims_prop_itm_core_quantity(itm); + case Wdata_dict_val_tid.Tid_monolingualtext : return Srl_claims_prop_itm_core_monolingualtext(itm); default: return KeyVal_.Ary_empty; } } } - private static KeyVal[] Srl_claims_prop_itm_core_str(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_str(Wdata_claim_itm_core itm) { + Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)itm; KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, itm.Val_tid_str()); - rv[1] = KeyVal_.new_(Key_value, String_.new_utf8_(itm.Val())); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid())); + rv[1] = KeyVal_.new_(Key_value, String_.new_utf8_(claim_str.Val_str())); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_entity(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_entity(Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_prop_itm_base_.Val_str_entity); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_entity); rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_entity_value(itm)); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_entity_value(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_entity_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm; KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Wdata_doc_consts.Key_ent_entity_type_str, Wdata_doc_consts.Val_ent_entity_type_item_str); - rv[1] = KeyVal_.new_(Wdata_doc_consts.Key_ent_numeric_id_str, String_.new_utf8_(itm.Val())); + rv[0] = KeyVal_.new_(Wdata_dict_value_entity.Str_entity_type, Wdata_dict_value_entity.Val_entity_type_item_str); + rv[1] = KeyVal_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.Xto_str(claim_entity.Entity_id())); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_time(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_time(Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_doc_consts.Key_time_time_str); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_time); rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_time_value(itm)); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_time_value(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_time_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)itm; KeyVal[] rv = new KeyVal[6]; - rv[0] = KeyVal_.new_(Wdata_doc_consts.Key_time_time_str , String_.new_ascii_(itm.Val())); - rv[1] = KeyVal_.new_(Wdata_doc_consts.Key_time_precision_str , Wdata_doc_consts.Val_time_precision_int); // NOTE: must return int, not str; DATE:2014-02-18 - rv[2] = KeyVal_.new_(Wdata_doc_consts.Key_time_before_str , Wdata_doc_consts.Val_time_before_int); - rv[3] = KeyVal_.new_(Wdata_doc_consts.Key_time_after_str , Wdata_doc_consts.Val_time_after_int); - rv[4] = KeyVal_.new_(Wdata_doc_consts.Key_time_timezone_str , Wdata_doc_consts.Val_time_timezone_str); - rv[5] = KeyVal_.new_(Wdata_doc_consts.Key_time_calendarmodel_str , Wdata_doc_consts.Val_time_calendarmodel_str); + rv[0] = KeyVal_.new_(Wdata_dict_value_time.Str_time , String_.new_ascii_(claim_time.Time())); + rv[1] = KeyVal_.new_(Wdata_dict_value_time.Str_precision , Wdata_dict_value_time.Val_precision_int); // NOTE: must return int, not str; DATE:2014-02-18 + rv[2] = KeyVal_.new_(Wdata_dict_value_time.Str_before , Wdata_dict_value_time.Val_before_int); + rv[3] = KeyVal_.new_(Wdata_dict_value_time.Str_after , Wdata_dict_value_time.Val_after_int); + rv[4] = KeyVal_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); + rv[5] = KeyVal_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate(Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_doc_consts.Key_geo_type_str); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_globecoordinate); rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_globecoordinate_value(itm)); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate_value(Wdata_prop_itm_core itm) { - byte[][] flds = Bry_.Split(itm.Val(), Byte_ascii.Pipe); + private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)itm; KeyVal[] rv = new KeyVal[5]; - rv[0] = KeyVal_.new_(Wdata_doc_consts.Key_geo_latitude_str , Double_.parse_(String_.new_ascii_(flds[0]))); - rv[1] = KeyVal_.new_(Wdata_doc_consts.Key_geo_longitude_str , Double_.parse_(String_.new_ascii_(flds[1]))); - rv[2] = KeyVal_.new_(Wdata_doc_consts.Key_geo_altitude_str , null); - rv[3] = KeyVal_.new_(Wdata_doc_consts.Key_geo_globe_str , Wdata_doc_consts.Val_time_globe_bry); - rv[4] = KeyVal_.new_(Wdata_doc_consts.Key_geo_precision_str , .00001d); + rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lat()))); + rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lng()))); + rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , null); + rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_str); + rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , .00001d); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_quantity(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_quantity(Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_doc_consts.Key_quantity_type_str); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_quantity); rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_quantity_value(itm)); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_quantity_value(Wdata_prop_itm_core itm) { - byte[][] flds = Bry_.Split(itm.Val(), Byte_ascii.Pipe); + private static KeyVal[] Srl_claims_prop_itm_core_quantity_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)itm; KeyVal[] rv = new KeyVal[4]; - rv[0] = KeyVal_.new_(Wdata_doc_consts.Key_quantity_amount_str , String_.new_utf8_(flds[0])); - rv[1] = KeyVal_.new_(Wdata_doc_consts.Key_quantity_unit_str , String_.new_utf8_(flds[1])); - rv[2] = KeyVal_.new_(Wdata_doc_consts.Key_quantity_ubound_str , String_.new_utf8_(flds[2])); - rv[3] = KeyVal_.new_(Wdata_doc_consts.Key_quantity_lbound_str , String_.new_utf8_(flds[3])); + rv[0] = KeyVal_.new_(Wdata_dict_value_quantity.Str_amount , String_.new_utf8_(claim_quantity.Amount())); + rv[1] = KeyVal_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_utf8_(claim_quantity.Unit())); + rv[2] = KeyVal_.new_(Wdata_dict_value_quantity.Str_upperbound , String_.new_utf8_(claim_quantity.Ubound())); + rv[3] = KeyVal_.new_(Wdata_dict_value_quantity.Str_lowerbound , String_.new_utf8_(claim_quantity.Lbound())); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext(Wdata_prop_itm_core itm) { + private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext(Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_doc_consts.Key_quantity_type_str); + rv[0] = KeyVal_.new_(Key_type, Wdata_dict_value_monolingualtext.Str_language); rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_monolingualtext_value(itm)); return rv; } - private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext_value(Wdata_prop_itm_core itm) { - byte[][] flds = Bry_.Split(itm.Val(), Byte_ascii.Pipe); + private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)itm; KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Wdata_doc_consts.Key_monolingualtext_text_str , String_.new_utf8_(flds[0])); - rv[1] = KeyVal_.new_(Wdata_doc_consts.Key_monolingualtext_language_str , String_.new_utf8_(flds[1])); + rv[0] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_utf8_(claim_monolingualtext.Text())); + rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_utf8_(claim_monolingualtext.Lang())); return rv; } private static final String Key_type = "type", Key_value = "value"; diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java index d32253e9c..689c28ae9 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java @@ -17,8 +17,7 @@ along with this program. If not, see . */ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import org.junit.*; -import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Scrib_lib_wikibase_srl_tst { @Before public void init() {fxt.Clear();} private Scrib_lib_wikibase_srl_fxt fxt = new Scrib_lib_wikibase_srl_fxt(); @Test public void Label() { @@ -285,12 +284,10 @@ class Scrib_lib_wikibase_srl_fxt { wdata_fxt.Init(); doc_bldr = wdata_fxt.page_bldr_("q2"); header_enabled = false; - parser = new Wdata_doc_parser(wdata_fxt.App().Usr_dlg()); } public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt; private Wdata_doc_bldr doc_bldr; private boolean header_enabled; - private Wdata_doc_parser parser; public Scrib_lib_wikibase_srl_fxt Init_header_enabled_y_() {header_enabled = true; return this;} public Scrib_lib_wikibase_srl_fxt Init_label(String lang, String label) { doc_bldr.Label_add(lang, label); @@ -308,16 +305,16 @@ class Scrib_lib_wikibase_srl_fxt { doc_bldr.Alias_add(lang, ary); return this; } - public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_prop_itm_core prop) {doc_bldr.Props_add(prop); return this;} + public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {doc_bldr.Props_add(prop); return this;} public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);} public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) { - KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(parser, doc_bldr.Xto_page_doc(), header_enabled, base0); + KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(doc_bldr.Xto_page_doc(), header_enabled, base0); Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl))); return this; } public Scrib_lib_wikibase_srl_fxt Test(Wdata_doc wdoc, String... expd) {return Test(false, wdoc, expd);} public Scrib_lib_wikibase_srl_fxt Test(boolean base0, Wdata_doc wdoc, String... expd) { - KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(parser, wdoc, header_enabled, base0); + KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc, header_enabled, base0); Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl))); return this; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java index a0bc2dc19..4f5410001 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java @@ -16,20 +16,20 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Wdata_doc { - public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc doc) {this.qid = qid; this.mgr = mgr; this.doc = doc;} Wdata_wiki_mgr mgr; - public Json_doc Doc() {return doc;} Json_doc doc; + public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;} private Wdata_wiki_mgr mgr; + public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc; public byte[] Qid() {return qid;} private byte[] qid; - public OrderedHash Link_list() {if (link_list == null) link_list = mgr.Page_doc_parser().Bld_hash(doc, Wdata_doc_consts.Key_atr_links_bry); return link_list;} private OrderedHash link_list; - public OrderedHash Label_list() {if (label_list == null) label_list = mgr.Page_doc_parser().Bld_hash(doc, Wdata_doc_consts.Key_atr_label_bry); return label_list;} private OrderedHash label_list; - public OrderedHash Alias_list() {if (alias_list == null) alias_list = mgr.Page_doc_parser().Bld_hash(doc, Wdata_doc_consts.Key_atr_aliases_bry); return alias_list;} private OrderedHash alias_list; - public OrderedHash Description_list() {if (description_list == null) description_list = mgr.Page_doc_parser().Bld_hash(doc, Wdata_doc_consts.Key_atr_description_bry); return description_list;} private OrderedHash description_list; - public OrderedHash Claim_list() {if (claim_list == null) claim_list = mgr.Page_doc_parser().Bld_props(doc); return claim_list;} private OrderedHash claim_list; + public OrderedHash Sitelink_list() {if (sitelink_list == null) sitelink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return sitelink_list;} private OrderedHash sitelink_list; + public OrderedHash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private OrderedHash label_list; + public OrderedHash Description_list() {if (description_list == null) description_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return description_list;} private OrderedHash description_list; + public OrderedHash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private OrderedHash alias_list; + public OrderedHash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(jdoc); return claim_list;} private OrderedHash claim_list; + public Wdata_claim_grp Claim_list_get(int pid) {return (Wdata_claim_grp)this.Claim_list().Fetch(mgr.Tmp_prop_ref().Val_(pid));} public byte[] Label_list_get(byte[] lang_key) { - Object rv = this.Label_list().Fetch(lang_key); if (rv == null) return null; - Json_itm_kv kv = (Json_itm_kv)rv; - return kv.Val().Data_bry(); - } - public Wdata_prop_grp Claim_list_get(int pid) {return (Wdata_prop_grp)this.Claim_list().Fetch(mgr.Tmp_prop_ref().Val_(pid));} + Object rv_obj = this.Label_list().Fetch(lang_key); if (rv_obj == null) return null; + Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj; + return rv.Text(); + } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java index bd01afd68..3a5c1d454 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java @@ -16,16 +16,17 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Wdata_doc_bldr { public Wdata_doc_bldr(Wdata_wiki_mgr mgr) {this.mgr = mgr;} Wdata_wiki_mgr mgr; public Wdata_doc_bldr Qid_(String v) {this.qid = Bry_.new_ascii_(v); return this;} private byte[] qid; ListAdp props = ListAdp_.new_(); - public Wdata_doc_bldr Props_add(Wdata_prop_itm_core... ary) { + public Wdata_doc_bldr Props_add(Wdata_claim_itm_core... ary) { int len = ary.length; for (int i = 0; i < len; i++) props.Add(ary[i]); return this; } + public static byte[] Xto_time(String date) {return Xto_time(DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));} public static byte[] Xto_time(DateAdp date) { // +0000000yyyy-MM-ddTHH:mm:ssZ tmp_bfr @@ -54,10 +55,10 @@ public class Wdata_doc_bldr { } OrderedHash aliases = OrderedHash_.new_(); public byte[] Xto_bry() { wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_doc_consts.Key_atr_entity_bry, qid); - Xto_bry__list(Wdata_doc_consts.Key_atr_label_bry, labels); - Xto_bry__list(Wdata_doc_consts.Key_atr_description_bry, descriptions); - Xto_bry__sitelinks(Wdata_doc_consts.Key_atr_links_bry, links); + wtr.Kv(Bool_.N, Wdata_doc_parser_v1.Bry_entity, qid); + Xto_bry__list(Wdata_doc_parser_v1.Bry_label, labels); + Xto_bry__list(Wdata_doc_parser_v1.Bry_description, descriptions); + Xto_bry__sitelinks(Wdata_doc_parser_v1.Bry_links, links); Xto_bry__aliases(); Xto_bry__claims(); wtr.Nde_end(); @@ -83,9 +84,9 @@ public class Wdata_doc_bldr { for (int i = 0; i < len; i++) { if (i != 0) wtr.Comma(); KeyVal kv = (KeyVal)list.FetchAt(i); - wtr.Key(false, Bry_.new_utf8_(kv.Key())); // write key; EX: enwiki: + wtr.Key(false, Bry_.new_utf8_(kv.Key())); // write key; EX: enwiki: wtr.Nde_bgn(); // bgn nde; EX: { - wtr.Kv(false, Wdata_doc_.Key_name, Bry_.new_utf8_(kv.Val_to_str_or_empty())); // write name; EX: name=Earth + wtr.Kv(false, Wdata_doc_parser_v1.Bry_name, Bry_.new_utf8_(kv.Val_to_str_or_empty())); // write name; EX: name=Earth wtr.Nde_end(); // end nde; EX: } } wtr.Nde_end(); @@ -94,7 +95,7 @@ public class Wdata_doc_bldr { private void Xto_bry__aliases() { int len = aliases.Count(); if (len == 0) return; - wtr.Key(true, Wdata_doc_consts.Key_atr_aliases_bry); + wtr.Key(true, Wdata_doc_parser_v1.Bry_aliases); wtr.Nde_bgn(); for (int i = 0; i < len; i++) { Wdata_doc_alias alias = (Wdata_doc_alias)aliases.FetchAt(i); @@ -114,91 +115,94 @@ public class Wdata_doc_bldr { private void Xto_bry__claims() { int len = props.Count(); if (len == 0) return; - wtr.Key(true, Wdata_doc_consts.Key_atr_claims_bry); + wtr.Key(true, Wdata_doc_parser_v1.Bry_claims); wtr.Ary_bgn(); for (int i = 0; i < len; i++) { if (i != 0) wtr.Comma(); - Wdata_prop_itm_core prop = (Wdata_prop_itm_core)props.FetchAt(i); + Wdata_claim_itm_core prop = (Wdata_claim_itm_core)props.FetchAt(i); wtr.Nde_bgn(); - wtr.Key(false, Wdata_doc_consts.Key_claims_m_bry); + wtr.Key(false, Wdata_dict_claim_v1.Bry_m); wtr.Ary_bgn(); - wtr.Val(Bool_.N, prop.Snak_bry()); + wtr.Val(Bool_.N, Wdata_dict_snak_tid.Xto_bry(prop.Snak_tid())); wtr.Val(Bool_.Y, prop.Pid()); - if (prop.Snak_tid() == Wdata_prop_itm_base_.Snak_tid_value) { - switch (prop.Val_tid_byte()) { - case Wdata_prop_itm_base_.Val_tid_string: - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_string); - wtr.Val(Bool_.Y, prop.Val()); + if (prop.Snak_tid() == Wdata_dict_snak_tid.Tid_value) { + switch (prop.Val_tid()) { + case Wdata_dict_val_tid.Tid_string: + Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_string); + wtr.Val(Bool_.Y, claim_str.Val_str()); break; - case Wdata_prop_itm_base_.Val_tid_entity: - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_entity); + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_entity); wtr.Comma(); wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_doc_consts.Key_ent_entity_type_bry, Wdata_doc_consts.Val_ent_entity_type_item_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_ent_numeric_id_bry, Bry_.Xto_int(prop.Val())); + wtr.Kv(Bool_.N, Wdata_dict_value_entity.Bry_entity_type , Wdata_dict_value_entity.Val_entity_type_item_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_entity.Bry_numeric_id , claim_entity.Entity_id()); wtr.Nde_end(); break; - case Wdata_prop_itm_base_.Val_tid_time: - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_time); + case Wdata_dict_val_tid.Tid_time: + Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_time); wtr.Comma(); wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_doc_consts.Key_time_time_bry , prop.Val()); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_time_precision_bry , Wdata_doc_consts.Val_time_precision_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_time_before_bry , Wdata_doc_consts.Val_time_before_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_time_after_bry , Wdata_doc_consts.Val_time_after_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_time_timezone_bry , Wdata_doc_consts.Val_time_timezone_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_time_calendarmodel_bry , Wdata_doc_consts.Val_time_calendarmodel_bry); + wtr.Kv(Bool_.N, Wdata_dict_value_time.Bry_time , claim_time.Time()); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_precision , Wdata_dict_value_time.Val_timezone_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_before , Wdata_dict_value_time.Val_before_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_after , Wdata_dict_value_time.Val_after_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_timezone , Wdata_dict_value_time.Val_timezone_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_bry); wtr.Nde_end(); break; - case Wdata_prop_itm_base_.Val_tid_globecoordinate: { - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_globecoordinate); + case Wdata_dict_val_tid.Tid_globecoordinate: { + Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_globecoordinate); wtr.Comma(); wtr.Nde_bgn(); - byte[][] flds = Bry_.Split(prop.Val(), Byte_ascii.Pipe); - wtr.Kv_double (Bool_.N, Wdata_doc_consts.Key_geo_latitude_bry , Double_.parse_(String_.new_ascii_(flds[0]))); - wtr.Kv_double (Bool_.Y, Wdata_doc_consts.Key_geo_longitude_bry , Double_.parse_(String_.new_ascii_(flds[1]))); - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_geo_altitude_bry , null); - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_geo_globe_bry , Wdata_doc_consts.Val_time_globe_bry); - wtr.Kv_double (Bool_.Y, Wdata_doc_consts.Key_geo_precision_bry , .00001d); + wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lat()))); + wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lng()))); + wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_altitude , null); + wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_bry); + wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_precision , .00001d); wtr.Nde_end(); break; } - case Wdata_prop_itm_base_.Val_tid_quantity: { - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_quantity); + case Wdata_dict_val_tid.Tid_quantity: { + Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_quantity); wtr.Comma(); wtr.Nde_bgn(); - byte[][] flds = Bry_.Split(prop.Val(), Byte_ascii.Pipe); - wtr.Kv (Bool_.N, Wdata_doc_consts.Key_quantity_amount_bry , flds[0]); // +1,234 - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_quantity_unit_bry , flds[1]); // 1 - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_quantity_ubound_bry , flds[2]); // +1,235 - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_quantity_lbound_bry , flds[3]); // +1,233 + wtr.Kv (Bool_.N, Wdata_dict_value_quantity.Bry_amount , claim_quantity.Amount()); // +1,234 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_unit , claim_quantity.Unit()); // 1 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_upperbound , claim_quantity.Ubound()); // +1,235 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_lowerbound , claim_quantity.Lbound()); // +1,233 wtr.Nde_end(); break; } - case Wdata_prop_itm_base_.Val_tid_monolingualtext: { - wtr.Val(Bool_.Y, Wdata_prop_itm_base_.Val_bry_monolingualtext); + case Wdata_dict_val_tid.Tid_monolingualtext: { + Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_monolingualtext); wtr.Comma(); wtr.Nde_bgn(); - byte[][] flds = Bry_.Split(prop.Val(), Byte_ascii.Pipe); - wtr.Kv (Bool_.N, Wdata_doc_consts.Key_monolingualtext_text_bry , flds[0]); // text - wtr.Kv (Bool_.Y, Wdata_doc_consts.Key_monolingualtext_language_bry , flds[1]); // en + wtr.Kv (Bool_.N, Wdata_dict_value_monolingualtext.Bry_text , claim_monolingualtext.Text()); // text + wtr.Kv (Bool_.Y, Wdata_dict_value_monolingualtext.Bry_language , claim_monolingualtext.Lang()); // en wtr.Nde_end(); break; } - default: throw Err_.unhandled(prop.Val_tid_byte()); + default: throw Err_.unhandled(prop.Val_tid()); } } wtr.Ary_end(); - wtr.Kv_ary_empty(Bool_.Y, Wdata_doc_consts.Key_claims_q_bry); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_claims_g_bry, qid); - wtr.Kv(Bool_.Y, Wdata_doc_consts.Key_claims_rank_bry, Wdata_prop_itm_base_.Rank_normal); - wtr.Kv_ary_empty(Bool_.Y, Wdata_doc_consts.Key_claims_refs_bry); + wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_q); + wtr.Kv(Bool_.Y, Wdata_dict_claim_v1.Bry_g, qid); + wtr.Kv(Bool_.Y, Wdata_dict_claim_v1.Bry_rank, Wdata_dict_rank.Tid_normal); + wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_refs); wtr.Nde_end(); } wtr.Ary_end(); props.Clear(); } - public Wdata_doc Xto_page_doc() {return new Wdata_doc(qid, mgr, mgr.Parser().Parse(Xto_bry()));} + public Wdata_doc Xto_page_doc() {return new Wdata_doc(qid, mgr, mgr.Jdoc_parser().Parse(Xto_bry()));} } class Wdata_doc_alias { public Wdata_doc_alias(String lang, String[] aliases) {this.lang = lang; this.aliases = aliases;} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java index 5e02bef64..64e8954e6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java @@ -18,18 +18,23 @@ along with this program. If not, see . package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.html.*; -import gplx.xowa.parsers.logs.*; +import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*; public class Wdata_wiki_mgr implements GfoInvkAble { + private Wdata_doc_parser wdoc_parser_v1, wdoc_parser_v2; public Wdata_wiki_mgr(Xoa_app app) { this.app = app; - page_doc_parser = new Wdata_doc_parser(app.Usr_dlg()); + wdoc_parser_v1 = new Wdata_doc_parser_v1(); + wdoc_parser_v2 = new Wdata_doc_parser_v2(); doc_cache = app.Cache_mgr().Doc_cache(); } private Xoa_app app; gplx.xowa.apps.caches.Wdata_doc_cache doc_cache; public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true; public byte[] Domain() {return domain;} public void Domain_(byte[] v) {domain = v;} private byte[] domain = Bry_.new_ascii_("www.wikidata.org"); public Xow_wiki Wdata_wiki() {if (wdata_wiki == null) wdata_wiki = app.Wiki_mgr().Get_by_key_or_make(domain).Init_assert(); return wdata_wiki;} private Xow_wiki wdata_wiki; - public Json_parser Parser() {return parser;} Json_parser parser = new Json_parser(); - public Wdata_doc_parser Page_doc_parser() {return page_doc_parser;} Wdata_doc_parser page_doc_parser; + public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser(); + public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) { + Json_itm_kv itm_0 = Json_itm_kv.cast_(jdoc.Root().Subs_get_at(0)); // get 1st node + return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type) ? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2 + } public Xop_log_property_wkr Property_wkr() {return property_wkr;} private Xop_log_property_wkr property_wkr; public Int_obj_ref Tmp_prop_ref() {return tmp_prop_ref;} Int_obj_ref tmp_prop_ref = Int_obj_ref.zero_(); public void Clear() { @@ -71,7 +76,7 @@ public class Wdata_wiki_mgr implements GfoInvkAble { public void Pages_add(byte[] qid, Wdata_doc page) { doc_cache.Add(qid, page); } - @gplx.Internal protected Wdata_doc Pages_get(Xow_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) { + public Wdata_doc Pages_get(Xow_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) { if (data.Q() != null) return Pages_get(data.Q()); else if (data.Of() != null) { Xoa_ttl of_ttl = Xoa_ttl.parse_(wiki, data.Of()); if (of_ttl == null) return null; @@ -115,20 +120,27 @@ public class Wdata_wiki_mgr implements GfoInvkAble { } return qids[qid_idx]; } - public void Resolve_to_bfr(Bry_bfr bfr, Wdata_prop_grp prop_grp, byte[] lang_key) { + public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) { int len = prop_grp.Itms_len(); for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: roles = scientist,painter if (i != 0) bfr.Add(Prop_tmpl_val_dlm); - Wdata_prop_itm_core prop = prop_grp.Itms_get_at(i); + Wdata_claim_itm_core prop = prop_grp.Itms_get_at(i); switch (prop.Snak_tid()) { - case Wdata_prop_itm_base_.Snak_tid_novalue : bfr.Add(Wdata_doc_consts.Val_prop_novalue_bry); break; - case Wdata_prop_itm_base_.Snak_tid_somevalue: bfr.Add(Wdata_doc_consts.Val_prop_somevalue_bry); break; + case Wdata_dict_snak_tid.Tid_novalue : bfr.Add(Wdata_dict_snak_tid.Bry_novalue); break; + case Wdata_dict_snak_tid.Tid_somevalue : bfr.Add(Wdata_dict_snak_tid.Bry_somevalue); break; default: { - switch (prop.Val_tid_byte()) { - case Wdata_prop_itm_base_.Val_tid_string : - case Wdata_prop_itm_base_.Val_tid_time : bfr.Add(prop.Val()); break; - case Wdata_prop_itm_base_.Val_tid_entity: - Wdata_doc entity_doc = Pages_get(Bry_.Add(Bry_q, prop.Val())); + switch (prop.Val_tid()) { + case Wdata_dict_val_tid.Tid_string: + Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)prop; + bfr.Add(claim_str.Val_str()); + break; + case Wdata_dict_val_tid.Tid_time: + Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)prop; + bfr.Add(claim_time.Time()); + break; + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)prop; + Wdata_doc entity_doc = Pages_get(Bry_.Add(Bry_q, claim_entity.Entity_id_bry())); if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01 byte[] label = entity_doc.Label_list_get(lang_key); if (label == null && !Bry_.Eq(lang_key, Xol_lang_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19 @@ -136,29 +148,29 @@ public class Wdata_wiki_mgr implements GfoInvkAble { if (label != null) // if label is still not found, don't add null reference bfr.Add(label); break; - case Wdata_prop_itm_base_.Val_tid_globecoordinate: { - byte[][] flds = Bry_.Split(prop.Val(), Wdata_prop_itm_core.Prop_dlm); - bfr.Add(flds[0]); + case Wdata_dict_val_tid.Tid_globecoordinate: { + Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)prop; + bfr.Add(claim_globecoordinate.Lat()); bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); - bfr.Add(flds[1]); + bfr.Add(claim_globecoordinate.Lng()); break; } - case Wdata_prop_itm_base_.Val_tid_quantity: { - byte[][] flds = Bry_.Split(prop.Val(), Wdata_prop_itm_core.Prop_dlm); - byte[] amount_bry = flds[0]; + case Wdata_dict_val_tid.Tid_quantity: { + Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)prop; + byte[] amount_bry = claim_quantity.Amount(); int val = Bry_.Xto_int_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0); Xol_lang lang = app.Lang_mgr().Get_by_key(lang_key); bfr.Add(lang.Num_mgr().Format_num(val)); // amount; EX: 1,234 bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ± - bfr.Add(flds[1]); // unit; EX: 1 + bfr.Add(claim_quantity.Unit()); // unit; EX: 1 break; } - case Wdata_prop_itm_base_.Val_tid_monolingualtext: { // {{#property:monolingualprop}} -> some phrase (la) - byte[][] flds = Bry_.Split(prop.Val(), Wdata_prop_itm_core.Prop_dlm); - bfr.Add(flds[0]); // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28 + case Wdata_dict_val_tid.Tid_monolingualtext: { // {{#property:monolingualprop}} -> some phrase (la) + Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)prop; + bfr.Add(claim_monolingualtext.Text()); // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28 break; } - default: throw Err_.unhandled(prop.Val_tid_byte()); + default: throw Err_.unhandled(prop.Val_tid()); } break; } @@ -170,7 +182,7 @@ public class Wdata_wiki_mgr implements GfoInvkAble { public static final byte[] Bry_q = Bry_.new_ascii_("q"), Prop_tmpl_val_dlm = Bry_.new_ascii_(", "); public void Write_json_as_html(Bry_bfr bfr, byte[] data_raw) { bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Id_atr).Add(Html_json_id).Add(Xoh_consts.__end_quote); // - Json_doc json = parser.Parse(data_raw); + Json_doc json = jdoc_parser.Parse(data_raw); json.Root().Print_as_json(bfr, 0); bfr.Add(Xoh_consts.Span_end); } @@ -179,7 +191,7 @@ public class Wdata_wiki_mgr implements GfoInvkAble { Xoa_ttl qid_ttl = Xoa_ttl.parse_(this.Wdata_wiki(), qid_bry); if (qid_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", String_.new_utf8_(qid_bry)); return null;} Xoa_page qid_page = this.Wdata_wiki().Data_mgr().Get_page(qid_ttl, false); if (qid_page.Missing()) return null; byte[] src = qid_page.Data_raw(); - return parser.Parse(src); + return jdoc_parser.Parse(src); } public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java index 8b4b584dd..ee356defb 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.imports.*; import gplx.xowa.pages.*; -import gplx.xowa.langs.*; +import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*; public class Wdata_wiki_mgr_fxt { public Xow_wiki Wiki() {return parser_fxt.Wiki();} public Wdata_wiki_mgr_fxt Init() {return Init(new Xop_fxt(), true);} @@ -36,16 +36,16 @@ public class Wdata_wiki_mgr_fxt { } private Xoa_app app; Xow_wiki wiki; Wdata_wiki_mgr wdata_mgr; Wdata_doc_bldr page_bldr; Xop_fxt parser_fxt; public Xoa_app App() {return app;} public Wdata_doc_bldr page_bldr_(String qid) {return page_bldr.Qid_(qid);} - public Wdata_prop_itm_core prop_novalue_(int pid) {return Wdata_prop_itm_core.new_novalue_(pid);} - public Wdata_prop_itm_core prop_somevalue_(int pid) {return Wdata_prop_itm_core.new_somevalue_(pid);} - public Wdata_prop_itm_core prop_str_(int pid, String val) {return Wdata_prop_itm_core.new_str_(pid, val);} - public Wdata_prop_itm_core prop_str_(int pid, byte[] val) {return Wdata_prop_itm_core.new_str_(pid, val);} - public Wdata_prop_itm_core prop_time_(int pid, String val) {return Wdata_prop_itm_core.new_time_(pid, val);} - public Wdata_prop_itm_core prop_geodata_(int pid, String lat, String lon) {return Wdata_prop_itm_core.new_geodata_(pid, lat, lon);} - public Wdata_prop_itm_core prop_quantity_(int pid, String amount, String unit, String ubound, String lbound) {return Wdata_prop_itm_core.new_quantity_(pid, amount, unit, ubound, lbound);} - public Wdata_prop_itm_core prop_monolingualtext_(int pid, String text, String lang) {return Wdata_prop_itm_core.new_monolingualtext_(pid, text, lang);} - public Wdata_prop_itm_core prop_entity_(int pid, int val) {return Wdata_prop_itm_core.new_entity_(pid, val);} - public Wdata_doc doc_(String qid, Wdata_prop_itm_core... props) {return page_bldr.Qid_(qid).Props_add(props).Xto_page_doc();} + public Wdata_claim_itm_core prop_novalue_(int pid) {return Wdata_claim_itm_system.new_novalue(pid);} + public Wdata_claim_itm_core prop_somevalue_(int pid) {return Wdata_claim_itm_system.new_somevalue(pid);} + public Wdata_claim_itm_core prop_str_(int pid, String val) {return prop_str_(pid, Bry_.new_utf8_(val));} + public Wdata_claim_itm_core prop_str_(int pid, byte[] val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, val);} + public Wdata_claim_itm_core prop_time_(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_doc_bldr.Xto_time(val), Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty);} + public Wdata_claim_itm_core prop_monolingualtext_(int pid, String text, String lang) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_claim_itm_core prop_geodata_(int pid, String lat, String lon) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon), Bry_.Empty, Bry_.Empty, Bry_.Empty);} + public Wdata_claim_itm_core prop_quantity_(int pid, String amount, String unit, String ubound, String lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(amount), Bry_.new_ascii_(unit), Bry_.new_ascii_(ubound), Bry_.new_ascii_(lbound));} + public Wdata_claim_itm_core prop_entity_(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(val));} + public Wdata_doc doc_(String qid, Wdata_claim_itm_core... props) {return page_bldr.Qid_(qid).Props_add(props).Xto_page_doc();} public void Init_xwikis_add(String... prefixes) { int len = prefixes.length; for (int i = 0; i < len; i++) { diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java index a3f0541b6..86e7863a6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*; public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg { public Wdata_xwiki_link_wtr Page_(Xoa_page page) {this.page = page; return this;} private Xoa_page page; public void XferAry(Bry_bfr bfr, int idx) { @@ -36,13 +36,13 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg { Wdata_wiki_mgr wdata_mgr = wiki.App().Wiki_mgr().Wdata_mgr(); Wdata_doc doc = wdata_mgr.Pages_get(wiki, ttl); if (doc == null) return Qid_null; // no links boolean external_links_mgr_enabled = external_links_mgr.Enabled(); - OrderedHash links = doc.Link_list(); + OrderedHash links = doc.Sitelink_list(); Bry_bfr tmp_bfr = wiki.App().Utl_bry_bfr_mkr().Get_k004(); Xow_wiki_abrv wiki_abrv = new Xow_wiki_abrv(); int len = links.Count(); for (int i = 0; i < len; i++) { - Json_itm_kv kv = (Json_itm_kv)links.FetchAt(i); - byte[] xwiki_key = kv.Key().Data_bry(); + Wdata_sitelink_itm sitelink = (Wdata_sitelink_itm)links.FetchAt(i); + byte[] xwiki_key = sitelink.Site(); Xow_wiki_abrv_.parse_(wiki_abrv, xwiki_key, 0, xwiki_key.length); if (wiki_abrv.Domain_tid() == Xow_wiki_abrv_.Tid_null) { wiki.App().Usr_dlg().Warn_many("", "", "unknown wiki in wikidata: ttl=~{0} wiki=~{1}", ttl.Page_db_as_str(), String_.new_utf8_(xwiki_key)); @@ -53,7 +53,7 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg { if (external_links_mgr_enabled && external_links_mgr.Langs_hide(lang_key, 0, lang_key.length)) continue; tmp_bfr.Add(lang_key); tmp_bfr.Add_byte(Byte_ascii.Colon); - tmp_bfr.Add(Wdata_doc_.Link_extract(kv)); + tmp_bfr.Add(sitelink.Name()); Xoa_ttl lang_ttl = Xoa_ttl.parse_(wiki, tmp_bfr.XtoAryAndClear()); if (lang_ttl == null) continue; // invalid ttl Xow_xwiki_itm xwiki_itm = lang_ttl.Wik_itm(); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java new file mode 100644 index 000000000..e61bf8ce5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +public class Wdata_alias_itm { + public Wdata_alias_itm(byte[] lang, byte[][] vals) {this.lang = lang; this.vals = vals;} + public byte[] Lang() {return lang;} private byte[] lang; + public byte[][] Vals() {return vals;} private byte[][] vals; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", String_.new_utf8_(lang), String_.Concat_with_str("~", String_.Ary(vals))); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java new file mode 100644 index 000000000..80a4c98f0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java @@ -0,0 +1,36 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_grp { + public Wdata_claim_grp(Int_obj_ref id_ref, Wdata_claim_itm_core[] itms) {this.id_ref = id_ref; this.itms = itms;} + public Int_obj_ref Id_ref() {return id_ref;} private final Int_obj_ref id_ref; + public int Id() {return id_ref.Val();} + public int Itms_len() {return itms.length;} private Wdata_claim_itm_core[] itms; + public Wdata_claim_itm_core Itms_get_at(int i) {return itms[i];} + public static ListAdp Xto_list(OrderedHash hash) { + int len = hash.Count(); + ListAdp rv = ListAdp_.new_(); + for (int i = 0; i < len; ++i) { + Wdata_claim_grp grp = (Wdata_claim_grp)hash.FetchAt(i); + int grp_len = grp.Itms_len(); + for (int j = 0; j < grp_len; ++j) + rv.Add(grp.Itms_get_at(j)); + } + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java new file mode 100644 index 000000000..b8b836a7a --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java @@ -0,0 +1,33 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public abstract class Wdata_claim_itm_base implements CompareAble { + public Wdata_claim_itm_base Ctor(int pid, byte snak_tid) { + this.pid = pid; + this.snak_tid = snak_tid; + return this; + } + public int Pid() {return pid;} private int pid; + public abstract byte Val_tid(); + public byte Snak_tid() {return snak_tid;} private byte snak_tid = Wdata_dict_snak_tid.Tid_value; + public byte Rank_tid() {return rank_tid;} public void Rank_tid_(byte v) {this.rank_tid = v;} private byte rank_tid; + public int compareTo(Object obj) { + Wdata_claim_itm_base comp = (Wdata_claim_itm_base)obj; + return Int_.Compare(pid, comp.pid); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java new file mode 100644 index 000000000..7ddbb087b --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java @@ -0,0 +1,24 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public abstract class Wdata_claim_itm_core extends Wdata_claim_itm_base { + public byte[] Wguid() {return wguid;} public void Wguid_(byte[] v) {this.wguid = v;} private byte[] wguid; + public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement"; + public Wdata_claim_itm_base[] Qual_ary() {return qual_ary;} public void Qual_ary_(Wdata_claim_itm_base[] v) {this.qual_ary = v;} private Wdata_claim_itm_base[] qual_ary; + public Wdata_claim_itm_base[] Ref_ary() {return ref_ary;} public void Ref_ary_(Wdata_claim_itm_base[] v) {this.ref_ary = v;} private Wdata_claim_itm_base[] ref_ary; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java new file mode 100644 index 000000000..8f68998eb --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_entity extends Wdata_claim_itm_core { public Wdata_claim_itm_entity(int pid, byte snak_tid, byte[] entity_id_bry) { + this.Ctor(pid, snak_tid); + this.entity_id_bry = entity_id_bry; + this.entity_id = Bry_.Xto_int_or_fail(entity_id_bry); + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_entity;} + public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry; + public int Entity_id() {return entity_id;} private final int entity_id; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), Int_.Xto_str(entity_id)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java new file mode 100644 index 000000000..09be202a6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { public Wdata_claim_itm_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) { + this.Ctor(pid, snak_tid); + this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb; + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_globecoordinate;} + public byte[] Lat() {return lat;} private final byte[] lat; + public byte[] Lng() {return lng;} private final byte[] lng; + public byte[] Alt() {return alt;} private final byte[] alt; + public byte[] Prc() {return prc;} private final byte[] prc; + public byte[] Glb() {return glb;} private final byte[] glb; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(lat), String_.new_utf8_(lng), String_.new_utf8_(alt), String_.new_utf8_(prc), String_.new_utf8_(glb)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java new file mode 100644 index 000000000..dbed601a3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_monolingualtext extends Wdata_claim_itm_core { public Wdata_claim_itm_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) { + this.Ctor(pid, snak_tid); + this.lang = lang; this.text = text; + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_monolingualtext;} + public byte[] Lang() {return lang;} private final byte[] lang; + public byte[] Text() {return text;} private final byte[] text; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(lang), String_.new_utf8_(text)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java new file mode 100644 index 000000000..eddafaf18 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wdata_claim_itm_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) { + this.Ctor(pid, snak_tid); + this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound; + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_quantity;} + public byte[] Amount() {return amount;} private final byte[] amount; + public byte[] Unit() {return unit;} private final byte[] unit; + public byte[] Ubound() {return ubound;} private final byte[] ubound; + public byte[] Lbound() {return lbound;} private final byte[] lbound; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(amount), String_.new_utf8_(unit), String_.new_utf8_(ubound), String_.new_utf8_(lbound)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java new file mode 100644 index 000000000..4e1829ea4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_str extends Wdata_claim_itm_core { public Wdata_claim_itm_str(int pid, byte snak_tid, byte[] val) { + this.Ctor(pid, snak_tid); + this.val = val; + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_string;} + public byte[] Val_str() {return val;} private final byte[] val; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(val)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java new file mode 100644 index 000000000..ede593b21 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_system extends Wdata_claim_itm_core { public Wdata_claim_itm_system(int pid, byte val_tid, byte snak_tid) { + this.Ctor(pid, snak_tid); + this.val_tid = val_tid; + } + @Override public byte Val_tid() {return val_tid;} private byte val_tid; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid())); + } + public static Wdata_claim_itm_system new_novalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown , Wdata_dict_snak_tid.Tid_novalue);} + public static Wdata_claim_itm_system new_somevalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown , Wdata_dict_snak_tid.Tid_somevalue);} +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java new file mode 100644 index 000000000..525b1bf7f --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_claim_itm_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendarmodel) { + this.Ctor(pid, snak_tid); + this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendarmodel = calendarmodel; + } + @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_time;} + public byte[] Time() {return time;} private final byte[] time; + public byte[] Before() {return before;} private final byte[] before; + public byte[] After() {return after;} private final byte[] after; + public byte[] Precision() {return precision;} private final byte[] precision; + public byte[] Calendarmodel() {return calendarmodel;} private final byte[] calendarmodel; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(time), String_.new_utf8_(before), String_.new_utf8_(after), String_.new_utf8_(precision), String_.new_utf8_(calendarmodel)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java new file mode 100644 index 000000000..f4f3fbdde --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java @@ -0,0 +1,47 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_claim { + public static final byte + Tid_mainsnak = 0 + , Tid_type = 1 + , Tid_id = 2 + , Tid_rank = 3 + , Tid_references = 4 + , Tid_qualifiers = 5 + , Tid_qualifiers_order = 6 + ; + public static byte[] + Bry_mainsnak = Bry_.new_ascii_("mainsnak") + , Bry_type = Bry_.new_ascii_("type") + , Bry_id = Bry_.new_ascii_("id") + , Bry_rank = Bry_.new_ascii_("rank") + , Bry_references = Bry_.new_ascii_("references") + , Bry_qualifiers = Bry_.new_ascii_("qualifiers") + , Bry_qualifiers_order = Bry_.new_ascii_("qualifiers-order") + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_mainsnak , Tid_mainsnak) + .Add_bry_byte(Bry_type , Tid_type) + .Add_bry_byte(Bry_id , Tid_id) + .Add_bry_byte(Bry_rank , Tid_rank) + .Add_bry_byte(Bry_references , Tid_references) + .Add_bry_byte(Bry_qualifiers , Tid_qualifiers) + .Add_bry_byte(Bry_qualifiers_order , Tid_qualifiers_order) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim_v1.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim_v1.java new file mode 100644 index 000000000..f24b6c759 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim_v1.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_claim_v1 { + public static final String + Str_m = "m" + , Str_q = "q" + , Str_g = "g" + , Str_rank = "rank" + , Str_refs = "refs" + ; + public static final byte[] + Bry_m = Bry_.new_ascii_(Str_m) + , Bry_q = Bry_.new_ascii_(Str_q) + , Bry_g = Bry_.new_ascii_(Str_g) + , Bry_rank = Bry_.new_ascii_(Str_rank) + , Bry_refs = Bry_.new_ascii_(Str_refs) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java new file mode 100644 index 000000000..f3e1ea258 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_datavalue { + public static final byte + Tid_value = 0 + , Tid_type = 1 + ; + public static byte[] + Bry_value = Bry_.new_ascii_("value") + , Bry_type = Bry_.new_ascii_("type") + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_value , Tid_value) + .Add_bry_byte(Bry_type , Tid_type) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_langtext.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_langtext.java new file mode 100644 index 000000000..406db63ee --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_langtext.java @@ -0,0 +1,36 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_langtext { + public static final byte + Tid_language = 0 + , Tid_value = 1 + ; + public static final String + Str_language = "language" + , Str_value = "value" + ; + public static byte[] + Bry_language = Bry_.new_ascii_(Str_language) + , Bry_value = Bry_.new_ascii_(Str_value) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_language , Tid_language) + .Add_bry_byte(Bry_value , Tid_value) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_mainsnak.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_mainsnak.java new file mode 100644 index 000000000..44b5d9fb0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_mainsnak.java @@ -0,0 +1,41 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_mainsnak { + public static final byte + Tid_snaktype = 0 + , Tid_property = 1 + , Tid_hash = 2 + , Tid_datavalue = 3 + , Tid_type = 4 + ; + public static byte[] + Bry_snaktype = Bry_.new_ascii_("snaktype") + , Bry_property = Bry_.new_ascii_("property") + , Bry_hash = Bry_.new_ascii_("hash") + , Bry_datavalue = Bry_.new_ascii_("datavalue") + , Bry_type = Bry_.new_ascii_("type") + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_snaktype , Tid_snaktype) + .Add_bry_byte(Bry_property , Tid_property) + .Add_bry_byte(Bry_hash , Tid_hash) + .Add_bry_byte(Bry_datavalue , Tid_datavalue) + .Add_bry_byte(Bry_type , Tid_type) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_rank.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_rank.java new file mode 100644 index 000000000..3f9550e3f --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_rank.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_rank { + public static final byte // SERIALIZED: + Tid_preferred = 2 + , Tid_normal = 1 + , Tid_deprecated = 0 + , Tid_unknown = Byte_.MaxValue_127 + ; + public static final String + Str_preferred = "preferred" + , Str_normal = "normal" + , Str_deprecated = "deprecated" + ; + public static byte[] + Bry_preferred = Bry_.new_ascii_(Str_preferred) + , Bry_normal = Bry_.new_ascii_(Str_normal) + , Bry_deprecated = Bry_.new_ascii_(Str_deprecated) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_preferred , Tid_preferred) + .Add_bry_byte(Bry_normal , Tid_normal) + .Add_bry_byte(Bry_deprecated , Tid_deprecated) + ; + public static String Xto_str(byte tid) { + switch (tid) { + case Tid_preferred : return Str_preferred; + case Tid_normal : return Str_normal; + case Tid_deprecated : return Str_deprecated; + default : throw Err_.unhandled(tid); + } + } + public static byte Xto_tid(byte[] v) { + Object rv_obj = Dict.Get_by_bry(v); if (rv_obj == null) throw Err_.new_fmt_("unknown rank: val=~{0}", String_.new_utf8_(v)); + return ((Byte_obj_val)rv_obj).Val(); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_sitelink.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_sitelink.java new file mode 100644 index 000000000..91c22d664 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_sitelink.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_sitelink { + public static final byte + Tid_site = 0 + , Tid_title = 1 + , Tid_badges = 2 + ; + public static final String + Str_site = "site" + , Str_title = "title" + , Str_badges = "badges" + ; + public static byte[] + Bry_site = Bry_.new_ascii_(Str_site) + , Bry_title = Bry_.new_ascii_(Str_title) + , Bry_badges = Bry_.new_ascii_(Str_badges) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_site , Tid_site) + .Add_bry_byte(Bry_title , Tid_title) + .Add_bry_byte(Bry_badges , Tid_badges) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_snak_tid.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_snak_tid.java new file mode 100644 index 000000000..075044f46 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_snak_tid.java @@ -0,0 +1,60 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_snak_tid { + public static final byte + Tid_novalue = 0 + , Tid_value = 1 + , Tid_somevalue = 2 + ; + public static final String + Str_novalue = "novalue" + , Str_value = "value" + , Str_somevalue = "somevalue" + ; + public static final byte[] + Bry_novalue = Bry_.new_ascii_(Str_novalue) + , Bry_value = Bry_.new_ascii_(Str_value) + , Bry_somevalue = Bry_.new_ascii_(Str_somevalue) + ; + private static Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_novalue , Tid_novalue) + .Add_bry_byte(Bry_value , Tid_value) + .Add_bry_byte(Bry_somevalue , Tid_somevalue) + ; + public static String Xto_str(byte v) { + switch (v) { + case Tid_novalue: return Str_novalue; + case Tid_value: return Str_value; + case Tid_somevalue: return Str_somevalue; + default: return "unknown"; + } + } + public static byte[] Xto_bry(byte v) { + switch (v) { + case Tid_novalue: return Bry_novalue; + case Tid_value: return Bry_value; + case Tid_somevalue: return Bry_somevalue; + default: return null; + } + } + public static byte Xto_tid(byte[] v) { + Object rv_obj = Dict.Get_by_bry(v); if (rv_obj == null) throw Err_.new_fmt_("unknown snak tid: val=~{0}", String_.new_utf8_(v)); + return ((Byte_obj_val)rv_obj).Val(); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java new file mode 100644 index 000000000..e481e4270 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_utl { + public static byte Get_tid_or_fail(Hash_adp_bry dict, byte[] key) { + Object rv_obj = dict.Get_by_bry(key); + if (rv_obj == null) throw Err_.new_("unknown key; key={0}", String_.new_ascii_(key)); + return ((Byte_obj_val)rv_obj).Val(); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java new file mode 100644 index 000000000..4e767c3c0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_val_tid { + public static final byte + Tid_unknown = 0 + , Tid_value = 1 + , Tid_bad = 1 + , Tid_string = 2 + , Tid_entity = 3 + , Tid_time = 4 + , Tid_globecoordinate = 5 + , Tid_quantity = 6 + , Tid_monolingualtext = 7 + ; + public static final String + Str_bad = "bad" + , Str_string = "string" + , Str_entity = "wikibase-entityid" + , Str_time = "time" + , Str_globecoordinate = "globecoordinate" + , Str_quantity = "quantity" + , Str_monolingualtext = "monolingualtext" + , Str_unknown = "unknown" + ; + public static final byte[] + Bry_bad = Bry_.new_ascii_(Str_bad) + , Bry_string = Bry_.new_ascii_(Str_string) + , Bry_entity = Bry_.new_ascii_(Str_entity) + , Bry_time = Bry_.new_ascii_(Str_time) + , Bry_globecoordinate = Bry_.new_ascii_(Str_globecoordinate) + , Bry_quantity = Bry_.new_ascii_(Str_quantity) + , Bry_monolingualtext = Bry_.new_ascii_(Str_monolingualtext) + ; + private static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_string , Tid_string) + .Add_bry_byte(Bry_entity , Tid_entity) + .Add_bry_byte(Bry_time , Tid_time) + .Add_bry_byte(Bry_globecoordinate , Tid_globecoordinate) + .Add_bry_byte(Bry_quantity , Tid_quantity) + .Add_bry_byte(Bry_monolingualtext , Tid_monolingualtext) + .Add_bry_byte(Bry_bad , Tid_bad) + ; + public static String Xto_str(byte tid) { + switch (tid) { + case Tid_string : return Str_string; + case Tid_entity : return Str_entity; + case Tid_time : return Str_time; + case Tid_globecoordinate : return Str_globecoordinate; + case Tid_quantity : return Str_quantity; + case Tid_monolingualtext : return Str_monolingualtext; + case Tid_bad : return Str_bad; // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20 + default : return Str_unknown; + } + } + public static byte Xto_tid(byte[] src) {return Xto_tid(src, 0, src.length);} + public static byte Xto_tid(byte[] src, int bgn, int end) { + Object bval_obj = Dict.Get_by_mid(src, bgn, end); + if (bval_obj == null) return Tid_unknown; + return ((Byte_obj_val)bval_obj).Val(); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_entity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_entity.java new file mode 100644 index 000000000..6ffbee595 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_entity.java @@ -0,0 +1,42 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_entity { + public static final byte + Tid_entity_type = 0 + , Tid_numeric_id = 1 + ; + public static final String + Str_entity_type = "entity-type" + , Str_numeric_id = "numeric-id" + ; + public static byte[] + Bry_entity_type = Bry_.new_ascii_(Str_entity_type) + , Bry_numeric_id = Bry_.new_ascii_(Str_numeric_id) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_entity_type , Tid_entity_type) + .Add_bry_byte(Bry_numeric_id , Tid_numeric_id) + ; + public static final String + Val_entity_type_item_str = "item" + ; + public static final byte[] + Val_entity_type_item_bry = Bry_.new_ascii_(Val_entity_type_item_str) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_globecoordinate.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_globecoordinate.java new file mode 100644 index 000000000..2afa536fc --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_globecoordinate.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_globecoordinate { + public static final byte + Tid_latitude = 0 + , Tid_longitude = 1 + , Tid_altitude = 2 + , Tid_precision = 3 + , Tid_globe = 4 + ; + public static final String + Str_latitude = "latitude" + , Str_longitude = "longitude" + , Str_altitude = "altitude" + , Str_precision = "precision" + , Str_globe = "globe" + ; + public static byte[] + Bry_latitude = Bry_.new_ascii_(Str_latitude) + , Bry_longitude = Bry_.new_ascii_(Str_longitude) + , Bry_altitude = Bry_.new_ascii_(Str_altitude) + , Bry_precision = Bry_.new_ascii_(Str_precision) + , Bry_globe = Bry_.new_ascii_(Str_globe) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_latitude , Tid_latitude) + .Add_bry_byte(Bry_longitude , Tid_longitude) + .Add_bry_byte(Bry_altitude , Tid_altitude) + .Add_bry_byte(Bry_precision , Tid_precision) + .Add_bry_byte(Bry_globe , Tid_globe) + ; + public static String + Val_globe_dflt_str = "http:\\/\\/www.wikidata.org\\/entity\\/Q2" + ; + public static byte[] + Val_globe_dflt_bry = Bry_.new_ascii_(Val_globe_dflt_str) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_monolingualtext.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_monolingualtext.java new file mode 100644 index 000000000..ecee3c9a1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_monolingualtext.java @@ -0,0 +1,36 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_monolingualtext { + public static final byte + Tid_text = 0 + , Tid_language = 1 + ; + public static final String + Str_text = "text" + , Str_language = "language" + ; + public static byte[] + Bry_text = Bry_.new_ascii_(Str_text) + , Bry_language = Bry_.new_ascii_(Str_language) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_text , Tid_text) + .Add_bry_byte(Bry_language , Tid_language) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_quantity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_quantity.java new file mode 100644 index 000000000..a9a569270 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_quantity.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_quantity { + public static final byte + Tid_amount = 0 + , Tid_unit = 1 + , Tid_upperbound = 2 + , Tid_lowerbound = 3 + ; + public static final String + Str_amount = "amount" + , Str_unit = "unit" + , Str_upperbound = "upperBound" + , Str_lowerbound = "lowerBound" + ; + public static byte[] + Bry_amount = Bry_.new_ascii_(Str_amount) + , Bry_unit = Bry_.new_ascii_(Str_unit) + , Bry_upperbound = Bry_.new_ascii_(Str_upperbound) + , Bry_lowerbound = Bry_.new_ascii_(Str_lowerbound) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_amount , Tid_amount) + .Add_bry_byte(Bry_unit , Tid_unit) + .Add_bry_byte(Bry_upperbound , Tid_upperbound) + .Add_bry_byte(Bry_lowerbound , Tid_lowerbound) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_string.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_string.java new file mode 100644 index 000000000..66105ef28 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_string.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_string { + public static final byte + Tid_value = 0 + , Tid_type = 1 + ; + public static byte[] + Bry_value = Bry_.new_ascii_("value") + , Bry_type = Bry_.new_ascii_("type") + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_value , Tid_value) + .Add_bry_byte(Bry_type , Tid_type) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java new file mode 100644 index 000000000..9da1368b7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_dict_value_time { + public static final byte + Tid_time = 0 + , Tid_timezone = 1 + , Tid_before = 2 + , Tid_after = 3 + , Tid_precision = 4 + , Tid_calendarmodel = 5 + ; + public static final String + Str_time = "time" + , Str_timezone = "timezone" + , Str_before = "before" + , Str_after = "after" + , Str_precision = "precision" + , Str_calendarmodel = "calendarmodel" + ; + public static byte[] + Bry_time = Bry_.new_ascii_(Str_time) + , Bry_timezone = Bry_.new_ascii_(Str_timezone) + , Bry_before = Bry_.new_ascii_(Str_before) + , Bry_after = Bry_.new_ascii_(Str_after) + , Bry_precision = Bry_.new_ascii_(Str_precision) + , Bry_calendarmodel = Bry_.new_ascii_(Str_calendarmodel) + ; + public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() + .Add_bry_byte(Bry_time , Tid_time) + .Add_bry_byte(Bry_timezone , Tid_timezone) + .Add_bry_byte(Bry_before , Tid_before) + .Add_bry_byte(Bry_after , Tid_after) + .Add_bry_byte(Bry_precision , Tid_precision) + .Add_bry_byte(Bry_calendarmodel , Tid_calendarmodel) + ; + public static final int + Val_precision_int = 11 + , Val_before_int = 0 + , Val_after_int = 0 + , Val_timezone_int = 0 + ; + public static final String + Val_precision_str = "11" + , Val_before_str = "0" + , Val_after_str = "0" + , Val_timezone_str = "0" + , Val_calendarmodel_str = "http://www.wikidata.org/entity/Q1985727" + ; + public static final byte[] + Val_precision_bry = Bry_.new_ascii_(Val_precision_str) + , Val_before_bry = Bry_.new_ascii_(Val_before_str) + , Val_after_bry = Bry_.new_ascii_(Val_after_str) + , Val_timezone_bry = Bry_.new_ascii_(Val_timezone_str) + , Val_calendarmodel_bry = Bry_.new_ascii_(Val_calendarmodel_str) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java new file mode 100644 index 000000000..f9c030e01 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +public class Wdata_langtext_itm { + public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text;} + public byte[] Lang() {return lang;} private byte[] lang; + public byte[] Text() {return text;} private byte[] text; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", String_.new_utf8_(lang), String_.new_utf8_(text)); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java new file mode 100644 index 000000000..67209d431 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +public class Wdata_sitelink_itm { + public Wdata_sitelink_itm(byte[] site, byte[] name, byte[][] badges) {this.site = site; this.name = name; this.badges = badges;} + public byte[] Site() {return site;} private final byte[] site; + public byte[] Name() {return name;} private final byte[] name; + public byte[][] Badges() {return badges;} private final byte[][] badges; + @Override public String toString() {// TEST: + return String_.Concat_with_str("|", String_.new_utf8_(site), String_.new_utf8_(name), String_.Concat_with_str(",", String_.Ary(badges))); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java index 07a3bb28c..dc5c2e16d 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.qrys.*; -import gplx.json.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.bldrs.oimgs.*; public class Xob_wdata_db_cmd extends Xob_dump_mgr_base implements Xob_cmd { private Wdata_tbl_mgr tbl_mgr = new Wdata_tbl_mgr(); @@ -38,7 +38,7 @@ public class Xob_wdata_db_cmd extends Xob_dump_mgr_base implements Xob_cmd { } @Override protected void Cmd_bgn_end() { wdata_mgr = bldr.App().Wiki_mgr().Wdata_mgr(); - json_parser = wdata_mgr.Parser(); + json_parser = wdata_mgr.Jdoc_parser(); tbl_mgr.Provider().Txn_mgr().Txn_bgn_if_none(); } @Override public void Exec_pg_itm_hook(Xow_ns ns, Xodb_page page, byte[] page_src) { @@ -196,7 +196,7 @@ class Wdata_link_tbl extends Wdata_tbl_base { @Override public Db_idx_itm[] Idx_ary() {return new Db_idx_itm[] {Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_link__main ON wdata_link (page_id, wiki_key);")};} @Override public String[] Fld_ary() {return new String[] {Fld_page_id, Fld_wiki_key, Fld_val};} @Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) { - OrderedHash hash = wdoc.Link_list(); + OrderedHash hash = wdoc.Sitelink_list(); int len = hash.Count(); Db_stmt insert_stmt = this.Insert_stmt(); for (int i = 0; i < len; i++) { @@ -250,35 +250,46 @@ class Wdata_claim_tbl extends Wdata_tbl_base { OrderedHash list = wdoc.Claim_list(); int list_len = list.Count(); for (int i = 0; i < list_len; i++) { - Wdata_prop_grp claim_grp = (Wdata_prop_grp)list.FetchAt(i); + Wdata_claim_grp claim_grp = (Wdata_claim_grp)list.FetchAt(i); int itms_len = claim_grp.Itms_len(); int entity_id = -1; byte[] claim_val = Bry_.Empty; for (int j = 0; j < itms_len; j++) { - Wdata_prop_itm_core claim = claim_grp.Itms_get_at(j); - byte val_tid = claim.Val_tid_byte(); + Wdata_claim_itm_core claim = claim_grp.Itms_get_at(j); + byte val_tid = claim.Val_tid(); switch (val_tid) { - case Wdata_prop_itm_base_.Val_tid_string: - case Wdata_prop_itm_base_.Val_tid_time: - case Wdata_prop_itm_base_.Val_tid_quantity: - case Wdata_prop_itm_base_.Val_tid_monolingualtext: - claim_val = claim.Val(); + case Wdata_dict_val_tid.Tid_string: + Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)claim; + claim_val = claim_str.Val_str(); break; - case Wdata_prop_itm_base_.Val_tid_entity: - entity_id = Bry_.Xto_int_or(claim.Val(), -2); - Wdata_doc entity_doc = wdata_mgr.Pages_get(Bry_.Add(Wdata_wiki_mgr.Bry_q, claim.Val())); + case Wdata_dict_val_tid.Tid_time: + Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)claim; + claim_val = claim_time.Time(); + break; + case Wdata_dict_val_tid.Tid_quantity: + Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)claim; + claim_val = claim_quantity.Amount(); + break; + case Wdata_dict_val_tid.Tid_monolingualtext: + Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)claim; + claim_val = Bry_.Add_w_dlm(Byte_ascii.Pipe, claim_monolingualtext.Lang(), claim_monolingualtext.Text()); + break; + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)claim; + entity_id = claim_entity.Entity_id(); + Wdata_doc entity_doc = wdata_mgr.Pages_get(Bry_.Add(Wdata_wiki_mgr.Bry_q, claim_entity.Entity_id_bry())); if (entity_doc != null) // NOTE: invalid document could be cited; EX: Q3235 cites prop p832 as Q14916523 claim_val = entity_doc.Label_list_get(lang_key); break; - case Wdata_prop_itm_base_.Val_tid_globecoordinate: - case Wdata_prop_itm_base_.Val_tid_bad: { - byte[][] flds = Bry_.Split(claim.Val(),Wdata_prop_itm_core.Prop_dlm); - claim_val = Bry_.Add_w_dlm(Byte_ascii.Comma, flds[0], flds[1]); + case Wdata_dict_val_tid.Tid_globecoordinate: + case Wdata_dict_val_tid.Tid_bad: { + Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)claim; + claim_val = Bry_.Add_w_dlm(Byte_ascii.Comma, claim_globecoordinate.Lat(), claim_globecoordinate.Lng()); break; } default: - if ( claim.Snak_tid() == Wdata_prop_itm_base_.Snak_tid_somevalue // somevalue has no val_tid; not sure why; see Q17 and prop 138 - || claim.Snak_tid() == Wdata_prop_itm_base_.Snak_tid_novalue) {} // novalue has no val_tid; see q30 and official language + if ( claim.Snak_tid() == Wdata_dict_snak_tid.Tid_somevalue // somevalue has no val_tid; not sure why; see Q17 and prop 138 + || claim.Snak_tid() == Wdata_dict_snak_tid.Tid_novalue) {} // novalue has no val_tid; see q30 and official language else throw Err_.unhandled(val_tid); break; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_pid_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_pid_base.java index 94a017e23..89c21c42a 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_pid_base.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_pid_base.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xobd_wkr, GfoInvkAble { public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;} public abstract String Wkr_key(); @@ -26,24 +26,23 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo public void Wkr_ini(Xob_bldr bldr) {} public void Wkr_bgn(Xob_bldr bldr) { this.Init_dump(this.Wkr_key(), wiki.Fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append) - parser = bldr.App().Wiki_mgr().Wdata_mgr().Parser(); + parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser(); this.Pid_bgn(); } Json_parser parser; public void Wkr_run(Xodb_page page) { if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return; - Json_doc doc = parser.Parse(page.Text()); - if (doc == null) { + Json_doc jdoc = parser.Parse(page.Text()); + if (jdoc == null) { bldr.Usr_dlg().Warn_many(GRP_KEY, "json.invalid", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_utf8_(page.Ttl_wo_ns())); return; } - byte[] qid = Wdata_doc_.Entity_extract(doc); - Json_itm_nde label_nde = Json_itm_nde.cast_(doc.Get_grp(Wdata_doc_consts.Key_atr_label_bry)); if (label_nde == null) return; // no labels; ignore - int len = label_nde.Subs_len(); - for (int i = 0; i < len; i++) { - Json_itm_kv kv = (Json_itm_kv)label_nde.Subs_get_at(i); - byte[] lang_key = kv.Key().Data_bry(); - byte[] prop_key = kv.Val().Data_bry(); - this.Pid_add(lang_key, prop_key, qid); + Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc); + byte[] qid = wdoc_parser.Parse_qid(jdoc); + OrderedHash list = wdoc_parser.Parse_langvals(qid, jdoc, Bool_.Y); + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_langtext_itm label = (Wdata_langtext_itm)list.FetchAt(i); + this.Pid_add(label.Lang(), label.Text(), qid); } } public void Wkr_end() {this.Pid_end();} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_qid_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_qid_base.java index 44e214838..d2fe0e630 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_qid_base.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_qid_base.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; import gplx.ios.*; +import gplx.json.*; import gplx.ios.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xobd_wkr, GfoInvkAble { public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;} public abstract String Wkr_key(); @@ -26,38 +26,37 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo public void Wkr_ini(Xob_bldr bldr) {} public void Wkr_bgn(Xob_bldr bldr) { this.Init_dump(this.Wkr_key(), wiki.Fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append) - parser = bldr.App().Wiki_mgr().Wdata_mgr().Parser(); + parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser(); this.Qid_bgn(); - } Json_parser parser; + } private Json_parser parser; public void Wkr_run(Xodb_page page) { if (page.Ns_id() != Xow_ns_.Id_main) return; // qid pages are only in the Main namespace - Json_doc doc = parser.Parse(page.Text()); - if (doc == null) { + Json_doc jdoc = parser.Parse(page.Text()); + if (jdoc == null) { bldr.Usr_dlg().Warn_many(GRP_KEY, "json.invalid", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_utf8_(page.Ttl_wo_ns())); return; } - byte[] qid = Wdata_doc_.Entity_extract(doc); - Json_itm_nde links_nde = Json_itm_nde.cast_(doc.Get_grp(Wdata_doc_consts.Key_atr_links_bry)); if (links_nde == null) return; // no links; ignore - int len = links_nde.Subs_len(); if (len == 0) return; // no subs; return; - Wdata_qid_data data_core = null; - links.Clear(); - for (int i = 0; i < len; i++) { // iterate links; find data_core (hopefully enwiki) - Json_itm_kv kv = (Json_itm_kv)links_nde.Subs_get_at(i); - byte[] xwiki_key = kv.Key().Data_bry(); - byte[] ttl_bry = Wdata_doc_.Link_extract(kv); - Wdata_qid_data data = new Wdata_qid_data(xwiki_key, ttl_bry); - links.Add(data); - if (i == 0) data_core = data; - if (Bry_.Eq(xwiki_key, Xwiki_key_en)) data_core = data; + Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc); + byte[] qid = wdoc_parser.Parse_qid(jdoc); + OrderedHash sitelinks = wdoc_parser.Parse_sitelinks(qid, jdoc); + int sitelinks_len = sitelinks.Count(); if (sitelinks_len == 0) return; // no subs; return; + Wdata_sitelink_itm main_sitelink = null; + for (int i = 0; i < sitelinks_len; i++) { // iterate links; find main_sitelink (hopefully enwiki) + Wdata_sitelink_itm sitelink = (Wdata_sitelink_itm)sitelinks.FetchAt(i); + byte[] xwiki_key = sitelink.Site(); + if ( i == 0 // assume 1st item is mainlink_data; needed for null checks; also, if no links are enwiki, then hope / assume that first link will be to an article in correct ns + || Bry_.Eq(xwiki_key, Xwiki_key_en) // assume enwiki item is to correct ns + ) + main_sitelink = sitelink; } - Xoa_ttl core_ttl = Xoa_ttl.parse_(wiki, data_core.Ttl()); // NOTE: parse ttl to get ns; this may still be inaccurate as it is using wikidata's ns, not enwiki's;; DATE:2014-07-23 + Xoa_ttl core_ttl = Xoa_ttl.parse_(wiki, main_sitelink.Name()); // NOTE: parse ttl to get ns; this may still be inaccurate as it is using wikidata's ns, not enwiki's;; DATE:2014-07-23 Xow_ns core_ns = core_ttl.Ns(); boolean core_ns_is_main = core_ns.Id_main(); - for (int i = 0; i < len; i++) { // iterate links again; do parsing, but assume any ns is same as enwiki - Wdata_qid_data data = (Wdata_qid_data)links.FetchAt(i); - byte[] data_ttl_bry = data.Ttl(); + for (int i = 0; i < sitelinks_len; i++) { // iterate links again; do parsing, but assume any ns is same as enwiki + Wdata_sitelink_itm sitelink = (Wdata_sitelink_itm)sitelinks.FetchAt(i); + byte[] data_ttl_bry = sitelink.Name(); byte[] actl_ttl = null; if (core_ns_is_main) { Xoa_ttl data_ttl = Xoa_ttl.parse_(wiki, data_ttl_bry); @@ -73,9 +72,9 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo else actl_ttl = Bry_.Mid(data_ttl_bry, colon_pos + 1, data_ttl_len); } - this.Qid_add(data.Xwiki_key(), core_ns, actl_ttl, qid); + this.Qid_add(sitelink.Site(), core_ns, actl_ttl, qid); } - } ListAdp links = ListAdp_.new_(); Xob_bz2_file tmp_xwiki = new Xob_bz2_file(); Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + } public void Wkr_end() { this.Qid_end(); } static final byte[] Xwiki_key_en = Bry_.new_ascii_("enwiki"); @@ -83,11 +82,6 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo public void Wkr_print() {} private static final String GRP_KEY = "xowa.wdata.qid_wkr"; } -class Wdata_qid_data { - public Wdata_qid_data(byte[] xwiki_key, byte[] ttl) {this.xwiki_key = xwiki_key; this.ttl = ttl;} - public byte[] Xwiki_key() {return xwiki_key;} private byte[] xwiki_key; - public byte[] Ttl() {return ttl;} private byte[] ttl; -} class Wdata_idx_bldr_qid extends Wdata_idx_mgr_base { public Wdata_idx_bldr_qid Ctor(Xob_wdata_qid_base wkr, Xob_bldr bldr, Xow_wiki wiki, int dump_fil_len) {super.Ctor(wkr, bldr, wiki, dump_fil_len); return this;} public void Add(String wiki_key, Xow_ns ns, byte[] ttl, byte[] qid) { diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java new file mode 100644 index 000000000..bb6dfebbf --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +public interface Wdata_doc_parser { + byte[] Parse_qid(Json_doc doc); + OrderedHash Parse_sitelinks(byte[] qid, Json_doc doc); + OrderedHash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description); + OrderedHash Parse_aliases(byte[] qid, Json_doc doc); + OrderedHash Parse_claims(Json_doc doc); + Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java new file mode 100644 index 000000000..473bbe22c --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java @@ -0,0 +1,261 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +public class Wdata_doc_parser_v1 implements Wdata_doc_parser { + public Wdata_doc_parser_v1(Gfo_usr_dlg usr_dlg) {this.usr_dlg = usr_dlg;} private Gfo_usr_dlg usr_dlg; + public Wdata_doc_parser_v1() {} + public byte[] Parse_qid(Json_doc doc) { + try { + Json_itm kv_val = doc.Find_nde(Bry_entity); + switch (kv_val.Tid()) { + case Json_itm_.Tid_string: // "entity":"q1" + return kv_val.Data_bry(); + case Json_itm_.Tid_array: // "entity":["item",1] + Json_itm_ary kv_val_as_ary = (Json_itm_ary)kv_val; + Json_itm entity_id = kv_val_as_ary.Subs_get_at(1); + return Bry_.Add(Byte_ascii.Ltr_q, entity_id.Data_bry()); + default: + throw Err_.unhandled(kv_val.Tid()); + } + } catch (Exception e) {throw Err_.err_(e, "failed to parse qid; src={0}", String_.new_utf8_(doc.Src()));} + } + public OrderedHash Parse_sitelinks(byte[] qid, Json_doc doc) { + try { + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + for (int i = 0; i < list_len; ++i) { + Json_itm_kv wiki_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + byte[] site_bry = wiki_kv.Key().Data_bry(); + byte[] title_bry = null; byte[][] badges_bry_ary = null; + if (wiki_kv.Val().Tid() == Json_itm_.Tid_nde) { // v1.2: "enwiki":{name:"Earth", badges:[]} + Json_itm_nde val_nde = Json_itm_nde.cast_(wiki_kv.Val()); + Json_itm_kv name_kv = Json_itm_kv.cast_(val_nde.Subs_get_at(0)); + title_bry = name_kv.Val().Data_bry(); + Json_itm_kv badges_kv = Json_itm_kv.cast_(val_nde.Subs_get_at(1)); + if (badges_kv != null) {// TEST:some tests do not define a badges nde; ignore if null; DATE:2014-09-19 + Json_itm_ary badges_ary = Json_itm_ary.cast_(badges_kv.Val()); + badges_bry_ary = badges_ary.Xto_bry_ary(); + } + } + else { // v1.1: "enwiki":"Earth" + title_bry = wiki_kv.Val().Data_bry(); + } + Wdata_sitelink_itm itm = new Wdata_sitelink_itm(site_bry, title_bry, badges_bry_ary); + rv.Add(site_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse sitelinks; qid={0}", String_.new_utf8_(qid));} + } + public OrderedHash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) { + try { + byte[] langval_key = label_or_description ? Bry_label : Bry_description; + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + for (int i = 0; i < list_len; ++i) { + Json_itm_kv data_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + byte[] lang_bry = data_kv.Key().Data_bry(); + Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, data_kv.Val().Data_bry()); + rv.Add(lang_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse langvals; qid={0} langval_tid={1}", String_.new_utf8_(qid), label_or_description);} + } + public OrderedHash Parse_aliases(byte[] qid, Json_doc doc) { + try { + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + for (int i = 0; i < list_len; ++i) { + Json_itm_kv data_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + byte[] lang_bry = data_kv.Key().Data_bry(); + byte[][] vals_bry_ary = null; + Json_itm data_val = data_kv.Val(); + switch (data_val.Tid()) { + case Json_itm_.Tid_array: // EX: 'en':['en_val_1','en_val_2'] + Json_itm_ary vals_ary = Json_itm_ary.cast_(data_val); + vals_bry_ary = vals_ary.Xto_bry_ary(); + break; + case Json_itm_.Tid_nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21 + Json_itm_nde vals_nde = Json_itm_nde.cast_(data_val); + int vals_len = vals_nde.Subs_len(); + vals_bry_ary = new byte[vals_len][]; + for (int j = 0; j < vals_len; ++j) { + Json_itm_kv vals_sub_kv = Json_itm_kv.cast_(vals_nde.Subs_get_at(j)); + vals_bry_ary[j] = vals_sub_kv.Val().Data_bry(); + } + break; + default: throw Err_.unhandled(data_val.Tid()); + } + Wdata_alias_itm itm = new Wdata_alias_itm(lang_bry, vals_bry_ary); + rv.Add(lang_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse aliases; qid={0}", String_.new_utf8_(qid));} + } + public OrderedHash Parse_claims(Json_doc doc) { + try { + Json_itm_ary list_nde = Json_itm_ary.cast_(doc.Get_grp(Bry_claims)); if (list_nde == null) return Empty_ordered_hash_generic; + ListAdp temp_list = ListAdp_.new_(); + byte[] src = doc.Src(); + int len = list_nde.Subs_len(); + for (int i = 0; i < len; i++) { + Json_itm_nde claim_nde = Json_itm_nde.cast_(list_nde.Subs_get_at(i)); + Wdata_claim_itm_core claim_itm = Make_claim_itm(src, claim_nde); + temp_list.Add(claim_itm); + } + return Claims_list_to_hash(temp_list); + } catch (Exception e) {throw Err_.err_(e, "failed to parse claims; qid={0}", String_.new_utf8_(doc.Src()));} + } + public Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde) {throw Err_.not_implemented_();} + public static OrderedHash Claims_list_to_hash(ListAdp full_list) { + full_list.Sort(); + OrderedHash rv = OrderedHash_.new_(); ListAdp temp_itms = ListAdp_.new_(); + int prv_pid = -1; + int len = full_list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_claim_itm_core claim_itm = (Wdata_claim_itm_core)full_list.FetchAt(i); + int cur_pid = claim_itm.Pid(); + if (prv_pid != cur_pid && prv_pid != -1) + Claims_list_to_hash__add(rv, prv_pid, temp_itms); + temp_itms.Add(claim_itm); + prv_pid = cur_pid; + } + Claims_list_to_hash__add(rv, prv_pid, temp_itms); + return rv; + } + private static void Claims_list_to_hash__add(OrderedHash rv, int pid, ListAdp temp_itms) { + Int_obj_ref claim_grp_key = Int_obj_ref.new_(pid); + Wdata_claim_grp claim_grp = new Wdata_claim_grp(claim_grp_key, (Wdata_claim_itm_core[])temp_itms.XtoAryAndClear(Wdata_claim_itm_core.class)); + rv.Add(claim_grp_key, claim_grp); + } + private Wdata_claim_itm_core Make_claim_itm(byte[] src, Json_itm_nde prop_nde) { + int len = prop_nde.Subs_len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys) + Wdata_claim_itm_core rv = null; + for (int i = 0; i < len; i++) { + Json_itm_kv kv = Json_itm_kv.cast_(prop_nde.Subs_get_at(i)); + 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()); + if (bv == null) {Warn("invalid prop node: ~{0}", String_.new_utf8_mid_safe_(src, kv_key.Src_bgn(), kv_key.Src_end())); return null;} + switch (bv.Val()) { + case Prop_tid_m: + rv = New_prop_by_m(src, Json_itm_ary.cast_(kv.Val())); + if (rv == null) return null; + break; + case Prop_tid_g: + rv.Wguid_(kv.Data_bry()); + break; + case Prop_tid_rank: + rv.Rank_tid_((byte)Int_.cast_(((Json_itm_int)kv.Val()).Data_as_int())); + break; + case Prop_tid_q: + break; + case Prop_tid_refs: + break; + default: throw Err_.unhandled(bv.Val()); + } + } + return rv; + } + private Wdata_claim_itm_core New_prop_by_m(byte[] src, Json_itm_ary ary) { + byte snak_tid = Wdata_dict_snak_tid.Xto_tid(ary.Subs_get_at(0).Data_bry()); + int pid = Json_itm_int.cast_(ary.Subs_get_at(1)).Data_as_int(); + switch (snak_tid) { + case Wdata_dict_snak_tid.Tid_novalue : return Wdata_claim_itm_system.new_novalue(pid); + case Wdata_dict_snak_tid.Tid_somevalue : return Wdata_claim_itm_system.new_somevalue(pid); + } + Json_itm val_tid_itm = ary.Subs_get_at(2); + byte val_tid = Wdata_dict_val_tid.Xto_tid(src, val_tid_itm.Src_bgn(), val_tid_itm.Src_end()); + return Make_itm(pid, snak_tid, val_tid, ary); + } + + private Wdata_claim_itm_core Make_itm(int pid, byte snak_tid, byte val_tid, Json_itm_ary ary) { + switch (val_tid) { + case Wdata_dict_val_tid.Tid_string: + return new Wdata_claim_itm_str(pid, snak_tid, ary.Subs_get_at(3).Data_bry()); + case Wdata_dict_val_tid.Tid_entity: { + Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); + Json_itm_kv entity_kv = Json_itm_kv.cast_(sub_nde.Subs_get_at(1)); + return new Wdata_claim_itm_entity(pid, snak_tid, entity_kv.Val().Data_bry()); + } + case Wdata_dict_val_tid.Tid_time: { + Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); + return new Wdata_claim_itm_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 Wdata_dict_val_tid.Tid_globecoordinate: case Wdata_dict_val_tid.Tid_bad: { + Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); + return new Wdata_claim_itm_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 Wdata_dict_val_tid.Tid_quantity: { + Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); + return new Wdata_claim_itm_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 Wdata_dict_val_tid.Tid_monolingualtext: { + Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); + return new Wdata_claim_itm_monolingualtext(pid, snak_tid, Get_val(sub_nde, 1), Get_val(sub_nde, 0)); + } + default: {throw Err_.unhandled(val_tid);} + } + } + private static byte[] Get_val(Json_itm_nde sub_nde, int i) { + Json_itm_kv kv = Json_itm_kv.cast_(sub_nde.Subs_get_at(i)); + return kv.Val().Data_bry(); + } + private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);} + public static final OrderedHash Empty_ordered_hash_bry = OrderedHash_.new_bry_(), Empty_ordered_hash_generic = OrderedHash_.new_(); + private static final byte Prop_tid_m = 0, Prop_tid_q = 1, Prop_tid_g = 2, Prop_tid_rank = 3, Prop_tid_refs = 4; + private static final Hash_adp_bry Prop_key_hash = Hash_adp_bry.ci_ascii_() + .Add_bry_byte(Wdata_dict_claim_v1.Bry_m , Prop_tid_m) + .Add_bry_byte(Wdata_dict_claim_v1.Bry_q , Prop_tid_q) + .Add_bry_byte(Wdata_dict_claim_v1.Bry_g , Prop_tid_g) + .Add_bry_byte(Wdata_dict_claim_v1.Bry_rank , Prop_tid_rank) + .Add_bry_byte(Wdata_dict_claim_v1.Bry_refs , Prop_tid_refs); + OrderedHash Bld_hash(Json_doc doc, byte[] key) { + Json_itm_nde nde = Json_itm_nde.cast_(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int len = nde.Subs_len(); + for (int i = 0; i < len; i++) { + Json_itm_kv kv = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte[] kv_key = kv.Key().Data_bry(); + rv.Add(kv_key, kv); + } + return rv; + } + public static final String + Str_entity = "entity" + , Str_id = "id" + , Str_links = "links" + , Str_label = "label" + , Str_aliases = "aliases" + , Str_claims = "claims" + , Str_description = "description" + , Str_name = "name" + ; + public static final byte[] + Bry_entity = Bry_.new_ascii_(Str_entity) + , Bry_id = Bry_.new_ascii_(Str_id) + , Bry_links = Bry_.new_ascii_(Str_links) + , Bry_label = Bry_.new_ascii_(Str_label) + , Bry_aliases = Bry_.new_ascii_(Str_aliases) + , Bry_claims = Bry_.new_ascii_(Str_claims) + , Bry_description = Bry_.new_ascii_(Str_description) + , Bry_name = Bry_.new_ascii_(Str_name) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java new file mode 100644 index 000000000..97b474855 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java @@ -0,0 +1,229 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +public class Wdata_doc_parser_v1_tst { + @Before public void init() {fxt.Init();} private Wdata_doc_parser_v1_fxt fxt = new Wdata_doc_parser_v1_fxt(); + @Test public void Entity_v1_1() { + fxt.Test_entity("{ 'entity':'q1' }", "q1"); + } + @Test public void Entity_v1_2() { + fxt.Test_entity("{ 'entity':['item',1] }", "q1"); + } + @Test public void Sitelink_v1_1() { + fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last + ( "{ 'links':" + , " { 'enwiki':'en_val'" + , " , 'dewiki':'de_val'" + , " , 'frwiki':'fr_val'" + , " }" + , "}" + ) + , fxt.Make_sitelink("enwiki", "en_val") + , fxt.Make_sitelink("dewiki", "de_val") + , fxt.Make_sitelink("frwiki", "fr_val") + ); + } + @Test public void Sitelink_v1_2() { + fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last + ( "{ 'links':" + , " { 'enwiki':" + , " { 'name':'en_val'" + , " , 'badges':" + , " [ 'Q10'" + , " , 'Q11'" + , " , 'Q12'" + , " ]" + , " }" + , " , 'dewiki':" + , " { 'name':'de_val'" + , " , 'badges':" + , " [ 'Q2'" + , " ]" + , " }" + , " , 'frwiki':" + , " { 'name':'fr_val'" + , " , 'badges':[]" + , " }" + , " }" + , "}" + ) + , fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12") + , fxt.Make_sitelink("dewiki", "de_val", "Q2") + , fxt.Make_sitelink("frwiki", "fr_val") + ); + } + @Test public void Labels() { + fxt.Test_labels(String_.Concat_lines_nl_skip_last + ( "{ 'label':" + , " { 'en':'en_val'" + , " , 'de':'de_val'" + , " , 'fr':'fr_val'" + , " }" + , "}" + ) + , fxt.Make_langval("en", "en_val") + , fxt.Make_langval("de", "de_val") + , fxt.Make_langval("fr", "fr_val") + ); + } + @Test public void Descriptions() { + fxt.Test_descriptions(String_.Concat_lines_nl_skip_last + ( "{ 'description':" + , " { 'en':'en_val'" + , " , 'de':'de_val'" + , " , 'fr':'fr_val'" + , " }" + , "}" + ) + , fxt.Make_langval("en", "en_val") + , fxt.Make_langval("de", "de_val") + , fxt.Make_langval("fr", "fr_val") + ); + } + @Test public void Aliases() { + fxt.Test_aliases(String_.Concat_lines_nl_skip_last + ( "{ 'aliases':" + , " { 'en':" + , " [ 'en_val_1'" + , " , 'en_val_2'" + , " , 'en_val_3'" + , " ]" + , " ," + , " 'de':" + , " [ 'de_val_1'" + , " , 'de_val_2'" + , " ]" + , " ," + , " 'fr':" + , " [ 'fr_val_1'" + , " ]" + , " }" + , "}" + ) + , fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3") + , fxt.Make_alias("de", "de_val_1", "de_val_2") + , fxt.Make_alias("fr", "fr_val_1") + ); + } + @Test public void Aliases_alt() { + fxt.Test_aliases(String_.Concat_lines_nl_skip_last + ( "{ 'aliases':" + , " { 'en':" + , " { '0':'en_val_1'" + , " , '1':'en_val_2'" + , " , '2':'en_val_3'" + , " }" + , " }" + , "}" + ) + , fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3") + ); + } + @Test public void Claims() { + fxt.Test_claims(String_.Concat_lines_nl_skip_last + ( "{ 'claims':" + , " [" + , " { 'm':" + , " [ 'value'" + , " , 1" + , " , 'string'" + , " , 'abc'" + , " ]" + , " , 'q':[]" + , " , 'g':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'" + , " , 'rank':1" + , " , 'refs':[]" + , " }" + , " ]" + , "}" + ) + , fxt.Make_claim_str(1, "abc") + ); + } + @Test public void Claim_bad() { // wikidata flags several entries as "bad"; https://www.wikidata.org/wiki/Wikidata:Project_chat/Archive/2013/10 + fxt.Test_claims(String_.Concat_lines_nl_skip_last + ( "{ 'entity':['item',2]" + , ", 'claims':" + , " [" + , " { 'm':" + , " [ 'value'" + , " , 373" + , " , 'bad'" + , " ," + , " { 'latitude':1" + , " , 'longitude':2" + , " , 'altitude':null" + , " , 'precision':1" + , " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'" + , " }" + , " ]" + , " }" + , " ]" + , "}" + ) + , fxt.Make_claim_globecoordinate(1, "1", "2", "1") // assume "bad" is same as globecoordinate; DATE:2014-09-20 + ); + } +} +abstract class Wdata_doc_parser_fxt_base { + protected Wdata_doc_parser parser; + public void Init() { + if (parser == null) parser = Make_parser(); + } + public abstract Wdata_doc_parser Make_parser(); + public Wdata_sitelink_itm Make_sitelink(String site, String name, String... badges) {return new Wdata_sitelink_itm(Bry_.new_utf8_(site), Bry_.new_utf8_(name), Bry_.Ary(badges));} + public Wdata_langtext_itm Make_langval(String lang, String text) {return new Wdata_langtext_itm(Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_alias_itm Make_alias(String lang, String... vals) {return new Wdata_alias_itm(Bry_.new_utf8_(lang), Bry_.Ary(vals));} + public Wdata_claim_itm_core Make_claim_str(int pid, String val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(val));} + public Wdata_claim_itm_core Make_claim_entity(int pid, int entityId) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(entityId));} + public Wdata_claim_itm_core Make_claim_monolingualtext(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_claim_itm_core Make_claim_globecoordinate(int pid, String lat, String lng, String prc) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lat), Bry_.new_utf8_(lng), Bry_.new_ascii_("null"), Bry_.new_utf8_(prc), Bry_.new_ascii_("http://www.wikidata.org/entity/Q2"));} + public Wdata_claim_itm_core Make_claim_quantity(int pid, int val, int unit, int ubound, int lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(Int_.Xto_str(val)), Bry_.new_utf8_(Int_.Xto_str(unit)), Bry_.new_utf8_(Int_.Xto_str(ubound)), Bry_.new_utf8_(Int_.Xto_str(lbound)));} + public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_doc_bldr.Xto_time(val), Wdata_dict_value_time.Val_timezone_bry, Wdata_dict_value_time.Val_before_bry, Wdata_dict_value_time.Val_after_bry, Wdata_dict_value_time.Val_precision_bry, Wdata_dict_value_time.Val_calendarmodel_bry);} + public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_utf8_(parser.Parse_qid(Json_doc.new_apos_(raw))));} + public void Test_sitelinks(String raw, Wdata_sitelink_itm... expd) { + OrderedHash actl_hash = parser.Parse_sitelinks(Q1_bry, Json_doc.new_apos_(raw)); + Tfds.Eq_ary_str((Wdata_sitelink_itm[])actl_hash.XtoAry(Wdata_sitelink_itm.class), expd); + } + public void Test_labels(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.Y, expd);} + public void Test_descriptions(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.N, expd);} + private void Test_langvals(String raw, boolean labels_or_descriptions, Wdata_langtext_itm... expd) { + OrderedHash actl_hash = parser.Parse_langvals(Q1_bry, Json_doc.new_apos_(raw), labels_or_descriptions); + Tfds.Eq_ary_str((Wdata_langtext_itm[])actl_hash.XtoAry(Wdata_langtext_itm.class), expd); + } + public void Test_aliases(String raw, Wdata_alias_itm... expd) { + OrderedHash actl_hash = parser.Parse_aliases(Q1_bry, Json_doc.new_apos_(raw)); + Tfds.Eq_ary_str((Wdata_alias_itm[])actl_hash.XtoAry(Wdata_alias_itm.class), expd); + } + public void Test_claims(String raw, Wdata_claim_itm_core... expd) { + OrderedHash actl_hash = parser.Parse_claims(Json_doc.new_apos_(raw)); + ListAdp actl_list = Wdata_claim_grp.Xto_list(actl_hash); + Tfds.Eq_ary_str((Wdata_claim_itm_core[])actl_list.XtoAry(Wdata_claim_itm_core.class), expd); + } + public void Test_claims_data(String raw, Wdata_claim_itm_core expd) { + Json_doc jdoc = Json_doc.new_apos_(raw); + Wdata_claim_itm_base actl = parser.Parse_claims_data(1, Wdata_dict_snak_tid.Tid_value, jdoc.Root()); + Tfds.Eq(expd.toString(), actl.toString()); + } + private static final byte[] Q1_bry = Bry_.new_ascii_("Q1"); +} +class Wdata_doc_parser_v1_fxt extends Wdata_doc_parser_fxt_base { + @Override public Wdata_doc_parser Make_parser() {return new Wdata_doc_parser_v1();} +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java new file mode 100644 index 000000000..d4b002a90 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java @@ -0,0 +1,305 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.core.btries.*; +public class Wdata_doc_parser_v2 implements Wdata_doc_parser { + private Wdata_claims_parser__v2 claims_parser = new Wdata_claims_parser__v2(); + public byte[] Parse_qid(Json_doc doc) { + try { + Json_itm itm = doc.Find_nde(Bry_id); + return Bry_.Lower_1st(itm.Data_bry()); // standardize on "q" instead of "Q" for compatibility with v1 + } catch (Exception e) {throw Err_.err_(e, "failed to parse qid; src={0}", String_.new_utf8_(doc.Src()));} + } + public OrderedHash Parse_sitelinks(byte[] qid, Json_doc doc) { + try { + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_sitelink.Dict; + for (int i = 0; i < list_len; ++i) { + Json_itm_kv data_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + Json_itm_nde data_nde = Json_itm_nde.cast_(data_kv.Val()); + int data_nde_len = data_nde.Subs_len(); + Json_itm_kv site_kv = null, name_kv = null; Json_itm_ary badges_ary = null; + for (int j = 0; j < data_nde_len; ++j) { + Json_itm_kv sub = Json_itm_kv.cast_(data_nde.Subs_get_at(j)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_sitelink.Tid_site: site_kv = Json_itm_kv.cast_(sub); break; + case Wdata_dict_sitelink.Tid_title: name_kv = Json_itm_kv.cast_(sub); break; + case Wdata_dict_sitelink.Tid_badges: badges_ary = Json_itm_ary.cast_(Json_itm_kv.cast_(sub).Val()); break; + } + } + byte[] site_bry = site_kv.Val().Data_bry(); + Wdata_sitelink_itm itm = new Wdata_sitelink_itm(site_bry, name_kv.Val().Data_bry(), badges_ary.Xto_bry_ary()); + rv.Add(site_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse sitelinks; qid={0}", String_.new_utf8_(qid));} + } + public OrderedHash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) { + try { + byte[] langval_key = label_or_description ? Bry_labels : Bry_descriptions; + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_langtext.Dict; + for (int i = 0; i < list_len; ++i) { + Json_itm_kv data_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + Json_itm_nde data_nde = Json_itm_nde.cast_(data_kv.Val()); + Json_itm_kv text_kv = null; + int data_nde_len = data_nde.Subs_len(); + for (int j = 0; j < data_nde_len; ++j) { + Json_itm_kv sub = Json_itm_kv.cast_(data_nde.Subs_get_at(j)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_langtext.Tid_language: break; + case Wdata_dict_langtext.Tid_value: text_kv = Json_itm_kv.cast_(sub); break; + } + } + byte[] lang_bry = data_kv.Key().Data_bry(); + Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, text_kv.Val().Data_bry()); + rv.Add(lang_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse langvals; qid={0} langval_tid={1}", String_.new_utf8_(qid), label_or_description);} + } + public OrderedHash Parse_aliases(byte[] qid, Json_doc doc) { + try { + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry; + OrderedHash rv = OrderedHash_.new_bry_(); + int list_len = list_nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_langtext.Dict; + for (int i = 0; i < list_len; ++i) { + Json_itm_kv data_kv = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + Json_itm_ary vals_ary = Json_itm_ary.cast_(data_kv.Val()); + int vals_len = vals_ary.Subs_len(); + byte[][] vals = new byte[vals_len][]; + for (int j = 0; j < vals_len; ++j) { + Json_itm_nde lang_nde = Json_itm_nde.cast_(vals_ary.Subs_get_at(j)); + int k_len = lang_nde.Subs_len(); + for (int k = 0; k < k_len; ++k) { + Json_itm_kv sub = Json_itm_kv.cast_(lang_nde.Subs_get_at(k)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_langtext.Tid_language: break; + case Wdata_dict_langtext.Tid_value: vals[j] = sub.Val().Data_bry(); break; + } + } + } + byte[] lang_bry = data_kv.Key().Data_bry(); + Wdata_alias_itm itm = new Wdata_alias_itm(lang_bry, vals); + rv.Add(lang_bry, itm); + } + return rv; + } catch (Exception e) {throw Err_.err_(e, "failed to parse sitelinks; qid={0}", String_.new_utf8_(qid));} + } + public OrderedHash Parse_claims(Json_doc doc) { + try { + Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic; + ListAdp temp_list = ListAdp_.new_(); + byte[] src = doc.Src(); + int len = list_nde.Subs_len(); + for (int i = 0; i < len; i++) { + Json_itm_kv claim_nde = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); + claims_parser.Make_claim_itms(temp_list, src, claim_nde); + } + return Wdata_doc_parser_v1.Claims_list_to_hash(temp_list); + } catch (Exception e) {throw Err_.err_(e, "failed to parse claims; qid={0}", String_.new_utf8_(doc.Src()));} + } + public Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde) {return claims_parser.Parse_datavalue(pid, snak_tid, nde);} + public static final String + Str_id = "id" + , Str_sitelinks = "sitelinks" + , Str_labels = "labels" + , Str_descriptions = "descriptions" + , Str_aliases = "aliases" + , Str_claims = "claims" + , Str_type = "type" + ; + public static final byte[] + Bry_id = Bry_.new_ascii_(Str_id) + , Bry_sitelinks = Bry_.new_ascii_(Str_sitelinks) + , Bry_labels = Bry_.new_ascii_(Str_labels) + , Bry_descriptions = Bry_.new_ascii_(Str_descriptions) + , Bry_aliases = Bry_.new_ascii_(Str_aliases) + , Bry_claims = Bry_.new_ascii_(Str_claims) + , Bry_type = Bry_.new_ascii_(Str_type) + ; +} +class Wdata_claims_parser__v2 { + public void Make_claim_itms(ListAdp claim_itms_list, byte[] src, Json_itm_kv claim_grp) { + Json_itm_ary claim_itms_ary = Json_itm_ary.cast_(claim_grp.Val()); + int claim_itms_len = claim_itms_ary.Subs_len(); + byte[] pid_bry = claim_grp.Key().Data_bry(); + int pid = Bry_.Xto_int_or(pid_bry, 1, pid_bry.length, -1); + for (int i = 0; i < claim_itms_len; ++i) { + Json_itm_nde claim_itm_nde = Json_itm_nde.cast_(claim_itms_ary.Subs_get_at(i)); + Wdata_claim_itm_base itm = Parse_claim_itm(claim_itm_nde, pid); + if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20 + claim_itms_list.Add(itm); + } + } + private Wdata_claim_itm_base Parse_claim_itm(Json_itm_nde nde, int pid) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_claim.Dict; + byte rank_tid = Wdata_dict_rank.Tid_unknown; + Wdata_claim_itm_base claim_itm = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(Json_itm_nde.cast_(sub.Val()), pid); break; + case Wdata_dict_claim.Tid_rank: rank_tid = Wdata_dict_rank.Xto_tid(sub.Val().Data_bry()); break; + case Wdata_dict_claim.Tid_references: break; + case Wdata_dict_claim.Tid_qualifiers: break; + case Wdata_dict_claim.Tid_qualifiers_order: break; + case Wdata_dict_claim.Tid_type: break; // ignore: "statement" + case Wdata_dict_claim.Tid_id: break; // ignore: "Q2$F909BD1C-D34D-423F-9ED2-3493663321AF" + } + } + if (claim_itm != null) claim_itm.Rank_tid_(rank_tid); + return claim_itm; + } + public Wdata_claim_itm_base Parse_mainsnak(Json_itm_nde nde, int pid) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_mainsnak.Dict; + byte snak_tid = Byte_.MaxValue_127; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_mainsnak.Tid_snaktype: snak_tid = Wdata_dict_snak_tid.Xto_tid(sub.Val().Data_bry()); break; + case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(pid, snak_tid, Json_itm_nde.cast_(sub.Val())); + case Wdata_dict_mainsnak.Tid_property: break; // ignore: pid already available above + case Wdata_dict_mainsnak.Tid_hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390" + } + } + return null; // NOTE: mainsnak can be null; PAGE:Q2!P576; DATE:2014-09-20 + } + public Wdata_claim_itm_base Parse_datavalue(int pid, byte snak_tid, Json_itm_nde nde) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_datavalue.Dict; + Json_itm value_itm = null; byte value_tid = Wdata_dict_val_tid.Tid_unknown; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_datavalue.Tid_type: value_tid = Wdata_dict_val_tid.Xto_tid(sub.Val().Data_bry()); break; + case Wdata_dict_datavalue.Tid_value: value_itm = sub.Val(); break; + } + } + switch (value_tid) { + case Wdata_dict_val_tid.Tid_string: return new Wdata_claim_itm_str(pid, snak_tid, value_itm.Data_bry()); + case Wdata_dict_val_tid.Tid_entity: return Parse_datavalue_entity (pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_time: return Parse_datavalue_time (pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_quantity: return Parse_datavalue_quantity (pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_globecoordinate: return Parse_datavalue_globecoordinate (pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_monolingualtext: return Parse_datavalue_monolingualtext (pid, snak_tid, Json_itm_nde.cast_(value_itm)); + } + throw Err_.new_("unknown val_tid; val_tid={0}", value_tid); + } + private Wdata_claim_itm_base Parse_datavalue_entity(int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_entity.Dict; + int len = nde.Subs_len(); + byte[] entity_id_bry = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + switch (tid) { + case Wdata_dict_value_entity.Tid_entity_type: break; // ignore: "item" + case Wdata_dict_value_entity.Tid_numeric_id: entity_id_bry = sub.Val().Data_bry(); break; + } + } + if (entity_id_bry == null) throw Err_.new_("pid is invalid entity; pid={0}", pid); + return new Wdata_claim_itm_entity(pid, snak_tid, entity_id_bry); + } + private Wdata_claim_itm_base Parse_datavalue_monolingualtext(int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_monolingualtext.Dict; + int len = nde.Subs_len(); + byte[] lang = null, text = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_monolingualtext.Tid_text: text = sub_val_bry; break; + case Wdata_dict_value_monolingualtext.Tid_language: lang = sub_val_bry; break; + } + } + if (lang == null || text == null) throw Err_.new_("pid is invalid monolingualtext; pid={0}", pid); + return new Wdata_claim_itm_monolingualtext(pid, snak_tid, lang, text); + } + private Wdata_claim_itm_base Parse_datavalue_globecoordinate(int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_globecoordinate.Dict; + int len = nde.Subs_len(); + byte[] lat = null, lng = null, alt = null, prc = null, glb = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_globecoordinate.Tid_latitude: lat = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_longitude: lng = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_altitude: alt = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_precision: prc = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_globe: glb = sub_val_bry; break; + } + } + if (lat == null || lng == null) throw Err_.new_("pid is invalid globecoordinate; pid={0}", pid); + return new Wdata_claim_itm_globecoordinate(pid, snak_tid, lat, lng, alt, prc, glb); + } + private Wdata_claim_itm_base Parse_datavalue_quantity(int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_quantity.Dict; + int len = nde.Subs_len(); + byte[] amount = null, unit = null, ubound = null, lbound = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_quantity.Tid_amount: amount = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_unit: unit = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_upperbound: ubound = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_lowerbound: lbound = sub_val_bry; break; + } + } + if (amount == null) throw Err_.new_("pid is invalid quantity; pid={0}", pid); + return new Wdata_claim_itm_quantity(pid, snak_tid, amount, unit, ubound, lbound); + } + private Wdata_claim_itm_base Parse_datavalue_time(int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_time.Dict; + int len = nde.Subs_len(); + byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_time.Tid_time: time = sub_val_bry; break; + case Wdata_dict_value_time.Tid_timezone: timezone = sub_val_bry; break; + case Wdata_dict_value_time.Tid_before: before = sub_val_bry; break; + case Wdata_dict_value_time.Tid_after: after = sub_val_bry; break; + case Wdata_dict_value_time.Tid_precision: precision = sub_val_bry; break; + case Wdata_dict_value_time.Tid_calendarmodel: calendarmodel = sub_val_bry; break; + } + } + if (time == null) throw Err_.new_("pid is invalid time; pid={0}", pid); + return new Wdata_claim_itm_time(pid, snak_tid, time, timezone, before, after, precision, calendarmodel); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java new file mode 100644 index 000000000..c0a5f3402 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java @@ -0,0 +1,253 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +public class Wdata_doc_parser_v2_tst { + @Before public void init() {fxt.Init();} private Wdata_doc_parser_v2_fxt fxt = new Wdata_doc_parser_v2_fxt(); + @Test public void Entity() { + fxt.Test_entity("{ 'id':'Q2' }", "q2"); + } + @Test public void Sitelink() { + fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last + ( "{ 'sitelinks':" + , " { 'enwiki':" + , " { 'site':'enwiki'" + , " , 'title':'en_val'" + , " , 'badges':" + , " [ 'Q10'" + , " , 'Q11'" + , " , 'Q12'" + , " ]" + , " }" + , " , 'dewiki':" + , " { 'site':'dewiki'" + , " , 'title':'de_val'" + , " , 'badges':" + , " [ 'Q2'" + , " ]" + , " }" + , " , 'frwiki':" + , " { 'site':'frwiki'" + , " , 'title':'fr_val'" + , " , 'badges':[]" + , " }" + , " }" + , "}" + ) + , fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12") + , fxt.Make_sitelink("dewiki", "de_val", "Q2") + , fxt.Make_sitelink("frwiki", "fr_val") + ); + } + @Test public void Labels() { + fxt.Test_labels(String_.Concat_lines_nl_skip_last + ( "{ 'labels':" + , " { 'en':" + , " { 'language':'enwiki'" + , " , 'value':'en_val'" + , " }" + , " , 'de':" + , " { 'language':'dewiki'" + , " , 'value':'de_val'" + , " }" + , " , 'fr':" + , " { 'language':'frwiki'" + , " , 'value':'fr_val'" + , " }" + , " }" + , "}" + ) + , fxt.Make_langval("en", "en_val") + , fxt.Make_langval("de", "de_val") + , fxt.Make_langval("fr", "fr_val") + ); + } + @Test public void Descriptions() { + fxt.Test_descriptions(String_.Concat_lines_nl_skip_last + ( "{ 'descriptions':" + , " { 'en':" + , " { 'language':'enwiki'" + , " , 'value':'en_val'" + , " }" + , " , 'de':" + , " { 'language':'dewiki'" + , " , 'value':'de_val'" + , " }" + , " , 'fr':" + , " { 'language':'frwiki'" + , " , 'value':'fr_val'" + , " }" + , " }" + , "}" + ) + , fxt.Make_langval("en", "en_val") + , fxt.Make_langval("de", "de_val") + , fxt.Make_langval("fr", "fr_val") + ); + } + @Test public void Aliases() { + fxt.Test_aliases(String_.Concat_lines_nl_skip_last + ( "{ 'aliases':" + , " { 'en':" + , " [" + , " { 'language':'en'" + , " , 'value':'en_val_1'" + , " }" + , " ," + , " { 'language':'en'" + , " , 'value':'en_val_2'" + , " }" + , " ," + , " { 'language':'en'" + , " , 'value':'en_val_3'" + , " }" + , " ]" + , " ," + , " 'de':" + , " [" + , " { 'language':'de'" + , " , 'value':'de_val_1'" + , " }" + , " ," + , " { 'language':'de'" + , " , 'value':'de_val_2'" + , " }" + , " ]" + , " ," + , " 'fr':" + , " [" + , " { 'language':'fr'" + , " , 'value':'fr_val_1'" + , " }" + , " ]" + , " }" + , "}" + ) + , fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3") + , fxt.Make_alias("de", "de_val_1", "de_val_2") + , fxt.Make_alias("fr", "fr_val_1") + ); + } + @Test public void Claims() { + fxt.Test_claims(String_.Concat_lines_nl_skip_last + ( "{ 'claims':" + , " { 'P1':" + , " [" + , " { 'mainsnak':" + , " { 'snaktype':'value'" + , " , 'property':'P1'" + , " , 'hash':'84487fc3f93b4f74ab1cc5a47d78f596f0b49390'" + , " , 'datavalue':" + , " { 'value':'abc'" + , " , 'type':'string'" + , " }" + , " }" + , " , 'type':'statement'" + , " , 'id':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'" + , " , 'rank':'normal'" + , " }" + , " ]" + , " }" + , "}" + ) + , fxt.Make_claim_str(1, "abc") + ); + } + @Test public void Claims_data_string() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':'abc'" + , ", 'type':'string'" + , "}" + ) + , fxt.Make_claim_str(1, "abc") + ); + } + @Test public void Claims_data_entity() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':" + , " { 'entity-type':'item'" + , " , 'numeric-id':'123'" + , " }" + , ", 'type':'wikibase-entityid'" + , "}" + ) + , fxt.Make_claim_entity(1, 123) + ); + } + @Test public void Claims_data_monolingualtext() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':" + , " { 'text':'en_text'" + , " , 'language':'en'" + , " }" + , ", 'type':'monolingualtext'" + , "}" + ) + , fxt.Make_claim_monolingualtext(1, "en", "en_text") + ); + } + @Test public void Claims_data_globecoordinate() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':" + , " { 'latitude':1.2" + , " , 'longitude':3.4" + , " , 'altitude':null" + , " , 'precision':0.0002" + , " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'" + , " }" + , ", 'type':'globecoordinate'" + , "}" + ) + , fxt.Make_claim_globecoordinate(1, "1.2", "3.4", "0.0002") + ); + } + @Test public void Claims_data_quantity() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':" + , " { 'amount':'123'" + , " , 'unit':'2'" + , " , 'upperBound':'125'" + , " , 'lowerBound':'121'" + , " }" + , ", 'type':'quantity'" + , "}" + ) + , fxt.Make_claim_quantity(1, 123, 2, 125, 121) + ); + } + @Test public void Claims_data_time() { + fxt.Test_claims_data(String_.Concat_lines_nl_skip_last + ( "{ 'value':" + , " { 'time':'+00000002001-02-03T04:05:06Z'" + , " , 'timezone':0" + , " , 'before':0" + , " , 'after':0" + , " , 'precision':11" + , " , 'calendarmodel':'http:\\/\\/www.wikidata.org\\/entity\\/Q1985727'" + , " }" + , ", 'type':'time'" + , "}" + ) + , fxt.Make_claim_time(1, "2001-02-03 04:05:06") + ); + } +} +class Wdata_doc_parser_v2_fxt extends Wdata_doc_parser_fxt_base { + @Override public Wdata_doc_parser Make_parser() {return new Wdata_doc_parser_v2();} +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java new file mode 100644 index 000000000..2df8f5d57 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.pfuncs.*; +public class Wdata_external_lang_links_data { + private ListAdp langs_list = ListAdp_.new_(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:lang_code + public boolean Enabled() {return enabled;} private boolean enabled; public Wdata_external_lang_links_data Enabled_(boolean v) {enabled = v; return this;} + public boolean Sort() {return sort;} private boolean sort; public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} + public int Langs_len() {return langs_list.Count();} + public Wdata_external_lang_links_data Langs_add(byte[] v) {langs_hash.Add(v, v); langs_list.Add(v); return this;} + public byte[] Langs_get_at(int i) {return (byte[])langs_list.FetchAt(i);} + public boolean Langs_hide(byte[] src, int bgn, int end) { + if (sort) return false; + return langs_hash.Get_by_mid(src, bgn, end) == null; + } + public void Reset() { + enabled = false; + sort = false; + langs_list.Clear(); + langs_hash.Clear(); + } + public void Parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Pf_func_base pfunc) { + enabled = true; + byte[] argx = pfunc.Eval_argx(ctx, src, caller, self); + if (Bry_.Eq(argx, Key_sort)) {sort = true; return;} // {{noexternallanglinks:*}}; assume it cannot be combined with other langs_hash: EX: {{noexternallanglinks:*|en|fr}} + int args_len = self.Args_len(); + Langs_add(argx); + Bry_bfr tmp_bfr = ctx.App().Utl_bry_bfr_mkr().Get_b128(); + for (int i = 0; i < args_len; i++) { + Arg_nde_tkn nde = self.Args_get_by_idx(i); + nde.Val_tkn().Tmpl_evaluate(ctx, src, self, tmp_bfr); + byte[] lang = tmp_bfr.XtoAryAndClear(); + Langs_add(lang); + } + tmp_bfr.Mkr_rls(); + } + public static final byte[] Key_sort = new byte[] {Byte_ascii.Asterisk}; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks.java new file mode 100644 index 000000000..fd075ef39 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +import gplx.xowa.xtns.pfuncs.*; +public class Wdata_pf_noExternalLangLinks extends Pf_func_base { + @Override public int Id() {return Xol_kwd_grp_.Id_noexternallanglinks;} + @Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_noExternalLangLinks().Name_(name);} + @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { + ctx.Cur_page().Wdata_external_lang_links().Parse(ctx, src, caller, self, this); + } + public static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) { + bfr.Add_mid(src, self.Src_bgn(), self.Src_end()); + usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args); + } + static final String GRP_KEY = "xowa.xtns.wdata.noexternallanglinks"; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks_tst.java new file mode 100644 index 000000000..118836664 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_noExternalLangLinks_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +public class Wdata_pf_noExternalLangLinks_tst { + @Before public void init() {fxt.Clear();} Wdata_pf_noExternalLangLinks_fxt fxt = new Wdata_pf_noExternalLangLinks_fxt(); + @Test public void Basic() { + fxt.Clear().Expd_enabled_(true).Test_parse("{{noexternallanglinks}}"); + fxt.Clear().Expd_enabled_(false).Expd_sort_(false).Expd_langs_().Test_parse(""); + } + @Test public void Selected() { + fxt.Clear().Expd_enabled_(true).Expd_langs_("en", "fr").Test_parse("{{noexternallanglinks:en|fr}}"); + } + @Test public void Sort() { + fxt.Clear().Expd_enabled_(true).Expd_sort_(true).Expd_langs_().Test_parse("{{noexternallanglinks:*}}"); + } +} +class Wdata_pf_noExternalLangLinks_fxt { + public Wdata_pf_noExternalLangLinks_fxt Clear() { + if (parser_fxt == null) { + parser_fxt = new Xop_fxt(); + app = parser_fxt.App(); + wiki = parser_fxt.Wiki(); + data = wiki.Ctx().Cur_page().Wdata_external_lang_links(); + } + expd_sort = expd_enabled = Bool_.__byte; + expd_langs = null; + data.Reset(); + return this; + } private Xop_fxt parser_fxt; Xoa_app app; Xow_wiki wiki; Wdata_external_lang_links_data data; + public Wdata_pf_noExternalLangLinks_fxt Expd_enabled_(boolean v) {expd_enabled = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_enabled; + public Wdata_pf_noExternalLangLinks_fxt Expd_sort_(boolean v) {expd_sort = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_sort; + public Wdata_pf_noExternalLangLinks_fxt Expd_langs_(String... v) {expd_langs = v; return this;} private String[] expd_langs; + public void Test_parse(String raw) { + byte[] expd = parser_fxt.Test_parse_tmpl_str_rv(raw); + Tfds.Eq(Bry_.Empty, expd); + if (expd_enabled != Bool_.__byte) Tfds.Eq(expd_enabled == Bool_.Y_byte, data.Enabled()); + if (expd_sort != Bool_.__byte) Tfds.Eq(expd_sort == Bool_.Y_byte, data.Sort()); + if (expd_langs != null) Tfds.Eq_ary_str(expd_langs, Data_langs_xto_str_ary()); + } + String[] Data_langs_xto_str_ary() { + int len = data.Langs_len(); + String[] rv = new String[len]; + for (int i = 0; i < len; i++) { + rv[i] = String_.new_utf8_((byte[])data.Langs_get_at(i)); + } + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property.java new file mode 100644 index 000000000..fb809194d --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.wdatas.core.*; +public class Wdata_pf_property extends Pf_func_base { + @Override public int Id() {return Xol_kwd_grp_.Id_property;} + @Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_property().Name_(name);} + @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {// {{#property:pNumber|}} + byte[] id = Eval_argx(ctx, src, caller, self); + Xop_log_property_wkr property_wkr = ctx.Xtn__wikidata__property_wkr(); + long log_time_bgn = 0; + if (property_wkr != null) { + log_time_bgn = Env_.TickCount(); + if (!property_wkr.Eval_bgn(ctx.Cur_page(), id)) return; + } + + Xoa_app app = ctx.App(); + Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr(); + if (!wdata_mgr.Enabled()) return; + Xow_wiki wiki = ctx.Wiki(); + Xoa_ttl ttl = ctx.Cur_page().Ttl(); + + Wdata_pf_property_data data = new Wdata_pf_property_data(); + data.Init_by_parse(ctx, src, caller, self, this, id); + Wdata_doc prop_doc = wdata_mgr.Pages_get(wiki, ttl, data); if (prop_doc == null) return; // NOTE: some pages will not exist in qid; EX: {{#property:P345}} for "Unknown_page" will not even had a qid; if no qid, then no pid + int pid = data.Id_int(); + if (pid == Wdata_wiki_mgr.Pid_null) + pid = wdata_mgr.Pids_get(wiki.Wdata_wiki_lang(), data.Id()); + if (pid == Wdata_wiki_mgr.Pid_null) {Print_self(app.Usr_dlg(), bfr, src, self, "prop_not_found", "prop id not found: ~{0} ~{1} ~{2}", wiki.Domain_str(), ttl.Page_db_as_str(), data.Id()); return;} + Wdata_claim_grp prop_grp = prop_doc.Claim_list_get(pid); if (prop_grp == null) return;// NOTE: some props may not exist; EX: {{#property:P345}} for "Unknown_movie" may have a qid, but doesn't have a defined pid + wdata_mgr.Resolve_to_bfr(bfr, prop_grp, wiki.Wdata_wiki_lang()); // NOTE: was ctx.Cur_page().Lang().Key_bry(), but fails in simplewiki; DATE:2013-12-02 + if (property_wkr != null) + property_wkr.Eval_end(ctx.Cur_page(), id, log_time_bgn); + } + public static int Parse_pid(NumberParser num_parser, byte[] bry) { + int bry_len = bry.length; + if (bry_len < 2) return Wdata_wiki_mgr.Pid_null; // must have at least 2 chars; p# + byte b_0 = bry[0]; + if (b_0 != Byte_ascii.Ltr_p && b_0 != Byte_ascii.Ltr_P) return Wdata_wiki_mgr.Pid_null; + num_parser.Parse(bry, 1, bry_len); + return num_parser.HasErr() ? Wdata_wiki_mgr.Pid_null : num_parser.AsInt(); + } + public static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) { + bfr.Add_mid(src, self.Src_bgn(), self.Src_end()); + usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args); + } + public static void Print_empty(Gfo_usr_dlg usr_dlg, String warn_cls, String warn_fmt, Object... args) { + usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args); + } + private static final String GRP_KEY = "xowa.xtns.wdata.property"; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_data.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_data.java new file mode 100644 index 000000000..47fc29d81 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_data.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_pf_property_data { + public byte[] Of() {return of;} private byte[] of; + public byte[] Q() {return q;} private byte[] q; + public byte[] Id() {return id;} private byte[] id; + public int Id_int() {return id_int;} private int id_int; + public void Init_by_parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Wdata_pf_property pfunc) { + byte[] id = pfunc.Eval_argx(ctx, src, caller, self); + Init_by_parse(ctx, src, caller, self, pfunc, id); + } + public void Init_by_parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Wdata_pf_property pfunc, byte[] id) { + this.id = id; + id_int = Wdata_pf_property.Parse_pid(ctx.App().Utl_num_parser(), id); + if (id_int == Wdata_wiki_mgr.Pid_null) {} // named; TODO: get pid from pid_regy + int args_len = self.Args_len(); + Bry_bfr tmp_bfr = ctx.Wiki().Utl_bry_bfr_mkr().Get_b512(); + for (int i = 0; i < args_len; i++) { + Arg_nde_tkn nde = self.Args_get_by_idx(i); + Arg_itm_tkn nde_key = nde.Key_tkn(); + int nde_key_bgn = nde_key.Src_bgn(), nde_key_end = nde_key.Src_end(); + if (nde_key_bgn == nde_key_end && nde_key_bgn == -1) continue; // null arg; ignore, else will throw warning below; EX: {{#property:p1|}}; DATE:2013-11-15 + Object o = Atr_keys.Get_by_mid(src, nde_key_bgn, nde_key_end); + if (o == null) { + ctx.App().Usr_dlg().Warn_many("", "", "unknown key for property: ~{0} ~{1}", String_.new_utf8_(ctx.Cur_page().Ttl().Full_txt()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end())); + continue; + } + nde.Val_tkn().Tmpl_evaluate(ctx, src, self, tmp_bfr); + byte[] val = tmp_bfr.XtoAryAndClear(); + byte key_tid = ((Byte_obj_val)o).Val(); + switch (key_tid) { + case Atr_of_id: of = val; break; + case Atr_q_id: q = val; break; + default: throw Err_.unhandled(key_tid); + } + } + tmp_bfr.Mkr_rls(); + } + static final byte Atr_of_id = 1, Atr_q_id = 2; + private static final byte[] Atr_of_bry = Bry_.new_ascii_("of"), Atr_q_bry = Bry_.new_ascii_("q"); + private static final Hash_adp_bry Atr_keys = Hash_adp_bry.ci_ascii_().Add_bry_byte(Atr_of_bry, Atr_of_id).Add_bry_byte(Atr_q_bry, Atr_q_id); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_fmt.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_fmt.java new file mode 100644 index 000000000..748675702 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_fmt.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_pf_property_fmt { + public byte[] Separator() {return separator;} private byte[] separator; + public byte[] Value_template() {return value_template;} private byte[] value_template; + public byte[] Qualifier_template() {return qualifier_template;} private byte[] qualifier_template; + public byte[] Qualifier_separator() {return qualifier_separator;} private byte[] qualifier_separator; + public byte[] Qualifiers_wrapper() {return qualifiers_wrapper;} private byte[] qualifiers_wrapper; + public byte[] Qualifiers_template() {return qualifiers_template;} private byte[] qualifiers_template; + public byte[] Qualifiers_value_separator() {return qualifiers_value_separator;} private byte[] qualifiers_value_separator; + public byte[] Reference_keyvalue_template() {return reference_keyvalue_template;} private byte[] reference_keyvalue_template; + public byte[] Reference_wrapper() {return reference_wrapper;} private byte[] reference_wrapper; + public byte[] References_wrapper() {return references_wrapper;} private byte[] references_wrapper; + public byte[] Reference_keyvalue_separator() {return reference_keyvalue_separator;} private byte[] reference_keyvalue_separator; + public byte[] Reference_template() {return reference_template;} private byte[] reference_template; + public byte[] Reference_value_separator() {return reference_value_separator;} private byte[] reference_value_separator; + public byte[] Reference_separator() {return reference_separator;} private byte[] reference_separator; + public void Init() { + byte[] comma = new byte[] {Byte_ascii.Comma}; + separator = comma; + value_template = Bry_.new_ascii_("{{{value}}} {{{qualifiers}}}{{{references}}}"); + qualifier_template = Bry_.new_ascii_("{{{1}}} {{{2}}}"); + qualifier_separator = comma; + qualifiers_wrapper = Bry_.new_ascii_("{{{1}}}"); + qualifiers_template = Bry_.Empty; + qualifiers_value_separator = comma; + reference_keyvalue_template = Bry_.new_ascii_("{{{1}}} {{{2}}}"); + reference_wrapper = Bry_.new_ascii_("{{{1}}}"); + references_wrapper = Bry_.new_ascii_("{{{1}}}"); + reference_keyvalue_separator = comma; + reference_template = Bry_.Empty; + reference_value_separator = comma; + reference_separator = Bry_.Empty; // "a separator to use between each reference" + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java new file mode 100644 index 000000000..b3f148584 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java @@ -0,0 +1,150 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +public class Wdata_pf_property_tst { + @Before public void init() {fxt.Init();} Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt(); + @Test public void String() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"))); + fxt.Test_parse("{{#property:p1}}", "a"); + fxt.Test_parse("{{#property:p2}}", ""); + } + @Test public void Entity() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); + fxt.Test_parse("{{#property:p1}}", "b"); + } + @Test public void Entity_fr() { // PURPOSE: non-English wiki should default to English label if non-English label not available; DATE:2013-12-19 + fxt.Wiki().Wdata_wiki_lang_(Bry_.new_ascii_("fr")); // set wiki to French + fxt.Init_links_add("frwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2 + fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); // create wdata page Q2 with label in en (not fr) + fxt.Test_parse("{{#property:p1}}", "b"); // parse; should get en label + } + @Test public void Entity_missing() { // PURPOSE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01 + fxt.Init_links_add("enwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created + fxt.Test_parse("{{#property:p1}}", ""); // parse; get "" + } + @Test public void Time() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_time_(1, "2012-01-02 03:04:05"))); + fxt.Test_parse("{{#property:p1}}", "+00000002012-01-02T03:04:05Z"); + } + @Test public void Geodata() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_geodata_(1, "1.2345", "6.789"))); + fxt.Test_parse("{{#property:p1}}", "1.2345, 6.789"); + } + @Test public void Quantity() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_quantity_(1, "+1,234", "2", "+1,236", "+1232"))); + fxt.Test_parse("{{#property:p1}}", "1,234±2"); + } + @Test public void Monolingualtext() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_monolingualtext_(1, "Lorem ipsum dolor sit amet", "la"))); + fxt.Test_parse("{{#property:p1}}", "Lorem ipsum dolor sit amet"); + } + @Test public void Novalue() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_novalue_(1))); + fxt.Test_parse("{{#property:p1}}", "novalue"); + } + @Test public void Somevalue() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_somevalue_(1))); + fxt.Test_parse("{{#property:p1}}", "somevalue"); + } + @Test public void Multiple() { + fxt.Init_links_add("enwiki", "Test_page", "q1"); + fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"), fxt.prop_str_(1, "b"))); + fxt.Test_parse("{{#property:p1}}", "a, b"); + } + @Test public void Q() { + fxt.Init_links_add("enwiki", "Test_page", "q2"); + fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Test_parse("{{#property:p1|q=q2}}", "a"); + } + @Test public void Of() { + fxt.Init_links_add("enwiki", "Of_page", "q2"); + fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Test_parse("{{#property:p1|of=Of_page}}", "a"); + } + @Test public void Pid_as_name() { + fxt.Init_links_add("enwiki", "Test_page", "q2"); + fxt.Init_pids_add("en", "astronomic symbol", 1); + fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Test_parse("{{#property:astronomic symbol}}", "a"); + } + @Test public void Empty_arg() { // PURPOSE: {{#property:p1|}} should not fail / warn; DATE:2013-11-15 + fxt.Init_links_add("enwiki", "Test_page", "q2"); + fxt.Init_pids_add("en", "astronomic symbol", 1); + fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Test_parse("{{#property:p1|}}", "a"); + } + @Test public void Data() { + Wdata_pf_property_data_fxt fxt = new Wdata_pf_property_data_fxt(); + fxt.Init().Expd_id_int_(1).Test_parse("{{#property:p1}}"); + fxt.Init().Expd_id_int_(1).Expd_q_("q2").Test_parse("{{#property:p1|q=q2}}"); + fxt.Init().Expd_id_int_(1).Expd_of_("Earth").Test_parse("{{#property:p1|of=Earth}}"); + } + @Test public void Parse_pid() { + fxt.Test_parse_pid ("p123" , 123); // basic + fxt.Test_parse_pid ("P123" , 123); // uppercase + fxt.Test_parse_pid_null ("population"); // name test + fxt.Test_parse_pid_null ("123"); // missing p + fxt.Test_parse_pid_null (""); // empty String test + } +} +class Wdata_pf_property_data_fxt { + public Wdata_pf_property_data_fxt Init() { + if (app == null) { + parser_fxt = new Xop_fxt(); + app = parser_fxt.App(); + page_bldr = new Wdata_doc_bldr(app.Wiki_mgr().Wdata_mgr()); + wdata_mgr = app.Wiki_mgr().Wdata_mgr(); + } + Io_mgr._.InitEngine_mem(); + wdata_mgr.Clear(); + parser_fxt.Reset(); + expd_id_int = -1; + expd_q = expd_of = null; + return this; + } private Xoa_app app; Wdata_wiki_mgr wdata_mgr; Wdata_doc_bldr page_bldr; Xop_fxt parser_fxt; + public Wdata_pf_property_data_fxt Expd_id_int_(int v) {expd_id_int = v; return this;} private int expd_id_int; + public Wdata_pf_property_data_fxt Expd_q_(String v) {expd_q = Bry_.new_ascii_(v); return this;} private byte[] expd_q; + public Wdata_pf_property_data_fxt Expd_of_(String v) {expd_of = Bry_.new_ascii_(v); return this;} private byte[] expd_of; + public void Test_parse(String raw) { + Wdata_pf_property_data actl = new Wdata_pf_property_data(); + byte[] raw_bry = Bry_.new_utf8_(raw); + Xow_wiki wiki = parser_fxt.Wiki(); Xop_ctx ctx = wiki.Ctx(); + Xop_tkn_mkr tkn_mkr = app.Tkn_mkr(); + Wdata_pf_property pfunc = new Wdata_pf_property(); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + wiki.Parser().Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry); + Xot_invk tkn = (Xot_invk)root.Subs_get(0); + actl.Init_by_parse(ctx, raw_bry, Xot_invk_mock.Null, tkn, pfunc); + + if (expd_id_int != -1) Tfds.Eq(expd_id_int, actl.Id_int()); + if (expd_q != null) Tfds.Eq_bry(expd_q, actl.Q()); + if (expd_of != null) Tfds.Eq_bry(expd_of, actl.Of()); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame.java new file mode 100644 index 000000000..f8c5880d7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +import gplx.xowa.xtns.pfuncs.*; +public class Wdata_pf_wbreponame extends Pf_func_base { + @Override public int Id() {return Xol_kwd_grp_.Id_wbreponame;} + @Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_wbreponame().Name_(name);} + @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { + bfr.Add(Reponame); // NOTE: MW has logic to look for message named "wbreponame", and returning it if it exists; only applies to non-WMF Wikidatas; DATE:2014-09-07 + } private static final byte[] Reponame = Bry_.new_ascii_("Wikidata"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame_tst.java new file mode 100644 index 000000000..600f20e41 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_wbreponame_tst.java @@ -0,0 +1,36 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +public class Wdata_pf_wbreponame_tst { + @Before public void init() {fxt.Clear();} private Wdata_pf_wbreponame_fxt fxt = new Wdata_pf_wbreponame_fxt(); + @Test public void Basic() { + fxt.Test_parse("{{wbreponame}}", "Wikidata"); + } +} +class Wdata_pf_wbreponame_fxt { + public Wdata_pf_wbreponame_fxt Clear() { + if (parser_fxt == null) { + parser_fxt = new Xop_fxt(); + } + return this; + } private Xop_fxt parser_fxt; + public void Test_parse(String raw, String expd) { + parser_fxt.Test_html_full_str(raw, expd); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_cfg.java b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_cfg.java new file mode 100644 index 000000000..4e70c730d --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_cfg.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_itemByTitle_cfg implements GfoInvkAble { + public byte[] Site_default() {return site_default;} private byte[] site_default = Bry_.new_ascii_("enwiki"); + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_site_default)) return site_default; + else if (ctx.Match(k, Invk_site_default_)) site_default = m.ReadBry("v"); + else return GfoInvkAble_.Rv_unhandled; + return this; + } private static final String Invk_site_default = "site_default", Invk_site_default_ = "site_default_"; + public static final String Key = "itemByTitle"; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java new file mode 100644 index 000000000..69112c06a --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.specials.*; +public class Wdata_itemByTitle_page implements Xows_page { + private Xoa_url_arg_hash arg_hash = new Xoa_url_arg_hash(); + private static final byte[] Arg_site = Bry_.new_ascii_("site"), Arg_page = Bry_.new_ascii_("page"); + public Bry_fmtr Html_fmtr() {return html_fmtr;} + private Wdata_itemByTitle_cfg cfg; + public void Special_gen(Xoa_url calling_url, Xoa_page page, Xow_wiki wiki, Xoa_ttl ttl) { + if (cfg == null) cfg = (Wdata_itemByTitle_cfg)wiki.App().Special_mgr().Get_or_null(Wdata_itemByTitle_cfg.Key); + // Special:ItemByTitle/enwiki/Earth -> www.wikidata.org/wiki/Q2 + Gfo_usr_dlg usr_dlg = wiki.App().Usr_dlg(); + byte[] site_bry = cfg.Site_default(); + byte[] page_bry = Bry_.Empty; + byte[] raw_bry = ttl.Full_txt_wo_qarg(); // EX: enwiki/Earth + int args_len = calling_url.Args().length; + if (args_len > 0) { + arg_hash.Load(calling_url); + site_bry = arg_hash.Get_val_bry_or(Arg_site, Bry_.Empty); + page_bry = arg_hash.Get_val_bry_or(Arg_page, Bry_.Empty); + } + int site_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr); + if (site_bgn != Bry_.NotFound) { // leaf arg is available + int page_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr, site_bgn + 1); + int raw_bry_len = raw_bry.length; + if (page_bgn != Bry_.NotFound && page_bgn < raw_bry_len) { // pipe is found and not last char (EX: "enwiki/" is invalid + site_bry = Bry_.Mid(raw_bry, site_bgn + 1, page_bgn); + page_bry = Bry_.Mid(raw_bry, page_bgn + 1, raw_bry_len); + } + } + Xoa_app app = wiki.App(); + if (Bry_.Len_gt_0(site_bry) && Bry_.Len_gt_0(page_bry)) + if (Navigate(usr_dlg, app, app.Wiki_mgr().Wdata_mgr(), page, site_bry, page_bry)) return; + Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004(); + html_fmtr.Bld_bfr_many(tmp_bfr, "Search for items by site and title", "Site", site_bry, "Page", page_bry, "Search"); + page.Data_raw_(tmp_bfr.Mkr_rls().XtoAryAndClear()); + page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML + } + private static boolean Navigate(Gfo_usr_dlg usr_dlg, Xoa_app app, Wdata_wiki_mgr wdata_mgr, Xoa_page page, byte[] site_bry, byte[] page_bry) { + page_bry = app.Encoder_mgr().Url().Decode(page_bry); // NOTE: space is converted to + on postback to url; decode + byte[] wiki_domain = Xob_bz2_file.Parse_wmf_key(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_utf8_(site_bry)); return false;} + Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_utf8_(wiki_domain)); return false;} + Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_utf8_(page_bry)); return false;} + Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_utf8_(wdata_ttl.Raw())); return false;} + byte[] qid_bry = doc.Qid(); + Xoa_page qid_page = wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (qid_page.Missing()) {usr_dlg.Warn_many("", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_utf8_(qid_bry)); return false;} + return true; + } + private static Bry_fmtr html_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl + ( "
    " + , "
    " + , "
    " + , "~{legend}" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "
    " + , "
    " + , "
    " + , "
    To change the default site, see Help:Options/Wikibase" + ) + , "legend", "site_lbl", "site_val", "page_lbl", "page_val", "search_lbl"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java new file mode 100644 index 000000000..2d8d6197e --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; import gplx.xowa.wikis.*; +public class Wdata_itemByTitle_page_tst { + @Before public void init() {fxt.Clear();} private Wdata_itemByTitle_page_fxt fxt = new Wdata_itemByTitle_page_fxt(); + @Test public void Url() { + fxt.Init_wdata_page("Q2", "q2_earth"); + fxt.Init_wdata_label("enwiki", "Earth", "Q2"); + fxt.Test_open("Special:ItemByTitle/enwiki/Earth", "q2_earth"); + } + @Test public void Missing() { + fxt.Test_open("Special:ItemByTitle/enwiki/unknown_page", fxt.Expd_html("enwiki", "unknown page")); + } + @Test public void Html() { + fxt.Test_open("Special:ItemByTitle", fxt.Expd_html("enwiki", "")); + } + @Test public void Args() { + fxt.Init_wdata_page("Q2", "q2_earth"); + fxt.Init_wdata_label("enwiki", "Earth", "Q2"); + fxt.Test_open("Special:ItemByTitle?site=enwiki&page=Earth", "q2_earth"); + } + @Test public void Url_decode() { // PURPOSE: spaces not handled; EX: Albert Einstein -> Albert+Einstein; DATE:2013-07-24 + fxt.Init_wdata_page("Q2", "q2_page"); + fxt.Init_wdata_label("enwiki", "A_B", "Q2"); + fxt.Test_open("Special:ItemByTitle?site=enwiki&page=A+B", "q2_page"); + } +} +class Wdata_itemByTitle_page_fxt { + public void Clear() { + parser_fxt = new Xop_fxt(); + parser_fxt.Reset(); + app = parser_fxt.App(); + wiki = parser_fxt.Wiki(); + special_page = wiki.Special_mgr().Page_itemByTitle(); + wdata_fxt = new Wdata_wiki_mgr_fxt().Init(parser_fxt, true); + } private Xop_fxt parser_fxt; private Xoa_app app; private Wdata_itemByTitle_page special_page; private Xow_wiki wiki; + Wdata_wiki_mgr_fxt wdata_fxt; + public void Init_wdata_page(String qid_ttl, String text) { + Wdata_doc doc = wdata_fxt.doc_(qid_ttl); + app.Wiki_mgr().Wdata_mgr().Pages_add(Bry_.new_ascii_(qid_ttl), doc); + parser_fxt.Init_page_create(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), qid_ttl, text); + } + public void Init_wdata_label(String wmf_key_str, String wdata_label, String qid) { + wdata_fxt.Init_qids_add("en", Xow_wiki_domain_.Tid_wikipedia, wdata_label, qid); + } + public void Test_open(String link, String expd) { + Xoa_page page = wiki.Ctx().Cur_page(); + Xoa_url url = Xoa_url_parser.Parse_url(app, wiki, link); + page.Url_(url); + Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_ascii_(link)); + page.Ttl_(ttl); + special_page.Special_gen(url, page, wiki, ttl); + Tfds.Eq_str_lines(expd, String_.new_ascii_(page.Data_raw())); + } + public String Expd_html(String wmf_key, String ttl_str) { + Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004(); + special_page.Html_fmtr().Bld_bfr_many(tmp_bfr, "Search for items by site and title", "Site", wmf_key, "Page", ttl_str, "Search"); + return tmp_bfr.Mkr_rls().XtoStrAndClear(); + } +} + diff --git a/400_xowa/src_300_html/gplx/xowa/Xoa_page.java b/400_xowa/src_300_html/gplx/xowa/Xoa_page.java index d6aef1355..2fdc4b271 100644 --- a/400_xowa/src_300_html/gplx/xowa/Xoa_page.java +++ b/400_xowa/src_300_html/gplx/xowa/Xoa_page.java @@ -18,7 +18,7 @@ along with this program. If not, see . package gplx.xowa; import gplx.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.*; import gplx.xowa.pages.*; import gplx.xowa.files.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*; -import gplx.xowa.html.modules.popups.*; import gplx.xowa.hdumps.pages.*; +import gplx.xowa.html.modules.popups.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.xtns.wdatas.pfuncs.*; public class Xoa_page { private Xopg_hdump_data hdump_data; Xoa_page(Xow_wiki wiki, Xoa_ttl ttl) { diff --git a/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java b/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java index 06950c440..b4c8281b1 100644 --- a/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java +++ b/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa; import gplx.*; -import gplx.core.btries.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.parsers.amps.*; +import gplx.core.btries.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.langs.cases.*; public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.MW: Ttl.php|secureAndSplit; public Xow_ns Ns() {return ns;} private Xow_ns ns; public boolean ForceLiteralLink() {return forceLiteralLink;} private boolean forceLiteralLink; @@ -90,25 +90,30 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. public static Xoa_ttl parse_(Xow_wiki wiki, int ns_id, byte[] ttl) { Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id); byte[] raw = Bry_.Add(ns.Name_db_w_colon(), ttl); - return new_(wiki, wiki.App().Msg_log(), raw, raw, 0, raw.length); + return new_(wiki, wiki.App().Msg_log(), raw, 0, raw.length); } - public static Xoa_ttl parse_(Xow_wiki wiki, byte[] raw) {return new_(wiki, wiki.App().Msg_log(), raw, raw, 0, raw.length);} + public static Xoa_ttl parse_(Xow_wiki wiki, byte[] raw) {return new_(wiki, wiki.App().Msg_log(), raw, 0, raw.length);} private static final Object thread_lock = new Object(); - public static Xoa_ttl new_(Xow_wiki wiki, Gfo_msg_log msg_log, byte[] raw, byte[] src, int bgn, int end) { + public static Xoa_ttl new_(Xow_wiki wiki, Gfo_msg_log msg_log, byte[] src, int bgn, int end) { + Xoa_app app = wiki.App(); + Bry_bfr_mkr bry_mkr = app.Utl_bry_bfr_mkr(); + return parse(bry_mkr, app.Parser_amp_mgr(), wiki.Lang().Case_mgr(), wiki.Xwiki_mgr(), wiki.Ns_mgr(), msg_log, src, bgn, end); + } private Xoa_ttl() {} + public static Xoa_ttl parse(Bry_bfr_mkr bry_mkr, Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, Gfo_msg_log msg_log, byte[] src, int bgn, int end) { synchronized (thread_lock) { Xoa_ttl rv = new Xoa_ttl(); - Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_b512(); + Bry_bfr bfr = bry_mkr.Get_b512(); try { - boolean pass = rv.Parse(bfr, wiki, msg_log, raw, src, bgn, end); + boolean pass = rv.Parse(bfr, bry_mkr, amp_mgr, case_mgr, xwiki_mgr, ns_mgr, msg_log, src, bgn, end); return pass ? rv : null; } finally {bfr.Mkr_rls();} } - } private Xoa_ttl() {} - private boolean Parse(Bry_bfr bfr, Xow_wiki wiki, Gfo_msg_log msg_log, byte[] raw, byte[] src, int bgn, int end) { + } + private boolean Parse(Bry_bfr bfr, Bry_bfr_mkr bry_mkr, Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, Gfo_msg_log msg_log, byte[] src, int bgn, int end) { /* This proc will - identify all parts: Wiki, Namespace, Base/Leaf, Anchor; it will also identify Subject/Talk ns - - trim whitespace around part delimiters; EX: "Help : Test" --> "Help:Test"; note that it will trim only if the part is real; EX: "Helpx : Test" is unchanged + - trim whitespace around part delimiters; EX: "Help : Test" --> "Help:Test"; note that it will trim only if the ns part is real; EX: "Helpx : Test" is unchanged - replace multiple whitespaces with 1; EX: "Many ws" --> "Many ws" - capitalize the first letter of the page title note: a byte[] is needed b/c proc does collapsing and casing @@ -125,13 +130,11 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. Bry_bfr anchor_encoder_bfr = null; bfr.Clear(); if (end - bgn == 0) {msg_log.Add_itm_none(Xop_ttl_log.Len_0, src, bgn, bgn); return false;} - this.raw = raw; - Xow_ns_mgr ns_mgr = wiki.Ns_mgr(); ns = ns_mgr.Ns_main(); + this.raw = src; + ns = ns_mgr.Ns_main(); boolean add_ws = false, ltr_bgn_reset = false; int ltr_bgn = -1, txt_bb_len = 0, colon_count = 0; bfr.Clear(); - Xop_amp_mgr amp_mgr = wiki.App().Parser_amp_mgr(); - Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie(); - //Btrie_fast_mgr ttlTrie = wiki.App().TtlTrie(); + Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie(); byte[] b_ary = null; int cur = bgn; int match_pos = -1; @@ -155,7 +158,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. if (colon_count == 0) {// 1st colon; Object o = ns_mgr.Names_get_or_null(bfr.Bfr(), ltr_bgn, txt_bb_len); if (o == null) { // not ns; try alias - wik_itm = wiki.Xwiki_mgr().Get_by_mid(bfr.Bfr(), ltr_bgn, txt_bb_len); // check if wiki; note: wiki is not possible for other colons + wik_itm = xwiki_mgr.Get_by_mid(bfr.Bfr(), ltr_bgn, txt_bb_len); // check if wiki; note: wiki is not possible for other colons if (wik_itm != null) { wik_bgn = 0; // wik_bgn can only start at 0 part_found = true; @@ -271,24 +274,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. match_pos = cur + 1; } break; -//case Byte_ascii.Bang: case Byte_ascii.Quote: case Byte_ascii.Dollar: case Byte_ascii.Percent: case Byte_ascii.Apos: case Byte_ascii.Paren_bgn: -//case Byte_ascii.Paren_end: case Byte_ascii.Asterisk: case Byte_ascii.Comma: case Byte_ascii.Dash: case Byte_ascii.Dot: -//case Byte_ascii.Semic: case Byte_ascii.Eq: case Byte_ascii.Question: case Byte_ascii.At: -//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.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E: -//case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J: -//case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O: -//case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T: -//case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z: -//case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e: -//case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j: -//case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o: -//case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t: -//case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z: -//case Byte_ascii.Backslash: case Byte_ascii.Pow: case Byte_ascii.Tick: case Byte_ascii.Tilde: -//case Byte_ascii.Plus: // NOTE: not in wgLegalTitleChars, but appears in MW titles; EX: [[File:ASLSJSW Aas+.PNG]] -// NOTE: DefaultSettings.php defines wgLegalTitleChars as " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; the characters above are okay; those below are not + // NOTE: DefaultSettings.php defines wgLegalTitleChars as " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; the characters above are okay; those below are not case Byte_ascii.Gt: case Byte_ascii.Pipe: case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end: case Byte_ascii.Curly_bgn: case Byte_ascii.Curly_end: if (anch_bgn != -1) { @@ -322,93 +308,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. break; } ++cur; -// Object itm_obj = ttlTrie.Match(b, src, cur, end); -// if (itm_obj == null) ++cur; -// else { -// Byte_obj_val itm = (Byte_obj_val)itm_obj; -// switch (itm.Val()) { -// case Xoa_ttl_trie.Id_invalid: -// msg_log.Add_itm_none(src, bgn, end, Xop_ttl_log.Invalid_char); -// return false; -// case Xoa_ttl_trie.Id_colon: -// if (cur == bgn) { // initial colon; flag; note that " :" is not handled; note that colon_count is not incremented -// forceLiteralLink = true; -// cur = ttlTrie.Match_pos(); -// continue; // do not add to bfr -// } -// else { -// if (ltr_bgn == -1) {// no ltrs seen; treat as literal; occurs for ::fr:wikt:test and fr::Help:test -// ++colon_count; -// break; -// } -// boolean part_found = false; -// if (colon_count == 0) {// 1st colon; -// Object o = wiki.Wiki_mgr().GetByMid(bfr.Bfr(), ltr_bgn, txt_bb_len); // check if wiki; note: wiki is not possible for other colons -// if (o != null) { -// wik_bgn = 0; // wik_bgn can only start at 0 -// part_found = true; -// } -// else { // not wiki; check if ns; note: if wiki, don't try to extract ns; EX: "fr:Aide:test" -// o = ns_mgr.Trie_match_exact(bfr.Bfr(), ltr_bgn, txt_bb_len); -// if (o != null) { -// ns = (Xow_ns)o; -// ns_bgn = ltr_bgn; -// part_found = true; -// } -// } -// } -// if (part_found) { -// page_bgn = txt_bb_len + 1; // anticipate page_bgn; -// add_ws = false; // if there was an add_ws, ignore; EX: "Category :" should ignore space -// ltr_bgn_reset = true; // ltr_bgn_reset -// } -// colon_count++; // increment colon count -// break; -// } -// case Xoa_ttl_trie.Id_hash: anch_bgn = (txt_bb_len) + 1; break; // flag last anch_bgn -// case Xoa_ttl_trie.Id_slash: leaf_bgn = (txt_bb_len) + 1; break; // flag last leaf_bgn -// case Xoa_ttl_trie.Id_newLine: // NOTE: for now, treat nl just like space; not sure if it should accept "a\nb" or "\nab"; need to handle trailing \n for "Argentina\n\n" in {{Infobox settlement|pushpin_map=Argentina|pushpin_label_position=|pushpin_map_alt=|pushpin_map_caption=Location of Salta in Argentina}}; -// case Xoa_ttl_trie.Id_space: -// case Xoa_ttl_trie.Id_underline:if (ltr_bgn != -1) add_ws = true; cur = ttlTrie.Match_pos(); continue; // only mark add_ws if ltr_seen; this ignores ws at bgn; also, note "continue" -// case Xoa_ttl_trie.Id_amp: -// cur = ttlTrie.Match_pos(); -// if (cur == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character; -// else { -// Object html_ent_obj = wiki.App().Amp_trie().Match_bgn(src, cur, end); -// if (html_ent_obj != null) { -// Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)html_ent_obj; -// switch (amp_itm.CharInt()) { -// case Byte_ascii.Amp: -// case Byte_ascii.Quote: -// case Byte_ascii.Lt: -// case Byte_ascii.Gt: -// b_ary = amp_itm.XmlEntityName(); -// break; -// default: -// b_ary = amp_itm.CharIntAsAry(); -// break; -// } -// } -// } -// break; -// case Xoa_ttl_trie.Id_comment_bgn: -// cur = ttlTrie.Match_pos(); -// int find = Bry_finder.Find_fwd(src, Xop_comm_lxr.End_ary, cur, end); -// if (find != -1) { -// cur = find + Xop_comm_lxr.End_ary.length; -// continue; -// } -// else { -// msg_log.Add_itm_none(src, bgn, end, Xop_ttl_log.Comment_eos); -// return false; -// } -// default: break; -// } -// cur = ttlTrie.Match_pos(); -// } if (add_ws) { // add ws and toggle flag bfr.Add_byte(Byte_ascii.Space); ++txt_bb_len; -// bfr.Add_byte(Byte_ascii.Underline); ++txt_bb_len; add_ws = false; } if (ltr_bgn == -1) ltr_bgn = txt_bb_len; // if 1st letter not seen, mark 1st letter @@ -420,19 +321,11 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. } } if (txt_bb_len == 0) {msg_log.Add_itm_none(Xop_ttl_log.Len_0, src, bgn, end); return false;} -// if ( ((txt_bb_len - ns_len) > 255 && ns.Id() != Xow_ns_.Id_special) // DELETE: will cause multi-byte langs like thai to fail on long links; DATE:2013-02-02 -// || ((txt_bb_len - ns_len) > 512 && ns.Id() == Xow_ns_.Id_special)) {msg_log.Add_itm_none(Xop_ttl_log.Len_max, src, bgn, end); return false;} if (wik_bgn == -1 && page_bgn == txt_bb_len) { // if no wiki, but page_bgn is at end, then ttl is ns only; EX: "Help:"; NOTE: "fr:", "fr:Help" is allowed msg_log.Add_itm_none(Xop_ttl_log.Ttl_is_ns_only, src, bgn, end); return false; } full_txt = bfr.XtoAryAndClear(); - -// if (wik_bgn == 0 && txt_bb_len == page_bgn) { // 0-len intrawiki; EX: [[fr:]] on Main Page -// Xoa_ttl cur_page_ttl = wiki.Ctx().Cur_page().Ttl(); -// this.raw = cur_page_ttl == null ? Bry_.Empty : Bry_.Copy(cur_page_ttl.Page_txt()); // set raw to current page ttl; note that this is needed for lnki_caption to show correctly (otherwise lnki_caption will be blank); this is a quasi-hack as it depends on the ttl of the current page, but passing in another argument feels sloppy -// bfr.Add(this.raw); -// } if ( ns.Case_match() == Xow_ns_case_.Id_1st && wik_bgn == -1 ) { // do not check case if xwiki; EX: "fr:" would have a wik_bgn of 0 (and a wik_end of 3); "A" (and any non-xwiki ttl) would have a wik_bgn == -1 byte char_1st = full_txt[page_bgn]; @@ -443,8 +336,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. if (page_end > full_txt_len) // ttl is too too short for 1st multi-byte char; EX: [[%D0]] is 208 but in utf8, 208 requires at least another char; DATE:2013-11-11 return false; // ttl is invalid else { // ttl is long enough for 1st mult-byte char; need to use platform uppercasing; Xol_case_mgr_.Utf_8 is not sufficient - Bry_bfr upper_1st = wiki.Utl_bry_bfr_mkr().Get_b512(); - byte[] page_txt = wiki.Lang().Case_mgr().Case_build_1st_upper(upper_1st, full_txt, page_bgn, full_txt_len); // always build; never reuse; (multi-byte character will expand array) + Bry_bfr upper_1st = bry_mkr.Get_b512(); + byte[] page_txt = case_mgr.Case_build_1st_upper(upper_1st, full_txt, page_bgn, full_txt_len); // always build; never reuse; (multi-byte character will expand array) if (page_bgn == 0) // page only; EX: A full_txt = page_txt; else // ns + page; EX: Help:A @@ -453,7 +346,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. } } else - full_txt = wiki.Lang().Case_mgr().Case_reuse_upper(full_txt, page_bgn, page_end); + full_txt = case_mgr.Case_reuse_upper(full_txt, page_bgn, page_end); } Xow_ns tors_ns = ns.Id_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id()); tors_txt = tors_ns.Name_txt_w_colon(); diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_mock.java b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_mock.java index e8f2f299a..4c28648fa 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_mock.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_mock.java @@ -18,7 +18,9 @@ along with this program. If not, see . package gplx.xowa; import gplx.*; import gplx.xowa.xtns.scribunto.*; public class Xot_invk_mock implements Xot_invk { - public Xot_invk_mock(byte defn_tid, int idx_adj) {this.defn_tid = defn_tid; this.idx_adj = idx_adj;} private int idx_adj; // SEE NOTE_1: + Xot_invk_mock(byte defn_tid, int idx_adj, byte[] frame_ttl) { + this.defn_tid = defn_tid; this.idx_adj = idx_adj; this.frame_ttl = frame_ttl; + } private int idx_adj; // SEE NOTE_1: public int Src_bgn() {return -1;} public int Src_end() {return -1;} public byte Defn_tid() {return defn_tid;} private byte defn_tid = Xot_defn_.Tid_null; @@ -54,25 +56,11 @@ public class Xot_invk_mock implements Xot_invk { return Args_get_by_key(src, Bry_.XtoStrBytesByInt(idx + 1, 1)); } public Arg_nde_tkn Args_get_by_key(byte[] src, byte[] key) {return (Arg_nde_tkn)args.Fetch(key);} - public static Xot_invk_mock new_(byte defn_tid, KeyVal... args) {return new_(defn_tid, 1, args);} - public static Xot_invk_mock new_(KeyVal... args) {return new_(Xot_defn_.Tid_null, 1, args);} - public static Xot_invk_mock test_(KeyVal... args) {return new_(Xot_defn_.Tid_null, 0, args);} -// public static Xot_invk_mock new_(byte defn_tid, int idx_adj, params KeyVal[] args) { -// Xot_invk_mock rv = new Xot_invk_mock(defn_tid, idx_adj); -// int len = args.length; -// for (int i = 0; i < len; i++) { -// KeyVal arg = args[i]; -// Object arg_key_obj = arg.Key_as_obj(); -// String arg_key = arg.Key(); -// boolean arg_key_is_int = ClassAdp_.Eq_typeSafe(arg_key_obj, Int_.ClassOf); -// byte[] arg_key_bry = Bry_.new_utf8_(arg_key); -//// if (!rv.args.Has(arg_key_bry)) // ignore duplicates; EX:{{Template1|key1=a|key2=b|key1=c}} -// rv.args.AddReplace(arg_key_bry, new Arg_nde_tkn_mock(arg_key_is_int, arg_key, arg.Val_to_str_or_empty())); -// } -// return rv; -// } - public static Xot_invk_mock new_(byte defn_tid, int idx_adj, KeyVal... args) { - Xot_invk_mock rv = new Xot_invk_mock(defn_tid, idx_adj); + public static Xot_invk_mock new_(byte defn_tid, byte[] frame_ttl, KeyVal... args) {return new_(defn_tid, 1, frame_ttl, args);} + public static Xot_invk_mock new_(byte[] frame_ttl, KeyVal... args) {return new_(Xot_defn_.Tid_null, 1, frame_ttl, args);} + public static Xot_invk_mock test_(byte[] frame_ttl, KeyVal... args) {return new_(Xot_defn_.Tid_null, 0, frame_ttl, args);} + public static Xot_invk_mock new_(byte defn_tid, int idx_adj, byte[] frame_ttl, KeyVal... args) { + Xot_invk_mock rv = new Xot_invk_mock(defn_tid, idx_adj, frame_ttl); int len = args.length; for (int i = 0; i < len; i++) { KeyVal kv = args[i]; @@ -94,7 +82,7 @@ public class Xot_invk_mock implements Xot_invk { } return rv; } - public static final Xot_invk_mock Null = new Xot_invk_mock(Xot_defn_.Tid_null, 1); + public static final Xot_invk_mock Null = new Xot_invk_mock(Xot_defn_.Tid_null, 1, Bry_.Empty); } /* NOTE_1: Xot_invk_mock is being used as a container for two functions diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java index 5fe198cd2..74f822a1b 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java @@ -379,7 +379,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { byte old_parse_tid = ctx.Parse_tid(); // NOTE: reusing ctxs is a bad idea; will change Parse_tid and cause strange errors; however, keeping for PERF reasons Xow_ns ns_tmpl = wiki.Ns_mgr().Ns_template(); rv = wiki.Parser().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ns_tmpl, name_ary, tmpl_page_bry); - byte[] frame_ttl = tmpl_page_itm.Ttl().Full_txt(); // NOTE: (1) must have ns (Full); (2) must be txt (underscore, not space); EX:Template:Location map+; DATE:2014-08-22 + byte[] frame_ttl = tmpl_page_itm.Ttl().Full_txt(); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-08-22 rv.Frame_ttl_(frame_ttl); // set defn's frame_ttl; needed for redirect_trg; PAGE:en.w:Statutory_city; DATE:2014-08-22 ctx.Parse_tid_(old_parse_tid); wiki.Cache_mgr().Defn_cache().Add(rv, ns_tmpl.Case_match());