mirror of https://github.com/gnosygnu/xowa
parent
ad140a93fe
commit
5ce4ea2a08
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public interface Io_zip_decompress_cmd {
|
||||
void Decompress__exec(Io_zip_decompress_task task, Io_url src_fil, Io_url trg_dir);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public class Io_zip_decompress_cmd_ {
|
||||
public static Io_zip_decompress_cmd New__jre() {return new Io_zip_decompress_cmd__jre();}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
import gplx.core.envs.*; import gplx.core.threads.*;
|
||||
class Io_zip_decompress_cmd__jre implements Io_zip_decompress_cmd {
|
||||
public void Decompress__exec(Io_zip_decompress_task task, Io_url src_fil, Io_url trg_dir) {
|
||||
// init
|
||||
byte[] buffer = new byte[4096];
|
||||
String resume_entry_name = task.Resume__entry();
|
||||
long resume_bytes = task.Resume__bytes();
|
||||
|
||||
// assert that trg_dir exists and can be written
|
||||
Io_mgr.Instance.CreateDirIfAbsent(trg_dir);
|
||||
|
||||
// open src_fil_stream
|
||||
FileInputStream src_fil_stream = null;
|
||||
try {src_fil_stream = new FileInputStream(src_fil.Raw());}
|
||||
catch (FileNotFoundException e) {throw Err_.new_("ios.zip", "file not found", "path", src_fil.Raw());}
|
||||
|
||||
ZipInputStream src_zip_stream = new ZipInputStream(src_fil_stream);
|
||||
try {
|
||||
ZipEntry entry = null;
|
||||
boolean loop_entries = true;
|
||||
while (loop_entries) {
|
||||
|
||||
// read next entry
|
||||
entry = src_zip_stream.getNextEntry();
|
||||
if ( entry == null // no more entries
|
||||
|| resume_entry_name == null // resume_entry_name will be null in most cases
|
||||
|| String_.Eq(resume_entry_name, entry.getName()) // if resume_entry_name is not null, keep reading until match
|
||||
)
|
||||
break;
|
||||
if (resume_bytes > 0) {
|
||||
src_zip_stream.skip(resume_bytes);
|
||||
resume_bytes = 0;
|
||||
}
|
||||
|
||||
// get entry name; also convert / to \ for wnt
|
||||
String entry_name = entry.getName();
|
||||
task.Prog__update_name(entry_name);
|
||||
if (Op_sys.Cur().Tid_is_wnt()) entry_name = String_.Replace(entry_name, "/", "\\");
|
||||
|
||||
// create file
|
||||
Io_url trg_fil_url = Io_url_.new_any_(trg_dir.GenSubFil(entry_name).Raw());
|
||||
Io_mgr.Instance.CreateDirIfAbsent(trg_fil_url.OwnerDir()); // make sure owner dir exists
|
||||
if (trg_fil_url.Type_fil()) {
|
||||
// write file
|
||||
Io_mgr.Instance.SaveFilStr_args(trg_fil_url, "").Exec(); // need to write to create dirs; permissions;
|
||||
FileOutputStream trg_fil_stream = new FileOutputStream(new File(trg_fil_url.Raw()));
|
||||
boolean loop_bytes = true;
|
||||
while (loop_bytes) {
|
||||
int len = src_zip_stream.read(buffer); if (len < 1) break;
|
||||
trg_fil_stream.write(buffer, 0, len);
|
||||
switch (task.Prog__update(len)) {
|
||||
case Io_zip_decompress_task.Status__canceled:
|
||||
loop_entries = false;
|
||||
loop_bytes = false;
|
||||
break;
|
||||
case Io_zip_decompress_task.Status__paused:
|
||||
while (true) {
|
||||
Thread_adp_.Sleep(1000);
|
||||
if (!task.Paused()) break;
|
||||
if (task.Canceled()) {
|
||||
loop_entries = false;
|
||||
loop_bytes = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Io_zip_decompress_task.Status__ok:
|
||||
break;
|
||||
}
|
||||
}
|
||||
trg_fil_stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e) {throw Err_.new_exc(e, "ios.zip", "error duing unzip", "src", src_fil.Raw(), "trg", trg_dir.Raw());}
|
||||
finally {
|
||||
try {
|
||||
src_zip_stream.closeEntry();
|
||||
src_zip_stream.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import gplx.core.threads.*; import gplx.core.progs.*;
|
||||
public class Io_zip_decompress_task implements GfoInvkAble {
|
||||
private Gfo_prog_ui prog_ui;
|
||||
private Io_url src_fil, trg_dir;
|
||||
private boolean async;
|
||||
private boolean canceled, paused;
|
||||
private long src_fil_len = 0;
|
||||
private long prog__cur = 0;
|
||||
private Io_zip_decompress_cmd cmd;
|
||||
public Gfo_prog_task Prog__owner() {return Gfo_prog_task_.Null;}
|
||||
public void Init(boolean async, Gfo_prog_ui prog_ui, Io_zip_decompress_cmd cmd, Io_url src_fil, Io_url trg_dir) {
|
||||
this.async = async; this.cmd = cmd; this.prog_ui = prog_ui;
|
||||
this.src_fil = src_fil; this.trg_dir = trg_dir;
|
||||
}
|
||||
public String Resume__entry() {return resume__entry;} private String resume__entry;
|
||||
public long Resume__bytes() {return resume__bytes;} private long resume__bytes;
|
||||
public boolean Canceled() {return canceled;}
|
||||
public boolean Paused() {return paused;}
|
||||
public void Prog__start() {
|
||||
this.src_fil_len = Io_mgr.Instance.QueryFil(src_fil).Size();
|
||||
this.resume__entry = null;
|
||||
this.resume__bytes = 0;
|
||||
// load resume
|
||||
// prog_ui.Prog__init(src_fil_len);
|
||||
Thread_adp_.Run_cmd(async, "zip.decompress:" + src_fil.Raw(), this, Invk__unzip);
|
||||
}
|
||||
public byte Prog__update(long v) {
|
||||
prog__cur += v;
|
||||
prog_ui.Prog__update_val(prog__cur, src_fil_len);
|
||||
if (paused) return Status__paused;
|
||||
else if (canceled) return Status__canceled;
|
||||
else return Status__ok;
|
||||
}
|
||||
public boolean Prog__update_name(String name) {
|
||||
// prog_ui.Prog__update_misc("name", name);
|
||||
return canceled;
|
||||
}
|
||||
public void Prog__pause() {
|
||||
paused = true;
|
||||
// save resume
|
||||
}
|
||||
public void Prog__resume() {
|
||||
paused = false;
|
||||
}
|
||||
public void Prog__cancel() {
|
||||
canceled = true;
|
||||
// discard resume
|
||||
}
|
||||
public void Unzip() {
|
||||
cmd.Decompress__exec(this, src_fil, trg_dir);
|
||||
prog_ui.Prog__end();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__unzip)) this.Unzip();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__unzip = "unzip";
|
||||
public static final byte Status__ok = 0, Status__paused = 1, Status__canceled = 2;
|
||||
}
|
||||
/*
|
||||
class Notifier {
|
||||
public Prog_update_bgn() {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_end() {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_val(long cur, long all) {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
}
|
||||
class unzip_prog_bar {
|
||||
public Prog_update_val(long itm_cur, long itm_all) {
|
||||
cur += itm_cur;
|
||||
double pct = (cur / all) * 100;
|
||||
pbar.style.width = pct + "%";
|
||||
pbar.text = Io_size.To_str(cur);
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
file.text = "unzipping:" + name;
|
||||
}
|
||||
public Prog_update_bgn(long cur) {
|
||||
if (all == 0) {
|
||||
panels.add(this);
|
||||
}
|
||||
all += cur;
|
||||
}
|
||||
public Prog_update_end() {
|
||||
if (cur >= all) {
|
||||
panels.del(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
class pack_prog_bar {
|
||||
public Prog_update_val(long cur, long all) {
|
||||
double pct = (cur / all) * 100;
|
||||
pbar.style.width = pct + "%";
|
||||
pbar.text = Io_size.To_str(cur);
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
file.text = "unzipping:" + name;
|
||||
}
|
||||
public Prog_update_bgn() {
|
||||
pbar.visible = true;
|
||||
file.visible = true;
|
||||
file.text = "unzipping: " + ;
|
||||
}
|
||||
public Prog_update_end() {
|
||||
pbar.visible = false;
|
||||
file.visible = false;
|
||||
}
|
||||
}
|
||||
*/
|
@ -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.progs; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_prog_task {
|
||||
Gfo_prog_task Prog__owner();
|
||||
long Prog__all();
|
||||
long Prog__cur();
|
||||
void Prog__start();
|
||||
void Prog__cancel();
|
||||
void Prog__pause();
|
||||
void Prog__resume();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.progs; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_prog_task_ {
|
||||
public static final Gfo_prog_task Null = null;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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 interface Gfo_prog_ui {
|
||||
void Prog__update_val(long cur, long max);
|
||||
void Prog__end();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoax_addon_itm__json {
|
||||
gplx.xowa.htmls.bridges.Bridge_cmd_itm[] Json__cmds();
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.apps.file_browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
public class Xoa_url_enum_itm {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Xoa_url_enum_itm(byte[] key) {this.key = key;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public Xoa_url_enum_itm Add(String key, int val) {
|
||||
hash.Add_bry_int(Bry_.new_u8(key), val);
|
||||
return this;
|
||||
}
|
||||
public int Get_as_int_or(byte[] val, int or) {return hash.Get_as_int_or(val, or);}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.apps.file_browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
public class Xoa_url_enum_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Xoa_url_enum_mgr(Xoa_url_enum_itm... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoa_url_enum_itm itm = ary[i];
|
||||
hash.Add_bry_obj(itm.Key(), itm);
|
||||
}
|
||||
}
|
||||
public Xoa_url_enum_itm Get(byte[] key) {return (Xoa_url_enum_itm)hash.Get_by_bry(key);}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
|
||||
public class Http_long_poll_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
private final List_adp msgs = List_adp_.new_();
|
||||
private long send_time_prv = 0;
|
||||
public int Sleep_interval = 100;
|
||||
public int Send_interval = 1000;
|
||||
|
||||
public void Send_msg(String msg) {
|
||||
msgs.Add(msg);
|
||||
}
|
||||
public String Exec(gplx.langs.jsons.Json_nde data) {
|
||||
while (true) {
|
||||
if (msgs.Len() == 0) {
|
||||
gplx.core.threads.Thread_adp_.Sleep(Sleep_interval);
|
||||
}
|
||||
else {
|
||||
long send_time_cur = gplx.core.envs.Env_.TickCount();
|
||||
if (send_time_cur - send_time_prv > Send_interval) {
|
||||
send_time_prv = send_time_cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return String_.Concat_lines_nl(msgs.To_str_ary_and_clear());
|
||||
}
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;}
|
||||
public static final byte[] BRIDGE_KEY = Bry_.new_a7("long_poll");
|
||||
public static final Http_long_poll_cmd Instance = new Http_long_poll_cmd(); Http_long_poll_cmd() {}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
|
||||
public class Http_send_msg_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public String Exec(gplx.langs.jsons.Json_nde data) {
|
||||
gplx.langs.jsons.Json_nde jnde = (gplx.langs.jsons.Json_nde)data.Get_as_itm_or_null(Bry_.new_a7("msg"));
|
||||
Http_long_poll_cmd.Instance.Send_msg(jnde.Print_as_json());
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;}
|
||||
public static final byte[] BRIDGE_KEY = Bry_.new_a7("send_msg");
|
||||
}
|
@ -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.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
|
||||
import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xoax_long_poll_addon implements Xoax_addon_itm, Xoax_addon_itm__json {
|
||||
public Bridge_cmd_itm[] Json__cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ Http_long_poll_cmd.Instance
|
||||
, new Http_send_msg_cmd()
|
||||
};
|
||||
}
|
||||
|
||||
public static final byte[] ADDON_KEY = Bry_.new_a7("xowa.servers.https.long_poll");
|
||||
public byte[] Addon__key() {return ADDON_KEY;}
|
||||
}
|
@ -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.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
|
||||
import gplx.xowa.guis.cbks.*;
|
||||
public class Xog_cbk_wkr__http implements Xog_cbk_wkr {
|
||||
public void Send_prog(String head) {
|
||||
Http_long_poll_cmd.Instance.Send_msg(head);
|
||||
}
|
||||
public static final Xog_cbk_wkr__http Instance = new Xog_cbk_wkr__http(); Xog_cbk_wkr__http() {}
|
||||
}
|
@ -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.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xoax_downloads_addon implements Xoax_addon_itm, Xoax_addon_itm__special {
|
||||
public Xows_page[] Pages_ary() {
|
||||
return new Xows_page[]
|
||||
{ Xodl_special_page.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public static final byte[] ADDON_KEY = Bry_.new_a7("xowa.imports.downloads");
|
||||
public byte[] Addon__key() {return ADDON_KEY;}
|
||||
}
|
||||
// class Xodl_core_regy {
|
||||
// public void Update() {} // update from http
|
||||
// public void Load() {} // load bin/
|
||||
// }
|
||||
// class Xodl_user_regy {
|
||||
// public void Load() {}
|
||||
// public void Apply() {} // mark already downloaded items
|
||||
// }
|
||||
// class Xodl_main_mgr {
|
||||
// public void Show_ui() {} // show list for ui
|
||||
// public void Process() {} // process choices
|
||||
// }
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*;
|
||||
import gplx.xowa.addons.updates.downloads.core.*;
|
||||
import gplx.xowa.addons.updates.downloads.itms.*;
|
||||
class Xodl_download_mgr implements Gfo_download_cbk {
|
||||
public void Download(Gfo_download_wkr download_wkr, Xodl_itm_pack[] packs) {
|
||||
download_wkr.Download__bgn(this, packs);
|
||||
}
|
||||
public void Download__end_itm(Gfo_download_itm itm) {
|
||||
// unzip; start
|
||||
}
|
||||
public void Download__end_all(Gfo_download_itm[] itms) {}
|
||||
public void Unzip__end(Gfo_download_itm[] itms) {
|
||||
// register
|
||||
}
|
||||
}
|
@ -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.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;}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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_cbk {
|
||||
void Download__end_itm(Gfo_download_itm itm);
|
||||
void Download__end_all(Gfo_download_itm[] itms);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.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);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.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);}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
import gplx.langs.jsons.*; import gplx.langs.mustaches.*;
|
||||
import gplx.xowa.addons.updates.downloads.core.*;
|
||||
public class Xodl_itm_pack implements Mustache_doc_itm, Gfo_download_itm {
|
||||
public int Id = -1; // EX: 1
|
||||
public String Wiki = ""; // EX: 'simple.wikipedia.org'
|
||||
public String Date = ""; // EX: '2016-04-07'
|
||||
public String Type = ""; // EX: 'html' or 'file'
|
||||
public String Name = ""; // EX: 'html: complete'
|
||||
public long Size = 0; // EX: 1234
|
||||
public String Url = ""; // EX: https://archive.org/download/Xowa_simplewiki_latest/Xowa_simplewiki_2016-04-06_html.7z
|
||||
public int Ns = -1; // EX: 0
|
||||
public int Part = -1; // EX: 1, 2
|
||||
public Xodl_itm_pack() {}
|
||||
public Xodl_itm_pack(int id, String wiki, String date, String type, int ns, int part, String name, long size, String url) {
|
||||
this.Id = id;
|
||||
this.Wiki = wiki;
|
||||
this.Date = date;
|
||||
this.Type = type;
|
||||
this.Ns = ns;
|
||||
this.Part = part;
|
||||
this.Name = name;
|
||||
this.Size = size;
|
||||
this.Url = url;
|
||||
}
|
||||
public String Download__src() {return Url;}
|
||||
public Io_url Download__trg() {return trg;} private Io_url trg; public void Download__trg_(Io_url v) {this.trg = v;}
|
||||
public void To_json(Json_wtr wtr) {
|
||||
wtr.Kv_int("id", Id);
|
||||
wtr.Kv_str("wiki", Wiki);
|
||||
wtr.Kv_str("date", Date);
|
||||
wtr.Kv_str("type", Type);
|
||||
wtr.Kv_str("name", Name);
|
||||
wtr.Kv_long("size", Size);
|
||||
wtr.Kv_str("url", Url);
|
||||
if (Ns != -1) wtr.Kv_int("ns", Ns);
|
||||
if (Part != -1) wtr.Kv_int("part", Part);
|
||||
}
|
||||
public void By_json(Json_nde nde) {
|
||||
this.Id = nde.Get_as_int("id");
|
||||
this.Wiki = nde.Get_as_str("wiki");
|
||||
this.Date = nde.Get_as_str("date");
|
||||
this.Type = nde.Get_as_str("type");
|
||||
this.Name = nde.Get_as_str("name");
|
||||
this.Size = nde.Get_as_long("size");
|
||||
this.Url = nde.Get_as_str("url");
|
||||
this.Ns = nde.Get_as_int_or("ns", -1);
|
||||
this.Part = nde.Get_as_int_or("part", -1);
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "id")) bfr.Add_int(Id);
|
||||
else if (String_.Eq(key, "wiki")) bfr.Add_str_u8(Wiki);
|
||||
else if (String_.Eq(key, "date")) bfr.Add_str_u8(Date);
|
||||
else if (String_.Eq(key, "type")) bfr.Add_str_u8(Type);
|
||||
else if (String_.Eq(key, "name")) bfr.Add_str_u8(Name);
|
||||
else if (String_.Eq(key, "size")) bfr.Add_long(Size);
|
||||
else if (String_.Eq(key, "url")) bfr.Add_str_u8(Url);
|
||||
else if (String_.Eq(key, "ns")) bfr.Add_int(Ns);
|
||||
else if (String_.Eq(key, "part")) bfr.Add_int(Part);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
|
||||
public static final Xodl_itm_pack[] Ary_empty = new Xodl_itm_pack[0];
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
import gplx.langs.jsons.*; import gplx.langs.mustaches.*;
|
||||
public class Xodl_itm_regy implements Mustache_doc_itm {
|
||||
public Xodl_itm_pack[] Packs = Xodl_itm_pack.Ary_empty;
|
||||
public Xodl_itm_regy() {}
|
||||
public Xodl_itm_regy(Xodl_itm_pack[] pack_ary) {this.Packs = pack_ary;}
|
||||
public Xodl_itm_pack[] Packs__select(int[] ids) {
|
||||
Hash_adp packs_hash = Hash_adp_.new_();
|
||||
int packs_len = Packs.length;
|
||||
for (int i = 0; i < packs_len; ++i) {
|
||||
Xodl_itm_pack pack = Packs[i];
|
||||
packs_hash.Add(pack.Id, pack);
|
||||
}
|
||||
|
||||
List_adp rv = List_adp_.new_();
|
||||
int ids_len = ids.length;
|
||||
for (int i = 0; i < ids_len; ++i) {
|
||||
int id = ids[i];
|
||||
Xodl_itm_pack pack = (Xodl_itm_pack)packs_hash.Get_by(id);
|
||||
if (pack != null)
|
||||
rv.Add(pack);
|
||||
}
|
||||
return (Xodl_itm_pack[])rv.To_ary_and_clear(Xodl_itm_pack.class);
|
||||
}
|
||||
public void To_json(Json_wtr wtr) {
|
||||
wtr.Doc_ary_bgn();
|
||||
int wikis_len = Packs.length;
|
||||
for (int i = 0; i < wikis_len; ++i) {
|
||||
wtr.Nde_bgn_ary();
|
||||
Xodl_itm_pack wiki = Packs[i];
|
||||
wiki.To_json(wtr);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
wtr.Doc_ary_end();
|
||||
}
|
||||
public void By_json(Json_grp ary) {
|
||||
int len = ary.Len();
|
||||
Packs = new Xodl_itm_pack[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_nde sub_nde = ary.Get_as_nde(i);
|
||||
Xodl_itm_pack sub_itm = new Xodl_itm_pack();
|
||||
Packs[i] = sub_itm;
|
||||
sub_itm.By_json(sub_nde);
|
||||
}
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {return false;}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "packs")) return Packs;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
public static Xodl_itm_regy Load_by_json(Io_url url) {return Load_by_json(Io_mgr.Instance.LoadFilBry(url));}
|
||||
public static Xodl_itm_regy Load_by_json(byte[] bry) {
|
||||
Xodl_itm_regy rv = new Xodl_itm_regy();
|
||||
Json_parser parser = new Json_parser();
|
||||
Json_doc jdoc = parser.Parse(bry);
|
||||
rv.By_json(jdoc.Root_grp());
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xodl_itm_regy_tst {
|
||||
private final Xodl_itm_regy_fxt fxt = new Xodl_itm_regy_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__srl
|
||||
( Json_doc.Make_str_ary_by_apos
|
||||
( "["
|
||||
, " { 'id':1"
|
||||
, " , 'wiki':'simple.wikipedia.org'"
|
||||
, " , 'date':'2016-04-07'"
|
||||
, " , 'type':'html'"
|
||||
, " , 'name':'html: complete'"
|
||||
, " , 'size':1234"
|
||||
, " , 'url':'http://archive.org/Xowa_simplewiki_latest/Xowa_simplewiki_2016-04-07_html.zip'"
|
||||
, " }"
|
||||
, ","
|
||||
, " { 'id':2"
|
||||
, " , 'wiki':'simple.wikipedia.org'"
|
||||
, " , 'date':'2016-04-07'"
|
||||
, " , 'type':'file'"
|
||||
, " , 'name':'file: complete'"
|
||||
, " , 'size':4321"
|
||||
, " , 'url':'http://archive.org/Xowa_simplewiki_latest/Xowa_simplewiki_2016-04-07_file.zip'"
|
||||
, " }"
|
||||
, "]"
|
||||
)
|
||||
, fxt.Make__regy
|
||||
( fxt.Make__pack(1, "simple.wikipedia.org", "2016-04-07", "html", -1, -1, "html: complete", 1234, "http://archive.org/Xowa_simplewiki_latest/Xowa_simplewiki_2016-04-07_html.zip")
|
||||
, fxt.Make__pack(2, "simple.wikipedia.org", "2016-04-07", "file", -1, -1, "file: complete", 4321, "http://archive.org/Xowa_simplewiki_latest/Xowa_simplewiki_2016-04-07_file.zip")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xodl_itm_regy_fxt {
|
||||
private final Json_wtr wtr = new Json_wtr();
|
||||
public Xodl_itm_regy Make__regy(Xodl_itm_pack... pack_ary) {return new Xodl_itm_regy(pack_ary);}
|
||||
public Xodl_itm_pack Make__pack(int id, String wiki, String date, String type, int ns, int part, String name, long size, String url) {return new Xodl_itm_pack(id, wiki, date, type, ns, part, name, size, url);}
|
||||
public Xodl_itm_regy_fxt Test__srl(String[] json, Xodl_itm_regy regy) {
|
||||
regy.To_json(wtr);
|
||||
byte[][] json_bry = wtr.Bfr().To_bry_ary_and_clear();
|
||||
Gftest.Eq__ary(json, json_bry, "to_json");
|
||||
|
||||
regy = Xodl_itm_regy.Load_by_json(Bry_.Add(json_bry));
|
||||
regy.To_json(wtr);
|
||||
json_bry = wtr.Bfr().To_bry_ary_and_clear();
|
||||
Gftest.Eq__ary(json, json_bry, "by_json");
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.updates.downloads.unzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; import gplx.xowa.addons.updates.downloads.*;
|
||||
public interface Gfo_unzip_cbk {
|
||||
void Unzip__end_itm(Gfo_unzip_itm itm);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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();
|
||||
}
|
@ -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.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() {}
|
||||
}
|
@ -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.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,47 @@
|
||||
/*
|
||||
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.apps.apis.xowa.bldrs.runners; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.bldrs.*;
|
||||
public class Xoapi_runner implements GfoInvkAble {
|
||||
private Xoa_app app;
|
||||
public void Ctor_by_app(Xoa_app app) {this.app = app;}
|
||||
private void Exec(GfoMsg msg) {
|
||||
// int len = msg.Args_count();
|
||||
// String cmd = (String)msg.Args_getAt(0).Val();
|
||||
// Keyval[] args = new Keyval[len - 1];
|
||||
// for (int i = 1; i < len; ++i) {
|
||||
// String arg = (String)msg.Args_getAt(i).Val();
|
||||
// int eq_pos = String_.FindFwd(arg, "=");
|
||||
// String key = String_.Mid(arg, 0, eq_pos);
|
||||
// String val = String_.Mid(arg, eq_pos + 1);
|
||||
// args[i - 1] = Keyval_.new_(key, val);
|
||||
// }
|
||||
// gplx.core.ios.zips.Io_zip_decompress_task task = new gplx.core.ios.zips.Io_zip_decompress_task();
|
||||
// task.Init(true, Gfo
|
||||
app.Gui__cbk_mgr().Send_prog("test", "key_0", "val_0");
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_exec)) Exec(m);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_exec = "exec";
|
||||
}
|
||||
class Xodl_prog_ui implements gplx.core.progs.Gfo_prog_ui {
|
||||
public void Prog__update_val(long cur, long max) {}
|
||||
public void Prog__end() {}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
public class Xog_cbk_mgr { // INSTANCE:app
|
||||
private Xog_cbk_wkr[] wkrs = Xog_cbk_wkr_.Ary_empty; private int wkrs_len = 0;
|
||||
public void Reg(Xog_cbk_wkr wkr) {
|
||||
this.wkrs = (Xog_cbk_wkr[])Array_.Resize_add_one(wkrs, wkrs_len, wkr);
|
||||
++wkrs_len;
|
||||
}
|
||||
public void Send_prog(String head, Object... args) {
|
||||
String msg = gplx.core.errs.Err_msg.To_str(head, args);
|
||||
for (int i = 0; i < wkrs_len; ++i) {
|
||||
Xog_cbk_wkr wkr = wkrs[i];
|
||||
wkr.Send_prog(msg);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
public interface Xog_cbk_wkr {
|
||||
void Send_prog(String head);
|
||||
}
|
||||
class Xog_cbk_wkr_ {
|
||||
public static final Xog_cbk_wkr[] Ary_empty = new Xog_cbk_wkr[0];
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue