1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
This commit is contained in:
gnosygnu 2014-07-20 23:42:54 -04:00
parent bc10cd76b6
commit e882217c62
408 changed files with 3648 additions and 2687 deletions

View File

@ -50,7 +50,7 @@ abstract class String_bldr_base implements String_bldr {
public String_bldr Add_fmt_line(String format, Object... args) {Add_str_w_crlf(String_.Format(format, args)); return this;}
public String_bldr Add_kv_obj(String k, Object v) {
if (this.Count() != 0) this.Add(" ");
this.Add_fmt("{0}={1}", k, Object_.XtoStr_OrNullStr(v));
this.Add_fmt("{0}={1}", k, Object_.Xto_str_strict_or_null_mark(v));
return this;
}
public String_bldr Add_char_pipe() {return Add("|");}

View File

@ -27,7 +27,7 @@ public class Err_ { //_20110415
public static Err err_(Exception e, String fmt, Object... args) {return Err.exc_(e, String_.Format(fmt, args));}
public static Err cast_(Exception ignore, Class<?> t, Object o) {
String o_str = "";
try {o_str = Object_.XtoStr_OrNullStr(o);}
try {o_str = Object_.Xto_str_strict_or_null_mark(o);}
catch (Exception e) {Err_.Noop(e); o_str = "<ERROR>";}
return cast_manual_msg_(ignore, t, o_str);
}
@ -46,7 +46,7 @@ public class Err_ { //_20110415
return Err.hdr_("type mismatch")
.Add("expdType", ClassAdp_.FullNameOf_type(t))
.Add("actlType", ClassAdp_.NameOf_obj(o))
.Add("actlObj", Object_.XtoStr_OrNullStr(o))
.Add("actlObj", Object_.Xto_str_strict_or_null_mark(o))
;
}
public static Err missing_idx_(int idx, int len) {return Err.hdr_("index is out of bounds").Add("idx", idx).Add("len", len);}

View File

@ -20,7 +20,7 @@ public class Err_mgr {
Err_mgr(Gfo_msg_root msg_root) {this.msg_root = msg_root;} Gfo_msg_root msg_root;
public Err not_implemented_() {return Err_.new_(Msg_not_implemented.Gen_str_none());}
public Err unhandled_(Object obj) {return Err_.new_(Msg_unhandled.Gen_str_one(obj));}
public Err cast_(Exception e, Class<?> obj_class, Object obj) {return Err_.new_(Msg_cast.Gen_str_many(ClassAdp_.NameOf_type(obj_class), Object_.XtoStr_OrNullStr(obj)));}
public Err cast_(Exception e, Class<?> obj_class, Object obj) {return Err_.new_(Msg_cast.Gen_str_many(ClassAdp_.NameOf_type(obj_class), Object_.Xto_str_strict_or_null_mark(obj)));}
public Err parse_(Class<?> type , byte[] raw) {return Err_.new_(Msg_parse.Gen_str_many(ClassAdp_.NameOf_type(type), String_.new_utf8_len_safe_(raw, 0, 255)));}
public Err parse_obj_(Object o , byte[] raw) {return Err_.new_(Msg_parse.Gen_str_many(ClassAdp_.NameOf_obj(o), String_.new_utf8_len_safe_(raw, 0, 255)));}
public Err parse_(String type_name, byte[] raw) {return Err_.new_(Msg_parse.Gen_str_many(type_name, String_.new_utf8_len_safe_(raw, 0, 255)));}

View File

@ -24,7 +24,7 @@ public class SrlAble_ {
return sb.XtoStr();
}
public static String XtoStr(Object o) {
SrlAble s = SrlAble_.as_(o); if (s == null) return Object_.XtoStr_OrNullStr(o);
SrlAble s = SrlAble_.as_(o); if (s == null) return Object_.Xto_str_strict_or_null_mark(o);
GfoMsg m = GfoMsg_.new_parse_("root");
s.Srl(m);
return XtoStr(m);
@ -36,7 +36,7 @@ public class SrlAble_ {
for (int i = 0; i < owner.Args_count(); i++) {
if (i != 0) sb.Add(" ");
KeyVal kv = owner.Args_getAt(i);
sb.Add(kv.Key()).Add("=").Add("'").Add(Object_.XtoStr_OrNullStr(kv.Val())).Add("'");
sb.Add(kv.Key()).Add("=").Add("'").Add(Object_.Xto_str_strict_or_null_mark(kv.Val())).Add("'");
}
int subsCount = owner.Subs_count();
if (subsCount == 0) {

View File

@ -41,7 +41,8 @@ public class Bool_ implements GfoInvkAble {
public static final byte N_byte = 0, Y_byte = 1, __byte = 127;
public static final boolean N = false, Y = true;
public static final String N_str = "n", Y_str = "y";
public static final byte[] True_bry = Bry_.new_ascii_("true"), False_bry = Bry_.new_ascii_("false");
public static final String True_str = "true", False_str = "false";
public static final byte[] True_bry = Bry_.new_ascii_(True_str), False_bry = Bry_.new_ascii_(False_str);
public static final byte[] Y_bry = new byte[] {Byte_ascii.Ltr_y}, N_bry = new byte[] {Byte_ascii.Ltr_n};
public static final Bool_ Gfs = new Bool_();

View File

@ -75,7 +75,7 @@ public class Bry_ {
byte[][] rv = new byte[ary_len][];
for (int i = 0; i < ary_len; i++) {
Object itm = ary[i];
rv[i] = itm == null ? null : Bry_.new_utf8_(Object_.XtoStr_OrEmpty(itm));
rv[i] = itm == null ? null : Bry_.new_utf8_(Object_.Xto_str_strict_or_empty(itm));
}
return rv;
}
@ -450,6 +450,19 @@ public class Bry_ {
if (lhs[i] != rhs[i + rhs_bgn]) return false;
return true;
}
public static boolean Eq_ci_ascii(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;
int lhs_len = lhs.length;
int rhs_len = rhs_end - rhs_bgn;
if (lhs_len != rhs_len) return false;
for (int i = 0; i < lhs_len; i++) {
byte lhs_b = lhs[i]; if (lhs_b > 64 && lhs_b < 91) lhs_b += 32; // lowercase
byte rhs_b = rhs[i + rhs_bgn]; if (rhs_b > 64 && rhs_b < 91) rhs_b += 32; // lowercase
if (lhs_b != rhs_b) return false;
}
return true;
}
public static byte[] XtoStrBytesByInt(int val, int padLen) {return XtoStrBytesByInt(val, null, 0, padLen);}
public static byte[] XtoStrBytesByInt(int val, byte[] ary, int aryPos, int padLen) {
int neg = 0;
@ -481,24 +494,24 @@ public class Bry_ {
}
return ary;
}
public static byte X_to_byte_by_int(byte[] ary, int bgn, int end, byte or) {return (byte)X_to_int_or(ary, bgn, end, or);}
public static int X_to_int(byte[] ary) {return X_to_int_or(ary, null, 0, ary.length, -1);}
public static int X_to_int_or_fail(byte[] ary) {
int rv = X_to_int_or(ary, null, 0, ary.length, Int_.MinValue);
public static byte Xto_byte_by_int(byte[] ary, int bgn, int end, byte or) {return (byte)Xto_int_or(ary, bgn, end, or);}
public static int Xto_int(byte[] ary) {return Xto_int_or(ary, null, 0, ary.length, -1);}
public static int Xto_int_or_fail(byte[] ary) {
int rv = Xto_int_or(ary, null, 0, ary.length, Int_.MinValue);
if (rv == Int_.MinValue) throw Err_.new_fmt_("could not parse to int; val={0}", String_.new_utf8_(ary));
return rv;
}
public static boolean X_to_bool_by_int_or_fail(byte[] ary) {
int rv = X_to_int_or(ary, null, 0, ary.length, Int_.MinValue);
public static boolean Xto_bool_by_int_or_fail(byte[] ary) {
int rv = Xto_int_or(ary, null, 0, ary.length, Int_.MinValue);
switch (rv) {
case 0: return false;
case 1: return true;
default: throw Err_.new_fmt_("could not parse to boolean int; val={0}", String_.new_utf8_(ary));
}
}
public static int X_to_int_or(byte[] ary, int or) {return X_to_int_or(ary, null, 0, ary.length, or);}
public static int X_to_int_or(byte[] ary, int bgn, int end, int or) {return X_to_int_or(ary, null, bgn, end, or);}
public static int X_to_int_or(byte[] ary, byte[] ignore_ary, int bgn, int end, int or) {
public static int Xto_int_or(byte[] ary, int or) {return Xto_int_or(ary, null, 0, ary.length, or);}
public static int Xto_int_or(byte[] ary, int bgn, int end, int or) {return Xto_int_or(ary, null, bgn, end, or);}
public static int Xto_int_or(byte[] ary, byte[] ignore_ary, int bgn, int end, int or) {
if ( ary == null
|| end == bgn // null-len
) return or;
@ -532,7 +545,7 @@ public class Bry_ {
}
return rv;
}
public static int X_to_int_or_trim(byte[] ary, int bgn, int end, int or) { // NOTE: same as X_to_int_or, except trims ws at bgn / end; DATE:2014-02-09
public static int Xto_int_or_trim(byte[] ary, int bgn, int end, int or) { // NOTE: same as Xto_int_or, except trims ws at bgn / end; DATE:2014-02-09
if (end == bgn) return or; // null len
int rv = 0, multiple = 1;
boolean numbers_seen = false, ws_seen = false;
@ -558,7 +571,7 @@ public class Bry_ {
}
return rv;
}
public static int X_to_int_or_lax(byte[] ary, int bgn, int end, int or) {
public static int Xto_int_or_lax(byte[] ary, int bgn, int end, int or) {
if (end == bgn) return or; // null-len
int end_num = end;
for (int i = bgn; i < end; i++) {
@ -579,7 +592,7 @@ public class Bry_ {
break;
}
}
return X_to_int_or(ary, bgn, end_num, or);
return Xto_int_or(ary, bgn, end_num, or);
}
public static float XtoFloatByPos(byte[] ary, int bgn, int end) {return Float_.parse_(String_.new_utf8_(ary, bgn, end));}
public static double XtoDoubleByPosOr(byte[] ary, int bgn, int end, double or) {return Double_.parseOr_(String_.new_utf8_(ary, bgn, end), or);}
@ -655,7 +668,7 @@ public class Bry_ {
int bgn = posRef.Val();
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
if (pos == Bry_.NotFound) throw Err_.new_("lkp failed").Add("lkp", (char)lkp).Add("bgn", bgn);
int rv = Bry_.X_to_int_or(ary, posRef.Val(), pos, -1);
int rv = Bry_.Xto_int_or(ary, posRef.Val(), pos, -1);
posRef.Val_(pos + 1); // +1 = lkp.Len
return rv;
}

View File

@ -109,7 +109,7 @@ public class Bry__tst {
tst_XtoInt("", -1);
}
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.X_to_int_or(Bry_.new_utf8_(val), or));}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or(Bry_.new_utf8_(val), or));}
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.XtoIntBy4Bytes(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.XbyInt(expd), "XbyInt");}
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.zero_() , expd);}
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.new_(bgn), expd);}
@ -141,21 +141,21 @@ public class Bry__tst {
Trim_tst("a c", 1, 3, "");
Trim_tst(" ", 0, 2, "");
} void Trim_tst(String raw, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_utf8_(Bry_.Trim(Bry_.new_utf8_(raw), bgn, end)));}
@Test public void X_to_int_lax() {
tst_X_to_int_lax("12a", 12);
tst_X_to_int_lax("1", 1);
tst_X_to_int_lax("123", 123);
tst_X_to_int_lax("a", 0);
tst_X_to_int_lax("-1", -1);
@Test public void Xto_int_lax() {
tst_Xto_int_lax("12a", 12);
tst_Xto_int_lax("1", 1);
tst_Xto_int_lax("123", 123);
tst_Xto_int_lax("a", 0);
tst_Xto_int_lax("-1", -1);
}
private void tst_X_to_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.X_to_int_or_lax(Bry_.new_utf8_(val), 0, String_.Len(val), 0));}
@Test public void X_to_int_or_trim() {
tst_X_to_int_trim("123 " , 123);
tst_X_to_int_trim(" 123" , 123);
tst_X_to_int_trim(" 123 " , 123);
tst_X_to_int_trim(" 1 3 " , -1);
private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or_lax(Bry_.new_utf8_(val), 0, String_.Len(val), 0));}
@Test public void Xto_int_or_trim() {
tst_Xto_int_trim("123 " , 123);
tst_Xto_int_trim(" 123" , 123);
tst_Xto_int_trim(" 123 " , 123);
tst_Xto_int_trim(" 1 3 " , -1);
}
private void tst_X_to_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.X_to_int_or_trim(Bry_.new_utf8_(val), 0, String_.Len(val), -1));}
private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or_trim(Bry_.new_utf8_(val), 0, String_.Len(val), -1));}
@Test public void Compare() {
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same);
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less);

View File

@ -19,7 +19,7 @@ package gplx;
public class Bry_fmtr_eval_mgr_gfs implements Bry_fmtr_eval_mgr {
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public byte[] Eval(byte[] cmd) {
return enabled ? Bry_.new_utf8_(Object_.XtoStr_OrNullStr(GfsCore._.ExecText(String_.new_utf8_(cmd)))) : null;
return enabled ? Bry_.new_utf8_(Object_.Xto_str_strict_or_null_mark(GfsCore._.ExecText(String_.new_utf8_(cmd)))) : null;
}
public static final Bry_fmtr_eval_mgr_gfs _ = new Bry_fmtr_eval_mgr_gfs(); Bry_fmtr_eval_mgr_gfs() {}
}

View File

