v3.3.4 v3.5.1.1
gnosygnu 8 years ago
parent 5ce4ea2a08
commit 96636f3161

@ -31,7 +31,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
return this.Add_day(days);
}
else return GfoInvkAble_.Rv_unhandled;
} public static final String Invk_XtoStr_fmt = "XtoStr_fmt", Invk_AddDays = "Add_day";
} public static final String Invk_XtoStr_fmt = "XtoStr_fmt", Invk_AddDays = "Add_day";
public int Segment(int segmentIdx) {
switch (segmentIdx) {
case DateAdp_.SegIdx_year: return this.Year();
@ -140,9 +140,9 @@ public class DateAdp implements CompareAble, GfoInvkAble {
long diff = this.under.getTimeInMillis() - prev.under.getTimeInMillis();
return (int)(diff / (1000 * 60 * 60 * 24));
}
public TimeSpanAdp Diff(DateAdp earlier) {
public Time_span Diff(DateAdp earlier) {
long diff = this.under.getTimeInMillis() - earlier.under.getTimeInMillis();
return TimeSpanAdp_.fracs_(diff);
return Time_span_.fracs_(diff);
}
protected DateAdp(Calendar under) {this.under = under;}
protected DateAdp(int year, int month, int day, int hour, int minute, int second, int frac) {

@ -31,6 +31,8 @@ public class GfoInvkAble_ {
return rv;
}
public static final GfoInvkAble Null = new GfoInvkAble_null();
public static Object Invk(GfoInvkAble itm) {return itm.Invk(null, -1, null, null);}
public static Object Invk(GfoInvkAble itm, String key) {return itm.Invk(null, -1, key , null);}
public static final String Mutator_suffix = "_";
}
class GfoInvkAble_null implements GfoInvkAble {

@ -17,42 +17,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*;
public class TimeSpanAdp implements CompareAble {
public class Time_span implements CompareAble { // NOTE: gplx.Time_span b/c System.TimeSpan
public long Fracs() {return fracs;} long fracs; public int FracsAsInt() {return (int)fracs;}
public Decimal_adp TotalSecs() {
return Decimal_adp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Sec]);
return Decimal_adp_.divide_(fracs, Time_span_.Divisors[Time_span_.Idx_Sec]);
}
public Decimal_adp Total_days() {
return Decimal_adp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Hour] * 24);
return Decimal_adp_.divide_(fracs, Time_span_.Divisors[Time_span_.Idx_Hour] * 24);
}
public int[] Units() {return TimeSpanAdp_.Split_long(fracs, TimeSpanAdp_.Divisors);}
public int[] Units() {return Time_span_.Split_long(fracs, Time_span_.Divisors);}
public int Units_fracs() {
int[] ary = TimeSpanAdp_.Split_long(fracs, TimeSpanAdp_.Divisors);
return ary[TimeSpanAdp_.Idx_Frac];
int[] ary = Time_span_.Split_long(fracs, Time_span_.Divisors);
return ary[Time_span_.Idx_Frac];
}
public TimeSpanAdp Add(TimeSpanAdp val) {return new TimeSpanAdp(fracs + val.fracs);}
public TimeSpanAdp Add_fracs(long val) {return new TimeSpanAdp(fracs + val);}
public TimeSpanAdp Add_unit(int idx, int val) {
int[] units = TimeSpanAdp_.Split_long(fracs, TimeSpanAdp_.Divisors);
public Time_span Add(Time_span val) {return new Time_span(fracs + val.fracs);}
public Time_span Add_fracs(long val) {return new Time_span(fracs + val);}
public Time_span Add_unit(int idx, int val) {
int[] units = Time_span_.Split_long(fracs, Time_span_.Divisors);
units[idx] += val;
int sign = fracs >= 0 ? 1 : -1;
long rv = sign * TimeSpanAdp_.Merge_long(units, TimeSpanAdp_.Divisors);
return TimeSpanAdp_.fracs_(rv);
long rv = sign * Time_span_.Merge_long(units, Time_span_.Divisors);
return Time_span_.fracs_(rv);
}
public TimeSpanAdp Subtract(TimeSpanAdp val) {return new TimeSpanAdp(fracs - val.fracs);}
public Time_span Subtract(Time_span val) {return new Time_span(fracs - val.fracs);}
public int compareTo(Object obj) {TimeSpanAdp comp = TimeSpanAdp_.cast(obj); return CompareAble_.Compare_obj(fracs, comp.fracs);}
public int compareTo(Object obj) {Time_span comp = Time_span_.cast(obj); return CompareAble_.Compare_obj(fracs, comp.fracs);}
public boolean Eq(Object o) {
TimeSpanAdp comp = TimeSpanAdp_.cast(o); if (comp == null) return false;
Time_span comp = Time_span_.cast(o); if (comp == null) return false;
return fracs == comp.fracs;
}
@Override public String toString() {return To_str(TimeSpanAdp_.Fmt_Default);}
@Override public boolean equals(Object obj) {TimeSpanAdp comp = TimeSpanAdp_.cast(obj); return Object_.Eq(fracs, comp.fracs);}
@Override public String toString() {return To_str(Time_span_.Fmt_Default);}
@Override public boolean equals(Object obj) {Time_span comp = Time_span_.cast(obj); return Object_.Eq(fracs, comp.fracs);}
@Override public int hashCode() {return super.hashCode();}
public String To_str() {return TimeSpanAdp_.To_str(fracs, TimeSpanAdp_.Fmt_Default);}
public String To_str() {return Time_span_.To_str(fracs, Time_span_.Fmt_Default);}
public String To_str(String format) {
return TimeSpanAdp_.To_str(fracs, format);
return Time_span_.To_str(fracs, format);
}
public String XtoStrUiAbbrv() {
if (fracs == 0) return "0" + UnitAbbrv(0);
@ -81,5 +81,5 @@ public class TimeSpanAdp implements CompareAble {
default: return "unknown:<" + Int_.To_str(i) + ">";
}
}
@gplx.Internal protected TimeSpanAdp(long fracs) {this.fracs = fracs;}
@gplx.Internal protected Time_span(long fracs) {this.fracs = fracs;}
}

@ -17,28 +17,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*; import gplx.core.envs.*;
public class TimeSpanAdp_ {
public static final TimeSpanAdp Zero = new TimeSpanAdp(0);
public static final TimeSpanAdp Null = new TimeSpanAdp(-1);
public static TimeSpanAdp fracs_(long val) {return new TimeSpanAdp(val);}
public static TimeSpanAdp seconds_(double seconds) {
public class Time_span_ {
public static final Time_span Zero = new Time_span(0);
public static final Time_span Null = new Time_span(-1);
public static Time_span fracs_(long val) {return new Time_span(val);}
public static Time_span seconds_(double seconds) {
long fracs = (long)(seconds * Divisors[Idx_Sec]);
return new TimeSpanAdp(fracs);
return new Time_span(fracs);
}
public static TimeSpanAdp decimal_(Decimal_adp seconds) {
return new TimeSpanAdp(seconds.To_long_mult_1000());
public static Time_span decimal_(Decimal_adp seconds) {
return new Time_span(seconds.To_long_mult_1000());
}
public static TimeSpanAdp units_(int frc, int sec, int min, int hour) {
public static Time_span units_(int frc, int sec, int min, int hour) {
int[] units = new int[] {frc, sec, min, hour};
long fracs = Merge_long(units, TimeSpanAdp_.Divisors);
return TimeSpanAdp_.fracs_(fracs);
long fracs = Merge_long(units, Time_span_.Divisors);
return Time_span_.fracs_(fracs);
}
public static TimeSpanAdp from_(long bgn) {return TimeSpanAdp_.fracs_(Env_.TickCount() - bgn);}
public static Time_span from_(long bgn) {return Time_span_.fracs_(Env_.TickCount() - bgn);}
public static final long parse_null = Long_.Min_value;
public static TimeSpanAdp parse(String raw) {
public static Time_span parse(String raw) {
byte[] bry = Bry_.new_u8(raw);
long fracs = parse_to_fracs(bry, 0, bry.length, false);
return fracs == parse_null ? null : TimeSpanAdp_.fracs_(fracs);
return fracs == parse_null ? null : Time_span_.fracs_(fracs);
}
public static long parse_to_fracs(byte[] raw, int bgn, int end, boolean fail_if_ws) {
int sign = 1, val_f = 0, val_s = 0, val_m = 0, val_h = 0, colon_pos = 0, unit_val = 0, unit_multiple = 1;
@ -84,7 +84,7 @@ public class TimeSpanAdp_ {
String_bldr sb = String_bldr_.new_();
int[] units = Split_long(frc, Divisors);
if (String_.Eq(fmt, TimeSpanAdp_.Fmt_Short)) {
if (String_.Eq(fmt, Time_span_.Fmt_Short)) {
for (int i = Idx_Hour; i > -1; i--) {
int val = units[i];
if (val == 0 && i == Idx_Hour) continue; // skip hour if 0; ex: 01:02, instead of 00:01:02
@ -97,8 +97,8 @@ public class TimeSpanAdp_ {
}
return sb.To_str_and_clear();
}
boolean fmt_fracs = !String_.Eq(fmt, TimeSpanAdp_.Fmt_NoFractionals);
boolean fmt_padZeros = String_.Eq(fmt, TimeSpanAdp_.Fmt_PadZeros);
boolean fmt_fracs = !String_.Eq(fmt, Time_span_.Fmt_NoFractionals);
boolean fmt_padZeros = String_.Eq(fmt, Time_span_.Fmt_PadZeros);
if (frc == 0) return fmt_padZeros ? "00:00:00.000" : "0";
int[] padZerosAry = ZeroPadding;
@ -140,24 +140,24 @@ public class TimeSpanAdp_ {
}
return rv;
}
public static final String Fmt_PadZeros = "00:00:00.000"; // u,h00:m00:s00.f000
public static final String Fmt_Short = "short"; // u,h##:m#0:s00;
public static final String Fmt_Default = "0.000"; // v,#.000
public static final String Fmt_NoFractionals = "0"; // v,#
@gplx.Internal protected static final int[] Divisors = {
public static final String Fmt_PadZeros = "00:00:00.000"; // u,h00:m00:s00.f000
public static final String Fmt_Short = "short"; // u,h##:m#0:s00;
public static final String Fmt_Default = "0.000"; // v,#.000
public static final String Fmt_NoFractionals = "0"; // v,#
@gplx.Internal protected static final int[] Divisors = {
1, //1 fracs
1000, //1,000 fracs in a second
60000, //60,000 fracs in a minute (60 seconds * 1,000)
3600000, //3,600,000 fracs in an hour (60 minutes * 60,000)
};
public static final String MajorDelimiter = ":";
public static final int
public static final String MajorDelimiter = ":";
public static final int
Idx_Frac = 0
, Idx_Sec = 1
, Idx_Min = 2
, Idx_Hour = 3;
static int[] ZeroPadding = {3, 2, 2, 2,};
static String[] Sprs = {".", MajorDelimiter, MajorDelimiter, "",};
public static TimeSpanAdp cast(Object arg) {try {return (TimeSpanAdp)arg;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TimeSpanAdp.class, arg);}}
public static Time_span cast(Object arg) {try {return (Time_span)arg;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Time_span.class, arg);}}
public static final double Ratio_f_to_s = 1000;
}

@ -15,24 +15,14 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.texts; import gplx.*; import gplx.core.*;
public class HexDecUtl {
public static int parse_or(String raw, int or) {
int rv = 0; int digit; int factor = 1, rawLen = String_.Len(raw);
for (int i = rawLen - 1; i >= 0; i--) {
digit = XtoInt(String_.CharAt(raw, i));
if (digit == -1) return or;
rv += digit * factor;
factor *= 16;
}
return rv;
}
public static int parse_or(byte[] raw, int or) {return parse_or(raw, 0, raw.length, or);}
public static int parse_or(byte[] raw, int bgn, int end, int or) {
package gplx.core.encoders; import gplx.*; import gplx.core.*;
public class Hex_utl_ {
static public int Parse_or(byte[] src, int or) {return Parse_or(src, 0, src.length, or);}
static public int Parse_or(byte[] src, int bgn, int end, int or) {
int rv = 0; int factor = 1;
byte b = Byte_.Max_value_127;
for (int i = end - 1; i >= bgn; i--) {
switch (raw[i]) {
switch (src[i]) {
case Byte_ascii.Num_0: b = 0; break; case Byte_ascii.Num_1: b = 1; break; case Byte_ascii.Num_2: b = 2; break; case Byte_ascii.Num_3: b = 3; break; case Byte_ascii.Num_4: b = 4; break;
case Byte_ascii.Num_5: b = 5; break; case Byte_ascii.Num_6: b = 6; break; case Byte_ascii.Num_7: b = 7; break; case Byte_ascii.Num_8: b = 8; break; case Byte_ascii.Num_9: b = 9; break;
case Byte_ascii.Ltr_A: b = 10; break; case Byte_ascii.Ltr_B: b = 11; break; case Byte_ascii.Ltr_C: b = 12; break; case Byte_ascii.Ltr_D: b = 13; break; case Byte_ascii.Ltr_E: b = 14; break; case Byte_ascii.Ltr_F: b = 15; break;
@ -45,22 +35,50 @@ public class HexDecUtl {
}
return rv;
}
public static int parse(String raw) {
int rv = parse_or(raw, -1); if (rv == -1) throw Err_.new_parse("HexDec", "raw");
static public int Parse(String src) {
int rv = Parse_or(src, -1); if (rv == -1) throw Err_.new_parse("HexDec", "src");
return rv;
}
public static String To_str(int val, int pad) {
static public int Parse_or(String src, int or) {
int rv = 0; int digit = 0, factor = 1, len = String_.Len(src);
for (int i = len - 1; i > -1; --i) {
digit = To_int(String_.CharAt(src, i));
if (digit == -1) return or;
rv += digit * factor;
factor *= 16;
}
return rv;
}
static public void Encode_bry(byte[] src, byte[] trg) {
int src_len = src.length, trg_len = trg.length;
if (trg_len != src_len * 2) throw Err_.new_("hex", "trg.len must be src.len * 2", "src_len", src_len, "trg_len", trg_len);
int trg_idx = -1;
for (int src_idx = 0; src_idx < src_len; ++src_idx) {
byte src_byte = src[src_idx];
trg[++trg_idx] = To_byte_lcase(0xf & src_byte >>> 4);
trg[++trg_idx] = To_byte_lcase(0xf & src_byte);
}
}
static public String To_str(int val, int pad) {
char[] ary = new char[8]; int idx = 8; // 8 is max len of hexString; (2^4 * 8); EX: int.MaxValue = 7FFFFFFF
do {
int byt = val % 16;
ary[--idx] = XtoChar(byt);
ary[--idx] = To_char(byt);
val /= 16;
} while (val > 0);
while (8 - idx < pad) // pad left with zeros
ary[--idx] = '0';
return String_.new_charAry_(ary, idx, 8-idx);
}
static int XtoInt(char c) {
static public void Write(byte[] bry, int bgn, int end, int val) {
for (int i = end - 1; i > bgn - 1; i--) {
int b = val % 16;
bry[i] = To_byte(b);
val /= 16;
if (val == 0) break;
}
}
static private int To_int(char c) {
switch (c) {
case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
@ -69,7 +87,7 @@ public class HexDecUtl {
default: return -1;
}
}
static char XtoChar(int val) {
static private char To_char(int val) {
switch (val) {
case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4';
case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9';
@ -77,7 +95,7 @@ public class HexDecUtl {
default: throw Err_.new_parse("hexstring", Int_.To_str(val));
}
}
static byte Xto_byte(int v) {
static private byte To_byte(int v) {
switch (v) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
@ -85,12 +103,13 @@ public class HexDecUtl {
default: throw Err_.new_parse("hexstring", Int_.To_str(v));
}
}
public static void Write(byte[] bry, int bgn, int end, int val) {
for (int i = end - 1; i > bgn - 1; i--) {
int b = val % 16;
bry[i] = Xto_byte(b);
val /= 16;
if (val == 0) break;
static private byte To_byte_lcase(int v) {
switch (v) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3;
case 4: return Byte_ascii.Num_4; case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7;
case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9; case 10: return Byte_ascii.Ltr_a; case 11: return Byte_ascii.Ltr_b;
case 12: return Byte_ascii.Ltr_c; case 13: return Byte_ascii.Ltr_d; case 14: return Byte_ascii.Ltr_e; case 15: return Byte_ascii.Ltr_f;
default: throw Err_.new_parse("hexstring", Int_.To_str(v));
}
}
}

@ -0,0 +1,70 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.encoders; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hex_utl__tst {
private final Hex_utl__fxt fxt = new Hex_utl__fxt();
@Test public void To_int() {
fxt.Test__to_int("0" , 0);
fxt.Test__to_int("F" , 15);
fxt.Test__to_int("0F" , 15);
fxt.Test__to_int("10" , 16);
fxt.Test__to_int("20" , 32);
fxt.Test__to_int("FF" , 255);
fxt.Test__to_int("100" , 256);
fxt.Test__to_int("0a" , 10);
fxt.Test__to_int("7FFFFFFF" , Int_.Max_value);
fxt.Test__to_int_bry("100" , 256);
}
@Test public void To_str() {
fxt.Test__to_str(0 , "0");
fxt.Test__to_str(15 , "F");
fxt.Test__to_str(16 , "10");
fxt.Test__to_str(32 , "20");
fxt.Test__to_str(255 , "FF");
fxt.Test__to_str(Int_.Max_value, "7FFFFFFF");
fxt.Test__to_str(15, 2 , "0F");
fxt.Test__to_str(15, 3 , "00F");
}
@Test public void Write() {
fxt.Test__write("[00000000]", 1, 9, 15, "[0000000F]");
fxt.Test__write("[00000000]", 1, 9, 255, "[000000FF]");
}
}
class Hex_utl__fxt {
public void Test__write(String s, int bgn, int end, int val, String expd) {
byte[] bry = Bry_.new_a7(s);
Hex_utl_.Write(bry, bgn, end, val);
Tfds.Eq(expd, String_.new_a7(bry));
}
public void Test__to_int(String raw, int expd) {
int actl = Hex_utl_.Parse(raw);
Tfds.Eq(expd, actl);
}
public void Test__to_int_bry(String raw, int expd) {Tfds.Eq(expd, Hex_utl_.Parse_or(Bry_.new_a7(raw), -1));}
public void Test__to_str(int val, String expd) {Test__to_str(val, 0, expd);}
public void Test__to_str(int val, int pad, String expd) {
String actl = Hex_utl_.To_str(val, pad);
Tfds.Eq(expd, actl);
}
// public void Test__encode_bry(int val, int pad, String expd) {
// String actl = Hex_utl_.To_str(val, pad);
// Tfds.Eq(expd, actl);
// }
}

@ -53,7 +53,7 @@ public class Utf16_ {
public static byte[] Encode_hex_to_bry(String raw) {return Encode_hex_to_bry(Bry_.new_a7(raw));}
public static byte[] Encode_hex_to_bry(byte[] raw) {
if (raw == null) return null;
int int_val = gplx.core.texts.HexDecUtl.parse_or(raw, Int_.Min_value);
int int_val = gplx.core.encoders.Hex_utl_.Parse_or(raw, Int_.Min_value);
return int_val == Int_.Min_value ? null : Encode_int_to_bry(int_val);
}
public static byte[] Encode_int_to_bry(int c) {

@ -37,6 +37,60 @@ public class Io_size_ {
String[] unit = Io_size_.Units[exp_1024];
return val_as_decimal.To_str(val_fmt) + " " + String_.PadBgn(unit[0], 2, unit_pad);
}
public static String To_str_new(Bry_bfr bfr, long val, int decimal_places) {To_bfr_new(bfr, val, decimal_places); return bfr.To_str_and_clear();}
public static void To_bfr_new(Bry_bfr bfr, long val, int decimal_places) {
// init
int unit_idx = 0;
int mult = 1024;
long cur_val = val;
long cur_exp = 1;
long nxt_exp = mult;
// get 1024 mult; EX: 1549 -> 1024
for (unit_idx = 0; unit_idx < 6; ++unit_idx) {
if (cur_val < nxt_exp) break;
cur_exp = nxt_exp;
nxt_exp *= mult;
}
// calc integer / decimal values
int int_val = (int)(val / cur_exp);
int dec_val = (int)(val % cur_exp);
if (decimal_places == 0) { // if 0 decimal places, round up
if (dec_val >= .5) ++int_val;
dec_val = 0;
}
else {// else, calculate decimal value as integer; EX: 549 -> .512 -> 512
long dec_factor = 0;
switch (decimal_places) {
case 1: dec_factor = 10; break;
case 2: dec_factor = 100; break;
default:
case 3: dec_factor = 1000; break;
}
dec_val = (int)((dec_val * dec_factor) / cur_exp);
}
// calc unit_str
String unit_str = "";
switch (unit_idx) {
case 0: unit_str = " B"; break;
case 1: unit_str = " KB"; break;
case 2: unit_str = " MB"; break;
case 3: unit_str = " GB"; break;
case 4: unit_str = " PB"; break;
case 5:
default: unit_str = " EB"; break;
}
// build String
bfr.Add_long_variable(int_val);
if (decimal_places > 0 && unit_idx != 0) {
bfr.Add_byte_dot();
bfr.Add_long_variable(dec_val);
}
bfr.Add_str_a7(unit_str);
}
public static long parse_or(String raw, long or) {
if (raw == null || raw == String_.Empty) return or;
String[] terms = String_.Split(raw, " ");

@ -56,6 +56,18 @@ public class Io_size__tst {
fxt.Test_Equals("1024 kb", "1 mb");
fxt.Test_Equals("1.5 kb", "1536 b");
}
@Test public void To_str_new___b___0() {fxt.Test__to_str_new( 0, 2, "0 B");}
@Test public void To_str_new___b___1() {fxt.Test__to_str_new( 1, 2, "1 B");}
@Test public void To_str_new__kb___1_501__1() {fxt.Test__to_str_new( 1538, 1, "1.5 KB");}
@Test public void To_str_new__kb___1_501__2() {fxt.Test__to_str_new( 1538, 2, "1.50 KB");}
@Test public void To_str_new__kb___1_501__3() {fxt.Test__to_str_new( 1538, 3, "1.501 KB");}
@Test public void To_str_new__kb___1_512__1() {fxt.Test__to_str_new( 1549, 1, "1.5 KB");}
@Test public void To_str_new__kb___1_512__2() {fxt.Test__to_str_new( 1549, 2, "1.51 KB");}
@Test public void To_str_new__kb___1_512__3() {fxt.Test__to_str_new( 1549, 3, "1.512 KB");}
@Test public void To_str_new__mb___1_512__1() {fxt.Test__to_str_new((1024 * 1024) + 536871, 1, "1.5 MB");}
@Test public void To_str_new__mb___1_512__2() {fxt.Test__to_str_new((1024 * 1024) + 536871, 2, "1.51 MB");}
@Test public void To_str_new__mb___1_512__3() {fxt.Test__to_str_new((1024 * 1024) + 536871, 3, "1.512 MB");}
@Test public void To_str_new__gb___1() {fxt.Test__to_str_new(1819264175, 2, "1.69 GB");}
}
class Io_size__fxt {
public void Test_XtoLong(String raw, long expd) {Tfds.Eq(expd, Io_size_.parse_or(raw, Long_.Min_value));}
@ -66,4 +78,8 @@ class Io_size__fxt {
public void Test_Equals(String lhs, String rhs) {Tfds.Eq(Io_size_.parse_or(lhs, Long_.Min_value), Io_size_.parse_or(rhs, Long_.Min_value));}
public void Test_XtoStr(long val, String expd) {Tfds.Eq(expd, Io_size_.To_str(val));}
public void Test_Xto_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1, String expd) {Tfds.Eq(expd, Io_size_.To_str(val, exp_1024, val_fmt, unit_pad, round_0_to_1));}
public void Test__to_str_new(long val, int decimal_places, String expd) {
Bry_bfr bfr = Bry_bfr.new_();
Tfds.Eq_str(expd, Io_size_.To_str_new(bfr, val, decimal_places));
}
}

@ -18,16 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
import gplx.core.threads.*; import gplx.core.progs.*;
public class Io_zip_decompress_task implements GfoInvkAble {
private Gfo_prog_ui prog_ui;
// private Gfo_prog_ui prog_ui;
private Io_url src_fil, trg_dir;
private boolean async;
private boolean canceled, paused;
private long src_fil_len = 0;
private long prog__cur = 0;
// private long src_fil_len = 0;
// private long prog__cur = 0;
private Io_zip_decompress_cmd cmd;
public Gfo_prog_task Prog__owner() {return Gfo_prog_task_.Null;}
public void Init(boolean async, Gfo_prog_ui prog_ui, Io_zip_decompress_cmd cmd, Io_url src_fil, Io_url trg_dir) {
this.async = async; this.cmd = cmd; this.prog_ui = prog_ui;
public void Init(boolean async, Io_zip_decompress_cmd cmd, Io_url src_fil, Io_url trg_dir) {
this.async = async; this.cmd = cmd; // this.prog_ui = prog_ui;
this.src_fil = src_fil; this.trg_dir = trg_dir;
}
public String Resume__entry() {return resume__entry;} private String resume__entry;
@ -35,7 +34,7 @@ public class Io_zip_decompress_task implements GfoInvkAble {
public boolean Canceled() {return canceled;}
public boolean Paused() {return paused;}
public void Prog__start() {
this.src_fil_len = Io_mgr.Instance.QueryFil(src_fil).Size();
// this.src_fil_len = Io_mgr.Instance.QueryFil(src_fil).Size();
this.resume__entry = null;
this.resume__bytes = 0;
// load resume
@ -43,8 +42,8 @@ public class Io_zip_decompress_task implements GfoInvkAble {
Thread_adp_.Run_cmd(async, "zip.decompress:" + src_fil.Raw(), this, Invk__unzip);
}
public byte Prog__update(long v) {
prog__cur += v;
prog_ui.Prog__update_val(prog__cur, src_fil_len);
// prog__cur += v;
// prog_ui.Prog__update_val(prog__cur, src_fil_len);
if (paused) return Status__paused;
else if (canceled) return Status__canceled;
else return Status__ok;
@ -66,7 +65,7 @@ public class Io_zip_decompress_task implements GfoInvkAble {
}
public void Unzip() {
cmd.Decompress__exec(this, src_fil, trg_dir);
prog_ui.Prog__end();
// prog_ui.Prog__end();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__unzip)) this.Unzip();

@ -17,6 +17,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs; import gplx.*; import gplx.core.*;
public interface Gfo_prog_ui {
void Prog__update_val(long cur, long max);
void Prog__end();
boolean Prog__started();
boolean Prog__paused();
boolean Prog__finished();
boolean Prog__canceled();
long Prog__cur();
long Prog__end();
void Prog__start();
void Prog__pause();
void Prog__resume();
void Prog__cancel();
byte Prog__notify__working(long cur, long max);
void Prog__notify__finished();
}

@ -15,7 +15,14 @@ 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.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_unzip_cbk {
void Unzip__end_itm(Gfo_unzip_itm itm);
package gplx.core.progs; import gplx.*; import gplx.core.*;
public class Gfo_prog_ui_ {
public static final byte State__inited = 0, State__started = 1, State__paused = 2, State__finished = 3, State__canceled = 4;
public static boolean Sleep_while_paused(Gfo_prog_ui prog_ui) {
while (true) {
gplx.core.threads.Thread_adp_.Sleep(100);
if (!prog_ui.Prog__paused()) return Bool_.Y;
else if (prog_ui.Prog__canceled()) return Bool_.N;
}
}
}

@ -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.core.progs; import gplx.*; import gplx.core.*;
public abstract class Gfo_prog_ui_base implements Gfo_prog_ui {
public boolean Prog__started() {return started;} private boolean started;
public boolean Prog__paused() {return paused;} private boolean paused;
public boolean Prog__finished() {return finished;} private boolean finished;
public boolean Prog__canceled() {return canceled;} private boolean canceled;
public long Prog__cur() {return cur;} private long cur;
public long Prog__end() {return end;} private long end; public void Prog__end_(long v) {this.end = v;}
public void Prog__start() {started = true;}
public void Prog__pause() {paused = true;}
public void Prog__resume() {paused = false;}
public void Prog__cancel() {canceled = true;}
@gplx.Virtual public void Prog__notify__finished() {
this.finished = true;
}
@gplx.Virtual public byte Prog__notify__working(long cur, long end) {
this.cur = cur; this.end = end;
if (paused) return Gfo_prog_ui_.State__paused;
else if (canceled) return Gfo_prog_ui_.State__canceled;
else return Gfo_prog_ui_.State__started;
}
}

@ -1,94 +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.core.security; import gplx.*; import gplx.core.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import gplx.core.consoles.*; import gplx.core.stores.*;
import gplx.core.ios.*; /*IoStream*/import gplx.core.texts.*; /*Base32Converter*/
public class HashAlgo_ {
public static final HashAlgo Null = new HashAlgo_null();
public static final HashAlgo Sha1 = HashAlgo_sha1.new_();
public static final HashAlgo Md5 = HashAlgo_md5.new_();
public static final HashAlgo Tth192 = HashAlgo_tth192.new_();
public static HashAlgo as_(Object obj) {return obj instanceof HashAlgo ? (HashAlgo)obj : null;}
public static HashAlgo cast(Object obj) {if (obj == null) return null; HashAlgo rv = as_(obj); if (rv == null) throw Err_.new_type_mismatch(HashAlgo.class, obj); return rv;}
public static HashAlgo fetch_(String key) {
if (key == HashAlgo_md5.KEY) return Md5;
else if (key == HashAlgo_sha1.KEY) return Sha1;
else if (key == HashAlgo_tth192.KEY) return Tth192;
else throw Err_.new_unhandled(key);
}
public static HashAlgo store_orSelf_(SrlMgr mgr, String key, HashAlgo or) {
String algoType = mgr.SrlStrOr(key, or.Key());
return mgr.Type_rdr() ? HashAlgo_.fetch_(algoType): or;
}
}
class HashAlgo_null implements HashAlgo {
public String Key() {return "HashAlgo_null";}
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return "NullAlgoHash";}
}
class HashAlgo_md5 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "md5";
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "MD5");}
public static HashAlgo_md5 new_() {return new HashAlgo_md5();} HashAlgo_md5() {}
}
class HashAlgo_sha1 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "sha1";
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "SHA1");}
public static HashAlgo_sha1 new_() {return new HashAlgo_sha1();} HashAlgo_sha1() {}
}
class HashAlgoUtl {
public static String CalcHashAsString(Console_adp dialog, IoStream stream, String key) {
MessageDigest md = null;
try {md = MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
byte[] buffer = new byte[8192];
int read = 0;
long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
while (true) {
read = stream.Read(buffer, 0, 8192);
if (pos >= len) break;
md.update(buffer, 0, read);
pos += read;
}
byte[] md5sum = md.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String rv = bigInt.toString(16);
int rvLen = rv.length();
while (rvLen < 32) {
rv = "0" + rv;
rvLen++;
}
return rv;
}
public static String XtoStrBase16(byte[] ary) {
BigInteger bigInt = new BigInteger(1, ary);
String rv = bigInt.toString(16);
int rvLen = rv.length();
while (rvLen < 32) {
rv = "0" + rv;
rvLen++;
}
return rv;
}
public static String XtoStrBase32(byte[] ary) {return Base32Converter.Encode(ary);}
}

@ -1,81 +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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class HashAlgo_md5_tst {
@Test public void Empty() {
tst_CalcBase16FromString("", "d41d8cd98f00b204e9800998ecf8427e");
}
@Test public void A() {
tst_CalcBase16FromString("a", "0cc175b9c0f1b6a831c399e269772661");
}
@Test public void Abc() {
tst_CalcBase16FromString("abc", "900150983cd24fb0d6963f7d28e17f72");
}
@Test public void A_Za_z0_9() {
tst_CalcBase16FromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f");
}
//@Test
public void A_1Million() {
tst_CalcBase16FromString(String_.Repeat("a", 1000000), "7707d6ae4e027c70eea2a935c2296f21");
}
void tst_CalcBase16FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Md5.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
/*
https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
Set 1, vector# 0:
message="" (empty String)
hash=D41D8CD98F00B204E9800998ECF8427E
Set 1, vector# 1:
message="a"
hash=0CC175B9C0F1B6A831C399E269772661
Set 1, vector# 2:
message="abc"
hash=900150983CD24FB0D6963F7D28E17F72
Set 1, vector# 3:
message="message digest"
hash=F96B697D7CB7938D525A2F31AAF161D0
Set 1, vector# 4:
message="abcdefghijklmnopqrstuvwxyz"
hash=C3FCD3D76192E4007DFB496CCA67E13B
Set 1, vector# 5:
message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
hash=8215EF0796A20BCAAAE116D3876C664A
Set 1, vector# 6:
message="A...Za...z0...9"
hash=D174AB98D277D9F5A5611C2C9F419D9F
Set 1, vector# 7:
message=8 times "1234567890"
hash=57EDF4A22BE3C955AC49DA2E2107B67A
Set 1, vector# 8:
message=1 million times "a"
hash=7707D6AE4E027C70EEA2A935C2296F21
*/
}

@ -1,81 +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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class HashAlgo_sha1_tst {
@Test public void Empty() {
tst_CalcBase16FromString("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
}
@Test public void A() {
tst_CalcBase16FromString("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
}
@Test public void Abc() {
tst_CalcBase16FromString("abc", "a9993e364706816aba3e25717850c26c9cd0d89d");
}
@Test public void A_Za_z0_9() {
tst_CalcBase16FromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "761c457bf73b14d27e9e9265c46f4b4dda11f940");
}
//@Test
public void A_1Million() {
tst_CalcBase16FromString(String_.Repeat("a", 1000000), "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
}
void tst_CalcBase16FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Sha1.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
/*
https://www.cosic.esat.kuleuven.be/nessie/testvectors/
Set 1, vector# 0:
message="" (empty String)
hash=DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
Set 1, vector# 1:
message="a"
hash=86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8
Set 1, vector# 2:
message="abc"
hash=A9993E364706816ABA3E25717850C26C9CD0D89D
Set 1, vector# 3:
message="message digest"
hash=C12252CEDA8BE8994D5FA0290A47231C1D16AAE3
Set 1, vector# 4:
message="abcdefghijklmnopqrstuvwxyz"
hash=32D10C7B8CF96570CA04CE37F2A19D84240D3A89
Set 1, vector# 5:
message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
hash=84983E441C3BD26EBAAE4AA1F95129E5E54670F1
Set 1, vector# 6:
message="A...Za...z0...9"
hash=761C457BF73B14D27E9E9265C46F4B4DDA11F940
Set 1, vector# 7:
message=8 times "1234567890"
hash=50ABF5706A150990A08B2C5EA40FA0E585554732
Set 1, vector# 8:
message=1 million times "a"
hash=34AA973CD4C4DAA4F61EEB2BDBAD27316534016F
*/
}

@ -1,58 +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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class HashAlgo_tth192_tst {
@Test public void Char0000() {tst_CalcBase32FromString("", "LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ");}
@Test public void Char0001() {tst_CalcBase32FromString("\0", "VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA");}
@Test public void Char0002() {tst_CalcBase32FromString("ab", "XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ");}
@Test public void Char0003() {tst_CalcBase32FromString("abc", "ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA");}
@Test public void Char0004() {tst_CalcBase32FromString("abcd", "SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI");}
@Test public void Char0005() {tst_CalcBase32FromString("abcde", "SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ");}
@Test public void Char0009() {tst_CalcBase32FromString("abcdefghi", "RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY");}
@Test public void Char1024() {tst_CalcBase32FromString(String_.Repeat("A", 1024), "L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA");}
@Test public void Char1025() {tst_CalcBase32FromString(String_.Repeat("A", 1025), "PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY");}
// @Test // commented out due to time (approx 17.94 seconds)
public void Ax2Pow27() { // 134 MB
tst_CalcBase32FromString(String_.Repeat("A", (int)Math_.Pow(2, 27)), "QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ");
}
void tst_CalcBase32FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Tth192.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
}
/*
The empty (zero-length) file:
urn:tree:tiger:LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ
A file with a single zero byte:
urn:tree:tiger:VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA
A file with 1024 'A' characters:
urn:tree:tiger:L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA
A file with 1025 'A' characters:
urn:tree:tiger:PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY
http://open-content.net/specs/draft-jchapweske-thex-02.html
A file with 134,217,728 'A' characters (2 Pow 27)
urn:tree:tiger:QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ
queried against DC++ 0.698
*/

@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
public interface Hash_algo {
String Key();
byte[] Hash_bry_as_bry(byte[] src);
String Hash_bry_as_str(byte[] src);
String Hash_stream_as_str(gplx.core.consoles.Console_adp console, gplx.core.ios.IoStream src_stream);
byte[] Hash_stream_as_bry(gplx.core.progs.Gfo_prog_ui prog_ui, gplx.core.ios.IoStream src_stream);
}

@ -0,0 +1,140 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
import gplx.core.texts.*; /*Base32Converter*/ import gplx.core.progs.*;
public class Hash_algo_ {
public static Hash_algo New__md5() {return new Hash_algo__md5();}
public static Hash_algo New__sha1() {return new Hash_algo__sha1();}
public static Hash_algo New__sha2_256() {return new Hash_algo__sha2_256();}
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
public static Hash_algo New(String key) {
if (key == Hash_algo__md5.KEY) return New__md5();
else if (key == Hash_algo__sha1.KEY) return New__sha1();
else if (key == Hash_algo__sha2_256.KEY) return New__sha2_256();
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
else throw Err_.new_unhandled(key);
}
}
abstract class Hash_algo_base implements Hash_algo {
private final MessageDigest md;
private final byte[] trg_bry;
private byte[] tmp_bfr; private final int tmp_bfr_len = 4096;
public Hash_algo_base(MessageDigest md, int trg_bry_len) {
this.md = md; this.trg_bry = new byte[trg_bry_len];
}
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] Hash_bry_as_bry(byte[] src) {
Hash_algo_utl_.Hash_bry(md, src, src.length, trg_bry);
return Bry_.Copy(trg_bry); // NOTE: must copy to return different instances to callers; else callers may hash same instance with different values
}
public String Hash_stream_as_str(Console_adp console, IoStream stream) {return String_.new_a7(Hash_stream_as_bry(console, stream));}
public byte[] Hash_stream_as_bry(Console_adp console, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(console, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(prog_ui, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
protected static MessageDigest Get_message_digest(String key) {
try {return MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
}
}
class Hash_algo__md5 extends Hash_algo_base {
public Hash_algo__md5() {super(Get_message_digest_instance(), 32);}
public String Key() {return KEY;} public static final String KEY = "md5";
private static MessageDigest Get_message_digest_instance() {
if (md__md5 == null)
md__md5 = Get_message_digest(KEY);
return md__md5;
} private static MessageDigest md__md5;
}
class Hash_algo__sha1 extends Hash_algo_base {
public Hash_algo__sha1() {super(Get_message_digest_instance(), 40);}
public String Key() {return KEY;} public static final String KEY = "sha1";
private static MessageDigest Get_message_digest_instance() {
if (md__sha1 == null)
md__sha1 = Get_message_digest(KEY);
return md__sha1;
} private static MessageDigest md__sha1;
}
class Hash_algo__sha2_256 extends Hash_algo_base {
public Hash_algo__sha2_256() {super(Get_message_digest_instance(), 64);}
public String Key() {return KEY;} public static final String KEY = "sha-256";
private static MessageDigest Get_message_digest_instance() {
if (md__sha2_256 == null)
md__sha2_256 = Get_message_digest(KEY);
return md__sha2_256;
} private static MessageDigest md__sha2_256;
}
class Hash_algo_utl_ {
public static void Hash_bry(MessageDigest md, byte[] src_bry, int src_len, byte[] trg_bry) {
int pos = 0;
while (true) {
if (pos == src_len) break;
int end = pos + 4096;
if (end > src_len) end = src_len;
md.update(src_bry, pos, end);
pos = end;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry, trg_bry);
}
public static void Hash_stream(Console_adp dialog, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
// long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
// pos += read;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static void Hash_stream(Gfo_prog_ui prog_ui, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
try {
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
switch (prog_ui.Prog__notify__working(pos, len)) {
case Gfo_prog_ui_.State__started: break;
case Gfo_prog_ui_.State__canceled: return;
case Gfo_prog_ui_.State__paused: if (!Gfo_prog_ui_.Sleep_while_paused(prog_ui)) return; break;
}
pos += read;
}
}
finally {stream.Rls();}
prog_ui.Prog__notify__finished();
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static String To_base_32_str(byte[] ary) {return Base32Converter.Encode(ary);}
}

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5());
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
@Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");}
@Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");}
@Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
//@Test
public void Num__x_8() {fxt.Test__hash("57edf4a22be3c955ac49da2e2107b67a", String_.Repeat("1234567890", 8));}
//@Test
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
}
class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw)));
Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.IoStream_.mem_txt_(Io_url_.Empty, raw)));
}
}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1());
@Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");}
@Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");}
@Test public void abc() {fxt.Test__hash("a9993e364706816aba3e25717850c26c9cd0d89d", "abc");}
@Test public void message_digest() {fxt.Test__hash("c12252ceda8be8994d5fa0290a47231c1d16aae3", "message digest");}
@Test public void a_z() {fxt.Test__hash("32d10c7b8cf96570ca04ce37f2a19d84240d3a89", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("84983e441c3bd26ebaae4aa1f95129e5e54670f1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("761c457bf73b14d27e9e9265c46f4b4dda11f940", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
// @Test
public void Num() {fxt.Test__hash("50abf5706a150990a08b2c5ea40fa0e585554732", String_.Repeat("1234567890", 8));}
//@Test
public void A_1Million() {fxt.Test__hash("34aa973cd4c4daa4f61eeb2bdbad27316534016f", String_.Repeat("a", 1000000));}
}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256());
@Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");}
@Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");}
@Test public void abc() {fxt.Test__hash("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");}
@Test public void message_digest() {fxt.Test__hash("f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650", "message digest");}
@Test public void a_z() {fxt.Test__hash("71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
// @Test
public void Num() {fxt.Test__hash("f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e", String_.Repeat("1234567890", 8));}
//@Test
public void A_1Million() {fxt.Test__hash("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0", String_.Repeat("a", 1000000));}
}

@ -16,13 +16,15 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import gplx.core.consoles.*;
import gplx.core.ios.*; /*IoStream*/
public class HashAlgo_tth192 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "tth192";
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
import gplx.core.progs.*;
public class Hash_algo__tth_192 implements Hash_algo {
public String Key() {return KEY;} public static final String KEY = "tth192";
public int BlockSize() {return blockSize;} public void BlockSize_set(int v) {blockSize = v;} int blockSize = 1024;
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] Hash_bry_as_bry(byte[] v) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(v)));}
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, stream));}
public String Hash_stream_as_str(Console_adp dialog, IoStream stream) {
int leafCount = (int)(stream.Len() / blockSize);
HashDlgWtr dialogWtr = HashDlgWtr_.Current;
dialogWtr.Bgn(dialog, stream.Url(), CalcWorkUnits(stream.Len()));
@ -35,7 +37,7 @@ public class HashAlgo_tth192 implements HashAlgo {
hashMainCount = 0;
HashAllBytes(dialogWtr, stream, leafCount);
byte[] rv = HashAllHashes(dialogWtr);
return HashAlgoUtl.XtoStrBase32(rv);
return Hash_algo_utl_.To_base_32_str(rv);
}
byte[] CalcHash_next(IoStream stream) {
if (blockA == null || blockA.length != blockSize) blockA = new byte[blockSize];
@ -133,7 +135,6 @@ public class HashAlgo_tth192 implements HashAlgo {
Tiger192 algo = new Tiger192();
byte[][] hashMain; int hashMainCount = 0;
byte[] blockA, blockB, branchRv, leaf0, leaf1;
public static HashAlgo_tth192 new_() {return new HashAlgo_tth192();} HashAlgo_tth192() {}
}
interface HashDlgWtr {
boolean Canceled();

@ -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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());
@Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");}
@Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");}
@Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");}
@Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");}
@Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");}
@Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");}
@Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");}
// @Test
public void a__x_1024() {fxt.Test__hash("L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA", String_.Repeat("A", 1024));}
// @Test
public void a__x_1025() {fxt.Test__hash("PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY", String_.Repeat("A", 1025));}
// @Test
public void A__Pow27() {fxt.Test__hash("QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ", String_.Repeat("A", (int)Math_.Pow(2, 27)));
}
}

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class HashAlgo_tth192_tree_tst {
public class Hash_algo__tth_192_tree_tst {
@Test public void CalcRecursiveHalves() {
tst_CalcRecursiveHalves(129, 128);
tst_CalcRecursiveHalves(128, 127);
@ -42,7 +42,7 @@ public class HashAlgo_tth192_tree_tst {
tst_CalcWorkUnits(0, 1);
}
void tst_CalcWorkUnits(int length, int expd) {
HashAlgo_tth192 algo = HashAlgo_tth192.new_(); algo.BlockSize_set(10);
Hash_algo__tth_192 algo = new Hash_algo__tth_192(); algo.BlockSize_set(10);
int actl = algo.CalcWorkUnits(length);
Tfds.Eq(expd, actl);
}

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class HashDlgWtr_tst {
public class Hash_console_wtr_tst {
@Before public void setup() {
HashAlgo_tth192 algo = HashAlgo_tth192.new_();
Hash_algo__tth_192 algo = new Hash_algo__tth_192();
algo.BlockSize_set(10);
calc = algo;
}
@ -32,10 +32,10 @@ public class HashDlgWtr_tst {
Console_adp__mem dialog = Console_adp_.Dev();
String data = String_.Repeat("A", count);
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data);
calc.CalcHash(dialog, stream);
calc.Hash_stream_as_str(dialog, stream);
String[] actlWritten = dialog.Written().To_str_ary();
Tfds.Eq_ary(actlWritten, expdWritten);
}
String[] stringAry_(String... ary) {return ary;}
HashAlgo calc;
Hash_algo calc;
}

@ -45,10 +45,10 @@ public class PerfLogMgr_fxt {
entries.Clear();
}
List_adp entries = List_adp_.new_(); PerfLogTmr tmr = PerfLogTmr.new_(); Io_url url = Io_url_.Empty;
public static final PerfLogMgr_fxt Instance = new PerfLogMgr_fxt(); PerfLogMgr_fxt() {}
public static final PerfLogMgr_fxt Instance = new PerfLogMgr_fxt(); PerfLogMgr_fxt() {}
class PerfLogItm {
public String To_str() {
String secondsStr = TimeSpanAdp_.To_str(milliseconds, TimeSpanAdp_.Fmt_Default);
String secondsStr = Time_span_.To_str(milliseconds, Time_span_.Fmt_Default);
secondsStr = String_.PadBgn(secondsStr, 7, "0"); // 7=000.000; left-aligns all times
return String_.Concat(secondsStr, "|", text);
}

@ -1,63 +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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*;
public class HexDecUtl_tst {
@Test public void XtoInt() {
tst_XtoInt("0", 0);
tst_XtoInt("F", 15);
tst_XtoInt("0F", 15);
tst_XtoInt("10", 16);
tst_XtoInt("20", 32);
tst_XtoInt("FF", 255);
tst_XtoInt("100", 256);
tst_XtoInt("0a", 10);
tst_XtoInt("7FFFFFFF", Int_.Max_value);
tst_XtoInt_bry("100", 256);
}
@Test public void To_str() {
tst_XtoStr(0, "0");
tst_XtoStr(15, "F");
tst_XtoStr(16, "10");
tst_XtoStr(32, "20");
tst_XtoStr(255, "FF");
tst_XtoStr(Int_.Max_value, "7FFFFFFF");
tst_XtoStr(15, 2, "0F");
tst_XtoStr(15, 3, "00F");
}
@Test public void Write() {
tst_Write("[00000000]", 1, 9, 15, "[0000000F]");
tst_Write("[00000000]", 1, 9, 255, "[000000FF]");
}
private void tst_Write(String s, int bgn, int end, int val, String expd) {
byte[] bry = Bry_.new_a7(s);
HexDecUtl.Write(bry, bgn, end, val);
Tfds.Eq(expd, String_.new_a7(bry));
}
private void tst_XtoInt(String raw, int expd) {
int actl = HexDecUtl.parse(raw);
Tfds.Eq(expd, actl);
}
private void tst_XtoInt_bry(String raw, int expd) {Tfds.Eq(expd, HexDecUtl.parse_or(Bry_.new_a7(raw), -1));}
private void tst_XtoStr(int val, String expd) {tst_XtoStr(val, 0, expd);}
private void tst_XtoStr(int val, int pad, String expd) {
String actl = HexDecUtl.To_str(val, pad);
Tfds.Eq(expd, actl);
}
}

@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp__basic_tst {
public class Time_span__basic_tst {
@Test public void seconds_() {
TimeSpanAdp expd = TimeSpanAdp_.fracs_(123987);
TimeSpanAdp actl = TimeSpanAdp_.seconds_(123.987);
Time_span expd = Time_span_.fracs_(123987);
Time_span actl = Time_span_.seconds_(123.987);
Tfds.Eq(expd, actl);
}
@Test public void TotalSecs() {
TimeSpanAdp val = TimeSpanAdp_.fracs_(1987);
Time_span val = Time_span_.fracs_(1987);
Tfds.Eq_decimal(Decimal_adp_.parts_(1, 987), val.TotalSecs());
}
@Test public void Units() {
@ -34,17 +34,17 @@ public class TimeSpanAdp__basic_tst {
tst_Units("02:00.987", 0, 2, 0, 987);
}
@Test public void Add() {
TimeSpanAdp val = TimeSpanAdp_.fracs_(3);
TimeSpanAdp arg = TimeSpanAdp_.fracs_(2);
TimeSpanAdp expd = TimeSpanAdp_.fracs_(5);
TimeSpanAdp actl = val.Add(arg);
Time_span val = Time_span_.fracs_(3);
Time_span arg = Time_span_.fracs_(2);
Time_span expd = Time_span_.fracs_(5);
Time_span actl = val.Add(arg);
Tfds.Eq(expd, actl);
}
@Test public void Subtract() {
TimeSpanAdp val = TimeSpanAdp_.fracs_(3);
TimeSpanAdp arg = TimeSpanAdp_.fracs_(2);
TimeSpanAdp expd = TimeSpanAdp_.fracs_(1);
TimeSpanAdp actl = val.Subtract(arg);
Time_span val = Time_span_.fracs_(3);
Time_span arg = Time_span_.fracs_(2);
Time_span expd = Time_span_.fracs_(1);
Time_span actl = val.Subtract(arg);
Tfds.Eq(expd, actl);
}
@Test public void Add_unit_identity() {
@ -68,17 +68,17 @@ public class TimeSpanAdp__basic_tst {
tst_XtoStrUiAbbrv("00:00:03.000", "3s 0f");
tst_XtoStrUiAbbrv("11:22:33.444", "11h 22m 33s 444f");
tst_XtoStrUiAbbrv("00:00:00.000", "0f");
} void tst_XtoStrUiAbbrv(String raw, String expd) {Tfds.Eq(expd, TimeSpanAdp_.parse(raw).XtoStrUiAbbrv());}
} void tst_XtoStrUiAbbrv(String raw, String expd) {Tfds.Eq(expd, Time_span_.parse(raw).XtoStrUiAbbrv());}
void tst_AddUnit(String valRaw, int unitIdx, int delta, String expdRaw) {
TimeSpanAdp val = TimeSpanAdp_.parse(valRaw);
TimeSpanAdp actl = val.Add_unit(unitIdx, delta);
Tfds.Eq(TimeSpanAdp_.parse(expdRaw), actl);
Time_span val = Time_span_.parse(valRaw);
Time_span actl = val.Add_unit(unitIdx, delta);
Tfds.Eq(Time_span_.parse(expdRaw), actl);
}
void tst_Units(String text, int... expd) {
TimeSpanAdp val = TimeSpanAdp_.parse(text);
Time_span val = Time_span_.parse(text);
int hour = 0, min = 0, sec = 0, frac = 0;
int[] ary = val.Units();
hour = ary[TimeSpanAdp_.Idx_Hour]; min = ary[TimeSpanAdp_.Idx_Min]; sec = ary[TimeSpanAdp_.Idx_Sec]; frac = ary[TimeSpanAdp_.Idx_Frac];
hour = ary[Time_span_.Idx_Hour]; min = ary[Time_span_.Idx_Min]; sec = ary[Time_span_.Idx_Sec]; frac = ary[Time_span_.Idx_Frac];
Tfds.Eq(expd[0], hour);
Tfds.Eq(expd[1], min);
Tfds.Eq(expd[2], sec);

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp__parse_tst {
public class Time_span__parse_tst {
@Test public void Zero() {
tst_Parse("0", 0);
}
@ -48,7 +48,7 @@ public class TimeSpanAdp__parse_tst {
tst_Parse(" 01 : 02 : 03 . 987", 3723987); // whitespace
}
void tst_Parse(String text, long expd) {
TimeSpanAdp val = TimeSpanAdp_.parse(text);
Time_span val = Time_span_.parse(text);
Tfds.Eq(expd, val.Fracs());
}
}

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp__to_str_tst {
public class Time_span__to_str_tst {
@Test public void Zero() {
tst_Default(0, "0");
}
@ -47,13 +47,13 @@ public class TimeSpanAdp__to_str_tst {
tst_ZeroPadding("2:01.456", "00:02:01.456");
}
void tst_Default(long fractionals, String expd) {
TimeSpanAdp ts = TimeSpanAdp_.fracs_(fractionals);
String actl = ts.To_str(TimeSpanAdp_.Fmt_Default);
Time_span ts = Time_span_.fracs_(fractionals);
String actl = ts.To_str(Time_span_.Fmt_Default);
Tfds.Eq(expd, actl);
}
void tst_ZeroPadding(String val, String expd) {
TimeSpanAdp timeSpan = TimeSpanAdp_.parse(val);
String actl = timeSpan.To_str(TimeSpanAdp_.Fmt_PadZeros);
Time_span timeSpan = Time_span_.parse(val);
String actl = timeSpan.To_str(Time_span_.Fmt_PadZeros);
Tfds.Eq(expd, actl);
}
}

@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.type_xtns; import gplx.*; import gplx.core.*;
public class TimeSpanAdpClassXtn extends ClassXtn_base implements ClassXtn {
public String Key() {return Key_const;} public static final String Key_const = "timeSpan";
@Override public Class<?> UnderClass() {return TimeSpanAdp.class;}
public Object DefaultValue() {return TimeSpanAdp_.Zero;}
@Override public Object ParseOrNull(String raw) {return TimeSpanAdp_.parse(raw);}
@Override public Object XtoDb(Object obj) {return TimeSpanAdp_.cast(obj).TotalSecs();}
@Override public String XtoUi(Object obj, String fmt) {return TimeSpanAdp_.cast(obj).To_str(fmt);}
public boolean Eq(Object lhs, Object rhs) {try {return TimeSpanAdp_.cast(lhs).Eq(rhs);} catch (Exception e) {Err_.Noop(e); return false;}}
public static final TimeSpanAdpClassXtn Instance = new TimeSpanAdpClassXtn(); TimeSpanAdpClassXtn() {} // added to ClassXtnPool by default
public String Key() {return Key_const;} public static final String Key_const = "timeSpan";
@Override public Class<?> UnderClass() {return Time_span.class;}
public Object DefaultValue() {return Time_span_.Zero;}
@Override public Object ParseOrNull(String raw) {return Time_span_.parse(raw);}
@Override public Object XtoDb(Object obj) {return Time_span_.cast(obj).TotalSecs();}
@Override public String XtoUi(Object obj, String fmt) {return Time_span_.cast(obj).To_str(fmt);}
public boolean Eq(Object lhs, Object rhs) {try {return Time_span_.cast(lhs).Eq(rhs);} catch (Exception e) {Err_.Noop(e); return false;}}
public static final TimeSpanAdpClassXtn Instance = new TimeSpanAdpClassXtn(); TimeSpanAdpClassXtn() {} // added to ClassXtnPool by default
}

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*; import gplx.core.texts.*;
import gplx.core.strings.*; import gplx.core.encoders.*;
public class ColorAdp {
public int Value() {return val;} int val;
public int Alpha() {return (255 & val >> 24);}
@ -26,10 +26,10 @@ public class ColorAdp {
public String XtoHexStr() {
String_bldr sb = String_bldr_.new_();
sb.Add("#");
sb.Add(HexDecUtl.To_str(Alpha(), 2));
sb.Add(HexDecUtl.To_str(Red(), 2));
sb.Add(HexDecUtl.To_str(Green(), 2));
sb.Add(HexDecUtl.To_str(Blue(), 2));
sb.Add(Hex_utl_.To_str(Alpha(), 2));
sb.Add(Hex_utl_.To_str(Red(), 2));
sb.Add(Hex_utl_.To_str(Green(), 2));
sb.Add(Hex_utl_.To_str(Blue(), 2));
return sb.To_str();
}
public boolean Eq(Object obj) {
@ -52,5 +52,5 @@ class ColorAdpCache {
return (java.awt.Color)rv;
}
Hash_adp hash = Hash_adp_.new_();
public static final ColorAdpCache Instance = new ColorAdpCache(); ColorAdpCache() {}
public static final ColorAdpCache Instance = new ColorAdpCache(); ColorAdpCache() {}
}

@ -16,12 +16,12 @@ 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.gfui; import gplx.*;
import gplx.core.texts.*; import gplx.core.interfaces.*;
import gplx.core.encoders.*; import gplx.core.interfaces.*;
public class ColorAdp_ implements ParseAble {
public static ColorAdp as_(Object obj) {return obj instanceof ColorAdp ? (ColorAdp)obj : null;}
public static ColorAdp cast(Object obj) {try {return (ColorAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, ColorAdp.class, obj);}}
public static ColorAdp new_(int a, int r, int g, int b) {return ColorAdp.new_((int)a, (int)r, (int)g, (int)b);}
public static final ColorAdp_ Parser = new ColorAdp_();
public static final ColorAdp_ Parser = new ColorAdp_();
public Object ParseAsObj(String raw) {return ColorAdp_.parse(raw);}
public static ColorAdp parseOr_(String raw, ColorAdp or) {
ColorAdp rv = parse_internal_(raw); if (rv == null) return or;
@ -63,7 +63,7 @@ public class ColorAdp_ implements ParseAble {
int rawLen = String_.Len(raw);
for (int i = 1; i < rawLen; i += 2) { // fill ARGB ary by parsing raw 2 at a time; EX: #FFFFFFFF -> 255,255,255,255; NOTE: start at 1 to ignore leading #
String hexStr = String_.MidByLen(raw, i, 2);
ary[idx++] = HexDecUtl.parse(hexStr);
ary[idx++] = Hex_utl_.Parse(hexStr);
}
return ColorAdp.new_(ary[0], ary[1], ary[2], ary[3]);
} catch (Exception exc) {throw Err_.new_parse_exc(exc, ColorAdp.class, raw);}
@ -95,7 +95,7 @@ public class ColorAdp_ implements ParseAble {
return ColorAdp.new_(a, r, g, b);
}
public static ColorAdp read_(Object o) {String s = String_.as_(o); return s != null ? ColorAdp_.parse(s) : ColorAdp_.cast(o);}
public static final ColorAdp
public static final ColorAdp
Null = new_( 0, 0, 0, 0)
, Black = new_(255, 0, 0, 0)
, White = new_(255, 255, 255, 255)

@ -25,6 +25,7 @@ public interface Gxw_html extends GxwElem {
boolean Html_js_eval_proc_as_bool (String name, Object... args);
String Html_js_eval_script (String script);
void Html_js_cbks_add (String js_func_name, GfoInvkAble invk);
String Html_js_send_json (String name, String data);
void Html_invk_src_(GfoEvObj v);
void Html_dispose();
}

@ -26,6 +26,7 @@ public class Gfui_html extends GfuiElemBase {
@gplx.Virtual public String Html_js_eval_proc_as_str(String name, Object... args) {return under.Html_js_eval_proc_as_str(name, args);}
@gplx.Virtual public boolean Html_js_eval_proc_as_bool(String name, Object... args) {return under.Html_js_eval_proc_as_bool(name, args);}
public String Html_js_eval_script(String script) {return under.Html_js_eval_script(script);}
public String Html_js_send_json(String name, String data) {return under.Html_js_send_json(name, data);}
public void Html_js_cbks_add(String js_func_name, GfoInvkAble invk) {under.Html_js_cbks_add(js_func_name, invk);}
public void Html_invk_src_(GfoEvObj v) {under.Html_invk_src_(v);}
public void Html_dispose() {under.Html_dispose();}

@ -31,6 +31,7 @@ class Mem_html extends GxwTextMemo_lang implements Gxw_html { public void Html_
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
public String Html_js_eval_script(String script) {return "";}
public String Html_js_send_json(String name, String data) {return "";}
String ExtractAtr(String key, String txt, int pos) {
int key_pos = String_.FindBwd(txt, key, pos); if (key_pos == String_.Find_none) return null;
int q0 = String_.FindFwd(txt, "\"", key_pos); if (q0 == String_.Find_none) return null;

@ -318,6 +318,7 @@ class Swt_kit_mode {
class Swt_gui_cmd implements GfuiInvkCmd, Runnable {
private final Swt_kit kit; private final Gfo_usr_dlg usr_dlg; private final Display display; private final GfoInvkAble target; private final boolean async;
private GfsCtx invk_ctx; private int invk_ikey; private String invk_key; private GfoMsg invk_msg;
private Object rv_obj;
public Swt_gui_cmd(Swt_kit kit, Gfo_usr_dlg usr_dlg, Display display, GfoInvkAble target, boolean async) {
this.kit = kit; this.usr_dlg = usr_dlg; this.display = display; this.target = target; this.async = async;
}
@ -330,11 +331,11 @@ class Swt_gui_cmd implements GfuiInvkCmd, Runnable {
try {display.syncExec(this);}
finally {kit.Kit_sync_cmd_del(this);}
}
return this;
return rv_obj;
}
@Override public void run() {
synchronized (this) {// needed for Special:Search and async; DATE:2015-04-23
try {target.Invk(invk_ctx, invk_ikey, invk_key, invk_msg);}
try {rv_obj = target.Invk(invk_ctx, invk_ikey, invk_key, invk_msg);}
catch (Exception e) {
if (kit.Kit_mode__term()) return; // NOTE: if shutting down, don't warn; warn will try to write to status.bar, which will fail b/c SWT is shutting down; failures will try to write to status.bar again, causing StackOverflow exception; DATE:2014-05-04
usr_dlg.Warn_many("", "", "fatal error while running; key=~{0} err=~{1}", invk_key, Err_.Message_gplx_full(e));

@ -39,8 +39,9 @@ public class ImageAdp_tst {
DateAdp afterModifiedTime = Io_mgr.Instance.QueryFil(save).ModifiedTime();
Tfds.Eq_true(CompareAble_.Is_more(afterModifiedTime, beforeModifiedTime));
String loadHash = HashAlgo_.Md5.CalcHash(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load));
String saveHash = HashAlgo_.Md5.CalcHash(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(save));
Hash_algo algo = Hash_algo_.New__md5();
String loadHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load));
String saveHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(save));
Tfds.Eq(loadHash, saveHash);
}
}

@ -79,6 +79,10 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);}
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.cast(Html_js_eval_proc_as_obj(proc, args));}
public String Html_js_eval_proc_as_str(String proc, Object... args) {return Object_.Xto_str_strict_or_null(Html_js_eval_proc_as_obj(proc, args));}
public String Html_js_send_json(String name, String data) {
String script = String_.Format("return {0}('{1}');", name, String_.Replace(data, "\n", "") );
return (String)Eval_script(script);
}
private Object Html_js_eval_proc_as_obj(String proc, Object... args) {
Bry_bfr bfr = Bry_bfr.new_();
bfr.Add_str_a7("return ").Add_str_u8(proc).Add_byte(Byte_ascii.Paren_bgn);

@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_ary extends Gfobj_grp {
byte Ary_tid();
int Len();
}
class Gfo_ary_str implements Gfobj_ary {
public Gfo_ary_str(String[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__str;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public String[] Ary_str() {return ary;} private final String[] ary;
}
class Gfo_ary_int implements Gfobj_ary {
public Gfo_ary_int(int[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__int;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public int[] Ary_int() {return ary;} private final int[] ary;
}
class Gfo_ary_ary implements Gfobj_ary {
public Gfo_ary_ary(Gfobj_ary[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__ary;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public Gfobj_ary[] Ary_ary() {return ary;} private Gfobj_ary[] ary;
}

@ -15,13 +15,12 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs; import gplx.*; import gplx.core.*;
public interface Gfo_prog_task {
Gfo_prog_task Prog__owner();
long Prog__all();
long Prog__cur();
void Prog__start();
void Prog__cancel();
void Prog__pause();
void Prog__resume();
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public class Gfobj_ary_ {
public static final byte
Ary_tid__ary = 0
, Ary_tid__nde = 1
, Ary_tid__str = 2
, Ary_tid__int = 3
;
}

@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public class Gfobj_ary_nde implements Gfobj_ary {
public Gfobj_ary_nde(Gfobj_nde[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__nde;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public Gfobj_nde[] Ary_nde() {return ary;} private Gfobj_nde[] ary;
public void Ary_nde_(Gfobj_nde[] v) {this.ary = v;}
}

@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_fld {
byte Fld_tid();
String Key();
Object As_obj();
}
class Gfobj_fld_ {
public static final byte
Fld_tid__ary = 0
, Fld_tid__nde = 1
, Fld_tid__int = 2
, Fld_tid__long = 3
, Fld_tid__str = 4
;
}
class Gfobj_fld_str implements Gfobj_fld {
public Gfobj_fld_str(String key, String val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__str;}
public Object As_obj() {return val;}
public String As_str() {return val;} private String val;
}
class Gfobj_fld_int implements Gfobj_fld {
public Gfobj_fld_int(String key, int val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__int;}
public Object As_obj() {return val;}
public int As_int() {return val;} private int val;
}
class Gfobj_fld_long implements Gfobj_fld {
public Gfobj_fld_long(String key, long val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__long;}
public Object As_obj() {return val;}
public long As_long() {return val;} private long val;
}
class Gfobj_fld_nde implements Gfobj_fld {
public Gfobj_fld_nde(String key, Gfobj_nde val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__nde;}
public Object As_obj() {return val;}
public Gfobj_nde As_nde() {return val;} private Gfobj_nde val;
}
class Gfobj_fld_ary implements Gfobj_fld {
public Gfobj_fld_ary(String key, Gfobj_ary val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__ary;}
public Object As_obj() {return val;}
public Gfobj_ary As_ary() {return val;} private Gfobj_ary val;
}

@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs; import gplx.*; import gplx.core.*;
public class Gfo_prog_task_ {
public static final Gfo_prog_task Null = null;
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_grp {
byte Grp_tid();
}

@ -15,11 +15,10 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import gplx.core.consoles.*;
import gplx.core.ios.*; /*IoStream*/
public interface HashAlgo {
String Key();
String CalcHash(Console_adp dialog, IoStream stream);
byte[] Calc_hash_bry(byte[] v);
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
class Gfobj_grp_ {
public static final byte
Grp_tid__ary = 0
, Grp_tid__nde = 1
;
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public class Gfobj_nde implements Gfobj_grp {
private Ordered_hash subs;
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__nde;}
public int Len() {return subs == null ? 0 : subs.Len();}
public Gfobj_fld Get_at(int i) {return subs == null ? null : (Gfobj_fld)subs.Get_at(i);}
public Gfobj_fld Get_by(String k) {return subs == null ? null : (Gfobj_fld)subs.Get_by(k);}
public Gfobj_nde Add_fld(Gfobj_fld fld) {if (subs == null) subs = Ordered_hash_.New(); subs.Add(fld.Key(), fld); return this;}
public Gfobj_nde Add_int(String key, int val) {return Add_fld(new Gfobj_fld_int(key, val));}
public Gfobj_nde Add_long(String key, long val) {return Add_fld(new Gfobj_fld_long(key, val));}
public Gfobj_nde Add_str(String key, String val) {return Add_fld(new Gfobj_fld_str(key, val));}
public Gfobj_nde Add_nde(String key, Gfobj_nde val) {return Add_fld(new Gfobj_fld_nde(key, val));}
public Gfobj_nde Add_ary(String key, Gfobj_ary val) {return Add_fld(new Gfobj_fld_ary(key, val));}
public Gfobj_nde New_nde(String key) {Gfobj_nde rv = new Gfobj_nde(); Add_fld(new Gfobj_fld_nde(key, rv)); return rv;}
public Gfobj_ary_nde New_ary_nde(String key) {Gfobj_ary_nde rv = new Gfobj_ary_nde(null); Add_fld(new Gfobj_fld_ary(key, rv)); return rv;}
public static Gfobj_nde New() {return new Gfobj_nde();}
}

@ -0,0 +1,92 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.langs.jsons.*;
public class Gfobj_wtr__json {
private final Json_wtr wtr = new Json_wtr();
public Gfobj_wtr__json Opt_ws_(boolean v) {wtr.Opt_ws_(v); return this;}
public Bry_bfr Bfr() {return wtr.Bfr();}
public String To_str() {return wtr.To_str_and_clear();}
public Gfobj_wtr__json Write(Gfobj_grp root) {
switch (root.Grp_tid()) {
case Gfobj_grp_.Grp_tid__nde:
wtr.Doc_nde_bgn();
Write_nde((Gfobj_nde)root);
wtr.Doc_nde_end();
break;
case Gfobj_grp_.Grp_tid__ary:
wtr.Doc_ary_bgn();
Write_ary((Gfobj_ary)root);
wtr.Doc_ary_end();
break;
default:
throw Err_.new_unhandled_default(root.Grp_tid());
}
return this;
}
private void Write_nde(Gfobj_nde nde) {
int len = nde.Len();
for (int i = 0; i < len; ++i) {
Gfobj_fld fld = (Gfobj_fld)nde.Get_at(i);
Write_fld(fld);
}
}
private void Write_fld(Gfobj_fld itm) {
switch (itm.Fld_tid()) {
case Gfobj_fld_.Fld_tid__str: wtr.Kv_str(itm.Key() , ((Gfobj_fld_str)itm).As_str()); break;
case Gfobj_fld_.Fld_tid__int: wtr.Kv_int(itm.Key() , ((Gfobj_fld_int)itm).As_int()); break;
case Gfobj_fld_.Fld_tid__long: wtr.Kv_long(itm.Key() , ((Gfobj_fld_long)itm).As_long()); break;
case Gfobj_fld_.Fld_tid__nde: wtr.Nde_bgn(itm.Key()); Write_nde(((Gfobj_fld_nde)itm).As_nde()); wtr.Nde_end();break;
case Gfobj_fld_.Fld_tid__ary: wtr.Ary_bgn(itm.Key()); Write_ary(((Gfobj_fld_ary)itm).As_ary()); wtr.Ary_end();break;
default: throw Err_.new_unhandled_default(itm.Fld_tid());
}
}
private void Write_ary(Gfobj_ary ary) {
int len = ary.Len();
byte ary_tid = ary.Ary_tid();
switch (ary_tid) {
case Gfobj_ary_.Ary_tid__str:
String[] ary_str = ((Gfo_ary_str)ary).Ary_str();
for (int i = 0; i < len; ++i)
wtr.Ary_itm_str(ary_str[i]);
break;
case Gfobj_ary_.Ary_tid__int:
int[] ary_int = ((Gfo_ary_int)ary).Ary_int();
for (int i = 0; i < len; ++i)
wtr.Ary_itm_obj(ary_int[i]);
break;
case Gfobj_ary_.Ary_tid__nde:
Gfobj_nde[] ary_nde = ((Gfobj_ary_nde)ary).Ary_nde();
for (int i = 0; i < len; ++i) {
wtr.Nde_bgn_ary();
Write_nde(ary_nde[i]);
wtr.Nde_end();
}
break;
case Gfobj_ary_.Ary_tid__ary:
Gfobj_ary[] ary_ary = ((Gfo_ary_ary)ary).Ary_ary();
for (int i = 0; i < len; ++i) {
wtr.Ary_bgn_ary();
Write_ary(ary_ary[i]);
wtr.Ary_end();
}
break;
default: throw Err_.new_unhandled_default(ary_tid);
}
}
}

@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.core.tests.*; import gplx.langs.jsons.*;
public class Gfobj_wtr__json_fxt {
protected final Gfobj_wtr__json mgr = new Gfobj_wtr__json();
public Gfobj_nde Make__nde(Gfobj_fld... ary) {return Make__nde(Gfobj_nde.New(), ary);}
private Gfobj_nde Make__nde(Gfobj_nde nde, Gfobj_fld[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Gfobj_fld fld = (Gfobj_fld)ary[i];
nde.Add_fld(fld);
}
return nde;
}
public Gfobj_fld Make__fld_str(String key, String val) {return new Gfobj_fld_str(key, val);}
public Gfobj_fld Make__fld_int(String key, int val) {return new Gfobj_fld_int(key, val);}
public Gfobj_fld Make__fld_long(String key, long val) {return new Gfobj_fld_long(key, val);}
public Gfobj_fld Make__fld_nde(String key, Gfobj_fld... ary) {
Gfobj_nde nde = Make__nde(Gfobj_nde.New(), ary);
Gfobj_fld_nde rv = new Gfobj_fld_nde(key, nde);
return rv;
}
public Gfobj_fld Make__fld_ary_str(String key, String... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_str(ary));}
public Gfobj_fld Make__fld_ary_int(String key, int... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_int(ary));}
public Gfobj_fld Make__fld_ary_ary(String key, Gfobj_ary... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_ary(ary));}
public Gfobj_fld Make__fld_ary_nde(String key, Gfobj_nde... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary_nde(ary));}
public Gfobj_ary Make__ary_int(int... ary) {return new Gfo_ary_int(ary);}
public Gfobj_wtr__json_fxt Test__write(Gfobj_grp root, String... lines) {
String[] expd = Json_doc.Make_str_ary_by_apos(lines);
Gftest.Eq__ary(expd, Bry_.Ary(String_.SplitLines_nl(mgr.Write(root).To_str())), "json_write");
return this;
}
}

@ -0,0 +1,155 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
public class Gfobj_wtr__json_tst {
private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt();
@Test public void Flds() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_long ("k2", 2)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':2"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Sub_ndes() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_nde ("k2"
, fxt.Make__fld_str ("k2a", "v2a")
, fxt.Make__fld_int ("k2b", 2)
)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':"
, " { 'k2a':'v2a'"
, " , 'k2b':2"
, " }"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Ary_str() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_str ("k2", "a1", "a2", "a3")
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':"
, " [ 'a1'"
, " , 'a2'"
, " , 'a3'"
, " ]"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Ary_int() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_int ("k2", 1, 2, 3)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':"
, " [ 1"
, " , 2"
, " , 3"
, " ]"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Ary_nde() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_nde ("k2"
, fxt.Make__nde (fxt.Make__fld_str("k21", "v21"))
, fxt.Make__nde (fxt.Make__fld_str("k22", "v22"))
)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':"
, " ["
, " { 'k21':'v21'"
, " }"
, " ,"
, " { 'k22':'v22'"
, " }"
, " ]"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Ary_ary() {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_ary ("k2"
, fxt.Make__ary_int (1, 2, 3)
, fxt.Make__ary_int (4, 5, 6)
)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
, ", 'k2':"
, " ["
, " [ 1"
, " , 2"
, " , 3"
, " ]"
, " ,"
, " [ 4"
, " , 5"
, " , 6"
, " ]"
, " ]"
, ", 'k3':3"
, "}"
, ""
);
}
@Test public void Root_ary() {
fxt.Test__write
( fxt.Make__ary_int(1, 2, 3)
, "[ 1"
, ", 2"
, ", 3"
, "]"
, ""
);
}
}

@ -27,16 +27,37 @@ public class Gftest {
public static void Eq__ary(byte[][] expd_bry_ary, byte[][] actl_bry_ary, String msg_fmt, Object... msg_args) {
boolean[] failures = Calc__failures(Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
if (failures != null) {
bfr.Add(Bry__line_bgn);
if (msg_fmt != null) {
bfr.Add_str_u8(String_.Format(msg_fmt, msg_args));
bfr.Add(Bry__line_mid);
}
Write__failures(bfr, failures, Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
Write_fail_head(bfr, msg_fmt, msg_args);
Write_fail_ary(bfr, failures, Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
}
private static void Write__failures(Bry_bfr bfr, boolean[] failures, int type_id, Object expd_ary, Object actl_ary) {
public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);}
public static void Eq__str(String expd, String actl, String msg_fmt, Object... msg_args) {
if (String_.Eq(expd, actl)) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add_str_u8(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add_str_u8(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__bry(byte[] expd, byte[] actl) {Eq__bry(expd, actl, null);}
public static void Eq__bry(byte[] expd, byte[] actl, String msg_fmt, Object... msg_args) {
if (Bry_.Eq(expd, actl)) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
private static void Write_fail_head(Bry_bfr bfr, String msg_fmt, Object[] msg_args) {
bfr.Add(Bry__line_bgn);
if (msg_fmt != null) {
bfr.Add_str_u8(String_.Format(msg_fmt, msg_args));
bfr.Add(Bry__line_mid);
}
}
private static void Write_fail_ary(Bry_bfr bfr, boolean[] failures, int type_id, Object expd_ary, Object actl_ary) {
int len = failures.length;
int expd_len = Array_.Len(expd_ary);
int actl_len = Array_.Len(actl_ary);

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
class Json_itm_str extends Json_itm_base {
private final boolean exact; private final Json_doc doc;
private final boolean exact; private final Json_doc doc;
private String data_str; private byte[] data_bry = null;
public Json_itm_str(Json_doc doc, int src_bgn, int src_end, boolean exact) {this.Ctor(src_bgn + 1, src_end - 1); this.doc = doc; this.exact = exact;}
@Override public byte Tid() {return Json_itm_.Tid__str;}
@ -57,7 +57,7 @@ class Json_itm_str extends Json_itm_base {
case Byte_ascii.Ltr_b: bfr.Add_byte(Byte_ascii.Backfeed); break;
case Byte_ascii.Ltr_f: bfr.Add_byte(Byte_ascii.Formfeed); break;
case Byte_ascii.Ltr_u:
int utf8_val = gplx.core.texts.HexDecUtl.parse_or(src, i + 1, i + 5, -1);
int utf8_val = gplx.core.encoders.Hex_utl_.Parse_or(src, i + 1, i + 5, -1);
int len = gplx.core.intls.Utf16_.Encode_int(utf8_val, utf8_bry, 0);
bfr.Add_mid(utf8_bry, 0, len);
i += 4;

@ -43,7 +43,7 @@ public class Json_wtr {
public Json_wtr Nde_bgn(byte[] key) {
Write_indent_itm();
if (key == Bry_.Empty) {
bfr.Del_by_1(); // remove trailing space from Write_indent_itm
if (opt_ws) bfr.Del_by_1(); // remove trailing space from Write_indent_itm
++idx;
}
else
@ -55,9 +55,15 @@ public class Json_wtr {
Write_grp_end(Bool_.Y, Sym_nde_end);
return Write_nl();
}
public Json_wtr Ary_bgn_ary() {return Ary_bgn(String_.Empty);}
public Json_wtr Ary_bgn(String nde) {
Write_indent_itm();
Write_key(Bry_.new_u8(nde));
if (nde == String_.Empty) {
if (opt_ws) bfr.Del_by_1(); // remove trailing space from Write_indent_itm
++idx;
}
else
Write_key(Bry_.new_u8(nde));
return Ary_bgn_keyless();
}
private Json_wtr Ary_bgn_keyless() {
@ -203,9 +209,7 @@ public class Json_wtr {
}
}
}
// else {
bfr.Add_byte_nl();
// }
bfr.Add_byte_nl();
Write_grp_bgn(Sym_nde_bgn, Bool_.Y);
Json_nde sub_nde = (Json_nde)obj;
int sub_nde_len = sub_nde.Len();

@ -34,7 +34,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "3.4.4.1";
public static final String Version = "3.5.1.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

@ -45,7 +45,7 @@ public class Xoax_addon_mgr {
// specials
, new gplx.xowa.addons.apps.file_browsers .Fbrow_addon()
, new gplx.xowa.addons.updates.downloads .Xoax_downloads_addon()
, new gplx.xowa.addons.builds.centrals .Xoax_downloads_addon()
// jsons
, new gplx.xowa.addons.servers.https .Xoax_long_poll_addon()
@ -67,8 +67,10 @@ public class Xoax_addon_mgr {
if (Type_adp_.Implements_intf_obj(addon, Xoax_addon_itm__json.class)) {
Xoax_addon_itm__json addon_json = (Xoax_addon_itm__json)addon;
gplx.xowa.htmls.bridges.Bridge_cmd_itm[] json_cmds = addon_json.Json__cmds();
for (gplx.xowa.htmls.bridges.Bridge_cmd_itm json_cmd : json_cmds)
for (gplx.xowa.htmls.bridges.Bridge_cmd_itm json_cmd : json_cmds) {
json_cmd.Init_by_app(app);
app.Html__bridge_mgr().Cmd_mgr().Add(json_cmd);
}
}
}
app.Gui__cbk_mgr().Reg(gplx.xowa.addons.servers.https.Xog_cbk_wkr__http.Instance);

@ -0,0 +1,49 @@
/*
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.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.langs.jsons.*;
public class Xoa_dashboard_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {
Xobc_ui_mgr dl_mgr = Xoa_dashboard_special.Download_mgr;
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
switch (proc_id) {
case Proc__init: dl_mgr.Init(); break;
case Proc__todo__move_to_work: dl_mgr.Todo__move_to_work(args.Get_as_str("job_uid")); break;
case Proc__work__resume: dl_mgr.Work__resume(args.Get_as_str("job_uid")); break;
case Proc__work__pause: dl_mgr.Work__pause(args.Get_as_str("job_uid")); break;
case Proc__work__cancel: dl_mgr.Work__cancel(args.Get_as_str("job_uid")); break;
default: throw Err_.new_unhandled_default(proc_id);
}
return "";
}
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
private static final byte Proc__init = 0, Proc__todo__move_to_work = 1, Proc__work__resume = 2, Proc__work__pause = 3, Proc__work__cancel = 4;
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
.Add_str_byte("init" , Proc__init)
.Add_str_byte("todo__move_to_work" , Proc__todo__move_to_work)
.Add_str_byte("work__resume__send" , Proc__work__resume)
.Add_str_byte("work__pause__send" , Proc__work__pause)
.Add_str_byte("work__cancel__send" , Proc__work__cancel)
;
public byte[] Key() {return BRIDGE_KEY;}
public static final byte[] BRIDGE_KEY = Bry_.new_a7("builder_central.exec");
public static final Xoa_dashboard_bridge Prototype = new Xoa_dashboard_bridge(); Xoa_dashboard_bridge() {}
}

@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.*;
class Xoa_dashboard_file_mgr {
private final Xog_cbk_mgr cbk_mgr;
private final Ordered_hash hash = Ordered_hash_.New();
public Xoa_dashboard_file_mgr(Xog_cbk_mgr cbk_mgr) {
this.cbk_mgr = cbk_mgr;
}
public void Add(Xobc_file_itm itm) {hash.Add(itm.Job_uid(), itm);}
public void Clear() {hash.Clear();}
public int Len() {return hash.Len();}
public Xobc_file_itm Get_at(int i) {return (Xobc_file_itm)hash.Get_at(i);}
public Xobc_file_itm Get_by(String k) {return (Xobc_file_itm)hash.Get_by(k);}
public Xobc_file_itm Del_by(String k) {
Xobc_file_itm rv = (Xobc_file_itm)hash.Get_by(k);
hash.Del(k);
return rv;
}
public void Exec_all(String invk_cmd) {
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_at(i);
GfoInvkAble_.Invk(itm, invk_cmd);
}
}
public void Exec_one(String invk_cmd, String file_id) {this.Exec_one(invk_cmd, file_id, null, null);}
public void Exec_one(String invk_cmd, String file_id, String send_func, Gfobj_nde send_data) {
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_by(file_id);
GfoInvkAble_.Invk(itm, invk_cmd);
if (send_func != null) cbk_mgr.Send_json(send_func, send_data);
}
public void Move_all(Xoa_dashboard_file_mgr trg) {this.Move_all(trg, null);}
public void Move_all(Xoa_dashboard_file_mgr trg, String invk_cmd) {
List_adp tmp = List_adp_.new_();
int len = hash.Len();
for (int i = 0; i < len; ++i)
tmp.Add((Xobc_file_itm)hash.Get_at(i));
for (int i = 0; i < len; ++i) {
Xobc_file_itm itm = (Xobc_file_itm)tmp.Get_at(i);
if (invk_cmd != null) GfoInvkAble_.Invk(itm, invk_cmd);
hash.Del(itm.Job_uid());
trg.Add(itm);
}
}
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg) {this.Move_one(file_id, trg, null, null, null);}
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg, String invk_cmd) {this.Move_one(file_id, trg, invk_cmd, null, null);}
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg, String invk_cmd, String send_func, Gfobj_nde send_data) {
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_by(file_id);
if (invk_cmd != null) GfoInvkAble_.Invk(itm, invk_cmd);
hash.Del(file_id);
trg.Add(itm);
if (send_func != null) cbk_mgr.Send_json(send_func, send_data);
}
public void To_nde(Bry_bfr tmp_bfr, Gfobj_ary ary_obj) {
Gfobj_ary_nde ary = (Gfobj_ary_nde)ary_obj;
List_adp list = List_adp_.new_();
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Xobc_file_itm sub_itm = (Xobc_file_itm)hash.Get_at(i);
Gfobj_nde sub_nde = Gfobj_nde.New();
sub_itm.Write_to_nde(tmp_bfr, sub_nde);
list.Add(sub_nde);
}
ary.Ary_nde_((Gfobj_nde[])list.To_ary_and_clear(Gfobj_nde.class));
}
}

@ -0,0 +1,63 @@
/*
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.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.addons.builds.centrals.itms.*; import gplx.xowa.addons.builds.centrals.*;
import gplx.xowa.addons.apps.file_browsers.*;
import gplx.core.security.*; import gplx.core.progs.*; import gplx.xowa.guis.cbks.*;
public class Xoa_dashboard_special implements Xows_page {
public static Xobc_ui_mgr Download_mgr;
private static boolean init = true;
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
if (init) {
init = false;
Download_mgr = new Xobc_ui_mgr(wiki.App().Gui__cbk_mgr());
wiki.App().Gui__cbk_mgr().Reg(new gplx.xowa.guis.cbks.swts.Xog_cbk_wkr__swt(((Xoae_app)wiki.App()).Gui_mgr()));
}
Download_mgr.Clear();
Io_url addon_dir = wiki.App().Fsys_mgr().Bin_addon_dir().GenSubDir_nest("bldr", "central");
Xopage_html_data html_data = Write_html(wiki.App(), addon_dir);
html_data.Apply(page);
}
private static Xopage_html_data Write_html(Xoa_app app, Io_url addon_dir) {
// write body
Xodl_itm_regy owner_itm = new Xodl_itm_regy();
byte[] template_src = Io_mgr.Instance.LoadFilBry(addon_dir.GenSubFil_nest("tmpl", "bldr.central.main.mustache.html"));
Bry_bfr tmp_bfr = Bry_bfr.new_();
byte[] body = gplx.langs.mustaches.Mustache_wtr_.Write_to_bry(tmp_bfr, template_src, owner_itm);
// write head
Xopage_html_data rv = new Xopage_html_data(Display_ttl, body);
rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("css", "bldr.central.css")));
rv.Head_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "lib", "mustache.js")));
rv.Head_tags().Add(Xopg_tag_itm.New_html_code(addon_dir.GenSubFil_nest("tmpl", "bldr.central.row.mustache.html"), "bldr.central.row"));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.elem.js")));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.tmpl.js")));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.notify.js")));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.server.js")));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "bldr.central.util.js")));
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "bldr.central.js")));
return rv;
}
public static final String SPECIAL_KEY = "XowaWikiDownload";
public static final byte[] Display_ttl = Bry_.new_a7("Download Central");
public Xows_special_meta Special__meta() {return new Xows_special_meta(Xows_special_meta_.Src__xowa, SPECIAL_KEY);}
public static final Xows_page Prototype = new Xoa_dashboard_special();
public Xows_page Special__clone() {return this;}
}

@ -15,27 +15,20 @@ 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.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
import gplx.xowa.specials.*;
public class Xoax_downloads_addon implements Xoax_addon_itm, Xoax_addon_itm__special {
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
public class Xoax_downloads_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
public Xows_page[] Pages_ary() {
return new Xows_page[]
{ Xodl_special_page.Prototype
{ Xoa_dashboard_special.Prototype
};
}
public Bridge_cmd_itm[] Json__cmds() {
return new Bridge_cmd_itm[]
{ gplx.xowa.addons.builds.centrals.Xoa_dashboard_bridge.Prototype
};
}
public static final byte[] ADDON_KEY = Bry_.new_a7("xowa.imports.downloads");
public byte[] Addon__key() {return ADDON_KEY;}
}
// class Xodl_core_regy {
// public void Update() {} // update from http
// public void Load() {} // load bin/
// }
// class Xodl_user_regy {
// public void Load() {}
// public void Apply() {} // mark already downloaded items
// }
// class Xodl_main_mgr {
// public void Show_ui() {} // show list for ui
// public void Process() {} // process choices
// }

@ -0,0 +1,117 @@
/*
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.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.*;
import gplx.xowa.addons.builds.centrals.jobs.*;
class Xobc_file_itm implements GfoInvkAble {
public Xobc_file_itm(Xog_cbk_mgr cbk_mgr, String job_uid, String job_name) {
this.job_uid = job_uid;
this.job_name = job_name;
this.tasks = new Xobc_job_itm[]
{ new Xobc_job_itm__verify(cbk_mgr, "77801297-db0a-47b4-af95-0db1eb63a192", Io_url_.new_fil_("C:\\xowa\\wiki\\en.wikipedia.org\\en.wikipedia.org-core.xowa"))
};
this.tasks_len = tasks.length;
}
public String Job_uid() {return job_uid;} private final String job_uid; // guid
public String Job_name() {return job_name;} private final String job_name; // Simple Wikipedia: html
public String Job_type() {return job_type;} private final String job_type = "gplx.xowa.bldr.wikis.copy_part";
public Xobc_job_itm[] Tasks() {return tasks;} private Xobc_job_itm[] tasks; private int tasks_len = 0;
public void Pause() {
for (int i = 0; i < tasks_len; ++i) {
Xobc_job_itm task = tasks[i];
if ( !task.Prog__paused() // ignore already paused tasks
&& task.Prog__started() // only pause tasks if started; don't pause inited tasks
)
task.Prog__pause();
}
}
public void Resume() {
for (int i = 0; i < tasks_len; ++i) {
Xobc_job_itm task = tasks[i];
if (task.Prog__paused())
task.Prog__resume();
else {
gplx.core.threads.Thread_adp_.invk_("job: " + task.Job_name(), task, "").Start();
break; // only start one
}
}
}
public void Cancel() {
for (int i = 0; i < tasks_len; ++i) {
Xobc_job_itm task = tasks[i];
task.Prog__cancel();
}
}
public void Write_to_nde(Bry_bfr tmp_bfr, Gfobj_nde itm) {
itm.Add_str ("job_uid" , job_uid);
itm.Add_str ("job_name" , job_name);
Gfobj_ary_nde ary_nde = itm.New_ary_nde("subs");
Gfobj_nde[] ary = new Gfobj_nde[tasks_len];
ary_nde.Ary_nde_(ary);
long prog_time_end = 0;
long prog_data_end = 0;
for (int i = 0; i < tasks_len; ++i) {
Xobc_job_itm sub_itm = tasks[i];
Gfobj_nde sub_nde = Gfobj_nde.New();
ary[i] = sub_nde;
sub_itm.Write_to_nde(tmp_bfr, sub_nde);
prog_time_end += sub_itm.Prog__end();
}
itm.Add_str ("prog_data_end_str" , gplx.core.ios.Io_size_.To_str_new(tmp_bfr, prog_data_end, 2));
itm.Add_str ("prog_time_end_str" , Time_dhms_.To_str(tmp_bfr, prog_time_end, true, 2));
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (String_.Eq(k, Invk__pause)) this.Pause();
else if (String_.Eq(k, Invk__resume)) this.Resume();
else if (String_.Eq(k, Invk__cancel)) this.Cancel();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk__pause = "pause", Invk__resume = "resume", Invk__cancel = "cancel";
}
/*
{ prog_finished : 0
, prog_data_cur : 0
, prog_data_end : 10
, prog_data_end_str : '1.81 gb'
, prog_time_cur : 0
, prog_time_end : 30
, prog_time_end_str : '30'
, jobs:
[
{ job_type : 'gplx.xowa.core.security.verify'
, job_name : 'verifying'
, job_sort : 0
, job_uid : '77801297-db0a-47b4-af95-0db1eb63a192'
, prog_data_cur : 0
, prog_data_end : 1819264175
, prog_time_cur : 0
, prog_time_end : 10
}
, { job_type : 'gplx.xowa.core.ios.zips.zip_decompress'
, job_name : 'unzipping'
, job_sort : 1
, job_uid : '79fbfebe-0165-42b0-b71a-c66f95cb7fd1'
, prog_data_cur : 0
, prog_data_end : 1819264175
, prog_time_cur : 0
, prog_time_end : 20
}
]
}
*/

@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
class Xobc_rate_mgr {
private final Ordered_hash hash = Ordered_hash_.New();
public int Len() {return hash.Len();}
public Xobc_rate_itm Get_at(int i) {return (Xobc_rate_itm)hash.Get_at(i);}
public Xobc_rate_itm Get_by(String k) {return (Xobc_rate_itm)hash.Get_by(k);}
public void Add(Xobc_rate_itm rate) {hash.Add_if_dupe_use_nth(rate.Key(), rate);}
}
class Xobc_rate_itm {
public Xobc_rate_itm(String type, String key, long rate) {this.type = type; this.key = key; this.rate = rate;}
public String Type() {return type;} private final String type; // EX: download
public String Key() {return key;} private final String key; // EX: http://archive.org|C:\xowa\wiki\
public long Rate() {return rate;} private final long rate; // EX: 4000000
}

@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.xowa.guis.cbks.*; import gplx.core.gfobjs.*;
public class Xobc_ui_mgr {
private final Xoa_dashboard_file_mgr work_mgr, todo_mgr, done_mgr;
private final Xog_cbk_mgr cbk_mgr;
public Xobc_ui_mgr(Xog_cbk_mgr cbk_mgr) {
this.cbk_mgr = cbk_mgr;
work_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
todo_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
done_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
}
public void Init() {
todo_mgr.Clear();
todo_mgr.Add(new Xobc_file_itm(cbk_mgr, "0", "Simple Wikipedia: html"));
Bry_bfr tmp_bfr = Bry_bfr.new_();
Gfobj_nde root = Gfobj_nde.New();
Gfobj_nde lists_nde = root.New_nde("lists");
Gfobj_ary todo_ary = lists_nde.New_ary_nde("todo");
todo_mgr.To_nde(tmp_bfr, todo_ary);
cbk_mgr.Send_json("xo.bldr.core.init__recv", root);
}
public void Clear() {
work_mgr.Clear();
todo_mgr.Clear();
done_mgr.Clear();
}
public void Todo__move_to_work(String job_uid) {todo_mgr.Move_one(job_uid, work_mgr, null, "xo.bldr.todo.move_to_work__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
public void Work__resume(String job_uid) {work_mgr.Exec_one(Xobc_file_itm.Invk__resume, job_uid, "xo.bldr.work.resume__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
public void Work__pause(String job_uid) {work_mgr.Exec_one(Xobc_file_itm.Invk__pause, job_uid, "xo.bldr.work.pause__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
public void Work__cancel(String job_uid) {work_mgr.Move_one(job_uid, todo_mgr, Xobc_file_itm.Invk__cancel, "xo.bldr.work.cancel__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
public void Work__pause_all() {work_mgr.Exec_all(Xobc_file_itm.Invk__pause);}
public void Work__resume_all() {
int len = work_mgr.Len();
for (int i = 0; i < len; ++i) {
Xobc_file_itm itm = work_mgr.Get_at(i);
itm.Resume();
}
if (len > 0) { // TODO: if multiple items paused; send back notify for each paused item
Xobc_file_itm itm = work_mgr.Get_at(0);
itm.Resume();
cbk_mgr.Send_json("work__resume__recv", Gfobj_nde.New().Add_str("file_id", itm.Job_uid()));
}
}
public void Work__cancel_all() {work_mgr.Move_all(todo_mgr, Xobc_file_itm.Invk__cancel);}
public void Work__complete(String file_id) {work_mgr.Move_one(file_id, done_mgr);} // not called by ui called by task wkr
public void Todo__load(String url) {
// Xobc_job_itm
}
/*
public void User__rates__load() {}
public void User__rates__save() {}
public void Done__save() {}
public void Done__load() {}
*/
}

@ -15,10 +15,9 @@ 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.addons.updates.downloads.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
package gplx.xowa.addons.builds.centrals.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import gplx.langs.jsons.*; import gplx.langs.mustaches.*;
import gplx.xowa.addons.updates.downloads.core.*;
public class Xodl_itm_pack implements Mustache_doc_itm, Gfo_download_itm {
public class Xodl_itm_pack implements Mustache_doc_itm {
public int Id = -1; // EX: 1
public String Wiki = ""; // EX: 'simple.wikipedia.org'
public String Date = ""; // EX: '2016-04-07'

@ -15,7 +15,7 @@ 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.addons.updates.downloads.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
package gplx.xowa.addons.builds.centrals.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import gplx.langs.jsons.*; import gplx.langs.mustaches.*;
public class Xodl_itm_regy implements Mustache_doc_itm {
public Xodl_itm_pack[] Packs = Xodl_itm_pack.Ary_empty;

@ -15,7 +15,7 @@ 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.addons.updates.downloads.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
package gplx.xowa.addons.builds.centrals.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
public class Xodl_itm_regy_tst {

@ -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.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
public class Time_dhms_ {
public static String To_str(Bry_bfr bfr, long val, boolean show_unit, int max_places) {To_bfr(bfr, val, show_unit, max_places); return bfr.To_str_and_clear();}
public static void To_bfr(Bry_bfr bfr, long val, boolean show_unit, int max_places) {
byte suffix = Byte_ascii.Null;
int count = 0;
for (int i = 0; i < 4; ++i) {
// get factor and unit
long factor = 0;
byte unit = Byte_ascii.Null;
switch(i) {
case 0: unit = Byte_ascii.Ltr_d; factor = 86400; break;
case 1: unit = Byte_ascii.Ltr_h; factor = 3600; break;
case 2: unit = Byte_ascii.Ltr_m; factor = 60; break;
case 3: unit = Byte_ascii.Ltr_s; factor = 1; break;
}
// calc cur and update val; EX: 3690 -> cur:1,mod:90
int cur = (int)(val / factor);
val %= factor;
if (count == 0) { // no str yet
if ( cur == 0 // cur is 0; EX: 3690 and factor = 86400 -> 0 days; don't write anything
&& i != 3) // unless it is the seconds place; need to handle "0 s" specifically
continue;
suffix = unit; // set suffix
bfr.Add_int_variable(cur); // write cur; note that this is not zero-padded
}
else { // str exists
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 2, cur); // write cur; note that this zero-padded; also, note will write "00" if cur == 0
}
if (++count == max_places) break; // stop if max-places reached; EX: 86400 should write 1:00, not 1:00:00:00
if (i != 3) // do not add ":" if seconds
bfr.Add_byte_colon();
}
if (show_unit) // add units; EX: " s" for seconds
bfr.Add_byte_space().Add_byte(suffix);
}
}

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import org.junit.*; import gplx.core.tests.*;
public class Time_dhms__tst {
private final Time_dhms__fxt fxt = new Time_dhms__fxt();
@Test public void S___0() {fxt.Test__to_str( 0, 4, "0 s");}
@Test public void S___1() {fxt.Test__to_str( 1, 4, "1 s");}
@Test public void S___2() {fxt.Test__to_str( 30, 4, "30 s");}
@Test public void M___1() {fxt.Test__to_str( 60, 4, "1:00 m");}
@Test public void M___2() {fxt.Test__to_str( 600, 4, "10:00 m");}
@Test public void H___1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");}
@Test public void H___2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");}
@Test public void D___1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");}
@Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");}
}
class Time_dhms__fxt {
private final Bry_bfr bfr = Bry_bfr.new_();
public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) {
Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places));
return this;}
}

@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
public interface Xobc_job_itm extends gplx.core.progs.Gfo_prog_ui, GfoInvkAble {
String Job_uid();
String Job_name();
void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde itm);
Xobc_job_itm Owner();
Xobc_job_itm[] Subs();
}

@ -15,8 +15,8 @@ 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.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_download_cbk {
void Download__end_itm(Gfo_download_itm itm);
void Download__end_all(Gfo_download_itm[] itms);
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
public class Xobc_job_itm_ {
public static final Xobc_job_itm[] Ary_empty = new Xobc_job_itm[0];
public static final Xobc_job_itm Null = null;
}

@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import gplx.core.progs.*; import gplx.core.gfobjs.*;
import gplx.core.ios.zips.*; import gplx.xowa.guis.cbks.*;
public class Xobc_job_itm__unzip extends Gfo_prog_ui_base implements Xobc_job_itm {
private final Xog_cbk_mgr cbk_mgr;
private long nxt_time;
public Xobc_job_itm__unzip(Xog_cbk_mgr cbk_mgr, String job_uid, Io_url url) {
this.cbk_mgr = cbk_mgr; this.job_uid = job_uid;
this.Prog__end_(10);
}
public String Job_uid() {return job_uid;} private final String job_uid;
public String Job_name() {return job_name;} private final String job_name = "unzipping";
public Xobc_job_itm Owner() {return Xobc_job_itm_.Null;}
public Xobc_job_itm[] Subs() {return Xobc_job_itm_.Ary_empty;}
public void Task__exec() {
}
public void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde nde) {
nde.Add_str ("job_uid" , job_uid);
nde.Add_str ("job_name" , job_name);
nde.Add_long("prog_data_cur" , this.Prog__cur());
nde.Add_long("prog_data_end" , this.Prog__end());
nde.Add_long("prog_time_cur" , 0);
nde.Add_long("prog_time_end" , this.Prog__end());
}
@Override public byte Prog__notify__working(long cur, long end) {
long cur_time = gplx.core.envs.Env_.TickCount();
if (cur_time < nxt_time) return Gfo_prog_ui_.State__started; // message came too soon. ignore it
nxt_time = cur_time + 200;
Gfobj_nde nde = Gfobj_nde.New();
nde.Add_str("job_uid", job_uid);
nde.Add_str("task_type", "verify");
nde.Add_long("prog_cur", cur);
nde.Add_long("prog_end", end);
cbk_mgr.Send_json("work__update_progress", nde);
return super.Prog__notify__working(cur, end);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
Task__exec();
return this;
}
}

@ -0,0 +1,65 @@
/*
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.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
import gplx.core.progs.*; import gplx.core.gfobjs.*;
import gplx.core.security.*; import gplx.xowa.guis.cbks.*;
public class Xobc_job_itm__verify extends Gfo_prog_ui_base implements Xobc_job_itm {
private final Xog_cbk_mgr cbk_mgr; private final Io_url url;
private long nxt_time;
public Xobc_job_itm__verify(Xog_cbk_mgr cbk_mgr, String job_uid, Io_url url) {
this.cbk_mgr = cbk_mgr; this.job_uid = job_uid; this.url = url;
this.Prog__end_(10);
}
public String Job_uid() {return job_uid;} private final String job_uid;
public String Job_name() {return job_name;} private final String job_name = "verifying";
public Xobc_job_itm Owner() {return Xobc_job_itm_.Null;}
public Xobc_job_itm[] Subs() {return Xobc_job_itm_.Ary_empty;}
public byte[] Hash() {return hash;} private byte[] hash;
public void Task__exec() {
Hash_algo algo = Hash_algo_.New__md5();
gplx.core.ios.IoStream stream = Io_mgr.Instance.OpenStreamRead(url);
try {this.hash = algo.Hash_stream_as_bry(this, stream);}
finally {stream.Rls();}
}
public void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde nde) {
nde.Add_str ("job_uid" , job_uid);
nde.Add_str ("job_name" , job_name);
nde.Add_long("prog_data_cur" , this.Prog__cur());
nde.Add_long("prog_data_end" , this.Prog__end());
nde.Add_long("prog_time_cur" , 0);
nde.Add_long("prog_time_end" , this.Prog__end());
}
@Override public byte Prog__notify__working(long cur, long end) {
long cur_time = gplx.core.envs.Env_.TickCount();
if (cur_time < nxt_time) return Gfo_prog_ui_.State__started; // message came too soon. ignore it
nxt_time = cur_time + 200;
Gfobj_nde nde = Gfobj_nde.New();
nde.Add_str("job_uid", job_uid);
nde.Add_str("task_type", "verify");
nde.Add_long("prog_cur", cur);
nde.Add_long("prog_end", end);
cbk_mgr.Send_json("work__update_progress", nde);
return super.Prog__notify__working(cur, end);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
Task__exec();
return this;
}
}

@ -22,6 +22,7 @@ public class Http_long_poll_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_it
public int Sleep_interval = 100;
public int Send_interval = 1000;
public void Init_by_app(Xoa_app app) {}
public void Send_msg(String msg) {
msgs.Add(msg);
}

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
public class Http_send_msg_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
public void Init_by_app(Xoa_app app) {}
public String Exec(gplx.langs.jsons.Json_nde data) {
gplx.langs.jsons.Json_nde jnde = (gplx.langs.jsons.Json_nde)data.Get_as_itm_or_null(Bry_.new_a7("msg"));
Http_long_poll_cmd.Instance.Send_msg(jnde.Print_as_json());

@ -16,8 +16,9 @@ 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.addons.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
import gplx.xowa.guis.cbks.*;
import gplx.xowa.guis.cbks.*; import gplx.core.gfobjs.*;
public class Xog_cbk_wkr__http implements Xog_cbk_wkr {
public Object Send_json(String func, Gfobj_nde data) {return null;}
public void Send_prog(String head) {
Http_long_poll_cmd.Instance.Send_msg(head);
}

@ -1,63 +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.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.addons.updates.downloads.itms.*; import gplx.xowa.addons.updates.downloads.core.*;
import gplx.xowa.addons.apps.file_browsers.*;
public class Xodl_special_page implements Xows_page {
public static Gfo_download_wkr Download_wkr = Gfo_download_wkr_.Noop;
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
Io_url addon_dir = wiki.App().Fsys_mgr().Bin_addon_dir().GenSubDir_nest("import", "wiki_download");
Xoa_url_arg_mgr arg_mgr = new Xoa_url_arg_mgr(null).Init(url.Qargs_ary());
byte[] ids_bry = arg_mgr.Read_bry_or_null("ids");
if (ids_bry == null) {
Xopage_html_data html_data = Write_html(wiki.App(), addon_dir);
html_data.Apply(page);
}
else {
Xodl_itm_regy regy = Load_regy(addon_dir);
int[] ids_ary = Int_.Ary_parse(String_.new_u8(ids_bry), ",");
Xodl_itm_pack[] packs = regy.Packs__select(ids_ary);
if (packs.length > 0) {
Xodl_download_mgr download_mgr = new Xodl_download_mgr();
download_mgr.Download(Download_wkr, packs);
}
}
}
private static Xodl_itm_regy Load_regy(Io_url addon_dir) {
return Xodl_itm_regy.Load_by_json(addon_dir.GenSubFil_nest("data", "wiki_download.json"));
}
private static Xopage_html_data Write_html(Xoa_app app, Io_url addon_dir) {
// write body
Xodl_itm_regy owner_itm = Load_regy(addon_dir);
byte[] template_src = Io_mgr.Instance.LoadFilBry(addon_dir.GenSubFil_nest("bin", "wiki_download.mustache.html"));
Bry_bfr tmp_bfr = Bry_bfr.new_();
byte[] body = gplx.langs.mustaches.Mustache_wtr_.Write_to_bry(tmp_bfr, template_src, owner_itm);
// write head
Xopage_html_data rv = new Xopage_html_data(Display_ttl, body);
rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "wiki_download.css")));
return rv;
}
public static final String SPECIAL_KEY = "XowaWikiDownload";
public static final byte[] Display_ttl = Bry_.new_a7("Download wikis");
public Xows_special_meta Special__meta() {return new Xows_special_meta(Xows_special_meta_.Src__xowa, SPECIAL_KEY);}
public static final Xows_page Prototype = new Xodl_special_page();
public Xows_page Special__clone() {return this;}
}

@ -1,23 +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.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_download_itm {
String Download__src();
Io_url Download__trg();
void Download__trg_(Io_url v);
}

@ -1,21 +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.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_download_wkr {
void Download__bgn(Gfo_download_cbk cbk, Gfo_download_itm[] itms);
}

@ -1,24 +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.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public class Gfo_download_wkr_ {
public static final Gfo_download_wkr Noop = new Gfo_download_wkr__noop();
}
class Gfo_download_wkr__noop implements Gfo_download_wkr {
public void Download__bgn(Gfo_download_cbk cbk, Gfo_download_itm[] itms) {cbk.Download__end_all(itms);}
}

@ -1,22 +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.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_unzip_itm {
Io_url Unzip__src_fil();
Io_url Unzip__trg_dir();
}

@ -1,25 +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.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
public interface Gfo_unzip_wkr {
void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm);
}
class Gfo_unzip_wkr__noop implements Gfo_unzip_wkr {
public void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm) {cbk.Unzip__end_itm(itm);}
public static final Gfo_unzip_wkr__noop Instance = new Gfo_unzip_wkr__noop(); Gfo_unzip_wkr__noop() {}
}

@ -1,27 +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.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
import gplx.core.ios.zips.*;
class Gfo_unzip_wkr__jre implements Gfo_unzip_wkr {
public void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm) {
Io_zip_mgr_base.Instance.Unzip_to_dir(itm.Unzip__src_fil(), itm.Unzip__trg_dir());
cbk.Unzip__end_itm(itm);
}
public static final Gfo_unzip_wkr__jre Instance = new Gfo_unzip_wkr__jre(); Gfo_unzip_wkr__jre() {}
}

@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.apis.xowa.bldrs.runners; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.bldrs.*;
public class Xoapi_runner implements GfoInvkAble {
private Xoa_app app;
public void Ctor_by_app(Xoa_app app) {this.app = app;}
// private Xoa_app app;
public void Ctor_by_app(Xoa_app app) {}//this.app = app;}
private void Exec(GfoMsg msg) {
// int len = msg.Args_count();
// String cmd = (String)msg.Args_getAt(0).Val();
@ -32,7 +32,7 @@ public class Xoapi_runner implements GfoInvkAble {
// }
// gplx.core.ios.zips.Io_zip_decompress_task task = new gplx.core.ios.zips.Io_zip_decompress_task();
// task.Init(true, Gfo
app.Gui__cbk_mgr().Send_prog("test", "key_0", "val_0");
// app.Gui__cbk_mgr().Send_prog("test", "key_0", "val_0");
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exec)) Exec(m);
@ -41,7 +41,7 @@ public class Xoapi_runner implements GfoInvkAble {
}
private static final String Invk_exec = "exec";
}
class Xodl_prog_ui implements gplx.core.progs.Gfo_prog_ui {
public void Prog__update_val(long cur, long max) {}
public void Prog__end() {}
}
// class Xodl_prog_ui : gplx.core.progs.Gfo_prog_ui {
// public void Prog__update_val(long cur, long max) {}
// public void Prog__end() {}
// }

@ -22,7 +22,7 @@ import gplx.xowa.apps.servers.tcp.*;
import gplx.xowa.apps.servers.http.*; import gplx.xowa.guis.views.*;
public class Gxw_html_server implements Gxw_html {
private Xosrv_socket_wtr wtr; private Gfo_usr_dlg usr_dlg;
private final Js_wtr js_wtr = new Js_wtr();
private final Js_wtr js_wtr = new Js_wtr();
public Gxw_html_server(Gfo_usr_dlg usr_dlg, Xosrv_socket_wtr wtr) {
this.usr_dlg = usr_dlg; this.wtr = wtr;
}
@ -36,6 +36,7 @@ public class Gxw_html_server implements Gxw_html {
public boolean Html_js_eval_proc_as_bool(String name, Object... args) {return Exec_as_bool(js_wtr.Write_statement_return_func(name, args).To_str_and_clear());}
public String Html_js_eval_script(String script) {return Exec_as_str(script);}
public void Html_js_cbks_add(String js_func_name, GfoInvkAble invk) {}
public String Html_js_send_json(String name, String data) {throw Err_.new_unimplemented();}
public void Html_invk_src_(GfoEvObj v) {}
public GxwCore_base Core() {throw Err_.new_unimplemented();}
public GxwCbkHost Host() {throw Err_.new_unimplemented();} public void Host_set(GxwCbkHost host) {throw Err_.new_unimplemented();}

@ -61,7 +61,7 @@ public class Xosrv_server implements GfoInvkAble {
Xosrv_msg rsp_msg = Xosrv_msg.new_(rsp_name, msg.Msg_id(), msg.Recipient(), msg.Sender(), msg.Msg_date(), Bry_.new_u8(rsp_str));
app.Usr_dlg().Note_many("", "", "sending rsp: bytes=~{0}", String_.Len(rsp_str));
wtr.Write(rsp_msg);
app.Usr_dlg().Note_many("", "", "rsp sent: elapsed=~{0}", TimeSpanAdp_.fracs_(Env_.TickCount() - time_bgn).XtoStrUiAbbrv());
app.Usr_dlg().Note_many("", "", "rsp sent: elapsed=~{0}", Time_span_.fracs_(Env_.TickCount() - time_bgn).XtoStrUiAbbrv());
} catch (Exception e) {app.Usr_dlg().Warn_many("", "", "server error: ~{0}", Err_.Message_gplx_full(e));}
}
private String Exec_cmd(String msg_text) {
@ -80,7 +80,7 @@ public class Xosrv_server implements GfoInvkAble {
trace.Val_("json_write: " + Object_.Xto_str_strict_or_null_mark(rv_obj));
return json_wtr.Write_root(Bry_xowa_js_result, rv_obj).Bld_as_str();
} catch (Exception e) {throw Err_.new_exc(e, "http", "exec_js error", "trace", trace, "msg", msg_text);}
} private Xosrv_xowa_exec_parser xowa_exec_parser = new Xosrv_xowa_exec_parser(); private Json_doc_srl json_wtr = new Json_doc_srl(); private static final byte[] Bry_xowa_js_result = Bry_.new_a7("xowa_js_result");
} private Xosrv_xowa_exec_parser xowa_exec_parser = new Xosrv_xowa_exec_parser(); private Json_doc_srl json_wtr = new Json_doc_srl(); private static final byte[] Bry_xowa_js_result = Bry_.new_a7("xowa_js_result");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_rdr_port)) return rdr_port;
else if (ctx.Match(k, Invk_rdr_port_)) rdr_port = m.ReadInt("v");
@ -94,7 +94,7 @@ public class Xosrv_server implements GfoInvkAble {
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_stop = "stop", Invk_rdr_port = "rdr_port", Invk_rdr_port_ = "rdr_port_", Invk_wtr_port = "wtr_port", Invk_wtr_port_ = "wtr_port_", Invk_wtr_host = "wtr_host", Invk_wtr_host_ = "wtr_host_"
public static final String Invk_stop = "stop", Invk_rdr_port = "rdr_port", Invk_rdr_port_ = "rdr_port_", Invk_wtr_port = "wtr_port", Invk_wtr_port_ = "wtr_port_", Invk_wtr_host = "wtr_host", Invk_wtr_host_ = "wtr_host_"
, Invk_shutdown_interval = "shutdown_interval", Invk_shutdown_interval_ = "shutdown_interval_";
}
class Xosrv_xowa_exec_parser {

@ -53,7 +53,10 @@ public class Xow_url_parser {
Xow_wiki wiki_itm = app.Wiki_mgri().Get_by_or_make_init_y(wiki_bry); // NOTE: must call Init to load Main_Page; only call if from url_bar, else all sister wikis will be loaded when parsing Sister_wikis panel
rv.Page_bry_(wiki_itm.Props().Main_page());
}
Xoa_ttl ttl = wiki.Ttl_parse(rv.Page_bry()); // parse to ttl to get proper casing; EX: "earth" -> "Earth" x> "earth"; DATE:2016-03-25
Xow_wiki parse_wiki = wiki;
if (!Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: url's wiki is different than current wiki
parse_wiki = app.Wiki_mgr().Get_by_or_make_init_y(wiki_bry); // NOTE: change parse_wiki to url's wiki; needed to handle transition from home to en.d or other case-sensitivity wiki; EX: "d:earth" -> "earth" x> "Earth"; DATE:2016-04-28
Xoa_ttl ttl = parse_wiki .Ttl_parse(rv.Page_bry()); // NOTE: parse to ttl to get proper casing; EX: "earth" -> "Earth" x> "earth"; DATE:2016-03-25
rv.Page_bry_(ttl.Full_db());
return rv;
}

@ -108,13 +108,13 @@ public class Xob_bldr implements GfoInvkAble {
throw Err_.new_exc(e, "bldr", "unknown error", "key", cmd.Cmd_key());
}
Env_.GarbageCollect();
app.Usr_dlg().Note_many("", "", "cmd end: ~{0} ~{1}", cmd.Cmd_key(), TimeSpanAdp_.from_(time_cur).XtoStrUiAbbrv());
app.Usr_dlg().Note_many("", "", "cmd end: ~{0} ~{1}", cmd.Cmd_key(), Time_span_.from_(time_cur).XtoStrUiAbbrv());
}
for (int i = 0; i < cmd_mgr_len; i++) {
Xob_cmd cmd = cmd_mgr.Get_at(i);
cmd.Cmd_term();
}
app.Usr_dlg().Note_many("", "", "bldr done: ~{0}", TimeSpanAdp_.from_(time_bgn).XtoStrUiAbbrv());
app.Usr_dlg().Note_many("", "", "bldr done: ~{0}", Time_span_.from_(time_bgn).XtoStrUiAbbrv());
cmd_mgr.Clear();
if (pause_at_end && !Env_.Mode_testing()) {Console_adp__sys.Instance.Read_line("press enter to continue");}
}

@ -23,7 +23,7 @@ import gplx.xowa.wikis.domains.*;
import gplx.xowa.bldrs.wms.*; import gplx.xowa.bldrs.wms.dumps.*;
public class Xoi_cmd_wiki_tst {
@Test public void Run() { // MAINT
// Bld_import_list(Xow_domain_regy.All);
Bld_import_list(Xow_domain_regy.All);
// Bld_cfg_files(Xow_domain_regy.All); // NOTE: remember to carry over the wikisource / page / index commands from the existing xowa_build_cfg.gfs; also, only run the xowa_build_cfg.gfs once; DATE:2013-10-15; last run: DATE:2014-09-09
}
public void Bld_import_list(String... ary) {
@ -46,15 +46,16 @@ public class Xoi_cmd_wiki_tst {
for (int j = 0; j < 5; ++j) {
latest_html = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(url);
if (latest_html != null) break;
Tfds.Dbg("fail|" + url);
Tfds.Dbg("fail|" + domain_str + "|" + url);
if (j == 4) return;
}
Tfds.Dbg("pass|" + url);
parser.Parse(latest_html);
Xowm_dump_file dump_file = new Xowm_dump_file(domain_str, "latest", Xowm_dump_type_.Str__pages_articles);
dump_file.Server_url_(Xowm_dump_file_.Server_wmf_https);
byte[] pages_articles_key = Bry_.new_a7(wmf_key + "-latest-pages-articles.xml.bz2");
Wmf_latest_itm latest_itm = parser.Get_by(pages_articles_key);
if (latest_itm == null) {Tfds.Dbg("missing|" + domain_str + "|" + url); return;} // NOTE: commonswiki missing entry for commonswiki-latest-pages-articles.xml.bz2 DATE:2016-05-01
Tfds.Dbg("pass|" + url);
bfr.Add(domain_bry).Add_byte_pipe();
bfr.Add_str_u8(dump_file.File_url()).Add_byte_pipe();
bfr.Add(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id())).Add_byte_pipe();

@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.consoles.*; import gplx.langs.htmls.encoders.*;
public class Xof_file_wkr_ {
public static final Gfo_url_encoder Md5_decoder = Gfo_url_encoder_.New__http_url().Init__same__many(Byte_ascii.Plus).Make();
public static byte[] Md5_fast(byte[] v) {return Bry_.new_a7(gplx.core.security.HashAlgo_.Md5.CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(v)));}
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
public static final Gfo_url_encoder Md5_decoder = Gfo_url_encoder_.New__http_url().Init__same__many(Byte_ascii.Plus).Make();
public static byte[] Md5_fast(byte[] v) {return md5_hash.Hash_bry_as_bry(v);}
public static byte[] Md5(byte[] ttl) {
ttl = Md5_decoder.Decode(Ttl_standardize(ttl));
return Xof_file_wkr_.Md5_fast(ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title

@ -16,17 +16,17 @@ 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.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.gfobjs.*;
public class Xog_cbk_mgr { // INSTANCE:app
private Xog_cbk_wkr[] wkrs = Xog_cbk_wkr_.Ary_empty; private int wkrs_len = 0;
public void Reg(Xog_cbk_wkr wkr) {
this.wkrs = (Xog_cbk_wkr[])Array_.Resize_add_one(wkrs, wkrs_len, wkr);
++wkrs_len;
}
public void Send_prog(String head, Object... args) {
String msg = gplx.core.errs.Err_msg.To_str(head, args);
public void Send_json(String func, Gfobj_nde data) {
for (int i = 0; i < wkrs_len; ++i) {
Xog_cbk_wkr wkr = wkrs[i];
wkr.Send_prog(msg);
wkr.Send_json(func, data);
}
}
}

@ -16,8 +16,9 @@ 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.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.gfobjs.*;
public interface Xog_cbk_wkr {
void Send_prog(String head);
Object Send_json(String func, Gfobj_nde data);
}
class Xog_cbk_wkr_ {
public static final Xog_cbk_wkr[] Ary_empty = new Xog_cbk_wkr[0];

@ -15,18 +15,24 @@ 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.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
import gplx.xowa.addons.updates.downloads.core.*;
import gplx.xowa.addons.updates.downloads.itms.*;
class Xodl_download_mgr implements Gfo_download_cbk {
public void Download(Gfo_download_wkr download_wkr, Xodl_itm_pack[] packs) {
download_wkr.Download__bgn(this, packs);
package gplx.xowa.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
import gplx.core.gfobjs.*;
public class Gfobj_wtr__json__swt extends Gfobj_wtr__json { private final Bry_bfr bfr;
public Gfobj_wtr__json__swt() {
this.Opt_ws_(Bool_.N);
this.bfr = this.Bfr();
}
public void Download__end_itm(Gfo_download_itm itm) {
// unzip; start
}
public void Download__end_all(Gfo_download_itm[] itms) {}
public void Unzip__end(Gfo_download_itm[] itms) {
// register
public String Write_as_func(String func_name, Gfobj_grp root) {
bfr.Add(Bry__func_bgn);
bfr.Add_str_u8(func_name);
bfr.Add(Bry__args_bgn);
this.Write(root);
bfr.Add(Bry__args_end);
return this.To_str();
}
private static final byte[]
Bry__func_bgn = Bry_.new_a7("return ")
, Bry__args_bgn = Bry_.new_a7("('")
, Bry__args_end = Bry_.new_a7("');")
;
}

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.core.gfobjs.*;
public class Gfobj_wtr__json__swt_tst {
private final Gfobj_wtr__json__swt_fxt fxt = new Gfobj_wtr__json__swt_fxt();
@Test public void Json_proc() {
fxt.Test__json_proc
( "proc_name"
, fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_long ("k2", 2)
, fxt.Make__fld_int ("k3", 3)
)
, "return proc_name('{\"k1\":\"v1\",\"k2\":2,\"k3\":3}');"
);
}
}
class Gfobj_wtr__json__swt_fxt extends Gfobj_wtr__json_fxt { public Gfobj_wtr__json__swt_fxt Test__json_proc() {return this;}
public void Test__json_proc(String proc_name, Gfobj_nde root, String expd) {
Gfobj_wtr__json__swt wtr = new Gfobj_wtr__json__swt();
String actl = wtr.Write_as_func(proc_name, root);
Gftest.Eq__str(expd, actl, "json_write");
}
}

@ -0,0 +1,48 @@
/*
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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
import gplx.core.gfobjs.*;
import gplx.gfui.*; import gplx.xowa.guis.*;
public class Xog_cbk_wkr__swt implements Xog_cbk_wkr {
private final Xoa_gui_mgr gui_mgr;
private final Xog_browser_func browser_func;
private final Gfobj_wtr__json__swt json_wtr = new Gfobj_wtr__json__swt();
public Xog_cbk_wkr__swt(Xoa_gui_mgr gui_mgr) {
this.gui_mgr = gui_mgr;
this.browser_func = new Xog_browser_func(gui_mgr.Browser_win().Active_tab().Html_box());
}
public Object Send_json(String func, Gfobj_nde data) {
String script = json_wtr.Write_as_func(func, data);
GfuiInvkCmd swt_cmd = gui_mgr.Kit().New_cmd_sync(browser_func.Init(script));
return GfoInvkAble_.Invk(swt_cmd);
}
}
class Xog_browser_func implements GfoInvkAble {
private final Gfui_html html_box;
private String script;
public Xog_browser_func(Gfui_html html_box) {
this.html_box = html_box;
}
public Xog_browser_func Init(String script) {
this.script = script;
return this;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return html_box.Html_js_eval_script(script);
}
}

@ -19,5 +19,6 @@ package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.
import gplx.langs.jsons.*;
public interface Bridge_cmd_itm {
byte[] Key();
void Init_by_app(Xoa_app app);
String Exec(Json_nde data);
}

@ -34,7 +34,10 @@ public class Bridge_cmd_mgr {
byte[] key_bry = msg.Get_bry(Key_cmd);
Bridge_cmd_itm cmd = (Bridge_cmd_itm)cmd_hash.Get_by_bry(key_bry); if (cmd == null) throw Err_.new_("bridge.cmds", "unknown cmd", "cmd", cmd);
try {return cmd.Exec(msg.Get(Key_data));}
catch (Exception e) {throw Err_.new_exc(e, "bridge.cmds", "exec json failed", "json", jdoc_bry);}
catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "exec json failed: ~{0}", "json", jdoc_bry);
throw Err_.new_exc(e, "bridge.cmds", "exec json failed", "json", jdoc_bry);
}
}
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_data = Bry_.new_a7("data");
}

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.bridges.dbuis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*;
import gplx.langs.jsons.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
public class Dbui_cmd_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
private final Hash_adp_bry hash = Hash_adp_bry.cs();
private boolean init;
public void Init_by_bridge(Bridge_cmd_mgr cmd_mgr) {
if (init) return;
@ -54,34 +54,38 @@ public class Dbui_cmd_mgr {
}
return rv;
}
public static final Dbui_cmd_mgr Instance = new Dbui_cmd_mgr(); Dbui_cmd_mgr() {}
private static final byte[]
public static final Dbui_cmd_mgr Instance = new Dbui_cmd_mgr(); Dbui_cmd_mgr() {}
private static final byte[]
Arg_tbl_key = Bry_.new_a7("tbl_key"), Arg_row_pkey = Bry_.new_a7("row_pkey"), Arg_row_id = Bry_.new_a7("row_id")
, Arg_vals = Bry_.new_a7("vals"), Arg_key = Bry_.new_a7("key"), Arg_val = Bry_.new_a7("val")
, Arg_pkeys = Bry_.new_a7("pkeys")
;
}
class Dbui_cmd_row_del implements Bridge_cmd_itm {
private final Dbui_cmd_mgr mgr;
private final Dbui_cmd_mgr mgr;
public Dbui_cmd_row_del(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Key() {return key;} private final byte[] key;
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {return mgr.Del(data);}
}
class Dbui_cmd_row_edit implements Bridge_cmd_itm {
private final Dbui_cmd_mgr mgr;
private final Dbui_cmd_mgr mgr;
public Dbui_cmd_row_edit(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Key() {return key;} private final byte[] key;
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {return mgr.Edit(data);}
}
class Dbui_cmd_row_save implements Bridge_cmd_itm {
private final Dbui_cmd_mgr mgr;
private final Dbui_cmd_mgr mgr;
public Dbui_cmd_row_save(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Key() {return key;} private final byte[] key;
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {return mgr.Save(data);}
}
class Dbui_cmd_row_reorder implements Bridge_cmd_itm {
private final Dbui_cmd_mgr mgr;
private final Dbui_cmd_mgr mgr;
public Dbui_cmd_row_reorder(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Key() {return key;} private final byte[] key;
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {return mgr.Reorder(data);}
}

@ -125,8 +125,6 @@ public class Xoh_js_cbk implements GfoInvkAble {
Xowe_wiki wiki = html_itm.Owner_tab().Wiki();
byte[] search_str = Bry_.new_u8((String)m.ReadValAt(0));
byte[] cbk_func = Bry_.new_u8((String)m.ReadValAt(1));
app.Gui_mgr().Search_cfg().Search(wiki, search_str, cbk_func);
return "";
}

@ -45,7 +45,7 @@ public class Xol_lang_itm_ {
return Char_tid_misc;
}
}
public static final byte[] Key_en = Bry_.new_a7("en");
public static final byte[] Key_en = Bry_.new_a7("en");
public static Xol_lang_itm Lang_en_make(Xoa_lang_mgr lang_mgr) {
Xol_lang_itm rv = new Xol_lang_itm(lang_mgr, Xol_lang_itm_.Key_en);
Xol_lang_itm_.Lang_init(rv);
@ -269,7 +269,7 @@ kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pagesincategory_files, "pagesincategory_fil
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_revisionsize, "REVISIONSIZE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_pagebanner, "PAGEBANNER"); // NOTE: must be casematch; EX: in en.v, {{pagebanner}} is actually template name which calls {{PAGEBANNER}}
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_protectionexpiry, "PROTECTIONEXPIRY");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_new_window_link, "#NewWindowLink"
);
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_new_window_link, "#NewWindowLink");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_categorytree, "#categorytree");
}
}

@ -232,8 +232,9 @@ public static final int
, Id_pagebanner = 210
, Id_rev_protectionexpiry = 211
, Id_new_window_link = 212
, Id_categorytree = 213
;
public static final int Id__max = 213;
public static final int Id__max = 214;
private static byte[] ary_itm_(int id) {
switch (id) {
@ -450,6 +451,7 @@ case Xol_kwd_grp_.Id_rev_revisionsize: return Bry_.new_u8("revisionsize");
case Xol_kwd_grp_.Id_pagebanner: return Bry_.new_u8("pagebanner");
case Xol_kwd_grp_.Id_rev_protectionexpiry: return Bry_.new_u8("protectionexpiry");
case Xol_kwd_grp_.Id_new_window_link: return Bry_.new_u8("newwindowlink");
case Xol_kwd_grp_.Id_categorytree: return Bry_.new_u8("categorytree");
default: throw Err_.new_unhandled(id);
}
}

@ -22,7 +22,7 @@ import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*;
import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.lnkis.redlinks.*;
public class Xop_lnki_wkr_ {
private static final Int_obj_ref rel2abs_tid = Int_obj_ref.zero_();
private static final Int_obj_ref rel2abs_tid = Int_obj_ref.zero_();
public static final int Invalidate_lnki_len = 128;
public static int Invalidate_lnki(Xop_ctx ctx, byte[] src, Xop_root_tkn root, Xop_lnki_tkn lnki, int cur_pos) {
lnki.Tkn_tid_to_txt(); // convert initial "[[" to text; note that this lnki has no pipes as pipe_lxr does similar check; EX: [[<invalid>]]; DATE:2014-03-26
@ -108,12 +108,12 @@ public class Xop_lnki_wkr_ {
}
public static void Thumbtime_parse(Xop_ctx ctx, byte[] src, Number_parser number_parser, Xop_lnki_tkn lnki, Arg_nde_tkn arg) {
int val_tkn_bgn = arg.Val_tkn().Src_bgn(), val_tkn_end = arg.Val_tkn().Src_end();
long fracs = TimeSpanAdp_.parse_to_fracs(src, val_tkn_bgn, val_tkn_end, false);
if (fracs == TimeSpanAdp_.parse_null) {
long fracs = Time_span_.parse_to_fracs(src, val_tkn_bgn, val_tkn_end, false);
if (fracs == Time_span_.parse_null) {
ctx.Msg_log().Add_itm_none(Xop_lnki_log.Upright_val_is_invalid, src, val_tkn_bgn, val_tkn_end);
}
else
lnki.Time_(fracs / TimeSpanAdp_.Ratio_f_to_s);
lnki.Time_(fracs / Time_span_.Ratio_f_to_s);
}
public static boolean Adjust_for_brack_end_len_of_3(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int cur_pos, Xop_lnki_tkn lnki) {
if ( cur_pos < src_len // bounds check
@ -138,4 +138,10 @@ public class Xop_lnki_wkr_ {
}
return false;
}
public static void Write_lnki(Bry_bfr bfr, Xoa_ttl ttl, boolean literal) {
bfr.Add(Xop_tkn_.Lnki_bgn);
if (literal) bfr.Add_byte(Byte_ascii.Colon);
bfr.Add(ttl.Full_db());
bfr.Add(Xop_tkn_.Lnki_end);
}
}

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

Loading…
Cancel
Save