1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.5.1.1'

This commit is contained in:
gnosygnu
2016-05-01 21:06:12 -04:00
parent 5ce4ea2a08
commit 96636f3161
131 changed files with 2287 additions and 928 deletions

View File

@@ -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;
}

View File

@@ -15,7 +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.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.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
;
}

View File

@@ -15,10 +15,13 @@ 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);}
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;}
}

View File

@@ -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;
}

View File

@@ -15,8 +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.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();
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_grp {
byte Grp_tid();
}

View File

@@ -15,7 +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.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);
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
class Gfobj_grp_ {
public static final byte
Grp_tid__ary = 0
, Grp_tid__nde = 1
;
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.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();}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -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"
, "]"
, ""
);
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();

View File

@@ -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 = "";

View File

@@ -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);

View File

@@ -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() {}
}

View File

@@ -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));
}
}

View File

@@ -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;}
}

View File

@@ -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
// }

View File

@@ -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
}
]
}
*/

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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() {}
*/
}

View File

@@ -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'

View File

@@ -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;

View File

@@ -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 {

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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);
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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;}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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();
}

View File

@@ -15,9 +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_itm {
String Download__src();
Io_url Download__trg();
void Download__trg_(Io_url v);
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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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());

View File

@@ -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);
}

View File

@@ -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;}
}

View File

@@ -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() {}
}

View File

@@ -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() {}
}

View File

@@ -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() {}
// }

View File

@@ -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();}

View File

@@ -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 {

View File

@@ -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;
}

View File

@@ -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");}
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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];

View File

@@ -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("');")
;
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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");
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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");
}

View File

@@ -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);}
}

View File

@@ -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 "";
}

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -29,6 +29,7 @@ public class Xow_cache_mgr {
public Xow_page_cache Page_cache() {return page_cache;} private Xow_page_cache page_cache;
public Xow_defn_cache Defn_cache() {return defn_cache;} private Xow_defn_cache defn_cache;
public Xow_defn_cache Lst_cache() {return lst_cache;} private Xow_defn_cache lst_cache;
public Hash_adp Misc_cache() {return misc_cache;} private final Hash_adp misc_cache = Hash_adp_.new_();
public Keyval[] Scrib_lang_names() {
if (scrib_lang_names == null) {
List_adp list = List_adp_.new_();
@@ -47,6 +48,7 @@ public class Xow_cache_mgr {
tmpl_result_cache.Clear();
defn_cache.Free_mem_all();
page_cache.Free_mem_all();
misc_cache.Clear();
lst_cache.Free_mem_all();
scrib_lang_names = null;
}

View File

@@ -32,7 +32,7 @@ public class Xopage_html_data {
page.Html_data().Display_ttl_(display_ttl);
page.Html_data().Custom_body_(this.Body());
page.Html_data().Custom_head_tags().Copy(head_tags);
page.Html_data().Custom_tail_tags().Copy(head_tags);
page.Html_data().Custom_tail_tags().Copy(tail_tags);
}
public static Xopage_html_data err_(String msg) {return new Xopage_html_data(Bry_.Empty, Bry_.new_u8(msg));}

View File

@@ -63,4 +63,8 @@ public class Xopg_tag_itm {
public static Xopg_tag_itm New_js_code(byte[] code) {
return new Xopg_tag_itm(Gfh_tag_.Bry__script , code, Keyval_.new_("type", "text/javascript"));
}
public static Xopg_tag_itm New_html_code(Io_url url, String tmpl) {
byte[] html = Io_mgr.Instance.LoadFilBry(url);
return new Xopg_tag_itm(Gfh_tag_.Bry__script , html, Keyval_.new_("type", "text/html"), Keyval_.new_("id", tmpl));
}
}

View File

@@ -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.xowa.xtns.categorytrees; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.htmls.core.htmls.utls.*;
public class Categorytree_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_categorytree;}
@Override public Pf_func New(int id, byte[] name) {return new Categorytree_func().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return;
Xow_wiki wiki = ctx.Wiki();
Xoa_ttl ctg_ttl = wiki.Ttl_parse(gplx.xowa.wikis.nss.Xow_ns_.Tid__category, argx); if (ctg_ttl == null) return; // ignore bad titles; EX: {{#categorytree:<>}}
gplx.xowa.parsers.lnkis.Xop_lnki_wkr_.Write_lnki(bfr, ctg_ttl, true);
}
public static final Categorytree_func Instance = new Categorytree_func(); Categorytree_func() {}
}

View File

@@ -15,8 +15,11 @@ 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.xtns.categorytrees; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Categorytree_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test__parse__tmpl_to_html("{{#categorytree:A B}}", "<a href='/wiki/Category:A_B'>Category:A B</a>");
}
}

