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

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
public class Xobc_task_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
public Xow_special_page[] Special_pages() {
return new Xow_special_page[]
{ Xobc_task_special.Prototype
};
}
public Bridge_cmd_itm[] Json_cmds() {
return new Bridge_cmd_itm[]
{ gplx.xowa.addons.bldrs.centrals.Xobc_task_bridge.Prototype
};
}
public String Addon__key() {return "xowa.imports.downloads";}
}

View File

@@ -0,0 +1,55 @@
/*
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.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.langs.jsons.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*;
public class Xobc_task_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
public void Init_by_app(Xoa_app app) {}
public String Exec(Json_nde data) {
Xobc_task_mgr task_mgr = Xobc_task_special.Task_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__reload: task_mgr.Reload(); break;
case Proc__add_work: task_mgr.Todo_mgr().Add_work(args.Get_as_int("task_id")); break;
case Proc__del_work: task_mgr.Work_mgr().Del_work(args.Get_as_int("task_id")); break;
case Proc__del_done: task_mgr.Done_mgr().Del_done(args.Get_as_int("task_id")); break;
case Proc__run_next: task_mgr.Work_mgr().Run_next(); break;
case Proc__stop_cur: task_mgr.Work_mgr().Stop_cur(); break;
case Proc__redo_cur: task_mgr.Work_mgr().Redo_cur(); break;
case Proc__download_db: gplx.xowa.addons.bldrs.centrals.dbs.Xobc_data_db_upgrader.Check_for_updates(task_mgr); 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__reload = 0, Proc__add_work = 1, Proc__del_work = 2, Proc__del_done = 3, Proc__run_next = 4, Proc__stop_cur = 5, Proc__redo_cur = 6, Proc__download_db = 7;
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
.Add_str_byte("reload" , Proc__reload)
.Add_str_byte("add_work" , Proc__add_work)
.Add_str_byte("del_work" , Proc__del_work)
.Add_str_byte("del_done" , Proc__del_done)
.Add_str_byte("run_next" , Proc__run_next)
.Add_str_byte("stop_cur" , Proc__stop_cur)
.Add_str_byte("redo_cur" , Proc__redo_cur)
.Add_str_byte("download_db" , Proc__download_db)
;
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("builder_central.exec");
public static final Xobc_task_bridge Prototype = new Xobc_task_bridge(); Xobc_task_bridge() {}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.langs.mustaches.*;
class Xobc_task_doc implements Mustache_doc_itm {
private final boolean app_is_drd;
private final String link_help;
public Xobc_task_doc(boolean app_is_drd, String link_help) {
this.app_is_drd = app_is_drd; this.link_help = link_help;
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "link_help")) bfr.Add_str_u8(link_help);
return false;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "app_is_drd")) return Mustache_doc_itm_.Ary__bool(app_is_drd);
return Mustache_doc_itm_.Ary__empty;
}
}

View File

@@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
class Xobc_task_html extends Xow_special_wtr__base {
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "bldr", "central");}
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xobc.main.mustache.html");}
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
return new Xobc_task_doc(gplx.core.envs.Op_sys.Cur().Tid_is_drd(), "/site/home/wiki/App/Import/Download_Central");
}
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
Xopg_tag_mgr head_tags = page_data.Head_tags();
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__mustache (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__jquery (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__notifyjs (head_tags, app.Fsys_mgr().Http_root());
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("js", "xo.log.css")));
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xobc.css")));
head_tags.Add(Xopg_tag_itm.New_htm_frag(addon_dir.GenSubFil_nest("bin", "xobc.row.mustache.html"), "xobc.row"));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.log.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.app.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.app." + (gplx.core.envs.Op_sys.Cur().Tid_is_drd() ? "drd" : "swt") + ".js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.elem.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.tmpl.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.notify.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.server.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xobc.util.js")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xobc.js")));
}
}

View File

@@ -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.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.core.brys.evals.*; import gplx.core.gfobjs.*; import gplx.core.progs.rates.*; import gplx.core.threads.*;
import gplx.xowa.addons.bldrs.centrals.tasks.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.xowa.guis.cbks.*;
public class Xobc_task_mgr implements Xog_json_wkr {
private final Xog_cbk_trg cbk_trg = Xog_cbk_trg.New(Xobc_task_special.Prototype.Special__meta().Ttl_bry());
public Xobc_task_mgr(Xoa_app app, Io_url data_db_url) {
this.app = app;
this.cbk_mgr = app.Gui__cbk_mgr();
this.user_db = new Xobc_user_db(app.User().User_db_mgr().Conn());
this.data_db = new Xobc_data_db(data_db_url);
this.work_mgr = new Xobc_task_regy__work(this, app);
this.todo_mgr = new Xobc_task_regy__todo(this);
this.done_mgr = new Xobc_task_regy__done(this);
this.step_mgr = new Xobc_step_factory(this, data_db, app.Fsys_mgr().Wiki_dir());
this.ary = new Xobc_task_regy__base[] {work_mgr, todo_mgr, done_mgr};
this.rate_mgr = Xobc_cmd__base.New_rate_mgr();
}
public Xoa_app App() {return app;} private final Xoa_app app;
public Xog_cbk_mgr Cbk_mgr() {return cbk_mgr;} private final Xog_cbk_mgr cbk_mgr;
public Xobc_task_regy__work Work_mgr() {return work_mgr;} private final Xobc_task_regy__work work_mgr;
public Xobc_task_regy__todo Todo_mgr() {return todo_mgr;} private final Xobc_task_regy__todo todo_mgr;
public Xobc_task_regy__done Done_mgr() {return done_mgr;} private final Xobc_task_regy__done done_mgr;
public Xobc_task_regy__base Get_at(int i) {return ary[i];} private final Xobc_task_regy__base[] ary;
public Xobc_data_db Data_db() {return data_db;} private final Xobc_data_db data_db;
public Xobc_user_db User_db() {return user_db;} private final Xobc_user_db user_db;
public Gfo_rate_mgr Rate_mgr() {return rate_mgr;} private final Gfo_rate_mgr rate_mgr;
public Xobc_step_factory Step_mgr() {return step_mgr;} private final Xobc_step_factory step_mgr;
public void Send_json(String func, Gfobj_nde data) {cbk_mgr.Send_json(cbk_trg, func, data);}
public Xobc_task_mgr Load_or_init() {
Gfo_log_.Instance.Info("task_mgr.load_or_init.bgn");
data_db.Tbl__task_regy().Select_all(todo_mgr);
user_db.Work_task_tbl().Select_all(this, todo_mgr, work_mgr);
user_db.Done_task_tbl().Select_all(todo_mgr, done_mgr);
return this;
}
public void Reload() {
Gfo_log_.Instance.Info("task_mgr.reload.bgn");
Gfobj_nde root = Gfobj_nde.New();
Gfobj_nde lists_nde = root.New_nde("lists");
work_mgr.Save_to(lists_nde.New_ary("work"));
todo_mgr.Save_to(lists_nde.New_ary("todo"));
done_mgr.Save_to(lists_nde.New_ary("done"));
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.reload__recv", root);
}
public void Transfer(Xobc_task_regy__base src, Xobc_task_regy__base trg, Xobc_task_itm task) {
Gfo_log_.Instance.Info("task_mgr.transfer.bgn", "task_uid", task.Task_id(), "src", src.Name(), "trg", trg.Name());
src.Del_by(task.Task_id());
trg.Add(task);
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.transfer__recv", Gfobj_nde.New().Add_str("src", src.Name()).Add_str("trg", trg.Name()).Add_nde("task", task.Save_to(Gfobj_nde.New())));
}
public static final int Lists_len = 3;
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
public class Xobc_task_special implements Xow_special_page {
public static Xobc_task_mgr Task_mgr;
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
// init task_mgr
page.Html_data().Cbk_enabled_(true); // apply cbk_enabled early to capture logging statements
Xoa_app app = wiki.App();
if (Task_mgr == null) Task_mgr = New_task_mgr(app);
Task_mgr.Load_or_init();
new Xobc_task_html().Bld_page_by_mustache(app, page, this);
}
private static Xobc_task_mgr New_task_mgr(Xoa_app app) {
Io_url data_db_url = app.Fsys_mgr().Bin_addon_dir().GenSubFil_nest("bldr", "central", "bldr_central.data_db.xowa");
app.User().User_db_mgr().Init_site_mgr();
return new Xobc_task_mgr(app, data_db_url);
}
Xobc_task_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
public Xow_special_page Special__clone() {return this;}
public static final Xow_special_page Prototype = new Xobc_task_special(Xow_special_meta.New_xo("XowaDownloadCentral", "Download Central"));
}

View File

@@ -0,0 +1,133 @@
/*
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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.progs.rates.*;
public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
private final Xobc_task_mgr task_mgr;
private final Gfo_rate_list rate_list; private final long notify_delay = 1000;
private final double delta_threshold = .25d; // allow variance of up to 25% before updating rate
private long time_prv;
private double rate_cur;
public Xobc_cmd__base(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id) {
this.task_mgr = task_mgr; this.task_id = task_id; this.step_id = step_id; this.cmd_id = cmd_id;
this.cmd_uid = String_.Concat_with_str(":", Int_.To_str(task_id), Int_.To_str(step_id), Int_.To_str(cmd_id));
this.rate_list = task_mgr == null ? null : task_mgr.Rate_mgr().Get_or_new(this.Cmd_type());
}
public long Prog_data_cur() {return data_cur;} private long data_cur; public void Prog_data_cur_(long v) {this.data_cur = v;}
public long Prog_data_end() {return data_end;} private long data_end; public void Prog_data_end_(long v) {this.data_end = v;}
public byte Prog_status() {return status;} private byte status = Gfo_prog_ui_.Status__init; public void Prog_status_(byte v) {status = v;}
public boolean Canceled() {return status == Gfo_prog_ui_.Status__suspended;}
public void Cancel() {status = Gfo_prog_ui_.Status__suspended;}
public int Task_id() {return task_id;} private final int task_id;
public int Step_id() {return step_id;} private final int step_id;
public int Cmd_id() {return cmd_id;} private final int cmd_id;
public abstract String Cmd_type();
public abstract String Cmd_name();
@gplx.Virtual public boolean Cmd_suspendable() {return false;}
public String Cmd_uid() {return cmd_uid;} private final String cmd_uid;
@gplx.Virtual public String Cmd_fallback() {return this.Cmd_type();}
@gplx.Virtual public void Cmd_clear() {// called when restarting failed task
this.status = Gfo_prog_ui_.Status__init;
this.cmd_exec_err = null;
}
public void Cmd_exec(Xobc_cmd_ctx ctx) {
// rate_list.Clear();
// this.rate_cur = 0;
this.time_prv = gplx.core.envs.Env_.TickCount();
this.status = Gfo_prog_ui_.Status__working;
this.Cmd_exec_hook(ctx);
switch (status) {
case Gfo_prog_ui_.Status__suspended: task_mgr.Work_mgr().On_suspended(this); break;
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, cmd_exec_err); break;
case Gfo_prog_ui_.Status__working:
this.Prog_notify_and_chk_if_suspended(data_end, data_end); // fire one more time for 100%; note that 100% may not fire due to timer logic below
task_mgr.Work_mgr().On_done(this);
break;
}
}
protected abstract void Cmd_exec_hook(Xobc_cmd_ctx ctx);
protected void Cmd_exec_err_(String v) {this.status = Gfo_prog_ui_.Status__fail; this.cmd_exec_err = v;} private String cmd_exec_err;
@gplx.Virtual public void Cmd_cleanup() {}
public Gfobj_nde Save_to(Gfobj_nde nde) {
nde.Add_int ("task_id" , task_id);
nde.Add_int ("step_id" , step_id);
nde.Add_int ("cmd_id" , cmd_id);
nde.Add_str ("cmd_type" , this.Cmd_type());
nde.Add_str ("cmd_name" , this.Cmd_name());
nde.Add_bool("cmd_suspendable" , this.Cmd_suspendable());
nde.Add_byte("prog_status" , this.Prog_status());
nde.Add_long("prog_data_cur" , this.Prog_data_cur());
nde.Add_long("prog_data_end" , this.Prog_data_end());
nde.Add_long("prog_time_end" , 0);
return nde;
}
public void Load_checkpoint() {
long data_cur = this.Load_checkpoint_hook();
this.Prog_data_cur_(data_cur);
if (data_cur > 0)
this.Prog_status_(Gfo_prog_ui_.Status__working); // set status to working, else js won't warn about accidental removal
}
@gplx.Virtual protected long Load_checkpoint_hook() {return 0;}
public boolean Prog_notify_and_chk_if_suspended(long new_data_cur, long new_data_end) {
if (status == Gfo_prog_ui_.Status__suspended) return true; // task paused by ui; exit now;
long time_cur = gplx.core.envs.Env_.TickCount();
if (time_cur < time_prv + notify_delay) return false; // message came too soon. ignore it
// update rate
double rate_now = (rate_list.Add(new_data_cur - data_cur, (time_cur - time_prv))) * 1000;
double delta = Math_.Abs_double((rate_now - rate_cur) / rate_cur);
if ( rate_cur == 0 // rate not set
|| delta > delta_threshold) { // rate_now is at least 25% different than rate_prv
if (delta > delta_threshold * 2) // rate_now is > 50% different
rate_cur = rate_now; // update it now
else {
double rate_new = ((rate_now - rate_cur) * .05) + rate_cur; // calc new rate as 5% of difference
Tfds.Dbg(delta, rate_now, rate_cur, rate_new);
rate_cur = rate_new;
}
}
// update prog vals
this.time_prv = time_cur;
this.data_cur = new_data_cur;
this.data_end = new_data_end;
task_mgr.Send_json("xo.bldr.work.prog__update__recv", Gfobj_nde.New()
.Add_int ("task_id", task_id).Add_long("prog_data_cur", data_cur).Add_long("prog_data_end", data_end).Add_int("prog_rate", (int)rate_cur));
return false;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__exec)) Cmd_exec((Xobc_cmd_ctx)m.ReadObj("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk__exec = "exec";
public static final int Seqn__0 = 0;
public static Gfo_rate_mgr New_rate_mgr() {
Gfo_rate_mgr rv = new Gfo_rate_mgr(128);
rv.Add_new(Xobc_cmd__verify_dir.CMD_TYPE);
rv.Add_new(Xobc_cmd__verify_fil.CMD_TYPE);
rv.Add_new(Xobc_cmd__download.CMD_TYPE);
rv.Add_new(Xobc_cmd__unzip.CMD_TYPE);
return rv;
}
}

View File

@@ -0,0 +1,43 @@
/*
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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*; import gplx.core.net.downloads.*;
public class Xobc_cmd__download extends Xobc_cmd__base {
private final String src_url; private final Io_url trg_url;
private final long expd_size;
private final Http_download_wkr wkr;
public Xobc_cmd__download(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, String src_url, Io_url trg_url, long file_size_zip) {super(task_mgr, task_id, step_id, cmd_id);
this.src_url = src_url; this.trg_url = trg_url; this.expd_size = file_size_zip;
this.wkr = Http_download_wkr_.Proto.Make_new();
this.Prog_data_end_(expd_size);
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.download";
@Override public String Cmd_name() {return "download";}
@Override public boolean Cmd_suspendable() {return true;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
if (wkr.Exec(this, src_url, trg_url, expd_size) == Gfo_prog_ui_.Status__fail)
this.Cmd_exec_err_(wkr.Fail_msg());
}
@Override public void Cmd_cleanup() {
wkr.Exec_cleanup();
}
@Override protected long Load_checkpoint_hook() {
return wkr.Checkpoint__load_by_trg_fil(trg_url);
}
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
public class Xobc_cmd__move_fils extends Xobc_cmd__base {
private final Io_url src_dir, trg_dir;
private final List_adp trg_fils = List_adp_.New();
public Xobc_cmd__move_fils(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url src_dir, Io_url trg_dir) {super(task_mgr, task_id, step_id, cmd_idx);
this.src_dir = src_dir; this.trg_dir = trg_dir;
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.move_fil";
@Override public String Cmd_name() {return "move";}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
Io_url[] src_fils = Io_mgr.Instance.QueryDir_fils(src_dir);
int len = src_fils.length;
for (int i = 0; i < len; ++i) {
Io_url src_fil = src_fils[i];
if (String_.Eq(src_fil.Ext(), ".md5")) continue;
Io_url trg_fil = trg_dir.GenSubFil(src_fil.NameAndExt());
Io_mgr.Instance.MoveFil_args(src_fil, trg_fil, true).Exec();
trg_fils.Add(trg_fil);
}
}
@Override public void Cmd_cleanup() {
Io_mgr.Instance.Delete_dir_empty(trg_dir.GenSubDir("tmp")); // deletes dir only if empty
}
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.ios.zips.*; import gplx.core.progs.*;
public class Xobc_cmd__unzip extends Xobc_cmd__base {
private final Io_url src_fil, trg_dir;
private final Io_zip_decompress_cmd wkr;
private final List_adp trg_fils = List_adp_.New();
public Xobc_cmd__unzip(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, Io_url src_fil, Io_url trg_dir, long prog_data_end) {super(task_mgr, task_id, step_id, cmd_id);
this.src_fil = src_fil; this.trg_dir = trg_dir;
this.Prog_data_end_(prog_data_end);
this.wkr = Io_zip_decompress_cmd_.Proto.Make_new();
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.ios.zips.zip_unzip";
@Override public String Cmd_name() {return "unzip";}
@Override public boolean Cmd_suspendable() {return true;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
if (wkr.Exec(this, src_fil, trg_dir, trg_fils) == Gfo_prog_ui_.Status__fail)
this.Cmd_exec_err_(wkr.Fail_msg());
}
@Override public void Cmd_cleanup() {
wkr.Exec_cleanup();
Io_mgr.Instance.DeleteFil(src_fil);
Io_mgr.Instance.DeleteDirDeep(trg_dir);
}
@Override protected long Load_checkpoint_hook() {
return wkr.Checkpoint__load_by_src_fil(src_fil);
}
}

View File

@@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*;
import gplx.core.security.*; import gplx.core.security.files.*;
public class Xobc_cmd__verify_dir extends Xobc_cmd__base {
private final Io_url delete_fil, checksum_fil;
public Xobc_cmd__verify_dir(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url dir_url, String checksum_fil_name, Io_url delete_fil) {super(task_mgr, task_id, step_id, cmd_idx);
this.delete_fil = delete_fil;
this.checksum_fil = dir_url.GenSubFil(checksum_fil_name);
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.hash_dir";
@Override public String Cmd_name() {return "verify";}
@Override public String Cmd_fallback() {return Xobc_cmd__unzip.CMD_TYPE;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
// parse file
Cksum_list list = Cksum_list.Parse_by_fil(checksum_fil);
this.Prog_data_end_(list.Itms_size);
// verify itms
Hash_algo algo = Hash_algo_.New_by_tid(list.Type);
Cksum_itm[] itms = list.Itms;
int len = itms.length;
long prog_data_cur = 0;
for (int i = 0; i < len; ++i) {
Cksum_itm itm = itms[i];
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(itm.File_url);
byte[] actl_hash = Bry_.Empty;
this.Prog_data_cur_(prog_data_cur);
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
finally {stream.Rls();}
prog_data_cur += itm.File_size;
if (this.Prog_notify_and_chk_if_suspended(prog_data_cur, Prog_data_end())) return;
if (this.Prog_status() != Gfo_prog_ui_.Status__suspended && !Bry_.Eq(itm.Hash, actl_hash)) {
this.Cmd_exec_err_(String_.Format("bad hash; file={0} bad={1} good={2}", itm.File_url.Raw(), actl_hash, itm.Hash));
return;
}
}
}
@Override public void Cmd_cleanup() {
Io_mgr.Instance.DeleteFil(checksum_fil);
Io_mgr.Instance.DeleteFil(delete_fil);
}
}

View File

@@ -0,0 +1,42 @@
/*
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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*; import gplx.core.security.*;
public class Xobc_cmd__verify_fil extends Xobc_cmd__base {
private final Io_url src_url; private final byte[] expd_hash;
public Xobc_cmd__verify_fil(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, Io_url src_url, String expd_hash_str, long prog_data_end) {super(task_mgr, task_id, step_id, cmd_id);
this.src_url = src_url;
this.expd_hash = Bry_.new_a7(expd_hash_str);
this.Prog_data_end_(prog_data_end);
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.hash_fil";
@Override public String Cmd_name() {return "verify";}
@Override public String Cmd_fallback() {return Xobc_cmd__download.CMD_TYPE;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
Hash_algo algo = Hash_algo_.New__md5();
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(src_url);
byte[] actl_hash = Bry_.Empty;
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
finally {stream.Rls();}
if (this.Prog_status() != Gfo_prog_ui_.Status__suspended && !Bry_.Eq(expd_hash, actl_hash))
this.Cmd_exec_err_(Xobc_cmd__verify_fil.Err_make(actl_hash, expd_hash));
}
public static String Err_make(byte[] actl, byte[] expd) {return String_.Format("bad hash: bad={0} good={1}", String_.new_u8(actl), String_.new_u8(expd));}
}

View File

@@ -0,0 +1,57 @@
/*
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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.dbs.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.bldrs.exports.splits.mgrs.*; import gplx.xowa.addons.bldrs.exports.merges.*;
public class Xobc_cmd__wiki_merge extends Xobc_cmd__base {
private final String wiki_domain;
private final Io_url src_dir;
private final Merge2_mgr merge_mgr;
private final Merge_prog_wkr prog_wkr;
private final int idx_cur;
public Xobc_cmd__wiki_merge(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Merge2_mgr merge_mgr, String wiki_domain, Io_url src_dir
, long prog_size_end, int prog_count_end, int idx_cur) {super(task_mgr, task_id, step_id, cmd_idx);
this.merge_mgr = merge_mgr;
this.wiki_domain = wiki_domain;
this.src_dir = src_dir;
this.prog_wkr = new Merge_prog_wkr(this, src_dir.GenSubFil("merge.checkpoint"), prog_count_end, prog_size_end);
merge_mgr.Prog_wkr_(prog_wkr);
this.Prog_data_end_(prog_count_end);
this.idx_cur = idx_cur;
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.wiki.merge";
@Override public String Cmd_name() {return "merge";}
@Override public boolean Cmd_suspendable() {return true;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
Xow_wiki wiki = ctx.App().Wiki_mgri().Make(Bry_.new_u8(wiki_domain), ctx.App().Fsys_mgr().Wiki_dir().GenSubDir(wiki_domain));
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(src_dir);
for (Io_url fil : fils) {
if (prog_wkr.Checkpoint__skip_fil(fil)) continue;
switch (Split_file_tid_.To_tid(fil)) {
case Split_file_tid_.Tid__core: merge_mgr.ctx.Idx_cur_add_(); merge_mgr.Merge_core(wiki, fil); break;
case Split_file_tid_.Tid__data: merge_mgr.ctx.Idx_cur_add_(); merge_mgr.Merge_data(wiki, fil, idx_cur); break;
}
}
prog_wkr.Checkpoint__delete();
}
@Override public void Cmd_cleanup() {
Io_mgr.Instance.DeleteDirDeep(src_dir.OwnerDir()); // src_dir is "unzip" dir; owner dir is actual archive dir
}
@Override protected long Load_checkpoint_hook() {return prog_wkr.Checkpoint__load();}
}

View File

@@ -0,0 +1,53 @@
/*
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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.security.*;
import gplx.xowa.wikis.*;
public class Xobc_cmd__wiki_reg extends Xobc_cmd__base {
private final Io_url wiki_dir;
private final String wiki_domain;
public Xobc_cmd__wiki_reg(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url wiki_dir, String wiki_domain) {super(task_mgr, task_id, step_id, cmd_idx);
this.wiki_dir = wiki_dir;
this.wiki_domain = wiki_domain;
}
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.wiki.reg";
@Override public String Cmd_name() {return "import";}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
ctx.App().User().User_db_mgr().Init_site_mgr(); // must init for wiki.register cmd
// get wiki_core_url
Io_url[] wiki_fils = Io_mgr.Instance.QueryDir_fils(wiki_dir);
Io_url wiki_core_url = null;
int len = wiki_fils.length;
for (int i = 0; i < len; ++i) {
Io_url url = wiki_fils[i];
if (gplx.xowa.wikis.data.Xow_db_file__core_.Is_core_fil_name(wiki_domain, url.NameAndExt())) {
wiki_core_url = url;
break;
}
}
if (wiki_core_url == null) throw Err_.new_("wiki_import", "import_url not found", "domain", wiki_domain);
// import; open
Xoa_wiki_mgr wiki_mgr = ctx.App().Wiki_mgri();
Gfo_invk_.Invk_by_val(wiki_mgr, gplx.xowa.wikis.Xoa_wiki_mgr_.Invk__import_by_url, wiki_core_url);
// COMMENTED: do not auto-open wiki; wait for true-pack mode
// Xow_wiki wiki = wiki_mgr.Get_by_or_null(Bry_.new_u8(wiki_domain));
// Gfo_invk_.Invk_by_msg(ctx.App().Gui__tab_mgr() , gplx.xowa.guis.tabs.Xog_tab_mgr_.Invk__new_tab, GfoMsg_.new_cast_("").Add("focus", true).Add("site", wiki_domain).Add("page", String_.new_u8(wiki.Props().Main_page())));
}
}

View File

@@ -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.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
public class Xobc_cmd_ctx {
public Xobc_cmd_ctx(Xoa_app app) {this.app = app;}
public Xoa_app App() {return app;} private final Xoa_app app;
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*; import gplx.core.gfobjs.*;
public interface Xobc_cmd_itm extends Gfo_prog_ui, Gfo_invk {
int Task_id();
int Step_id();
int Cmd_id();
String Cmd_type(); // "xowa.core.http_download"
String Cmd_name(); // "download"
boolean Cmd_suspendable(); // "true"
String Cmd_uid(); // for thread_pool_mgr: "0:0:0"
void Cmd_cleanup();
String Cmd_fallback();
void Cmd_clear();
Gfobj_nde Save_to(Gfobj_nde nde);
void Load_checkpoint();
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
public class Xobc_data_db {
public Xobc_data_db(Io_url db_url) {
this.url = db_url;
this.conn = Db_conn_bldr.Instance.Get_or_autocreate(true, db_url);
this.tbl__task_regy = new Xobc_task_regy_tbl(conn);
this.tbl__step_regy = new Xobc_step_regy_tbl(conn);
this.tbl__step_map = new Xobc_step_map_tbl(conn);
this.tbl__import_step = new Xobc_import_step_tbl(conn);
this.tbl__host_regy = new Xobc_host_regy_tbl(conn);
this.tbl__version_regy = new Xobc_version_regy_tbl(conn);
conn.Meta_tbl_assert(tbl__task_regy, tbl__step_regy, tbl__step_map, tbl__import_step, tbl__host_regy, tbl__version_regy);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Io_url Url() {return url;} private final Io_url url;
public Xobc_task_regy_tbl Tbl__task_regy() {return tbl__task_regy;} private final Xobc_task_regy_tbl tbl__task_regy;
public Xobc_step_regy_tbl Tbl__step_regy() {return tbl__step_regy;} private final Xobc_step_regy_tbl tbl__step_regy;
public Xobc_step_map_tbl Tbl__step_map() {return tbl__step_map;} private final Xobc_step_map_tbl tbl__step_map;
public Xobc_import_step_tbl Tbl__import_step() {return tbl__import_step;} private final Xobc_import_step_tbl tbl__import_step;
public Xobc_host_regy_tbl Tbl__host_regy() {return tbl__host_regy;} private final Xobc_host_regy_tbl tbl__host_regy;
public Xobc_version_regy_tbl Tbl__version_regy() {return tbl__version_regy;} private final Xobc_version_regy_tbl tbl__version_regy;
public void Delete_by_import(byte[] wiki_abrv, String wiki_date) {
// get all step ids from import_regy
Xobc_task_step_hash task_step_hash = new Xobc_task_step_hash();
tbl__import_step.Select_tasks_steps(task_step_hash, tbl__step_map, wiki_abrv, wiki_date);
for (int i = 0; i < task_step_hash.Tasks__len(); ++i) {
int task_id = task_step_hash.Tasks__get_at(i);
tbl__task_regy.Delete(task_id);
tbl__step_map.Delete_by_task_id(task_id);
}
for (int i = 0; i < task_step_hash.Steps__len(); ++i) {
int step_id = task_step_hash.Steps__get_at(i);
tbl__step_regy.Delete(step_id);
tbl__import_step.Delete(step_id);
}
}
private final gplx.core.lists.hashs.Hash_adp__int host_hash = new gplx.core.lists.hashs.Hash_adp__int();
public String Bld_src_http_url(gplx.core.brys.evals.Bry_eval_mgr eval_mgr, int host_id, String file_name) {
Xobc_host_regy_itm host_itm = (Xobc_host_regy_itm)host_hash.Get_by_or_null(host_id);
if (host_itm == null) {
host_itm = tbl__host_regy.Select(host_id);
host_hash.Add(host_id, host_itm);
}
String host_dir = String_.new_u8(eval_mgr.Eval(Bry_.new_u8(host_itm.Host_data_dir())));
return String_.Format("http://{0}/{1}/{2}", host_itm.Host_domain(), host_dir, file_name);
}
}

View File

@@ -0,0 +1,89 @@
/*
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.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.dbs.*;
import gplx.core.progs.*; import gplx.core.net.downloads.*; import gplx.core.gfobjs.*;
import gplx.xowa.users.data.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
import gplx.xowa.wikis.pages.tags.*;
public class Xobc_data_db_upgrader {
private static final String
Cfg__last_check_date = "xowa.bldr_central.data_db.last_check_date"
// , Cfg__next_check_interval = "xowa.bldr_central.data_db.next_check_interval"
, Date_fmt = "yyyy-MM-dd HH:mm"
;
public static void Check_for_updates(Xobc_task_mgr task_mgr) {
Io_url data_db_url = task_mgr.Data_db().Url();
Xoud_cfg_mgr cfg_mgr = task_mgr.App().User().User_db_mgr().Cfg_mgr();
// check if update needed
//String last_check_str = cfg_mgr.Select_str_or("", Cfg__last_check_date, "");
//int next_check_interval = cfg_mgr.Select_int_or("", Cfg__next_check_interval, 24 * 7);
//DateAdp last_check = DateAdp_.parse_fmt_or(last_check_str, Date_fmt, null);
//if (last_check != null) { // check if last_check_str exists
// Time_span span = DateAdp_.Now().Diff(last_check);
// if (span.Total_hours().To_double() < next_check_interval) { // check if enough time passed
// Gfo_log_.Instance.Info("xobc_db update not needed", "last_check", last_check_str, "next_check_interval", next_check_interval);
// return;
// }
// else
// Gfo_log_.Instance.Info("xobc_db update needed b/c of last_check", "last_check", last_check_str);
//}
//else
// Gfo_log_.Instance.Info("xobc_db update needed b/c of missing or invalid last_check_str", "last_check", last_check_str);
// update needed; first, update cfg_key, then get host
cfg_mgr.Upsert_str("", Cfg__last_check_date, DateAdp_.Now().XtoStr_fmt(Date_fmt));
Xobc_data_db bc_db = task_mgr.Data_db();
Xobc_host_regy_itm host_itm = bc_db.Tbl__host_regy().Select(Xobc_host_regy_tbl.Host_id__archive_org);
// download manifest
Http_download_wkr download_wkr = Http_download_wkr_.Proto.Make_new();
Io_url manifest_url = data_db_url.GenNewExt(".txt");
download_wkr.Exec(Gfo_prog_ui_.Always
, String_.Format("http://{0}/{1}/bldr_central.data_db.txt", host_itm.Host_domain(), host_itm.Host_update_dir())
, manifest_url, -1);
// parse manifest and get version_id
byte[] manifest_txt = Io_mgr.Instance.LoadFilBry(manifest_url);
byte[][] manifest_data = Bry_split_.Split(manifest_txt, Byte_ascii.Pipe);
int expd_version_id = Bry_.To_int(manifest_data[0]);
Xobc_version_regy_itm actl_version = bc_db.Tbl__version_regy().Select_latest();
// cleanup
Io_mgr.Instance.DeleteFil(manifest_url);
bc_db.Conn().Rls_conn();
if (expd_version_id == actl_version.Id()) {
Gfo_log_.Instance.Info("xobc_db update not needed", "version", expd_version_id);
Xopg_alertify_.Exec_log(task_mgr, "Wikis are up-to-date");
return; // version matches; exit
}
// version doesn't match; download new
// next_check_interval = Bry_.To_int(manifest_data[2]);
// cfg_mgr.Upsert_int("", Cfg__next_check_interval, next_check_interval);
// Gfo_log_.Instance.Info("xobc_db update needed", "version", expd_version_id, "next_check_interval", next_check_interval);
byte[] new_db_url = manifest_data[1];
String note = String_.new_u8(manifest_data[3]);
download_wkr.Exec(Gfo_prog_ui_.Always
, String_.new_u8(new_db_url)
, data_db_url, -1);
Xopg_alertify_.Exec_log(task_mgr, "Wikis have been updated:<br/>" + note);
task_mgr.Load_or_init();
task_mgr.Reload();
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
public class Xobc_task_step_hash {
private final Ordered_hash tasks_hash = Ordered_hash_.New();
private final Ordered_hash steps_hash = Ordered_hash_.New();
public int Tasks__len() {return tasks_hash.Len();}
public int Tasks__get_at(int i) {return Int_.cast(tasks_hash.Get_at(i));}
public int Steps__len() {return steps_hash.Len();}
public int Steps__get_at(int i) {return Int_.cast(steps_hash.Get_at(i));}
public void Clear() {tasks_hash.Clear(); steps_hash.Clear();}
public void Add(int task_id, int step_id) {
tasks_hash.Add_if_dupe_use_nth(task_id, task_id);
steps_hash.Add_if_dupe_use_nth(step_id, step_id);
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.dbs.users.*;
public class Xobc_user_db {
public Xobc_user_db(Db_conn conn) {
this.work_task_tbl = new Xobc_work_task_tbl(conn);
this.done_task_tbl = new Xobc_done_task_tbl(conn);
this.done_step_tbl = new Xobc_done_step_tbl(conn);
conn.Meta_tbl_assert(work_task_tbl, done_task_tbl, done_step_tbl);
}
public Xobc_work_task_tbl Work_task_tbl() {return work_task_tbl;} private final Xobc_work_task_tbl work_task_tbl;
public Xobc_done_task_tbl Done_task_tbl() {return done_task_tbl;} private final Xobc_done_task_tbl done_task_tbl;
public Xobc_done_step_tbl Done_step_tbl() {return done_step_tbl;} private final Xobc_done_step_tbl done_step_tbl;
}

View File

@@ -0,0 +1,30 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
public class Xobc_host_regy_itm {
public Xobc_host_regy_itm(int host_id, String host_domain, String host_data_dir, String host_update_dir) {
this.host_id = host_id;
this.host_domain = host_domain;
this.host_data_dir = host_data_dir;
this.host_update_dir = host_update_dir;
}
public int Host_id() {return host_id;} private final int host_id;
public String Host_domain() {return host_domain;} private final String host_domain;
public String Host_data_dir() {return host_data_dir;} private final String host_data_dir;
public String Host_update_dir() {return host_update_dir;} private final String host_update_dir;
}

View File

@@ -0,0 +1,51 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
public class Xobc_host_regy_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_host_id, fld_host_domain, fld_host_data_dir, fld_host_update_dir;
private final Db_conn conn;
public Xobc_host_regy_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "host_regy";
this.fld_host_id = flds.Add_int_pkey("host_id");
this.fld_host_domain = flds.Add_str("host_domain", 255); // EX: archive.org
this.fld_host_data_dir = flds.Add_str("host_data_dir", 255); // EX: download/Xowa_~{host_regy|wiki_abrv}_latest
this.fld_host_update_dir = flds.Add_str("host_update_dir", 255); // EX: download/Xowa_app_support
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Stmt_insert(tbl_name, flds)
.Val_int(fld_host_id, Host_id__archive_org).Val_str(fld_host_domain, "archive.org")
.Val_str(fld_host_data_dir, "download/Xowa_~{host_regy|wiki_abrv}_latest").Val_str(fld_host_update_dir, "download/Xowa_app_support")
.Exec_insert();
}
public Xobc_host_regy_itm Select(int host_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_host_id).Crt_int(fld_host_id, host_id).Exec_select__rls_auto();
try {return rdr.Move_next() ? Load_itm(rdr) : null;}
finally {rdr.Rls();}
}
private Xobc_host_regy_itm Load_itm(Db_rdr rdr) {
return new Xobc_host_regy_itm(rdr.Read_int(fld_host_id), rdr.Read_str(fld_host_domain), rdr.Read_str(fld_host_data_dir), rdr.Read_str(fld_host_update_dir));
}
public void Rls() {}
public static final int Host_id__archive_org = 1;
}

View File

@@ -0,0 +1,30 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
public class Xobc_step_map_itm {
public Xobc_step_map_itm(int sm_id, int task_id, int step_id, int step_seqn) {
this.Sm_id = sm_id;
this.Task_id = task_id;
this.Step_id = step_id;
this.Step_seqn = step_seqn;
}
public final int Sm_id;
public final int Task_id;
public final int Step_id;
public final int Step_seqn;
}

View File

@@ -0,0 +1,82 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
public class Xobc_step_map_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_sm_id, fld_step_seqn, fld_task_id, fld_step_id;
private final Db_conn conn; private Db_stmt insert_stmt;
public Xobc_step_map_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "step_map";
this.fld_sm_id = flds.Add_int_pkey("sm_id");
this.fld_task_id = flds.Add_int("task_id");
this.fld_step_id = flds.Add_int("step_id");
this.fld_step_seqn = flds.Add_int("step_seqn");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public int Select_step_id(int task_id, int step_seqn) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id, fld_step_seqn).Crt_int(fld_task_id, task_id).Crt_int(fld_step_seqn, step_seqn).Exec_select__rls_auto();
try {
if (rdr.Move_next())
return rdr.Read_int(fld_step_id);
else
throw Err_.new_("", "xobc:could not find step_id", "task_id", task_id, "step_seqn", step_seqn);
}
finally {rdr.Rls();}
}
public Xobc_step_map_itm Select_one(int task_id, int step_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id, fld_step_id).Crt_int(fld_task_id, task_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
try {
if (rdr.Move_next())
return new Xobc_step_map_itm
( rdr.Read_int(fld_sm_id)
, rdr.Read_int(fld_task_id)
, rdr.Read_int(fld_step_id)
, rdr.Read_int(fld_step_seqn)
);
else
throw Err_.new_("", "bldr.central:could not find step_id", "task_id", task_id, "step_id", step_id);
}
finally {rdr.Rls();}
}
public int Select_seqn_but_skip_done(int task_id, Hash_adp step_ids) {
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, String_.Ary(fld_task_id), fld_step_seqn).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int step_id = rdr.Read_int("step_id");
if (step_ids.Has(step_id))
return rdr.Read_int("step_seqn");
}
} finally {rdr.Rls();}
throw Err_.new_("", "xobc:could not find next sort", "task_id", task_id);
}
public void Insert(int sm_id, int task_id, int step_id, int step_seqn) {
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
insert_stmt.Clear().Val_int(fld_sm_id, sm_id).Val_int(fld_task_id, task_id).Val_int(fld_step_id, step_id).Val_int(fld_step_seqn, step_seqn)
.Exec_insert();
}
public void Delete_by_task_id(int task_id) {
conn.Stmt_delete(tbl_name, fld_task_id).Crt_int(fld_task_id, task_id).Exec_delete();
}
public void Rls() {
insert_stmt = Db_stmt_.Rls(insert_stmt);
}
}

View File

@@ -0,0 +1,55 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Xobc_step_regy_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_step_id, fld_step_type;
private final Db_conn conn; private Db_stmt insert_stmt;
public Xobc_step_regy_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "step_regy";
this.fld_step_id = flds.Add_int_pkey("step_id");
this.fld_step_type = flds.Add_int("step_type");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public int Select_type(int step_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_step_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
try {
if (rdr.Move_next())
return rdr.Read_int(fld_step_type);
else
throw Err_.new_("", "bldr.central:could not find step_type", "step_id", step_id);
}
finally {rdr.Rls();}
}
public void Insert(int step_id, int step_type) {
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
insert_stmt.Clear().Val_int(fld_step_id, step_id).Val_int(fld_step_type, step_type)
.Exec_insert();
}
public void Delete(int step_id) {
conn.Stmt_delete(tbl_name, fld_step_id).Crt_int(fld_step_id, step_id).Exec_delete();
}
public void Rls() {
insert_stmt = Db_stmt_.Rls(insert_stmt);
}
}

View File

@@ -0,0 +1,71 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Xobc_task_regy_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_task_id, fld_task_seqn, fld_step_count, fld_task_key, fld_task_name;
private final Db_conn conn; private Db_stmt insert_stmt;
public Xobc_task_regy_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "task_regy";
this.fld_task_id = flds.Add_int_pkey("task_id");
this.fld_task_seqn = flds.Add_int("task_seqn");
this.fld_step_count = flds.Add_int("step_count");
this.fld_task_key = flds.Add_str("task_key", 255);
this.fld_task_name = flds.Add_str("task_name", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "task_seqn", fld_task_seqn));
}
public void Select_all(Xobc_task_regy__base todo_regy) {
todo_regy.Clear();
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, String_.Ary_empty, fld_task_seqn).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int task_id = rdr.Read_int(fld_task_id);
int task_seqn = rdr.Read_int(fld_task_seqn);
int step_count = rdr.Read_int(fld_step_count);
String task_key = rdr.Read_str(fld_task_name);
String task_name = rdr.Read_str(fld_task_name);
todo_regy.Add(new Xobc_task_itm(task_id, task_seqn, step_count, task_key, task_name));
}
} finally {rdr.Rls();}
}
public int Select_by_key(String key) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_key).Exec_select__rls_auto();
try {return rdr.Move_next() ? rdr.Read_int(fld_task_id) : -1;}
finally {rdr.Rls();}
}
public void Insert(int task_id, int task_seqn, int step_count, String task_key, String task_name) {
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
insert_stmt.Clear().Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_count, step_count)
.Val_str(fld_task_key, task_key).Val_str(fld_task_name, task_name)
.Exec_insert();
}
public void Delete(int task_id) {
conn.Stmt_delete(tbl_name, fld_task_id).Crt_int(fld_task_id, task_id).Exec_delete();
}
public void Rls() {
insert_stmt = Db_stmt_.Rls(insert_stmt);
}
}

View File

@@ -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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
public class Xobc_version_regy_itm {
public Xobc_version_regy_itm(int id, String date, String note) {
this.id = id;
this.date = date;
this.note = note;
}
public int Id() {return id;} private final int id;
public String Date() {return date;} private final String date;
public String Note() {return note;} private final String note;
}

View File

@@ -0,0 +1,50 @@
/*
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.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
public class Xobc_version_regy_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_version_id, fld_version_date, fld_version_note;
private final Db_conn conn;
public Xobc_version_regy_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "version_regy";
this.fld_version_id = flds.Add_int_pkey("version_id");
this.fld_version_date = flds.Add_str("version_date", 16);
this.fld_version_note = flds.Add_str("version_note", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Stmt_insert(tbl_name, flds)
.Val_int(fld_version_id, 1).Val_str(fld_version_date, DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd_HH_mm()).Val_str(fld_version_note, "initial")
.Exec_insert();
}
public Xobc_version_regy_itm Select_latest() {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
try {
if (rdr.Move_next())
return new Xobc_version_regy_itm(rdr.Read_int(fld_version_id), rdr.Read_str(fld_version_date), rdr.Read_str(fld_version_note));
else
throw Err_.new_("", "version_regy does not have version");
}
finally {rdr.Rls();}
}
public void Rls() {}
}

View File

@@ -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.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
public class Xobc_import_date {
public static String To_str__yyyy_mm(String raw, String dlm) {
return String_.Mid(raw, 0, 4) + dlm + String_.Mid(raw, 4, 6);
}
}

View File

@@ -0,0 +1,52 @@
/*
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.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
import gplx.dbs.*;
public class Xobc_import_step_itm {
public Xobc_import_step_itm(int step_id, int host_id, byte[] wiki_abrv, String wiki_date
, String import_name, int import_type, byte import_zip_type, long import_size_zip, long import_size_raw, String import_md5
, long import_prog_data_max, int import_prog_row_max
) {
this.Step_id = step_id;
this.Host_id = host_id;
this.wiki_abrv = wiki_abrv;
this.Wiki_date = wiki_date;
this.Import_name = import_name;
this.Import_type = import_type;
this.Import_zip_type = import_zip_type;
this.Import_size_zip = import_size_zip;
this.Import_size_raw = import_size_raw;
this.Import_md5 = import_md5;
this.Import_prog_data_max = import_prog_data_max;
this.Import_prog_row_max = import_prog_row_max;
}
public final int Step_id;
public final int Host_id;
public byte[] Wiki_abrv() {return wiki_abrv;} private final byte[] wiki_abrv;
public final String Wiki_date;
public final String Import_name;
public final int Import_type;
public final byte Import_zip_type;
public final long Import_size_zip;
public final long Import_size_raw;
public final String Import_md5;
public final long Import_prog_data_max;
public final int Import_prog_row_max;
public static final Xobc_import_step_itm Null = null;
}

View File

@@ -0,0 +1,101 @@
/*
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.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
import gplx.dbs.*;
public class Xobc_import_step_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_step_id, fld_host_id, fld_wiki_abrv, fld_wiki_date, fld_import_name, fld_import_type, fld_import_zip, fld_import_md5, fld_import_size_zip, fld_import_size_raw, fld_prog_size_end, fld_prog_count_end;
public final Db_conn conn; private Db_stmt insert_stmt;
public Xobc_import_step_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "import_step";
this.fld_step_id = flds.Add_int_pkey("step_id");
this.fld_host_id = flds.Add_int("host_id");
this.fld_wiki_abrv = flds.Add_str("wiki_abrv", 255);
this.fld_wiki_date = flds.Add_str("wiki_date", 8);
this.fld_import_name = flds.Add_str("import_name", 255);
this.fld_import_type = flds.Add_int("import_type");
this.fld_import_zip = flds.Add_byte("import_zip");
this.fld_import_size_zip = flds.Add_long("import_size_zip");
this.fld_import_size_raw = flds.Add_long("import_size_raw");
this.fld_import_md5 = flds.Add_str("import_md5", 48);
this.fld_prog_size_end = flds.Add_long("prog_size_end");
this.fld_prog_count_end = flds.Add_long("prog_count_end");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Xobc_import_step_itm Select_one(int step_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_step_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
try {
return (rdr.Move_next())
? new Xobc_import_step_itm
( rdr.Read_int(fld_step_id)
, rdr.Read_int(fld_host_id)
, rdr.Read_bry_by_str(fld_wiki_abrv)
, rdr.Read_str(fld_wiki_date)
, rdr.Read_str(fld_import_name)
, rdr.Read_int(fld_import_type)
, rdr.Read_byte(fld_import_zip)
, rdr.Read_long(fld_import_size_zip)
, rdr.Read_long(fld_import_size_raw)
, rdr.Read_str(fld_import_md5)
, rdr.Read_long(fld_prog_size_end)
, rdr.Read_int(fld_prog_count_end)
)
: Xobc_import_step_itm.Null;
}
finally {rdr.Rls();}
}
public void Delete(int step_id) {
conn.Stmt_delete(tbl_name, fld_step_id).Crt_int(fld_step_id, step_id).Exec_delete();
}
public void Insert(int step_id, int host_id, byte[] wiki_abrv, String wiki_date, String import_name, int import_type, byte zip_type, byte[] md5, long size_zip, long size_raw
, long prog_size_end, int prog_count_end) {
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
insert_stmt.Clear().Val_int(fld_step_id, step_id).Val_int(fld_host_id, host_id)
.Val_bry_as_str(fld_wiki_abrv, wiki_abrv).Val_str(fld_wiki_date, wiki_date)
.Val_str(fld_import_name, import_name)
.Val_int(fld_import_type, import_type).Val_byte(fld_import_zip, zip_type)
.Val_long(fld_import_size_zip, size_zip).Val_long(fld_import_size_raw, size_raw).Val_bry_as_str(fld_import_md5, md5)
.Val_long(fld_prog_size_end, prog_size_end).Val_int(fld_prog_count_end, prog_count_end)
.Exec_insert();
}
public void Select_tasks_steps(Xobc_task_step_hash task_step_hash, Xobc_step_map_tbl step_map_tbl, byte[] wiki_abrv, String wiki_date) {
task_step_hash.Clear();
Db_rdr rdr = conn.Stmt_sql(String_.Concat_lines_nl_skip_last
( "SELECT DISTINCT sm.task_id, sm.step_id"
, "FROM " + tbl_name + " imps"
, " JOIN " + step_map_tbl.Tbl_name() + " sm ON sm.step_id = imps.step_id"
, "WHERE imps.wiki_abrv = ?"
, "AND imps.wiki_date = ?"
))
.Crt_bry_as_str(fld_wiki_abrv, wiki_abrv)
.Crt_str(fld_wiki_date, wiki_date)
.Exec_select__rls_auto()
;
try {
while (rdr.Move_next()) {
task_step_hash.Add(rdr.Read_int("task_id"), rdr.Read_int("step_id"));
}
} finally {rdr.Rls();}
}
public void Rls() {
insert_stmt = Db_stmt_.Rls(insert_stmt);
}
}

View File

@@ -0,0 +1,30 @@
/*
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.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
public class Xobc_import_type {
public static final int // SERIALIZED: bc_db; import_step
Tid__ignore = 0
, Tid__pack = 1
, Tid__wiki__core = 2
, Tid__wiki__srch = 3
, Tid__wiki__html = 4
, Tid__wiki__text = 5
, Tid__file__core = 6
, Tid__file__data = 7
;
}

View File

@@ -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.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
public class Xobc_zip_type {
public static String To_str(byte type) {
switch (type) {
case Type__zip: return "zip";
default: throw Err_.new_unhandled_default(type);
}
}
public static final byte Type__zip = 1; // SERIALIZED
}

View File

@@ -0,0 +1,55 @@
/*
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.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Xobc_done_step_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_task_id, fld_step_id;
private final Db_conn conn;
public Xobc_done_step_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "xobc_done_step";
this.fld_task_id = flds.Add_int("task_id");
this.fld_step_id = flds.Add_int("step_id");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_task_id, fld_step_id));
}
public void Insert(int task_id, int step_id) {
conn.Stmt_insert(tbl_name, fld_task_id, fld_step_id)
.Val_int(fld_task_id, task_id).Val_int(fld_step_id, step_id)
.Exec_insert();
}
public Hash_adp Select_all(int task_id) {
Hash_adp rv = null;
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_step_id), fld_task_id).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
try {
if (rdr.Move_next()) {
if (rv == null) rv = Hash_adp_.New();
rv.Add_as_key_and_val(rdr.Read_int("step_id"));
}
}
finally {rdr.Rls();}
return null;
}
public void Rls() {}
}

View File

@@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Xobc_done_task_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_task_id, fld_task_seqn;
private final Db_conn conn;
public Xobc_done_task_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "xobc_done_task";
this.fld_task_id = flds.Add_int_pkey("task_id");
this.fld_task_seqn = flds.Add_int("task_seqn");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(int task_id, int task_seqn) {
conn.Stmt_insert(tbl_name, fld_task_id, fld_task_seqn)
.Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn)
.Exec_insert();
}
public void Delete(int task_id) {
conn.Stmt_delete(tbl_name, fld_task_id)
.Crt_int(fld_task_id, task_id)
.Exec_delete();
}
public void Select_all(Xobc_task_regy__base todo_regy, Xobc_task_regy__base done_regy) {
done_regy.Clear();
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int task_id = rdr.Read_int(fld_task_id);
int task_seqn = rdr.Read_int(fld_task_seqn);
Xobc_task_itm itm = (Xobc_task_itm)todo_regy.Get_by(task_id);
if (itm == null) {
Gfo_log_.Instance.Warn("task exists in done, but not in todo", "task_id", task_id);
continue;
}
done_regy.Add(itm);
todo_regy.Del_by(task_id);
itm.Task_seqn_(task_seqn);
}
} finally {rdr.Rls();}
}
public void Rls() {}
}

View File

@@ -0,0 +1,72 @@
/*
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.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
import gplx.dbs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Xobc_work_task_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_task_id, fld_task_seqn, fld_step_id, fld_cmd_id;
private final Db_conn conn;
public Xobc_work_task_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "xobc_work_task";
this.fld_task_id = flds.Add_int_pkey("task_id");
this.fld_task_seqn = flds.Add_int("task_seqn");
this.fld_step_id = flds.Add_int("step_id");
this.fld_cmd_id = flds.Add_int("cmd_id");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Select_all(Xobc_task_mgr task_mgr, Xobc_task_regy__base todo_regy, Xobc_task_regy__base work_regy) {
work_regy.Clear();
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int task_id = rdr.Read_int(fld_task_id);
int task_seqn = rdr.Read_int(fld_task_seqn);
int step_id = rdr.Read_int(fld_step_id);
int cmd_id = rdr.Read_int(fld_cmd_id);
Xobc_task_itm task = (Xobc_task_itm)todo_regy.Get_by(task_id);
if (task == null) {
Gfo_log_.Instance.Warn("task exists in work, but not in todo", "task_id", task_id);
continue;
}
work_regy.Add(task);
todo_regy.Del_by(task_id);
task.Task_seqn_(task_seqn);
task.Task_status_(cmd_id == Xobc_cmd__base.Seqn__0 ? gplx.core.progs.Gfo_prog_ui_.Status__init : gplx.core.progs.Gfo_prog_ui_.Status__working);
task_mgr.Step_mgr().Load(task, step_id, cmd_id);
}
} finally {rdr.Rls();}
}
public void Insert(int task_id, int task_seqn, int step_id, int cmd_id) {
conn.Stmt_insert(tbl_name, fld_task_id, fld_task_seqn, fld_step_id, fld_cmd_id)
.Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_id, step_id).Val_int(fld_cmd_id, cmd_id)
.Exec_insert();
}
public void Update(int task_id, int task_seqn, int step_id, int cmd_id) {
conn.Stmt_update_exclude(tbl_name, flds, fld_task_id)
.Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_id, step_id).Val_int(fld_cmd_id, cmd_id).Crt_int(fld_task_id, task_id)
.Exec_update();
}
public void Delete(int task_id) {
conn.Stmt_delete(tbl_name, fld_task_id).Val_int(fld_task_id, task_id).Exec_insert();
}
public void Rls() {}
}

View File

@@ -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.bldrs.centrals.steps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.brys.evals.*; import gplx.core.primitives.*;
import gplx.xowa.addons.bldrs.centrals.tasks.*; import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.utils.*;
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
import gplx.xowa.addons.bldrs.exports.merges.*;
import gplx.xowa.wikis.domains.*;
public class Xobc_step_factory {
private final Xobc_task_mgr task_mgr;
private final Xobc_data_db data_db;
private final Bry_eval_mgr eval_mgr = Bry_eval_mgr.Dflt(), eval_mgr__host_regy = Bry_eval_mgr.Dflt();
private final Bry_eval_wkr__host_regy eval_wkr__host_regy = new Bry_eval_wkr__host_regy();
public Xobc_step_factory(Xobc_task_mgr task_mgr, Xobc_data_db data_db, Io_url wiki_dir) {
this.task_mgr = task_mgr;
this.data_db = data_db;
eval_mgr.Add_many(new Bry_eval_wkr__builder_central(wiki_dir));
eval_mgr__host_regy.Add_many(eval_wkr__host_regy);
}
public void Load(Xobc_task_itm task, int step_id, int cmd_idx) {
int step_type = data_db.Tbl__step_regy().Select_type(step_id);
switch (step_type) {
case Xobc_step_itm.Type__wiki_import: Load_wiki_import(task, step_id, cmd_idx); break;
default: throw Err_.new_unhandled_default(step_type);
}
}
private void Load_wiki_import(Xobc_task_itm task, int step_id, int cmd_idx) {
int step_seqn = data_db.Tbl__step_map().Select_one(task.Task_id(), step_id).Step_seqn;
Xobc_import_step_itm import_itm = data_db.Tbl__import_step().Select_one(step_id); String_obj_ref step_name = String_obj_ref.empty_();
Xobc_cmd_itm[] cmds = Make_wiki_import_cmds(import_itm, task.Task_id(), step_id, step_name, step_seqn);
Xobc_step_itm step = new Xobc_step_itm(step_id, step_seqn, cmds).Cmd_idx_(cmd_idx);
step.Step_name_(String_.Format("{0}&nbsp;&middot;({1}/{2})", step_name.Val(), step_seqn + List_adp_.Base1, task.Step_count()));
task.Step_(step);
step.Cmd().Load_checkpoint();
if (step.Cmd().Prog_status() == gplx.core.progs.Gfo_prog_ui_.Status__working)
task.Task_status_(step.Cmd().Prog_status());
}
private Xobc_cmd_itm[] Make_wiki_import_cmds(Xobc_import_step_itm import_itm, int task_id, int step_id, String_obj_ref step_name, int step_seqn) {
List_adp list = List_adp_.New();
Xow_domain_itm domain_itm = Xow_abrv_xo_.To_itm(import_itm.Wiki_abrv());
String wiki_domain = domain_itm.Domain_str();
String file_name = import_itm.Import_name;
step_name.Val_(file_name);
eval_wkr__host_regy.Domain_itm_(domain_itm);
String src_http_url = data_db.Bld_src_http_url(eval_mgr__host_regy, import_itm.Host_id, file_name);
Io_url zip_file_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__download_fil, wiki_domain, file_name));
Io_url unzip_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__unzip_dir, wiki_domain, file_name));
Io_url wiki_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__wiki_dir, wiki_domain, file_name));
list.Add(new Xobc_cmd__download (task_mgr, task_id, step_id, 0, src_http_url, zip_file_url, import_itm.Import_size_zip));
list.Add(new Xobc_cmd__verify_fil (task_mgr, task_id, step_id, 1, zip_file_url, import_itm.Import_md5, import_itm.Import_size_zip));
list.Add(new Xobc_cmd__unzip (task_mgr, task_id, step_id, 2, zip_file_url, unzip_dir_url, import_itm.Import_size_raw));
list.Add(new Xobc_cmd__verify_dir (task_mgr, task_id, step_id, 3, unzip_dir_url, String_.Replace(file_name, ".zip", ".md5"), zip_file_url));
// list.Add(new Xobc_cmd__wiki_merge (task_mgr, task_id, step_id, 4, merge_mgr, wiki_domain, unzip_dir_url, import_itm.Import_prog_data_max, import_itm.Import_prog_row_max, step_seqn));
list.Add(new Xobc_cmd__move_fils (task_mgr, task_id, step_id, 4, unzip_dir_url, wiki_dir_url));
if (import_itm.Import_type == Xobc_import_type.Tid__wiki__core) {
list.Add(new Xobc_cmd__wiki_reg (task_mgr, task_id, step_id, 5, wiki_dir_url, wiki_domain));
}
return (Xobc_cmd_itm[])list.To_ary_and_clear(Xobc_cmd_itm.class);
}
private Io_url Eval_url(String src) {return Io_url_.new_any_(String_.new_u8(eval_mgr.Eval(Bry_.new_u8(src))));}
}

View File

@@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.steps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*;
public class Xobc_step_itm {
private int cmd_idx = 0;
private final Xobc_cmd_itm[] cmds;
public Xobc_step_itm(int step_id, int step_seqn, Xobc_cmd_itm[] cmds) {
this.step_id = step_id; this.step_seqn = step_seqn; this.cmds = cmds;
}
public int Step_id() {return step_id;} private final int step_id;
public int Step_seqn() {return step_seqn;} private final int step_seqn;
public String Step_name() {return step_name;} private String step_name;
public Xobc_cmd_itm Cmd() {return cmds[cmd_idx];}
public Xobc_step_itm Cmd_idx_(int v) {cmd_idx = v; return this;}
public void Cmd_idx_next_() {++cmd_idx;}
public boolean Cmd_is_last() {return cmd_idx == cmds.length - 1;}
public Xobc_cmd_itm Step_fallback_to(String fallback_id) {
int fallback_idx = 0;
int len = cmds.length;
for (int i = 0; i < len; ++i) {
Xobc_cmd_itm cmd = cmds[i];
if (String_.Eq(cmd.Cmd_type(), fallback_id)) {
fallback_idx = cmd.Cmd_id();
break;
}
}
cmd_idx = fallback_idx;
return Cmd();
}
public void Step_name_(String v) {this.step_name = v;}
public void Step_cleanup() {
int len = cmds.length;
for (int i = 0; i < len; ++i) {
cmds[i].Cmd_cleanup();
}
}
public Gfobj_nde Save_to(Gfobj_nde nde) {
nde.Add_int ("step_id", step_id);
nde.Add_str ("step_name", step_name);
this.Cmd().Save_to(nde.New_nde("cmd"));
return nde; // fluent
}
public static final int Type__wiki_import = 1;
public static final int Seqn__0 = 0;
}

View File

@@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*;
public class Xobc_task_itm {
public Xobc_task_itm(int task_id, int task_seqn, int step_count, String task_key, String task_name) {
this.task_id = task_id; this.task_seqn = task_seqn;
this.step_count = step_count;
this.task_key = task_key;
this.task_name = task_name;
}
public int Task_id() {return task_id;} private final int task_id;
public String Task_key() {return task_key;} private final String task_key;
public String Task_name() {return task_name;} private final String task_name;
public int Step_count() {return step_count;} private final int step_count;
public int Task_seqn() {return task_seqn;} private int task_seqn;
public byte Task_status() {return task_status;} private byte task_status;
public Xobc_step_itm Step() {return step;} public void Step_(Xobc_step_itm v) {this.step = v;} private Xobc_step_itm step;
public boolean Step_is_last() {return step.Step_seqn() == step_count - 1;}
public void Task_status_(byte v) {task_status = v;} // called when task moves from init -> working -> suspended -> done
public void Task_seqn_(int v) {this.task_seqn = v;} // called when task is init'd from db, or added to list
public Gfobj_nde Save_to(Gfobj_nde nde) {
nde.Add_int ("task_id" , task_id);
nde.Add_str ("task_name" , task_name);
nde.Add_byte("task_status" , task_status);
if (step != null) {
step.Save_to(nde.New_nde("step"));
}
return nde; // FLUENT
}
}

View File

@@ -0,0 +1,42 @@
/*
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.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*;
public abstract class Xobc_task_regy__base {
private final Ordered_hash hash = Ordered_hash_.New();
protected final Xobc_task_mgr task_mgr;
public Xobc_task_regy__base(Xobc_task_mgr task_mgr, String name) {this.task_mgr = task_mgr; this.name = name;}
public String Name() {return name;} private final String name;
public int Len() {return hash.Len();}
public void Add(Xobc_task_itm t) {hash.Add(t.Task_id(), t);}
public void Clear() {hash.Clear();}
public Xobc_task_itm Get_at(int i) {return (Xobc_task_itm)hash.Get_at(i);}
public Xobc_task_itm Get_by(int i) {return (Xobc_task_itm)hash.Get_by(i);}
public void Del_by(int i) {hash.Del(i);}
public void Save_to(Gfobj_ary ary) {
int len = hash.Len();
Gfobj_nde[] sub_ndes = new Gfobj_nde[len];
ary.Ary_(sub_ndes);
for (int i = 0; i < len; ++i) {
Gfobj_nde sub_nde = sub_ndes[i] = Gfobj_nde.New();
Xobc_task_itm sub_task = (Xobc_task_itm)hash.Get_at(i);
sub_task.Save_to(sub_nde);
}
}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
public class Xobc_task_regy__done extends Xobc_task_regy__base {
public Xobc_task_regy__done(Xobc_task_mgr task_mgr) {super(task_mgr, "done");}
public void Del_done(int task_id) {
task_mgr.User_db().Done_task_tbl().Delete(task_id);
task_mgr.Transfer(this, task_mgr.Todo_mgr(), this.Get_by(task_id));
}
}

View File

@@ -0,0 +1,43 @@
/*
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.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*;
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
public class Xobc_task_regy__todo extends Xobc_task_regy__base {
public Xobc_task_regy__todo(Xobc_task_mgr task_mgr) {super(task_mgr, "todo");}
public void Add_work(int task_id) {
Xobc_user_db user_db = task_mgr.User_db();
Xobc_task_itm task = task_mgr.Todo_mgr().Get_by(task_id);
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__init);
task.Task_seqn_(task_mgr.Work_mgr().Len());
// get step_id; default is 1st step with seqn=0, but skip any steps that have already been downloaded; handles user accidentally removing item from work;
int step_seqn = Xobc_step_itm.Seqn__0;
Hash_adp done_steps = user_db.Done_step_tbl().Select_all(task_id);
if (done_steps != null)
step_seqn = task_mgr.Data_db().Tbl__step_map().Select_seqn_but_skip_done(task_id, done_steps);
int step_id = task_mgr.Data_db().Tbl__step_map().Select_step_id(task_id, step_seqn);
// load task, cur_step, and all cmds
task_mgr.Step_mgr().Load(task, step_id, Xobc_cmd__base.Seqn__0);
// do transfer
user_db.Work_task_tbl().Insert(task_id, task.Task_seqn(), step_id, Xobc_cmd__base.Seqn__0);
task_mgr.Transfer(this, task_mgr.Work_mgr(), task);
}
}

View File

@@ -0,0 +1,139 @@
/*
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.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.threads.*;
import gplx.xowa.drds.powers.*;
import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.cmds.*;
public class Xobc_task_regy__work extends Xobc_task_regy__base {
private final Thread_adp_mgr thread_mgr = new Thread_adp_mgr(1000, 5000);
private final Xobc_cmd_ctx ctx;
public Xobc_task_regy__work(Xobc_task_mgr task_mgr, Xoa_app app) {super(task_mgr, "work");
this.ctx = new Xobc_cmd_ctx(app);
}
public void Del_work(int task_id) {
Xobc_task_itm task = this.Get_by(task_id);
if (task.Step() != null) task.Step().Step_cleanup();
this.Del_task(task, task_mgr.Todo_mgr());
}
private void Del_task(Xobc_task_itm task, Xobc_task_regy__base trg) {
task_mgr.User_db().Work_task_tbl().Delete(task.Task_id());
task_mgr.Transfer(this, trg, task);
}
public void Run_next() {
Xod_power_mgr_.Instance.Wake_lock__get("task_mgr");
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xobc_task_itm task = this.Get_at(i);
Xobc_cmd_itm cmd = task.Step().Cmd();
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__runnable, cmd.Prog_status())) { // must be runnable
Run_task(task, cmd);
break;
}
}
}
public void Run_task(Xobc_task_itm task, Xobc_cmd_itm cmd) {
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__working);
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
}
public void Stop_cur() {
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xobc_task_itm task = this.Get_at(i);
Xobc_cmd_itm cmd = task.Step().Cmd();
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__working, cmd.Prog_status())) { // must be runnable
Stop_task(cmd.Cmd_uid());
break;
}
}
}
public void Redo_cur() {
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xobc_task_itm task = this.Get_at(i);
Xobc_step_itm step = task.Step();
Xobc_cmd_itm cmd = step.Cmd();
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__fail, cmd.Prog_status())) { // must be runnable
Redo_task(task, step, cmd);
break;
}
}
}
private void Stop_task(String cmd_uid) {
thread_mgr.Halt(cmd_uid, Thread_halt_cbk_.Noop);
}
private void Redo_task(Xobc_task_itm task, Xobc_step_itm step, Xobc_cmd_itm cmd) {
cmd.Cmd_clear();
cmd = step.Step_fallback_to(cmd.Cmd_fallback());
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__working);
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
}
public void On_done(Xobc_cmd_itm cmd) {
Xobc_task_itm task = this.Get_by(cmd.Task_id());
Xobc_step_itm step = task.Step();
boolean step_is_done = step.Cmd_is_last();
boolean task_is_done = step_is_done && task.Step_is_last();
task_mgr.Send_json("xo.bldr.work.prog__done__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_bool("task_is_done", task_is_done));
// step.done -> task.done || step.next
if (step_is_done) {
step.Step_cleanup();
task_mgr.User_db().Done_step_tbl().Insert(cmd.Task_id(), cmd.Step_id());
// task.done
if (task_is_done) {
task.Task_status_(Gfo_prog_ui_.Status__done);
task_mgr.User_db().Done_task_tbl().Insert(cmd.Task_id(), task.Task_seqn()); // NOTE: this will order by todo's sort, not by actually completed sorted
Del_task(task, task_mgr.Done_mgr());
}
// step.next
else {
int next_step = task_mgr.Data_db().Tbl__step_map().Select_step_id(task.Task_id(), step.Step_seqn() + 1);
task_mgr.Step_mgr().Load(task, next_step, Xobc_cmd__base.Seqn__0);
}
}
// step.work -> cmd.next
else {
step.Cmd_idx_next_();
}
// task_regy.done
if (task_is_done) {
if (this.Len() == 0)
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
else
this.Run_next();
}
// task_regy.work
else {
cmd = task.Step().Cmd();
task_mgr.User_db().Work_task_tbl().Update(cmd.Task_id(), task.Task_seqn(), cmd.Step_id(), cmd.Cmd_id());
this.Run_next();
}
}
public void On_suspended(Xobc_cmd_itm cmd) {
Xobc_task_itm task = this.Get_by(cmd.Task_id());
task.Task_status_(Gfo_prog_ui_.Status__suspended);
task_mgr.Send_json("xo.bldr.work.stop_cur__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()));
}
public void On_fail(Xobc_cmd_itm task, String msg) {
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
task_mgr.Send_json("xo.bldr.work.prog__fail__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_str("err", msg));
}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.brys.evals.*;
public class Bry_eval_wkr__builder_central implements Bry_eval_wkr {
private final byte[] wiki_dir;
public Bry_eval_wkr__builder_central(Io_url wiki_dir) {this.wiki_dir = wiki_dir.RawBry();}
public String Key() {return "builder_central";}
public void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end) {
// EX: "~{builder_central|download_fil|en.wikipedia.org|en.wikipedia.org-2016.05-html-ns.000-db.001.zip}" -> "/xowa/wiki/en.wikipedia.org/tmp/bldr/en.wikipedia.org-2016.05-html-ns.000-db.001.zip/download.zip"
byte[][] args = Bry_split_.Split(src, args_bgn, args_end, Byte_ascii.Pipe, Bool_.N);
int type = hash.Get_as_byte_or(args[0], Byte_.Max_value_127);
if (type == Byte_.Max_value_127) throw Err_.new_wo_type("unknown eval type", "src", src);
byte dir_spr = gplx.core.envs.Op_sys.Cur().Fsys_dir_spr_byte();
rv.Add(wiki_dir); // "/xowa/wiki/"
rv.Add(args[1]).Add_byte(dir_spr); // "en.wikipedia.org/"
if (type == Type__wiki_dir) return;
rv.Add_str_a7("tmp").Add_byte(dir_spr); // "tmp/"
rv.Add_str_a7("bldr").Add_byte(dir_spr); // "bldr/"
rv.Add(args[2]).Add_byte(dir_spr); // "en.wikipedia.org-2016.05-html-ns.000-db.001.zip/"
switch (type) {
case Type__download_fil: rv.Add_str_a7("download.zip"); break;
case Type__unzip_dir: rv.Add_str_a7("unzip").Add_byte(dir_spr); break;
default: throw Err_.new_unhandled_default(type);
}
}
public static final byte Type__download_fil = 0, Type__unzip_dir = 1, Type__wiki_dir = 2;
private static final Hash_adp_bry hash = Hash_adp_bry.cs()
.Add_str_byte("download_fil", Type__download_fil)
.Add_str_byte("unzip_dir", Type__unzip_dir)
.Add_str_byte("wiki_dir", Type__wiki_dir)
;
public static String Make_str(byte type, String domain, String file_name) {
String type_name = null;
switch (type) {
case Type__download_fil: type_name = "download_fil"; break;
case Type__unzip_dir: type_name = "unzip_dir"; break;
case Type__wiki_dir: type_name = "wiki_dir"; break;
default: throw Err_.new_unhandled_default(type);
}
return "~{" + String_.Format("builder_central|{0}|{1}|{2}", type_name, domain, file_name) + "}";
}
public static String Make_str(byte type, String domain) {
String type_name = null;
switch (type) {
case Type__wiki_dir: type_name = "wiki_dir"; break;
default: throw Err_.new_unhandled_default(type);
}
return "~{" + String_.Format("builder_central|{0}|{1}", type_name, domain) + "}";
}
}

View File

@@ -0,0 +1,38 @@
/*
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.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.brys.evals.*;
import gplx.xowa.wikis.domains.*;
public class Bry_eval_wkr__host_regy implements Bry_eval_wkr {
private Xow_domain_itm domain_itm;
public String Key() {return "host_regy";}
public Bry_eval_wkr__host_regy Domain_itm_(Xow_domain_itm domain_itm) {this.domain_itm = domain_itm; return this;}
public void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end) {
// EX: "~{host_regy|wiki_abrv}" -> "enwiki"
int type = hash.Get_as_byte_or(src, args_bgn, args_end, Byte_.Max_value_127);
switch (type) {
case Type__wiki_abrv: rv.Add(domain_itm.Abrv_wm()); break;
default: throw Err_.new_unhandled_default(type);
}
}
public static final byte Type__wiki_abrv = 0;
private static final Hash_adp_bry hash = Hash_adp_bry.cs()
.Add_str_byte("wiki_abrv", Type__wiki_abrv)
;
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
public class Time_dhms_ {
public static String To_str(Bry_bfr bfr, long val, boolean show_unit, int max_places) {To_bfr(bfr, val, show_unit, max_places); return bfr.To_str_and_clear();}
public static void To_bfr(Bry_bfr bfr, long val, boolean show_unit, int max_places) {
byte suffix = Byte_ascii.Null;
int count = 0;
for (int i = 0; i < 4; ++i) {
// get factor and unit
long factor = 0;
byte unit = Byte_ascii.Null;
switch(i) {
case 0: unit = Byte_ascii.Ltr_d; factor = 86400; break;
case 1: unit = Byte_ascii.Ltr_h; factor = 3600; break;
case 2: unit = Byte_ascii.Ltr_m; factor = 60; break;
case 3: unit = Byte_ascii.Ltr_s; factor = 1; break;
}
// calc cur and update val; EX: 3690 -> cur:1,mod:90
int cur = (int)(val / factor);
val %= factor;
if (count == 0) { // no str yet
if ( cur == 0 // cur is 0; EX: 3690 and factor = 86400 -> 0 days; don't write anything
&& i != 3) // unless it is the seconds place; need to handle "0 s" specifically
continue;
suffix = unit; // set suffix
bfr.Add_int_variable(cur); // write cur; note that this is not zero-padded
}
else { // str exists
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 2, cur); // write cur; note that this zero-padded; also, note will write "00" if cur == 0
}
if (++count == max_places) break; // stop if max-places reached; EX: 86400 should write 1:00, not 1:00:00:00
if (i != 3) // do not add ":" if seconds
bfr.Add_byte_colon();
}
if (show_unit) // add units; EX: " s" for seconds
bfr.Add_byte_space().Add_byte(suffix);
}
}

View File

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