@ -41,7 +41,7 @@ public class Byte_ {
public static byte cast_(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, byte.class, o);}}
public static byte parse_(String raw) {return Byte.parseByte(raw);}
public static byte int_(int v) {return v > 127 ? (byte)(v - 256) : (byte)v;} // PERF?: (byte)(v & 0xff)
public static byte X_to_boolean_byte(boolean v) {
public static byte Xto_boolean_byte(boolean v) {
return v ? Bool_.Y_byte : Bool_.N_byte;
}
public static final byte Zero = 0, MaxValue_127 = 127;

View File

@ -56,7 +56,7 @@ public class Byte_ascii {
public static boolean Is_num(byte b) {
return b > Byte_ascii.Slash && b < Byte_ascii.Colon;
}
public static int X_to_digit(byte b) {return b - Byte_ascii.Num_0;}
public static int Xto_digit(byte b) {return b - Byte_ascii.Num_0;}
public static byte Case_upper(byte b) {
return b > 96 && b < 123
? (byte)(b - 32)

View File

@ -35,6 +35,12 @@ public class Double_ {
int v_int = (int)v;
return v - v_int == 0 ? Int_.XtoStr(v_int) : Double.toString(v);
}
public static String Xto_str_loose(double v) {
int v_as_int = (int)v;
return v == v_as_int
? Int_.XtoStr(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
: String.format("%g", v); // call "%g" format which should eliminate most, though not all; EX:2449.6000000000004; DATE:2014-07-14
}
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.type_mismatch_exc_(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, double.class, raw);}}
public static double parseOr_(String raw, double v) {try {return Double.parseDouble(raw);} catch(Exception e) {Err_.Noop(e); return v;}}

View File

@ -151,7 +151,7 @@ public class Int_ implements GfoInvkAble {
public static int parse_(String raw) {try {return Integer.parseInt(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, int.class, raw);}}
public static int cast_(Object obj) {try {return (Integer)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, int.class, obj);}}
public static int cast_or_(Object obj, int or) {try {return (Integer)obj;} catch(Exception e) {Err_.Noop(e); return or;}}
public static int X_by_double_(double v) {return (int)v;}
public static int Xby_double_(double v) {return (int)v;}
public static String XtoStr(int v) {return new Integer(v).toString();}
public static String XtoStr_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
public static boolean TypeMatch(Class<?> type) {return type == int.class || type == Integer.class;}

View File

@ -32,7 +32,7 @@ public class Int_ary_ {
|| pos_is_last
) {
if (num_bgn == -1) return or; // empty itm; EX: "1,"; "1,,2"
int num = Bry_.X_to_int_or(src, num_bgn, num_end, Int_.MinValue);
int num = Bry_.Xto_int_or(src, num_bgn, num_end, Int_.MinValue);
if (num == Int_.MinValue) return or; // not a number; parse failed
if (rv_len == 0) { // rv not init'd
rv_len = (raw_len / 2) + 1; // default rv_len to len of String / 2; + 1 to avoid fraction rounding down
@ -77,7 +77,7 @@ public class Int_ary_ {
case Byte_ascii.Dash:
if (pos == raw_len -1) return or; // eos; EX: "1-"
if (num_bgn == -1) return or; // no rng_bgn; EX: "-2"
rng_bgn = Bry_.X_to_int_or(src, num_bgn, pos, Int_.MinValue);
rng_bgn = Bry_.Xto_int_or(src, num_bgn, pos, Int_.MinValue);
if (rng_bgn == Int_.MinValue) return or;
num_bgn = -1;
itm_is_rng = true;

View File

@ -101,7 +101,7 @@ public class Long_ {
public static long Int_merge(int hi, int lo) {return (long)hi << 32 | (lo & 0xFFFFFFFFL);}
public static int Int_split_lo(long v) {return (int)(v);}
public static int Int_split_hi(long v) {return (int)(v >> 32);}
public static long X_by_int(int v) {return (long)v;}
public static long Xby_int(int v) {return (long)v;}
}
/* alternate for Int_merge does not work in java
public static long MergeInts(int lo, int hi) {return (uint)(hi << 32) | (lo & 0xffffffff);}

View File

@ -24,13 +24,9 @@ public class Object_ {
else if (lhs == null || rhs == null) return false;
else return lhs.equals(rhs);
}
public static Object Parse(String val, String valType) {
if (String_.Eq(valType, IntClassXtn.Key_const)) return Int_.parse_(val);
else return val;
}
public static String XtoStr_OrNull(Object v) {return v == null ? null : ToString_lang(v);}
public static String XtoStr_OrNullStr(Object v) {return v == null ? String_.Null_mark : ToString_lang(v);}
public static String XtoStr_OrEmpty(Object v) {return v == null ? String_.Empty : ToString_lang(v);}
public static String Xto_str_strict_or_null(Object v) {return v == null ? null : ToString_lang(v);}
public static String Xto_str_strict_or_null_mark(Object v) {return v == null ? String_.Null_mark : ToString_lang(v);}
public static String Xto_str_strict_or_empty(Object v) {return v == null ? String_.Empty : ToString_lang(v);}
static String ToString_lang(Object v) {
if (v == null) return null;
Class<?> c = v.getClass();
@ -38,4 +34,13 @@ public class Object_ {
else if (ClassAdp_.Eq(c, String_.ClassOf)) return (String)v;
else return v.toString();
}
public static String Xto_str_loose_or(Object v, String or) { // tries to pretty-print doubles; also standardizes true/false; DATE:2014-07-14
if (v == null) return null;
Class<?> c = ClassAdp_.ClassOf_obj(v);
if (ClassAdp_.Eq(c, Bry_.ClassOf)) return String_.new_utf8_((byte[])v);
else if (ClassAdp_.Eq(c, String_.ClassOf)) return (String)v;
else if (ClassAdp_.Eq(c, Bool_.ClassOf)) return Bool_.cast_(v) ? Bool_.True_str : Bool_.False_str; // always return true / false
else if (ClassAdp_.Eq(c, Double_.ClassOf)) return Double_.Xto_str_loose(Double_.cast_(v));
else return v.toString();
}
}

View File

@ -18,10 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import org.junit.*;
public class Object__tst {
@Test public void Eq() {
tst_Eq(null, null, true); // both null
tst_Eq(5, 5, true); // both non-null
tst_Eq(5, null, false); // rhs non-null
tst_Eq(null, 5, false); // lhs non-null
} void tst_Eq(Object lhs, Object rhs, boolean expd) {Tfds.Eq(expd, Object_.Eq(lhs, rhs));}
@Before public void init() {} private Object__fxt fxt = new Object__fxt();
@Test public void Eq() {
fxt.Test_eq(null, null, true); // both null
fxt.Test_eq(5, 5, true); // both non-null
fxt.Test_eq(5, null, false); // rhs non-null
fxt.Test_eq(null, 5, false); // lhs non-null
}
@Test public void Xto_str_loose_or_null() {
fxt.Test_xto_str_loose_or_null(null, null);
fxt.Test_xto_str_loose_or_null(2449.6000000000004d, "2449.60");
}
}
class Object__fxt {
public void Test_eq(Object lhs, Object rhs, boolean expd) {Tfds.Eq(expd, Object_.Eq(lhs, rhs));}
public void Test_xto_str_loose_or_null(Object v, String expd) {Tfds.Eq(expd, Object_.Xto_str_loose_or(v, null));}
}

View File

@ -283,7 +283,7 @@ public class String_ implements GfoInvkAble {
for (int i = 0; i < aryLen; i++) {
if (i != 0) sb.Add(separator);
Object val = ary[i];
sb.Add_obj(Object_.XtoStr_OrEmpty(val));
sb.Add_obj(Object_.Xto_str_strict_or_empty(val));
}
return sb.XtoStr();
}
@ -373,7 +373,7 @@ public class String_ implements GfoInvkAble {
else if (c == bracketEnd) {
int aryIdx = Int_.parse_or_(numberStr, Int_.MinValue);
if (aryIdx != Int_.MinValue && Int_.Between(aryIdx, 0, aryLength - 1)) // check (a) aryIdx is num; (b) aryIdx is in bounds
aryVal = Object_.XtoStr_OrEmpty(ary[aryIdx]);
aryVal = Object_.Xto_str_strict_or_empty(ary[aryIdx]);
else
aryVal = String_.Concat_any(bracketBgn, numberStr, bracketEnd); // not valid, just add String
sb.Add(aryVal);

View File

@ -18,14 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class KeyVal implements XtoStrAble {
@gplx.Internal protected KeyVal(byte key_tid, Object k, Object v) {this.key_tid = key_tid; key = k; val = v;}
public String Key() {return Object_.XtoStr_OrNull(key);}
public String Key() {return Object_.Xto_str_strict_or_null(key);}
public byte Key_tid() {return key_tid;} private byte key_tid;
public Object Key_as_obj() {return key;} private Object key;
public KeyVal Key_(Object v) {this.key = v; return this;}
public Object Val() {return val;} public KeyVal Val_(Object v) {val = v; return this;} private Object val;
public String Val_to_str_or_empty() {return Object_.XtoStr_OrEmpty(val);}
public String Val_to_str_or_null() {return Object_.XtoStr_OrNull(val);}
public byte[] Val_to_bry() {return Bry_.new_utf8_(Object_.XtoStr_OrNull(val));}
public String Val_to_str_or_empty() {return Object_.Xto_str_strict_or_empty(val);}
public String Val_to_str_or_null() {return Object_.Xto_str_strict_or_null(val);}
public byte[] Val_to_bry() {return Bry_.new_utf8_(Object_.Xto_str_strict_or_null(val));}
@Override public String toString() {return XtoStr();}
public String XtoStr() {return Key() + "=" + Object_.XtoStr_OrNullStr(val);}
public String XtoStr() {return Key() + "=" + Object_.Xto_str_strict_or_null_mark(val);}
}

View File

@ -49,7 +49,7 @@ public class KeyVal_ {
if (ClassAdp_.Eq_typeSafe(itm_val, KeyVal[].class))
sb.Add(Ary_x_to_str((KeyVal[])itm_val));
else
sb.Add(Object_.XtoStr_OrNullStr(itm_val));
sb.Add(Object_.Xto_str_strict_or_null_mark(itm_val));
sb.Add_char_nl();
}
return sb.XtoStr();
@ -73,7 +73,7 @@ public class KeyVal_ {
KeyVal itm = ary[i];
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent : " "
bfr.Add_str(Object_.XtoStr_OrEmpty(itm.Key())).Add_byte_eq(); // add key + eq : "key="
bfr.Add_str(Object_.Xto_str_strict_or_empty(itm.Key())).Add_byte_eq(); // add key + eq : "key="
Object val = itm.Val();
if (val == null)
bfr.Add_str(String_.Null_mark);
@ -89,7 +89,7 @@ public class KeyVal_ {
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
else
bfr.Add_str(Object_.XtoStr_OrNullStr(val)); // call toString()
bfr.Add_str(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
}
bfr.Add_byte_nl();
}

View File

@ -46,7 +46,7 @@ public class TimeSpanAdp_ {
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
int unit_digit = Byte_ascii.X_to_digit(b);
int unit_digit = Byte_ascii.Xto_digit(b);
unit_val = (unit_multiple == 1) ? unit_digit : unit_val + (unit_digit * unit_multiple);
switch (colon_pos) {
case 0: val_s = unit_val; break;

View File

@ -39,7 +39,7 @@ public class Yn {
if (v_int == Bool_.__int) Err_mgr._.unhandled_(v);
return v_int == Bool_.Y_int;
}
public static String X_to_str(boolean v) {return v ? "y" : "n";}
public static String Xto_str(boolean v) {return v ? "y" : "n";}
public static boolean store_bool_or(SrlMgr mgr, String key, boolean or) {
String v = mgr.SrlStrOr(key, "");
return mgr.Type_rdr() ? parse_or_(v, or) : or;

View File

@ -26,7 +26,7 @@ class HashAdp_null implements HashAdp {
public int Count() {return 0;}
public boolean Has(Object key) {return false;}
public Object Fetch(Object key) {return null;}
public Object FetchOrFail(Object key) {throw Err_.missing_key_(Object_.XtoStr_OrNullStr(key));}
public Object FetchOrFail(Object key) {throw Err_.missing_key_(Object_.Xto_str_strict_or_null_mark(key));}
public Object FetchOrNew(Object key, NewAble proto) {throw Err_.new_("could not add to null hash");}
public void Add(Object key, Object val) {}
public void AddKeyVal(Object val) {}

View File

@ -119,7 +119,7 @@ public abstract class ListAdp_base implements ListAdp, GfoInvkAble {
for (int i = 0; i < count; i++) {
if (i != 0) sb.Add_char_crlf();
Object val = list[i];
sb.Add_obj(Object_.XtoStr_OrEmpty(val));
sb.Add_obj(Object_.Xto_str_strict_or_empty(val));
}
return sb.XtoStr();
}

View File

@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.texts; import gplx.*;
import org.junit.*;
public class RegxPatn_cls_like_tst {
@Test public void Basic() {
@Test public void Basic() {
tst_Match("abcd", "abcd", true); // basic; pass
tst_Match("abcd", "zbcd", false); // basic; fail
tst_Match("abcd", "abc", false); // no wildcard; must be exact match
tst_Match("a cd", "a cd", true); // check space works
}
@Test public void Wildcard() {
@Test public void Wildcard() {
tst_Match("abcd", "a%", true); // bgn; pass
tst_Match("abcd", "b%", false); // bgn; fail
tst_Match("abcd", "%d", true); // end; pass
@ -34,12 +34,12 @@ public class RegxPatn_cls_like_tst {
tst_Match("abcd", "%a%", true); // flank; bgn; pass
tst_Match("abcd", "%d%", true); // flank; end; pass
}
@Test public void Any() {
@Test public void Any() {
tst_Match("abcd", "a_cd", true); // basic; pass
tst_Match("abcd", "z_cd", false); // basic; fail
tst_Match("abcd", "a_c", false); // fail; check no wildcard
}
@Test public void CharSet() {
@Test public void CharSet() {
tst_Match("abcd", "a[b]cd", true); // pass
tst_Match("abcd", "a[x]cd", false); // fail
tst_Match("abcd", "a[bcde]cd", true); // multiple; pass
@ -47,20 +47,20 @@ public class RegxPatn_cls_like_tst {
tst_Match("abcd", "a[^z]cd", true); // not; pass
tst_Match("abcd", "a[^b]cd", false); // not; fail
}
@Test public void Escape() {
@Test public void Escape() {
tst_Match("a%b", "a|%b", true); // escape wildcard; pass
tst_Match("a%bc", "a|%b", false); // escape wildcard; fail
tst_Match("a|b", "a|b", false); // escape char; fail
tst_Match("a|b", "a||b", true); // escape char; pass
}
@Test public void Escape_diffChar() {
@Test public void Escape_diffChar() {
tst_Match("a%b", "a~%b", '~', true); // escape wildcard; pass
tst_Match("a%bc", "a~%b", '~', false); // escape wildcard; fail
tst_Match("a|b", "a|b", '~', true); // no escape needed
tst_Match("a~b", "a~b", '~', false); // escape char; fail
tst_Match("a~b", "a~~b", '~', true); // escape char; pass
}
@Test public void Chars() { // Escape RegxBldr; ex: LIKE 'a{' -> a\{
@Test public void Chars() { // Escape RegxBldr; ex: LIKE 'a{' -> a\{
tst_EscapeRegxChar(RegxBldr.Tkn_Escape); // \
tst_EscapeRegxChar(RegxBldr.Tkn_GroupBegin); // [
tst_EscapeRegxChar(RegxBldr.Tkn_GroupEnd); // ]
@ -79,8 +79,8 @@ public class RegxPatn_cls_like_tst {
Tfds.Eq(expd, actl, "raw={0} regx={1} expd={2}", raw, regx, expd);
}
void tst_EscapeRegxChar(char regexChar) {
RegxPatn_cls_like like = RegxPatn_cls_like_.parse_(Object_.XtoStr_OrEmpty(regexChar), '|');
Tfds.Eq(true, like.Matches(Object_.XtoStr_OrEmpty(regexChar)));
RegxPatn_cls_like like = RegxPatn_cls_like_.parse_(Object_.Xto_str_strict_or_empty(regexChar), '|');
Tfds.Eq(true, like.Matches(Object_.Xto_str_strict_or_empty(regexChar)));
Tfds.Eq(false, like.Matches("a")); // catches errors for improper escaping of wildcard
}
}

View File

@ -38,7 +38,7 @@ public class IoEngine_xrg_recycleFil extends IoEngine_xrg_fil_affects1_base {
for (int i = 0; i < aryLen; i++) {
if (i != 0) sb.Add(separator);
Object val = ary.FetchAt(i);
sb.Add_obj(Object_.XtoStr_OrEmpty(val));
sb.Add_obj(Object_.Xto_str_strict_or_empty(val));
}
return sb.XtoStr();
}

View File

@ -71,9 +71,9 @@ public class ProcessAdp implements GfoInvkAble, RlsAble {
default: throw Err_mgr._.unhandled_(run_mode);
}
}
public String[] X_to_process_bldr_args(String... args) {
public String[] Xto_process_bldr_args(String... args) {
String args_str = args_fmtr.Bld_str_many(args);
return X_to_process_bldr_args_utl(exe_url, args_str);
return Xto_process_bldr_args_utl(exe_url, args_str);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return enabled;
@ -209,7 +209,7 @@ public class ProcessAdp implements GfoInvkAble, RlsAble {
exit_code = Exit_init;
rslt_out = "";
WhenBgn_run();
pb = new ProcessBuilder(X_to_process_bldr_args_utl(exe_url, args_str));
pb = new ProcessBuilder(Xto_process_bldr_args_utl(exe_url, args_str));
pb.redirectErrorStream(true); // NOTE: need to redirectErrorStream or rdr.readLine() will hang; see inkscape and Ostfriesland Verkehr-de.svg
if (working_dir != null)
pb.directory(new File(working_dir.Xto_api()));
@ -259,7 +259,7 @@ public class ProcessAdp implements GfoInvkAble, RlsAble {
}
private static final String GRP_KEY = "gplx.process";
public static final int Exit_pass = 0, Exit_init = -1;
public static String[] X_to_process_bldr_args_utl(Io_url exe_url, String args_str) {
public static String[] Xto_process_bldr_args_utl(Io_url exe_url, String args_str) {
ListAdp list = ListAdp_.new_();
list.Add(exe_url.Xto_api());
String_bldr sb = String_bldr_.new_();

View File

@ -20,7 +20,7 @@ public abstract class ClassXtn_base {
public abstract Class<?> UnderClass();
public abstract Object ParseOrNull(String raw);
@gplx.Virtual public Object XtoDb(Object obj) {return obj;}
@gplx.Virtual public String XtoUi(Object obj, String fmt) {return Object_.XtoStr_OrNullStr(obj);}
@gplx.Virtual public String XtoUi(Object obj, String fmt) {return Object_.Xto_str_strict_or_null_mark(obj);}
@gplx.Virtual public boolean MatchesClass(Object obj) {if (obj == null) throw Err_.null_("obj");
return ClassAdp_.Eq_typeSafe(obj, UnderClass());
}

View File

@ -33,7 +33,7 @@ public class GfoNde implements GfoInvkAble {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < aryLen; i++) {
String key = i >= flds.Count() ? "<< NULL " + i + " >>" : flds.FetchAt(i).Key();
String val = i >= aryLen ? "<< NULL " + i + " >>" : Object_.XtoStr_OrNullStr(ary[i]);
String val = i >= aryLen ? "<< NULL " + i + " >>" : Object_.Xto_str_strict_or_null_mark(ary[i]);
sb.Add(key).Add("=").Add(val);
}
return sb.XtoStr();

View File

@ -260,9 +260,9 @@ class XtoStrWkr_gplx implements XtoStrWkr {
String rv = null;
if (type == String.class) rv = String_.cast_(o);
else if (Int_.TypeMatch(type)) return Int_.XtoStr(Int_.cast_(o));
else if (Bool_.TypeMatch(type)) return Yn.X_to_str(Bool_.cast_(o));
else if (Bool_.TypeMatch(type)) return Yn.Xto_str(Bool_.cast_(o));
else if (type == DateAdp.class) return DateAdp_.cast_(o).XtoStr_gplx();
else rv = Object_.XtoStr_OrEmpty(o);
else rv = Object_.Xto_str_strict_or_empty(o);
return String_.Replace(rv, "'", "''");
}
}

View File

@ -23,7 +23,7 @@ class XmlDataWtr extends DataWtr_base implements DataWtr {
public void InitWtr(String key, Object val) {}
@Override public void WriteData(String name, Object val) {
// if (val == null) return;
String valString = Object_.XtoStr_OrEmpty(val);
String valString = Object_.Xto_str_strict_or_empty(val);
int valStringLen = String_.Len(valString);
sb.Add(" ").Add(name).Add("=\"");
for (int i = 0; i < valStringLen; i++) {

View File

@ -190,7 +190,7 @@ class DsvDataRdr_fxt {
GfoNde row = tbl.Subs().FetchAt_asGfoNde(i);
for (int j = 0; j < row.Flds().Count(); j++) {
if (j != 0) sb.Add("~");
sb.Add_obj(Object_.XtoStr_OrNullStr(row.ReadAt(j)));
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(row.ReadAt(j)));
}
expdList.Add(sb.XtoStrAndClear());
}
@ -201,7 +201,7 @@ class DsvDataRdr_fxt {
}
for (int j = 0; j < expdRow.length; j++) {
if (j != 0) sb.Add("~");
sb.Add_obj(Object_.XtoStr_OrNullStr(expdRow[j]));
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(expdRow[j]));
}
actlList.Add(sb.XtoStrAndClear());
}

View File

@ -119,7 +119,7 @@ class GfsCore_ {
if (type == String.class) invk = String_.Gfs;
else if (Int_.TypeMatch(type)) invk = Int_.Gfs;
else if (Bool_.TypeMatch(type)) invk = Bool_.Gfs;
else throw Err_.new_("unknown primitive").Add("type", ClassAdp_.NameOf_type(type)).Add("obj", Object_.XtoStr_OrNullStr(rv));
else throw Err_.new_("unknown primitive").Add("type", ClassAdp_.NameOf_type(type)).Add("obj", Object_.Xto_str_strict_or_null_mark(rv));
primitive = rv;
}
Object exec_rv = null;

View File

@ -37,6 +37,6 @@ class GfsCoreFxt {
public void tst_MsgStr(GfoMsg msg, Object expd) {
GfsCtx ctx = GfsCtx.new_();
Object actl = core.ExecOne(ctx, msg);
Tfds.Eq(Object_.XtoStr_OrNullStr(expd), Object_.XtoStr_OrNullStr(actl));
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl));
}
}

View File

@ -37,7 +37,7 @@ public class UsrMsg {
KeyVal kv = (KeyVal)args.FetchAt(i);
m.Add(kv.Key(), kv.Val());
}
return Object_.XtoStr_OrNullStr(invk.Invk(GfsCtx._, 0, cmd, m));
return Object_.Xto_str_strict_or_null_mark(invk.Invk(GfsCtx._, 0, cmd, m));
}
String_bldr sb = String_bldr_.new_();
sb.Add(hdr).Add(spr);

View File

@ -165,13 +165,13 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
String_bldr sb = String_bldr_.new_();
int aryLen = Array_.Len(ary);
for (int i = 0; i < aryLen; i++)
sb.Add_many("'", Object_.XtoStr_OrNullStr(ary[i]), "'", " ");
sb.Add_many("'", Object_.Xto_str_strict_or_null_mark(ary[i]), "'", " ");
WriteText(sb.XtoStr() + String_.CrLf);
}
}
class TfdsEqListItmStr_cls_default implements TfdsEqListItmStr {
public String XtoStr(Object cur, Object actl) {
return Object_.XtoStr_OrNullStr(cur);
return Object_.Xto_str_strict_or_null_mark(cur);
}
public static final TfdsEqListItmStr_cls_default _ = new TfdsEqListItmStr_cls_default(); TfdsEqListItmStr_cls_default() {}
}
@ -230,7 +230,7 @@ class TfdsMsgBldr {
if (s != null) return String_.Concat("'", s, "'"); // if Object is String, put quotes around it for legibility
XtoStrAble xtoStrAble = XtoStrAble_.as_(obj);
if (xtoStrAble != null) return xtoStrAble.XtoStr();
return Object_.XtoStr_OrNullStr(obj);
return Object_.Xto_str_strict_or_null_mark(obj);
}
String WrapMsg(String text) {
return String_.Concat(String_.CrLf

View File

@ -80,7 +80,7 @@ public class GfmlDataWtr extends DataWtr_base implements DataWtr {
}
String XtoStr(Object obj) {
if (obj == null) return "''";
String s = Object_.XtoStr_OrEmpty(obj);
String s = Object_.Xto_str_strict_or_empty(obj);
return String_.Concat("'", String_.Replace(s, "'", "''"), "'");
}
GfmlTkn AddTkn_raw(String raw) {return AddTkn(raw, raw);}

View File

@ -157,7 +157,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
|| valType == Integer.class || valType == Long.class
|| valType == Float.class || valType == Double.class
)
sb.Add(Object_.XtoStr_OrNull(val));
sb.Add(Object_.Xto_str_strict_or_null(val));
else if (valType == DateAdp.class)
XtoSqlVal_DateAdp(sb, prm, (DateAdp)val);
else if (valType == DecimalAdp.class) {
@ -167,7 +167,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
// else if (valType == System.Enum.class)
// sb.Add_any(Enm_.XtoInt(val)); // save enum as 0 or 1, since (a) no db supports enum datatype; (b) names are fungible; (c) int is less space than name
else {
String valString = Object_.XtoStr_OrNull(val);
String valString = Object_.Xto_str_strict_or_null(val);
XtoSqlVal_Str(sb, prm, valString);
}
}
@ -268,7 +268,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
sb.Add(fld.Name());
sb.Add("=");
if (quote) sb.Add("'");
sb.Add(Object_.XtoStr_OrEmpty(val));
sb.Add(Object_.Xto_str_strict_or_empty(val));
if (quote) sb.Add("'");
}
sb.Add(")");

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs; import gplx.*;
public class Db_cmd_mode {
public static final byte Create = 1, Update = 2, Delete = 3, Ignore = 4;
public static byte X_to_update(byte cur) {
public static byte Xto_update(byte cur) {
switch (cur) {
case Create: // ignore update if item is already marked for create
case Delete: // ignore update if item is already marked for delete (might want to throw error)

View File

@ -66,7 +66,7 @@ class DataTypes_base_fxt {
Tfds.Eq(rdr.ReadStr("full_name"), "John Doe");
Tfds.Eq(rdr.ReadBool("is_active"), true);
Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("2006-03-30 22:22:00.000"));
Tfds.Eq(floatStr, Object_.XtoStr_OrEmpty(rdr.ReadFloat("quantity")));
Tfds.Eq(floatStr, Object_.Xto_str_strict_or_empty(rdr.ReadFloat("quantity")));
Tfds.Eq_decimal(rdr.ReadDecimal("amount"), DecimalAdp_.parts_(12, 345));
}
public void UpdateDate_hook() {

View File

@ -20,12 +20,12 @@ public class GfoNdeTstr {
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
ListAdp expd = ListAdp_.new_();
for (int i = 0; i < expdAry.length; i++) {
expd.Add(Object_.XtoStr_OrEmpty(expdAry[i]));
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
}
ListAdp actl = ListAdp_.new_();
for (int i = 0; i < nde.Subs().Count(); i++) {
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
actl.Add(Object_.XtoStr_OrEmpty(sub.Read(fld)));
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
}
Tfds.Eq_ary(expd.XtoStrAry(), actl.XtoStrAry());
}

View File

@ -220,8 +220,8 @@ public class SqliteDbMain {
byte[] orig = Bry_.new_ascii_(flds[4]);
int orig_mode = orig[0] - Byte_ascii.Num_0;
int comma_pos = Bry_finder.Find_fwd(orig, Byte_ascii.Comma);
int orig_w = Bry_.X_to_int_or(orig, 2, comma_pos, -1);
int orig_h = Bry_.X_to_int_or(orig, comma_pos + 1, orig.length, -1);
int orig_w = Bry_.Xto_int_or(orig, 2, comma_pos, -1);
int orig_h = Bry_.Xto_int_or(orig, comma_pos + 1, orig.length, -1);
stmt.setInt(4, orig_mode);
stmt.setInt(5, orig_w);
stmt.setInt(6, orig_h);

View File

@ -197,5 +197,5 @@ class CheckListItem {
public Object Data() {return data;} Object data;
public boolean Selected() {return selected;} public void Selected_set(boolean selected) {this.selected = selected;} protected boolean selected;
public void Selected_toggle() {selected = !selected;}
public String toString() {return Object_.XtoStr_OrNullStr(data);}
public String toString() {return Object_.Xto_str_strict_or_null_mark(data);}
}

View File

@ -57,7 +57,7 @@ public class GxwComboBox_lang extends JComboBox implements GxwComboBox, GxwElem,
@Override public void setBounds(Rectangle r) {super.setBounds(r); this.validate();}
@Override public void setSize(int w, int h) {super.setSize(w, h); this.validate();}
@Override public void setSize(Dimension d) {super.setSize(d); this.validate();}
public String TextVal() {return Object_.XtoStr_OrEmpty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
public String TextVal() {return Object_.Xto_str_strict_or_empty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}

View File

@ -50,7 +50,7 @@ class GxwListBox_lang extends JList implements GxwListBox {
@Override public void setBounds(Rectangle r) {super.setBounds(r); this.validate();}
@Override public void setSize(int w, int h) {super.setSize(w, h); this.validate();}
@Override public void setSize(Dimension d) {super.setSize(d); this.validate();}
public String TextVal() {return Object_.XtoStr_OrEmpty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
public String TextVal() {return Object_.Xto_str_strict_or_empty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}

View File

@ -109,7 +109,7 @@ class GfoConsoleWinCmds implements GfoInvkAble {
try {runMsg = GfsCore._.MsgParser().ParseToMsg(cmd);} catch (Exception e) {statusBox.Text_("invalid gfml " + Err_.Message_gplx(e)); return;}
GfsCtx ctx = GfsCtx.new_();
Object rv = GfsCore._.ExecMany(ctx, runMsg);
resultBox.Text_(Object_.XtoStr_OrEmpty(rv));
resultBox.Text_(Object_.Xto_str_strict_or_empty(rv));
}
void Help() {
statusBox.Text_("");
@ -122,7 +122,7 @@ class GfoConsoleWinCmds implements GfoInvkAble {
try {
Object rv = GfsCore._.ExecOne(ctx, runMsg);
if (rv != GfoInvkAble_.Rv_handled && rv != GfoInvkAble_.Rv_unhandled) {
UsrDlg_._.Note(Object_.XtoStr_OrEmpty(rv));
UsrDlg_._.Note(Object_.Xto_str_strict_or_empty(rv));
}
// Results_add(FixNewLines(ctx.Results_XtoStr()));
} catch (Exception e) {statusBox.Text_("help failed " + Err_.Message_gplx(e)); return;}

View File

@ -68,7 +68,7 @@ public class GfuiElemBase implements GfuiElem {
public GfuiElem Border_off_() {border.All_(null); return this;}
public GfxStringData TextMgr() {return textMgr;} GfxStringData textMgr;
public String Text() {return textMgr.Val();}
public GfuiElem Text_any_(Object obj) {return Text_(Object_.XtoStr_OrNullStr(obj));}
public GfuiElem Text_any_(Object obj) {return Text_(Object_.Xto_str_strict_or_null_mark(obj));}
@gplx.Virtual public GfuiElem Text_(String v) {
this.TextMgr().Text_set(v);
Click_key_set_(v);

View File

@ -36,7 +36,7 @@ public class DataBndr_whenEvt_execCmd implements InjectAble, GfoInvkAble, GfoEvO
if (ctx.Match(k, whenEvt)) {
Object evtVal = m.CastObjOr(whenArg, "");
Object getVal = getInvk.Invk(GfsCtx._, 0, getCmd, GfoMsg_.new_cast_(getCmd).Add("v", evtVal));
GfoMsg setMsg = GfoMsg_.new_cast_(setCmd).Add("v", Object_.XtoStr_OrEmpty(getVal));
GfoMsg setMsg = GfoMsg_.new_cast_(setCmd).Add("v", Object_.Xto_str_strict_or_empty(getVal));
setInvk.Invk(GfsCtx._, 0, setCmd, setMsg);
return GfoInvkAble_.Rv_handled;
}

View File

@ -29,7 +29,6 @@
<classpathentry kind="src" path="src_490_xnde"/>
<classpathentry kind="src" path="src_500_tmpl"/>
<classpathentry kind="src" path="src_510_pf_core"/>
<classpathentry kind="src" path="src_530_pf_str"/>
<classpathentry kind="src" path="xtn"/>
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>

View File

@ -30,8 +30,8 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
public byte[] Read_bry_simple() {Move_next_simple(); return Bry_.Mid(data, fld_bgn, fld_end);} // was Mid_by_len???; 20120915
public int Read_int_base85_lenN(int len) {fld_bgn = pos; fld_end = pos + len - 1 ; pos = pos + len + 1 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int_base85_len5() {fld_bgn = pos; fld_end = pos + 4 ; pos = pos + 6 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int() {Move_next_simple(); return Bry_.X_to_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.X_to_int_or(data, fld_bgn, fld_end, -1);}
public int Read_int() {Move_next_simple(); return Bry_.Xto_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.Xto_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_byte() {Move_next_simple(); return data[fld_bgn];}
public double Read_double() {Move_next_simple(); return Bry_.XtoDoubleByPos(data, fld_bgn, fld_end);}
public DateAdp Read_dte() {// NOTE: fmt = yyyyMMdd HHmmss.fff

View File

@ -31,7 +31,7 @@ public class Fsdb_db_bin_mgr implements RlsAble {
for (int i = 0; i < itms_len; i++)
itms[i].Bin_max_(v);
return this;
} private long db_bin_max = Io_mgr.Len_mb * Long_.X_by_int(188);
} private long db_bin_max = Io_mgr.Len_mb * Long_.Xby_int(188);
public Fsdb_db_bin_fil Get_at(int i) {return itms[i];}
private Fsdb_db_bin_fil Get_cur() {return itms_len == 0 ? null : itms[itms_len - 1];}
public void Txn_open() {

View File

@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb; import gplx.*;
public class Fsdb_db_tid_ {
public static final byte Tid_cfg = 0, Tid_atr = 1, Tid_bin = 2;
public static final String Key_cfg = "cfg", Key_atr = "atr", Key_bin = "bin";
public static byte Xto_tid(String s) {
if (String_.Eq(s, Key_cfg)) return Tid_cfg;
else if (String_.Eq(s, Key_atr)) return Tid_atr;
else if (String_.Eq(s, Key_bin)) return Tid_bin;
else throw Err_.unhandled(s);
}
public static String Xto_key(byte v) {
switch (v) {
case Tid_cfg: return Key_cfg;
case Tid_atr: return Key_atr;
case Tid_bin: return Key_bin;
default: throw Err_.unhandled(v);
}
}
}

View File

@ -41,8 +41,8 @@ public class Gfui_bnd_parser {
};
private byte[] src; private int src_len;
private ListAdp tkns = ListAdp_.new_(); private int mod_val = Mod_val_null;
public String X_to_norm(String src_str) {return Convert(Bool_.Y, src_str);}
public String X_to_gfui(String src_str) {return Convert(Bool_.N, src_str);}
public String Xto_norm(String src_str) {return Convert(Bool_.Y, src_str);}
public String Xto_gfui(String src_str) {return Convert(Bool_.N, src_str);}
private String Convert(boolean src_is_gfui, String src_str) {
this.src = Bry_.new_utf8_(src_str); this.src_len = src.length;
tkns.Clear(); mod_val = Mod_val_null;

View File

@ -48,9 +48,9 @@ class Gfui_bnd_parser_fxt {
parser = Gfui_bnd_parser.new_en_();
}
public void Test_x_to_norm(String key, String expd) {
Tfds.Eq(expd, parser.X_to_norm(key));
Tfds.Eq(expd, parser.Xto_norm(key));
}
public void Test_x_to_gfui(String key, String expd) {
Tfds.Eq(expd, parser.X_to_gfui(key));
Tfds.Eq(expd, parser.Xto_gfui(key));
}
}

View File

@ -82,9 +82,9 @@ public class Html_wtr {
bfr.Add_byte(Byte_ascii.Gt);
return this;
}
public byte[] X_to_bry_and_clear() {return bfr.XtoAryAndClear();}
public byte[] X_to_bry() {return bfr.XtoAry();}
public String X_to_str() {return bfr.XtoStr();}
public byte[] Xto_bry_and_clear() {return bfr.XtoAryAndClear();}
public byte[] Xto_bry() {return bfr.XtoAry();}
public String Xto_str() {return bfr.XtoStr();}
public static void Write_atr(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr(bfr, Byte_ascii.Quote, key, val);}
public static void Write_atr(Bry_bfr bfr, byte atr_quote, byte[] key, byte[] val) {
if (Bry_.Len_eq_0(val)) return; // don't write empty

View File

@ -33,7 +33,7 @@ public class Json_doc_srl {
if (ClassAdp_.Is_array(t))
Write_kv_ary(comma, key, (Object[])val);
else
Write_kv_str(comma, key, Object_.XtoStr_OrEmpty(val));
Write_kv_str(comma, key, Object_.Xto_str_strict_or_empty(val));
}
private void Write_kv_ary(boolean comma, byte[] key, Object[] val) {
Write_key(comma, key); Write_new_line(); // '"key":\n'
@ -42,7 +42,7 @@ public class Json_doc_srl {
int len = val.length;
for (int i = 0; i < len; i++) {
Write_itm_hdr(i != 0); // ', '
Write_str(Bry_.new_utf8_(Object_.XtoStr_OrNull(val[i])));
Write_str(Bry_.new_utf8_(Object_.Xto_str_strict_or_null(val[i])));
Write_new_line();
}
Indent_del();

View File

@ -67,6 +67,6 @@ public class Json_itm_nde extends Json_itm_base implements Json_grp {
Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth);
bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl();
}
Json_itm[] subs = Json_itm_.Ary_empty;
private Json_itm[] subs = Json_itm_.Ary_empty;
public static Json_itm_nde cast_(Json_itm v) {return v == null || v.Tid() != Json_itm_.Tid_nde ? null : (Json_itm_nde)v;}
}

View File

@ -19,7 +19,7 @@ package gplx.json; import gplx.*;
public class Json_itm_tmp implements Json_itm {
public Json_itm_tmp(byte tid, String data) {this.tid = tid; this.data = data;}
public byte Tid() {return tid;} private byte tid;
public byte[] Data_bry() {return Bry_.new_utf8_(Object_.XtoStr_OrEmpty(data));}
public byte[] Data_bry() {return Bry_.new_utf8_(Object_.Xto_str_strict_or_empty(data));}
public int Src_bgn() {return -1;}
public int Src_end() {return -1;}
public Object Data() {return data;} private String data;

View File

@ -26,7 +26,7 @@ public class Php_itm_ {
return rv;
case Php_itm_.Tid_quote:
byte[] bry = ((Php_itm_quote)itm).Val_obj_bry();
rv = Bry_.X_to_int_or(bry, -1);
rv = Bry_.Xto_int_or(bry, -1);
return (rv == -1) ? or : rv;
default:
return or;

View File

@ -39,7 +39,7 @@ abstract class Php_srl_itm_base implements Php_srl_itm {
@gplx.Virtual public void Xto_bfr(Bry_bfr bfr, int depth) {
Php_srl_wtr.Indent(bfr, depth);
bfr.Add(Php_srl_itm_.Names[this.Tid()]).Add_byte(Byte_ascii.Colon);
bfr.Add_str(Object_.XtoStr_OrNullStr(this.Val())).Add_byte(Byte_ascii.Semic).Add_byte_nl();
bfr.Add_str(Object_.Xto_str_strict_or_null_mark(this.Val())).Add_byte(Byte_ascii.Semic).Add_byte_nl();
}
public void Clear() {}
}

View File

@ -42,7 +42,7 @@ public class Php_srl_parser {
val = Xto_kv_ary(ary);
break;
case Php_srl_itm_.Tid_function:
val = new gplx.xowa.xtns.scribunto.Scrib_lua_proc(Object_.XtoStr_OrNullStr(key), Int_.cast_(itm_val.Val())); // NOTE: in most cases, key is a STRING (name of ScribFunction); however, for gsub it is an INT (arg_idx) b/c it is passed as a parameter
val = new gplx.xowa.xtns.scribunto.Scrib_lua_proc(Object_.Xto_str_strict_or_null_mark(key), Int_.cast_(itm_val.Val())); // NOTE: in most cases, key is a STRING (name of ScribFunction); however, for gsub it is an INT (arg_idx) b/c it is passed as a parameter
break;
default:
val = itm_val.Val();
@ -147,7 +147,7 @@ public class Php_srl_parser {
pos = bgn;
pos = Chk(raw, pos + 1, Byte_ascii.Colon);
int int_end = Skip_while_num(raw, raw_len, pos, true);
int int_val = Bry_.X_to_int_or(raw, pos, int_end, Int_.MinValue);
int int_val = Bry_.Xto_int_or(raw, pos, int_end, Int_.MinValue);
pos = int_end;
return int_val;
}
@ -155,7 +155,7 @@ public class Php_srl_parser {
pos = bgn;
pos = Chk(raw, pos + 1, Byte_ascii.Colon);
int int_end = Skip_while_num(raw, raw_len, pos, true);
int int_val = Bry_.X_to_int_or(raw, pos, int_end, Int_.MinValue);
int int_val = Bry_.Xto_int_or(raw, pos, int_end, Int_.MinValue);
Php_srl_itm_int rv = factory.Int(pos, int_end, int_val);
pos = int_end;
return rv;

View File

@ -84,7 +84,7 @@ public class Php_text_itm_parser {
//throw Err_mgr._.fmt_auto_(GRP_KEY, "dollar_is_last_char", String_.new_utf8_(raw));
}
int int_end = Find_fwd_non_int(raw, i + 1, raw_len); // +1 to search after $
int int_val = Bry_.X_to_int_or(raw, i + 1, int_end, -1); // +1 to search after $
int int_val = Bry_.Xto_int_or(raw, i + 1, int_end, -1); // +1 to search after $
if (int_val == -1) {
tmp_list.Add(new Php_text_itm_text(i, i + 1));
continue;

View File

@ -59,7 +59,7 @@ class Php_tkn_var extends Php_tkn_base {
class Php_tkn_num extends Php_tkn_base {
public Php_tkn_num(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_num;}
public int Num_val_int(byte[] src) {return Bry_.X_to_int_or(src, this.Src_bgn(), this.Src_end(), Int_.MinValue);}
public int Num_val_int(byte[] src) {return Bry_.Xto_int_or(src, this.Src_bgn(), this.Src_end(), Int_.MinValue);}
}
class Php_tkn_quote extends Php_tkn_base {
public Php_tkn_quote(int src_bgn, int src_end, byte quote_tid) {this.Src_rng_(src_bgn, src_end); this.quote_tid = quote_tid;}

View File

@ -63,14 +63,14 @@ class Dsv_fld_parser_int implements Dsv_fld_parser {
boolean pos_is_last = pos == src_len;
byte b = pos_is_last ? row_dlm : src[pos];
if (b == fld_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.X_to_int_or(src, fld_bgn, pos, -1));
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.Xto_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
int rv = pos + 1; // fld_dlm is always 1 byte
parser.Update_by_fld(rv);
return rv;
}
else if (b == row_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.X_to_int_or(src, fld_bgn, pos, -1));
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.Xto_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
wkr.Commit_itm(parser, pos);
int rv = pos + 1; // row_dlm is always 1 byte

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.threads.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.urls.encoders.*;
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.gui.*; import gplx.xowa.cfgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.html.tocs.*; import gplx.xowa.fmtrs.*; import gplx.xowa.html.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*;
@ -39,7 +39,7 @@ public class Xoa_app implements GfoInvkAble {
gui_mgr = new Xoa_gui_mgr(this);
bldr = new Xob_bldr(this);
file_mgr.Init_app(this, usr_dlg);
href_parser = new Xoh_href_parser(url_converter_href, url_parser.Url_parser());
href_parser = new Xoh_href_parser(encoder_mgr.Href(), url_parser.Url_parser());
sanitizer = new Xop_sanitizer(parser_amp_mgr, msg_log);
user_mgr = new Xou_user_mgr(this, user);
sys_cfg = new Xoa_sys_cfg(this);
@ -49,7 +49,7 @@ public class Xoa_app implements GfoInvkAble {
gfs_mgr = new Xoa_gfs_mgr(this);
xtn_mgr = new Xow_xtn_mgr().Ctor_by_app(this);
hive_mgr = new Xoa_hive_mgr(this);
Io_url.Http_file_str_encoder = url_converter_fsys;
Io_url.Http_file_str_encoder = encoder_mgr.Fsys();
tcp_server.App_ctor(this);
fmtr_mgr = new Xoa_fmtr_mgr(this);
log_mgr = new Xop_log_mgr(this);
@ -113,7 +113,7 @@ public class Xoa_app implements GfoInvkAble {
public byte Mode() {return mode;} public Xoa_app Mode_(byte v) {mode = v; return this;} private byte mode = Xoa_app_.Mode_console;
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = new Xop_amp_mgr();
public Xoa_thread_mgr Thread_mgr() {return thread_mgr;} private Xoa_thread_mgr thread_mgr = new Xoa_thread_mgr();
public Url_encoder_mgr Encoder_mgr() {return encoder_mgr;} private Url_encoder_mgr encoder_mgr = new Url_encoder_mgr();
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xoa_fsys_mgr fsys_mgr;
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
@ -129,21 +129,13 @@ public class Xoa_app implements GfoInvkAble {
public Gfo_msg_log Msg_log() {return msg_log;} private Gfo_msg_log msg_log = new Gfo_msg_log(Xoa_app_.Name);
public Gfo_msg_log Msg_log_null() {return msg_log_null;} private Gfo_msg_log msg_log_null = new Gfo_msg_log("null_log");
public Url_encoder Url_converter_id() {return url_converter_id;} private Url_encoder url_converter_id = Url_encoder.new_html_id_();
public Url_encoder Url_converter_url() {return url_converter_url;} private Url_encoder url_converter_url = Url_encoder.new_http_url_();
public Url_encoder Url_converter_url_ttl() {return url_converter_url_ttl;} private Url_encoder url_converter_url_ttl = Url_encoder.new_http_url_ttl_();
public Url_encoder Url_converter_href() {return url_converter_href;} private Url_encoder url_converter_href = Url_encoder.new_html_href_mw_();
public Url_encoder Url_converter_comma() {return url_converter_comma;} private Url_encoder url_converter_comma = Url_encoder.url_comma();
public Url_encoder Url_converter_gfs() {return url_converter_gfs;} private Url_encoder url_converter_gfs = Url_encoder.new_gfs_();
public Url_encoder Url_converter_fsys() {return url_converter_fsys;} private Url_encoder url_converter_fsys = Url_encoder.new_fsys_lnx_();
public Url_encoder Url_converter_fsys_safe() {return url_converter_fsys_safe;} private Url_encoder url_converter_fsys_safe = Url_encoder.new_fsys_wnt_();
public Xoh_file_main_wkr File_main_wkr() {return file_main_wkr;} private Xoh_file_main_wkr file_main_wkr = new Xoh_file_main_wkr();
public Btrie_slim_mgr Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private Btrie_slim_mgr utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return utl_bry_bfr_mkr;} Bry_bfr_mkr utl_bry_bfr_mkr = new Bry_bfr_mkr();
public Gfo_fld_rdr Utl_fld_rdr() {return utl_fld_rdr;} Gfo_fld_rdr utl_fld_rdr = Gfo_fld_rdr.xowa_();
public Gfo_log_bfr Log_bfr() {return log_bfr;} private Gfo_log_bfr log_bfr = new Gfo_log_bfr();
public Xoa_sys_cfg Sys_cfg() {return sys_cfg;} private Xoa_sys_cfg sys_cfg;
public Bry_fmtr Tmp_fmtr() {return tmp_fmtr;} Bry_fmtr tmp_fmtr = Bry_fmtr.new_("");
public Bry_fmtr Tmp_fmtr() {return tmp_fmtr;} Bry_fmtr tmp_fmtr = Bry_fmtr.new_("");
public boolean Xwiki_missing(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) == null;} // NOTE: only the user_wiki has a full list of all wikis b/c it has xwiki objects; wiki_mgr does not, b/c it has heavier wiki objects which are loaded dynamically;
public boolean Xwiki_exists(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) != null;}
public Xoa_ctg_mgr Ctg_mgr() {return ctg_mgr;} private Xoa_ctg_mgr ctg_mgr = new Xoa_ctg_mgr();

View File

@ -23,7 +23,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "1.7.2.1";
public static final String Version = "1.7.3.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";
@ -120,7 +120,7 @@ class Xoa_app_boot_mgr {
Io_url wiki_dir = args_mgr.Args_get("wiki_dir").Val_as_url_rel_dir_or(root_dir.GenSubDir("wiki"), root_dir.GenSubDir("wiki"));
Io_url cmd_file = args_mgr.Args_get("cmd_file").Val_as_url_rel_fil_or(jar_dir, root_dir.GenSubFil("xowa.gfs"));
String app_mode = args_mgr.Args_get("app_mode").Val_as_str_or("gui");
String launch_url = args_mgr.Args_get("url").Val_as_str_or(Xoa_sys_cfg.Launch_url_dflt);
String launch_url = args_mgr.Args_get("url").Val_as_str_or(null);
int server_port_recv = args_mgr.Args_get("server_port_recv").Val_as_int_or(55000);
int server_port_send = args_mgr.Args_get("server_port_send").Val_as_int_or(55001);
int http_server_port = args_mgr.Args_get("http_server_port").Val_as_int_or(8080);
@ -133,8 +133,9 @@ class Xoa_app_boot_mgr {
app = new Xoa_app(usr_dlg, root_dir, user_dir, Xoa_app_.Op_sys); usr_dlg.Log_wtr().Queue_enabled_(false); log_wtr.Log_msg_to_session_fmt("app.init");
app.Fsys_mgr().Wiki_dir_(wiki_dir);
try {
app.Sys_cfg().Lang_(System_lang()); chkpoint = "lang";
app.Sys_cfg().Launch_url_(launch_url); chkpoint = "url";
app.Sys_cfg().Lang_(System_lang());
if (launch_url != null)
app.Api_root().App().Startup().Tabs().Manual_(launch_url);
app.Tcp_server().Rdr_port_(server_port_recv).Wtr_port_(server_port_send);
app.Http_server().Port_(http_server_port);
app.Init(); chkpoint = "init_gfs";
@ -147,7 +148,7 @@ class Xoa_app_boot_mgr {
catch (Exception e) {
usr_dlg.Warn_many("", "", "script file failed: ~{0} ~{1} ~{2}", chkpoint, cmd_file.Raw(), Err_.Message_gplx(e));
if (app_mode_gui)
GfuiEnv_.ShowMsg(Err_.Message_gplx_brief(e));
GfuiEnv_.ShowMsg(Err_.Message_gplx(e));
}
// launch
@ -158,7 +159,7 @@ class Xoa_app_boot_mgr {
app.Http_server().Run();
else {
if (cmd_text != null)
ConsoleAdp._.WriteLine_utf8(Object_.XtoStr_OrEmpty(app.Gfs_mgr().Run_str(cmd_text)));
ConsoleAdp._.WriteLine_utf8(Object_.Xto_str_strict_or_empty(app.Gfs_mgr().Run_str(cmd_text)));
if (app_mode_gui) {
app.Mode_(Xoa_app_.Mode_gui);
app.Gui_mgr().Run(); chkpoint = "run";

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apis; import gplx.*; import gplx.xowa.*;
import gplx.xowa.apis.xowa.*; import gplx.xowa.gui.cmds.*;
public class Xoapi_root implements GfoInvkAble {
public Xoa_app app;
private Xoa_app app;
public Xoapi_root(Xoa_app app) {usr_api.Ctor_by_app(app);}
public void Init_by_kit(Xoa_app app) {
this.app = app;

View File

@ -17,16 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.gui.views.*;
import gplx.xowa.apis.xowa.startups.*;
public class Xoapi_app implements GfoInvkAble {
private Xog_win_itm win;
public void Init_by_kit(Xoa_app app) {
win = app.Gui_mgr().Browser_win();
}
public void Exit() {win.App__exit();}
public Xoapi_startups Startup() {return startup;} private Xoapi_startups startup = new Xoapi_startups();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exit)) this.Exit();
else if (ctx.Match(k, Invk_startup)) return startup;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_exit = "exit";
private static final String Invk_exit = "exit", Invk_startup = "startup";
}

View File

@ -24,10 +24,12 @@ public class Xoapi_html implements GfoInvkAble {
}
public Xoapi_tidy Tidy() {return tidy;} private Xoapi_tidy tidy = new Xoapi_tidy();
public Xoapi_modules Modules() {return modules;} private Xoapi_modules modules = new Xoapi_modules();
public Xoapi_skins Skins() {return skins;} private Xoapi_skins skins = new Xoapi_skins();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tidy)) return tidy;
else if (ctx.Match(k, Invk_modules)) return modules;
else if (ctx.Match(k, Invk_skins)) return skins;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_tidy = "tidy", Invk_modules = "modules";
private static final String Invk_tidy = "tidy", Invk_modules = "modules", Invk_skins = "skins";
}

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_info implements GfoInvkAble {
public class Xoapi_info implements Gfo_usr_dlg_ui_opt, GfoInvkAble {
public void Init_by_kit(Xoa_app app) {this.app = app;} private Xoa_app app;
private Xog_win_itm Win() {return app.Gui_mgr().Browser_win();}
public void Focus() {this.Win().Info_box().Focus();}
@ -26,12 +26,21 @@ public class Xoapi_info implements GfoInvkAble {
Io_url session_fil = app.Log_wtr().Session_fil();
app.Fsys_mgr().App_mgr().App_view_text().Run(session_fil);
}
public boolean Warn_enabled() {return warn_enabled;} private boolean warn_enabled;
public boolean Note_enabled() {return note_enabled;} private boolean note_enabled;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_launch)) this.Launch();
else if (ctx.Match(k, Invk_warn_enabled)) return Yn.Xto_str(warn_enabled);
else if (ctx.Match(k, Invk_warn_enabled_)) warn_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_note_enabled)) return Yn.Xto_str(note_enabled);
else if (ctx.Match(k, Invk_note_enabled_)) note_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_clear = "clear", Invk_launch = "launch";
private static final String Invk_focus = "focus", Invk_clear = "clear", Invk_launch = "launch"
, Invk_warn_enabled = "warn_enabled", Invk_warn_enabled_ = "warn_enabled_"
, Invk_note_enabled = "note_enabled", Invk_note_enabled_ = "note_enabled_"
;
}

View File

@ -36,7 +36,7 @@ public class Xoapi_view implements GfoInvkAble {
public void Save_as() {
if (this.Active_tab_is_null()) return;
Xog_tab_itm tab = win.Tab_mgr().Active_tab();
String file_name = app.Url_converter_fsys_safe().Encode_str(String_.new_utf8_(tab.Page().Ttl().Full_url())) + ".html";
String file_name = app.Encoder_mgr().Fsys_safe().Encode_str(String_.new_utf8_(tab.Page().Ttl().Full_url())) + ".html";
String file_url = app.Gui_mgr().Kit().New_dlg_file(Gfui_kit_.File_dlg_type_save, "Select file to save to:").Init_file_(file_name).Ask();
if (String_.Len_eq_0(file_url)) return;
Io_mgr._.SaveFilStr(file_url, tab.Html_box().Text());

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.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.html.skins.*;
public class Xoapi_skins implements GfoInvkAble {
private HashAdp hash = HashAdp_.new_();
public Xoapi_skins() {
server.Sidebar_home_enabled_(true);
hash.Add("desktop", desktop);
hash.Add("server", server);
}
public Xoapi_skin_app_base Desktop() {return desktop;} private Xoapi_skin_app_base desktop = new Xoapi_skin_app_base();
public Xoapi_skin_app_base Server () {return server ;} private Xoapi_skin_app_base server = new Xoapi_skin_app_base();
private GfoInvkAble Get(String key) {return (GfoInvkAble)hash.Fetch(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get(m.ReadStr("v"));
return this;
}
private static final String Invk_get = "get";
}

View File

@ -21,7 +21,7 @@ public class Xoapi_collapsible implements GfoInvkAble {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.X_to_str(collapsed);
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;

View File

@ -21,7 +21,7 @@ public class Xoapi_navframe implements GfoInvkAble {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.X_to_str(collapsed);
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;

View File

@ -60,7 +60,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
wiki.Html_mgr().Module_mgr().Popup_mgr().Show_all(popup_id);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(enabled);
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_show_more)) Show_more(m.ReadStr("popup_id"));
else if (ctx.Match(k, Invk_show_all)) Show_all (m.ReadStr("popup_id"));
@ -80,7 +80,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
else if (ctx.Match(k, Invk_win_max_h_)) {win_max_h = Set_int(m, win_max_h, Evt_win_max_h_changed);}
else if (ctx.Match(k, Invk_win_show_all_max_w)) return win_show_all_max_w;
else if (ctx.Match(k, Invk_win_show_all_max_w_)) {win_show_all_max_w = m.ReadInt("v");}
else if (ctx.Match(k, Invk_win_bind_focus_blur)) return Yn.X_to_str(win_bind_focus_blur);
else if (ctx.Match(k, Invk_win_bind_focus_blur)) return Yn.Xto_str(win_bind_focus_blur);
else if (ctx.Match(k, Invk_win_bind_focus_blur_)) win_bind_focus_blur = m.ReadYn("v");
else if (ctx.Match(k, Invk_xnde_ignore_ids)) return String_.new_utf8_(xnde_ignore_ids);
else if (ctx.Match(k, Invk_xnde_ignore_ids_)) {xnde_ignore_ids = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_xnde_ignore_ids_changed, xnde_ignore_ids);}
@ -184,7 +184,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
;
public static final byte[]
Dflt_xnde_ignore_ids = Bry_.new_ascii_("coordinates")
, Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age_in_days;as_of;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm|\n")
, Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age;age_in_days;age_in_years_and_days*;nts;number_table_sorting*;as_of;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm|\n")
, Dflt_html_fmtr_popup = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "<div dir=~{page_lang_ltr}>"
, " <div>~{content}"

View File

@ -21,7 +21,7 @@ public class Xoapi_toc implements GfoInvkAble {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed = false;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.X_to_str(collapsed);
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;

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.xowa.apis.xowa.html.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
public class Xoapi_skin_app_base implements GfoInvkAble {
public void Init_by_kit(Xoa_app app) {
}
public boolean Sidebar_home_enabled() {return sidebar_home_enabled;} public void Sidebar_home_enabled_(boolean v) {sidebar_home_enabled = v;} private boolean sidebar_home_enabled;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_sidebar_home_enabled)) return Yn.Xto_str(sidebar_home_enabled);
else if (ctx.Match(k, Invk_sidebar_home_enabled_)) sidebar_home_enabled = m.ReadYn("v");
return this;
}
private static final String Invk_sidebar_home_enabled = "sidebar_home_enabled", Invk_sidebar_home_enabled_ = "sidebar_home_enabled_";
}

View File

@ -1,78 +0,0 @@
/*
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.xowa.apis.xowa.startup; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
class Xoapi_startup_tabs implements GfoInvkAble {
public String[] Calc_startup_strs() {
switch (type) {
case Xoapi_startup_tabs_type_.Tid_blank: return new String[] {gplx.xowa.specials.xowa.default_tab.Default_tab_page.Ttl_full_str};
case Xoapi_startup_tabs_type_.Tid_xowa: return new String[] {gplx.xowa.users.Xouc_pages_mgr.Page_xowa};
case Xoapi_startup_tabs_type_.Tid_custom: return String_.SplitLines_nl(custom);
case Xoapi_startup_tabs_type_.Tid_previous: return String_.SplitLines_nl(previous);
default: throw Err_.unhandled(type);
}
}
public String Custom() {return custom;} private String custom;
public boolean Custom_is_expr() {return custom_is_expr;} private boolean custom_is_expr;
public String Previous() {return previous;} public Xoapi_startup_tabs Previous_(String v) {previous = v; return this;} private String previous = "";
public byte Type() {return type;} private byte type = Xoapi_startup_tabs_type_.Tid_xowa;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_type)) return Xoapi_startup_tabs_type_.X_to_key(type);
else if (ctx.Match(k, Invk_type_)) type = Xoapi_startup_tabs_type_.X_to_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_custom)) return custom;
else if (ctx.Match(k, Invk_custom_)) custom = m.ReadStr("v");
else if (ctx.Match(k, Invk_custom_is_expr)) return Yn.X_to_str(custom_is_expr);
else if (ctx.Match(k, Invk_custom_is_expr_)) custom_is_expr = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_type = "type", Invk_type_ = "type_"
, Invk_custom = "custom", Invk_custom_ = "custom_"
, Invk_custom_is_expr = "custom_is_expr", Invk_custom_is_expr_ = "custom_is_expr_"
;
}
class Xoapi_startup_tabs_type_ {
public static final byte Tid_blank = 0, Tid_xowa = 1, Tid_previous = 2, Tid_custom = 3;
public static final String Key_blank = "blank", Key_xowa = "xowa", Key_previous = "previous", Key_custom = "custom";
public static String X_to_key(byte v) {
switch (v) {
case Tid_blank: return Key_blank;
case Tid_xowa: return Key_xowa;
case Tid_previous: return Key_previous;
case Tid_custom: return Key_custom;
default: throw Err_.not_implemented_();
}
}
public static byte X_to_tid(String s) {
if (String_.Eq(s, Key_blank)) return Tid_blank;
else if (String_.Eq(s, Key_xowa)) return Tid_xowa;
else if (String_.Eq(s, Key_previous)) return Tid_previous;
else if (String_.Eq(s, Key_custom)) return Tid_custom;
else throw Err_.not_implemented_();
}
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_blank), KeyVal_.new_(Key_xowa), KeyVal_.new_(Key_previous), KeyVal_.new_(Key_custom));
}
/*
startup {
tabs {
type = 'previous|blank|custom|xowa_home';
custom = 'en.wikipedia.org/wiki/{{{MONTHNAME}}} {{{DAY}}';
custom_has_wikitext = 'n';
}
}
*/

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.xowa.apis.xowa.startups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.startups.tabs.*;
public class Xoapi_startups implements GfoInvkAble {
public void Init_by_kit(Xoa_app app) {
}
public Xoapi_startup_tabs Tabs() {return tabs;} private Xoapi_startup_tabs tabs = new Xoapi_startup_tabs();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tabs)) return tabs;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_tabs = "tabs";
}

View File

@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.startups.tabs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.startups.*;
public class Xoapi_startup_tabs implements GfoInvkAble {
public String Custom() {return custom;} private String custom;
public boolean Custom_is_expr() {return custom_is_expr;} private boolean custom_is_expr;
public String Previous() {return previous;} public Xoapi_startup_tabs Previous_(String v) {previous = v; return this;} private String previous = "";
public String Manual() {return manual;} public void Manual_(String v) {manual = v;} private String manual;
public byte Type() {return type;} private byte type = Xoapi_startup_tabs_tid_.Tid_xowa;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_type)) return Xoapi_startup_tabs_tid_.Xto_key(type);
else if (ctx.Match(k, Invk_type_)) type = Xoapi_startup_tabs_tid_.Xto_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_type_list)) return Xoapi_startup_tabs_tid_.Options__list;
else if (ctx.Match(k, Invk_previous)) return previous;
else if (ctx.Match(k, Invk_previous_)) previous = m.ReadStr("v");
else if (ctx.Match(k, Invk_custom)) return custom;
else if (ctx.Match(k, Invk_custom_)) custom = m.ReadStr("v");
else if (ctx.Match(k, Invk_custom_is_expr)) return Yn.Xto_str(custom_is_expr);
else if (ctx.Match(k, Invk_custom_is_expr_)) custom_is_expr = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_type = "type", Invk_type_ = "type_", Invk_type_list = "type_list"
, Invk_custom = "custom", Invk_custom_ = "custom_"
, Invk_previous = "previous", Invk_previous_ = "previous_"
, Invk_custom_is_expr = "custom_is_expr", Invk_custom_is_expr_ = "custom_is_expr_"
;
public String[] Calc_startup_strs() {
if (manual != null) return new String[] {manual};
switch (type) {
case Xoapi_startup_tabs_tid_.Tid_blank: return new String[] {gplx.xowa.specials.xowa.default_tab.Default_tab_page.Ttl_full_str};
case Xoapi_startup_tabs_tid_.Tid_xowa: return new String[] {gplx.xowa.users.Xouc_pages_mgr.Page_xowa};
case Xoapi_startup_tabs_tid_.Tid_custom: return String_.SplitLines_nl(String_.Trim(custom));
case Xoapi_startup_tabs_tid_.Tid_previous: return String_.SplitLines_nl(String_.Trim(previous));
default: throw Err_.unhandled(type);
}
}
}

View File

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.startups.tabs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.startups.*;
public class Xoapi_startup_tabs_tid_ {
public static final byte Tid_blank = 0, Tid_xowa = 1, Tid_previous = 2, Tid_custom = 3;
public static final String Key_blank = "blank", Key_xowa = "xowa", Key_previous = "previous", Key_custom = "custom";
public static String Xto_key(byte v) {
switch (v) {
case Tid_blank: return Key_blank;
case Tid_xowa: return Key_xowa;
case Tid_previous: return Key_previous;
case Tid_custom: return Key_custom;
default: throw Err_.not_implemented_();
}
}
public static byte Xto_tid(String s) {
if (String_.Eq(s, Key_blank)) return Tid_blank;
else if (String_.Eq(s, Key_xowa)) return Tid_xowa;
else if (String_.Eq(s, Key_previous)) return Tid_previous;
else if (String_.Eq(s, Key_custom)) return Tid_custom;
else throw Err_.not_implemented_();
}
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_blank), KeyVal_.new_(Key_xowa), KeyVal_.new_(Key_previous), KeyVal_.new_(Key_custom));
}

View File

@ -42,7 +42,7 @@ public class Xoapi_bookmarks implements GfoInvkAble {
}
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Data:Bookmarks");}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(this.Enabled());
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_add)) this.Add(m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_show)) this.Show();