View File

@@ -24,7 +24,7 @@ public class Geoc_isin_func_tst {
}
}
class Geoc_isin_func_fxt {
private final Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
}

View File

@@ -19,6 +19,7 @@ package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa
import gplx.core.brys.fmtrs.*; import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.envs.*;
import gplx.xowa.apps.progs.*;
public class Xof_math_mgr implements GfoInvkAble {
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
private Xoae_app app;
public Process_adp Cmd_convert_tex_to_dvi() {return cmd_convert_tex_to_dvi;} private Process_adp cmd_convert_tex_to_dvi = new Process_adp();
public Process_adp Cmd_convert_dvi_to_png() {return cmd_convert_dvi_to_png;} private Process_adp cmd_convert_dvi_to_png = new Process_adp();
@@ -29,11 +30,11 @@ public class Xof_math_mgr implements GfoInvkAble {
cmd_convert_dvi_to_png = app_mgr.App_convert_dvi_to_png();
}
private Io_url Make_math_dir(String wiki_key) {return app.Fsys_mgr().Root_dir().GenSubDir_nest("file", wiki_key, "math");}
public Xof_math_html_wtr Html_wtr() {return html_wtr;} private final Xof_math_html_wtr html_wtr = new Xof_math_html_wtr();
public Xof_math_html_wtr Html_wtr() {return html_wtr;} private final Xof_math_html_wtr html_wtr = new Xof_math_html_wtr();
public void Make_itm(Xof_math_itm rv, String wiki_key, byte[] math_bry) {
Io_url math_dir = Make_math_dir(wiki_key);
math_bry = app.Math_subst_regy().Subst(math_bry);
String md5 = gplx.core.security.HashAlgo_.Md5.CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(math_bry));
String md5 = md5_hash.Hash_bry_as_str(math_bry);
Io_url png_fil = Make_png_fil(math_dir, md5);
rv.Ctor(math_bry, md5, png_fil);
}

View File

@@ -241,6 +241,7 @@ public class Pf_func_ {
, Xol_kwd_grp_.Id_rev_revisionsize
, Xol_kwd_grp_.Id_pagebanner
, Xol_kwd_grp_.Id_rev_protectionexpiry
, Xol_kwd_grp_.Id_categorytree
};
public static Xot_defn Get_prototype(int id) {
switch (id) {
@@ -408,6 +409,7 @@ public class Pf_func_ {
case Xol_kwd_grp_.Id_insider: return gplx.xowa.xtns.insiders.Insider_func.Instance;
case Xol_kwd_grp_.Id_massMessage_target: return gplx.xowa.xtns.massMessage.Message_target_func.Instance;
case Xol_kwd_grp_.Id_categorytree: return gplx.xowa.xtns.categorytrees.Categorytree_func.Instance;
case Xol_kwd_grp_.Id_pendingChangeLevel: return gplx.xowa.xtns.flaggedRevs.Pending_change_level_func.Instance;
case Xol_kwd_grp_.Id_pagesUsingPendingChanges: return gplx.xowa.xtns.flaggedRevs.Pages_using_pending_changes_func.Instance;

View File

@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_if_tst {
private final Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void If_y() {fxt.Test_parse_tmpl_str_test("{{#if:1|a|b}}" , "{{test}}" , "a");}
@Test public void If_n() {fxt.Test_parse_tmpl_str_test("{{#if:|a|b}}" , "{{test}}" , "b");}
@Test public void If_n() {fxt.Test_parse_tmpl_str_test("{{#if:|a|b}}" , "{{test}}" , "b");}
@Test public void If_n_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b}}" , "{{test}}" , "b");}
@Test public void If_y_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b \n}}" , "{{test}}" , "b");}
@Test public void If_y_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b \n}}" , "{{test}}" , "b");}
@Test public void If_y_ws1() {fxt.Test_parse_tmpl_str_test("{{#if: |a|{{#if: |a|b}}\n}}" , "{{test}}" , "b");}
@Test public void If_prm_n() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test}}" , "b");}
@Test public void If_prm_y() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test|a}}" , "a");}
@@ -31,7 +31,7 @@ public class Pfunc_if_tst {
@Test public void If_prm_nest_0() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test}}" , "c");}
@Test public void If_prm_nest_1() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1}}" , "b");}
@Test public void If_prm_nest_2() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1|2}}" , "a");}
@Test public void If_ignore_key() {fxt.Test_parse_tmpl_str_test("{{#if:|<i id=1|<i id=2}}" , "{{test}}" , "<i id=2");}
@Test public void If_ignore_key() {fxt.Test_parse_tmpl_str_test("{{#if:|<i id=1|<i id=2}}" , "{{test}}" , "<i id=2");}
@Test public void If_newline() { // PURPOSE: new_line in comments; WP:[[redirect-distinguish|a|b]]
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{#if:1<!--"

View File

@@ -38,9 +38,9 @@ public class Pfunc_scrib_lib implements Scrib_lib {
}
private static final int Proc_expr = 0;
public static final String Invk_expr = "expr";
private static final String[] Proc_names = String_.Ary(Invk_expr);
private static final String[] Proc_names = String_.Ary(Invk_expr);
public boolean Expr(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] expr_bry = args.Pull_bry(0);
byte[] expr_bry = args.Xstr_bry_or_null(0); // NOTE: some modules will pass in an int; PAGE:en.w:531_BC DATE:2016-04-29
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b128();
Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry);
String expr_rslt = tmp_bfr.To_str_and_rls();

View File

@@ -28,6 +28,9 @@ public class Pfunc_scrib_lib_tst {
@Test public void Expr__pass() {
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("1 + 2") , "3");
}
@Test public void Expr__int() {
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary(3) , "3"); // int should not cause class cast error; PAGE:en.w:531_BC; DATE:2016-04-29
}
@Test public void Expr__fail() { // PURPOSE: if bad input don't throw error; return error message; PAGE:es.w:Freer_(Texas) DATE:2015-07-28
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("fail") , "<strong class=\"error\">Expression error: Unrecognised word \"fail\"</strong>");
}

