mirror of https://github.com/gnosygnu/xowa
parent
5ce4ea2a08
commit
96636f3161
@ -0,0 +1,70 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Hex_utl__tst {
|
||||
private final Hex_utl__fxt fxt = new Hex_utl__fxt();
|
||||
@Test public void To_int() {
|
||||
fxt.Test__to_int("0" , 0);
|
||||
fxt.Test__to_int("F" , 15);
|
||||
fxt.Test__to_int("0F" , 15);
|
||||
fxt.Test__to_int("10" , 16);
|
||||
fxt.Test__to_int("20" , 32);
|
||||
fxt.Test__to_int("FF" , 255);
|
||||
fxt.Test__to_int("100" , 256);
|
||||
fxt.Test__to_int("0a" , 10);
|
||||
fxt.Test__to_int("7FFFFFFF" , Int_.Max_value);
|
||||
fxt.Test__to_int_bry("100" , 256);
|
||||
}
|
||||
@Test public void To_str() {
|
||||
fxt.Test__to_str(0 , "0");
|
||||
fxt.Test__to_str(15 , "F");
|
||||
fxt.Test__to_str(16 , "10");
|
||||
fxt.Test__to_str(32 , "20");
|
||||
fxt.Test__to_str(255 , "FF");
|
||||
fxt.Test__to_str(Int_.Max_value, "7FFFFFFF");
|
||||
|
||||
fxt.Test__to_str(15, 2 , "0F");
|
||||
fxt.Test__to_str(15, 3 , "00F");
|
||||
}
|
||||
@Test public void Write() {
|
||||
fxt.Test__write("[00000000]", 1, 9, 15, "[0000000F]");
|
||||
fxt.Test__write("[00000000]", 1, 9, 255, "[000000FF]");
|
||||
}
|
||||
}
|
||||
class Hex_utl__fxt {
|
||||
public void Test__write(String s, int bgn, int end, int val, String expd) {
|
||||
byte[] bry = Bry_.new_a7(s);
|
||||
Hex_utl_.Write(bry, bgn, end, val);
|
||||
Tfds.Eq(expd, String_.new_a7(bry));
|
||||
}
|
||||
public void Test__to_int(String raw, int expd) {
|
||||
int actl = Hex_utl_.Parse(raw);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
public void Test__to_int_bry(String raw, int expd) {Tfds.Eq(expd, Hex_utl_.Parse_or(Bry_.new_a7(raw), -1));}
|
||||
public void Test__to_str(int val, String expd) {Test__to_str(val, 0, expd);}
|
||||
public void Test__to_str(int val, int pad, String expd) {
|
||||
String actl = Hex_utl_.To_str(val, pad);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
// public void Test__encode_bry(int val, int pad, String expd) {
|
||||
// String actl = Hex_utl_.To_str(val, pad);
|
||||
// Tfds.Eq(expd, actl);
|
||||
// }
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.progs; import gplx.*; import gplx.core.*;
|
||||
public abstract class Gfo_prog_ui_base implements Gfo_prog_ui {
|
||||
public boolean Prog__started() {return started;} private boolean started;
|
||||
public boolean Prog__paused() {return paused;} private boolean paused;
|
||||
public boolean Prog__finished() {return finished;} private boolean finished;
|
||||
public boolean Prog__canceled() {return canceled;} private boolean canceled;
|
||||
public long Prog__cur() {return cur;} private long cur;
|
||||
public long Prog__end() {return end;} private long end; public void Prog__end_(long v) {this.end = v;}
|
||||
public void Prog__start() {started = true;}
|
||||
public void Prog__pause() {paused = true;}
|
||||
public void Prog__resume() {paused = false;}
|
||||
public void Prog__cancel() {canceled = true;}
|
||||
@gplx.Virtual public void Prog__notify__finished() {
|
||||
this.finished = true;
|
||||
}
|
||||
@gplx.Virtual public byte Prog__notify__working(long cur, long end) {
|
||||
this.cur = cur; this.end = end;
|
||||
if (paused) return Gfo_prog_ui_.State__paused;
|
||||
else if (canceled) return Gfo_prog_ui_.State__canceled;
|
||||
else return Gfo_prog_ui_.State__started;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import gplx.core.consoles.*; import gplx.core.stores.*;
|
||||
import gplx.core.ios.*; /*IoStream*/import gplx.core.texts.*; /*Base32Converter*/
|
||||
public class HashAlgo_ {
|
||||
public static final HashAlgo Null = new HashAlgo_null();
|
||||
public static final HashAlgo Sha1 = HashAlgo_sha1.new_();
|
||||
public static final HashAlgo Md5 = HashAlgo_md5.new_();
|
||||
public static final HashAlgo Tth192 = HashAlgo_tth192.new_();
|
||||
public static HashAlgo as_(Object obj) {return obj instanceof HashAlgo ? (HashAlgo)obj : null;}
|
||||
public static HashAlgo cast(Object obj) {if (obj == null) return null; HashAlgo rv = as_(obj); if (rv == null) throw Err_.new_type_mismatch(HashAlgo.class, obj); return rv;}
|
||||
public static HashAlgo fetch_(String key) {
|
||||
if (key == HashAlgo_md5.KEY) return Md5;
|
||||
else if (key == HashAlgo_sha1.KEY) return Sha1;
|
||||
else if (key == HashAlgo_tth192.KEY) return Tth192;
|
||||
else throw Err_.new_unhandled(key);
|
||||
}
|
||||
public static HashAlgo store_orSelf_(SrlMgr mgr, String key, HashAlgo or) {
|
||||
String algoType = mgr.SrlStrOr(key, or.Key());
|
||||
return mgr.Type_rdr() ? HashAlgo_.fetch_(algoType): or;
|
||||
}
|
||||
}
|
||||
class HashAlgo_null implements HashAlgo {
|
||||
public String Key() {return "HashAlgo_null";}
|
||||
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(v)));}
|
||||
public String CalcHash(Console_adp dialog, IoStream stream) {return "NullAlgoHash";}
|
||||
}
|
||||
class HashAlgo_md5 implements HashAlgo {
|
||||
public String Key() {return KEY;} public static final String KEY = "md5";
|
||||
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, IoStream_.ary_(v)));}
|
||||
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "MD5");}
|
||||
public static HashAlgo_md5 new_() {return new HashAlgo_md5();} HashAlgo_md5() {}
|
||||
}
|
||||
class HashAlgo_sha1 implements HashAlgo {
|
||||
public String Key() {return KEY;} public static final String KEY = "sha1";
|
||||
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, IoStream_.ary_(v)));}
|
||||
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "SHA1");}
|
||||
public static HashAlgo_sha1 new_() {return new HashAlgo_sha1();} HashAlgo_sha1() {}
|
||||
}
|
||||
class HashAlgoUtl {
|
||||
public static String CalcHashAsString(Console_adp dialog, IoStream stream, String key) {
|
||||
MessageDigest md = null;
|
||||
try {md = MessageDigest.getInstance(key);}
|
||||
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
|
||||
byte[] buffer = new byte[8192];
|
||||
int read = 0;
|
||||
long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
|
||||
while (true) {
|
||||
read = stream.Read(buffer, 0, 8192);
|
||||
if (pos >= len) break;
|
||||
md.update(buffer, 0, read);
|
||||
pos += read;
|
||||
}
|
||||
byte[] md5sum = md.digest();
|
||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
String rv = bigInt.toString(16);
|
||||
int rvLen = rv.length();
|
||||
while (rvLen < 32) {
|
||||
rv = "0" + rv;
|
||||
rvLen++;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String XtoStrBase16(byte[] ary) {
|
||||
BigInteger bigInt = new BigInteger(1, ary);
|
||||
String rv = bigInt.toString(16);
|
||||
int rvLen = rv.length();
|
||||
while (rvLen < 32) {
|
||||
rv = "0" + rv;
|
||||
rvLen++;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String XtoStrBase32(byte[] ary) {return Base32Converter.Encode(ary);}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
|
||||
public class HashAlgo_md5_tst {
|
||||
@Test public void Empty() {
|
||||
tst_CalcBase16FromString("", "d41d8cd98f00b204e9800998ecf8427e");
|
||||
}
|
||||
@Test public void A() {
|
||||
tst_CalcBase16FromString("a", "0cc175b9c0f1b6a831c399e269772661");
|
||||
}
|
||||
@Test public void Abc() {
|
||||
tst_CalcBase16FromString("abc", "900150983cd24fb0d6963f7d28e17f72");
|
||||
}
|
||||
@Test public void A_Za_z0_9() {
|
||||
tst_CalcBase16FromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f");
|
||||
}
|
||||
//@Test
|
||||
public void A_1Million() {
|
||||
tst_CalcBase16FromString(String_.Repeat("a", 1000000), "7707d6ae4e027c70eea2a935c2296f21");
|
||||
}
|
||||
void tst_CalcBase16FromString(String raw, String expd) {
|
||||
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
|
||||
String actl = HashAlgo_.Md5.CalcHash(Console_adp_.Noop, stream);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
/*
|
||||
https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
|
||||
Set 1, vector# 0:
|
||||
message="" (empty String)
|
||||
hash=D41D8CD98F00B204E9800998ECF8427E
|
||||
|
||||
Set 1, vector# 1:
|
||||
message="a"
|
||||
hash=0CC175B9C0F1B6A831C399E269772661
|
||||
|
||||
Set 1, vector# 2:
|
||||
message="abc"
|
||||
hash=900150983CD24FB0D6963F7D28E17F72
|
||||
|
||||
Set 1, vector# 3:
|
||||
message="message digest"
|
||||
hash=F96B697D7CB7938D525A2F31AAF161D0
|
||||
|
||||
Set 1, vector# 4:
|
||||
message="abcdefghijklmnopqrstuvwxyz"
|
||||
hash=C3FCD3D76192E4007DFB496CCA67E13B
|
||||
|
||||
Set 1, vector# 5:
|
||||
message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
hash=8215EF0796A20BCAAAE116D3876C664A
|
||||
|
||||
Set 1, vector# 6:
|
||||
message="A...Za...z0...9"
|
||||
hash=D174AB98D277D9F5A5611C2C9F419D9F
|
||||
|
||||
Set 1, vector# 7:
|
||||
message=8 times "1234567890"
|
||||
hash=57EDF4A22BE3C955AC49DA2E2107B67A
|
||||
|
||||
Set 1, vector# 8:
|
||||
message=1 million times "a"
|
||||
hash=7707D6AE4E027C70EEA2A935C2296F21
|
||||
*/
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
|
||||
public class HashAlgo_sha1_tst {
|
||||
@Test public void Empty() {
|
||||
tst_CalcBase16FromString("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
}
|
||||
@Test public void A() {
|
||||
tst_CalcBase16FromString("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
|
||||
}
|
||||
@Test public void Abc() {
|
||||
tst_CalcBase16FromString("abc", "a9993e364706816aba3e25717850c26c9cd0d89d");
|
||||
}
|
||||
@Test public void A_Za_z0_9() {
|
||||
tst_CalcBase16FromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "761c457bf73b14d27e9e9265c46f4b4dda11f940");
|
||||
}
|
||||
//@Test
|
||||
public void A_1Million() {
|
||||
tst_CalcBase16FromString(String_.Repeat("a", 1000000), "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
|
||||
}
|
||||
void tst_CalcBase16FromString(String raw, String expd) {
|
||||
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
|
||||
String actl = HashAlgo_.Sha1.CalcHash(Console_adp_.Noop, stream);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
/*
|
||||
https://www.cosic.esat.kuleuven.be/nessie/testvectors/
|
||||
Set 1, vector# 0:
|
||||
message="" (empty String)
|
||||
hash=DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
|
||||
|
||||
Set 1, vector# 1:
|
||||
message="a"
|
||||
hash=86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8
|
||||
|
||||
Set 1, vector# 2:
|
||||
message="abc"
|
||||
hash=A9993E364706816ABA3E25717850C26C9CD0D89D
|
||||
|
||||
Set 1, vector# 3:
|
||||
message="message digest"
|
||||
hash=C12252CEDA8BE8994D5FA0290A47231C1D16AAE3
|
||||
|
||||
Set 1, vector# 4:
|
||||
message="abcdefghijklmnopqrstuvwxyz"
|
||||
hash=32D10C7B8CF96570CA04CE37F2A19D84240D3A89
|
||||
|
||||
Set 1, vector# 5:
|
||||
message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
hash=84983E441C3BD26EBAAE4AA1F95129E5E54670F1
|
||||
|
||||
Set 1, vector# 6:
|
||||
message="A...Za...z0...9"
|
||||
hash=761C457BF73B14D27E9E9265C46F4B4DDA11F940
|
||||
|
||||
Set 1, vector# 7:
|
||||
message=8 times "1234567890"
|
||||
hash=50ABF5706A150990A08B2C5EA40FA0E585554732
|
||||
|
||||
Set 1, vector# 8:
|
||||
message=1 million times "a"
|
||||
hash=34AA973CD4C4DAA4F61EEB2BDBAD27316534016F
|
||||
*/
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
|
||||
public class HashAlgo_tth192_tst {
|
||||
@Test public void Char0000() {tst_CalcBase32FromString("", "LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ");}
|
||||
@Test public void Char0001() {tst_CalcBase32FromString("\0", "VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA");}
|
||||
@Test public void Char0002() {tst_CalcBase32FromString("ab", "XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ");}
|
||||
@Test public void Char0003() {tst_CalcBase32FromString("abc", "ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA");}
|
||||
@Test public void Char0004() {tst_CalcBase32FromString("abcd", "SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI");}
|
||||
@Test public void Char0005() {tst_CalcBase32FromString("abcde", "SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ");}
|
||||
@Test public void Char0009() {tst_CalcBase32FromString("abcdefghi", "RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY");}
|
||||
@Test public void Char1024() {tst_CalcBase32FromString(String_.Repeat("A", 1024), "L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA");}
|
||||
@Test public void Char1025() {tst_CalcBase32FromString(String_.Repeat("A", 1025), "PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY");}
|
||||
// @Test // commented out due to time (approx 17.94 seconds)
|
||||
public void Ax2Pow27() { // 134 MB
|
||||
tst_CalcBase32FromString(String_.Repeat("A", (int)Math_.Pow(2, 27)), "QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ");
|
||||
}
|
||||
void tst_CalcBase32FromString(String raw, String expd) {
|
||||
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
|
||||
String actl = HashAlgo_.Tth192.CalcHash(Console_adp_.Noop, stream);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
/*
|
||||
The empty (zero-length) file:
|
||||
urn:tree:tiger:LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ
|
||||
|
||||
A file with a single zero byte:
|
||||
urn:tree:tiger:VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA
|
||||
|
||||
A file with 1024 'A' characters:
|
||||
urn:tree:tiger:L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA
|
||||
|
||||
A file with 1025 'A' characters:
|
||||
urn:tree:tiger:PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY
|
||||
|
||||
http://open-content.net/specs/draft-jchapweske-thex-02.html
|
||||
|
||||
A file with 134,217,728 'A' characters (2 Pow 27)
|
||||
urn:tree:tiger:QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ
|
||||
queried against DC++ 0.698
|
||||
*/
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
public interface Hash_algo {
|
||||
String Key();
|
||||
byte[] Hash_bry_as_bry(byte[] src);
|
||||
String Hash_bry_as_str(byte[] src);
|
||||
String Hash_stream_as_str(gplx.core.consoles.Console_adp console, gplx.core.ios.IoStream src_stream);
|
||||
byte[] Hash_stream_as_bry(gplx.core.progs.Gfo_prog_ui prog_ui, gplx.core.ios.IoStream src_stream);
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
|
||||
import gplx.core.texts.*; /*Base32Converter*/ import gplx.core.progs.*;
|
||||
public class Hash_algo_ {
|
||||
public static Hash_algo New__md5() {return new Hash_algo__md5();}
|
||||
public static Hash_algo New__sha1() {return new Hash_algo__sha1();}
|
||||
public static Hash_algo New__sha2_256() {return new Hash_algo__sha2_256();}
|
||||
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
|
||||
public static Hash_algo New(String key) {
|
||||
if (key == Hash_algo__md5.KEY) return New__md5();
|
||||
else if (key == Hash_algo__sha1.KEY) return New__sha1();
|
||||
else if (key == Hash_algo__sha2_256.KEY) return New__sha2_256();
|
||||
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
|
||||
else throw Err_.new_unhandled(key);
|
||||
}
|
||||
}
|
||||
abstract class Hash_algo_base implements Hash_algo {
|
||||
private final MessageDigest md;
|
||||
private final byte[] trg_bry;
|
||||
private byte[] tmp_bfr; private final int tmp_bfr_len = 4096;
|
||||
public Hash_algo_base(MessageDigest md, int trg_bry_len) {
|
||||
this.md = md; this.trg_bry = new byte[trg_bry_len];
|
||||
}
|
||||
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
|
||||
public byte[] Hash_bry_as_bry(byte[] src) {
|
||||
Hash_algo_utl_.Hash_bry(md, src, src.length, trg_bry);
|
||||
return Bry_.Copy(trg_bry); // NOTE: must copy to return different instances to callers; else callers may hash same instance with different values
|
||||
}
|
||||
public String Hash_stream_as_str(Console_adp console, IoStream stream) {return String_.new_a7(Hash_stream_as_bry(console, stream));}
|
||||
public byte[] Hash_stream_as_bry(Console_adp console, IoStream stream) {
|
||||
if (tmp_bfr == null) tmp_bfr = new byte[4096];
|
||||
Hash_algo_utl_.Hash_stream(console, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
|
||||
return trg_bry;
|
||||
}
|
||||
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {
|
||||
if (tmp_bfr == null) tmp_bfr = new byte[4096];
|
||||
Hash_algo_utl_.Hash_stream(prog_ui, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
|
||||
return trg_bry;
|
||||
}
|
||||
protected static MessageDigest Get_message_digest(String key) {
|
||||
try {return MessageDigest.getInstance(key);}
|
||||
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
|
||||
}
|
||||
}
|
||||
class Hash_algo__md5 extends Hash_algo_base {
|
||||
public Hash_algo__md5() {super(Get_message_digest_instance(), 32);}
|
||||
public String Key() {return KEY;} public static final String KEY = "md5";
|
||||
|
||||
private static MessageDigest Get_message_digest_instance() {
|
||||
if (md__md5 == null)
|
||||
md__md5 = Get_message_digest(KEY);
|
||||
return md__md5;
|
||||
} private static MessageDigest md__md5;
|
||||
}
|
||||
class Hash_algo__sha1 extends Hash_algo_base {
|
||||
public Hash_algo__sha1() {super(Get_message_digest_instance(), 40);}
|
||||
public String Key() {return KEY;} public static final String KEY = "sha1";
|
||||
|
||||
private static MessageDigest Get_message_digest_instance() {
|
||||
if (md__sha1 == null)
|
||||
md__sha1 = Get_message_digest(KEY);
|
||||
return md__sha1;
|
||||
} private static MessageDigest md__sha1;
|
||||
}
|
||||
class Hash_algo__sha2_256 extends Hash_algo_base {
|
||||
public Hash_algo__sha2_256() {super(Get_message_digest_instance(), 64);}
|
||||
public String Key() {return KEY;} public static final String KEY = "sha-256";
|
||||
|
||||
private static MessageDigest Get_message_digest_instance() {
|
||||
if (md__sha2_256 == null)
|
||||
md__sha2_256 = Get_message_digest(KEY);
|
||||
return md__sha2_256;
|
||||
} private static MessageDigest md__sha2_256;
|
||||
}
|
||||
class Hash_algo_utl_ {
|
||||
public static void Hash_bry(MessageDigest md, byte[] src_bry, int src_len, byte[] trg_bry) {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
if (pos == src_len) break;
|
||||
int end = pos + 4096;
|
||||
if (end > src_len) end = src_len;
|
||||
md.update(src_bry, pos, end);
|
||||
pos = end;
|
||||
}
|
||||
byte[] md_bry = md.digest();
|
||||
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry, trg_bry);
|
||||
}
|
||||
public static void Hash_stream(Console_adp dialog, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
|
||||
// long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
|
||||
while (true) {
|
||||
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
|
||||
if (read < 1) break;
|
||||
md.update(tmp_bfr, 0, read);
|
||||
// pos += read;
|
||||
}
|
||||
byte[] md_bry = md.digest();
|
||||
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
|
||||
}
|
||||
public static void Hash_stream(Gfo_prog_ui prog_ui, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
|
||||
long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
|
||||
try {
|
||||
while (true) {
|
||||
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
|
||||
if (read < 1) break;
|
||||
md.update(tmp_bfr, 0, read);
|
||||
switch (prog_ui.Prog__notify__working(pos, len)) {
|
||||
case Gfo_prog_ui_.State__started: break;
|
||||
case Gfo_prog_ui_.State__canceled: return;
|
||||
case Gfo_prog_ui_.State__paused: if (!Gfo_prog_ui_.Sleep_while_paused(prog_ui)) return; break;
|
||||
}
|
||||
pos += read;
|
||||
}
|
||||
}
|
||||
finally {stream.Rls();}
|
||||
prog_ui.Prog__notify__finished();
|
||||
byte[] md_bry = md.digest();
|
||||
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
|
||||
}
|
||||
public static String To_base_32_str(byte[] ary) {return Base32Converter.Encode(ary);}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
|
||||
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5());
|
||||
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
|
||||
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
|
||||
@Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");}
|
||||
@Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");}
|
||||
@Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
|
||||
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
|
||||
//@Test
|
||||
public void Num__x_8() {fxt.Test__hash("57edf4a22be3c955ac49da2e2107b67a", String_.Repeat("1234567890", 8));}
|
||||
//@Test
|
||||
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
|
||||
}
|
||||
class Hash_algo__fxt {
|
||||
private final Hash_algo algo;
|
||||
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
|
||||
public void Test__hash(String expd, String raw) {
|
||||
Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw)));
|
||||
Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.IoStream_.mem_txt_(Io_url_.Empty, raw)));
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
|
||||
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1());
|
||||
@Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");}
|
||||
@Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");}
|
||||
@Test public void abc() {fxt.Test__hash("a9993e364706816aba3e25717850c26c9cd0d89d", "abc");}
|
||||
@Test public void message_digest() {fxt.Test__hash("c12252ceda8be8994d5fa0290a47231c1d16aae3", "message digest");}
|
||||
@Test public void a_z() {fxt.Test__hash("32d10c7b8cf96570ca04ce37f2a19d84240d3a89", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void a_q__mixed() {fxt.Test__hash("84983e441c3bd26ebaae4aa1f95129e5e54670f1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
|
||||
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("761c457bf73b14d27e9e9265c46f4b4dda11f940", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
|
||||
// @Test
|
||||
public void Num() {fxt.Test__hash("50abf5706a150990a08b2c5ea40fa0e585554732", String_.Repeat("1234567890", 8));}
|
||||
//@Test
|
||||
public void A_1Million() {fxt.Test__hash("34aa973cd4c4daa4f61eeb2bdbad27316534016f", String_.Repeat("a", 1000000));}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
|
||||
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256());
|
||||
@Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");}
|
||||
@Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");}
|
||||
@Test public void abc() {fxt.Test__hash("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");}
|
||||
@Test public void message_digest() {fxt.Test__hash("f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650", "message digest");}
|
||||
@Test public void a_z() {fxt.Test__hash("71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void a_q__mixed() {fxt.Test__hash("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
|
||||
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
|
||||
// @Test
|
||||
public void Num() {fxt.Test__hash("f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e", String_.Repeat("1234567890", 8));}
|
||||
//@Test
|
||||
public void A_1Million() {fxt.Test__hash("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0", String_.Repeat("a", 1000000));}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.security; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
|
||||
public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698
|
||||
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());
|
||||
@Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");}
|
||||
@Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");}
|
||||
@Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");}
|
||||
@Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");}
|
||||
@Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");}
|
||||
@Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");}
|
||||
@Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");}
|
||||
// @Test
|
||||
public void a__x_1024() {fxt.Test__hash("L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA", String_.Repeat("A", 1024));}
|
||||
// @Test
|
||||
public void a__x_1025() {fxt.Test__hash("PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY", String_.Repeat("A", 1025));}
|
||||
// @Test
|
||||
public void A__Pow27() {fxt.Test__hash("QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ", String_.Repeat("A", (int)Math_.Pow(2, 27)));
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.texts; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class HexDecUtl_tst {
|
||||
@Test public void XtoInt() {
|
||||
tst_XtoInt("0", 0);
|
||||
tst_XtoInt("F", 15);
|
||||
tst_XtoInt("0F", 15);
|
||||
tst_XtoInt("10", 16);
|
||||
tst_XtoInt("20", 32);
|
||||
tst_XtoInt("FF", 255);
|
||||
tst_XtoInt("100", 256);
|
||||
tst_XtoInt("0a", 10);
|
||||
tst_XtoInt("7FFFFFFF", Int_.Max_value);
|
||||
tst_XtoInt_bry("100", 256);
|
||||
}
|
||||
@Test public void To_str() {
|
||||
tst_XtoStr(0, "0");
|
||||
tst_XtoStr(15, "F");
|
||||
tst_XtoStr(16, "10");
|
||||
tst_XtoStr(32, "20");
|
||||
tst_XtoStr(255, "FF");
|
||||
tst_XtoStr(Int_.Max_value, "7FFFFFFF");
|
||||
|
||||
tst_XtoStr(15, 2, "0F");
|
||||
tst_XtoStr(15, 3, "00F");
|
||||
}
|
||||
@Test public void Write() {
|
||||
tst_Write("[00000000]", 1, 9, 15, "[0000000F]");
|
||||
tst_Write("[00000000]", 1, 9, 255, "[000000FF]");
|
||||
}
|
||||
private void tst_Write(String s, int bgn, int end, int val, String expd) {
|
||||
byte[] bry = Bry_.new_a7(s);
|
||||
HexDecUtl.Write(bry, bgn, end, val);
|
||||
Tfds.Eq(expd, String_.new_a7(bry));
|
||||
}
|
||||
private void tst_XtoInt(String raw, int expd) {
|
||||
int actl = HexDecUtl.parse(raw);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
private void tst_XtoInt_bry(String raw, int expd) {Tfds.Eq(expd, HexDecUtl.parse_or(Bry_.new_a7(raw), -1));}
|
||||
private void tst_XtoStr(int val, String expd) {tst_XtoStr(val, 0, expd);}
|
||||
private void tst_XtoStr(int val, int pad, String expd) {
|
||||
String actl = HexDecUtl.To_str(val, pad);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
public class Gfobj_ary_nde implements Gfobj_ary {
|
||||
public Gfobj_ary_nde(Gfobj_nde[] ary) {this.ary = ary;}
|
||||
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
|
||||
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__nde;}
|
||||
public int Len() {return ary.length;}
|
||||
public Object Get_at(int i) {return ary[i];}
|
||||
public Gfobj_nde[] Ary_nde() {return ary;} private Gfobj_nde[] ary;
|
||||
public void Ary_nde_(Gfobj_nde[] v) {this.ary = v;}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
public interface Gfobj_fld {
|
||||
byte Fld_tid();
|
||||
String Key();
|
||||
Object As_obj();
|
||||
}
|
||||
class Gfobj_fld_ {
|
||||
public static final byte
|
||||
Fld_tid__ary = 0
|
||||
, Fld_tid__nde = 1
|
||||
, Fld_tid__int = 2
|
||||
, Fld_tid__long = 3
|
||||
, Fld_tid__str = 4
|
||||
;
|
||||
}
|
||||
class Gfobj_fld_str implements Gfobj_fld {
|
||||
public Gfobj_fld_str(String key, String val) {this.key = key; this.val = val;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__str;}
|
||||
public Object As_obj() {return val;}
|
||||
public String As_str() {return val;} private String val;
|
||||
}
|
||||
class Gfobj_fld_int implements Gfobj_fld {
|
||||
public Gfobj_fld_int(String key, int val) {this.key = key; this.val = val;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__int;}
|
||||
public Object As_obj() {return val;}
|
||||
public int As_int() {return val;} private int val;
|
||||
}
|
||||
class Gfobj_fld_long implements Gfobj_fld {
|
||||
public Gfobj_fld_long(String key, long val) {this.key = key; this.val = val;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__long;}
|
||||
public Object As_obj() {return val;}
|
||||
public long As_long() {return val;} private long val;
|
||||
}
|
||||
class Gfobj_fld_nde implements Gfobj_fld {
|
||||
public Gfobj_fld_nde(String key, Gfobj_nde val) {this.key = key; this.val = val;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__nde;}
|
||||
public Object As_obj() {return val;}
|
||||
public Gfobj_nde As_nde() {return val;} private Gfobj_nde val;
|
||||
}
|
||||
class Gfobj_fld_ary implements Gfobj_fld {
|
||||
public Gfobj_fld_ary(String key, Gfobj_ary val) {this.key = key; this.val = val;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__ary;}
|
||||
public Object As_obj() {return val;}
|
||||
public Gfobj_ary As_ary() {return val;} private Gfobj_ary val;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
public class Gfobj_nde implements Gfobj_grp {
|
||||
private Ordered_hash subs;
|
||||
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__nde;}
|
||||
public int Len() {return subs == null ? 0 : subs.Len();}
|
||||
public Gfobj_fld Get_at(int i) {return subs == null ? null : (Gfobj_fld)subs.Get_at(i);}
|
||||
public Gfobj_fld Get_by(String k) {return subs == null ? null : (Gfobj_fld)subs.Get_by(k);}
|
||||
public Gfobj_nde Add_fld(Gfobj_fld fld) {if (subs == null) subs = Ordered_hash_.New(); subs.Add(fld.Key(), fld); return this;}
|
||||
public Gfobj_nde Add_int(String key, int val) {return Add_fld(new Gfobj_fld_int(key, val));}
|
||||
public Gfobj_nde Add_long(String key, long val) {return Add_fld(new Gfobj_fld_long(key, val));}
|
||||
public Gfobj_nde Add_str(String key, String val) {return Add_fld(new Gfobj_fld_str(key, val));}
|
||||
public Gfobj_nde Add_nde(String key, Gfobj_nde val) {return Add_fld(new Gfobj_fld_nde(key, val));}
|
||||
public Gfobj_nde Add_ary(String key, Gfobj_ary val) {return Add_fld(new Gfobj_fld_ary(key, val));}
|
||||
public Gfobj_nde New_nde(String key) {Gfobj_nde rv = new Gfobj_nde(); Add_fld(new Gfobj_fld_nde(key, rv)); return rv;}
|
||||
public Gfobj_ary_nde New_ary_nde(String key) {Gfobj_ary_nde rv = new Gfobj_ary_nde(null); Add_fld(new Gfobj_fld_ary(key, rv)); return rv;}
|
||||
public static Gfobj_nde New() {return new Gfobj_nde();}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Gfobj_wtr__json {
|
||||
private final Json_wtr wtr = new Json_wtr();
|
||||
public Gfobj_wtr__json Opt_ws_(boolean v) {wtr.Opt_ws_(v); return this;}
|
||||
public Bry_bfr Bfr() {return wtr.Bfr();}
|
||||
public String To_str() {return wtr.To_str_and_clear();}
|
||||
public Gfobj_wtr__json Write(Gfobj_grp root) {
|
||||
switch (root.Grp_tid()) {
|
||||
case Gfobj_grp_.Grp_tid__nde:
|
||||
wtr.Doc_nde_bgn();
|
||||
Write_nde((Gfobj_nde)root);
|
||||
wtr.Doc_nde_end();
|
||||
break;
|
||||
case Gfobj_grp_.Grp_tid__ary:
|
||||
wtr.Doc_ary_bgn();
|
||||
Write_ary((Gfobj_ary)root);
|
||||
wtr.Doc_ary_end();
|
||||
break;
|
||||
default:
|
||||
throw Err_.new_unhandled_default(root.Grp_tid());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Write_nde(Gfobj_nde nde) {
|
||||
int len = nde.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfobj_fld fld = (Gfobj_fld)nde.Get_at(i);
|
||||
Write_fld(fld);
|
||||
}
|
||||
}
|
||||
private void Write_fld(Gfobj_fld itm) {
|
||||
switch (itm.Fld_tid()) {
|
||||
case Gfobj_fld_.Fld_tid__str: wtr.Kv_str(itm.Key() , ((Gfobj_fld_str)itm).As_str()); break;
|
||||
case Gfobj_fld_.Fld_tid__int: wtr.Kv_int(itm.Key() , ((Gfobj_fld_int)itm).As_int()); break;
|
||||
case Gfobj_fld_.Fld_tid__long: wtr.Kv_long(itm.Key() , ((Gfobj_fld_long)itm).As_long()); break;
|
||||
case Gfobj_fld_.Fld_tid__nde: wtr.Nde_bgn(itm.Key()); Write_nde(((Gfobj_fld_nde)itm).As_nde()); wtr.Nde_end();break;
|
||||
case Gfobj_fld_.Fld_tid__ary: wtr.Ary_bgn(itm.Key()); Write_ary(((Gfobj_fld_ary)itm).As_ary()); wtr.Ary_end();break;
|
||||
default: throw Err_.new_unhandled_default(itm.Fld_tid());
|
||||
}
|
||||
}
|
||||
private void Write_ary(Gfobj_ary ary) {
|
||||
int len = ary.Len();
|
||||
byte ary_tid = ary.Ary_tid();
|
||||
switch (ary_tid) {
|
||||
case Gfobj_ary_.Ary_tid__str:
|
||||
String[] ary_str = ((Gfo_ary_str)ary).Ary_str();
|
||||
for (int i = 0; i < len; ++i)
|
||||
wtr.Ary_itm_str(ary_str[i]);
|
||||
break;
|
||||
case Gfobj_ary_.Ary_tid__int:
|
||||
int[] ary_int = ((Gfo_ary_int)ary).Ary_int();
|
||||
for (int i = 0; i < len; ++i)
|
||||
wtr.Ary_itm_obj(ary_int[i]);
|
||||
break;
|
||||
case Gfobj_ary_.Ary_tid__nde:
|
||||
Gfobj_nde[] ary_nde = ((Gfobj_ary_nde)ary).Ary_nde();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
wtr.Nde_bgn_ary();
|
||||
Write_nde(ary_nde[i]);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
break;
|
||||
case Gfobj_ary_.Ary_tid__ary:
|
||||
Gfobj_ary[] ary_ary = ((Gfo_ary_ary)ary).Ary_ary();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
wtr.Ary_bgn_ary();
|
||||
Write_ary(ary_ary[i]);
|
||||
wtr.Ary_end();
|
||||
}
|
||||
break;
|
||||
default: throw Err_.new_unhandled_default(ary_tid);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.tests.*; import gplx.langs.jsons.*;
|
||||
public class Gfobj_wtr__json_fxt {
|
||||
protected final Gfobj_wtr__json mgr = new Gfobj_wtr__json();
|
||||
public Gfobj_nde Make__nde(Gfobj_fld... ary) {return Make__nde(Gfobj_nde.New(), ary);}
|
||||
private Gfobj_nde Make__nde(Gfobj_nde nde, Gfobj_fld[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfobj_fld fld = (Gfobj_fld)ary[i];
|
||||
nde.Add_fld(fld);
|
||||
}
|
||||
return nde;
|
||||
}
|
||||
public Gfobj_fld Make__fld_str(String key, String val) {return new Gfobj_fld_str(key, val);}
|
||||
public Gfobj_fld Make__fld_int(String key, int val) {return new Gfobj_fld_int(key, val);}
|
||||
public Gfobj_fld Make__fld_long(String key, long val) {return new Gfobj_fld_long(key, val);}
|
||||
public Gfobj_fld Make__fld_nde(String key, Gfobj_fld... ary) {
|
||||
Gfobj_nde nde = Make__nde(Gfobj_nde.New(), ary);
|
||||
Gfobj_fld_nde rv = new Gfobj_fld_nde(key, nde);
|
||||
return rv;
|
||||
}
|
||||
public Gfobj_fld Make__fld_ary_str(String key, String... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_str(ary));}
|
||||
public Gfobj_fld Make__fld_ary_int(String key, int... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_int(ary));}
|
||||
public Gfobj_fld Make__fld_ary_ary(String key, Gfobj_ary... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_ary(ary));}
|
||||
public Gfobj_fld Make__fld_ary_nde(String key, Gfobj_nde... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary_nde(ary));}
|
||||
public Gfobj_ary Make__ary_int(int... ary) {return new Gfo_ary_int(ary);}
|
||||
public Gfobj_wtr__json_fxt Test__write(Gfobj_grp root, String... lines) {
|
||||
String[] expd = Json_doc.Make_str_ary_by_apos(lines);
|
||||
Gftest.Eq__ary(expd, Bry_.Ary(String_.SplitLines_nl(mgr.Write(root).To_str())), "json_write");
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Gfobj_wtr__json_tst {
|
||||
private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt();
|
||||
@Test public void Flds() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_long ("k2", 2)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':2"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Sub_ndes() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_nde ("k2"
|
||||
, fxt.Make__fld_str ("k2a", "v2a")
|
||||
, fxt.Make__fld_int ("k2b", 2)
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " { 'k2a':'v2a'"
|
||||
, " , 'k2b':2"
|
||||
, " }"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_str() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary_str ("k2", "a1", "a2", "a3")
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " [ 'a1'"
|
||||
, " , 'a2'"
|
||||
, " , 'a3'"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_int() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary_int ("k2", 1, 2, 3)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_nde() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary_nde ("k2"
|
||||
, fxt.Make__nde (fxt.Make__fld_str("k21", "v21"))
|
||||
, fxt.Make__nde (fxt.Make__fld_str("k22", "v22"))
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " ["
|
||||
, " { 'k21':'v21'"
|
||||
, " }"
|
||||
, " ,"
|
||||
, " { 'k22':'v22'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_ary() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary_ary ("k2"
|
||||
, fxt.Make__ary_int (1, 2, 3)
|
||||
, fxt.Make__ary_int (4, 5, 6)
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " ["
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, " ,"
|
||||
, " [ 4"
|
||||
, " , 5"
|
||||
, " , 6"
|
||||
, " ]"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Root_ary() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__ary_int(1, 2, 3)
|
||||
, "[ 1"
|
||||
, ", 2"
|
||||
, ", 3"
|
||||
, "]"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xoa_dashboard_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(Json_nde data) {
|
||||
Xobc_ui_mgr dl_mgr = Xoa_dashboard_special.Download_mgr;
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__init: dl_mgr.Init(); break;
|
||||
case Proc__todo__move_to_work: dl_mgr.Todo__move_to_work(args.Get_as_str("job_uid")); break;
|
||||
case Proc__work__resume: dl_mgr.Work__resume(args.Get_as_str("job_uid")); break;
|
||||
case Proc__work__pause: dl_mgr.Work__pause(args.Get_as_str("job_uid")); break;
|
||||
case Proc__work__cancel: dl_mgr.Work__cancel(args.Get_as_str("job_uid")); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
private static final byte Proc__init = 0, Proc__todo__move_to_work = 1, Proc__work__resume = 2, Proc__work__pause = 3, Proc__work__cancel = 4;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("init" , Proc__init)
|
||||
.Add_str_byte("todo__move_to_work" , Proc__todo__move_to_work)
|
||||
.Add_str_byte("work__resume__send" , Proc__work__resume)
|
||||
.Add_str_byte("work__pause__send" , Proc__work__pause)
|
||||
.Add_str_byte("work__cancel__send" , Proc__work__cancel)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;}
|
||||
public static final byte[] BRIDGE_KEY = Bry_.new_a7("builder_central.exec");
|
||||
public static final Xoa_dashboard_bridge Prototype = new Xoa_dashboard_bridge(); Xoa_dashboard_bridge() {}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.*;
|
||||
class Xoa_dashboard_file_mgr {
|
||||
private final Xog_cbk_mgr cbk_mgr;
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xoa_dashboard_file_mgr(Xog_cbk_mgr cbk_mgr) {
|
||||
this.cbk_mgr = cbk_mgr;
|
||||
}
|
||||
public void Add(Xobc_file_itm itm) {hash.Add(itm.Job_uid(), itm);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public int Len() {return hash.Len();}
|
||||
public Xobc_file_itm Get_at(int i) {return (Xobc_file_itm)hash.Get_at(i);}
|
||||
public Xobc_file_itm Get_by(String k) {return (Xobc_file_itm)hash.Get_by(k);}
|
||||
public Xobc_file_itm Del_by(String k) {
|
||||
Xobc_file_itm rv = (Xobc_file_itm)hash.Get_by(k);
|
||||
hash.Del(k);
|
||||
return rv;
|
||||
}
|
||||
public void Exec_all(String invk_cmd) {
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_at(i);
|
||||
GfoInvkAble_.Invk(itm, invk_cmd);
|
||||
}
|
||||
}
|
||||
public void Exec_one(String invk_cmd, String file_id) {this.Exec_one(invk_cmd, file_id, null, null);}
|
||||
public void Exec_one(String invk_cmd, String file_id, String send_func, Gfobj_nde send_data) {
|
||||
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_by(file_id);
|
||||
GfoInvkAble_.Invk(itm, invk_cmd);
|
||||
if (send_func != null) cbk_mgr.Send_json(send_func, send_data);
|
||||
}
|
||||
public void Move_all(Xoa_dashboard_file_mgr trg) {this.Move_all(trg, null);}
|
||||
public void Move_all(Xoa_dashboard_file_mgr trg, String invk_cmd) {
|
||||
List_adp tmp = List_adp_.new_();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
tmp.Add((Xobc_file_itm)hash.Get_at(i));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_file_itm itm = (Xobc_file_itm)tmp.Get_at(i);
|
||||
if (invk_cmd != null) GfoInvkAble_.Invk(itm, invk_cmd);
|
||||
hash.Del(itm.Job_uid());
|
||||
trg.Add(itm);
|
||||
}
|
||||
}
|
||||
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg) {this.Move_one(file_id, trg, null, null, null);}
|
||||
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg, String invk_cmd) {this.Move_one(file_id, trg, invk_cmd, null, null);}
|
||||
public void Move_one(String file_id, Xoa_dashboard_file_mgr trg, String invk_cmd, String send_func, Gfobj_nde send_data) {
|
||||
Xobc_file_itm itm = (Xobc_file_itm)hash.Get_by(file_id);
|
||||
if (invk_cmd != null) GfoInvkAble_.Invk(itm, invk_cmd);
|
||||
hash.Del(file_id);
|
||||
trg.Add(itm);
|
||||
if (send_func != null) cbk_mgr.Send_json(send_func, send_data);
|
||||
}
|
||||
public void To_nde(Bry_bfr tmp_bfr, Gfobj_ary ary_obj) {
|
||||
Gfobj_ary_nde ary = (Gfobj_ary_nde)ary_obj;
|
||||
List_adp list = List_adp_.new_();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_file_itm sub_itm = (Xobc_file_itm)hash.Get_at(i);
|
||||
Gfobj_nde sub_nde = Gfobj_nde.New();
|
||||
sub_itm.Write_to_nde(tmp_bfr, sub_nde);
|
||||
list.Add(sub_nde);
|
||||
}
|
||||
ary.Ary_nde_((Gfobj_nde[])list.To_ary_and_clear(Gfobj_nde.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.addons.builds.centrals.itms.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
import gplx.xowa.addons.apps.file_browsers.*;
|
||||
import gplx.core.security.*; import gplx.core.progs.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Xoa_dashboard_special implements Xows_page {
|
||||
public static Xobc_ui_mgr Download_mgr;
|
||||
private static boolean init = true;
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
if (init) {
|
||||
init = false;
|
||||
Download_mgr = new Xobc_ui_mgr(wiki.App().Gui__cbk_mgr());
|
||||
wiki.App().Gui__cbk_mgr().Reg(new gplx.xowa.guis.cbks.swts.Xog_cbk_wkr__swt(((Xoae_app)wiki.App()).Gui_mgr()));
|
||||
}
|
||||
Download_mgr.Clear();
|
||||
Io_url addon_dir = wiki.App().Fsys_mgr().Bin_addon_dir().GenSubDir_nest("bldr", "central");
|
||||
Xopage_html_data html_data = Write_html(wiki.App(), addon_dir);
|
||||
html_data.Apply(page);
|
||||
}
|
||||
private static Xopage_html_data Write_html(Xoa_app app, Io_url addon_dir) {
|
||||
// write body
|
||||
Xodl_itm_regy owner_itm = new Xodl_itm_regy();
|
||||
byte[] template_src = Io_mgr.Instance.LoadFilBry(addon_dir.GenSubFil_nest("tmpl", "bldr.central.main.mustache.html"));
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
byte[] body = gplx.langs.mustaches.Mustache_wtr_.Write_to_bry(tmp_bfr, template_src, owner_itm);
|
||||
|
||||
// write head
|
||||
Xopage_html_data rv = new Xopage_html_data(Display_ttl, body);
|
||||
rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("css", "bldr.central.css")));
|
||||
rv.Head_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "lib", "mustache.js")));
|
||||
rv.Head_tags().Add(Xopg_tag_itm.New_html_code(addon_dir.GenSubFil_nest("tmpl", "bldr.central.row.mustache.html"), "bldr.central.row"));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.elem.js")));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.tmpl.js")));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.notify.js")));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.server.js")));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "bldr.central.util.js")));
|
||||
rv.Tail_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "bldr.central.js")));
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final String SPECIAL_KEY = "XowaWikiDownload";
|
||||
public static final byte[] Display_ttl = Bry_.new_a7("Download Central");
|
||||
public Xows_special_meta Special__meta() {return new Xows_special_meta(Xows_special_meta_.Src__xowa, SPECIAL_KEY);}
|
||||
public static final Xows_page Prototype = new Xoa_dashboard_special();
|
||||
public Xows_page Special__clone() {return this;}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.xowa.addons.builds.centrals.jobs.*;
|
||||
class Xobc_file_itm implements GfoInvkAble {
|
||||
public Xobc_file_itm(Xog_cbk_mgr cbk_mgr, String job_uid, String job_name) {
|
||||
this.job_uid = job_uid;
|
||||
this.job_name = job_name;
|
||||
this.tasks = new Xobc_job_itm[]
|
||||
{ new Xobc_job_itm__verify(cbk_mgr, "77801297-db0a-47b4-af95-0db1eb63a192", Io_url_.new_fil_("C:\\xowa\\wiki\\en.wikipedia.org\\en.wikipedia.org-core.xowa"))
|
||||
};
|
||||
this.tasks_len = tasks.length;
|
||||
}
|
||||
public String Job_uid() {return job_uid;} private final String job_uid; // guid
|
||||
public String Job_name() {return job_name;} private final String job_name; // Simple Wikipedia: html
|
||||
public String Job_type() {return job_type;} private final String job_type = "gplx.xowa.bldr.wikis.copy_part";
|
||||
public Xobc_job_itm[] Tasks() {return tasks;} private Xobc_job_itm[] tasks; private int tasks_len = 0;
|
||||
public void Pause() {
|
||||
for (int i = 0; i < tasks_len; ++i) {
|
||||
Xobc_job_itm task = tasks[i];
|
||||
if ( !task.Prog__paused() // ignore already paused tasks
|
||||
&& task.Prog__started() // only pause tasks if started; don't pause inited tasks
|
||||
)
|
||||
task.Prog__pause();
|
||||
}
|
||||
}
|
||||
public void Resume() {
|
||||
for (int i = 0; i < tasks_len; ++i) {
|
||||
Xobc_job_itm task = tasks[i];
|
||||
if (task.Prog__paused())
|
||||
task.Prog__resume();
|
||||
else {
|
||||
gplx.core.threads.Thread_adp_.invk_("job: " + task.Job_name(), task, "").Start();
|
||||
break; // only start one
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Cancel() {
|
||||
for (int i = 0; i < tasks_len; ++i) {
|
||||
Xobc_job_itm task = tasks[i];
|
||||
task.Prog__cancel();
|
||||
}
|
||||
}
|
||||
public void Write_to_nde(Bry_bfr tmp_bfr, Gfobj_nde itm) {
|
||||
itm.Add_str ("job_uid" , job_uid);
|
||||
itm.Add_str ("job_name" , job_name);
|
||||
Gfobj_ary_nde ary_nde = itm.New_ary_nde("subs");
|
||||
Gfobj_nde[] ary = new Gfobj_nde[tasks_len];
|
||||
ary_nde.Ary_nde_(ary);
|
||||
long prog_time_end = 0;
|
||||
long prog_data_end = 0;
|
||||
for (int i = 0; i < tasks_len; ++i) {
|
||||
Xobc_job_itm sub_itm = tasks[i];
|
||||
Gfobj_nde sub_nde = Gfobj_nde.New();
|
||||
ary[i] = sub_nde;
|
||||
sub_itm.Write_to_nde(tmp_bfr, sub_nde);
|
||||
prog_time_end += sub_itm.Prog__end();
|
||||
}
|
||||
itm.Add_str ("prog_data_end_str" , gplx.core.ios.Io_size_.To_str_new(tmp_bfr, prog_data_end, 2));
|
||||
itm.Add_str ("prog_time_end_str" , Time_dhms_.To_str(tmp_bfr, prog_time_end, true, 2));
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (String_.Eq(k, Invk__pause)) this.Pause();
|
||||
else if (String_.Eq(k, Invk__resume)) this.Resume();
|
||||
else if (String_.Eq(k, Invk__cancel)) this.Cancel();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk__pause = "pause", Invk__resume = "resume", Invk__cancel = "cancel";
|
||||
}
|
||||
/*
|
||||
{ prog_finished : 0
|
||||
, prog_data_cur : 0
|
||||
, prog_data_end : 10
|
||||
, prog_data_end_str : '1.81 gb'
|
||||
, prog_time_cur : 0
|
||||
, prog_time_end : 30
|
||||
, prog_time_end_str : '30'
|
||||
, jobs:
|
||||
[
|
||||
{ job_type : 'gplx.xowa.core.security.verify'
|
||||
, job_name : 'verifying'
|
||||
, job_sort : 0
|
||||
, job_uid : '77801297-db0a-47b4-af95-0db1eb63a192'
|
||||
, prog_data_cur : 0
|
||||
, prog_data_end : 1819264175
|
||||
, prog_time_cur : 0
|
||||
, prog_time_end : 10
|
||||
}
|
||||
, { job_type : 'gplx.xowa.core.ios.zips.zip_decompress'
|
||||
, job_name : 'unzipping'
|
||||
, job_sort : 1
|
||||
, job_uid : '79fbfebe-0165-42b0-b71a-c66f95cb7fd1'
|
||||
, prog_data_cur : 0
|
||||
, prog_data_end : 1819264175
|
||||
, prog_time_cur : 0
|
||||
, prog_time_end : 20
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
class Xobc_rate_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public Xobc_rate_itm Get_at(int i) {return (Xobc_rate_itm)hash.Get_at(i);}
|
||||
public Xobc_rate_itm Get_by(String k) {return (Xobc_rate_itm)hash.Get_by(k);}
|
||||
public void Add(Xobc_rate_itm rate) {hash.Add_if_dupe_use_nth(rate.Key(), rate);}
|
||||
}
|
||||
class Xobc_rate_itm {
|
||||
public Xobc_rate_itm(String type, String key, long rate) {this.type = type; this.key = key; this.rate = rate;}
|
||||
public String Type() {return type;} private final String type; // EX: download
|
||||
public String Key() {return key;} private final String key; // EX: http://archive.org|C:\xowa\wiki\
|
||||
public long Rate() {return rate;} private final long rate; // EX: 4000000
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
|
||||
import gplx.xowa.guis.cbks.*; import gplx.core.gfobjs.*;
|
||||
public class Xobc_ui_mgr {
|
||||
private final Xoa_dashboard_file_mgr work_mgr, todo_mgr, done_mgr;
|
||||
private final Xog_cbk_mgr cbk_mgr;
|
||||
public Xobc_ui_mgr(Xog_cbk_mgr cbk_mgr) {
|
||||
this.cbk_mgr = cbk_mgr;
|
||||
work_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
|
||||
todo_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
|
||||
done_mgr = new Xoa_dashboard_file_mgr(cbk_mgr);
|
||||
}
|
||||
public void Init() {
|
||||
todo_mgr.Clear();
|
||||
todo_mgr.Add(new Xobc_file_itm(cbk_mgr, "0", "Simple Wikipedia: html"));
|
||||
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
Gfobj_nde root = Gfobj_nde.New();
|
||||
Gfobj_nde lists_nde = root.New_nde("lists");
|
||||
Gfobj_ary todo_ary = lists_nde.New_ary_nde("todo");
|
||||
todo_mgr.To_nde(tmp_bfr, todo_ary);
|
||||
cbk_mgr.Send_json("xo.bldr.core.init__recv", root);
|
||||
}
|
||||
public void Clear() {
|
||||
work_mgr.Clear();
|
||||
todo_mgr.Clear();
|
||||
done_mgr.Clear();
|
||||
}
|
||||
public void Todo__move_to_work(String job_uid) {todo_mgr.Move_one(job_uid, work_mgr, null, "xo.bldr.todo.move_to_work__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
|
||||
public void Work__resume(String job_uid) {work_mgr.Exec_one(Xobc_file_itm.Invk__resume, job_uid, "xo.bldr.work.resume__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
|
||||
public void Work__pause(String job_uid) {work_mgr.Exec_one(Xobc_file_itm.Invk__pause, job_uid, "xo.bldr.work.pause__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
|
||||
public void Work__cancel(String job_uid) {work_mgr.Move_one(job_uid, todo_mgr, Xobc_file_itm.Invk__cancel, "xo.bldr.work.cancel__recv", Gfobj_nde.New().Add_str("job_uid", job_uid));}
|
||||
public void Work__pause_all() {work_mgr.Exec_all(Xobc_file_itm.Invk__pause);}
|
||||
public void Work__resume_all() {
|
||||
int len = work_mgr.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_file_itm itm = work_mgr.Get_at(i);
|
||||
itm.Resume();
|
||||
}
|
||||
if (len > 0) { // TODO: if multiple items paused; send back notify for each paused item
|
||||
Xobc_file_itm itm = work_mgr.Get_at(0);
|
||||
itm.Resume();
|
||||
cbk_mgr.Send_json("work__resume__recv", Gfobj_nde.New().Add_str("file_id", itm.Job_uid()));
|
||||
}
|
||||
}
|
||||
public void Work__cancel_all() {work_mgr.Move_all(todo_mgr, Xobc_file_itm.Invk__cancel);}
|
||||
public void Work__complete(String file_id) {work_mgr.Move_one(file_id, done_mgr);} // not called by ui called by task wkr
|
||||
public void Todo__load(String url) {
|
||||
// Xobc_job_itm
|
||||
}
|
||||
|
||||
/*
|
||||
public void User__rates__load() {}
|
||||
public void User__rates__save() {}
|
||||
public void Done__save() {}
|
||||
public void Done__load() {}
|
||||
*/
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
public class Time_dhms_ {
|
||||
public static String To_str(Bry_bfr bfr, long val, boolean show_unit, int max_places) {To_bfr(bfr, val, show_unit, max_places); return bfr.To_str_and_clear();}
|
||||
public static void To_bfr(Bry_bfr bfr, long val, boolean show_unit, int max_places) {
|
||||
byte suffix = Byte_ascii.Null;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
// get factor and unit
|
||||
long factor = 0;
|
||||
byte unit = Byte_ascii.Null;
|
||||
switch(i) {
|
||||
case 0: unit = Byte_ascii.Ltr_d; factor = 86400; break;
|
||||
case 1: unit = Byte_ascii.Ltr_h; factor = 3600; break;
|
||||
case 2: unit = Byte_ascii.Ltr_m; factor = 60; break;
|
||||
case 3: unit = Byte_ascii.Ltr_s; factor = 1; break;
|
||||
}
|
||||
// calc cur and update val; EX: 3690 -> cur:1,mod:90
|
||||
int cur = (int)(val / factor);
|
||||
val %= factor;
|
||||
if (count == 0) { // no str yet
|
||||
if ( cur == 0 // cur is 0; EX: 3690 and factor = 86400 -> 0 days; don't write anything
|
||||
&& i != 3) // unless it is the seconds place; need to handle "0 s" specifically
|
||||
continue;
|
||||
suffix = unit; // set suffix
|
||||
bfr.Add_int_variable(cur); // write cur; note that this is not zero-padded
|
||||
}
|
||||
else { // str exists
|
||||
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 2, cur); // write cur; note that this zero-padded; also, note will write "00" if cur == 0
|
||||
}
|
||||
if (++count == max_places) break; // stop if max-places reached; EX: 86400 should write 1:00, not 1:00:00:00
|
||||
if (i != 3) // do not add ":" if seconds
|
||||
bfr.Add_byte_colon();
|
||||
}
|
||||
if (show_unit) // add units; EX: " s" for seconds
|
||||
bfr.Add_byte_space().Add_byte(suffix);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Time_dhms__tst {
|
||||
private final Time_dhms__fxt fxt = new Time_dhms__fxt();
|
||||
@Test public void S___0() {fxt.Test__to_str( 0, 4, "0 s");}
|
||||
@Test public void S___1() {fxt.Test__to_str( 1, 4, "1 s");}
|
||||
@Test public void S___2() {fxt.Test__to_str( 30, 4, "30 s");}
|
||||
@Test public void M___1() {fxt.Test__to_str( 60, 4, "1:00 m");}
|
||||
@Test public void M___2() {fxt.Test__to_str( 600, 4, "10:00 m");}
|
||||
@Test public void H___1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");}
|
||||
@Test public void H___2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");}
|
||||
@Test public void D___1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");}
|
||||
@Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");}
|
||||
}
|
||||
class Time_dhms__fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) {
|
||||
Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places));
|
||||
return this;}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
public interface Xobc_job_itm extends gplx.core.progs.Gfo_prog_ui, GfoInvkAble {
|
||||
String Job_uid();
|
||||
String Job_name();
|
||||
void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde itm);
|
||||
Xobc_job_itm Owner();
|
||||
Xobc_job_itm[] Subs();
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
import gplx.core.progs.*; import gplx.core.gfobjs.*;
|
||||
import gplx.core.ios.zips.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Xobc_job_itm__unzip extends Gfo_prog_ui_base implements Xobc_job_itm {
|
||||
private final Xog_cbk_mgr cbk_mgr;
|
||||
private long nxt_time;
|
||||
public Xobc_job_itm__unzip(Xog_cbk_mgr cbk_mgr, String job_uid, Io_url url) {
|
||||
this.cbk_mgr = cbk_mgr; this.job_uid = job_uid;
|
||||
this.Prog__end_(10);
|
||||
}
|
||||
public String Job_uid() {return job_uid;} private final String job_uid;
|
||||
public String Job_name() {return job_name;} private final String job_name = "unzipping";
|
||||
public Xobc_job_itm Owner() {return Xobc_job_itm_.Null;}
|
||||
public Xobc_job_itm[] Subs() {return Xobc_job_itm_.Ary_empty;}
|
||||
public void Task__exec() {
|
||||
}
|
||||
public void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde nde) {
|
||||
nde.Add_str ("job_uid" , job_uid);
|
||||
nde.Add_str ("job_name" , job_name);
|
||||
nde.Add_long("prog_data_cur" , this.Prog__cur());
|
||||
nde.Add_long("prog_data_end" , this.Prog__end());
|
||||
nde.Add_long("prog_time_cur" , 0);
|
||||
nde.Add_long("prog_time_end" , this.Prog__end());
|
||||
}
|
||||
@Override public byte Prog__notify__working(long cur, long end) {
|
||||
long cur_time = gplx.core.envs.Env_.TickCount();
|
||||
if (cur_time < nxt_time) return Gfo_prog_ui_.State__started; // message came too soon. ignore it
|
||||
nxt_time = cur_time + 200;
|
||||
|
||||
Gfobj_nde nde = Gfobj_nde.New();
|
||||
nde.Add_str("job_uid", job_uid);
|
||||
nde.Add_str("task_type", "verify");
|
||||
nde.Add_long("prog_cur", cur);
|
||||
nde.Add_long("prog_end", end);
|
||||
cbk_mgr.Send_json("work__update_progress", nde);
|
||||
|
||||
return super.Prog__notify__working(cur, end);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Task__exec();
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.builds.centrals.jobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*; import gplx.xowa.addons.builds.centrals.*;
|
||||
import gplx.core.progs.*; import gplx.core.gfobjs.*;
|
||||
import gplx.core.security.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Xobc_job_itm__verify extends Gfo_prog_ui_base implements Xobc_job_itm {
|
||||
private final Xog_cbk_mgr cbk_mgr; private final Io_url url;
|
||||
private long nxt_time;
|
||||
public Xobc_job_itm__verify(Xog_cbk_mgr cbk_mgr, String job_uid, Io_url url) {
|
||||
this.cbk_mgr = cbk_mgr; this.job_uid = job_uid; this.url = url;
|
||||
this.Prog__end_(10);
|
||||
}
|
||||
public String Job_uid() {return job_uid;} private final String job_uid;
|
||||
public String Job_name() {return job_name;} private final String job_name = "verifying";
|
||||
public Xobc_job_itm Owner() {return Xobc_job_itm_.Null;}
|
||||
public Xobc_job_itm[] Subs() {return Xobc_job_itm_.Ary_empty;}
|
||||
public byte[] Hash() {return hash;} private byte[] hash;
|
||||
public void Task__exec() {
|
||||
Hash_algo algo = Hash_algo_.New__md5();
|
||||
gplx.core.ios.IoStream stream = Io_mgr.Instance.OpenStreamRead(url);
|
||||
try {this.hash = algo.Hash_stream_as_bry(this, stream);}
|
||||
finally {stream.Rls();}
|
||||
}
|
||||
public void Write_to_nde(Bry_bfr tmp_bfr, gplx.core.gfobjs.Gfobj_nde nde) {
|
||||
nde.Add_str ("job_uid" , job_uid);
|
||||
nde.Add_str ("job_name" , job_name);
|
||||
nde.Add_long("prog_data_cur" , this.Prog__cur());
|
||||
nde.Add_long("prog_data_end" , this.Prog__end());
|
||||
nde.Add_long("prog_time_cur" , 0);
|
||||
nde.Add_long("prog_time_end" , this.Prog__end());
|
||||
}
|
||||
@Override public byte Prog__notify__working(long cur, long end) {
|
||||
long cur_time = gplx.core.envs.Env_.TickCount();
|
||||
if (cur_time < nxt_time) return Gfo_prog_ui_.State__started; // message came too soon. ignore it
|
||||
nxt_time = cur_time + 200;
|
||||
|
||||
Gfobj_nde nde = Gfobj_nde.New();
|
||||
nde.Add_str("job_uid", job_uid);
|
||||
nde.Add_str("task_type", "verify");
|
||||
nde.Add_long("prog_cur", cur);
|
||||
nde.Add_long("prog_end", end);
|
||||
cbk_mgr.Send_json("work__update_progress", nde);
|
||||
|
||||
return super.Prog__notify__working(cur, end);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Task__exec();
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.addons.updates.downloads.itms.*; import gplx.xowa.addons.updates.downloads.core.*;
|
||||
import gplx.xowa.addons.apps.file_browsers.*;
|
||||
public class Xodl_special_page implements Xows_page {
|
||||
public static Gfo_download_wkr Download_wkr = Gfo_download_wkr_.Noop;
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Io_url addon_dir = wiki.App().Fsys_mgr().Bin_addon_dir().GenSubDir_nest("import", "wiki_download");
|
||||
Xoa_url_arg_mgr arg_mgr = new Xoa_url_arg_mgr(null).Init(url.Qargs_ary());
|
||||
byte[] ids_bry = arg_mgr.Read_bry_or_null("ids");
|
||||
if (ids_bry == null) {
|
||||
Xopage_html_data html_data = Write_html(wiki.App(), addon_dir);
|
||||
html_data.Apply(page);
|
||||
}
|
||||
else {
|
||||
Xodl_itm_regy regy = Load_regy(addon_dir);
|
||||
int[] ids_ary = Int_.Ary_parse(String_.new_u8(ids_bry), ",");
|
||||
Xodl_itm_pack[] packs = regy.Packs__select(ids_ary);
|
||||
if (packs.length > 0) {
|
||||
Xodl_download_mgr download_mgr = new Xodl_download_mgr();
|
||||
download_mgr.Download(Download_wkr, packs);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Xodl_itm_regy Load_regy(Io_url addon_dir) {
|
||||
return Xodl_itm_regy.Load_by_json(addon_dir.GenSubFil_nest("data", "wiki_download.json"));
|
||||
}
|
||||
private static Xopage_html_data Write_html(Xoa_app app, Io_url addon_dir) {
|
||||
// write body
|
||||
Xodl_itm_regy owner_itm = Load_regy(addon_dir);
|
||||
byte[] template_src = Io_mgr.Instance.LoadFilBry(addon_dir.GenSubFil_nest("bin", "wiki_download.mustache.html"));
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
byte[] body = gplx.langs.mustaches.Mustache_wtr_.Write_to_bry(tmp_bfr, template_src, owner_itm);
|
||||
|
||||
// write head
|
||||
Xopage_html_data rv = new Xopage_html_data(Display_ttl, body);
|
||||
rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "wiki_download.css")));
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final String SPECIAL_KEY = "XowaWikiDownload";
|
||||
public static final byte[] Display_ttl = Bry_.new_a7("Download wikis");
|
||||
public Xows_special_meta Special__meta() {return new Xows_special_meta(Xows_special_meta_.Src__xowa, SPECIAL_KEY);}
|
||||
public static final Xows_page Prototype = new Xodl_special_page();
|
||||
public Xows_page Special__clone() {return this;}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public interface Gfo_download_itm {
|
||||
String Download__src();
|
||||
Io_url Download__trg();
|
||||
void Download__trg_(Io_url v);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public interface Gfo_download_wkr {
|
||||
void Download__bgn(Gfo_download_cbk cbk, Gfo_download_itm[] itms);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public class Gfo_download_wkr_ {
|
||||
public static final Gfo_download_wkr Noop = new Gfo_download_wkr__noop();
|
||||
}
|
||||
class Gfo_download_wkr__noop implements Gfo_download_wkr {
|
||||
public void Download__bgn(Gfo_download_cbk cbk, Gfo_download_itm[] itms) {cbk.Download__end_all(itms);}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public interface Gfo_unzip_itm {
|
||||
Io_url Unzip__src_fil();
|
||||
Io_url Unzip__trg_dir();
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public interface Gfo_unzip_wkr {
|
||||
void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm);
|
||||
}
|
||||
class Gfo_unzip_wkr__noop implements Gfo_unzip_wkr {
|
||||
public void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm) {cbk.Unzip__end_itm(itm);}
|
||||
public static final Gfo_unzip_wkr__noop Instance = new Gfo_unzip_wkr__noop(); Gfo_unzip_wkr__noop() {}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
import gplx.core.ios.zips.*;
|
||||
|
||||
class Gfo_unzip_wkr__jre implements Gfo_unzip_wkr {
|
||||
public void Unzip__bgn(Gfo_unzip_cbk cbk, Gfo_unzip_itm itm) {
|
||||
Io_zip_mgr_base.Instance.Unzip_to_dir(itm.Unzip__src_fil(), itm.Unzip__trg_dir());
|
||||
cbk.Unzip__end_itm(itm);
|
||||
}
|
||||
public static final Gfo_unzip_wkr__jre Instance = new Gfo_unzip_wkr__jre(); Gfo_unzip_wkr__jre() {}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Gfobj_wtr__json__swt_tst {
|
||||
private final Gfobj_wtr__json__swt_fxt fxt = new Gfobj_wtr__json__swt_fxt();
|
||||
@Test public void Json_proc() {
|
||||
fxt.Test__json_proc
|
||||
( "proc_name"
|
||||
, fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_long ("k2", 2)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "return proc_name('{\"k1\":\"v1\",\"k2\":2,\"k3\":3}');"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Gfobj_wtr__json__swt_fxt extends Gfobj_wtr__json_fxt { public Gfobj_wtr__json__swt_fxt Test__json_proc() {return this;}
|
||||
public void Test__json_proc(String proc_name, Gfobj_nde root, String expd) {
|
||||
Gfobj_wtr__json__swt wtr = new Gfobj_wtr__json__swt();
|
||||
String actl = wtr.Write_as_func(proc_name, root);
|
||||
Gftest.Eq__str(expd, actl, "json_write");
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.gfui.*; import gplx.xowa.guis.*;
|
||||
public class Xog_cbk_wkr__swt implements Xog_cbk_wkr {
|
||||
private final Xoa_gui_mgr gui_mgr;
|
||||
private final Xog_browser_func browser_func;
|
||||
private final Gfobj_wtr__json__swt json_wtr = new Gfobj_wtr__json__swt();
|
||||
public Xog_cbk_wkr__swt(Xoa_gui_mgr gui_mgr) {
|
||||
this.gui_mgr = gui_mgr;
|
||||
this.browser_func = new Xog_browser_func(gui_mgr.Browser_win().Active_tab().Html_box());
|
||||
}
|
||||
public Object Send_json(String func, Gfobj_nde data) {
|
||||
String script = json_wtr.Write_as_func(func, data);
|
||||
GfuiInvkCmd swt_cmd = gui_mgr.Kit().New_cmd_sync(browser_func.Init(script));
|
||||
return GfoInvkAble_.Invk(swt_cmd);
|
||||
}
|
||||
}
|
||||
class Xog_browser_func implements GfoInvkAble {
|
||||
private final Gfui_html html_box;
|
||||
private String script;
|
||||
public Xog_browser_func(Gfui_html html_box) {
|
||||
this.html_box = html_box;
|
||||
}
|
||||
public Xog_browser_func Init(String script) {
|
||||
this.script = script;
|
||||
return this;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return html_box.Html_js_eval_script(script);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue