1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2016-01-03 21:27:38 -05:00
parent 9509363f46
commit 096045614c
647 changed files with 11693 additions and 7648 deletions

View File

@@ -39,6 +39,11 @@ public class Bool_ implements GfoInvkAble {
return false;
throw Err_.new_parse_type(boolean.class, raw);
}
public static int Compare(boolean lhs, boolean rhs) {
if ( lhs == rhs) return CompareAble_.Same;
else if (!lhs && rhs) return CompareAble_.Less;
else /*lhs && !rhs*/ return CompareAble_.More;
}
public static boolean By_int(int v) {return v == Y_int;}
public static int To_int(boolean v) {return v ? Y_int : N_int;}
public static byte To_byte(boolean v) {return v ? Y_byte : N_byte;}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*;
public class Bool__tst {
private final Bool__fxt fxt = new Bool__fxt();
@Test public void Compare() {
fxt.Test__compare(Bool_.Y, Bool_.Y, CompareAble_.Same);
fxt.Test__compare(Bool_.N, Bool_.N, CompareAble_.Same);
fxt.Test__compare(Bool_.N, Bool_.Y, CompareAble_.Less);
fxt.Test__compare(Bool_.Y, Bool_.N, CompareAble_.More);
}
}
class Bool__fxt {
public void Test__compare(boolean lhs, boolean rhs, int expd) {Tfds.Eq(expd, Bool_.Compare(lhs, rhs));}
}

View File