View File

@@ -56,6 +56,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
Xox_mgr_base.Xtn_write_escape(app, bfr, code);
bfr.Add(Xoh_consts.Pre_end);
}
private static final gplx.core.security.Hash_algo sha1_hash = gplx.core.security.Hash_algo_.New__sha1();
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xowe_wiki wiki = ctx.Wiki(); Xoae_page page = ctx.Page();
Score_xtn_mgr score_xtn = (Score_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Score_xtn_mgr.XTN_KEY);
@@ -68,7 +69,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
if (ly_process.Exe_exists() == Bool_.N_byte) {Html_write_code_as_pre(bfr, app); return;}
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
tmp_bfr.Add(code).Add_byte_pipe().Add_int_bool(lang_is_abc).Add_byte_pipe().Add_int_bool(code_is_raw);
sha1 = gplx.core.security.HashAlgo_.Sha1.Calc_hash_bry(tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
sha1 = sha1_hash.Hash_bry_as_bry(tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
sha1_prefix = String_.new_a7(sha1, 0, 8);
output_dir = app.Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str(), "lilypond", Char_.To_str(sha1[0]), Char_.To_str(sha1[1]), String_.new_a7(sha1)); // NOTE: MW also adds an extra level for 8-len; EX: /.../sha1_32_len/sha1_8_len/
png_file = output_dir.GenSubFil(sha1_prefix + ".png");

View File

@@ -24,7 +24,34 @@ public class Scrib_proc_args {
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
public Keyval[] Pull_kv_ary(int i) {return (Keyval[])Get_or_fail(i);}
public Keyval[] Pull_kv_ary_safe(int idx) { // NOTE: must check for null array items; EX:[2:v2] -> [1:null,2:v2]; PAGE:en.d:Category:Nouns_by_language DATE:2016-04-29
Keyval[] rv = (Keyval[])Get_or_fail(idx);
List_adp list = null;
int rv_len = rv.length;
for (int i = 0; i < rv_len; ++i) {
Keyval kv = rv[i];
if ( kv.Key_tid() == Type_adp_.Tid__int // luaj will be int
|| kv.Key_tid() == Type_adp_.Tid__obj) { // lua will be obj; note that luaj will also have other non-key objects
Object key_obj = kv.Key_as_obj();
if (key_obj.getClass() == Int_.Cls_ref_type) { // key is int; cast it
int key_int = Int_.cast(kv.Key_as_obj());
if (key_int != i + 1) { // key_int should match i; if not, then gaps exist; EX:[2:v2] should be 2nd element, not 1st
if (list == null) {
list = List_adp_.new_();
rv = null;
}
for (int j = 0; j < key_int - 1; ++j) // add everything up to key_int as null; EX: [2:v2] -> [1:null]
list.Add(Keyval_.int_(j + List_adp_.Base1, null));
}
}
}
if (rv == null)
list.Add(kv);
}
if (rv == null)
rv = (Keyval[])list.To_ary(Keyval.class);
return rv;
}
public int Pull_int(int i) {Object rv = Get_or_fail(i);
try {return Int_.coerce_(rv);} // coerce to handle "1" and 1; will still fail if "abc" is passed
catch (Exception e) {

View File

@@ -45,7 +45,7 @@ public class Luaj_engine implements Scrib_engine {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_registerLibrary);
msg.set("name", "mw_interface");
msg.set("functions", Luaj_value_.X_obj_to_val(server, functions));
msg.set("functions", Luaj_value_.Obj_to_lua_val(server, functions));
server.Dispatch(msg);
}
public Keyval[] CallFunction(int id, Keyval[] args) {
@@ -54,7 +54,7 @@ public class Luaj_engine implements Scrib_engine {
msg.set("op", Val_callFunction);
msg.set("id", LuaValue.valueOf(id));
msg.set("nargs", LuaValue.valueOf(args_len));
msg.set("args", Luaj_value_.X_obj_to_val(server, args));
msg.set("args", Luaj_value_.Obj_to_lua_val(server, args));
return this.Dispatch_as_kv_ary(msg);
}
public Keyval[] ExecuteModule(int mod_id) {
@@ -63,7 +63,7 @@ public class Luaj_engine implements Scrib_engine {
public void CleanupChunks(Keyval[] ids) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", "cleanupChunks");
msg.set("ids", Luaj_value_.X_obj_to_val(server, ids));
msg.set("ids", Luaj_value_.Obj_to_lua_val(server, ids));
this.Dispatch_as_kv_ary(msg);
}
public Keyval[] Dispatch_as_kv_ary(LuaTable msg) {
@@ -103,7 +103,7 @@ public class Luaj_engine implements Scrib_engine {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_returnMessage);
msg.set("nvalues", LuaValue.valueOf(values.length));
msg.set("values", Luaj_value_.X_obj_to_val(server, values));
msg.set("values", Luaj_value_.Obj_to_lua_val(server, values));
return msg;
}
private LuaTable ReturnFail(String fail_msg) {

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.luaj; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import java.util.*;
import org.luaj.vm2.*;
class Luaj_value_ {
public static String Get_val_as_str(LuaTable owner, String key) {
@@ -26,9 +27,9 @@ class Luaj_value_ {
}
public static Keyval[] Get_val_as_kv_ary(Luaj_server server, LuaTable owner, String key) {
LuaTable table = (LuaTable)owner.get(key);
return Luaj_value_.X_tbl_to_kv_ary(server, table);
return Luaj_value_.Lua_tbl_to_kv_ary(server, table);
}
public static Keyval[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
public static Keyval[] Lua_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
List_adp temp = List_adp_.new_();
LuaValue cur = LuaValue.NIL;
int len = 0;
@@ -36,7 +37,7 @@ class Luaj_value_ {
Varargs itm = tbl.next(cur);
if (itm == LuaValue.NIL) break; // no more pairs; stop
LuaValue itm_val = itm.arg(2); // val is itm 2
Object itm_val_obj = X_val_to_obj(server, itm_val);
Object itm_val_obj = Lua_val_to_obj(server, itm_val);
LuaValue itm_key = itm.arg(1);
Keyval kv = null;
if (itm_val.type() == LuaValue.TFUNCTION) { // function is converted to Scrib_lua_proc
@@ -51,7 +52,8 @@ class Luaj_value_ {
else {
switch (itm_key.type()) {
case LuaValue.TNUMBER:
kv = Keyval_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
int key_int = ((LuaNumber)itm_key).toint();
kv = Keyval_.int_(key_int, itm_val_obj);
break;
case LuaValue.TSTRING:
kv = Keyval_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
@@ -67,7 +69,7 @@ class Luaj_value_ {
if (len == 0) return Keyval_.Ary_empty;
return (Keyval[])temp.To_ary(Keyval.class);
}
private static Object X_val_to_obj(Luaj_server server, LuaValue v) {
private static Object Lua_val_to_obj(Luaj_server server, LuaValue v) {
switch (v.type()) {
case LuaValue.TNIL: return null;
case LuaValue.TBOOLEAN: return ((LuaBoolean)v).toboolean();
@@ -78,12 +80,12 @@ class Luaj_value_ {
return v_num.toint();
else
return v_num.todouble();
case LuaValue.TTABLE: return X_tbl_to_kv_ary(server, (LuaTable)v);
case LuaValue.TTABLE: return Lua_tbl_to_kv_ary(server, (LuaTable)v);
case LuaValue.TFUNCTION: return server.Get_id_by_closure(v);
default: throw Err_.new_unhandled(v.type());
}
}
public static LuaValue X_obj_to_val(Luaj_server server, Object o) {
public static LuaValue Obj_to_lua_val(Luaj_server server, Object o) {
if (o == null) return LuaValue.NIL;
Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o);
@@ -92,8 +94,8 @@ class Luaj_value_ {
else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o);
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)o);
else if (Object_.Eq(c, byte[].class)) return LuaValue.valueOf(String_.new_u8((byte[])o));
else if (Object_.Eq(c, Keyval.class)) return X_kv_ary_to_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return X_kv_ary_to_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Keyval.class)) return Kv_ary_to_lua_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return Kv_ary_to_lua_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Long_.Cls_ref_type)) return LuaValue.valueOf((Long)o);
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
else if (Object_.Eq(c, Float_.Cls_ref_type)) return LuaValue.valueOf((Float)o);
@@ -101,12 +103,12 @@ class Luaj_value_ {
else if (Object_.Eq(c, Short_.Cls_ref_type)) return LuaValue.valueOf((Short)o);
else return LuaValue.NIL;
}
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {
private static LuaTable Kv_ary_to_lua_tbl(Luaj_server server, Keyval... ary) {
LuaTable rv = LuaValue.tableOf();
int len = ary.length;
for (int i = 0; i < len; i++) {
Keyval itm = ary[i];
LuaValue itm_val = X_obj_to_val(server, itm.Val());
LuaValue itm_val = Obj_to_lua_val(server, itm.Val());
switch (itm.Key_tid()) {
case Type_adp_.Tid__int:
rv.set(Int_.cast(itm.Key_as_obj()), itm_val);

View File

@@ -19,16 +19,16 @@ package gplx.xowa.xtns.scribunto.engines.mocks; import gplx.*; import gplx.xowa.
import gplx.core.primitives.*;
public abstract class Mock_proc_fxt {
public Mock_proc_fxt(int id, String key) {this.id = id; this.key = key;}
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public Scrib_lua_proc To_scrib_lua_proc() {return new Scrib_lua_proc(key, id);}
public abstract Keyval[] Exec_by_scrib(Keyval[] args);
}
class Mock_engine implements Scrib_engine {
private final Hash_adp hash = Hash_adp_.new_();
private final Int_obj_ref tmp_hash_id = Int_obj_ref.neg1_();
private final Hash_adp hash = Hash_adp_.new_();
private final Int_obj_ref tmp_hash_id = Int_obj_ref.neg1_();
public boolean Dbg_print() {return false;} public void Dbg_print_(boolean v) {}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {} private final Mock_server server = new Mock_server();
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {} private final Mock_server server = new Mock_server();
public Scrib_lua_proc LoadString(String name, String text) {return null;}
public Keyval[] CallFunction(int id, Keyval[] args) {
Mock_proc_fxt proc = (Mock_proc_fxt)hash.Get_by_or_fail(tmp_hash_id.Val_(id));
@@ -37,7 +37,7 @@ class Mock_engine implements Scrib_engine {
public void RegisterLibrary(Keyval[] functions_ary) {}
public Keyval[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(Keyval[] ids) {}
public void Clear() {}
public void Clear() {hash.Clear();}
public void RegisterLibraryForTest(Mock_proc_fxt proc) {
hash.Add(Int_obj_ref.new_(proc.Id()), proc);
}

View File

@@ -36,6 +36,7 @@ public class Mock_scrib_fxt {
core.When_page_changed(parser_fxt.Page());
}
public void Init__cbk(Mock_proc_fxt... ary) {
engine.Clear();
for (Mock_proc_fxt proc : ary)
engine.RegisterLibraryForTest(proc);
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.texts.*;
import gplx.core.encoders.*;
import gplx.xowa.xtns.scribunto.libs.*;
public class Process_engine implements Scrib_engine {
private Scrib_core core; private Xoae_app app; private Scrib_xtn_mgr scrib_opts;
@@ -85,7 +85,7 @@ public class Process_engine implements Scrib_engine {
return Keyval_.Ary_empty;
}
}
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec
private void Dispatch_bld_send(Bry_bfr bfr, Object[] ary) {
int len = ary.length; if (len % 2 != 0) throw Err_.new_wo_type("arguments must be factor of 2", "len", len);
bfr.Add(Dispatch_hdr);
@@ -102,7 +102,7 @@ public class Process_engine implements Scrib_engine {
bfr.Add_byte(Byte_ascii.Curly_end);
int msg_len = bfr.Len() - 16; // 16 for Dispatch_hdr_len
int chk_len = (msg_len * 2) -1; // defined by Scribunto
HexDecUtl.Write(bfr.Bfr(), 0, 8, msg_len);
HexDecUtl.Write(bfr.Bfr(), 9, 16, chk_len);
Hex_utl_.Write(bfr.Bfr(), 0, 8, msg_len);
Hex_utl_.Write(bfr.Bfr(), 9, 16, chk_len);
}
}

View File

@@ -53,7 +53,7 @@ public class Process_send_wtr {
bfr.Add_int_variable(prc.Id());
bfr.Add_byte(Byte_ascii.Brack_end);
return true;
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
private boolean Encode_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_byte(Byte_ascii.Curly_bgn);
@@ -82,17 +82,18 @@ public class Process_send_wtr {
public boolean Encode_obj(Bry_bfr bfr, Object o) {
if (o == null) {bfr.Add(CONST_nil); return true;}
Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
else if (Object_.Eq(c, Long_.Cls_ref_type)) bfr.Add_long_variable(Long_.cast(o));
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}
else if (Object_.Eq(c, String.class)) {if (!Encode_str(bfr, (String)o)) return false;}
else if (Object_.Eq(c, byte[].class)) {if (!Encode_str(bfr, (byte[])o)) return false;} // NOTE: not in Scribunto; added here for PERF of not re-creating a String Object
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
else if (Object_.Eq(c, Keyval.class)) {if (!Encode_kv(bfr, (Keyval)o)) return false;}
else if (Object_.Eq(c, Keyval[].class)) {if (!Encode_ary(bfr, (Keyval[])o)) return false;}
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: {0}", Type_adp_.NameOf_obj(o));}
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: ~{0}", Type_adp_.NameOf_obj(o));}
return true;
}
private static final byte[] CONST_nil = Bry_.new_a7("nil"), CONST_bool_true = Bry_.new_a7("true"), CONST_bool_false = Bry_.new_a7("false"), CONST_escape_000 = Bry_.new_a7("\\000");
private static final byte[] CONST_nil = Bry_.new_a7("nil"), CONST_bool_true = Bry_.new_a7("true"), CONST_bool_false = Bry_.new_a7("false"), CONST_escape_000 = Bry_.new_a7("\\000");
private static final String GRP_KEY = "xowa-scribunto-lua-srl";
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.threads.*;
import gplx.core.texts.HexDecUtl;
import gplx.core.encoders.*;
import gplx.xowa.xtns.scribunto.*;
import gplx.core.threads.Thread_adp_;
import java.io.*;

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.ios.*; import gplx.core.texts.*;
import gplx.core.ios.*; import gplx.core.encoders.*;
public class Process_stream_rdr {
public Process_stream_rdr(byte[] bry_header, byte[] bry_body) {this.bry_header = bry_header; this.bry_body = bry_body;} private byte[] bry_header, bry_body;
public IoStream_stream_rdr Rdr() {return rdr;} IoStream_stream_rdr rdr = new IoStream_stream_rdr();
@@ -26,8 +26,8 @@ public class Process_stream_rdr {
if (bytes_read == -1) return null; // stream closed; should only occur when shutting down
else throw Err_.new_wo_type("failed to read header");
}
int body_len = HexDecUtl.parse_or(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
int chk_len= HexDecUtl.parse_or(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
int body_len = Hex_utl_.Parse_or(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
int chk_len= Hex_utl_.Parse_or(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
byte[] trg_bry = (body_len > bry_body.length) ? new byte[body_len] : bry_body;
return Read_body(trg_bry, body_len, rdr);
}

View File

@@ -41,17 +41,17 @@ public class Scrib_lib_message implements Scrib_lib {
}
private static final int Proc_plain = 0, Proc_check = 1, Proc_init_message_for_lang = 2;
public static final String Invk_plain = "plain", Invk_check = "check", Invk_init_message_for_lang = "init_message_for_lang";
private static final String[] Proc_names = String_.Ary(Invk_plain, Invk_check, Invk_init_message_for_lang);
private static final String[] Proc_names = String_.Ary(Invk_plain, Invk_check, Invk_init_message_for_lang);
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean Plain(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte fmt_tid = Scrib_lib_message_data.Fmt_tid_plain;
Keyval[] data_kvary = args.Pull_kv_ary(0);
Keyval[] data_kvary = args.Pull_kv_ary_safe(0);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(String_.new_u8(msg_data.Make_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), true, fmt_tid)));
}
public boolean Check(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte chk_tid = Scrib_lib_message_data.parse_chk_(args.Pull_bry(0));
Keyval[] data_kvary = args.Pull_kv_ary(1);
Keyval[] data_kvary = args.Pull_kv_ary_safe(1);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(msg_data.Chk_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), false, chk_tid));
}
@@ -153,7 +153,7 @@ class Scrib_lib_message_data {
return msg_val;
}
static final byte Key_tid_keys = 1, Key_tid_rawMessage = 2, Key_tid_lang = 3, Key_tid_useDB = 4, Key_tid_title = 5, Key_tid_params = 6;
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("keys", Key_tid_keys)
.Add_str_byte("rawMessage", Key_tid_rawMessage)
.Add_str_byte("lang", Key_tid_lang)
@@ -168,14 +168,14 @@ class Scrib_lib_message_data {
return ((Byte_obj_val)o).Val();
}
public static final byte Fmt_tid_parse = 1, Fmt_tid_text = 2, Fmt_tid_plain = 3, Fmt_tid_escaped = 4, Fmt_tid_parseAsBlock = 5;
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("parse", Fmt_tid_parse)
.Add_str_byte("text", Fmt_tid_text)
.Add_str_byte("plain", Fmt_tid_plain)
.Add_str_byte("escaped", Fmt_tid_escaped)
.Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
public static final byte Check_tid_exists = 1, Check_tid_isBlank = 2, Check_tid_isDisabled = 3;
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("exists", Check_tid_exists)
.Add_str_byte("isBlank", Check_tid_isBlank)
.Add_str_byte("isDisabled", Check_tid_isDisabled);

View File

@@ -306,7 +306,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (ttl == null) return rslt.Init_ary_empty(); // invalid ttl;
if (!ttl.ForceLiteralLink() && ttl.Ns().Id_is_main()) // title is not literal and is not prefixed with Template; parse again as template; EX: ":A" and "Template:A" are fine; "A" is parsed again as "Template:A"
ttl = Xoa_ttl.parse(cur_wiki, Bry_.Add(cur_wiki.Ns_mgr().Ns_template().Name_db_w_colon(), ttl_bry)); // parse again, but add "Template:"
Keyval[] args_ary = args.Pull_kv_ary(2);
Keyval[] args_ary = args.Pull_kv_ary_safe(2);
// BLOCK.bgn:Xot_invk_tkn.Transclude; cannot reuse b/c Transclude needs invk_tkn, and invk_tkn is manufactured late; DATE:2014-01-02
byte[] sub_src = null;
if (ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
@@ -359,7 +359,7 @@ public class Scrib_lib_mw implements Scrib_lib {
ttl = Xoa_ttl.parse(cur_wiki, Bry_.new_u8((String)ttl_obj));
if (ttl == null) throw Err_.new_wo_type("newChild: invalid title", "title", (String)ttl_obj);
}
Keyval[] args_ary = args.Pull_kv_ary(2);
Keyval[] args_ary = args.Pull_kv_ary_safe(2);
Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt_w_ttl_case(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14
String new_frame_id = "frame" + Int_.To_str(frame_list_len);
frame_list.Add(new_frame_id, new_frame);

View File

@@ -18,10 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*;
public class Scrib_lib_mw__lib_tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_mw().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
}
@Test public void ParentFrameExists() {
fxt.Init_frame_parent("test");
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, true);
@@ -79,6 +80,11 @@ public class Scrib_lib_mw__lib_tst {
@Test public void NewChildFrame() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_newChildFrame, Object_.Ary("current", "Page_0", Scrib_kv_utl_.flat_many_("key1", "val1")), "frame0");
}
@Test public void ExpandTemplate__null_arg() {
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Parser_fxt().Data_create("Template:A", "b{{{1}}}c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "A", Scrib_kv_utl_.flat_many_(2, "v2")), "bc"); // list: args is ary
}
@Test public void SetTTL() {
fxt.Test_scrib_proc_empty(lib, Scrib_lib_mw.Invk_setTTL, Object_.Ary(123));
Tfds.Eq(123, fxt.Core().Frame_current().Frame_lifetime());

View File

@@ -99,17 +99,23 @@ public class Scrib_lib_site implements Scrib_lib {
local = 0;
else if (filter != null)
throw Err_.new_wo_type("bad argument #1 to 'interwikiMap' (unknown filter '$filter')", "filter", filter);
// TODO: cache interwikimap results
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
Keyval[][] rv = new Keyval[xwiki_len][];
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
rv[i] = InterwikiMap_itm(itm, prefix, itm_is_local);
Hash_adp misc_cache = core.Wiki().Cache_mgr().Misc_cache();
String cache_key = "scribunto.interwikimap." + core.Wiki().Domain_str() + "." + filter;
Keyval[] rv = (Keyval[])misc_cache.Get_by(cache_key);
if (rv == null) {
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
List_adp list = List_adp_.new_();
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
list.Add(Keyval_.new_(prefix, InterwikiMap_itm(itm, prefix, itm_is_local)));
}
rv = (Keyval[])list.To_ary_and_clear(Keyval.class);
misc_cache.Add(cache_key, rv);
}
return rslt.Init_obj(rv);
}

View File

@@ -52,6 +52,19 @@ public class Scrib_lib_site_tst {
@Test public void PagesInNs() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
}
@Test public void InterwikiMap() {
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_interwikiMap, Object_.Ary("!local"), String_.Concat_lines_nl_skip_last
( "1="
, " en.wikipedia.org="
, " prefix=en.wikipedia.org"
, " url=en.wikipedia.org"
, " isProtocolRelative=false"
, " isLocal=false"
, " isTranscludable=false"
, " isCurrentWiki=false"
, " isExtraLanguageLink=false"
));
}
@Test public void Init_lib_site() {
Xowe_wiki wiki = fxt.Core().Wiki();
wiki.Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);

View File

@@ -144,7 +144,7 @@ public class Scrib_lib_title implements Scrib_lib {
Keyval[] rv = new Keyval[4];
rv[ 0] = Keyval_.new_("isRedirect" , ttl_redirect); // title.isRedirect
rv[ 1] = Keyval_.new_("id" , ttl_id); // $title->getArticleID(),
rv[ 2] = Keyval_.new_("contentModel" , Key_wikitexet); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 2] = Keyval_.new_("contentModel" , Key_wikitext); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 3] = Keyval_.new_("exists" , ttl_exists); // $ret['id'] > 0; TODO: if Special: check regy of implemented pages
return rslt.Init_obj(rv);
}
@@ -227,5 +227,5 @@ public class Scrib_lib_title implements Scrib_lib {
rv[rv_idx++] = Keyval_.new_("file" , false); // REF.MW: if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) $ret['file'] = false;
return rv;
} private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
public static final String Key_wikitexet = "wikitext";
public static final String Key_wikitext = "wikitext";
}

View File

@@ -132,7 +132,7 @@ public class Scrib_lib_title_tst {
( "1="
, " isRedirect=" + Bool_.To_str_lower(redirect)
, " id=" + Int_.To_str(ttl_id)
, " contentModel=" + Scrib_lib_title.Key_wikitexet
, " contentModel=" + Scrib_lib_title.Key_wikitext
, " exists=" + Bool_.To_str_lower(exists)
);
}

View File

@@ -346,7 +346,10 @@ class Scrib_lib_ustring_gsub_mgr {
}
}
Keyval[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
tmp_bfr.Add_str_u8(Scrib_kv_utl_.Val_to_str(rslts, 0));
if (rslts.length > 0) { // ArrayIndex check
Object rslt_obj = rslts[0].Val(); // 0th idx has result
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_empty(rslt_obj)); // NOTE: always convert to String; rslt_obj can be int; PAGE:en.d:seven DATE:2016-04-27
}
break;
}
default: throw Err_.new_unhandled(repl_tid);

View File

@@ -56,6 +56,11 @@ public class Scrib_lib_ustring__gsub__tst {
Exec_gsub("ab", ".", -1, proc_root.To_scrib_lua_proc(), "ab;2"); // fails if "ab;4"
Tfds.Eq_str("0;1;2;0;1;2;", bfr.To_str_and_clear()); // fails if "0;1;1;1"
}
@Test public void Replace__proc__number() { // PURPOSE:handle replace-as-number in gproc; PAGE:en.d:seven; DATE:2016-04-27
Mock_proc__number proc = new Mock_proc__number(0);
fxt.Init__cbk(proc);
Exec_gsub("ab", ".", -1, proc.To_scrib_lua_proc(), "12;2"); // fails if "ab;4"
}
@Test public void Regx__int() { // PURPOSE: do not fail if integer is passed in for @regx; PAGE:en.d:λύω DATE:2014-09-02
Exec_gsub("abcd", 1 , -1, "A" , "abcd;0");
}
@@ -102,3 +107,10 @@ class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_f
return args;
}
}
class Mock_proc__number extends Mock_proc_fxt { private int counter = 0;
public Mock_proc__number(int id) {super(id, "number");}
@Override public Keyval[] Exec_by_scrib(Keyval[] args) {
args[0].Val_(++counter); // set replace-val to int
return args;
}
}

View File

@@ -21,6 +21,7 @@ import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.p
public class Tabber_xnde implements Xox_xnde {
private byte[] id;
private Tabber_tab_itm[] tab_itms_ary;
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
@@ -28,7 +29,7 @@ public class Tabber_xnde implements Xox_xnde {
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
List_adp tab_itms_list = List_adp_.new_();
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
this.id = Id_test == null ? gplx.core.security.HashAlgo_.Md5.Calc_hash_bry(xnde_body) : Id_test;
this.id = Id_test == null ? md5_hash.Hash_bry_as_bry(xnde_body) : Id_test;
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
for (int i = 0; i < tab_itms.length; ++i) {
byte[] tab_itm = tab_itms[i];