View File

@ -26,7 +26,7 @@ public class Xoapi_history implements GfoInvkAble {
public void Goto_recent() {win.Page__navigate_by_url_bar(app.User().History_mgr().Get_at_last(app));}
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Special:XowaPageHistory");}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(this.Enabled());
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_goto_recent)) this.Goto_recent();
else if (ctx.Match(k, Invk_show)) this.Show();

View File

@ -28,7 +28,7 @@ public class Xoapi_logs implements GfoInvkAble {
Io_mgr._.DeleteFil_args(app.Log_wtr().Session_fil()).MissingFails_off().Exec();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(this.Enabled());
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;

View File

@ -99,7 +99,7 @@ public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
public static void Msg_parser_init() {
GfsCore._.MsgParser_(gplx.gfs.Gfs_msg_bldr._);
}
public static byte[] Cfg_save_escape(String v) {return Cfg_save_escape(Bry_.new_ascii_(v));}
public static byte[] Cfg_save_escape(String v) {return Cfg_save_escape(Bry_.new_utf8_(v));}
public static byte[] Cfg_save_escape(byte[] v) {
return Bry_finder.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Bry_apos_1, Bry_apos_2);
} static final byte[] Bry_apos_1 = Bry_.new_ascii_("'"), Bry_apos_2 = Bry_.new_ascii_("''");