@@ -23,14 +23,26 @@ public class Bry_ {
public static final byte[] Empty = new byte[0];
public static final byte[][] Ary_empty = new byte[0][];
public static final Class<?> Cls_ref_type = byte[].class;
public static byte[] new_bytes(byte... ary) {return ary;}
public static byte[] new_ints(int... ary) {
public static byte[] New_by_byte(byte b) {return new byte[] {b};}
public static byte[] New_by_ints(int... ary) {
int len = ary.length;
byte[] rv = new byte[len];
for (int i = 0; i < len; i++)
rv[i] = (byte)ary[i];
return rv;
}
public static byte[] New_by_objs(Bry_bfr bfr, Object... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Object itm = ary[i];
Class<?> type = Type_adp_.ClassOf_obj(itm);
if (Type_adp_.Eq(type, int.class)) bfr.Add_byte((byte)Int_.cast(itm));
else if (Type_adp_.Eq(type, String.class)) bfr.Add_str_u8((String)itm);
else if (Type_adp_.Eq(type, byte[].class)) bfr.Add((byte[])itm);
else throw Err_.new_unhandled(Type_adp_.FullNameOf_type(type));
}
return bfr.To_bry_and_clear();
}
public static byte[] Coalesce_to_empty(byte[] v) {return v == null ? Bry_.Empty : v;}
public static byte[] Coalesce(byte[] v, byte[] or) {return v == null ? or : v;}
public static byte[] new_a7(String str) {
@@ -210,6 +222,8 @@ public class Bry_ {
if (src[i] == lkp) return true;
return false;
}
public static boolean Has_at_bgn(byte[] src, byte lkp) {return Has_at_bgn(src, lkp, 0);}
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
int lkp_len = lkp.length;
@@ -229,7 +243,6 @@ public class Bry_ {
}
return true;
}
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
public static void Set(byte[] src, int bgn, int end, byte[] repl) {
int repl_len = repl.length;
for (int i = 0; i < repl_len; i++)

View File

@@ -20,17 +20,17 @@ import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*;
public class Bry__tst {
private final Bry__fxt fxt = new Bry__fxt();
@Test public void new_ascii_() {
fxt.Test_new_a7("a" , Bry_.new_ints(97)); // one
fxt.Test_new_a7("abc" , Bry_.new_ints(97, 98, 99)); // many
fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_a7("" , Bry_.Empty); // none
fxt.Test_new_a7("¢€𤭢" , Bry_.new_ints(63, 63, 63, 63)); // non-ascii -> ?
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
}
@Test public void new_u8() {
fxt.Test_new_u8("a" , Bry_.new_ints(97)); // one
fxt.Test_new_u8("abc" , Bry_.new_ints(97, 98, 99)); // many
fxt.Test_new_u8("¢" , Bry_.new_ints(194, 162)); // bry_len=2; cent
fxt.Test_new_u8("" , Bry_.new_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("𤭢" , Bry_.new_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent
fxt.Test_new_u8("" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
}
@Test public void Add__bry_plus_byte() {
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic

View File

@@ -25,6 +25,10 @@ public class Bry_find_ {
if (src[i] == lkp) return i;
return Bry_find_.Not_found;
}
public static int Find_fwd_or(byte[] src, byte lkp, int cur, int end, int or) {
int rv = Find_fwd(src, lkp, cur, end);
return rv == Bry_find_.Not_found ? or : rv;
}
public static int Find_bwd(byte[] src, byte lkp) {return Find_bwd(src, lkp, src.length, 0);}
public static int Find_bwd(byte[] src, byte lkp, int cur) {return Find_bwd(src, lkp, cur , 0);}
public static int Find_bwd(byte[] src, byte lkp, int cur, int end) {
@@ -177,6 +181,16 @@ public class Bry_find_ {
}
return bgn;
}
public static int Find_bwd__skip(byte[] src, int end, int bgn, byte skip) {
int src_len = src.length; if (end == src_len) return end;
if (end > src_len || end < 0) return Bry_find_.Not_found;
int pos = end - 1; // start from end - 1; handles situations where len is passed in
for (int i = pos; i >= bgn; --i) {
if (src[i] != skip)
return i + 1;
}
return bgn;
}
public static int Find_bwd_while(byte[] src, int cur, int end, byte while_byte) {
--cur;
while (true) {

View File

@@ -23,6 +23,8 @@ public class Byte_ {
Zero = 0
, Min_value = Byte.MIN_VALUE
, Max_value_127 = 127
, Val_128 = -128
, Val_255 = -1
;
public static byte cast(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, byte.class, o);}}
public static byte parse(String raw) {return Byte.parseByte(raw);}

View File

@@ -108,10 +108,12 @@ public class Byte_ascii {
, Angle_end_bry = new byte[] {Byte_ascii.Angle_end}
, Comma_bry = new byte[] {Byte_ascii.Comma}
, Colon_bry = new byte[] {Byte_ascii.Colon}
, Semic_bry = new byte[] {Byte_ascii.Semic}
, Eq_bry = new byte[] {Byte_ascii.Eq}
, Amp_bry = new byte[] {Byte_ascii.Amp}
, Lt_bry = new byte[] {Byte_ascii.Lt}
, Gt_bry = new byte[] {Byte_ascii.Gt}
, Question_bry = new byte[] {Byte_ascii.Question}
, Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn}
, Brack_end_bry = new byte[] {Byte_ascii.Brack_end}
, Apos_bry = new byte[] {Byte_ascii.Apos}

View File

@@ -18,9 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Cancelable_ {
public static final Cancelable Never = new Cancelable_never();
public static Cancelable New_proxy() {return new Cancelable_proxy();}
}
class Cancelable_never implements Cancelable {
public boolean Canceled() {return false;}
public void Cancel() {}
public void Cancel_reset() {}
}
class Cancelable_proxy implements Cancelable {
private boolean canceled = false;
public boolean Canceled() {return canceled;}
public void Cancel() {canceled = true;}
public void Cancel_reset() {canceled = false;}
}

View File

@@ -69,6 +69,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
public String XtoStr_fmt_yyyy_MM_dd_HH_mm() {return XtoStr_fmt("yyyy-MM-dd HH:mm");}
public String XtoStr_fmt_yyyy_MM_dd_HH_mm_ss() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
public String XtoStr_fmt_iso_8561() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
public String XtoStr_fmt_iso_8561_w_tz() {return XtoStr_fmt("yyyy-MM-dd'T'HH:mm:ss'Z'");}
public static int Timezone_offset_test = Int_.Min_value;
public Calendar UnderDateTime() {return under;} Calendar under;
public int Year() {return under.get(Calendar.YEAR);}

View File

@@ -58,7 +58,7 @@ public class Err extends RuntimeException {
String nl_str = called_by_log ? "\t" : "\n";
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
for (int i = 0; i < msgs_idx; ++i) {
rv += "[err " + Int_.To_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
rv += "[err " + Int_.To_str(i) + "] " + String_.Replace(msgs_ary[i].To_str(), "\n", nl_str) + nl_str;
}
if (include_trace)
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);

View File

@@ -23,6 +23,11 @@ public class Float_ {
public static boolean IsNaN(float v) {return Float.isNaN(v);}
public static float cast(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, float.class, obj);}}
public static float parse(String raw) {try {return Float.parseFloat(raw);} catch(Exception exc) {throw Err_.new_parse_exc(exc, float.class, raw);}}
public static int Compare(float lhs, float rhs) {
if ( lhs == rhs) return CompareAble_.Same;
else if ( lhs < rhs) return CompareAble_.Less;
else /*lhs > rhs*/ return CompareAble_.More;
}
public static String To_str(float v) {
int v_int = (int)v;
return v - v_int == 0 ? Int_.To_str(v_int) : Float.toString(v);

View File

@@ -0,0 +1,131 @@
/*
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;
import gplx.core.lists.*;
public class GfoEvMgr {
@gplx.Internal protected void AddSub(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subPrc) {
GfoEvLnk lnk = new GfoEvLnk(pub, pubEvt, sub, subPrc);
if (subsRegy == null) subsRegy = Ordered_hash_.New();
AddInList(subsRegy, pubEvt, lnk);
sub.EvMgr().AddPub(pubEvt, lnk);
}
@gplx.Internal protected void Lnk(GfoEvMgrOwner pub) {
if (pub.EvMgr().lnks == null) pub.EvMgr().lnks = List_adp_.new_();
pub.EvMgr().lnks.Add(this);
} List_adp lnks;
void AddInList(Ordered_hash regy, String key, GfoEvLnk lnk) {
GfoEvLnkList list = (GfoEvLnkList)regy.Get_by(key);
if (list == null) {
list = new GfoEvLnkList(key);
regy.Add(key, list);
}
list.Add(lnk);
}
@gplx.Internal protected void AddPub(String pubEvt, GfoEvLnk lnk) {
if (pubsRegy == null) pubsRegy = Ordered_hash_.New();
AddInList(pubsRegy, pubEvt, lnk);
}
@gplx.Internal protected void Pub(GfsCtx ctx, String evt, GfoMsg m) {
ctx.MsgSrc_(sender);
GfoEvLnkList subs = subsRegy == null ? null : (GfoEvLnkList)subsRegy.Get_by(evt);
if (subs != null) {
for (int i = 0; i < subs.Count(); i++) {
GfoEvLnk lnk = (GfoEvLnk)subs.Get_at(i);
lnk.Sub().Invk(ctx, 0, lnk.SubPrc(), m); // NOTE: itm.Key() needed for Subscribe_diff()
}
}
if (lnks != null) {
for (int i = 0; i < lnks.Count(); i++) {
GfoEvMgr lnk = (GfoEvMgr)lnks.Get_at(i);
lnk.Pub(ctx, evt, m);
}
}
}
@gplx.Internal protected void RlsSub(GfoEvMgrOwner eobj) {
RlsRegyObj(pubsRegy, eobj, true);
RlsRegyObj(subsRegy, eobj, false);
}
@gplx.Internal protected void RlsPub(GfoEvMgrOwner eobj) {
RlsRegyObj(pubsRegy, eobj, true);
RlsRegyObj(subsRegy, eobj, false);
}
@gplx.Internal protected void RlsRegyObj(Ordered_hash regy, GfoEvMgrOwner eobj, boolean pub) {
if (regy == null) return;
List_adp delList = List_adp_.new_();
for (int i = 0; i < regy.Count(); i++) {
GfoEvLnkList pubsList = (GfoEvLnkList)regy.Get_at(i);
delList.Clear();
for (int j = 0; j < pubsList.Count(); j++) {
GfoEvLnk lnk = (GfoEvLnk)pubsList.Get_at(j);
if (lnk.End(!pub) == eobj) delList.Add(lnk);
}
for (int j = 0; j < delList.Count(); j++) {
GfoEvLnk del = (GfoEvLnk)delList.Get_at(j);
del.End(pub).EvMgr().RlsLnk(!pub, pubsList.Key(), del.End(!pub));
pubsList.Del(del);
}
}
}
@gplx.Internal protected void RlsLnk(boolean pubEnd, String key, GfoEvMgrOwner endObj) {
Ordered_hash regy = pubEnd ? pubsRegy : subsRegy;
GfoEvLnkList list = (GfoEvLnkList)regy.Get_by(key);
List_adp delList = List_adp_.new_();
for (int i = 0; i < list.Count(); i++) {
GfoEvLnk lnk = (GfoEvLnk)list.Get_at(i);
if (lnk.End(pubEnd) == endObj) delList.Add(lnk);
}
for (int i = 0; i < delList.Count(); i++) {
GfoEvLnk lnk = (GfoEvLnk)delList.Get_at(i);
list.Del(lnk);
}
delList.Clear();
}
Object sender; Ordered_hash subsRegy, pubsRegy;
public static GfoEvMgr new_(Object sender) {
GfoEvMgr rv = new GfoEvMgr();
rv.sender = sender;
return rv;
} GfoEvMgr() {}
}
class GfoEvLnkList {
public String Key() {return key;} private String key;
public int Count() {return list.Count();}
public void Add(GfoEvLnk lnk) {list.Add(lnk);}
public void Del(GfoEvLnk lnk) {list.Del(lnk);}
public GfoEvLnk Get_at(int i) {return (GfoEvLnk)list.Get_at(i);}
public GfoEvLnkList(String key) {this.key = key;}
List_adp list = List_adp_.new_();
}
class GfoEvLnk {
public GfoEvMgrOwner Pub() {return pub;} GfoEvMgrOwner pub;
public String PubEvt() {return pubEvt;} private String pubEvt;
public GfoEvObj Sub() {return sub;} GfoEvObj sub;
public String SubPrc() {return subPrc;} private String subPrc;
public GfoEvMgrOwner End(boolean pubEnd) {return pubEnd ? pub : sub;}
public GfoEvLnk(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subPrc) {this.pub = pub; this.pubEvt = pubEvt; this.sub = sub; this.subPrc = subPrc;}
}
class GfoEvItm {
public String Key() {return key;} private String key;
public GfoInvkAble InvkAble() {return invkAble;} GfoInvkAble invkAble;
public static GfoEvItm new_(GfoInvkAble invkAble, String key) {
GfoEvItm rv = new GfoEvItm();
rv.invkAble = invkAble; rv.key = key;
return rv;
}
}

View 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;
public interface GfoEvMgrOwner {
GfoEvMgr EvMgr();
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class GfoEvMgr_ {
public static void Sub(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subEvt) {pub.EvMgr().AddSub(pub, pubEvt, sub, subEvt);}
public static void SubSame(GfoEvMgrOwner pub, String evt, GfoEvObj sub) {pub.EvMgr().AddSub(pub, evt, sub, evt);}
public static void SubSame_many(GfoEvMgrOwner pub, GfoEvObj sub, String... evts) {
int len = evts.length;
for (int i = 0; i < len; i++) {
String evt = evts[i];
pub.EvMgr().AddSub(pub, evt, sub, evt);
}
}
public static void Pub(GfoEvMgrOwner pub, String pubEvt) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, GfoMsg_.new_cast_(pubEvt));}
public static void PubObj(GfoEvMgrOwner pub, String pubEvt, String key, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, KeyVal_.new_(key, v)));}
public static void PubVal(GfoEvMgrOwner pub, String pubEvt, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, KeyVal_.new_("v", v)));}
public static void PubVals(GfoEvMgrOwner pub, String pubEvt, KeyVal... ary) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, ary));}
public static void PubMsg(GfoEvMgrOwner pub, GfsCtx ctx, String pubEvt, GfoMsg m) {pub.EvMgr().Pub(ctx, pubEvt, m);}
public static void Lnk(GfoEvMgrOwner pub, GfoEvMgrOwner sub) {sub.EvMgr().Lnk(pub);}
public static void RlsPub(GfoEvMgrOwner pub) {pub.EvMgr().RlsPub(pub);}
public static void RlsSub(GfoEvMgrOwner sub) {sub.EvMgr().RlsSub(sub);}
static GfoMsg msg_(String evt, KeyVal... kvAry) {
GfoMsg m = GfoMsg_.new_cast_(evt);
for (int i = 0; i < kvAry.length; i++) {
KeyVal kv = kvAry[i];
m.Add(kv.Key(), kv.Val());
}
return m;
}
}

View File

@@ -0,0 +1,69 @@
/*
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;
import org.junit.*;
public class GfoEvMgr_tst {
@Before public void setup() {
pub = make_(); sub = make_();
} MockEvObj pub, sub;
@Test public void Basic() {
GfoEvMgr_.SubSame(pub, "ev1", sub);
GfoEvMgr_.PubVal(pub, "ev1", "val1");
sub.tst_Handled("val1");
}
@Test public void None() {// make sure no subscribers does not cause exception
GfoEvMgr_.SubSame(pub, "ev1", sub);
GfoEvMgr_.PubVal(pub, "ev2", "val1"); //ev2 does not exist
sub.tst_Handled();
}
@Test public void Lnk() {
MockEvObj mid = make_();
mid.EvMgr().Lnk(pub);
GfoEvMgr_.SubSame(mid, "ev1", sub);
GfoEvMgr_.PubVal(pub, "ev1", "val1");
sub.tst_Handled("val1");
}
@Test public void RlsSub() {
this.Basic();
GfoEvMgr_.RlsSub(sub);
GfoEvMgr_.PubVal(pub, "ev1", "val1");
sub.tst_Handled();
}
@Test public void RlsPub() {
this.Basic();
GfoEvMgr_.RlsSub(pub);
GfoEvMgr_.PubVal(pub, "ev1", "val1");
sub.tst_Handled();
}
MockEvObj make_() {return new MockEvObj();}
}
class MockEvObj implements GfoEvObj {
public GfoEvMgr EvMgr() {return eventMgr;} GfoEvMgr eventMgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
handled.Add(m.ReadStr("v"));
return this;
}
List_adp handled = List_adp_.new_();
public void tst_Handled(String... expd) {
Tfds.Eq_ary_str(expd, handled.To_str_ary());
handled.Clear();
}
public MockEvObj(){eventMgr = GfoEvMgr.new_(this);}
}

View File

@@ -0,0 +1,19 @@
/*
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;
public interface GfoEvObj extends GfoInvkAble, GfoEvMgrOwner {}

View 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;
public interface GfoInvkAble {
Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m);
}
/*
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) {}
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_set = "set";
*/

View File

@@ -0,0 +1,35 @@
/*
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;
public class GfoInvkAbleCmd {
private GfoMsg m;
public GfoInvkAble InvkAble() {return invkAble;} private GfoInvkAble invkAble;
public String Cmd() {return cmd;} private String cmd;
public Object Arg() {return arg;} private Object arg;
public Object Invk() {
return invkAble.Invk(GfsCtx.Instance, 0, cmd, m);
}
public static final GfoInvkAbleCmd Null = new GfoInvkAbleCmd();
public static GfoInvkAbleCmd new_(GfoInvkAble invkAble, String cmd) {return arg_(invkAble, cmd, null);}
public static GfoInvkAbleCmd arg_(GfoInvkAble invkAble, String cmd, Object arg) {
GfoInvkAbleCmd rv = new GfoInvkAbleCmd();
rv.invkAble = invkAble; rv.cmd = cmd; rv.arg = arg;
rv.m = (arg == null) ? GfoMsg_.Null : GfoMsg_.new_parse_(cmd).Add("v", arg);
return rv;
} GfoInvkAbleCmd() {}
}

View File

@@ -0,0 +1,37 @@
/*
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;
import gplx.core.primitives.*;
public class GfoInvkAble_ {
public static GfoInvkAble as_(Object obj) {return obj instanceof GfoInvkAble ? (GfoInvkAble)obj : null;}
public static GfoInvkAble cast(Object obj) {try {return (GfoInvkAble)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfoInvkAble.class, obj);}}
public static final String_obj_val Rv_unhandled = String_obj_val.new_("Unhandled"), Rv_handled = String_obj_val.new_("Handled"), Rv_host = String_obj_val.new_("Host")
, Rv_cancel = String_obj_val.new_("Cancel"), Rv_error = String_obj_val.new_("Error");
public static Object InvkCmd(GfoInvkAble invk, String k) {return InvkCmd_msg(invk, k, GfoMsg_.Null);}
public static Object InvkCmd_val(GfoInvkAble invk, String k, Object v) {return InvkCmd_msg(invk, k, GfoMsg_.new_cast_(k).Add("v", v));}
public static Object InvkCmd_msg(GfoInvkAble invk, String k, GfoMsg m) {
Object rv = invk.Invk(GfsCtx.Instance, 0, k, m);
if (rv == GfoInvkAble_.Rv_unhandled) throw Err_.new_wo_type("invkable did not handle message", "key", k);
return rv;
}
public static final GfoInvkAble Null = new GfoInvkAble_null();
}
class GfoInvkAble_null implements GfoInvkAble {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
}

View File

@@ -0,0 +1,68 @@
/*
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;
import gplx.core.primitives.*;
public class GfoInvkCmdMgr {
public GfoInvkCmdMgr Add_cmd_many(GfoInvkAble invk, String... keys) {
for (String key : keys)
list.Add(GfoInvkCmdItm.new_(key, invk));
return this;
}
public GfoInvkCmdMgr Add_cmd(String key, GfoInvkAble invk) {
list.Add(GfoInvkCmdItm.new_(key, invk));
return this;
}
public GfoInvkCmdMgr Add_mgr(String key, GfoInvkAble invk) {
list.Add(GfoInvkCmdItm.new_(key, invk).Type_isMgr_(true));
return this;
}
public GfoInvkCmdMgr Add_xtn(GfoInvkAble xtn) {
list.Add(GfoInvkCmdItm.new_("xtn", xtn).Type_isXtn_(true));
return this;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m, Object host) {
for (int i = 0; i < list.Count(); i++) {
GfoInvkCmdItm itm = (GfoInvkCmdItm)list.Get_at(i);
if (itm.Type_isXtn()) {
Object invkVal = itm.Invk().Invk(ctx, ikey, k, m);
if (invkVal != GfoInvkAble_.Rv_unhandled) return invkVal;
}
if (!ctx.Match(k, itm.Key())) continue;
if (itm.Type_isMgr()) return itm.Invk();
Object rv = null;
m.Add("host", host);
rv = itm.Invk().Invk(ctx, ikey, k, m);
return rv == GfoInvkAble_.Rv_host ? host : rv; // if returning "this" return host
}
return Unhandled;
}
public static final String_obj_val Unhandled = String_obj_val.new_("GfoInvkCmdMgr Unhandled");
List_adp list = List_adp_.new_();
public static GfoInvkCmdMgr new_() {return new GfoInvkCmdMgr();} GfoInvkCmdMgr() {}
}
class GfoInvkCmdItm {
public String Key() {return key;} private String key;
public GfoInvkAble Invk() {return invk;} GfoInvkAble invk;
public boolean Type_isMgr() {return type_isMgr;} public GfoInvkCmdItm Type_isMgr_(boolean v) {type_isMgr = v; return this;} private boolean type_isMgr;
public boolean Type_isXtn() {return type_isXtn;} public GfoInvkCmdItm Type_isXtn_(boolean v) {type_isXtn = v; return this;} private boolean type_isXtn;
public static GfoInvkCmdItm new_(String key, GfoInvkAble invk) {
GfoInvkCmdItm rv = new GfoInvkCmdItm();
rv.key = key; rv.invk = invk;
return rv;
} GfoInvkCmdItm() {}
}

View 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;
public interface GfoInvkCmdMgrOwner {
GfoInvkCmdMgr InvkMgr();
}

View 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;
public interface GfoInvkRootWkr {
Object Run_str_for(GfoInvkAble invk, GfoMsg msg);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.langs.gfs.*;
public class GfoInvkXtoStr {
public static GfoMsg ReadMsg(GfoInvkAble invk, String k) {
GfsCtx ctx = GfsCtx.wtr_();
GfoMsg m = GfoMsg_.rdr_(k);
invk.Invk(ctx, 0, k, m);
String invkKey = GfsCore.Instance.FetchKey(invk);
GfoMsg root = GfoMsg_.new_cast_(invkKey);
root.Subs_add(m);
return root;
}
public static GfoMsg WriteMsg(GfoInvkAble invk, String k, Object... ary) {return WriteMsg(GfsCore.Instance.FetchKey(invk), invk, k, ary);}
public static GfoMsg WriteMsg(String invkKey, GfoInvkAble invk, String k, Object... ary) {
GfsCtx ctx = GfsCtx.wtr_();
GfoMsg m = GfoMsg_.wtr_();
invk.Invk(ctx, 0, k, m);
GfoMsg rv = GfoMsg_.new_cast_(k);
for (int i = 0; i < m.Args_count(); i++) {
KeyVal kv = m.Args_getAt(i);
rv.Add(kv.Key(), ary[i]);
}
GfoMsg root = GfoMsg_.new_cast_(invkKey);
root.Subs_add(rv);
return root;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.interfaces.*;
public interface GfoMsg {
String Key();
GfoMsg CloneNew();
String To_str();
GfoMsg Clear();
GfoMsg Parse_(boolean v);
int Args_count();
KeyVal Args_getAt(int i);
GfoMsg Args_ovr(String k, Object v);
void Args_reset();
GfoMsg Add(String k, Object v);
int Subs_count();
GfoMsg Subs_getAt(int i);
GfoMsg Subs_add(GfoMsg m);
GfoMsg Subs_(GfoMsg... ary);
boolean ReadBool(String k);
boolean ReadBoolOr(String k, boolean or);
boolean ReadBoolOrFalse(String k);
boolean ReadBoolOrTrue(String k);
int ReadInt(String k);
int ReadIntOr(String k, int or);
long ReadLong(String k);
long ReadLongOr(String k, long or);
float ReadFloat(String k);
float ReadFloatOr(String k, float or);
double ReadDouble(String k);
double ReadDoubleOr(String k, double or);
DateAdp ReadDate(String k);
DateAdp ReadDateOr(String k, DateAdp or);
Decimal_adp ReadDecimal(String k);
Decimal_adp ReadDecimalOr(String k, Decimal_adp or);
String ReadStr(String k);
String ReadStrOr(String k, String or);
Io_url ReadIoUrl(String k);
Io_url ReadIoUrlOr(String k, Io_url url);
boolean ReadYn(String k);
boolean ReadYn_toggle(String k, boolean cur);
boolean ReadYnOrY(String k);
byte ReadByte(String k);
byte[] ReadBry(String k);
byte[] ReadBryOr(String k, byte[] or);
Object ReadObj(String k);
Object ReadObj(String k, ParseAble parseAble);
Object ReadObjOr(String k, ParseAble parseAble, Object or);
String[]ReadStrAry(String k, String spr);
String[]ReadStrAryIgnore(String k, String spr, String ignore);
byte[][]ReadBryAry(String k, byte spr);
Object ReadValAt(int i);
Object CastObj(String k);
Object CastObjOr(String k, Object or);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class GfoMsgUtl {
public static int SetInt(GfsCtx ctx, GfoMsg m, int cur) {return ctx.Deny() ? cur : m.ReadIntOr("v", cur);}
public static boolean SetBool(GfsCtx ctx, GfoMsg m, boolean cur) {return ctx.Deny() ? cur : m.ReadBoolOr("v", cur);}
public static String SetStr(GfsCtx ctx, GfoMsg m, String cur) {return ctx.Deny() ? cur : m.ReadStrOr("v", cur);}
public static Io_url SetIoUrl(GfsCtx ctx, GfoMsg m, Io_url cur) {return ctx.Deny() ? cur : m.ReadIoUrlOr("v", cur);}
public static Decimal_adp SetDecimal(GfsCtx ctx, GfoMsg m, Decimal_adp cur) {return ctx.Deny() ? cur : m.ReadDecimalOr("v", cur);}
}

View File

@@ -0,0 +1,270 @@
/*
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;
import gplx.core.primitives.*; import gplx.core.strings.*; import gplx.core.brys.*; import gplx.core.interfaces.*;
public class GfoMsg_ {
public static GfoMsg as_(Object obj) {return obj instanceof GfoMsg ? (GfoMsg)obj : null;}
public static final GfoMsg Null = new GfoMsg_base().ctor_("<<NULL MSG>>", false);
public static GfoMsg new_parse_(String key) {return new GfoMsg_base().ctor_(key, true);}
public static GfoMsg new_cast_(String key) {return new GfoMsg_base().ctor_(key, false);}
public static GfoMsg srl_(GfoMsg owner, String key) {
GfoMsg rv = new_parse_(key);
owner.Subs_add(rv);
return rv;
}
public static GfoMsg root_(String... ary) {return root_leafArgs_(ary);}
public static GfoMsg root_leafArgs_(String[] ary, KeyVal... kvAry) {
int len = Array_.Len(ary); if (len == 0) throw Err_.new_invalid_arg("== 0", "@len", len);
GfoMsg root = new GfoMsg_base().ctor_(ary[0], false);
GfoMsg owner = root;
for (int i = 1; i < len; i++) {
String key = ary[i];
GfoMsg cur = new GfoMsg_base().ctor_(key, false);
owner.Subs_add(cur);
owner = cur;
}
for (int i = 0; i < kvAry.length; i++) {
KeyVal kv = kvAry[i];
owner.Add(kv.Key(), kv.Val());
}
return root;
}
public static GfoMsg chain_(GfoMsg owner, String key) {
GfoMsg sub = owner;
List_adp list = List_adp_.new_();
list.Add(sub.Key());
while (sub != null) {
if (sub.Subs_count() == 0) break;
sub = (GfoMsg)sub.Subs_getAt(0);
list.Add(sub.Key());
}
list.Add(key);
GfoMsg root = GfoMsg_.new_parse_((String)list.Get_at(0));
GfoMsg cur = root;
for (int i = 1; i < list.Count(); i++) {
String k = (String)list.Get_at(i);
GfoMsg mm = GfoMsg_.new_parse_(k);
cur.Subs_add(mm);
cur = mm;
}
return root;
}
public static GfoMsg wtr_() {return new GfoMsg_wtr().ctor_("", false);}
public static GfoMsg rdr_(String cmd) {return new GfoMsg_rdr().ctor_(cmd, false);}
public static GfoMsg basic_(String cmd, Object... vals) {
GfoMsg rv = new_cast_(cmd);
int len = vals.length;
for (int i = 0; i < len; i++)
rv.Add("", vals[i]);
return rv;
}
}
class GfoMsg_wtr extends GfoMsg_base {
@Override protected Object ReadOr(String k, Object defaultOr) {
if (args == null) args = List_adp_.new_();
args.Add(KeyVal_.new_(k, null));
return defaultOr;
}
}
class GfoMsg_rdr extends GfoMsg_base {
@Override protected Object ReadOr(String k, Object defaultOr) {
if (args == null) args = List_adp_.new_();
args.Add(KeyVal_.new_(k, defaultOr));
return defaultOr;
}
}
class GfoMsg_base implements GfoMsg {
public String Key() {return key;} private String key;
public int Subs_count() {return subs == null ? 0 : subs.Count();}
public GfoMsg Subs_getAt(int i) {return subs == null ? null : (GfoMsg)subs.Get_at(i);}
public GfoMsg Subs_add(GfoMsg m) {if (subs == null) subs = List_adp_.new_(); subs.Add(m); return this;}
public GfoMsg Subs_(GfoMsg... ary) {for (GfoMsg m : ary) Subs_add(m); return this;}
public int Args_count() {return args == null ? 0 : args.Count();}
public void Args_reset() {
counter = 0;
Args_reset(this);
}
public GfoMsg Clear() {
this.Args_reset();
if (subs != null) subs.Clear();
if (args != null) args.Clear();
return this;
}
static void Args_reset(GfoMsg owner) {
int len = owner.Subs_count();
for (int i = 0; i < len; i++) {
GfoMsg sub = owner.Subs_getAt(i);
sub.Args_reset();
}
}
public KeyVal Args_getAt(int i) {return args == null ? null : (KeyVal)args.Get_at(i);}
public GfoMsg Args_ovr(String k, Object v) {
if (args == null) args = List_adp_.new_();
for (int i = 0; i < args.Count(); i++) {
KeyVal kv = (KeyVal)args.Get_at(i);
if (String_.Eq(k, kv.Key())) {
kv.Val_(v);
return this;
}
}
args.Add(KeyVal_.new_(k, v));
return this;
}
public GfoMsg Parse_(boolean v) {parse = v; return this;}
public GfoMsg Add(String k, Object v) {
if (args == null) args = List_adp_.new_();
args.Add(KeyVal_.new_(k, v));
return this;
}
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Bool_.cast(rv);}
public int ReadInt(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Int_.parse((String)rv) : Int_.cast(rv);}
public byte ReadByte(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Byte_.parse((String)rv) : Byte_.cast(rv);}
public long ReadLong(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
public float ReadFloat(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Float_.parse((String)rv) : Float_.cast(rv);}
public double ReadDouble(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Double_.parse((String)rv) : Double_.cast(rv);}
public Decimal_adp ReadDecimal(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Decimal_adp_.parse((String)rv) : Decimal_adp_.cast(rv);}
public String ReadStr(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return (String)rv;}
public DateAdp ReadDate(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
public Io_url ReadIoUrl(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
public Object CastObj(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return rv;}
public boolean ReadBoolOr(String k, boolean or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Yn.parse_or((String)rv, or) : Bool_.cast(rv);}
public int ReadIntOr(String k, int or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Int_.parse((String)rv) : Int_.cast(rv);}
public long ReadLongOr(String k, long or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
public float ReadFloatOr(String k, float or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Float_.parse((String)rv) : Float_.cast(rv);}
public double ReadDoubleOr(String k,double or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Double_.parse((String)rv) : Double_.cast(rv);}
public Decimal_adp ReadDecimalOr(String k,Decimal_adp or) {Object rv = ReadOr(k, or); if (rv == Nil) return or ; return parse ? Decimal_adp_.parse((String)rv) : Decimal_adp_.cast(rv);}
public String ReadStrOr(String k, String or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return (String)rv;}
public DateAdp ReadDateOr(String k, DateAdp or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
public Io_url ReadIoUrlOr(String k, Io_url or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
public boolean ReadBoolOrFalse(String k) {Object rv = ReadOr(k,false); if (rv == Nil) return false ; return parse ? Yn.parse_or((String)rv, false) : Bool_.cast(rv);}
public boolean ReadBoolOrTrue(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.cast(rv);}
public boolean ReadYnOrY(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.cast(rv);}
public boolean ReadYn(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Yn.coerce_(rv);}
public boolean ReadYn_toggle(String k, boolean cur) {
Object rv = ReadOr(k, "!");
if (rv == Nil) ThrowNotFound(k);
if (!parse) throw Err_.new_wo_type("only parse supported");
String rv_str = (String)rv;
return (String_.Eq(rv_str, "!")) ? !cur : Yn.parse(rv_str);
}
public byte[] ReadBry(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Bry_.new_u8((String)rv) : (byte[])rv;}
public byte[] ReadBryOr(String k, byte[] or) {Object rv = ReadOr(k, or); if (rv == Nil) return or; return parse ? Bry_.new_u8((String)rv) : (byte[])rv;}
public Object CastObjOr(String k, Object or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return rv;}
public Object ReadObj(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return rv;}
public Object ReadObj(String k, ParseAble parseAble) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? parseAble.ParseAsObj((String)rv) : rv;}
public Object ReadObjOr(String k, ParseAble parseAble, Object or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? parseAble.ParseAsObj((String)rv) : rv;}
public String[] ReadStrAry(String k, String spr) {return String_.Split(ReadStr(k), spr);}
public byte[][] ReadBryAry(String k, byte spr) {return Bry_split_.Split(ReadBry(k), spr);}
public String[] ReadStrAryIgnore(String k, String spr, String ignore) {return String_.Split(String_.Replace(ReadStr(k), ignore, ""), spr);}
public Object ReadValAt(int i) {return Args_getAt(i).Val();}
@gplx.Virtual protected Object ReadOr(String k, Object defaultOr) {
if (args == null) return Nil; // WORKAROUND.gfui: args null for DataBndr_whenEvt_execCmd
if (!String_.Eq(k, "")) {
for (int i = 0; i < args.Count(); i++) {
KeyVal kv = (KeyVal)args.Get_at(i);
if (String_.Eq(k, kv.Key())) return kv.Val();
}
}
if (counter >= args.Count()) return Nil;
for (int i = 0; i < args.Count(); i++) {
KeyVal kv = (KeyVal)args.Get_at(i);
if (String_.Eq(kv.Key(), "") && i >= counter) {
counter++;
return kv.Val();
}
}
return Nil;
} int counter = 0;
void ThrowNotFound(String k) {throw Err_.new_wo_type("arg not found in msg", "k", k, "counter", counter, "args", args);}
String ArgsXtoStr() {
if (this.Args_count() == 0) return "<<EMPTY>>";
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < this.Args_count(); i++) {
KeyVal rv = (KeyVal)this.Args_getAt(i);
sb.Add_fmt("{0};", rv.Key());
}
return sb.To_str();
}
public GfoMsg CloneNew() {
GfoMsg_base rv = new GfoMsg_base().ctor_(key, parse);
if (args != null) {
rv.args = List_adp_.new_();
for (int i = 0; i < args.Count(); i++)
rv.args.Add(args.Get_at(i));
}
if (subs != null) {
rv.subs = List_adp_.new_();
for (int i = 0; i < args.Count(); i++) {
GfoMsg sub = (GfoMsg)args.Get_at(i);
rv.subs.Add(sub.CloneNew()); // NOTE: recursion
}
}
return rv;
}
protected List_adp args;
List_adp subs;
public String To_str() {
String_bldr sb = String_bldr_.new_();
To_str(sb, new XtoStrWkr_gplx(), this);
return sb.To_str_and_clear();
}
void To_str(String_bldr sb, XtoStrWkr wkr, GfoMsg m) {
sb.Add(m.Key());
if (m.Subs_count() == 0) {
sb.Add(":");
boolean first = true;
for (int i = 0; i < m.Args_count(); i++) {
KeyVal kv = m.Args_getAt(i);
if (kv.Val() == null) continue;
if (!first) sb.Add(" ");
sb.Add(kv.Key());
sb.Add("='");
sb.Add(wkr.To_str(kv.Val()));
sb.Add("'");
first = false;
}
sb.Add(";");
}
else {
sb.Add(".");
To_str(sb, wkr, m.Subs_getAt(0));
}
}
public GfoMsg_base ctor_(String key, boolean parse) {this.key = key; this.parse = parse; return this;} private boolean parse;
@gplx.Internal protected GfoMsg_base(){}
static final String_obj_val Nil = String_obj_val.new_("<<NOT FOUND>>");
}
interface XtoStrWkr {
String To_str(Object o);
}
class XtoStrWkr_gplx implements XtoStrWkr {
public String To_str(Object o) {
if (o == null) return "<<NULL>>";
Class<?> type = Type_adp_.ClassOf_obj(o);
String rv = null;
if (type == String.class) rv = String_.cast(o);
else if (Int_.TypeMatch(type)) return Int_.To_str(Int_.cast(o));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) return Yn.To_str(Bool_.cast(o));
else if (type == DateAdp.class) return DateAdp_.cast(o).XtoStr_gplx();
else rv = Object_.Xto_str_strict_or_empty(o);
return String_.Replace(rv, "'", "''");
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*; import gplx.langs.gfs.*;
public class GfoMsg_tst {
@Before public void setup() {
GfsCore.Instance.AddObj(new Mok(), "Mok");
}
@Test public void Write1() {
GfoMsg m = GfoMsg_.root_leafArgs_(String_.Ary("a", "b"), KeyVal_.new_("int0", 1));
tst_Msg(m, "a.b:int0='1';");
}
@Test public void Write() {
Mok mok = new Mok();
tst_Msg(GfoInvkXtoStr.WriteMsg(mok, Mok.Invk_Cmd0, true, 1, "a"), "Mok.Cmd0:bool0='y' int0='1' str0='a';");
mok.Int0 = 2;
mok.Bool0 = true;
mok.Str0 = "b";
tst_Msg(GfoInvkXtoStr.ReadMsg(mok, Mok.Invk_Cmd0), "Mok.Cmd0:bool0='y' int0='2' str0='b';");
}
void tst_Msg(GfoMsg m, String expd) {Tfds.Eq(expd, m.To_str());}
class Mok implements GfoInvkAble {
public boolean Bool0;
public int Int0;
public String Str0;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Cmd0)) {
Bool0 = m.ReadBoolOr("bool0", Bool0);
Int0 = m.ReadIntOr("int0", Int0);
Str0 = m.ReadStrOr("str0", Str0);
if (ctx.Deny()) return this;
}
return this;
} public static final String Invk_Cmd0 = "Cmd0";
}
}

View 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;
public interface GfoTemplate {
Object NewCopy(GfoTemplate template);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class GfoTemplateFactory implements GfoInvkAble {
public void Reg(String key, GfoTemplate template) {hash.Add(key, template);}
public Object Make(String key) {
GfoTemplate template = (GfoTemplate)hash.Get_by(key);
return template.NewCopy(template);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
ctx.Match(k, k);
Object o = hash.Get_by(k);
return o == null ? GfoInvkAble_.Rv_unhandled : o;
}
public static final GfoTemplateFactory Instance = new GfoTemplateFactory(); GfoTemplateFactory() {}
Hash_adp hash = Hash_adp_.new_();
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Gfo_log_bfr {
private Bry_bfr bfr = Bry_bfr.reset_(255);
public Gfo_log_bfr Add(String s) {
bfr.Add_str_a7(DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff());
bfr.Add_byte_space();
bfr.Add_str_u8(s);
bfr.Add_byte_nl();
return this;
}
public String Xto_str() {return bfr.To_str_and_clear();}
}

View File

@@ -0,0 +1,35 @@
/*
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;
public interface Gfo_usr_dlg extends Cancelable {
void Canceled_y_(); void Canceled_n_();
Gfo_usr_dlg__log Log_wkr(); void Log_wkr_(Gfo_usr_dlg__log v);
Gfo_usr_dlg__gui Gui_wkr(); void Gui_wkr_(Gfo_usr_dlg__gui v);
String Log_many(String grp_key, String msg_key, String fmt, Object... args);
String Warn_many(String grp_key, String msg_key, String fmt, Object... args);
Err Fail_many(String grp_key, String msg_key, String fmt, Object... args);
String Prog_many(String grp_key, String msg_key, String fmt, Object... args);
String Prog_none(String grp_key, String msg_key, String fmt);
String Note_many(String grp_key, String msg_key, String fmt, Object... args);
String Note_none(String grp_key, String msg_key, String fmt);
String Note_gui_none(String grp_key, String msg_key, String fmt);
String Prog_one(String grp_key, String msg_key, String fmt, Object arg);
String Prog_direct(String msg);
String Log_direct(String msg);
String Plog_many(String grp_key, String msg_key, String fmt, Object... args);
}

View File

@@ -0,0 +1,74 @@
/*
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;
public class Gfo_usr_dlg_ {
private static Gfo_usr_dlg_base test__list, test__show;
public static Gfo_usr_dlg Instance = Gfo_usr_dlg_noop.Instance; // NOTE: global instance which can be reassigned
public static final Gfo_usr_dlg Noop = Gfo_usr_dlg_noop.Instance;
public static Gfo_usr_dlg__gui Test__list__init() {
if (test__list == null)
test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
Gfo_usr_dlg__gui_.Test.Clear();
Instance = test__list;
return Gfo_usr_dlg__gui_.Test;
}
public static String Test__list__term__get_1st() {
Instance = Noop;
String[] rv = ((Gfo_usr_dlg__gui_test)test__list.Gui_wkr()).Warns().To_str_ary_and_clear();
return rv.length == 0 ? "" : rv[0];
}
public static void Test__show__init() {
if (test__show == null)
test__show = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console);
Instance = test__show;
}
public static void Test__show__term() {
Instance = Noop;
}
public static Gfo_usr_dlg Test() {
if (test__list == null)
test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
return test__list;
}
public static Gfo_usr_dlg Test_console() {
if (test_console == null)
test_console = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Console);
return test_console;
} private static Gfo_usr_dlg_base test_console;
}
class Gfo_usr_dlg_noop implements Gfo_usr_dlg {
public boolean Canceled() {return false;} public void Canceled_y_() {} public void Canceled_n_() {}
public void Cancel() {} public void Cancel_reset() {}
public void Clear() {}
public Gfo_usr_dlg__log Log_wkr() {return Gfo_usr_dlg__log_.Noop;} public void Log_wkr_(Gfo_usr_dlg__log v) {}
public Gfo_usr_dlg__gui Gui_wkr() {return Gfo_usr_dlg__gui_.Noop;} public void Gui_wkr_(Gfo_usr_dlg__gui v) {}
public String Log_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public String Warn_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public Err Fail_many(String grp_key, String msg_key, String fmt, Object... args) {return Err_.new_wo_type(fmt);}
public String Prog_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public String Prog_none(String grp_key, String msg_key, String fmt) {return "";}
public String Note_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public String Note_none(String grp_key, String msg_key, String fmt) {return "";}
public String Note_gui_none(String grp_key, String msg_key, String fmt) {return "";}
public String Prog_one(String grp_key, String msg_key, String fmt, Object arg) {return "";}
public String Prog_direct(String msg) {return "";}
public String Log_direct(String msg) {return "";}
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public static final Gfo_usr_dlg_noop Instance = new Gfo_usr_dlg_noop(); Gfo_usr_dlg_noop() {}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*;
public interface Gfo_usr_dlg__gui {
void Clear();
String_ring Prog_msgs();
void Write_prog(String text);
void Write_note(String text);
void Write_warn(String text);
void Write_stop(String text);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.consoles.*; import gplx.core.strings.*;
public class Gfo_usr_dlg__gui_ {
public static final Gfo_usr_dlg__gui Noop = new Gfo_usr_dlg__gui_noop();
public static final Gfo_usr_dlg__gui Console = new Gfo_usr_dlg__gui_console();
public static final Gfo_usr_dlg__gui Test = new Gfo_usr_dlg__gui_test();
}
class Gfo_usr_dlg__gui_noop implements Gfo_usr_dlg__gui {
public void Clear() {}
public String_ring Prog_msgs() {return ring;} String_ring ring = new String_ring().Max_(0);
public void Write_prog(String text) {}
public void Write_note(String text) {}
public void Write_warn(String text) {}
public void Write_stop(String text) {}
}
class Gfo_usr_dlg__gui_console implements Gfo_usr_dlg__gui {
private final Console_adp__sys console = Console_adp__sys.Instance;
public void Clear() {}
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
public void Write_prog(String text) {console.Write_tmp(text);}
public void Write_note(String text) {console.Write_str_w_nl(text);}
public void Write_warn(String text) {console.Write_str_w_nl(text);}
public void Write_stop(String text) {console.Write_str_w_nl(text);}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*;
public class Gfo_usr_dlg__gui_test implements Gfo_usr_dlg__gui {
public List_adp Warns() {return warns;} private final List_adp warns = List_adp_.new_();
public List_adp Msgs() {return msgs;} private final List_adp msgs = List_adp_.new_();
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
public void Clear() {msgs.Clear(); warns.Clear();}
public void Write_prog(String text) {msgs.Add(text);}
public void Write_note(String text) {msgs.Add(text);}
public void Write_warn(String text) {warns.Add(text);}
public void Write_stop(String text) {msgs.Add(text);}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface Gfo_usr_dlg__log extends GfoInvkAble {
boolean Enabled(); void Enabled_(boolean v);
boolean Queue_enabled(); void Queue_enabled_(boolean v);
Io_url Log_dir(); void Log_dir_(Io_url v);
Io_url Session_dir();
Io_url Session_fil();
void Log_msg_to_url_fmt(Io_url url, String fmt, Object... args);
void Log_to_session(String txt);
void Log_to_session_fmt(String fmt, Object... args);
void Log_to_session_direct(String txt);
void Log_to_err(String txt);
void Log_term();
}

View File

@@ -0,0 +1,35 @@
/*
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;
public class Gfo_usr_dlg__log_ {
public static final Gfo_usr_dlg__log Noop = new Gfo_usr_dlg__log_noop();
}
class Gfo_usr_dlg__log_noop implements Gfo_usr_dlg__log {
public Io_url Session_fil() {return Io_url_.Empty;}
public Io_url Session_dir() {return Io_url_.Empty;}
public Io_url Log_dir() {return Io_url_.Empty;} public void Log_dir_(Io_url v) {}
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public boolean Queue_enabled() {return queue_enabled;} public void Queue_enabled_(boolean v) {queue_enabled = v;} private boolean queue_enabled;
public void Log_msg_to_url_fmt(Io_url url, String fmt, Object... args) {}
public void Log_to_session_fmt(String fmt, Object... args) {}
public void Log_to_session(String txt) {}
public void Log_to_session_direct(String txt) {}
public void Log_to_err(String txt) {}
public void Log_term() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
}

View File

@@ -0,0 +1,123 @@
/*
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;
import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.brys.fmtrs.*;
public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
private int archive_dirs_max = 8;
private Io_url log_dir, err_fil;
private Ordered_hash queued_list = Ordered_hash_.New();
private Bry_fmtr fmtr = Bry_fmtr.tmp_(); private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public boolean Queue_enabled() {return queue_enabled;} public void Queue_enabled_(boolean v) {queue_enabled = v; if (!v) this.Flush();} private boolean queue_enabled;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public Io_url Session_dir() {return session_dir;} private Io_url session_dir;
public Io_url Session_fil() {return session_fil;} private Io_url session_fil;
private void Flush() {
int queued_len = queued_list.Count();
for (int i = 0; i < queued_len; i++) {
Usr_log_fil fil = (Usr_log_fil)queued_list.Get_at(i);
if (fil.Url() == null) {
fil.Url_(session_dir.GenSubFil("session.txt"));
}
fil.Flush();
}
}
public Io_url Log_dir() {return log_dir;}
public void Log_dir_(Io_url log_dir) {
this.log_dir = log_dir;
session_dir = log_dir.GenSubDir(Dir_name_current);
session_fil = session_dir.GenSubFil("session.txt");
err_fil = session_dir.GenSubFil("err.txt");
}
public void Log_term() {
if (!enabled) return;
Io_url[] archive_dirs = Io_mgr.Instance.QueryDir_args(log_dir).DirInclude_().DirOnly_().ExecAsUrlAry();
int archive_dirs_len = archive_dirs.length;
int session_cutoff = archive_dirs_len - archive_dirs_max;
for (int i = 0; i < session_cutoff; i++) {
Io_url archive_dir = archive_dirs[i];
Io_mgr.Instance.DeleteDirDeep(archive_dir);
this.Log_to_session("archive dir del: " + session_dir.Raw());
}
this.Log_to_session("app term");
MoveCurrentToArchive(session_dir);
}
private void MoveCurrentToArchive(Io_url dir) {Io_mgr.Instance.MoveDirDeep(dir, dir.OwnerDir().GenSubDir(DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss_fff()));}
public void Log_info(boolean warn, String s) {if (warn) Log_to_err(s); else Log_to_session(s);}
public void Log_msg_to_url_fmt(Io_url url, String fmt, Object... args) {
if (!enabled) return;
String msg = Bld_msg(String_.new_u8(fmtr.Fmt_(fmt).Bld_bry_many(tmp_bfr, args)));
Log_msg(url, msg);
Log_msg(session_fil, msg);
}
public void Log_to_session_fmt(String fmt, Object... args) {Log_to_session(String_.new_u8(fmtr.Fmt_(fmt).Bld_bry_many(tmp_bfr, args)));}
public void Log_to_session(String s) {
if (!enabled) return;
String line = Bld_msg(s);
Log_msg(session_fil, line);
}
public void Log_to_session_direct(String s) {
if (!enabled) return;
Log_msg(session_fil, s);
}
public void Log_to_err(String s) {
if (!enabled) return;
try {
String line = Bld_msg(s);
Log_msg(session_fil, line);
Log_msg(err_fil, line);
}
catch (Exception e) {Err_.Noop(e);} // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors
} private String_bldr sb = String_bldr_.new_thread(); // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread
private String Bld_msg(String s) {return sb.Add(DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().To_str_and_clear();}
private void Log_msg(Io_url url, String txt) {
if (queue_enabled) {
String url_raw = url == null ? "mem" : url.Raw();
Usr_log_fil fil = (Usr_log_fil)queued_list.Get_by(url_raw);
if (fil == null) {
fil = new Usr_log_fil(url);
queued_list.Add(url_raw, fil);
}
fil.Add(txt);
}
else
Io_mgr.Instance.AppendFilStr(url, txt);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_archive_dirs_max_)) archive_dirs_max = m.ReadInt("v");
else if (ctx.Match(k, Invk_log_dir_)) log_dir = m.ReadIoUrl("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_enabled_ = "enabled_", Invk_archive_dirs_max_ = "archive_dirs_max_", Invk_log_dir_ = "log_dir_";
static final String Dir_name_log = "log", Dir_name_current = "current";
public static final Gfo_usr_dlg__log_base Instance = new Gfo_usr_dlg__log_base();
}
class Usr_log_fil {
public Usr_log_fil(Io_url url) {this.url = url;}
public Io_url Url() {return url;} public Usr_log_fil Url_(Io_url v) {url = v; return this;} Io_url url;
public void Add(String text) {sb.Add(text);} String_bldr sb = String_bldr_.new_();
public void Flush() {
if (sb.Count() == 0) return;
try {
Io_mgr.Instance.AppendFilStr(url, sb.To_str_and_clear());
}
catch (Exception e) {
Console_adp__sys.Instance.Write_str_w_nl(Err_.Message_gplx_full(e));
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.brys.fmtrs.*;
public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false); // do not fail b/c msgs may contain excerpt of random text; EX:[[User:A|~A~]] DATE:2014-11-28
public Gfo_usr_dlg_base(Gfo_usr_dlg__log log_wkr, Gfo_usr_dlg__gui gui_wkr) {this.log_wkr = log_wkr; this.gui_wkr = gui_wkr;}
public Gfo_usr_dlg__log Log_wkr() {return log_wkr;} public void Log_wkr_(Gfo_usr_dlg__log v) {log_wkr = v;} private Gfo_usr_dlg__log log_wkr;
public Gfo_usr_dlg__gui Gui_wkr() {return gui_wkr;} public void Gui_wkr_(Gfo_usr_dlg__gui v) {gui_wkr = v;} private Gfo_usr_dlg__gui gui_wkr;
public boolean Canceled() {return canceled;} public void Canceled_y_() {canceled = true;} public void Canceled_n_() {canceled = false;} private boolean canceled;
public void Cancel() {canceled = true;} public void Cancel_reset() {canceled = false;}
public String Log_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wkr.Log_to_session(rv); return rv;}
public String Warn_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wkr.Log_to_err(rv); gui_wkr.Write_warn(rv); return rv;}
public String Prog_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); gui_wkr.Write_prog(rv); return rv;}
public String Prog_one(String grp_key, String msg_key, String fmt, Object arg) {String rv = Bld_msg_one (grp_key, msg_key, fmt, arg ); gui_wkr.Write_prog(rv); return rv;}
public String Prog_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); gui_wkr.Write_prog(rv); return rv;}
public String Prog_direct(String msg) { gui_wkr.Write_prog(msg); return msg;}
public String Log_direct(String msg) { log_wkr.Log_to_session(msg); return msg;}
public String Note_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wkr.Log_to_session(rv); gui_wkr.Write_note(rv); return rv;}
public String Note_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); log_wkr.Log_to_session(rv); gui_wkr.Write_note(rv); return rv;}
public String Note_gui_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); gui_wkr.Write_note(rv); return rv;}
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {
String rv = Log_many(grp_key, msg_key, fmt, args);
return Prog_direct(rv);
}
public Err Fail_many(String grp_key, String msg_key, String fmt, Object... args) {
Err rv = Err_.new_wo_type(Bld_msg_many(grp_key, msg_key, fmt, args));
log_wkr.Log_to_err(rv.To_str__full());
return rv;
}
private String Bld_msg_many(String grp_key, String msg_key, String fmt, Object[] args) {
tmp_fmtr.Fmt_(fmt).Bld_bfr_many(tmp_bfr, args);
return tmp_bfr.To_str_and_clear();
}
private String Bld_msg_one(String grp_key, String msg_key, String fmt, Object val) {
tmp_fmtr.Fmt_(fmt).Bld_bfr_one(tmp_bfr, val);
return tmp_bfr.To_str_and_clear();
}
private String Bld_msg_none(String grp_key, String msg_key, String fmt) {return fmt;}
}

View File

@@ -43,7 +43,7 @@ public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_
}
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_byte_int(byte key, int val) {this.Add_base(Bry_.new_bytes(key), Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(new byte[]{key}, Int_obj_val.new_(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_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;}

View File

@@ -0,0 +1,19 @@
/*
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;
public @interface Internal {}

View File

@@ -0,0 +1,19 @@
/*
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;
public @interface New {}

View File

@@ -0,0 +1,99 @@
/*
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;
import gplx.core.strings.*;
import gplx.core.lists.*;
public class TfdsTstr_fxt {
public TfdsTstr_fxt Eq_str(Object expd, Object actl, String name) {
int nameLen = String_.Len(name); if (nameLen > nameLenMax) nameLenMax = nameLen;
TfdsTstrItm itm = TfdsTstrItm.new_().Expd_(expd).Actl_(actl).Name_(name);
list.Add(itm);
return this;
}
public void SubName_push(String s) {
stack.Push(s);
TfdsTstrItm itm = TfdsTstrItm.new_();
itm.SubName_make(stack);
itm.TypeOf = 1;
list.Add(itm);
} StackAdp stack = StackAdp_.new_();
public void Fail() {
manualFail = true;
}boolean manualFail = false;
public int List_Max(List_adp expd, List_adp actl) {return Math_.Max(expd.Count(), actl.Count());}
public int List_Max(String[] expd, String[] actl) {return Math_.Max(expd.length, actl.length);}
public Object List_FetchAtOrNull(List_adp l, int i) {return (i >= l.Count()) ? null : l.Get_at(i);}
public void SubName_pop() {stack.Pop();}
int nameLenMax = 0;
public void tst_Equal(String hdr) {
boolean pass = true;
for (int i = 0; i < list.Count(); i++) {
TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i);
if (!itm.Compare()) pass = false; // don't break early; Compare all vals
}
if (pass && !manualFail) return;
String_bldr sb = String_bldr_.new_();
sb.Add_char_crlf();
sb.Add_str_w_crlf(hdr);
for (int i = 0; i < list.Count(); i++) {
TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i);
if (itm.TypeOf == 1) {
sb.Add_fmt_line(" /{0}", itm.SubName());
continue;
}
boolean hasError = itm.CompareResult() != TfdsTstrItm.CompareResult_eq;
String errorKey = hasError ? "*" : " ";
sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd(itm.Name(), nameLenMax, " "), itm.Expd());
if (hasError)
sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd("", nameLenMax, " "), itm.Actl());
}
sb.Add(String_.Repeat("_", 80));
throw Err_.new_wo_type(sb.To_str());
}
List_adp list = List_adp_.new_();
public static TfdsTstr_fxt new_() {return new TfdsTstr_fxt();} TfdsTstr_fxt() {}
}
class TfdsTstrItm {
public String Name() {return name;} public TfdsTstrItm Name_(String val) {name = val; return this;} private String name;
public Object Expd() {return expd;} public TfdsTstrItm Expd_(Object val) {expd = val; return this;} Object expd;
public Object Actl() {return actl;} public TfdsTstrItm Actl_(Object val) {actl = val; return this;} Object actl;
public String SubName() {return subName;} private String subName = "";
public int TypeOf;
public void SubName_make(StackAdp stack) {
if (stack.Count() == 0) return;
List_adp list = stack.XtoList();
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < list.Count(); i++) {
if (i != 0) sb.Add(".");
sb.Add((String)list.Get_at(i));
}
subName = sb.To_str();
}
public int CompareResult() {return compareResult;} public TfdsTstrItm CompareResult_(int val) {compareResult = val; return this;} int compareResult;
public boolean Compare() {
boolean eq = Object_.Eq(expd, actl);
compareResult = eq ? 1 : 0;
return eq;
}
public String CompareSym() {
return compareResult == 1 ? "==" : "!=";
}
public static TfdsTstrItm new_() {return new TfdsTstrItm();} TfdsTstrItm() {}
public static final int CompareResult_none = 0, CompareResult_eq = 1, CompareResult_eqn = 2;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class UsrDlg {
public int Verbosity() {return verbosity;} public UsrDlg Verbosity_(int v) {verbosity = v; return this;} int verbosity = UsrMsgWkr_.Type_Note;
public void Note(String text, Object... ary) {Exec(text, ary, noteWkrs);}
public void Warn(String text, Object... ary) {Exec(text, ary, warnWkrs);}
public void Stop(String text, Object... ary) {Exec(text, ary, stopWkrs);}
public void Note(UsrMsg msg) {Exec(UsrMsgWkr_.Type_Note, msg);}
public void Warn(UsrMsg msg) {Exec(UsrMsgWkr_.Type_Warn, msg);}
public void Stop(UsrMsg msg) {Exec(UsrMsgWkr_.Type_Stop, msg);}
public void Exec(int type, UsrMsg umsg) {
UsrMsgWkrList list = GetList(type);
list.Exec(umsg);
}
void Exec(String text, Object[] ary, UsrMsgWkrList list) {
String msg = String_.Format(text, ary);
list.Exec(UsrMsg.new_(msg));
}
public void Reg(int type, UsrMsgWkr wkr) {
UsrMsgWkrList list = GetList(type);
list.Add(wkr);
}
public void RegOff(int type, UsrMsgWkr wkr) {
UsrMsgWkrList list = GetList(type);
list.Del(wkr);
}
UsrMsgWkrList GetList(int type) {
if (type == UsrMsgWkr_.Type_Note) return noteWkrs;
else if (type == UsrMsgWkr_.Type_Warn) return warnWkrs;
else if (type == UsrMsgWkr_.Type_Stop) return stopWkrs;
else throw Err_.new_unhandled(type);
}
UsrMsgWkrList noteWkrs = new UsrMsgWkrList(UsrMsgWkr_.Type_Note), warnWkrs = new UsrMsgWkrList(UsrMsgWkr_.Type_Warn), stopWkrs = new UsrMsgWkrList(UsrMsgWkr_.Type_Stop);
public static UsrDlg new_() {return new UsrDlg();}
}

View 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;
public class UsrDlg_ {
public static final UsrDlg Instance = UsrDlg.new_();
}

View File

@@ -0,0 +1,68 @@
/*
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;
import gplx.core.strings.*; import gplx.core.envs.*;
public class UsrMsg {
public int VisibilityDuration() {return visibilityDuration;} public UsrMsg VisibilityDuration_(int v) {visibilityDuration = v; return this;} int visibilityDuration = 3000;
public String Hdr() {return hdr;} public UsrMsg Hdr_(String val) {hdr = val; return this;} private String hdr;
public Ordered_hash Args() {return args;} Ordered_hash args = Ordered_hash_.New();
public UsrMsg Add(String k, Object v) {
args.Add(k, KeyVal_.new_(k, v));
return this;
}
public UsrMsg Add_if_dupe_use_nth(String k, Object v) {
args.Add_if_dupe_use_nth(k, KeyVal_.new_(k, v));
return this;
}
public String XtoStrSingleLine() {return To_str(" ");}
public String To_str() {return To_str(Op_sys.Cur().Nl_str());}
String To_str(String spr) {
if (hdr == null) {
GfoMsg m = GfoMsg_.new_cast_(cmd);
for (int i = 0; i < args.Count(); i++) {
KeyVal kv = (KeyVal)args.Get_at(i);
m.Add(kv.Key(), kv.Val());
}
return Object_.Xto_str_strict_or_null_mark(invk.Invk(GfsCtx.Instance, 0, cmd, m));
}
String_bldr sb = String_bldr_.new_();
sb.Add(hdr).Add(spr);
for (int i = 0; i < args.Count(); i++) {
KeyVal kv = (KeyVal)args.Get_at(i);
sb.Add_spr_unless_first("", " ", i);
sb.Add_fmt("{0}={1}", kv.Key(), kv.Val(), spr);
}
return sb.To_str();
}
public static UsrMsg fmt_(String hdr, Object... ary) {
UsrMsg rv = new UsrMsg();
rv.hdr = String_.Format(hdr, ary);
return rv;
} UsrMsg() {}
public static UsrMsg new_(String hdr) {
UsrMsg rv = new UsrMsg();
rv.hdr = hdr;
return rv;
}
public static UsrMsg invk_(GfoInvkAble invk, String cmd) {
UsrMsg rv = new UsrMsg();
rv.invk = invk;
rv.cmd = cmd;
return rv;
} GfoInvkAble invk; String cmd;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface UsrMsgWkr {
void ExecUsrMsg(int type, UsrMsg umsg);
}
class UsrMsgWkrList {
public void Add(UsrMsgWkr v) {
if (wkr == null && list == null)
wkr = v;
else {
if (list == null) {
list = List_adp_.new_();
list.Add(wkr);
wkr = null;
}
list.Add(v);
}
}
public void Del(UsrMsgWkr v) {
// list.Del(v);
}
public void Exec(UsrMsg umsg) {
if (wkr != null)
wkr.ExecUsrMsg(type, umsg);
else if (list != null) {
for (Object lObj : list) {
UsrMsgWkr l = (UsrMsgWkr)lObj;
l.ExecUsrMsg(type, umsg);
}
}
}
List_adp list; UsrMsgWkr wkr; int type;
public UsrMsgWkrList(int type) {this.type = type;}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class UsrMsgWkr_ {
public static final int
Type_None = 0
, Type_Stop = 1
, Type_Warn = 2
, Type_Note = 4
, Type_Log = 8
;
}

View File

@@ -0,0 +1,35 @@
/*
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;
import gplx.core.consoles.*;
public class UsrMsgWkr_console implements UsrMsgWkr {
public void ExecUsrMsg(int type, UsrMsg umsg) {
String text = umsg.To_str();
if (type == UsrMsgWkr_.Type_Warn)
text = "!!!!" + text;
else if (type == UsrMsgWkr_.Type_Stop)
text = "****" + text;
Console_adp__sys.Instance.Write_str(text);
}
public static void RegAll(UsrDlg dlg) {
UsrMsgWkr wkr = new UsrMsgWkr_console();
dlg.Reg(UsrMsgWkr_.Type_Note, wkr);
dlg.Reg(UsrMsgWkr_.Type_Stop, wkr);
dlg.Reg(UsrMsgWkr_.Type_Warn, wkr);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx;
public class UsrMsgWkr_test implements UsrMsgWkr {
public void ExecUsrMsg(int type, UsrMsg m) {
msgs.Add(m);
}
public boolean HasWarn(UsrMsg um) {
for (int i = 0; i < msgs.Count(); i++) {
UsrMsg found = (UsrMsg)msgs.Get_at(i);
if (String_.Eq(um.To_str(), found.To_str())) return true;
}
return false;
}
public static UsrMsgWkr_test RegAll(UsrDlg dlg) {
UsrMsgWkr_test wkr = new UsrMsgWkr_test();
dlg.Reg(UsrMsgWkr_.Type_Note, wkr);
dlg.Reg(UsrMsgWkr_.Type_Stop, wkr);
dlg.Reg(UsrMsgWkr_.Type_Warn, wkr);
return wkr;
}
List_adp msgs = List_adp_.new_();
}

View File

@@ -0,0 +1,19 @@
/*
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;
public @interface Virtual {}

View File

@@ -17,7 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public interface Bfr_arg {
void Bfr_arg__clear();
boolean Bfr_arg__exists();
void Bfr_arg__add(Bry_bfr bfr);
}

View File

@@ -20,18 +20,16 @@ import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*;
public class Bfr_arg_ {
public static Bfr_arg__int New_int(int v) {return new Bfr_arg__int(v);}
public static Bfr_arg__byte New_byte(byte v) {return new Bfr_arg__byte(v);}
public static Bfr_arg__bry New_bry(String v) {return new Bfr_arg__bry(Bry_.new_u8(v));}
public static Bfr_arg__bry New_bry(byte[] v) {return new Bfr_arg__bry(v);}
public static Bfr_arg__bry New_bry(String v) {return Bfr_arg__bry.New(Bry_.new_u8(v));}
public static Bfr_arg__bry New_bry(byte[] v) {return Bfr_arg__bry.New(v);}
public static Bfr_arg__bry_fmtr New_bry_fmtr__null() {return new Bfr_arg__bry_fmtr(null, null);}
public static Bfr_arg__bry_fmtr New_bry_fmtr(Bry_fmtr v, Bfr_arg... arg_ary) {return new Bfr_arg__bry_fmtr(v, arg_ary);}
public static final Bfr_arg Noop = new Bfr_arg___noop();
public static void Clear(Bfr_arg... ary) {
for (Bfr_arg arg : ary)
public static void Clear(Bfr_arg_clearable... ary) {
for (Bfr_arg_clearable arg : ary)
arg.Bfr_arg__clear();
}
}
class Bfr_arg___noop implements gplx.core.brys.Bfr_arg {
public void Bfr_arg__clear() {}
public boolean Bfr_arg__exists() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {}
}

View File

@@ -16,8 +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.core.brys; import gplx.*; import gplx.core.*;
public abstract class Bfr_arg_base implements Bfr_arg {
@gplx.Virtual public void Bfr_arg__clear() {}
@gplx.Virtual public boolean Bfr_arg__exists() {return true;}
public abstract void Bfr_arg__add(Bry_bfr bfr);
public interface Bfr_arg_clearable extends Bfr_arg {
void Bfr_arg__clear();
boolean Bfr_arg__missing();
}

View File

@@ -16,9 +16,28 @@ 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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__bry extends gplx.core.brys.Bfr_arg_base {
private byte[] bry;
public Bfr_arg__bry(byte[] v) {this.bry = v;}
public void Set(byte[] v) {this.bry = v;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add(bry);}
public class Bfr_arg__bry implements Bfr_arg_clearable {
private int tid;
private byte[] src; private int src_bgn, src_end;
private Bfr_arg arg;
public void Set_by_mid(byte[] src, int bgn, int end) {this.tid = Tid_mid; this.src = src; this.src_bgn = bgn; this.src_end = end;}
public void Set_by_val(byte[] src) {this.tid = Tid_val; this.src = src;}
public void Set_by_arg(Bfr_arg arg) {this.tid = Tid_arg; this.arg = arg;}
public void Bfr_arg__clear() {
tid = Tid_nil;
src = null; src_bgn = src_end = -1;
arg = null;
}
public boolean Bfr_arg__missing() {return tid == Tid_nil;}
public void Bfr_arg__add(Bry_bfr bfr) {
switch (tid) {
case Tid_val: bfr.Add(src); break;
case Tid_mid: bfr.Add_mid(src, src_bgn, src_end); break;
case Tid_arg: arg.Bfr_arg__add(bfr); break;
case Tid_nil: break;
}
}
public static Bfr_arg__bry New_empty() {return new Bfr_arg__bry();}
public static Bfr_arg__bry New(byte[] v) {Bfr_arg__bry rv = new Bfr_arg__bry(); rv.Set_by_val(v); return rv;}
private static final int Tid_nil = 0, Tid_val = 1, Tid_mid = 2, Tid_arg = 3;
}

View File

@@ -16,10 +16,10 @@ 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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__bry_ary extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__bry_ary implements Bfr_arg {
private byte[][] bry_ary;
public Bfr_arg__bry_ary Set(byte[][] v) {this.bry_ary = v; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public Bfr_arg__bry_ary Set(byte[]... v) {this.bry_ary = v; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
for (byte[] bry : bry_ary)
bfr.Add(bry);
}

View File

@@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import gplx.core.brys.fmtrs.*;
public class Bfr_arg__bry_fmtr extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__bry_fmtr implements Bfr_arg {
private Bry_fmtr fmtr; private Object[] arg_ary;
public Bfr_arg__bry_fmtr(Bry_fmtr fmtr, Object[] arg_ary) {Set(fmtr, arg_ary);}
public Bfr_arg__bry_fmtr Set(Bry_fmtr fmtr, Object... arg_ary) {
this.fmtr = fmtr; this.arg_ary = arg_ary;
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
}

View File

@@ -16,8 +16,8 @@ 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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__byte extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__byte implements Bfr_arg {
private final byte byt;
public Bfr_arg__byte(byte byt) {this.byt = byt;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
}

View File

@@ -16,10 +16,10 @@ 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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__decimal_int extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__decimal_int implements Bfr_arg {
public int Val() {return val;} public Bfr_arg__decimal_int Val_(int v) {val = v; return this;} int val;
public Bfr_arg__decimal_int Places_(int v) {places = v; multiple = (int)Math_.Pow(10, v); return this;} int multiple = 1000, places = 3;
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_int_variable(val / multiple).Add_byte(Byte_ascii.Dot).Add_int_fixed(val % multiple, places);
}
}

View File

@@ -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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__int implements Bfr_arg {
private int val, val_digits;
public Bfr_arg__int(int v) {Set(v);}
public Bfr_arg__int Set(int v) {
@@ -24,5 +24,5 @@ public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
this.val_digits = Int_.DigitCount(val);
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
}

View File

@@ -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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__time implements Bfr_arg {
public Bfr_arg__time() {
units_len = units.length;
}
@@ -30,7 +30,7 @@ public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
int[] units = new int[] {86400, 3600, 60, 1};
int units_len;
byte[] spr = new byte[] {Byte_ascii.Space};
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
if (seconds == 0) { // handle 0 separately (since it will always be < than units[*]
bfr.Add_int_fixed(0, 2).Add(segs[units_len - 1]);
return;

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_fmt_arg {
public Bfr_fmt_arg(byte[] key, Bfr_arg arg) {this.Key = key; this.Arg = arg;}
public byte[] Key;
public Bfr_arg Arg;
public static final Bfr_fmt_arg[] Ary_empty = new Bfr_fmt_arg[0];
}

View File

@@ -0,0 +1,71 @@
/*
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bry_fmt {
private byte[] src;
private Bry_fmt_itm[] itms; private int itms_len;
private Bfr_fmt_arg[] args = Bfr_fmt_arg.Ary_empty;
private byte[][] keys = Bry_.Ary_empty;
private boolean dirty;
public Bry_fmt(byte[] src, byte[][] keys, Bfr_fmt_arg[] args) {
dirty = true;
this.src = src; this.keys = keys; this.args = args;
}
public Bry_fmt Fmt_(String v) {dirty = true; src = Bry_.new_u8(v); return this;}
public Bry_fmt Args_(Bfr_fmt_arg... v) {dirty = true; args = v; return this;}
public Bry_fmt Keys_(byte[]... v) {dirty = true; keys = v; return this;}
public void Bld_bfr_many(Bry_bfr bfr, Object... vals) {
if (dirty) Compile();
int vals_len = vals.length;
for (int i = 0; i < itms_len; ++i) {
Bry_fmt_itm itm = itms[i];
switch (itm.Tid) {
case Bry_fmt_itm.Tid__txt: bfr.Add_mid(src, itm.Src_bgn, itm.Src_end); break;
case Bry_fmt_itm.Tid__arg: itm.Arg.Bfr_arg__add(bfr);break;
case Bry_fmt_itm.Tid__key:
int idx = itm.Key_idx;
if (idx > -1 && idx < vals_len)
bfr.Add_obj(vals[idx]);
else
bfr.Add_mid(src, itm.Src_bgn, itm.Src_end);
break;
default: throw Err_.new_unhandled(itm.Tid);
}
}
}
private void Compile() {
dirty = false;
this.itms = Bry_fmt_parser_.Parse(Byte_ascii.Tilde, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end, args, keys, src);
this.itms_len = itms.length;
}
public static Bry_fmt New(String fmt, String... keys) {return new Bry_fmt(Bry_.new_u8(fmt), Bry_.Ary(keys), Bfr_fmt_arg.Ary_empty);}
}
class Bry_fmt_itm {
public Bry_fmt_itm(int tid, int src_bgn, int src_end) {
this.Tid = tid;
this.Src_bgn = src_bgn;
this.Src_end = src_end;
}
public int Tid;
public int Src_bgn;
public int Src_end;
public int Key_idx;
public Bfr_arg Arg;
public static final int Tid__txt = 0, Tid__key = 1, Tid__arg = 2;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
class Bry_fmt_parser_ {
public static Bry_fmt_itm[] Parse(byte escape, byte grp_bgn, byte grp_end, Bfr_fmt_arg[] args, byte[][] keys, byte[] src) {
int src_len = src.length;
int pos = 0;
int txt_bgn = -1;
int key_idx = -1;
Hash_adp_bry keys_hash = Hash_adp_bry.cs();
List_adp list = List_adp_.new_();
while (true) {
boolean is_last = pos == src_len;
byte b = is_last ? escape : src[pos];
if (b == escape) {
if (txt_bgn != -1) list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, txt_bgn, pos));
if (is_last) break;
++pos;
if (pos == src_len) throw Err_.new_("bry_fmtr", "fmt cannot end with escape", "escape", Byte_ascii.To_str(escape), "raw", src);
b = src[pos];
if (b == escape) {
list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, pos, pos + 1));
++pos;
}
else if (b == grp_bgn) {
++pos;
int grp_end_pos = Bry_find_.Find_fwd(src, grp_end, pos); if (grp_end_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmtr", "grp_end missing", "grp_bgn", Byte_ascii.To_str(grp_bgn), "grp_end", Byte_ascii.To_str(grp_end), "raw", src);
byte[] key_bry = Bry_.Mid(src, pos, grp_end_pos);
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by_bry(key_bry);
if (key_itm == null) {
key_itm = new Bry_fmt_itm(Bry_fmt_itm.Tid__key, pos - 2, grp_end_pos + 1); // -2 to get "~{"; +1 to get "}"
key_itm.Key_idx = ++key_idx;
keys_hash.Add(key_bry, key_itm);
}
list.Add(key_itm);
pos = grp_end_pos + 1;
}
else throw Err_.new_("bry_fmtr", "escape must be followed by escape or group_bgn", "escape", Byte_ascii.To_str(escape), "group_bgn", Byte_ascii.To_str(escape), "raw", src);
txt_bgn = -1;
}
else {
if (txt_bgn == -1) txt_bgn = pos;
++pos;
}
}
Bry_fmt_itm[] rv = (Bry_fmt_itm[])list.To_ary_and_clear(Bry_fmt_itm.class);
int len = args.length;
for (int i = 0; i < len; ++i) {
Bfr_fmt_arg arg = args[i];
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(arg.Key); if (key_itm == null) continue;
key_itm.Tid = Bry_fmt_itm.Tid__arg;
key_itm.Arg = arg.Arg;
}
len = keys.length;
for (int i = 0; i < len; ++i) {
byte[] key = keys[i];
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(key); if (key_itm == null) throw Err_.new_("bry_fmtr", "could not find key", "key", key);
key_itm.Key_idx = i;
}
return rv;
}
}

View File

@@ -0,0 +1,52 @@
/*
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bry_fmt_tst {
private final Bry_fmt_fxt fxt = new Bry_fmt_fxt();
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Vals("a").Test("a");}
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Vals("a", "b").Test("ab");}
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Vals("a").Test("aa");}
@Test public void Key__missing() {fxt.Clear().Fmt("~{key}").Test("~{key}");}
@Test public void Tilde() {fxt.Clear().Fmt("~~~~").Test("~~");}
@Test public void Simple() {fxt.Clear().Fmt("0~{key1}1~{key2}2").Vals(".", ",").Test("0.1,2");}
@Test public void Arg() {fxt.Clear().Fmt("~{custom}").Args("custom", new Bfr_fmt_arg_mok(123)).Test("123");}
@Test public void Keys() {fxt.Clear().Fmt("~{b}~{c}~{a}").Keys("a", "b", "c").Vals("a", "b", "c").Test("bca");}
}
class Bfr_fmt_arg_mok implements Bfr_arg {
private int num;
public Bfr_fmt_arg_mok(int num) {this.num = num;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_int_variable(num);
}
}
class Bry_fmt_fxt {
private final Bry_fmt fmt = new Bry_fmt(Bry_.Empty, Bry_.Ary_empty, Bfr_fmt_arg.Ary_empty);
private final Bry_bfr bfr = Bry_bfr.new_();
private Object[] vals;
public Bry_fmt_fxt Clear() {vals = Object_.Ary_empty; return this;}
public Bry_fmt_fxt Fmt(String s) {fmt.Fmt_(s); return this;}
public Bry_fmt_fxt Vals(Object... vals) {this.vals = vals; return this;}
public Bry_fmt_fxt Args(String key, Bfr_arg arg) {fmt.Args_(new Bfr_fmt_arg(Bry_.new_u8(key), arg)); return this;}
public Bry_fmt_fxt Keys(String... keys) {fmt.Keys_(Bry_.Ary(keys)); return this;}
public void Test(String expd) {
fmt.Bld_bfr_many(bfr, vals);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -17,6 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bry_fmtr_itm {
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
}
public boolean Arg;
public int ArgIdx;
public byte[] Dat;
@@ -27,7 +30,4 @@ public class Bry_fmtr_itm {
public static Bry_fmtr_itm arg_(int idx) {return new Bry_fmtr_itm(true, idx, Bry_.Empty);}
public static Bry_fmtr_itm dat_(byte[] dat, int len) {return new Bry_fmtr_itm(false, -1, Bry_.Mid(dat, 0, len));}
public static Bry_fmtr_itm dat_bry_(byte[] bry) {return new Bry_fmtr_itm(false, -1, bry);}
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
}
}

View File

@@ -18,17 +18,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bry_fmtr_tst {
@Test public void Idx_text() {tst_Format("a", "a");}
@Test public void Idx_1() {tst_Format("a", "~{0}", "a");}
@Test public void Idx_3() {tst_Format("abc", "~{0}~{1}~{2}", "a", "b", "c");}
@Test public void Idx_mix() {tst_Format("abcde", "a~{0}c~{1}e", "b", "d");}
@Test public void Key_basic() {tst("~{key}" , String_.Ary("key") , ary_("a") , "a");}
@Test public void Key_mult() {tst("~{key1}~{key2}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
@Test public void Key_mix() {tst("~{key1}~{1}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
@Test public void Key_repeat() {tst("~{key1}~{key1}" , String_.Ary("key1") , ary_("a") , "aa");}
private final Bry_fmtr_fxt fxt = new Bry_fmtr_fxt();
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
@Test public void Idx__1() {fxt.Clear().Fmt("~{0}").Args("a").Test("a");}
@Test public void Idx__3() {fxt.Clear().Fmt("~{0}~{1}~{2}").Args("a", "b", "c").Test("abc");}
@Test public void Idx__mix() {fxt.Clear().Fmt("a~{0}c~{1}e").Args("b", "d").Test("abcde");}
@Test public void Idx__missing() {fxt.Clear().Fmt("~{0}").Test("~{0}");}
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Keys("key").Args("a").Test("a");}
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Keys("key1").Args("a").Test("aa");}
@Test public void Mix() {fxt.Clear().Fmt("~{key1}~{1}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Simple() {
Bry_fmtr fmtr = Bry_fmtr.new_("0~{key1}1~{key2}2", "key1", "key2");
Tfds.Eq("0.1,2", fmtr.Bld_str_many(".", ","));
fxt.Clear().Fmt("0~{key1}1~{key2}2").Keys("key1", "key2").Args(".", ",").Test("0.1,2");
}
@Test public void Cmd() {
Bry_fmtr_tst_mok mok = new Bry_fmtr_tst_mok();
@@ -37,20 +41,7 @@ public class Bry_fmtr_tst {
mok.Enabled_(true);
Tfds.Eq("01234", fmtr.Bld_str_many("1"));
}
@Test public void Err_missing_idx() {tst_Format("~{0}", "~{0}");}
String[] ary_(String... ary) {return ary;}
void tst(String fmt, String[] keys, String[] args, String expd) {
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(Bry_.new_u8(fmt));
fmtr.Keys_(keys);
String actl = fmtr.Bld_str_many(args);
Tfds.Eq(expd, actl);
}
void tst_Format(String expd, String fmt, String... args) {
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(fmt);
Tfds.Eq(expd, fmtr.Bld_str_many(args));
}
@Test public void Bld_bfr_many_and_set_fmt() {
Bry_fmtr_fxt fxt = new Bry_fmtr_fxt().Clear();
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
}
@Test public void Escape_tilde() {
@@ -64,12 +55,17 @@ class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
}
}
class Bry_fmtr_fxt {
public Bry_fmtr_fxt Clear() {
if (fmtr == null) {
fmtr = Bry_fmtr.new_();
}
return this;
} private Bry_fmtr fmtr;
private final Bry_fmtr fmtr = Bry_fmtr.new_();
private final Bry_bfr bfr = Bry_bfr.new_();
private Object[] args;
public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;}
public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;}
public Bry_fmtr_fxt Keys(String... args) {fmtr.Keys_(args); return this;}
public Bry_fmtr_fxt Args(Object... args) {this.args = args; return this;}
public void Test(String expd) {
fmtr.Bld_bfr_many(bfr, args);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
public void Bld_bfr_many_and_set_fmt(String fmt, Object[] args, String expd) {
fmtr.Fmt_(fmt);
fmtr.Bld_bfr_many_and_set_fmt(args);

View File

@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import gplx.core.brys.*;
public class Bry_fmtr_vals extends gplx.core.brys.Bfr_arg_base {
public class Bry_fmtr_vals implements Bfr_arg {
private final Bry_fmtr fmtr; private Object[] vals;
Bry_fmtr_vals(Bry_fmtr fmtr) {this.fmtr = fmtr;}
public Bry_fmtr_vals Vals_(Object... v) {this.vals = v; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_ary(bfr, vals);
}
public static Bry_fmtr_vals new_fmt(String fmt, String... keys) {

View File

@@ -41,6 +41,10 @@ public class Btrie_slim_mgr implements Btrie_mgr {
cur = nxt;
}
}
public byte Match_byte_or(byte[] src, int bgn, int end, byte or) {
Object rv_obj = Match_bgn(src, bgn, end);
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
}
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_bry_int(byte[] key, int val) {return (Btrie_slim_mgr)Add_obj(key, Int_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}

View File

@@ -59,7 +59,8 @@ public class Base85_ {
throw Err_.new_wo_type("neg number not allowed", "v", v);
}
public static final int Len_int = 5;
private static final int Pow85_last = 4, Radix = 85; private static final byte A7_offset = 33;
private static final int Pow85_last = 4, Radix = 85;
public static final byte A7_offset = 33;
public static final int Pow85_0 = 1, Pow85_1 = 85, Pow85_2 = 7225, Pow85_3 = 614125, Pow85_4 = 52200625;
public static int[] Pow85 = new int[]{Pow85_0, Pow85_1, Pow85_2, Pow85_3, Pow85_4}; // NOTE: ary constructed to match index to exponent; Pow85[1] = 85^1
}

View File

@@ -38,7 +38,7 @@ public class Utf16__tst {
class Utf16__fxt {
private Int_obj_ref hi_ref = Int_obj_ref.neg1_(), lo_ref = Int_obj_ref.neg1_();
public void Test_encode_decode(int expd_c_int, int... expd_int) {
byte[] expd = Bry_.new_ints(expd_int);
byte[] expd = Bry_.New_by_ints(expd_int);
byte[] bfr = new byte[10];
int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0);
byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len);

View File

@@ -129,6 +129,20 @@ public class IoEngine_system extends IoEngine_base {
Closeable_close(reader, url_str, false);
return sw.toString();
}
@SuppressWarnings("resource") public static byte[] Load_from_stream_as_bry(InputStream stream, String url_str) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[4096];
int read = 0;
try {
while ((read = stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, read);
}
buffer.flush();
} catch (IOException e) {
e.printStackTrace();
}
return buffer.toByteArray();
}
@Override public boolean ExistsDir(Io_url url) {return new File(url.Xto_api()).exists();}
@Override public void CreateDir(Io_url url) {new File(url.Xto_api()).mkdirs();}
@Override public void DeleteDir(Io_url url) {

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public class IoItm_fxt {
public IoItmFil fil_wnt_(String s) {return fil_(Io_url_.wnt_fil_(s));}
public IoItmFil fil_(Io_url url) {return IoItmFil_.new_(url, 1, DateAdp_.parse_gplx("2001-01-01"), DateAdp_.parse_gplx("2001-01-01"));}
public IoItmDir dir_wnt_(String s) {return dir_(Io_url_.wnt_dir_(s));}
public IoItmDir dir_(Io_url url, IoItm_base... ary) {
IoItmDir rv = IoItmDir_.top_(url);
for (IoItm_base itm : ary) {
if (itm.Type_dir())
rv.SubDirs().Add(itm);
else
rv.SubFils().Add(itm);
}
return rv;
}
public static IoItm_fxt new_() {return new IoItm_fxt();} IoItm_fxt() {}
}

View File

@@ -20,7 +20,7 @@ import org.junit.*; //using System.IO; /*Stream*/
public class IoStream_mem_tst {
@Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer
IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0);
byte[] data = Bry_.new_ints(1);
byte[] data = Bry_.New_by_ints(1);
stream.Write(data, 0, Array_.Len(data));
Tfds.Eq(1L , stream.Len());

View File

@@ -99,10 +99,10 @@ public class Io_size_ {
return val == Int_.Min_value ? cur : (val * Io_mgr.Len_mb_long);
}
}
class Io_size_fmtr_arg extends gplx.core.brys.Bfr_arg_base {
class Io_size_fmtr_arg implements Bfr_arg {
public long Val() {return val;} public Io_size_fmtr_arg Val_(long v) {val = v; return this;} long val;
public byte[] Suffix() {return suffix;} public Io_size_fmtr_arg Suffix_(byte[] v) {suffix = v; return this;} private byte[] suffix;
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
long cur = val; int pow = 0;
while (cur >= 1024) {
cur /= 1024;

View File

@@ -30,11 +30,8 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
Bry_obj_ref comp = (Bry_obj_ref)obj;
return Bry_.Match(val, val_bgn, val_end, comp.val, comp.val_bgn, comp.val_end);
}
public void Bfr_arg__clear() {val = null;}
public boolean Bfr_arg__exists() {return val != null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__exists())
bfr.Add_mid(val, val_bgn, val_end);
bfr.Add_mid(val, val_bgn, val_end);
}
public static int CalcHashCode(byte[] ary, int bgn, int end) {
int rv = 0;
@@ -44,4 +41,5 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
}
public static Bry_obj_ref New_empty() {return New(Bry_.Empty);}
public static Bry_obj_ref New(byte[] val) {return new Bry_obj_ref().Val_(val);}
public static Bry_obj_ref New(String val) {return new Bry_obj_ref().Val_(Bry_.new_u8(val));}
}