mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.3.1
This commit is contained in:
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdrOpts {
|
||||
public boolean HasHeader() {return hasHeader;} public DsvDataRdrOpts HasHeader_(boolean val) {hasHeader = val; return this;} private boolean hasHeader = false;
|
||||
public String NewLineSep() {return newLineSep;} public DsvDataRdrOpts NewLineSep_(String val) {newLineSep = val; return this;} private String newLineSep = String_.CrLf;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.strings.*; import gplx.stores.*;
|
||||
import gplx.core.strings.*; import gplx.core.gfo_ndes.*; import gplx.stores.*;
|
||||
import gplx.core.texts.*; /*CharStream*/
|
||||
public class DsvDataRdr_ {
|
||||
public static DataRdr dsv_(String text) {return DsvParser.dsv_().ParseAsRdr(text);}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdr_csv_dat_tst {
|
||||
@Before public void setup() {
|
||||
fx.Parser_(DsvParser.csv_(false, GfoFldList_.Null));
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdr_dsv_hdr_tst {
|
||||
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void Names() {
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdr_dsv_misc_tst {
|
||||
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void CmdDlm_NearMatches() {
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdr_layout_tst {
|
||||
@Test public void TableName() {
|
||||
run_parse_lines("table0, ,\" \",#");
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.core.strings.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataWtr extends DataWtr_base implements DataWtr {
|
||||
public void InitWtr(String key, Object val) {
|
||||
if (key == DsvStoreLayout.Key_const) layout = (DsvStoreLayout)val;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataWtr_csv_tst {
|
||||
@Test public void Dat_Val_0() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root);
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataWtr_tbls_tst {
|
||||
@Before public void setup() {
|
||||
DsvStoreLayout layout = DsvStoreLayout.dsv_brief_();
|
||||
|
||||
90
100_core/src/gplx/langs/gfs/GfsCore.java
Normal file
90
100_core/src/gplx/langs/gfs/GfsCore.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.gfo_regys.*;
|
||||
public class GfsCore implements GfoInvkAble {
|
||||
public GfoInvkAble Root() {return root;}
|
||||
@gplx.Internal protected GfsRegy Root_as_regy() {return root;} GfsRegy root = GfsRegy.new_();
|
||||
public void Clear() {root.Clear();}
|
||||
public GfoMsgParser MsgParser() {return msgParser;} public GfsCore MsgParser_(GfoMsgParser v) {msgParser = v; return this;} GfoMsgParser msgParser;
|
||||
public void Del(String key) {root.Del(key);}
|
||||
public void AddLib(GfsLibIni... ary) {for (GfsLibIni itm : ary) itm.Ini(this);}
|
||||
public void AddCmd(GfoInvkAble invk, String key) {root.AddCmd(invk, key);}
|
||||
public void AddObj(GfoInvkAble invk, String key) {root.AddObj(invk, key);}
|
||||
public void AddDeep(GfoInvkAble invk, String... ary) {
|
||||
GfoInvkCmdMgrOwner cur = (GfoInvkCmdMgrOwner)((GfsRegyItm)root.Get_by(ary[0])).InvkAble();
|
||||
for (int i = 1; i < ary.length - 1; i++)
|
||||
cur = (GfoInvkCmdMgrOwner)cur.InvkMgr().Invk(GfsCtx.Instance, 0, ary[i], GfoMsg_.Null, cur);
|
||||
cur.InvkMgr().Add_cmd(ary[ary.length - 1], invk);
|
||||
}
|
||||
public String FetchKey(GfoInvkAble invk) {return root.FetchByType(invk).Key();}
|
||||
public Object ExecOne(GfsCtx ctx, GfoMsg msg) {return GfsCore_.Exec(ctx, root, msg, null, 0);}
|
||||
public Object ExecOne_to(GfsCtx ctx, GfoInvkAble invk, GfoMsg msg) {return GfsCore_.Exec(ctx, invk, msg, null, 0);}
|
||||
public Object ExecMany(GfsCtx ctx, GfoMsg rootMsg) {
|
||||
Object rv = null;
|
||||
for (int i = 0; i < rootMsg.Subs_count(); i++) {
|
||||
GfoMsg subMsg = (GfoMsg)rootMsg.Subs_getAt(i);
|
||||
rv = GfsCore_.Exec(ctx, root, subMsg, null, 0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void ExecRegy(String key) {
|
||||
GfoRegyItm itm = GfoRegy.Instance.FetchOrNull(key);
|
||||
if (itm == null) {UsrDlg_.Instance.Warn(UsrMsg.new_("could not find script for key").Add("key", key)); return;}
|
||||
Io_url url = itm.Url();
|
||||
if (!Io_mgr.Instance.ExistsFil(url)) {
|
||||
UsrDlg_.Instance.Warn(UsrMsg.new_("script url does not exist").Add("key", key).Add("url", url));
|
||||
return;
|
||||
}
|
||||
this.ExecText(Io_mgr.Instance.LoadFilStr(url));
|
||||
}
|
||||
public Object ExecFile_ignoreMissing(Io_url url) {if (!Io_mgr.Instance.ExistsFil(url)) return null; return ExecText(Io_mgr.Instance.LoadFilStr(url));}
|
||||
public Object ExecFile(Io_url url) {return ExecText(Io_mgr.Instance.LoadFilStr(url));}
|
||||
public Object ExecFile_ignoreMissing(GfoInvkAble root, Io_url url) {
|
||||
if (!Io_mgr.Instance.ExistsFil(url)) return null;
|
||||
if (msgParser == null) throw Err_.new_wo_type("msgParser is null");
|
||||
return Exec_bry(Io_mgr.Instance.LoadFilBry(url), root);
|
||||
}
|
||||
public Object Exec_bry(byte[] bry) {return Exec_bry(bry, root);}
|
||||
public Object Exec_bry(byte[] bry, GfoInvkAble root) {
|
||||
GfoMsg rootMsg = msgParser.ParseToMsg(String_.new_u8(bry));
|
||||
Object rv = null;
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
for (int i = 0; i < rootMsg.Subs_count(); i++) {
|
||||
GfoMsg subMsg = (GfoMsg)rootMsg.Subs_getAt(i);
|
||||
rv = GfsCore_.Exec(ctx, root, subMsg, null, 0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Object ExecText(String text) {
|
||||
if (msgParser == null) throw Err_.new_wo_type("msgParser is null");
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
return ExecMany(ctx, msgParser.ParseToMsg(text));
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_ExecFil)) {
|
||||
Io_url url = m.ReadIoUrl("url");
|
||||
if (ctx.Deny()) return this;
|
||||
return ExecFile(url);
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
// return this;
|
||||
} public static final String Invk_ExecFil = "ExecFil";
|
||||
public static final GfsCore Instance = new GfsCore();
|
||||
@gplx.Internal protected static GfsCore new_() {return new GfsCore();}
|
||||
}
|
||||
73
100_core/src/gplx/langs/gfs/GfsCoreHelp.java
Normal file
73
100_core/src/gplx/langs/gfs/GfsCoreHelp.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.strings.*;
|
||||
class GfsCoreHelp implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
String path = m.ReadStrOr("path", "");
|
||||
if (String_.Eq(path, "")) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < core.Root_as_regy().Count(); i++) {
|
||||
GfsRegyItm itm = (GfsRegyItm)core.Root_as_regy().Get_at(i);
|
||||
sb.Add_spr_unless_first(itm.Key(), String_.CrLf, i);
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
else return Exec(ctx, core.Root_as_regy(), path);
|
||||
}
|
||||
public static Err Err_Unhandled(String objPath, String key) {return Err_.new_wo_type("obj does not handle msgKey", "objPath", objPath, "key", key).Trace_ignore_add_1_();}
|
||||
static Err Err_Unhandled(String[] itmAry, int i) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int j = 0; j < i; j++)
|
||||
sb.Add_spr_unless_first(itmAry[j], ".", j);
|
||||
return Err_Unhandled(sb.To_str(), itmAry[i]);
|
||||
}
|
||||
static Object Exec(GfsCtx rootCtx, GfoInvkAble rootInvk, String path) {
|
||||
String[] itmAry = String_.Split(path, ".");
|
||||
GfoInvkAble invk = rootInvk;
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
Object curRv = null;
|
||||
for (int i = 0; i < itmAry.length; i++) {
|
||||
String itm = itmAry[i];
|
||||
curRv = invk.Invk(ctx, 0, itm, GfoMsg_.Null);
|
||||
if (curRv == GfoInvkAble_.Rv_unhandled) throw Err_Unhandled(itmAry, i);
|
||||
invk = GfoInvkAble_.as_(curRv);
|
||||
}
|
||||
GfsCoreHelp helpData = GfsCoreHelp.as_(curRv);
|
||||
if (helpData != null) { // last itm is actually Method
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
ctx = GfsCtx.new_().Help_browseMode_(true);
|
||||
invk.Invk(ctx, 0, "", GfoMsg_.Null);
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < ctx.Help_browseList().Count(); i++) {
|
||||
String s = (String)ctx.Help_browseList().Get_at(i);
|
||||
sb.Add_spr_unless_first(s, String_.CrLf, i);
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
}
|
||||
public static GfsCoreHelp as_(Object obj) {return obj instanceof GfsCoreHelp ? (GfsCoreHelp)obj : null;}
|
||||
public static GfsCoreHelp new_(GfsCore core) {
|
||||
GfsCoreHelp rv = new GfsCoreHelp();
|
||||
rv.core = core;
|
||||
return rv;
|
||||
} GfsCoreHelp() {}
|
||||
GfsCore core;
|
||||
}
|
||||
96
100_core/src/gplx/langs/gfs/GfsCore_.java
Normal file
96
100_core/src/gplx/langs/gfs/GfsCore_.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
public class GfsCore_ {
|
||||
public static final String Arg_primitive = "v";
|
||||
public static Object Exec(GfsCtx ctx, GfoInvkAble owner_invk, GfoMsg owner_msg, Object owner_primitive, int depth) {
|
||||
if (owner_msg.Args_count() == 0 && owner_msg.Subs_count() == 0 && String_.Eq(owner_msg.Key(), "")) {UsrDlg_.Instance.Warn("empty msg"); return GfoInvkAble_.Rv_unhandled;}
|
||||
if (owner_primitive != null) owner_msg.Parse_(false).Add(GfsCore_.Arg_primitive, owner_primitive);
|
||||
Object rv = owner_invk.Invk(ctx, 0, owner_msg.Key(), owner_msg);
|
||||
if (rv == GfoInvkAble_.Rv_cancel) return rv;
|
||||
else if (rv == GfoInvkAble_.Rv_unhandled) {
|
||||
if (ctx.Fail_if_unhandled())
|
||||
throw Err_.new_wo_type("Object does not support key", "key", owner_msg.Key(), "ownerType", Type_adp_.FullNameOf_obj(owner_invk));
|
||||
else {
|
||||
Gfo_usr_dlg usr_dlg = ctx.Usr_dlg();
|
||||
if (usr_dlg != null) usr_dlg.Warn_many(GRP_KEY, "unhandled_key", "Object does not support key: key=~{0} ownerType=~{1}", owner_msg.Key(), Type_adp_.FullNameOf_obj(owner_invk));
|
||||
return GfoInvkAble_.Null;
|
||||
}
|
||||
}
|
||||
if (owner_msg.Subs_count() == 0) { // msg is leaf
|
||||
GfsRegyItm regyItm = GfsRegyItm.as_(rv);
|
||||
if (regyItm == null) return rv; // rv is primitive or other non-regy Object
|
||||
if (regyItm.IsCmd()) // rv is cmd; invk cmd
|
||||
return regyItm.InvkAble().Invk(ctx, 0, owner_msg.Key(), owner_msg);
|
||||
else // rv is host
|
||||
return regyItm.InvkAble();
|
||||
}
|
||||
else { // intermediate; cast to invk and call Exec
|
||||
GfoInvkAble invk = GfoInvkAble_.as_(rv);
|
||||
Object primitive = null;
|
||||
if (invk == null) { // rv is primitive; find appropriate mgr
|
||||
Class<?> type = rv.getClass();
|
||||
if (type == String.class) invk = String_.Gfs;
|
||||
else if (Int_.TypeMatch(type)) invk = Int_.Gfs;
|
||||
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) invk = Bool_.Gfs;
|
||||
else throw Err_.new_wo_type("unknown primitive", "type", Type_adp_.NameOf_type(type), "obj", Object_.Xto_str_strict_or_null_mark(rv));
|
||||
primitive = rv;
|
||||
}
|
||||
Object exec_rv = null;
|
||||
int len = owner_msg.Subs_count();
|
||||
for (int i = 0; i < len; i++) // iterate over subs; needed for a{b;c;d;}
|
||||
exec_rv = Exec(ctx, invk, owner_msg.Subs_getAt(i), primitive, depth + 1);
|
||||
return exec_rv;
|
||||
}
|
||||
}
|
||||
static final String GRP_KEY = "gplx.gfs_core";
|
||||
}
|
||||
// class GfsRegyMgr : GfoInvkAble {
|
||||
// public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
// if (ctx.Match(k, Invk_Add)) {
|
||||
// String libKey = m.ReadStr("libKey"), regKey = m.ReadStr("regKey");
|
||||
// if (ctx.Deny()) return this;
|
||||
// GfsRegyItm itm = regy.Get_by(libKey);
|
||||
// if (regy.Has(regKey)) {ctx.Write_warn("'{0}' already exists", regKey); return this;}
|
||||
// regy.Add(regKey, itm.InvkAble(), itm.Type_cmd());
|
||||
// ctx.Write_note("added '{0}' as '{1}'", regKey, libKey);
|
||||
// }
|
||||
// else if (ctx.Match(k, Invk_Del)) {
|
||||
// String regKey = m.ReadStr("regKey");
|
||||
// if (ctx.Deny()) return this;
|
||||
// if (!regy.Has(regKey)) {ctx.Write_warn("{0} does not exist", regKey); return this;}
|
||||
// regy.Del(regKey);
|
||||
// ctx.Write_note("removed '{0}'", regKey);
|
||||
// }
|
||||
// else if (ctx.Match(k, Invk_Load)) {
|
||||
// Io_url url = (Io_url)m.ReadObj("url", Io_url_.Parser);
|
||||
// if (ctx.Deny()) return this;
|
||||
// String loadText = Io_mgr.Instance.LoadFilStr(url);
|
||||
// GfoMsg loadMsg = core.MsgParser().ParseToMsg(loadText);
|
||||
// return core.Exec(ctx, loadMsg);
|
||||
// }
|
||||
// else return GfoInvkAble_.Rv_unhandled;
|
||||
// return this;
|
||||
// } public static final String Invk_Add = "Add", Invk_Del = "Del", Invk_Load = "Load";
|
||||
// GfsCore core; GfsRegy regy;
|
||||
// public static GfsRegyMgr new_(GfsCore core, GfsRegy regy) {
|
||||
// GfsRegyMgr rv = new GfsRegyMgr();
|
||||
// rv.core = core; rv.regy = regy;
|
||||
// return rv;
|
||||
// } GfsRegyMgr() {}
|
||||
// }
|
||||
113
100_core/src/gplx/langs/gfs/GfsCore_tst.java
Normal file
113
100_core/src/gplx/langs/gfs/GfsCore_tst.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class GfsCore_tst {
|
||||
@Before public void setup() {
|
||||
core = GfsCore.new_();
|
||||
core.AddObj(String_.Gfs, "String_");
|
||||
core.AddObj(Int_.Gfs, "Int_");
|
||||
} GfsCore core;
|
||||
@Test public void Basic() { // String_.Len('abc') >> 3
|
||||
tst_Msg
|
||||
( msg_("String_").Subs_
|
||||
( msg_("Len").Add("v", "abc"))
|
||||
, 3);
|
||||
}
|
||||
@Test public void PrimitiveConversion() { // String_.Len('abc').Add(-3) >> 0
|
||||
tst_Msg
|
||||
( msg_("String_").Subs_
|
||||
( msg_("Len").Add("v", "abc").Subs_
|
||||
( msg_("Add").Add("operand", -3))
|
||||
)
|
||||
, 0);
|
||||
}
|
||||
// @Test public void Fail_notFound() { // String_.DoesNotExists
|
||||
// tst_Err
|
||||
// ( msg_("help").Add("", "String_.DoesNotExist")
|
||||
// , GfsHelp.Err_Unhandled("String_", "DoesNotExist"));
|
||||
// }
|
||||
@Test public void Cmd() { // cmd
|
||||
core.AddCmd(new GfsTest_cmd(), "testCmd");
|
||||
tst_Msg
|
||||
( msg_("testCmd").Add("s", "pass")
|
||||
, "pass");
|
||||
}
|
||||
@Test public void EmptyMsg() {
|
||||
tst_Msg
|
||||
( msg_("")
|
||||
, GfoInvkAble_.Rv_unhandled);
|
||||
}
|
||||
// @Test public void Fail_argMissing() { // String_.Len()
|
||||
// tst_String__Len_Err(msg_("Len"), GfsCtx.Err_KeyNotFound("v", "<<EMPTY>>"));
|
||||
// }
|
||||
// @Test public void Fail_argWrongKey() { // String_.Len(badKey='abc')
|
||||
// tst_String__Len_Err(msg_("Len").Add("badKey", "abc"), GfsCtx.Err_KeyNotFound("v", "badKey;"));
|
||||
// }
|
||||
// @Test public void Fail_argExtraKey() { // String_.Len(v='abc' extraKey=1)
|
||||
// tst_String__Len_Err(msg_("Len").Add("v", "abc").Add("extraKey", 1), GfsCtx.Err_KeyNotFound("v", "badKey;"));
|
||||
// }
|
||||
@Test public void Add_obj_deep() { // String_.Len(badKey='abc')
|
||||
GfsCore_tst_nest obj1 = GfsCore_tst_nest.new_("1", "val1");
|
||||
GfsCore_tst_nest obj1_1 = GfsCore_tst_nest.new_("1_1", "val2");
|
||||
core.AddObj(obj1, "1");
|
||||
core.AddDeep(obj1_1, "1", "1_1");
|
||||
|
||||
GfoMsg root = GfoMsg_.root_("1", "1_1", GfsCore_tst_nest.Prop2);
|
||||
Object actl = core.ExecOne(GfsCtx.Instance, root);
|
||||
Tfds.Eq("val2", actl);
|
||||
}
|
||||
void tst_String__Len_Err(GfoMsg m, Err expd) {
|
||||
tst_Err(msg_("String_").Subs_(m), expd);
|
||||
}
|
||||
void tst_Err(GfoMsg msg, Err expd) {
|
||||
GfoMsg root = msg;
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
try {
|
||||
core.ExecOne(ctx, root);
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Tfds.Eq_err(expd, e);
|
||||
}
|
||||
}
|
||||
GfoMsg msg_(String k) {return GfoMsg_.new_cast_(k);}
|
||||
void tst_Msg(GfoMsg msg, Object expd) {
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
Object actl = core.ExecOne(ctx, msg);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
class GfsCore_tst_nest implements GfoInvkAble, GfoInvkCmdMgrOwner {
|
||||
public GfoInvkCmdMgr InvkMgr() {return invkMgr;} GfoInvkCmdMgr invkMgr = GfoInvkCmdMgr.new_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Prop1)) {return prop1;}
|
||||
else if (ctx.Match(k, Prop2)) {return prop2;}
|
||||
else if (ctx.Match(k, prop1)) {return this;}
|
||||
else return invkMgr.Invk(ctx, ikey, k, m, this);
|
||||
} public static final String Prop1 = "Prop1", Prop2 = "Prop2";
|
||||
String prop1, prop2;
|
||||
public static GfsCore_tst_nest new_(String prop1, String prop2) {
|
||||
GfsCore_tst_nest rv = new GfsCore_tst_nest();
|
||||
rv.prop1 = prop1; rv.prop2 = prop2;
|
||||
return rv;
|
||||
} GfsCore_tst_nest() {}
|
||||
}
|
||||
class GfsTest_cmd implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return m.ReadStr("s");}
|
||||
}
|
||||
21
100_core/src/gplx/langs/gfs/GfsLibIni.java
Normal file
21
100_core/src/gplx/langs/gfs/GfsLibIni.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
public interface GfsLibIni {
|
||||
void Ini(GfsCore core);
|
||||
}
|
||||
36
100_core/src/gplx/langs/gfs/GfsLibIni_core.java
Normal file
36
100_core/src/gplx/langs/gfs/GfsLibIni_core.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.gfo_regys.*;
|
||||
public class GfsLibIni_core implements GfsLibIni {
|
||||
public void Ini(GfsCore core) {
|
||||
core.AddCmd(GfsCoreHelp.new_(core), "help");
|
||||
core.AddObj(String_.Gfs, "String_");
|
||||
core.AddObj(Int_.Gfs, "Int_");
|
||||
core.AddObj(DateAdp_.Gfs, "Date_");
|
||||
core.AddObj(RandomAdp_.Gfs, "RandomAdp_");
|
||||
core.AddObj(GfoTemplateFactory.Instance, "factory");
|
||||
core.AddObj(GfoRegy.Instance, "GfoRegy_");
|
||||
core.AddObj(GfsCore.Instance, "GfsCore_");
|
||||
core.AddObj(gplx.core.ios.IoUrlInfoRegy.Instance, "IoUrlInfoRegy_");
|
||||
core.AddObj(gplx.core.ios.IoUrlTypeRegy.Instance, "IoUrlTypeRegy_");
|
||||
|
||||
GfoRegy.Instance.Parsers().Add("Io_url", Io_url_.Parser);
|
||||
}
|
||||
public static final GfsLibIni_core Instance = new GfsLibIni_core(); GfsLibIni_core() {}
|
||||
}
|
||||
54
100_core/src/gplx/langs/gfs/GfsRegy.java
Normal file
54
100_core/src/gplx/langs/gfs/GfsRegy.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
class GfsRegy implements GfoInvkAble {
|
||||
public int Count() {return hash.Count();}
|
||||
public void Clear() {hash.Clear(); typeHash.Clear();}
|
||||
public boolean Has(String k) {return hash.Has(k);}
|
||||
public GfsRegyItm Get_at(int i) {return (GfsRegyItm)hash.Get_at(i);}
|
||||
public GfsRegyItm Get_by(String key) {return (GfsRegyItm)hash.Get_by(key);}
|
||||
public GfsRegyItm FetchByType(GfoInvkAble invk) {return (GfsRegyItm)typeHash.Get_by(Type_adp_.FullNameOf_obj(invk));}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Object rv = (GfsRegyItm)hash.Get_by(k); if (rv == null) throw Err_.new_missing_key(k);
|
||||
return rv;
|
||||
}
|
||||
public void AddObj(GfoInvkAble invk, String key) {Add(key, invk, false);}
|
||||
public void AddCmd(GfoInvkAble invk, String key) {Add(key, invk, true);}
|
||||
public void Add(String key, GfoInvkAble invk, boolean typeCmd) {
|
||||
if (hash.Has(key)) return;
|
||||
GfsRegyItm regyItm = new GfsRegyItm().Key_(key).InvkAble_(invk).IsCmd_(typeCmd).TypeKey_(Type_adp_.FullNameOf_obj(invk));
|
||||
hash.Add(key, regyItm);
|
||||
typeHash.Add_if_dupe_use_1st(regyItm.TypeKey(), regyItm); // NOTE: changed to allow same Object to be added under different aliases (app, xowa) DATE:2014-06-09;
|
||||
}
|
||||
public void Del(String k) {
|
||||
GfsRegyItm itm =(GfsRegyItm)hash.Get_by(k);
|
||||
if (itm != null) typeHash.Del(itm.TypeKey());
|
||||
hash.Del(k);
|
||||
}
|
||||
Hash_adp typeHash = Hash_adp_.new_();
|
||||
Ordered_hash hash = Ordered_hash_.New();
|
||||
public static GfsRegy new_() {return new GfsRegy();} GfsRegy() {}
|
||||
}
|
||||
class GfsRegyItm implements GfoInvkAble {
|
||||
public String Key() {return key;} public GfsRegyItm Key_(String v) {key = v; return this;} private String key;
|
||||
public String TypeKey() {return typeKey;} public GfsRegyItm TypeKey_(String v) {typeKey = v; return this;} private String typeKey;
|
||||
public boolean IsCmd() {return isCmd;} public GfsRegyItm IsCmd_(boolean v) {isCmd = v; return this;} private boolean isCmd;
|
||||
public GfoInvkAble InvkAble() {return invkAble;} public GfsRegyItm InvkAble_(GfoInvkAble v) {invkAble = v; return this;} GfoInvkAble invkAble;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return invkAble.Invk(ctx, ikey, k, m);}
|
||||
public static GfsRegyItm as_(Object obj) {return obj instanceof GfsRegyItm ? (GfsRegyItm)obj : null;}
|
||||
}
|
||||
28
100_core/src/gplx/langs/gfs/GfsTypeNames.java
Normal file
28
100_core/src/gplx/langs/gfs/GfsTypeNames.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
public class GfsTypeNames {
|
||||
public static final String
|
||||
String = "string"
|
||||
, Int = "int"
|
||||
, Bool = "bool"
|
||||
, Float = "float"
|
||||
, YesNo = "yn"
|
||||
, Date = "date"
|
||||
;
|
||||
}
|
||||
42
100_core/src/gplx/langs/gfs/Gfs_Date_tst.java
Normal file
42
100_core/src/gplx/langs/gfs/Gfs_Date_tst.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_Date_tst {
|
||||
@Before public void setup() {
|
||||
fx = new GfsCoreFxt();
|
||||
fx.AddObj(DateAdp_.Gfs, "Date_");
|
||||
Tfds.Now_enabled_y_();
|
||||
} GfsCoreFxt fx;
|
||||
@Test public void Now() {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now")), DateAdp_.parse_gplx("2001-01-01 00:00:00.000"));
|
||||
}
|
||||
@Test public void Add_day() {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now", "Add_day"), KeyVal_.new_("days", 1)), DateAdp_.parse_gplx("2001-01-02 00:00:00.000"));
|
||||
}
|
||||
}
|
||||
class GfsCoreFxt {
|
||||
public GfsCore Core() {return core;} GfsCore core = GfsCore.new_();
|
||||
public GfoMsg msg_(String[] ary, KeyVal... kvAry) {return GfoMsg_.root_leafArgs_(ary, kvAry);}
|
||||
public void AddObj(GfoInvkAble invk, String s) {core.AddObj(invk, s);}
|
||||
public void tst_MsgStr(GfoMsg msg, Object expd) {
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
Object actl = core.ExecOne(ctx, msg);
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user