View File

@ -74,7 +74,7 @@ public class Xoa_gfs_php_mgr {
)
throw Err_.new_("invalid gfs; num_end not found={0}", String_.new_utf8_(src));
bfr.Add_byte(Byte_ascii.Dollar);
int arg_idx = Bry_.X_to_int_or(src, num_bgn, num_end, -1);
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
if (arg_idx == -1) {
throw Err_.new_("invalid int");
}
@ -103,7 +103,7 @@ public class Xoa_gfs_php_mgr {
break;
case Byte_ascii.Dollar:
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
int int_val = Bry_.X_to_int_or(raw, i + 1, end_pos, -1);
int int_val = Bry_.Xto_int_or(raw, i + 1, end_pos, -1);
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
i = end_pos - 1;
break;

View File

@ -53,6 +53,8 @@ public class Xob_cmd_mgr implements GfoInvkAble {
else if (String_.Eq(cmd_key, Xob_xfer_regy_cmd.KEY_oimg)) return Add(new Xob_xfer_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_xfer_regy_update_cmd.KEY_oimg)) return Add(new Xob_xfer_regy_update_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_xfer_update_cmd.KEY_oimg)) return Add(new Xob_xfer_update_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_diff_regy_exec_cmd.KEY_oimg)) return Add(new Xob_diff_regy_exec_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_diff_regy_make_cmd.KEY_oimg)) return Add(new Xob_diff_regy_make_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xof_wiki_orig_cmd.KEY_oimg)) return Add(new Xof_wiki_orig_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_download_wkr.KEY_oimg)) return Add(new Xob_download_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_page_regy_cmd.KEY_oimg)) return Add(new Xob_page_regy_cmd(bldr, wiki));

View File

@ -0,0 +1,82 @@
/*
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.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.dbs.*; import gplx.fsdb.*; import gplx.xowa.bldrs.oimgs.*;
public class Xob_diff_regy_exec_cmd extends Xob_itm_basic_base implements Xob_cmd {
private Io_url sql_dir;
public Xob_diff_regy_exec_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.diff_regy.exec";
public void Cmd_ini(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {}
public void Cmd_run() {Exec_main();}
public void Cmd_end() {}
public void Cmd_print() {}
private void Exec_main() {
if (sql_dir == null)
sql_dir = wiki.Ctx().App().Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str(), "tmp_sql");
Xob_diff_regy_sql_runner runner = new Xob_diff_regy_sql_runner();
Io_url[] urls = Io_mgr._.QueryDir_fils(sql_dir);
int urls_len = urls.length;
for (int i = 0; i < urls_len; ++i)
runner.Exec(app, urls[i]);
Xob_diff_regy_sql_runner.Get_provider(wiki, 0, Fsdb_db_tid_.Tid_atr).Exec_sql("VACUUM;");
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_sql_dir_)) sql_dir = m.ReadIoUrl("v");
else return super.Invk(ctx, ikey, k, m);
return this;
} private static final String Invk_sql_dir_ = "sql_dir_";
}
class Xob_diff_regy_sql_runner {
public Io_url Url() {return url;} private Io_url url;
public String Wiki_domain() {return wiki_domain;} private String wiki_domain;
public int Fsdb_db_id() {return fsdb_db_id;} private int fsdb_db_id;
public byte Fsdb_db_tid() {return fsdb_db_tid;} private byte fsdb_db_tid;
public void Exec(Xoa_app app, Io_url url) {
Parse_url(url);
Run_sql(app);
}
public void Parse_url(Io_url url) {
this.url = url;
String[] parts = String_.Split(url.NameOnly(), "-");
wiki_domain = parts[0];
fsdb_db_id = Int_.parse_(parts[1]);
fsdb_db_tid = Fsdb_db_tid_.Xto_tid(parts[2]);
}
public void Run_sql(Xoa_app app) {
Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_null(Bry_.new_utf8_(wiki_domain));
app.Usr_dlg().Prog_many("", "", "running sql: url=~{0}", url.Raw());
Db_provider provider = Get_provider(wiki, fsdb_db_id, fsdb_db_tid);
provider.Exec_sql(Io_mgr._.LoadFilStr(url));
if (fsdb_db_tid == Fsdb_db_tid_.Tid_bin)
provider.Exec_sql("VACUUM;");
}
public static Db_provider Get_provider(Xow_wiki wiki, int fsdb_db_id, byte fsdb_db_tid) {
wiki.File_mgr().Fsdb_mgr().Init_by_wiki(wiki);
Fsdb_db_abc_mgr abc_mgr = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Abc_mgr_at(0);
if (fsdb_db_tid == Fsdb_db_tid_.Tid_bin)
return abc_mgr.Bin_mgr().Get_at(fsdb_db_id).Provider();
else if (fsdb_db_tid == Fsdb_db_tid_.Tid_atr)
return abc_mgr.Atr_mgr().Get_at(0).Provider();
else
throw Err_.unhandled(fsdb_db_tid);
}
public static String Build_url(String wiki_domain, int fsdb_db_id, String fsdb_db_type) {
return String_.Format("{0}-{1}-{2}.sql", wiki_domain, Int_.XtoStr_PadBgn(fsdb_db_id, 3), fsdb_db_type);
}
}

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.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import org.junit.*;
import gplx.fsdb.*;
public class Xob_diff_regy_exec_cmd_tst {
private Xob_diff_regy_exec_cmd_fxt fxt = new Xob_diff_regy_exec_cmd_fxt();
@Test public void Xto_commons() {
fxt.Test_build_url("enwiki", 1, "atr", "enwiki-001-atr.sql");
fxt.Test_parse_url("/file/enwiki-001-atr.sql", "enwiki", 1, Fsdb_db_tid_.Tid_atr);
}
// @Test public void Smoke() {
// Xoa_app app = Xoa_app_fxt.app_(Io_url_.new_dir_("C:\\xowa\\"), "wnt");
// Xow_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
// Xob_diff_regy_make_cmd cmd = new Xob_diff_regy_make_cmd(app.Bldr(), wiki);
// cmd.Cmd_run();
// }
}
class Xob_diff_regy_exec_cmd_fxt {
public void Test_build_url(String wiki_domain, int fsdb_db_id, String fsdb_db_type, String expd) {
Tfds.Eq(expd, Xob_diff_regy_sql_runner.Build_url(wiki_domain, fsdb_db_id, fsdb_db_type));
}
public void Test_parse_url(String raw, String expd_wiki_domain, int expd_fsdb_db_id, byte expd_fsdb_db_tid) {
Xob_diff_regy_sql_runner runner = new Xob_diff_regy_sql_runner();
runner.Parse_url(Io_url_.new_any_(raw));
Tfds.Eq(expd_wiki_domain, runner.Wiki_domain());
Tfds.Eq(expd_fsdb_db_id, runner.Fsdb_db_id());
Tfds.Eq(expd_fsdb_db_tid, runner.Fsdb_db_tid());
}
}

View File

@ -0,0 +1,132 @@
/*
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.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.dbs.*; import gplx.fsdb.*; import gplx.xowa.bldrs.oimgs.*;
public class Xob_diff_regy_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
public Xob_diff_regy_make_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.diff_regy.make";
public void Cmd_ini(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {}
public void Cmd_run() {Exec_main();}
public void Cmd_end() {}
public void Cmd_print() {}
private void Exec_main() {
Db_provider make_db_provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
this.Make_join_indexes(make_db_provider);
this.Make_diff_regy(make_db_provider);
this.Make_delete_sql(make_db_provider);
}
private void Make_join_indexes(Db_provider make_db_provider) {
Sqlite_engine_.Idx_create(make_db_provider, Xob_diff_regy_tbl.Idx_fsdb_regy__join);
Sqlite_engine_.Idx_create(make_db_provider, Xob_diff_regy_tbl.Idx_xfer_regy__join);
}
private void Make_diff_regy(Db_provider make_db_provider) {
Sqlite_engine_.Tbl_create_and_delete(make_db_provider, Xob_diff_regy_tbl.Tbl_name, Xob_diff_regy_tbl.Tbl_sql);
make_db_provider.Exec_sql(Xob_diff_regy_tbl.Make_diff_regy);
Sqlite_engine_.Idx_create(make_db_provider, Xob_diff_regy_tbl.Idx_xfer_regy__join);
}
private void Make_delete_sql(Db_provider make_db_provider) {
DataRdr rdr = make_db_provider.Exec_sql_as_rdr(Xob_diff_regy_tbl.Make_deletes);
int cur_db_id = -1, cur_count = 0;
Bry_bfr atr_bfr = Bry_bfr.new_(), bin_bfr = Bry_bfr.new_();
Io_url sql_tmp_dir = wiki.Ctx().App().Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str(), "tmp_sql");
while (rdr.MoveNextPeer()) {
byte diff_is_orig = rdr.ReadByte("diff_is_orig");
int diff_db_id = rdr.ReadInt("diff_db_id");
int diff_fil_id = rdr.ReadInt("diff_fil_id");
int diff_thm_id = rdr.ReadInt("diff_thm_id");
if (cur_db_id != diff_db_id) {
Make_delete_sql_file(atr_bfr, bin_bfr, sql_tmp_dir, cur_db_id, cur_count);
cur_db_id = diff_db_id;
cur_count = 0;
}
Make_delete_sql_item(atr_bfr, bin_bfr, diff_is_orig, diff_db_id, diff_fil_id, diff_thm_id);
++cur_count;
}
}
private void Make_delete_sql_file(Bry_bfr atr_bfr, Bry_bfr bin_bfr, Io_url sql_tmp_dir, int cur_db_id, int cur_count) {
Make_delete_sql_file(atr_bfr, sql_tmp_dir, cur_db_id, cur_count, Fsdb_db_tid_.Tid_atr);
Make_delete_sql_file(bin_bfr, sql_tmp_dir, cur_db_id, cur_count, Fsdb_db_tid_.Tid_bin);
app.Usr_dlg().Note_many("", "", "file.diff:sql generated: db_id=~{0} count=~{1}", Int_.XtoStr_PadBgn_space(cur_db_id, 3), Int_.XtoStr_PadBgn_space(cur_count, 7));
}
private void Make_delete_sql_file(Bry_bfr bfr, Io_url sql_dir, int db_id, int cur_count, byte db_tid) {
if (db_id != -1 && cur_count > 0) { // do not write 1st bfr
bfr.Add_str("COMMIT;\n");
String sql_url_name = String_.Format("{0}-{1}-{2}.sql", wiki.Domain_str(), Int_.XtoStr_PadBgn(db_id, 3), Fsdb_db_tid_.Xto_key(db_tid));
Io_url sql_url = sql_dir.GenSubFil(sql_url_name);
Io_mgr._.SaveFilBfr(sql_url, bfr);
}
bfr.Clear(); // clear bfr if cur_count == 0
bfr.Add_str("BEGIN TRANSACTION;\n");
}
private void Make_delete_sql_item(Bry_bfr atr_bfr, Bry_bfr bin_bfr, byte diff_is_orig, int diff_db_id, int diff_fil_id, int diff_thm_id) {
if (diff_is_orig == Byte_.Zero) {
atr_bfr.Add_str("DELETE FROM fsdb_xtn_thm WHERE thm_id = " + Int_.XtoStr(diff_thm_id) + ";\n");
bin_bfr.Add_str("DELETE FROM fsdb_bin WHERE bin_owner_id = " + Int_.XtoStr(diff_thm_id) + ";\n");
}
else {
atr_bfr.Add_str("UPDATE fsdb_fil SET fil_bin_db_id = -1 WHERE fil_id = " + Int_.XtoStr(diff_fil_id) + ";\n");
bin_bfr.Add_str("DELETE FROM fsdb_bin WHERE bin_owner_id = " + Int_.XtoStr(diff_fil_id) + ";\n");
}
}
}
class Xob_diff_regy_tbl {
public static final String Tbl_name = "diff_regy";
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE diff_regy"
, "( diff_id integer NOT NULL PRIMARY KEY"
, ", diff_is_orig tinyint NOT NULL "
, ", diff_status integer NOT NULL"
, ", diff_db_id integer NOT NULL"
, ", diff_fil_id integer NOT NULL"
, ", diff_thm_id integer NOT NULL"
, ", diff_name varchar(255) NOT NULL"
, ", diff_repo tinyint NOT NULL"
, ", diff_w integer NOT NULL"
, ", diff_time double NOT NULL"
, ", diff_page integer NOT NULL"
, ", diff_size bigint NOT NULL"
, ");"
);
public static final Db_idx_itm Idx_fsdb_regy__join = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__join ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
public static final Db_idx_itm Idx_xfer_regy__join = Db_idx_itm.sql_("CREATE INDEX xfer_regy__join ON xfer_regy (lnki_ttl , file_is_orig, orig_repo, file_w, lnki_time, lnki_page);");
public static final Db_idx_itm Idx_diff_regy__load = Db_idx_itm.sql_("CREATE INDEX diff_regy__load ON diff_regy (diff_status, diff_db_id, diff_is_orig, diff_fil_id, diff_thm_id);");
public static final String
Make_diff_regy = String_.Concat_lines_nl
( "INSERT INTO diff_regy "
, " (diff_id, diff_is_orig, diff_db_id, diff_fil_id, diff_thm_id, diff_name, diff_repo, diff_w, diff_time, diff_page, diff_size, diff_status)"
, "SELECT "
, " f.fsdb_id, f.fsdb_is_orig, f.fsdb_db_id, f.fsdb_fil_id, f.fsdb_thm_id, f.fsdb_name, f.fsdb_repo, f.fsdb_w, f.fsdb_time, f.fsdb_page, f.fsdb_size, CASE WHEN x.lnki_ttl IS NULL THEN 0 ELSE 1 END"
, "FROM fsdb_regy f"
, " LEFT JOIN xfer_regy x "
, " ON f.fsdb_name = x.lnki_ttl"
, " AND f.fsdb_is_orig = x.file_is_orig"
, " AND f.fsdb_repo = x.orig_repo"
, " AND f.fsdb_w = x.file_w"
, " AND f.fsdb_time = x.lnki_time"
, " AND f.fsdb_page = x.lnki_page"
, ";"
)
, Make_deletes = String_.Concat_lines_nl
( "SELECT diff_db_id, diff_is_orig, diff_fil_id, diff_thm_id"
, "FROM diff_regy"
, "WHERE diff_status = 0"
, "ORDER BY diff_db_id, diff_is_orig, diff_fil_id, diff_thm_id"
)
;
}

View File

@ -105,7 +105,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_log
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
double lnki_thumbtime = lnki.Thumbtime();
int lnki_page = lnki.Page();
byte[] ttl_commons = X_to_commons(wiki_ns_file_is_case_match_all, commons_wiki, ttl);
byte[] ttl_commons = Xto_commons(wiki_ns_file_is_case_match_all, commons_wiki, ttl);
if ( Xof_doc_page.Null_n(lnki_page) // page set
&& Xof_doc_thumb.Null_n(lnki_thumbtime)) // thumbtime set
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Cur_page().Ttl().Page_db_as_str(), String_.new_utf8_(ttl));
@ -137,7 +137,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_log
if (property_wkr == null) property_wkr = bldr.App().Wiki_mgr().Wdata_mgr().Property_wkr_or_new();
return property_wkr;
}
public static byte[] X_to_commons(boolean wiki_ns_file_is_case_match_all, Xow_wiki commons_wiki, byte[] ttl_bry) {
public static byte[] Xto_commons(boolean wiki_ns_file_is_case_match_all, Xow_wiki commons_wiki, byte[] ttl_bry) {
if (!wiki_ns_file_is_case_match_all) return null; // return "" if wiki matches common
Xoa_ttl ttl = Xoa_ttl.parse_(commons_wiki, Xow_ns_.Id_file, ttl_bry);
byte[] rv = ttl.Page_db();

View File

@ -19,27 +19,27 @@ package gplx.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xo
import org.junit.*;
public class Xob_lnki_temp_wkr_tst {
private Xob_lnki_temp_wkr_fxt fxt = new Xob_lnki_temp_wkr_fxt();
@Test public void X_to_commons() {
fxt.Init_X_to_commons(true);
fxt.Test_X_to_commons("a", "A");
fxt.Test_X_to_commons("A", null);
@Test public void Xto_commons() {
fxt.Init_Xto_commons(true);
fxt.Test_Xto_commons("a", "A");
fxt.Test_Xto_commons("A", null);
fxt.Init_X_to_commons(false);
fxt.Test_X_to_commons("a", null);
fxt.Test_X_to_commons("A", null);
fxt.Init_Xto_commons(false);
fxt.Test_Xto_commons("a", null);
fxt.Test_Xto_commons("A", null);
}
}
class Xob_lnki_temp_wkr_fxt {
private boolean wiki_ns_file_is_case_match_all;
private Xow_wiki commons_wiki;
public Xob_lnki_temp_wkr_fxt Init_X_to_commons(boolean wiki_ns_file_is_case_match_all) {
public Xob_lnki_temp_wkr_fxt Init_Xto_commons(boolean wiki_ns_file_is_case_match_all) {
Xoa_app app = Xoa_app_fxt.app_();
this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all;
this.commons_wiki = Xoa_app_fxt.wiki_tst_(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st
return this;
}
public void Test_X_to_commons(String ttl, String expd) {
Tfds.Eq(expd, String_.new_utf8_(Xob_lnki_temp_wkr.X_to_commons(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_utf8_(ttl))));
public void Test_Xto_commons(String ttl, String expd) {
Tfds.Eq(expd, String_.new_utf8_(Xob_lnki_temp_wkr.Xto_commons(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_utf8_(ttl))));
}
}

View File

@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
class Xob_page_regy_tbl {
public static void Reset_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p, byte repo_tid, Xow_wiki wiki) {
Create_data__insert_page(usr_dlg, p, repo_tid, wiki.Db_mgr_as_sql().Fsys_mgr().Get_url(Xodb_file.Tid_core));
Create_data__insert_page(usr_dlg, p, repo_tid, wiki.Db_mgr_as_sql().Fsys_mgr().Get_url(Xodb_file_tid_.Tid_core));
Create_data__insert_redirect(usr_dlg, p, repo_tid, wiki.Fsys_mgr().Root_dir().GenSubFil(Xodb_db_file.Name__wiki_redirect));
}
public static void Delete_local(Db_provider p) {

View File

@ -71,12 +71,14 @@ class Xob_fsdb_regy_tbl {
, ", fsdb_db_id integer NOT NULL"
, ", fsdb_size bigint NOT NULL"
, ", fsdb_status tinyint NOT NULL"
, ", fsdb_fil_id integer NOT NULL"
, ", fsdb_thm_id integer NOT NULL"
, ");"
);
public static final Db_idx_itm Idx_main = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__main ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
public static final String
Insert_fsdb_fil = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id)"
, "SELECT f.fil_name"
, ", 1"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
@ -86,13 +88,15 @@ class Xob_fsdb_regy_tbl {
, ", f.fil_bin_db_id"
, ", f.fil_size"
, ", 0"
, ", f.fil_id"
, ", -1"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, "WHERE f.fil_bin_db_id != -1"
, ";"
)
, Insert_fsdb_thm = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id)"
, "SELECT f.fil_name"
, ", 0"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
@ -102,13 +106,15 @@ class Xob_fsdb_regy_tbl {
, ", t.thm_bin_db_id"
, ", t.thm_size"
, ", 0"
, ", f.fil_id"
, ", t.thm_id"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.fsdb_xtn_thm t ON f.fil_id = t.thm_owner_id"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, ";"
)
, Insert_fsdb_thm_v0 = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id)"
, "SELECT f.fil_name"
, ", 0"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
@ -118,6 +124,8 @@ class Xob_fsdb_regy_tbl {
, ", t.thm_bin_db_id"
, ", t.thm_size"
, ", 0"
, ", f.fil_id"
, ", t.thm_id"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.fsdb_xtn_thm t ON f.fil_id = t.thm_owner_id"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"

View File

@ -41,7 +41,7 @@ public class Xob_import_cfg {
Xoa_app app = wiki.App();
if (app.Setup_mgr().Dump_mgr().Import_bz2_by_stdout()) {
ProcessAdp process = app.Fsys_mgr().App_mgr().App_decompress_bz2_by_stdout();
return Io_stream_rdr_process.new_(process.Exe_url(), src_fil_bz2, process.X_to_process_bldr_args(src_fil_bz2.Raw()));
return Io_stream_rdr_process.new_(process.Exe_url(), src_fil_bz2, process.Xto_process_bldr_args(src_fil_bz2.Raw()));
}
else
return gplx.ios.Io_stream_rdr_.bzip2_(src_fil_bz2);

View File

@ -77,7 +77,7 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
db_mgr.Tbl_xowa_ns().Insert(ns_mgr); // save ns
db_mgr.Tbl_xowa_db().Commit_all(page_provider, db_mgr.Fsys_mgr().Ary()); // save dbs; note that dbs can be saved again later
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file.Tid_core, Xodb_file.Tid_text), Xodb_file.Indexes_page_title, Xodb_file.Indexes_page_random);
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_text), Index_page_title, Index_page_random);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_txn_commit_interval_)) txn_commit_interval = m.ReadInt("v");
@ -85,6 +85,10 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
} private static final String Invk_txn_commit_interval_ = "txn_commit_interval_";
public void Wkr_ini(Xob_bldr bldr) {}
public void Wkr_print() {}
private static final Db_idx_itm
Index_page_title = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__title ON page (page_namespace, page_title, page_id, page_len, page_is_redirect);") // PERF:page_id for general queries; PERF: page_len for search_suggest; PREF:page_is_redirect for oimg
, Index_page_random = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__name_random ON page (page_namespace, page_random_int);")
;
}
class Xob_text_stmts_mgr {
public Xob_text_stmts_mgr(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
@ -116,12 +120,12 @@ class Xob_text_stmts_mgr {
Xodb_file File_get(int file_idx, int text_len) {
if (file_idx == Xow_ns.Bldr_file_idx_heap) {
file_idx = fsys_mgr.Tid_text_idx();
Xodb_file file = fsys_mgr.Get_or_make(Xodb_file.Tid_text, file_idx);
Xodb_file file = fsys_mgr.Get_or_make(Xodb_file_tid_.Tid_text, file_idx);
long file_len = file.File_len();
long file_max = fsys_mgr.Tid_text_max();
if (file_max != Xodb_fsys_mgr.Heap_max_infinite && (file_len + text_len > file_max)) { // file is "full"
file.Provider().Txn_mgr().Txn_end_all(); // close txn
file = fsys_mgr.Make(Xodb_file.Tid_text);
file = fsys_mgr.Make(Xodb_file_tid_.Tid_text);
file_idx = file.Id();
fsys_mgr.Tid_text_idx_(file_idx);
}
@ -129,7 +133,7 @@ class Xob_text_stmts_mgr {
return file;
}
else
return fsys_mgr.Get_or_make(Xodb_file.Tid_text, file_idx);
return fsys_mgr.Get_or_make(Xodb_file_tid_.Tid_text, file_idx);
}
private void Add(Db_stmt stmt, int stmt_idx) {
int new_len = stmt_idx + 1;

View File

@ -30,12 +30,12 @@ public class Xob_search_sql_cmd extends Xob_itm_basic_base implements Xob_cmd {
if (!Env_.Mode_testing()) wiki.Init_assert();
Xodb_fsys_mgr db_fs = wiki.Db_mgr_as_sql().Fsys_mgr();
usr_dlg.Log_many("", "", "search_title.cmd: getting core db");
Xodb_file page_db = db_fs.Get_tid_root(Xodb_file.Tid_core);
Xodb_file page_db = db_fs.Get_tid_root(Xodb_file_tid_.Tid_core);
usr_dlg.Log_many("", "", "search_title.cmd: getting existing searchdb");
Xodb_file search_db = db_fs.Get_tid_root(Xodb_file.Tid_search);
Xodb_file search_db = db_fs.Get_tid_root(Xodb_file_tid_.Tid_search);
if (search_db == null) {
usr_dlg.Log_many("", "", "search_title.cmd: making new searchdb");
search_db = db_fs.Make(Xodb_file.Tid_search);
search_db = db_fs.Make(Xodb_file_tid_.Tid_search);
}
DataRdr page_rdr = DataRdr_.Null;
Db_provider search_provider = search_db.Provider();

View File

@ -25,9 +25,9 @@ public class Xob_search_sql_wkr extends Xob_search_base implements Io_make_cmd {
public void Sort_bgn() {
db_mgr = wiki.Db_mgr_as_sql();
boolean created = false;
Xodb_file search_db = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file.Tid_search);
Xodb_file search_db = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_search);
if (search_db == null) {
search_db = db_mgr.Fsys_mgr().Make(Xodb_file.Tid_search);
search_db = db_mgr.Fsys_mgr().Make(Xodb_file_tid_.Tid_search);
created = true;
}
provider = search_db.Provider();

View File

@ -60,7 +60,7 @@ public class Xobc_core_calc_stats extends Xob_itm_basic_base implements Xob_cmd
for (int i = 0; i < len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
Object val = vals[i];
bfr.Add_str(Object_.XtoStr_OrNullStr(val));
bfr.Add_str(Object_.Xto_str_strict_or_null_mark(val));
}
bfr.Add_byte(Byte_ascii.Paren_end);
}

View File

@ -25,7 +25,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
parser.Fld_cmd_(this).Flds_req_(Fld_cl_from, Fld_cl_to, Fld_cl_timestamp, Fld_cl_collation, Fld_cl_sortkey, Fld_cl_type);
} static final byte[] Fld_cl_from = Bry_.new_ascii_("cl_from"), Fld_cl_to = Bry_.new_ascii_("cl_to"), Fld_cl_timestamp = Bry_.new_ascii_("cl_timestamp"), Fld_cl_collation = Bry_.new_ascii_("cl_collation"), Fld_cl_sortkey = Bry_.new_ascii_("cl_sortkey"), Fld_cl_type = Bry_.new_ascii_("cl_type");
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.X_to_int_or(src, fld_bgn, fld_end, -1);
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1);
else if (Bry_.Eq(fld_key, Fld_cl_to)) cur_ctg = Bry_.Mid(src, fld_bgn, fld_end);
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.HasAtBgn(src, Collation_uca, fld_bgn, fld_end);
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {

View File

@ -26,11 +26,11 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
name_id_rdr = New_registry_rdr(wiki, usr_dlg);
cur_cat_file_max = wiki.App().Setup_mgr().Dump_mgr().Db_categorylinks_max();
db_mgr.Delete_by_tid(Xodb_file.Tid_category);
db_mgr.Delete_by_tid(Xodb_file_tid_.Tid_category);
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
Xodb_file category_file = fsys_mgr.Get_tid_root(Xodb_file.Tid_core);
Xodb_file category_file = fsys_mgr.Get_tid_root(Xodb_file_tid_.Tid_core);
if (cur_cat_file_max > 0) {
category_file = fsys_mgr.Make(Xodb_file.Tid_category);
category_file = fsys_mgr.Make(Xodb_file_tid_.Tid_category);
fsys_mgr.Init_by_tid_category(category_file);
}
@ -70,7 +70,7 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
db_mgr.Category_version_update(false);
cat_provider.Txn_mgr().Txn_end_all();
ctg_stmt.Rls();
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file.Tid_core, Xodb_file.Tid_category), Xodb_file.Indexes_categorylinks_from, Xodb_file.Indexes_categorylinks_main);
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_category), Index_categorylinks_from, Index_categorylinks_main);
name_id_rdr.Rls();
if (String_.Eq(sql_parser.Src_fil().NameAndExt(), Xob_ctg_v1_sql_make.Url_sql)) // delete temp xowa_categorylinks.sql file created by cat_v1
Io_mgr._.DeleteFil(sql_parser.Src_fil());
@ -79,7 +79,7 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
if (cur_cat_ttl != Bry_.Empty && cur_cat_id != -1)
db_mgr.Tbl_category().Insert(ctg_stmt, cur_cat_id, cur_cat_counts[Xoa_ctg_mgr.Tid_page], cur_cat_counts[Xoa_ctg_mgr.Tid_subc], cur_cat_counts[Xoa_ctg_mgr.Tid_file], Xoa_ctg_mgr.Hidden_n, cur_cat_file_idx);
if (new_ctg_ttl == Ttl_last) return Cur_cat_id_null; // last ttl; called by this.End(); exit early else will fail in Cur_cat_id_find()
if (cur_cat_file_max > 0 && cur_cat_file_size > cur_cat_file_max) {File_close(); File_open(db_mgr.Fsys_mgr().Make(Xodb_file.Tid_category));}
if (cur_cat_file_max > 0 && cur_cat_file_size > cur_cat_file_max) {File_close(); File_open(db_mgr.Fsys_mgr().Make(Xodb_file_tid_.Tid_category));}
cur_cat_id = Cur_cat_id_find(new_ctg_ttl);
for (int i = 0; i < Xoa_ctg_mgr.Tid__max; i++)
cur_cat_counts[i] = 0;
@ -130,6 +130,10 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
return new Io_line_rdr(usr_dlg, urls).Key_gen_(Io_line_rdr_key_gen_.first_pipe);
} Io_line_rdr name_id_rdr;
private static final byte[] Ttl_last = null, Ttl_first = Bry_.Empty;
private static final Db_idx_itm
Index_categorylinks_main = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_main ON categorylinks (cl_to_id, cl_type_id, cl_sortkey, cl_from);")
, Index_categorylinks_from = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_from ON categorylinks (cl_from);")
;
}
/*
NOTE_1: categorylinks row size: 34 + 20 + 12 + (ctg_sortkey.length * 2)

Some files were not shown because too many files have changed in this diff Show More